Seamly2D
Code documentation
vlinelength.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * Copyright (C) 2017 Seamly, LLC *
4  * *
5  * https://github.com/fashionfreedom/seamly2d *
6  * *
7  ***************************************************************************
8  **
9  ** Seamly2D is free software: you can redistribute it and/or modify
10  ** it under the terms of the GNU General Public License as published by
11  ** the Free Software Foundation, either version 3 of the License, or
12  ** (at your option) any later version.
13  **
14  ** Seamly2D is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  ** GNU General Public License for more details.
18  **
19  ** You should have received a copy of the GNU General Public License
20  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
21  **
22  **************************************************************************
23 
24  ************************************************************************
25  **
26  ** @file vlinelength.cpp
27  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
28  ** @date 28 7, 2014
29  **
30  ** @brief
31  ** @copyright
32  ** This source code is part of the Valentine project, a pattern making
33  ** program, whose allow create and modeling patterns of clothing.
34  ** Copyright (C) 2013-2015 Seamly2D project
35  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
36  **
37  ** Seamly2D is free software: you can redistribute it and/or modify
38  ** it under the terms of the GNU General Public License as published by
39  ** the Free Software Foundation, either version 3 of the License, or
40  ** (at your option) any later version.
41  **
42  ** Seamly2D is distributed in the hope that it will be useful,
43  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
44  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  ** GNU General Public License for more details.
46  **
47  ** You should have received a copy of the GNU General Public License
48  ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
49  **
50  *************************************************************************/
51 
52 #include "vlinelength.h"
53 
54 #include <QLineF>
55 #include <QMessageLogger>
56 #include <QPointF>
57 #include <QString>
58 
59 #include "../ifc/ifcdef.h"
60 #include "../vgeometry/vpointf.h"
61 #include "vinternalvariable.h"
62 #include "vlinelength_p.h"
63 
64 #ifdef Q_COMPILER_RVALUE_REFS
65 VLengthLine &VLengthLine::operator=(VLengthLine &&var) Q_DECL_NOTHROW
66 { Swap(var); return *this; }
67 #endif
68 
69 void VLengthLine::Swap(VLengthLine &var) Q_DECL_NOTHROW
70 { VInternalVariable::Swap(var); std::swap(d, var.d); }
71 
72 //---------------------------------------------------------------------------------------------------------------------
75 {
77 }
78 
79 //---------------------------------------------------------------------------------------------------------------------
80 VLengthLine::VLengthLine(const VPointF *p1, const quint32 &p1Id, const VPointF *p2, const quint32 &p2Id,
81  Unit patternUnit)
82  :VInternalVariable(), d(new VLengthLineData(p1Id, p2Id, patternUnit))
83 {
84  SCASSERT(p1 != nullptr)
85  SCASSERT(p2 != nullptr)
86 
88  SetName(QString(line_+"%1_%2").arg(p1->name(), p2->name()));
89  SetValue(p1, p2);
90 }
91 
92 //---------------------------------------------------------------------------------------------------------------------
94  :VInternalVariable(var), d(var.d)
95 {}
96 
97 //---------------------------------------------------------------------------------------------------------------------
99 {
100  if ( &var == this )
101  {
102  return *this;
103  }
105  d = var.d;
106  return *this;
107 }
108 
109 //---------------------------------------------------------------------------------------------------------------------
111 {}
112 
113 //---------------------------------------------------------------------------------------------------------------------
114 bool VLengthLine::Filter(quint32 id)
115 {
116  return id == d->p1Id || id == d->p2Id;
117 }
118 
119 //---------------------------------------------------------------------------------------------------------------------
120 void VLengthLine::SetValue(const VPointF *p1, const VPointF *p2)
121 {
122  SCASSERT(p1 != nullptr)
123  SCASSERT(p2 != nullptr)
124 
125  VInternalVariable::SetValue(FromPixel(QLineF(static_cast<QPointF>(*p1), static_cast<QPointF>(*p2)).length(),
126  d->patternUnit));
127 }
128 
129 //---------------------------------------------------------------------------------------------------------------------
130 quint32 VLengthLine::GetP1Id() const
131 {
132  return d->p1Id;
133 }
134 
135 //---------------------------------------------------------------------------------------------------------------------
136 quint32 VLengthLine::GetP2Id() const
137 {
138  return d->p2Id;
139 }
virtual QString name() const
name return name graphical object.
Definition: vgobject.cpp:148
void SetType(const VarType &type)
void SetValue(const qreal &value)
void Swap(VInternalVariable &var) Q_DECL_NOTHROW
void SetName(const QString &name)
VInternalVariable & operator=(const VInternalVariable &var)
QSharedDataPointer< VLengthLineData > d
Definition: vlinelength.h:88
virtual bool Filter(quint32 id) Q_DECL_OVERRIDE
void SetValue(const VPointF *p1, const VPointF *p2)
virtual ~VLengthLine() Q_DECL_OVERRIDE
quint32 GetP1Id() const
VLengthLine & operator=(const VLengthLine &var)
Definition: vlinelength.cpp:98
void Swap(VLengthLine &var) Q_DECL_NOTHROW
Definition: vlinelength.cpp:69
quint32 GetP2Id() const
The VPointF class keep data of point.
Definition: vpointf.h:75
double FromPixel(double pix, const Unit &unit)
Definition: def.cpp:250
#define SCASSERT(cond)
Definition: def.h:317
Unit
Definition: def.h:105
const QString line_
Definition: ifcdef.cpp:414