1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_MeshInfosDlg.cxx
24 // Author : Nicolas BARBEROU
27 #include "SMESHGUI_MeshInfosDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_MeshInfosBox.h"
33 // SALOME GUI includes
34 #include <SUIT_Desktop.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_OverrideCursor.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_MessageBox.h>
40 #include <LightApp_SelectionMgr.h>
41 #include <LightApp_Application.h>
42 #include <SALOME_ListIO.hxx>
44 // SALOME KERNEL includes
45 #include <SALOMEDSClient_Study.hxx>
51 #include <QStackedWidget>
52 #include <QVBoxLayout>
53 #include <QHBoxLayout>
54 #include <QGridLayout>
55 #include <QPushButton>
59 #include <SALOMEconfig.h>
60 #include CORBA_SERVER_HEADER(SMESH_Mesh)
61 #include CORBA_SERVER_HEADER(SMESH_Group)
63 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
67 //=================================================================================
68 // function : SMESHGUI_MeshInfosDlg()
69 // purpose : Constructor
70 //=================================================================================
71 SMESHGUI_MeshInfosDlg::SMESHGUI_MeshInfosDlg(SMESHGUI* theModule):
72 QDialog(SMESH::GetDesktop(theModule)),
73 mySelectionMgr(SMESH::GetSelectionMgr(theModule)),
77 setAttribute( Qt::WA_DeleteOnClose, true );
78 setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
79 setSizeGripEnabled(true);
81 myStartSelection = true;
82 myIsActiveWindow = true;
84 QVBoxLayout* aTopLayout = new QVBoxLayout(this);
85 aTopLayout->setSpacing(SPACING); aTopLayout->setMargin(MARGIN);
87 // select button & label
88 QPixmap image0(SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH",tr("ICON_SELECT")));
89 mySelectBtn = new QPushButton(this);
90 mySelectBtn->setIcon(image0);
91 mySelectBtn->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
93 mySelectLab = new QLabel(this);
94 mySelectLab->setAlignment(Qt::AlignCenter);
95 QFont fnt = mySelectLab->font(); fnt.setBold(true);
96 mySelectLab->setFont(fnt);
98 QHBoxLayout* aSelectLayout = new QHBoxLayout;
99 aSelectLayout->setMargin(0); aSelectLayout->setSpacing(0);
100 aSelectLayout->addWidget(mySelectBtn);
101 aSelectLayout->addWidget(mySelectLab);
104 myWGStack = new QStackedWidget(this);
106 // no valid selection
107 QWidget* myBadWidget = new QWidget(myWGStack);
108 QVBoxLayout* aBadLayout = new QVBoxLayout(myBadWidget);
109 QLabel* myBadLab = new QLabel(tr("SMESH_BAD_SELECTION"), myBadWidget);
110 myBadLab->setAlignment(Qt::AlignCenter);
111 myBadLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
112 aBadLayout->addWidget(myBadLab);
113 myWGStack->addWidget(myBadWidget);
116 myMeshWidget = new QWidget(myWGStack);
117 QGridLayout* aMeshLayout = new QGridLayout(myMeshWidget);
118 aMeshLayout->setSpacing(SPACING); aMeshLayout->setMargin(0);
119 myWGStack->addWidget(myMeshWidget);
122 QLabel* myMeshNameLab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NAME")), myMeshWidget);
123 myMeshName = new QLabel(myMeshWidget);
124 myMeshName->setMinimumWidth(100);
125 QFrame* line1 = new QFrame(myMeshWidget);
126 line1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
128 myMeshInfoBox = new SMESHGUI_MeshInfosBox(true, myMeshWidget);
130 aMeshLayout->addWidget(myMeshNameLab, 0, 0);
131 aMeshLayout->addWidget(myMeshName, 0, 1);
132 aMeshLayout->addWidget(line1, 1, 0, 1, 2);
133 aMeshLayout->addWidget(myMeshInfoBox, 2, 0, 1, 2);
134 aMeshLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 3, 0);
137 myButtonsGroup = new QGroupBox(this);
138 QHBoxLayout* myButtonsGroupLayout = new QHBoxLayout(myButtonsGroup);
139 myButtonsGroupLayout->setSpacing(SPACING); myButtonsGroupLayout->setMargin(MARGIN);
141 // buttons --> OK and Help buttons
142 myOkBtn = new QPushButton(tr("SMESH_BUT_OK" ), myButtonsGroup);
143 myOkBtn->setAutoDefault(true); myOkBtn->setDefault(true);
144 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
145 myHelpBtn->setAutoDefault(true);
147 myButtonsGroupLayout->addWidget(myOkBtn);
148 myButtonsGroupLayout->addSpacing(10);
149 myButtonsGroupLayout->addStretch();
150 myButtonsGroupLayout->addWidget(myHelpBtn);
152 aTopLayout->addLayout(aSelectLayout);
153 aTopLayout->addWidget(myWGStack);
154 aTopLayout->addWidget(myButtonsGroup);
156 mySMESHGUI->SetActiveDialogBox(this);
159 connect(myOkBtn, SIGNAL(clicked()), this, SLOT(close()));
160 connect( myHelpBtn, SIGNAL(clicked()), this, SLOT(onHelp()));
161 connect(mySelectBtn, SIGNAL(clicked()), this, SLOT(onStartSelection()));
162 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(close()));
163 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
164 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
166 // init dialog with current selection
167 onSelectionChanged();
169 myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
172 //=================================================================================
173 // function : ~SMESHGUI_MeshInfosDlg()
174 // purpose : Destructor
175 //=================================================================================
176 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
180 //=================================================================================
181 // function : DumpMeshInfos()
183 //=================================================================================
184 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
186 SUIT_OverrideCursor wc;
189 mySelectionMgr->selectedObjects(aList);
191 int nbSel = aList.Extent();
193 myStartSelection = false;
194 mySelectLab->setText("");
195 Handle(SALOME_InteractiveObject) IObject = aList.First();
196 _PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
198 //CORBA::Object_var anObject = aSO->GetObject();
199 CORBA::Object_var anObject = SMESH::SObjectToObject(aSO);
200 if (!CORBA::is_nil(anObject)) {
201 SMESH::SMESH_IDSource_var anIDSource = SMESH::SMESH_IDSource::_narrow(anObject);
202 if (!anIDSource->_is_nil()) {
203 myWGStack->setCurrentWidget(myMeshWidget);
204 setWindowTitle(tr("SMESH_MESHINFO_TITLE") + " [" + tr("SMESH_OBJECT_MESH") + "]");
205 myMeshName->setText(aSO->GetName().c_str());
207 SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
208 myMeshInfoBox->SetMeshInfo( aMeshInfo );
215 myWGStack->setCurrentIndex(0);
216 setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
219 //=================================================================================
220 // function : SelectionIntoArgument()
221 // purpose : Called when selection has changed
222 //=================================================================================
223 void SMESHGUI_MeshInfosDlg::onSelectionChanged()
225 if (myStartSelection)
229 //=================================================================================
230 // function : closeEvent()
232 //=================================================================================
233 void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
235 mySMESHGUI->ResetState();
236 QDialog::closeEvent(e);
239 //=================================================================================
240 // function : windowActivationChange()
241 // purpose : called when window is activated/deactivated
242 //=================================================================================
243 void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
245 QDialog::windowActivationChange(oldActive);
246 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
247 ActivateThisDialog();
248 myIsActiveWindow = isActiveWindow();
251 //=================================================================================
252 // function : DeactivateActiveDialog()
254 //=================================================================================
255 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
257 disconnect(mySelectionMgr, 0, this, 0);
260 //=================================================================================
261 // function : ActivateThisDialog()
263 //=================================================================================
264 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
266 /* Emit a signal to deactivate any active dialog */
267 mySMESHGUI->EmitSignalDeactivateDialog();
268 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
271 //=================================================================================
272 // function : onStartSelection()
273 // purpose : starts selection
274 //=================================================================================
275 void SMESHGUI_MeshInfosDlg::onStartSelection()
277 myStartSelection = true;
278 onSelectionChanged();
279 myStartSelection = true;
280 mySelectLab->setText(tr("INF_SELECT_OBJECT"));
283 //=================================================================================
284 // function : onHelp()
286 //=================================================================================
287 void SMESHGUI_MeshInfosDlg::onHelp()
289 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
291 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
295 platform = "winapplication";
297 platform = "application";
299 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
300 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
301 arg(app->resourceMgr()->stringValue("ExternalBrowser",
303 arg(myHelpFileName));
307 //=================================================================================
308 // function : keyPressEvent()
310 //=================================================================================
311 void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
313 QDialog::keyPressEvent( e );
314 if ( e->isAccepted() )
317 if ( e->key() == Qt::Key_F1 ) {