Salome HOME
0020889: EDF 1433 SMESH: SplitHexaToTetra: add the 24 tetras mode
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshInfosDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_MeshInfosDlg.cxx
25 // Author : Nicolas BARBEROU
26 // SMESH includes
27 //
28 #include "SMESHGUI_MeshInfosDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33
34 // SALOME GUI includes
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SUIT_Session.h>
39 #include <SUIT_MessageBox.h>
40
41 #include <LightApp_SelectionMgr.h>
42 #include <LightApp_Application.h>
43 #include <SALOME_ListIO.hxx>
44
45 // SALOME KERNEL includes
46 #include <SALOMEDSClient_Study.hxx>
47
48 // Qt includes
49 #include <QGroupBox>
50 #include <QLabel>
51 #include <QFrame>
52 #include <QStackedWidget>
53 #include <QVBoxLayout>
54 #include <QHBoxLayout>
55 #include <QGridLayout>
56 #include <QPushButton>
57 #include <QKeyEvent>
58
59 // IDL includes
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
62 #include CORBA_SERVER_HEADER(SMESH_Group)
63
64 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
65 #define SPACING 6
66 #define MARGIN  11
67
68 //=================================================================================
69 // function : SMESHGUI_MeshInfosDlg()
70 // purpose  : Constructor
71 //=================================================================================
72 SMESHGUI_MeshInfosDlg::SMESHGUI_MeshInfosDlg(SMESHGUI* theModule): 
73   QDialog(SMESH::GetDesktop(theModule)),
74   mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
75   mySMESHGUI(theModule)
76 {
77   setModal( false );
78   setAttribute( Qt::WA_DeleteOnClose, true );
79   setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
80   setSizeGripEnabled(true);
81
82   myStartSelection = true;
83   myIsActiveWindow = true;
84
85   QVBoxLayout* aTopLayout = new QVBoxLayout(this);
86   aTopLayout->setSpacing(SPACING);  aTopLayout->setMargin(MARGIN);
87
88   // select button & label
89   QPixmap image0(SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH",tr("ICON_SELECT")));
90   mySelectBtn = new QPushButton(this);
91   mySelectBtn->setIcon(image0);
92   mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
93
94   mySelectLab = new QLabel(this);
95   mySelectLab->setAlignment(Qt::AlignCenter);
96   QFont fnt = mySelectLab->font(); fnt.setBold(true);
97   mySelectLab->setFont(fnt);
98
99   QHBoxLayout* aSelectLayout = new QHBoxLayout;
100   aSelectLayout->setMargin(0); aSelectLayout->setSpacing(0);
101   aSelectLayout->addWidget(mySelectBtn);
102   aSelectLayout->addWidget(mySelectLab);
103
104   // top widget stack
105   myWGStack = new QStackedWidget(this);
106
107   // no valid selection
108   QWidget* myBadWidget = new QWidget(myWGStack);
109   QVBoxLayout* aBadLayout = new QVBoxLayout(myBadWidget);
110   QLabel* myBadLab = new QLabel(tr("SMESH_BAD_SELECTION"), myBadWidget);
111   myBadLab->setAlignment(Qt::AlignCenter);
112   myBadLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
113   aBadLayout->addWidget(myBadLab);
114   myWGStack->addWidget(myBadWidget);
115
116   // mesh
117   myMeshWidget = new QWidget(myWGStack);
118   QGridLayout* aMeshLayout = new QGridLayout(myMeshWidget);
119   aMeshLayout->setSpacing(SPACING);  aMeshLayout->setMargin(0);
120   myWGStack->addWidget(myMeshWidget);
121
122   // --> name
123   QLabel* myMeshNameLab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NAME")), myMeshWidget);
124   myMeshName    = new QLabel(myMeshWidget);
125   myMeshName->setMinimumWidth(100);
126   QFrame* line1 = new QFrame(myMeshWidget);
127   line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
128
129   myMeshInfoBox = new SMESHGUI_MeshInfosBox(true, myMeshWidget);
130
131   aMeshLayout->addWidget(myMeshNameLab,      0, 0);
132   aMeshLayout->addWidget(myMeshName,         0, 1);
133   aMeshLayout->addWidget(line1,              1, 0, 1, 2);
134   aMeshLayout->addWidget(myMeshInfoBox,      2, 0, 1, 2);
135   aMeshLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0);
136
137   // buttons
138   myButtonsGroup = new QGroupBox(this);
139   QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
140   myButtonsGroupLayout->setSpacing(SPACING); myButtonsGroupLayout->setMargin(MARGIN);
141
142   // buttons --> OK and Help buttons
143   myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup);
144   myOkBtn->setAutoDefault(true); myOkBtn->setDefault(true);
145   myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
146   myHelpBtn->setAutoDefault(true);
147
148   myButtonsGroupLayout->addWidget(myOkBtn);
149   myButtonsGroupLayout->addSpacing(10);
150   myButtonsGroupLayout->addStretch();
151   myButtonsGroupLayout->addWidget(myHelpBtn);
152
153   aTopLayout->addLayout(aSelectLayout);
154   aTopLayout->addWidget(myWGStack);
155   aTopLayout->addWidget(myButtonsGroup);
156
157   mySMESHGUI->SetActiveDialogBox(this);
158
159   // connect signals
160   connect(myOkBtn,                 SIGNAL(clicked()),                      this, SLOT(close()));
161   connect( myHelpBtn,              SIGNAL(clicked()),                      this, SLOT(onHelp()));
162   connect(mySelectBtn,             SIGNAL(clicked()),                      this, SLOT(onStartSelection()));
163   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()),        this, SLOT(close()));
164   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
165   connect(mySelectionMgr,          SIGNAL(currentSelectionChanged()),      this, SLOT(onSelectionChanged()));
166
167   // init dialog with current selection
168   onSelectionChanged();
169
170   myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
171 }
172
173 //=================================================================================
174 // function : ~SMESHGUI_MeshInfosDlg()
175 // purpose  : Destructor
176 //=================================================================================
177 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
178 {
179 }
180
181 //=================================================================================
182 // function : DumpMeshInfos()
183 // purpose  : 
184 //=================================================================================
185 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
186 {
187   SUIT_OverrideCursor wc;
188
189   SALOME_ListIO aList;
190   mySelectionMgr->selectedObjects(aList);
191
192   int nbSel = aList.Extent();
193   if (nbSel == 1) {
194     myStartSelection = false;
195     mySelectLab->setText("");
196     Handle(SALOME_InteractiveObject) IObject = aList.First();
197     _PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
198     if (aSO) {
199       //CORBA::Object_var anObject = aSO->GetObject();
200       CORBA::Object_var anObject = SMESH::SObjectToObject(aSO);
201       if (!CORBA::is_nil(anObject)) {
202         SMESH::SMESH_IDSource_var anIDSource = SMESH::SMESH_IDSource::_narrow(anObject);
203         if (!anIDSource->_is_nil()) {
204           myWGStack->setCurrentWidget(myMeshWidget);
205           setWindowTitle(tr("SMESH_MESHINFO_TITLE") + " [" + tr("SMESH_OBJECT_MESH") + "]");
206           myMeshName->setText(aSO->GetName().c_str());
207
208           SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
209           myMeshInfoBox->SetMeshInfo( aMeshInfo );
210
211           return;
212         }
213       }
214     }
215   }
216   myWGStack->setCurrentIndex(0);
217   setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
218 }
219
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose  : Called when selection has changed
223 //=================================================================================
224 void SMESHGUI_MeshInfosDlg::onSelectionChanged()
225 {
226   if (myStartSelection)
227     DumpMeshInfos();
228 }
229
230 //=================================================================================
231 // function : closeEvent()
232 // purpose  :
233 //=================================================================================
234 void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
235 {
236   mySMESHGUI->ResetState();
237   QDialog::closeEvent(e);
238 }
239
240 //=================================================================================
241 // function : windowActivationChange()
242 // purpose  : called when window is activated/deactivated
243 //=================================================================================
244 void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
245 {
246   QDialog::windowActivationChange(oldActive);
247   if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
248     ActivateThisDialog();
249   myIsActiveWindow = isActiveWindow();
250 }
251
252 //=================================================================================
253 // function : DeactivateActiveDialog()
254 // purpose  :
255 //=================================================================================
256 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
257 {
258   disconnect(mySelectionMgr, 0, this, 0);
259 }
260
261 //=================================================================================
262 // function : ActivateThisDialog()
263 // purpose  :
264 //=================================================================================
265 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
266 {
267   /* Emit a signal to deactivate any active dialog */
268   mySMESHGUI->EmitSignalDeactivateDialog();
269   connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
270 }
271
272 //=================================================================================
273 // function : onStartSelection()
274 // purpose  : starts selection
275 //=================================================================================
276 void SMESHGUI_MeshInfosDlg::onStartSelection()
277 {
278   myStartSelection = true;
279   onSelectionChanged();
280   myStartSelection = true;
281   mySelectLab->setText(tr("INF_SELECT_OBJECT"));
282 }
283
284 //=================================================================================
285 // function : onHelp()
286 // purpose  :
287 //=================================================================================
288 void SMESHGUI_MeshInfosDlg::onHelp()
289 {
290   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
291   if (app) 
292     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
293   else {
294     QString platform;
295 #ifdef WIN32
296     platform = "winapplication";
297 #else
298     platform = "application";
299 #endif
300     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
301                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
302                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
303                                                                  platform)).
304                              arg(myHelpFileName));
305   }
306 }
307
308 //=================================================================================
309 // function : keyPressEvent()
310 // purpose  :
311 //=================================================================================
312 void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
313 {
314   QDialog::keyPressEvent( e );
315   if ( e->isAccepted() )
316     return;
317
318   if ( e->key() == Qt::Key_F1 ) {
319     e->accept();
320     onHelp();
321   }
322 }