-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <vtkActorCollection.h>
// OCCT includes
+#include <TColStd_MapOfAsciiString.hxx>
#include <TColStd_MapOfInteger.hxx>
// Qt includes
QString aName = "";
// collect all object names of SMESH component
- SalomeApp_Study* appStudy =
- dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
- if ( !appStudy ) return aName;
- _PTR(Study) aStudy = appStudy->studyDS();
+ _PTR(Study) aStudy = SMESH::getStudy();
std::set<std::string> aSet;
_PTR(SComponent) aMeshCompo (aStudy->FindComponent( "SMESH" ));
bool isUnique = false;
while (!isUnique) {
aName = theOperation + "_" + QString::number(++aNumber);
- isUnique = (aSet.count(std::string(SMESH::toUtf8(aName))) == 0);
+ isUnique = (aSet.count(std::string(aName.toUtf8().constData())) == 0);
}
return aName;
}
+//=======================================================================
+//function : setDefaultName
+//purpose :
+//=======================================================================
+
void SMESHGUI_GroupDlg::setDefaultName() const
{
QString aResName;
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
- int i=1;
- QString aPrefix ="Group_";
- _PTR(SObject) anObj;
- do
+ const QString aPrefix ="Group_";
+
+ if ( myMesh->_is_nil() )
{
- aResName = aPrefix + QString::number( i++ );
- anObj = aStudy->FindObject( SMESH::toUtf8(aResName) );
+ aResName = aPrefix + "1";
}
- while ( anObj );
- myName->setText(aResName);
+ else
+ {
+ SMESH::ListOfGroups_var allGroups = myMesh->GetGroups();
+ TColStd_MapOfAsciiString allNames( allGroups->length() );
+ for ( CORBA::ULong i = 0; i < allGroups->length(); ++i )
+ {
+ CORBA::String_var name = allGroups[i]->GetName();
+ allNames.Add( name.in() );
+ }
+ int i = 1;
+ while ( true )
+ {
+ aResName = aPrefix + QString::number( i++ );
+ if ( !allNames.Contains( aResName.toUtf8().constData() ))
+ break;
+ }
+ }
+ myName->setText(aResName);
}
//=================================================================================
SALOMEDS::Color aColor = theGroup->GetColor();
setGroupColor( aColor );
- myMeshGroupLine->setText(SMESH::fromUtf8(theGroup->GetName()));
+ myMeshGroupLine->setText(theGroup->GetName());
int aType = 0;
switch(theGroup->GetType()) {
else if ( grpType == 1 ) // group on geom
{
QString aShapeName( "" );
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ _PTR(Study) aStudy = SMESH::getStudy();
GEOM::GEOM_Object_var aGroupShape = myGroupOnGeom->GetShape();
if (!aGroupShape->_is_nil())
{
{
myNameChanged = true;
myName->blockSignals(true);
- myName->setText(SMESH::fromUtf8(theGroup->GetName()));
+ myName->setText(theGroup->GetName());
myName->blockSignals(false);
}
//=================================================================================
bool SMESHGUI_GroupDlg::onApply()
{
- if (mySMESHGUI->isActiveStudyLocked())
+ if (SMESHGUI::isStudyLocked())
return false;
if (myName->text().trimmed().isEmpty())
if (myGroup->_is_nil()) { // creation or conversion
// check if group on geometry is not null
- if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil()) {
+ if (!myGroupOnGeom->_is_nil() || !myGroupOnFilter->_is_nil())
+ {
if (myMesh->_is_nil())
return false;
if ( myGroupOnGeom->_is_nil() )
}
}
- if (myGroup->_is_nil()) { // creation
+ if (myGroup->_is_nil()) // creation
+ {
if (myMesh->_is_nil())
return false;
myGroup->Add(anIdList.inout());
}
}
+ }
-
- } else { // edition
-
+ else // edition
+ {
resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroup );
isCreation = false;
if (myMesh->_is_nil() || !myGeomObjects->length())
return false;
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ _PTR(Study) aStudy = SMESH::getStudy();
if (myGeomObjects->length() == 1) {
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
- SMESH::toUtf8(myName->text()),
+ myName->text().toUtf8(),
myGeomObjects[0]);
}
else {
SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
- if ( aSMESHGen->_is_nil() )
+ if ( aSMESHGen->_is_nil() || myGeomObjects->length() == 0 )
return false;
// create a geometry group
- GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
-
- if (geomGen->_is_nil() || !aStudy)
+ GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( myGeomObjects[0] );
+ if (geomGen->_is_nil())
return false;
- GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations(aStudy->StudyId());
+ GEOM::GEOM_IGroupOperations_wrap op = geomGen->GetIGroupOperations();
if (op->_is_nil())
return false;
// check and add all selected GEOM objects: they must be
// a sub-shapes of the main GEOM and must be of one type
TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
- for ( int i =0; i < (int)myGeomObjects->length(); i++) {
+ for ( CORBA::ULong i =0; i < myGeomObjects->length(); i++)
+ {
TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)myGeomObjects[i]->GetShapeType();
- if (i == 0)
+ if ( i == 0 )
aGroupType = aSubShapeType;
- else if (aSubShapeType != aGroupType) {
+ else if ( aSubShapeType != aGroupType ) {
aGroupType = TopAbs_SHAPE;
break;
}
GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
GEOM::GEOM_Object_wrap aGroupVar = op->CreateGroup(aMeshShape, aGroupType);
+ if ( aGroupVar->_is_nil() )
+ return false;
op->UnionList(aGroupVar, myGeomObjects);
if (op->IsDone()) {
QString aNewGeomGroupName ( "Auto_group_for_" );
aNewGeomGroupName += myName->text();
SALOMEDS::SObject_var aNewGroupSO =
- geomGen->AddInStudy(aSMESHGen->GetCurrentStudy(), aGroupVar,
- SMESH::toUtf8(aNewGeomGroupName), aMeshShape);
+ geomGen->AddInStudy(aGroupVar,
+ aNewGeomGroupName.toUtf8(), aMeshShape);
}
myGroupOnGeom = myMesh->CreateGroupFromGEOM(aType,
- SMESH::toUtf8(myName->text()),
+ myName->text().toUtf8(),
aGroupVar);
}
resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnGeom );
isCreation = false;
- }
+ }
anIsOk = true;
}
+
if (myGrpTypeId == 2) // group on filter
{
if ( myFilter->_is_nil() ) return false;
return false;
myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
- SMESH::toUtf8(myName->text()),
+ myName->text().toUtf8(),
myFilter);
resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
isCreation = true;
if( aMeshGroupSO )
anEntryList.append( aMeshGroupSO->GetID().c_str() );
- resultGroup->SetName(SMESH::toUtf8(myName->text().trimmed()));
+ resultGroup->SetName(myName->text().trimmed().toUtf8());
if ( isCreation )
{
Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
if ( isConversion ) { // need to reset TVisualObj and actor
SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
- SMESH::Update( anIO,true);
+ SMESH::Update( anIO, true );
myActorsList.clear();
anActor = SMESH::FindActorByEntry( anIO->getEntry() );
if ( !anActor ) return false;
myActorsList.append( anActor );
}
- anActor->setName(SMESH::toUtf8(myName->text()));
+ anActor->setName(myName->text().toUtf8());
QColor c;
int delta;
switch ( myTypeId ) {
SALOME_ListIteratorOfListIO anIt (aList);
for (; anIt.More(); anIt.Next())
{
- aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
-
+ CORBA::Object_var aGroupObj = SMESH::IObjectToObject(anIt.Value());
+ if (CORBA::is_nil(aGroupObj))
+ continue;
// Check if the object is a geometry group
+ aGeomGroup = GEOM::GEOM_Object::_narrow(aGroupObj);
if (CORBA::is_nil(aGeomGroup))
continue;
// Check if group constructed on the same shape as a mesh or on its child
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
// The main shape of the group
GEOM::GEOM_Object_var aGroupMainShape;
- if (aGeomGroup->GetType() == 37) {
+ if (aGeomGroup->GetType() == 37)
+ {
GEOM::GEOM_IGroupOperations_wrap anOp =
- SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
- aGroupMainShape = anOp->GetMainShape(aGeomGroup);
+ SMESH::GetGEOMGen( aGeomGroup )->GetIGroupOperations();
+ aGroupMainShape = anOp->GetMainShape( aGeomGroup );
// aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
}
- else {
+ else
+ {
aGroupMainShape = aGeomGroup;
aGroupMainShape->Register();
}
CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
- _PTR(SObject) aGroupMainShapeSO = aStudy->FindObjectID( entry.in() );
+ _PTR(SObject) aGroupMainShapeSO =
+ SMESH::getStudy()->FindObjectID( entry.in() );
_PTR(SObject) anObj, aRef;
bool isRefOrSubShape = false;
QListWidgetItem* anItem = 0;
QList<QListWidgetItem*> listItemsToSel;
- if (myCurrentLineEdit == 0) {
+ if ( myCurrentLineEdit == 0 )
+ {
//if (aNbSel != 1) { myIsBusy = false; return; }
QString aListStr = "";
int aNbItems = 0;
onListSelectionChanged();
listItemsToSel.clear();
}
- } else if (myCurrentLineEdit == mySubMeshLine) {
+ }
+ else if ( myCurrentLineEdit == mySubMeshLine )
+ {
//SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
SALOME_ListIO aList;
myIsBusy = false;
onListSelectionChanged();
- } else if (myCurrentLineEdit == myGroupLine) {
+ }
+ else if ( myCurrentLineEdit == myGroupLine )
+ {
//SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
SALOME_ListIO aList;
mySelectionMgr->selectedObjects( aList );
myIsBusy = false;
onListSelectionChanged();
- } else if (myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1) {
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
+ }
+ else if ( myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1 )
+ {
GEOM::GEOM_IGroupOperations_wrap aGroupOp =
- SMESH::GetGEOMGen()->GetIGroupOperations(aStudy->StudyId());
+ SMESH::GetGEOMGen( myGeomObjects[0] )->GetIGroupOperations();
SMESH::ElementType aGroupType = SMESH::ALL;
switch(aGroupOp->GetType(myGeomObjects[0])) {
if (aGroupType == aType) {
_PTR(SObject) aGroupSO =
- //aStudy->FindObjectIOR(aStudy->ConvertObjectToIOR(myGeomGroup));
- aStudy->FindObjectID(myGeomObjects[0]->GetStudyEntry());
+ //SMESH::getStudy()->FindObjectIOR(SMESH::getStudy()->ConvertObjectToIOR(myGeomGroup));
+ SMESH::getStudy()->FindObjectID(myGeomObjects[0]->GetStudyEntry());
// Construct filter
SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
if ( !aGeomVar->_is_nil() )
{
- CORBA::String_var ID = aGeomVar->GetStudyEntry();
- _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
- if ( _PTR(SObject) aGeomSO = aStudy->FindObjectID( ID.in() )) {
+ QString ID = aGeomVar->GetStudyEntry();
+ if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toLatin1().data() )) {
SALOME_ListIO anIOList;
Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );