]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_Operation.cxx
Salome HOME
Undo/Redo operation.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Operation.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_Operation.h"
24
25 #include "HYDROGUI_InputPanel.h"
26 #include "HYDROGUI_Module.h"
27 #include "HYDROGUI_Tool.h"
28
29 #include <HYDROData_Document.h>
30 #include <HYDROData_Iterator.h>
31
32 #include <LightApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34
35 #include <SUIT_Desktop.h>
36 #include <SUIT_Study.h>
37
38 HYDROGUI_Operation::HYDROGUI_Operation( HYDROGUI_Module* theModule )
39 : LightApp_Operation(),
40   myModule( theModule ),
41   myPanel( 0 )
42 {
43 }
44
45 HYDROGUI_Operation::~HYDROGUI_Operation()
46 {
47 }
48
49 void HYDROGUI_Operation::setName( const QString& theName )
50 {
51   myName = theName;
52 }
53
54 const QString& HYDROGUI_Operation::getName() const
55 {
56   return myName;
57 }
58
59 SUIT_SelectionMgr* HYDROGUI_Operation::selectionMgr() const
60 {
61   return myModule->getApp()->selectionMgr();
62 }
63
64 HYDROGUI_Module* HYDROGUI_Operation::module() const
65 {
66   return myModule;
67 }
68
69 void HYDROGUI_Operation::startOperation()
70 {
71   LightApp_Operation::startOperation();
72
73   doc()->StartOperation();
74
75   if( inputPanel() )
76   {
77     inputPanel()->show();
78     myModule->getApp()->desktop()->addDockWidget( Qt::RightDockWidgetArea, inputPanel() );
79   }
80 }
81
82 void HYDROGUI_Operation::abortOperation()
83 {
84   doc()->AbortOperation();
85
86   LightApp_Operation::abortOperation();
87
88   if( inputPanel() )
89     inputPanel()->hide();
90 }
91
92 void HYDROGUI_Operation::commitOperation()
93 {
94   doc()->CommitOperation( HYDROGUI_Tool::ToExtString( getName() ) );
95
96   LightApp_Operation::commitOperation();
97
98   if( inputPanel() )
99     inputPanel()->hide();
100 }
101
102 HYDROGUI_InputPanel* HYDROGUI_Operation::inputPanel() const
103 {
104   if( !myPanel )
105   {
106     ( ( HYDROGUI_Operation* )this )->myPanel = createInputPanel();
107     connect( myPanel, SIGNAL( panelApply() ),  this, SLOT( onApply() ) );
108     connect( myPanel, SIGNAL( panelCancel() ), this, SLOT( onCancel() ) );
109   }
110   return myPanel;
111 }
112
113 Handle_HYDROData_Document HYDROGUI_Operation::doc() const
114 {
115   int aStudyId = myModule->application()->activeStudy()->id();
116   return HYDROData_Document::Document( aStudyId );
117 }
118
119 void HYDROGUI_Operation::onApply()
120 {
121   commit();
122 }
123
124 void HYDROGUI_Operation::onCancel()
125 {
126   abort();
127 }
128
129 Handle_HYDROData_Object HYDROGUI_Operation::FindObjectByName( const QString& theName, int theKind ) const
130 {
131   HYDROData_Iterator anIt( doc(), theKind );
132   for( ; anIt.More(); anIt.Next() )
133   {
134     if( anIt.Current()->GetName() == theName )
135       return anIt.Current();
136   }
137   return Handle_HYDROData_Object();
138 }