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.com
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"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_PythonDump.hxx"
40 #include "utilities.h"
42 using namespace SMESH;
44 //=============================================================================
48 //=============================================================================
50 SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
51 : SALOME::GenericObj_i( thePOA ),
52 myMeshServant( theMeshServant ),
53 myLocalID( theLocalID )
55 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i,
56 // servant activation is performed by SMESH_Mesh_i::createGroup()
57 // thePOA->activate_object( this );
60 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
61 : SALOME::GenericObj_i( thePOA ),
62 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
64 MESSAGE("SMESH_Group_i; this = "<<this );
67 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
68 : SALOME::GenericObj_i( thePOA ),
69 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
71 MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
74 //=============================================================================
78 //=============================================================================
80 SMESH_GroupBase_i::~SMESH_GroupBase_i()
82 MESSAGE("~SMESH_GroupBase_i; this = "<<this );
83 // akl: removeGroup() is called from SMESH_Mesh_i() destructor
84 // if ( myMeshServant )
85 // myMeshServant->removeGroup(myLocalID);
88 //=======================================================================
89 //function : GetSmeshGroup
91 //=======================================================================
93 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
95 if ( myMeshServant ) {
96 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
97 return aMesh.GetGroup(myLocalID);
102 //=======================================================================
103 //function : GetGroupDS
105 //=======================================================================
107 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
109 ::SMESH_Group* aGroup = GetSmeshGroup();
111 return aGroup->GetGroupDS();
115 //=============================================================================
119 //=============================================================================
121 void SMESH_GroupBase_i::SetName( const char* theName )
123 // Update Python script
124 TPythonDump() << _this() << ".SetName( '" << theName << "' )";
127 ::SMESH_Group* aGroup = GetSmeshGroup();
129 aGroup->SetName(theName);
131 // Update group name in a study
132 SMESH_Gen_i* aGen = myMeshServant->GetGen();
133 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
136 MESSAGE("can't set name of a vague group");
139 //=============================================================================
143 //=============================================================================
145 char* SMESH_GroupBase_i::GetName()
147 ::SMESH_Group* aGroup = GetSmeshGroup();
149 return CORBA::string_dup (aGroup->GetName());
150 MESSAGE("get name of a vague group");
151 return CORBA::string_dup( "NO_NAME" );
154 //=============================================================================
158 //=============================================================================
160 SMESH::ElementType SMESH_GroupBase_i::GetType()
162 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
164 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
165 SMESH::ElementType aType;
167 case SMDSAbs_Node: aType = SMESH::NODE; break;
168 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
169 case SMDSAbs_Face: aType = SMESH::FACE; break;
170 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
171 default: aType = SMESH::ALL; break;
175 MESSAGE("get type of a vague group");
180 //=============================================================================
184 //=============================================================================
186 CORBA::Long SMESH_GroupBase_i::Size()
188 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
190 return aGroupDS->Extent();
191 MESSAGE("get size of a vague group");
195 //=============================================================================
199 //=============================================================================
201 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
203 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
205 return aGroupDS->IsEmpty();
206 MESSAGE("checking IsEmpty of a vague group");
210 //=============================================================================
214 //=============================================================================
216 void SMESH_Group_i::Clear()
218 // Update Python script
219 TPythonDump() << _this() << ".Clear()";
222 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
227 MESSAGE("attempt to clear a vague group");
230 //=============================================================================
234 //=============================================================================
236 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
238 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
240 return aGroupDS->Contains(theID);
241 MESSAGE("attempt to check contents of a vague group");
245 //=============================================================================
249 //=============================================================================
251 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
253 // Update Python script
254 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
256 // Add elements to the group
257 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
260 for (int i = 0; i < theIDs.length(); i++) {
261 int anID = (int) theIDs[i];
262 if (aGroupDS->Add(anID))
267 MESSAGE("attempt to add elements to a vague group");
271 //=============================================================================
275 //=============================================================================
277 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
279 // Update Python script
280 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
282 // Remove elements from the group
283 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
286 for (int i = 0; i < theIDs.length(); i++) {
287 int anID = (int) theIDs[i];
288 if (aGroupDS->Remove(anID))
293 MESSAGE("attempt to remove elements from a vague group");
297 //=============================================================================
301 //=============================================================================
303 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
306 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
307 SMESHDS_GroupBase* theGroupBase,
308 TFunChangeGroup theFun)
311 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
312 SMESH::Controls::Filter::TIdSequence aSequence;
313 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
314 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
316 CORBA::Long i = 0, iEnd = aSequence.size();
318 if((aGroupDS->*theFun)(aSequence[i]))
327 AddByPredicate( SMESH::Predicate_ptr thePredicate )
329 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
330 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
331 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
338 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
340 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
341 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
342 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
347 //=============================================================================
351 //=============================================================================
353 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
355 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
357 return aGroupDS->GetID(theIndex);
358 MESSAGE("attempt to iterate on a vague group");
362 //=============================================================================
366 //=============================================================================
368 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
370 SMESH::long_array_var aRes = new SMESH::long_array();
371 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
373 int aSize = aGroupDS->Extent();
375 for (int i = 0; i < aSize; i++)
376 aRes[i] = aGroupDS->GetID(i+1);
379 MESSAGE("get list of IDs of a vague group");
383 //=============================================================================
387 //=============================================================================
388 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
390 SMESH::SMESH_Mesh_var aMesh;
392 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
393 return aMesh._retn();
396 //=============================================================================
400 //=============================================================================
401 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
403 SMESH::long_array_var aResult = GetListOfID();
404 return aResult._retn();
407 //=======================================================================
408 //function : GetShape
410 //=======================================================================
412 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
414 GEOM::GEOM_Object_var aGeomObj;
415 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
417 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
418 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
420 return aGeomObj._retn();
423 //=============================================================================
427 //=============================================================================
428 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
430 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
433 Quantity_Color aQColor = aGroupDS->GetColor();
434 SALOMEDS::Color aColor;
435 aColor.R = aQColor.Red();
436 aColor.G = aQColor.Green();
437 aColor.B = aQColor.Blue();
441 MESSAGE("get color of a group");
442 return SALOMEDS::Color();
445 //=============================================================================
449 //=============================================================================
450 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
452 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
455 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
456 return aGroupDS->SetColor(aQColor);
458 MESSAGE("set color of a group");
462 //=============================================================================
466 //=============================================================================
467 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
469 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
471 return aGroupDS->GetColorGroup();
472 MESSAGE("get color number of a group");
476 //=============================================================================
480 //=============================================================================
481 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
483 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
485 return aGroupDS->SetColorGroup(color);
486 MESSAGE("set color number of a group");