1 // Created on: 1997-03-13
2 // Created by: Prestataire Mary FABIEN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Draw_Color.hxx>
19 #include <Draw_Display.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <Geom_Curve.hxx>
23 #include <Standard_CString.hxx>
24 #include <Standard_Type.hxx>
25 #include <TColgp_Array1OfPnt.hxx>
26 #include <TColgp_HArray1OfPnt.hxx>
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>
35 IMPLEMENT_STANDARD_RTTIEXT(TestTopOpeDraw_DrawableMesure,TestTopOpeDraw_DrawableC3D)
37 static gp_Pnt PScale(const gp_Pnt& P,
38 const Standard_Real ScaleX,
39 const Standard_Real ScaleY)
42 Pnt.SetX(P.X() * ScaleX);
43 Pnt.SetY(P.Y() * ScaleY);
48 static TColgp_Array1OfPnt& Scale(const TColgp_Array1OfPnt& AP,
49 const Standard_Real ScaleX,
50 const Standard_Real ScaleY)
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));
60 Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M,
61 Handle(TColgp_HArray1OfPnt) T)
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));
73 Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M)
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));
86 Handle(Geom_Curve) makecurvescale (const Handle(TColgp_HArray1OfPnt)& HP,
87 const Standard_Real ScaleX,
88 const Standard_Real ScaleY)
91 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(Scale(HP->Array1(),ScaleX,ScaleY));
95 Handle(Geom_Curve) makecurve(const Handle(TColgp_HArray1OfPnt)& HP)
98 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(HP->Array1());
103 static Standard_CString makename(const TCollection_AsciiString C)
105 char * temp = new char[C.Length()+2];
107 temp[C.Length()+1] = 0;
108 strncpy(&temp[1], C.ToCString(), C.Length());
112 static Standard_CString makename1(const gp_Pnt& P)
114 TCollection_AsciiString C((Standard_Integer)P.Coord(1));
116 char * temp = new char[C.Length()+2];
118 temp[C.Length()+1]=0;
119 strncpy(&temp[1], C.ToCString(), C.Length());
123 static Standard_CString makename2(const gp_Pnt& P)
125 TCollection_AsciiString C;
127 C = "";C = C + P.Coord(2);
128 TCollection_AsciiString S1 = C.Token(".",1);
129 S1.RightJustify(15, ' ');
130 TCollection_AsciiString S2 = C.Token(".",2);
132 C = " ";C = C + S1 + "." + S2;
134 char * temp = new char[C.Length()+1];
136 strncpy(&temp[0], C.ToCString(), C.Length());
140 static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T,
141 const Standard_Real ScaleX)
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);
149 Handle(Geom_Curve) C;
150 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
154 static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T,
155 const Standard_Real ScaleY)
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);
163 Handle(Geom_Curve) C;
164 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
168 //=======================================================================
169 //function : TestTopOpeDraw_DrawableMesure
171 //=======================================================================
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())
183 ,myAXE1(new TestTopOpeDraw_DrawableC3D(DrawAxe1(myP->Array1(), ScaleX),
185 ,myAXE2(new TestTopOpeDraw_DrawableC3D(DrawAxe2(myP->Array1(), ScaleY),
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),
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);
214 //=======================================================================
215 //function : SetScaleX
217 //=======================================================================
219 void TestTopOpeDraw_DrawableMesure::SetScaleX(const Standard_Real ScaleX)
221 SetScale(ScaleX, myScaleY);
224 //=======================================================================
225 //function : SetScaleY
227 //=======================================================================
229 void TestTopOpeDraw_DrawableMesure::SetScaleY(const Standard_Real ScaleY)
231 SetScale(myScaleX, ScaleY);
234 //=======================================================================
235 //function : SetScale
237 //=======================================================================
239 void TestTopOpeDraw_DrawableMesure::SetScale(const Standard_Real ScaleX,
240 const Standard_Real ScaleY)
244 Handle(Geom_Curve) GC = ::makecurvescale(myP, myScaleX, myScaleY);
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);
258 myHDP->SetValue(i,DP);
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);
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);
272 //=======================================================================
275 //=======================================================================
277 gp_Pnt TestTopOpeDraw_DrawableMesure::Pnt() const
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);
288 //=======================================================================
291 //=======================================================================
293 const Handle(TColgp_HArray1OfPnt)& TestTopOpeDraw_DrawableMesure::Pnts() const
298 //=======================================================================
301 //=======================================================================
303 void TestTopOpeDraw_DrawableMesure::SetName(const TCollection_AsciiString& Name)
305 Standard_CString Str = makename(Name);
309 //=======================================================================
312 //=======================================================================
314 void TestTopOpeDraw_DrawableMesure::Clear()
321 //=======================================================================
324 //=======================================================================
326 void TestTopOpeDraw_DrawableMesure::Whatis(Draw_Interpretor& s)const
329 s << "DrawableMesure";
332 //=======================================================================
335 //=======================================================================
337 void TestTopOpeDraw_DrawableMesure::DrawOn(Draw_Display& dis) const
339 Standard_Integer i,n;
342 n = myHADP1->Upper();
344 for(i = 1; i <= n; i++) {
345 myHADP1->Value(i)->DrawOn(dis);
349 n = myHADP2->Upper();
350 for(i = 1; i <= n; i++) {
351 myHADP2->Value(i)->DrawOn(dis);
354 // la courbe et ses points
355 TestTopOpeDraw_DrawableC3D::DrawOn(dis);
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);