1 // Created on: 2017-06-16
2 // Created by: Natalia ERMOLAEVA
3 // Copyright (c) 2017 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <DrawTrSurf.hxx>
18 #include <Draw_Interpretor.hxx>
19 #include <GccAna_Circ2d3Tan.hxx>
21 #include <GccEnt_QualifiedLin.hxx>
22 #include <GccEnt_QualifiedCirc.hxx>
23 #include <Geom2d_Line.hxx>
24 #include <Geom2d_Circle.hxx>
25 #include <Geom2dAdaptor_Curve.hxx>
26 #include <GeometryTest.hxx>
27 #include <GeometryTest_DrawableQualifiedCurve2d.hxx>
28 #include <Precision.hxx>
29 #include <TCollection_AsciiString.hxx>
32 //=======================================================================
34 //purpose : Parses command: "qcircle name x y radius [-unqualified|-enclosing|-enclosed|-outside|-noqualifier]"
35 //=======================================================================
36 static Standard_Integer qcurve (Draw_Interpretor&, Standard_Integer theArgsNb, const char** theArgVec)
40 cout << "Error: wrong number of arguments.\n";
44 Handle(Geom2d_Curve) aResult2d;
45 TCollection_AsciiString aPositionType;
46 if (!strcmp (theArgVec[0], "qcircle"))
48 if (theArgsNb == 5 || theArgsNb == 6)
49 aResult2d = new Geom2d_Circle (gp_Ax22d (gp_Pnt2d (Draw::Atof (theArgVec[2]), Draw::Atof (theArgVec[3])),
50 gp_Dir2d (1,0)), Draw::Atof (theArgVec[4]));
51 else if (theArgsNb == 7 || theArgsNb == 8)
52 aResult2d = new Geom2d_Circle (gp_Ax22d (gp_Pnt2d (Draw::Atof (theArgVec[2]), Draw::Atof (theArgVec[3])),
53 gp_Dir2d (Draw::Atof (theArgVec[4]), Draw::Atof (theArgVec[5]))), Draw::Atof (theArgVec[6]));
56 aPositionType = theArgVec[5];
57 else if (theArgsNb == 8)
58 aPositionType = theArgVec[7];
60 else if(!strcmp (theArgVec[0], "qline"))
64 cout << "Error: wrong number of arguments.\n";
67 aResult2d = new Geom2d_Line (gp_Pnt2d (Draw::Atof (theArgVec[2]), Draw::Atof (theArgVec[3])),
68 gp_Dir2d (Draw::Atof (theArgVec[4]), Draw::Atof (theArgVec[5])));
70 aPositionType = theArgVec[6];
74 cout << "Error: wrong command name.\n";
78 GccEnt_Position aKindOfPosition = GccEnt_unqualified;
79 if (!aPositionType.IsEmpty())
81 GccEnt_Position aParameterPosition;
82 if (GccEnt::PositionFromString (aPositionType.ToCString(), aParameterPosition))
83 aKindOfPosition = aParameterPosition;
86 Draw::Set (theArgVec[1], new GeometryTest_DrawableQualifiedCurve2d (aResult2d, aKindOfPosition));
90 //=======================================================================
91 //function : solutions
93 //=======================================================================
94 static Standard_Integer solutions (Draw_Interpretor& theDI, GccAna_Circ2d3Tan& theCirTan3, const char* theName)
96 if (!theCirTan3.IsDone())
98 cout << "GccAna_Circ2d3Tan is not done";
102 TCollection_AsciiString aName = TCollection_AsciiString (theName) + "_";
103 GccEnt_Position aQualifier1, aQualifier2, aQualifier3;
104 Standard_Real aParSol, aParArg;
106 for (Standard_Integer aSolId = 1; aSolId <= theCirTan3.NbSolutions(); aSolId++)
108 Handle(Geom2d_Circle) aCircle = new Geom2d_Circle (theCirTan3.ThisSolution (aSolId));
109 TCollection_AsciiString aSolIdName = aName;
110 aSolIdName += TCollection_AsciiString (aSolId);
111 DrawTrSurf::Set (aSolIdName.ToCString(), aCircle);
112 theCirTan3.WhichQualifier (aSolId, aQualifier1, aQualifier2, aQualifier3);
113 theDI << "circle: " << aSolIdName.ToCString() << ", " << "qualifiers: " << GccEnt::PositionToString (aQualifier1)
114 << ", " << GccEnt::PositionToString (aQualifier2) << ", " << GccEnt::PositionToString (aQualifier3) << "\n";
116 theDI << " tangent points: point (parameter on solution, parameter on argument)\n";
117 // the first tangent point
118 if (theCirTan3.IsTheSame1 (aSolId))
119 theDI << " " << "= the solution number " << aSolId << " is equal to the first argument\n";
122 theCirTan3.Tangency1 (aSolId, aParSol, aParArg, aPntSol);
123 TCollection_AsciiString aTanPntIdName = aSolIdName + "_tp_1";
124 DrawTrSurf::Set (aTanPntIdName.ToCString(), aPntSol);
125 theDI << " " << aTanPntIdName.ToCString() << " (" << aParSol << ", " << aParArg << ")\n";
127 // the second tangent point
128 if (theCirTan3.IsTheSame2 (aSolId))
129 theDI << " " << "= the solution number " << aSolId << " is equal to the second argument\n";
132 theCirTan3.Tangency2 (aSolId, aParSol, aParArg, aPntSol);
133 TCollection_AsciiString aTanPntIdName = aSolIdName + "_tp_2";
134 DrawTrSurf::Set (aTanPntIdName.ToCString(), aPntSol);
135 theDI << " " << aTanPntIdName.ToCString() << " (" << aParSol << ", " << aParArg << ")\n";
137 // the third tangent point
138 if (theCirTan3.IsTheSame3 (aSolId))
139 theDI << " " << "= the solution number " << aSolId << " is equal to the third argument\n";
142 theCirTan3.Tangency3 (aSolId, aParSol, aParArg, aPntSol);
143 TCollection_AsciiString aTanPntIdName = aSolIdName + "_tp_3";
144 DrawTrSurf::Set (aTanPntIdName.ToCString(), aPntSol);
145 theDI << " " << aTanPntIdName.ToCString() << " (" << aParSol << ", " << aParArg << ")";
147 if (aSolId != theCirTan3.NbSolutions())
153 //=======================================================================
154 //function : circ2d3Tan
155 //purpose : Parses command: [circ2d3Tan cname qcicrle1/qlin1/point1 qcicrle2/qlin2/point2 qcicrle3/qlin3/point3
157 //=======================================================================
158 static Standard_Integer circ2d3Tan (Draw_Interpretor& theDI, Standard_Integer theArgsNb, const char** theArgVec)
162 cout << "Error: wrong number of arguments.\n";
166 Handle(GeometryTest_DrawableQualifiedCurve2d) aQCurve1 =
167 Handle(GeometryTest_DrawableQualifiedCurve2d)::DownCast (Draw::Get (theArgVec[2]));
168 Handle(GeometryTest_DrawableQualifiedCurve2d) aQCurve2 =
169 Handle(GeometryTest_DrawableQualifiedCurve2d)::DownCast (Draw::Get (theArgVec[3]));
170 Handle(GeometryTest_DrawableQualifiedCurve2d) aQCurve3 =
171 Handle(GeometryTest_DrawableQualifiedCurve2d)::DownCast (Draw::Get (theArgVec[4]));
173 gp_Pnt2d aPoint1, aPoint2, aPoint3;
174 Standard_Boolean anIsPoint1 = DrawTrSurf::GetPoint2d (theArgVec[2], aPoint1);
175 Standard_Boolean anIsPoint2 = DrawTrSurf::GetPoint2d (theArgVec[3], aPoint2);
176 Standard_Boolean anIsPoint3 = DrawTrSurf::GetPoint2d (theArgVec[4], aPoint3);
178 Standard_Real aTolerance = Precision::Confusion();
180 aTolerance = Draw::Atof (theArgVec[5]);
182 if (aQCurve1.IsNull()) // <point, point, point>
184 if (!anIsPoint1 || !anIsPoint2 || !anIsPoint3)
186 cout << "Error: wrong points definition.\n";
189 GccAna_Circ2d3Tan aCircBuilder (aPoint1, aPoint2, aPoint3, aTolerance);
190 return solutions (theDI, aCircBuilder, theArgVec[1]);
193 // the first curve is not NULL
194 if (aQCurve2.IsNull()) // <qcircle, point, point> or <qlin, point, point>
196 if (!anIsPoint2 || !anIsPoint3)
198 cout << "Error: wrong points definition.\n";
201 Geom2dAdaptor_Curve anAdaptorCurve1 (aQCurve1->GetCurve());
202 if (anAdaptorCurve1.GetType() == GeomAbs_Circle)
204 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
205 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aPoint2, aPoint3, aTolerance);
206 return solutions (theDI, aCircBuilder, theArgVec[1]);
208 else if (anAdaptorCurve1.GetType() == GeomAbs_Line)
210 GccEnt_QualifiedLin aQualifiedLin1 (anAdaptorCurve1.Line(), aQCurve1->GetPosition());
211 GccAna_Circ2d3Tan aCircBuilder (aQualifiedLin1, aPoint2, aPoint3, aTolerance);
212 return solutions (theDI, aCircBuilder, theArgVec[1]);
214 cout << "Error: wrong curve type.\n";
218 // the first and the second curves are not NULL
219 if (aQCurve3.IsNull()) // <qcircle, qcircle, point> or <qcircle, qlin, point> or <qlin, qlin, point>
223 cout << "Error: wrong point definition.\n";
226 Geom2dAdaptor_Curve anAdaptorCurve1 (aQCurve1->GetCurve());
227 Geom2dAdaptor_Curve anAdaptorCurve2 (aQCurve2->GetCurve());
228 if (anAdaptorCurve1.GetType() == GeomAbs_Circle && anAdaptorCurve2.GetType() == GeomAbs_Circle)
230 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
231 GccEnt_QualifiedCirc aQualifiedCircle2 (anAdaptorCurve2.Circle(), aQCurve2->GetPosition());
232 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aQualifiedCircle2, aPoint3, aTolerance);
233 return solutions (theDI, aCircBuilder, theArgVec[1]);
235 else if (anAdaptorCurve1.GetType() == GeomAbs_Circle && anAdaptorCurve2.GetType() == GeomAbs_Line)
237 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
238 GccEnt_QualifiedLin aQualifiedLin2 (anAdaptorCurve2.Line(), aQCurve2->GetPosition());
239 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aQualifiedLin2, aPoint3, aTolerance);
240 return solutions (theDI, aCircBuilder, theArgVec[1]);
242 else if (anAdaptorCurve1.GetType() == GeomAbs_Line && anAdaptorCurve2.GetType() == GeomAbs_Line)
244 GccEnt_QualifiedLin aQualifiedLin1 (anAdaptorCurve1.Line(), aQCurve1->GetPosition());
245 GccEnt_QualifiedLin aQualifiedLin2 (anAdaptorCurve2.Line(), aQCurve2->GetPosition());
246 GccAna_Circ2d3Tan aCircBuilder (aQualifiedLin1, aQualifiedLin2, aPoint3, aTolerance);
247 return solutions (theDI, aCircBuilder, theArgVec[1]);
249 cout << "Error: wrong curve type.\n";
253 // the first, the second and the third curves are not NULL
254 // <qcircle, qcircle, qcircle> or <qcircle, qcircle, qlin>, <qcircle, qlin, qlin>, <qlin, qlin, qlin>
255 Geom2dAdaptor_Curve anAdaptorCurve1 (aQCurve1->GetCurve());
256 Geom2dAdaptor_Curve anAdaptorCurve2 (aQCurve2->GetCurve());
257 Geom2dAdaptor_Curve anAdaptorCurve3 (aQCurve3->GetCurve());
258 if (anAdaptorCurve1.GetType() == GeomAbs_Circle && anAdaptorCurve2.GetType() == GeomAbs_Circle &&
259 anAdaptorCurve3.GetType() == GeomAbs_Circle)
261 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
262 GccEnt_QualifiedCirc aQualifiedCircle2 (anAdaptorCurve2.Circle(), aQCurve2->GetPosition());
263 GccEnt_QualifiedCirc aQualifiedCircle3 (anAdaptorCurve3.Circle(), aQCurve3->GetPosition());
264 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aQualifiedCircle2, aQualifiedCircle3, aTolerance);
265 return solutions (theDI, aCircBuilder, theArgVec[1]);
267 if (anAdaptorCurve1.GetType() == GeomAbs_Circle && anAdaptorCurve2.GetType() == GeomAbs_Circle &&
268 anAdaptorCurve3.GetType() == GeomAbs_Line)
270 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
271 GccEnt_QualifiedCirc aQualifiedCircle2 (anAdaptorCurve2.Circle(), aQCurve2->GetPosition());
272 GccEnt_QualifiedLin aQualifiedLin3 (anAdaptorCurve3.Line(), aQCurve3->GetPosition());
273 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aQualifiedCircle2, aQualifiedLin3, aTolerance);
274 return solutions (theDI, aCircBuilder, theArgVec[1]);
276 if (anAdaptorCurve1.GetType() == GeomAbs_Circle && anAdaptorCurve2.GetType() == GeomAbs_Line &&
277 anAdaptorCurve3.GetType() == GeomAbs_Line)
279 GccEnt_QualifiedCirc aQualifiedCircle1 (anAdaptorCurve1.Circle(), aQCurve1->GetPosition());
280 GccEnt_QualifiedLin aQualifiedLin2 (anAdaptorCurve2.Line(), aQCurve2->GetPosition());
281 GccEnt_QualifiedLin aQualifiedLin3 (anAdaptorCurve3.Line(), aQCurve3->GetPosition());
282 GccAna_Circ2d3Tan aCircBuilder (aQualifiedCircle1, aQualifiedLin2, aQualifiedLin3, aTolerance);
283 return solutions (theDI, aCircBuilder, theArgVec[1]);
285 if (anAdaptorCurve1.GetType() == GeomAbs_Line && anAdaptorCurve2.GetType() == GeomAbs_Line &&
286 anAdaptorCurve3.GetType() == GeomAbs_Line)
288 GccEnt_QualifiedLin aQualifiedLin1 (anAdaptorCurve1.Line(), aQCurve1->GetPosition());
289 GccEnt_QualifiedLin aQualifiedLin2 (anAdaptorCurve2.Line(), aQCurve2->GetPosition());
290 GccEnt_QualifiedLin aQualifiedLin3 (anAdaptorCurve3.Line(), aQCurve3->GetPosition());
291 GccAna_Circ2d3Tan aCircBuilder (aQualifiedLin1, aQualifiedLin2, aQualifiedLin3, aTolerance);
292 return solutions (theDI, aCircBuilder, theArgVec[1]);
295 cout << "Error: wrong curve type.\n";
299 //=======================================================================
300 //function : CurveTanCommands
302 //=======================================================================
303 void GeometryTest::CurveTanCommands (Draw_Interpretor& theCommands)
305 static Standard_Boolean aLoaded = Standard_False;
307 aLoaded = Standard_True;
309 DrawTrSurf::BasicCommands (theCommands);
312 aGroup = "GEOMETRY tangent curves creation";
314 theCommands.Add ("qcircle",
315 "qcircle name {x y [ux uy] radius} [-unqualified|-enclosing|-enclosed|-outside|-noqualifier]"
316 "\n\t\t: Creates qualified circle.",
317 __FILE__, qcurve, aGroup);
319 theCommands.Add ("qline",
320 "qline name x y dx dy [-unqualified|-enclosing|-enclosed|-outside|-noqualifier]"
321 "\n\t\t: Creates qualified line.",
322 __FILE__, qcurve, aGroup);
324 theCommands.Add ("circ2d3Tan",
325 "circ2d3Tan cname {qcicrle1|qlin1|point1} {qcicrle2|qlin2|point2} {qcicrle3|qlin3|point3} [tolerance]"
326 "\n\t\t: Creates 2d circles tangent to 3 arguments. The arguments are points, lines or circles."
327 "\n\t\t: Possible arguments combinations:"
328 "\n\t\t: <qcircle, qcircle, qcircle>,"
329 "\n\t\t: <qcircle, qcircle, qlin>,"
330 "\n\t\t: <qcircle, qcircle, point>,"
331 "\n\t\t: <qcircle, qlin, qlin>,"
332 "\n\t\t: <qcircle, qlin, point>,"
333 "\n\t\t: <qcircle, qlin, qlin>,"
334 "\n\t\t: <qcircle, point, point>,"
335 "\n\t\t: <qlin, qlin, qlin>,"
336 "\n\t\t: <qlin, qlin, point>,"
337 "\n\t\t: <qlin, point, point>,"
338 "\n\t\t: <point, point, point>.",
339 __FILE__, circ2d3Tan, aGroup);