Salome HOME
Merge branch 'BR_LAND_COVER_MAP' into BR_quadtree
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_PolylineDlg.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_PolylineDlg.h"
20
21 #include "HYDROGUI_Module.h"
22 #include <CurveCreator_Widget.h>
23 #include <CurveCreator_ICurve.hxx>
24
25 #include <OCCViewer_ViewModel.h>
26
27 #include <QGroupBox>
28 #include <QHBoxLayout>
29 #include <QLabel>
30 #include <QLineEdit>
31 #include <QScrollArea>
32
33 HYDROGUI_PolylineDlg::HYDROGUI_PolylineDlg( HYDROGUI_Module* theModule, const QString& theTitle )
34 : HYDROGUI_InputPanel( theModule, theTitle ), myName(NULL)
35 {
36   QScrollArea* aScrollView = new QScrollArea( this );
37   aScrollView->setFrameStyle( QFrame::NoFrame );
38   addWidget( aScrollView );
39
40   QWidget* aContent = new QWidget( aScrollView );
41   QVBoxLayout* aCLayout = new QVBoxLayout( aContent );
42   aCLayout->setMargin( 0 );
43
44   aScrollView->setWidget( aContent );
45   aScrollView->setWidgetResizable( true );
46
47   QHBoxLayout* aNameLayout = new QHBoxLayout();
48   QLabel* aNameLabel = new QLabel(tr("POLYLINE_NAME_TLT"), aContent);
49   aNameLayout->addWidget(aNameLabel);
50   myName = new QLineEdit(aContent);
51   aNameLayout->addWidget(myName);
52
53   aCLayout->addLayout(aNameLayout);
54
55   myEditorWidget = new CurveCreator_Widget( aContent, NULL );
56   aCLayout->addWidget( myEditorWidget, 3 );
57
58   myAddElementBox = new QGroupBox( tr( "ADD_ELEMENT" ), aContent );
59   aCLayout->addWidget( myAddElementBox, 2 );
60
61   QBoxLayout* anAddElementLayout = new QVBoxLayout( myAddElementBox );
62   anAddElementLayout->setMargin( 0 );
63   anAddElementLayout->setSpacing( 5 );
64
65   connect( myEditorWidget, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
66   connect( myEditorWidget, SIGNAL( subOperationStarted(QWidget*, bool) ), this, SLOT( processStartedSubOperation(QWidget*, bool) ) );
67   connect( myEditorWidget, SIGNAL( subOperationFinished(QWidget*) ), this, SLOT( processFinishedSubOperation(QWidget*) ) );
68
69   myAddElementBox->hide();
70 }
71
72 HYDROGUI_PolylineDlg::~HYDROGUI_PolylineDlg()
73 {
74 }
75
76 void HYDROGUI_PolylineDlg::setOCCViewer( OCCViewer_Viewer* theViewer )
77 {
78   myEditorWidget->setOCCViewer( theViewer );
79 }
80
81 void HYDROGUI_PolylineDlg::processStartedSubOperation( QWidget* theWidget, bool theIsEdit )
82 {
83   myEditorWidget->setEnabled( false );
84
85   myAddElementBox->setTitle( theIsEdit ? tr( "EDIT_ELEMENT" ) : tr( "ADD_ELEMENT" ) );
86   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
87   anAddElementLayout->addWidget( theWidget );
88
89   theWidget->show();
90   myAddElementBox->show();
91 }
92
93 void HYDROGUI_PolylineDlg::processFinishedSubOperation( QWidget* theWidget )
94 {
95   myEditorWidget->setEnabled( true );
96
97   QBoxLayout* anAddElementLayout = dynamic_cast<QBoxLayout*>( myAddElementBox->layout() );
98   anAddElementLayout->removeWidget( theWidget );
99
100   theWidget->hide();
101   myAddElementBox->hide();
102 }
103
104 void HYDROGUI_PolylineDlg::reset()
105 {
106 }
107
108 void HYDROGUI_PolylineDlg::setPolylineName( const QString& theName )
109 {
110   myName->setText(theName);
111 }
112
113 QString HYDROGUI_PolylineDlg::getPolylineName() const
114 {
115   return myName->text();
116 }
117
118 void HYDROGUI_PolylineDlg::setCurve( CurveCreator_ICurve* theCurve )
119 {
120   myEditorWidget->setCurve( theCurve );
121 }
122
123 QList<int> HYDROGUI_PolylineDlg::getSelectedSections()
124 {
125   return myEditorWidget->getSelectedSections();
126 }
127
128 /**
129  * Redirect the delete action to editor widget
130  */
131 void HYDROGUI_PolylineDlg::deleteSelected()
132 {
133   myEditorWidget->removeSelected();
134 }
135
136 /**
137  * Checks whether there are some to delete
138  */
139 bool HYDROGUI_PolylineDlg::deleteEnabled()
140 {
141   return myEditorWidget->removeEnabled();
142 }