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_IGroupOperations_i.hh"
24 #include "utilities.h"
26 #include "Utils_ExceptHandlers.hxx"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 #include <TColStd_HArray1OfInteger.hxx>
34 //=============================================================================
38 //=============================================================================
39 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
40 GEOM::GEOM_Gen_ptr theEngine,
41 ::GEOMImpl_IGroupOperations* theImpl)
42 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
44 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
47 //=============================================================================
51 //=============================================================================
52 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
54 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
58 //=============================================================================
62 //=============================================================================
63 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
65 GEOM::GEOM_Object_var aGEOMObject;
68 GetOperations()->SetNotDone();
70 if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
72 //Get the reference shape
73 Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
75 if (aShapeRef.IsNull()) return aGEOMObject._retn();
78 Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
79 if (!GetOperations()->IsDone() || anObject.IsNull())
80 return aGEOMObject._retn();
82 return GetObject(anObject);
85 //=============================================================================
89 //=============================================================================
90 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
93 GetOperations()->SetNotDone();
95 if (theGroup == NULL) return;
97 //Get the reference group
98 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
99 if (aGroupRef.IsNull()) return;
101 GetOperations()->AddObject(aGroupRef, theSubShapeId);
105 //=============================================================================
109 //=============================================================================
110 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
112 //Set a not done flag
113 GetOperations()->SetNotDone();
115 if (theGroup == NULL) return;
117 //Get the reference group
118 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
119 if (aGroupRef.IsNull()) return;
121 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
126 //=============================================================================
130 //=============================================================================
131 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
132 const GEOM::ListOfGO& theSubShapes)
134 //Set a not done flag
135 GetOperations()->SetNotDone();
137 if (theGroup == NULL) return;
139 //Get the reference group
140 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
141 (theGroup->GetStudyID(), theGroup->GetEntry());
142 if (aGroupRef.IsNull()) return;
144 //Get sub-shape to add
145 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
147 int ind, aLen = theSubShapes.length();
148 for (ind = 0; ind < aLen; ind++) {
149 if (theSubShapes[ind] == NULL) return;
150 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
151 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
152 if (aSh.IsNull()) return;
153 aSubShapes->Append(aSh);
156 //Perform the operation
157 GetOperations()->UnionList(aGroupRef, aSubShapes);
161 //=============================================================================
165 //=============================================================================
166 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
167 const GEOM::ListOfGO& theSubShapes)
169 //Set a not done flag
170 GetOperations()->SetNotDone();
172 if (theGroup == NULL) return;
174 //Get the reference group
175 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
176 (theGroup->GetStudyID(), theGroup->GetEntry());
177 if (aGroupRef.IsNull()) return;
179 //Get sub-shape to remove
180 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
182 int ind, aLen = theSubShapes.length();
183 for (ind = 0; ind < aLen; ind++) {
184 if (theSubShapes[ind] == NULL) return;
185 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
186 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
187 if (aSh.IsNull()) return;
188 aSubShapes->Append(aSh);
191 //Perform the operation
192 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
196 //=============================================================================
200 //=============================================================================
201 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
202 const GEOM::ListOfLong& theSubShapes)
204 //Set a not done flag
205 GetOperations()->SetNotDone();
207 if (theGroup == NULL) return;
209 //Get the reference group
210 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
211 (theGroup->GetStudyID(), theGroup->GetEntry());
212 if (aGroupRef.IsNull()) return;
214 //Get sub-shape to add
215 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
217 int ind, aLen = theSubShapes.length();
218 for (ind = 0; ind < aLen; ind++) {
219 aSubShapes->Append(theSubShapes[ind]);
222 //Perform the operation
223 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
227 //=============================================================================
231 //=============================================================================
232 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
233 const GEOM::ListOfLong& theSubShapes)
235 //Set a not done flag
236 GetOperations()->SetNotDone();
238 if (theGroup == NULL) return;
240 //Get the reference group
241 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
242 (theGroup->GetStudyID(), theGroup->GetEntry());
243 if (aGroupRef.IsNull()) return;
245 //Get sub-shape to remove
246 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
248 int ind, aLen = theSubShapes.length();
249 for (ind = 0; ind < aLen; ind++) {
250 aSubShapes->Append(theSubShapes[ind]);
253 //Perform the operation
254 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
258 //=============================================================================
262 //=============================================================================
263 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
265 //Set a not done flag
266 GetOperations()->SetNotDone();
268 if (theGroup == NULL) return -1;
270 //Get the reference group
271 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
273 if (aGroupRef.IsNull()) return -1;
275 return GetOperations()->GetType(aGroupRef);
278 //=============================================================================
282 //=============================================================================
283 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
285 GEOM::GEOM_Object_var aGEOMObject;
287 //Set a not done flag
288 GetOperations()->SetNotDone();
290 if (theGroup == NULL) return aGEOMObject._retn();
292 //Get the reference group
293 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
294 if (aGroupRef.IsNull()) return aGEOMObject._retn();
296 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
297 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
299 return GetObject(anObject);
302 //=============================================================================
306 //=============================================================================
307 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
309 GEOM::ListOfLong_var aList;
311 //Set a not done flag
312 GetOperations()->SetNotDone();
314 if (theGroup == NULL) return aList._retn();
316 //Get the reference group
317 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
318 if (aGroupRef.IsNull()) return aList._retn();
320 aList = new GEOM::ListOfLong;
322 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
323 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
325 aList->length(aSeq->Length());
326 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
328 return aList._retn();