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
28 #include "SMESH_Group_i.hxx"
29 #include "SMESH_Mesh_i.hxx"
30 #include "SMESH_Gen_i.hxx"
31 #include <SMESH_Group.hxx>
32 #include <SMESHDS_Group.hxx>
33 #include <SMDSAbs_ElementType.hxx>
34 #include <utilities.h>
36 //=============================================================================
40 //=============================================================================
42 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
43 : SALOME::GenericObj_i( thePOA ),
44 myMeshServant( theMeshServant ),
45 myLocalID( theLocalID )
47 thePOA->activate_object( this );
51 //=============================================================================
55 //=============================================================================
57 SMESH_Group_i::~SMESH_Group_i()
59 MESSAGE("~SMESH_Group_i;" );
61 myMeshServant->removeGroup(myLocalID);
65 //=============================================================================
69 //=============================================================================
71 void SMESH_Group_i::SetName( const char* theName )
73 if ( myMeshServant ) {
74 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
75 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
77 aGroup->SetName(theName);
79 // Update group name in a study
80 SALOMEDS::Study_var aStudy = myMeshServant->GetGen()->GetCurrentStudy();
81 if ( !aStudy->_is_nil() ) {
82 SALOMEDS::SObject_var aGroupSO = aStudy->FindObjectIOR( SMESH_Gen_i::GetORB()->object_to_string( _this() ) );
83 if ( !aGroupSO->_is_nil() ) {
84 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
85 aBuilder->SetName( aGroupSO, theName );
91 MESSAGE("can't set name of a vague group");
95 //=============================================================================
99 //=============================================================================
101 char* SMESH_Group_i::GetName()
103 if ( myMeshServant ) {
104 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
105 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
107 return CORBA::string_dup (aGroup->GetName());
109 MESSAGE("get name of a vague group");
110 return CORBA::string_dup( "NO_NAME" );
114 //=============================================================================
118 //=============================================================================
120 SMESH::ElementType SMESH_Group_i::GetType()
122 if ( myMeshServant ) {
123 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
124 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
126 SMDSAbs_ElementType aSMDSType = aGroup->GetGroupDS()->GetType();
127 SMESH::ElementType aType;
129 case SMDSAbs_Node: aType = SMESH::NODE; break;
130 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
131 case SMDSAbs_Face: aType = SMESH::FACE; break;
132 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
133 default: aType = SMESH::ALL; break;
138 MESSAGE("get type of a vague group");
143 //=============================================================================
147 //=============================================================================
149 CORBA::Long SMESH_Group_i::Size()
151 if ( myMeshServant ) {
152 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
153 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
155 int aSize = aGroup->GetGroupDS()->Extent();
159 MESSAGE("get size of a vague group");
164 //=============================================================================
168 //=============================================================================
170 CORBA::Boolean SMESH_Group_i::IsEmpty()
172 if ( myMeshServant ) {
173 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
174 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
176 bool isEmpty = aGroup->GetGroupDS()->IsEmpty();
180 MESSAGE("checking IsEmpty of a vague group");
185 //=============================================================================
189 //=============================================================================
191 void SMESH_Group_i::Clear()
193 if ( myMeshServant ) {
194 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
195 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
197 // a SMDS group forgets its type after clearing, so we must re-set it
198 SMDSAbs_ElementType aSMDSType = aGroup->GetGroupDS()->GetType();
199 aGroup->GetGroupDS()->Clear();
200 aGroup->GetGroupDS()->SetType(aSMDSType);
204 MESSAGE("attempt to clear a vague group");
208 //=============================================================================
212 //=============================================================================
214 CORBA::Boolean SMESH_Group_i::Contains( CORBA::Long theID )
216 if ( myMeshServant ) {
217 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
218 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
220 bool res = aGroup->GetGroupDS()->Contains(theID);
224 MESSAGE("attempt to check contents of a vague group");
229 //=============================================================================
233 //=============================================================================
235 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
237 if ( myMeshServant ) {
238 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
239 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
241 SMESHDS_Group* aGroupDS = aGroup->GetGroupDS();
243 for (int i = 0; i < theIDs.length(); i++) {
244 int anID = (int) theIDs[i];
245 if (aGroupDS->Add(anID))
251 MESSAGE("attempt to add elements to a vague group");
256 //=============================================================================
260 //=============================================================================
262 CORBA::Long SMESH_Group_i::GetID( CORBA::Long theIndex )
264 if ( myMeshServant ) {
265 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
266 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
268 int anID = aGroup->GetGroupDS()->GetID(theIndex);
272 MESSAGE("attempt to iterate on a vague group");
277 //=============================================================================
281 //=============================================================================
283 SMESH::long_array* SMESH_Group_i::GetListOfID()
285 SMESH::long_array_var aRes = new SMESH::long_array();
286 if ( myMeshServant ) {
287 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
288 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
290 SMESHDS_Group* aGroupDS = aGroup->GetGroupDS();
291 int aSize = aGroupDS->Extent();
293 for (int i = 0; i < aSize; i++)
294 aRes[i] = aGroupDS->GetID(i+1);
298 MESSAGE("get list of IDs of a vague group");
303 //=============================================================================
307 //=============================================================================
309 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
311 if ( myMeshServant ) {
312 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
313 ::SMESH_Group* aGroup = aMesh.GetGroup(myLocalID);
315 // a SMDS group forgets its type after clearing, so we must re-set it
316 // if the group becomes empty
317 SMDSAbs_ElementType aSMDSType = aGroup->GetGroupDS()->GetType();
318 SMESHDS_Group* aGroupDS = aGroup->GetGroupDS();
320 for (int i = 0; i < theIDs.length(); i++) {
321 int anID = (int) theIDs[i];
322 if (aGroupDS->Remove(anID))
325 if (aGroupDS->IsEmpty())
326 aGroupDS->SetType(aSMDSType);
330 MESSAGE("attempt to remove elements from a vague group");
335 //=============================================================================
339 //=============================================================================
340 SMESH::SMESH_Mesh_ptr SMESH_Group_i::GetMesh()
342 MESSAGE("SMESH_Group_i::GetMesh(): mesh servant = " << myMeshServant );
343 SMESH::SMESH_Mesh_var aMesh;
345 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
346 return aMesh._retn();
350 //=============================================================================
354 //=============================================================================
355 int SMESH_Group_i::GetLocalID()