Salome HOME
Edit polyline operation was added
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PolylineOp.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 #include "HYDROGUI_Module.h"
23 #include "HYDROGUI_PolylineOp.h"
24 #include "HYDROGUI_PolylineDlg.h"
25 #include "HYDROGUI_Tool.h"
26
27 #include <HYDROData_Document.h>
28 #include <HYDROData_Polyline.h>
29
30 #include <LightApp_Application.h>
31 #include <LightApp_UpdateFlags.h>
32
33
34 HYDROGUI_PolylineOp::HYDROGUI_PolylineOp( HYDROGUI_Module* theModule, bool theIsEdit )
35 : HYDROGUI_Operation( theModule ), myIsEdit(theIsEdit)
36 {
37   setName( theIsEdit ? tr( "EDIT_POLYLINE" ) : tr( "CREATE_POLYLINE" ) );
38 }
39
40 HYDROGUI_PolylineOp::~HYDROGUI_PolylineOp()
41 {
42 }
43
44 HYDROGUI_InputPanel* HYDROGUI_PolylineOp::createInputPanel() const
45 {
46   return new HYDROGUI_PolylineDlg( module(), getName() );
47 }
48
49 bool HYDROGUI_PolylineOp::processApply( int& theUpdateFlags )
50 {
51   HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
52
53   int aStudyId = module()->getStudyId();
54   bool aHasDoc = HYDROData_Document::HasDocument(aStudyId);
55   Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( aStudyId );
56   if( aDocument.IsNull() )
57     return false;
58
59   Handle(HYDROData_Polyline) aPolylineObj;
60   if( myIsEdit ){
61     aPolylineObj = myEditedObject;
62   }
63   else{
64     aPolylineObj = Handle(HYDROData_Polyline)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
65   }
66
67   if( aPolylineObj.IsNull() )
68     return false;
69
70   if( !myIsEdit ){
71     static int PolylineId = 0;
72     aPolylineObj->SetName( QString( "Polyline_%1" ).arg( QString::number( ++PolylineId ) ) );
73   }
74
75   aPolylineObj->SetVisibility( true );
76
77   theUpdateFlags = UF_Model | UF_Viewer;
78   return true;
79 }
80
81 void HYDROGUI_PolylineOp::startOperation()
82 {
83   HYDROGUI_Operation::startOperation();
84
85   HYDROGUI_PolylineDlg* aPanel = (HYDROGUI_PolylineDlg*)inputPanel();
86   aPanel->reset();
87
88   myEditedObject = Handle(HYDROData_Polyline)::DownCast( HYDROGUI_Tool::GetSelectedObject( module() ) );
89   if( !myEditedObject.IsNull() )
90   {
91   }
92 }