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>
27 #include <BOPAlgo_Tools.hxx>
29 static Standard_Integer attachpcurve (Draw_Interpretor&, Standard_Integer, const char**);
30 static Standard_Integer edgestowire (Draw_Interpretor&, Standard_Integer, const char**);
31 static Standard_Integer edgestofaces (Draw_Interpretor&, Standard_Integer, const char**);
33 //=======================================================================
34 //function : BOPCommands
36 //=======================================================================
37 void BOPTest::UtilityCommands(Draw_Interpretor& theCommands)
39 static Standard_Boolean done = Standard_False;
43 const char* group = "BOPTest commands";
46 theCommands.Add("attachpcurve", "attachpcurve eold enew face", __FILE__, attachpcurve, group);
47 theCommands.Add("edgestowire" , "edgestowire wire edges" , __FILE__, edgestowire , group);
48 theCommands.Add("edgestofaces" , "edgestofaces faces edges [-a AngTol -s Shared(0/1)]", __FILE__, edgestofaces , group);
51 //=======================================================================
52 //function : BOPCommands
53 //purpose : Attaches p-curve of the given edge to the given face.
54 //=======================================================================
55 static Standard_Integer attachpcurve(Draw_Interpretor& theDI,
56 Standard_Integer theNArg,
57 const char ** theArgVal)
61 theDI << "Use: " << theArgVal[0] << " eold enew face\n";
65 TopoDS_Shape aShEOld(DBRep::Get(theArgVal[1]));
66 TopoDS_Shape aShENew(DBRep::Get(theArgVal[2]));
67 TopoDS_Shape aShFace(DBRep::Get(theArgVal[3]));
69 if (aShEOld.IsNull()) {
70 theDI << theArgVal[1] << " is null shape\n";
72 } else if (aShEOld.ShapeType() != TopAbs_EDGE) {
73 theDI << theArgVal[1] << " is not an edge\n";
77 if (aShENew.IsNull()) {
78 theDI << theArgVal[2] << " is null shape\n";
80 } else if (aShENew.ShapeType() != TopAbs_EDGE) {
81 theDI << theArgVal[2] << " is not an edge\n";
85 if (aShFace.IsNull()) {
86 theDI << theArgVal[3] << " is null shape\n";
88 } else if (aShFace.ShapeType() != TopAbs_FACE) {
89 theDI << theArgVal[3] << " is not a face\n";
93 TopoDS_Edge aEOld = TopoDS::Edge(aShEOld);
94 TopoDS_Edge aENew = TopoDS::Edge(aShENew);
95 TopoDS_Face aFace = TopoDS::Face(aShFace);
97 // Try to copy PCurve from old edge to the new one.
98 Handle(IntTools_Context) aCtx = new IntTools_Context;
99 const Standard_Integer iRet =
100 BOPTools_AlgoTools2D::AttachExistingPCurve(aEOld, aENew, aFace, aCtx);
103 theDI << "Error! Code: " << iRet << "\n";
105 theDI << "PCurve is attached successfully\n";
111 //=======================================================================
112 //function : edgestowire
113 //purpose : Orients the edges to make wire
114 //=======================================================================
115 static Standard_Integer edgestowire(Draw_Interpretor& theDI,
116 Standard_Integer theNArg,
117 const char ** theArgVal)
120 theDI << "Use: edgestowire wire edges\n";
124 TopoDS_Shape anEdges = DBRep::Get(theArgVal[2]);
125 if (anEdges.IsNull()) {
126 theDI << "no edges\n";
130 BOPTools_AlgoTools::OrientEdgesOnWire(anEdges);
131 DBRep::Set(theArgVal[1], anEdges);
135 //=======================================================================
136 //function : edgestofaces
137 //purpose : Creates planar faces from linear edges
138 //=======================================================================
139 static Standard_Integer edgestofaces(Draw_Interpretor& theDI,
140 Standard_Integer theNArg,
141 const char ** theArgVal)
144 theDI << "Use: edgestofaces faces edges [-a AngTol -s Shared(0/1)]\n";
145 theDI << " AngTol - angular tolerance for comparing the planes;\n";
146 theDI << " Shared - boolean flag which defines whether the input\n";
147 theDI << " edges are already shared or have to be intersected.\n";
151 TopoDS_Shape anEdges = DBRep::Get(theArgVal[2]);
152 if (anEdges.IsNull()) {
153 theDI << "no edges\n";
157 Standard_Real anAngTol = 1.e-8;
158 Standard_Boolean bShared = Standard_False;
160 for (Standard_Integer i = 3; i < theNArg; ++i) {
161 if (!strcmp(theArgVal[i], "-a") && (i+1 < theNArg)) {
162 anAngTol = Draw::Atof(theArgVal[i+1]);
164 if (!strcmp(theArgVal[i], "-s") && (i+1 < theNArg)) {
165 bShared = (Draw::Atoi(theArgVal[i+1]) == 1);
170 Standard_Integer iErr = BOPAlgo_Tools::EdgesToWires(anEdges, aWires, bShared, anAngTol);
172 theDI << "Unable to build wires from given edges\n";
177 Standard_Boolean bDone = BOPAlgo_Tools::WiresToFaces(aWires, aFaces, anAngTol);
179 theDI << "Unable to build faces from wires\n";
183 DBRep::Set(theArgVal[1], aFaces);