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