1 // Created on: 2001-03-28
2 // Created by: Peter KURNEV
3 // Copyright (c) 2001-2014 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 <BOPTest.hxx>
18 #include <BOPTools_AlgoTools2D.hxx>
19 #include <BRep_CurveRepresentation.hxx>
20 #include <BRep_GCurve.hxx>
21 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
22 #include <BRep_TEdge.hxx>
23 #include <BRep_Tool.hxx>
24 #include <BRepClass3d_SolidClassifier.hxx>
25 #include <BRepClass_FaceClassifier.hxx>
28 #include <DrawTrSurf.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <IntTools_FClass2d.hxx>
32 #include <TCollection_AsciiString.hxx>
33 #include <TopAbs_State.hxx>
35 #include <TopoDS_Shape.hxx>
39 void PrintState (Draw_Interpretor& aDI,
40 const TopAbs_State& aState);
42 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
47 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
48 const Handle(Geom_Surface)& S,
49 const TopLoc_Location& L,
53 static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** );
54 static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
55 static Standard_Integer b2dclassifx (Draw_Interpretor& , Standard_Integer , const char** );
56 static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** );
58 //=======================================================================
59 //function : LowCommands
61 //=======================================================================
62 void BOPTest::LowCommands(Draw_Interpretor& theCommands)
64 static Standard_Boolean done = Standard_False;
68 const char* g = "BOPTest commands";
69 theCommands.Add("bclassify" , "use bclassify Solid Point [Tolerance=1.e-7]",
70 __FILE__, bclassify , g);
71 theCommands.Add("b2dclassify" , "use b2dclassify Face Point2d [Tol] ",
72 __FILE__, b2dclassify , g);
73 theCommands.Add("b2dclassifx" , "use b2dclassifx Face Point2d [Tol] ",
74 __FILE__, b2dclassifx , g);
75 theCommands.Add("bhaspc" , "use bhaspc Edge Face [do]",
76 __FILE__, bhaspc , g);
81 //=======================================================================
82 //function : b2dclassifx
84 //=======================================================================
85 Standard_Integer b2dclassifx (Draw_Interpretor& theDI,
86 Standard_Integer theArgNb,
87 const char** theArgVec)
90 theDI << " use b2dclassifx Face Point2d [Tol]\n";
94 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
96 theDI << " Null Shape is not allowed here\n";
99 else if (aS.ShapeType() != TopAbs_FACE) {
100 theDI << " Shape type must be FACE\n";
104 gp_Pnt2d aP (8., 9.);
106 DrawTrSurf::GetPoint2d (theArgVec[2], aP);
107 const TopoDS_Face& aF = TopoDS::Face(aS);
108 const Standard_Real aTol = (theArgNb == 4) ?
109 Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF);
111 IntTools_FClass2d aClassifier(aF, aTol);
112 aState=aClassifier.Perform(aP);
113 PrintState (theDI, aState);
118 //=======================================================================
119 //function : b2dclassify
121 //=======================================================================
122 Standard_Integer b2dclassify (Draw_Interpretor& theDI,
123 Standard_Integer theArgNb,
124 const char** theArgVec)
127 theDI << " use b2dclassify Face Point2d [Tol]\n";
131 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
133 theDI << " Null Shape is not allowed here\n";
136 else if (aS.ShapeType() != TopAbs_FACE) {
137 theDI << " Shape type must be FACE\n";
141 gp_Pnt2d aP (8., 9.);
143 DrawTrSurf::GetPoint2d (theArgVec[2], aP);
144 const TopoDS_Face& aF = TopoDS::Face(aS);
145 const Standard_Real aTol = (theArgNb == 4) ?
146 Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF);
148 BRepClass_FaceClassifier aClassifier;
149 aClassifier.Perform(aF, aP, aTol);
150 PrintState (theDI, aClassifier.State());
155 //=======================================================================
156 //function : bclassify
158 //=======================================================================
159 Standard_Integer bclassify (Draw_Interpretor& theDI,
160 Standard_Integer theArgNb,
161 const char** theArgVec)
164 theDI << " use bclassify Solid Point [Tolerance=1.e-7]\n";
168 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
170 theDI << " Null Shape is not allowed\n";
173 else if (aS.ShapeType() != TopAbs_SOLID) {
174 theDI << " Shape type must be SOLID\n";
178 gp_Pnt aP (8., 9., 10.);
179 DrawTrSurf::GetPoint (theArgVec[2], aP);
180 const Standard_Real aTol = (theArgNb == 4) ?
181 Draw::Atof (theArgVec[3]) : 1.e-7;
183 BRepClass3d_SolidClassifier aSC (aS);
184 aSC.Perform (aP,aTol);
186 PrintState (theDI, aSC.State());
190 //=======================================================================
193 //=======================================================================
194 Standard_Integer bhaspc (Draw_Interpretor& di,
199 di << " use bhaspc Edge Face [do]\n";
203 TopoDS_Shape S1 = DBRep::Get(a[1]);
204 TopoDS_Shape S2 = DBRep::Get(a[2]);
206 if (S1.IsNull() || S2.IsNull()) {
207 di << " Null shapes are not allowed \n";
210 if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
211 di << " Type mismatch\n";
215 const TopoDS_Edge& aE=TopoDS::Edge(S1);
216 const TopoDS_Face& aF=TopoDS::Face(S2);
217 Standard_Real f2D, l2D;
219 Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D);
222 di << " No 2D Curves detected\n";
225 di << " Ok Edge has P-Curve on this Face\n";
229 if (!strcmp(a[3], "do")) {
230 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aF);
236 //=======================================================================
237 //function : PrintState
239 //=======================================================================
240 void PrintState (Draw_Interpretor& theDI,
241 const TopAbs_State& theState)
245 theDI << "The point is IN shape\n";
248 theDI << "The point is OUT of shape\n";
251 theDI << "The point is ON shape\n";
255 theDI << "The point is UNKNOWN shape\n";
259 //=======================================================================
260 //function : CurveOnSurface
262 //=======================================================================
263 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
264 const TopoDS_Face& F,
265 Standard_Real& First,
269 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
270 TopoDS_Edge aLocalEdge = E;
271 if (F.Orientation() == TopAbs_REVERSED) {
272 aLocalEdge.Reverse();
274 return CurveOnSurface(aLocalEdge,S,l,First,Last);
277 static Handle(Geom2d_Curve) nullPCurve;
278 //=======================================================================
279 //function : CurveOnSurface
281 //=======================================================================
282 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
283 const Handle(Geom_Surface)& S,
284 const TopLoc_Location& L,
285 Standard_Real& First,
288 TopLoc_Location l = L.Predivided(E.Location());
289 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
291 // find the representation
292 BRep_ListIteratorOfListOfCurveRepresentation itcr
293 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
295 while (itcr.More()) {
296 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
297 if (cr->IsCurveOnSurface(S,l)) {
298 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
299 GC->Range(First,Last);
300 if (GC->IsCurveOnClosedSurface() && Eisreversed)
301 return GC->PCurve2();