]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_CreateHypothesesDlg.cxx
Salome HOME
e5e2285d4c723b271e82f6550d7e5f1becb67853
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_CreateHypothesesDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  CEA
4 //
5 //  This library is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU Lesser General Public
7 //  License as published by the Free Software Foundation; either
8 //  version 2.1 of the License.
9 //
10 //  This library is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 //  Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with this library; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 //
19 //  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
20 //
21 //
22 //
23 //  File   : SMESHGUI_CreateHypothesesDlg.cxx
24 //  Author : Julia DOROVSKIKH
25 //  Module : SMESH
26 //  $Header$
27
28 #include "SMESHGUI_CreateHypothesesDlg.h"
29
30 #include "SUIT_Desktop.h"
31 #include "SUIT_ResourceMgr.h"
32
33 #include "SALOME_ListIteratorOfListIO.hxx"
34
35 #include "utilities.h"
36
37 // QT Includes
38 #include <qbuttongroup.h>
39 #include <qgroupbox.h>
40 #include <qpushbutton.h>
41 #include <qlayout.h>
42 #include <qlistview.h>
43 #include <qheader.h>
44
45 /*!
46  * \brief Constructor
47   * \param theIsAlgo - If TRUE when operator is used for creation of gypotheses
48 *
49 * Constructor does nothing
50 */
51 SMESHGUI_CreateHypothesesDlg::SMESHGUI_CreateHypothesesDlg ( bool isAlgo )
52 : SMESHGUI_Dialog( 0, false, true, Apply | Cancel ),
53   myIsAlgo(isAlgo)
54 {
55   setCaption(  isAlgo ? tr( "SMESH_CREATE_ALGORITHMS"  ) : tr( "SMESH_CREATE_HYPOTHESES"  )  );
56   setSizeGripEnabled( TRUE  );
57
58   QGridLayout* SMESHGUI_CreateHypothesesDlgLayout = new QGridLayout( mainFrame() );
59   SMESHGUI_CreateHypothesesDlgLayout->setSpacing( 6 );
60   SMESHGUI_CreateHypothesesDlgLayout->setMargin( 11 );
61
62   /***************************************************************/
63   QGroupBox* GroupAlgorithms = new QGroupBox( mainFrame(), "GroupAlgorithms" );
64   GroupAlgorithms->setTitle( isAlgo ? tr( "SMESH_AVAILABLE_ALGORITHMS" ) : tr( "SMESH_AVAILABLE_HYPOTHESES" ) );
65   GroupAlgorithms->setColumnLayout( 0, Qt::Vertical );
66   GroupAlgorithms->layout()->setSpacing( 0 );
67   GroupAlgorithms->layout()->setMargin( 0 );
68
69   QGridLayout* hypLayout = new QGridLayout( GroupAlgorithms->layout() );
70   hypLayout->setGeometry( QRect( 12, 18, 139, 250 ) );
71   hypLayout->setAlignment( Qt::AlignTop );
72   hypLayout->setSpacing( 6 );
73   hypLayout->setMargin( 11 );
74
75   myList = new QListView( GroupAlgorithms, "myList" );
76   myList->setMinimumSize( 400, 200 );
77   myList->addColumn( "" );
78   myList->header()->hide();
79   myList->setSelectionMode( QListView::Single );
80   myList->setResizeMode( QListView::AllColumns );
81   myList->setRootIsDecorated( true );
82
83   hypLayout->addWidget( myList, 0, 0 );
84   SMESHGUI_CreateHypothesesDlgLayout->addWidget( GroupAlgorithms, 0, 0 );
85
86   setButtonText( Apply, tr( "SMESH_BUT_CREATE" ) );
87
88   // connect signals and slots
89   connect( myList, SIGNAL( selectionChanged() ), SLOT( onHypSelected() ) );
90   connect( myList, SIGNAL( doubleClicked( QListViewItem* ) ), SLOT( onDoubleClicked( QListViewItem* ) ) );
91
92   // update button state
93   onHypSelected();
94 }
95
96 /*!
97  * \brief Destructor
98 */
99 SMESHGUI_CreateHypothesesDlg::~SMESHGUI_CreateHypothesesDlg()
100 {
101 }
102
103 /*!
104  * \brief Get Name of hypotheses or algorithm
105   * \return Name of hypotheses or algorithm
106 */
107 QString SMESHGUI_CreateHypothesesDlg::hypName() const
108 {
109   QListViewItem* item = myList->selectedItem();
110   return item ? item->text( 1 ) : "";
111 }
112
113 /*!
114  * \brief Enable/Disable "Apply" button 
115 *
116 * Private slot called when selection in list box changed enables/disables "Apply" button
117 */
118 void SMESHGUI_CreateHypothesesDlg::onHypSelected()
119 {
120   QListViewItem* item = myList->selectedItem();
121   setButtonEnabled( item && item->depth() > 0, Apply );
122 }
123
124 /*!
125  * \brief Emits dlgApply signal
126   * \param i - clicked item
127 *
128 * Private slot called when item of list box is double clicked emits dlgApply signal
129 */
130 void SMESHGUI_CreateHypothesesDlg::onDoubleClicked ( QListViewItem* i )
131 {
132   if ( i && i->depth() > 0 )
133     emit dlgApply();
134 }
135
136 /*!
137  * \brief Initialize dialog
138   * \param theHypList - List of hypotheses
139   * \param theHypList - Plugin names
140   * \param theHypList - Labels
141   * \param theHypList - Icons' identifiers
142 *
143 * Initializes dialog with parameters. This method is called by operation before showing
144 * dialog
145 */
146 void SMESHGUI_CreateHypothesesDlg::init( const QStringList& theHypList,
147                                          const QStringList& thePluginNames,
148                                          const QStringList& theLabels,
149                                          const QStringList& theIconIds )
150 {
151   myList->clear();
152   for ( int i = 0; i < theHypList.count(); ++i )
153   {
154     QListViewItem* parentItem = 0;
155     QListViewItem* childItem = myList->firstChild();
156     while ( childItem )
157     {
158       if ( childItem->text( 0 ) == thePluginNames[ i ] )
159       {
160         parentItem = childItem;
161         break;
162       }
163       childItem = childItem->nextSibling();
164     }
165     
166     if ( !parentItem )
167       parentItem = new QListViewItem( myList, thePluginNames[ i ] );
168     parentItem->setOpen( true );
169     QListViewItem* aItem =
170       new QListViewItem( parentItem, theLabels[ i ], theHypList[ i ] );
171     QPixmap aPixMap( resMgr()->loadPixmap( "SMESH", tr( theIconIds[ i ] ) ) );
172     if ( !aPixMap.isNull() )
173       aItem->setPixmap( 0, aPixMap );
174   }
175 }
176
177
178
179
180
181
182
183
184
185