Warnings on vc14 were eliminated
[occt.git] / src / BOPTest / BOPTest_HistoryCommands.cxx
CommitLineData
a493b4a1 1// Created by: Eugeny MALTCHIKOV
2// Copyright (c) 2015 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
8a755387 15#include <BOPTest.hxx>
a493b4a1 16//
17#include <Draw.hxx>
18#include <DBRep.hxx>
19//
20#include <BRep_Builder.hxx>
21//
22#include <TopoDS_Compound.hxx>
23//
24#include <BOPAlgo_Builder.hxx>
25//
26#include <TopTools_ListOfShape.hxx>
27#include <TopTools_ListIteratorOfListOfShape.hxx>
28//
29#include <BOPTest_DrawableShape.hxx>
30#include <BOPTest_Objects.hxx>
31
32//
33static Standard_Integer bmodified (Draw_Interpretor&, Standard_Integer, const char**);
34static Standard_Integer bgenerated (Draw_Interpretor&, Standard_Integer, const char**);
35static Standard_Integer bisdeleted (Draw_Interpretor&, Standard_Integer, const char**);
36
37//=======================================================================
38//function : HistoryCommands
39//purpose :
40//=======================================================================
41void BOPTest::HistoryCommands(Draw_Interpretor& theCommands)
42{
43 static Standard_Boolean done = Standard_False;
44 if (done) return;
45 done = Standard_True;
46 // Chapter's name
47 const char* g = "BOPTest commands";
48 // Commands
49 theCommands.Add("bmodified" , "Use: bmodified rc shape", __FILE__, bmodified , g);
50 theCommands.Add("bgenerated", "Use: bgenerated rc shape", __FILE__, bgenerated, g);
51 theCommands.Add("bisdeleted", "Use: bisdeleted shape" , __FILE__, bisdeleted, g);
52}
53
54//=======================================================================
55//function : bmodified
56//purpose :
57//=======================================================================
58Standard_Integer bmodified(Draw_Interpretor& di,
59 Standard_Integer n,
60 const char** a)
61{
62 if (n < 3) {
63 di << "Use: bmodified rc shape\n";
64 return 1;
65 }
66 //
67 TopoDS_Shape aS = DBRep::Get(a[2]);
68 if (aS.IsNull()) {
69 di << "Null shape\n";
70 return 1;
71 }
72 //
73 TopAbs_ShapeEnum aType = aS.ShapeType();
74 if (!(aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
75 aType==TopAbs_FACE || aType==TopAbs_SOLID)) {
76 di << "The shape must be one of the following types: VERTEX, EDGE, FACE or SOLID\n";
77 return 1;
78 }
79 //
80 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
81 const TopTools_ListOfShape& aLS = aBuilder.Modified(aS);
82 //
83 if (aLS.IsEmpty()) {
84 di << "The shape has not been modified\n";
85 return 0;
86 }
87 //
88 BRep_Builder aBB;
89 TopoDS_Compound aRes;
90 //
91 aBB.MakeCompound(aRes);
92 TopTools_ListIteratorOfListOfShape aIt(aLS);
93 for (; aIt.More(); aIt.Next()) {
51740958 94 const TopoDS_Shape& aShape = aIt.Value();
95 aBB.Add(aRes, aShape);
a493b4a1 96 }
97 //
98 DBRep::Set(a[1], aRes);
99 //
100 return 0;
101}
102
103//=======================================================================
104//function : bgenerated
105//purpose :
106//=======================================================================
107Standard_Integer bgenerated(Draw_Interpretor& di,
108 Standard_Integer n,
109 const char** a)
110{
111 if (n < 3) {
112 di << "Use: bgenerated rc shape\n";
113 return 1;
114 }
115 //
116 TopoDS_Shape aS = DBRep::Get(a[2]);
117 if (aS.IsNull()) {
118 di << "Null shape\n";
119 return 1;
120 }
121 //
122 TopAbs_ShapeEnum aType = aS.ShapeType();
123 if (!(aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
124 aType==TopAbs_FACE || aType==TopAbs_SOLID)) {
125 di << "The shape must be one of the following types: VERTEX, EDGE, FACE or SOLID\n";
126 return 1;
127 }
128 //
129 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
130 const TopTools_ListOfShape& aLS = aBuilder.Generated(aS);
131 //
132 if (aLS.IsEmpty()) {
133 di << "No shapes were generated from the shape\n";
134 return 0;
135 }
136 //
137 BRep_Builder aBB;
138 TopoDS_Compound aRes;
139 //
140 aBB.MakeCompound(aRes);
141 TopTools_ListIteratorOfListOfShape aIt(aLS);
142 for (; aIt.More(); aIt.Next()) {
51740958 143 const TopoDS_Shape& aShape = aIt.Value();
144 aBB.Add(aRes, aShape);
a493b4a1 145 }
146 //
147 DBRep::Set(a[1], aRes);
148 //
149 return 0;
150}
151
152//=======================================================================
153//function : bisdeleted
154//purpose :
155//=======================================================================
156Standard_Integer bisdeleted(Draw_Interpretor& di,
157 Standard_Integer n,
158 const char** a)
159{
160 if (n < 2) {
161 di << "Use: bisdeleted shape\n";
162 return 1;
163 }
164 //
165 TopoDS_Shape aS = DBRep::Get(a[1]);
166 if (aS.IsNull()) {
167 di << "Null shape\n";
168 return 1;
169 }
170 //
171 TopAbs_ShapeEnum aType = aS.ShapeType();
172 if (!(aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
173 aType==TopAbs_FACE || aType==TopAbs_SOLID)) {
174 di << "The shape must be one of the following types: VERTEX, EDGE, FACE or SOLID\n";
175 return 1;
176 }
177 //
178 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
179 Standard_Boolean isDeleted = aBuilder.IsDeleted(aS);
180 //
181 di << (isDeleted ? "Deleted" : "Not deleted") << "\n";
182 //
183 return 0;
184}