1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
3 // Copyright (C) 2004 CEA
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.
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.
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
19 // See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
23 // File : SMESH_Group_i.cxx
24 // Author : Sergey ANIKIN, OCC
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"
38 //=============================================================================
42 //=============================================================================
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 )
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 );
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 )
58 MESSAGE("SMESH_Group_i; this = "<<this );
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 )
65 MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
68 //=============================================================================
72 //=============================================================================
74 SMESH_GroupBase_i::~SMESH_GroupBase_i()
76 MESSAGE("~SMESH_GroupBase_i; this = "<<this );
78 myMeshServant->removeGroup(myLocalID);
81 //=======================================================================
82 //function : GetSmeshGroup
84 //=======================================================================
86 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
88 if ( myMeshServant ) {
89 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
90 return aMesh.GetGroup(myLocalID);
95 //=======================================================================
96 //function : GetGroupDS
98 //=======================================================================
100 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
102 ::SMESH_Group* aGroup = GetSmeshGroup();
104 return aGroup->GetGroupDS();
108 //=============================================================================
112 //=============================================================================
114 void SMESH_GroupBase_i::SetName( const char* theName )
116 ::SMESH_Group* aGroup = GetSmeshGroup();
118 aGroup->SetName(theName);
120 // Update group name in a study
121 SMESH_Gen_i* aGen = myMeshServant->GetGen();
122 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
125 MESSAGE("can't set name of a vague group");
128 //=============================================================================
132 //=============================================================================
134 char* SMESH_GroupBase_i::GetName()
136 ::SMESH_Group* aGroup = GetSmeshGroup();
138 return CORBA::string_dup (aGroup->GetName());
139 MESSAGE("get name of a vague group");
140 return CORBA::string_dup( "NO_NAME" );
143 //=============================================================================
147 //=============================================================================
149 SMESH::ElementType SMESH_GroupBase_i::GetType()
151 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
153 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
154 SMESH::ElementType aType;
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;
164 MESSAGE("get type of a vague group");
169 //=============================================================================
173 //=============================================================================
175 CORBA::Long SMESH_GroupBase_i::Size()
177 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
179 return aGroupDS->Extent();
180 MESSAGE("get size of a vague group");
184 //=============================================================================
188 //=============================================================================
190 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
192 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
194 return aGroupDS->IsEmpty();
195 MESSAGE("checking IsEmpty of a vague group");
199 //=============================================================================
203 //=============================================================================
205 void SMESH_Group_i::Clear()
207 // Update Python script
208 TCollection_AsciiString aStr;
209 SMESH_Gen_i::AddObject(aStr, _this()) += ".Clear()";
211 SMESH_Gen_i::AddToCurrentPyScript(aStr);
214 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
219 MESSAGE("attempt to clear a vague group");
222 //=============================================================================
226 //=============================================================================
228 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
230 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
232 return aGroupDS->Contains(theID);
233 MESSAGE("attempt to check contents of a vague group");
237 //=============================================================================
241 //=============================================================================
243 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
245 // Update Python script
246 TCollection_AsciiString aStr ("nbAdd = ");
247 SMESH_Gen_i::AddObject(aStr, _this()) += ".Add(";
248 SMESH_Gen_i::AddArray(aStr, theIDs) += ")";
250 SMESH_Gen_i::AddToCurrentPyScript(aStr);
252 // Add elements to the group
253 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
256 for (int i = 0; i < theIDs.length(); i++) {
257 int anID = (int) theIDs[i];
258 if (aGroupDS->Add(anID))
263 MESSAGE("attempt to add elements to a vague group");
267 //=============================================================================
271 //=============================================================================
273 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
275 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
277 return aGroupDS->GetID(theIndex);
278 MESSAGE("attempt to iterate on a vague group");
282 //=============================================================================
286 //=============================================================================
288 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
290 SMESH::long_array_var aRes = new SMESH::long_array();
291 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
293 int aSize = aGroupDS->Extent();
295 for (int i = 0; i < aSize; i++)
296 aRes[i] = aGroupDS->GetID(i+1);
299 MESSAGE("get list of IDs of a vague group");
303 //=============================================================================
307 //=============================================================================
309 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
311 // Update Python script
312 TCollection_AsciiString aStr ("nbDel = ");
313 SMESH_Gen_i::AddObject(aStr, _this()) += ".Remove(";
314 SMESH_Gen_i::AddArray(aStr, theIDs) += ")";
316 SMESH_Gen_i::AddToCurrentPyScript(aStr);
318 // Remove elements from the group
319 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
322 for (int i = 0; i < theIDs.length(); i++) {
323 int anID = (int) theIDs[i];
324 if (aGroupDS->Remove(anID))
329 MESSAGE("attempt to remove elements from a vague group");
333 //=============================================================================
337 //=============================================================================
338 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
340 SMESH::SMESH_Mesh_var aMesh;
342 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
343 return aMesh._retn();
346 //=============================================================================
350 //=============================================================================
351 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
353 SMESH::long_array_var aResult = GetListOfID();
354 return aResult._retn();
357 //=======================================================================
358 //function : GetShape
360 //=======================================================================
362 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
364 GEOM::GEOM_Object_var aGeomObj;
365 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
367 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
368 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
370 return aGeomObj._retn();