diff --git a/lckernel/cad/geometry/geoarc.cpp b/lckernel/cad/geometry/geoarc.cpp index 8d3b60db9d..eb71264b55 100644 --- a/lckernel/cad/geometry/geoarc.cpp +++ b/lckernel/cad/geometry/geoarc.cpp @@ -32,7 +32,7 @@ double Arc::endAngle() const { return _endAngle; } -const Coordinate& Arc::center() const { +const Coordinate Arc::center() const { return _center; } diff --git a/lckernel/cad/geometry/geoarc.h b/lckernel/cad/geometry/geoarc.h index c698a75876..7a37ee3159 100644 --- a/lckernel/cad/geometry/geoarc.h +++ b/lckernel/cad/geometry/geoarc.h @@ -10,7 +10,7 @@ namespace lc { public: Arc(const Coordinate& center, double radius, double startAngle, double endAngle); - const Coordinate& center() const; + const Coordinate center() const; /*! * \brief Returns the radius of Arc. diff --git a/lckernel/cad/geometry/geoarea.cpp b/lckernel/cad/geometry/geoarea.cpp index 27d73e902a..97690637a1 100644 --- a/lckernel/cad/geometry/geoarea.cpp +++ b/lckernel/cad/geometry/geoarea.cpp @@ -15,10 +15,10 @@ Area::Area(const Coordinate& coordA, const Coordinate& coordB) : } -const Coordinate& Area::minP() const { +const Coordinate Area::minP() const { return _minP; } -const Coordinate& Area::maxP() const { +const Coordinate Area::maxP() const { return _maxP; } diff --git a/lckernel/cad/geometry/geoarea.h b/lckernel/cad/geometry/geoarea.h index f5c83ac211..5cfe70a67b 100644 --- a/lckernel/cad/geometry/geoarea.h +++ b/lckernel/cad/geometry/geoarea.h @@ -24,12 +24,12 @@ namespace lc { /** * Return the smalles corner (closest to (0,0,0) ) */ - const Coordinate& minP() const; + const Coordinate minP() const; /** * Return the heigest corner */ - const Coordinate& maxP() const; + const Coordinate maxP() const; /** * Test of a specific point lies within a area diff --git a/lckernel/cad/geometry/geocircle.cpp b/lckernel/cad/geometry/geocircle.cpp index 8ca16bb4a3..685258c39b 100644 --- a/lckernel/cad/geometry/geocircle.cpp +++ b/lckernel/cad/geometry/geocircle.cpp @@ -11,7 +11,7 @@ Circle::Circle(const Coordinate& center, double radius) : _center(center) { _radius = radius; } -const Coordinate& Circle::center() const { +const Coordinate Circle::center() const { return _center; } double Circle::radius() const { diff --git a/lckernel/cad/geometry/geocircle.h b/lckernel/cad/geometry/geocircle.h index 34725526c4..f1dbf573b1 100644 --- a/lckernel/cad/geometry/geocircle.h +++ b/lckernel/cad/geometry/geocircle.h @@ -15,7 +15,7 @@ namespace lc { * \brief Returns the Center of circle. * \return lc::geo::Coordinate Center. */ - const Coordinate& center() const; + const Coordinate center() const; /*! * \brief returns the radius of the circle. diff --git a/lckernel/cad/geometry/geoellipse.cpp b/lckernel/cad/geometry/geoellipse.cpp index 0b8a8d8ee9..96327e79c9 100644 --- a/lckernel/cad/geometry/geoellipse.cpp +++ b/lckernel/cad/geometry/geoellipse.cpp @@ -16,11 +16,11 @@ Ellipse::Ellipse(const Coordinate& center, const Coordinate& majorP, double mino _endAngle = endAngle; } -const Coordinate& Ellipse::center() const { +const Coordinate Ellipse::center() const { return _center; } -const Coordinate& Ellipse::majorP() const { +const Coordinate Ellipse::majorP() const { return _majorP; } diff --git a/lckernel/cad/geometry/geoellipse.h b/lckernel/cad/geometry/geoellipse.h index ee19ff6b58..3c9c2d85ea 100644 --- a/lckernel/cad/geometry/geoellipse.h +++ b/lckernel/cad/geometry/geoellipse.h @@ -10,8 +10,8 @@ namespace lc { public: Ellipse(const Coordinate& center, const Coordinate& majorP, double minorRadius, double startAngle, double endAngle, bool isArc = false); - const Coordinate& center() const; - const Coordinate& majorP() const; + const Coordinate center() const; + const Coordinate majorP() const; double minorRadius() const; double startAngle() const; double endAngle() const; diff --git a/lckernel/cad/geometry/geospline.cpp b/lckernel/cad/geometry/geospline.cpp index a44e79c2dd..f36e179403 100644 --- a/lckernel/cad/geometry/geospline.cpp +++ b/lckernel/cad/geometry/geospline.cpp @@ -8,7 +8,7 @@ Spline::Spline(const std::vector& control_points, int degree, bool c _closed = closed; } -const std::vector& Spline::control_points() const { +const std::vector Spline::control_points() const { return _control_points; } diff --git a/lckernel/cad/geometry/geospline.h b/lckernel/cad/geometry/geospline.h index 417b741771..9fdaa986a1 100644 --- a/lckernel/cad/geometry/geospline.h +++ b/lckernel/cad/geometry/geospline.h @@ -11,7 +11,7 @@ namespace lc { public: Spline(const std::vector& control_points, int degree, bool closed); - const std::vector& control_points() const; + const std::vector control_points() const; int degree() const; diff --git a/lckernel/cad/geometry/geotext.cpp b/lckernel/cad/geometry/geotext.cpp index fbcdef812e..ccf3ec9927 100644 --- a/lckernel/cad/geometry/geotext.cpp +++ b/lckernel/cad/geometry/geotext.cpp @@ -3,24 +3,65 @@ using namespace lc; using namespace geo; -Text::Text(const Coordinate& insertion_point, double height, std::string text_value) : _insertion_point(insertion_point) { +Text::Text(const Coordinate &insertion_point, + const Coordinate& second_point, const double height, + const std::string text_value, const double width_rel, + const double angle, const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign) : + _insertion_point(insertion_point), _second_point(second_point) { + + _height = height; + _text_value = text_value; + _width_rel = width_rel; + _angle = angle; + _style = style; + _textgeneration = textgeneration; + _halign = halign; + _valign = valign; - _height = height; - _text_value = text_value; } -const Coordinate& Text::insertion_point() const { +const Coordinate Text::insertion_point() const { return _insertion_point; } +const Coordinate Text::second_point() const { + return _second_point; +} + double Text::height() const { return _height; } +double Text::width_rel() const { + return _width_rel; +} + +double Text::angle() const { + return _angle; +} + std::string Text::text_value() const { return _text_value; } +std::string Text::style() const { + return _style; +} + +Text::TextGeneration Text::textgeneration() const { + return _textgeneration; +} + +Text::HAlign Text::halign() const { + return _halign; +} + +Text::VAlign Text::valign() const { + return _valign; +} + Coordinate Text::nearestPointOnPath(const Coordinate& coord) const { //return; } diff --git a/lckernel/cad/geometry/geotext.h b/lckernel/cad/geometry/geotext.h index a368192fb8..20881bfcb3 100644 --- a/lckernel/cad/geometry/geotext.h +++ b/lckernel/cad/geometry/geotext.h @@ -7,21 +7,159 @@ namespace lc { namespace geo { + /** + * @brief The Text class + * Reference : http://www.autodesk.com/techpubs/autocad/acad2000/dxf/text_dxf_06.htm + */ class Text { public: - Text(const Coordinate& insertion_point, double height, std::string text_value); + /** + * Vertical alignments. + */ + enum VAlign { + VABaseline, /**< Bottom */ + VABottom, /**< Bottom */ + VAMiddle, /**< Middle */ + VATop /**< Top. */ + }; - const Coordinate& insertion_point() const; + /** + * Horizontal alignments. + */ + enum HAlign { + HALeft, /**< Left */ + HACenter, /**< Centered */ + HARight, /**< Right */ + HAAligned, /**< Aligned */ + HAMiddle, /**< Middle */ + HAFit /**< Fit */ + }; + + /** + * Text drawing direction. + */ + enum TextGeneration { + None, /**< Normal text */ + Backward, /**< Mirrored in X */ + UpsideDown /**< Mirrored in Y */ + }; + /** + * @brief Text Entity + * @param insertion_point insertion_point of the text + * @param second_point second_point of text in UCS + * @param height height of the text + * @param text_value the text itself + * @param width_rel X scale factor-width + * @param angle angle of obliqueness + * @param style name of text style + * @param textgeneration Text drawing direction + * @param halign Horizontal alignment + * @param valign Vertical alignment + */ + Text(const Coordinate& insertion_point, + const Coordinate& second_point, const double height, + const std::string text_value, const double width_rel, + const double angle, const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign); + + /** + * @brief Insertion point of text + * First alignment point (in OCS) + * DXF: X value; APP: 3D point + * DXF: Y and Z values of first alignment point (in OCS) + * @return Coordinate insertion_point + */ + const Coordinate insertion_point() const; + + /** + * @brief Height of text + * Text height. code 40 + * @return double height + */ double height() const; + + /** + * @brief text value of the text + * Text value itself. code 1 + * @return string text value. + */ std::string text_value() const; + /** + * @brief Second point + * Second alignment point (in OCS) (optional) + * DXF: X value; APP: 3D point + * This value is meaningful only if the value of a 72 or 73 group is nonzero + * (if the justification is anything other than baseline/left). + * DXF: Y and Z values of second alignment point (in OCS) (optional) + * @return Coordinate second point. + */ + const Coordinate second_point() const; + + /** + * @brief X factor relative width + * Relative X scale factor-width (optional; default = 1) + * This value is also adjusted when fit-type text is used. + * @return double X factor relative width + */ + double width_rel() const; + + /** + * @brief angle + * Oblique angle (optional; default = 0) + * @return double oblique angle + */ + double angle() const; + + /** + * @brief style + * Text style name (optional, default = STANDARD) + * @return string style name + */ + std::string style() const; + + /** + * @brief textgeneration + * Text generation flags (optional, default = 0): + * 2 = Text is backward (mirrored in X). + * 4 = Text is upside down (mirrored in Y). + * @return + */ + TextGeneration textgeneration() const; + + /** + * @brief halign + * Horizontal text justification type (optional, default = 0) integer codes (not bit-coded) + * 0 = Left; 1= Center; 2 = Right + * 3 = Aligned (if vertical alignment = 0) + * 4 = Middle (if vertical alignment = 0) + * 5 = Fit (if vertical alignment = 0) + * See the Group 72 and 73 integer codes table for clarification. + * @return + */ + HAlign halign() const; + + /** + * @brief valign + * Vertical text justification type (optional, default = 0): integer codes (not bit- coded): + * 0 = Baseline; 1 = Bottom; 2 = Middle; 3 = Top + * See the Group 72 and 73 integer codes table for clarification. + * @return + */ + VAlign valign() const; + Coordinate nearestPointOnPath(const Coordinate& coord) const; bool isCoordinateOnPath(const Coordinate& coord) const; private: - const Coordinate _insertion_point; - double _height; - std::string _text_value; + const Coordinate _insertion_point, _second_point; + double _height, _width_rel, _angle; + VAlign _valign; + HAlign _halign; + TextGeneration _textgeneration; + std::string _style, _text_value; + }; } } diff --git a/lckernel/cad/geometry/geovector.cpp b/lckernel/cad/geometry/geovector.cpp index d8680c9b96..8671a0a05d 100644 --- a/lckernel/cad/geometry/geovector.cpp +++ b/lckernel/cad/geometry/geovector.cpp @@ -11,10 +11,10 @@ Vector::Vector(const Coordinate& start, const Coordinate& end) : _start(start), Vector::Vector(const Vector& v) : _start(v._start), _end(v._end) { } -const Coordinate& Vector::start() const { +const Coordinate Vector::start() const { return _start; } -const Coordinate& Vector::end() const { +const Coordinate Vector::end() const { return _end; } diff --git a/lckernel/cad/geometry/geovector.h b/lckernel/cad/geometry/geovector.h index 37bbf895fa..5d33f5dae2 100644 --- a/lckernel/cad/geometry/geovector.h +++ b/lckernel/cad/geometry/geovector.h @@ -12,8 +12,8 @@ namespace lc { Vector(const Coordinate& start, const Coordinate& end); Vector(const Vector& v); - const Coordinate& start() const; - const Coordinate& end() const; + const Coordinate start() const; + const Coordinate end() const; Coordinate nearestPointOnPath(const geo::Coordinate& coord) const; bool isCoordinateOnPath(const Coordinate& coord) const; diff --git a/lckernel/cad/primitive/text.cpp b/lckernel/cad/primitive/text.cpp index d38f15c4ef..0502677b19 100644 --- a/lckernel/cad/primitive/text.cpp +++ b/lckernel/cad/primitive/text.cpp @@ -1,26 +1,74 @@ #include "text.h" + + using namespace lc; -Text::Text(const geo::Coordinate& insertion_point, double height, std::string text_value, const Layer_CSPtr layer) : CADEntity(layer), geo::Text(insertion_point, height, text_value) { +Text::Text(const geo::Coordinate& insertion_point, + const geo::Coordinate& second_point, + const double height, + const std::string text_value, + const double width_rel, + const double angle, + const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign, const Layer_CSPtr layer) : CADEntity(layer), geo::Text(insertion_point, second_point, height, + text_value, width_rel, angle, style, + textgeneration, halign, valign) { } -Text::Text(const geo::Coordinate& insertion_point, double height, std::string text_value, const Layer_CSPtr layer, const std::list& metaTypes) : CADEntity(layer, metaTypes), geo::Text(insertion_point, height, text_value) { +Text::Text(const geo::Coordinate& insertion_point, + const geo::Coordinate& second_point, + const double height, + const std::string text_value, + const double width_rel, + const double angle, + const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign, const Layer_CSPtr layer, const std::list& metaTypes) : CADEntity(layer, metaTypes), geo::Text(insertion_point, second_point, height, + text_value, width_rel, angle, style, + textgeneration, halign, valign) { + } CADEntity_CSPtr Text::move(const geo::Coordinate& offset) const { - + auto newText = std::make_shared(this->insertion_point() + offset, + this->second_point() + offset, + this->height(), this->text_value(), + this->width_rel(),this->angle(), this->style(), + this->textgeneration(), this->halign(), this->valign(),layer()); + newText->setID(this->id()); + return newText; } CADEntity_CSPtr Text::copy(const geo::Coordinate& offset) const { + auto newText = std::make_shared(this->insertion_point() + offset, + this->second_point() + offset, + this->height(), this->text_value(), + this->width_rel(),this->angle(), this->style(), + this->textgeneration(), this->halign(), this->valign(), layer()); + return newText; } CADEntity_CSPtr Text::rotate(const geo::Coordinate& rotation_center, const double rotation_angle) const { - + // TODO : Implement the correct angle fuction to get angle between 0 adn 360 + auto newText = std::make_shared(this->insertion_point().rotate(rotation_center, rotation_angle), + this->second_point().rotate(rotation_center, rotation_angle), + this->height(), this->text_value(), + this->width_rel(), this->angle() + rotation_angle, this->style(), + this->textgeneration(), this->halign(), this->valign(), layer()); + newText->setID(this->id()); + return newText; } CADEntity_CSPtr Text::scale(const geo::Coordinate& scale_center, const geo::Coordinate& scale_factor) const { - + auto newText = std::make_shared(this->insertion_point().scale(scale_center, scale_factor), + this->second_point().scale(scale_center, scale_factor), + this->height()* scale_factor.x(), this->text_value(), + this->width_rel(),this->angle(), this->style(), + this->textgeneration(), this->halign(), this->valign(), layer()); + newText->setID(this->id()); + return newText; } diff --git a/lckernel/cad/primitive/text.h b/lckernel/cad/primitive/text.h index 4d1c406cc0..ecb1e593fc 100644 --- a/lckernel/cad/primitive/text.h +++ b/lckernel/cad/primitive/text.h @@ -16,10 +16,57 @@ namespace lc { typedef std::shared_ptr Text_SPtr; typedef std::shared_ptr Text_CSPtr; + class Text : public std::enable_shared_from_this, public CADEntity, public geo::Text { public: - Text(const geo::Coordinate& insertion_point, double height, std::string text_value, const Layer_CSPtr layer); - Text(const geo::Coordinate& insertion_point, double height, std::string text_value, const Layer_CSPtr layer, const std::list& metaTypes); + /** + * @brief Text Entity + * @param insertion_point insertion_point of the text + * @param second_point second_point of text in UCS + * @param height height of the text + * @param text_value the text itself + * @param width_rel X scale factor-width + * @param angle angle of obliqueness + * @param style name of text style + * @param textgeneration Text drawing direction + * @param halign Horizontal alignment + * @param valign Vertical alignment + * @param layer Layer of the entity + */ + Text(const geo::Coordinate& insertion_point, + const geo::Coordinate& second_point, + const double height, + const std::string text_value, + const double width_rel, + const double angle, + const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign, const Layer_CSPtr layer); + + /** + * @brief Text Entity + * @param insertion_point insertion_point of the text + * @param second_point second_point of text in UCS + * @param height height of the text + * @param text_value the text itself + * @param width_rel X scale factor-width + * @param angle angle of obliqueness + * @param style name of text style + * @param textgeneration Text drawing direction + * @param halign Horizontal alignment + * @param valign Vertical alignment + * @param layer Layer of the entity + * @param metatypes metatypes of the cad entity + */ + Text(const geo::Coordinate& insertion_point, + const geo::Coordinate& second_point, + const double height, + const std::string text_value, + const double width_rel, + const double angle, + const std::string style, + const TextGeneration textgeneration, + const HAlign halign, const VAlign valign, const Layer_CSPtr layer, const std::list& metaTypes); public: virtual CADEntity_CSPtr move(const geo::Coordinate& offset) const;