1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
23 // File : SMESH_Group_i.cxx
24 // Author : Sergey ANIKIN, OCC
27 #include "SMESH_Group_i.hxx"
28 #include "SMESH_Mesh_i.hxx"
29 #include "SMESH_Gen_i.hxx"
30 #include "SMESH_Group.hxx"
31 #include "SMESHDS_Group.hxx"
32 #include "SMESHDS_GroupOnGeom.hxx"
33 #include "SMDSAbs_ElementType.hxx"
35 #include "SMESH_Filter_i.hxx"
36 #include "SMESH_PythonDump.hxx"
38 #include "utilities.h"
40 using namespace SMESH;
42 //=============================================================================
46 //=============================================================================
48 SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
49 : SALOME::GenericObj_i( thePOA ),
50 myMeshServant( theMeshServant ),
51 myLocalID( theLocalID )
53 // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i,
54 // servant activation is performed by SMESH_Mesh_i::createGroup()
55 // thePOA->activate_object( this );
58 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
59 : SALOME::GenericObj_i( thePOA ),
60 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
62 //MESSAGE("SMESH_Group_i; this = "<<this );
65 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
66 : SALOME::GenericObj_i( thePOA ),
67 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
69 //MESSAGE("SMESH_GroupOnGeom_i; this = "<<this );
72 //=============================================================================
76 //=============================================================================
78 SMESH_GroupBase_i::~SMESH_GroupBase_i()
80 MESSAGE("~SMESH_GroupBase_i; this = "<<this );
82 myMeshServant->removeGroup(myLocalID);
85 //=======================================================================
86 //function : GetSmeshGroup
88 //=======================================================================
90 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
92 if ( myMeshServant ) {
93 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
94 return aMesh.GetGroup(myLocalID);
99 //=======================================================================
100 //function : GetGroupDS
102 //=======================================================================
104 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
106 ::SMESH_Group* aGroup = GetSmeshGroup();
108 return aGroup->GetGroupDS();
112 //=============================================================================
116 //=============================================================================
118 void SMESH_GroupBase_i::SetName( const char* theName )
121 ::SMESH_Group* aGroup = GetSmeshGroup();
123 MESSAGE("can't set name of a vague group");
127 if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
128 return; // nothing to rename
130 aGroup->SetName(theName);
132 // Update group name in a study
133 SMESH_Gen_i* aGen = myMeshServant->GetGen();
134 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
136 // Update Python script
137 TPythonDump() << _this() << ".SetName( '" << theName << "' )";
140 //=============================================================================
144 //=============================================================================
146 char* SMESH_GroupBase_i::GetName()
148 ::SMESH_Group* aGroup = GetSmeshGroup();
150 return CORBA::string_dup (aGroup->GetName());
151 MESSAGE("get name of a vague group");
152 return CORBA::string_dup( "NO_NAME" );
155 //=============================================================================
159 //=============================================================================
161 SMESH::ElementType SMESH_GroupBase_i::GetType()
163 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
165 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
166 SMESH::ElementType aType;
168 case SMDSAbs_Node: aType = SMESH::NODE; break;
169 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
170 case SMDSAbs_Face: aType = SMESH::FACE; break;
171 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
172 default: aType = SMESH::ALL; break;
176 MESSAGE("get type of a vague group");
181 //=============================================================================
185 //=============================================================================
187 CORBA::Long SMESH_GroupBase_i::Size()
189 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
191 return aGroupDS->Extent();
192 MESSAGE("get size of a vague group");
196 //=============================================================================
200 //=============================================================================
202 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
204 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
206 return aGroupDS->IsEmpty();
207 MESSAGE("checking IsEmpty of a vague group");
211 //=============================================================================
215 //=============================================================================
217 void SMESH_Group_i::Clear()
219 // Update Python script
220 TPythonDump() << _this() << ".Clear()";
223 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
228 MESSAGE("attempt to clear a vague group");
231 //=============================================================================
235 //=============================================================================
237 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
239 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
241 return aGroupDS->Contains(theID);
242 MESSAGE("attempt to check contents of a vague group");
246 //=============================================================================
250 //=============================================================================
252 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
254 // Update Python script
255 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
257 // Add elements to the group
258 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
261 for (int i = 0; i < theIDs.length(); i++) {
262 int anID = (int) theIDs[i];
263 if (aGroupDS->Add(anID))
268 MESSAGE("attempt to add elements to a vague group");
272 //=============================================================================
276 //=============================================================================
278 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
280 // Update Python script
281 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
283 // Remove elements from the group
284 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
287 for (int i = 0; i < theIDs.length(); i++) {
288 int anID = (int) theIDs[i];
289 if (aGroupDS->Remove(anID))
294 MESSAGE("attempt to remove elements from a vague group");
298 //=============================================================================
302 //=============================================================================
304 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
307 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
308 SMESHDS_GroupBase* theGroupBase,
309 TFunChangeGroup theFun)
312 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
313 SMESH::Controls::Filter::TIdSequence aSequence;
314 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
315 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
317 CORBA::Long i = 0, iEnd = aSequence.size();
319 if((aGroupDS->*theFun)(aSequence[i]))
328 AddByPredicate( SMESH::Predicate_ptr thePredicate )
330 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
331 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
332 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
339 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
341 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
342 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
343 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
348 //=============================================================================
352 //=============================================================================
354 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
356 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
358 return aGroupDS->GetID(theIndex);
359 MESSAGE("attempt to iterate on a vague group");
363 //=============================================================================
367 //=============================================================================
369 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
371 SMESH::long_array_var aRes = new SMESH::long_array();
372 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
374 int aSize = aGroupDS->Extent();
376 for (int i = 0; i < aSize; i++)
377 aRes[i] = aGroupDS->GetID(i+1);
380 MESSAGE("get list of IDs of a vague group");
384 //=============================================================================
388 //=============================================================================
389 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
391 SMESH::SMESH_Mesh_var aMesh;
393 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
394 return aMesh._retn();
397 //=============================================================================
401 //=============================================================================
402 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
404 SMESH::long_array_var aResult = GetListOfID();
405 return aResult._retn();
408 //=======================================================================
409 //function : GetShape
411 //=======================================================================
413 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
415 GEOM::GEOM_Object_var aGeomObj;
416 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
418 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
419 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
421 return aGeomObj._retn();
424 //=============================================================================
428 //=============================================================================
429 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
431 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
434 Quantity_Color aQColor = aGroupDS->GetColor();
435 SALOMEDS::Color aColor;
436 aColor.R = aQColor.Red();
437 aColor.G = aQColor.Green();
438 aColor.B = aQColor.Blue();
442 MESSAGE("get color of a group");
443 return SALOMEDS::Color();
446 //=============================================================================
450 //=============================================================================
451 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
453 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
456 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
457 return aGroupDS->SetColor(aQColor);
459 MESSAGE("set color of a group");
463 //=============================================================================
467 //=============================================================================
468 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
470 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
472 return aGroupDS->GetColorGroup();
473 MESSAGE("get color number of a group");
477 //=============================================================================
481 //=============================================================================
482 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
484 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
486 return aGroupDS->SetColorGroup(color);
487 MESSAGE("set color number of a group");