1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include "GEOM_IBooleanOperations_i.hh"
25 #include "utilities.h"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 #include <TColStd_HArray1OfInteger.hxx>
33 //=============================================================================
37 //=============================================================================
38 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
39 GEOM::GEOM_Gen_ptr theEngine,
40 ::GEOMImpl_IBooleanOperations* theImpl)
41 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
43 MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
46 //=============================================================================
50 //=============================================================================
51 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
53 MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
57 //=============================================================================
61 //=============================================================================
62 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
63 (GEOM::GEOM_Object_ptr theShape1,
64 GEOM::GEOM_Object_ptr theShape2,
67 GEOM::GEOM_Object_var aGEOMObject;
70 GetOperations()->SetNotDone();
72 if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn();
74 //Get the reference shapes
75 Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
76 (theShape1->GetStudyID(), theShape1->GetEntry());
77 Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
78 (theShape2->GetStudyID(), theShape2->GetEntry());
80 if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
83 Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
84 if (!GetOperations()->IsDone() || anObject.IsNull())
85 return aGEOMObject._retn();
87 return GetObject(anObject);
90 //=============================================================================
94 //=============================================================================
95 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
96 (const GEOM::ListOfGO& theShapes,
97 const GEOM::ListOfGO& theTools,
98 const GEOM::ListOfGO& theKeepIns,
99 const GEOM::ListOfGO& theRemoveIns,
100 CORBA::Short theLimit,
101 CORBA::Boolean theRemoveWebs,
102 const GEOM::ListOfLong& theMaterials)
104 GEOM::GEOM_Object_var aGEOMObject;
106 //Set a not done flag
107 GetOperations()->SetNotDone();
110 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
111 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
112 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
113 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
114 Handle(TColStd_HArray1OfInteger) aMaterials;
117 aLen = theShapes.length();
118 for (ind = 0; ind < aLen; ind++) {
119 if (theShapes[ind] == NULL) return aGEOMObject._retn();
120 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
121 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
122 if (aSh.IsNull()) return aGEOMObject._retn();
123 aShapes->Append(aSh);
127 aLen = theTools.length();
128 for (ind = 0; ind < aLen; ind++) {
129 if (theTools[ind] == NULL) return aGEOMObject._retn();
130 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
131 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
132 if (aSh.IsNull()) return aGEOMObject._retn();
136 //Get the keep inside shapes
137 aLen = theKeepIns.length();
138 for (ind = 0; ind < aLen; ind++) {
139 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
140 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
141 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
142 if (aSh.IsNull()) return aGEOMObject._retn();
143 aKeepIns->Append(aSh);
146 //Get the remove inside shapes
147 aLen = theRemoveIns.length();
148 for (ind = 0; ind < aLen; ind++) {
149 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
150 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
151 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
152 if (aSh.IsNull()) return aGEOMObject._retn();
153 aRemIns->Append(aSh);
157 aLen = theMaterials.length();
159 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
160 for (ind = 0; ind < aLen; ind++) {
161 aMaterials->SetValue(ind+1, theMaterials[ind]);
166 Handle(GEOM_Object) anObject =
167 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
168 theLimit, theRemoveWebs, aMaterials,
169 /*PerformSelfIntersections*/Standard_True);
170 if (!GetOperations()->IsDone() || anObject.IsNull())
171 return aGEOMObject._retn();
173 return GetObject(anObject);
176 //=============================================================================
178 * MakePartitionNonSelfIntersectedShape
180 //=============================================================================
181 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
182 (const GEOM::ListOfGO& theShapes,
183 const GEOM::ListOfGO& theTools,
184 const GEOM::ListOfGO& theKeepIns,
185 const GEOM::ListOfGO& theRemoveIns,
186 CORBA::Short theLimit,
187 CORBA::Boolean theRemoveWebs,
188 const GEOM::ListOfLong& theMaterials)
190 GEOM::GEOM_Object_var aGEOMObject;
192 //Set a not done flag
193 GetOperations()->SetNotDone();
196 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
197 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
198 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
199 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
200 Handle(TColStd_HArray1OfInteger) aMaterials;
203 aLen = theShapes.length();
204 for (ind = 0; ind < aLen; ind++) {
205 if (theShapes[ind] == NULL) return aGEOMObject._retn();
206 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
207 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
208 if (aSh.IsNull()) return aGEOMObject._retn();
209 aShapes->Append(aSh);
213 aLen = theTools.length();
214 for (ind = 0; ind < aLen; ind++) {
215 if (theTools[ind] == NULL) return aGEOMObject._retn();
216 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
217 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
218 if (aSh.IsNull()) return aGEOMObject._retn();
222 //Get the keep inside shapes
223 aLen = theKeepIns.length();
224 for (ind = 0; ind < aLen; ind++) {
225 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
226 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
227 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
228 if (aSh.IsNull()) return aGEOMObject._retn();
229 aKeepIns->Append(aSh);
232 //Get the remove inside shapes
233 aLen = theRemoveIns.length();
234 for (ind = 0; ind < aLen; ind++) {
235 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
236 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
237 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
238 if (aSh.IsNull()) return aGEOMObject._retn();
239 aRemIns->Append(aSh);
243 aLen = theMaterials.length();
245 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
246 for (ind = 0; ind < aLen; ind++) {
247 aMaterials->SetValue(ind+1, theMaterials[ind]);
252 Handle(GEOM_Object) anObject =
253 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
254 theLimit, theRemoveWebs, aMaterials,
255 /*PerformSelfIntersections*/Standard_False);
256 if (!GetOperations()->IsDone() || anObject.IsNull())
257 return aGEOMObject._retn();
259 return GetObject(anObject);
262 //=============================================================================
266 //=============================================================================
267 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
268 (GEOM::GEOM_Object_ptr theShape,
269 GEOM::GEOM_Object_ptr thePlane)
271 GEOM::GEOM_Object_var aGEOMObject;
273 //Set a not done flag
274 GetOperations()->SetNotDone();
276 if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
278 //Get the reference shapes
279 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
280 (theShape->GetStudyID(), theShape->GetEntry());
281 Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
282 (thePlane->GetStudyID(), thePlane->GetEntry());
284 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
286 // Make Half Partition
287 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
288 if (!GetOperations()->IsDone() || anObject.IsNull())
289 return aGEOMObject._retn();
291 return GetObject(anObject);