Fix: Activate GEOM operation inside the HYDRO operation.
const bool theIsToEnableFileSelection )
: HYDROGUI_InputPanel( theModule, theTitle ),
myFileSelectionEnabled( theIsToEnableFileSelection ),
- myDefaultName( theObjectTypeName )
+ myDefaultName( "" )
{
// Get resource manager
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
#include <LightApp_Application.h>
#include <LightApp_UpdateFlags.h>
+#include <SUIT_Desktop.h>
+
+#include <QDialog>
+
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" ) );
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 ) {
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<HYDROGUI_GeomObjectDlg*>( inputPanel() );
aPanel->reset();
// Set default name
- SalomeApp_Study* aStudy =
- dynamic_cast<SalomeApp_Study*>( 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;
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();
}
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 =
return aPanel;
}
+void HYDROGUI_ImportGeomObjectOp::updateDefaultName()
+{
+ // Get panel
+ HYDROGUI_GeomObjectDlg* aPanel = ::qobject_cast<HYDROGUI_GeomObjectDlg*>( inputPanel() );
+ if ( !aPanel ) {
+ return;
+ }
+
+ // Set the current GEOM object name to the panel
+ if ( myGeomObjects.count() == 1 ) {
+ SalomeApp_Study* aStudy =
+ dynamic_cast<SalomeApp_Study*>( 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<QDialog*> aDialogs = aDesktop->findChildren<QDialog*>();
+ foreach ( QDialog* aDlg, aDialogs ) {
+ if ( typeid(*aDlg).name() == myGEOMOpName ) {
+ aDlg->close();
+ break;
+ }
+ }
+ }
+}
+
QList<GEOM::shape_type> HYDROGUI_ImportGeomObjectOp::getObstacleTypes()
{
QList<GEOM::shape_type> aTypes;
public:
HYDROGUI_ImportGeomObjectOp( HYDROGUI_Module* theModule,
const int theOpType,
- const bool theIsToShowPanel = true );
+ const int theGEOMOp = -1 );
virtual ~HYDROGUI_ImportGeomObjectOp();
static QList<GEOM::shape_type> getObstacleTypes();
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
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;
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 );
*/
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
virtual void onViewCreated( SUIT_ViewWindow* );
void onViewPortMouseEvent( QGraphicsSceneMouseEvent* );
-
- void onExternalOperationFinished( const QString&, const QString&,
- const QStringList& );
void onMouseMove( SUIT_ViewWindow*, QMouseEvent* );
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();
+ }
}
}
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;
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 );
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
ImportObstacleFromFileId,
ImportGeomObjectAsObstacleId,
ImportGeomObjectAsPolylineId,
- ImportCreatedPrimitiveId,
CreateBoxId,
CreateCylinderId,
<source>IMPORT_GEOM_OBJECT_AS_POLYLINE</source>
<translation>Import GEOM object as polyline</translation>
</message>
+ <message>
+ <source>NO_GEOM_OBJECT_TO_IMPORT</source>
+ <translation>No GEOM object(s) to import.</translation>
+ </message>
</context>
<context>