From: mzn Date: Thu, 19 Dec 2013 07:02:59 +0000 (+0000) Subject: Support #101: it is possible to start operation Obstacle - Create Box during creation... X-Git-Tag: BR_hydro_v_0_6~29 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=95666601f14d4315afb4689162b6702ec526ad34;p=modules%2Fhydro.git Support #101: it is possible to start operation Obstacle - Create Box during creation of polyline. Fix: Activate GEOM operation inside the HYDRO operation. --- diff --git a/src/HYDROGUI/HYDROGUI_GeomObjectDlg.cxx b/src/HYDROGUI/HYDROGUI_GeomObjectDlg.cxx index f3275eb3..aec19ada 100644 --- a/src/HYDROGUI/HYDROGUI_GeomObjectDlg.cxx +++ b/src/HYDROGUI/HYDROGUI_GeomObjectDlg.cxx @@ -44,7 +44,7 @@ HYDROGUI_GeomObjectDlg::HYDROGUI_GeomObjectDlg( HYDROGUI_Module* theModule, cons const bool theIsToEnableFileSelection ) : HYDROGUI_InputPanel( theModule, theTitle ), myFileSelectionEnabled( theIsToEnableFileSelection ), - myDefaultName( theObjectTypeName ) + myDefaultName( "" ) { // Get resource manager SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx index 344f8cad..c3d9488f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx +++ b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.cxx @@ -40,12 +40,18 @@ #include #include +#include + +#include + HYDROGUI_ImportGeomObjectOp::HYDROGUI_ImportGeomObjectOp( HYDROGUI_Module* theModule, const int theOpType, - const bool theIsToShowPanel ) + const int theGEOMOp ) : HYDROGUI_Operation( theModule ), - myOpType ( theOpType ), - myIsToShowPanel ( theIsToShowPanel ) + myOpType( theOpType ), + myGEOMOp( theGEOMOp ), + myGEOMOpName( "" ), + myIsToShowPanel( true ) { if ( myOpType == ImportSelectedAsPolyline ) { setName( tr( "IMPORT_GEOM_OBJECT_AS_POLYLINE" ) ); @@ -60,13 +66,10 @@ HYDROGUI_ImportGeomObjectOp::~HYDROGUI_ImportGeomObjectOp() void HYDROGUI_ImportGeomObjectOp::startOperation() { - HYDROGUI_Operation::startOperation(); - // Get GEOM objects to import myGeomObjects.clear(); - if ( myOpType == ImportCreatedAsObstacle ) { - myGeomObjects = module()->GetGeomObjectsToImport(); - } else if ( myOpType == ImportSelectedAsObstacle ) { + + if ( myOpType == ImportSelectedAsObstacle ) { myGeomObjects = HYDROGUI_Tool::GetSelectedGeomObjects( module(), getObstacleTypes() ); } else if ( myOpType == ImportSelectedAsPolyline ) { @@ -74,9 +77,14 @@ void HYDROGUI_ImportGeomObjectOp::startOperation() HYDROGUI_Tool::GetSelectedGeomObjects( module(), getPolylineTypes() ); } + // Do not show the panel if more than one GEOM objects are selected + myIsToShowPanel = myIsToShowPanel && ( myGeomObjects.count() <= 1 ); + + HYDROGUI_Operation::startOperation(); + HYDROGUI_GeomObjectDlg* aPanel = 0; - if ( myGeomObjects.count() == 1 ) { + if ( myIsToShowPanel ) { // Get panel aPanel = ::qobject_cast( inputPanel() ); @@ -85,15 +93,7 @@ void HYDROGUI_ImportGeomObjectOp::startOperation() 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()) ); - } - } + updateDefaultName(); // Pass the existing object names to the panel QStringList anExistingNames; @@ -111,15 +111,35 @@ void HYDROGUI_ImportGeomObjectOp::startOperation() if ( !aPanel ) { onApply(); } + + // Activate GEOM module operation in case of the corresponding operation type + if ( myOpType == ImportCreatedAsObstacle && myGEOMOp > 0 ) { + LightApp_Application* anApp = module()->getApp(); + if ( anApp ) { + connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), + this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) ); + + module()->getApp()->activateOperation( "Geometry", myGEOMOp ); + } + } } void HYDROGUI_ImportGeomObjectOp::abortOperation() { + LightApp_Application* anApp = module()->getApp(); + if ( anApp ) { + anApp->disconnect( this ); + } + + closeExternalOperationDlg(); + HYDROGUI_Operation::abortOperation(); } void HYDROGUI_ImportGeomObjectOp::commitOperation() { + closeExternalOperationDlg(); + HYDROGUI_Operation::commitOperation(); } @@ -133,6 +153,12 @@ bool HYDROGUI_ImportGeomObjectOp::processApply( int& theUpdateFlags, return false; } + // Check that GEOM objects list is not empty + if ( myGeomObjects.isEmpty() ) { + theErrorMsg = tr( "NO_GEOM_OBJECT_TO_IMPORT" ); + return false; + } + QString anObjectName; Handle(HYDROData_Entity) anObjectToEdit; ObjectKind anObjectKind = @@ -244,6 +270,71 @@ HYDROGUI_InputPanel* HYDROGUI_ImportGeomObjectOp::createInputPanel() const return aPanel; } +void HYDROGUI_ImportGeomObjectOp::updateDefaultName() +{ + // Get panel + HYDROGUI_GeomObjectDlg* aPanel = ::qobject_cast( inputPanel() ); + if ( !aPanel ) { + return; + } + + // Set the current GEOM object name to the panel + if ( myGeomObjects.count() == 1 ) { + 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()) ); + } + } + } +} + +/** + * Called when the operation perfomed by another module is finished. + * \param theModuleName the name of the module which perfomed the operation + * \param theOperationName the operation name + * \param theEntryList the list of the created objects entries + */ +void HYDROGUI_ImportGeomObjectOp::onExternalOperationFinished( + const QString& theModuleName, const QString& theOperationName, + const QStringList& theEntryList ) +{ + // Process "Geometry" module operations with non-empty list of created objects only + if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) { + return; + } + + // Store the operation name + myGEOMOpName = theOperationName; + + // Store the geom objects entries list + myGeomObjects = theEntryList; + + // Update the default name of the HYDRO object + updateDefaultName(); +} + +void HYDROGUI_ImportGeomObjectOp::closeExternalOperationDlg() +{ + if ( myGEOMOpName.isEmpty() ) { + return; + } + + SUIT_Desktop* aDesktop = module()->getApp()->desktop(); + if ( aDesktop ) { + QList aDialogs = aDesktop->findChildren(); + foreach ( QDialog* aDlg, aDialogs ) { + if ( typeid(*aDlg).name() == myGEOMOpName ) { + aDlg->close(); + break; + } + } + } +} + QList HYDROGUI_ImportGeomObjectOp::getObstacleTypes() { QList aTypes; diff --git a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.h b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.h index 4b182584..b8830f9f 100644 --- a/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.h +++ b/src/HYDROGUI/HYDROGUI_ImportGeomObjectOp.h @@ -45,7 +45,7 @@ public: public: HYDROGUI_ImportGeomObjectOp( HYDROGUI_Module* theModule, const int theOpType, - const bool theIsToShowPanel = true ); + const int theGEOMOp = -1 ); virtual ~HYDROGUI_ImportGeomObjectOp(); static QList getObstacleTypes(); @@ -60,10 +60,20 @@ protected: virtual bool processApply( int& theUpdateFlags, QString& theErrorMsg ); +protected slots: + void onExternalOperationFinished( const QString&, const QString&, + const QStringList& ); + +private: + void updateDefaultName(); + void closeExternalOperationDlg(); + private: QStringList myGeomObjects; ///< the list of GEOM object entries bool myIsToShowPanel; ///< indicates if obstacle panel to be shown int myOpType; ///< operation type (to import selected GEOM objects or the objects just created by GEOM ) + int myGEOMOp; ///< GEOM module operation to be called to create GEOM object for import + QString myGEOMOpName; ///< the name of the called GEOM module operation }; #endif \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_Module.cxx b/src/HYDROGUI/HYDROGUI_Module.cxx index 6091e92e..909dbdb5 100644 --- a/src/HYDROGUI/HYDROGUI_Module.cxx +++ b/src/HYDROGUI/HYDROGUI_Module.cxx @@ -191,9 +191,6 @@ bool HYDROGUI_Module::activateModule( SUIT_Study* theStudy ) updateCommandsStatus(); - connect( anApp, SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), - this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) ); - HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, false ); ViewManagerList anOCCViewManagers; @@ -243,9 +240,6 @@ bool HYDROGUI_Module::deactivateModule( SUIT_Study* theStudy ) getApp()->setEditEnabled( true ); // show SalomeApp copy/paste actions - disconnect( getApp(), SIGNAL( operationFinished( const QString&, const QString&, const QStringList& ) ), - this, SLOT( onExternalOperationFinished( const QString&, const QString&, const QStringList& ) ) ); - HYDROGUI_Tool::setOCCActionShown( this, OCCViewer_ViewWindow::MaximizedId, true ); return LightApp_Module::deactivateModule( theStudy ); diff --git a/src/HYDROGUI/HYDROGUI_Module.h b/src/HYDROGUI/HYDROGUI_Module.h index dc1e7cbc..3f46027b 100644 --- a/src/HYDROGUI/HYDROGUI_Module.h +++ b/src/HYDROGUI/HYDROGUI_Module.h @@ -148,8 +148,6 @@ public: */ void updateVTKZRange( const int theViewId, double theRange[] ); - QStringList GetGeomObjectsToImport(); - /** * Returns true if the object with the given entry can be renamed. * @param theEntry the object entry @@ -189,9 +187,6 @@ protected slots: virtual void onViewCreated( SUIT_ViewWindow* ); void onViewPortMouseEvent( QGraphicsSceneMouseEvent* ); - - void onExternalOperationFinished( const QString&, const QString&, - const QStringList& ); void onMouseMove( SUIT_ViewWindow*, QMouseEvent* ); diff --git a/src/HYDROGUI/HYDROGUI_Operation.cxx b/src/HYDROGUI/HYDROGUI_Operation.cxx index ed01027c..90a5e308 100644 --- a/src/HYDROGUI/HYDROGUI_Operation.cxx +++ b/src/HYDROGUI/HYDROGUI_Operation.cxx @@ -213,7 +213,12 @@ void HYDROGUI_Operation::onApply() aMsg.prepend( anErrorMsg + "\n" ); SUIT_MessageBox::critical( module()->getApp()->desktop(), tr( "INSUFFICIENT_INPUT_DATA" ), - aMsg ); + aMsg ); + + // If the operation has no input panel - do abort + if ( !inputPanel() ) { + abort(); + } } } diff --git a/src/HYDROGUI/HYDROGUI_Operations.cxx b/src/HYDROGUI/HYDROGUI_Operations.cxx index d3a2d04f..277eee95 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.cxx +++ b/src/HYDROGUI/HYDROGUI_Operations.cxx @@ -456,9 +456,6 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const case ImportObstacleFromFileId: anOp = new HYDROGUI_ImportObstacleFromFileOp( aModule ); break; - case ImportCreatedPrimitiveId: - anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle ); - break; case ImportGeomObjectAsObstacleId: anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsObstacle ); break; @@ -466,10 +463,12 @@ LightApp_Operation* HYDROGUI_Module::createOperation( const int theId ) const anOp = new HYDROGUI_ImportGeomObjectOp( aModule, HYDROGUI_ImportGeomObjectOp::ImportSelectedAsPolyline ); break; case CreateBoxId: - application()->activateOperation( "Geometry", GEOMOp::OpBox ); + anOp = new HYDROGUI_ImportGeomObjectOp( aModule, + HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpBox ); break; case CreateCylinderId: - application()->activateOperation( "Geometry", GEOMOp::OpCylinder ); + anOp = new HYDROGUI_ImportGeomObjectOp( aModule, + HYDROGUI_ImportGeomObjectOp::ImportCreatedAsObstacle, GEOMOp::OpCylinder ); break; case DeleteId: anOp = new HYDROGUI_DeleteOp( aModule ); @@ -502,35 +501,6 @@ bool HYDROGUI_Module::reusableOperation( const int id ) return LightApp_Module::reusableOperation( id ); } -/** - * Called when the operation perfomed by another module is finished. - * \param theModuleName the name of the module which perfomed the operation - * \param theOperationName the operation name - * \param theEntryList the list of the created objects entries - */ -void HYDROGUI_Module::onExternalOperationFinished( const QString& theModuleName, - const QString& theOperationName, - const QStringList& theEntryList ) -{ - // Process "Geometry" module operations with non-empty list of created objects only - if ( theModuleName != "Geometry" || theEntryList.isEmpty() ) { - return; - } - - // Start import GEOM object operation - myGeomObjectsToImport = theEntryList; - startOperation( ImportCreatedPrimitiveId ); - myGeomObjectsToImport.clear(); -} - -/** - * Returns the list of entries of GEOM objects to be imported. - */ -QStringList HYDROGUI_Module::GetGeomObjectsToImport() -{ - return myGeomObjectsToImport; -} - /** * Returns true if the object with the given entry can be renamed. * @param theEntry the object entry diff --git a/src/HYDROGUI/HYDROGUI_Operations.h b/src/HYDROGUI/HYDROGUI_Operations.h index 7184340a..5528cbac 100644 --- a/src/HYDROGUI/HYDROGUI_Operations.h +++ b/src/HYDROGUI/HYDROGUI_Operations.h @@ -87,7 +87,6 @@ enum OperationId ImportObstacleFromFileId, ImportGeomObjectAsObstacleId, ImportGeomObjectAsPolylineId, - ImportCreatedPrimitiveId, CreateBoxId, CreateCylinderId, diff --git a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts index b0e13dd5..e2cadb8e 100644 --- a/src/HYDROGUI/resources/HYDROGUI_msg_en.ts +++ b/src/HYDROGUI/resources/HYDROGUI_msg_en.ts @@ -1464,6 +1464,10 @@ file cannot be correctly imported for a Bathymetry definition. IMPORT_GEOM_OBJECT_AS_POLYLINE Import GEOM object as polyline + + NO_GEOM_OBJECT_TO_IMPORT + No GEOM object(s) to import. +