0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / TestTopOpe / TestTopOpe_CORCommands.cxx
CommitLineData
b311480e 1// Created on: 1997-07-24
2// Created by: Xuan PHAM PHU
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <TestTopOpe.hxx>
18#include <TopOpeBRepTool_2d.hxx>
19#include <TopOpeBRepTool_C2DF.hxx>
20#include <TopOpeBRepTool_CORRISO.hxx>
21#include <TopOpeBRepTool_TOOL.hxx>
22#include <TopOpeBRepTool_REGUS.hxx>
23#include <TopOpeBRepTool_CLASSI.hxx>
24#include <TopOpeBRepTool_TOOL.hxx>
25#include <TopOpeBRepBuild_define.hxx>
26
27#include <gp_Pnt2d.hxx>
28#include <gp_Trsf2d.hxx>
29#include <gp_Pnt2d.hxx>
30#include <gp_Dir2d.hxx>
31#include <gp_Vec2d.hxx>
32#include <BRepAdaptor_Curve2d.hxx>
33#include <BndLib_Add2dCurve.hxx>
34#include <BRepLProp_SLProps.hxx>
35#include <Geom_Curve.hxx>
36#include <Geom2dAdaptor_Curve.hxx>
37#include <Geom2d_Line.hxx>
38#include <Geom2d_Curve.hxx>
39#include <Geom2d_TrimmedCurve.hxx>
40#include <Geom_Line.hxx>
41#include <Geom_Surface.hxx>
42#include <GeomAPI_IntCS.hxx>
43#include <TopoDS.hxx>
44#include <TopoDS_Solid.hxx>
45#include <TopoDS_Wire.hxx>
46#include <TopoDS_Compound.hxx>
47#include <TopExp.hxx>
48#include <TopExp_Explorer.hxx>
49#include <BRep_Tool.hxx>
50#include <BRep_Builder.hxx>
51#include <Precision.hxx>
52#include <Bnd_Box2d.hxx>
53#include <Bnd_Array1OfBox2d.hxx>
54#include <BRepClass3d_SolidClassifier.hxx>
55
56#include <TopOpeBRepTool.hxx>
57#include <TopOpeBRepDS.hxx>
58#include <TopOpeBRepBuild_FaceBuilder.hxx>
59#include <TopOpeBRepBuild_ShellToSolid.hxx>
60#include <TopOpeBRepTool_EXPORT.hxx>
61#include <TopOpeBRepTool_SolidClassifier.hxx>
62#include <TopOpeBRepTool_ShapeClassifier.hxx>
63#include <TopOpeBRepDS_EXPORT.hxx>
64
91322f44 65#include <Draw.hxx>
7fd59977 66#include <Draw_Interpretor.hxx>
67#include <DrawTrSurf.hxx>
68#include <Draw_Color.hxx>
69#include <DBRep.hxx>
70
d633fd70 71#include <Extrema_ExtFlag.hxx>
72#include <Extrema_ExtAlgo.hxx>
73
7fd59977 74#ifdef DRAW
75#include <TopOpeBRepTool_DRAW.hxx>
76#endif
77
78Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
79Standard_IMPORT void DBRep_WriteColorOrientation ();
80Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
81
82Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
83Standard_IMPORT void DBRep_WriteColorOrientation ();
84Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
85Standard_EXPORT void FUN_tool_mkBnd2d(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d);
86Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d, const Bnd_Box2d& newB2d);
87Standard_IMPORT Standard_Integer FUN_tool_classiBnd2d(const Bnd_Array1OfBox2d& B,const Standard_Boolean chklarge = Standard_True);
88Standard_IMPORT Standard_Boolean FUN_tool_chkp2dFORinE(const gp_Pnt2d& p2d,const TopoDS_Edge& E,
89 const TopoDS_Face& F, Standard_Real& tol2d);
90Standard_IMPORT TopoDS_Vertex FUN_tool_getv(const Standard_Integer Index,const TopoDS_Edge& E);
91
92
93#define SAME (-1)
94#define DIFF (-2)
95#define UNKNOWN ( 0)
96#define oneINtwo ( 1)
97#define twoINone ( 2)
98
7fd59977 99static void FUN_test_draw(TCollection_AsciiString aa,
100 const TopoDS_Edge& E, const TopoDS_Face& F,
101 const Standard_Integer ie,
102 Draw_Interpretor& di)
103{
104 if (E.IsNull()) {di<<"************* null edge\n"; return;}
105 Standard_Real f,l; const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(E,F,f,l);
106 if (PC.IsNull()) {di<<"************* no curv on surf\n"; return;}
107 TCollection_AsciiString bb(aa); bb += TCollection_AsciiString(ie);
108 char* aaa = (char *)bb.ToCString();
109
110 Standard_Boolean coldef = Standard_False;
111 TopExp_Explorer ex(F,TopAbs_EDGE);
112 Draw_Color col;
96a95605 113 DrawTrSurf_CurveColor(Draw_Color(Draw_rouge));
7fd59977 114 for (; ex.More(); ex.Next())
115 if (E.IsEqual(ex.Current()))
116 {col = DBRep_ColorOrientation(ex.Current().Orientation());
117 coldef = Standard_True;
118 break;}
119 if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
120
121 DrawTrSurf_CurveColor(col);
122 DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
123}
124
125void FUN_draw(const TCollection_AsciiString aa,const TopoDS_Shape& s)
126{char* aaa = (char *)aa.ToCString(); DBRep::Set(aaa,s);}
127
128void FUN_cout(const gp_Pnt2d& p2d, Draw_Interpretor& di)
129{di <<" = ("<<p2d.X()<<" "<<p2d.Y()<<") ";}
130
0797d9d3 131#ifdef OCCT_DEBUG
7fd59977 132Standard_IMPORT void FUN_tool_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2);
133#endif
134
135
136Standard_Integer regularize(Draw_Interpretor& di, Standard_Integer n, const char** a)
137{
138 if (n < 2) return 1;
139 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
140 TopoDS_Face fa = TopoDS::Face(aLocalShape);
141// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
142 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
143
144 TopTools_DataMapOfShapeListOfShape ESplits;
145 TopTools_ListOfShape lof;
146 TopOpeBRepTool::Regularize(fa, lof, ESplits);
147 Standard_Integer nfa = lof.Extent();
148 di<<"face gives "<<nfa<<" newfaces"<<"\n";
149
150 Standard_Integer i = 0;
151 TopTools_ListIteratorOfListOfShape itlof(lof) ;
152 for ( ; itlof.More(); itlof.Next()) {
153 i++;
154 TCollection_AsciiString aa = TCollection_AsciiString("fa_");
155 aa += TCollection_AsciiString(i);
156 FUN_draw(aa,itlof.Value());
157 }
158 BRep_Builder BB;
159 TopoDS_Compound CC; BB.MakeCompound(CC);
160 for (itlof.Initialize(lof); itlof.More(); itlof.Next()) BB.Add(CC, itlof.Value());
161 di<<"resulting compound is cmp"<<"\n";
162 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
163 FUN_draw(aa,CC);
164
165 return 0;
166}
167
168static Standard_Integer splitF(Draw_Interpretor& di, Standard_Integer n, const char** a)
169{
170 if (n < 2) return 1;
171 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
172 const TopoDS_Face& fa = TopoDS::Face(aLocalShape);
173// const TopoDS_Face& fa = TopoDS::Face(DBRep::Get(a[1]));
174 if (fa.IsNull()) {di<<"null face"<<"\n"; return 1;}
175
176 TopTools_ListOfShape fsplits;
177// Standard_Boolean splitok = FUN_tool_SplitF(fa,fsplits);
178 Standard_Boolean splitok = TopOpeBRepTool_REGUS::SplitF(fa,fsplits);
179
180 if (!splitok) {di<<"no splits"<<"\n"; return 0;}
181 di<<"fa gives "<<fsplits.Extent()<<" splits"<<"\n";
182
183 BRep_Builder BB;
184 TopoDS_Compound CC; BB.MakeCompound(CC);
185 for (TopTools_ListIteratorOfListOfShape it(fsplits); it.More(); it.Next()) BB.Add(CC, it.Value());
186
187 di<<"resulting compound is cmp"<<"\n";
188 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
189 FUN_draw(aa,CC);
190 return 0;
191}
192
193
194static Standard_Integer regush(Draw_Interpretor& di, Standard_Integer n, const char** a)
195{
196 if (n < 2) return 1;
197 const TopoDS_Shape& sha = DBRep::Get(a[1]);
198 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
199 TopExp_Explorer ex(sha, TopAbs_SOLID);
200 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
201 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
202
203 TopTools_DataMapOfShapeListOfShape FSplits;
204 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
205
206 BRep_Builder BB;
207 TopoDS_Compound CC; BB.MakeCompound(CC);
208 Standard_Integer nshe = 0;
209 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
210 if (!regu) {di<<"solid gives no new shell"<<"\n";}
211 else {
212 Standard_Integer noldshe = OldSheNewShe.Extent();
213 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape ite(OldSheNewShe);
214 for (; ite.More(); ite.Next()){
215 const TopoDS_Shape& oldshe = ite.Key();
216 const TopTools_ListOfShape& newshells = ite.Value();
217 if (newshells.IsEmpty()) {BB.Add(CC,oldshe); nshe++;}
218 else {
219 for (TopTools_ListIteratorOfListOfShape it(newshells); it.More(); it.Next()){
220 BB.Add(CC,it.Value()); nshe++;
221 }
222 }
223 } // i = 1..noldshe
224 di <<"noldshe = "<<noldshe<<" gives nshe = "<<nshe<<"\n";
225 di<<"resulting compound is cmp"<<"\n";
226 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
227 FUN_draw(aa,CC);
228 }
229 return 0;
230}
231
232Standard_Integer reguso(Draw_Interpretor& di, Standard_Integer n, const char** a)
233{
234 if (n < 2) return 1;
235 const TopoDS_Shape& sha = DBRep::Get(a[1]);
236 if (sha.IsNull()) {di<<"null shape"<<"\n"; return 1;}
237 TopExp_Explorer ex(sha, TopAbs_SOLID);
238 const TopoDS_Solid& so = TopoDS::Solid(ex.Current());
239 if (so.IsNull()) {di<<"no solid"<<"\n"; return 1;}
240
241 TopTools_DataMapOfShapeListOfShape FSplits;
242 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
243
244 BRep_Builder BB;
245 TopoDS_Compound CC; BB.MakeCompound(CC);
246// Standard_Integer nshe = 0;
247 Standard_Boolean regu = TopOpeBRepTool::RegularizeShells(so,OldSheNewShe,FSplits);
248 if (!regu) {di<<"solid gives no new shell"<<"\n";}
249 else {
250 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(OldSheNewShe);
251
252 TopOpeBRepBuild_ShellToSolid SheToSo;
253 for (; itm.More(); itm.Next()) {
254 const TopTools_ListOfShape& lns = itm.Value();
7fd59977 255 TopTools_ListIteratorOfListOfShape itsh(lns);
256 for (; itsh.More(); itsh.Next()) {
257 const TopoDS_Shell& she = TopoDS::Shell(itsh.Value());
258 SheToSo.AddShell(she);
259 }
260 }
261 TopTools_ListOfShape splits;
262 SheToSo.MakeSolids(so,splits);
263
264 BRep_Builder BB;
265 TopoDS_Compound CC; BB.MakeCompound(CC);
266 Standard_Integer nSo = 0;
267 TopTools_ListIteratorOfListOfShape itSo(splits);
268 for (; itSo.More(); itSo.Next()) {
269 const TopoDS_Shape& spli = itSo.Value();
270 BB.Add(CC,spli);
271 nSo++;
272 }
273 di<<"so gives "<<nSo<<" new solids"<<"\n";
274 di<<"resulting compound is cmp"<<"\n";
275 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
276 FUN_draw(aa,CC);
277 }
278 return 0;
279}
280
281static Standard_Integer purge(Draw_Interpretor& di, Standard_Integer n, const char** a)
282{
283
284 if (n < 2) return 1;
285 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
286 TopoDS_Face fa = TopoDS::Face(aLocalShape);
287// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[1]));
288 if (fa.IsNull()) return 1;
289 TopOpeBRepTool_CORRISO CORRISO(fa);
290 Standard_Real tolF = BRep_Tool::Tolerance(fa);
291 Standard_Real uperiod; Standard_Boolean uclosed = CORRISO.Refclosed(1,uperiod);
292 Standard_Real vperiod; Standard_Boolean vclosed = CORRISO.Refclosed(2,vperiod);
293 if (!uclosed && !vclosed) return 1;
294 Standard_Boolean inU = uclosed ? Standard_True : Standard_False;
295 Standard_Real xmin = inU ? (CORRISO.GASref().FirstUParameter()) : (CORRISO.GASref().LastUParameter());
296 Standard_Real xper = inU ? uperiod : vperiod;
297 Standard_Real tolx = inU ? (CORRISO.Tol(1,tolF)) : (CORRISO.Tol(2,tolF));
298
299 BRep_Builder BB;
300 TopTools_ListOfShape lWs; Standard_Boolean hasnew = Standard_False;
301 TopExp_Explorer exw(fa, TopAbs_WIRE);
302 for (; exw.More(); exw.Next()){
303 const TopoDS_Shape& W = exw.Current();
304
305 CORRISO.Init(W);
306 Standard_Boolean ok = CORRISO.UVClosed();
307 if (ok) {lWs.Append(W); continue;}
308
309 TopTools_ListOfShape cEds;
310 TopTools_ListIteratorOfListOfShape ite(CORRISO.Eds());
311 for (; ite.More(); ite.Next()){
312 const TopoDS_Edge& E = TopoDS::Edge(ite.Value());
313 Standard_Boolean closing = BRep_Tool::IsClosed(E,fa);
314 if (!closing) {// xpu231198 : pcurve modified, the information is lost
315 TopOpeBRepTool_C2DF C2DF; Standard_Boolean isb = CORRISO.UVRep(E,C2DF);
316 if (!isb) return 1;//NYIRAISE
317 Standard_Boolean onclo = TopOpeBRepTool_TOOL::IsonCLO(C2DF,inU,xmin,xper,tolx);
318 if (onclo) closing=Standard_True;
319 }
320 if (closing) cEds.Append(E);
321 }
322 Standard_Integer ncE = cEds.Extent();
323 Standard_Boolean nopurge = (ncE <= 1);
324 if (nopurge) {lWs.Append(W); continue;}
325
326 // Checking <W>
327 TopTools_ListOfShape lfyE; Standard_Boolean topurge = CORRISO.PurgeFyClosingE(cEds,lfyE);
328 if (!topurge) {lWs.Append(W); continue;}
329
330 TopoDS_Wire Wi; BB.MakeWire(Wi); // Add une TShape
331 Wi.Free(Standard_True);
332 ite.Initialize(CORRISO.Eds());
333 for (; ite.More(); ite.Next()) {
334 const TopoDS_Edge& ed = TopoDS::Edge(ite.Value());
335 Standard_Boolean equ = Standard_False;
336 for (TopTools_ListIteratorOfListOfShape itlfyE(lfyE);itlfyE.More();itlfyE.Next()) {
337 const TopoDS_Shape& fyE = itlfyE.Value();
338 if (ed.IsEqual(fyE)) {
339 equ = Standard_True;
340 break;
341 }
342 }
343 if (equ) {
344 continue;
345 }
346 BB.Add(Wi,ed);
347 }
348 lWs.Append(Wi);
349 } // exw
350
351 if (!hasnew) return 1;
352
353 // Building up the new face :
354 aLocalShape = fa.EmptyCopied();
355 TopoDS_Face newF = TopoDS::Face(aLocalShape);
356// TopoDS_Face newF = TopoDS::Face(fa.EmptyCopied());
357 TopTools_ListIteratorOfListOfShape itw(lWs);
358 for (; itw.More(); itw.Next()) BB.Add(newF, TopoDS::Wire(itw.Value()));
359
360 di <<"New face built is newF"<<"\n";
361 TCollection_AsciiString aa("newF");
362 FUN_draw(aa, newF);
363 return 0;
364}
365
366
367Standard_Integer correctONISO(Draw_Interpretor& di, Standard_Integer n, const char** a)
368{
369 if (n < 3) return 1;
370 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
371 TopoDS_Face F = TopoDS::Face(aLocalShape);
372 aLocalShape = DBRep::Get(a[2]);
373 TopoDS_Face Fsp = TopoDS::Face(aLocalShape);
374// TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1]));
375// TopoDS_Face Fsp = TopoDS::Face(DBRep::Get(a[2]));
376
377 FC2D_Prepare(F,F);
378
379 if (F.IsNull() || Fsp.IsNull()) {di<<"NULL shape(s)"<<"\n";return 1;}
380
381 TopOpeBRepTool::CorrectONUVISO(F,Fsp);
382 TCollection_AsciiString aa("newFsp");
383 FUN_draw(aa,Fsp);
384 di<<"-> newFsp"<<"\n";
385
386 return 0;
387}
388
389// ======================================================================
390// useful commands :
391// ======================================================================
392
393static Standard_Integer isclosingE(Draw_Interpretor& di, Standard_Integer n, const char** a)
394{
395 if (n < 3) return 1;
396 TopoDS_Shape aLocalShape = DBRep::Get(a[1]) ;
397 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
398 aLocalShape = DBRep::Get(a[2]);
399 TopoDS_Face fa = TopoDS::Face(aLocalShape);
400// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[1]));
401// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[2]));
402 Standard_Boolean isclosing = BRep_Tool::IsClosed(ed,fa);
403 TopAbs_Orientation oriE = ed.Orientation();
404 if (isclosing) {di <<"edge is ";
405 //TopAbs::Print(oriE,cout);
406 Standard_SStream aSStream;
407 TopAbs::Print(oriE,aSStream);
408 di << aSStream;
409 di<<" closing edge"<<"\n";}
410 else di <<"edge is NOT closing edge"<<"\n";
411 return 0;
412}
413
414static Standard_Integer compareshsh(Draw_Interpretor& di, Standard_Integer n, const char** a)
415{
416 if (n < 3) return 1;
417 TopoDS_Shape sh1 = DBRep::Get(a[1]);
418 TopoDS_Shape sh2 = DBRep::Get(a[2]);
419 Standard_Boolean issame = sh1.IsSame(sh2);
420 if (issame) di<<" same shapes"<<"\n";
421 else di <<" shapes are not same"<<"\n";
422 Standard_Boolean isequal = sh1.IsEqual(sh2); if (isequal) di<<" equal shapes"<<"\n";
423 return 0;
424}
425static Standard_Integer pcurveedgeonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
426{
427 if (n < 3) return 1;
428 TopoDS_Shape ed = DBRep::Get(a[1]);
429 TopoDS_Shape fa = DBRep::Get(a[2]);
430 TCollection_AsciiString aa("edonfa_");
431 FUN_test_draw(aa,TopoDS::Edge(ed),TopoDS::Face(fa),0,di);
432 return 0;
433}
434
435static Standard_Integer pcurvesonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
436{
437 if (n < 3) return 1;
438 TopoDS_Shape sh = DBRep::Get(a[2]);
439 TopoDS_Shape fa = DBRep::Get(a[3]);
440 TopExp_Explorer exe(sh, TopAbs_EDGE);
441 Standard_Integer i = 0;
442 for (; exe.More(); exe.Next()){
443 i++;
444 TCollection_AsciiString aa(a[1]);
445 FUN_test_draw(aa,TopoDS::Edge(exe.Current()),TopoDS::Face(fa),i,di);
446 }
447 return 0;
448}
449
450static Standard_Integer orivine(Draw_Interpretor& di, Standard_Integer n, const char** a)
451{
452 if (n < 3) return 1;
453 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
454 TopoDS_Vertex v = TopoDS::Vertex(aLocalShape);
455 aLocalShape = DBRep::Get(a[2]);
456 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
457// TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
458// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
459
460 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
461 if (ori==0) di<<"v not in ed"<<"\n";
462 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
463 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
464 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
465 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
466 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
467 return 0;
468}
469
470static Standard_Integer vine(Draw_Interpretor& di, Standard_Integer n, const char** a)
471{
472 if (n < 4) return 1;
473 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
474 TopoDS_Vertex v = TopoDS::Vertex(aLocalShape);
475 aLocalShape = DBRep::Get(a[2]);
476 TopoDS_Edge ed = TopoDS::Edge(aLocalShape);
477 aLocalShape = DBRep::Get(a[3]);
478 TopoDS_Face fa = TopoDS::Face(aLocalShape);
479// TopoDS_Vertex v = TopoDS::Vertex(DBRep::Get(a[1]));
480// TopoDS_Edge ed = TopoDS::Edge(DBRep::Get(a[2]));
481// TopoDS_Face fa = TopoDS::Face(DBRep::Get(a[3]));
482
483 Standard_Real pf,pl;
484 const Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(ed,fa,pf,pl);
485 gp_Pnt2d p2df, p2dl; PC->D0(pf,p2df); PC->D0(pl,p2dl);
486 di << "p2df";FUN_cout(p2df,di); di << "p2dl";FUN_cout(p2dl,di);di<<"\n";
487
488 Standard_Integer ori = TopOpeBRepTool_TOOL::OriinSor(v,ed);
489 if (ori==0) {di<<"v not in ed"<<"\n"; return 0;}
490 else if (ori==1) di<<"v FORWARD in ed"<<"\n";
491 else if (ori==2) di<<"v REVERSED in ed"<<"\n";
492 else if (ori==3) di<<"v INTERNAL in ed"<<"\n";
493 else if (ori==4) di<<"v EXTERNAL in ed"<<"\n";
494 else if (ori==5) di<<"v CLOSING in ed"<<"\n";
495
496 if ((ori == 1) || (ori == 2)) {
497 Standard_Real par = TopOpeBRepTool_TOOL::ParE(ori,ed);//FUN_tool_parOnE(ind,ed,fa);
498 gp_Pnt2d p2d; PC->D0(par,p2d);
499 di <<"p2d : with TopOpeBRepTool_TOOL::ParE";FUN_cout(p2d,di);di<<"\n";
500 }
501
502 Standard_Real par = BRep_Tool::Parameter(v,ed,fa);
503 gp_Pnt2d pp2d; PC->D0(par,pp2d);
504 di <<"p2d computed with BRep_Tool::Parameter";FUN_cout(pp2d,di);di<<"\n";
505
506 return 0;
507}
508
509static Standard_Integer issubshape(Draw_Interpretor& di, Standard_Integer n, const char** a)
510{
511 if (n < 3) return 1;
512 TopoDS_Shape subshape = DBRep::Get(a[1]);
513 TopoDS_Shape shape = DBRep::Get(a[2]);
514 TopExp_Explorer ex(shape, subshape.ShapeType());
515 Standard_Boolean issubs = Standard_False;
516 for (; ex.More(); ex.Next())
517 if (ex.Current().IsSame(subshape)) {issubs = Standard_True; break;}
518
519 if (issubs) di<<" is subshape"<<"\n";
520 else di<<" is NOT subshape"<<"\n";
521 return 0;
522}
523
524void FUN_mkBnd2dBREP(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d,const Standard_Integer& i)
525{
526 // greater <B> with <W>'s UV representation on <F>
527 Standard_Real tol = 1.e-8;
528 TopExp_Explorer ex;
529 for (ex.Init(W, TopAbs_EDGE); ex.More(); ex.Next()) {
530// for (TopExp_Explorer ex(W, TopAbs_EDGE); ex.More(); ex.Next()) {
531 if (i == 0) {
532 FUN_tool_mkBnd2d(W,F,B2d);
533 }
534 if (i == 1) {
535 BRepAdaptor_Curve2d BC2d(TopoDS::Edge(ex.Current()), TopoDS::Face(F));
536 BndLib_Add2dCurve::Add(BC2d, tol, B2d);
537 }
538 if (i == 2) {
539 Standard_Real f,l;
540 Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),TopoDS::Face(F),f,l);
541 Geom2dAdaptor_Curve GC2d(PC);
542 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
543 }
544 if (i == 3) {
545 TopLoc_Location L; Standard_Real f,l;
546 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(F),L);
547 const Handle(Geom2d_Curve)& PC = BRep_Tool::CurveOnSurface(TopoDS::Edge(ex.Current()),S,L,f,l);
548 Geom2dAdaptor_Curve GC2d(PC);
549 BndLib_Add2dCurve::Add(GC2d, tol, B2d);
550 }
551
552 } //ex(W,EDGE)
553}
554
555static Standard_Integer drawbnd2d(Draw_Interpretor& , Standard_Integer n, const char** a)
556{
557 if (n < 5) return 1;
91322f44 558 Standard_Integer i = Draw::Atoi(a[4]);
7fd59977 559 TopoDS_Shape W = DBRep::Get(a[2]);
560 TopoDS_Shape F = DBRep::Get(a[3]);
561 if (W.IsNull() || F.IsNull()) return 1;
562 Bnd_Box2d B2d;
563 Standard_Real umin,vmin,umax,vmax;
564 FUN_mkBnd2dBREP(W,F,B2d,i);
565 B2d.Get(umin,vmin,umax,vmax);
566
567 Handle(Geom2d_Line) cx = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(1.,0.));
568 Handle(Geom2d_Line) cy = new Geom2d_Line(gp_Pnt2d(umin,vmin),gp_Dir2d(0.,1.));
569 gp_Trsf2d tx; gp_Vec2d vx(umax-umin,0.); tx.SetTranslation(vx);
570 gp_Trsf2d ty; gp_Vec2d vy(0.,vmax-vmin); ty.SetTranslation(vy);
571
543a9964 572 Handle(Geom2d_Curve) tcx = new Geom2d_TrimmedCurve(cx,0.,umax-umin);
573 Handle(Geom2d_Curve) tcy = new Geom2d_TrimmedCurve(cy,0.,vmax-vmin);
574 Handle(Geom2d_Curve) tccx = Handle(Geom2d_Curve)::DownCast (tcx->Copy());
575 tccx->Transform(ty);
576 Handle(Geom2d_Curve) tccy = Handle(Geom2d_Curve)::DownCast (tcy->Copy());
577 tccy->Transform(tx);
7fd59977 578
579 Draw_Color col(Draw_blanc);
580 DrawTrSurf_CurveColor(col);
581
582 TCollection_AsciiString aa3 = TCollection_AsciiString(a[1]); aa3 += TCollection_AsciiString(3);
583 TCollection_AsciiString aa4 = TCollection_AsciiString(a[1]); aa4 += TCollection_AsciiString(4);
584
585 TCollection_AsciiString aa;
586 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(1); char* aaa = (char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcx);
587 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(2); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcy);
588 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(3); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccx);
589 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(4); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccy);
590 return 0;
591}
592
593static Standard_Integer classifBnd2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
594{
595 if (n < 5) return 1;
596 TopoDS_Shape W1 = DBRep::Get(a[1]);
597 TopoDS_Shape W2 = DBRep::Get(a[2]);
598 TopoDS_Shape F = DBRep::Get(a[3]);
7fd59977 599
600 TopoDS_Wire w1 = TopoDS::Wire(W1);
601 TopoDS_Wire w2 = TopoDS::Wire(W2);
602 TopoDS_Face Fref = TopoDS::Face(F);
603
604 TopOpeBRepTool_CLASSI classi; classi.Init2d(Fref);
605 Standard_Real tolF = BRep_Tool::Tolerance(Fref);
606 Standard_Real toluv = TopOpeBRepTool_TOOL::TolUV(Fref,tolF);
607
608 if (w1.IsNull() || w2.IsNull() || Fref.IsNull()) return 1;
609
0797d9d3 610#ifdef OCCT_DEBUG
96a95605
DB
611 Standard_Integer sta =
612#endif
613 classi.ClassiBnd2d(w1,w2,toluv,Standard_True);
7fd59977 614 di <<"wires classification : checklarge=true ";
0797d9d3 615#ifdef OCCT_DEBUG
7fd59977 616 FUN_tool_coutsta(sta,1,2);
617#endif
618
0797d9d3 619#ifdef OCCT_DEBUG
96a95605
DB
620 sta =
621#endif
622 classi.ClassiBnd2d(w1,w2,toluv,Standard_False);
7fd59977 623 di <<"wires classification : checklarge=false ";
0797d9d3 624#ifdef OCCT_DEBUG
7fd59977 625 FUN_tool_coutsta(sta,1,2);
626#endif
627
628 return 0;
629}
630
631static Standard_Integer pntonc(Draw_Interpretor& di, Standard_Integer n, const char** a)
632{
633 if (n < 3) return 1;
91322f44 634 Standard_Real x = Draw::Atof(a[1]);
7fd59977 635 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
636 if (C.IsNull()) {di<<"null curve"<<"\n"; return 1;}
637 gp_Pnt p = C->Value(x);
638 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
639 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
640 return 0;
641}
642
643static Standard_Integer pntonc2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
644{
645 if (n < 4) return 1;
91322f44 646 Standard_Real x = Draw::Atof(a[1]);
7fd59977 647 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
648 if (C2d.IsNull()) {di<<"null curve"<<"\n"; return 1;}
649 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
650 if (S.IsNull()) {di<<"null surface"<<"\n"; return 1;}
651 gp_Pnt2d p2d = C2d->Value(x);
652 di<<"point on curve of parameter "<<x<<" =("<<p2d.X()<<","<<p2d.Y()<<")"<<"\n";
653 gp_Pnt p = S->Value(p2d.X(),p2d.Y());
654 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
655 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
656 return 0;
657}
658
659static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
660{
d633fd70 661 if (n < 3) {
662 di << "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
663 return 1;
664 }
665 //
7fd59977 666 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
667 TopoDS_Face f = TopoDS::Face(aLocalShape);
d633fd70 668 //
669 if (f.IsNull()) {
670 di<<"null shape"<<"\n";
671 return 1;
672 }
673 //
674 Standard_Real dist=0.;
675 Standard_Boolean ok;
676 gp_Pnt2d uv;
677 gp_Pnt p, pproj;
95978b28 678 Extrema_ExtAlgo anExtAlgo = Extrema_ExtAlgo_Grad;
679 Extrema_ExtFlag anExtFlag = Extrema_ExtFlag_MINMAX;
d633fd70 680 //
681 DrawTrSurf::GetPoint(a[2], p);
682 //
683 if (n > 3) {
684 const char* key1 = a[3];
685 const char* key2 = (n > 4) ? a[4] : NULL;
686 if (key1) {
687 if (!strcasecmp(key1,"-min")) {
95978b28 688 anExtFlag = Extrema_ExtFlag_MIN;
d633fd70 689 } else if (!strcasecmp(key1,"-max")) {
95978b28 690 anExtFlag = Extrema_ExtFlag_MAX;
d633fd70 691 } else {
95978b28 692 anExtAlgo = (!strcasecmp(key1,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
d633fd70 693 }
694 }
695 if (key2) {
95978b28 696 anExtAlgo = (!strcasecmp(key2,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
d633fd70 697 }
698 }
95978b28 699 ok = FUN_tool_projPonF(p, f, uv, dist, anExtFlag, anExtAlgo);
d633fd70 700 //
701 if (!ok) {
702 di<<"projection failed"<<"\n";
703 return 1;
704 }
705 //
706 ok = FUN_tool_value(uv,f,pproj);
707 if (!ok) {
708 di<<"projection failed"<<"\n";
709 return 1;
710 }
711 //
7fd59977 712 di<<"proj dist = "<<dist<<" uvproj = ("<<uv.X()<<" "<<uv.Y();
713 di<<"); pproj = ("<<pproj.X()<<" "<<pproj.Y()<<" "<<pproj.Z()<<")"<<"\n";
714 return 0;
715}
716
717static Standard_Integer tolmax(Draw_Interpretor& di, Standard_Integer n, const char** a)
718{
719 if (n < 2) return 1;
720 TopoDS_Shape s = DBRep::Get(a[1]);
721 if (s.IsNull()) {di<<"null shape"<<"\n"; return 1;}
722 Standard_Real tol = FUN_tool_maxtol(s);
723 di<<"max tol = "<<tol<<"\n";
724 return 0;
725}
726
727static Standard_Integer solidclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
728{
729 if (n < 4) return 1;
730 TopoDS_Shape s = DBRep::Get(a[1]);
731 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
732 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
91322f44 733 Standard_Real tol = Draw::Atof(a[3]);
7fd59977 734
735 TopOpeBRepTool_SolidClassifier soclassi;
736 TopAbs_State sta = TopAbs_UNKNOWN;
737 if (s.ShapeType() == TopAbs_SOLID) soclassi.Classify(TopoDS::Solid(s),p,tol);
738 else if (s.ShapeType() == TopAbs_SHELL) soclassi.Classify(TopoDS::Shell(s),p,tol);
739 else {di<<"shape is not a solid nor a shell => KO"<<"\n"; return 1;}
740
741 sta = soclassi.State();
742 di<<"point is ";
743 //TopAbs::Print(sta,cout);
744 Standard_SStream aSStream;
745 TopAbs::Print(sta,aSStream);
746 di << aSStream;
747 di<<" shape s"<<"\n";
748 return 0;
749}
750
751static Standard_Integer class3dclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
752{
753 if (n < 4) return 1;
754 TopoDS_Shape s = DBRep::Get(a[1]);
755 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
756 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
91322f44 757 Standard_Real tol = Draw::Atof(a[3]);
7fd59977 758
759 BRepClass3d_SolidClassifier soclassi(s);
760 TopAbs_State sta = TopAbs_UNKNOWN;
761 soclassi.Perform(p,tol);
762
763 sta = soclassi.State();
764 di<<"point is ";
765 //TopAbs::Print(sta,cout);
766 Standard_SStream aSStream;
767 TopAbs::Print(sta,aSStream);
768 di << aSStream;
769 di<<" shape s"<<"\n";
770 return 0;
771}
772static Standard_Integer shapeclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
773{
774 if (n < 3) return 1;
775 TopoDS_Shape sh = DBRep::Get(a[1]);
776 if (sh.IsNull()) {di<<"null shape"<<"\n";return 1;}
777 TopoDS_Shape shref = DBRep::Get(a[2]);
778 if (shref.IsNull()) {di<<"null reference shape"<<"\n";return 1;}
779 Standard_Boolean hastoavoid = (n > 3);
780 TopTools_ListOfShape toavoid;
781 if (hastoavoid) {
782 for (Standard_Integer i=3; i<=n; i++) {
783 TopoDS_Shape shtoavoid = DBRep::Get(a[i]);
784 if (shtoavoid.IsNull()) {di<<"null toavoid shape"<<"\n";return 1;}
785 toavoid.Append(shtoavoid);
786 }
787 }
788
789 TopOpeBRepTool_ShapeClassifier shclassi;
790 TopAbs_State sta = TopAbs_UNKNOWN;
791 if (hastoavoid) sta = shclassi.StateShapeShape(sh,shref);
792 else if (toavoid.Extent() == 1) sta = shclassi.StateShapeShape(sh,toavoid.First(),shref);
793 else sta = shclassi.StateShapeShape(sh,toavoid,shref);
794
795 di<<"shape is ";
796 //TopAbs::Print(sta,cout);
797 Standard_SStream aSStream;
798 TopAbs::Print(sta,aSStream);
799 di << aSStream;
800 di<<" shape ref"<<"\n";
801 return 0;
802}
803
804
805// normals ..
806static Standard_Integer normal(Draw_Interpretor& di, Standard_Integer n, const char** a)
807{
808 if (n < 3) return 1;
809 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
810 TopoDS_Face f = TopoDS::Face(aLocalShape);
811// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
812 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
813 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
302f96fb 814
7fd59977 815 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
816 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
0797d9d3 817#ifdef OCCT_DEBUG
7fd59977 818 gp_Vec ngf =
819#endif
820 FUN_tool_nggeomF(uv,f);
821 TCollection_AsciiString aa("ngS");
822#ifdef DRAW
823 FUN_tool_draw(aa,p,ngf,length);
824#endif
825 return 0;
826}
827
828static Standard_Integer curvature(Draw_Interpretor& di, Standard_Integer n, const char** a)
829{
830 if (n < 5) return 1;
831 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
832 TopoDS_Face f = TopoDS::Face(aLocalShape);
833// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
834 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
91322f44 835 Standard_Real x = Draw::Atof(a[2]);
836 Standard_Real y = Draw::Atof(a[3]);
837 Standard_Real z = Draw::Atof(a[4]);
7fd59977 838 Handle(Geom_Line) line = new Geom_Line(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(x,y,z)));
839 BRepAdaptor_Surface BS(f);
840 Handle(Geom_Surface) su = BRep_Tool::Surface(f);
841 GeomAPI_IntCS intcs(line,su);
842 Standard_Boolean done = intcs.IsDone();
843 if (!done) {di<<"intersection point on surface not found"<<"\n"; return 1;}
844 Standard_Integer npnts = intcs.NbPoints();
845 if (npnts < 1) {di<<"intersection point on surface not found"<<"\n"; return 1;}
846
847 Standard_Real tol = Precision::Confusion();
848 BRepLProp_SLProps props(BS,2,tol);
7fd59977 849 gp_Dir Norm,D1,D2;
850 for (Standard_Integer i = 1; i <= npnts; i++) {
851 gp_Pnt p = intcs.Point(i);
852 Standard_Real u,v,w; intcs.Parameters(i,u,v,w);
853 di<<"point("<<i<<") = { ("<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"), ("<<u<<" "<<v<<") }"<<"\n";
854 props.SetParameters(u,v);
855 Standard_Boolean curdef = props.IsCurvatureDefined();
856 if (!curdef) {di<<"!IsCurvatureDefined"<<"\n"; continue;}
857 Standard_Boolean umbilic = props.IsUmbilic();
858 if (umbilic) {
7fd59977 859 D1 = gp_Dir(0,0,1);
860 D2 = gp_Dir(0,1,0);
861 di<<"umbilic";
862 }
863 else {
7fd59977 864 props.CurvatureDirections(D1,D2);
865 }
866 Norm = gp_Dir(D1^D2);
867 di<<"D1 = ("<<D1.X()<<" "<<D1.Y()<<" "<<D1.Z()<<" "<<")"<<"\n";
868 di<<"D2 = ("<<D2.X()<<" "<<D2.Y()<<" "<<D2.Z()<<" "<<")"<<"\n";
869 di<<"Norm = ("<<Norm.X()<<" "<<Norm.Y()<<" "<<Norm.Z()<<" "<<")"<<"\n";
870 } // i
871 return 0;
872}
873
874void TestTopOpe::CORCommands(Draw_Interpretor& theCommands)
875{
876 static Standard_Boolean done = Standard_False;
877 if (done) return; done = Standard_True;
878 const char* g = "TestTopOpe CORCommands";
879 // purge, regularization commands :
880 theCommands.Add("purge", "purge f", __FILE__, purge, g);
881 theCommands.Add("corrISO", "corrISO f Fsp", __FILE__, correctONISO, g);
882 theCommands.Add("regufa", "regufa f", __FILE__, regularize, g);
883 theCommands.Add("splitf", "splitf f", __FILE__, splitF, g);
884 theCommands.Add("regush", "regush so", __FILE__, regush, g);
885 theCommands.Add("reguso", "reguso so", __FILE__, reguso, g);
886 // builder commands :
887 theCommands.Add("soclass", "soclass sh pnt tol", __FILE__, solidclassifier, g);
888 theCommands.Add("shclass", "shclass sh shref <toavoid>", __FILE__, shapeclassifier, g);
889 theCommands.Add("clclass", "clclass sh shref <toavoid>", __FILE__, class3dclassifier, g);
890
891 // useful commands :
892 theCommands.Add("cled", "cled ed f", __FILE__, isclosingE, g);
893 theCommands.Add("compare", "compare s1 s2", __FILE__, compareshsh, g);
894 theCommands.Add("edonfa", "edonfa ed f", __FILE__, pcurveedgeonface, g);
895 theCommands.Add("pconfa", "pconfa name s f", __FILE__, pcurvesonface, g);
896 theCommands.Add("orivine", "orivine v ed", __FILE__, orivine, g);
897 theCommands.Add("vine", "vine v ed fa", __FILE__, vine, g);
898 theCommands.Add("issubsh", "issubsh subsh sh", __FILE__, issubshape, g);
899 theCommands.Add("bnd2d", "bnd2d name W F i", __FILE__, drawbnd2d, g);
900 theCommands.Add("classibnd2d","classibnd2d W1 W2 F i", __FILE__, classifBnd2d, g);
901 theCommands.Add("pntonc", "pntonc par C3d", __FILE__, pntonc, g);
902 theCommands.Add("pntonc2d", "pntonc2d par C2d S", __FILE__, pntonc2d, g);
d633fd70 903 theCommands.Add("projponf",
904 "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]",
905 __FILE__, projponf, g);
7fd59977 906 theCommands.Add("tolmax", "tolmax s", __FILE__, tolmax, g);
907 theCommands.Add("normal", "normal f p3d length", __FILE__, normal, g);
908 theCommands.Add("curvature", "curvature f x y z", __FILE__, curvature , g);
909
910}