Salome HOME
land cover object is removed from the data model
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_LandCoverDlg.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_LandCoverDlg.h"
20
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_OrderedListWidget.h"
23 #include "HYDROGUI_ListSelector.h"
24
25 #include <LightApp_Application.h>
26 #include <LightApp_SelectionMgr.h>
27
28 #include <QGroupBox>
29 #include <QLabel>
30 #include <QLayout>
31 #include <QListWidget>
32 #include <QPushButton>
33
34 HYDROGUI_LandCoverDlg::HYDROGUI_LandCoverDlg( HYDROGUI_Module* theModule, const QString& theTitle )
35 : HYDROGUI_BasicZoneDlg( theModule, theTitle,
36                          tr( "LAND_COVER_NAME" ), tr( "NAME" ),
37                          tr( "LAND_COVER_PARAMETERS" ), tr( "LAND_COVER_STRICKLER_TYPE" ) )
38 {
39   myPolylines = new HYDROGUI_OrderedListWidget( myPolylineFrame, 16 );
40   myPolylines->setHiddenObjectsShown(true);
41   myPolylines->setVisibilityIconShown(false);
42   myPolylines->setContentsMargins(QMargins());
43   myPolylines->setOrderingEnabled( true );
44
45   // Include/Exclude buttons
46   QFrame* aBtnsFrame = new QFrame( myPolylineFrame );
47   QVBoxLayout* aBtnsLayout = new QVBoxLayout( aBtnsFrame );
48   aBtnsLayout->setMargin( 0 );
49   aBtnsLayout->setSpacing( 5 );
50   aBtnsFrame->setLayout( aBtnsLayout );
51   QPushButton* anAddBtn = new QPushButton( tr("INCLUDE"), aBtnsFrame );
52   QPushButton* aRemoveBtn = new QPushButton( tr("EXCLUDE"), aBtnsFrame );
53
54   // Fill the butons frame with two buttons
55   aBtnsLayout->addWidget( anAddBtn );
56   aBtnsLayout->addWidget( aRemoveBtn );
57   aBtnsLayout->addStretch( 1 );
58
59   QGridLayout* aPolyLayout = new QGridLayout( myPolylineFrame );
60   aPolyLayout->setMargin( 0 );
61   aPolyLayout->setSpacing( 10 );
62   aPolyLayout->addWidget( new QLabel( tr( "LAND_COVER_POLYLINES" ), myPolylineFrame ), 0, 0, 1, 2 );
63   aPolyLayout->addWidget( aBtnsFrame, 1, 0, 1, 1 );
64   aPolyLayout->addWidget( myPolylines, 1, 1, 1, 1 );
65   
66   QBoxLayout* aParamLayout = new QVBoxLayout( myParamGroup );
67   aParamLayout->setMargin( 5 );
68   aParamLayout->setSpacing( 5 );
69   aParamLayout->addWidget( myPolylineFrame );
70
71   // Create selector
72   if ( module() ) {
73     HYDROGUI_ListSelector* aListSelector = 
74       new HYDROGUI_ListSelector( myPolylines, module()->getApp()->selectionMgr() );
75     aListSelector->setAutoBlock( true );
76   }
77
78   // Connect signals and slots
79   connect( myPolylines, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onZoneDefChanged() ) );
80   connect( myPolylines, SIGNAL( orderPolylinesChanged() ), SLOT( onOrderPolylinesChanged() ) );
81   connect( anAddBtn, SIGNAL( clicked() ), SIGNAL( addPolylines() ) );
82   connect( aRemoveBtn, SIGNAL( clicked() ), SIGNAL( removePolylines() ) );
83 }
84
85 HYDROGUI_LandCoverDlg::~HYDROGUI_LandCoverDlg()
86 {
87 }
88
89 void HYDROGUI_LandCoverDlg::reset()
90 {
91   bool isBlocked = blockSignals( true );
92
93   HYDROGUI_BasicZoneDlg::reset();
94
95   HYDROGUI_ListModel::Object2VisibleList anObject2VisibleList;
96   myPolylines->setObjects(anObject2VisibleList);
97   myPolylines->setOrderingEnabled( false );
98   
99   blockSignals( isBlocked );
100
101   onZoneDefChanged();
102 }
103
104 bool HYDROGUI_LandCoverDlg::includePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
105 {
106   QStringList anIncludedPolylinesNames = myPolylines->getAllNames();
107
108   bool aSetOfPolylinesChanged = false;
109   foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
110   {
111     if ( !anIncludedPolylinesNames.contains( aSelectedPolyline.first->GetName() ) )
112     {
113       myPolylines->addObject( aSelectedPolyline );
114       aSetOfPolylinesChanged = true;
115     }
116   }
117   myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
118
119   return aSetOfPolylinesChanged;
120 }
121
122 bool HYDROGUI_LandCoverDlg::excludePolylines( const HYDROGUI_ListModel::Object2VisibleList& theSelectedPolylines )
123 {
124   bool aSetOfPolylinesChanged = !theSelectedPolylines.isEmpty();
125
126   foreach ( const HYDROGUI_ListModel::Object2Visible& aSelectedPolyline, theSelectedPolylines )
127     myPolylines->removeObjectByName( aSelectedPolyline.first->GetName() );
128   myPolylines->setOrderingEnabled( myPolylines->getObjects().count() > 1 );
129
130   return aSetOfPolylinesChanged;
131 }
132
133 QStringList HYDROGUI_LandCoverDlg::getPolylineNames() const
134 {
135   return myPolylines->getAllNames();
136 }
137
138 QStringList HYDROGUI_LandCoverDlg::getSelectedPolylineNames() const
139 {
140   return myPolylines->getSelectedNames();
141 }
142
143 void HYDROGUI_LandCoverDlg::onZoneDefChanged()
144 {
145   if ( signalsBlocked() )
146     return;
147
148   QStringList aPolylineNames = getPolylineNames();
149   emit CreatePreview( aPolylineNames );
150 }
151
152 void HYDROGUI_LandCoverDlg::onOrderPolylinesChanged()
153 {
154   // TODO: implement this method
155 }