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 CORBA::String_var entry=theShape1->GetEntry();
76 Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
77 (theShape1->GetStudyID(), entry);
78 entry=theShape2->GetEntry();
79 Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
80 (theShape2->GetStudyID(), entry);
82 if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
85 Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
86 if (!GetOperations()->IsDone() || anObject.IsNull())
87 return aGEOMObject._retn();
89 return GetObject(anObject);
92 //=============================================================================
96 //=============================================================================
97 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
98 (const GEOM::ListOfGO& theShapes,
99 const GEOM::ListOfGO& theTools,
100 const GEOM::ListOfGO& theKeepIns,
101 const GEOM::ListOfGO& theRemoveIns,
102 CORBA::Short theLimit,
103 CORBA::Boolean theRemoveWebs,
104 const GEOM::ListOfLong& theMaterials,
105 CORBA::Short theKeepNonlimitShapes)
107 GEOM::GEOM_Object_var aGEOMObject;
109 //Set a not done flag
110 GetOperations()->SetNotDone();
113 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
114 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
115 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
116 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
117 Handle(TColStd_HArray1OfInteger) aMaterials;
120 aLen = theShapes.length();
121 for (ind = 0; ind < aLen; ind++) {
122 if (theShapes[ind] == NULL) return aGEOMObject._retn();
123 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
124 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
125 if (aSh.IsNull()) return aGEOMObject._retn();
126 aShapes->Append(aSh);
130 aLen = theTools.length();
131 for (ind = 0; ind < aLen; ind++) {
132 if (theTools[ind] == NULL) return aGEOMObject._retn();
133 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
134 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
135 if (aSh.IsNull()) return aGEOMObject._retn();
139 //Get the keep inside shapes
140 aLen = theKeepIns.length();
141 for (ind = 0; ind < aLen; ind++) {
142 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
143 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
144 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
145 if (aSh.IsNull()) return aGEOMObject._retn();
146 aKeepIns->Append(aSh);
149 //Get the remove inside shapes
150 aLen = theRemoveIns.length();
151 for (ind = 0; ind < aLen; ind++) {
152 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
153 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
154 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
155 if (aSh.IsNull()) return aGEOMObject._retn();
156 aRemIns->Append(aSh);
160 aLen = theMaterials.length();
162 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
163 for (ind = 0; ind < aLen; ind++) {
164 aMaterials->SetValue(ind+1, theMaterials[ind]);
169 Handle(GEOM_Object) anObject =
170 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
171 theLimit, theRemoveWebs, aMaterials,
172 theKeepNonlimitShapes,
173 /*PerformSelfIntersections*/Standard_True);
174 if (!GetOperations()->IsDone() || anObject.IsNull())
175 return aGEOMObject._retn();
177 return GetObject(anObject);
180 //=============================================================================
182 * MakePartitionNonSelfIntersectedShape
184 //=============================================================================
185 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
186 (const GEOM::ListOfGO& theShapes,
187 const GEOM::ListOfGO& theTools,
188 const GEOM::ListOfGO& theKeepIns,
189 const GEOM::ListOfGO& theRemoveIns,
190 CORBA::Short theLimit,
191 CORBA::Boolean theRemoveWebs,
192 const GEOM::ListOfLong& theMaterials,
193 CORBA::Short theKeepNonlimitShapes)
195 GEOM::GEOM_Object_var aGEOMObject;
197 //Set a not done flag
198 GetOperations()->SetNotDone();
201 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
202 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
203 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
204 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
205 Handle(TColStd_HArray1OfInteger) aMaterials;
208 aLen = theShapes.length();
209 for (ind = 0; ind < aLen; ind++) {
210 if (theShapes[ind] == NULL) return aGEOMObject._retn();
211 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
212 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
213 if (aSh.IsNull()) return aGEOMObject._retn();
214 aShapes->Append(aSh);
218 aLen = theTools.length();
219 for (ind = 0; ind < aLen; ind++) {
220 if (theTools[ind] == NULL) return aGEOMObject._retn();
221 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
222 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
223 if (aSh.IsNull()) return aGEOMObject._retn();
227 //Get the keep inside shapes
228 aLen = theKeepIns.length();
229 for (ind = 0; ind < aLen; ind++) {
230 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
231 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
232 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
233 if (aSh.IsNull()) return aGEOMObject._retn();
234 aKeepIns->Append(aSh);
237 //Get the remove inside shapes
238 aLen = theRemoveIns.length();
239 for (ind = 0; ind < aLen; ind++) {
240 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
241 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
242 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
243 if (aSh.IsNull()) return aGEOMObject._retn();
244 aRemIns->Append(aSh);
248 aLen = theMaterials.length();
250 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
251 for (ind = 0; ind < aLen; ind++) {
252 aMaterials->SetValue(ind+1, theMaterials[ind]);
257 Handle(GEOM_Object) anObject =
258 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
259 theLimit, theRemoveWebs, aMaterials,
260 theKeepNonlimitShapes,
261 /*PerformSelfIntersections*/Standard_False);
262 if (!GetOperations()->IsDone() || anObject.IsNull())
263 return aGEOMObject._retn();
265 return GetObject(anObject);
268 //=============================================================================
272 //=============================================================================
273 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
274 (GEOM::GEOM_Object_ptr theShape,
275 GEOM::GEOM_Object_ptr thePlane)
277 GEOM::GEOM_Object_var aGEOMObject;
279 //Set a not done flag
280 GetOperations()->SetNotDone();
282 if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
284 //Get the reference shapes
285 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
286 (theShape->GetStudyID(), theShape->GetEntry());
287 Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
288 (thePlane->GetStudyID(), thePlane->GetEntry());
290 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
292 // Make Half Partition
293 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
294 if (!GetOperations()->IsDone() || anObject.IsNull())
295 return aGEOMObject._retn();
297 return GetObject(anObject);