1 // Copyright (C) 2007-2008 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
22 #include <Standard_Stream.hxx>
24 #include "GEOM_IBooleanOperations_i.hh"
26 #include "utilities.h"
29 #include "GEOM_Engine.hxx"
30 #include "GEOM_Object.hxx"
32 #include <TColStd_HArray1OfInteger.hxx>
34 //=============================================================================
38 //=============================================================================
39 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
40 GEOM::GEOM_Gen_ptr theEngine,
41 ::GEOMImpl_IBooleanOperations* theImpl)
42 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
44 MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
47 //=============================================================================
51 //=============================================================================
52 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
54 MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
58 //=============================================================================
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
64 (GEOM::GEOM_Object_ptr theShape1,
65 GEOM::GEOM_Object_ptr theShape2,
68 GEOM::GEOM_Object_var aGEOMObject;
71 GetOperations()->SetNotDone();
73 //Get the reference shapes
74 Handle(GEOM_Object) aSh1 = GetObjectImpl(theShape1);
75 Handle(GEOM_Object) aSh2 = GetObjectImpl(theShape2);
77 if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
80 Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
81 if (!GetOperations()->IsDone() || anObject.IsNull())
82 return aGEOMObject._retn();
84 return GetObject(anObject);
87 //=============================================================================
91 //=============================================================================
92 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
93 (const GEOM::ListOfGO& theShapes,
94 const GEOM::ListOfGO& theTools,
95 const GEOM::ListOfGO& theKeepIns,
96 const GEOM::ListOfGO& theRemoveIns,
97 CORBA::Short theLimit,
98 CORBA::Boolean theRemoveWebs,
99 const GEOM::ListOfLong& theMaterials,
100 CORBA::Short theKeepNonlimitShapes)
102 GEOM::GEOM_Object_var aGEOMObject;
104 //Set a not done flag
105 GetOperations()->SetNotDone();
108 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
109 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
110 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
111 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
112 Handle(TColStd_HArray1OfInteger) aMaterials;
115 aLen = theShapes.length();
116 for (ind = 0; ind < aLen; ind++) {
117 Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
118 if (aSh.IsNull()) return aGEOMObject._retn();
119 aShapes->Append(aSh);
123 aLen = theTools.length();
124 for (ind = 0; ind < aLen; ind++) {
125 Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
126 if (aSh.IsNull()) return aGEOMObject._retn();
130 //Get the keep inside shapes
131 aLen = theKeepIns.length();
132 for (ind = 0; ind < aLen; ind++) {
133 Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
134 if (aSh.IsNull()) return aGEOMObject._retn();
135 aKeepIns->Append(aSh);
138 //Get the remove inside shapes
139 aLen = theRemoveIns.length();
140 for (ind = 0; ind < aLen; ind++) {
141 Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
142 if (aSh.IsNull()) return aGEOMObject._retn();
143 aRemIns->Append(aSh);
147 aLen = theMaterials.length();
149 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
150 for (ind = 0; ind < aLen; ind++) {
151 aMaterials->SetValue(ind+1, theMaterials[ind]);
156 Handle(GEOM_Object) anObject =
157 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
158 theLimit, theRemoveWebs, aMaterials,
159 theKeepNonlimitShapes,
160 /*PerformSelfIntersections*/Standard_True);
161 if (!GetOperations()->IsDone() || anObject.IsNull())
162 return aGEOMObject._retn();
164 return GetObject(anObject);
167 //=============================================================================
169 * MakePartitionNonSelfIntersectedShape
171 //=============================================================================
172 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
173 (const GEOM::ListOfGO& theShapes,
174 const GEOM::ListOfGO& theTools,
175 const GEOM::ListOfGO& theKeepIns,
176 const GEOM::ListOfGO& theRemoveIns,
177 CORBA::Short theLimit,
178 CORBA::Boolean theRemoveWebs,
179 const GEOM::ListOfLong& theMaterials,
180 CORBA::Short theKeepNonlimitShapes)
182 GEOM::GEOM_Object_var aGEOMObject;
184 //Set a not done flag
185 GetOperations()->SetNotDone();
188 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
189 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
190 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
191 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
192 Handle(TColStd_HArray1OfInteger) aMaterials;
195 aLen = theShapes.length();
196 for (ind = 0; ind < aLen; ind++) {
197 Handle(GEOM_Object) aSh = GetObjectImpl(theShapes[ind]);
198 if (aSh.IsNull()) return aGEOMObject._retn();
199 aShapes->Append(aSh);
203 aLen = theTools.length();
204 for (ind = 0; ind < aLen; ind++) {
205 Handle(GEOM_Object) aSh = GetObjectImpl(theTools[ind]);
206 if (aSh.IsNull()) return aGEOMObject._retn();
210 //Get the keep inside shapes
211 aLen = theKeepIns.length();
212 for (ind = 0; ind < aLen; ind++) {
213 Handle(GEOM_Object) aSh = GetObjectImpl(theKeepIns[ind]);
214 if (aSh.IsNull()) return aGEOMObject._retn();
215 aKeepIns->Append(aSh);
218 //Get the remove inside shapes
219 aLen = theRemoveIns.length();
220 for (ind = 0; ind < aLen; ind++) {
221 Handle(GEOM_Object) aSh = GetObjectImpl(theRemoveIns[ind]);
222 if (aSh.IsNull()) return aGEOMObject._retn();
223 aRemIns->Append(aSh);
227 aLen = theMaterials.length();
229 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
230 for (ind = 0; ind < aLen; ind++) {
231 aMaterials->SetValue(ind+1, theMaterials[ind]);
236 Handle(GEOM_Object) anObject =
237 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
238 theLimit, theRemoveWebs, aMaterials,
239 theKeepNonlimitShapes,
240 /*PerformSelfIntersections*/Standard_False);
241 if (!GetOperations()->IsDone() || anObject.IsNull())
242 return aGEOMObject._retn();
244 return GetObject(anObject);
247 //=============================================================================
251 //=============================================================================
252 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
253 (GEOM::GEOM_Object_ptr theShape,
254 GEOM::GEOM_Object_ptr thePlane)
256 GEOM::GEOM_Object_var aGEOMObject;
258 //Set a not done flag
259 GetOperations()->SetNotDone();
261 //Get the reference shapes
262 Handle(GEOM_Object) aSh = GetObjectImpl(theShape);
263 Handle(GEOM_Object) aPl = GetObjectImpl(thePlane);
265 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
267 // Make Half Partition
268 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
269 if (!GetOperations()->IsDone() || anObject.IsNull())
270 return aGEOMObject._retn();
272 return GetObject(anObject);