]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESH_I/SMESH_Group_i.cxx
Salome HOME
Dump Python: dump more methods.
[modules/smesh.git] / src / SMESH_I / SMESH_Group_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
2 //
3 //  Copyright (C) 2004  CEA
4 // 
5 //  This library is free software; you can redistribute it and/or 
6 //  modify it under the terms of the GNU Lesser General Public 
7 //  License as published by the Free Software Foundation; either 
8 //  version 2.1 of the License. 
9 // 
10 //  This library is distributed in the hope that it will be useful, 
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
13 //  Lesser General Public License for more details. 
14 // 
15 //  You should have received a copy of the GNU Lesser General Public 
16 //  License along with this library; if not, write to the Free Software 
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
18 // 
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org 
20 //
21 //
22 //
23 //  File   : SMESH_Group_i.cxx
24 //  Author : Sergey ANIKIN, OCC
25 //  Module : SMESH
26 //  $Header$
27
28
29 #include "SMESH_Group_i.hxx"
30 #include "SMESH_Mesh_i.hxx"
31 #include "SMESH_Gen_i.hxx"
32 #include "SMESH_Group.hxx"
33 #include "SMESHDS_Group.hxx"
34 #include "SMESHDS_GroupOnGeom.hxx"
35 #include "SMDSAbs_ElementType.hxx"
36 #include "utilities.h"
37
38 //=============================================================================
39 /*!
40  *  
41  */
42 //=============================================================================
43
44 SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
45 : SALOME::GenericObj_i( thePOA ),
46   myMeshServant( theMeshServant ), 
47   myLocalID( theLocalID )
48 {
49   // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i,
50   // servant activation is performed by SMESH_Mesh_i::createGroup()
51   // thePOA->activate_object( this );
52 }
53
54 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
55      : SALOME::GenericObj_i( thePOA ),
56        SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
57 {
58   MESSAGE("SMESH_Group_i; this = "<<this );
59 }
60
61 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
62      : SALOME::GenericObj_i( thePOA ),
63        SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
64 {
65   MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
66 }
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73
74 SMESH_GroupBase_i::~SMESH_GroupBase_i()
75 {
76   MESSAGE("~SMESH_GroupBase_i; this = "<<this );
77   if ( myMeshServant )
78     myMeshServant->removeGroup(myLocalID);
79 }
80
81 //=======================================================================
82 //function : GetSmeshGroup
83 //purpose  : 
84 //=======================================================================
85
86 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
87 {
88   if ( myMeshServant ) {
89     ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
90     return aMesh.GetGroup(myLocalID);
91   }
92   return 0;
93 }
94
95 //=======================================================================
96 //function : GetGroupDS
97 //purpose  : 
98 //=======================================================================
99
100 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
101 {
102   ::SMESH_Group* aGroup = GetSmeshGroup();
103   if ( aGroup )
104     return aGroup->GetGroupDS();
105   return 0;
106 }
107
108 //=============================================================================
109 /*!
110  *  
111  */
112 //=============================================================================
113
114 void SMESH_GroupBase_i::SetName( const char* theName )
115 {
116   ::SMESH_Group* aGroup = GetSmeshGroup();
117   if (aGroup) {
118     aGroup->SetName(theName);
119
120     // Update group name in a study
121     SMESH_Gen_i* aGen = myMeshServant->GetGen();
122     aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
123     return;
124   }
125   MESSAGE("can't set name of a vague group");
126 }
127
128 //=============================================================================
129 /*!
130  *  
131  */
132 //=============================================================================
133
134 char* SMESH_GroupBase_i::GetName()
135 {
136   ::SMESH_Group* aGroup = GetSmeshGroup();
137   if (aGroup)
138     return CORBA::string_dup (aGroup->GetName());
139   MESSAGE("get name of a vague group");
140   return CORBA::string_dup( "NO_NAME" );
141 }
142
143 //=============================================================================
144 /*!
145  *  
146  */
147 //=============================================================================
148
149 SMESH::ElementType SMESH_GroupBase_i::GetType()
150 {
151   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
152   if (aGroupDS) {
153     SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
154     SMESH::ElementType aType;
155     switch (aSMDSType) {
156     case SMDSAbs_Node:   aType = SMESH::NODE; break;
157     case SMDSAbs_Edge:   aType = SMESH::EDGE; break;
158     case SMDSAbs_Face:   aType = SMESH::FACE; break;
159     case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
160     default:             aType = SMESH::ALL; break;
161     }
162     return aType;
163   }
164   MESSAGE("get type of a vague group");
165   return SMESH::ALL;
166 }
167
168
169 //=============================================================================
170 /*!
171  *  
172  */
173 //=============================================================================
174
175 CORBA::Long SMESH_GroupBase_i::Size()
176 {
177   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
178   if (aGroupDS)
179     return aGroupDS->Extent();
180   MESSAGE("get size of a vague group");
181   return 0;
182 }
183
184 //=============================================================================
185 /*!
186  *  
187  */
188 //=============================================================================
189
190 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
191 {
192   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
193   if (aGroupDS)
194     return aGroupDS->IsEmpty();
195   MESSAGE("checking IsEmpty of a vague group");
196   return true;
197 }
198
199 //=============================================================================
200 /*!
201  *  
202  */
203 //=============================================================================
204
205 void SMESH_Group_i::Clear()
206 {
207   // Update Python script
208   TCollection_AsciiString aStr;
209   SMESH_Gen_i::AddObject(aStr, _this()) += ".Clear()";
210
211   SMESH_Gen_i::AddToCurrentPyScript(aStr);
212
213   // Clear the group
214   SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
215   if (aGroupDS) {
216     aGroupDS->Clear();
217     return;
218   }
219   MESSAGE("attempt to clear a vague group");
220 }
221
222 //=============================================================================
223 /*!
224  *  
225  */
226 //=============================================================================
227
228 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
229 {
230   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
231   if (aGroupDS)
232     return aGroupDS->Contains(theID);
233   MESSAGE("attempt to check contents of a vague group");
234   return false;
235 }
236
237 //=============================================================================
238 /*!
239  *  
240  */
241 //=============================================================================
242
243 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
244 {
245   // Update Python script
246   TCollection_AsciiString aStr ("nbAdd = ");
247   SMESH_Gen_i::AddObject(aStr, _this()) += ".Add(";
248   SMESH_Gen_i::AddArray(aStr, theIDs) += ")";
249
250   SMESH_Gen_i::AddToCurrentPyScript(aStr);
251
252   // Add elements to the group
253   SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
254   if (aGroupDS) {
255     int nbAdd = 0;
256     for (int i = 0; i < theIDs.length(); i++) {
257       int anID = (int) theIDs[i];
258       if (aGroupDS->Add(anID))
259         nbAdd++;
260     }
261     return nbAdd;
262   }
263   MESSAGE("attempt to add elements to a vague group");
264   return 0;
265 }
266
267 //=============================================================================
268 /*!
269  *  
270  */
271 //=============================================================================
272
273 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
274 {
275   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
276   if (aGroupDS)
277     return aGroupDS->GetID(theIndex);
278   MESSAGE("attempt to iterate on a vague group");
279   return -1;
280 }
281
282 //=============================================================================
283 /*!
284  *  
285  */
286 //=============================================================================
287
288 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
289 {
290   SMESH::long_array_var aRes = new SMESH::long_array();
291   SMESHDS_GroupBase* aGroupDS = GetGroupDS();
292   if (aGroupDS) {
293     int aSize = aGroupDS->Extent();
294     aRes->length(aSize);
295     for (int i = 0; i < aSize; i++)
296       aRes[i] = aGroupDS->GetID(i+1);
297     return aRes._retn();
298   }
299   MESSAGE("get list of IDs of a vague group");
300   return aRes._retn();
301 }
302
303 //=============================================================================
304 /*!
305  *  
306  */
307 //=============================================================================
308
309 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
310 {
311   // Update Python script
312   TCollection_AsciiString aStr ("nbDel = ");
313   SMESH_Gen_i::AddObject(aStr, _this()) += ".Remove(";
314   SMESH_Gen_i::AddArray(aStr, theIDs) += ")";
315
316   SMESH_Gen_i::AddToCurrentPyScript(aStr);
317
318   // Remove elements from the group
319   SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
320   if (aGroupDS) {
321     int nbDel = 0;
322     for (int i = 0; i < theIDs.length(); i++) {
323       int anID = (int) theIDs[i];
324       if (aGroupDS->Remove(anID))
325         nbDel++;
326     }
327     return nbDel;
328   }
329   MESSAGE("attempt to remove elements from a vague group");
330   return 0;
331 }
332
333 //=============================================================================
334 /*!
335  *  
336  */
337 //=============================================================================
338 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
339 {
340   SMESH::SMESH_Mesh_var aMesh;
341   if ( myMeshServant )
342     aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
343   return aMesh._retn();
344 }
345
346 //=============================================================================
347 /*!
348  *  
349  */
350 //=============================================================================
351 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
352 {
353   SMESH::long_array_var aResult = GetListOfID();
354   return aResult._retn();
355 }
356
357 //=======================================================================
358 //function : GetShape
359 //purpose  : 
360 //=======================================================================
361
362 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
363 {
364   GEOM::GEOM_Object_var aGeomObj;
365   SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
366   if ( aGroupDS ) {
367     SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
368     aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
369   }
370   return aGeomObj._retn();
371 }
372