1 // Copyright (C) 2007-2013 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.
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
23 #include "HYDROGUI_CalculationOp.h"
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"
31 #include <LightApp_Application.h>
32 #include <LightApp_UpdateFlags.h>
34 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
35 : HYDROGUI_Operation( theModule ),
38 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
41 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
45 void HYDROGUI_CalculationOp::startOperation()
47 HYDROGUI_Operation::startOperation();
49 HYDROGUI_CalculationDlg* aPanel =
50 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
56 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
58 myEditedObject.Nullify();
61 myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
62 if ( !myEditedObject.IsNull() )
63 anObjectName = myEditedObject->GetName();
66 aPanel->setObjectName( anObjectName );
69 void HYDROGUI_CalculationOp::abortOperation()
71 HYDROGUI_Operation::abortOperation();
74 void HYDROGUI_CalculationOp::commitOperation()
76 HYDROGUI_Operation::commitOperation();
79 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
81 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
85 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
86 QString& theErrorMsg )
88 HYDROGUI_CalculationDlg* aPanel =
89 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
93 QString anObjectName = aPanel->getObjectName().simplified();
94 if ( anObjectName.isEmpty() )
96 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
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() )
104 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
108 Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
109 Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
110 if ( aCalculObj.IsNull() )
113 aCalculObj->SetName( anObjectName );
115 theUpdateFlags = UF_Model;