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
20 #include <Standard_Stream.hxx>
22 #include "GEOM_IBooleanOperations_i.hh"
24 #include "utilities.h"
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
30 #include <TColStd_HArray1OfInteger.hxx>
32 //=============================================================================
36 //=============================================================================
37 GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i (PortableServer::POA_ptr thePOA,
38 GEOM::GEOM_Gen_ptr theEngine,
39 ::GEOMImpl_IBooleanOperations* theImpl)
40 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
42 MESSAGE("GEOM_IBooleanOperations_i::GEOM_IBooleanOperations_i");
45 //=============================================================================
49 //=============================================================================
50 GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i()
52 MESSAGE("GEOM_IBooleanOperations_i::~GEOM_IBooleanOperations_i");
56 //=============================================================================
60 //=============================================================================
61 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeBoolean
62 (GEOM::GEOM_Object_ptr theShape1,
63 GEOM::GEOM_Object_ptr theShape2,
66 GEOM::GEOM_Object_var aGEOMObject;
69 GetOperations()->SetNotDone();
71 if (theShape1 == NULL || theShape2 == NULL) return aGEOMObject._retn();
73 //Get the reference shapes
74 Handle(GEOM_Object) aSh1 = GetOperations()->GetEngine()->GetObject
75 (theShape1->GetStudyID(), theShape1->GetEntry());
76 Handle(GEOM_Object) aSh2 = GetOperations()->GetEngine()->GetObject
77 (theShape2->GetStudyID(), theShape2->GetEntry());
79 if (aSh1.IsNull() || aSh2.IsNull()) return aGEOMObject._retn();
82 Handle(GEOM_Object) anObject = GetOperations()->MakeBoolean(aSh1, aSh2, theOp);
83 if (!GetOperations()->IsDone() || anObject.IsNull())
84 return aGEOMObject._retn();
86 return GetObject(anObject);
89 //=============================================================================
93 //=============================================================================
94 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakePartition
95 (const GEOM::ListOfGO& theShapes,
96 const GEOM::ListOfGO& theTools,
97 const GEOM::ListOfGO& theKeepIns,
98 const GEOM::ListOfGO& theRemoveIns,
99 const CORBA::Short theLimit,
100 const CORBA::Boolean theRemoveWebs,
101 const GEOM::ListOfLong& theMaterials)
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 if (theShapes[ind] == NULL) return aGEOMObject._retn();
119 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
120 (theShapes[ind]->GetStudyID(), theShapes[ind]->GetEntry());
121 if (aSh.IsNull()) return aGEOMObject._retn();
122 aShapes->Append(aSh);
126 aLen = theTools.length();
127 for (ind = 0; ind < aLen; ind++) {
128 if (theTools[ind] == NULL) return aGEOMObject._retn();
129 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
130 (theTools[ind]->GetStudyID(), theTools[ind]->GetEntry());
131 if (aSh.IsNull()) return aGEOMObject._retn();
135 //Get the keep inside shapes
136 aLen = theKeepIns.length();
137 for (ind = 0; ind < aLen; ind++) {
138 if (theKeepIns[ind] == NULL) return aGEOMObject._retn();
139 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
140 (theKeepIns[ind]->GetStudyID(), theKeepIns[ind]->GetEntry());
141 if (aSh.IsNull()) return aGEOMObject._retn();
142 aKeepIns->Append(aSh);
145 //Get the remove inside shapes
146 aLen = theRemoveIns.length();
147 for (ind = 0; ind < aLen; ind++) {
148 if (theRemoveIns[ind] == NULL) return aGEOMObject._retn();
149 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
150 (theRemoveIns[ind]->GetStudyID(), theRemoveIns[ind]->GetEntry());
151 if (aSh.IsNull()) return aGEOMObject._retn();
152 aRemIns->Append(aSh);
156 aLen = theMaterials.length();
158 aMaterials = new TColStd_HArray1OfInteger (1, aLen);
159 for (ind = 0; ind < aLen; ind++) {
160 aMaterials->SetValue(ind+1, theMaterials[ind]);
165 Handle(GEOM_Object) anObject =
166 GetOperations()->MakePartition(aShapes, aTools, aKeepIns, aRemIns,
167 theLimit, theRemoveWebs, aMaterials);
168 if (!GetOperations()->IsDone() || anObject.IsNull())
169 return aGEOMObject._retn();
171 return GetObject(anObject);
174 //=============================================================================
178 //=============================================================================
179 GEOM::GEOM_Object_ptr GEOM_IBooleanOperations_i::MakeHalfPartition
180 (GEOM::GEOM_Object_ptr theShape,
181 GEOM::GEOM_Object_ptr thePlane)
183 GEOM::GEOM_Object_var aGEOMObject;
185 //Set a not done flag
186 GetOperations()->SetNotDone();
188 if (theShape == NULL || thePlane == NULL) return aGEOMObject._retn();
190 //Get the reference shapes
191 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
192 (theShape->GetStudyID(), theShape->GetEntry());
193 Handle(GEOM_Object) aPl = GetOperations()->GetEngine()->GetObject
194 (thePlane->GetStudyID(), thePlane->GetEntry());
196 if (aSh.IsNull() || aPl.IsNull()) return aGEOMObject._retn();
198 // Make Half Partition
199 Handle(GEOM_Object) anObject = GetOperations()->MakeHalfPartition(aSh, aPl);
200 if (!GetOperations()->IsDone() || anObject.IsNull())
201 return aGEOMObject._retn();
203 return GetObject(anObject);