7fd59977 |
1 | // Copyright: Matra-Datavision 1996 |
2 | // File: DsgPrs_DiameterPresentation.cxx |
3 | // Created: Wed Aug 21 15:36:02 1996 |
4 | // Author: Jacques MINOT |
5 | // <jmi> |
6 | // modified 12-january-98 |
7 | // Sergey ZARITCHNY |
8 | // <szy@androxx.nnov.matra-dtv.fr> |
9 | // szy |
10 | #include <DsgPrs_DiameterPresentation.ixx> |
11 | |
12 | #include <Prs3d_LineAspect.hxx> |
13 | #include <Prs3d_TextAspect.hxx> |
14 | #include <Prs3d_LengthAspect.hxx> |
15 | #include <Prs3d_Arrow.hxx> |
16 | #include <Prs3d_Text.hxx> |
17 | #include <Prs3d_ArrowAspect.hxx> |
18 | |
19 | #include <Graphic3d_Group.hxx> |
20 | #include <Graphic3d_Array1OfVertex.hxx> |
21 | |
22 | #include <gp_Dir.hxx> |
23 | #include <gp_Pnt.hxx> |
24 | #include <gp_Vec.hxx> |
25 | |
26 | #include <ElCLib.hxx> |
27 | |
28 | #include <Graphic3d_Vertex.hxx> |
29 | #include <Graphic3d_AspectMarker3d.hxx> |
30 | #include <Graphic3d_AspectLine3d.hxx> |
31 | #include <Aspect_TypeOfLine.hxx> |
32 | #include <Aspect_TypeOfMarker.hxx> |
33 | #include <Aspect_AspectMarker.hxx> |
34 | #include <Quantity_Color.hxx> |
35 | #include <DsgPrs.hxx> |
36 | |
37 | //========================================================================== |
38 | // function : DsgPrs_DiameterPresentation::Add |
39 | // purpose : ODL 4-fevrier-97 |
40 | // on peut choisir le symbol des extremites de la cote (fleche, point ...) |
41 | //========================================================================== |
42 | void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
43 | const Handle(Prs3d_Drawer)& aDrawer, |
44 | const TCollection_ExtendedString& aText, |
45 | const gp_Pnt& AttachmentPoint, |
46 | const gp_Circ& aCircle, |
47 | const DsgPrs_ArrowSide ArrowPrs, |
48 | const Standard_Boolean IsDiamSymbol ) |
49 | { |
50 | |
51 | |
52 | Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect(); |
53 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
54 | |
55 | Standard_Real parat = ElCLib::Parameter(aCircle, AttachmentPoint); |
56 | gp_Pnt ptoncirc = ElCLib::Value (parat, aCircle); |
57 | |
58 | // ligne de cote |
59 | |
60 | gp_Pnt center = aCircle.Location(); |
61 | gp_Vec vecrap (ptoncirc,center); |
62 | |
63 | Standard_Real dist = center.Distance(AttachmentPoint); |
64 | Standard_Real aRadius = aCircle.Radius(); |
65 | Standard_Boolean inside = Standard_False; |
66 | |
67 | gp_Pnt pt1 = AttachmentPoint; |
68 | if (dist < aRadius) { |
69 | pt1 = ptoncirc; |
70 | dist = aRadius; |
71 | inside = Standard_True; |
72 | } |
73 | vecrap.Normalize(); |
74 | vecrap *= (dist+aRadius); |
75 | gp_Pnt OppositePoint = pt1.Translated(vecrap); |
76 | |
77 | |
78 | Graphic3d_Array1OfVertex V(1,2); |
79 | Quantity_Length X,Y,Z; |
80 | pt1.Coord(X,Y,Z); |
81 | V(1).SetCoord(X,Y,Z); |
82 | OppositePoint.Coord(X,Y,Z); |
83 | V(2).SetCoord(X,Y,Z); |
84 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(V); |
85 | |
86 | // value |
87 | TCollection_ExtendedString Text = aText; |
88 | if(IsDiamSymbol) |
89 | Text = TCollection_ExtendedString("\330 ") + aText; // VRO (2007-05-17) inserted a blank. |
90 | Prs3d_Text::Draw(aPresentation, LA->TextAspect(), Text, AttachmentPoint); |
91 | |
92 | // arrows |
93 | |
94 | gp_Dir arrdir (vecrap); |
95 | if (inside) arrdir.Reverse(); |
96 | |
97 | |
98 | gp_Vec vecrap2 = vecrap; |
99 | gp_Pnt ptoncirc2 = ptoncirc; |
100 | gp_Dir arrdir2 = arrdir; |
101 | vecrap2.Normalize(); |
102 | vecrap2 *= (aCircle.Radius() * 2.); |
103 | ptoncirc2.Translate (vecrap2); |
104 | arrdir2.Reverse(); |
105 | |
106 | DsgPrs::ComputeSymbol(aPresentation,LA,ptoncirc,ptoncirc2,arrdir,arrdir2,ArrowPrs); |
107 | } |
108 | |
109 | |
110 | static Standard_Boolean DsgPrs_InDomain(const Standard_Real fpar, |
111 | const Standard_Real lpar, |
112 | const Standard_Real para) |
113 | { |
114 | if (fpar >= 0.) { |
115 | if(lpar > fpar) |
116 | return ((para >= fpar) && (para <= lpar)); |
117 | else { // fpar > lpar |
118 | Standard_Real delta = 2*PI-fpar; |
119 | Standard_Real lp, par, fp; |
120 | lp = lpar + delta; |
121 | par = para + delta; |
122 | while(lp > 2*PI) lp-=2*PI; |
123 | while(par > 2*PI) par-=2*PI; |
124 | fp = 0.; |
125 | return ((par >= fp) && (par <= lp)); |
126 | } |
127 | |
128 | } |
129 | if (para >= (fpar+2*PI)) return Standard_True; |
130 | if (para <= lpar) return Standard_True; |
131 | return Standard_False; |
132 | } |
133 | |
134 | |
135 | //======================================================================= |
136 | //function : DsgPrs_DiameterPresentation::Add |
137 | //purpose : SZY 12-february-98 |
138 | //======================================================================= |
139 | |
140 | void DsgPrs_DiameterPresentation::Add (const Handle(Prs3d_Presentation)& aPresentation, |
141 | const Handle(Prs3d_Drawer)& aDrawer, |
142 | const TCollection_ExtendedString& aText, |
143 | const gp_Pnt& AttachmentPoint, |
144 | const gp_Circ& aCircle, |
145 | const Standard_Real uFirst, |
146 | const Standard_Real uLast, |
147 | const DsgPrs_ArrowSide ArrowPrs,//ArrowSide |
148 | const Standard_Boolean IsDiamSymbol ) |
149 | { |
150 | Standard_Real fpara = uFirst; |
151 | Standard_Real lpara = uLast; |
152 | while (lpara > 2*PI) { |
153 | fpara -= 2*PI; |
154 | lpara -= 2*PI; |
155 | } |
156 | |
157 | Handle(Prs3d_LengthAspect) LA = aDrawer->LengthAspect(); |
158 | // Handle(Prs3d_TextAspect) TA = aDrawer->TextAspect(); |
159 | Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(LA->LineAspect()->Aspect()); |
160 | // AspectText3d from Graphic3d |
161 | Standard_Real parEndOfArrow = ElCLib::Parameter(aCircle,AttachmentPoint); // |
162 | gp_Pnt EndOfArrow; |
163 | gp_Pnt DrawPosition = AttachmentPoint;// attachment point |
164 | Standard_Boolean otherside = Standard_False; |
165 | |
166 | gp_Pnt Center = aCircle.Location(); |
167 | gp_Pnt FirstPoint = ElCLib::Value(uFirst, aCircle); |
168 | gp_Pnt SecondPoint = ElCLib::Value(uLast, aCircle); |
169 | |
170 | if ( !DsgPrs_InDomain(fpara,lpara,parEndOfArrow)) { |
171 | Standard_Real otherpar = parEndOfArrow + PI;// not in domain |
172 | if (otherpar > 2*PI) otherpar -= 2*PI; |
173 | if (DsgPrs_InDomain(fpara,lpara,otherpar)) { |
174 | parEndOfArrow = otherpar; // parameter on circle |
175 | EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle); |
176 | otherside = Standard_True; |
177 | } |
178 | else { |
179 | gp_Dir dir1(gp_Vec(Center, FirstPoint)); |
180 | gp_Dir dir2(gp_Vec(Center, SecondPoint)); |
181 | gp_Lin L1( Center, dir1 ); |
182 | gp_Lin L2( Center, dir2 ); |
183 | if(L1.Distance(AttachmentPoint) < L2.Distance(AttachmentPoint)) |
184 | { |
185 | EndOfArrow = FirstPoint; //*** |
186 | DrawPosition = ElCLib::Value(ElCLib::Parameter( L1, AttachmentPoint ), L1); |
187 | } |
188 | else |
189 | { |
190 | EndOfArrow = SecondPoint; //*** |
191 | DrawPosition = ElCLib::Value(ElCLib::Parameter( L2, AttachmentPoint ), L2); |
192 | } |
193 | } |
194 | // EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle); |
195 | // DrawPosition = AttachmentPoint; |
196 | } |
197 | else { |
198 | EndOfArrow = ElCLib::Value(parEndOfArrow, aCircle); |
199 | DrawPosition = AttachmentPoint; |
200 | } |
201 | Graphic3d_Array1OfVertex Vrap(1,2); |
202 | |
203 | Quantity_Length X,Y,Z; |
204 | |
205 | DrawPosition.Coord(X,Y,Z); |
206 | Vrap(1).SetCoord(X,Y,Z); |
207 | |
208 | EndOfArrow.Coord(X,Y,Z); |
209 | Vrap(2).SetCoord(X,Y,Z); |
210 | |
211 | Prs3d_Root::CurrentGroup(aPresentation)->Polyline(Vrap); |
212 | |
213 | // text |
214 | TCollection_ExtendedString Text = aText; |
215 | if(IsDiamSymbol) |
216 | Text = TCollection_ExtendedString("\330 ") + Text;// => \330 | \370? |
217 | Prs3d_Text::Draw(aPresentation,LA->TextAspect(),Text,DrawPosition); |
218 | |
219 | // Add presentation of arrow |
220 | gp_Dir DirOfArrow(gp_Vec(DrawPosition, EndOfArrow).XYZ()); |
221 | DsgPrs::ComputeSymbol(aPresentation, LA, EndOfArrow, EndOfArrow, DirOfArrow, DirOfArrow, ArrowPrs); |
222 | |
223 | } |