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