| 29 #include "triangle.h" |
29 #include "triangle.h" |
| 30 #include "quadrilateral.h" |
30 #include "quadrilateral.h" |
| 31 #include "conditionaledge.h" |
31 #include "conditionaledge.h" |
| 32 #include "comment.h" |
32 #include "comment.h" |
| 33 #include "empty.h" |
33 #include "empty.h" |
| |
34 #include "cylinder.h" |
| 34 |
35 |
| 35 // List of all LDObjects |
36 // List of all LDObjects |
| 36 QMap<qint32, LDObject*> g_allObjects; |
37 QMap<qint32, LDObject*> g_allObjects; |
| 37 |
38 |
| 38 enum { MAX_LDOBJECT_IDS = (1 << 24) }; |
39 enum { MAX_LDOBJECT_IDS = (1 << 24) }; |
| 144 |
145 |
| 145 if (obj->color() == MainColor) |
146 if (obj->color() == MainColor) |
| 146 obj->setColor (parentcolor); |
147 obj->setColor (parentcolor); |
| 147 } |
148 } |
| 148 |
149 |
| 149 bool shouldInvert(LDSubfileReference* reference, Winding winding, DocumentManager* context) |
150 /* |
| |
151 * Returns whether or not a compound object should be inverted. |
| |
152 */ |
| |
153 bool LDMatrixObject::shouldInvert(Winding winding, DocumentManager* context) |
| 150 { |
154 { |
| 151 bool result = false; |
155 bool result = false; |
| 152 result ^= (reference->isInverted()); |
156 result ^= (isInverted()); |
| 153 result ^= (reference->transformationMatrix().determinant() < 0); |
157 result ^= (transformationMatrix().determinant() < 0); |
| 154 result ^= (reference->fileInfo(context)->winding() != winding); |
158 result ^= (nativeWinding(context) != winding); |
| 155 return result; |
159 return result; |
| 156 } |
160 } |
| 157 |
161 |
| |
162 /* |
| |
163 * The winding used by the object's geometry. By default it's CCW but some documents referenced by |
| |
164 * a subfile reference may use CW geometry. |
| |
165 * |
| |
166 * Since the native winding of a subfile reference depends on the actual document it references, |
| |
167 * determining the winding requires the libraries for reference. |
| |
168 */ |
| |
169 Winding LDObject::nativeWinding(DocumentManager* /*context*/) const |
| |
170 { |
| |
171 return CounterClockwise; |
| |
172 } |
| |
173 |
| |
174 /* |
| |
175 * Reimplementation of LDObject::nativeWinding for subfile references |
| |
176 */ |
| |
177 Winding LDSubfileReference::nativeWinding(DocumentManager* context) const |
| |
178 { |
| |
179 return fileInfo(context)->winding(); |
| |
180 } |
| |
181 |
| 158 // ============================================================================= |
182 // ============================================================================= |
| 159 // ----------------------------------------------------------------------------- |
183 // ----------------------------------------------------------------------------- |
| 160 void LDSubfileReference::inlineContents( |
184 void LDSubfileReference::rasterize( |
| 161 DocumentManager* context, |
185 DocumentManager* context, |
| 162 Winding parentWinding, |
186 Winding parentWinding, |
| 163 Model& model, |
187 Model& model, |
| 164 bool deep, |
188 bool deep, |
| 165 bool render |
189 bool render |
| 172 subfile->inlineContents(inlined, deep, render); |
196 subfile->inlineContents(inlined, deep, render); |
| 173 |
197 |
| 174 // Transform the objects |
198 // Transform the objects |
| 175 for (LDObject* object : inlined) |
199 for (LDObject* object : inlined) |
| 176 { |
200 { |
| 177 if (::shouldInvert(this, parentWinding, context)) |
201 if (shouldInvert(parentWinding, context)) |
| 178 ::invert(object, context); |
202 ::invert(object, context); |
| 179 |
203 |
| 180 TransformObject(object, transformationMatrix(), position(), color()); |
204 TransformObject(object, transformationMatrix(), position(), color()); |
| 181 } |
205 } |
| 182 |
206 |
| 228 return false; |
252 return false; |
| 229 } |
253 } |
| 230 |
254 |
| 231 // ============================================================================= |
255 // ============================================================================= |
| 232 // |
256 // |
| 233 QList<LDPolygon> LDSubfileReference::inlinePolygons(DocumentManager* context, Winding parentWinding) |
257 QVector<LDPolygon> LDSubfileReference::rasterizePolygons(DocumentManager* context, Winding parentWinding) |
| 234 { |
258 { |
| 235 LDDocument* file = fileInfo(context); |
259 LDDocument* file = fileInfo(context); |
| 236 |
260 |
| 237 if (file) |
261 if (file) |
| 238 { |
262 { |
| 239 QList<LDPolygon> data = fileInfo(context)->inlinePolygons(); |
263 QVector<LDPolygon> data = fileInfo(context)->inlinePolygons(); |
| 240 |
264 |
| 241 for (LDPolygon& entry : data) |
265 for (LDPolygon& entry : data) |
| 242 { |
266 { |
| 243 for (int i = 0; i < entry.numVertices(); ++i) |
267 for (int i = 0; i < entry.numVertices(); ++i) |
| 244 entry.vertices[i].transform (transformationMatrix(), position()); |
268 entry.vertices[i].transform (transformationMatrix(), position()); |
| 245 |
269 |
| 246 if (::shouldInvert(this, parentWinding, context)) |
270 if (shouldInvert(parentWinding, context)) |
| 247 ::invertPolygon(entry); |
271 ::invertPolygon(entry); |
| 248 } |
272 } |
| 249 |
273 |
| 250 return data; |
274 return data; |
| 251 } |
275 } |
| 329 case LDObjectType::Empty: |
353 case LDObjectType::Empty: |
| 330 return new LDEmpty {}; |
354 return new LDEmpty {}; |
| 331 |
355 |
| 332 case LDObjectType::BezierCurve: |
356 case LDObjectType::BezierCurve: |
| 333 return new LDBezierCurve {}; |
357 return new LDBezierCurve {}; |
| |
358 |
| |
359 case LDObjectType::Cylinder: |
| |
360 return new LDCylinder {}; |
| 334 |
361 |
| 335 case LDObjectType::_End: |
362 case LDObjectType::_End: |
| 336 break; |
363 break; |
| 337 } |
364 } |
| 338 |
365 |