Salome HOME
latests developments debug and porting Python3
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_RecognizeContoursDlg.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_RecognizeContoursDlg.h"
20
21 #include <QGroupBox>
22 #include <QLabel>
23 #include <QLineEdit>
24 #include <QListWidget>
25 #include <QVBoxLayout>
26
27 /**
28  * Constructor.
29  * \param theModule the module
30  * \param theTitle the panel title
31  */
32 HYDROGUI_RecognizeContoursDlg::HYDROGUI_RecognizeContoursDlg( HYDROGUI_Module* theModule, const QString& theTitle )
33 : HYDROGUI_InputPanel( theModule, theTitle )
34 {
35   // Original image
36   QGroupBox* anImageGroup = new QGroupBox( tr( "ORIGINAL_IMAGE" ), mainFrame() );
37   QLabel* aNameLabel = new QLabel( tr("NAME") );
38   myImageName = new QLineEdit;
39   myImageName->setReadOnly( true );
40
41   QHBoxLayout* anImageLayout = new QHBoxLayout();
42   anImageLayout->addWidget( aNameLabel );
43   anImageLayout->addWidget( myImageName );
44   anImageGroup->setLayout( anImageLayout );
45
46   // List of recognized polylines
47   QGroupBox* aPolylinesGroup = new QGroupBox( tr( "RECOGNIZED_POLYLINES" ), mainFrame() );
48   myPolylines = new QListWidget( aPolylinesGroup );
49   myPolylines->setSelectionMode( QListWidget::ExtendedSelection );
50   myPolylines->setEditTriggers( QListWidget::NoEditTriggers );
51   myPolylines->setViewMode( QListWidget::ListMode );
52   myPolylines->setSortingEnabled( false );
53
54   QBoxLayout* aPolylinesLayout = new QVBoxLayout;
55   aPolylinesLayout->addWidget( myPolylines );
56   aPolylinesGroup->setLayout( aPolylinesLayout );
57
58   // Layout
59   addWidget( anImageGroup );
60   addWidget( aPolylinesGroup );
61
62   // Conections
63   connect( myPolylines, SIGNAL( itemSelectionChanged() ), this, SLOT( onItemSelectionChanged() ) );
64 }
65
66 /**
67  * Destructor.
68  */
69 HYDROGUI_RecognizeContoursDlg::~HYDROGUI_RecognizeContoursDlg()
70 {
71 }
72
73 /**
74  * Set the image name.
75  * \param theName the name
76  */
77 void HYDROGUI_RecognizeContoursDlg::setImageName( const QString& theName )
78 {
79   myImageName->setText( theName );
80 }
81
82 /**
83  * Reset the panel.
84  */
85 void HYDROGUI_RecognizeContoursDlg::reset()
86 {
87   myImageName->clear();
88   myPolylines->clear();
89 }
90
91 /**
92  * Refill the list of polylines names.
93  * \param theNames the list of names
94  */
95 void HYDROGUI_RecognizeContoursDlg::setPolylineNames( const QStringList& theNames )
96 {
97   myPolylines->clear();
98   myPolylines->addItems( theNames );
99 }
100
101 /**
102  * Remove the given polyline names from the list.
103  * \param theNames the list of names
104  */
105 void HYDROGUI_RecognizeContoursDlg::removePolylineNames( const QStringList& theNames )
106 {
107   QList<QListWidgetItem*> aFoundItems;
108
109   foreach ( const QString& aName, theNames ) {
110     aFoundItems = myPolylines->findItems( aName, Qt::MatchExactly );
111     foreach ( QListWidgetItem* anItem, aFoundItems ) {
112       anItem = myPolylines->takeItem( myPolylines->row( anItem ) );
113       delete anItem;
114     }
115   }
116 }
117
118 /**
119  * Select the given polyline names in the list.
120  * \param theNames the list of names
121  */
122 void HYDROGUI_RecognizeContoursDlg::setSelectedPolylineNames( const QStringList& theNames )
123 {
124   myPolylines->clearSelection();
125
126   foreach( const QString aName, theNames ) {
127     QList<QListWidgetItem*> anItems = myPolylines->findItems( aName, Qt::MatchExactly );
128     if ( anItems.count() == 1 ) {
129       anItems.first()->setSelected( true );
130     }
131   }
132 }
133
134 /**
135  * Slot called when polyline names selection changed.
136  */
137 void HYDROGUI_RecognizeContoursDlg::onItemSelectionChanged()
138 {
139   emit selectionChanged( getSelectedtPolylineNames() );
140 }
141
142 /**
143  * Get the list of selected polyline names.
144  * \return the list of names
145  */ 
146 QStringList HYDROGUI_RecognizeContoursDlg::getSelectedtPolylineNames() const
147 {
148   QStringList aSelectedNames;
149
150   QList<QListWidgetItem*> aSelectedItems = myPolylines->selectedItems();
151   foreach( const QListWidgetItem* anItem, aSelectedItems ) {
152     aSelectedNames << anItem->text();
153   }
154
155   return aSelectedNames;
156 }