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,
66 CORBA::Long theShapeType)
68 GEOM::GEOM_Object_var aGEOMObject;
71 GetOperations()->SetNotDone();
73 if (theShapeType < 0) return aGEOMObject._retn();
75 //Get the reference shape
76 Handle(GEOM_Object) aShapeRef = GetObjectImpl(theMainShape);
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 //Get the reference group
98 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
99 if (aGroupRef.IsNull()) return;
101 GetOperations()->AddObject(aGroupRef, theSubShapeId);
104 //=============================================================================
108 //=============================================================================
109 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
111 //Set a not done flag
112 GetOperations()->SetNotDone();
114 //Get the reference group
115 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
116 if (aGroupRef.IsNull()) return;
118 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
121 //=============================================================================
125 //=============================================================================
126 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
127 const GEOM::ListOfGO& theSubShapes)
129 //Set a not done flag
130 GetOperations()->SetNotDone();
132 //Get the reference group
133 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
134 if (aGroupRef.IsNull()) return;
136 //Get sub-shape to add
137 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
139 int ind, aLen = theSubShapes.length();
140 for (ind = 0; ind < aLen; ind++) {
141 Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
142 if (aSh.IsNull()) return;
143 aSubShapes->Append(aSh);
146 //Perform the operation
147 GetOperations()->UnionList(aGroupRef, aSubShapes);
150 //=============================================================================
154 //=============================================================================
155 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
156 const GEOM::ListOfGO& theSubShapes)
158 //Set a not done flag
159 GetOperations()->SetNotDone();
161 //Get the reference group
162 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
163 if (aGroupRef.IsNull()) return;
165 //Get sub-shape to remove
166 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
168 int ind, aLen = theSubShapes.length();
169 for (ind = 0; ind < aLen; ind++) {
170 Handle(GEOM_Object) aSh = GetObjectImpl(theSubShapes[ind]);
171 if (aSh.IsNull()) return;
172 aSubShapes->Append(aSh);
175 //Perform the operation
176 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
179 //=============================================================================
183 //=============================================================================
184 void GEOM_IGroupOperations_i::UnionIDs (GEOM::GEOM_Object_ptr theGroup,
185 const GEOM::ListOfLong& theSubShapes)
187 //Set a not done flag
188 GetOperations()->SetNotDone();
190 //Get the reference group
191 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
192 if (aGroupRef.IsNull()) return;
194 //Get sub-shape to add
195 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
197 int ind, aLen = theSubShapes.length();
198 for (ind = 0; ind < aLen; ind++) {
199 aSubShapes->Append(theSubShapes[ind]);
202 //Perform the operation
203 GetOperations()->UnionIDs(aGroupRef, aSubShapes);
207 //=============================================================================
211 //=============================================================================
212 void GEOM_IGroupOperations_i::DifferenceIDs (GEOM::GEOM_Object_ptr theGroup,
213 const GEOM::ListOfLong& theSubShapes)
215 //Set a not done flag
216 GetOperations()->SetNotDone();
218 //Get the reference group
219 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
220 if (aGroupRef.IsNull()) return;
222 //Get sub-shape to remove
223 Handle(TColStd_HSequenceOfInteger) aSubShapes = new TColStd_HSequenceOfInteger;
225 int ind, aLen = theSubShapes.length();
226 for (ind = 0; ind < aLen; ind++) {
227 aSubShapes->Append(theSubShapes[ind]);
230 //Perform the operation
231 GetOperations()->DifferenceIDs(aGroupRef, aSubShapes);
235 //=============================================================================
239 //=============================================================================
240 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
242 //Set a not done flag
243 GetOperations()->SetNotDone();
245 //Get the reference group
246 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
247 if (aGroupRef.IsNull()) return -1;
249 return GetOperations()->GetType(aGroupRef);
252 //=============================================================================
256 //=============================================================================
257 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
259 GEOM::GEOM_Object_var aGEOMObject;
261 //Set a not done flag
262 GetOperations()->SetNotDone();
264 //Get the reference group
265 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
266 if (aGroupRef.IsNull()) return aGEOMObject._retn();
268 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
269 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
271 return GetObject(anObject);
274 //=============================================================================
278 //=============================================================================
279 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
281 GEOM::ListOfLong_var aList;
283 //Set a not done flag
284 GetOperations()->SetNotDone();
286 //Get the reference group
287 Handle(GEOM_Object) aGroupRef = GetObjectImpl(theGroup);
288 if (aGroupRef.IsNull()) return aList._retn();
290 aList = new GEOM::ListOfLong;
292 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
293 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
295 aList->length(aSeq->Length());
296 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
298 return aList._retn();