b311480e |
1 | // Created on: 1997-03-13 |
2 | // Created by: Prestataire Mary FABIEN |
3 | // Copyright (c) 1997-1999 Matra Datavision |
4 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | // |
6 | // The content of this file is subject to the Open CASCADE Technology Public |
7 | // License Version 6.5 (the "License"). You may not use the content of this file |
8 | // except in compliance with the License. Please obtain a copy of the License |
9 | // at http://www.opencascade.org and read it completely before using this file. |
10 | // |
11 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | // |
14 | // The Original Code and all software distributed under the License is |
15 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | // Initial Developer hereby disclaims all such warranties, including without |
17 | // limitation, any warranties of merchantability, fitness for a particular |
18 | // purpose or non-infringement. Please see the License for the specific terms |
19 | // and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | #include <TestTopOpeDraw_DrawableMesure.ixx> |
24 | #include <TestTopOpeDraw_DrawableMesure.hxx> |
25 | #include <TestTopOpeDraw_DrawableP3D.hxx> |
26 | #include <TestTopOpeTools_Mesure.hxx> |
27 | #include <Geom_Curve.hxx> |
28 | #include <TopOpeBRepTool_CurveTool.hxx> |
29 | #include <Standard_CString.hxx> |
30 | #include <TColgp_Array1OfPnt.hxx> |
31 | #include <TColgp_HArray1OfPnt.hxx> |
32 | #include <string.h> |
33 | #include <Draw_Interpretor.hxx> |
34 | |
35 | |
36 | static gp_Pnt PScale(const gp_Pnt& P, |
37 | const Standard_Real ScaleX, |
38 | const Standard_Real ScaleY) |
39 | { |
40 | gp_Pnt Pnt; |
41 | Pnt.SetX(P.X() * ScaleX); |
42 | Pnt.SetY(P.Y() * ScaleY); |
43 | Pnt.SetZ(0.); |
44 | return Pnt; |
45 | } |
46 | |
47 | static TColgp_Array1OfPnt& Scale(const TColgp_Array1OfPnt& AP, |
48 | const Standard_Real ScaleX, |
49 | const Standard_Real ScaleY) |
50 | { |
51 | Standard_Integer i,up = AP.Upper(); |
52 | TColgp_Array1OfPnt *aAP = new TColgp_Array1OfPnt(1, up); |
53 | for (i = 1; i <= up;i++) { |
54 | aAP->SetValue(i, PScale(AP.Value(i), ScaleX, ScaleY)); |
55 | } |
56 | return *aAP; |
57 | } |
58 | |
59 | Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M, |
60 | Handle(TColgp_HArray1OfPnt) T) |
61 | |
62 | { |
63 | Standard_Integer up = T->Upper(); |
64 | TColgp_Array1OfPnt& AOP = T->ChangeArray1(); |
65 | const TColgp_Array1OfPnt& MAOP = M.Pnts(); |
66 | for(Standard_Integer i= 1; i <= up; i++) { |
67 | AOP.SetValue(i,MAOP.Value(i)); |
68 | } |
69 | return T; |
70 | } |
71 | |
72 | Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M) |
73 | |
74 | { |
75 | Standard_Integer up = M.NPnts(); |
76 | Handle(TColgp_HArray1OfPnt) T = new TColgp_HArray1OfPnt(1,up); |
77 | TColgp_Array1OfPnt& AOP = T->ChangeArray1(); |
78 | const TColgp_Array1OfPnt& MAOP = M.Pnts(); |
79 | for(Standard_Integer i= 1; i <= up; i++) { |
80 | AOP.SetValue(i,MAOP.Value(i)); |
81 | } |
82 | return T; |
83 | } |
84 | |
85 | Handle(Geom_Curve) makecurvescale (const Handle(TColgp_HArray1OfPnt)& HP, |
86 | const Standard_Real ScaleX, |
87 | const Standard_Real ScaleY) |
88 | { |
89 | Handle(Geom_Curve) C; |
90 | C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(Scale(HP->Array1(),ScaleX,ScaleY)); |
91 | return C; |
92 | } |
93 | |
94 | Handle(Geom_Curve) makecurve(const Handle(TColgp_HArray1OfPnt)& HP) |
95 | { |
96 | Handle(Geom_Curve) C; |
97 | C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(HP->Array1()); |
98 | return C; |
99 | } |
100 | |
101 | |
102 | static Standard_CString makename(const TCollection_AsciiString C) |
103 | { |
104 | char * temp = new char[C.Length()+2]; |
105 | temp[0] = ' ' ; |
106 | temp[C.Length()+1] = 0; |
107 | strncpy(&temp[1], C.ToCString(), C.Length()); |
108 | return temp; |
109 | } |
110 | |
111 | static Standard_CString makename1(const gp_Pnt& P) |
112 | { |
113 | TCollection_AsciiString C((Standard_Integer)P.Coord(1)); |
114 | |
115 | char * temp = new char[C.Length()+2]; |
116 | temp[0]=' '; |
117 | temp[C.Length()+1]=0; |
118 | strncpy(&temp[1], C.ToCString(), C.Length()); |
119 | return temp; |
120 | } |
121 | |
122 | static Standard_CString makename2(const gp_Pnt& P) |
123 | { |
124 | TCollection_AsciiString C; |
125 | |
126 | C = "";C = C + P.Coord(2); |
127 | TCollection_AsciiString S1 = C.Token(".",1); |
7fd59977 |
128 | S1.RightJustify(15, ' '); |
129 | TCollection_AsciiString S2 = C.Token(".",2); |
130 | S2.Trunc(2); |
131 | C = " ";C = C + S1 + "." + S2; |
132 | |
133 | char * temp = new char[C.Length()+1]; |
134 | temp[C.Length()]=0; |
135 | strncpy(&temp[0], C.ToCString(), C.Length()); |
136 | return temp; |
137 | } |
138 | |
7fd59977 |
139 | static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T, |
140 | const Standard_Real ScaleX) |
141 | { |
142 | Standard_Integer up = T.Upper(); |
143 | TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up); |
144 | for(Standard_Integer i= 1; i <= up; i++) { |
145 | gp_Pnt pnt(T.Value(i).Coord(1) * ScaleX, 0, 0); |
146 | (*AOP).SetValue(i, pnt); |
147 | } |
148 | Handle(Geom_Curve) C; |
149 | C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP); |
150 | return C; |
151 | } |
152 | |
153 | static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T, |
154 | const Standard_Real ScaleY) |
155 | { |
156 | Standard_Integer up = T.Upper(); |
157 | TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up); |
158 | for(Standard_Integer i= 1; i <= up; i++) { |
159 | gp_Pnt pnt(0, T.Value(i).Coord(2) * ScaleY, 0); |
160 | (*AOP).SetValue(i, pnt); |
161 | } |
162 | Handle(Geom_Curve) C; |
163 | C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP); |
164 | return C; |
165 | } |
166 | |
167 | //======================================================================= |
168 | //function : TestTopOpeDraw_DrawableMesure |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | TestTopOpeDraw_DrawableMesure::TestTopOpeDraw_DrawableMesure |
173 | (const TestTopOpeTools_Mesure& M, |
174 | const Draw_Color& CurveColor, |
175 | const Draw_Color& TextColor, |
176 | const Standard_Real ScaleX, |
177 | const Standard_Real ScaleY) : |
178 | TestTopOpeDraw_DrawableC3D(::makecurvescale(makepnt(M),ScaleX,ScaleY), |
179 | CurveColor, ::makename(M.Name()) |
180 | , TextColor) |
181 | ,myP(makepnt(M)) |
182 | ,myAXE1(new TestTopOpeDraw_DrawableC3D(DrawAxe1(myP->Array1(), ScaleX), |
183 | Draw_saumon)) |
184 | ,myAXE2(new TestTopOpeDraw_DrawableC3D(DrawAxe2(myP->Array1(), ScaleY), |
185 | Draw_saumon)) |
186 | ,myScaleX(ScaleX) |
187 | ,myScaleY(ScaleY) |
188 | { |
189 | Standard_Integer up = myP->Upper(), i; |
190 | myHDP = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up); |
191 | myHADP1 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up); |
192 | myHADP2 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up); |
193 | for(i = 1; i <= up; i++) { |
194 | Handle(TestTopOpeDraw_DrawableP3D) DP |
195 | = new TestTopOpeDraw_DrawableP3D(PScale(myP->Value(i), ScaleX, ScaleY), |
196 | Draw_rouge); |
197 | myHDP->SetValue(i,DP); |
198 | gp_Pnt PA1(myP->Value(i).Coord(1), 0, 0); |
199 | gp_Pnt PA1Sc(myP->Value(i).Coord(1) * ScaleX, 0, 0); |
200 | Handle(TestTopOpeDraw_DrawableP3D) DPA1 |
201 | = new TestTopOpeDraw_DrawableP3D(PA1Sc,Draw_rose, |
202 | makename1(PA1),Draw_rose,-7,15); |
203 | myHADP1->SetValue(i,DPA1); |
204 | gp_Pnt PA2(0,myP->Value(i).Coord(2), 0); |
205 | gp_Pnt PA2Sc(0,myP->Value(i).Coord(2) * myScaleY, 0); |
206 | Handle(TestTopOpeDraw_DrawableP3D) DPA2 |
207 | = new TestTopOpeDraw_DrawableP3D(PA2Sc,Draw_rose, |
208 | makename2(PA2),Draw_rose,-120,5); |
209 | myHADP2->SetValue(i,DPA2); |
210 | } |
211 | } |
212 | |
213 | //======================================================================= |
214 | //function : SetScaleX |
215 | //purpose : |
216 | //======================================================================= |
217 | |
218 | void TestTopOpeDraw_DrawableMesure::SetScaleX(const Standard_Real ScaleX) |
219 | { |
220 | SetScale(ScaleX, myScaleY); |
221 | } |
222 | |
223 | //======================================================================= |
224 | //function : SetScaleY |
225 | //purpose : |
226 | //======================================================================= |
227 | |
228 | void TestTopOpeDraw_DrawableMesure::SetScaleY(const Standard_Real ScaleY) |
229 | { |
230 | SetScale(myScaleX, ScaleY); |
231 | } |
232 | |
233 | //======================================================================= |
234 | //function : SetScale |
235 | //purpose : |
236 | //======================================================================= |
237 | |
238 | void TestTopOpeDraw_DrawableMesure::SetScale(const Standard_Real ScaleX, |
239 | const Standard_Real ScaleY) |
240 | { |
241 | myScaleX = ScaleX; |
242 | myScaleY = ScaleY; |
243 | Handle(Geom_Curve) GC = ::makecurvescale(myP, myScaleX, myScaleY); |
244 | ChangeCurve(GC); |
245 | ChangePnt(Pnt()); |
246 | GC = DrawAxe1(myP->Array1(), myScaleX); |
247 | myAXE1->ChangeCurve(GC); |
248 | myAXE1->ChangePnt(Pnt()); |
249 | GC = DrawAxe2(myP->Array1(), myScaleY); |
250 | myAXE2->ChangeCurve(GC); |
251 | myAXE2->ChangePnt(Pnt()); |
252 | Standard_Integer up = myP->Upper(), i; |
253 | for(i = 1; i <= up; i++) { |
254 | Handle(TestTopOpeDraw_DrawableP3D) DP = myHDP->Value(i); |
255 | gp_Pnt P = PScale(myP->Value(i), myScaleX, myScaleY); |
256 | DP->ChangePnt(P); |
257 | myHDP->SetValue(i,DP); |
258 | |
259 | Handle(TestTopOpeDraw_DrawableP3D) DPA1 = myHADP1->Value(i); |
260 | gp_Pnt PA1(myP->Value(i).Coord(1) * myScaleX, 0, 0); |
261 | DPA1->ChangePnt(PA1); |
262 | myHADP1->SetValue(i,DPA1); |
263 | |
264 | Handle(TestTopOpeDraw_DrawableP3D) DPA2 = myHADP2->Value(i); |
265 | gp_Pnt PA2(0, myP->Value(i).Coord(2) * myScaleY, 0); |
266 | DPA2->ChangePnt(PA2); |
267 | myHADP2->SetValue(i,DPA2); |
268 | } |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : Pnt |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | gp_Pnt TestTopOpeDraw_DrawableMesure::Pnt() const |
277 | { |
278 | const Handle(Geom_Curve)& GC = DrawTrSurf_Curve::GetCurve(); |
279 | Standard_Real f = GC->FirstParameter(); |
280 | Standard_Real l = GC->LastParameter(); |
281 | Standard_Real t = 0.; |
282 | Standard_Real p = t*f + (1-t)*l; |
283 | gp_Pnt P = GC->Value(p); |
284 | return P; |
285 | } |
286 | |
287 | //======================================================================= |
288 | //function : Pnts |
289 | //purpose : |
290 | //======================================================================= |
291 | |
292 | const Handle(TColgp_HArray1OfPnt)& TestTopOpeDraw_DrawableMesure::Pnts() const |
293 | { |
294 | return myP; |
295 | } |
296 | |
297 | //======================================================================= |
298 | //function : SetName |
299 | //purpose : |
300 | //======================================================================= |
301 | |
302 | void TestTopOpeDraw_DrawableMesure::SetName(const TCollection_AsciiString& Name) |
303 | { |
304 | Standard_CString Str = makename(Name); |
305 | ChangeText(Str); |
306 | } |
307 | |
308 | //======================================================================= |
309 | //function : Clear |
310 | //purpose : |
311 | //======================================================================= |
312 | |
313 | void TestTopOpeDraw_DrawableMesure::Clear() |
314 | { |
315 | myScaleX = 1; |
316 | myScaleY = 1; |
317 | |
318 | } |
319 | |
320 | //======================================================================= |
321 | //function : Whatis |
322 | //purpose : |
323 | //======================================================================= |
324 | |
325 | void TestTopOpeDraw_DrawableMesure::Whatis(Draw_Interpretor& s)const |
326 | { |
327 | if (!myP.IsNull()) |
328 | s << "DrawableMesure"; |
329 | } |
330 | |
331 | //======================================================================= |
332 | //function : DrawOn |
333 | //purpose : |
334 | //======================================================================= |
335 | |
336 | void TestTopOpeDraw_DrawableMesure::DrawOn(Draw_Display& dis) const |
337 | { |
338 | Standard_Integer i,n; |
339 | |
340 | // les axes |
341 | n = myHADP1->Upper(); |
342 | myAXE1->DrawOn(dis); |
343 | for(i = 1; i <= n; i++) { |
344 | myHADP1->Value(i)->DrawOn(dis); |
345 | } |
346 | |
347 | myAXE2->DrawOn(dis); |
348 | n = myHADP2->Upper(); |
349 | for(i = 1; i <= n; i++) { |
350 | myHADP2->Value(i)->DrawOn(dis); |
351 | } |
352 | |
353 | // la courbe et ses points |
354 | TestTopOpeDraw_DrawableC3D::DrawOn(dis); |
355 | n = myHDP->Upper(); |
356 | for(i = 1; i <= n; i++) { |
357 | myHDP->Value(i)->DrawOn(dis); |
358 | myHADP1->Value(i)->DrawOn(dis); |
359 | myHADP2->Value(i)->DrawOn(dis); |
360 | } |
361 | } |