// Created on: 1994-06-20 // Created by: Modeling // Copyright (c) 1994-1999 Matra Datavision // Copyright (c) 1999-2012 OPEN CASCADE SAS // // The content of this file is subject to the Open CASCADE Technology Public // License Version 6.5 (the "License"). You may not use the content of this file // except in compliance with the License. Please obtain a copy of the License // at http://www.opencascade.org and read it completely before using this file. // // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. // // The Original Code and all software distributed under the License is // distributed on an "AS IS" basis, without warranty of any kind, and the // Initial Developer hereby disclaims all such warranties, including without // limitation, any warranties of merchantability, fitness for a particular // purpose or non-infringement. Please see the License for the specific terms // and conditions governing the rights and limitations under the License. #ifdef HAVE_CONFIG_H # include #endif #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 WNT //#define strcasecmp strcmp Already defined #endif #ifdef HAVE_STRINGS_H # include #endif #include //#endif static Standard_Real t3d = 1.e-4; static Standard_Real t2d = 1.e-5; static Standard_Real ta = 1.e-2; static Standard_Real fl = 1.e-3; static Standard_Real tapp_angle = 1.e-2; static GeomAbs_Shape blend_cont = GeomAbs_C1; static BRepFilletAPI_MakeFillet* Rakk = 0; static BRepFilletAPI_MakeFillet* Rake = 0; static char name[100]; static Standard_Integer contblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) { if(narg ==1) { //cout<<"tolerance angular of approximation : "<< tapp_angle <3) return 1; if (narg == 3) { tapp_angle = Abs(Draw::Atof(a[2])); } char c=a[1][1]; switch (c) { case '0': blend_cont = GeomAbs_C0; break; case '2': blend_cont = GeomAbs_C2; break; default : blend_cont = GeomAbs_C1; } return 0; } } static void printtolblend(Draw_Interpretor& di) { //cout<<"tolerance ang : "<SetParams(ta,t3d,t2d,t3d,t2d,fl); Rakk->SetContinuity(blend_cont, tapp_angle); Standard_Real Rad; TopoDS_Edge E; Standard_Integer nbedge = 0; for (Standard_Integer ii = 1; ii < (narg-1)/2; ii++){ Rad = Draw::Atof(a[2*ii + 1]); TopoDS_Shape aLocalEdge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE)); E = TopoDS::Edge(aLocalEdge); // E = TopoDS::Edge(DBRep::Get(a[(2*ii+2)],TopAbs_EDGE)); if(!E.IsNull()){ Rakk->Add(Rad,E); nbedge++; } } if(!nbedge) return 1; Rakk->Build(); if(!Rakk->IsDone()) return 1; TopoDS_Shape res = Rakk->Shape(); DBRep::Set(a[1],res); return 0; } static void PrintHist(const TopoDS_Shape& S, TopTools_ListIteratorOfListOfShape& It, Standard_Integer& nbgen) { TopoDS_Compound C; BRep_Builder B; B.MakeCompound(C); B.Add(C,S); char localname[100]; if(nbgen<10){ Sprintf(localname,"generated_00%d", nbgen++); } else if(nbgen<100){ Sprintf(localname,"generated_0%d", nbgen++); } else { Sprintf(localname,"generated_%d", nbgen++); } for(; It.More(); It.Next()){ B.Add(C,It.Value()); } DBRep::Set(localname,C); } static Standard_Integer CheckHist(Draw_Interpretor& di, Standard_Integer , const char** ) { if(Rakk == 0) { //cout<<"No active Builder"<IsDone()) { //cout<<"Active Builder Not Done"<NbContours(); Standard_Integer nbgen = 0; TopTools_ListIteratorOfListOfShape It; TopoDS_Shape curshape; for(Standard_Integer i = 1; i <= nbc; i++){ curshape = Rakk->FirstVertex(i); It.Initialize(Rakk->Generated(curshape)); PrintHist(curshape,It,nbgen); Standard_Integer nbe = Rakk->NbEdges(i); for(Standard_Integer j = 1; j <= nbe; j++){ curshape = Rakk->Edge(i,j); It.Initialize(Rakk->Generated(curshape)); PrintHist(curshape,It,nbgen); } curshape = Rakk->LastVertex(i); It.Initialize(Rakk->Generated(curshape)); PrintHist(curshape,It,nbgen); } //cout<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<SetParams(ta,t3d,t2d,t3d,t2d,fl); Rake->SetContinuity(blend_cont, tapp_angle); if (narg == 4) { ChFi3d_FilletShape FSh = ChFi3d_Rational; if (!strcasecmp(a[3], "Q")) { FSh = ChFi3d_QuasiAngular; } else if (!strcasecmp(a[3], "P")) { FSh = ChFi3d_Polynomial; } Rake->SetFilletShape(FSh); } strcpy(name, a[1]); return 0; } static Standard_Integer UPDATEVOL(Draw_Interpretor& di, Standard_Integer narg, const char** a) { if(Rake == 0){ //cout << "MakeFillet not initialized"<Add(uandr,E); return 0; } static Standard_Integer BUILDEVOL(Draw_Interpretor& di, Standard_Integer, const char**) { if(Rake == 0){ //cout << "MakeFillet not initialized"<Build(); if(Rake->IsDone()){ TopoDS_Shape result = Rake->Shape(); DBRep::Set(name,result); if(Rake != 0) {delete Rake; Rake = 0;} return 0; } if(Rake != 0) {delete Rake; Rake = 0;} return 1; } //********************************************** // command fuse and cut with fillets * //********************************************** Standard_Integer topoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) { printtolblend(di); if(narg != 5) return 1; Standard_Boolean fuse = !strcmp(a[0],"fubl"); TopoDS_Shape S1 = DBRep::Get(a[2]); TopoDS_Shape S2 = DBRep::Get(a[3]); Standard_Real Rad = Draw::Atof(a[4]); BRepAlgo_BooleanOperation* BC; if(fuse){ BC = new BRepAlgo_Fuse(S1,S2); } else{ BC = new BRepAlgo_Cut(S1,S2); } TopoDS_Shape ShapeCut = BC->Shape(); Handle(TopOpeBRepBuild_HBuilder) build = BC->Builder(); TopTools_ListIteratorOfListOfShape its; TopoDS_Compound result; BRep_Builder B; B.MakeCompound(result); TopExp_Explorer ex; for (ex.Init(ShapeCut,TopAbs_SOLID); ex.More(); ex.Next()) { const TopoDS_Shape& cutsol = ex.Current(); BRepFilletAPI_MakeFillet fill(cutsol); fill.SetParams(ta,t3d,t2d,t3d,t2d,fl); fill.SetContinuity(blend_cont, tapp_angle); its = build->Section(); while (its.More()) { TopoDS_Edge E = TopoDS::Edge(its.Value()); fill.Add(Rad,E); its.Next(); } fill.Build(); if(fill.IsDone()){ B.Add(result,fill.Shape()); } else { B.Add(result,cutsol); } } delete BC; DBRep::Set(a[1],result); return 0; } //********************************************** // bfuse or bcut and then blend the section //********************************************** Standard_Integer boptopoblend(Draw_Interpretor& di, Standard_Integer narg, const char** a) { printtolblend(di); if(narg != 5) return 1; Standard_Boolean fuse = !strcmp(a[0],"bfuseblend"); TopoDS_Shape S1 = DBRep::Get(a[2]); TopoDS_Shape S2 = DBRep::Get(a[3]); if (S1.IsNull() || S2.IsNull()) { printf(" Null shapes are not allowed \n"); return 1; } Standard_Real Rad = Draw::Atof(a[4]); BOPTools_DSFiller theDSFiller; theDSFiller.SetShapes( S1, S2 ); if (!theDSFiller.IsDone()) { printf("Check types of the arguments, please\n"); return 1; } theDSFiller.Perform(); BRepAlgoAPI_BooleanOperation* pBuilder=NULL; if (fuse) pBuilder = new BRepAlgoAPI_Fuse( S1, S2, theDSFiller ); else pBuilder = new BRepAlgoAPI_Cut ( S1, S2, theDSFiller ); Standard_Boolean anIsDone = pBuilder->IsDone(); if (!anIsDone) { printf("boolean operation not done ErrorStatus()=%d\n", pBuilder->ErrorStatus()); return 1; } TopoDS_Shape ResultOfBop = pBuilder->Shape(); delete pBuilder; pBuilder = new BRepAlgoAPI_Section( S1, S2, theDSFiller ); TopoDS_Shape theSection = pBuilder->Shape(); TopoDS_Compound result; BRep_Builder BB; BB.MakeCompound(result); TopExp_Explorer Explo( ResultOfBop, TopAbs_SOLID ); for (; Explo.More(); Explo.Next()) { const TopoDS_Shape& aSolid = Explo.Current(); BRepFilletAPI_MakeFillet Blender(aSolid); Blender.SetParams(ta,t3d,t2d,t3d,t2d,fl); Blender.SetContinuity( blend_cont, tapp_angle ); TopExp_Explorer expsec( theSection, TopAbs_EDGE ); for (; expsec.More(); expsec.Next()) { TopoDS_Edge anEdge = TopoDS::Edge(expsec.Current()); Blender.Add( Rad, anEdge ); } Blender.Build(); if (Blender.IsDone()) BB.Add( result, Blender.Shape() ); else BB.Add( result, aSolid ); } delete pBuilder; DBRep::Set( a[1], result ); return 0; } static Standard_Integer blend1(Draw_Interpretor& di, Standard_Integer narg, const char** a) { if (narg<5) return 1; TopoDS_Shape V = DBRep::Get(a[2]); if(V.IsNull()) return 1; Standard_Integer nb ,i; Standard_Real Rad; Standard_Boolean simul=Standard_False; const char *ns0=(a[1]); Rad = Draw::Atof(a[3]); TopTools_ListOfShape E; for (i=4; i <=(narg-1) ; i++){ TopoDS_Shape edge= DBRep::Get(a[i],TopAbs_EDGE); if (edge.IsNull()) return 1 ; if(edge.ShapeType()!=TopAbs_EDGE) return 1; E.Append(edge); } FilletSurf_Builder Rakk(V,E,Rad); if (simul) Rakk.Simulate(); else Rakk.Perform(); //if (Rakk.IsDone()==FilletSurf_IsNotOk) // { FilletSurf_ErrorTypeStatus err=Rakk.StatusError(); // if (err==FilletSurf_EmptyList) cout<< "StatusError=EmptyList"<