1 // Copyright (C) 2007-2010 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::MakePartition
94 (const GEOM::ListOfGO& theShapes,
95 const GEOM::ListOfGO& theTools,
96 const GEOM::ListOfGO& theKeepIns,
97 const GEOM::ListOfGO& theRemoveIns,
98 CORBA::Short theLimit,
99 CORBA::Boolean theRemoveWebs,
100 const GEOM::ListOfLong& theMaterials,
101 CORBA::Short theKeepNonlimitShapes)
103 GEOM::GEOM_Object_var aGEOMObject;
105 //Set a not done flag
106 GetOperations()->SetNotDone();
109 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
110 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
111 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
112 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
113 Handle(TColStd_HArray1OfInteger) aMaterials;
116 aLen = theShapes.length();
117 for (ind = 0; ind < aLen; ind++) {
118 Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
119 if (aSh.IsNull()) return aGEOMObject._retn();
120 aShapes->Append(aSh);
124 aLen = theTools.length();
125 for (ind = 0; ind < aLen; ind++) {
126 Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
127 if (aSh.IsNull()) return aGEOMObject._retn();
131 //Get the keep inside shapes
132 aLen = theKeepIns.length();
133 for (ind = 0; ind < aLen; ind++) {
134 Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
135 if (aSh.IsNull()) return aGEOMObject._retn();
136 aKeepIns->Append(aSh);
139 //Get the remove inside shapes
140 aLen = theRemoveIns.length();
141 for (ind = 0; ind < aLen; ind++) {
142 Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
143 if (aSh.IsNull()) return aGEOMObject._retn();
144 aRemIns->Append(aSh);
148 aLen = theMaterials.length();
150 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
151 for (ind = 0; ind < aLen; ind++) {
152 aMaterials->SetValue(ind+1, theMaterials[ind]);
157 Handle(GEOM_Object) anObject =
158 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
159 theLimit, theRemoveWebs, aMaterials,
160 theKeepNonlimitShapes,
161 /*PerformSelfIntersections*/Standard_True);
162 if (!GetOperations()->IsDone() || anObject.IsNull())
163 return aGEOMObject._retn();
165 return GetObject(anObject);
168 //=============================================================================
170 * MakePartitionNonSelfIntersectedShape
172 //=============================================================================
173 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
174 (const GEOM::ListOfGO& theShapes,
175 const GEOM::ListOfGO& theTools,
176 const GEOM::ListOfGO& theKeepIns,
177 const GEOM::ListOfGO& theRemoveIns,
178 CORBA::Short theLimit,
179 CORBA::Boolean theRemoveWebs,
180 const GEOM::ListOfLong& theMaterials,
181 CORBA::Short theKeepNonlimitShapes)
183 GEOM::GEOM_Object_var aGEOMObject;
185 //Set a not done flag
186 GetOperations()->SetNotDone();
189 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
190 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
191 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
192 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
193 Handle(TColStd_HArray1OfInteger) aMaterials;
196 aLen = theShapes.length();
197 for (ind = 0; ind < aLen; ind++) {
198 Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
199 if (aSh.IsNull()) return aGEOMObject._retn();
200 aShapes->Append(aSh);
204 aLen = theTools.length();
205 for (ind = 0; ind < aLen; ind++) {
206 Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
207 if (aSh.IsNull()) return aGEOMObject._retn();
211 //Get the keep inside shapes
212 aLen = theKeepIns.length();
213 for (ind = 0; ind < aLen; ind++) {
214 Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
215 if (aSh.IsNull()) return aGEOMObject._retn();
216 aKeepIns->Append(aSh);
219 //Get the remove inside shapes
220 aLen = theRemoveIns.length();
221 for (ind = 0; ind < aLen; ind++) {
222 Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
223 if (aSh.IsNull()) return aGEOMObject._retn();
224 aRemIns->Append(aSh);
228 aLen = theMaterials.length();
230 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
231 for (ind = 0; ind < aLen; ind++) {
232 aMaterials->SetValue(ind+1, theMaterials[ind]);
237 Handle(GEOM_Object) anObject =
238 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
239 theLimit, theRemoveWebs, aMaterials,
240 theKeepNonlimitShapes,
241 /*PerformSelfIntersections*/Standard_False);
242 if (!GetOperations()->IsDone() || anObject.IsNull())
243 return aGEOMObject._retn();
245 return GetObject(anObject);
248 //=============================================================================
252 //=============================================================================
253 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
254 (GEOM::GEOM_Object_ptr theShape,
255 GEOM::GEOM_Object_ptr thePlane)
257 GEOM::GEOM_Object_var aGEOMObject;
259 //Set a not done flag
260 GetOperations()->SetNotDone();
262 //Get the reference shapes
263 Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
264 Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
266 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
268 // Make Half Partition
269 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
270 if (!GetOperations()->IsDone() || anObject.IsNull())
271 return aGEOMObject._retn();
273 return GetObject(anObject);