]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_CalculationOp.cxx
Salome HOME
25aac2717abbc34b2da26389c67bd370c649fda6
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_CalculationOp.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_CalculationOp.h"
24
25 #include "HYDROGUI_DataModel.h"
26 #include "HYDROGUI_CalculationDlg.h"
27 #include "HYDROGUI_Module.h"
28 #include "HYDROGUI_Tool.h"
29 #include "HYDROGUI_UpdateFlags.h"
30
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
33
34 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
35 : HYDROGUI_Operation( theModule ),
36   myIsEdit( theIsEdit )
37 {
38   setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
39 }
40
41 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
42 {
43 }
44
45 void HYDROGUI_CalculationOp::startOperation()
46 {
47   HYDROGUI_Operation::startOperation();
48
49   HYDROGUI_CalculationDlg* aPanel = 
50     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
51   if ( !aPanel )
52     return;
53
54   aPanel->reset();
55
56   QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
57
58   myEditedObject.Nullify();
59   if ( myIsEdit )
60   {
61     myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
62     if ( !myEditedObject.IsNull() )
63       anObjectName = myEditedObject->GetName();
64   }
65
66   aPanel->setObjectName( anObjectName );
67 }
68
69 void HYDROGUI_CalculationOp::abortOperation()
70 {
71   HYDROGUI_Operation::abortOperation();
72 }
73
74 void HYDROGUI_CalculationOp::commitOperation()
75 {
76   HYDROGUI_Operation::commitOperation();
77 }
78
79 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
80 {
81   HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
82   return aPanel;
83 }
84
85 bool HYDROGUI_CalculationOp::processApply( int&     theUpdateFlags,
86                                            QString& theErrorMsg )
87 {
88   HYDROGUI_CalculationDlg* aPanel = 
89     ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
90   if ( !aPanel )
91     return false;
92
93   QString anObjectName = aPanel->getObjectName().simplified();
94   if ( anObjectName.isEmpty() )
95   {
96     theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
97     return false;
98   }
99
100   // check that there are no other objects with the same name in the document
101   Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
102   if ( !anObject.IsNull() )
103   {
104     theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
105     return false;
106   }
107
108   Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
109     Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
110   if ( aCalculObj.IsNull() )
111     return false;
112
113   aCalculObj->SetName( anObjectName );
114
115   theUpdateFlags = UF_Model;
116
117   return true;
118 }
119
120