1 // Created on: 1999-03-09
2 // Created by: data exchange team
3 // Copyright (c) 1999-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
21 #include <SWDRAW_ShapeFix.ixx>
27 #include <gp_Pnt2d.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Wire.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Iterator.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <BRep_Tool.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepBuilderAPI.hxx>
38 #include <BRepTopAdaptor_FClass2d.hxx>
40 #include <ShapeBuild_ReShape.hxx>
41 #include <ShapeAnalysis_Edge.hxx>
42 #include <ShapeAnalysis_WireOrder.hxx>
43 #include <ShapeAnalysis_WireVertex.hxx>
44 #include <ShapeAnalysis_Wire.hxx>
45 #include <ShapeExtend_WireData.hxx>
46 #include <ShapeFix.hxx>
47 #include <ShapeFix_ShapeTolerance.hxx>
48 #include <ShapeFix_Wire.hxx>
49 #include <ShapeFix_WireVertex.hxx>
50 #include <ShapeFix_Wireframe.hxx>
51 #include <ShapeFix_Face.hxx>
52 #include <ShapeFix_Shape.hxx>
53 #include <Precision.hxx>
54 #include <ShapeExtend_DataMapOfShapeListOfMsg.hxx>
55 #include <ShapeExtend_MsgRegistrator.hxx>
56 #include <ShapeExtend_DataMapIteratorOfDataMapOfShapeListOfMsg.hxx>
57 #include <Message_ListIteratorOfListOfMsg.hxx>
58 #include <Message_Msg.hxx>
59 #include <TCollection_AsciiString.hxx>
60 #include <TColStd_DataMapIteratorOfDataMapOfAsciiStringInteger.hxx>
61 #include <TColStd_DataMapOfAsciiStringInteger.hxx>
62 #include <TopTools_MapOfShape.hxx>
63 #include <TopTools_DataMapOfShapeListOfShape.hxx>
64 #include <TopAbs_State.hxx>
66 #include <Draw_ProgressIndicator.hxx>
67 #include <ShapeAnalysis_FreeBounds.hxx>
68 #include <TopTools_HSequenceOfShape.hxx>
69 #include <BRep_Builder.hxx>
70 #include <TopTools_IndexedMapOfShape.hxx>
77 #include <ShapeExtend_WireData.hxx>
79 //=======================================================================
80 //function : edgesameparam
82 //=======================================================================
84 static Standard_Integer edgesameparam (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
86 // const Standard_CString arg1 = argv[1];
87 const Standard_CString arg2 (argc > 2 ? argv[2] : NULL);
88 // **** Edge:SameParameter ****
89 if (argc < 2) { di<<"shapename , option f to force, else only Edges not-SameParameter are computed"<<"\n"; return 1 /* Error */; }
90 TopoDS_Shape Shape = DBRep::Get(argv[1]);
92 if (!ShapeFix::SameParameter(Shape, (argc > 2 && arg2[0] == 'f') , BRepBuilderAPI::Precision()) )
93 di<<"Some edges were not processed"<<"\n";
98 //=======================================================================
99 //function : settolerance
101 //=======================================================================
103 static Standard_Integer settolerance (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
106 di<< "myshape val : forces tolerances at <val>"<<"\n"
107 << "myshape < max : sets maximum tolerance to <max>"<<"\n"
108 << "myshape > min : sets minimum tolerance to <min>"<<"\n"
109 << "myshape min max : bounds tolerances between <min> and <max>"<<"\n"
110 <<"myshape mode=v-e-f other args : idem but only on vertex-edge-face"<<"\n";
111 return (argc < 2 ? 0 : 1 /* Error */);
113 Standard_CString arg1 = argv[1];
114 Standard_CString arg2 = argv[2];
115 TopoDS_Shape Shape = DBRep::Get(arg1);
116 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; }
118 Standard_Integer premarg = 2;
119 TopAbs_ShapeEnum styp = TopAbs_SHAPE;
120 if (mod2 == 'v') { styp = TopAbs_VERTEX; premarg = 3; }
121 if (mod2 == 'e') { styp = TopAbs_EDGE; premarg = 3; }
122 if (mod2 == 'w') { styp = TopAbs_WIRE; premarg = 3; }
123 if (mod2 == 'f') { styp = TopAbs_FACE; premarg = 3; }
124 if (mod2 == 'a') { styp = TopAbs_SHAPE; premarg = 3; }
126 Standard_Real tmin,tmax;
127 mod2 = argv[premarg][0];
128 if (mod2 == '=') tmin = tmax = Draw::Atof (argv[argc-1]);
129 else if (mod2 == '<') { tmin = 0; tmax = Draw::Atof (argv[argc-1]); }
130 else if (mod2 == '>') { tmin = Draw::Atof (argv[argc-1]); tmax = 0; }
131 else { tmin = Draw::Atof (argv[premarg]); tmax = Draw::Atof (argv[argc-1]); }
133 if (argc == premarg + 1 || tmin == tmax) di<<"Setting Tolerance to "<<tmin<<"\n";
134 else if (tmax < tmin) di<<"Minimum Tolerance to "<<tmin<<"\n";
135 else if (tmin <= 0) di<<"Maximum Tolerance to "<<tmax<<"\n";
136 else di<<"Tolerance Limited between "<<tmin<<" and "<<tmax<<"\n";
137 ShapeFix_ShapeTolerance sat;
138 sat.LimitTolerance (Shape,tmin,tmax,styp);
142 //=======================================================================
145 //=======================================================================
147 static Standard_Integer stwire (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
149 if (argc < 2) { // help
150 di<<"Donner nom shape depart + nom shape resultat + option"<<"\n";
151 di<<"Options de chargement : x add connected (sinon add simple)\n"
152 << "Options de traitement : l fix little/BRepBuilderAPI\n"
153 <<"Options de sortie : aucune make simple\n"
154 <<" m MakeAPI r avec reorder v vertex\n"
155 <<"Autres (se cumulent) : q quid(stats)"<<"\n";
158 if (argc < 4) { di<<"stwire tout court pour help"<<"\n"; return 1 /* Error */; }
159 Standard_CString arg1 = argv[1];
160 Standard_CString arg2 = argv[2];
163 Standard_Integer i; int ox,ol,om,orint,oq,ov; ox=ol=om=orint=oq=ov=0;
164 for (i = 3; i < argc; i ++) {
166 char opt = argv[i][0];
167 if (opt == '+') opt = argv[i][1];
168 if (opt == '-') { opt = argv[i][1]; valopt = 0; }
170 case 'l' : ol = valopt; break;
171 case 'm' : om = valopt; break;
172 case 'q' : oq = valopt; break;
173 case 'r' : orint = valopt; break;
174 case 'v' : ov = valopt; break;
175 case 'x' : ox = valopt; break;
179 TopoDS_Shape Shape = DBRep::Get(arg1);
180 if (Shape.IsNull()) { di<<arg1<<" inconnu"<<"\n"; return 1 /* Error */; }
183 Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData;
184 Handle(ShapeAnalysis_Wire) saw = new ShapeAnalysis_Wire;
187 TopoDS_Shape awire; // en principe un Wire
188 if (Shape.ShapeType() == TopAbs_WIRE) {
190 } else if (Shape.ShapeType() == TopAbs_FACE) {
191 saw->SetFace (TopoDS::Face(Shape));
192 TopExp_Explorer expw(Shape,TopAbs_WIRE);
193 if (expw.More()) awire = expw.Current();
194 saw->SetPrecision (BRepBuilderAPI::Precision());
196 if (awire.IsNull()) {
197 di<<"Neither FACE nor WIRE : "<<arg1<<"\n";
198 di<<"Considering as list of edges ..."<<"\n";
200 // return 1 /* Error */;
203 // Chargement : normal ou par connected(oriented)
205 for (TopExp_Explorer exp(Shape,TopAbs_EDGE); exp.More(); exp.Next()) {
206 TopoDS_Edge E = TopoDS::Edge (exp.Current());
207 Standard_Integer orient = saw->CheckShapeConnect (E);
208 di<<"Orientation : "<<orient<<" LowerDist : "<< saw->MinDistance3d() << "\n";
209 if (ox) sbwd->AddOriented (E,orient);
213 // else sbwd->Init (awire);
215 Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire;
218 // Traitement en cours
220 Standard_Integer nb = sfw->NbEdges();
221 for (i = 1; i <= nb; i ++) {
222 Standard_Boolean stat = sfw->FixSmall (i, Standard_True, 0.0);
223 //cout<<"FixSmall for"<<i<<(stat ? " done" : " not done"); //:sw <<" StatusFix="<<STW.StatusFix()<<"\n";
224 di<<"FixSmall for"<<i;
230 if ( sfw->LastFixStatus ( ShapeExtend_FAIL ) ) di << " (failed)";
236 if (orint) { // reorder ?
237 ShapeAnalysis_WireOrder WO ( (Shape.ShapeType() != TopAbs_FACE), BRepBuilderAPI::Precision());
239 Standard_Integer stwo = saw->CheckOrder (WO);
240 Standard_Integer nb = WO.NbEdges();
241 di<<"Reorder status : "<<stwo<<" NbEdges="<<nb<<"\n";
242 for (i = 1; i <= nb; i ++) {
243 Standard_Integer iord = WO.Ordered(i);
245 if ( sbwd->Edge(iord).Orientation() == TopAbs_REVERSED) di<<" REV";
247 di<<" ordered to "<<iord<<" Gap="<<WO.Gap(i)<<"\n";
249 di<<"Reorder not yet done"<<"\n";
250 sfw->FixReorder (WO);
251 // Mais on n execute pas
256 ShapeAnalysis_Edge sae;
257 Standard_Integer nb = sbwd->NbEdges();
258 di<<"NbEdges : "<<nb<<"\n";
259 for (i = 1; i <= nb; i ++) {
260 TopoDS_Edge E = sbwd->Edge(i);
262 if (E.Orientation() == TopAbs_REVERSED) di<<" REV";
264 if (BRep_Tool::Degenerated(E)) di<<" DGNR";
265 if (sbwd->IsSeam(i)) di<<" SEAM_WIRE";
266 if (Shape.ShapeType() == TopAbs_FACE &&
267 sae.IsSeam(E,TopoDS::Face(Shape))) di<<" SEAM_FACE";
268 if (Shape.ShapeType() == TopAbs_FACE )
269 if (sae.HasPCurve(E,TopoDS::Face(Shape))) di<<" PCU";
271 if (sae.HasCurve3d(E)) di<<" C3D";
273 if (sae.IsClosed3d(E)) di<<" CLOSED";
281 ShapeAnalysis_WireVertex sawv;
282 sawv.Init ( sbwd, saw->Precision() );
284 Standard_Integer nb = sbwd->NbEdges();
285 di<<"Nb(End)Vertex : "<<nb<<"\n";
286 for (i = 1; i <= nb; i ++) {
287 gp_XYZ pos; Standard_Real upre,ufol;
288 Standard_Integer stat = sawv.Data (i,pos,upre,ufol);
291 case 0 : di<<"Same Vertex"<<"\n"; break;
292 case 1 : di<<"Same Coords with recorded precisions (but not Same Vertex)"<<"\n"; break;
293 case 2 : di<<"Close (with preci="<< saw->Precision()<<")"<<"\n"; break;
294 case 3 : di<<"End of "<<i<<" OK, Start of "<<(i == nb ? 1 : i+1)<<" at U="<<ufol; break;
295 case 4 : di<<"End of "<<i<<" at U="<<upre<<", Start of "<<(i == nb ? 1 : i+1)<<" OK"; break;
296 case 5 : di<<"Intersection, End of "<<i<<" at U="<<upre<<", Start of "<<(i == nb ? 1 : i+1)<<" at U="<<ufol; break;
297 default : di<<"Disjoined"<<"\n";
299 if (stat >= 3 && stat <= 5) di<<"\n - Position : "<<pos.X()<<" "<<pos.Y()<<" "<<pos.Z()<<"\n";
301 ShapeFix_WireVertex sfwv;
303 di<<"Nb Fixed Vertex : "<< sfwv.Fix() <<"\n";
307 if ( Shape.ShapeType() == TopAbs_FACE ) {
308 Correct_Wire CW ( TopoDS::Face(Shape) );
309 Standard_Integer i, nb = sbwd->NbEdges();
310 Standard_Integer num = 1;
311 for (i = 1; i <= nb; i ++) CW.Add (sbwd->Edge(i));
312 CW.Perform ( saw->Precision() );
315 // On prend celui qui a le plus d edges
316 Standard_Integer nbe, maxe = 0;
317 for (i = 1; i <= nb; i ++) {
318 TopoDS_Wire wir = CW.Wire(i);
320 for (TopoDS_Iterator ite(wir); ite.More(); ite.Next()) nbe ++;
321 if (nbe > maxe) { num = i; maxe = nbe; }
323 di<<"Correct_Wire produced "<<nb<<" Wires, taken n0 "<<num<<"\n";
325 result = CW.Wire (num);
327 else di << "Cannot apply Correct_Wire: face not defined" << "\n";
330 else if (om) result = sbwd->WireAPIMake();
331 else result = sbwd->Wire();
332 if (result.IsNull()) {
333 di<<"Pas de resultat, desole"<<"\n";
336 DBRep::Set (arg2,result);
340 //=======================================================================
343 //=======================================================================
345 static Standard_Integer reface (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
347 if (argc < 3) { di<<"Donner un nom de SHAPE (SHELL ou FACE) + un nom de RESULTAT"<<"\n"; return 1 /* Error */; }
348 Standard_CString arg1 = argv[1];
349 Standard_CString arg2 = argv[2];
350 TopoDS_Shape Shape = DBRep::Get(arg1);
351 if (Shape.IsNull()) { di<<"Shape unknown : "<<arg1<<"\n"; return 1 /* Error */; }
353 Standard_Boolean rebuild = Standard_False;
355 Handle(ShapeFix_Face) STF = new ShapeFix_Face;
357 Standard_Integer i; // svv Jan11 2000 : porting on DEC
358 for (i = 3; i < argc; i ++) {
359 Standard_Boolean valopt = Standard_True;
360 char opt = argv[i][0];
361 if (opt == '+') opt = argv[i][1];
362 if (opt == '-') { opt = argv[i][1]; valopt = Standard_False; }
363 //cout<<(valopt ? ".." : ".. NO");
370 if (opt == 'R') { di<<" REBUILD-ANYWAY .."; rebuild = valopt; }
371 if (opt == 'd') { di<<" fix-dgnr .."; STF->FixWireTool()->FixDegeneratedMode() = valopt; }
372 if (opt == 'r') { di<<" fix-reorder-wire .."; STF->FixWireTool()->FixReorderMode() = valopt; }
378 ShapeBuild_ReShape resh;
380 Standard_Integer nbf = 0, nbfc = 0;
381 for (TopExp_Explorer EF (Shape,TopAbs_FACE); EF.More(); EF.Next()) {
382 TopoDS_Face F = TopoDS::Face (EF.Current()); face = F;
384 Standard_Boolean newface = Standard_False;
385 // on va voir si ShapeTool_Face trouve qqchose a redire
386 //:sw ShapeTool_Wire STW;
387 //:sw STW.SetFace (F);
389 STF->Init (F); // qui fait tout
392 newface = STF->Status(ShapeExtend_DONE) || rebuild;
393 if (newface) { nbfc ++; resh.Replace (F,face); }
396 di<<"Faces reprises par ShapeFix_Face : "<<nbfc<<"\n";
397 DBRep::Set (arg2,resh.Apply (Shape,TopAbs_FACE,2));
400 else di<<"ShapeFix_Face n a rien trouve a redire"<<"\n";
405 //=======================================================================
406 //function : fixshape
408 //=======================================================================
410 static Standard_Integer fixshape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
412 Handle(ShapeExtend_MsgRegistrator) msg = new ShapeExtend_MsgRegistrator;
413 Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
414 sfs->SetMsgRegistrator ( msg );
416 Standard_CString res = 0;
417 Standard_Integer par = 0, mess=0;
418 for ( Standard_Integer i=1; i < argc; i++ ) {
419 if ( argv[i][0] == '-' || argv[i][0] == '+' || argv[i][0] == '*' ) {
420 Standard_Integer val = ( argv[i][0] == '-' ? 0 : argv[i][0] == '+' ? 1 : -1 );
421 switch ( argv[i][1] ) {
422 case 'l': sfs->FixWireTool()->FixLackingMode() = val; break;
423 case 'o': sfs->FixFaceTool()->FixOrientationMode() = val; break;
424 case 'h': sfs->FixWireTool()->FixShiftedMode() = val; break;
425 case 'm': sfs->FixFaceTool()->FixMissingSeamMode() = val; break;
426 case 'd': sfs->FixWireTool()->FixDegeneratedMode() = val; break;
427 case 's': sfs->FixWireTool()->FixSmallMode() = val; break;
428 case 'i': sfs->FixWireTool()->FixSelfIntersectionMode() = val; break;
429 case 'n': sfs->FixWireTool()->FixNotchedEdgesMode() = val; break;
430 case '?': mess = val; break;
436 case 0: res = argv[i]; break;
438 TopoDS_Shape initShape = DBRep::Get(argv[i]);
439 if(initShape.IsNull()) continue;
440 sfs->Init ( initShape );
442 case 2: sfs->SetPrecision (Draw::Atof(argv[i])); break;
443 case 3: sfs->SetMaxTolerance(Draw::Atof(argv[i])); break;
450 di << "Use: " << argv[0] << " result shape [tolerance [max_tolerance]] [switches]" << "\n";
451 di << "Switches allow to tune parameters of ShapeFix" << "\n";
452 di << "The following syntax is used: <symbol><parameter>" << "\n";
453 di << "- symbol may be - to set parameter off, + to set on or * to set default" << "\n";
454 di << "- parameters are identified by letters:" << "\n";
455 di << " l - FixLackingMode" << "\n";
456 di << " o - FixOrientationMode" << "\n";
457 di << " h - FixShiftedMode" << "\n";
458 di << " m - FixMissingSeamMode" << "\n";
459 di << " d - FixDegeneratedMode" << "\n";
460 di << " s - FixSmallMode" << "\n";
461 di << " i - FixSelfIntersectionMode" << "\n";
462 di << " n - FixNotchedEdgesMode" << "\n";
463 di << "For enhanced message output, use switch '+?'" << "\n";
467 Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator (di, 1);
468 sfs->Perform (aProgress);
469 DBRep::Set (res,sfs->Shape());
473 TColStd_DataMapOfAsciiStringInteger aMapOfNumberOfFixes;
474 Standard_SStream aSStream;
475 TopoDS_Compound aCompound;
476 BRep_Builder aBuilder;
477 aBuilder.MakeCompound (aCompound);
478 const ShapeExtend_DataMapOfShapeListOfMsg &map = msg->MapShape();
479 // Counting the number of each type of fixes. If the switch '*?' store all modified shapes in compound.
480 for ( ShapeExtend_DataMapIteratorOfDataMapOfShapeListOfMsg it ( map ); it.More(); it.Next() )
482 for ( Message_ListIteratorOfListOfMsg iter ( it.Value() ); iter.More(); iter.Next() )
484 if ( aMapOfNumberOfFixes.IsBound ( iter.Value().Value() ) )
486 aMapOfNumberOfFixes ( iter.Value().Value() )++;
490 aMapOfNumberOfFixes.Bind ( iter.Value().Value(), 1 );
495 aBuilder.Add ( aCompound, it.Key() );
499 aSStream << " Fix" << setw (58) << "Count\n";
500 aSStream << " ------------------------------------------------------------\n";
501 for ( TColStd_DataMapIteratorOfDataMapOfAsciiStringInteger anIter ( aMapOfNumberOfFixes ); anIter.More(); anIter.Next() )
503 aSStream << " " << anIter.Key() << setw ( 60 - anIter.Key().Length() ) << anIter.Value() << "\n";
505 aSStream << " ------------------------------------------------------------\n";
511 Sprintf ( buff, "%s_%s", res, "m" );
512 di << " Modified shapes saved in compound: " << buff;
513 DBRep::Set (buff, aCompound);
520 //=======================================================================
523 //=======================================================================
525 Standard_Integer fixgaps(Draw_Interpretor& di, Standard_Integer n, const char** a)
529 TopoDS_Shape S = DBRep::Get(a[2]);
531 di << " Shape is null" << "\n";
535 Handle(ShapeFix_Wireframe) SFWF = new ShapeFix_Wireframe(S);
536 Standard_Real prec = ( n >3 ? Draw::Atof(a[3]) : 0. );
537 SFWF->SetPrecision(prec);
538 if ( SFWF->FixWireGaps() ) {
539 DBRep::Set(a[1],SFWF->Shape());
540 di<<" Wireframe gaps fixed on shape"<<"\n";
546 //=======================================================================
547 //function : fixsmall
549 //=======================================================================
551 Standard_Integer fixsmall(Draw_Interpretor& di, Standard_Integer n, const char** a)
555 TopoDS_Shape S = DBRep::Get(a[2]);
557 di << " Shape is null" << "\n";
561 Standard_Real prec = (n == 4)? Draw::Atof(a[3]) : 1.;
562 ShapeFix_Wireframe SFWF(S);
563 SFWF.SetPrecision(prec);
565 if (SFWF.FixSmallEdges()) {
566 DBRep::Set(a[1],SFWF.Shape());
567 di<<" Small edges fixed on shape"<<"\n";
573 //=======================================================================
574 //function : fixsmalledges
576 //=======================================================================
578 static Standard_Integer fixsmalledges(Draw_Interpretor& di, Standard_Integer n, const char** a)
581 di<<"Invalid number of arguments"<<"\n";
584 TopoDS_Shape Sh = DBRep::Get(a[2]);
586 Standard_Integer k = 3;
587 Standard_Real tol = 100000;
588 Standard_Integer mode = 2;
589 Standard_Real tolang = M_PI/2;
591 tol = Draw::Atof(a[k++]);
594 mode= Draw::Atoi(a[k++]);
597 tolang = Draw::Atof(a[k++]);
599 Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe();
600 Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape;
601 aSfwr->SetContext(aReShape);
603 aSfwr->SetPrecision(tol);
604 Standard_Boolean aModeDrop = Standard_True;
606 aModeDrop = Standard_False;
608 TopTools_MapOfShape theSmallEdges, theMultyEdges;
609 TopTools_DataMapOfShapeListOfShape theEdgeToFaces,theFaceWithSmall;
610 aSfwr->CheckSmallEdges(theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges);
611 aSfwr->MergeSmallEdges (theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges, aModeDrop,tolang);
612 //aSfwr->FixSmallEdges();
613 TopoDS_Shape resShape = aSfwr->Shape();;
614 DBRep::Set ( a[1], resShape );
618 //=======================================================================
619 //function : checkoverlapedges
621 //=======================================================================
623 static Standard_Integer checkoverlapedges(Draw_Interpretor& di, Standard_Integer n, const char** a)
626 di<<"Invalid number of arguments"<<"\n";
629 TopoDS_Shape Sh1 = DBRep::Get(a[1]);
630 TopoDS_Shape Sh2 = DBRep::Get(a[2]);
631 if(Sh1.IsNull() || Sh2.IsNull()) {
632 di<<"Invalid arguments"<<"\n";
635 TopoDS_Edge e1 = TopoDS::Edge(Sh1);
636 TopoDS_Edge e2 = TopoDS::Edge(Sh2);
637 if(e1.IsNull() || e2.IsNull()) {
638 di<<"Invalid type of arguments"<<"\n";
641 Standard_Real aTol = Precision::Confusion();
642 Standard_Real aDistDomain = 0.0;
643 Standard_Integer k = 3;
645 aTol = Draw::Atof(a[k++]);
647 aDistDomain = Draw::Atof(a[k++]);
649 ShapeAnalysis_Edge sae;
650 if(sae.CheckOverlapping(e1,e2,aTol,aDistDomain)) {
651 if(aDistDomain ==0.0)
652 di<<"Edges is overlaping comletly"<<"\n";
654 di<<"Edges is overlaped"<<"\n";
655 di<<"with tolerance = "<<aTol<<"\n";
656 di<<"on segment length = "<<aDistDomain<<"\n";
659 else di<<"Edges is not overlaped"<<"\n";
663 //=======================================================================
664 //function : checkfclass2d
666 //=======================================================================
668 static Standard_Integer checkfclass2d(Draw_Interpretor& di, Standard_Integer n, const char** a)
671 di<<"Invalid number of arguments"<<"\n";
674 TopoDS_Shape Sh1 = DBRep::Get(a[1]);
675 Standard_Real ucoord = Draw::Atof(a[2]);
676 Standard_Real vcoord = Draw::Atof(a[3]);
677 if(Sh1.IsNull() || Sh1.ShapeType()!= TopAbs_FACE) {
678 di<<"Invalid arguments"<<"\n";
681 TopoDS_Face aFace = TopoDS::Face(Sh1);
682 gp_Pnt2d p2d(ucoord,vcoord);
683 BRepTopAdaptor_FClass2d f2d(aFace,Precision::Confusion());
684 TopAbs_State stat = f2d.Perform(p2d);
685 if(stat == TopAbs_OUT)
686 di<<"Point is OUT"<<"\n";
687 else if(stat == TopAbs_IN)
688 di<<"Point is IN"<<"\n";
689 else if(stat == TopAbs_ON)
690 di<<"Point is ON"<<"\n";
692 di<<"Point is UNKNOWN"<<"\n";
696 static Standard_Integer connectedges(Draw_Interpretor& di, Standard_Integer n, const char** a)
699 di<<"Invalid number of arguments. Should be : result shape [toler shared]"<<"\n";
702 TopoDS_Shape aSh1 = DBRep::Get(a[2]);
704 di<<"Shape is null"<<"\n";
707 Standard_Real aTol = Precision::Confusion();
709 aTol = Draw::Atof(a[3]);
711 Standard_Boolean shared = Standard_True;
713 shared = (Draw::Atoi(a[4]) == 1);
714 TopExp_Explorer aExpE(aSh1,TopAbs_EDGE);
715 Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
716 Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
717 TopTools_IndexedMapOfShape aMapEdges;
718 for( ; aExpE.More(); aExpE.Next())
720 aSeqEdges->Append(aExpE.Current());
721 aMapEdges.Add(aExpE.Current());
724 ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges,aTol,shared,aSeqWires );
725 TopoDS_Compound aComp;
727 aB.MakeCompound(aComp);
728 Standard_Integer i = 1;
729 for( ; i <= aSeqWires->Length() ; i++)
731 TopoDS_Shape aW = aSeqWires->Value(i);
732 di<<"Wire - "<<i<<" : "<<"\n";
734 TopExp_Explorer aExp1(aW, TopAbs_EDGE);
735 for( ; aExp1.More(); aExp1.Next())
739 Standard_Integer ind = aMapEdges.FindIndex(aExp1.Current());
744 TopoDS_Vertex aV1, aV2;
745 TopExp::Vertices(TopoDS::Edge(aExp1.Current()), aV1,aV2);
746 gp_Pnt aP = BRep_Tool::Pnt(aV1);
747 di<<aP.X()<<" "<<aP.Y()<<" "<<aP.Z()<<"\n";
752 aB.Add( aComp,aSeqWires->Value(i));
754 DBRep::Set(a[1],aComp);
759 //=======================================================================
760 //function : InitCommands
762 //=======================================================================
764 void SWDRAW_ShapeFix::InitCommands(Draw_Interpretor& theCommands)
766 static Standard_Integer initactor = 0;
767 if (initactor) return; initactor = 1;
769 Standard_CString g = SWDRAW::GroupName();
771 theCommands.Add ("edgesameparam","nom shape draw ou * [+ option force]",
772 __FILE__,edgesameparam,g);
773 theCommands.Add ("settolerance","shape [mode=v-e-f-a] val(fix value) or tolmin tolmax",
774 __FILE__,settolerance,g);
775 theCommands.Add ("stwire","stwire tout court pour help complet",
777 theCommands.Add ("reface","shape result : controle sens wire",
779 theCommands.Add ("fixshape","res shape [preci [maxpreci]] [{switches}]",
780 __FILE__,fixshape,g);
781 // theCommands.Add ("testfill","result edge1 edge2",
782 // __FILE__,XSHAPE_testfill,g);
783 theCommands.Add ("fixwgaps","result shape [toler=0]",
785 theCommands.Add ("fixsmall","result shape [toler=1.]",
786 __FILE__,fixsmall,g);
787 theCommands.Add ("fixsmalledges","result shape [toler mode amxangle]",
788 __FILE__,fixsmalledges,g);
789 theCommands.Add ("checkoverlapedges","edge1 edge2 [toler domaindist]",
790 __FILE__,checkoverlapedges,g);
791 theCommands.Add ("checkfclass2d","face ucoord vcoord",
792 __FILE__,checkfclass2d,g);
793 theCommands.Add ("connectedges","res shape [toler shared]",
794 __FILE__,connectedges,g);