Line data Source code
1 : /*******************************************************************************
2 : * Project: libopencad
3 : * Purpose: OpenSource CAD formats support library
4 : * Author: Alexandr Borzykh, mush3d at gmail.com
5 : * Author: Dmitry Baryshnikov, bishop.dev@gmail.com
6 : * Language: C++
7 : *******************************************************************************
8 : * The MIT License (MIT)
9 : *
10 : * Copyright (c) 2016 Alexandr Borzykh
11 : * Copyright (c) 2016 NextGIS, <info@nextgis.com>
12 : *
13 : * SPDX-License-Identifier: MIT
14 : *******************************************************************************/
15 : #include "cadgeometry.h"
16 :
17 : #include <cmath>
18 : #include <iostream>
19 :
20 : using namespace std;
21 :
22 : //------------------------------------------------------------------------------
23 : // CADGeometry
24 : //------------------------------------------------------------------------------
25 :
26 0 : void Matrix::translate( const CADVector& vector )
27 : {
28 0 : double a00 = matrix[0];
29 0 : double a01 = matrix[1];
30 0 : double a02 = matrix[2];
31 0 : double a10 = matrix[3];
32 0 : double a11 = matrix[4];
33 0 : double a12 = matrix[5];
34 0 : double a20 = matrix[6];
35 0 : double a21 = matrix[7];
36 0 : double a22 = matrix[8];
37 :
38 0 : matrix[6] = vector.getX() * a00 + vector.getY() * a10 + a20;
39 0 : matrix[7] = vector.getX() * a01 + vector.getY() * a11 + a21;
40 0 : matrix[8] = vector.getX() * a02 + vector.getY() * a12 + a22;
41 0 : }
42 :
43 0 : void Matrix::rotate( double rotation )
44 : {
45 0 : const double s = sin( rotation );
46 0 : const double c = cos( rotation );
47 0 : double a00 = matrix[0];
48 0 : double a01 = matrix[1];
49 0 : double a02 = matrix[2];
50 0 : double a10 = matrix[3];
51 0 : double a11 = matrix[4];
52 0 : double a12 = matrix[5];
53 :
54 0 : matrix[0] = c * a00 + s * a10;
55 0 : matrix[1] = c * a01 + s * a11;
56 0 : matrix[2] = c * a02 + s * a12;
57 :
58 0 : matrix[3] = c * a10 - s * a00;
59 0 : matrix[4] = c * a11 - s * a01;
60 0 : matrix[5] = c * a12 - s * a02;
61 0 : }
62 :
63 0 : void Matrix::scale( const CADVector& vector )
64 : {
65 0 : matrix[0] *= vector.getX();
66 0 : matrix[1] *= vector.getX();
67 0 : matrix[2] *= vector.getX();
68 0 : matrix[3] *= vector.getY();
69 0 : matrix[4] *= vector.getY();
70 0 : matrix[5] *= vector.getY();
71 0 : }
72 :
73 0 : CADVector Matrix::multiply( const CADVector& vector ) const
74 : {
75 0 : CADVector out;
76 0 : out.setX( vector.getX() * matrix[0] + vector.getY() * matrix[1] + vector.getZ() * matrix[2] );
77 0 : out.setY( vector.getX() * matrix[3] + vector.getY() * matrix[4] + vector.getZ() * matrix[5] );
78 0 : out.setZ( vector.getX() * matrix[6] + vector.getY() * matrix[7] + vector.getZ() * matrix[8] );
79 0 : return out;
80 : }
81 :
82 : //------------------------------------------------------------------------------
83 : // CADGeometry
84 : //------------------------------------------------------------------------------
85 :
86 19 : CADGeometry::CADGeometry() :
87 : geometryType( UNDEFINED ),
88 19 : m_thickness( 0 )
89 : {
90 19 : geometry_color.R = 0;
91 19 : geometry_color.G = 0;
92 19 : geometry_color.B = 0;
93 19 : }
94 :
95 27 : CADGeometry::~CADGeometry()
96 : {
97 :
98 27 : }
99 :
100 13 : CADGeometry::GeometryType CADGeometry::getType() const
101 : {
102 13 : return geometryType;
103 : }
104 :
105 13 : double CADGeometry::getThickness() const
106 : {
107 13 : return m_thickness;
108 : }
109 :
110 13 : void CADGeometry::setThickness( double thickness )
111 : {
112 13 : m_thickness = thickness;
113 13 : }
114 :
115 13 : RGBColor CADGeometry::getColor() const
116 : {
117 13 : return geometry_color;
118 : }
119 :
120 17 : void CADGeometry::setColor( RGBColor color )
121 : {
122 17 : geometry_color = color;
123 17 : }
124 :
125 16 : vector<string> CADGeometry::getEED() const
126 : {
127 16 : return asEED;
128 : }
129 :
130 17 : void CADGeometry::setEED( const vector<string>& eed )
131 : {
132 17 : asEED = eed;
133 17 : }
134 :
135 13 : vector<CADAttrib> CADGeometry::getBlockAttributes() const
136 : {
137 13 : return blockAttributes;
138 : }
139 :
140 0 : void CADGeometry::setBlockAttributes( const vector<CADAttrib>& data )
141 : {
142 0 : blockAttributes = data;
143 0 : }
144 :
145 : //------------------------------------------------------------------------------
146 : // CADUnknown
147 : //------------------------------------------------------------------------------
148 0 : CADUnknown::CADUnknown()
149 : {
150 0 : }
151 :
152 0 : void CADUnknown::transform( const Matrix& /*matrix*/)
153 : {
154 0 : }
155 :
156 0 : void CADUnknown::print() const
157 : {
158 0 : cout << "|---------Unhandled---------|\n\n";
159 0 : }
160 :
161 : //------------------------------------------------------------------------------
162 : // CADPoint3D
163 : //------------------------------------------------------------------------------
164 :
165 16 : CADPoint3D::CADPoint3D() :
166 16 : xAxisAng( 0.0 )
167 : {
168 16 : geometryType = CADGeometry::POINT;
169 16 : }
170 :
171 2 : CADPoint3D::CADPoint3D( const CADVector& positionIn, double thicknessIn ) :
172 : position( positionIn),
173 2 : xAxisAng( 0.0 )
174 : {
175 2 : m_thickness = thicknessIn;
176 2 : geometryType = CADGeometry::POINT;
177 2 : }
178 :
179 32 : CADVector CADPoint3D::getPosition() const
180 : {
181 32 : return position;
182 : }
183 :
184 16 : void CADPoint3D::setPosition( const CADVector& value )
185 : {
186 16 : position = value;
187 16 : }
188 :
189 0 : CADVector CADPoint3D::getExtrusion() const
190 : {
191 0 : return extrusion;
192 : }
193 :
194 11 : void CADPoint3D::setExtrusion( const CADVector& value )
195 : {
196 11 : extrusion = value;
197 11 : }
198 :
199 0 : double CADPoint3D::getXAxisAng() const
200 : {
201 0 : return xAxisAng;
202 : }
203 :
204 3 : void CADPoint3D::setXAxisAng( double value )
205 : {
206 3 : xAxisAng = value;
207 3 : }
208 :
209 0 : void CADPoint3D::print() const
210 : {
211 : cout << "|---------Point---------|\n" <<
212 0 : "Position: \t" << position.getX() <<
213 0 : "\t" << position.getY() <<
214 0 : "\t" << position.getZ() << "\n\n";
215 0 : }
216 :
217 0 : void CADPoint3D::transform( const Matrix& matrix )
218 : {
219 0 : position = matrix.multiply( position );
220 0 : }
221 :
222 : //------------------------------------------------------------------------------
223 : // CADLine
224 : //------------------------------------------------------------------------------
225 :
226 0 : CADLine::CADLine()
227 : {
228 0 : geometryType = CADGeometry::LINE;
229 0 : }
230 :
231 1 : CADLine::CADLine( const CADPoint3D& startIn, const CADPoint3D& endIn ) :
232 : start( startIn ),
233 1 : end( endIn )
234 : {
235 1 : geometryType = CADGeometry::LINE;
236 1 : }
237 :
238 3 : CADPoint3D CADLine::getStart() const
239 : {
240 3 : return start;
241 : }
242 :
243 0 : void CADLine::setStart( const CADPoint3D& value )
244 : {
245 0 : start = value;
246 0 : }
247 :
248 3 : CADPoint3D CADLine::getEnd() const
249 : {
250 3 : return end;
251 : }
252 :
253 0 : void CADLine::setEnd( const CADPoint3D& value )
254 : {
255 0 : end = value;
256 0 : }
257 :
258 0 : void CADLine::print() const
259 : {
260 : cout << "|---------Line---------|\n" <<
261 0 : "Start Position: \t" << start.getPosition().getX() <<
262 0 : "\t" << start.getPosition().getY() <<
263 0 : "\t" << start.getPosition().getZ() << "\n" <<
264 0 : "End Position: \t" << end.getPosition().getX() <<
265 0 : "\t" << end.getPosition().getY() <<
266 0 : "\t" << end.getPosition().getZ() << "\n\n";
267 0 : }
268 :
269 0 : void CADLine::transform( const Matrix& matrix )
270 : {
271 0 : start.transform( matrix );
272 0 : end.transform( matrix );
273 0 : }
274 :
275 : //------------------------------------------------------------------------------
276 : // CADCircle
277 : //------------------------------------------------------------------------------
278 :
279 4 : CADCircle::CADCircle() : radius( 0.0f )
280 : {
281 4 : geometryType = CADGeometry::CIRCLE;
282 4 : }
283 :
284 12 : double CADCircle::getRadius() const
285 : {
286 12 : return radius;
287 : }
288 :
289 3 : void CADCircle::setRadius( double value )
290 : {
291 3 : radius = value;
292 3 : }
293 :
294 0 : void CADCircle::print() const
295 : {
296 : cout << "|---------Circle---------|\n" <<
297 0 : "Position: \t" << position.getX() <<
298 0 : "\t" << position.getY() <<
299 0 : "\t" << position.getZ() << "\n" <<
300 0 : "Radius: " << radius << "\n\n";
301 0 : }
302 :
303 : //------------------------------------------------------------------------------
304 : // CADArc
305 : //------------------------------------------------------------------------------
306 :
307 1 : CADArc::CADArc() : CADCircle(),
308 : startingAngle( 0.0f ),
309 1 : endingAngle( 0.0f )
310 : {
311 1 : geometryType = CADGeometry::ARC;
312 1 : }
313 :
314 1 : double CADArc::getStartingAngle() const
315 : {
316 1 : return startingAngle;
317 : }
318 :
319 1 : void CADArc::setStartingAngle( double value )
320 : {
321 1 : startingAngle = value;
322 1 : }
323 :
324 1 : double CADArc::getEndingAngle() const
325 : {
326 1 : return endingAngle;
327 : }
328 :
329 1 : void CADArc::setEndingAngle( double value )
330 : {
331 1 : endingAngle = value;
332 1 : }
333 :
334 0 : void CADArc::print() const
335 : {
336 : cout << "|---------Arc---------|\n" <<
337 0 : "Position: \t" << position.getX() <<
338 0 : "\t" << position.getY() <<
339 0 : "\t" << position.getZ() << "\n" <<
340 0 : "Radius: \t" << radius << "\n" <<
341 0 : "Beg & End angles: \t" << startingAngle <<
342 0 : "\t" << endingAngle << "\n\n";
343 0 : }
344 :
345 : //------------------------------------------------------------------------------
346 : // CADPolyline3D
347 : //------------------------------------------------------------------------------
348 :
349 0 : CADPolyline3D::CADPolyline3D()
350 : {
351 0 : geometryType = CADGeometry::POLYLINE3D;
352 0 : }
353 :
354 0 : void CADPolyline3D::addVertex( const CADVector& vertex )
355 : {
356 0 : vertices.push_back( vertex );
357 0 : }
358 :
359 0 : size_t CADPolyline3D::getVertexCount() const
360 : {
361 0 : return vertices.size();
362 : }
363 :
364 0 : CADVector& CADPolyline3D::getVertex( size_t index )
365 : {
366 0 : return vertices[index];
367 : }
368 :
369 0 : void CADPolyline3D::print() const
370 : {
371 0 : cout << "|------Polyline3D-----|\n";
372 0 : for( size_t i = 0; i < vertices.size(); ++i )
373 : {
374 0 : cout << " #" << i <<
375 0 : ". X: " << vertices[i].getX() <<
376 0 : ", Y: " << vertices[i].getY() << "\n";
377 : }
378 0 : cout << "\n";
379 0 : }
380 :
381 0 : void CADPolyline3D::transform( const Matrix& matrix )
382 : {
383 0 : for( CADVector& vertex : vertices )
384 : {
385 0 : vertex = matrix.multiply( vertex );
386 : }
387 0 : }
388 :
389 : //------------------------------------------------------------------------------
390 : // CADLWPolyline
391 : //------------------------------------------------------------------------------
392 :
393 0 : CADLWPolyline::CADLWPolyline() :
394 : bClosed( false ),
395 : constWidth( 0.0 ),
396 0 : elevation( 0.0 )
397 : {
398 0 : geometryType = CADGeometry::LWPOLYLINE;
399 0 : }
400 :
401 0 : void CADLWPolyline::print() const
402 : {
403 0 : cout << "|------LWPolyline-----|\n";
404 0 : for( size_t i = 0; i < vertices.size(); ++i )
405 : {
406 0 : cout << " #" << i <<
407 0 : ". X: " << vertices[i].getX() <<
408 0 : ", Y: " << vertices[i].getY() << "\n";
409 : }
410 0 : cout << "\n";
411 0 : }
412 :
413 0 : double CADLWPolyline::getConstWidth() const
414 : {
415 0 : return constWidth;
416 : }
417 :
418 0 : void CADLWPolyline::setConstWidth( double value )
419 : {
420 0 : constWidth = value;
421 0 : }
422 :
423 0 : double CADLWPolyline::getElevation() const
424 : {
425 0 : return elevation;
426 : }
427 :
428 0 : void CADLWPolyline::setElevation( double value )
429 : {
430 0 : elevation = value;
431 0 : }
432 :
433 0 : CADVector CADLWPolyline::getVectExtrusion() const
434 : {
435 0 : return vectExtrusion;
436 : }
437 :
438 0 : void CADLWPolyline::setVectExtrusion( const CADVector& value )
439 : {
440 0 : vectExtrusion = value;
441 0 : }
442 :
443 0 : vector<pair<double, double> > CADLWPolyline::getWidths() const
444 : {
445 0 : return widths;
446 : }
447 :
448 0 : void CADLWPolyline::setWidths( const vector<pair<double, double> >& value )
449 : {
450 0 : widths = value;
451 0 : }
452 :
453 0 : vector<double> CADLWPolyline::getBulges() const
454 : {
455 0 : return bulges;
456 : }
457 :
458 0 : void CADLWPolyline::setBulges( const vector<double>& value )
459 : {
460 0 : bulges = value;
461 0 : }
462 :
463 0 : bool CADLWPolyline::isClosed() const
464 : {
465 0 : return bClosed;
466 : }
467 :
468 0 : void CADLWPolyline::setClosed( bool state )
469 : {
470 0 : bClosed = state;
471 0 : }
472 :
473 : //------------------------------------------------------------------------------
474 : // CADEllipse
475 : //------------------------------------------------------------------------------
476 :
477 1 : CADEllipse::CADEllipse() : CADArc(),
478 1 : axisRatio( 0.0f )
479 : {
480 1 : geometryType = CADGeometry::ELLIPSE;
481 1 : }
482 :
483 1 : double CADEllipse::getAxisRatio() const
484 : {
485 1 : return axisRatio;
486 : }
487 :
488 1 : void CADEllipse::setAxisRatio( double value )
489 : {
490 1 : axisRatio = value;
491 1 : }
492 :
493 1 : CADVector CADEllipse::getSMAxis()
494 : {
495 1 : return vectSMAxis;
496 : }
497 :
498 1 : void CADEllipse::setSMAxis( const CADVector& SMAxisVect )
499 : {
500 1 : vectSMAxis = SMAxisVect;
501 1 : }
502 :
503 0 : void CADEllipse::print() const
504 : {
505 : cout << "|---------Ellipse---------|\n" <<
506 0 : "Position: \t" << position.getX() <<
507 0 : "\t" << position.getY() <<
508 0 : "\t" << position.getZ() << "\n" <<
509 0 : "Beg & End angles: \t" << startingAngle <<
510 0 : "\t" << endingAngle << "\n\n";
511 0 : }
512 :
513 : //------------------------------------------------------------------------------
514 : // CADText
515 : //------------------------------------------------------------------------------
516 :
517 11 : CADText::CADText() : CADPoint3D(),
518 : obliqueAngle( 0 ),
519 : rotationAngle( 0 ),
520 11 : height( 0 )
521 : {
522 11 : geometryType = CADGeometry::TEXT;
523 11 : }
524 :
525 6 : string CADText::getTextValue() const
526 : {
527 6 : return textValue;
528 : }
529 :
530 11 : void CADText::setTextValue( const string& value )
531 : {
532 11 : textValue = value;
533 11 : }
534 :
535 0 : double CADText::getHeight() const
536 : {
537 0 : return height;
538 : }
539 :
540 11 : void CADText::setHeight( double value )
541 : {
542 11 : height = value;
543 11 : }
544 :
545 0 : double CADText::getRotationAngle() const
546 : {
547 0 : return rotationAngle;
548 : }
549 :
550 9 : void CADText::setRotationAngle( double value )
551 : {
552 9 : rotationAngle = value;
553 9 : }
554 :
555 0 : double CADText::getObliqueAngle() const
556 : {
557 0 : return obliqueAngle;
558 : }
559 :
560 9 : void CADText::setObliqueAngle( double value )
561 : {
562 9 : obliqueAngle = value;
563 9 : }
564 :
565 0 : void CADText::print() const
566 : {
567 : cout << "|---------Text---------|\n" <<
568 0 : "Position: \t" << position.getX() <<
569 0 : "\t" << position.getY() << "\n" <<
570 0 : "Text value: \t" << textValue << "\n\n";
571 0 : }
572 :
573 : //------------------------------------------------------------------------------
574 : // CADRay
575 : //------------------------------------------------------------------------------
576 :
577 0 : CADRay::CADRay() : CADPoint3D()
578 : {
579 0 : geometryType = CADGeometry::RAY;
580 0 : }
581 :
582 0 : CADVector CADRay::getVectVector() const
583 : {
584 0 : return extrusion;
585 : }
586 :
587 0 : void CADRay::setVectVector( const CADVector& value )
588 : {
589 0 : extrusion = value;
590 0 : }
591 :
592 0 : void CADRay::print() const
593 : {
594 : cout << "|---------Ray---------|\n" <<
595 0 : "Position: \t" << position.getX() <<
596 0 : "\t" << position.getY() << "\n" <<
597 0 : "Vector: \t" << extrusion.getX() <<
598 0 : "\t" << extrusion.getY() << "\n\n";
599 0 : }
600 :
601 : //------------------------------------------------------------------------------
602 : // CADHatch
603 : //------------------------------------------------------------------------------
604 :
605 0 : CADHatch::CADHatch()
606 : {
607 0 : geometryType = CADGeometry::HATCH;
608 0 : }
609 :
610 : CADHatch::~CADHatch() = default;
611 :
612 : //------------------------------------------------------------------------------
613 : // CADSpline
614 : //------------------------------------------------------------------------------
615 :
616 0 : CADSpline::CADSpline() :
617 : scenario( 0 ),
618 : rational( false ),
619 : closed( false ),
620 : weight( false ),
621 : fitTolerance( 0.0 ),
622 0 : degree( 0 )
623 : {
624 0 : geometryType = CADGeometry::SPLINE;
625 0 : }
626 :
627 0 : void CADSpline::print() const
628 : {
629 :
630 : cout << "|---------Spline---------|\n" <<
631 0 : "Is rational: \t" << rational << "\n" <<
632 0 : "Is closed: \t" << closed << "\n" <<
633 0 : "Control pts count: " << avertCtrlPoints.size() << "\n";
634 0 : for( size_t j = 0; j < avertCtrlPoints.size(); ++j )
635 : {
636 0 : cout << " #" << j << ".\t" << avertCtrlPoints[j].getX() <<
637 0 : "\t" << avertCtrlPoints[j].getY() <<
638 0 : "\t" << avertCtrlPoints[j].getZ() << "\t";
639 0 : if( weight == true )
640 0 : cout << ctrlPointsWeight[j] << "\n";
641 : else
642 0 : cout << "\n";
643 : }
644 :
645 0 : cout << "Fit pts count: " << averFitPoints.size() << "\n";
646 0 : for( size_t j = 0; j < averFitPoints.size(); ++j )
647 : {
648 0 : cout << " #" << j << ".\t" << averFitPoints[j].getX() <<
649 0 : "\t" << averFitPoints[j].getY() <<
650 0 : "\t" << averFitPoints[j].getZ() << "\n";
651 : }
652 0 : cout << "\n";
653 0 : }
654 :
655 0 : void CADSpline::transform( const Matrix& matrix )
656 : {
657 0 : for( CADVector& pt : avertCtrlPoints )
658 0 : pt = matrix.multiply( pt );
659 0 : for( CADVector& pt : averFitPoints )
660 0 : pt = matrix.multiply( pt );
661 0 : }
662 :
663 0 : long CADSpline::getScenario() const
664 : {
665 0 : return scenario;
666 : }
667 :
668 0 : void CADSpline::setScenario( long value )
669 : {
670 0 : scenario = value;
671 0 : }
672 :
673 0 : bool CADSpline::isRational() const
674 : {
675 0 : return rational;
676 : }
677 :
678 0 : void CADSpline::setRational( bool value )
679 : {
680 0 : rational = value;
681 0 : }
682 :
683 0 : bool CADSpline::isClosed() const
684 : {
685 0 : return closed;
686 : }
687 :
688 0 : void CADSpline::setClosed( bool value )
689 : {
690 0 : closed = value;
691 0 : }
692 :
693 0 : void CADSpline::addControlPointsWeight( double p_weight )
694 : {
695 0 : ctrlPointsWeight.push_back( p_weight );
696 0 : }
697 :
698 0 : void CADSpline::addControlPoint( const CADVector& point )
699 : {
700 0 : avertCtrlPoints.push_back( point );
701 0 : }
702 :
703 0 : void CADSpline::addFitPoint( const CADVector& point )
704 : {
705 0 : averFitPoints.push_back( point );
706 0 : }
707 :
708 0 : bool CADSpline::getWeight() const
709 : {
710 0 : return weight;
711 : }
712 :
713 0 : void CADSpline::setWeight( bool value )
714 : {
715 0 : weight = value;
716 0 : }
717 :
718 0 : double CADSpline::getFitTolerance() const
719 : {
720 0 : return fitTolerance;
721 : }
722 :
723 0 : void CADSpline::setFitTolerance( double value )
724 : {
725 0 : fitTolerance = value;
726 0 : }
727 :
728 0 : long CADSpline::getDegree() const
729 : {
730 0 : return degree;
731 : }
732 :
733 0 : void CADSpline::setDegree( long value )
734 : {
735 0 : degree = value;
736 0 : }
737 :
738 0 : vector<CADVector>& CADSpline::getControlPoints()
739 : {
740 0 : return avertCtrlPoints;
741 : }
742 :
743 0 : vector<CADVector>& CADSpline::getFitPoints()
744 : {
745 0 : return averFitPoints;
746 : }
747 :
748 0 : vector<double>& CADSpline::getControlPointsWeights()
749 : {
750 0 : return ctrlPointsWeight;
751 : }
752 :
753 : //------------------------------------------------------------------------------
754 : // CADSolid
755 : //------------------------------------------------------------------------------
756 :
757 0 : CADSolid::CADSolid() :
758 0 : elevation( 0.0 )
759 : {
760 0 : geometryType = CADGeometry::SOLID;
761 0 : }
762 :
763 0 : void CADSolid::print() const
764 : {
765 0 : cout << "|---------Solid---------|\n";
766 0 : for( size_t i = 0; i < avertCorners.size(); ++i )
767 : {
768 0 : cout << " #" << i << ".\t" << avertCorners[i].getX() <<
769 0 : "\t" << avertCorners[i].getY() << "\n" <<
770 0 : "Elevation: " << elevation << "\n";
771 : }
772 0 : cout << "\n";
773 0 : }
774 :
775 0 : void CADSolid::transform( const Matrix& matrix )
776 : {
777 0 : CADPoint3D::transform( matrix );
778 0 : for( CADVector& corner : avertCorners )
779 0 : corner = matrix.multiply( corner );
780 0 : }
781 :
782 0 : double CADSolid::getElevation() const
783 : {
784 0 : return elevation;
785 : }
786 :
787 0 : void CADSolid::setElevation( double value )
788 : {
789 0 : elevation = value;
790 0 : }
791 :
792 0 : void CADSolid::addCorner( const CADVector& corner )
793 : {
794 0 : avertCorners.push_back( corner );
795 0 : }
796 :
797 0 : vector<CADVector> CADSolid::getCorners()
798 : {
799 0 : return avertCorners;
800 : }
801 :
802 : //------------------------------------------------------------------------------
803 : // CADImage
804 : //------------------------------------------------------------------------------
805 :
806 0 : CADImage::CADImage() :
807 : bTransparency( false ),
808 : bClipping( false ),
809 : dBrightness( 0 ),
810 : dContrast( 0 ),
811 : resolutionUnits( NONE ),
812 0 : clippingBoundaryType( 0 )
813 : {
814 0 : geometryType = CADGeometry::IMAGE;
815 0 : }
816 :
817 0 : CADVector CADImage::getVertInsertionPoint() const
818 : {
819 0 : return vertInsertionPoint;
820 : }
821 :
822 0 : void CADImage::setVertInsertionPoint( const CADVector& value )
823 : {
824 0 : vertInsertionPoint = value;
825 0 : }
826 :
827 0 : CADVector CADImage::getImageSize() const
828 : {
829 0 : return imageSize;
830 : }
831 :
832 0 : void CADImage::setImageSize( const CADVector& value )
833 : {
834 0 : imageSize = value;
835 0 : }
836 :
837 0 : CADVector CADImage::getImageSizeInPx() const
838 : {
839 0 : return imageSizeInPx;
840 : }
841 :
842 0 : void CADImage::setImageSizeInPx( const CADVector& value )
843 : {
844 0 : imageSizeInPx = value;
845 0 : }
846 :
847 0 : CADVector CADImage::getPixelSizeInACADUnits() const
848 : {
849 0 : return pixelSizeInACADUnits;
850 : }
851 :
852 0 : void CADImage::setPixelSizeInACADUnits( const CADVector& value )
853 : {
854 0 : pixelSizeInACADUnits = value;
855 0 : }
856 :
857 0 : short CADImage::getClippingBoundaryType() const
858 : {
859 0 : return clippingBoundaryType;
860 : }
861 :
862 0 : void CADImage::setClippingBoundaryType( short value )
863 : {
864 0 : clippingBoundaryType = value;
865 0 : }
866 :
867 0 : enum CADImage::ResolutionUnit CADImage::getResolutionUnits() const
868 : {
869 0 : return resolutionUnits;
870 : }
871 :
872 0 : void CADImage::setResolutionUnits( enum CADImage::ResolutionUnit res_unit )
873 : {
874 0 : resolutionUnits = res_unit;
875 0 : }
876 :
877 0 : string CADImage::getFilePath() const
878 : {
879 0 : return filePath;
880 : }
881 :
882 0 : void CADImage::setFilePath( const string& value )
883 : {
884 0 : filePath = value;
885 0 : }
886 :
887 0 : void CADImage::setOptions( bool transparency, bool clip, unsigned char brightness,
888 : unsigned char contrast )
889 : {
890 0 : bTransparency = transparency;
891 0 : bClipping = clip;
892 0 : dBrightness = brightness;
893 0 : dContrast = contrast;
894 0 : }
895 :
896 0 : void CADImage::print() const
897 : {
898 : cout << "|---------Image---------|\n" <<
899 0 : "Filepath: " << filePath << "\n" <<
900 0 : "Insertion point: " << vertInsertionPoint.getX() << "\t" <<
901 0 : vertInsertionPoint.getY() << "\n" <<
902 0 : "Transparent? : " << bTransparency << "\n" <<
903 0 : "Brightness (0-100) : " << dBrightness << "\n" <<
904 0 : "Contrast (0-100) : " << dContrast << "\n" <<
905 0 : "Clipping polygon:" << endl;
906 0 : for( size_t i = 0; i < avertClippingPolygon.size(); ++i )
907 : {
908 0 : cout << " #" << i << ". X: " << avertClippingPolygon[i].getX() <<
909 0 : ", Y: " << avertClippingPolygon[i].getY() << "\n";
910 : }
911 0 : cout << "\n";
912 0 : }
913 :
914 0 : void CADImage::transform( const Matrix& matrix )
915 : {
916 0 : vertInsertionPoint = matrix.multiply( vertInsertionPoint );
917 0 : for( CADVector& pt : avertClippingPolygon )
918 0 : pt = matrix.multiply( pt );
919 0 : }
920 :
921 0 : void CADImage::addClippingPoint( const CADVector& pt )
922 : {
923 0 : avertClippingPolygon.push_back( pt );
924 0 : }
925 :
926 : //------------------------------------------------------------------------------
927 : // CADMText
928 : //------------------------------------------------------------------------------
929 :
930 2 : CADMText::CADMText() :
931 : rectWidth( 0.0 ),
932 : extents( 0.0 ),
933 2 : extentsWidth( 0.0 )
934 : {
935 2 : geometryType = CADGeometry::MTEXT;
936 2 : }
937 :
938 0 : double CADMText::getRectWidth() const
939 : {
940 0 : return rectWidth;
941 : }
942 :
943 2 : void CADMText::setRectWidth( double value )
944 : {
945 2 : rectWidth = value;
946 2 : }
947 :
948 0 : double CADMText::getExtents() const
949 : {
950 0 : return extents;
951 : }
952 :
953 2 : void CADMText::setExtents( double value )
954 : {
955 2 : extents = value;
956 2 : }
957 :
958 0 : double CADMText::getExtentsWidth() const
959 : {
960 0 : return extentsWidth;
961 : }
962 :
963 2 : void CADMText::setExtentsWidth( double value )
964 : {
965 2 : extentsWidth = value;
966 2 : }
967 :
968 0 : void CADMText::print() const
969 : {
970 : cout << "|---------MText---------|\n" <<
971 0 : "Position: " << position.getX() << "\t" <<
972 0 : position.getY() << "\t" <<
973 0 : position.getZ() << "\n" <<
974 0 : "Text: " << textValue << "\n\n";
975 0 : }
976 :
977 : //------------------------------------------------------------------------------
978 : // CADFace3D
979 : //------------------------------------------------------------------------------
980 :
981 0 : CADFace3D::CADFace3D() :
982 0 : invisFlags( 0 )
983 : {
984 0 : geometryType = CADGeometry::FACE3D;
985 0 : }
986 :
987 0 : void CADFace3D::addCorner( const CADVector& corner )
988 : {
989 0 : avertCorners.push_back( corner );
990 0 : }
991 :
992 0 : CADVector CADFace3D::getCorner( size_t index )
993 : {
994 0 : return avertCorners[index];
995 : }
996 :
997 0 : void CADFace3D::print() const
998 : {
999 : cout << "|---------3DFace---------|\n" <<
1000 0 : "Corners: \n";
1001 0 : for( size_t i = 0; i < avertCorners.size(); ++i )
1002 : {
1003 0 : cout << " #" << i << ". X: " << avertCorners[i].getX() << "\t" <<
1004 0 : "Y: " << avertCorners[i].getY() << "\t" <<
1005 0 : "Z: " << avertCorners[i].getZ() << "\n";
1006 : }
1007 0 : cout << "\n";
1008 0 : }
1009 :
1010 0 : void CADFace3D::transform( const Matrix& matrix )
1011 : {
1012 0 : for( CADVector& corner : avertCorners )
1013 : {
1014 0 : corner = matrix.multiply( corner );
1015 : }
1016 0 : }
1017 :
1018 0 : short CADFace3D::getInvisFlags() const
1019 : {
1020 0 : return invisFlags;
1021 : }
1022 :
1023 0 : void CADFace3D::setInvisFlags( short value )
1024 : {
1025 0 : invisFlags = value;
1026 0 : }
1027 :
1028 : //------------------------------------------------------------------------------
1029 : // CADPolylinePFace
1030 : //------------------------------------------------------------------------------
1031 :
1032 0 : CADPolylinePFace::CADPolylinePFace()
1033 : {
1034 0 : geometryType = CADGeometry::POLYLINE_PFACE;
1035 0 : }
1036 :
1037 0 : void CADPolylinePFace::print() const
1038 : {
1039 0 : cout << "|---------PolylinePface---------|\n";
1040 0 : for( size_t i = 0; i < vertices.size(); ++i )
1041 : {
1042 0 : cout << " #" << i << ".\t" << vertices[i].getX() <<
1043 0 : "\t" << vertices[i].getY() <<
1044 0 : "\t" << vertices[i].getZ() << "\n";
1045 : }
1046 0 : cout << "\n";
1047 0 : }
1048 :
1049 0 : void CADPolylinePFace::transform( const Matrix& matrix )
1050 : {
1051 0 : for( CADVector& vertex : vertices )
1052 0 : vertex = matrix.multiply( vertex );
1053 0 : }
1054 :
1055 0 : void CADPolylinePFace::addVertex( const CADVector& vertex )
1056 : {
1057 0 : vertices.push_back( vertex );
1058 0 : }
1059 :
1060 : //------------------------------------------------------------------------------
1061 : // CADXLine
1062 : //------------------------------------------------------------------------------
1063 :
1064 0 : CADXLine::CADXLine()
1065 : {
1066 0 : geometryType = CADGeometry::XLINE;
1067 0 : }
1068 :
1069 0 : void CADXLine::print() const
1070 : {
1071 : cout << "|---------XLine---------|\n" <<
1072 0 : "Position: " << position.getX() << "\t" <<
1073 0 : position.getY() << "\t" <<
1074 0 : position.getZ() << "\n" <<
1075 0 : "Direction: " << extrusion.getX() << "\t" <<
1076 0 : extrusion.getY() << "\t" <<
1077 0 : extrusion.getZ() << "\n\n";
1078 0 : }
1079 :
1080 : //------------------------------------------------------------------------------
1081 : // CADMLine
1082 : //------------------------------------------------------------------------------
1083 :
1084 0 : CADMLine::CADMLine() :
1085 : scale( 0.0 ),
1086 0 : opened( false )
1087 : {
1088 0 : geometryType = CADGeometry::MLINE;
1089 0 : }
1090 :
1091 0 : void CADMLine::print() const
1092 : {
1093 : cout << "|---------MLine---------|\n" <<
1094 0 : "Base point: " << position.getX() << "\t" <<
1095 0 : position.getY() << "\t" <<
1096 0 : position.getZ() << "\n" <<
1097 0 : "Vertices:\n";
1098 0 : for( size_t i = 0; i < avertVertices.size(); ++i )
1099 : {
1100 0 : cout << " #" << i << ".\t" << avertVertices[i].getX() <<
1101 0 : "\t" << avertVertices[i].getY() <<
1102 0 : "\t" << avertVertices[i].getZ() << "\n";
1103 : }
1104 0 : cout << "\n";
1105 0 : }
1106 :
1107 0 : void CADMLine::transform( const Matrix& matrix )
1108 : {
1109 0 : CADPoint3D::transform( matrix );
1110 0 : for( CADVector& vertex : avertVertices )
1111 : {
1112 0 : vertex = matrix.multiply( vertex );
1113 : }
1114 0 : }
1115 :
1116 0 : double CADMLine::getScale() const
1117 : {
1118 0 : return scale;
1119 : }
1120 :
1121 0 : void CADMLine::setScale( double value )
1122 : {
1123 0 : scale = value;
1124 0 : }
1125 :
1126 0 : bool CADMLine::isOpened() const
1127 : {
1128 0 : return opened;
1129 : }
1130 :
1131 0 : void CADMLine::setOpened( bool value )
1132 : {
1133 0 : opened = value;
1134 0 : }
1135 :
1136 0 : void CADMLine::addVertex( const CADVector& vertex )
1137 : {
1138 0 : avertVertices.push_back( vertex );
1139 0 : }
1140 :
1141 : //------------------------------------------------------------------------------
1142 : // CADAttrib
1143 : //------------------------------------------------------------------------------
1144 :
1145 5 : CADAttrib::CADAttrib() :
1146 : dfElevation( 0.0 ),
1147 5 : bLockPosition( false )
1148 : {
1149 5 : geometryType = CADGeometry::ATTRIB;
1150 5 : }
1151 :
1152 0 : void CADAttrib::print() const
1153 : {
1154 : cout << "|---------Attribute---------|\n" <<
1155 0 : "Base point: " << position.getX() << "\t" <<
1156 0 : position.getY() << "\t" <<
1157 0 : position.getZ() << "\n" <<
1158 0 : "Tag: " << sTag << "\n" <<
1159 0 : "Text: " << textValue << "\n\n";
1160 0 : }
1161 :
1162 0 : void CADAttrib::transform( const Matrix& matrix )
1163 : {
1164 0 : CADText::transform( matrix );
1165 0 : vertAlignmentPoint = matrix.multiply( vertAlignmentPoint );
1166 0 : }
1167 :
1168 0 : double CADAttrib::getElevation() const
1169 : {
1170 0 : return dfElevation;
1171 : }
1172 :
1173 5 : void CADAttrib::setElevation( double elev )
1174 : {
1175 5 : dfElevation = elev;
1176 5 : }
1177 :
1178 5 : string CADAttrib::getTag() const
1179 : {
1180 5 : return sTag;
1181 : }
1182 :
1183 5 : void CADAttrib::setTag( const string& tag )
1184 : {
1185 5 : sTag = tag;
1186 5 : }
1187 :
1188 0 : CADVector CADAttrib::getAlignmentPoint() const
1189 : {
1190 0 : return vertAlignmentPoint;
1191 : }
1192 :
1193 5 : void CADAttrib::setAlignmentPoint( const CADVector& vect )
1194 : {
1195 5 : vertAlignmentPoint = vect;
1196 5 : }
1197 :
1198 0 : bool CADAttrib::isPositionLocked() const
1199 : {
1200 0 : return bLockPosition;
1201 : }
1202 :
1203 5 : void CADAttrib::setPositionLocked( bool lock )
1204 : {
1205 5 : bLockPosition = lock;
1206 5 : }
1207 :
1208 : //------------------------------------------------------------------------------
1209 : // CADAttdef
1210 : //------------------------------------------------------------------------------
1211 :
1212 5 : CADAttdef::CADAttdef()
1213 : {
1214 5 : geometryType = CADGeometry::ATTDEF;
1215 5 : }
1216 :
1217 0 : void CADAttdef::print() const
1218 : {
1219 : cout << "|---------Attribute defn---------|\n" <<
1220 0 : "Base point: " << position.getX() << "\t" <<
1221 0 : position.getY() << "\t" <<
1222 0 : position.getZ() << "\n" <<
1223 0 : "Tag: " << sTag << "\n" <<
1224 0 : "Text: " << textValue << "\n" <<
1225 0 : "Prompt: " << sPrompt << "\n\n";
1226 0 : }
1227 :
1228 0 : string CADAttdef::getPrompt() const
1229 : {
1230 0 : return sPrompt;
1231 : }
1232 :
1233 5 : void CADAttdef::setPrompt( const string& prompt )
1234 : {
1235 5 : sPrompt = prompt;
1236 5 : }
|