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
24 // File : SMESHGUI_WhatIsDlg.cxx
25 // Author : Vladimir TURIN
29 #include "SMESHGUI_WhatIsDlg.h"
32 #include "SMESHGUI_SpinBox.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_IdValidator.h"
38 #include "SMESH_Actor.h"
39 #include "SMESH_TypeFilter.hxx"
40 #include "SMESH_LogicalFilter.hxx"
41 #include "SMDS_Mesh.hxx"
42 #include "SMDS_VolumeTool.hxx"
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ResourceMgr.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_MessageBox.h"
49 #include "LightApp_Application.h"
51 #include "SVTK_ViewModel.h"
52 #include "SVTK_Selection.h"
53 #include "SVTK_ViewWindow.h"
54 #include "SVTK_Selector.h"
55 #include "SALOME_ListIO.hxx"
57 #include "utilities.h"
60 #include <TColStd_MapOfInteger.hxx>
61 #include <TColStd_IndexedMapOfInteger.hxx>
65 #include <qapplication.h>
66 #include <qbuttongroup.h>
67 #include <qgroupbox.h>
69 #include <qlineedit.h>
70 #include <qpushbutton.h>
71 #include <qradiobutton.h>
72 #include <qcheckbox.h>
76 #include <qtextbrowser.h>
79 #include "SALOMEconfig.h"
80 #include CORBA_SERVER_HEADER(SMESH_Group)
81 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
85 //=================================================================================
86 // class : SMESHGUI_WhatIsDlg()
88 //=================================================================================
89 SMESHGUI_WhatIsDlg::SMESHGUI_WhatIsDlg( SMESHGUI* theModule, const char* name,
90 bool modal, WFlags fl)
91 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
92 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
93 mySMESHGUI( theModule ),
94 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
97 setName("SMESHGUI_WhatIsDlg");
99 setCaption(tr("SMESH_WHAT_IS_TITLE"));
100 setSizeGripEnabled(TRUE);
101 SMESHGUI_WhatIsDlgLayout = new QGridLayout(this);
102 SMESHGUI_WhatIsDlgLayout->setSpacing(6);
103 SMESHGUI_WhatIsDlgLayout->setMargin(11);
105 /***************************************************************/
106 GroupMesh = new QButtonGroup(this, "GroupSelections");
107 GroupMesh->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupMesh->sizePolicy().hasHeightForWidth()));
108 GroupMesh->setTitle(tr(""));
109 GroupMesh->setColumnLayout(0, Qt::Vertical);
110 GroupMesh->layout()->setSpacing(0);
111 GroupMesh->layout()->setMargin(0);
112 GroupMeshLayout = new QGridLayout(GroupMesh->layout());
113 GroupMeshLayout->setAlignment(Qt::AlignTop);
114 GroupMeshLayout->setSpacing(6);
115 GroupMeshLayout->setMargin(11);
116 MeshLabel = new QLabel(GroupMesh, "MeshLabel");
117 MeshLabel->setText(tr("SMESH_NAME"));
118 GroupMeshLayout->addWidget(MeshLabel, 0, 0);
119 MeshName = new QLabel(GroupMesh, "MeshName");
120 MeshName->setText(tr(""));
121 GroupMeshLayout->addWidget(MeshName, 0, 1);
122 SMESHGUI_WhatIsDlgLayout->addWidget(GroupMesh, 0, 0);
124 /***************************************************************/
125 GroupSelections = new QButtonGroup(this, "GroupSelections");
126 GroupSelections->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupSelections->sizePolicy().hasHeightForWidth()));
127 GroupSelections->setTitle(tr("ENTITY_TYPE" ));
128 GroupSelections->setExclusive(TRUE);
129 GroupSelections->setColumnLayout(0, Qt::Vertical);
130 GroupSelections->layout()->setSpacing(0);
131 GroupSelections->layout()->setMargin(0);
132 GroupSelectionsLayout = new QGridLayout(GroupSelections->layout());
133 GroupSelectionsLayout->setAlignment(Qt::AlignTop);
134 GroupSelectionsLayout->setSpacing(6);
135 GroupSelectionsLayout->setMargin(11);
136 RadioButtonNodes = new QRadioButton(GroupSelections, "RadioButtonNodes");
137 RadioButtonNodes->setText(tr("SMESH_NODES"));
138 GroupSelectionsLayout->addWidget(RadioButtonNodes, 0, 0);
139 RadioButtonElements = new QRadioButton(GroupSelections, "RadioButtonElements");
140 RadioButtonElements->setText(tr("SMESH_ELEMENTS"));
141 GroupSelectionsLayout->addWidget(RadioButtonElements, 0, 1 );
142 SMESHGUI_WhatIsDlgLayout->addWidget(GroupSelections, 1, 0);
144 /***************************************************************/
145 GroupArguments = new QGroupBox(this, "GroupArguments");
146 GroupArguments->setTitle(tr("SMESH_INFORMATION"));
147 GroupArguments->setColumnLayout(0, Qt::Vertical);
148 GroupArguments->layout()->setSpacing(0);
149 GroupArguments->layout()->setMargin(0);
150 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
151 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
152 GroupArgumentsLayout->setSpacing(6);
153 GroupArgumentsLayout->setMargin(11);
155 // Controls for elements selection
156 TextLabelElements = new QLabel(GroupArguments, "TextLabelElements");
157 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS" ));
158 TextLabelElements->setFixedWidth(74);
159 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
161 LineEditElements = new QLineEdit(GroupArguments, "LineEditElements");
162 LineEditElements->setValidator(new SMESHGUI_IdValidator(this, "validator"));
163 GroupArgumentsLayout->addMultiCellWidget(LineEditElements, 0, 0, 2, 7);
165 // information text browser
166 Info = new QTextBrowser(GroupArguments, "Info");
167 Info->setHScrollBarMode(QScrollView::AlwaysOff);
168 Info->setVScrollBarMode(QScrollView::AlwaysOff);
169 GroupArgumentsLayout->addMultiCellWidget(Info, 1, 1, 0, 7);
171 SMESHGUI_WhatIsDlgLayout->addWidget(GroupArguments, 2, 0);
173 /***************************************************************/
174 GroupButtons = new QGroupBox(this, "GroupButtons");
175 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth()));
176 GroupButtons->setTitle(tr("" ));
177 GroupButtons->setColumnLayout(0, Qt::Vertical);
178 GroupButtons->layout()->setSpacing(0);
179 GroupButtons->layout()->setMargin(0);
180 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
181 GroupButtonsLayout->setAlignment(Qt::AlignTop);
182 GroupButtonsLayout->setSpacing(6);
183 GroupButtonsLayout->setMargin(11);
184 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
185 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
186 buttonHelp->setAutoDefault(TRUE);
187 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
188 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
189 GroupButtonsLayout->addItem(spacer_9, 0, 1);
190 buttonOk = new QPushButton(GroupButtons, "buttonOk");
191 buttonOk->setText(tr("SMESH_BUT_OK" ));
192 buttonOk->setAutoDefault(TRUE);
193 buttonOk->setDefault(TRUE);
194 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
195 SMESHGUI_WhatIsDlgLayout->addWidget(GroupButtons, 3, 0);
197 GroupArguments->show();
198 RadioButtonNodes->setChecked(TRUE);
200 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
202 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
204 // Costruction of the logical filter
205 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
206 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
208 QPtrList<SUIT_SelectionFilter> aListOfFilters;
209 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
210 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
212 myMeshOrSubMeshOrGroupFilter =
213 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
215 myHelpFileName = "/files/viewing_mesh_info.htm#element_infos";
219 /* signals and slots connections */
220 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
221 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
222 connect(GroupSelections, SIGNAL(clicked(int)), SLOT(SelectionsClicked(int)));
224 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
225 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
226 /* to close dialog if study change */
227 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
228 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
229 this->show(); /* displays Dialog */
231 SelectionsClicked(0);
232 SelectionIntoArgument();
235 //=================================================================================
236 // function : ~SMESHGUI_WhatIsDlg()
237 // purpose : Destroys the object and frees any allocated resources
238 //=================================================================================
239 SMESHGUI_WhatIsDlg::~SMESHGUI_WhatIsDlg()
241 // no need to delete child widgets, Qt does it all for us
244 //=================================================================================
247 //=================================================================================
248 void SMESHGUI_WhatIsDlg::Init (bool ResetControls)
252 LineEditElements->clear();
255 myMesh = SMESH::SMESH_Mesh::_nil();
258 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
259 aViewWindow->SetSelectionMode( CellSelection );
260 onTextChange(LineEditElements->text());
262 SelectionIntoArgument();
266 //=================================================================================
267 // function : SelectionsClicked()
268 // purpose : Radio button management
269 //=================================================================================
270 void SMESHGUI_WhatIsDlg::SelectionsClicked (int selectionId)
272 disconnect(mySelectionMgr, 0, this, 0);
274 mySelectionMgr->clearFilters();
276 switch (selectionId) {
279 SMESH::SetPointRepresentation(true);
280 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
281 aViewWindow->SetSelectionMode( NodeSelection );
286 SMESH::SetPointRepresentation(false);
287 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
288 aViewWindow->SetSelectionMode( CellSelection );
293 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
294 SelectionIntoArgument();
297 //=================================================================================
298 // function : ClickOnOk()
300 //=================================================================================
301 void SMESHGUI_WhatIsDlg::ClickOnOk()
303 if (mySMESHGUI->isActiveStudyLocked())
308 SelectionIntoArgument();
312 //=================================================================================
313 // function : ClickOnCancel()
315 //=================================================================================
316 void SMESHGUI_WhatIsDlg::ClickOnCancel()
318 disconnect(mySelectionMgr, 0, this, 0);
319 mySelectionMgr->clearFilters();
320 SMESH::SetPointRepresentation(false);
321 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
322 aViewWindow->SetSelectionMode( ActorSelection );
323 mySMESHGUI->ResetState();
327 //=================================================================================
328 // function : ClickOnHelp()
330 //=================================================================================
331 void SMESHGUI_WhatIsDlg::ClickOnHelp()
333 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
335 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
337 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
338 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
339 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
340 QObject::tr("BUT_OK"));
344 //=======================================================================
345 // function : onTextChange()
347 //=======================================================================
348 void SMESHGUI_WhatIsDlg::onTextChange (const QString& theNewText)
353 // hilight entered elements
354 SMDS_Mesh* aMesh = 0;
356 aMesh = myActor->GetObject()->GetMesh();
359 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
361 TColStd_MapOfInteger newIndices;
363 QStringList aListId = QStringList::split(" ", theNewText, false);
365 for (int i = 0; i < aListId.count(); i++) {
366 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
367 aMesh->FindNode(aListId[ i ].toInt()):
368 aMesh->FindElement(aListId[ i ].toInt());
370 newIndices.Add(e->GetID());
373 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
374 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
375 aViewWindow->highlight( anIO, true, true );
378 SelectionIntoArgument();
383 //=================================================================================
384 // function : SelectionIntoArgument()
385 // purpose : Called when selection as changed or other case
386 //=================================================================================
387 void SMESHGUI_WhatIsDlg::SelectionIntoArgument()
389 int curBusy = myBusy;
393 QString aString = "";
397 LineEditElements->setText(aString);
398 MeshName->setText(aString);
399 GroupMesh->setTitle(tr(""));
403 if (!GroupButtons->isEnabled()) // inactive
408 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
410 int nbSel = aList.Extent();
415 Handle(SALOME_InteractiveObject) IO = aList.First();
416 myMesh = SMESH::GetMeshByIO(IO);
417 if (myMesh->_is_nil())
420 myActor = SMESH::FindActorByObject(myMesh);
422 myActor = SMESH::FindActorByEntry(IO->getEntry());
427 SMESH::GetNameOfSelectedIObjects(mySelectionMgr, aName);
428 MeshName->setText(aName);
429 if(!SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO)->_is_nil()) {
430 GroupMesh->setTitle(tr("SMESH_MESH"));
431 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) {
432 GroupMesh->setTitle(tr("SMESH_SUBMESH"));
433 } else if(!SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO)->_is_nil()) {
434 GroupMesh->setTitle(tr("SMESH_GROUP"));
439 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
444 const SMDS_MeshElement * e = RadioButtonNodes->isChecked()?
445 myActor->GetObject()->GetMesh()->FindNode(aString.toInt()):
446 myActor->GetObject()->GetMesh()->FindElement(aString.toInt());
449 anInfo=tr("ENTITY_TYPE") + ": ";
450 if(e->GetType() == SMDSAbs_Node) {
451 anInfo+=tr("MESH_NODE")+"\n";
452 const SMDS_MeshNode *en = (SMDS_MeshNode*) e;
453 } else if(e->GetType() == SMDSAbs_Edge) {
454 anInfo+=tr("SMESH_EDGE")+"\n";
455 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
456 const SMDS_MeshEdge *ee = (SMDS_MeshEdge*) e;
457 anInfo+=(ee->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+"\n";
458 } else if(e->GetType() == SMDSAbs_Face) {
459 const SMDS_MeshFace *ef = (SMDS_MeshFace*) e;
460 anInfo+=tr("SMESH_FACE")+"\n";
461 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
463 anInfo+=(ef->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
464 switch(ef->NbNodes()) {
468 anInfo+=tr("SMESH_TRIANGLE");
474 anInfo+=tr("SMESH_QUADRANGLE");
481 } else if(e->GetType() == SMDSAbs_Volume) {
482 anInfo+=tr("SMESH_VOLUME")+"\n";
483 anInfo+=tr("SMESH_MESHINFO_TYPE")+": ";
484 const SMDS_MeshVolume *ev = (SMDS_MeshVolume*) e;
485 SMDS_VolumeTool vt(ev);
486 if(vt.GetVolumeType() != SMDS_VolumeTool::POLYHEDA)
487 anInfo+=(ev->IsQuadratic()?tr("SMESH_MESHINFO_ORDER2"):tr("SMESH_MESHINFO_ORDER1"))+" ";
488 switch(vt.GetVolumeType()) {
489 case SMDS_VolumeTool::TETRA:
490 case SMDS_VolumeTool::QUAD_TETRA:
492 anInfo+=tr("SMESH_TETRAS");
495 case SMDS_VolumeTool::PYRAM:
496 case SMDS_VolumeTool::QUAD_PYRAM:
498 anInfo+=tr("SMESH_PYRAMID");
501 case SMDS_VolumeTool::PENTA:
502 case SMDS_VolumeTool::QUAD_PENTA:
504 anInfo+=tr("SMESH_PRISM");
507 case SMDS_VolumeTool::HEXA:
508 case SMDS_VolumeTool::QUAD_HEXA:
510 anInfo+=tr("SMESH_HEXAS");
513 case SMDS_VolumeTool::POLYHEDA:
515 anInfo+=tr("SMESH_POLYEDRON");
523 if(e->GetType() != SMDSAbs_Node)
524 anInfo+=tr("GRAVITY_CENTER") + ":\n";
525 gp_XYZ anXYZ(0.,0.,0.);
526 SMDS_ElemIteratorPtr nodeIt = e->nodesIterator();
528 for(; nodeIt->more(); nbNodes++) {
529 const SMDS_MeshNode* node = static_cast<const SMDS_MeshNode*>( nodeIt->next() );
530 anXYZ.Add( gp_XYZ( node->X(), node->Y(), node->Z() ) );
532 anXYZ.Divide(e->NbNodes()) ;
533 anInfo+=QString("X=%1\nY=%2\nZ=%3\n").arg(anXYZ.X()).arg(anXYZ.Y()).arg(anXYZ.Z());
534 Info->setText(anInfo);
539 LineEditElements->setText(aString);
544 //=================================================================================
545 // function : DeactivateActiveDialog()
547 //=================================================================================
548 void SMESHGUI_WhatIsDlg::DeactivateActiveDialog()
550 if (GroupArguments->isEnabled()) {
551 GroupSelections->setEnabled(false);
552 GroupMesh->setEnabled(false);
553 GroupArguments->setEnabled(false);
554 GroupButtons->setEnabled(false);
555 mySMESHGUI->ResetState();
556 mySMESHGUI->SetActiveDialogBox(0);
560 //=================================================================================
561 // function : ActivateThisDialog()
563 //=================================================================================
564 void SMESHGUI_WhatIsDlg::ActivateThisDialog()
566 /* Emit a signal to deactivate the active dialog */
567 mySMESHGUI->EmitSignalDeactivateDialog();
568 GroupArguments->setEnabled(true);
569 GroupButtons->setEnabled(true);
570 GroupSelections->setEnabled(true);
571 GroupMesh->setEnabled(true);
573 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
575 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
576 SelectionsClicked(RadioButtonNodes->isChecked()?0:1);
578 SelectionIntoArgument();
581 //=================================================================================
582 // function : enterEvent()
584 //=================================================================================
585 void SMESHGUI_WhatIsDlg::enterEvent (QEvent*)
587 if (!GroupArguments->isEnabled())
588 ActivateThisDialog();
591 //=================================================================================
592 // function : closeEvent()
594 //=================================================================================
595 void SMESHGUI_WhatIsDlg::closeEvent (QCloseEvent*)
597 /* same than click on cancel button */
598 this->ClickOnCancel();
601 //=======================================================================
602 //function : hideEvent
603 //purpose : caused by ESC key
604 //=======================================================================
605 void SMESHGUI_WhatIsDlg::hideEvent (QHideEvent*)
611 //=================================================================================
612 // function : keyPressEvent()
614 //=================================================================================
615 void SMESHGUI_WhatIsDlg::keyPressEvent( QKeyEvent* e )
617 QDialog::keyPressEvent( e );
618 if ( e->isAccepted() )
621 if ( e->key() == Key_F1 )