// File: BOPTest_LowCommands.cxx // Created: Wed Mar 28 16:46:22 2001 // Author: Peter KURNEV // #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 static Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, const TopoDS_Face& F, Standard_Real& First, Standard_Real& Last); static Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L, Standard_Real& First, Standard_Real& Last); static void PrintState (Draw_Interpretor& aDI, const TopAbs_State& aState); static Standard_Integer bhaspc (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer baddve (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bisclosed (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bexplode (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bupdateedge (Draw_Interpretor& , Standard_Integer , const char**); static Standard_Integer bremovesim (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bopsetdisp (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bfaceprepare(Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer brefine (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bclassify (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer b2dclassify (Draw_Interpretor& , Standard_Integer , const char** ); //modified by NIZNHY-PKV Mon May 29 11:44:24 2006f static Standard_Integer bhole (Draw_Interpretor& , Standard_Integer , const char** ); static Standard_Integer bxhole (Draw_Interpretor& , Standard_Integer , const char** ); //modified by NIZNHY-PKV Mon May 29 11:44:28 2006t //======================================================================= //function : LowCommands //purpose : //======================================================================= void BOPTest::LowCommands(Draw_Interpretor& theCommands) { static Standard_Boolean done = Standard_False; if (done) return; done = Standard_True; // Chapter's name const char* g = "CCR commands"; // // Whether Edge has PCurve on Face theCommands.Add("bhaspc" , "Use >bhaspc Edge Face" , __FILE__, bhaspc , g); theCommands.Add("baddve" , "Use >addve E V1 V2 p1 p2", __FILE__, baddve , g); theCommands.Add("bisclosed" , "Use >bisclosed Edge Face" , __FILE__, bisclosed , g); theCommands.Add("bexplode" , "" , __FILE__, bexplode , g); theCommands.Add("bupdateedge" , "Use bupdateedge Edge Face", __FILE__, bupdateedge , g); theCommands.Add("bremovesim" , "Use bremovesim Face" , __FILE__, bremovesim , g); theCommands.Add("bopsetdisp" , "Use bopsetdisp" , __FILE__, bopsetdisp , g); theCommands.Add("bfaceprepare" , "Use bfaceprepare F1 " , __FILE__, bfaceprepare, g); theCommands.Add("brefine" , "Use brefine Shape " , __FILE__, brefine , g); theCommands.Add("bclassify" , "Use >bclassify Solid Point [Tolerance=1.e-7]", __FILE__, bclassify , g); theCommands.Add("b2dclassify" , "Use >bclassify Face Point2d [Tol2D=Tol(Face)] ", __FILE__, b2dclassify , g); //modified by NIZNHY-PKV Mon May 29 11:45:33 2006f theCommands.Add("bhole" , "Use bhole" , __FILE__, bhole , g); theCommands.Add("bxhole" , "Use bxhole" , __FILE__, bxhole , g); //modified by NIZNHY-PKV Mon May 29 11:45:37 2006t } //======================================================================= //function : brefine //purpose : //======================================================================= Standard_Integer brefine (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<2) { di << " Use >brefine Shape1\n"; return 1; } TopoDS_Shape aS = DBRep::Get(a[1]); if (aS.IsNull()) { di << " Null shape is not allowed \n"; return 1; } Standard_Boolean bIsDone; BOP_Refiner aRefiner; aRefiner.SetShape(aS); aRefiner.Do(); bIsDone=aRefiner.IsDone(); if (bIsDone) { Standard_Integer aNbRemovedVertices, aNbRemovedEdges, iFlag=0; aNbRemovedVertices=aRefiner.NbRemovedVertices(); aNbRemovedEdges=aRefiner.NbRemovedEdges(); if (aNbRemovedVertices) { di << " Vertices removed=" << aNbRemovedVertices << "%d\n"; iFlag++; } if (aNbRemovedEdges) { di << " Edges removed=" << aNbRemovedEdges << "\n"; iFlag++; } // REFRESH if (iFlag) { TCollection_AsciiString aNm(a[1]); Standard_CString pstr; pstr=aNm.ToCString(); DBRep::Set(pstr, aS); } } else { di << "Not Done, err=" << aRefiner.ErrorStatus() << "\n"; } return 0; } //======================================================================= //function : bfaceprepare //purpose : //======================================================================= Standard_Integer bfaceprepare(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<2) { di << " Use bfaceprepare> F1\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); if (S1.IsNull()) { di << " Null shape is not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_FACE) { di << " Type mismatch\n"; return 1; } const TopoDS_Face& aF1=TopoDS::Face(S1); TopAbs_Orientation anOr; anOr=aF1.Orientation(); if (anOr==TopAbs_FORWARD) { return 0; } // Standard_Real aTol; TopoDS_Face newFace; BRep_Builder aBB; Handle(Geom_Surface) aS1=BRep_Tool::Surface(aF1); Handle(Geom_Surface) aS=Handle(Geom_Surface)::DownCast(aS1->Copy()); aS->VReverse(); aTol=BRep_Tool::Tolerance(aF1); aBB.MakeFace (newFace, aS, aTol); TopExp_Explorer anExp(aF1, TopAbs_WIRE); for (; anExp.More(); anExp.Next()) { const TopoDS_Shape& newWire=anExp.Current(); aBB.Add(newFace, newWire); } TCollection_AsciiString aNm(a[1]), aNmNew("_r"); aNm=aNm+aNmNew; Standard_CString an=aNm.ToCString(); di << an << "\n"; DBRep::Set(an, newFace); return 0; } //======================================================================= //function : bopsetdisp //purpose : //======================================================================= Standard_Integer bopsetdisp (Draw_Interpretor& di, Standard_Integer , const char** ) { Standard_Integer aFlag; char* xr=getenv("MDISP"); if (xr==NULL) { aFlag=putenv((char*)"MDISP=yes"); di << " MDISP=yes. Return code=" << aFlag << "\n"; } else if (!strcmp (xr, "yes")) { aFlag=putenv((char*)"MDISP=no"); di << " MDISP=no. Return code=" << aFlag << "\n"; } else { aFlag=putenv((char*)"MDISP=yes"); di << " MDISP=yes. Return code=" << aFlag << "\n"; } return 0; } //======================================================================= //function : bremovesim //purpose : //======================================================================= Standard_Integer bremovesim (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<2) { di << " Use bremovesim> Face\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); if (S1.IsNull()) { di << " Null shapes are not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_FACE) { di << " Type mismatch\n"; return 1; } const TopoDS_Face& aF=TopoDS::Face(S1); // IntTools_Context aCtx; BOPTools_Tools3D::RemoveSims (aF, aCtx); // di << " Ok\n"; return 0; } //======================================================================= //function : bupdateedge //purpose : //======================================================================= Standard_Integer bupdateedge (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<3) { di << " Use bupdateedge> Edge Face\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); TopoDS_Shape S2 = DBRep::Get(a[2]); if (S1.IsNull() || S2.IsNull()) { di << " Null shapes are not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) { di << " Type mismatch\n"; return 1; } const TopoDS_Edge& aE=TopoDS::Edge(S1); const TopoDS_Face& aF=TopoDS::Face(S2); Handle(Geom2d_Curve) aC2D; Standard_Real aTol; aTol=BRep_Tool::Tolerance(aE); BRep_Builder BB; BB.UpdateEdge(aE, aC2D, aF, aTol); di << " Ok\n"; return 0; } //======================================================================= //function : bisclosed //purpose : //======================================================================= Standard_Integer bisclosed (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<3) { di << " Use bisclosed> Edge Face\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); TopoDS_Shape S2 = DBRep::Get(a[2]); if (S1.IsNull() || S2.IsNull()) { di << " Null shapes are not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) { di << " Type mismatch\n"; return 1; } const TopoDS_Edge& aE=TopoDS::Edge(S1); const TopoDS_Face& aF=TopoDS::Face(S2); Standard_Boolean anIsClosed; anIsClosed=BRep_Tool::IsClosed(aE, aF); if (!anIsClosed) { di << " Edge is not closed on this face\n"; } else { di << " Edge is closed on this face\n"; } return 0; } //======================================================================= //function : bhaspc //purpose : //======================================================================= Standard_Integer bhaspc (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<3) { di << " Use bhaspc> Edge Face [do]\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); TopoDS_Shape S2 = DBRep::Get(a[2]); if (S1.IsNull() || S2.IsNull()) { di << " Null shapes are not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_FACE) { di << " Type mismatch\n"; return 1; } const TopoDS_Edge& aE=TopoDS::Edge(S1); const TopoDS_Face& aF=TopoDS::Face(S2); Standard_Real f2D, l2D; Handle(Geom2d_Curve) C2D=CurveOnSurface(aE, aF, f2D, l2D); if (C2D.IsNull()) { di << " No 2D Curves detected\n"; } else { di << " Ok Edge has P-Curve on this Face\n"; } if (n==4) { if (!strcmp(a[3], "do")) { BOPTools_Tools2D::BuildPCurveForEdgeOnFace(aE, aF); } } return 0; } //======================================================================= //function : baddve //purpose : //======================================================================= Standard_Integer baddve (Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n<6) { di << " Use baddve> E V1 V2 p1 p2\n"; return 1; } TopoDS_Shape S1 = DBRep::Get(a[1]); TopoDS_Shape S2 = DBRep::Get(a[2]); TopoDS_Shape S3 = DBRep::Get(a[3]); if (S1.IsNull() || S2.IsNull() || S3.IsNull()) { di << " Null shapes are not allowed \n"; return 1; } if (S1.ShapeType()!=TopAbs_EDGE || S2.ShapeType()!=TopAbs_VERTEX || S3.ShapeType()!=TopAbs_VERTEX ) { di << " Type mismatch\n"; return 1; } const TopoDS_Edge& aE=TopoDS::Edge(S1); const TopoDS_Vertex& aV1=TopoDS::Vertex(S2); const TopoDS_Vertex& aV2=TopoDS::Vertex(S3); Standard_Real p1, p2; p1=atof(a[4]); p2=atof(a[5]); TopoDS_Edge E=aE; E.EmptyCopy(); BRep_Builder BB; BB.Add (E, aV1); BB.Add (E, aV2); BB.Range(E, p1, p2); DBRep::Set("ne", E); return 0; } static Handle(Geom2d_Curve) nullPCurve; //======================================================================= //function : CurveOnSurface //purpose : //======================================================================= Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, const TopoDS_Face& F, Standard_Real& First, Standard_Real& Last) { TopLoc_Location l; const Handle(Geom_Surface)& S = BRep_Tool::Surface(F,l); TopoDS_Edge aLocalEdge = E; if (F.Orientation() == TopAbs_REVERSED) { aLocalEdge.Reverse(); } return CurveOnSurface(aLocalEdge,S,l,First,Last); } //======================================================================= //function : CurveOnSurface //purpose : //======================================================================= Handle(Geom2d_Curve) CurveOnSurface(const TopoDS_Edge& E, const Handle(Geom_Surface)& S, const TopLoc_Location& L, Standard_Real& First, Standard_Real& Last) { TopLoc_Location l = L.Predivided(E.Location()); Standard_Boolean Eisreversed = (E.Orientation() == TopAbs_REVERSED); // find the representation BRep_ListIteratorOfListOfCurveRepresentation itcr ((*((Handle(BRep_TEdge)*)&E.TShape()))->ChangeCurves()); while (itcr.More()) { const Handle(BRep_CurveRepresentation)& cr = itcr.Value(); if (cr->IsCurveOnSurface(S,l)) { const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr); GC->Range(First,Last); if (GC->IsCurveOnClosedSurface() && Eisreversed) return GC->PCurve2(); else return GC->PCurve(); } itcr.Next(); } return nullPCurve; } //======================================================================= //function : bexplode //purpose : //======================================================================= static Standard_Integer bexplode(Draw_Interpretor& di, Standard_Integer n, const char** a) { if (n <= 1) return 1; TopoDS_Shape S = DBRep::Get(a[1]); if (S.IsNull()) return 0; char newname[1024]; strcpy(newname,a[1]); char* p = newname; while (*p != '\0') p++; *p = '_'; p++; Standard_Integer i = 0; if (n == 2) { TopoDS_Iterator itr(S); while (itr.More()) { i++; sprintf(p,"%d",i); DBRep::Set(newname,itr.Value()); di.AppendElement(newname); itr.Next(); } } else { // explode a type TopAbs_ShapeEnum typ; switch (a[2][0]) { case 'C' : case 'c' : if ((a[2][1] == 'd')||(a[2][1] == 'D')) typ = TopAbs_COMPOUND; else typ = TopAbs_COMPSOLID; break; case 'S' : case 's' : if ((a[2][1] == 'O')||(a[2][1] == 'o')) typ = TopAbs_SOLID; else if ((a[2][1] == 'H')||(a[2][1] == 'h')) typ = TopAbs_SHELL; else return 1; break; case 'F' : case 'f' : typ = TopAbs_FACE; break; case 'W' : case 'w' : typ = TopAbs_WIRE; break; case 'E' : case 'e' : typ = TopAbs_EDGE; break; case 'V' : case 'v' : typ = TopAbs_VERTEX; break; default : return 1; } TopExp_Explorer ex(S,typ); for (; ex.More(); ex.Next()) { const TopoDS_Shape& aS = ex.Current(); i++; sprintf(p,"%d",i); DBRep::Set(newname,aS); di.AppendElement(newname); } } return 0; } //======================================================================= //function : bclassify //purpose : //======================================================================= Standard_Integer bclassify (Draw_Interpretor& aDI, Standard_Integer n, const char** a) { char sbf[512]; if (n < 3) { sprintf(sbf, " Use >bclassify Solid Point [Tolerance=1.e-7]\n"); aDI<bclassify Face Point2d [Tol2D=Tol(Face)]\n"); aDI<