1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_MeshInfosDlg.cxx
25 // Author : Nicolas BARBEROU
28 #include "SMESHGUI_MeshInfosDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
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>
41 #include <LightApp_SelectionMgr.h>
42 #include <LightApp_Application.h>
43 #include <SALOME_ListIO.hxx>
45 // SALOME KERNEL includes
46 #include <SALOMEDSClient_Study.hxx>
52 #include <QStackedWidget>
53 #include <QVBoxLayout>
54 #include <QHBoxLayout>
55 #include <QGridLayout>
56 #include <QPushButton>
60 #include <SALOMEconfig.h>
61 #include CORBA_SERVER_HEADER(SMESH_Mesh)
62 #include CORBA_SERVER_HEADER(SMESH_Group)
64 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
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)),
78 setAttribute( Qt::WA_DeleteOnClose, true );
79 setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
80 setSizeGripEnabled(true);
82 myStartSelection = true;
83 myIsActiveWindow = true;
85 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
86 aTopLayout->setSpacing(SPACING); aTopLayout->setMargin(MARGIN);
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));
94 mySelectLab = new QLabel(this);
95 mySelectLab->setAlignment(Qt::AlignCenter);
96 QFont fnt = mySelectLab->font(); fnt.setBold(true);
97 mySelectLab->setFont(fnt);
99 QHBoxLayout* aSelectLayout = new QHBoxLayout;
100 aSelectLayout->setMargin(0); aSelectLayout->setSpacing(0);
101 aSelectLayout->addWidget(mySelectBtn);
102 aSelectLayout->addWidget(mySelectLab);
105 myWGStack = new QStackedWidget(this);
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);
117 myMeshWidget = new QWidget(myWGStack);
118 QGridLayout* aMeshLayout = new QGridLayout(myMeshWidget);
119 aMeshLayout->setSpacing(SPACING); aMeshLayout->setMargin(0);
120 myWGStack->addWidget(myMeshWidget);
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);
129 myMeshInfoBox = new SMESHGUI_MeshInfosBox(true, myMeshWidget);
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);
138 myButtonsGroup = new QGroupBox(this);
139 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
140 myButtonsGroupLayout->setSpacing(SPACING); myButtonsGroupLayout->setMargin(MARGIN);
142 // buttons --> OK and Help buttons
143 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup);
144 myOkBtn->setAutoDefault(true);
145 myOkBtn->setDefault(true);
147 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
148 myHelpBtn->setAutoDefault(true);
150 myButtonsGroupLayout->addWidget(myOkBtn);
151 myButtonsGroupLayout->addSpacing(10);
152 myButtonsGroupLayout->addStretch();
153 myButtonsGroupLayout->addWidget(myHelpBtn);
155 aTopLayout->addLayout(aSelectLayout);
156 aTopLayout->addWidget(myWGStack);
157 aTopLayout->addWidget(myButtonsGroup);
159 mySMESHGUI->SetActiveDialogBox(this);
162 connect(myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
163 connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
164 connect(mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
165 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
166 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
167 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
169 // init dialog with current selection
170 onSelectionChanged();
172 myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
175 //=================================================================================
176 // function : ~SMESHGUI_MeshInfosDlg()
177 // purpose : Destructor
178 //=================================================================================
179 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
183 //=================================================================================
184 // function : DumpMeshInfos()
186 //=================================================================================
187 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
189 SUIT_OverrideCursor wc;
192 mySelectionMgr->selectedObjects(aList);
194 int nbSel = aList.Extent();
196 myStartSelection = false;
197 mySelectLab->setText("");
198 Handle(SALOME_InteractiveObject) IObject = aList.First();
199 _PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
201 //CORBA::Object_var anObject = aSO->GetObject();
202 CORBA::Object_var anObject = SMESH::SObjectToObject(aSO);
203 if (!CORBA::is_nil(anObject)) {
204 SMESH::SMESH_IDSource_var anIDSource = SMESH::SMESH_IDSource::_narrow(anObject);
205 if (!anIDSource->_is_nil()) {
206 myWGStack->setCurrentWidget(myMeshWidget);
207 setWindowTitle(tr("SMESH_MESHINFO_TITLE") + " [" + tr("SMESH_OBJECT_MESH") + "]");
208 myMeshName->setText(aSO->GetName().c_str());
210 SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
211 myMeshInfoBox->SetMeshInfo( aMeshInfo );
218 myWGStack->setCurrentIndex(0);
219 setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
222 //=================================================================================
223 // function : SelectionIntoArgument()
224 // purpose : Called when selection has changed
225 //=================================================================================
226 void SMESHGUI_MeshInfosDlg::onSelectionChanged()
228 if (myStartSelection)
232 //=================================================================================
233 // function : closeEvent()
235 //=================================================================================
236 void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
238 mySMESHGUI->ResetState();
239 QDialog::closeEvent(e);
242 //=================================================================================
243 // function : windowActivationChange()
244 // purpose : called when window is activated/deactivated
245 //=================================================================================
246 void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
248 QDialog::windowActivationChange(oldActive);
249 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
250 ActivateThisDialog();
251 myIsActiveWindow = isActiveWindow();
254 //=================================================================================
255 // function : DeactivateActiveDialog()
257 //=================================================================================
258 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
260 disconnect(mySelectionMgr, 0, this, 0);
263 //=================================================================================
264 // function : ActivateThisDialog()
266 //=================================================================================
267 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
269 /* Emit a signal to deactivate any active dialog */
270 mySMESHGUI->EmitSignalDeactivateDialog();
271 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
274 //=================================================================================
275 // function : onStartSelection()
276 // purpose : starts selection
277 //=================================================================================
278 void SMESHGUI_MeshInfosDlg::onStartSelection()
280 myStartSelection = true;
281 onSelectionChanged();
282 myStartSelection = true;
283 mySelectLab->setText(tr("INF_SELECT_OBJECT"));
286 //=================================================================================
287 // function : onHelp()
289 //=================================================================================
290 void SMESHGUI_MeshInfosDlg::onHelp()
292 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
294 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
298 platform = "winapplication";
300 platform = "application";
302 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
303 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
304 arg(app->resourceMgr()->stringValue("ExternalBrowser",
306 arg(myHelpFileName));
310 //=================================================================================
311 // function : keyPressEvent()
313 //=================================================================================
314 void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
316 QDialog::keyPressEvent( e );
317 if ( e->isAccepted() )
320 if ( e->key() == Qt::Key_F1 ) {