1 // Copyright (C) 2007-2010 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 GroupArgumentsLayout->addWidget(LineEditElements, 0, 1);
135 // information text browser
136 Info = new QTextBrowser(GroupArguments);
137 Info->setMinimumSize(300, 200);
138 GroupArgumentsLayout->addWidget(Info, 1, 0, 1, 2);
140 /***************************************************************/
141 GroupButtons = new QGroupBox(this);
142 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
143 GroupButtonsLayout->setSpacing(SPACING);
144 GroupButtonsLayout->setMargin(MARGIN);
146 buttonOk = new QPushButton(tr("SMESH_BUT_OK"), GroupButtons);
147 buttonOk->setAutoDefault(true);
148 buttonOk->setDefault(true);
149 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
150 buttonHelp->setAutoDefault(true);
152 GroupButtonsLayout->addWidget(buttonOk);
153 GroupButtonsLayout->addSpacing(10);
154 GroupButtonsLayout->addStretch();
155 GroupButtonsLayout->addWidget(buttonHelp);
157 SMESHGUI_WhatIsDlgLayout->addWidget(GroupMesh);
158 SMESHGUI_WhatIsDlgLayout->addWidget(GroupSelections);
159 SMESHGUI_WhatIsDlgLayout->addWidget(GroupArguments);
160 SMESHGUI_WhatIsDlgLayout->addWidget(GroupButtons);
162 RadioButtonNodes->setChecked(true);
164 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
166 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
168 // Costruction of the logical filter
169 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
170 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
172 QList<SUIT_SelectionFilter*> aListOfFilters;
173 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
174 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
176 myMeshOrSubMeshOrGroupFilter =
177 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
179 myHelpFileName = "mesh_infos_page.html#mesh_element_info_anchor";
183 /* signals and slots connections */
184 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
185 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
186 connect(GroupSel, SIGNAL(buttonClicked(int)), SLOT(SelectionsClicked(int)));
188 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
189 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 /* to close dialog if study change */
191 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
192 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
194 SelectionsClicked(0);
195 SelectionIntoArgument();
198 //=================================================================================
199 // function : ~SMESHGUI_WhatIsDlg()
200 // purpose : Destroys the object and frees any allocated resources
201 //=================================================================================
202 SMESHGUI_WhatIsDlg::~SMESHGUI_WhatIsDlg()
206 //=================================================================================
209 //=================================================================================
210 void SMESHGUI_WhatIsDlg::Init (bool ResetControls)
214 LineEditElements->clear();
217 myMesh = SMESH::SMESH_Mesh::_nil();
220 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
221 aViewWindow->SetSelectionMode( CellSelection );
222 onTextChange(LineEditElements->text());
224 SelectionIntoArgument();
228 //=================================================================================
229 // function : SelectionsClicked()
230 // purpose : Radio button management
231 //=================================================================================
232 void SMESHGUI_WhatIsDlg::SelectionsClicked (int selectionId)
234 disconnect(mySelectionMgr, 0, this, 0);
236 mySelectionMgr->clearFilters();
238 switch (selectionId) {
241 SMESH::SetPointRepresentation(true);
242 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
243 aViewWindow->SetSelectionMode( NodeSelection );
248 SMESH::SetPointRepresentation(false);
249 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
250 aViewWindow->SetSelectionMode( CellSelection );
255 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
256 SelectionIntoArgument();
259 //=================================================================================
260 // function : ClickOnOk()
262 //=================================================================================
263 void SMESHGUI_WhatIsDlg::ClickOnOk()
265 if (mySMESHGUI->isActiveStudyLocked())
270 SelectionIntoArgument();
274 //=================================================================================
275 // function : ClickOnCancel()
277 //=================================================================================
278 void SMESHGUI_WhatIsDlg::ClickOnCancel()
280 disconnect(mySelectionMgr, 0, this, 0);
281 mySelectionMgr->clearFilters();
282 SMESH::SetPointRepresentation(false);
283 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
284 aViewWindow->SetSelectionMode( ActorSelection );
285 mySMESHGUI->ResetState();
289 //=================================================================================
290 // function : ClickOnHelp()
292 //=================================================================================
293 void SMESHGUI_WhatIsDlg::ClickOnHelp()
295 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
297 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
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 : onTextChange()
310 //=======================================================================
311 void SMESHGUI_WhatIsDlg::onTextChange (const QString& theNewText)
316 // hilight entered elements
317 SMDS_Mesh* aMesh = 0;
319 aMesh = myActor->GetObject()->GetMesh();
322 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
324 TColStd_MapOfInteger newIndices;
326 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
328 for (int i = 0; i < aListId.count(); i++) {
329 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
330 aMesh->FindNode(aListId[ i ].toInt()):
331 aMesh->FindElement(aListId[ i ].toInt());
333 newIndices.Add(e->GetID());
336 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
337 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
338 aViewWindow->highlight( anIO, true, true );
341 SelectionIntoArgument();
346 //=================================================================================
347 // function : SelectionIntoArgument()
348 // purpose : Called when selection as changed or other case
349 //=================================================================================
350 void SMESHGUI_WhatIsDlg::SelectionIntoArgument()
352 int curBusy = myBusy;
356 QString aString = "";
360 LineEditElements->setText(aString);
361 MeshName->setText(aString);
362 GroupMesh->setTitle(tr(""));
366 if (!GroupButtons->isEnabled()) // inactive
371 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
373 int nbSel = aList.Extent();
378 Handle(SALOME_InteractiveObject) IO = aList.First();
379 myMesh = SMESH::GetMeshByIO(IO);
380 if (myMesh->_is_nil())
384 //check if all selected objects belongs to one mesh
385 SALOME_ListIteratorOfListIO io( aList );
386 for (io.Next(); io.More(); io.Next() ) {
387 SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(io.Value());
388 if (!mesh->_is_nil() && !mesh->_is_equivalent( myMesh ))
391 // select IO with any element selected (for case of selection by rectangle)
393 for (io.Initialize(aList); io.More() && IO.IsNull(); io.Next() )
394 if ( mySelector->HasIndex( io.Value() ))
396 if ( IO.IsNull() ) return;
398 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
399 for (io.Initialize(aList); io.More(); io.Next() )
400 if ( !IO->isSame( io.Value() ))
401 aViewWindow->highlight( io.Value(), false, true );
405 myActor = SMESH::FindActorByObject(myMesh);
407 myActor = SMESH::FindActorByEntry(IO->getEntry());
411 QString aName = IO->getName();
412 // cut off wite spaces from tail, else meaningful head is not visible
413 int size = aName.length();
414 while (size && aName.at(size-1).isSpace() )
416 if ( size != aName.length() )
417 aName.truncate( size );
418 MeshName->setText(aName); // can be something like "2 objects"
420 if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) {
421 GroupMesh->setTitle(tr("SMESH_MESH"));
422 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) {
423 GroupMesh->setTitle(tr("SMESH_SUBMESH"));
424 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) {
425 GroupMesh->setTitle(tr("SMESH_GROUP"));
430 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
435 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
436 myActor->GetObject()->GetMesh()->FindNode(aString.toInt()):
437 myActor->GetObject()->GetMesh()->FindElement(aString.toInt());
440 anInfo="<b>" + tr("ENTITY_TYPE") + ":</b> ";
441 if(e->GetType() == SMDSAbs_Node) {
442 anInfo+=tr("MESH_NODE")+"<br>";
443 //const SMDS_MeshNode *en = (SMDS_MeshNode*) e; // VSR: not used!
444 } else if (e->GetType() == SMDSAbs_0DElement) {
445 anInfo+=tr("SMESH_ELEM0D")+"<br>";
446 } else if(e->GetType() == SMDSAbs_Edge) {
447 anInfo+=tr("SMESH_EDGE")+"<br>";
448 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
449 const SMDS_MeshEdge *ee = (SMDS_MeshEdge*) e;
450 anInfo+=(ee->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+"<br>";
451 } else if(e->GetType() == SMDSAbs_Face) {
452 const SMDS_MeshFace *ef = (SMDS_MeshFace*) e;
453 anInfo+=tr("SMESH_FACE")+"<br>";
454 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
456 anInfo+=(ef->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
457 switch(ef->NbNodes()) {
461 anInfo+=tr("SMESH_TRIANGLE");
467 anInfo+=tr("SMESH_QUADRANGLE");
474 } else if(e->GetType() == SMDSAbs_Volume) {
475 anInfo+=tr("SMESH_VOLUME")+"<br>";
476 anInfo+="<b>" + tr("SMESH_MESHINFO_TYPE")+":</b> ";
477 const SMDS_MeshVolume *ev = (SMDS_MeshVolume*) e;
478 SMDS_VolumeTool vt(ev);
479 if(vt.GetVolumeType() != SMDS_VolumeTool::POLYHEDA)
480 anInfo+=(ev->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
481 switch(vt.GetVolumeType()) {
482 case SMDS_VolumeTool::TETRA:
483 case SMDS_VolumeTool::QUAD_TETRA:
485 anInfo+=tr("SMESH_TETRAS");
488 case SMDS_VolumeTool::PYRAM:
489 case SMDS_VolumeTool::QUAD_PYRAM:
491 anInfo+=tr("SMESH_PYRAMID");
494 case SMDS_VolumeTool::PENTA:
495 case SMDS_VolumeTool::QUAD_PENTA:
497 anInfo+=tr("SMESH_PRISM");
500 case SMDS_VolumeTool::HEXA:
501 case SMDS_VolumeTool::QUAD_HEXA:
503 anInfo+=tr("SMESH_HEXAS");
506 case SMDS_VolumeTool::POLYHEDA:
508 anInfo+=tr("SMESH_POLYEDRON");
516 gp_XYZ anXYZ(0.,0.,0.);
517 SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
519 QString aNodesInfo="";
520 for( ; nodeIt->more(); nbNodes++) {
521 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
522 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
523 if(e->GetType() != SMDSAbs_Node)
524 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());
525 // Calculate Connectivity
526 SMDS_ElemIteratorPtr it = node->GetInverseElementIterator();
528 aNodesInfo+="<b>" + tr("CONNECTED_ELEMENTS") + ":</b>";
530 const SMDS_MeshElement* elem = it->next();
531 aNodesInfo+=QString(" %1").arg(elem->GetID());
533 if ( (nbNodes+1) != e->NbNodes())
534 aNodesInfo+=QString("<br><br>");
537 if(e->GetType() != SMDSAbs_Node)
538 anInfo+="<b>" + tr("GRAVITY_CENTER") + ":</b><br>";
539 anXYZ.Divide(e->NbNodes());
540 anInfo+=QString("X=%1, Y=%2, Z=%3").arg(anXYZ.X()).arg(anXYZ.Y()).arg(anXYZ.Z());
541 if(e->GetType() != SMDSAbs_Node)
544 anInfo+= "<br>" + aNodesInfo;
545 Info->setText(anInfo);
550 LineEditElements->setText(aString);
555 //=================================================================================
556 // function : DeactivateActiveDialog()
558 //=================================================================================
559 void SMESHGUI_WhatIsDlg::DeactivateActiveDialog()
561 if (GroupArguments->isEnabled()) {
562 GroupSelections->setEnabled(false);
563 GroupMesh->setEnabled(false);
564 GroupArguments->setEnabled(false);
565 GroupButtons->setEnabled(false);
566 mySMESHGUI->ResetState();
567 mySMESHGUI->SetActiveDialogBox(0);
571 //=================================================================================
572 // function : ActivateThisDialog()
574 //=================================================================================
575 void SMESHGUI_WhatIsDlg::ActivateThisDialog()
577 /* Emit a signal to deactivate the active dialog */
578 mySMESHGUI->EmitSignalDeactivateDialog();
579 GroupArguments->setEnabled(true);
580 GroupButtons->setEnabled(true);
581 GroupSelections->setEnabled(true);
582 GroupMesh->setEnabled(true);
584 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
586 if ( SMESH::GetViewWindow( mySMESHGUI ))
587 SelectionsClicked(RadioButtonNodes->isChecked()?0:1);
589 SelectionIntoArgument();
592 //=================================================================================
593 // function : enterEvent()
595 //=================================================================================
596 void SMESHGUI_WhatIsDlg::enterEvent (QEvent*)
598 if (!GroupArguments->isEnabled())
599 ActivateThisDialog();
602 //=================================================================================
603 // function : closeEvent()
605 //=================================================================================
606 void SMESHGUI_WhatIsDlg::closeEvent (QCloseEvent*)
608 /* same than click on cancel button */
612 //=======================================================================
613 //function : hideEvent
614 //purpose : caused by ESC key
615 //=======================================================================
616 void SMESHGUI_WhatIsDlg::hideEvent (QHideEvent*)
622 //=================================================================================
623 // function : keyPressEvent()
625 //=================================================================================
626 void SMESHGUI_WhatIsDlg::keyPressEvent( QKeyEvent* e )
628 QDialog::keyPressEvent( e );
629 if ( e->isAccepted() )
632 if ( e->key() == Qt::Key_F1 ) {