1 // Created on: 1996-10-09
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1996-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 <GeometryTest.ixx>
26 #include <DrawTrSurf.hxx>
27 #include <DrawTrSurf_Point.hxx>
28 #include <gp_Pnt2d.hxx>
29 #include <FairCurve_AnalysisCode.hxx>
30 #include <FairCurve_Batten.hxx>
31 #include <FairCurve_MinimalVariation.hxx>
32 #include <DrawFairCurve_Batten.hxx>
33 #include <DrawFairCurve_MinimalVariation.hxx>
36 //=======================================================================
37 Standard_Boolean IsGoodNumber(Standard_Integer argc, Standard_Integer waiting, Draw_Interpretor& di)
38 //=======================================================================
40 // argc vaut 1 de plus, puisque argv[0] contient le nom de la commande
41 if (argc != (waiting+1))
43 di << "Waiting "<< waiting << " arguments" << "\n";
44 return Standard_False;
51 //=======================================================================
52 static Standard_Integer
53 BattenCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
54 //=======================================================================
56 if (!IsGoodNumber(argc,6,di)) return 1;
58 const char *cp1 = argv[1];
59 const char *cp2 = argv[2];
60 const char *cangle1 = argv[3];
61 const char *cangle2 = argv[4];
62 const char *cheigth = argv[5];
63 const char *BattenName = argv[6];
66 FairCurve_AnalysisCode Iana;
67 Standard_Real a1 = Draw::Atof(cangle1),
68 a2 = Draw::Atof(cangle2),
69 h = Draw::Atof(cheigth);
73 if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
74 if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;
76 FairCurve_Batten* Bat = new FairCurve_Batten (P1, P2, h);
77 Bat->SetAngle1(a1*M_PI/180);
78 Bat->SetAngle2(a2*M_PI/180);
80 Ok = Bat->Compute(Iana);
82 Handle(DrawFairCurve_Batten) aBatten = new DrawFairCurve_Batten(Bat);
84 if (aBatten.IsNull()) {
85 di << " Batten null "<< "\n";
88 Draw::Set(BattenName,aBatten);
91 // !!! Delete of Bat have to be make in DrawFairCurve_Batten destructor !!!!!
95 //=======================================================================
96 static Standard_Integer
97 MVCurve(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
98 //=======================================================================
100 if (!IsGoodNumber(argc,6,di)) return 1;
102 const char *cp1 = argv[1];
103 const char *cp2 = argv[2];
104 const char *cangle1 = argv[3];
105 const char *cangle2 = argv[4];
106 const char *cheigth = argv[5];
107 const char *MVCName = argv[6];
110 FairCurve_AnalysisCode Iana;
111 Standard_Real a1 = Draw::Atof(cangle1),
112 a2 = Draw::Atof(cangle2),
113 h = Draw::Atof(cheigth);
117 if (! DrawTrSurf::GetPoint2d(cp1, P1) ) return 1;
118 if (! DrawTrSurf::GetPoint2d(cp2, P2) ) return 1;
120 FairCurve_MinimalVariation* MVC = new FairCurve_MinimalVariation (P1, P2, h);
121 MVC->SetAngle1(a1*M_PI/180);
122 MVC->SetAngle2(a2*M_PI/180);
124 Ok = MVC->Compute(Iana);
126 Handle(DrawFairCurve_MinimalVariation) aMVC = new DrawFairCurve_MinimalVariation(MVC);
129 di << " MVC null "<< "\n";
132 Draw::Set(MVCName, aMVC);
135 // !!! Delete of Bat have to be make in DrawFairCurve_MinimalVariation destructor !!!!!
138 //=======================================================================
139 static Standard_Integer
140 SetPoint(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
141 //=======================================================================
143 if (!IsGoodNumber(argc,3,di)) return 1;
145 const char *side = argv[1];
146 const char *PointName = argv[2];
147 const char *BattenName = argv[3];
149 Standard_Integer cote = Draw::Atoi(side);
151 Handle(DrawTrSurf_Point)
152 Pnt = Handle(DrawTrSurf_Point)::DownCast(Draw::Get(PointName));
153 if (Pnt.IsNull()) return 1;
156 Handle(DrawFairCurve_Batten)
157 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
158 if (Bat.IsNull()) return 1;
160 Bat->SetPoint(cote, Pnt->Point2d());
165 //=======================================================================
166 static Standard_Integer
167 SetAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
168 //=======================================================================
170 if (!IsGoodNumber(argc,3,di)) return 1;
172 const char *side = argv[1];
173 const char *val = argv[2];
174 const char *BattenName = argv[3];
176 Standard_Real angle = Draw::Atof(val);
177 Standard_Integer cote = Draw::Atoi(side);
179 Handle(DrawFairCurve_Batten)
180 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
181 if (Bat.IsNull()) return 1;
183 Bat->SetAngle(cote, angle);
189 //=======================================================================
190 static Standard_Integer
191 SetCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
192 //=======================================================================
194 if (!IsGoodNumber(argc,3,di)) return 1;
196 const char *side = argv[1];
197 const char *val = argv[2];
198 const char *MVCName = argv[3];
200 Standard_Real rho = Draw::Atof(val);
201 Standard_Integer cote = Draw::Atoi(side);
203 Handle(DrawFairCurve_MinimalVariation)
204 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
205 if (MVC.IsNull()) return 1;
207 MVC->SetCurvature(cote, rho);
214 //=======================================================================
215 static Standard_Integer
216 SetSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
217 //=======================================================================
219 if (!IsGoodNumber(argc,2,di)) return 1;
221 const char *val = argv[1];
222 const char *BattenName = argv[2];
224 Standard_Real slide = Draw::Atof(val);
226 Handle(DrawFairCurve_Batten)
227 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
228 if (Bat.IsNull()) return 1;
230 Bat->SetSliding(slide);
236 //=======================================================================
237 static Standard_Integer
238 FreeAngle(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
239 //=======================================================================
241 if (!IsGoodNumber(argc,2,di)) return 1;
243 const char *side = argv[1];
244 const char *BattenName = argv[2];
246 Standard_Integer cote = Draw::Atoi(side);
248 Handle(DrawFairCurve_Batten)
249 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
250 if (Bat.IsNull()) return 1;
252 Bat->FreeAngle(cote);
257 //=======================================================================
258 static Standard_Integer
259 FreeCurvature(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
260 //=======================================================================
262 if (!IsGoodNumber(argc,2,di)) return 1;
264 const char *side = argv[1];
265 const char *MVCName = argv[2];
267 Standard_Integer cote = Draw::Atoi(side);
269 Handle(DrawFairCurve_MinimalVariation)
270 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
271 if (MVC.IsNull()) return 1;
273 MVC->FreeCurvature(cote);
278 //=======================================================================
279 static Standard_Integer
280 FreeSlide(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
281 //=======================================================================
283 if (!IsGoodNumber(argc,1,di)) return 1;
285 const char *BattenName = argv[1];
287 Handle(DrawFairCurve_Batten)
288 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
289 if (Bat.IsNull()) return 1;
296 //=======================================================================
297 static Standard_Integer
298 SetHeight(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
299 //=======================================================================
301 if (!IsGoodNumber(argc,2,di)) return 1;
303 const char *val = argv[1];
304 const char *BattenName = argv[2];
306 Standard_Real Height = Draw::Atof(val);
308 Handle(DrawFairCurve_Batten)
309 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
310 if (Bat.IsNull()) return 1;
312 Bat->SetHeight(Height);
317 //=======================================================================
318 static Standard_Integer
319 SetSlope(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
320 //=======================================================================
322 if (!IsGoodNumber(argc,2,di)) return 1;
324 const char *val = argv[1];
325 const char *BattenName = argv[2];
327 Standard_Real Slope = Draw::Atof(val);
329 Handle(DrawFairCurve_Batten)
330 Bat = Handle(DrawFairCurve_Batten)::DownCast(Draw::Get(BattenName));
331 if (Bat.IsNull()) return 1;
333 Bat->SetSlope(Slope);
337 //=======================================================================
338 static Standard_Integer
339 SetPhysicalRatio(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
340 //=======================================================================
342 if (!IsGoodNumber(argc,2,di)) return 1;
344 const char *val = argv[1];
345 const char *MVCName = argv[2];
347 Standard_Real ratio = Draw::Atof(val);
349 Handle(DrawFairCurve_MinimalVariation)
350 MVC = Handle(DrawFairCurve_MinimalVariation)::DownCast(Draw::Get(MVCName));
351 if (MVC.IsNull()) return 1;
353 MVC->SetPhysicalRatio(ratio);
359 //=======================================================================
360 void GeometryTest::FairCurveCommands(Draw_Interpretor& TheCommande)
361 //=======================================================================
366 g = "FairCurve command";
368 TheCommande.Add("battencurve","battencurve P1 P2 Angle1 Angle2 Heigth BattenName",
369 __FILE__,BattenCurve, g);
370 TheCommande.Add("minvarcurve","MVCurve P1 P2 Angle1 Angle2 Heigth MVCName",
371 __FILE__,MVCurve, g);
372 TheCommande.Add("setpoint","setpoint side point BattenName ",__FILE__, SetPoint, g);
373 TheCommande.Add("setangle","setangle side angle BattenName ",__FILE__, SetAngle, g);
374 TheCommande.Add("setslide","setangle slidingfactor BattenName ",__FILE__, SetSlide, g);
375 TheCommande.Add("freeangle","freeangle side BattenName",__FILE__, FreeAngle, g);
376 TheCommande.Add("freeslide","freeslide BattenName",__FILE__, FreeSlide, g);
377 TheCommande.Add("setheight","setheight height BattenName ",__FILE__, SetHeight, g);
378 TheCommande.Add("setslope","setslope slope BattenName ",__FILE__, SetSlope, g);
379 TheCommande.Add("setcurvature","setcurvature side rho MVCName ",__FILE__, SetCurvature, g);
380 TheCommande.Add("freecurvature","freecurvature side MVCName ",__FILE__, FreeCurvature, g);
381 TheCommande.Add("setphysicalratio","physicalratio ratio MVCName ",__FILE__, SetPhysicalRatio, g);