0023024: Update headers of OCCT files
[occt.git] / src / BOPTest / BOPTest_WSplitCommands.cxx
CommitLineData
b311480e 1// Created on: 2000-03-16
2// Created by: Peter KURNEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOPTest.ixx>
23
24#include <stdio.h>
25
26#include <BOPTest_DrawableShape.hxx>
27
28#include <DBRep.hxx>
29#include <DBRep_DrawableShape.hxx>
30
31#include <Draw.hxx>
32#include <Draw_Color.hxx>
33
34#include <TCollection_AsciiString.hxx>
35
36#include <TopoDS.hxx>
37#include <TopoDS_Shape.hxx>
38#include <TopoDS_Face.hxx>
39#include <TopoDS_Wire.hxx>
40#include <TopAbs_ShapeEnum.hxx>
41
42#include <BOP_WireSplitter.hxx>
43
44#include <BRep_Builder.hxx>
45#include <TopoDS_Compound.hxx>
46
47#include <TopoDS_Shell.hxx>
48#include <BOP_ShellSplitter.hxx>
49
50#include <BOPTColStd_ListOfListOfShape.hxx>
51#include <BOPTColStd_ListIteratorOfListOfListOfShape.hxx>
52
53#include <TopTools_ListOfShape.hxx>
54#include <TopTools_ListIteratorOfListOfShape.hxx>
55
56
57
58
59static Standard_Integer bwsplit (Draw_Interpretor&, Standard_Integer, const char** );
60static Standard_Integer bssplit (Draw_Interpretor&, Standard_Integer, const char** );
61
62
63//=======================================================================
64//function : WSplitCommands
65//purpose :
66//=======================================================================
67 void BOPTest::WSplitCommands(Draw_Interpretor& theCommands)
68{
69 static Standard_Boolean done = Standard_False;
70 if (done)
71 return;
72
73 done = Standard_True;
74 // Chapter's name
75 const char* g = "CCR commands";
76
77 theCommands.Add("bwsplit" , "Use bwsplit> Face" , __FILE__, bwsplit , g);
78 theCommands.Add("bssplit" , "Use bssplit> Shell" , __FILE__, bssplit , g);
79}
80
81//=======================================================================
82//function : bssplit
83//purpose :
84//=======================================================================
85Standard_Integer bssplit (Draw_Interpretor& di,
86 Standard_Integer n,
87 const char** a)
88{
89 if (n!=2) {
90 di << " Use bssplit> Shell\n";
91 return 1;
92 }
93
94 TopoDS_Shape S = DBRep::Get(a[1]);
95
96 if (S.IsNull()) {
97 di << " Null shape is not allowed \n";
98 return 1;
99 }
100
101 Standard_Boolean anIsDone, anIsNothingToDo ;
102
103 TopAbs_ShapeEnum aT;
104 aT=S.ShapeType();
105 if (aT!=TopAbs_SHELL) {
106 di << " Shape Type must be SHELL\n";
107 return 1;
108 }
109
110 const TopoDS_Shell& aSh = TopoDS::Shell(S);
111
112 BOP_ShellSplitter aShellSplitter;
113 aShellSplitter.SetShell(aSh);
114 aShellSplitter.DoWithShell ();
115 anIsDone=aShellSplitter.IsDone();
116 di << " aShellSplitter.IsDone=" << (Standard_Integer) anIsDone << "\n";
117
118 anIsNothingToDo=aShellSplitter.IsNothingToDo();
119 di << " IsNothingToDo=" << (Standard_Integer) anIsNothingToDo << "\n";
120
121 if (!anIsDone) {
122 return 0;
123 }
124 if (anIsNothingToDo) {
125 return 0;
126 }
127 //
128 Standard_Integer i=1;
129 BRep_Builder BB;
130 const BOPTColStd_ListOfListOfShape& aSSS=aShellSplitter.Shapes();
131 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
132 for (; aWireIt.More(); aWireIt.Next(), ++i) {
133 TopoDS_Compound aCompound;
134 BB.MakeCompound(aCompound);
135
136 const TopTools_ListOfShape& aListEd=aWireIt.Value();
137
138 TopTools_ListIteratorOfListOfShape anIt(aListEd);
139 for (; anIt.More(); anIt.Next()) {
140 const TopoDS_Shape& aE=anIt.Value();
141 BB.Add(aCompound, aE);
142 }
143 TCollection_AsciiString aName(a[1]), aDef("_"), anI(i), aRName;
144 aRName=aName;
145 aRName=aRName+aDef;
146 aRName=aRName+anI;
147
148 DBRep::Set (aRName.ToCString(), aCompound);
149 di << aRName.ToCString() << "\n";
150 }
151
152 return 0;
153}
154
155//=======================================================================
156//function : bwsplit
157//purpose :
158//=======================================================================
159Standard_Integer bwsplit (Draw_Interpretor& di,
160 Standard_Integer n,
161 const char** a)
162{
163 if (n!=2) {
164 di << " Use bwsplit> Face\n";
165 return 1;
166 }
167
168 TopoDS_Shape S = DBRep::Get(a[1]);
169
170 if (S.IsNull()) {
171 di << " Null shape is not allowed \n";
172 return 1;
173 }
174
175 Standard_Boolean anIsDone, anIsNothingToDo ;
176
177 TopAbs_ShapeEnum aT;
178 aT=S.ShapeType();
179 if (aT!=TopAbs_FACE) {
180 di << " Shape Type must be FACE\n";
181 return 1;
182 }
183
184 const TopoDS_Face& aF = TopoDS::Face(S);
185
186 BOP_WireSplitter aWireSplitter;
187 aWireSplitter.SetFace(aF);
188 aWireSplitter.DoWithFace ();
189 anIsDone=aWireSplitter.IsDone();
190 di << " aWireSplitter.IsDone=" << (Standard_Integer) anIsDone << "\n";
191
192 anIsNothingToDo=aWireSplitter.IsNothingToDo();
193 di << " IsNothingToDo=" << (Standard_Integer) anIsNothingToDo << "\n";
194
195 if (!anIsDone) {
196 return 0;
197 }
198 if (anIsNothingToDo) {
199 return 0;
200 }
201 //
202 Standard_Integer i=1;
203 BRep_Builder BB;
204 const BOPTColStd_ListOfListOfShape& aSSS=aWireSplitter.Shapes();
205 BOPTColStd_ListIteratorOfListOfListOfShape aWireIt(aSSS);
206 for (; aWireIt.More(); aWireIt.Next(), ++i) {
207 TopoDS_Compound aCompound;
208 BB.MakeCompound(aCompound);
209
210 const TopTools_ListOfShape& aListEd=aWireIt.Value();
211
212 TopTools_ListIteratorOfListOfShape anIt(aListEd);
213 for (; anIt.More(); anIt.Next()) {
214 const TopoDS_Shape& aE=anIt.Value();
215 BB.Add(aCompound, aE);
216 }
217 TCollection_AsciiString aName(a[1]), aDef("_"), anI(i), aRName;
218 aRName=aName;
219 aRName=aRName+aDef;
220 aRName=aRName+anI;
221
222 DBRep::Set (aRName.ToCString(), aCompound);
223 di << aRName.ToCString() << "\n";
224 }
225 return 0;
226}
227
228