1 // Copyright (C) 2007-2011 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
23 #include <Standard_Stream.hxx>
25 #include "GEOM_IGroupOperations_i.hh"
27 #include "utilities.h"
29 #include "Utils_ExceptHandlers.hxx"
31 #include "GEOM_Engine.hxx"
32 #include "GEOM_Object.hxx"
34 #include <TColStd_HArray1OfInteger.hxx>
37 //=============================================================================
41 //=============================================================================
42 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
43 GEOM::GEOM_Gen_ptr theEngine,
44 ::GEOMImpl_IGroupOperations* theImpl)
45 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
47 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
50 //=============================================================================
54 //=============================================================================
55 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
57 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
61 //=============================================================================
65 //=============================================================================
66 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape,
67 CORBA::Long theShapeType)
69 GEOM::GEOM_Object_var aGEOMObject;
72 GetOperations()->SetNotDone();
74 if (theShapeType < 0) return aGEOMObject._retn();
76 //Get the reference shape
77 Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
78 if (aShapeRef.IsNull()) return aGEOMObject._retn();
81 Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
82 if (!GetOperations()->IsDone() || anObject.IsNull())
83 return aGEOMObject._retn();
85 return GetObject(anObject);
88 //=============================================================================
92 //=============================================================================
93 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
96 GetOperations()->SetNotDone();
98 //Get the reference group
99 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
100 if (aGroupRef.IsNull()) return;
102 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 //Get the reference group
116 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
117 if (aGroupRef.IsNull()) return;
119 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
122 //=============================================================================
126 //=============================================================================
127 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
128 const GEOM::ListOfGO& theSubShapes)
130 //Set a not done flag
131 GetOperations()->SetNotDone();
133 //Get the reference group
134 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
135 if (aGroupRef.IsNull()) return;
137 //Get sub-shape to add
138 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
140 int ind, aLen = theSubShapes.length();
141 for (ind = 0; ind < aLen; ind++) {
142 Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
143 if (aSh.IsNull()) return;
144 aSubShapes->Append(aSh);
147 //Perform the operation
148 GetOperations()->UnionList(aGroupRef, aSubShapes);
151 //=============================================================================
155 //=============================================================================
156 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
157 const GEOM::ListOfGO& theSubShapes)
159 //Set a not done flag
160 GetOperations()->SetNotDone();
162 //Get the reference group
163 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
164 if (aGroupRef.IsNull()) return;
166 //Get sub-shape to remove
167 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
169 int ind, aLen = theSubShapes.length();
170 for (ind = 0; ind < aLen; ind++) {
171 Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
172 if (aSh.IsNull()) return;
173 aSubShapes->Append(aSh);
176 //Perform the operation
177 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
180 //=============================================================================
184 //=============================================================================
185 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
186 const GEOM::ListOfLong& theSubShapes)
188 //Set a not done flag
189 GetOperations()->SetNotDone();
191 //Get the reference group
192 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
193 if (aGroupRef.IsNull()) return;
195 //Get sub-shape to add
196 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
198 int ind, aLen = theSubShapes.length();
199 for (ind = 0; ind < aLen; ind++) {
200 aSubShapes->Append(theSubShapes[ind]);
203 //Perform the operation
204 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
208 //=============================================================================
212 //=============================================================================
213 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
214 const GEOM::ListOfLong& theSubShapes)
216 //Set a not done flag
217 GetOperations()->SetNotDone();
219 //Get the reference group
220 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
221 if (aGroupRef.IsNull()) return;
223 //Get sub-shape to remove
224 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
226 int ind, aLen = theSubShapes.length();
227 for (ind = 0; ind < aLen; ind++) {
228 aSubShapes->Append(theSubShapes[ind]);
231 //Perform the operation
232 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
236 //=============================================================================
240 //=============================================================================
241 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
243 //Set a not done flag
244 GetOperations()->SetNotDone();
246 //Get the reference group
247 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
248 if (aGroupRef.IsNull()) return -1;
250 return GetOperations()->GetType(aGroupRef);
253 //=============================================================================
257 //=============================================================================
258 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
260 GEOM::GEOM_Object_var aGEOMObject;
262 //Set a not done flag
263 GetOperations()->SetNotDone();
265 //Get the reference group
266 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
267 if (aGroupRef.IsNull()) return aGEOMObject._retn();
269 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
270 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
272 return GetObject(anObject);
275 //=============================================================================
279 //=============================================================================
280 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
282 GEOM::ListOfLong_var aList;
284 //Set a not done flag
285 GetOperations()->SetNotDone();
287 //Get the reference group
288 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
289 if (aGroupRef.IsNull()) return aList._retn();
291 aList = new GEOM::ListOfLong;
293 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
294 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
296 aList->length(aSeq->Length());
297 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
299 return aList._retn();