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); myOkBtn->setDefault(true);
145 myHelpBtn = new QPushButton(tr("SMESH_BUT_HELP" ), myButtonsGroup);
146 myHelpBtn->setAutoDefault(true);
148 myButtonsGroupLayout->addWidget(myOkBtn);
149 myButtonsGroupLayout->addSpacing(10);
150 myButtonsGroupLayout->addStretch();
151 myButtonsGroupLayout->addWidget(myHelpBtn);
153 aTopLayout->addLayout(aSelectLayout);
154 aTopLayout->addWidget(myWGStack);
155 aTopLayout->addWidget(myButtonsGroup);
157 mySMESHGUI->SetActiveDialogBox(this);
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()));
167 // init dialog with current selection
168 onSelectionChanged();
170 myHelpFileName = "mesh_infos_page.html#advanced_mesh_infos_anchor";
173 //=================================================================================
174 // function : ~SMESHGUI_MeshInfosDlg()
175 // purpose : Destructor
176 //=================================================================================
177 SMESHGUI_MeshInfosDlg::~SMESHGUI_MeshInfosDlg()
181 //=================================================================================
182 // function : DumpMeshInfos()
184 //=================================================================================
185 void SMESHGUI_MeshInfosDlg::DumpMeshInfos()
187 SUIT_OverrideCursor wc;
190 mySelectionMgr->selectedObjects(aList);
192 int nbSel = aList.Extent();
194 myStartSelection = false;
195 mySelectLab->setText("");
196 Handle(SALOME_InteractiveObject) IObject = aList.First();
197 _PTR(SObject) aSO = SMESH::GetActiveStudyDocument()->FindObjectID(IObject->getEntry());
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());
208 SMESH::long_array_var aMeshInfo = anIDSource->GetMeshInfo();
209 myMeshInfoBox->SetMeshInfo( aMeshInfo );
216 myWGStack->setCurrentIndex(0);
217 setWindowTitle(tr("SMESH_MESHINFO_TITLE"));
220 //=================================================================================
221 // function : SelectionIntoArgument()
222 // purpose : Called when selection has changed
223 //=================================================================================
224 void SMESHGUI_MeshInfosDlg::onSelectionChanged()
226 if (myStartSelection)
230 //=================================================================================
231 // function : closeEvent()
233 //=================================================================================
234 void SMESHGUI_MeshInfosDlg::closeEvent(QCloseEvent* e)
236 mySMESHGUI->ResetState();
237 QDialog::closeEvent(e);
240 //=================================================================================
241 // function : windowActivationChange()
242 // purpose : called when window is activated/deactivated
243 //=================================================================================
244 void SMESHGUI_MeshInfosDlg::windowActivationChange(bool oldActive)
246 QDialog::windowActivationChange(oldActive);
247 if (isActiveWindow() && myIsActiveWindow != isActiveWindow())
248 ActivateThisDialog();
249 myIsActiveWindow = isActiveWindow();
252 //=================================================================================
253 // function : DeactivateActiveDialog()
255 //=================================================================================
256 void SMESHGUI_MeshInfosDlg::DeactivateActiveDialog()
258 disconnect(mySelectionMgr, 0, this, 0);
261 //=================================================================================
262 // function : ActivateThisDialog()
264 //=================================================================================
265 void SMESHGUI_MeshInfosDlg::ActivateThisDialog()
267 /* Emit a signal to deactivate any active dialog */
268 mySMESHGUI->EmitSignalDeactivateDialog();
269 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
272 //=================================================================================
273 // function : onStartSelection()
274 // purpose : starts selection
275 //=================================================================================
276 void SMESHGUI_MeshInfosDlg::onStartSelection()
278 myStartSelection = true;
279 onSelectionChanged();
280 myStartSelection = true;
281 mySelectLab->setText(tr("INF_SELECT_OBJECT"));
284 //=================================================================================
285 // function : onHelp()
287 //=================================================================================
288 void SMESHGUI_MeshInfosDlg::onHelp()
290 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
292 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
296 platform = "winapplication";
298 platform = "application";
300 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
301 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
302 arg(app->resourceMgr()->stringValue("ExternalBrowser",
304 arg(myHelpFileName));
308 //=================================================================================
309 // function : keyPressEvent()
311 //=================================================================================
312 void SMESHGUI_MeshInfosDlg::keyPressEvent( QKeyEvent* e )
314 QDialog::keyPressEvent( e );
315 if ( e->isAccepted() )
318 if ( e->key() == Qt::Key_F1 ) {