0023796: Command "bhaspc" which was contained in BOPTest_LowCommands.cxx was removed.
[occt.git] / src / BOPTest / BOPTest_LowCommands.cxx
CommitLineData
b311480e 1// Created on: 2001-03-28
2// Created by: Peter KURNEV
3// Copyright (c) 2001-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21#include <BOPTest.ixx>
22
23#include <stdio.h>
24
7fd59977 25#include <gp_Pnt2d.hxx>
26#include <gp_Pnt.hxx>
27
7fd59977 28#include <TopoDS.hxx>
7fd59977 29#include <TopoDS_Shape.hxx>
4e57c75e 30#include <TopAbs_State.hxx>
7fd59977 31
4e57c75e 32#include <TCollection_AsciiString.hxx>
7fd59977 33
4e57c75e 34#include <BRepClass3d_SolidClassifier.hxx>
35#include <BRepClass_FaceClassifier.hxx>
b6fba42f 36
4e57c75e 37#include <BRep_Tool.hxx>
b6fba42f 38#include <BRep_CurveRepresentation.hxx>
39#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
40#include <BRep_TEdge.hxx>
41#include <BRep_GCurve.hxx>
7fd59977 42
91322f44 43#include <Draw.hxx>
7fd59977 44#include <DBRep.hxx>
7fd59977 45#include <DrawTrSurf.hxx>
46
b6fba42f 47#include <BOPTools_AlgoTools2D.hxx>
48
7fd59977 49static
50 void PrintState (Draw_Interpretor& aDI,
4e57c75e 51 const TopAbs_State& aState);
b6fba42f 52static
53 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
54 const TopoDS_Face& F,
55 Standard_Real& First,
56 Standard_Real& Last);
57static
58 Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
59 const Handle(Geom_Surface)& S,
60 const TopLoc_Location& L,
61 Standard_Real& First,
62 Standard_Real& Last);
7fd59977 63
7fd59977 64static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** );
65static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** );
b6fba42f 66static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** );
7fd59977 67
7fd59977 68//=======================================================================
69//function : LowCommands
70//purpose :
71//=======================================================================
72 void BOPTest::LowCommands(Draw_Interpretor& theCommands)
73{
74 static Standard_Boolean done = Standard_False;
75 if (done) return;
76 done = Standard_True;
77 // Chapter's name
78 const char* g = "CCR commands";
7fd59977 79 theCommands.Add("bclassify" , "Use >bclassify Solid Point [Tolerance=1.e-7]",
4e57c75e 80 __FILE__, bclassify , g);
7fd59977 81 theCommands.Add("b2dclassify" , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ",
4e57c75e 82 __FILE__, b2dclassify , g);
b6fba42f 83 theCommands.Add("bhaspc" , "Use >bhaspc Edge Face [do]",
84 __FILE__, bhaspc , g);
7fd59977 85}
7fd59977 86
7fd59977 87//=======================================================================
88//function : bclassify
89//purpose :
90//=======================================================================
91Standard_Integer bclassify (Draw_Interpretor& aDI,
4e57c75e 92 Standard_Integer n,
93 const char** a)
7fd59977 94{
95 char sbf[512];
96
97 if (n < 3) {
91322f44 98 Sprintf(sbf, " Use >bclassify Solid Point [Tolerance=1.e-7]\n");
7fd59977 99 aDI<<sbf;
100 return 1;
101 }
102
103 TopoDS_Shape aS = DBRep::Get(a[1]);
104 if (aS.IsNull()) {
91322f44 105 Sprintf(sbf, " Null Shape is not allowed here\n");
7fd59977 106 aDI<<sbf;
107 return 1;
108 }
109
110 if (aS.ShapeType()!=TopAbs_SOLID) {
91322f44 111 Sprintf(sbf, " Shape type must be SOLID\n");
7fd59977 112 aDI<<sbf;
113 return 1;
114 }
115 //
116 Standard_Real aTol=1.e-7;
117 TopAbs_State aState = TopAbs_UNKNOWN;
118 gp_Pnt aP(8., 9., 10.);
119
120 DrawTrSurf::GetPoint(a[2], aP);
121
122 aTol=1.e-7;
123 if (n==4) {
91322f44 124 aTol=Draw::Atof(a[3]);
7fd59977 125 }
126 //
127 BRepClass3d_SolidClassifier aSC(aS);
128 aSC.Perform(aP,aTol);
129 //
130 aState = aSC.State();
131 //
132 PrintState (aDI, aState);
133 //
134 return 0;
135}
136//
137//=======================================================================
138//function : b2dclassify
139//purpose :
140//=======================================================================
141Standard_Integer b2dclassify (Draw_Interpretor& aDI,
4e57c75e 142 Standard_Integer n,
143 const char** a)
7fd59977 144{
145 char sbf[512];
146
147 if (n < 3) {
91322f44 148 Sprintf(sbf, " Use >bclassify Face Point2d [Tol2D=Tol(Face)]\n");
7fd59977 149 aDI<<sbf;
150 return 1;
151 }
152
153 TopoDS_Shape aS = DBRep::Get(a[1]);
154 if (aS.IsNull()) {
91322f44 155 Sprintf(sbf, " Null Shape is not allowed here\n");
7fd59977 156 aDI<<sbf;
157 return 1;
158 }
159
160 if (aS.ShapeType()!=TopAbs_FACE) {
91322f44 161 Sprintf(sbf, " Shape type must be FACE\n");
7fd59977 162 aDI<<sbf;
163 return 1;
164 }
165 //
166 Standard_Real aTol;
167 TopAbs_State aState = TopAbs_UNKNOWN;
168 gp_Pnt2d aP(8., 9.);
169
170 DrawTrSurf::GetPoint2d(a[2], aP);
171
172 const TopoDS_Face& aF=TopoDS::Face(aS);
173 aTol=BRep_Tool::Tolerance(aF);
174 if (n==4) {
91322f44 175 aTol=Draw::Atof(a[3]);
7fd59977 176 }
177 //
178 BRepClass_FaceClassifier aClassifier;
179 aClassifier.Perform(aF, aP, aTol);
180 //
181 aState = aClassifier.State();
182 //
183 PrintState (aDI, aState);
184 //
185 return 0;
186}
4e57c75e 187
b6fba42f 188//=======================================================================
189//function : bhaspc
190//purpose :
191//=======================================================================
192Standard_Integer bhaspc (Draw_Interpretor& di, Standard_Integer n, const char** a)
193{
194 if (n<3) {
195 di << " Use bhaspc> Edge Face [do]\n";
196 return 1;
197 }
198
199 TopoDS_Shape S1 = DBRep::Get(a[1]);
200 TopoDS_Shape S2 = DBRep::Get(a[2]);
201
202 if (S1.IsNull() || S2.IsNull()) {
203 di << " Null shapes are not allowed \n";
204 return 1;
205 }
206 if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) {
207 di << " Type mismatch\n";
208 return 1;
209 }
210 //
211 const TopoDS_Edge& aE=TopoDS::Edge(S1);
212 const TopoDS_Face& aF=TopoDS::Face(S2);
213 Standard_Real f2D, l2D;
214
215 Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D);
216
217 if (C2D.IsNull()) {
218 di << " No 2D Curves detected\n";
219 }
220 else {
221 di << " Ok Edge has P-Curve on this Face\n";
222 }
223
224 if (n==4) {
225 if (!strcmp(a[3], "do")) {
226 BOPTools_AlgoTools2D::BuildPCurveForEdgeOnFace(aE, aF);
227 }
228 }
229
230 return 0;
231}
232
7fd59977 233//=======================================================================
234//function : PrintState
235//purpose :
236//=======================================================================
237void PrintState (Draw_Interpretor& aDI,
4e57c75e 238 const TopAbs_State& aState)
7fd59977 239{
240 char sbf[512];
241 TCollection_AsciiString sIN("IN"), sOUT("OUT of"), sON("ON"), sUNKNOWN("UNKNOWN");
242 //
91322f44 243 Sprintf(sbf, "The point is "); aDI<<sbf;
7fd59977 244 //
245 switch (aState) {
4e57c75e 246 case TopAbs_IN:
91322f44 247 Sprintf(sbf, sIN.ToCString());
7fd59977 248 break;
4e57c75e 249 case TopAbs_OUT:
91322f44 250 Sprintf(sbf, sOUT.ToCString());
7fd59977 251 break;
4e57c75e 252 case TopAbs_ON:
91322f44 253 Sprintf(sbf, sON.ToCString());
7fd59977 254 break;
4e57c75e 255 case TopAbs_UNKNOWN:
91322f44 256 Sprintf(sbf, sUNKNOWN.ToCString());
7fd59977 257 break;
258 default:
91322f44 259 Sprintf(sbf, sUNKNOWN.ToCString());
7fd59977 260 break;
261 }
262 aDI<<sbf;
4e57c75e 263 //
91322f44 264 Sprintf(sbf, " shape\n");
7fd59977 265 aDI<<sbf;
266
267}
b6fba42f 268
269//=======================================================================
270//function : CurveOnSurface
271//purpose :
272//=======================================================================
273Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
274 const TopoDS_Face& F,
275 Standard_Real& First,
276 Standard_Real& Last)
277{
278 TopLoc_Location l;
279 const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l);
280 TopoDS_Edge aLocalEdge = E;
281 if (F.Orientation() == TopAbs_REVERSED) {
282 aLocalEdge.Reverse();
283 }
284 return CurveOnSurface(aLocalEdge,S,l,First,Last);
285}
286
287static Handle(Geom2d_Curve) nullPCurve;
288//=======================================================================
289//function : CurveOnSurface
290//purpose :
291//=======================================================================
292Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E,
293 const Handle(Geom_Surface)& S,
294 const TopLoc_Location& L,
295 Standard_Real& First,
296 Standard_Real& Last)
297{
298 TopLoc_Location l = L.Predivided(E.Location());
299 Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED);
300
301 // find the representation
302 BRep_ListIteratorOfListOfCurveRepresentation itcr
303 ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves());
304
305 while (itcr.More()) {
306 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
307 if (cr->IsCurveOnSurface(S,l)) {
308 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
309 GC->Range(First,Last);
310 if (GC->IsCurveOnClosedSurface() && Eisreversed)
311 return GC->PCurve2();
312 else
313 return GC->PCurve();
314 }
315 itcr.Next();
316 }
317 return nullPCurve;
318}
319