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,
103 CORBA::Short theKeepNonlimitShapes)
105 GEOM::GEOM_Object_var aGEOMObject;
107 //Set a not done flag
108 GetOperations()->SetNotDone();
111 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
112 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
113 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
114 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
115 Handle(TColStd_HArray1OfInteger) aMaterials;
118 aLen = theShapes.length();
119 for (ind = 0; ind < aLen; ind++) {
120 if (theShapes[ind] == NULL) return aGEOMObject._retn();
121 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
122 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
123 if (aSh.IsNull()) return aGEOMObject._retn();
124 aShapes->Append(aSh);
128 aLen = theTools.length();
129 for (ind = 0; ind < aLen; ind++) {
130 if (theTools[ind] == NULL) return aGEOMObject._retn();
131 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
132 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
133 if (aSh.IsNull()) return aGEOMObject._retn();
137 //Get the keep inside shapes
138 aLen = theKeepIns.length();
139 for (ind = 0; ind < aLen; ind++) {
140 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
141 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
142 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
143 if (aSh.IsNull()) return aGEOMObject._retn();
144 aKeepIns->Append(aSh);
147 //Get the remove inside shapes
148 aLen = theRemoveIns.length();
149 for (ind = 0; ind < aLen; ind++) {
150 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
151 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
152 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
153 if (aSh.IsNull()) return aGEOMObject._retn();
154 aRemIns->Append(aSh);
158 aLen = theMaterials.length();
160 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
161 for (ind = 0; ind < aLen; ind++) {
162 aMaterials->SetValue(ind+1, theMaterials[ind]);
167 Handle(GEOM_Object) anObject =
168 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
169 theLimit, theRemoveWebs, aMaterials,
170 theKeepNonlimitShapes,
171 /*PerformSelfIntersections*/Standard_True);
172 if (!GetOperations()->IsDone() || anObject.IsNull())
173 return aGEOMObject._retn();
175 return GetObject(anObject);
178 //=============================================================================
180 * MakePartitionNonSelfIntersectedShape
182 //=============================================================================
183 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartitionNonSelfIntersectedShape
184 (const GEOM::ListOfGO& theShapes,
185 const GEOM::ListOfGO& theTools,
186 const GEOM::ListOfGO& theKeepIns,
187 const GEOM::ListOfGO& theRemoveIns,
188 CORBA::Short theLimit,
189 CORBA::Boolean theRemoveWebs,
190 const GEOM::ListOfLong& theMaterials,
191 CORBA::Short theKeepNonlimitShapes)
193 GEOM::GEOM_Object_var aGEOMObject;
195 //Set a not done flag
196 GetOperations()->SetNotDone();
199 Handle(TColStd_HSequenceOfTransient) aShapes = new TColStd_HSequenceOfTransient;
200 Handle(TColStd_HSequenceOfTransient) aTools = new TColStd_HSequenceOfTransient;
201 Handle(TColStd_HSequenceOfTransient) aKeepIns = new TColStd_HSequenceOfTransient;
202 Handle(TColStd_HSequenceOfTransient) aRemIns = new TColStd_HSequenceOfTransient;
203 Handle(TColStd_HArray1OfInteger) aMaterials;
206 aLen = theShapes.length();
207 for (ind = 0; ind < aLen; ind++) {
208 if (theShapes[ind] == NULL) return aGEOMObject._retn();
209 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
210 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
211 if (aSh.IsNull()) return aGEOMObject._retn();
212 aShapes->Append(aSh);
216 aLen = theTools.length();
217 for (ind = 0; ind < aLen; ind++) {
218 if (theTools[ind] == NULL) return aGEOMObject._retn();
219 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
220 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
221 if (aSh.IsNull()) return aGEOMObject._retn();
225 //Get the keep inside shapes
226 aLen = theKeepIns.length();
227 for (ind = 0; ind < aLen; ind++) {
228 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
229 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
230 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
231 if (aSh.IsNull()) return aGEOMObject._retn();
232 aKeepIns->Append(aSh);
235 //Get the remove inside shapes
236 aLen = theRemoveIns.length();
237 for (ind = 0; ind < aLen; ind++) {
238 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
239 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
240 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
241 if (aSh.IsNull()) return aGEOMObject._retn();
242 aRemIns->Append(aSh);
246 aLen = theMaterials.length();
248 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
249 for (ind = 0; ind < aLen; ind++) {
250 aMaterials->SetValue(ind+1, theMaterials[ind]);
255 Handle(GEOM_Object) anObject =
256 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
257 theLimit, theRemoveWebs, aMaterials,
258 theKeepNonlimitShapes,
259 /*PerformSelfIntersections*/Standard_False);
260 if (!GetOperations()->IsDone() || anObject.IsNull())
261 return aGEOMObject._retn();
263 return GetObject(anObject);
266 //=============================================================================
270 //=============================================================================
271 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
272 (GEOM::GEOM_Object_ptr theShape,
273 GEOM::GEOM_Object_ptr thePlane)
275 GEOM::GEOM_Object_var aGEOMObject;
277 //Set a not done flag
278 GetOperations()->SetNotDone();
280 if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
282 //Get the reference shapes
283 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
284 (theShape->GetStudyID(), theShape->GetEntry());
285 Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
286 (thePlane->GetStudyID(), thePlane->GetEntry());
288 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
290 // Make Half Partition
291 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
292 if (!GetOperations()->IsDone() || anObject.IsNull())
293 return aGEOMObject._retn();
295 return GetObject(anObject);