1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include "GEOM_IBooleanOperations_i.hh"
27 #include "utilities.h"
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
33 #include <TColStd_HArray1OfInteger.hxx>
35 //=============================================================================
39 //=============================================================================
40 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
41 GEOM::GEOM_Gen_ptr theEngine,
42 ::GEOMImpl_IBooleanOperations* theImpl)
43 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
45 MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
48 //=============================================================================
52 //=============================================================================
53 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
55 MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
59 //=============================================================================
63 //=============================================================================
64 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
65 (GEOM::GEOM_Object_ptr theShape1,
66 GEOM::GEOM_Object_ptr theShape2,
69 GEOM::GEOM_Object_var aGEOMObject;
72 GetOperations()->SetNotDone();
74 //Get the reference shapes
75 Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
76 Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
78 if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
81 Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
82 if (!GetOperations()->IsDone() || anObject.IsNull())
83 return aGEOMObject._retn();
85 return GetObject(anObject);
88 //=============================================================================
92 //=============================================================================
93 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeFuseList
94 (const GEOM::ListOfGO& theShapes)
96 GEOM::GEOM_Object_var aGEOMObject;
99 GetOperations()->SetNotDone();
101 Handle(TColStd_HSequenceOfTransient) aShapes =
102 GetListOfObjectsImpl(theShapes);
104 if (aShapes.IsNull()) {
105 return aGEOMObject._retn();
109 Handle(GEOM_Object) anObject = GetOperations()->MakeFuseList(aShapes);
111 if (!GetOperations()->IsDone() || anObject.IsNull())
112 return aGEOMObject._retn();
114 return GetObject(anObject);
117 //=============================================================================
121 //=============================================================================
122 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCommonList
123 (const GEOM::ListOfGO& theShapes)
125 GEOM::GEOM_Object_var aGEOMObject;
127 //Set a not done flag
128 GetOperations()->SetNotDone();
130 Handle(TColStd_HSequenceOfTransient) aShapes =
131 GetListOfObjectsImpl(theShapes);
133 if (aShapes.IsNull()) {
134 return aGEOMObject._retn();
138 Handle(GEOM_Object) anObject = GetOperations()->MakeCommonList(aShapes);
140 if (!GetOperations()->IsDone() || anObject.IsNull())
141 return aGEOMObject._retn();
143 return GetObject(anObject);
146 //=============================================================================
150 //=============================================================================
151 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeCutList
152 (GEOM::GEOM_Object_ptr theMainShape,
153 const GEOM::ListOfGO& theShapes)
155 GEOM::GEOM_Object_var aGEOMObject;
157 //Set a not done flag
158 GetOperations()->SetNotDone();
160 Handle(GEOM_Object) aMainShape = GetObjectImpl(theMainShape);
162 if (aMainShape.IsNull()) {
163 return aGEOMObject._retn();
166 Handle(TColStd_HSequenceOfTransient) aShapes =
167 GetListOfObjectsImpl(theShapes);
169 if (aShapes.IsNull()) {
170 return aGEOMObject._retn();
174 Handle(GEOM_Object) anObject = GetOperations()->MakeCutList(aMainShape, aShapes);
176 if (!GetOperations()->IsDone() || anObject.IsNull())
177 return aGEOMObject._retn();
179 return GetObject(anObject);
182 //=============================================================================
186 //=============================================================================
187 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
188 (const GEOM::ListOfGO& theShapes,
189 const GEOM::ListOfGO& theTools,
190 const GEOM::ListOfGO& theKeepIns,
191 const GEOM::ListOfGO& theRemoveIns,
192 CORBA::Short theLimit,
193 CORBA::Boolean theRemoveWebs,
194 const GEOM::ListOfLong& theMaterials,
195 CORBA::Short theKeepNonlimitShapes)
197 GEOM::GEOM_Object_var aGEOMObject;
199 //Set a not done flag
200 GetOperations()->SetNotDone();
202 Handle(TColStd_HSequenceOfTransient) aShapes = GetListOfObjectsImpl(theShapes);
203 Handle(TColStd_HSequenceOfTransient) aTools = GetListOfObjectsImpl(theTools);
204 Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
205 Handle(TColStd_HSequenceOfTransient) aRemIns = GetListOfObjectsImpl(theRemoveIns);
206 Handle(TColStd_HArray1OfInteger) aMaterials;
208 if (aShapes.IsNull() || aTools.IsNull() ||
209 aKeepIns.IsNull() || aRemIns.IsNull()) {
210 return aGEOMObject._retn();
215 int aLen = theMaterials.length();
217 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
218 for (ind = 0; ind < aLen; ind++) {
219 aMaterials->SetValue(ind+1, theMaterials[ind]);
224 Handle(GEOM_Object) anObject =
225 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
226 theLimit, theRemoveWebs, aMaterials,
227 theKeepNonlimitShapes,
228 /*PerformSelfIntersections*/Standard_True);
229 if (!GetOperations()->IsDone() || anObject.IsNull())
230 return aGEOMObject._retn();
232 return GetObject(anObject);
235 //=============================================================================
237 * MakePartitionNonSelfIntersectedShape
239 //=============================================================================
240 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
241 (const GEOM::ListOfGO& theShapes,
242 const GEOM::ListOfGO& theTools,
243 const GEOM::ListOfGO& theKeepIns,
244 const GEOM::ListOfGO& theRemoveIns,
245 CORBA::Short theLimit,
246 CORBA::Boolean theRemoveWebs,
247 const GEOM::ListOfLong& theMaterials,
248 CORBA::Short theKeepNonlimitShapes)
250 GEOM::GEOM_Object_var aGEOMObject;
252 //Set a not done flag
253 GetOperations()->SetNotDone();
255 Handle(TColStd_HSequenceOfTransient) aShapes = GetListOfObjectsImpl(theShapes);
256 Handle(TColStd_HSequenceOfTransient) aTools = GetListOfObjectsImpl(theTools);
257 Handle(TColStd_HSequenceOfTransient) aKeepIns = GetListOfObjectsImpl(theKeepIns);
258 Handle(TColStd_HSequenceOfTransient) aRemIns = GetListOfObjectsImpl(theRemoveIns);
259 Handle(TColStd_HArray1OfInteger) aMaterials;
261 if (aShapes.IsNull() || aTools.IsNull() ||
262 aKeepIns.IsNull() || aRemIns.IsNull()) {
263 return aGEOMObject._retn();
268 int aLen = theMaterials.length();
270 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
271 for (ind = 0; ind < aLen; ind++) {
272 aMaterials->SetValue(ind+1, theMaterials[ind]);
277 Handle(GEOM_Object) anObject =
278 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
279 theLimit, theRemoveWebs, aMaterials,
280 theKeepNonlimitShapes,
281 /*PerformSelfIntersections*/Standard_False);
282 if (!GetOperations()->IsDone() || anObject.IsNull())
283 return aGEOMObject._retn();
285 return GetObject(anObject);
288 //=============================================================================
292 //=============================================================================
293 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
294 (GEOM::GEOM_Object_ptr theShape,
295 GEOM::GEOM_Object_ptr thePlane)
297 GEOM::GEOM_Object_var aGEOMObject;
299 //Set a not done flag
300 GetOperations()->SetNotDone();
302 //Get the reference shapes
303 Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
304 Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
306 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
308 // Make Half Partition
309 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
310 if (!GetOperations()->IsDone() || anObject.IsNull())
311 return aGEOMObject._retn();
313 return GetObject(anObject);