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 <HYDROData_Polyline.h>
33 #include <LightApp_Application.h>
34 #include <LightApp_UpdateFlags.h>
36 HYDROGUI_CalculationOp::HYDROGUI_CalculationOp( HYDROGUI_Module* theModule, bool theIsEdit )
37 : HYDROGUI_Operation( theModule ),
40 setName( myIsEdit ? tr( "EDIT_CALCULATION" ) : tr( "CREATE_CALCULATION" ) );
43 HYDROGUI_CalculationOp::~HYDROGUI_CalculationOp()
47 void HYDROGUI_CalculationOp::startOperation()
49 HYDROGUI_Operation::startOperation();
51 HYDROGUI_CalculationDlg* aPanel =
52 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
58 QString anObjectName = HYDROGUI_Tool::GenerateObjectName( module(), "Case" );
60 myEditedObject.Nullify();
63 myEditedObject = Handle(HYDROData_Calculation)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
64 if ( !myEditedObject.IsNull() )
66 anObjectName = myEditedObject->GetName();
68 Handle(HYDROData_Polyline) aBoundaryPolyline = myEditedObject->GetBoundaryPolyline();
69 if ( !aBoundaryPolyline.IsNull() )
71 QString aPolylineName = aBoundaryPolyline->GetName();
72 aPanel->setPolylineName( aPolylineName );
77 aPanel->setObjectName( anObjectName );
80 void HYDROGUI_CalculationOp::abortOperation()
82 HYDROGUI_Operation::abortOperation();
85 void HYDROGUI_CalculationOp::commitOperation()
87 HYDROGUI_Operation::commitOperation();
90 HYDROGUI_InputPanel* HYDROGUI_CalculationOp::createInputPanel() const
92 HYDROGUI_CalculationDlg* aPanel = new HYDROGUI_CalculationDlg( module(), getName() );
96 bool HYDROGUI_CalculationOp::processApply( int& theUpdateFlags,
97 QString& theErrorMsg )
99 HYDROGUI_CalculationDlg* aPanel =
100 ::qobject_cast<HYDROGUI_CalculationDlg*>( inputPanel() );
104 QString anObjectName = aPanel->getObjectName().simplified();
105 if ( anObjectName.isEmpty() )
107 theErrorMsg = tr( "INCORRECT_OBJECT_NAME" );
111 // check that there are no other objects with the same name in the document
112 Handle(HYDROData_Object) anObject = HYDROGUI_Tool::FindObjectByName( module(), anObjectName );
113 if ( !anObject.IsNull() )
115 theErrorMsg = tr( "OBJECT_EXISTS_IN_DOCUMENT" ).arg( anObjectName );
119 Handle(HYDROData_Calculation) aCalculObj = myIsEdit ? myEditedObject :
120 Handle(HYDROData_Calculation)::DownCast( doc()->CreateObject( KIND_CALCULATION ) );
121 if ( aCalculObj.IsNull() )
124 aCalculObj->SetName( anObjectName );
126 Handle(HYDROData_Polyline) aBndPolyline;
128 QString aPolylineName = aPanel->getPolylineName();
129 if ( !aPolylineName.isEmpty() )
131 aBndPolyline = Handle(HYDROData_Polyline)::DownCast(
132 HYDROGUI_Tool::FindObjectByName( module(), aPolylineName, KIND_POLYLINE ) );
135 aCalculObj->SetBoundaryPolyline( aBndPolyline );
137 theUpdateFlags = UF_Model;