Salome HOME
lot 12 GUI p.1
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_Poly3DDlg.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_Poly3DDlg.h"
20
21 #include "HYDROGUI_ObjSelector.h"
22
23 #include <QCheckBox>
24 #include <QGroupBox>
25 #include <QLabel>
26 #include <QLayout>
27 #include <QLineEdit>
28
29 HYDROGUI_Poly3DDlg::HYDROGUI_Poly3DDlg( HYDROGUI_Module* theModule, const QString& theTitle )
30 : HYDROGUI_InputPanel( theModule, theTitle ),
31   myIsEdit( false )
32 {
33   // Profile name
34   QGroupBox* aNameGroup = new QGroupBox( tr( "POLYLINE_3D_NAME" ) );
35
36   QLabel* aNameLabel = new QLabel( tr( "NAME" ), aNameGroup );
37   myName = new QLineEdit( aNameGroup );
38
39   QGridLayout* aNameLayout = new QGridLayout( aNameGroup );
40   aNameLayout->setMargin( 5 );
41   aNameLayout->setSpacing( 5 );
42   aNameLayout->addWidget( aNameLabel,       0, 0 );
43   aNameLayout->addWidget( myName,           0, 1 );
44
45   // Parameters
46   QGroupBox* aParamGroup = new QGroupBox( tr( "PARAMETERS" ) );
47
48   myPolylineLabel = new QLabel( tr( "POLYLINE" ), aParamGroup );
49   myPolyline = new HYDROGUI_ObjSelector( theModule, KIND_POLYLINEXY, aParamGroup );
50
51   myProfileLabel = new QLabel( tr( "PROFILE" ), aParamGroup );
52   myProfile = new HYDROGUI_ObjSelector( theModule, KIND_PROFILE, aParamGroup );
53   
54   myBathLabel = new QLabel( tr( "BATH" ), aParamGroup );
55   myBath = new HYDROGUI_ObjSelector( theModule, KIND_BATHYMETRY, aParamGroup );
56
57   QGridLayout* aParamLayout = new QGridLayout( aParamGroup );
58   aParamLayout->setMargin( 5 );
59   aParamLayout->setSpacing( 5 );
60   aParamLayout->addWidget( myPolylineLabel,  0, 0 );
61   aParamLayout->addWidget( myPolyline,       0, 1 );
62   aParamLayout->addWidget( myProfileLabel,   1, 0 );
63   aParamLayout->addWidget( myProfile,        1, 1 );
64   aParamLayout->addWidget( myBathLabel,      2, 0 );
65   aParamLayout->addWidget( myBath,           2, 1 );
66
67   // Common
68   addWidget( aNameGroup );
69   addWidget( aParamGroup );
70   addStretch();
71
72   setMode( myIsEdit );
73
74   connect( myProfile, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
75   connect( myBath, SIGNAL( selectionChanged() ), this, SLOT( OnSelectionChanged() ) );
76 }
77
78 HYDROGUI_Poly3DDlg::~HYDROGUI_Poly3DDlg()
79 {
80 }
81
82 void HYDROGUI_Poly3DDlg::reset()
83 {
84   myName->clear();
85   myProfile->Clear();
86   myPolyline->Clear();
87 }
88
89 void HYDROGUI_Poly3DDlg::setMode( const bool theIsEdit )
90 {
91   myIsEdit = theIsEdit;
92 }
93
94 void HYDROGUI_Poly3DDlg::setResultName( const QString& theName )
95 {
96   myName->setText( theName );
97 }
98
99 QString HYDROGUI_Poly3DDlg::getResultName() const
100 {
101   return myName->text();
102 }
103
104 void HYDROGUI_Poly3DDlg::setSelectedObjects( const QString& theNamePoly,
105                                              const QString& theNameProfile,
106                                              const QString& theNameBath )
107 {
108   myPolyline->SetName( theNamePoly );
109   myProfile->SetName( theNameProfile );
110   myBath->SetName( theNameBath );
111 }
112
113 bool HYDROGUI_Poly3DDlg::getSelectedObjects( QString& theNamePoly,
114                                              QString& theNameProfile,
115                                              QString& theNameBath ) const
116 {
117   theNamePoly = myPolyline->GetName();
118   theNameProfile = myProfile->GetName();
119   theNameBath = myBath->GetName();
120   return !theNamePoly.isEmpty() && ( !theNameProfile.isEmpty() || !theNameBath.isEmpty() );
121 }
122
123 void HYDROGUI_Poly3DDlg::setPreselectedObject( const QString& theName )
124 {
125   myProfile->SetName( theName );
126   myPolyline->SetChecked( true );
127   myPolyline->SetName( QString() );
128 }
129
130 void HYDROGUI_Poly3DDlg::OnSelectionChanged()
131 {
132   if( sender()==myProfile && !myProfile->GetName().isEmpty() )
133     myBath->Clear();
134   if( sender()==myBath && !myBath->GetName().isEmpty() )
135     myProfile->Clear();
136 }