3 // Copyright (C) 2005 CEA/DEN, EDF R&D
7 // File : SMESHGUI_Operation.h
8 // Author : Sergey LITONIN
11 #include "SMESHGUI_Operation.h"
13 #include <SMESHGUI_Dialog.h>
15 #include <SalomeApp_Study.h>
16 #include <LightApp_Application.h>
18 #include <SUIT_Session.h>
19 #include <SUIT_MessageBox.h>
20 #include <SUIT_Desktop.h>
22 #include <qstringlist.h>
25 Class : SMESHGUI_Operation
26 Description : Base class for all SMESH operations
29 //=======================================================================
30 // name : SMESHGUI_Operation
31 // Purpose : Constructor
32 //=======================================================================
33 SMESHGUI_Operation::SMESHGUI_Operation()
34 : LightApp_Operation()
39 //=======================================================================
40 // name : ~SMESHGUI_Operation
41 // Purpose : Destructor
42 //=======================================================================
43 SMESHGUI_Operation::~SMESHGUI_Operation()
47 //=======================================================================
49 // Purpose : Get SMESH module
50 //=======================================================================
51 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
53 return dynamic_cast<SMESHGUI*>( module() );
56 //=======================================================================
57 // name : startOperation
58 // Purpose : Start opeartion
59 //=======================================================================
60 void SMESHGUI_Operation::startOperation()
64 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
65 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
66 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
67 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
68 disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
70 if( dlg()->testButtonFlags( QtxDialog::OK ) )
71 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
73 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
74 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
76 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
77 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
79 if( dlg()->testButtonFlags( QtxDialog::Help ) )
80 connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
82 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
83 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
84 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
89 LightApp_Operation::startOperation();
92 //=======================================================================
93 // name : isReadyToStart
94 // Purpose : Verify whether operation is ready to start
95 //=======================================================================
96 bool SMESHGUI_Operation::isReadyToStart() const
98 if ( !LightApp_Operation::isReadyToStart() )
100 else if ( getSMESHGUI() == 0 )
102 SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
103 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
106 else if ( isStudyLocked() )
112 //=======================================================================
113 // name : setDialogActive
115 //=======================================================================
116 void SMESHGUI_Operation::setDialogActive( const bool active )
118 LightApp_Operation::setDialogActive( active );
120 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
122 d->setContentActive( active );
126 //=======================================================================
129 //=======================================================================
130 _PTR(Study) SMESHGUI_Operation::studyDS() const
132 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
136 //=======================================================================
139 //=======================================================================
140 void SMESHGUI_Operation::onOk()
148 //=======================================================================
151 //=======================================================================
152 bool SMESHGUI_Operation::onApply()
157 //=======================================================================
160 //=======================================================================
161 void SMESHGUI_Operation::onCancel()
166 //=======================================================================
169 //=======================================================================
170 void SMESHGUI_Operation::onHelp()
172 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
174 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
176 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
177 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
178 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
179 QObject::tr("BUT_OK"));
183 //=======================================================================
186 //=======================================================================
187 void SMESHGUI_Operation::initDialog()
192 * \brief Verifies whether study of operation is locked
193 * \param theMess - specifies whether message box must be shown if study is locked
194 * \return State of study.
196 * Verifies whether study of operation is locked. If second parameter is TRUE and study
197 * is locked when corresponding message box appears
199 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
203 if ( studyDS()->GetProperties()->IsLocked() )
206 SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
207 QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
216 * \brief Verifies whether given operator is valid for this one
217 * \param theOtherOp - other operation
218 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
220 * Virtual method redefined from base class verifies whether given operator is valid for
221 * this one (i.e. can be started "above" this operator). In current implementation method
222 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
225 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
227 static QStringList anOps;
228 if ( anOps.count() == 0 )
230 anOps.append( "SMESHGUI_DeleteOp" );
231 // to do add other operations here
234 return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
235 ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );