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 );
84 myMeshServant->removeGroup(myLocalID);
87 //=======================================================================
88 //function : GetSmeshGroup
90 //=======================================================================
92 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
94 if ( myMeshServant ) {
95 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
96 return aMesh.GetGroup(myLocalID);
101 //=======================================================================
102 //function : GetGroupDS
104 //=======================================================================
106 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
108 ::SMESH_Group* aGroup = GetSmeshGroup();
110 return aGroup->GetGroupDS();
114 //=============================================================================
118 //=============================================================================
120 void SMESH_GroupBase_i::SetName( const char* theName )
123 ::SMESH_Group* aGroup = GetSmeshGroup();
125 MESSAGE("can't set name of a vague group");
129 if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
130 return; // nothing to rename
132 aGroup->SetName(theName);
134 // Update group name in a study
135 SMESH_Gen_i* aGen = myMeshServant->GetGen();
136 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
138 // Update Python script
139 TPythonDump() << _this() << ".SetName( '" << theName << "' )";
142 //=============================================================================
146 //=============================================================================
148 char* SMESH_GroupBase_i::GetName()
150 ::SMESH_Group* aGroup = GetSmeshGroup();
152 return CORBA::string_dup (aGroup->GetName());
153 MESSAGE("get name of a vague group");
154 return CORBA::string_dup( "NO_NAME" );
157 //=============================================================================
161 //=============================================================================
163 SMESH::ElementType SMESH_GroupBase_i::GetType()
165 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
167 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
168 SMESH::ElementType aType;
170 case SMDSAbs_Node: aType = SMESH::NODE; break;
171 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
172 case SMDSAbs_Face: aType = SMESH::FACE; break;
173 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
174 default: aType = SMESH::ALL; break;
178 MESSAGE("get type of a vague group");
183 //=============================================================================
187 //=============================================================================
189 CORBA::Long SMESH_GroupBase_i::Size()
191 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
193 return aGroupDS->Extent();
194 MESSAGE("get size of a vague group");
198 //=============================================================================
202 //=============================================================================
204 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
206 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
208 return aGroupDS->IsEmpty();
209 MESSAGE("checking IsEmpty of a vague group");
213 //=============================================================================
217 //=============================================================================
219 void SMESH_Group_i::Clear()
221 // Update Python script
222 TPythonDump() << _this() << ".Clear()";
225 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
230 MESSAGE("attempt to clear a vague group");
233 //=============================================================================
237 //=============================================================================
239 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
241 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
243 return aGroupDS->Contains(theID);
244 MESSAGE("attempt to check contents of a vague group");
248 //=============================================================================
252 //=============================================================================
254 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
256 // Update Python script
257 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
259 // Add elements to the group
260 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
263 for (int i = 0; i < theIDs.length(); i++) {
264 int anID = (int) theIDs[i];
265 if (aGroupDS->Add(anID))
270 MESSAGE("attempt to add elements to a vague group");
274 //=============================================================================
278 //=============================================================================
280 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
282 // Update Python script
283 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
285 // Remove elements from the group
286 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
289 for (int i = 0; i < theIDs.length(); i++) {
290 int anID = (int) theIDs[i];
291 if (aGroupDS->Remove(anID))
296 MESSAGE("attempt to remove elements from a vague group");
300 //=============================================================================
304 //=============================================================================
306 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
309 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
310 SMESHDS_GroupBase* theGroupBase,
311 TFunChangeGroup theFun)
314 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
315 SMESH::Controls::Filter::TIdSequence aSequence;
316 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
317 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
319 CORBA::Long i = 0, iEnd = aSequence.size();
321 if((aGroupDS->*theFun)(aSequence[i]))
330 AddByPredicate( SMESH::Predicate_ptr thePredicate )
332 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
333 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
334 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
341 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
343 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
344 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
345 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
350 //=============================================================================
354 //=============================================================================
356 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
358 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
360 return aGroupDS->GetID(theIndex);
361 MESSAGE("attempt to iterate on a vague group");
365 //=============================================================================
369 //=============================================================================
371 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
373 SMESH::long_array_var aRes = new SMESH::long_array();
374 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
376 int aSize = aGroupDS->Extent();
378 for (int i = 0; i < aSize; i++)
379 aRes[i] = aGroupDS->GetID(i+1);
382 MESSAGE("get list of IDs of a vague group");
386 //=============================================================================
390 //=============================================================================
391 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
393 SMESH::SMESH_Mesh_var aMesh;
395 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
396 return aMesh._retn();
399 //=============================================================================
403 //=============================================================================
404 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
406 SMESH::long_array_var aResult = GetListOfID();
407 return aResult._retn();
410 //=======================================================================
411 //function : GetShape
413 //=======================================================================
415 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
417 GEOM::GEOM_Object_var aGeomObj;
418 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
420 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
421 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
423 return aGeomObj._retn();
426 //=============================================================================
430 //=============================================================================
431 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
433 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
436 Quantity_Color aQColor = aGroupDS->GetColor();
437 SALOMEDS::Color aColor;
438 aColor.R = aQColor.Red();
439 aColor.G = aQColor.Green();
440 aColor.B = aQColor.Blue();
444 MESSAGE("get color of a group");
445 return SALOMEDS::Color();
448 //=============================================================================
452 //=============================================================================
453 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
455 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
458 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
459 return aGroupDS->SetColor(aQColor);
461 MESSAGE("set color of a group");
465 //=============================================================================
469 //=============================================================================
470 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
472 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
474 return aGroupDS->GetColorGroup();
475 MESSAGE("get color number of a group");
479 //=============================================================================
483 //=============================================================================
484 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
486 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
488 return aGroupDS->SetColorGroup(color);
489 MESSAGE("set color number of a group");