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>
17 #include <SUIT_MessageBox.h>
18 #include <SUIT_Desktop.h>
20 #include <qstringlist.h>
23 Class : SMESHGUI_Operation
24 Description : Base class for all SMESH operations
27 //=======================================================================
28 // name : SMESHGUI_Operation
29 // Purpose : Constructor
30 //=======================================================================
31 SMESHGUI_Operation::SMESHGUI_Operation()
32 : LightApp_Operation()
36 //=======================================================================
37 // name : ~SMESHGUI_Operation
38 // Purpose : Destructor
39 //=======================================================================
40 SMESHGUI_Operation::~SMESHGUI_Operation()
44 //=======================================================================
46 // Purpose : Get SMESH module
47 //=======================================================================
48 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
50 return dynamic_cast<SMESHGUI*>( module() );
53 //=======================================================================
54 // name : startOperation
55 // Purpose : Start opeartion
56 //=======================================================================
57 void SMESHGUI_Operation::startOperation()
61 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
62 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
63 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
64 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
66 if( dlg()->testButtonFlags( QtxDialog::OK ) )
67 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
69 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
70 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
72 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
73 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
75 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
76 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
77 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
82 LightApp_Operation::startOperation();
85 //=======================================================================
86 // name : isReadyToStart
87 // Purpose : Verify whether operation is ready to start
88 //=======================================================================
89 bool SMESHGUI_Operation::isReadyToStart() const
91 if ( !LightApp_Operation::isReadyToStart() )
93 else if ( getSMESHGUI() == 0 )
95 SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
96 tr( "NO_MODULE" ), tr( "SMESH_BUT_OK" ) );
99 else if ( isStudyLocked() )
105 //=======================================================================
106 // name : setDialogActive
108 //=======================================================================
109 void SMESHGUI_Operation::setDialogActive( const bool active )
111 LightApp_Operation::setDialogActive( active );
113 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
115 d->setContentActive( active );
119 //=======================================================================
122 //=======================================================================
123 _PTR(Study) SMESHGUI_Operation::studyDS() const
125 SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( study() );
129 //=======================================================================
132 //=======================================================================
133 void SMESHGUI_Operation::onOk()
141 //=======================================================================
144 //=======================================================================
145 bool SMESHGUI_Operation::onApply()
150 //=======================================================================
153 //=======================================================================
154 void SMESHGUI_Operation::onCancel()
159 //=======================================================================
162 //=======================================================================
163 void SMESHGUI_Operation::initDialog()
168 * \brief Verifies whether study of operation is locked
169 * \param theMess - specifies whether message box must be shown if study is locked
170 * \return State of study.
172 * Verifies whether study of operation is locked. If second parameter is TRUE and study
173 * is locked when corresponding message box appears
175 bool SMESHGUI_Operation::isStudyLocked( const bool theMess ) const
179 if ( studyDS()->GetProperties()->IsLocked() )
182 SUIT_MessageBox::warn1 ( SMESHGUI::desktop(), QObject::tr( "WRN_WARNING" ),
183 QObject::tr( "WRN_STUDY_LOCKED" ), QObject::tr( "BUT_OK" ) );
192 * \brief Verifies whether given operator is valid for this one
193 * \param theOtherOp - other operation
194 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
196 * Virtual method redefined from base class verifies whether given operator is valid for
197 * this one (i.e. can be started "above" this operator). In current implementation method
198 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
201 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
203 static QStringList anOps;
204 if ( anOps.count() == 0 )
206 anOps.append( "SMESHGUI_DeleteOp" );
207 // to do add other operations here
210 return theOtherOp && theOtherOp->inherits( "SMESHGUI_Operation" ) &&
211 ( !anOps.contains( theOtherOp->className() ) || anOps.contains( className() ) );