1 // Created on: 1997-07-24
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
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>
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>
44 #include <TopoDS_Solid.hxx>
45 #include <TopoDS_Wire.hxx>
46 #include <TopoDS_Compound.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>
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>
66 #include <Draw_Interpretor.hxx>
67 #include <DrawTrSurf.hxx>
68 #include <Draw_Color.hxx>
71 #include <Extrema_ExtFlag.hxx>
72 #include <Extrema_ExtAlgo.hxx>
75 #include <TopOpeBRepTool_DRAW.hxx>
78 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
79 Standard_IMPORT void DBRep_WriteColorOrientation ();
80 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
82 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
83 Standard_IMPORT void DBRep_WriteColorOrientation ();
84 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
85 Standard_EXPORT void FUN_tool_mkBnd2d(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d);
86 Standard_EXPORT void FUN_tool_UpdateBnd2d(Bnd_Box2d& B2d, const Bnd_Box2d& newB2d);
87 Standard_IMPORT Standard_Integer FUN_tool_classiBnd2d(const Bnd_Array1OfBox2d& B,const Standard_Boolean chklarge = Standard_True);
88 Standard_IMPORT Standard_Boolean FUN_tool_chkp2dFORinE(const gp_Pnt2d& p2d,const TopoDS_Edge& E,
89 const TopoDS_Face& F, Standard_Real& tol2d);
90 Standard_IMPORT TopoDS_Vertex FUN_tool_getv(const Standard_Integer Index,const TopoDS_Edge& E);
99 static 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)
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();
110 Standard_Boolean coldef = Standard_False;
111 TopExp_Explorer ex(F,TopAbs_EDGE);
113 DrawTrSurf_CurveColor(Draw_Color(Draw_rouge));
114 for (; ex.More(); ex.Next())
115 if (E.IsEqual(ex.Current()))
116 {col = DBRep_ColorOrientation(ex.Current().Orientation());
117 coldef = Standard_True;
119 if (!coldef) col = DBRep_ColorOrientation(E.Orientation());
121 DrawTrSurf_CurveColor(col);
122 DrawTrSurf::Set(aaa,new Geom2d_TrimmedCurve(PC,f,l));
125 void FUN_draw(const TCollection_AsciiString aa,const TopoDS_Shape& s)
126 {char* aaa = (char *)aa.ToCString(); DBRep::Set(aaa,s);}
128 void FUN_cout(const gp_Pnt2d& p2d, Draw_Interpretor& di)
129 {di <<" = ("<<p2d.X()<<" "<<p2d.Y()<<") ";}
132 Standard_IMPORT void FUN_tool_coutsta(const Standard_Integer& sta, const Standard_Integer& i1, const Standard_Integer& i2);
136 Standard_Integer regularize(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;}
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";
150 Standard_Integer i = 0;
151 TopTools_ListIteratorOfListOfShape itlof(lof) ;
152 for ( ; itlof.More(); itlof.Next()) {
154 TCollection_AsciiString aa = TCollection_AsciiString("fa_");
155 aa += TCollection_AsciiString(i);
156 FUN_draw(aa,itlof.Value());
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");
168 static Standard_Integer splitF(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;}
176 TopTools_ListOfShape fsplits;
177 // Standard_Boolean splitok = FUN_tool_SplitF(fa,fsplits);
178 Standard_Boolean splitok = TopOpeBRepTool_REGUS::SplitF(fa,fsplits);
180 if (!splitok) {di<<"no splits"<<"\n"; return 0;}
181 di<<"fa gives "<<fsplits.Extent()<<" splits"<<"\n";
184 TopoDS_Compound CC; BB.MakeCompound(CC);
185 for (TopTools_ListIteratorOfListOfShape it(fsplits); it.More(); it.Next()) BB.Add(CC, it.Value());
187 di<<"resulting compound is cmp"<<"\n";
188 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
194 static Standard_Integer regush(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;}
203 TopTools_DataMapOfShapeListOfShape FSplits;
204 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
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";}
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++;}
219 for (TopTools_ListIteratorOfListOfShape it(newshells); it.More(); it.Next()){
220 BB.Add(CC,it.Value()); nshe++;
224 di <<"noldshe = "<<noldshe<<" gives nshe = "<<nshe<<"\n";
225 di<<"resulting compound is cmp"<<"\n";
226 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
232 Standard_Integer reguso(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;}
241 TopTools_DataMapOfShapeListOfShape FSplits;
242 TopTools_DataMapOfShapeListOfShape OldSheNewShe;
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";}
250 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(OldSheNewShe);
252 TopOpeBRepBuild_ShellToSolid SheToSo;
253 for (; itm.More(); itm.Next()) {
254 const TopTools_ListOfShape& lns = itm.Value();
255 TopTools_ListIteratorOfListOfShape itsh(lns);
256 for (; itsh.More(); itsh.Next()) {
257 const TopoDS_Shell& she = TopoDS::Shell(itsh.Value());
258 SheToSo.AddShell(she);
261 TopTools_ListOfShape splits;
262 SheToSo.MakeSolids(so,splits);
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();
273 di<<"so gives "<<nSo<<" new solids"<<"\n";
274 di<<"resulting compound is cmp"<<"\n";
275 TCollection_AsciiString aa = TCollection_AsciiString("cmp");
281 static Standard_Integer purge(Draw_Interpretor& di, Standard_Integer n, const char** a)
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));
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();
306 Standard_Boolean ok = CORRISO.UVClosed();
307 if (ok) {lWs.Append(W); continue;}
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;
320 if (closing) cEds.Append(E);
322 Standard_Integer ncE = cEds.Extent();
323 Standard_Boolean nopurge = (ncE <= 1);
324 if (nopurge) {lWs.Append(W); continue;}
327 TopTools_ListOfShape lfyE; Standard_Boolean topurge = CORRISO.PurgeFyClosingE(cEds,lfyE);
328 if (!topurge) {lWs.Append(W); continue;}
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)) {
351 if (!hasnew) return 1;
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()));
360 di <<"New face built is newF"<<"\n";
361 TCollection_AsciiString aa("newF");
367 Standard_Integer correctONISO(Draw_Interpretor& di, Standard_Integer n, const char** a)
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]));
379 if (F.IsNull() || Fsp.IsNull()) {di<<"NULL shape(s)"<<"\n";return 1;}
381 TopOpeBRepTool::CorrectONUVISO(F,Fsp);
382 TCollection_AsciiString aa("newFsp");
384 di<<"-> newFsp"<<"\n";
389 // ======================================================================
391 // ======================================================================
393 static Standard_Integer isclosingE(Draw_Interpretor& di, Standard_Integer n, const char** a)
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);
409 di<<" closing edge"<<"\n";}
410 else di <<"edge is NOT closing edge"<<"\n";
414 static Standard_Integer compareshsh(Draw_Interpretor& di, Standard_Integer n, const char** a)
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";
425 static Standard_Integer pcurveedgeonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
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);
435 static Standard_Integer pcurvesonface(Draw_Interpretor& di, Standard_Integer n, const char** a)
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()){
444 TCollection_AsciiString aa(a[1]);
445 FUN_test_draw(aa,TopoDS::Edge(exe.Current()),TopoDS::Face(fa),i,di);
450 static Standard_Integer orivine(Draw_Interpretor& di, Standard_Integer n, const char** a)
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]));
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";
470 static Standard_Integer vine(Draw_Interpretor& di, Standard_Integer n, const char** a)
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]));
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";
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";
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";
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";
509 static Standard_Integer issubshape(Draw_Interpretor& di, Standard_Integer n, const char** a)
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;}
519 if (issubs) di<<" is subshape"<<"\n";
520 else di<<" is NOT subshape"<<"\n";
524 void FUN_mkBnd2dBREP(const TopoDS_Shape& W, const TopoDS_Shape& F,Bnd_Box2d& B2d,const Standard_Integer& i)
526 // greater <B> with <W>'s UV representation on <F>
527 Standard_Real tol = 1.e-8;
529 for (ex.Init(W, TopAbs_EDGE); ex.More(); ex.Next()) {
530 // for (TopExp_Explorer ex(W, TopAbs_EDGE); ex.More(); ex.Next()) {
532 FUN_tool_mkBnd2d(W,F,B2d);
535 BRepAdaptor_Curve2d BC2d(TopoDS::Edge(ex.Current()), TopoDS::Face(F));
536 BndLib_Add2dCurve::Add(BC2d, tol, B2d);
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);
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);
555 static Standard_Integer drawbnd2d(Draw_Interpretor& , Standard_Integer n, const char** a)
558 Standard_Integer i = Draw::Atoi(a[4]);
559 TopoDS_Shape W = DBRep::Get(a[2]);
560 TopoDS_Shape F = DBRep::Get(a[3]);
561 if (W.IsNull() || F.IsNull()) return 1;
563 Standard_Real umin,vmin,umax,vmax;
564 FUN_mkBnd2dBREP(W,F,B2d,i);
565 B2d.Get(umin,vmin,umax,vmax);
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);
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());
576 Handle(Geom2d_Curve) tccy = Handle(Geom2d_Curve)::DownCast (tcy->Copy());
579 Draw_Color col(Draw_blanc);
580 DrawTrSurf_CurveColor(col);
582 TCollection_AsciiString aa3 = TCollection_AsciiString(a[1]); aa3 += TCollection_AsciiString(3);
583 TCollection_AsciiString aa4 = TCollection_AsciiString(a[1]); aa4 += TCollection_AsciiString(4);
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);
593 static Standard_Integer classifBnd2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
596 TopoDS_Shape W1 = DBRep::Get(a[1]);
597 TopoDS_Shape W2 = DBRep::Get(a[2]);
598 TopoDS_Shape F = DBRep::Get(a[3]);
600 TopoDS_Wire w1 = TopoDS::Wire(W1);
601 TopoDS_Wire w2 = TopoDS::Wire(W2);
602 TopoDS_Face Fref = TopoDS::Face(F);
604 TopOpeBRepTool_CLASSI classi; classi.Init2d(Fref);
605 Standard_Real tolF = BRep_Tool::Tolerance(Fref);
606 Standard_Real toluv = TopOpeBRepTool_TOOL::TolUV(Fref,tolF);
608 if (w1.IsNull() || w2.IsNull() || Fref.IsNull()) return 1;
611 Standard_Integer sta =
613 classi.ClassiBnd2d(w1,w2,toluv,Standard_True);
614 di <<"wires classification : checklarge=true ";
616 FUN_tool_coutsta(sta,1,2);
622 classi.ClassiBnd2d(w1,w2,toluv,Standard_False);
623 di <<"wires classification : checklarge=false ";
625 FUN_tool_coutsta(sta,1,2);
631 static Standard_Integer pntonc(Draw_Interpretor& di, Standard_Integer n, const char** a)
634 Standard_Real x = Draw::Atof(a[1]);
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";
643 static Standard_Integer pntonc2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
646 Standard_Real x = Draw::Atof(a[1]);
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";
659 static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
662 di << "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
666 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
667 TopoDS_Face f = TopoDS::Face(aLocalShape);
670 di<<"null shape"<<"\n";
674 Standard_Real dist=0.;
678 Extrema_ExtAlgo anExtAlgo = Extrema_ExtAlgo_Grad;
679 Extrema_ExtFlag anExtFlag = Extrema_ExtFlag_MINMAX;
681 DrawTrSurf::GetPoint(a[2], p);
684 const char* key1 = a[3];
685 const char* key2 = (n > 4) ? a[4] : NULL;
687 if (!strcasecmp(key1,"-min")) {
688 anExtFlag = Extrema_ExtFlag_MIN;
689 } else if (!strcasecmp(key1,"-max")) {
690 anExtFlag = Extrema_ExtFlag_MAX;
692 anExtAlgo = (!strcasecmp(key1,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
696 anExtAlgo = (!strcasecmp(key2,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
699 ok = FUN_tool_projPonF(p, f, uv, dist, anExtFlag, anExtAlgo);
702 di<<"projection failed"<<"\n";
706 ok = FUN_tool_value(uv,f,pproj);
708 di<<"projection failed"<<"\n";
712 di<<"proj dist = "<<dist<<" uvproj = ("<<uv.X()<<" "<<uv.Y();
713 di<<"); pproj = ("<<pproj.X()<<" "<<pproj.Y()<<" "<<pproj.Z()<<")"<<"\n";
717 static Standard_Integer solidclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
720 TopoDS_Shape s = DBRep::Get(a[1]);
721 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
722 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
723 Standard_Real tol = Draw::Atof(a[3]);
725 TopOpeBRepTool_SolidClassifier soclassi;
726 TopAbs_State sta = TopAbs_UNKNOWN;
727 if (s.ShapeType() == TopAbs_SOLID) soclassi.Classify(TopoDS::Solid(s),p,tol);
728 else if (s.ShapeType() == TopAbs_SHELL) soclassi.Classify(TopoDS::Shell(s),p,tol);
729 else {di<<"shape is not a solid nor a shell => KO"<<"\n"; return 1;}
731 sta = soclassi.State();
733 //TopAbs::Print(sta,cout);
734 Standard_SStream aSStream;
735 TopAbs::Print(sta,aSStream);
737 di<<" shape s"<<"\n";
741 static Standard_Integer class3dclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
744 TopoDS_Shape s = DBRep::Get(a[1]);
745 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
746 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
747 Standard_Real tol = Draw::Atof(a[3]);
749 BRepClass3d_SolidClassifier soclassi(s);
750 TopAbs_State sta = TopAbs_UNKNOWN;
751 soclassi.Perform(p,tol);
753 sta = soclassi.State();
755 //TopAbs::Print(sta,cout);
756 Standard_SStream aSStream;
757 TopAbs::Print(sta,aSStream);
759 di<<" shape s"<<"\n";
762 static Standard_Integer shapeclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
765 TopoDS_Shape sh = DBRep::Get(a[1]);
766 if (sh.IsNull()) {di<<"null shape"<<"\n";return 1;}
767 TopoDS_Shape shref = DBRep::Get(a[2]);
768 if (shref.IsNull()) {di<<"null reference shape"<<"\n";return 1;}
769 Standard_Boolean hastoavoid = (n > 3);
770 TopTools_ListOfShape toavoid;
772 for (Standard_Integer i=3; i<=n; i++) {
773 TopoDS_Shape shtoavoid = DBRep::Get(a[i]);
774 if (shtoavoid.IsNull()) {di<<"null toavoid shape"<<"\n";return 1;}
775 toavoid.Append(shtoavoid);
779 TopOpeBRepTool_ShapeClassifier shclassi;
780 TopAbs_State sta = TopAbs_UNKNOWN;
781 if (hastoavoid) sta = shclassi.StateShapeShape(sh,shref);
782 else if (toavoid.Extent() == 1) sta = shclassi.StateShapeShape(sh,toavoid.First(),shref);
783 else sta = shclassi.StateShapeShape(sh,toavoid,shref);
786 //TopAbs::Print(sta,cout);
787 Standard_SStream aSStream;
788 TopAbs::Print(sta,aSStream);
790 di<<" shape ref"<<"\n";
796 static Standard_Integer normal(Draw_Interpretor& di, Standard_Integer n, const char** a)
799 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
800 TopoDS_Face f = TopoDS::Face(aLocalShape);
801 // TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
802 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
803 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
805 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
806 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
810 FUN_tool_nggeomF(uv,f);
811 TCollection_AsciiString aa("ngS");
813 FUN_tool_draw(aa,p,ngf,length);
818 static Standard_Integer curvature(Draw_Interpretor& di, Standard_Integer n, const char** a)
821 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
822 TopoDS_Face f = TopoDS::Face(aLocalShape);
823 // TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
824 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
825 Standard_Real x = Draw::Atof(a[2]);
826 Standard_Real y = Draw::Atof(a[3]);
827 Standard_Real z = Draw::Atof(a[4]);
828 Handle(Geom_Line) line = new Geom_Line(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(x,y,z)));
829 BRepAdaptor_Surface BS(f);
830 Handle(Geom_Surface) su = BRep_Tool::Surface(f);
831 GeomAPI_IntCS intcs(line,su);
832 Standard_Boolean done = intcs.IsDone();
833 if (!done) {di<<"intersection point on surface not found"<<"\n"; return 1;}
834 Standard_Integer npnts = intcs.NbPoints();
835 if (npnts < 1) {di<<"intersection point on surface not found"<<"\n"; return 1;}
837 Standard_Real tol = Precision::Confusion();
838 BRepLProp_SLProps props(BS,2,tol);
840 for (Standard_Integer i = 1; i <= npnts; i++) {
841 gp_Pnt p = intcs.Point(i);
842 Standard_Real u,v,w; intcs.Parameters(i,u,v,w);
843 di<<"point("<<i<<") = { ("<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"), ("<<u<<" "<<v<<") }"<<"\n";
844 props.SetParameters(u,v);
845 Standard_Boolean curdef = props.IsCurvatureDefined();
846 if (!curdef) {di<<"!IsCurvatureDefined"<<"\n"; continue;}
847 Standard_Boolean umbilic = props.IsUmbilic();
854 props.CurvatureDirections(D1,D2);
856 Norm = gp_Dir(D1^D2);
857 di<<"D1 = ("<<D1.X()<<" "<<D1.Y()<<" "<<D1.Z()<<" "<<")"<<"\n";
858 di<<"D2 = ("<<D2.X()<<" "<<D2.Y()<<" "<<D2.Z()<<" "<<")"<<"\n";
859 di<<"Norm = ("<<Norm.X()<<" "<<Norm.Y()<<" "<<Norm.Z()<<" "<<")"<<"\n";
864 void TestTopOpe::CORCommands(Draw_Interpretor& theCommands)
866 static Standard_Boolean done = Standard_False;
867 if (done) return; done = Standard_True;
868 const char* g = "TestTopOpe CORCommands";
869 // purge, regularization commands :
870 theCommands.Add("purge", "purge f", __FILE__, purge, g);
871 theCommands.Add("corrISO", "corrISO f Fsp", __FILE__, correctONISO, g);
872 theCommands.Add("regufa", "regufa f", __FILE__, regularize, g);
873 theCommands.Add("splitf", "splitf f", __FILE__, splitF, g);
874 theCommands.Add("regush", "regush so", __FILE__, regush, g);
875 theCommands.Add("reguso", "reguso so", __FILE__, reguso, g);
876 // builder commands :
877 theCommands.Add("soclass", "soclass sh pnt tol", __FILE__, solidclassifier, g);
878 theCommands.Add("shclass", "shclass sh shref <toavoid>", __FILE__, shapeclassifier, g);
879 theCommands.Add("clclass", "clclass sh shref <toavoid>", __FILE__, class3dclassifier, g);
882 theCommands.Add("cled", "cled ed f", __FILE__, isclosingE, g);
883 theCommands.Add("compare", "compare s1 s2", __FILE__, compareshsh, g);
884 theCommands.Add("edonfa", "edonfa ed f", __FILE__, pcurveedgeonface, g);
885 theCommands.Add("pconfa", "pconfa name s f", __FILE__, pcurvesonface, g);
886 theCommands.Add("orivine", "orivine v ed", __FILE__, orivine, g);
887 theCommands.Add("vine", "vine v ed fa", __FILE__, vine, g);
888 theCommands.Add("issubsh", "issubsh subsh sh", __FILE__, issubshape, g);
889 theCommands.Add("bnd2d", "bnd2d name W F i", __FILE__, drawbnd2d, g);
890 theCommands.Add("classibnd2d","classibnd2d W1 W2 F i", __FILE__, classifBnd2d, g);
891 theCommands.Add("pntonc", "pntonc par C3d", __FILE__, pntonc, g);
892 theCommands.Add("pntonc2d", "pntonc2d par C2d S", __FILE__, pntonc2d, g);
893 theCommands.Add("projponf",
894 "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]",
895 __FILE__, projponf, g);
896 theCommands.Add("normal", "normal f p3d length", __FILE__, normal, g);
897 theCommands.Add("curvature", "curvature f x y z", __FILE__, curvature , g);