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 case SMDSAbs_0DElement: aType = SMESH::ELEM0D; break;
173 default: aType = SMESH::ALL; break;
177 MESSAGE("get type of a vague group");
182 //=============================================================================
186 //=============================================================================
188 CORBA::Long SMESH_GroupBase_i::Size()
190 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
192 return aGroupDS->Extent();
193 MESSAGE("get size of a vague group");
197 //=============================================================================
201 //=============================================================================
203 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
205 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
207 return aGroupDS->IsEmpty();
208 MESSAGE("checking IsEmpty of a vague group");
212 //=============================================================================
216 //=============================================================================
218 void SMESH_Group_i::Clear()
220 // Update Python script
221 TPythonDump() << _this() << ".Clear()";
224 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
229 MESSAGE("attempt to clear a vague group");
232 //=============================================================================
236 //=============================================================================
238 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
240 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
242 return aGroupDS->Contains(theID);
243 MESSAGE("attempt to check contents of a vague group");
247 //=============================================================================
251 //=============================================================================
253 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
255 // Update Python script
256 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
258 // Add elements to the group
259 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
262 for (int i = 0; i < theIDs.length(); i++) {
263 int anID = (int) theIDs[i];
264 if (aGroupDS->Add(anID))
269 MESSAGE("attempt to add elements to a vague group");
273 //=============================================================================
277 //=============================================================================
279 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
281 // Update Python script
282 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
284 // Remove elements from the group
285 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
288 for (int i = 0; i < theIDs.length(); i++) {
289 int anID = (int) theIDs[i];
290 if (aGroupDS->Remove(anID))
295 MESSAGE("attempt to remove elements from a vague group");
299 //=============================================================================
303 //=============================================================================
305 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
308 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
309 SMESHDS_GroupBase* theGroupBase,
310 TFunChangeGroup theFun)
313 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
314 SMESH::Controls::Filter::TIdSequence aSequence;
315 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
316 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
318 CORBA::Long i = 0, iEnd = aSequence.size();
320 if((aGroupDS->*theFun)(aSequence[i]))
329 AddByPredicate( SMESH::Predicate_ptr thePredicate )
331 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
332 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
333 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
340 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
342 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
343 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
344 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
349 //=============================================================================
353 //=============================================================================
355 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
357 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
359 return aGroupDS->GetID(theIndex);
360 MESSAGE("attempt to iterate on a vague group");
364 //=============================================================================
368 //=============================================================================
370 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
372 SMESH::long_array_var aRes = new SMESH::long_array();
373 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
375 int aSize = aGroupDS->Extent();
377 for (int i = 0; i < aSize; i++)
378 aRes[i] = aGroupDS->GetID(i+1);
381 MESSAGE("get list of IDs of a vague group");
385 //=============================================================================
389 //=============================================================================
390 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
392 SMESH::SMESH_Mesh_var aMesh;
394 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
395 return aMesh._retn();
398 //=============================================================================
402 //=============================================================================
403 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
405 SMESH::long_array_var aResult = GetListOfID();
406 return aResult._retn();
409 //=======================================================================
410 //function : GetShape
412 //=======================================================================
414 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
416 GEOM::GEOM_Object_var aGeomObj;
417 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
419 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
420 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
422 return aGeomObj._retn();
425 //=============================================================================
429 //=============================================================================
430 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
432 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
435 Quantity_Color aQColor = aGroupDS->GetColor();
436 SALOMEDS::Color aColor;
437 aColor.R = aQColor.Red();
438 aColor.G = aQColor.Green();
439 aColor.B = aQColor.Blue();
443 MESSAGE("get color of a group");
444 return SALOMEDS::Color();
447 //=============================================================================
451 //=============================================================================
452 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
454 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
457 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
458 return aGroupDS->SetColor(aQColor);
460 MESSAGE("set color of a group");
464 //=============================================================================
468 //=============================================================================
469 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
471 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
473 return aGroupDS->GetColorGroup();
474 MESSAGE("get color number of a group");
478 //=============================================================================
482 //=============================================================================
483 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
485 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
487 return aGroupDS->SetColorGroup(color);
488 MESSAGE("set color number of a group");
492 //=============================================================================
494 * Returns statistic of mesh elements
495 * Result array of number enityties
496 * Inherited from SMESH_IDSource
498 //=============================================================================
499 SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
501 SMESH::long_array_var aRes = new SMESH::long_array();
502 aRes->length(SMESH::Entity_Last);
503 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
506 SMESHDS_GroupBase* aGrpDS = GetGroupDS();
509 if ( GetType() == NODE )
510 aRes[ SMESH::Entity_Node ] = aGrpDS->Extent();
512 SMESH_Mesh_i::CollectMeshInfo( aGrpDS->GetElements(), aRes);