Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SMESH_Group_i.hxx"
00029 #include "SMESH_Mesh_i.hxx"
00030 #include "SMESH_Gen_i.hxx"
00031 #include "SMESH_Group.hxx"
00032 #include "SMESHDS_Group.hxx"
00033 #include "SMESHDS_GroupOnGeom.hxx"
00034 #include "SMDSAbs_ElementType.hxx"
00035
00036 #include "SMESH_Filter_i.hxx"
00037 #include "SMESH_PythonDump.hxx"
00038
00039 #include CORBA_SERVER_HEADER(SMESH_Filter)
00040
00041 #include "utilities.h"
00042
00043 using namespace SMESH;
00044
00045
00049
00050
00051 SMESH_GroupBase_i::SMESH_GroupBase_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
00052 : SALOME::GenericObj_i( thePOA ),
00053 myMeshServant( theMeshServant ),
00054 myLocalID( theLocalID )
00055 {
00056
00057
00058
00059 }
00060
00061 SMESH_Group_i::SMESH_Group_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
00062 : SALOME::GenericObj_i( thePOA ),
00063 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
00064 {
00065
00066 }
00067
00068 SMESH_GroupOnGeom_i::SMESH_GroupOnGeom_i( PortableServer::POA_ptr thePOA, SMESH_Mesh_i* theMeshServant, const int theLocalID )
00069 : SALOME::GenericObj_i( thePOA ),
00070 SMESH_GroupBase_i( thePOA, theMeshServant, theLocalID )
00071 {
00072
00073 }
00074
00075
00079
00080
00081 SMESH_GroupBase_i::~SMESH_GroupBase_i()
00082 {
00083 MESSAGE("~SMESH_GroupBase_i; this = "<<this );
00084 if ( myMeshServant )
00085 myMeshServant->removeGroup(myLocalID);
00086 }
00087
00088
00089
00090
00091
00092
00093 ::SMESH_Group* SMESH_GroupBase_i::GetSmeshGroup() const
00094 {
00095 if ( myMeshServant ) {
00096 ::SMESH_Mesh& aMesh = myMeshServant->GetImpl();
00097 return aMesh.GetGroup(myLocalID);
00098 }
00099 return 0;
00100 }
00101
00102
00103
00104
00105
00106
00107 SMESHDS_GroupBase* SMESH_GroupBase_i::GetGroupDS() const
00108 {
00109 ::SMESH_Group* aGroup = GetSmeshGroup();
00110 if ( aGroup )
00111 return aGroup->GetGroupDS();
00112 return 0;
00113 }
00114
00115
00119
00120
00121 void SMESH_GroupBase_i::SetName( const char* theName )
00122 {
00123
00124 ::SMESH_Group* aGroup = GetSmeshGroup();
00125 if (!aGroup) {
00126 MESSAGE("can't set name of a vague group");
00127 return;
00128 }
00129
00130 if ( aGroup->GetName() && !strcmp( aGroup->GetName(), theName ) )
00131 return;
00132
00133 aGroup->SetName(theName);
00134
00135
00136 SMESH_Gen_i* aGen = myMeshServant->GetGen();
00137 aGen->SetName( aGen->ObjectToSObject( aGen->GetCurrentStudy(), _this() ), theName );
00138
00139
00140 TPythonDump() << _this() << ".SetName( '" << theName << "' )";
00141 }
00142
00143
00147
00148
00149 char* SMESH_GroupBase_i::GetName()
00150 {
00151 ::SMESH_Group* aGroup = GetSmeshGroup();
00152 if (aGroup)
00153 return CORBA::string_dup (aGroup->GetName());
00154 MESSAGE("get name of a vague group");
00155 return CORBA::string_dup( "NO_NAME" );
00156 }
00157
00158
00162
00163
00164 SMESH::ElementType SMESH_GroupBase_i::GetType()
00165 {
00166 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00167 if (aGroupDS) {
00168 SMDSAbs_ElementType aSMDSType = aGroupDS->GetType();
00169 SMESH::ElementType aType;
00170 switch (aSMDSType) {
00171 case SMDSAbs_Node: aType = SMESH::NODE; break;
00172 case SMDSAbs_Edge: aType = SMESH::EDGE; break;
00173 case SMDSAbs_Face: aType = SMESH::FACE; break;
00174 case SMDSAbs_Volume: aType = SMESH::VOLUME; break;
00175 case SMDSAbs_0DElement: aType = SMESH::ELEM0D; break;
00176 default: aType = SMESH::ALL; break;
00177 }
00178 return aType;
00179 }
00180 MESSAGE("get type of a vague group");
00181 return SMESH::ALL;
00182 }
00183
00184
00185
00189
00190
00191 CORBA::Long SMESH_GroupBase_i::Size()
00192 {
00193 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00194 if (aGroupDS)
00195 return aGroupDS->Extent();
00196 MESSAGE("get size of a vague group");
00197 return 0;
00198 }
00199
00200
00204
00205
00206 CORBA::Boolean SMESH_GroupBase_i::IsEmpty()
00207 {
00208 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00209 if (aGroupDS)
00210 return aGroupDS->IsEmpty();
00211 MESSAGE("checking IsEmpty of a vague group");
00212 return true;
00213 }
00214
00215
00219
00220
00221 void SMESH_Group_i::Clear()
00222 {
00223
00224 TPythonDump() << _this() << ".Clear()";
00225
00226
00227 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
00228 if (aGroupDS) {
00229 aGroupDS->Clear();
00230 return;
00231 }
00232 MESSAGE("attempt to clear a vague group");
00233 }
00234
00235
00239
00240
00241 CORBA::Boolean SMESH_GroupBase_i::Contains( CORBA::Long theID )
00242 {
00243 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00244 if (aGroupDS)
00245 return aGroupDS->Contains(theID);
00246 MESSAGE("attempt to check contents of a vague group");
00247 return false;
00248 }
00249
00250
00254
00255
00256 CORBA::Long SMESH_Group_i::Add( const SMESH::long_array& theIDs )
00257 {
00258
00259 TPythonDump() << "nbAdd = " << _this() << ".Add( " << theIDs << " )";
00260
00261
00262 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
00263 if (aGroupDS) {
00264 int nbAdd = 0;
00265 for (int i = 0; i < theIDs.length(); i++) {
00266 int anID = (int) theIDs[i];
00267 if (aGroupDS->Add(anID))
00268 nbAdd++;
00269 }
00270 return nbAdd;
00271 }
00272 MESSAGE("attempt to add elements to a vague group");
00273 return 0;
00274 }
00275
00276
00280
00281
00282 CORBA::Long SMESH_Group_i::Remove( const SMESH::long_array& theIDs )
00283 {
00284
00285 TPythonDump() << "nbDel = " << _this() << ".Remove( " << theIDs << " )";
00286
00287
00288 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
00289 if (aGroupDS) {
00290 int nbDel = 0;
00291 for (int i = 0; i < theIDs.length(); i++) {
00292 int anID = (int) theIDs[i];
00293 if (aGroupDS->Remove(anID))
00294 nbDel++;
00295 }
00296 return nbDel;
00297 }
00298 MESSAGE("attempt to remove elements from a vague group");
00299 return 0;
00300 }
00301
00302
00306
00307
00308 typedef bool (SMESHDS_Group::*TFunChangeGroup)(const int);
00309
00310 CORBA::Long
00311 ChangeByPredicate( SMESH::Predicate_i* thePredicate,
00312 SMESHDS_GroupBase* theGroupBase,
00313 TFunChangeGroup theFun)
00314 {
00315 CORBA::Long aNb = 0;
00316 if(SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>(theGroupBase)){
00317 SMESH::Controls::Filter::TIdSequence aSequence;
00318 const SMDS_Mesh* aMesh = theGroupBase->GetMesh();
00319 SMESH::Filter_i::GetElementsId(thePredicate,aMesh,aSequence);
00320
00321 CORBA::Long i = 0, iEnd = aSequence.size();
00322 for(; i < iEnd; i++)
00323 if((aGroupDS->*theFun)(aSequence[i]))
00324 aNb++;
00325 return aNb;
00326 }
00327 return aNb;
00328 }
00329
00330 CORBA::Long
00331 SMESH_Group_i::
00332 AddByPredicate( SMESH::Predicate_ptr thePredicate )
00333 {
00334 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
00335 TPythonDump()<<_this()<<".AddByPredicate("<<aPredicate<<")";
00336 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Add);
00337 }
00338 return 0;
00339 }
00340
00341 CORBA::Long
00342 SMESH_Group_i::
00343 RemoveByPredicate( SMESH::Predicate_ptr thePredicate )
00344 {
00345 if(SMESH::Predicate_i* aPredicate = SMESH::GetPredicate(thePredicate)){
00346 TPythonDump()<<_this()<<".RemoveByPredicate("<<aPredicate<<")";
00347 return ChangeByPredicate(aPredicate,GetGroupDS(),&SMESHDS_Group::Remove);
00348 }
00349 return 0;
00350 }
00351
00352 CORBA::Long SMESH_Group_i::AddFrom( SMESH::SMESH_IDSource_ptr theSource )
00353 {
00354 long nbAdd = 0;
00355 SMESHDS_Group* aGroupDS = dynamic_cast<SMESHDS_Group*>( GetGroupDS() );
00356 if (aGroupDS) {
00357 SMESH::long_array_var anIds;
00358 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theSource);
00359 SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow(theSource);
00360 SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow(theSource);
00361 SMESH::Filter_var filter = SMESH::Filter::_narrow(theSource);
00362 if ( !group->_is_nil())
00363 anIds = group->GetType()==GetType() ? theSource->GetIDs() : new SMESH::long_array();
00364 else if ( !mesh->_is_nil() )
00365 anIds = mesh->GetElementsByType( GetType() );
00366 else if ( !submesh->_is_nil())
00367 anIds = submesh->GetElementsByType( GetType() );
00368 else if ( !filter->_is_nil() )
00369 anIds = filter->GetElementType()==GetType() ? theSource->GetIDs() : new SMESH::long_array();
00370 else
00371 anIds = theSource->GetIDs();
00372 for ( int i = 0, total = anIds->length(); i < total; i++ ) {
00373 if ( aGroupDS->Add((int)anIds[i]) ) nbAdd++;
00374 }
00375 }
00376
00377
00378 TPythonDump() << "nbAdd = " << _this() << ".AddFrom( " << theSource << " )";
00379
00380 return nbAdd;
00381 }
00382
00383
00387
00388
00389 CORBA::Long SMESH_GroupBase_i::GetID( CORBA::Long theIndex )
00390 {
00391 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00392 if (aGroupDS)
00393 return aGroupDS->GetID(theIndex);
00394 MESSAGE("attempt to iterate on a vague group");
00395 return -1;
00396 }
00397
00398
00402
00403
00404 SMESH::long_array* SMESH_GroupBase_i::GetListOfID()
00405 {
00406 SMESH::long_array_var aRes = new SMESH::long_array();
00407 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00408 if (aGroupDS) {
00409 int aSize = aGroupDS->Extent();
00410 aRes->length(aSize);
00411 for (int i = 0; i < aSize; i++)
00412 aRes[i] = aGroupDS->GetID(i+1);
00413 return aRes._retn();
00414 }
00415 MESSAGE("get list of IDs of a vague group");
00416 return aRes._retn();
00417 }
00418
00419
00423
00424 SMESH::SMESH_Mesh_ptr SMESH_GroupBase_i::GetMesh()
00425 {
00426 SMESH::SMESH_Mesh_var aMesh;
00427 if ( myMeshServant )
00428 aMesh = SMESH::SMESH_Mesh::_narrow( myMeshServant->_this() );
00429 return aMesh._retn();
00430 }
00431
00432
00433
00434
00435
00436
00437 GEOM::GEOM_Object_ptr SMESH_GroupOnGeom_i::GetShape()
00438 {
00439 GEOM::GEOM_Object_var aGeomObj;
00440 SMESHDS_GroupOnGeom* aGroupDS = dynamic_cast<SMESHDS_GroupOnGeom*>( GetGroupDS() );
00441 if ( aGroupDS ) {
00442 SMESH_Gen_i* aGen = GetMeshServant()->GetGen();
00443 aGeomObj = aGen->ShapeToGeomObject( aGroupDS->GetShape() );
00444 }
00445 return aGeomObj._retn();
00446 }
00447
00448
00452
00453 SALOMEDS::Color SMESH_GroupBase_i::GetColor()
00454 {
00455 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00456 if (aGroupDS)
00457 {
00458 Quantity_Color aQColor = aGroupDS->GetColor();
00459 SALOMEDS::Color aColor;
00460 aColor.R = aQColor.Red();
00461 aColor.G = aQColor.Green();
00462 aColor.B = aQColor.Blue();
00463
00464 return aColor;
00465 }
00466 MESSAGE("get color of a group");
00467 return SALOMEDS::Color();
00468 }
00469
00470
00474
00475 void SMESH_GroupBase_i::SetColor(const SALOMEDS::Color& color)
00476 {
00477 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00478 if (aGroupDS)
00479 {
00480 Quantity_Color aQColor( color.R, color.G, color.B, Quantity_TOC_RGB );
00481 aGroupDS->SetColor(aQColor);
00482 TPythonDump()<<_this()<<".SetColor( SALOMEDS.Color( "<<color.R<<", "<<color.G<<", "<<color.B<<" ))";
00483 }
00484 }
00485
00486
00490
00491 CORBA::Long SMESH_GroupBase_i::GetColorNumber()
00492 {
00493 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00494 if (aGroupDS)
00495 return aGroupDS->GetColorGroup();
00496 MESSAGE("get color number of a group");
00497 return 0;
00498 }
00499
00500
00504
00505 void SMESH_GroupBase_i::SetColorNumber(CORBA::Long color)
00506 {
00507 SMESHDS_GroupBase* aGroupDS = GetGroupDS();
00508 if (aGroupDS)
00509 {
00510 aGroupDS->SetColorGroup(color);
00511 TPythonDump()<<_this()<<".SetColorNumber( "<<color<<" )";
00512 }
00513 MESSAGE("set color number of a group");
00514 return ;
00515 }
00516
00517
00523
00524 SMESH::long_array* SMESH_GroupBase_i::GetMeshInfo()
00525 {
00526 SMESH::long_array_var aRes = new SMESH::long_array();
00527 aRes->length(SMESH::Entity_Last);
00528 for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
00529 aRes[i] = 0;
00530
00531 SMESHDS_GroupBase* aGrpDS = GetGroupDS();
00532 if ( !aGrpDS )
00533 return aRes._retn();
00534 if ( GetType() == NODE )
00535 aRes[ SMESH::Entity_Node ] = aGrpDS->Extent();
00536 else
00537 SMESH_Mesh_i::CollectMeshInfo( aGrpDS->GetElements(), aRes);
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553 return aRes._retn();
00554 }
00555
00556
00557
00558
00559
00560
00561 SMESH::long_array* SMESH_GroupBase_i::GetIDs()
00562 {
00563 SMESH::long_array_var aResult = GetListOfID();
00564 return aResult._retn();
00565 }
00566
00567
00568
00569
00570
00571
00572 SMESH::array_of_ElementType* SMESH_GroupBase_i::GetTypes()
00573 {
00574 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
00575 if ( SMESHDS_GroupBase* ds = GetGroupDS() )
00576 if ( !ds->IsEmpty() )
00577 {
00578 types->length( 1 );
00579 types[0] = GetType();
00580 }
00581 return types._retn();
00582 }
00583