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 thePOA->activate_object( this );
52 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
53 : SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
57 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
58 : SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
62 //=============================================================================
66 //=============================================================================
68 SMESH_GroupBase_i::~SMESH_GroupBase_i()
70 MESSAGE("~SMESH_GroupBase_i;" );
72 myMeshServant->removeGroup(myLocalID);
75 //=======================================================================
76 //function : GetSmeshGroup
78 //=======================================================================
80 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
82 if ( myMeshServant ) {
83 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
84 return aMesh.GetGroup(myLocalID);
89 //=======================================================================
90 //function : GetGroupDS
92 //=======================================================================
94 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
96 ::SMESH_Group* aGroup = GetSmeshGroup();
98 return aGroup->GetGroupDS();
102 //=============================================================================
106 //=============================================================================
108 void SMESH_GroupBase_i::SetName( const char* theName )
110 ::SMESH_Group* aGroup = GetSmeshGroup();
112 aGroup->SetName(theName);
114 // Update group name in a study
115 SMESH_Gen_i* aGen = myMeshServant->GetGen();
116 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
119 MESSAGE("can't set name of a vague group");
122 //=============================================================================
126 //=============================================================================
128 char* SMESH_GroupBase_i::GetName()
130 ::SMESH_Group* aGroup = GetSmeshGroup();
132 return CORBA::string_dup (aGroup->GetName());
133 MESSAGE("get name of a vague group");
134 return CORBA::string_dup( "NO_NAME" );
137 //=============================================================================
141 //=============================================================================
143 SMESH::ElementType SMESH_GroupBase_i::GetType()
145 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
147 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
148 SMESH::ElementType aType;
150 case SMDSAbs_Node: aType = SMESH::NODE; break;
151 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
152 case SMDSAbs_Face: aType = SMESH::FACE; break;
153 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
154 default: aType = SMESH::ALL; break;
158 MESSAGE("get type of a vague group");
163 //=============================================================================
167 //=============================================================================
169 CORBA::Long SMESH_GroupBase_i::Size()
171 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
173 return aGroupDS->Extent();
174 MESSAGE("get size of a vague group");
178 //=============================================================================
182 //=============================================================================
184 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
186 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
188 return aGroupDS->IsEmpty();
189 MESSAGE("checking IsEmpty of a vague group");
193 //=============================================================================
197 //=============================================================================
199 void SMESH_Group_i::Clear()
201 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
206 MESSAGE("attempt to clear a vague group");
209 //=============================================================================
213 //=============================================================================
215 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
217 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
219 return aGroupDS->Contains(theID);
220 MESSAGE("attempt to check contents of a vague group");
224 //=============================================================================
228 //=============================================================================
230 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
232 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
235 for (int i = 0; i < theIDs.length(); i++) {
236 int anID = (int) theIDs[i];
237 if (aGroupDS->Add(anID))
242 MESSAGE("attempt to add elements to a vague group");
246 //=============================================================================
250 //=============================================================================
252 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
254 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
256 return aGroupDS->GetID(theIndex);
257 MESSAGE("attempt to iterate on a vague group");
261 //=============================================================================
265 //=============================================================================
267 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
269 SMESH::long_array_var aRes = new SMESH::long_array();
270 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
272 int aSize = aGroupDS->Extent();
274 for (int i = 0; i < aSize; i++)
275 aRes[i] = aGroupDS->GetID(i+1);
278 MESSAGE("get list of IDs of a vague group");
282 //=============================================================================
286 //=============================================================================
288 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
290 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
293 for (int i = 0; i < theIDs.length(); i++) {
294 int anID = (int) theIDs[i];
295 if (aGroupDS->Remove(anID))
300 MESSAGE("attempt to remove elements from a vague group");
304 //=============================================================================
308 //=============================================================================
309 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
311 SMESH::SMESH_Mesh_var aMesh;
313 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
314 return aMesh._retn();
317 //=============================================================================
321 //=============================================================================
322 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
324 SMESH::long_array_var aResult = GetListOfID();
325 return aResult._retn();
328 //=======================================================================
329 //function : GetShape
331 //=======================================================================
333 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
335 GEOM::GEOM_Object_var aGeomObj;
336 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
338 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
339 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
341 return aGeomObj._retn();