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.
16 #include <BOPTest.ixx>
20 #include <gp_Pnt2d.hxx>
24 #include <TopoDS_Shape.hxx>
25 #include <TopAbs_State.hxx>
27 #include <TCollection_AsciiString.hxx>
29 #include <BRepClass3d_SolidClassifier.hxx>
30 #include <BRepClass_FaceClassifier.hxx>
32 #include <BRep_Tool.hxx>
33 #include <BRep_CurveRepresentation.hxx>
34 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
35 #include <BRep_TEdge.hxx>
36 #include <BRep_GCurve.hxx>
40 #include <DrawTrSurf.hxx>
42 #include <BOPTools_AlgoTools2D.hxx>
43 #include <IntTools_FClass2d.hxx>
46 void PrintState (Draw_Interpretor& aDI,
47 const TopAbs_State& aState);
49 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
54 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
55 const Handle(Geom_Surface)& S,
56 const TopLoc_Location& L,
60 static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** );
61 static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
62 static Standard_Integer b2dclassifx (Draw_Interpretor& , Standard_Integer , const char** );
63 static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** );
65 //=======================================================================
66 //function : LowCommands
68 //=======================================================================
69 void BOPTest::LowCommands(Draw_Interpretor& theCommands)
71 static Standard_Boolean done = Standard_False;
75 const char* g = "BOPTest commands";
76 theCommands.Add("bclassify" , "use bclassify Solid Point [Tolerance=1.e-7]",
77 __FILE__, bclassify , g);
78 theCommands.Add("b2dclassify" , "use b2dclassify Face Point2d [Tol] ",
79 __FILE__, b2dclassify , g);
80 theCommands.Add("b2dclassifx" , "use b2dclassifx Face Point2d [Tol] ",
81 __FILE__, b2dclassifx , g);
82 theCommands.Add("bhaspc" , "use bhaspc Edge Face [do]",
83 __FILE__, bhaspc , g);
88 //=======================================================================
89 //function : b2dclassifx
91 //=======================================================================
92 Standard_Integer b2dclassifx (Draw_Interpretor& theDI,
93 Standard_Integer theArgNb,
94 const char** theArgVec)
97 theDI << " use b2dclassifx Face Point2d [Tol]\n";
101 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
103 theDI << " Null Shape is not allowed here\n";
106 else if (aS.ShapeType() != TopAbs_FACE) {
107 theDI << " Shape type must be FACE\n";
111 gp_Pnt2d aP (8., 9.);
113 DrawTrSurf::GetPoint2d (theArgVec[2], aP);
114 const TopoDS_Face& aF = TopoDS::Face(aS);
115 const Standard_Real aTol = (theArgNb == 4) ?
116 Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF);
118 IntTools_FClass2d aClassifier(aF, aTol);
119 aState=aClassifier.Perform(aP);
120 PrintState (theDI, aState);
125 //=======================================================================
126 //function : b2dclassify
128 //=======================================================================
129 Standard_Integer b2dclassify (Draw_Interpretor& theDI,
130 Standard_Integer theArgNb,
131 const char** theArgVec)
134 theDI << " use b2dclassify Face Point2d [Tol]\n";
138 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
140 theDI << " Null Shape is not allowed here\n";
143 else if (aS.ShapeType() != TopAbs_FACE) {
144 theDI << " Shape type must be FACE\n";
148 gp_Pnt2d aP (8., 9.);
150 DrawTrSurf::GetPoint2d (theArgVec[2], aP);
151 const TopoDS_Face& aF = TopoDS::Face(aS);
152 const Standard_Real aTol = (theArgNb == 4) ?
153 Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF);
155 BRepClass_FaceClassifier aClassifier;
156 aClassifier.Perform(aF, aP, aTol);
157 PrintState (theDI, aClassifier.State());
162 //=======================================================================
163 //function : bclassify
165 //=======================================================================
166 Standard_Integer bclassify (Draw_Interpretor& theDI,
167 Standard_Integer theArgNb,
168 const char** theArgVec)
171 theDI << " use bclassify Solid Point [Tolerance=1.e-7]\n";
175 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
177 theDI << " Null Shape is not allowed\n";
180 else if (aS.ShapeType() != TopAbs_SOLID) {
181 theDI << " Shape type must be SOLID\n";
185 gp_Pnt aP (8., 9., 10.);
186 DrawTrSurf::GetPoint (theArgVec[2], aP);
187 const Standard_Real aTol = (theArgNb == 4) ?
188 Draw::Atof (theArgVec[3]) : 1.e-7;
190 BRepClass3d_SolidClassifier aSC (aS);
191 aSC.Perform (aP,aTol);
193 PrintState (theDI, aSC.State());
197 //=======================================================================
200 //=======================================================================
201 Standard_Integer bhaspc (Draw_Interpretor& di,
206 di << " use bhaspc Edge Face [do]\n";
210 TopoDS_Shape S1 = DBRep::Get(a[1]);
211 TopoDS_Shape S2 = DBRep::Get(a[2]);
213 if (S1.IsNull() || S2.IsNull()) {
214 di << " Null shapes are not allowed \n";
217 if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
218 di << " Type mismatch\n";
222 const TopoDS_Edge& aE=TopoDS::Edge(S1);
223 const TopoDS_Face& aF=TopoDS::Face(S2);
224 Standard_Real f2D, l2D;
226 Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D);
229 di << " No 2D Curves detected\n";
232 di << " Ok Edge has P-Curve on this Face\n";
236 if (!strcmp(a[3], "do")) {
237 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aF);
243 //=======================================================================
244 //function : PrintState
246 //=======================================================================
247 void PrintState (Draw_Interpretor& theDI,
248 const TopAbs_State& theState)
252 theDI << "The point is IN shape\n";
255 theDI << "The point is OUT of shape\n";
258 theDI << "The point is ON shape\n";
262 theDI << "The point is UNKNOWN shape\n";
266 //=======================================================================
267 //function : CurveOnSurface
269 //=======================================================================
270 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
271 const TopoDS_Face& F,
272 Standard_Real& First,
276 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
277 TopoDS_Edge aLocalEdge = E;
278 if (F.Orientation() == TopAbs_REVERSED) {
279 aLocalEdge.Reverse();
281 return CurveOnSurface(aLocalEdge,S,l,First,Last);
284 static Handle(Geom2d_Curve) nullPCurve;
285 //=======================================================================
286 //function : CurveOnSurface
288 //=======================================================================
289 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
290 const Handle(Geom_Surface)& S,
291 const TopLoc_Location& L,
292 Standard_Real& First,
295 TopLoc_Location l = L.Predivided(E.Location());
296 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
298 // find the representation
299 BRep_ListIteratorOfListOfCurveRepresentation itcr
300 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
302 while (itcr.More()) {
303 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
304 if (cr->IsCurveOnSurface(S,l)) {
305 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
306 GC->Range(First,Last);
307 if (GC->IsCurveOnClosedSurface() && Eisreversed)
308 return GC->PCurve2();