1 /************************************************************************
2  **
3  **  @file   ifcdef.cpp
4  **  @author Roman Telezhynskyi <dismine(at)gmail.com>
5  **  @date   11 6, 2015
6  **
7  **  @brief
8  **  @copyright
9  **  This source code is part of the Valentina project, a pattern making
10  **  program, whose allow create and modeling patterns of clothing.
11  **  Copyright (C) 2015 Valentina project
12  **  <https://gitlab.com/smart-pattern/valentina> All Rights Reserved.
13  **
14  **  Valentina is free software: you can redistribute it and/or modify
15  **  it under the terms of the GNU General Public License as published by
16  **  the Free Software Foundation, either version 3 of the License, or
17  **  (at your option) any later version.
18  **
19  **  Valentina is distributed in the hope that it will be useful,
20  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  **  GNU General Public License for more details.
23  **
24  **  You should have received a copy of the GNU General Public License
25  **  along with Valentina.  If not, see <http://www.gnu.org/licenses/>.
26  **
27  *************************************************************************/
28 
29 #include "ifcdef.h"
30 
31 #include <QBrush>
32 #include <QIcon>
33 #include <QMap>
34 #include <QPainter>
35 #include <QPen>
36 #include <QPixmap>
37 #include <QStaticStringData>
38 #include <QStringData>
39 #include <QStringDataPtr>
40 
41 #include "../vmisc/diagnostic.h"
42 
43 const QString CustomMSign    = QStringLiteral("@");
44 const QString CustomIncrSign = QStringLiteral("#");
45 
46 const QString AttrType        = QStringLiteral("type");
47 const QString AttrMx          = QStringLiteral("mx");
48 const QString AttrMy          = QStringLiteral("my");
49 const QString AttrName        = QStringLiteral("name");
50 const QString AttrMx1         = QStringLiteral("mx1");
51 const QString AttrMy1         = QStringLiteral("my1");
52 const QString AttrName1       = QStringLiteral("name1");
53 const QString AttrMx2         = QStringLiteral("mx2");
54 const QString AttrMy2         = QStringLiteral("my2");
55 const QString AttrName2       = QStringLiteral("name2");
56 const QString AttrBaseLineP1  = QStringLiteral("baseLineP1");
57 const QString AttrBaseLineP2  = QStringLiteral("baseLineP2");
58 const QString AttrDartP1      = QStringLiteral("dartP1");
59 const QString AttrDartP2      = QStringLiteral("dartP2");
60 const QString AttrDartP3      = QStringLiteral("dartP3");
61 const QString AttrX           = QStringLiteral("x");
62 const QString AttrY           = QStringLiteral("y");
63 const QString AttrTypeLine    = QStringLiteral("typeLine");
64 const QString AttrCut         = QStringLiteral("cut");
65 const QString AttrLength      = QStringLiteral("length");
66 const QString AttrBasePoint   = QStringLiteral("basePoint");
67 const QString AttrFirstPoint  = QStringLiteral("firstPoint");
68 const QString AttrSecondPoint = QStringLiteral("secondPoint");
69 const QString AttrThirdPoint  = QStringLiteral("thirdPoint");
70 const QString AttrCenter      = QStringLiteral("center");
71 const QString AttrRadius      = QStringLiteral("radius");
72 const QString AttrRadius1     = QStringLiteral("radius1");
73 const QString AttrRadius2     = QStringLiteral("radius2");
74 const QString AttrAngle       = QStringLiteral("angle");
75 const QString AttrAngle1      = QStringLiteral("angle1");
76 const QString AttrAngle2      = QStringLiteral("angle2");
77 const QString AttrLength1     = QStringLiteral("length1");
78 const QString AttrLength2     = QStringLiteral("length2");
79 const QString AttrP1Line      = QStringLiteral("p1Line");
80 const QString AttrP2Line      = QStringLiteral("p2Line");
81 const QString AttrP1Line1     = QStringLiteral("p1Line1");
82 const QString AttrP2Line1     = QStringLiteral("p2Line1");
83 const QString AttrP1Line2     = QStringLiteral("p1Line2");
84 const QString AttrP2Line2     = QStringLiteral("p2Line2");
85 const QString AttrPShoulder   = QStringLiteral("pShoulder");
86 const QString AttrPoint1      = QStringLiteral("point1");
87 const QString AttrPoint2      = QStringLiteral("point2");
88 const QString AttrPoint3      = QStringLiteral("point3");
89 const QString AttrPoint4      = QStringLiteral("point4");
90 const QString AttrKAsm1       = QStringLiteral("kAsm1");
91 const QString AttrKAsm2       = QStringLiteral("kAsm2");
92 const QString AttrKCurve      = QStringLiteral("kCurve");
93 const QString AttrDuplicate   = QStringLiteral("duplicate");
94 const QString AttrAScale      = QStringLiteral("aScale");
95 const QString AttrPathPoint   = QStringLiteral("pathPoint");
96 const QString AttrPSpline     = QStringLiteral("pSpline");
97 const QString AttrAxisP1      = QStringLiteral("axisP1");
98 const QString AttrAxisP2      = QStringLiteral("axisP2");
99 const QString AttrCurve       = QStringLiteral("curve");
100 const QString AttrCurve1      = QStringLiteral("curve1");
101 const QString AttrCurve2      = QStringLiteral("curve2");
102 const QString AttrLineColor   = QStringLiteral("lineColor");
103 const QString AttrColor       = QStringLiteral("color");
104 const QString AttrPenStyle    = QStringLiteral("penStyle");
105 const QString AttrFirstArc    = QStringLiteral("firstArc");
106 const QString AttrSecondArc   = QStringLiteral("secondArc");
107 const QString AttrCrossPoint  = QStringLiteral("crossPoint");
108 const QString AttrVCrossPoint = QStringLiteral("vCrossPoint");
109 const QString AttrHCrossPoint = QStringLiteral("hCrossPoint");
110 const QString AttrAxisType    = QStringLiteral("axisType");
111 const QString AttrC1Center    = QStringLiteral("c1Center");
112 const QString AttrC2Center    = QStringLiteral("c2Center");
113 const QString AttrC1Radius    = QStringLiteral("c1Radius");
114 const QString AttrC2Radius    = QStringLiteral("c2Radius");
115 const QString AttrCCenter     = QStringLiteral("cCenter");
116 const QString AttrTangent     = QStringLiteral("tangent");
117 const QString AttrCRadius     = QStringLiteral("cRadius");
118 const QString AttrArc         = QStringLiteral("arc");
119 const QString AttrSuffix      = QStringLiteral("suffix");
120 const QString AttrItem        = QStringLiteral("item");
121 const QString AttrIdObject    = QStringLiteral("idObject");
122 const QString AttrInLayout    = QStringLiteral("inLayout");
123 const QString AttrForbidFlipping = QStringLiteral("forbidFlipping");
124 const QString AttrForceFlipping = QStringLiteral("forceFlipping");
125 const QString AttrRotationAngle = QStringLiteral("rotationAngle");
126 const QString AttrClosed      = QStringLiteral("closed");
127 const QString AttrShowLabel   = QStringLiteral("showLabel");
128 const QString AttrShowLabel1  = QStringLiteral("showLabel1");
129 const QString AttrShowLabel2  = QStringLiteral("showLabel2");
130 const QString AttrWidth       = QStringLiteral("width");
131 const QString AttrHeight      = QStringLiteral("height");
132 const QString AttrPlaceLabelType = QStringLiteral("placeLabelType");
133 const QString AttrVersion     = QStringLiteral("version");
134 const QString AttrFirstToCountour = QStringLiteral("firstToCountour");
135 const QString AttrLastToCountour = QStringLiteral("lastToCountour");
136 const QString AttrNotes       = QStringLiteral("notes");
137 const QString AttrAlias       = QStringLiteral("alias");
138 const QString AttrAlias1      = QStringLiteral("alias1");
139 const QString AttrAlias2      = QStringLiteral("alias2");
140 const QString AttrCurve1Alias1 = QStringLiteral("curve1Alias1");
141 const QString AttrCurve1Alias2 = QStringLiteral("curve1Alias2");
142 const QString AttrCurve2Alias1 = QStringLiteral("curve2Alias1");
143 const QString AttrCurve2Alias2 = QStringLiteral("curve2Alias2");
144 
145 const QString TypeLineDefault        = QStringLiteral("default");
146 const QString TypeLineNone           = QStringLiteral("none");
147 const QString TypeLineLine           = QStringLiteral("hair");
148 const QString TypeLineDashLine       = QStringLiteral("dashLine");
149 const QString TypeLineDotLine        = QStringLiteral("dotLine");
150 const QString TypeLineDashDotLine    = QStringLiteral("dashDotLine");
151 const QString TypeLineDashDotDotLine = QStringLiteral("dashDotDotLine");
152 
153 //---------------------------------------------------------------------------------------------------------------------
154 /**
155  * @brief Styles return list of all line styles.
156  * @return list of all line styles.
157  */
StylesList()158 QStringList StylesList()
159 {
160     return QStringList{
161         TypeLineNone,
162         TypeLineLine,
163         TypeLineDashLine,
164         TypeLineDotLine,
165         TypeLineDashDotLine,
166         TypeLineDashDotDotLine
167     };
168 }
169 
170 //---------------------------------------------------------------------------------------------------------------------
171 /**
172  * @brief LineStyle return pen style for current line style.
173  * @return pen style.
174  */
LineStyleToPenStyle(const QString & typeLine)175 Qt::PenStyle LineStyleToPenStyle(const QString &typeLine)
176 {
177     const QStringList styles = StylesList();
178     switch (styles.indexOf(typeLine))
179     {
180         case 0: // TypeLineNone
181             return Qt::NoPen;
182         case 2: // TypeLineDashLine
183             return Qt::DashLine;
184         case 3: // TypeLineDotLine
185             return Qt::DotLine;
186         case 4: // TypeLineDashDotLine
187             return Qt::DashDotLine;
188         case 5: // TypeLineDashDotDotLine
189             return Qt::DashDotDotLine;
190         default:
191             return Qt::SolidLine;
192     }
193 }
194 
195 //---------------------------------------------------------------------------------------------------------------------
PenStyleToLineStyle(Qt::PenStyle penStyle)196 QString PenStyleToLineStyle(Qt::PenStyle penStyle)
197 {
198     QT_WARNING_PUSH
199     QT_WARNING_DISABLE_GCC("-Wswitch-default")
200 
201     switch (penStyle)
202     {
203         case Qt::NoPen:
204             return TypeLineNone;
205         case Qt::DashLine:
206             return TypeLineDashLine;
207         case Qt::DotLine:
208             return TypeLineDotLine;
209         case Qt::DashDotLine:
210             return TypeLineDashDotLine;
211         case Qt::DashDotDotLine:
212             return TypeLineDashDotDotLine;
213         default:
214             break;
215     }
216 
217     QT_WARNING_POP
218 
219     return TypeLineLine;
220 }
221 
222 //---------------------------------------------------------------------------------------------------------------------
PenStylePic(Qt::PenStyle style)223 QIcon PenStylePic(Qt::PenStyle style)
224 {
225     QPixmap pix(80, 14);
226     pix.fill(Qt::white);
227 
228     QBrush brush(Qt::black);
229     QPen pen(brush, 2.5, style);
230 
231     QPainter painter(&pix);
232     painter.setPen(pen);
233     painter.drawLine(2, 7, 78, 7);
234 
235     return QIcon(pix);
236 }
237 
238 //---------------------------------------------------------------------------------------------------------------------
LineStylesPics()239 QMap<QString, QIcon> LineStylesPics()
240 {
241     QMap<QString, QIcon> map;
242     const QStringList styles = StylesList();
243 
244     for (auto &s : styles)
245     {
246         map.insert(s, PenStylePic(LineStyleToPenStyle(s)));
247     }
248     return map;
249 }
250 
251 //---------------------------------------------------------------------------------------------------------------------
CurvePenStylesPics()252 QMap<QString, QIcon> CurvePenStylesPics()
253 {
254     QMap<QString, QIcon> map = LineStylesPics();
255     map.remove(TypeLineNone);
256     return map;
257 }
258 
259 const QString ColorDefault          = QStringLiteral("default");
260 const QString ColorBlack            = QStringLiteral("black");
261 const QString ColorGreen            = QStringLiteral("green");
262 const QString ColorBlue             = QStringLiteral("blue");
263 const QString ColorDarkRed          = QStringLiteral("darkRed");
264 const QString ColorDarkGreen        = QStringLiteral("darkGreen");
265 const QString ColorDarkBlue         = QStringLiteral("darkBlue");
266 const QString ColorYellow           = QStringLiteral("yellow");
267 const QString ColorLightSalmon      = QStringLiteral("lightsalmon");
268 const QString ColorGoldenRod        = QStringLiteral("goldenrod");
269 const QString ColorOrange           = QStringLiteral("orange");
270 const QString ColorDeepPink         = QStringLiteral("deeppink");
271 const QString ColorViolet           = QStringLiteral("violet");
272 const QString ColorDarkViolet       = QStringLiteral("darkviolet");
273 const QString ColorMediumSeaGreen   = QStringLiteral("mediumseagreen");
274 const QString ColorLime             = QStringLiteral("lime");
275 const QString ColorDeepSkyBlue      = QStringLiteral("deepskyblue");
276 const QString ColorCornFlowerBlue   = QStringLiteral("cornflowerblue");
277 
278 //variables
279 const QString measurement_         = QStringLiteral("M_");
280 const QString increment_           = QStringLiteral("Increment_");
281 const QString line_                = QStringLiteral("Line_");
282 const QString angleLine_           = QStringLiteral("AngleLine_");
283 const QString spl_                 = QStringLiteral(SPL_);
284 const QString arc_                 = QStringLiteral(ARC_);
285 const QString elarc_               = QStringLiteral(ELARC_);
286 const QString splPath              = QStringLiteral("SplPath");
287 const QString radius_V             = QStringLiteral("Radius");
288 const QString radiusArc_           = radius_V + arc_;
289 const QString radius1ElArc_        = radius_V + QLatin1Char('1') + elarc_;
290 const QString radius2ElArc_        = radius_V + QLatin1Char('2') + elarc_;
291 const QString angle1_V             = QStringLiteral("Angle1");
292 const QString angle2_V             = QStringLiteral("Angle2");
293 const QString c1Length_V           = QStringLiteral("C1Length");
294 const QString c2Length_V           = QStringLiteral("C2Length");
295 const QString c1LengthSpl_         = c1Length_V + spl_;
296 const QString c2LengthSpl_         = c2Length_V + spl_;
297 const QString c1LengthSplPath      = c1Length_V + splPath;
298 const QString c2LengthSplPath      = c2Length_V + splPath;
299 const QString angle1Arc_           = angle1_V + arc_;
300 const QString angle2Arc_           = angle2_V + arc_;
301 const QString angle1ElArc_         = angle1_V + elarc_;
302 const QString angle2ElArc_         = angle2_V + elarc_;
303 const QString angle1Spl_           = angle1_V + spl_;
304 const QString angle2Spl_           = angle2_V + spl_;
305 const QString angle1SplPath        = angle1_V + splPath;
306 const QString angle2SplPath        = angle2_V + splPath;
307 const QString seg_                 = QStringLiteral("Seg_");
308 const QString currentLength        = QStringLiteral("CurrentLength");
309 const QString currentSeamAllowance = QStringLiteral("CurrentSeamAllowance");
310 const QString rotation_V           = QStringLiteral("Rotation");
311 const QString rotationElArc_       = rotation_V + elarc_;
312 
313 const QStringList builInVariables = QStringList() << measurement_
314                                                   << increment_
315                                                   << line_
316                                                   << angleLine_
317                                                   << arc_
318                                                   << elarc_
319                                                   << spl_
320                                                   << splPath
321                                                   << radiusArc_
322                                                   << radius1ElArc_
323                                                   << radius2ElArc_
324                                                   << angle1Arc_
325                                                   << angle2Arc_
326                                                   << angle1ElArc_
327                                                   << angle2ElArc_
328                                                   << angle1Spl_
329                                                   << angle2Spl_
330                                                   << angle1SplPath
331                                                   << angle2SplPath
332                                                   << seg_
333                                                   << currentLength
334                                                   << currentSeamAllowance
335                                                   << c1LengthSpl_
336                                                   << c2LengthSpl_
337                                                   << c1LengthSplPath
338                                                   << c2LengthSplPath
339                                                   << rotationElArc_;
340