]> Shamusworld >> Repos - architektonas/blob - src/base/rs_dimension.h
7477a45ce31963096d6638a16df6fbc6e7946331
[architektonas] / src / base / rs_dimension.h
1 #ifndef RS_DIMENSION_H
2 #define RS_DIMENSION_H
3
4 #include "rs_entitycontainer.h"
5
6 /**
7  * Holds the data that is common to all dimension entities.
8  */
9 class RS_DimensionData: public RS_Flags
10 {
11         public:
12                 /**
13                  * Default constructor. Leaves the data object uninitialized.
14                  */
15                 RS_DimensionData() {}
16
17                 /**
18                  * Constructor with initialisation.
19                  *
20                  * @param definitionPoint Definition point.
21                  * @param middleOfText Middle point of dimension text.
22                  * @param valign Vertical alignment.
23                  * @param halign Horizontal alignment.
24                  * @param lineSpacingStyle Line spacing style.
25                  * @param lineSpacingFactor Line spacing factor.
26                  * @param text Text string entered explicitly by user or null
27                  *         or "<>" for the actual measurement or " " (one blank space).
28                  *         for supressing the text.
29                  * @param style Dimension style name.
30                  * @param angle Rotation angle of dimension text away from
31                  *         default orientation.
32                  */
33                 RS_DimensionData(const Vector & definitionPoint,
34                         const Vector & middleOfText,
35                         RS2::VAlign valign,
36                         RS2::HAlign halign,
37                         RS2::TextLineSpacingStyle lineSpacingStyle,
38                         double lineSpacingFactor,
39                         QString text,
40                         QString style,
41                         double angle)
42                 {
43                         this->definitionPoint = definitionPoint;
44                         this->middleOfText = middleOfText;
45                         this->valign = valign;
46                         this->halign = halign;
47                         this->lineSpacingStyle = lineSpacingStyle;
48                         this->lineSpacingFactor = lineSpacingFactor;
49                         this->text = text;
50                         this->style = style;
51                         this->angle = angle;
52                 }
53
54                 friend class RS_Dimension;
55                 friend class RS_DimAligned;
56                 friend class RS_DimLinear;
57                 friend class RS_ActionDimAligned;
58                 friend class RS_ActionDimLinear;
59
60                 friend std::ostream & operator<<(std::ostream & os, const RS_DimensionData & dd)
61                 {
62                         os << "(" << dd.definitionPoint << ")";
63                         return os;
64                 }
65
66         public:
67                 /** Definition point */
68                 Vector definitionPoint;
69                 /** Middle point of dimension text */
70                 Vector middleOfText;
71                 /** Vertical alignment */
72                 RS2::VAlign valign;
73                 /** Horizontal alignment */
74                 RS2::HAlign halign;
75                 /** Line spacing style */
76                 RS2::TextLineSpacingStyle lineSpacingStyle;
77                 /** Line spacing factor */
78                 double lineSpacingFactor;
79                 /**
80                  * Text string entered explicitly by user or null
81                  * or "<>" for the actual measurement or " " (one blank space)
82                  * for supressing the text.
83                  */
84                 QString text;
85                 /** Dimension style name */
86                 QString style;
87                 /** Rotation angle of dimension text away from default orientation */
88                 double angle;
89 };
90
91 /**
92  * Abstract base class for dimension entity classes.
93  *
94  * @author Andrew Mustun
95  */
96 class RS_Dimension: public RS_EntityContainer
97 {
98         public:
99                 RS_Dimension(RS_EntityContainer * parent, const RS_DimensionData & d);
100                 virtual ~RS_Dimension();
101
102                 RS_DimensionData getData() const;
103                 Vector getNearestRef(const Vector & coord, double * dist);
104                 Vector getNearestSelectedRef(const Vector & coord, double * dist);
105                 QString getLabel(bool resolve = true);
106                 void setLabel(const QString & l);
107
108                 /**
109                  * Needs to be implemented by the dimension class to return the
110                  * measurement of the dimension (e.g. 10.5 or 15'14").
111                  */
112                 virtual QString getMeasuredLabel() = 0;
113
114                 /**
115                  * Must be overwritten by implementing dimension entity class
116                  * to update the subentities which make up the dimension entity.
117                  */
118                 virtual void update(bool autoText = false) = 0;
119
120                 void updateCreateDimensionLine(const Vector & p1, const Vector & p2,
121                         bool arrow1 = true, bool arrow2 = true, bool autoText = false);
122                 Vector getDefinitionPoint();
123                 Vector getMiddleOfText();
124                 RS2::VAlign getVAlign();
125                 RS2::HAlign getHAlign();
126                 RS2::TextLineSpacingStyle getLineSpacingStyle();
127                 double getLineSpacingFactor();
128                 QString getText();
129                 QString getStyle();
130                 double getAngle();
131                 double getArrowSize();
132                 double getExtensionLineExtension();
133                 double getExtensionLineOffset();
134                 double getDimensionLineGap();
135                 double getTextHeight();
136                 double getGraphicVariable(const QString & key, double defMM, int code);
137                 virtual double getLength();
138                 virtual void move(Vector offset);
139                 virtual void rotate(Vector center, double angle);
140                 virtual void scale(Vector center, Vector factor);
141                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
142
143         protected:
144                 /** Data common to all dimension entities. */
145                 RS_DimensionData data;
146 };
147
148 #endif