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_IGroupOperations_i.hh"
26 #include "utilities.h"
28 #include "Utils_ExceptHandlers.hxx"
30 #include "GEOM_Engine.hxx"
31 #include "GEOM_Object.hxx"
33 #include <TColStd_HArray1OfInteger.hxx>
36 //=============================================================================
40 //=============================================================================
41 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
42 GEOM::GEOM_Gen_ptr theEngine,
43 ::GEOMImpl_IGroupOperations* theImpl)
44 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
46 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
49 //=============================================================================
53 //=============================================================================
54 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
56 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
60 //=============================================================================
64 //=============================================================================
65 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
67 GEOM::GEOM_Object_var aGEOMObject;
70 GetOperations()->SetNotDone();
72 if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
74 //Get the reference shape
75 Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
77 if (aShapeRef.IsNull()) return aGEOMObject._retn();
80 Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
81 if (!GetOperations()->IsDone() || anObject.IsNull())
82 return aGEOMObject._retn();
84 return GetObject(anObject);
87 //=============================================================================
91 //=============================================================================
92 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
95 GetOperations()->SetNotDone();
97 if (theGroup == NULL) return;
99 //Get the reference group
100 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
101 if (aGroupRef.IsNull()) return;
103 GetOperations()->AddObject(aGroupRef, theSubShapeId);
107 //=============================================================================
111 //=============================================================================
112 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
114 //Set a not done flag
115 GetOperations()->SetNotDone();
117 if (theGroup == NULL) return;
119 //Get the reference group
120 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
121 if (aGroupRef.IsNull()) return;
123 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
128 //=============================================================================
132 //=============================================================================
133 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
134 const GEOM::ListOfGO& theSubShapes)
136 //Set a not done flag
137 GetOperations()->SetNotDone();
139 if (theGroup == NULL) return;
141 //Get the reference group
142 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
143 (theGroup->GetStudyID(), theGroup->GetEntry());
144 if (aGroupRef.IsNull()) return;
146 //Get sub-shape to add
147 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
149 int ind, aLen = theSubShapes.length();
150 for (ind = 0; ind < aLen; ind++) {
151 if (theSubShapes[ind] == NULL) return;
152 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
153 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
154 if (aSh.IsNull()) return;
155 aSubShapes->Append(aSh);
158 //Perform the operation
159 GetOperations()->UnionList(aGroupRef, aSubShapes);
163 //=============================================================================
167 //=============================================================================
168 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
169 const GEOM::ListOfGO& theSubShapes)
171 //Set a not done flag
172 GetOperations()->SetNotDone();
174 if (theGroup == NULL) return;
176 //Get the reference group
177 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
178 (theGroup->GetStudyID(), theGroup->GetEntry());
179 if (aGroupRef.IsNull()) return;
181 //Get sub-shape to remove
182 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
184 int ind, aLen = theSubShapes.length();
185 for (ind = 0; ind < aLen; ind++) {
186 if (theSubShapes[ind] == NULL) return;
187 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
188 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
189 if (aSh.IsNull()) return;
190 aSubShapes->Append(aSh);
193 //Perform the operation
194 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
198 //=============================================================================
202 //=============================================================================
203 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
204 const GEOM::ListOfLong& theSubShapes)
206 //Set a not done flag
207 GetOperations()->SetNotDone();
209 if (theGroup == NULL) return;
211 //Get the reference group
212 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
213 (theGroup->GetStudyID(), theGroup->GetEntry());
214 if (aGroupRef.IsNull()) return;
216 //Get sub-shape to add
217 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
219 int ind, aLen = theSubShapes.length();
220 for (ind = 0; ind < aLen; ind++) {
221 aSubShapes->Append(theSubShapes[ind]);
224 //Perform the operation
225 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
229 //=============================================================================
233 //=============================================================================
234 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
235 const GEOM::ListOfLong& theSubShapes)
237 //Set a not done flag
238 GetOperations()->SetNotDone();
240 if (theGroup == NULL) return;
242 //Get the reference group
243 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
244 (theGroup->GetStudyID(), theGroup->GetEntry());
245 if (aGroupRef.IsNull()) return;
247 //Get sub-shape to remove
248 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
250 int ind, aLen = theSubShapes.length();
251 for (ind = 0; ind < aLen; ind++) {
252 aSubShapes->Append(theSubShapes[ind]);
255 //Perform the operation
256 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
260 //=============================================================================
264 //=============================================================================
265 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
267 //Set a not done flag
268 GetOperations()->SetNotDone();
270 if (theGroup == NULL) return -1;
272 //Get the reference group
273 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
275 if (aGroupRef.IsNull()) return -1;
277 return GetOperations()->GetType(aGroupRef);
280 //=============================================================================
284 //=============================================================================
285 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
287 GEOM::GEOM_Object_var aGEOMObject;
289 //Set a not done flag
290 GetOperations()->SetNotDone();
292 if (theGroup == NULL) return aGEOMObject._retn();
294 //Get the reference group
295 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
296 if (aGroupRef.IsNull()) return aGEOMObject._retn();
298 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
299 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
301 return GetObject(anObject);
304 //=============================================================================
308 //=============================================================================
309 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
311 GEOM::ListOfLong_var aList;
313 //Set a not done flag
314 GetOperations()->SetNotDone();
316 if (theGroup == NULL) return aList._retn();
318 //Get the reference group
319 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
320 if (aGroupRef.IsNull()) return aList._retn();
322 aList = new GEOM::ListOfLong;
324 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
325 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
327 aList->length(aSeq->Length());
328 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
330 return aList._retn();