1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // SMESH SMESHGUI : GUI for SMESH component
21 // File : SMESHGUI_WhatIsDlg.cxx
22 // Author : Vladimir TURIN, Open CASCADE S.A.S.
25 #include "SMESHGUI_WhatIsDlg.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_IdValidator.h"
33 #include "SMESH_Actor.h"
34 #include "SMESH_TypeFilter.hxx"
35 #include "SMESH_LogicalFilter.hxx"
36 #include "SMDS_Mesh.hxx"
37 #include "SMDS_VolumeTool.hxx"
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_Selection.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
52 #include <SALOME_ListIteratorOfListIO.hxx>
55 #include <TColStd_MapOfInteger.hxx>
59 #include <QButtonGroup>
63 #include <QPushButton>
64 #include <QRadioButton>
65 #include <QTextBrowser>
66 #include <QHBoxLayout>
67 #include <QVBoxLayout>
68 #include <QGridLayout>
72 #include <SALOMEconfig.h>
73 #include CORBA_SERVER_HEADER(SMESH_Group)
78 //=================================================================================
79 // class : SMESHGUI_WhatIsDlg()
81 //=================================================================================
82 SMESHGUI_WhatIsDlg::SMESHGUI_WhatIsDlg( SMESHGUI* theModule )
83 : QDialog( SMESH::GetDesktop( theModule ) ),
84 mySMESHGUI( theModule ),
85 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
88 setAttribute( Qt::WA_DeleteOnClose, true );
89 setWindowTitle(tr("SMESH_WHAT_IS_TITLE"));
90 setSizeGripEnabled(true);
91 QVBoxLayout* SMESHGUI_WhatIsDlgLayout = new QVBoxLayout(this);
92 SMESHGUI_WhatIsDlgLayout->setSpacing(SPACING);
93 SMESHGUI_WhatIsDlgLayout->setMargin(MARGIN);
95 /***************************************************************/
96 GroupMesh = new QGroupBox(this);
97 QHBoxLayout* GroupMeshLayout = new QHBoxLayout(GroupMesh);
98 GroupMeshLayout->setSpacing(SPACING);
99 GroupMeshLayout->setMargin(MARGIN);
101 MeshLabel = new QLabel(tr("SMESH_NAME"), GroupMesh);
102 GroupMeshLayout->addWidget(MeshLabel);
103 MeshName = new QLineEdit(GroupMesh);
104 MeshName->setReadOnly(true);
105 GroupMeshLayout->addWidget(MeshName);
107 /***************************************************************/
108 GroupSelections = new QGroupBox(tr("ENTITY_TYPE"), this);
109 QButtonGroup* GroupSel = new QButtonGroup(this);
110 QHBoxLayout* GroupSelectionsLayout = new QHBoxLayout(GroupSelections);
111 GroupSelectionsLayout->setSpacing(SPACING);
112 GroupSelectionsLayout->setMargin(MARGIN);
114 RadioButtonNodes = new QRadioButton(tr("SMESH_NODES"), GroupSelections);
115 GroupSelectionsLayout->addWidget(RadioButtonNodes);
116 GroupSel->addButton(RadioButtonNodes, 0);
117 RadioButtonElements = new QRadioButton(tr("SMESH_ELEMENTS"), GroupSelections);
118 GroupSelectionsLayout->addWidget(RadioButtonElements);
119 GroupSel->addButton(RadioButtonElements, 1);
121 /***************************************************************/
122 GroupArguments = new QGroupBox(tr("SMESH_INFORMATION"), this);
123 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
124 GroupArgumentsLayout->setSpacing(SPACING);
125 GroupArgumentsLayout->setMargin(MARGIN);
127 // Controls for elements selection
128 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
129 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
131 LineEditElements = new QLineEdit(GroupArguments);
132 LineEditElements->setValidator(new SMESHGUI_IdValidator(this));
133 LineEditElements->setMaxLength(-1);
134 GroupArgumentsLayout->addWidget(LineEditElements, 0, 1);
136 // information text browser
137 Info = new QTextBrowser(GroupArguments);
138 Info->setMinimumSize(300, 200);
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 = "mesh_infos_page.html#mesh_element_info_anchor";
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())
385 //check if all selected objects belongs to one mesh
386 SALOME_ListIteratorOfListIO io( aList );
387 for (io.Next(); io.More(); io.Next() ) {
388 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io.Value());
389 if (!mesh->_is_nil() && !mesh->_is_equivalent( myMesh ))
392 // select IO with any element selected (for case of selection by rectangle)
394 for (io.Initialize(aList); io.More() && IO.IsNull(); io.Next() )
395 if ( mySelector->HasIndex( io.Value() ))
397 if ( IO.IsNull() ) return;
399 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
400 for (io.Initialize(aList); io.More(); io.Next() )
401 if ( !IO->isSame( io.Value() ))
402 aViewWindow->highlight( io.Value(), false, true );
406 myActor = SMESH::FindActorByObject(myMesh);
408 myActor = SMESH::FindActorByEntry(IO->getEntry());
412 QString aName = IO->getName();
413 // cut off wite spaces from tail, else meaningful head is not visible
414 int size = aName.length();
415 while (size && aName.at(size-1).isSpace() )
417 if ( size != aName.length() )
418 aName.truncate( size );
419 MeshName->setText(aName); // can be something like "2 objects"
421 if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) {
422 GroupMesh->setTitle(tr("SMESH_MESH"));
423 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) {
424 GroupMesh->setTitle(tr("SMESH_SUBMESH"));
425 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) {
426 GroupMesh->setTitle(tr("SMESH_GROUP"));
431 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
436 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
437 myActor->GetObject()->GetMesh()->FindNode(aString.toInt()):
438 myActor->GetObject()->GetMesh()->FindElement(aString.toInt());
441 anInfo="<b>" + tr("ENTITY_TYPE") + ":</b> ";
442 if(e->GetType() == SMDSAbs_Node) {
443 anInfo+=tr("MESH_NODE")+"<br>";
444 //const SMDS_MeshNode *en = (SMDS_MeshNode*) e; // VSR: not used!
445 } else if (e->GetType() == SMDSAbs_0DElement) {
446 anInfo+=tr("SMESH_ELEM0D")+"<br>";
447 } else if(e->GetType() == SMDSAbs_Edge) {
448 anInfo+=tr("SMESH_EDGE")+"<br>";
449 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
450 const SMDS_MeshEdge *ee = (SMDS_MeshEdge*) e;
451 anInfo+=(ee->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+"<br>";
452 } else if(e->GetType() == SMDSAbs_Face) {
453 const SMDS_MeshFace *ef = (SMDS_MeshFace*) e;
454 anInfo+=tr("SMESH_FACE")+"<br>";
455 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
457 anInfo+=(ef->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
458 switch(ef->NbNodes()) {
462 anInfo+=tr("SMESH_TRIANGLE");
468 anInfo+=tr("SMESH_QUADRANGLE");
475 } else if(e->GetType() == SMDSAbs_Volume) {
476 anInfo+=tr("SMESH_VOLUME")+"<br>";
477 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
478 const SMDS_MeshVolume *ev = (SMDS_MeshVolume*) e;
479 SMDS_VolumeTool vt(ev);
480 if(vt.GetVolumeType() != SMDS_VolumeTool::POLYHEDA)
481 anInfo+=(ev->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
482 switch(vt.GetVolumeType()) {
483 case SMDS_VolumeTool::TETRA:
484 case SMDS_VolumeTool::QUAD_TETRA:
486 anInfo+=tr("SMESH_TETRAS");
489 case SMDS_VolumeTool::PYRAM:
490 case SMDS_VolumeTool::QUAD_PYRAM:
492 anInfo+=tr("SMESH_PYRAMID");
495 case SMDS_VolumeTool::PENTA:
496 case SMDS_VolumeTool::QUAD_PENTA:
498 anInfo+=tr("SMESH_PRISM");
501 case SMDS_VolumeTool::HEXA:
502 case SMDS_VolumeTool::QUAD_HEXA:
504 anInfo+=tr("SMESH_HEXAS");
507 case SMDS_VolumeTool::POLYHEDA:
509 anInfo+=tr("SMESH_POLYEDRON");
517 gp_XYZ anXYZ(0.,0.,0.);
518 SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
520 QString aNodesInfo="";
521 for( ; nodeIt->more(); nbNodes++) {
522 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
523 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
524 if(e->GetType() != SMDSAbs_Node)
525 aNodesInfo+=QString("<b>Node %1:</b><br>Id=%2, X=%3, Y=%4, Z=%5<br>").arg(nbNodes+1).arg(node->GetID()).arg(node->X()).arg(node->Y()).arg(node->Z());
526 // Calculate Connectivity
527 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
529 aNodesInfo+="<b>" + tr("CONNECTED_ELEMENTS") + ":</b>";
531 const SMDS_MeshElement* elem = it->next();
532 aNodesInfo+=QString(" %1").arg(elem->GetID());
534 if ( (nbNodes+1) != e->NbNodes())
535 aNodesInfo+=QString("<br><br>");
538 if(e->GetType() != SMDSAbs_Node)
539 anInfo+="<b>" + tr("GRAVITY_CENTER") + ":</b><br>";
540 anXYZ.Divide(e->NbNodes());
541 anInfo+=QString("X=%1, Y=%2, Z=%3").arg(anXYZ.X()).arg(anXYZ.Y()).arg(anXYZ.Z());
542 if(e->GetType() != SMDSAbs_Node)
545 anInfo+= "<br>" + aNodesInfo;
546 Info->setText(anInfo);
551 LineEditElements->setText(aString);
556 //=================================================================================
557 // function : DeactivateActiveDialog()
559 //=================================================================================
560 void SMESHGUI_WhatIsDlg::DeactivateActiveDialog()
562 if (GroupArguments->isEnabled()) {
563 GroupSelections->setEnabled(false);
564 GroupMesh->setEnabled(false);
565 GroupArguments->setEnabled(false);
566 GroupButtons->setEnabled(false);
567 mySMESHGUI->ResetState();
568 mySMESHGUI->SetActiveDialogBox(0);
572 //=================================================================================
573 // function : ActivateThisDialog()
575 //=================================================================================
576 void SMESHGUI_WhatIsDlg::ActivateThisDialog()
578 /* Emit a signal to deactivate the active dialog */
579 mySMESHGUI->EmitSignalDeactivateDialog();
580 GroupArguments->setEnabled(true);
581 GroupButtons->setEnabled(true);
582 GroupSelections->setEnabled(true);
583 GroupMesh->setEnabled(true);
585 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
587 if ( SMESH::GetViewWindow( mySMESHGUI ))
588 SelectionsClicked(RadioButtonNodes->isChecked()?0:1);
590 SelectionIntoArgument();
593 //=================================================================================
594 // function : enterEvent()
596 //=================================================================================
597 void SMESHGUI_WhatIsDlg::enterEvent (QEvent*)
599 if (!GroupArguments->isEnabled())
600 ActivateThisDialog();
603 //=================================================================================
604 // function : closeEvent()
606 //=================================================================================
607 void SMESHGUI_WhatIsDlg::closeEvent (QCloseEvent*)
609 /* same than click on cancel button */
613 //=======================================================================
614 //function : hideEvent
615 //purpose : caused by ESC key
616 //=======================================================================
617 void SMESHGUI_WhatIsDlg::hideEvent (QHideEvent*)
623 //=================================================================================
624 // function : keyPressEvent()
626 //=================================================================================
627 void SMESHGUI_WhatIsDlg::keyPressEvent( QKeyEvent* e )
629 QDialog::keyPressEvent( e );
630 if ( e->isAccepted() )
633 if ( e->key() == Qt::Key_F1 ) {