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
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.
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.
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.
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>
33 #include <Draw_Interpretor.hxx>
36 static gp_Pnt PScale(const gp_Pnt& P,
37 const Standard_Real ScaleX,
38 const Standard_Real ScaleY)
41 Pnt.SetX(P.X() * ScaleX);
42 Pnt.SetY(P.Y() * ScaleY);
47 static TColgp_Array1OfPnt& Scale(const TColgp_Array1OfPnt& AP,
48 const Standard_Real ScaleX,
49 const Standard_Real ScaleY)
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));
59 Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M,
60 Handle(TColgp_HArray1OfPnt) T)
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));
72 Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M)
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));
85 Handle(Geom_Curve) makecurvescale (const Handle(TColgp_HArray1OfPnt)& HP,
86 const Standard_Real ScaleX,
87 const Standard_Real ScaleY)
90 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(Scale(HP->Array1(),ScaleX,ScaleY));
94 Handle(Geom_Curve) makecurve(const Handle(TColgp_HArray1OfPnt)& HP)
97 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(HP->Array1());
102 static Standard_CString makename(const TCollection_AsciiString C)
104 char * temp = new char[C.Length()+2];
106 temp[C.Length()+1] = 0;
107 strncpy(&temp[1], C.ToCString(), C.Length());
111 static Standard_CString makename1(const gp_Pnt& P)
113 TCollection_AsciiString C((Standard_Integer)P.Coord(1));
115 char * temp = new char[C.Length()+2];
117 temp[C.Length()+1]=0;
118 strncpy(&temp[1], C.ToCString(), C.Length());
122 static Standard_CString makename2(const gp_Pnt& P)
124 TCollection_AsciiString C;
126 C = "";C = C + P.Coord(2);
127 TCollection_AsciiString S1 = C.Token(".",1);
128 S1.RightJustify(15, ' ');
129 TCollection_AsciiString S2 = C.Token(".",2);
131 C = " ";C = C + S1 + "." + S2;
133 char * temp = new char[C.Length()+1];
135 strncpy(&temp[0], C.ToCString(), C.Length());
139 static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T,
140 const Standard_Real ScaleX)
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);
148 Handle(Geom_Curve) C;
149 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
153 static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T,
154 const Standard_Real ScaleY)
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);
162 Handle(Geom_Curve) C;
163 C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
167 //=======================================================================
168 //function : TestTopOpeDraw_DrawableMesure
170 //=======================================================================
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())
182 ,myAXE1(new TestTopOpeDraw_DrawableC3D(DrawAxe1(myP->Array1(), ScaleX),
184 ,myAXE2(new TestTopOpeDraw_DrawableC3D(DrawAxe2(myP->Array1(), ScaleY),
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),
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);
213 //=======================================================================
214 //function : SetScaleX
216 //=======================================================================
218 void TestTopOpeDraw_DrawableMesure::SetScaleX(const Standard_Real ScaleX)
220 SetScale(ScaleX, myScaleY);
223 //=======================================================================
224 //function : SetScaleY
226 //=======================================================================
228 void TestTopOpeDraw_DrawableMesure::SetScaleY(const Standard_Real ScaleY)
230 SetScale(myScaleX, ScaleY);
233 //=======================================================================
234 //function : SetScale
236 //=======================================================================
238 void TestTopOpeDraw_DrawableMesure::SetScale(const Standard_Real ScaleX,
239 const Standard_Real ScaleY)
243 Handle(Geom_Curve) GC = ::makecurvescale(myP, myScaleX, myScaleY);
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);
257 myHDP->SetValue(i,DP);
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);
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);
271 //=======================================================================
274 //=======================================================================
276 gp_Pnt TestTopOpeDraw_DrawableMesure::Pnt() const
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);
287 //=======================================================================
290 //=======================================================================
292 const Handle(TColgp_HArray1OfPnt)& TestTopOpeDraw_DrawableMesure::Pnts() const
297 //=======================================================================
300 //=======================================================================
302 void TestTopOpeDraw_DrawableMesure::SetName(const TCollection_AsciiString& Name)
304 Standard_CString Str = makename(Name);
308 //=======================================================================
311 //=======================================================================
313 void TestTopOpeDraw_DrawableMesure::Clear()
320 //=======================================================================
323 //=======================================================================
325 void TestTopOpeDraw_DrawableMesure::Whatis(Draw_Interpretor& s)const
328 s << "DrawableMesure";
331 //=======================================================================
334 //=======================================================================
336 void TestTopOpeDraw_DrawableMesure::DrawOn(Draw_Display& dis) const
338 Standard_Integer i,n;
341 n = myHADP1->Upper();
343 for(i = 1; i <= n; i++) {
344 myHADP1->Value(i)->DrawOn(dis);
348 n = myHADP2->Upper();
349 for(i = 1; i <= n; i++) {
350 myHADP2->Value(i)->DrawOn(dis);
353 // la courbe et ses points
354 TestTopOpeDraw_DrawableC3D::DrawOn(dis);
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);