Salome HOME
Merge with version on tag OCC-V2_1_0d
[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  *  GetType
110  */
111 //============================================================================= 
112 CORBA::Long GEOM_IGroupOperations_i::GetType(GEOM::GEOM_Object_ptr theGroup)
113 {
114   //Set a not done flag
115   GetOperations()->SetNotDone();
116
117   if (theGroup == NULL) return -1;
118
119   //Get the reference group
120   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
121
122   if (aGroupRef.IsNull()) return -1;
123
124   return GetOperations()->GetType(aGroupRef);
125 }
126
127 //=============================================================================
128 /*!
129  *  GetMainShape
130  */
131 //============================================================================= 
132 GEOM::GEOM_Object_ptr GEOM_IGroupOperations_i::GetMainShape(GEOM::GEOM_Object_ptr theGroup)
133 {
134   GEOM::GEOM_Object_var aGEOMObject;
135
136   //Set a not done flag
137   GetOperations()->SetNotDone();
138
139   if (theGroup == NULL) return aGEOMObject._retn();
140
141   //Get the reference group
142   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
143   if (aGroupRef.IsNull()) return aGEOMObject._retn();
144
145   Handle(GEOM_Object) anObject = GetOperations()->GetMainShape(aGroupRef);
146   if (!GetOperations()->IsDone() || anObject.IsNull()) return aGEOMObject._retn();
147
148   return GetObject(anObject);
149 }
150
151 //=============================================================================
152 /*!
153  *  GetObjects
154  */
155 //============================================================================= 
156 GEOM::ListOfLong* GEOM_IGroupOperations_i::GetObjects(GEOM::GEOM_Object_ptr theGroup)
157 {
158   GEOM::ListOfLong_var aList;
159
160   //Set a not done flag
161   GetOperations()->SetNotDone();
162
163   if (theGroup == NULL) return aList._retn();
164
165   //Get the reference group
166   Handle(GEOM_Object) aGroupRef = GetOperations()->GetEngine()->GetObject(theGroup->GetStudyID(), theGroup->GetEntry());
167   if (aGroupRef.IsNull()) return aList._retn();
168
169   aList = new GEOM::ListOfLong;    
170
171   Handle(TColStd_HArray1OfInteger) aSeq = GetOperations()->GetObjects(aGroupRef);
172   if (!GetOperations()->IsDone() || aSeq.IsNull()) return aList._retn();
173     
174   aList->length(aSeq->Length());
175   for(int i = 1; i<=aSeq->Length(); i++) aList[i-1] = aSeq->Value(i);
176
177   return aList._retn();
178 }
179