Salome HOME
Fix for PAL8309(now, if the ctrl key is pressed, the input coordinates function(by...
[modules/geom.git] / src / GEOM_I / GEOM_IGroupOperations_i.cc
1 using namespace std; 
2
3 #include "GEOM_IGroupOperations_i.hh"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7 #include "Utils_ExceptHandlers.hxx"
8
9 #include "GEOM_Engine.hxx"
10 #include "GEOM_Object.hxx"
11
12 #include <TColStd_HArray1OfInteger.hxx>
13 #include <TopAbs.hxx>
14
15 //=============================================================================
16 /*!
17  *   constructor:
18  */
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)
24 {
25   MESSAGE("GEOM_IGroupOperations_i::GEOM_IGroupOperations_i");
26 }
27
28 //=============================================================================
29 /*!
30  *  destructor
31  */
32 //=============================================================================
33 GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i()
34 {
35   MESSAGE("GEOM_IGroupOperations_i::~GEOM_IGroupOperations_i");
36 }
37
38
39 //=============================================================================
40 /*!
41  *  CreateGroup
42  */
43 //============================================================================= 
44 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::CreateGroup(GEOM::GEOM_Object_ptr theMainShape, CORBA::Long theShapeType)
45 {
46   GEOM::GEOM_Object_var aGEOMObject;
47
48   //Set a not done flag
49   GetOperations()->SetNotDone();
50
51   if (theMainShape == NULL || theShapeType < 0) return aGEOMObject._retn();
52
53   //Get the reference shape
54   Handle(GEOM_Object) aShapeRef = GetOperations()->GetEngine()->GetObject(theMainShape->GetStudyID(), theMainShape->GetEntry());
55
56   if (aShapeRef.IsNull()) return aGEOMObject._retn();
57
58   //Create the Fillet
59   Handle(GEOM_Object) anObject = GetOperations()->CreateGroup(aShapeRef, (TopAbs_ShapeEnum)theShapeType);
60   if (!GetOperations()->IsDone() || anObject.IsNull())
61     return aGEOMObject._retn();
62
63   return GetObject(anObject);
64 }
65
66 //=============================================================================
67 /*!
68  *  AddObject
69  */
70 //=============================================================================
71 void GEOM_IGroupOperations_i::AddObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
72 {
73   //Set a not done flag
74   GetOperations()->SetNotDone();
75
76   if (theGroup == NULL) return;
77
78   //Get the reference group
79   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
80   if (aGroupRef.IsNull()) return;
81
82   GetOperations()->AddObject(aGroupRef, theSubShapeId);
83   return;
84 }
85
86 //=============================================================================
87 /*!
88  *  RemoveObject
89  */
90 //============================================================================= 
91 void GEOM_IGroupOperations_i::RemoveObject(GEOM::GEOM_Object_ptr theGroup, CORBA::Long theSubShapeId) 
92 {
93   //Set a not done flag
94   GetOperations()->SetNotDone();
95
96   if (theGroup == NULL) return;
97
98   //Get the reference group
99   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
100   if (aGroupRef.IsNull()) return;
101
102   GetOperations()->RemoveObject(aGroupRef, theSubShapeId);
103
104   return;
105 }
106
107 //=============================================================================
108 /*!
109  *  UnionList
110  */
111 //=============================================================================
112 void GEOM_IGroupOperations_i::UnionList (GEOM::GEOM_Object_ptr theGroup,
113                                          const GEOM::ListOfGO& theSubShapes) 
114 {
115   //Set a not done flag
116   GetOperations()->SetNotDone();
117
118   if (theGroup == NULL) return;
119
120   //Get the reference group
121   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
122     (theGroup->GetStudyID(), theGroup->GetEntry());
123   if (aGroupRef.IsNull()) return;
124
125   //Get sub-shape to add
126   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
127
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);
135   }
136
137   //Perform the operation
138   GetOperations()->UnionList(aGroupRef, aSubShapes);
139   return;
140 }
141
142 //=============================================================================
143 /*!
144  *  DifferenceList
145  */
146 //=============================================================================
147 void GEOM_IGroupOperations_i::DifferenceList (GEOM::GEOM_Object_ptr theGroup,
148                                               const GEOM::ListOfGO& theSubShapes) 
149 {
150   //Set a not done flag
151   GetOperations()->SetNotDone();
152
153   if (theGroup == NULL) return;
154
155   //Get the reference group
156   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject
157     (theGroup->GetStudyID(), theGroup->GetEntry());
158   if (aGroupRef.IsNull()) return;
159
160   //Get sub-shape to remove
161   Handle(TColStd_HSequenceOfTransient) aSubShapes = new TColStd_HSequenceOfTransient;
162
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);
170   }
171
172   //Perform the operation
173   GetOperations()->DifferenceList(aGroupRef, aSubShapes);
174   return;
175 }
176
177 //=============================================================================
178 /*!
179  *  GetType
180  */
181 //============================================================================= 
182 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
183 {
184   //Set a not done flag
185   GetOperations()->SetNotDone();
186
187   if (theGroup == NULL) return -1;
188
189   //Get the reference group
190   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
191
192   if (aGroupRef.IsNull()) return -1;
193
194   return GetOperations()->GetType(aGroupRef);
195 }
196
197 //=============================================================================
198 /*!
199  *  GetMainShape
200  */
201 //============================================================================= 
202 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
203 {
204   GEOM::GEOM_Object_var aGEOMObject;
205
206   //Set a not done flag
207   GetOperations()->SetNotDone();
208
209   if (theGroup == NULL) return aGEOMObject._retn();
210
211   //Get the reference group
212   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
213   if (aGroupRef.IsNull()) return aGEOMObject._retn();
214
215   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
216   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
217
218   return GetObject(anObject);
219 }
220
221 //=============================================================================
222 /*!
223  *  GetObjects
224  */
225 //============================================================================= 
226 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
227 {
228   GEOM::ListOfLong_var aList;
229
230   //Set a not done flag
231   GetOperations()->SetNotDone();
232
233   if (theGroup == NULL) return aList._retn();
234
235   //Get the reference group
236   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
237   if (aGroupRef.IsNull()) return aList._retn();
238
239   aList = new GEOM::ListOfLong;    
240
241   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
242   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
243     
244   aList->length(aSeq->Length());
245   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
246
247   return aList._retn();
248 }
249