1 /************************************************************************ 2 ** 3 ** @file 4 ** @author Roman Telezhynskyi <dismine(at)gmail.com> 5 ** @date 3 11, 2016 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) 2016 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 #ifndef VPIECENODE_P_H 30 #define VPIECENODE_P_H 31 32 #include <QSharedData> 33 #include <QDataStream> 34 #include <QCoreApplication> 35 36 #include "../ifc/ifcdef.h" 37 #include "../ifc/exception/vexception.h" 38 #include "../vmisc/diagnostic.h" 39 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) 40 # include "../vmisc/vdatastreamenum.h" 41 #endif 42 43 QT_WARNING_PUSH 44 QT_WARNING_DISABLE_GCC("-Weffc++") 45 QT_WARNING_DISABLE_GCC("-Wnon-virtual-dtor") 46 47 class VPieceNodeData : public QSharedData 48 { 49 public: VPieceNodeData()50 VPieceNodeData() 51 {} 52 VPieceNodeData(quint32 id,Tool typeTool,bool reverse)53 VPieceNodeData(quint32 id, Tool typeTool, bool reverse) 54 : m_id(id), 55 m_typeTool(typeTool), 56 m_reverse(reverse) 57 { 58 if (m_typeTool == Tool::NodePoint) 59 { 60 m_reverse = false; 61 } 62 } 63 VPieceNodeData(const VPieceNodeData & node)64 VPieceNodeData (const VPieceNodeData& node) 65 : QSharedData(node), 66 m_id(node.m_id), 67 m_typeTool(node.m_typeTool), 68 m_reverse(node.m_reverse), 69 m_excluded(node.m_excluded), 70 m_isPassmark(node.m_isPassmark), 71 m_isMainPathNode(node.m_isMainPathNode), 72 m_formulaWidthBefore(node.m_formulaWidthBefore), 73 m_formulaWidthAfter(node.m_formulaWidthAfter), 74 m_formulaPassmarkLength(node.m_formulaPassmarkLength), 75 m_angleType(node.m_angleType), 76 m_passmarkLineType(node.m_passmarkLineType), 77 m_passmarkAngleType(node.m_passmarkAngleType), 78 m_isShowSecondPassmark(node.m_isShowSecondPassmark), 79 m_checkUniqueness(node.m_checkUniqueness), 80 m_manualPassmarkLength(node.m_manualPassmarkLength) 81 {} 82 83 ~VPieceNodeData() Q_DECL_EQ_DEFAULT; 84 85 friend QDataStream& operator<<(QDataStream& out, const VPieceNodeData& p); 86 friend QDataStream& operator>>(QDataStream& in, VPieceNodeData& p); 87 88 /** @brief id object id. */ 89 quint32 m_id{NULL_ID}; 90 91 /** @brief typeTool type of tool */ 92 Tool m_typeTool{Tool::NodePoint}; 93 94 /** @brief reverse true if need reverse points list for node. */ 95 bool m_reverse{false}; 96 97 /** @brief m_excluded true if item excluded from main path. Excluded item is not visible and also will not has 98 * affect on main path. Also include to exist path items automatically setted excluded. */ 99 bool m_excluded{false}; 100 101 /** @brief m_isPassmark has sense only for points. If true to seam allowance should be added a passmark. */ 102 bool m_isPassmark{false}; 103 104 /** @brief m_isMainPathNode need fin know if allowed for this passmakr to be double. */ 105 bool m_isMainPathNode{true}; 106 107 QString m_formulaWidthBefore{currentSeamAllowance}; 108 QString m_formulaWidthAfter{currentSeamAllowance}; 109 QString m_formulaPassmarkLength{}; 110 111 PieceNodeAngle m_angleType{PieceNodeAngle::ByLength}; 112 113 PassmarkLineType m_passmarkLineType{PassmarkLineType::OneLine}; 114 PassmarkAngleType m_passmarkAngleType{PassmarkAngleType::Straightforward}; 115 116 bool m_isShowSecondPassmark{true}; 117 118 /** @brief m_checkUniqueness need in cases where different points have the same coordinates, become one point. 119 * By default the check enabled. Disable it only if in a path cannot be used just one point. For example if 120 * gradation change a piece shape and the seond point should be remaind.*/ 121 bool m_checkUniqueness{true}; 122 123 bool m_manualPassmarkLength{false}; 124 125 private: 126 Q_DISABLE_ASSIGN(VPieceNodeData) 127 128 static const quint32 streamHeader; 129 static const quint16 classVersion; 130 }; 131 132 // Friend functions 133 //--------------------------------------------------------------------------------------------------------------------- 134 QDataStream &operator<<(QDataStream &out, const VPieceNodeData &p) 135 { 136 out << VPieceNodeData::streamHeader << VPieceNodeData::classVersion; 137 138 // Added in classVersion = 1 139 out << p.m_id 140 << p.m_typeTool 141 << p.m_reverse 142 << p.m_excluded 143 << p.m_isPassmark 144 << p.m_formulaWidthBefore 145 << p.m_formulaWidthAfter 146 << p.m_formulaPassmarkLength 147 << p.m_angleType 148 << p.m_passmarkLineType 149 << p.m_passmarkAngleType 150 << p.m_isShowSecondPassmark 151 << p.m_checkUniqueness 152 << p.m_manualPassmarkLength; 153 154 // Added in classVersion = 2 155 156 return out; 157 } 158 159 //--------------------------------------------------------------------------------------------------------------------- 160 QDataStream &operator>>(QDataStream &in, VPieceNodeData &p) 161 { 162 quint32 actualStreamHeader = 0; 163 in >> actualStreamHeader; 164 165 if (actualStreamHeader != VPieceNodeData::streamHeader) 166 { 167 QString message = QCoreApplication::tr("VPieceNodeData prefix mismatch error: actualStreamHeader = 0x%1 " 168 "and streamHeader = 0x%2") 169 .arg(actualStreamHeader, 8, 0x10, QChar('0')) 170 .arg(VPieceNodeData::streamHeader, 8, 0x10, QChar('0')); 171 throw VException(message); 172 } 173 174 quint16 actualClassVersion = 0; 175 in >> actualClassVersion; 176 177 if (actualClassVersion > VPieceNodeData::classVersion) 178 { 179 QString message = QCoreApplication::tr("VPieceNodeData compatibility error: actualClassVersion = %1 and " 180 "classVersion = %2") 181 .arg(actualClassVersion).arg(VPieceNodeData::classVersion); 182 throw VException(message); 183 } 184 185 in >> p.m_id 186 >> p.m_typeTool 187 >> p.m_reverse 188 >> p.m_excluded 189 >> p.m_isPassmark 190 >> p.m_formulaWidthBefore 191 >> p.m_formulaWidthAfter 192 >> p.m_formulaPassmarkLength 193 >> p.m_angleType 194 >> p.m_passmarkLineType 195 >> p.m_passmarkAngleType 196 >> p.m_isShowSecondPassmark 197 >> p.m_checkUniqueness 198 >> p.m_manualPassmarkLength; 199 200 // if (actualClassVersion >= 2) 201 // { 202 203 // } 204 205 return in; 206 } 207 208 QT_WARNING_POP 209 210 #endif // VPIECENODE_P_H 211 212