Debian Codegraph @

src/Gui/SoDatumLabel.h

raw
1 /***************************************************************************
2 * Copyright (c) 2011-2012 Luke Parry <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_SODATUMLABEL_H
24 #define GUI_SODATUMLABEL_H
25
26 #include <Inventor/SbBox3f.h>
27 #include <Inventor/fields/SoSFBool.h>
28 #include <Inventor/fields/SoSFColor.h>
29 #include <Inventor/fields/SoSFEnum.h>
30 #include <Inventor/fields/SoSFFloat.h>
31 #include <Inventor/fields/SoSFImage.h>
32 #include <Inventor/fields/SoSFInt32.h>
33 #include <Inventor/fields/SoSFName.h>
34 #include <Inventor/fields/SoSFVec3f.h>
35 #include <Inventor/fields/SoMFString.h>
36 #include <Inventor/fields/SoMFVec3f.h>
37 #include <Inventor/nodes/SoShape.h>
38
39 #include <FCGlobal.h>
40
41
42 namespace Gui
43 {
44
45 class GuiExport SoDatumLabel: public SoShape
46 {
47 using inherited = SoShape;
48
49 SO_NODE_HEADER(SoDatumLabel);
50
51 friend class DatumLabelBox;
52
53 public:
54 enum Type
55 {
56 ANGLE,
57 DISTANCE,
58 DISTANCEX,
59 DISTANCEY,
60 RADIUS,
61 DIAMETER,
62 SYMMETRIC,
63 ARCLENGTH
64 };
65
66 static void initClass();
67 SoDatumLabel();
68
69 /*The points have to be on XY plane, ie they need to be 2D points.
70 To draw on other planes, you need to attach a SoTransform to the SoDatumLabel (or parent).*/
71 void setPoints(SbVec3f p1, SbVec3f p2);
72
73 /* returns the center point of the text of the label */
74 SbVec3f getLabelTextCenter();
75
76 SoMFString string;
77 SoSFColor textColor;
78 SoSFEnum datumtype;
79 SoSFName name;
80 SoSFInt32 size;
81 SoSFFloat param1;
82 SoSFFloat param2;
83 SoSFFloat param3;
84 SoSFFloat param4;
85 SoSFFloat param5;
86 SoSFFloat param6;
87 SoSFFloat param7;
88 SoSFFloat param8;
89 SoMFVec3f pnts;
90 SoSFVec3f norm;
91 SoSFBool strikethrough;
92 SoSFImage image;
93 SoSFFloat lineWidth;
94 SoSFFloat sampling;
95 bool useAntialiasing;
96
97 protected:
98 ~SoDatumLabel() override = default;
99 void GLRender(SoGLRenderAction* action) override;
100 void computeBBox(SoAction*, SbBox3f& box, SbVec3f& center) override;
101 void generatePrimitives(SoAction* action) override;
102 void notify(SoNotList* l) override;
103
104 private:
105 struct DistanceGeometry
106 {
107 SbVec3f p1, p2; // main points used for measurement
108 SbVec3f dir, normal; // dir and normal vecs
109 SbVec3f midpos; // mid pt
110 SbVec3f perp1, perp2; // ext line endpts
111 SbVec3f par1, par2, par3, par4; // dim line pts
112 SbVec3f ar1, ar2; // 1st arrow head triang pts
113 SbVec3f ar3, ar4; // 2nd arrow head triang pts
114 float angle; // text angle
115 SbVec3f textOffset; // text pos
116 bool flipTriang; // check for arrow flipping
117 float margin; // margin for arrow calcs
118 float arrowWidth; // width of the arrow
119 };
120
121 struct DiameterGeometry
122 {
123 SbVec3f p1, p2; // main points (center and edge for radius, endpoints for diameter)
124 SbVec3f center; // center point
125 SbVec3f dir, normal; // direction and normal vectors
126 SbVec3f pos; // text position base
127 SbVec3f pnt1, pnt2; // line segment points around text
128 SbVec3f ar0, ar1, ar2; // first arrow head triangle points
129 SbVec3f ar0_1, ar1_1, ar2_1; // second arrow head triangle points (diameter only)
130 float angle; // text angle
131 SbVec3f textOffset; // text position
132 float radius; // radius value
133 float margin; // margin for calculations
134 float arrowWidth; // arrow width
135 bool isDiameter; // true for diameter, false for radius
136 // Arc helper parameters
137 float startAngle, startRange; // start parameters
138 float endAngle, endRange; // start parameters
139 };
140
141 struct AngleGeometry
142 {
143 SbVec3f p0; // angle intersection point
144 SbVec3f v0; // vector for text position
145 SbVec3f v1, v2; // direction vectors for start and end lines
146 SbVec3f pnt1, pnt2, pnt3, pnt4; // line endpoints
147 SbVec3f startArrowBase, endArrowBase; // arrow base points
148 SbVec3f dirStart, dirEnd; // arrow directions
149 float angle; // text angle (always 0 for angles)
150 SbVec3f textOffset; // text position
151 float length; // length parameter
152 float startangle, endangle, range; // angle parameters
153 float r; // arc radius
154 float margin; // margin for calculations
155 float arrowLength, arrowWidth; // arrow dimensions
156 double textMargin; // margin around text in arc
157 float endLineLength1, endLineLength2; // extension line lengths
158 float endLineLength12, endLineLength22; // extension line lengths (other side)
159 };
160
161 struct SymmetricGeometry
162 {
163 SbVec3f p1, p2; // main points
164 SbVec3f dir, normal; // direction and normal vectors
165 SbVec3f ar0, ar1, ar2; // first arrow triangle points (tip, base1, base2)
166 SbVec3f ar3, ar4, ar5; // second arrow triangle points (tip, base1, base2)
167 float margin; // margin for calculations
168 };
169
170 struct ArcLengthGeometry
171 {
172 SbVec3f ctr, p1, p2;
173 float length;
174 float margin;
175 float startangle, endangle;
176 float range;
177 float radius;
178 SbVec3f vm; // middle direction vector
179 SbVec3f pnt1, pnt2, pnt3, pnt4; // line endpoints
180 SbVec3f dirStart, dirEnd; // arrow directions
181 SbVec3f textOffset;
182 float angle;
183 bool isLargeArc; // whether range > pi
184 SbVec3f arcCenter; // center for arc drawing
185 float arcRadius; // radius for arc drawing
186 };
187
188 float getScaleFactor(SoState*) const;
189 void generateDistancePrimitives(SoAction* action, const SbVec3f&, const SbVec3f&);
190 void generateDiameterPrimitives(SoAction* action, const SbVec3f&, const SbVec3f&);
191 void generateAnglePrimitives(SoAction* action, const SbVec3f&);
192 void generateSymmetricPrimitives(SoAction* action, const SbVec3f&, const SbVec3f&);
193 void generateArcLengthPrimitives(SoAction* action, const SbVec3f&, const SbVec3f&, const SbVec3f&);
194 SbVec3f getLabelTextCenterDistance(const SbVec3f&, const SbVec3f&);
195 SbVec3f getLabelTextCenterDiameter(const SbVec3f&, const SbVec3f&);
196 SbVec3f getLabelTextCenterAngle(const SbVec3f&);
197 SbVec3f getLabelTextCenterArcLength(const SbVec3f&, const SbVec3f&, const SbVec3f&) const;
198 bool hasDatumText() const;
199 void getDimension(float scale, int& srcw, int& srch);
200 DistanceGeometry calculateDistanceGeometry(const SbVec3f* points) const;
201 DiameterGeometry calculateDiameterGeometry(const SbVec3f* points) const;
202 AngleGeometry calculateAngleGeometry(const SbVec3f* points) const;
203 SymmetricGeometry calculateSymmetricGeometry(const SbVec3f* points) const;
204 ArcLengthGeometry calculateArcLengthGeometry(const SbVec3f* points) const;
205 void generateLineSelectionPrimitive(
206 SoAction* action,
207 const SbVec3f& start,
208 const SbVec3f& end,
209 float width
210 );
211 void generateArcSelectionPrimitive(
212 SoAction* action,
213 const SbVec3f& center,
214 float radius,
215 float startAngle,
216 float endAngle,
217 float width
218 );
219 void generateArrowSelectionPrimitive(
220 SoAction* action,
221 const SbVec3f& base,
222 const SbVec3f& dir,
223 float width,
224 float length
225 );
226 void drawDistance(const SbVec3f* points, float& angle, SbVec3f& textOffset);
227 void drawDistance(const SbVec3f* points);
228 void drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbVec3f& textOffset);
229 void drawAngle(const SbVec3f* points, float& angle, SbVec3f& textOffset);
230 void drawSymmetric(const SbVec3f* points);
231 void drawArcLength(const SbVec3f* points, float& angle, SbVec3f& textOffset);
232 void drawText(SoState* state, int srcw, int srch, float angle, const SbVec3f& textOffset);
233
234 private:
235 void drawImage();
236 float imgWidth;
237 float imgHeight;
238 bool glimagevalid;
239 };
240
241 } // namespace Gui
242
243
244 #endif // GUI_SODATUMLABEL_H