3 #include "GEOM_IGroupOperations_i.hh"
7 #include "Utils_ExceptHandlers.hxx"
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
12 #include <TColStd_HArray1OfInteger.hxx>
15 //=============================================================================
19 //=============================================================================
20 GEOM_IGroupOperations_i::GEOM_IGroupOperations_i (PortableServer::POA_ptr thePOA,
21 GEOM::GEOM_Gen_ptr theEngine,
22 ::GEOMImpl_IGroupOperations* theImpl)
23 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
25 MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
28 //=============================================================================
32 //=============================================================================
33 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
35 MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
39 //=============================================================================
43 //=============================================================================
44 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
46 GEOM::GEOM_Object_var aGEOMObject;
49 GetOperations()->SetNotDone();
51 if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
53 //Get the reference shape
54 Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
56 if (aShapeRef.IsNull()) return aGEOMObject._retn();
59 Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
60 if (!GetOperations()->IsDone() || anObject.IsNull())
61 return aGEOMObject._retn();
63 return GetObject(anObject);
66 //=============================================================================
70 //=============================================================================
71 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
74 GetOperations()->SetNotDone();
76 if (theGroup == NULL) return;
78 //Get the reference group
79 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
80 if (aGroupRef.IsNull()) return;
82 GetOperations()->AddObject(aGroupRef, theSubShapeId);
86 //=============================================================================
90 //=============================================================================
91 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId)
94 GetOperations()->SetNotDone();
96 if (theGroup == NULL) return;
98 //Get the reference group
99 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
100 if (aGroupRef.IsNull()) return;
102 GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
107 //=============================================================================
111 //=============================================================================
112 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
113 const GEOM::ListOfGO& theSubShapes)
115 //Set a not done flag
116 GetOperations()->SetNotDone();
118 if (theGroup == NULL) return;
120 //Get the reference group
121 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
122 (theGroup->GetStudyID(), theGroup->GetEntry());
123 if (aGroupRef.IsNull()) return;
125 //Get sub-shape to add
126 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
128 int ind, aLen = theSubShapes.length();
129 for (ind = 0; ind < aLen; ind++) {
130 if (theSubShapes[ind] == NULL) return;
131 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
132 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
133 if (aSh.IsNull()) return;
134 aSubShapes->Append(aSh);
137 //Perform the operation
138 GetOperations()->UnionList(aGroupRef, aSubShapes);
142 //=============================================================================
146 //=============================================================================
147 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
148 const GEOM::ListOfGO& theSubShapes)
150 //Set a not done flag
151 GetOperations()->SetNotDone();
153 if (theGroup == NULL) return;
155 //Get the reference group
156 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
157 (theGroup->GetStudyID(), theGroup->GetEntry());
158 if (aGroupRef.IsNull()) return;
160 //Get sub-shape to remove
161 Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
163 int ind, aLen = theSubShapes.length();
164 for (ind = 0; ind < aLen; ind++) {
165 if (theSubShapes[ind] == NULL) return;
166 Handle(GEOM_Object) aSh = GetOperations()->GetEngine()->GetObject
167 (theSubShapes[ind]->GetStudyID(), theSubShapes[ind]->GetEntry());
168 if (aSh.IsNull()) return;
169 aSubShapes->Append(aSh);
172 //Perform the operation
173 GetOperations()->DifferenceList(aGroupRef, aSubShapes);
177 //=============================================================================
181 //=============================================================================
182 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
184 //Set a not done flag
185 GetOperations()->SetNotDone();
187 if (theGroup == NULL) return -1;
189 //Get the reference group
190 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
192 if (aGroupRef.IsNull()) return -1;
194 return GetOperations()->GetType(aGroupRef);
197 //=============================================================================
201 //=============================================================================
202 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
204 GEOM::GEOM_Object_var aGEOMObject;
206 //Set a not done flag
207 GetOperations()->SetNotDone();
209 if (theGroup == NULL) return aGEOMObject._retn();
211 //Get the reference group
212 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
213 if (aGroupRef.IsNull()) return aGEOMObject._retn();
215 Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
216 if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
218 return GetObject(anObject);
221 //=============================================================================
225 //=============================================================================
226 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
228 GEOM::ListOfLong_var aList;
230 //Set a not done flag
231 GetOperations()->SetNotDone();
233 if (theGroup == NULL) return aList._retn();
235 //Get the reference group
236 Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
237 if (aGroupRef.IsNull()) return aList._retn();
239 aList = new GEOM::ListOfLong;
241 Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
242 if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
244 aList->length(aSeq->Length());
245 for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
247 return aList._retn();