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
8 // under the terms of the GNU Lesser General Public 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>
45 void PrintState (Draw_Interpretor& aDI,
46 const TopAbs_State& aState);
48 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
53 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
54 const Handle(Geom_Surface)& S,
55 const TopLoc_Location& L,
59 static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** );
60 static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
61 static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** );
63 //=======================================================================
64 //function : LowCommands
66 //=======================================================================
67 void BOPTest::LowCommands(Draw_Interpretor& theCommands)
69 static Standard_Boolean done = Standard_False;
73 const char* g = "CCR commands";
74 theCommands.Add("bclassify" , "Use >bclassify Solid Point [Tolerance=1.e-7]",
75 __FILE__, bclassify , g);
76 theCommands.Add("b2dclassify" , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
77 __FILE__, b2dclassify , g);
78 theCommands.Add("bhaspc" , "Use >bhaspc Edge Face [do]",
79 __FILE__, bhaspc , g);
82 //=======================================================================
83 //function : bclassify
85 //=======================================================================
86 Standard_Integer bclassify (Draw_Interpretor& theDI,
87 Standard_Integer theArgNb,
88 const char** theArgVec)
92 theDI << " Use >bclassify Solid Point [Tolerance=1.e-7]\n";
96 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
99 theDI << " Null Shape is not allowed here\n";
102 else if (aS.ShapeType() != TopAbs_SOLID)
104 theDI << " Shape type must be SOLID\n";
108 gp_Pnt aP (8., 9., 10.);
109 DrawTrSurf::GetPoint (theArgVec[2], aP);
110 const Standard_Real aTol = (theArgNb == 4) ? Draw::Atof (theArgVec[3]) : 1.e-7; //Precision::Confusion();
112 BRepClass3d_SolidClassifier aSC (aS);
113 aSC.Perform (aP,aTol);
115 PrintState (theDI, aSC.State());
119 //=======================================================================
120 //function : b2dclassify
122 //=======================================================================
123 Standard_Integer b2dclassify (Draw_Interpretor& theDI,
124 Standard_Integer theArgNb,
125 const char** theArgVec)
129 theDI << " Use >bclassify Face Point2d [Tol2D=Tol(Face)]\n";
133 TopoDS_Shape aS = DBRep::Get (theArgVec[1]);
136 theDI << " Null Shape is not allowed here\n";
139 else if (aS.ShapeType() != TopAbs_FACE)
141 theDI << " Shape type must be FACE\n";
145 gp_Pnt2d aP (8., 9.);
146 DrawTrSurf::GetPoint2d (theArgVec[2], aP);
147 const TopoDS_Face& aF = TopoDS::Face(aS);
148 const Standard_Real aTol = (theArgNb == 4) ? Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF);
150 BRepClass_FaceClassifier aClassifier;
151 aClassifier.Perform(aF, aP, aTol);
153 PrintState (theDI, aClassifier.State());
157 //=======================================================================
160 //=======================================================================
161 Standard_Integer bhaspc (Draw_Interpretor& di, Standard_Integer n, const char** a)
164 di << " Use bhaspc> Edge Face [do]\n";
168 TopoDS_Shape S1 = DBRep::Get(a[1]);
169 TopoDS_Shape S2 = DBRep::Get(a[2]);
171 if (S1.IsNull() || S2.IsNull()) {
172 di << " Null shapes are not allowed \n";
175 if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
176 di << " Type mismatch\n";
180 const TopoDS_Edge& aE=TopoDS::Edge(S1);
181 const TopoDS_Face& aF=TopoDS::Face(S2);
182 Standard_Real f2D, l2D;
184 Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D);
187 di << " No 2D Curves detected\n";
190 di << " Ok Edge has P-Curve on this Face\n";
194 if (!strcmp(a[3], "do")) {
195 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aF);
202 //=======================================================================
203 //function : PrintState
205 //=======================================================================
206 void PrintState (Draw_Interpretor& theDI,
207 const TopAbs_State& theState)
211 case TopAbs_IN: theDI << "The point is IN shape\n"; return;
212 case TopAbs_OUT: theDI << "The point is OUT of shape\n"; return;
213 case TopAbs_ON: theDI << "The point is ON shape\n"; return;
215 default: theDI << "The point is UNKNOWN shape\n"; return;
219 //=======================================================================
220 //function : CurveOnSurface
222 //=======================================================================
223 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
224 const TopoDS_Face& F,
225 Standard_Real& First,
229 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
230 TopoDS_Edge aLocalEdge = E;
231 if (F.Orientation() == TopAbs_REVERSED) {
232 aLocalEdge.Reverse();
234 return CurveOnSurface(aLocalEdge,S,l,First,Last);
237 static Handle(Geom2d_Curve) nullPCurve;
238 //=======================================================================
239 //function : CurveOnSurface
241 //=======================================================================
242 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
243 const Handle(Geom_Surface)& S,
244 const TopLoc_Location& L,
245 Standard_Real& First,
248 TopLoc_Location l = L.Predivided(E.Location());
249 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
251 // find the representation
252 BRep_ListIteratorOfListOfCurveRepresentation itcr
253 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
255 while (itcr.More()) {
256 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
257 if (cr->IsCurveOnSurface(S,l)) {
258 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
259 GC->Range(First,Last);
260 if (GC->IsCurveOnClosedSurface() && Eisreversed)
261 return GC->PCurve2();