1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 
28 #ifndef RS_DIMENSION_H
29 #define RS_DIMENSION_H
30 
31 #include "rs_entitycontainer.h"
32 #include "rs_mtext.h"
33 
34 /**
35  * Holds the data that is common to all dimension entities.
36  */
37 struct RS_DimensionData : public RS_Flags {
38     /**
39 	 * Default constructor
40      */
41 	RS_DimensionData();
42 
43     /**
44      * Constructor with initialisation.
45      *
46      * @param definitionPoint Definition point.
47      * @param middleOfText Middle point of dimension text.
48      * @param valign Vertical alignment.
49      * @param halign Horizontal alignment.
50      * @param lineSpacingStyle Line spacing style.
51      * @param lineSpacingFactor Line spacing factor.
52      * @param text Text string entered explicitly by user or null
53      *         or "<>" for the actual measurement or " " (one blank space).
54      *         for suppressing the text.
55      * @param style Dimension style name.
56      * @param angle Rotation angle of dimension text away from
57      *         default orientation.
58      */
59 	RS_DimensionData(const RS_Vector& definitionPoint,
60                      const RS_Vector& middleOfText,
61                      RS_MTextData::VAlign valign,
62                      RS_MTextData::HAlign halign,
63                      RS_MTextData::MTextLineSpacingStyle lineSpacingStyle,
64                      double lineSpacingFactor,
65                      QString text,
66                      QString style,
67 					 double angle);
68 
69     /** Definition point */
70 	RS_Vector definitionPoint;
71     /** Middle point of dimension text */
72     RS_Vector middleOfText;
73     /** Vertical alignment */
74     RS_MTextData::VAlign valign;
75     /** Horizontal alignment */
76     RS_MTextData::HAlign halign;
77     /** Line spacing style */
78     RS_MTextData::MTextLineSpacingStyle lineSpacingStyle;
79     /** Line spacing factor */
80     double lineSpacingFactor;
81     /**
82     * Text string entered explicitly by user or null
83     * or "<>" for the actual measurement or " " (one blank space)
84     * for suppressing the text.
85     */
86     QString text;
87     /** Dimension style name */
88     QString style;
89     /** Rotation angle of dimension text away from default orientation */
90     double angle;
91 };
92 
93 std::ostream& operator << (std::ostream& os,
94 								  const RS_DimensionData& dd);
95 
96 /**
97  * Abstract base class for dimension entity classes.
98  *
99  * @author Andrew Mustun
100  */
101 class RS_Dimension : public RS_EntityContainer {
102 public:
103     RS_Dimension(RS_EntityContainer* parent,
104                  const RS_DimensionData& d);
105 
106 	RS_Vector getNearestRef( const RS_Vector& coord, double* dist = nullptr) const override;
107 	RS_Vector getNearestSelectedRef( const RS_Vector& coord, double* dist = nullptr) const override;
108 
109     /** @return Copy of data that defines the dimension. */
getData()110     RS_DimensionData getData() const {
111         return data;
112     }
113 
114     QString getLabel(bool resolve=true);
115         void setLabel(const QString& l);
116 
117     /**
118      * Needs to be implemented by the dimension class to return the
119      * measurement of the dimension (e.g. 10.5 or 15'14").
120      */
121     virtual QString getMeasuredLabel() = 0;
122 
123     /**
124      * Must be overwritten by implementing dimension entity class
125      * to update the subentities which make up the dimension entity.
126      */
update()127 	void update() override{
128             updateDim();
129         }
130 
131     virtual void updateDim(bool autoText=false) = 0;
132 
133     void updateCreateDimensionLine(const RS_Vector& p1, const RS_Vector& p2,
134                   bool arrow1=true, bool arrow2=true, bool autoText=false);
135 
getDefinitionPoint()136     RS_Vector getDefinitionPoint() {
137 		return data.definitionPoint;
138     }
139 
getMiddleOfText()140     RS_Vector getMiddleOfText() {
141         return data.middleOfText;
142     }
143 
getVAlign()144     RS_MTextData::VAlign getVAlign() {
145         return data.valign;
146     }
147 
getHAlign()148     RS_MTextData::HAlign getHAlign() {
149         return data.halign;
150     }
151 
getLineSpacingStyle()152     RS_MTextData::MTextLineSpacingStyle getLineSpacingStyle() {
153         return data.lineSpacingStyle;
154     }
155 
getLineSpacingFactor()156     double getLineSpacingFactor() {
157         return data.lineSpacingFactor;
158     }
159 
getText()160     QString getText() {
161         return data.text;
162     }
163 
getStyle()164     QString getStyle() {
165         return data.style;
166     }
167 
getAngle()168     double getAngle() {
169         return data.angle;
170     }
171 
172     double getGeneralFactor();
173     double getGeneralScale();
174     double getArrowSize();
175     double getTickSize();
176     double getExtensionLineExtension();
177     double getExtensionLineOffset();
178     double getDimensionLineGap();
179     double getTextHeight();
180     bool getInsideHorizontalText();
181     bool getFixedLengthOn();
182     double getFixedLength();
183     RS2::LineWidth getExtensionLineWidth();
184     RS2::LineWidth getDimensionLineWidth();
185     RS_Color getDimensionLineColor();
186     RS_Color getExtensionLineColor();
187     RS_Color getTextColor();
188     QString getTextStyle();
189 
190         double getGraphicVariable(const QString& key, double defMM, int code);
191         static QString stripZerosAngle(QString angle, int zeros=0);
192         static QString stripZerosLinear(QString linear, int zeros=1);
193 
194         //	virtual double getLength() {
195         //		return -1.0;
196         //	}
197 
198 		void move(const RS_Vector& offset) override;
199 		void rotate(const RS_Vector& center, const double& angle) override;
200 		void rotate(const RS_Vector& center, const RS_Vector& angleVector) override;
201 		void scale(const RS_Vector& center, const RS_Vector& factor) override;
202 		void mirror(const RS_Vector& axisPoint1, const RS_Vector& axisPoint2) override;
203 
204 private:
205     static RS_VectorSolutions  getIntersectionsLineContainer(
206         const RS_Line* l, const RS_EntityContainer* c, bool infiniteLine=false);
207     void updateCreateHorizontalTextDimensionLine(
208         const RS_Vector& p1, const RS_Vector& p2,
209         bool arrow1=true, bool arrow2=true, bool autoText=false);
210     void updateCreateAlignedTextDimensionLine(
211         const RS_Vector& p1, const RS_Vector& p2,
212         bool arrow1=true, bool arrow2=true, bool autoText=false);
213 
214 protected:
215     /** Data common to all dimension entities. */
216     RS_DimensionData data;
217 };
218 
219 #endif
220