From 12ee350be54f45d4e9429bf588fab0ca520ff62e Mon Sep 17 00:00:00 2001 From: mzn Date: Wed, 20 Nov 2013 07:38:55 +0000 Subject: [PATCH] Implement panel for obstacles creation/modification. --- src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx | 35 +++++++++-- .../HYDROGUI_ImportObstacleFromFileOp.cxx | 29 +++++++-- .../HYDROGUI_ImportObstacleFromFileOp.h | 4 +- src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx | 62 ++++++++++++++----- src/HYDROGUI/HYDROGUI_ObstacleDlg.h | 7 ++- src/HYDROGUI/HYDROGUI_Operations.cxx | 8 ++- src/HYDROGUI/HYDROGUI_Operations.h | 2 + src/HYDROGUI/HYDROGUI_Tool.cxx | 7 +-- src/HYDROGUI/HYDROGUI_Tool.h | 4 +- 9 files changed, 125 insertions(+), 33 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx index fd32dfad..6f771664 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 ); @@ -113,14 +125,29 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, // 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 ) ); } + } - 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 +160,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,7 +172,8 @@ 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 ); @@ -157,7 +184,7 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, // Set operation status anIsOk = true; - theUpdateFlags = UF_Model; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced; } } } diff --git a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx index 85320817..0fc2e3e5 100644 --- a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.cxx @@ -27,6 +27,7 @@ #include "HYDROGUI_DataModel.h" #include "HYDROGUI_Module.h" #include "HYDROGUI_Tool.h" +#include "HYDROGUI_UpdateFlags.h" #include @@ -72,7 +73,7 @@ void HYDROGUI_ImportObstacleFromFileOp::startOperation() aPanel->setObstacleNames( anObstacles ); } else { - myFileDlg = new SUIT_FileDlg( module()->application()->desktop(), true ); + myFileDlg = new SUIT_FileDlg( module()->getApp()->desktop(), true ); myFileDlg->setWindowTitle( getName() ); myFileDlg->setFilter( tr("OBSTACLE_FILTER") ); if ( !lastUsedFilter.isEmpty() ) { @@ -116,8 +117,6 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags, anObstacle = Handle(HYDROData_Obstacle)::DownCast( HYDROGUI_Tool::FindObjectByName( module(), anEditedName, KIND_OBSTACLE ) ); } - - anObstacleName = anEditedName; //TODO: aPanel->getObstacleName(); } else if ( myFileDlg ) { // Get file name and file filter defined by the user aFileName = myFileDlg->selectedFile(); @@ -125,12 +124,31 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags, } // Check the file name + if ( aFileName.isEmpty() ) { + return false; + } QFileInfo aFileInfo( aFileName ); if ( !aFileInfo.exists() || !aFileInfo.isReadable() ) { theErrorMsg = tr( "FILE_NOT_EXISTS_OR_CANT_BE_READ" ).arg( aFileName ); return false; } + // Check obstacle name + anObstacleName = aPanel->getObstacleName().simplified(); + if ( anObstacleName.isEmpty() ) { + theErrorMsg = tr( "INCORRECT_OBJECT_NAME" ); + return false; + } + + if( anObstacle.IsNull() || anObstacle->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; // If the obstacle for edit is null - create new obstacle object @@ -142,7 +160,8 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags, if ( anObstacle->ImportFromFile( aFileName ) ) { // Set name if ( anObstacleName.isEmpty() ) { - anObstacleName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() ); + anObstacleName = HYDROGUI_Tool::GenerateObjectName( + module(), aFileInfo.baseName(), QStringList(), true ); } if ( anObstacle->GetName() != anObstacleName ) { anObstacle->SetName( anObstacleName ); @@ -150,7 +169,7 @@ bool HYDROGUI_ImportObstacleFromFileOp::processApply( int& theUpdateFlags, // Set operation status anIsOk = true; - theUpdateFlags = UF_Model; + theUpdateFlags = UF_Model | UF_OCCViewer | UF_OCC_Forced;; } else { theErrorMsg = tr( "BAD_IMPORTED_OBSTACLE_FILE" ).arg( aFileName ); } diff --git a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.h b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.h index 05b217fd..e2647293 100644 --- a/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportObstacleFromFileOp.h @@ -20,8 +20,8 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#ifndef HYDROGUI_IMPORTOBSTACLEFROMFILE_H -#define HYDROGUI_IMPORTOBSTACLEFROMFILE_H +#ifndef HYDROGUI_IMPORTOBSTACLEFROMFILEOP_H +#define HYDROGUI_IMPORTOBSTACLEFROMFILEOP_H #include "HYDROGUI_Operation.h" diff --git a/src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx b/src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx index beb9f0d1..2697c8d3 100644 --- a/src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_ObstacleDlg.cxx @@ -42,7 +42,8 @@ static QString lastUsedFilter; HYDROGUI_ObstacleDlg::HYDROGUI_ObstacleDlg( HYDROGUI_Module* theModule, const QString& theTitle, const bool theIsToEnableFileSelection ) : HYDROGUI_InputPanel( theModule, theTitle ), - myFileSelectionEnabled ( theIsToEnableFileSelection ) + myFileSelectionEnabled ( theIsToEnableFileSelection ), + myDefaultName( tr("DEFAULT_OBSTACLE_NAME") ) { // Get resource manager SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); @@ -83,8 +84,6 @@ HYDROGUI_ObstacleDlg::HYDROGUI_ObstacleDlg( HYDROGUI_Module* theModule, const QS anObstacleNameLayout->addWidget( anObstacleNameLabel ); anObstacleNameLayout->addWidget( myObstacleName ); - myObstacleNameGroup->hide(); //TODO to be enabled? - // Mode selector (create/edit) myModeGroup = new QGroupBox( tr( "MODE" ), this ); @@ -138,12 +137,13 @@ void HYDROGUI_ObstacleDlg::setObstacleNames( const QStringList& theObstacles ) myObstacles->clear(); myObstacles->addItems( theObstacles ); - UpdateControls(); + updateControls(); } void HYDROGUI_ObstacleDlg::onModeActivated( int theMode ) { - UpdateControls(); + updateControls(); + updateObjectName(); } QString HYDROGUI_ObstacleDlg::getObstacleName() const @@ -191,13 +191,10 @@ void HYDROGUI_ObstacleDlg::onBrowse() if ( !aFileName.isEmpty() ) { myFileName->setText( aFileName ); - - QFileInfo aFileInfo( aFileName ); - QString aName = HYDROGUI_Tool::GenerateObjectName( module(), aFileInfo.baseName() ); - myObstacleName->setText( aName ); + updateObjectName(); } - UpdateControls(); + updateControls(); } } @@ -212,21 +209,56 @@ void HYDROGUI_ObstacleDlg::reset() myModeButtons->button( CreateNewId )->setChecked( true ); onModeActivated( CreateNewId ); - UpdateControls(); + updateControls(); } void HYDROGUI_ObstacleDlg::onObstacleSelectionChanged() { - if ( myObstacleName->text().isEmpty() ) { - myObstacleName->setText( myObstacles->currentText() ); - } + updateObjectName(); } -void HYDROGUI_ObstacleDlg::UpdateControls() +void HYDROGUI_ObstacleDlg::updateControls() { myObstacleNameGroup->setEnabled( !myFileSelectionEnabled || !myFileName->text().isEmpty() ); myModeGroup->setEnabled( myObstacleNameGroup->isEnabled() && myObstacles->count() > 0 ); myObstaclesGroup->setEnabled( myModeButtons->checkedId() == ModifyExistentId ); +} + +void HYDROGUI_ObstacleDlg::updateObjectName() +{ + QString aName; + + // Creation mode + int aMode = myModeButtons->checkedId(); + if ( aMode == CreateNewId ) { + if ( myFileSelectionEnabled ) { + QString aFileName = myFileName->text(); + if ( !aFileName.isEmpty() ) { + QFileInfo aFileInfo( aFileName ); + aName = HYDROGUI_Tool::GenerateObjectName( + module(), aFileInfo.baseName(), QStringList(), true ); + } + } else { + aName = HYDROGUI_Tool::GenerateObjectName( + module(), getDefaultName(), QStringList(), true ); + } + } else if ( aMode == ModifyExistentId ) { + aName = getEditedObstacleName(); + } + + myObstacleName->setText( aName ); +} + +void HYDROGUI_ObstacleDlg::setDefaultName( const QString& theName ) +{ + myDefaultName = theName; + + updateObjectName(); +} + +QString HYDROGUI_ObstacleDlg::getDefaultName() +{ + return myDefaultName; } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_ObstacleDlg.h b/src/HYDROGUI/HYDROGUI_ObstacleDlg.h index af303096..60d2acbb 100644 --- a/src/HYDROGUI/HYDROGUI_ObstacleDlg.h +++ b/src/HYDROGUI/HYDROGUI_ObstacleDlg.h @@ -50,13 +50,17 @@ public: QString getFileName() const; + QString getDefaultName(); + void setDefaultName( const QString& theName ); + protected slots: void onModeActivated( int ); void onObstacleSelectionChanged(); void onBrowse(); private: - void UpdateControls(); + void updateControls(); + void updateObjectName(); private: QLineEdit* myFileName; @@ -71,6 +75,7 @@ private: QComboBox* myObstacles; bool myFileSelectionEnabled; + QString myDefaultName; }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index 0378857c..d32802e9 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -44,6 +44,7 @@ #include "HYDROGUI_ImportGeomObjectOp.h" #include "HYDROGUI_ImportObstacleFromFileOp.h" #include "HYDROGUI_ExportCalculationOp.h" +#include "HYDROGUI_SetColorOp.h" #include "HYDROData_Document.h" #include "HYDROData_Obstacle.h" @@ -128,6 +129,8 @@ void HYDROGUI_Module::createActions() createAction( DeleteId, "DELETE", "", Qt::Key_Delete ); + createAction( SetColorId, "COLOR" ); + createAction( ShowId, "SHOW" ); createAction( ShowOnlyId, "SHOW_ONLY" ); createAction( ShowAllId, "SHOW_ALL" ); @@ -351,6 +354,9 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case DeleteId: anOp = new HYDROGUI_DeleteOp( aModule ); break; + case SetColorId: + anOp = new HYDROGUI_SetColorOp( aModule ); + break; case ShowId: case ShowOnlyId: case ShowAllId: @@ -392,7 +398,7 @@ void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName, // Start import GEOM object operation myGeomObjectsToImport = theEntryList; - startOperation ( ImportCreatedPrimitiveId ); + startOperation( ImportCreatedPrimitiveId ); myGeomObjectsToImport.clear(); } diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index cdfe34d3..c27188a1 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -78,6 +78,8 @@ enum OperationId ShowAllId, HideId, HideAllId, + + SetColorId }; #endif diff --git a/src/HYDROGUI/HYDROGUI_Tool.cxx b/src/HYDROGUI/HYDROGUI_Tool.cxx index 19d4e9c9..5e026dd4 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.cxx +++ b/src/HYDROGUI/HYDROGUI_Tool.cxx @@ -356,8 +356,6 @@ QStringList HYDROGUI_Tool::GetSelectedGeomObjects( HYDROGUI_Module* theModule ) } // Get selection - HYDROGUI_DataModel* aModel = theModule->getDataModel(); - SUIT_SelectionMgr* aSelectionMgr = theModule->getApp()->selectionMgr(); SUIT_DataOwnerPtrList anOwners; aSelectionMgr->selected( anOwners ); @@ -404,10 +402,11 @@ HYDROData_SequenceOfObjects HYDROGUI_Tool::FindObjectsByNames( HYDROGUI_Module* QString HYDROGUI_Tool::GenerateObjectName( HYDROGUI_Module* theModule, const QString& thePrefix, - const QStringList& theUsedNames ) + const QStringList& theUsedNames, + const bool theIsTryToUsePurePrefix) { Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( theModule->getStudyId() ); - return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames ); + return HYDROData_Tool::GenerateObjectName( aDocument, thePrefix, theUsedNames, theIsTryToUsePurePrefix ); } size_t HYDROGUI_Tool::GetActiveViewId( HYDROGUI_Module* theModule, diff --git a/src/HYDROGUI/HYDROGUI_Tool.h b/src/HYDROGUI/HYDROGUI_Tool.h index 5b590865..7a77b3af 100644 --- a/src/HYDROGUI/HYDROGUI_Tool.h +++ b/src/HYDROGUI/HYDROGUI_Tool.h @@ -196,11 +196,13 @@ public: * \param theModule module * \param thePrefix name prefix * \param theUsedNames list of already used names + * \param theIsTryToUsePurePrefix if true - the prefix will be returned if the name equal to the prefix is not busy * \return generated name */ static QString GenerateObjectName( HYDROGUI_Module* theModule, const QString& thePrefix, - const QStringList& theUsedNames = QStringList() ); + const QStringList& theUsedNames = QStringList(), + const bool theIsTryToUsePurePrefix = false ); /** * \brief Get id of the active view. -- 2.39.2