// File: SWDRAW_ShapeFix.cxx // Created: Tue Mar 9 15:49:13 1999 // Author: data exchange team // #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef AIX #include #endif #include #include //======================================================================= //function : edgesameparam //purpose : //======================================================================= static Standard_Integer edgesameparam (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { // const Standard_CString arg1 = argv[1]; const Standard_CString arg2 (argc > 2 ? argv[2] : NULL); // **** Edge:SameParameter **** if (argc < 2) { di<<"shapename , option f to force, else only Edges not-SameParameter are computed"<<"\n"; return 1 /* Error */; } TopoDS_Shape Shape = DBRep::Get(argv[1]); if (!ShapeFix::SameParameter(Shape, (argc > 2 && arg2[0] == 'f') , BRepBuilderAPI::Precision()) ) di<<"Some edges were not processed"<<"\n"; di<<"\n"; return 0; // Done } //======================================================================= //function : settolerance //purpose : //======================================================================= static Standard_Integer settolerance (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc < 3) { di<< "myshape val : forces tolerances at "<<"\n" << "myshape < max : sets maximum tolerance to "<<"\n" << "myshape > min : sets minimum tolerance to "<<"\n" << "myshape min max : bounds tolerances between and "<<"\n" <<"myshape mode=v-e-f other args : idem but only on vertex-edge-face"<<"\n"; return (argc < 2 ? 0 : 1 /* Error */); } Standard_CString arg1 = argv[1]; Standard_CString arg2 = argv[2]; TopoDS_Shape Shape = DBRep::Get(arg1); if (Shape.IsNull()) { di<<"Shape unknown : "<') { tmin = atof (argv[argc-1]); tmax = 0; } else { tmin = atof (argv[premarg]); tmax = atof (argv[argc-1]); } if (argc == premarg + 1 || tmin == tmax) di<<"Setting Tolerance to "<Load ( sbwd ); TopoDS_Shape awire; // en principe un Wire if (Shape.ShapeType() == TopAbs_WIRE) { awire = Shape; } else if (Shape.ShapeType() == TopAbs_FACE) { saw->SetFace (TopoDS::Face(Shape)); TopExp_Explorer expw(Shape,TopAbs_WIRE); if (expw.More()) awire = expw.Current(); saw->SetPrecision (BRepBuilderAPI::Precision()); } if (awire.IsNull()) { di<<"Neither FACE nor WIRE : "<CheckShapeConnect (E); di<<"Orientation : "<MinDistance3d() << "\n"; if (ox) sbwd->AddOriented (E,orient); else sbwd->Add (E); } // } // else sbwd->Init (awire); Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire; sfw->Init ( saw ); // Traitement en cours if (ol) { Standard_Integer nb = sfw->NbEdges(); for (i = 1; i <= nb; i ++) { Standard_Boolean stat = sfw->FixSmall (i, Standard_True, 0.0); //cout<<"FixSmall for"<LastFixStatus ( ShapeExtend_FAIL ) ) di << " (failed)"; di << "\n"; } } // Traitement if (orint) { // reorder ? ShapeAnalysis_WireOrder WO ( (Shape.ShapeType() != TopAbs_FACE), BRepBuilderAPI::Precision()); Standard_Integer stwo = saw->CheckOrder (WO); Standard_Integer nb = WO.NbEdges(); di<<"Reorder status : "<Edge(iord).Orientation() == TopAbs_REVERSED) di<<" REV"; else di<<" FWD"; di<<" ordered to "<FixReorder (WO); // Mais on n execute pas } // Statistiques if (oq) { ShapeAnalysis_Edge sae; Standard_Integer nb = sbwd->NbEdges(); di<<"NbEdges : "<Edge(i); di<<"Edge "<IsSeam(i)) di<<" SEAM_WIRE"; if (Shape.ShapeType() == TopAbs_FACE && sae.IsSeam(E,TopoDS::Face(Shape))) di<<" SEAM_FACE"; if (Shape.ShapeType() == TopAbs_FACE ) { if (sae.HasPCurve(E,TopoDS::Face(Shape))) di<<" PCU"; else di<<" NO_PCU"; } if (sae.HasCurve3d(E)) di<<" C3D"; else di<<" NO_C3D"; if (sae.IsClosed3d(E)) di<<" CLOSED"; di<<"\n"; } } // Resultat TopoDS_Wire result; if (ov) { ShapeAnalysis_WireVertex sawv; sawv.Init ( sbwd, saw->Precision() ); sawv.Analyze(); Standard_Integer nb = sbwd->NbEdges(); di<<"Nb(End)Vertex : "<= 3 && stat <= 5) di<<"\n - Position : "<NbEdges(); Standard_Integer num = 1; for (i = 1; i <= nb; i ++) CW.Add (sbwd->Edge(i)); CW.Perform ( saw->Precision() ); nb = CW.NbWires(); if (nb != 1) { // On prend celui qui a le plus d edges Standard_Integer nbe, maxe = 0; for (i = 1; i <= nb; i ++) { TopoDS_Wire wir = CW.Wire(i); nbe = 0; for (TopoDS_Iterator ite(wir); ite.More(); ite.Next()) nbe ++; if (nbe > maxe) { num = i; maxe = nbe; } } di<<"Correct_Wire produced "<WireAPIMake(); else result = sbwd->Wire(); if (result.IsNull()) { di<<"Pas de resultat, desole"<<"\n"; return 1; // Fail } DBRep::Set (arg2,result); return 0; // Done } //======================================================================= //function : reface //purpose : //======================================================================= static Standard_Integer reface (Draw_Interpretor& di, Standard_Integer argc, const char** argv) { if (argc < 3) { di<<"Donner un nom de SHAPE (SHELL ou FACE) + un nom de RESULTAT"<<"\n"; return 1 /* Error */; } Standard_CString arg1 = argv[1]; Standard_CString arg2 = argv[2]; TopoDS_Shape Shape = DBRep::Get(arg1); if (Shape.IsNull()) { di<<"Shape unknown : "<FixWireTool()->FixDegeneratedMode() = valopt; } if (opt == 'r') { di<<" fix-reorder-wire .."; STF->FixWireTool()->FixReorderMode() = valopt; } if (opt == 'k') { } } TopoDS_Face face; ShapeBuild_ReShape resh; Standard_Integer nbf = 0, nbfc = 0; for (TopExp_Explorer EF (Shape,TopAbs_FACE); EF.More(); EF.Next()) { TopoDS_Face F = TopoDS::Face (EF.Current()); face = F; nbf ++; Standard_Boolean newface = Standard_False; // on va voir si ShapeTool_Face trouve qqchose a redire //:sw ShapeTool_Wire STW; //:sw STW.SetFace (F); STF->Init (F); // qui fait tout STF->Perform(); face = STF->Face(); newface = STF->Status(ShapeExtend_DONE) || rebuild; if (newface) { nbfc ++; resh.Replace (F,face); } } if (nbfc > 0) { di<<"Faces reprises par ShapeFix_Face : "<SetMsgRegistrator ( msg ); Standard_CString res = 0; Standard_Integer par = 0, mess=0; for ( Standard_Integer i=1; i < argc; i++ ) { if ( argv[i][0] == '-' || argv[i][0] == '+' || argv[i][0] == '*' ) { Standard_Integer val = ( argv[i][0] == '-' ? 0 : argv[i][0] == '+' ? 1 : -1 ); switch ( argv[i][1] ) { case 'l': sfs->FixWireTool()->FixLackingMode() = val; case 'o': sfs->FixFaceTool()->FixOrientationMode() = val; case 'h': sfs->FixWireTool()->FixShiftedMode() = val; case 'm': sfs->FixFaceTool()->FixMissingSeamMode() = val; case 'd': sfs->FixWireTool()->FixDegeneratedMode() = val; case 's': sfs->FixWireTool()->FixSmallMode() = val; case 'i': sfs->FixWireTool()->FixSelfIntersectionMode() = val; case 'n': sfs->FixWireTool()->FixNotchedEdgesMode() = val; case '?': mess = val; } continue; } else { switch ( par ) { case 0: res = argv[i]; break; case 1: { TopoDS_Shape initShape = DBRep::Get(argv[i]); if(initShape.IsNull()) continue; sfs->Init ( initShape ); } break; case 2: sfs->SetPrecision (atof(argv[i])); break; case 3: sfs->SetMaxTolerance(atof(argv[i])); break; } } par++; } if ( par <2 ) { di << "Use: " << argv[0] << " result shape [tolerance [max_tolerance]] [switches]" << "\n"; di << "Switches allow to tune parameters of ShapeFix" << "\n"; di << "The following syntax is used: " << "\n"; di << "- symbol may be - to set parameter off, + to set on or * to set default" << "\n"; di << "- parameters are identified by letters:" << "\n"; di << " l - FixLackingMode" << "\n"; di << " o - FixOrientationMode" << "\n"; di << " h - FixShiftedMode" << "\n"; di << " m - FixMissingSeamMode" << "\n"; di << " d - FixDegeneratedMode" << "\n"; di << " s - FixSmallMode" << "\n"; di << " i - FixSelfIntersectionMode" << "\n"; di << " n - FixNotchedEdgesMode" << "\n"; di << "For enhanced message output, use switch '+?'" << "\n"; return 1; } sfs->Perform(); DBRep::Set (res,sfs->Shape()); if ( mess ) { Standard_Integer num = 0; const ShapeExtend_DataMapOfShapeListOfMsg &map = msg->MapShape(); for ( ShapeExtend_DataMapIteratorOfDataMapOfShapeListOfMsg it(map); it.More(); it.Next() ) { //cout << it.Key().TShape()->DynamicType()->Name() << " " << *(void**)&it.Key().TShape(); Standard_SStream aSStream; aSStream << it.Key().TShape()->DynamicType()->Name() << " " << *(void**)&it.Key().TShape(); di << aSStream; if ( mess <0 ) { char buff[256]; sprintf ( buff, "%s_%d", res, ++num ); di << " (saved in DRAW shape " << buff << ")"; DBRep::Set (buff,it.Key()); } di << ":" << "\n"; for (Message_ListIteratorOfListOfMsg iter (it.Value()); iter.More(); iter.Next()) di << " " << TCollection_AsciiString(iter.Value().Value()).ToCString() << "\n"; } } return 0; // Done } //======================================================================= //function : fixgaps //purpose : //======================================================================= Standard_Integer fixgaps(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n < 3) return 1; TopoDS_Shape S = DBRep::Get(a[2]); if (S.IsNull()) { di << " Shape is null" << "\n"; return 1; } Handle(ShapeFix_Wireframe) SFWF = new ShapeFix_Wireframe(S); Standard_Real prec = ( n >3 ? atof(a[3]) : 0. ); SFWF->SetPrecision(prec); if ( SFWF->FixWireGaps() ) { DBRep::Set(a[1],SFWF->Shape()); di<<" Wireframe gaps fixed on shape"<<"\n"; } return 0; } //======================================================================= //function : fixsmall //purpose : //======================================================================= Standard_Integer fixsmall(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n < 3) return 1; TopoDS_Shape S = DBRep::Get(a[2]); if (S.IsNull()) { di << " Shape is null" << "\n"; return 1; } Standard_Real prec = (n == 4)? atof(a[3]) : 1.; ShapeFix_Wireframe SFWF(S); SFWF.SetPrecision(prec); if (SFWF.FixSmallEdges()) { DBRep::Set(a[1],SFWF.Shape()); di<<" Small edges fixed on shape"<<"\n"; } return 0; } //======================================================================= //function : fixsmalledges //purpose : //======================================================================= static Standard_Integer fixsmalledges(Draw_Interpretor& di, Standard_Integer n, const char** a) { if( n < 3) { di<<"Invalid number of arguments"<<"\n"; return 1; } TopoDS_Shape Sh = DBRep::Get(a[2]); Standard_Integer k = 3; Standard_Real tol = 100000; Standard_Integer mode = 2; Standard_Real tolang = PI/2; if(n > k) tol = atof(a[k++]); if(n > k) mode= atoi(a[k++]); if(n > k) tolang = atof(a[k++]); Handle(ShapeFix_Wireframe) aSfwr = new ShapeFix_Wireframe(); Handle(ShapeBuild_ReShape) aReShape = new ShapeBuild_ReShape; aSfwr->SetContext(aReShape); aSfwr->Load(Sh); aSfwr->SetPrecision(tol); Standard_Boolean aModeDrop = Standard_True; if(mode == 2) aModeDrop = Standard_False; TopTools_MapOfShape theSmallEdges, theMultyEdges; TopTools_DataMapOfShapeListOfShape theEdgeToFaces,theFaceWithSmall; aSfwr->CheckSmallEdges(theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges); aSfwr->MergeSmallEdges (theSmallEdges,theEdgeToFaces,theFaceWithSmall, theMultyEdges, aModeDrop,tolang); //aSfwr->FixSmallEdges(); TopoDS_Shape resShape = aSfwr->Shape();; DBRep::Set ( a[1], resShape ); return 0; } //======================================================================= //function : checkoverlapedges //purpose : //======================================================================= static Standard_Integer checkoverlapedges(Draw_Interpretor& di, Standard_Integer n, const char** a) { if( n < 3) { di<<"Invalid number of arguments"<<"\n"; return 1; } TopoDS_Shape Sh1 = DBRep::Get(a[1]); TopoDS_Shape Sh2 = DBRep::Get(a[2]); if(Sh1.IsNull() || Sh2.IsNull()) { di<<"Invalid arguments"<<"\n"; return 1; } TopoDS_Edge e1 = TopoDS::Edge(Sh1); TopoDS_Edge e2 = TopoDS::Edge(Sh2); if(e1.IsNull() || e2.IsNull()) { di<<"Invalid type of arguments"<<"\n"; return 1; } Standard_Real aTol = Precision::Confusion(); Standard_Real aDistDomain = 0.0; Standard_Integer k = 3; if(k < n) aTol = atof(a[k++]); if(k < n) aDistDomain = atof(a[k++]); ShapeAnalysis_Edge sae; if(sae.CheckOverlapping(e1,e2,aTol,aDistDomain)) { if(aDistDomain ==0.0) di<<"Edges is overlaping comletly"<<"\n"; else { di<<"Edges is overlaped"<<"\n"; di<<"with tolerance = "<