0024510: Remove unused local variables
[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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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
131#ifdef DEB
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
572 Handle(Geom2d_TrimmedCurve) tcx = new Geom2d_TrimmedCurve(cx,0.,umax-umin);
573 Handle(Geom2d_TrimmedCurve) tcy = new Geom2d_TrimmedCurve(cy,0.,vmax-vmin);
574 Handle(Geom2d_TrimmedCurve) tccx = Handle(Geom2d_TrimmedCurve)::DownCast(tcx->Copy()); tccx->Transform(ty);
575 Handle(Geom2d_TrimmedCurve) tccy = Handle(Geom2d_TrimmedCurve)::DownCast(tcy->Copy()); tccy->Transform(tx);
576
577 Draw_Color col(Draw_blanc);
578 DrawTrSurf_CurveColor(col);
579
580 TCollection_AsciiString aa3 = TCollection_AsciiString(a[1]); aa3 += TCollection_AsciiString(3);
581 TCollection_AsciiString aa4 = TCollection_AsciiString(a[1]); aa4 += TCollection_AsciiString(4);
582
583 TCollection_AsciiString aa;
584 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(1); char* aaa = (char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcx);
585 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(2); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tcy);
586 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(3); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccx);
587 aa=TCollection_AsciiString(a[1]); aa+=TCollection_AsciiString(4); aaa=(char *)aa.ToCString(); DrawTrSurf::Set(aaa,tccy);
588 return 0;
589}
590
591static Standard_Integer classifBnd2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
592{
593 if (n < 5) return 1;
594 TopoDS_Shape W1 = DBRep::Get(a[1]);
595 TopoDS_Shape W2 = DBRep::Get(a[2]);
596 TopoDS_Shape F = DBRep::Get(a[3]);
7fd59977 597
598 TopoDS_Wire w1 = TopoDS::Wire(W1);
599 TopoDS_Wire w2 = TopoDS::Wire(W2);
600 TopoDS_Face Fref = TopoDS::Face(F);
601
602 TopOpeBRepTool_CLASSI classi; classi.Init2d(Fref);
603 Standard_Real tolF = BRep_Tool::Tolerance(Fref);
604 Standard_Real toluv = TopOpeBRepTool_TOOL::TolUV(Fref,tolF);
605
606 if (w1.IsNull() || w2.IsNull() || Fref.IsNull()) return 1;
607
96a95605
DB
608#ifdef DEB
609 Standard_Integer sta =
610#endif
611 classi.ClassiBnd2d(w1,w2,toluv,Standard_True);
7fd59977 612 di <<"wires classification : checklarge=true ";
613#ifdef DEB
614 FUN_tool_coutsta(sta,1,2);
615#endif
616
96a95605
DB
617#ifdef DEB
618 sta =
619#endif
620 classi.ClassiBnd2d(w1,w2,toluv,Standard_False);
7fd59977 621 di <<"wires classification : checklarge=false ";
622#ifdef DEB
623 FUN_tool_coutsta(sta,1,2);
624#endif
625
626 return 0;
627}
628
629static Standard_Integer pntonc(Draw_Interpretor& di, Standard_Integer n, const char** a)
630{
631 if (n < 3) return 1;
91322f44 632 Standard_Real x = Draw::Atof(a[1]);
7fd59977 633 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
634 if (C.IsNull()) {di<<"null curve"<<"\n"; return 1;}
635 gp_Pnt p = C->Value(x);
636 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
637 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
638 return 0;
639}
640
641static Standard_Integer pntonc2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
642{
643 if (n < 4) return 1;
91322f44 644 Standard_Real x = Draw::Atof(a[1]);
7fd59977 645 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
646 if (C2d.IsNull()) {di<<"null curve"<<"\n"; return 1;}
647 Handle(Geom_Surface) S = DrawTrSurf::GetSurface(a[3]);
648 if (S.IsNull()) {di<<"null surface"<<"\n"; return 1;}
649 gp_Pnt2d p2d = C2d->Value(x);
650 di<<"point on curve of parameter "<<x<<" =("<<p2d.X()<<","<<p2d.Y()<<")"<<"\n";
651 gp_Pnt p = S->Value(p2d.X(),p2d.Y());
652 di<<"point on curve of parameter "<<x<<" =("<<p.X()<<",";
653 di<<p.Y()<<","<<p.Z()<<")"<<"\n";
654 return 0;
655}
656
657static Standard_Integer projponf(Draw_Interpretor& di, Standard_Integer n, const char** a)
658{
d633fd70 659 if (n < 3) {
660 di << "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]\n";
661 return 1;
662 }
663 //
7fd59977 664 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
665 TopoDS_Face f = TopoDS::Face(aLocalShape);
d633fd70 666 //
667 if (f.IsNull()) {
668 di<<"null shape"<<"\n";
669 return 1;
670 }
671 //
672 Standard_Real dist=0.;
673 Standard_Boolean ok;
674 gp_Pnt2d uv;
675 gp_Pnt p, pproj;
95978b28 676 Extrema_ExtAlgo anExtAlgo = Extrema_ExtAlgo_Grad;
677 Extrema_ExtFlag anExtFlag = Extrema_ExtFlag_MINMAX;
d633fd70 678 //
679 DrawTrSurf::GetPoint(a[2], p);
680 //
681 if (n > 3) {
682 const char* key1 = a[3];
683 const char* key2 = (n > 4) ? a[4] : NULL;
684 if (key1) {
685 if (!strcasecmp(key1,"-min")) {
95978b28 686 anExtFlag = Extrema_ExtFlag_MIN;
d633fd70 687 } else if (!strcasecmp(key1,"-max")) {
95978b28 688 anExtFlag = Extrema_ExtFlag_MAX;
d633fd70 689 } else {
95978b28 690 anExtAlgo = (!strcasecmp(key1,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
d633fd70 691 }
692 }
693 if (key2) {
95978b28 694 anExtAlgo = (!strcasecmp(key2,"-t")) ? Extrema_ExtAlgo_Tree : anExtAlgo;
d633fd70 695 }
696 }
95978b28 697 ok = FUN_tool_projPonF(p, f, uv, dist, anExtFlag, anExtAlgo);
d633fd70 698 //
699 if (!ok) {
700 di<<"projection failed"<<"\n";
701 return 1;
702 }
703 //
704 ok = FUN_tool_value(uv,f,pproj);
705 if (!ok) {
706 di<<"projection failed"<<"\n";
707 return 1;
708 }
709 //
7fd59977 710 di<<"proj dist = "<<dist<<" uvproj = ("<<uv.X()<<" "<<uv.Y();
711 di<<"); pproj = ("<<pproj.X()<<" "<<pproj.Y()<<" "<<pproj.Z()<<")"<<"\n";
712 return 0;
713}
714
715static Standard_Integer tolmax(Draw_Interpretor& di, Standard_Integer n, const char** a)
716{
717 if (n < 2) return 1;
718 TopoDS_Shape s = DBRep::Get(a[1]);
719 if (s.IsNull()) {di<<"null shape"<<"\n"; return 1;}
720 Standard_Real tol = FUN_tool_maxtol(s);
721 di<<"max tol = "<<tol<<"\n";
722 return 0;
723}
724
725static Standard_Integer solidclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
726{
727 if (n < 4) return 1;
728 TopoDS_Shape s = DBRep::Get(a[1]);
729 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
730 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
91322f44 731 Standard_Real tol = Draw::Atof(a[3]);
7fd59977 732
733 TopOpeBRepTool_SolidClassifier soclassi;
734 TopAbs_State sta = TopAbs_UNKNOWN;
735 if (s.ShapeType() == TopAbs_SOLID) soclassi.Classify(TopoDS::Solid(s),p,tol);
736 else if (s.ShapeType() == TopAbs_SHELL) soclassi.Classify(TopoDS::Shell(s),p,tol);
737 else {di<<"shape is not a solid nor a shell => KO"<<"\n"; return 1;}
738
739 sta = soclassi.State();
740 di<<"point is ";
741 //TopAbs::Print(sta,cout);
742 Standard_SStream aSStream;
743 TopAbs::Print(sta,aSStream);
744 di << aSStream;
745 di<<" shape s"<<"\n";
746 return 0;
747}
748
749static Standard_Integer class3dclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
750{
751 if (n < 4) return 1;
752 TopoDS_Shape s = DBRep::Get(a[1]);
753 if (s.IsNull()) {di<<"null shape"<<"\n";return 1;}
754 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
91322f44 755 Standard_Real tol = Draw::Atof(a[3]);
7fd59977 756
757 BRepClass3d_SolidClassifier soclassi(s);
758 TopAbs_State sta = TopAbs_UNKNOWN;
759 soclassi.Perform(p,tol);
760
761 sta = soclassi.State();
762 di<<"point is ";
763 //TopAbs::Print(sta,cout);
764 Standard_SStream aSStream;
765 TopAbs::Print(sta,aSStream);
766 di << aSStream;
767 di<<" shape s"<<"\n";
768 return 0;
769}
770static Standard_Integer shapeclassifier(Draw_Interpretor& di, Standard_Integer n, const char** a)
771{
772 if (n < 3) return 1;
773 TopoDS_Shape sh = DBRep::Get(a[1]);
774 if (sh.IsNull()) {di<<"null shape"<<"\n";return 1;}
775 TopoDS_Shape shref = DBRep::Get(a[2]);
776 if (shref.IsNull()) {di<<"null reference shape"<<"\n";return 1;}
777 Standard_Boolean hastoavoid = (n > 3);
778 TopTools_ListOfShape toavoid;
779 if (hastoavoid) {
780 for (Standard_Integer i=3; i<=n; i++) {
781 TopoDS_Shape shtoavoid = DBRep::Get(a[i]);
782 if (shtoavoid.IsNull()) {di<<"null toavoid shape"<<"\n";return 1;}
783 toavoid.Append(shtoavoid);
784 }
785 }
786
787 TopOpeBRepTool_ShapeClassifier shclassi;
788 TopAbs_State sta = TopAbs_UNKNOWN;
789 if (hastoavoid) sta = shclassi.StateShapeShape(sh,shref);
790 else if (toavoid.Extent() == 1) sta = shclassi.StateShapeShape(sh,toavoid.First(),shref);
791 else sta = shclassi.StateShapeShape(sh,toavoid,shref);
792
793 di<<"shape is ";
794 //TopAbs::Print(sta,cout);
795 Standard_SStream aSStream;
796 TopAbs::Print(sta,aSStream);
797 di << aSStream;
798 di<<" shape ref"<<"\n";
799 return 0;
800}
801
802
803// normals ..
804static Standard_Integer normal(Draw_Interpretor& di, Standard_Integer n, const char** a)
805{
806 if (n < 3) return 1;
807 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
808 TopoDS_Face f = TopoDS::Face(aLocalShape);
809// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
810 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
811 gp_Pnt p; DrawTrSurf::GetPoint(a[2], p);
302f96fb 812
7fd59977 813 Standard_Real dist=0.; gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_projPonF(p,f,uv,dist);
814 if (!ok) {di<<"projection failed"<<"\n"; return 1;}
815#ifdef DEB
816 gp_Vec ngf =
817#endif
818 FUN_tool_nggeomF(uv,f);
819 TCollection_AsciiString aa("ngS");
820#ifdef DRAW
821 FUN_tool_draw(aa,p,ngf,length);
822#endif
823 return 0;
824}
825
826static Standard_Integer curvature(Draw_Interpretor& di, Standard_Integer n, const char** a)
827{
828 if (n < 5) return 1;
829 TopoDS_Shape aLocalShape = DBRep::Get(a[1]);
830 TopoDS_Face f = TopoDS::Face(aLocalShape);
831// TopoDS_Face f = TopoDS::Face(DBRep::Get(a[1]));
832 if (f.IsNull()) {di<<"null shape"<<"\n";return 1;}
91322f44 833 Standard_Real x = Draw::Atof(a[2]);
834 Standard_Real y = Draw::Atof(a[3]);
835 Standard_Real z = Draw::Atof(a[4]);
7fd59977 836 Handle(Geom_Line) line = new Geom_Line(gp_Ax1(gp_Pnt(0.,0.,0.), gp_Dir(x,y,z)));
837 BRepAdaptor_Surface BS(f);
838 Handle(Geom_Surface) su = BRep_Tool::Surface(f);
839 GeomAPI_IntCS intcs(line,su);
840 Standard_Boolean done = intcs.IsDone();
841 if (!done) {di<<"intersection point on surface not found"<<"\n"; return 1;}
842 Standard_Integer npnts = intcs.NbPoints();
843 if (npnts < 1) {di<<"intersection point on surface not found"<<"\n"; return 1;}
844
845 Standard_Real tol = Precision::Confusion();
846 BRepLProp_SLProps props(BS,2,tol);
7fd59977 847 gp_Dir Norm,D1,D2;
848 for (Standard_Integer i = 1; i <= npnts; i++) {
849 gp_Pnt p = intcs.Point(i);
850 Standard_Real u,v,w; intcs.Parameters(i,u,v,w);
851 di<<"point("<<i<<") = { ("<<p.X()<<" "<<p.Y()<<" "<<p.Z()<<"), ("<<u<<" "<<v<<") }"<<"\n";
852 props.SetParameters(u,v);
853 Standard_Boolean curdef = props.IsCurvatureDefined();
854 if (!curdef) {di<<"!IsCurvatureDefined"<<"\n"; continue;}
855 Standard_Boolean umbilic = props.IsUmbilic();
856 if (umbilic) {
7fd59977 857 D1 = gp_Dir(0,0,1);
858 D2 = gp_Dir(0,1,0);
859 di<<"umbilic";
860 }
861 else {
7fd59977 862 props.CurvatureDirections(D1,D2);
863 }
864 Norm = gp_Dir(D1^D2);
865 di<<"D1 = ("<<D1.X()<<" "<<D1.Y()<<" "<<D1.Z()<<" "<<")"<<"\n";
866 di<<"D2 = ("<<D2.X()<<" "<<D2.Y()<<" "<<D2.Z()<<" "<<")"<<"\n";
867 di<<"Norm = ("<<Norm.X()<<" "<<Norm.Y()<<" "<<Norm.Z()<<" "<<")"<<"\n";
868 } // i
869 return 0;
870}
871
872void TestTopOpe::CORCommands(Draw_Interpretor& theCommands)
873{
874 static Standard_Boolean done = Standard_False;
875 if (done) return; done = Standard_True;
876 const char* g = "TestTopOpe CORCommands";
877 // purge, regularization commands :
878 theCommands.Add("purge", "purge f", __FILE__, purge, g);
879 theCommands.Add("corrISO", "corrISO f Fsp", __FILE__, correctONISO, g);
880 theCommands.Add("regufa", "regufa f", __FILE__, regularize, g);
881 theCommands.Add("splitf", "splitf f", __FILE__, splitF, g);
882 theCommands.Add("regush", "regush so", __FILE__, regush, g);
883 theCommands.Add("reguso", "reguso so", __FILE__, reguso, g);
884 // builder commands :
885 theCommands.Add("soclass", "soclass sh pnt tol", __FILE__, solidclassifier, g);
886 theCommands.Add("shclass", "shclass sh shref <toavoid>", __FILE__, shapeclassifier, g);
887 theCommands.Add("clclass", "clclass sh shref <toavoid>", __FILE__, class3dclassifier, g);
888
889 // useful commands :
890 theCommands.Add("cled", "cled ed f", __FILE__, isclosingE, g);
891 theCommands.Add("compare", "compare s1 s2", __FILE__, compareshsh, g);
892 theCommands.Add("edonfa", "edonfa ed f", __FILE__, pcurveedgeonface, g);
893 theCommands.Add("pconfa", "pconfa name s f", __FILE__, pcurvesonface, g);
894 theCommands.Add("orivine", "orivine v ed", __FILE__, orivine, g);
895 theCommands.Add("vine", "vine v ed fa", __FILE__, vine, g);
896 theCommands.Add("issubsh", "issubsh subsh sh", __FILE__, issubshape, g);
897 theCommands.Add("bnd2d", "bnd2d name W F i", __FILE__, drawbnd2d, g);
898 theCommands.Add("classibnd2d","classibnd2d W1 W2 F i", __FILE__, classifBnd2d, g);
899 theCommands.Add("pntonc", "pntonc par C3d", __FILE__, pntonc, g);
900 theCommands.Add("pntonc2d", "pntonc2d par C2d S", __FILE__, pntonc2d, g);
d633fd70 901 theCommands.Add("projponf",
902 "projponf f pnt [extrema flag: -min/-max/-minmax] [extrema algo: -g(grad)/-t(tree)]",
903 __FILE__, projponf, g);
7fd59977 904 theCommands.Add("tolmax", "tolmax s", __FILE__, tolmax, g);
905 theCommands.Add("normal", "normal f p3d length", __FILE__, normal, g);
906 theCommands.Add("curvature", "curvature f x y z", __FILE__, curvature , g);
907
908}