1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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 // File : SMESHGUI_WhatIsDlg.cxx
23 // Author : Vladimir TURIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_WhatIsDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
35 #include "SMESH_Actor.h"
36 #include "SMESH_TypeFilter.hxx"
37 #include "SMESH_LogicalFilter.hxx"
38 #include "SMDS_Mesh.hxx"
39 #include "SMDS_VolumeTool.hxx"
41 // SALOME GUI includes
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ResourceMgr.h>
44 #include <SUIT_Session.h>
45 #include <SUIT_MessageBox.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_Selection.h>
52 #include <SVTK_ViewWindow.h>
53 #include <SALOME_ListIO.hxx>
56 #include <TColStd_MapOfInteger.hxx>
60 #include <QButtonGroup>
64 #include <QPushButton>
65 #include <QRadioButton>
66 #include <QTextBrowser>
67 #include <QHBoxLayout>
68 #include <QVBoxLayout>
69 #include <QGridLayout>
73 #include <SALOMEconfig.h>
74 #include CORBA_SERVER_HEADER(SMESH_Group)
79 //=================================================================================
80 // class : SMESHGUI_WhatIsDlg()
82 //=================================================================================
83 SMESHGUI_WhatIsDlg::SMESHGUI_WhatIsDlg( SMESHGUI* theModule )
84 : QDialog( SMESH::GetDesktop( theModule ) ),
85 mySMESHGUI( theModule ),
86 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
89 setAttribute( Qt::WA_DeleteOnClose, true );
90 setWindowTitle(tr("SMESH_WHAT_IS_TITLE"));
91 setSizeGripEnabled(true);
92 QVBoxLayout* SMESHGUI_WhatIsDlgLayout = new QVBoxLayout(this);
93 SMESHGUI_WhatIsDlgLayout->setSpacing(SPACING);
94 SMESHGUI_WhatIsDlgLayout->setMargin(MARGIN);
96 /***************************************************************/
97 GroupMesh = new QGroupBox(this);
98 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
99 GroupMeshLayout->setSpacing(SPACING);
100 GroupMeshLayout->setMargin(MARGIN);
102 MeshLabel = new QLabel(tr("SMESH_NAME"), GroupMesh);
103 GroupMeshLayout->addWidget(MeshLabel);
104 MeshName = new QLineEdit(GroupMesh);
105 MeshName->setReadOnly(true);
106 GroupMeshLayout->addWidget(MeshName);
108 /***************************************************************/
109 GroupSelections = new QGroupBox(tr("ENTITY_TYPE"), this);
110 QButtonGroup* GroupSel = new QButtonGroup(this);
111 QHBoxLayout* GroupSelectionsLayout = new QHBoxLayout(GroupSelections);
112 GroupSelectionsLayout->setSpacing(SPACING);
113 GroupSelectionsLayout->setMargin(MARGIN);
115 RadioButtonNodes = new QRadioButton(tr("SMESH_NODES"), GroupSelections);
116 GroupSelectionsLayout->addWidget(RadioButtonNodes);
117 GroupSel->addButton(RadioButtonNodes, 0);
118 RadioButtonElements = new QRadioButton(tr("SMESH_ELEMENTS"), GroupSelections);
119 GroupSelectionsLayout->addWidget(RadioButtonElements);
120 GroupSel->addButton(RadioButtonElements, 1);
122 /***************************************************************/
123 GroupArguments = new QGroupBox(tr("SMESH_INFORMATION"), this);
124 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
125 GroupArgumentsLayout->setSpacing(SPACING);
126 GroupArgumentsLayout->setMargin(MARGIN);
128 // Controls for elements selection
129 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
130 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
132 LineEditElements = new QLineEdit(GroupArguments);
133 LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
134 GroupArgumentsLayout->addWidget(LineEditElements, 0, 1);
136 // information text browser
137 Info = new QTextBrowser(GroupArguments);
138 Info->setMinimumSize(200, 150);
139 GroupArgumentsLayout->addWidget(Info, 1, 0, 1, 2);
141 /***************************************************************/
142 GroupButtons = new QGroupBox(this);
143 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
144 GroupButtonsLayout->setSpacing(SPACING);
145 GroupButtonsLayout->setMargin(MARGIN);
147 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
148 buttonOk->setAutoDefault(true);
149 buttonOk->setDefault(true);
150 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
151 buttonHelp->setAutoDefault(true);
153 GroupButtonsLayout->addWidget(buttonOk);
154 GroupButtonsLayout->addSpacing(10);
155 GroupButtonsLayout->addStretch();
156 GroupButtonsLayout->addWidget(buttonHelp);
158 SMESHGUI_WhatIsDlgLayout->addWidget(GroupMesh);
159 SMESHGUI_WhatIsDlgLayout->addWidget(GroupSelections);
160 SMESHGUI_WhatIsDlgLayout->addWidget(GroupArguments);
161 SMESHGUI_WhatIsDlgLayout->addWidget(GroupButtons);
163 RadioButtonNodes->setChecked(true);
165 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
167 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
169 // Costruction of the logical filter
170 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
171 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
173 QList<SUIT_SelectionFilter*> aListOfFilters;
174 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
175 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
177 myMeshOrSubMeshOrGroupFilter =
178 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
180 myHelpFileName = "/files/viewing_mesh_info.htm#element_infos";
184 /* signals and slots connections */
185 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
186 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
187 connect(GroupSel, SIGNAL(buttonClicked(int)), SLOT(SelectionsClicked(int)));
189 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
190 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 /* to close dialog if study change */
192 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
193 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
195 SelectionsClicked(0);
196 SelectionIntoArgument();
199 //=================================================================================
200 // function : ~SMESHGUI_WhatIsDlg()
201 // purpose : Destroys the object and frees any allocated resources
202 //=================================================================================
203 SMESHGUI_WhatIsDlg::~SMESHGUI_WhatIsDlg()
207 //=================================================================================
210 //=================================================================================
211 void SMESHGUI_WhatIsDlg::Init (bool ResetControls)
215 LineEditElements->clear();
218 myMesh = SMESH::SMESH_Mesh::_nil();
221 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
222 aViewWindow->SetSelectionMode( CellSelection );
223 onTextChange(LineEditElements->text());
225 SelectionIntoArgument();
229 //=================================================================================
230 // function : SelectionsClicked()
231 // purpose : Radio button management
232 //=================================================================================
233 void SMESHGUI_WhatIsDlg::SelectionsClicked (int selectionId)
235 disconnect(mySelectionMgr, 0, this, 0);
237 mySelectionMgr->clearFilters();
239 switch (selectionId) {
242 SMESH::SetPointRepresentation(true);
243 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
244 aViewWindow->SetSelectionMode( NodeSelection );
249 SMESH::SetPointRepresentation(false);
250 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
251 aViewWindow->SetSelectionMode( CellSelection );
256 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 SelectionIntoArgument();
260 //=================================================================================
261 // function : ClickOnOk()
263 //=================================================================================
264 void SMESHGUI_WhatIsDlg::ClickOnOk()
266 if (mySMESHGUI->isActiveStudyLocked())
271 SelectionIntoArgument();
275 //=================================================================================
276 // function : ClickOnCancel()
278 //=================================================================================
279 void SMESHGUI_WhatIsDlg::ClickOnCancel()
281 disconnect(mySelectionMgr, 0, this, 0);
282 mySelectionMgr->clearFilters();
283 SMESH::SetPointRepresentation(false);
284 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
285 aViewWindow->SetSelectionMode( ActorSelection );
286 mySMESHGUI->ResetState();
290 //=================================================================================
291 // function : ClickOnHelp()
293 //=================================================================================
294 void SMESHGUI_WhatIsDlg::ClickOnHelp()
296 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
298 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
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 : onTextChange()
311 //=======================================================================
312 void SMESHGUI_WhatIsDlg::onTextChange (const QString& theNewText)
317 // hilight entered elements
318 SMDS_Mesh* aMesh = 0;
320 aMesh = myActor->GetObject()->GetMesh();
323 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
325 TColStd_MapOfInteger newIndices;
327 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
329 for (int i = 0; i < aListId.count(); i++) {
330 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
331 aMesh->FindNode(aListId[ i ].toInt()):
332 aMesh->FindElement(aListId[ i ].toInt());
334 newIndices.Add(e->GetID());
337 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
338 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
339 aViewWindow->highlight( anIO, true, true );
342 SelectionIntoArgument();
347 //=================================================================================
348 // function : SelectionIntoArgument()
349 // purpose : Called when selection as changed or other case
350 //=================================================================================
351 void SMESHGUI_WhatIsDlg::SelectionIntoArgument()
353 int curBusy = myBusy;
357 QString aString = "";
361 LineEditElements->setText(aString);
362 MeshName->setText(aString);
363 GroupMesh->setTitle(tr(""));
367 if (!GroupButtons->isEnabled()) // inactive
372 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
374 int nbSel = aList.Extent();
379 Handle(SALOME_InteractiveObject) IO = aList.First();
380 myMesh = SMESH::GetMeshByIO(IO);
381 if (myMesh->_is_nil())
384 myActor = SMESH::FindActorByObject(myMesh);
386 myActor = SMESH::FindActorByEntry(IO->getEntry());
391 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
392 MeshName->setText(aName);
393 if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) {
394 GroupMesh->setTitle(tr("SMESH_MESH"));
395 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) {
396 GroupMesh->setTitle(tr("SMESH_SUBMESH"));
397 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) {
398 GroupMesh->setTitle(tr("SMESH_GROUP"));
403 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
408 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
409 myActor->GetObject()->GetMesh()->FindNode(aString.toInt()):
410 myActor->GetObject()->GetMesh()->FindElement(aString.toInt());
413 anInfo=tr("ENTITY_TYPE") + ": ";
414 if(e->GetType() == SMDSAbs_Node) {
415 anInfo+=tr("MESH_NODE")+"\n";
416 //const SMDS_MeshNode *en = (SMDS_MeshNode*) e; // VSR: not used!
417 } else if(e->GetType() == SMDSAbs_Edge) {
418 anInfo+=tr("SMESH_EDGE")+"\n";
419 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
420 const SMDS_MeshEdge *ee = (SMDS_MeshEdge*) e;
421 anInfo+=(ee->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+"\n";
422 } else if(e->GetType() == SMDSAbs_Face) {
423 const SMDS_MeshFace *ef = (SMDS_MeshFace*) e;
424 anInfo+=tr("SMESH_FACE")+"\n";
425 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
427 anInfo+=(ef->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
428 switch(ef->NbNodes()) {
432 anInfo+=tr("SMESH_TRIANGLE");
438 anInfo+=tr("SMESH_QUADRANGLE");
445 } else if(e->GetType() == SMDSAbs_Volume) {
446 anInfo+=tr("SMESH_VOLUME")+"\n";
447 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
448 const SMDS_MeshVolume *ev = (SMDS_MeshVolume*) e;
449 SMDS_VolumeTool vt(ev);
450 if(vt.GetVolumeType() != SMDS_VolumeTool::POLYHEDA)
451 anInfo+=(ev->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
452 switch(vt.GetVolumeType()) {
453 case SMDS_VolumeTool::TETRA:
454 case SMDS_VolumeTool::QUAD_TETRA:
456 anInfo+=tr("SMESH_TETRAS");
459 case SMDS_VolumeTool::PYRAM:
460 case SMDS_VolumeTool::QUAD_PYRAM:
462 anInfo+=tr("SMESH_PYRAMID");
465 case SMDS_VolumeTool::PENTA:
466 case SMDS_VolumeTool::QUAD_PENTA:
468 anInfo+=tr("SMESH_PRISM");
471 case SMDS_VolumeTool::HEXA:
472 case SMDS_VolumeTool::QUAD_HEXA:
474 anInfo+=tr("SMESH_HEXAS");
477 case SMDS_VolumeTool::POLYHEDA:
479 anInfo+=tr("SMESH_POLYEDRON");
487 if(e->GetType() != SMDSAbs_Node)
488 anInfo+=tr("GRAVITY_CENTER") + ":\n";
489 gp_XYZ anXYZ(0.,0.,0.);
490 SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
492 for( ; nodeIt->more(); nbNodes++) {
493 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
494 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
496 anXYZ.Divide(e->NbNodes());
497 anInfo+=QString("X=%1\nY=%2\nZ=%3\n").arg(anXYZ.X()).arg(anXYZ.Y()).arg(anXYZ.Z());
498 Info->setText(anInfo);
503 LineEditElements->setText(aString);
508 //=================================================================================
509 // function : DeactivateActiveDialog()
511 //=================================================================================
512 void SMESHGUI_WhatIsDlg::DeactivateActiveDialog()
514 if (GroupArguments->isEnabled()) {
515 GroupSelections->setEnabled(false);
516 GroupMesh->setEnabled(false);
517 GroupArguments->setEnabled(false);
518 GroupButtons->setEnabled(false);
519 mySMESHGUI->ResetState();
520 mySMESHGUI->SetActiveDialogBox(0);
524 //=================================================================================
525 // function : ActivateThisDialog()
527 //=================================================================================
528 void SMESHGUI_WhatIsDlg::ActivateThisDialog()
530 /* Emit a signal to deactivate the active dialog */
531 mySMESHGUI->EmitSignalDeactivateDialog();
532 GroupArguments->setEnabled(true);
533 GroupButtons->setEnabled(true);
534 GroupSelections->setEnabled(true);
535 GroupMesh->setEnabled(true);
537 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
539 if ( SMESH::GetViewWindow( mySMESHGUI ))
540 SelectionsClicked(RadioButtonNodes->isChecked()?0:1);
542 SelectionIntoArgument();
545 //=================================================================================
546 // function : enterEvent()
548 //=================================================================================
549 void SMESHGUI_WhatIsDlg::enterEvent (QEvent*)
551 if (!GroupArguments->isEnabled())
552 ActivateThisDialog();
555 //=================================================================================
556 // function : closeEvent()
558 //=================================================================================
559 void SMESHGUI_WhatIsDlg::closeEvent (QCloseEvent*)
561 /* same than click on cancel button */
565 //=======================================================================
566 //function : hideEvent
567 //purpose : caused by ESC key
568 //=======================================================================
569 void SMESHGUI_WhatIsDlg::hideEvent (QHideEvent*)
575 //=================================================================================
576 // function : keyPressEvent()
578 //=================================================================================
579 void SMESHGUI_WhatIsDlg::keyPressEvent( QKeyEvent* e )
581 QDialog::keyPressEvent( e );
582 if ( e->isAccepted() )
585 if ( e->key() == Qt::Key_F1 ) {