1 // Created on: 2016-04-01
2 // Created by: Nikolai BUKHALOV
3 // Copyright (c) 2000-2016 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <BOPTest.hxx>
18 #include <BOPTools_AlgoTools.hxx>
19 #include <BOPTools_AlgoTools2D.hxx>
21 #include <IntTools_Context.hxx>
23 #include <TopoDS_Edge.hxx>
24 #include <TopoDS_Face.hxx>
25 #include <TopoDS_Shape.hxx>
26 #include <TopExp_Explorer.hxx>
28 #include <BOPAlgo_Tools.hxx>
29 #include <BRepLib.hxx>
31 static Standard_Integer attachpcurve (Draw_Interpretor&, Standard_Integer, const char**);
32 static Standard_Integer edgestowire (Draw_Interpretor&, Standard_Integer, const char**);
33 static Standard_Integer edgestofaces (Draw_Interpretor&, Standard_Integer, const char**);
34 static Standard_Integer BuildPcurvesOnPlane(Draw_Interpretor&, Standard_Integer, const char**);
36 //=======================================================================
37 //function : BOPCommands
39 //=======================================================================
40 void BOPTest::UtilityCommands(Draw_Interpretor& theCommands)
42 static Standard_Boolean done = Standard_False;
46 const char* group = "BOPTest commands";
49 theCommands.Add("attachpcurve", "attachpcurve eold enew face", __FILE__, attachpcurve, group);
50 theCommands.Add("edgestowire" , "edgestowire wire edges" , __FILE__, edgestowire , group);
51 theCommands.Add("edgestofaces" , "edgestofaces faces edges [-a AngTol -s Shared(0/1)]", __FILE__, edgestofaces , group);
52 theCommands.Add("buildpcurvesonplane", "buildpcurvesonplane shape", __FILE__, BuildPcurvesOnPlane, group);
55 //=======================================================================
56 //function : BOPCommands
57 //purpose : Attaches p-curve of the given edge to the given face.
58 //=======================================================================
59 static Standard_Integer attachpcurve(Draw_Interpretor& theDI,
60 Standard_Integer theNArg,
61 const char ** theArgVal)
65 theDI << "Use: " << theArgVal[0] << " eold enew face\n";
69 TopoDS_Shape aShEOld(DBRep::Get(theArgVal[1]));
70 TopoDS_Shape aShENew(DBRep::Get(theArgVal[2]));
71 TopoDS_Shape aShFace(DBRep::Get(theArgVal[3]));
73 if (aShEOld.IsNull()) {
74 theDI << theArgVal[1] << " is null shape\n";
76 } else if (aShEOld.ShapeType() != TopAbs_EDGE) {
77 theDI << theArgVal[1] << " is not an edge\n";
81 if (aShENew.IsNull()) {
82 theDI << theArgVal[2] << " is null shape\n";
84 } else if (aShENew.ShapeType() != TopAbs_EDGE) {
85 theDI << theArgVal[2] << " is not an edge\n";
89 if (aShFace.IsNull()) {
90 theDI << theArgVal[3] << " is null shape\n";
92 } else if (aShFace.ShapeType() != TopAbs_FACE) {
93 theDI << theArgVal[3] << " is not a face\n";
97 TopoDS_Edge aEOld = TopoDS::Edge(aShEOld);
98 TopoDS_Edge aENew = TopoDS::Edge(aShENew);
99 TopoDS_Face aFace = TopoDS::Face(aShFace);
101 // Try to copy PCurve from old edge to the new one.
102 Handle(IntTools_Context) aCtx = new IntTools_Context;
103 const Standard_Integer iRet =
104 BOPTools_AlgoTools2D::AttachExistingPCurve(aEOld, aENew, aFace, aCtx);
107 theDI << "Error! Code: " << iRet << "\n";
109 theDI << "PCurve is attached successfully\n";
115 //=======================================================================
116 //function : edgestowire
117 //purpose : Orients the edges to make wire
118 //=======================================================================
119 static Standard_Integer edgestowire(Draw_Interpretor& theDI,
120 Standard_Integer theNArg,
121 const char ** theArgVal)
124 theDI << "Use: edgestowire wire edges\n";
128 TopoDS_Shape anEdges = DBRep::Get(theArgVal[2]);
129 if (anEdges.IsNull()) {
130 theDI << "no edges\n";
134 BOPTools_AlgoTools::OrientEdgesOnWire(anEdges);
135 DBRep::Set(theArgVal[1], anEdges);
139 //=======================================================================
140 //function : edgestofaces
141 //purpose : Creates planar faces from linear edges
142 //=======================================================================
143 static Standard_Integer edgestofaces(Draw_Interpretor& theDI,
144 Standard_Integer theNArg,
145 const char ** theArgVal)
148 theDI << "Use: edgestofaces faces edges [-a AngTol -s Shared(0/1)]\n";
149 theDI << " AngTol - angular tolerance for comparing the planes;\n";
150 theDI << " Shared - boolean flag which defines whether the input\n";
151 theDI << " edges are already shared or have to be intersected.\n";
155 TopoDS_Shape anEdges = DBRep::Get(theArgVal[2]);
156 if (anEdges.IsNull()) {
157 theDI << "no edges\n";
161 Standard_Real anAngTol = 1.e-8;
162 Standard_Boolean bShared = Standard_False;
164 for (Standard_Integer i = 3; i < theNArg; ++i) {
165 if (!strcmp(theArgVal[i], "-a") && (i+1 < theNArg)) {
166 anAngTol = Draw::Atof(theArgVal[i+1]);
168 if (!strcmp(theArgVal[i], "-s") && (i+1 < theNArg)) {
169 bShared = (Draw::Atoi(theArgVal[i+1]) == 1);
174 Standard_Integer iErr = BOPAlgo_Tools::EdgesToWires(anEdges, aWires, bShared, anAngTol);
176 theDI << "Unable to build wires from given edges\n";
181 Standard_Boolean bDone = BOPAlgo_Tools::WiresToFaces(aWires, aFaces, anAngTol);
183 theDI << "Unable to build faces from wires\n";
187 DBRep::Set(theArgVal[1], aFaces);
191 //=======================================================================
192 //function : BuildPcurvesOnPlane
193 //purpose : Build and store pcurves of edges on planes
194 //=======================================================================
195 static Standard_Integer BuildPcurvesOnPlane(Draw_Interpretor& theDI,
196 Standard_Integer theNArg,
197 const char ** theArgVal)
201 theDI << "Use: " << theArgVal[0] << " shape\n";
205 TopoDS_Shape aShape(DBRep::Get(theArgVal[1]));
206 if (aShape.IsNull()) {
207 theDI << theArgVal[1] << " is null shape\n";
211 TopExp_Explorer exp(aShape, TopAbs_FACE);
212 for (; exp.More(); exp.Next())
214 const TopoDS_Face& aF = TopoDS::Face(exp.Current());
215 BRepAdaptor_Surface aS(aF, Standard_False);
216 if (aS.GetType() == GeomAbs_Plane)
218 TopTools_ListOfShape aLE;
219 TopExp_Explorer exp1(aF, TopAbs_EDGE);
220 for (; exp1.More(); exp1.Next())
221 aLE.Append(exp1.Current());
222 BRepLib::BuildPCurveForEdgesOnPlane(aLE, aF);