LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/cad/libopencad - cadgeometry.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 146 639 22.8 %
Date: 2024-05-03 15:49:35 Functions: 50 179 27.9 %

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

Generated by: LCOV version 1.14