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