1 // Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_Operation.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
25 #include "SMESHGUI_Operation.h"
28 #include "SMESHGUI_Dialog.h"
30 // SALOME GUI includes
31 #include <SalomeApp_Study.h>
32 #include <LightApp_Application.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Desktop.h>
37 #include <SUIT_ResourceMgr.h>
40 #include <QStringList>
43 Class : SMESHGUI_Operation
44 Description : Base class for all SMESH operations
47 //=======================================================================
48 // name : SMESHGUI_Operation
49 // Purpose : Constructor
50 //=======================================================================
51 SMESHGUI_Operation::SMESHGUI_Operation()
52 : LightApp_Operation(),
53 myIsApplyAndClose( false )
58 //=======================================================================
59 // name : ~SMESHGUI_Operation
60 // Purpose : Destructor
61 //=======================================================================
62 SMESHGUI_Operation::~SMESHGUI_Operation()
66 //=======================================================================
68 // Purpose : Get SMESH module
69 //=======================================================================
70 SMESHGUI* SMESHGUI_Operation::getSMESHGUI() const
72 return dynamic_cast<SMESHGUI*>( module() );
75 //=======================================================================
76 // name : startOperation
77 // Purpose : Start operation
78 //=======================================================================
79 void SMESHGUI_Operation::startOperation()
83 disconnect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
84 disconnect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
85 disconnect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
86 disconnect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
87 disconnect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
89 if( dlg()->testButtonFlags( QtxDialog::OK ) )
90 connect( dlg(), SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
92 if( dlg()->testButtonFlags( QtxDialog::Apply ) )
93 connect( dlg(), SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
95 if( dlg()->testButtonFlags( QtxDialog::Cancel ) )
96 connect( dlg(), SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
98 if( dlg()->testButtonFlags( QtxDialog::Help ) )
99 connect( dlg(), SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
101 //if( dlg()->testButtonFlags( QtxDialog::Close ) )
102 //if dialog hasn't close, cancel, no and etc buttons, dlgClose will be emitted when dialog is closed not by OK
103 connect( dlg(), SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
108 LightApp_Operation::startOperation();
111 //=======================================================================
112 // name : isReadyToStart
113 // Purpose : Verify whether operation is ready to start
114 //=======================================================================
115 bool SMESHGUI_Operation::isReadyToStart() const
117 if ( !LightApp_Operation::isReadyToStart() )
119 else if ( getSMESHGUI() == 0 )
121 SUIT_MessageBox::warning( desktop(), tr( "SMESH_WRN_WARNING" ),
125 else if ( SMESHGUI::isStudyLocked() )
131 //=======================================================================
132 // name : setDialogActive
134 //=======================================================================
135 void SMESHGUI_Operation::setDialogActive( const bool active )
137 LightApp_Operation::setDialogActive( active );
139 SMESHGUI_Dialog* d = dynamic_cast<SMESHGUI_Dialog*>( dlg() );
141 d->setContentActive( active );
145 //=======================================================================
148 //=======================================================================
149 void SMESHGUI_Operation::onOk()
151 setIsApplyAndClose( true );
154 setIsApplyAndClose( false );
159 //=======================================================================
162 //=======================================================================
163 bool SMESHGUI_Operation::onApply()
168 //=======================================================================
171 //=======================================================================
172 void SMESHGUI_Operation::onCancel()
177 //=======================================================================
180 //=======================================================================
181 void SMESHGUI_Operation::onHelp()
183 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
185 app->onHelpContextModule(getSMESHGUI() ? app->moduleName(getSMESHGUI()->moduleName()) : QString(""), myHelpFileName);
189 platform = "winapplication";
191 platform = "application";
193 SUIT_MessageBox::warning( desktop(), tr("WRN_WARNING"),
194 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
195 arg(app->resourceMgr()->stringValue("ExternalBrowser",
197 arg(myHelpFileName) );
201 //=======================================================================
204 //=======================================================================
205 void SMESHGUI_Operation::initDialog()
209 //================================================================
210 // name : setIsApplyAndClose
211 // Purpose : Set value of the flag indicating that the dialog is
212 // accepted by Apply & Close button
213 //================================================================
214 void SMESHGUI_Operation::setIsApplyAndClose( const bool theFlag )
216 myIsApplyAndClose = theFlag;
219 //================================================================
220 // name : isApplyAndClose
221 // Purpose : Get value of the flag indicating that the dialog is
222 // accepted by Apply & Close button
223 //================================================================
224 bool SMESHGUI_Operation::isApplyAndClose() const
226 return myIsApplyAndClose;
230 * \brief Verifies whether given operator is valid for this one
231 * \param theOtherOp - other operation
232 * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
234 * Virtual method redefined from base class verifies whether given operator is valid for
235 * this one (i.e. can be started "above" this operator). In current implementation method
236 * returns false if theOtherOp operation is not intended for deleting objects or mesh
239 bool SMESHGUI_Operation::isValid( SUIT_Operation* theOtherOp ) const
241 static QStringList anOps;
242 if ( anOps.count() == 0 )
244 anOps.append( "SMESHGUI_DeleteOp" );
245 // to do add other operations here
248 return ( theOtherOp &&
249 ( ( theOtherOp->inherits("SMESHGUI_Operation") && ( !anOps.contains(theOtherOp->metaObject()->className() ) || anOps.contains(metaObject()->className()) ) ) ||
250 ( theOtherOp->inherits("LightApp_ShowHideOp") ) ) );