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 )
122 // Update Python script
123 TPythonDump() << _this() << ".SetName( '" << theName << "' )";
126 ::SMESH_Group* aGroup = GetSmeshGroup();
128 aGroup->SetName(theName);
130 // Update group name in a study
131 SMESH_Gen_i* aGen = myMeshServant->GetGen();
132 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
135 MESSAGE("can't set name of a vague group");
138 //=============================================================================
142 //=============================================================================
144 char* SMESH_GroupBase_i::GetName()
146 ::SMESH_Group* aGroup = GetSmeshGroup();
148 return CORBA::string_dup (aGroup->GetName());
149 MESSAGE("get name of a vague group");
150 return CORBA::string_dup( "NO_NAME" );
153 //=============================================================================
157 //=============================================================================
159 SMESH::ElementType SMESH_GroupBase_i::GetType()
161 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
163 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
164 SMESH::ElementType aType;
166 case SMDSAbs_Node: aType = SMESH::NODE; break;
167 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
168 case SMDSAbs_Face: aType = SMESH::FACE; break;
169 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
170 default: aType = SMESH::ALL; break;
174 MESSAGE("get type of a vague group");
179 //=============================================================================
183 //=============================================================================
185 CORBA::Long SMESH_GroupBase_i::Size()
187 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
189 return aGroupDS->Extent();
190 MESSAGE("get size of a vague group");
194 //=============================================================================
198 //=============================================================================
200 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
202 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
204 return aGroupDS->IsEmpty();
205 MESSAGE("checking IsEmpty of a vague group");
209 //=============================================================================
213 //=============================================================================
215 void SMESH_Group_i::Clear()
217 // Update Python script
218 TPythonDump() << _this() << ".Clear()";
221 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
226 MESSAGE("attempt to clear a vague group");
229 //=============================================================================
233 //=============================================================================
235 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
237 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
239 return aGroupDS->Contains(theID);
240 MESSAGE("attempt to check contents of a vague group");
244 //=============================================================================
248 //=============================================================================
250 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
252 // Update Python script
253 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
255 // Add elements to the group
256 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
259 for (int i = 0; i < theIDs.length(); i++) {
260 int anID = (int) theIDs[i];
261 if (aGroupDS->Add(anID))
266 MESSAGE("attempt to add elements to a vague group");
270 //=============================================================================
274 //=============================================================================
276 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
278 // Update Python script
279 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
281 // Remove elements from the group
282 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
285 for (int i = 0; i < theIDs.length(); i++) {
286 int anID = (int) theIDs[i];
287 if (aGroupDS->Remove(anID))
292 MESSAGE("attempt to remove elements from a vague group");
296 //=============================================================================
300 //=============================================================================
302 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
305 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
306 SMESHDS_GroupBase* theGroupBase,
307 TFunChangeGroup theFun)
310 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
311 SMESH::Controls::Filter::TIdSequence aSequence;
312 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
313 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
315 CORBA::Long i = 0, iEnd = aSequence.size();
317 if((aGroupDS->*theFun)(aSequence[i]))
326 AddByPredicate( SMESH::Predicate_ptr thePredicate )
328 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
329 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
330 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
337 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
339 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
340 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
341 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
346 //=============================================================================
350 //=============================================================================
352 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
354 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
356 return aGroupDS->GetID(theIndex);
357 MESSAGE("attempt to iterate on a vague group");
361 //=============================================================================
365 //=============================================================================
367 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
369 SMESH::long_array_var aRes = new SMESH::long_array();
370 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
372 int aSize = aGroupDS->Extent();
374 for (int i = 0; i < aSize; i++)
375 aRes[i] = aGroupDS->GetID(i+1);
378 MESSAGE("get list of IDs of a vague group");
382 //=============================================================================
386 //=============================================================================
387 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
389 SMESH::SMESH_Mesh_var aMesh;
391 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
392 return aMesh._retn();
395 //=============================================================================
399 //=============================================================================
400 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
402 SMESH::long_array_var aResult = GetListOfID();
403 return aResult._retn();
406 //=======================================================================
407 //function : GetShape
409 //=======================================================================
411 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
413 GEOM::GEOM_Object_var aGeomObj;
414 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
416 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
417 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
419 return aGeomObj._retn();
422 //=============================================================================
426 //=============================================================================
427 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
429 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
432 Quantity_Color aQColor = aGroupDS->GetColor();
433 SALOMEDS::Color aColor;
434 aColor.R = aQColor.Red();
435 aColor.G = aQColor.Green();
436 aColor.B = aQColor.Blue();
440 MESSAGE("get color of a group");
441 return SALOMEDS::Color();
444 //=============================================================================
448 //=============================================================================
449 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
451 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
454 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
455 return aGroupDS->SetColor(aQColor);
457 MESSAGE("set color of a group");
461 //=============================================================================
465 //=============================================================================
466 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
468 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
470 return aGroupDS->GetColorGroup();
471 MESSAGE("get color number of a group");
475 //=============================================================================
479 //=============================================================================
480 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
482 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
484 return aGroupDS->SetColorGroup(color);
485 MESSAGE("set color number of a group");