X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FHYDROGUI%2FHYDROGUI_ImportGeomObjectOp.cxx;h=4ba06589d180a3cce243b3e641ff58c3db810d2e;hb=ecb167067ddfbaf01ceedb62f754e6ca7d2f7131;hp=fd32dfad5d30c928c5489c4c7321448d8e2163ab;hpb=7e825ec456c9331ef0df1cb59865cc55f0d8516a;p=modules%2Fhydro.git diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx index fd32dfad..4ba06589 100644 --- a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" #include #include @@ -74,6 +75,17 @@ void HYDROGUI_ImportGeomObjectOp::startOperation() // Reset the panel state aPanel->reset(); + // Set default name + SalomeApp_Study* aStudy = + dynamic_cast( module()->getApp()->activeStudy() ); + if ( aStudy ) { + QString anEntry = myGeomObjects.first(); + _PTR(SObject) aSObject( aStudy->studyDS()->FindObjectID( qPrintable(anEntry) ) ); + if ( aSObject ) { + aPanel->setDefaultName( QString::fromStdString(aSObject->GetName()) ); + } + } + // Pass the existing obstacle names to the panel QStringList anObstacles = HYDROGUI_Tool::FindExistingObjectsNames( doc(), KIND_OBSTACLE ); @@ -110,17 +122,34 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, QString anObstacleName; Handle(HYDROData_Obstacle) anObstacleToEdit; - // Get panel - HYDROGUI_ObstacleDlg* aPanel = ::qobject_cast( inputPanel() ); - if ( aPanel ) { - QString anEditedName = aPanel->getEditedObstacleName().simplified(); + if ( myGeomObjects.count() == 1 ) { + // Get panel + HYDROGUI_ObstacleDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( aPanel ) { + // Check obstacle name + anObstacleName = aPanel->getObstacleName().simplified(); + if ( anObstacleName.isEmpty() ) { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); + return false; + } + + // Get obstacle to edit + QString anEditedName = aPanel->getEditedObstacleName().simplified(); - if ( !anEditedName.isEmpty() ) { - anObstacleToEdit = Handle(HYDROData_Obstacle)::DownCast( - HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) ); + if ( !anEditedName.isEmpty() ) { + anObstacleToEdit = Handle(HYDROData_Obstacle)::DownCast( + HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) ); + } } - anObstacleName = anEditedName; //TODO: aPanel->getObstacleName(); + if( anObstacleToEdit.IsNull() || anObstacleToEdit->GetName() != anObstacleName ) { + // check that there are no other objects with the same name in the document + Handle(HYDROData_Entity) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObstacleName ); + if( !anObject.IsNull() ) { + theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObstacleName ); + return false; + } + } } bool anIsOk = false; @@ -133,7 +162,6 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, TopoDS_Shape aShape = GEOMBase::GetShapeFromIOR( aSObject->GetIOR().c_str() ); if ( !aShape.IsNull() ) { // Create/edit an obstacle object - // TODO refactoring: get rid of obstacle from TopoDS_Shape creation code copy/paste Handle(HYDROData_Obstacle) anObstacle; if ( anObstacleToEdit.IsNull() ) { @@ -146,18 +174,21 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, // Set name if ( anObstacleName.isEmpty() ) { QString aName = QString::fromStdString( aSObject->GetName() ); - anObstacleName = HYDROGUI_Tool::GenerateObjectName( module(), aName ); + anObstacleName = HYDROGUI_Tool::GenerateObjectName( + module(), aName, QStringList(), true ); } if ( anObstacle->GetName() != anObstacleName ) { anObstacle->SetName( anObstacleName ); } + anObstacleName.clear(); + // Set shape anObstacle->SetShape3D( aShape ); // Set operation status anIsOk = true; - theUpdateFlags = UF_Model; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; } } }