// Created on: 1994-06-20 // Created by: Modeling // Copyright (c) 1994-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #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 Standard_Real tesp = 1.0e-4; 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) { // std::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) { // std::cout<<"tolerance ang : "<SetParams(ta, tesp, 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; // Save history for fillet if (BRepTest_Objects::IsHistoryNeeded()) { TopTools_ListOfShape anArg; anArg.Append(V); BRepTest_Objects::SetHistory(anArg, *Rakk); } 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) { // std::cout<<"No active Builder"<IsDone()) { // std::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); } // std::cout<<"foreach g [lsort [dir gen*]] { wclick; puts [dname $g]; donl $g; }"<SetParams(ta, tesp, 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) { // std::cout << "MakeFillet not initialized"<Add(uandr, E); return 0; } static Standard_Integer BUILDEVOL(Draw_Interpretor& di, Standard_Integer, const char**) { if (Rake == 0) { // std::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; } //********************************************** // 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) { Message::SendFail() << "Use result shape1 shape2 radius [-d]"; 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()) { Message::SendFail() << " Null shapes are not allowed"; return 1; } Standard_Real Rad = Draw::Atof(a[4]); Standard_Boolean isDebug = Standard_False; if (narg == 6) { if (!strcmp(a[5], "-d")) { isDebug = Standard_True; } } BOPAlgo_PaveFiller theDSFiller; Handle(Draw_ProgressIndicator) aProgress = new Draw_ProgressIndicator(di, 1); Message_ProgressScope aPS(aProgress->Start(), NULL, 10); TopTools_ListOfShape aLS; aLS.Append(S1); aLS.Append(S2); theDSFiller.SetArguments(aLS); // theDSFiller.Perform(aPS.Next(8)); if (theDSFiller.HasErrors()) { Message::SendFail() << "Check types of the arguments, please"; return 1; } BRepAlgoAPI_BooleanOperation* pBuilder = NULL; if (fuse) pBuilder = new BRepAlgoAPI_Fuse(S1, S2, theDSFiller, aPS.Next(2)); else pBuilder = new BRepAlgoAPI_Cut(S1, S2, theDSFiller, Standard_True, aPS.Next(2)); Standard_Boolean anIsDone = pBuilder->IsDone(); if (!anIsDone) { Message::SendFail() << "boolean operation not done HasErrors()=" << pBuilder->HasErrors(); return 1; } TopoDS_Shape ResultOfBop = pBuilder->Shape(); delete pBuilder; const int aStrLen = 1000; char aBuff[aStrLen]; if (isDebug) { strcpy(aBuff, a[1]); DBRep::Set(strcat(aBuff, "_bop"), ResultOfBop); di << "Intermediate result of BOP-operation is saved to \"" << aBuff << "\" variable\n"; } pBuilder = new BRepAlgoAPI_Section(S1, S2, theDSFiller); TopoDS_Shape theSection = pBuilder->Shape(); if (isDebug) { strcpy(aBuff, a[1]); DBRep::Set(strcat(aBuff, "_sec"), theSection); di << "Intermediate bopsection result is saved to \"" << aBuff << "\" variable\n"; } 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, tesp, 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 { di << "Error: Cannot find the result of BLEND-operation." " The result of BOP operation will be returned.\n"; 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 aRakk(V, E, Rad); if (simul) aRakk.Simulate(); else aRakk.Perform(); // if (Rakk.IsDone()==FilletSurf_IsNotOk) // { FilletSurf_ErrorTypeStatus err=Rakk.StatusError(); // if (err==FilletSurf_EmptyList) std::cout<< "StatusError=EmptyList"<