b311480e |
1 | // Created on: 2001-03-28 |
2 | // Created by: Peter KURNEV |
973c2be1 |
3 | // Copyright (c) 2001-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <BOPTest.hxx> |
18 | #include <BOPTools_AlgoTools2D.hxx> |
42cf5bc1 |
19 | #include <BRep_GCurve.hxx> |
b6fba42f |
20 | #include <BRep_TEdge.hxx> |
42cf5bc1 |
21 | #include <BRep_Tool.hxx> |
22 | #include <BRepClass3d_SolidClassifier.hxx> |
23 | #include <BRepClass_FaceClassifier.hxx> |
7fd59977 |
24 | #include <DBRep.hxx> |
42cf5bc1 |
25 | #include <Draw.hxx> |
7fd59977 |
26 | #include <DrawTrSurf.hxx> |
42cf5bc1 |
27 | #include <gp_Pnt.hxx> |
28 | #include <gp_Pnt2d.hxx> |
0a512187 |
29 | #include <IntTools_FClass2d.hxx> |
42cf5bc1 |
30 | #include <TopAbs_State.hxx> |
31 | #include <TopoDS.hxx> |
32 | #include <TopoDS_Shape.hxx> |
b6fba42f |
33 | |
42cf5bc1 |
34 | #include <stdio.h> |
7fd59977 |
35 | static |
36 | void PrintState (Draw_Interpretor& aDI, |
4e57c75e |
37 | const TopAbs_State& aState); |
b6fba42f |
38 | static |
39 | Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, |
40 | const TopoDS_Face& F, |
41 | Standard_Real& First, |
42 | Standard_Real& Last); |
43 | static |
44 | Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, |
45 | const Handle(Geom_Surface)& S, |
46 | const TopLoc_Location& L, |
47 | Standard_Real& First, |
48 | Standard_Real& Last); |
7fd59977 |
49 | |
7fd59977 |
50 | static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** ); |
51 | static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** ); |
0a512187 |
52 | static Standard_Integer b2dclassifx (Draw_Interpretor& , Standard_Integer , const char** ); |
b6fba42f |
53 | static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** ); |
7fd59977 |
54 | |
7fd59977 |
55 | //======================================================================= |
56 | //function : LowCommands |
57 | //purpose : |
58 | //======================================================================= |
59 | void BOPTest::LowCommands(Draw_Interpretor& theCommands) |
60 | { |
61 | static Standard_Boolean done = Standard_False; |
62 | if (done) return; |
63 | done = Standard_True; |
64 | // Chapter's name |
43cb0011 |
65 | const char* g = "BOPTest commands"; |
66 | theCommands.Add("bclassify" , "use bclassify Solid Point [Tolerance=1.e-7]", |
4e57c75e |
67 | __FILE__, bclassify , g); |
41e2eed0 |
68 | theCommands.Add("b2dclassify" , "use b2dclassify Face Point2d [Tol] [UseBox] [GapCheckTol]\n" |
69 | "Classify the Point Point2d with Tolerance <Tol> on the face described by <Face>.\n" |
70 | "<UseBox> == 1/0 (default <UseBox> = 0): switch on/off the use Bnd_Box in the classification.\n" |
71 | "<GapCheckTol> (default <GapCheckTol> = 0.1): this is for additional verification of\n" |
72 | "the vertex with a tolerance >= <GapCheckTol>.", |
4e57c75e |
73 | __FILE__, b2dclassify , g); |
0a512187 |
74 | theCommands.Add("b2dclassifx" , "use b2dclassifx Face Point2d [Tol] ", |
75 | __FILE__, b2dclassifx , g); |
43cb0011 |
76 | theCommands.Add("bhaspc" , "use bhaspc Edge Face [do]", |
b6fba42f |
77 | __FILE__, bhaspc , g); |
7fd59977 |
78 | } |
7fd59977 |
79 | |
0a512187 |
80 | |
41e2eed0 |
81 | //lj cd |
7fd59977 |
82 | //======================================================================= |
0a512187 |
83 | //function : b2dclassifx |
7fd59977 |
84 | //purpose : |
85 | //======================================================================= |
0a512187 |
86 | Standard_Integer b2dclassifx (Draw_Interpretor& theDI, |
87 | Standard_Integer theArgNb, |
88 | const char** theArgVec) |
7fd59977 |
89 | { |
43cb0011 |
90 | if (theArgNb < 3) { |
0a512187 |
91 | theDI << " use b2dclassifx Face Point2d [Tol]\n"; |
7fd59977 |
92 | return 1; |
93 | } |
64531d9c |
94 | |
95 | TopoDS_Shape aS = DBRep::Get (theArgVec[1]); |
43cb0011 |
96 | if (aS.IsNull()) { |
0a512187 |
97 | theDI << " Null Shape is not allowed here\n"; |
7fd59977 |
98 | return 1; |
99 | } |
0a512187 |
100 | else if (aS.ShapeType() != TopAbs_FACE) { |
101 | theDI << " Shape type must be FACE\n"; |
7fd59977 |
102 | return 1; |
103 | } |
0a512187 |
104 | TopAbs_State aState; |
105 | gp_Pnt2d aP (8., 9.); |
106 | // |
107 | DrawTrSurf::GetPoint2d (theArgVec[2], aP); |
108 | const TopoDS_Face& aF = TopoDS::Face(aS); |
43cb0011 |
109 | const Standard_Real aTol = (theArgNb == 4) ? |
0a512187 |
110 | Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF); |
111 | // |
112 | IntTools_FClass2d aClassifier(aF, aTol); |
113 | aState=aClassifier.Perform(aP); |
114 | PrintState (theDI, aState); |
115 | // |
7fd59977 |
116 | return 0; |
117 | } |
118 | // |
119 | //======================================================================= |
120 | //function : b2dclassify |
121 | //purpose : |
122 | //======================================================================= |
64531d9c |
123 | Standard_Integer b2dclassify (Draw_Interpretor& theDI, |
124 | Standard_Integer theArgNb, |
125 | const char** theArgVec) |
7fd59977 |
126 | { |
43cb0011 |
127 | if (theArgNb < 3) { |
715fcb5a |
128 | theDI << " use b2dclassify Face Point2d [Tol] [UseBox] [GapCheckTol]\n"; |
7fd59977 |
129 | return 1; |
130 | } |
64531d9c |
131 | |
132 | TopoDS_Shape aS = DBRep::Get (theArgVec[1]); |
43cb0011 |
133 | if (aS.IsNull()) { |
64531d9c |
134 | theDI << " Null Shape is not allowed here\n"; |
7fd59977 |
135 | return 1; |
136 | } |
43cb0011 |
137 | else if (aS.ShapeType() != TopAbs_FACE) { |
64531d9c |
138 | theDI << " Shape type must be FACE\n"; |
7fd59977 |
139 | return 1; |
140 | } |
0a512187 |
141 | // |
64531d9c |
142 | gp_Pnt2d aP (8., 9.); |
0a512187 |
143 | // |
64531d9c |
144 | DrawTrSurf::GetPoint2d (theArgVec[2], aP); |
145 | const TopoDS_Face& aF = TopoDS::Face(aS); |
41e2eed0 |
146 | const Standard_Real aTol = (theArgNb >= 4) ? |
43cb0011 |
147 | Draw::Atof (theArgVec[3]) : BRep_Tool::Tolerance (aF); |
41e2eed0 |
148 | const Standard_Boolean anUseBox = (theArgNb >= 5 && Draw::Atof(theArgVec[4]) == 1) ? |
149 | Standard_True : Standard_False; |
715fcb5a |
150 | const Standard_Real aGapCheckTol = (theArgNb == 6) ? Draw::Atof(theArgVec[5]) : 0.1; |
7fd59977 |
151 | BRepClass_FaceClassifier aClassifier; |
715fcb5a |
152 | aClassifier.Perform(aF, aP, aTol, anUseBox, aGapCheckTol); |
64531d9c |
153 | PrintState (theDI, aClassifier.State()); |
0a512187 |
154 | // |
155 | return 0; |
156 | } |
157 | |
158 | //======================================================================= |
159 | //function : bclassify |
160 | //purpose : |
161 | //======================================================================= |
162 | Standard_Integer bclassify (Draw_Interpretor& theDI, |
163 | Standard_Integer theArgNb, |
164 | const char** theArgVec) |
165 | { |
166 | if (theArgNb < 3) { |
167 | theDI << " use bclassify Solid Point [Tolerance=1.e-7]\n"; |
168 | return 1; |
169 | } |
170 | |
171 | TopoDS_Shape aS = DBRep::Get (theArgVec[1]); |
172 | if (aS.IsNull()) { |
173 | theDI << " Null Shape is not allowed\n"; |
174 | return 1; |
175 | } |
176 | else if (aS.ShapeType() != TopAbs_SOLID) { |
177 | theDI << " Shape type must be SOLID\n"; |
178 | return 1; |
179 | } |
180 | |
181 | gp_Pnt aP (8., 9., 10.); |
182 | DrawTrSurf::GetPoint (theArgVec[2], aP); |
183 | const Standard_Real aTol = (theArgNb == 4) ? |
184 | Draw::Atof (theArgVec[3]) : 1.e-7; |
185 | |
186 | BRepClass3d_SolidClassifier aSC (aS); |
187 | aSC.Perform (aP,aTol); |
188 | |
189 | PrintState (theDI, aSC.State()); |
7fd59977 |
190 | return 0; |
191 | } |
4e57c75e |
192 | |
b6fba42f |
193 | //======================================================================= |
194 | //function : bhaspc |
195 | //purpose : |
196 | //======================================================================= |
43cb0011 |
197 | Standard_Integer bhaspc (Draw_Interpretor& di, |
198 | Standard_Integer n, |
199 | const char** a) |
b6fba42f |
200 | { |
201 | if (n<3) { |
43cb0011 |
202 | di << " use bhaspc Edge Face [do]\n"; |
b6fba42f |
203 | return 1; |
204 | } |
205 | |
206 | TopoDS_Shape S1 = DBRep::Get(a[1]); |
207 | TopoDS_Shape S2 = DBRep::Get(a[2]); |
208 | |
209 | if (S1.IsNull() || S2.IsNull()) { |
210 | di << " Null shapes are not allowed \n"; |
211 | return 1; |
212 | } |
213 | if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) { |
214 | di << " Type mismatch\n"; |
215 | return 1; |
216 | } |
217 | // |
218 | const TopoDS_Edge& aE=TopoDS::Edge(S1); |
219 | const TopoDS_Face& aF=TopoDS::Face(S2); |
220 | Standard_Real f2D, l2D; |
221 | |
222 | Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D); |
223 | |
224 | if (C2D.IsNull()) { |
225 | di << " No 2D Curves detected\n"; |
226 | } |
227 | else { |
228 | di << " Ok Edge has P-Curve on this Face\n"; |
229 | } |
230 | |
231 | if (n==4) { |
232 | if (!strcmp(a[3], "do")) { |
233 | BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aF); |
234 | } |
235 | } |
236 | |
237 | return 0; |
238 | } |
7fd59977 |
239 | //======================================================================= |
240 | //function : PrintState |
64531d9c |
241 | //purpose : |
7fd59977 |
242 | //======================================================================= |
64531d9c |
243 | void PrintState (Draw_Interpretor& theDI, |
244 | const TopAbs_State& theState) |
7fd59977 |
245 | { |
43cb0011 |
246 | switch (theState) { |
247 | case TopAbs_IN: |
248 | theDI << "The point is IN shape\n"; |
249 | break; |
250 | case TopAbs_OUT: |
251 | theDI << "The point is OUT of shape\n"; |
252 | break; |
253 | case TopAbs_ON: |
254 | theDI << "The point is ON shape\n"; |
255 | break; |
256 | case TopAbs_UNKNOWN: |
257 | default: |
258 | theDI << "The point is UNKNOWN shape\n"; |
259 | break; |
7fd59977 |
260 | } |
7fd59977 |
261 | } |
b6fba42f |
262 | //======================================================================= |
263 | //function : CurveOnSurface |
264 | //purpose : |
265 | //======================================================================= |
266 | Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, |
267 | const TopoDS_Face& F, |
268 | Standard_Real& First, |
269 | Standard_Real& Last) |
270 | { |
271 | TopLoc_Location l; |
272 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l); |
273 | TopoDS_Edge aLocalEdge = E; |
274 | if (F.Orientation() == TopAbs_REVERSED) { |
275 | aLocalEdge.Reverse(); |
276 | } |
277 | return CurveOnSurface(aLocalEdge,S,l,First,Last); |
278 | } |
279 | |
280 | static Handle(Geom2d_Curve) nullPCurve; |
281 | //======================================================================= |
282 | //function : CurveOnSurface |
283 | //purpose : |
284 | //======================================================================= |
285 | Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, |
286 | const Handle(Geom_Surface)& S, |
287 | const TopLoc_Location& L, |
288 | Standard_Real& First, |
289 | Standard_Real& Last) |
290 | { |
291 | TopLoc_Location l = L.Predivided(E.Location()); |
292 | Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); |
293 | |
294 | // find the representation |
295 | BRep_ListIteratorOfListOfCurveRepresentation itcr |
296 | ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves()); |
297 | |
298 | while (itcr.More()) { |
299 | const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); |
300 | if (cr->IsCurveOnSurface(S,l)) { |
c5f3a425 |
301 | Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr)); |
b6fba42f |
302 | GC->Range(First,Last); |
303 | if (GC->IsCurveOnClosedSurface() && Eisreversed) |
304 | return GC->PCurve2(); |
305 | else |
306 | return GC->PCurve(); |
307 | } |
308 | itcr.Next(); |
309 | } |
310 | return nullPCurve; |
311 | } |