1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ScaleDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_ScaleDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 \brief Simple 'busy state' flag locker.
93 //! Constructor. Sets passed boolean flag to \c true.
94 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96 ~BusyLocker() { myBusy = false; }
98 bool& myBusy; //! External 'busy state' boolean flag
104 //=================================================================================
105 // class : SMESHGUI_ScaleDlg()
107 //=================================================================================
108 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
109 : QDialog( SMESH::GetDesktop( theModule ) ),
110 mySMESHGUI( theModule ),
111 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
113 mySelectedObject(SMESH::SMESH_IDSource::_nil())
115 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
116 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
117 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setAttribute(Qt::WA_DeleteOnClose, true);
121 setWindowTitle(tr("SMESH_SCALE_TITLE"));
122 setSizeGripEnabled(true);
124 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
125 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
126 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
128 /***************************************************************/
129 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
130 GroupConstructors = new QButtonGroup(this);
131 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132 ConstructorsBoxLayout->setSpacing(SPACING);
133 ConstructorsBoxLayout->setMargin(MARGIN);
135 RadioButton1= new QRadioButton(ConstructorsBox);
136 RadioButton1->setIcon(image0);
137 RadioButton2= new QRadioButton(ConstructorsBox);
138 RadioButton2->setIcon(image1);
140 ConstructorsBoxLayout->addWidget(RadioButton1);
141 ConstructorsBoxLayout->addWidget(RadioButton2);
142 GroupConstructors->addButton(RadioButton1, 0);
143 GroupConstructors->addButton(RadioButton2, 1);
145 /***************************************************************/
146 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148 GroupArgumentsLayout->setSpacing(SPACING);
149 GroupArgumentsLayout->setMargin(MARGIN);
151 myIdValidator = new SMESHGUI_IdValidator(this);
153 // Controls for elements selection
154 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155 SelectElementsButton = new QPushButton(GroupArguments);
156 SelectElementsButton->setIcon(image2);
157 LineEditElements = new QLineEdit(GroupArguments);
158 LineEditElements->setValidator(myIdValidator);
159 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
160 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
162 // Control for the whole mesh selection
163 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
165 // Controls for vector and points selection
166 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
167 SelectButton1 = new QPushButton(GroupArguments);
168 SelectButton1->setIcon(image2);
170 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
171 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
172 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
173 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
175 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
178 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
181 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
183 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
184 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
187 // switch of action type
188 ActionBox = new QGroupBox(GroupArguments);
189 ActionGroup = new QButtonGroup(GroupArguments);
190 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
191 ActionBoxLayout->addSpacing(SPACING);
192 ActionBoxLayout->setMargin(MARGIN);
194 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
195 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
196 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
198 ActionBoxLayout->addWidget(aMoveElements);
199 ActionBoxLayout->addWidget(aCopyElements);
200 ActionBoxLayout->addWidget(aCreateMesh);
201 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
202 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
203 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
205 // CheckBox for groups generation
206 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
207 MakeGroupsCheck->setChecked(false);
209 // Name of a mesh to create
210 LineEditNewMesh = new QLineEdit(GroupArguments);
213 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
214 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
216 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
217 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
218 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
219 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
220 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
221 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
222 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
223 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
224 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
225 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
226 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
227 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
228 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
229 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
230 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
231 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
232 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 5, 1, 4);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 8, 5, 1, 4);
236 /***************************************************************/
237 GroupButtons = new QGroupBox(this);
238 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
239 GroupButtonsLayout->setSpacing(SPACING);
240 GroupButtonsLayout->setMargin(MARGIN);
242 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
243 buttonOk->setAutoDefault(true);
244 buttonOk->setDefault(true);
245 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
246 buttonApply->setAutoDefault(true);
247 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
248 buttonCancel->setAutoDefault(true);
249 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
250 buttonHelp->setAutoDefault(true);
252 GroupButtonsLayout->addWidget(buttonOk);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addWidget(buttonApply);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addStretch();
257 GroupButtonsLayout->addWidget(buttonCancel);
258 GroupButtonsLayout->addWidget(buttonHelp);
260 /***************************************************************/
261 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
262 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
263 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
265 /* Initialisations */
266 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
267 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
268 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, DBL_DIGITS_DISPLAY);
269 //SpinBox_FX->RangeStepAndValidator(0.0, COORD_MAX, 1.0, DBL_DIGITS_DISPLAY);
270 //SpinBox_FY->RangeStepAndValidator(0.0, COORD_MAX, 1.0, DBL_DIGITS_DISPLAY);
271 //SpinBox_FZ->RangeStepAndValidator(0.0, COORD_MAX, 1.0, DBL_DIGITS_DISPLAY);
272 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, DBL_DIGITS_DISPLAY);
273 SpinBox_FX->SetStep(0.1);
274 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, DBL_DIGITS_DISPLAY);
275 SpinBox_FY->SetStep(0.1);
276 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, DBL_DIGITS_DISPLAY);
277 SpinBox_FZ->SetStep(0.1);
279 RadioButton1->setChecked(true);
281 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
283 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
285 // Costruction of the logical filter
286 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
287 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
289 QList<SUIT_SelectionFilter*> aListOfFilters;
290 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
291 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
293 myMeshOrSubMeshOrGroupFilter =
294 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
296 myHelpFileName = "scale_page.html";
300 /* signals and slots connections */
301 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
302 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
303 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
304 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
305 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
307 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
311 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
312 /* to close dialog if study change */
313 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
314 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
315 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
316 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
318 ConstructorsClicked(0);
319 SelectionIntoArgument();
320 onActionClicked(MOVE_ELEMS_BUTTON);
323 //=================================================================================
324 // function : ~SMESHGUI_ScaleDlg()
325 // purpose : Destroys the object and frees any allocated resources
326 //=================================================================================
327 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
330 myFilterDlg->setParent( 0 );
336 //=================================================================================
339 //=================================================================================
340 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
344 myEditCurrentArgument = 0;
345 LineEditElements->clear();
349 buttonOk->setEnabled(false);
350 buttonApply->setEnabled(false);
353 myMesh = SMESH::SMESH_Mesh::_nil();
356 SpinBox1_1->SetValue(0.0);
357 SpinBox1_2->SetValue(0.0);
358 SpinBox1_3->SetValue(0.0);
359 SpinBox_FX->SetValue(1.0);
360 SpinBox_FY->SetValue(1.0);
361 SpinBox_FZ->SetValue(1.0);
363 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
364 CheckBoxMesh->setChecked(false);
369 //=================================================================================
370 // function : ConstructorsClicked()
371 // purpose : Radio button management
372 //=================================================================================
373 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
375 disconnect(mySelectionMgr, 0, this, 0);
377 switch (constructorId) {
380 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
389 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
398 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
399 SMESH::SetPointRepresentation(false);
400 if (!CheckBoxMesh->isChecked())
401 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
402 aViewWindow->SetSelectionMode( CellSelection );
405 myEditCurrentArgument = (QWidget*)LineEditElements;
406 LineEditElements->setFocus();
408 if (CheckBoxMesh->isChecked())
411 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
413 QApplication::instance()->processEvents();
418 //=================================================================================
419 // function : ClickOnApply()
421 //=================================================================================
422 bool SMESHGUI_ScaleDlg::ClickOnApply()
424 if (mySMESHGUI->isActiveStudyLocked())
430 if (myNbOkElements) {
431 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
433 SMESH::long_array_var anElementsId = new SMESH::long_array;
435 anElementsId->length(aListElementsId.count());
436 for (int i = 0; i < aListElementsId.count(); i++)
437 anElementsId[i] = aListElementsId[i].toInt();
439 SMESH::PointStruct aPoint;
440 aPoint.x = SpinBox1_1->GetValue();
441 aPoint.y = SpinBox1_2->GetValue();
442 aPoint.z = SpinBox1_3->GetValue();
443 SMESH::double_array_var aScaleFact = new SMESH::double_array;
444 aScaleFact->length(3);
445 aScaleFact[0] = SpinBox_FX->GetValue();
446 if (GetConstructorId() == 0) {
447 aScaleFact[1] = SpinBox_FX->GetValue();
448 aScaleFact[2] = SpinBox_FX->GetValue();
451 aScaleFact[1] = SpinBox_FY->GetValue();
452 aScaleFact[2] = SpinBox_FZ->GetValue();
455 QStringList aParameters;
456 aParameters << SpinBox1_1->text();
457 aParameters << SpinBox1_2->text();
458 aParameters << SpinBox1_3->text();
459 aParameters << SpinBox_FX->text();
460 if (GetConstructorId() == 1) {
461 aParameters << SpinBox_FX->text();
462 aParameters << SpinBox_FX->text();
465 aParameters << SpinBox_FY->text();
466 aParameters << SpinBox_FZ->text();
469 int actionButton = ActionGroup->checkedId();
470 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
472 SUIT_OverrideCursor aWaitCursor;
473 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
474 switch ( actionButton ) {
475 case MOVE_ELEMS_BUTTON:
476 if(CheckBoxMesh->isChecked()) {
477 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
480 SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
481 aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
483 if( !myMesh->_is_nil())
484 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
486 case COPY_ELEMS_BUTTON:
488 SMESH::ListOfGroups_var groups;
489 if(CheckBoxMesh->isChecked()) {
490 groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
493 groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
498 if(CheckBoxMesh->isChecked()) {
499 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
502 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
503 aPoint, aScaleFact, true);
506 if( !myMesh->_is_nil())
507 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
509 case MAKE_MESH_BUTTON:
510 SMESH::SMESH_Mesh_var mesh;
511 if(CheckBoxMesh->isChecked()) {
512 mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
513 LineEditNewMesh->text().toLatin1().data());
516 mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
517 aPoint, aScaleFact, makeGroups,
518 LineEditNewMesh->text().toLatin1().data());
520 if( !mesh->_is_nil())
521 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
527 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
528 actionButton == MAKE_MESH_BUTTON )
529 mySMESHGUI->updateObjBrowser(true); // new groups may appear
531 ConstructorsClicked(GetConstructorId());
532 mySelectedObject = SMESH::SMESH_IDSource::_nil();
533 SelectionIntoArgument();
539 //=================================================================================
540 // function : ClickOnOk()
542 //=================================================================================
543 void SMESHGUI_ScaleDlg::ClickOnOk()
549 //=================================================================================
550 // function : ClickOnCancel()
552 //=================================================================================
553 void SMESHGUI_ScaleDlg::ClickOnCancel()
555 disconnect(mySelectionMgr, 0, this, 0);
556 mySelectionMgr->clearFilters();
557 //mySelectionMgr->clearSelected();
558 if (SMESH::GetCurrentVtkView()) {
559 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
560 SMESH::SetPointRepresentation(false);
562 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
563 aViewWindow->SetSelectionMode( ActorSelection );
564 mySMESHGUI->ResetState();
568 //=================================================================================
569 // function : ClickOnHelp()
571 //=================================================================================
572 void SMESHGUI_ScaleDlg::ClickOnHelp()
574 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
576 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
580 platform = "winapplication";
582 platform = "application";
584 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
585 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
586 arg(app->resourceMgr()->stringValue("ExternalBrowser",
588 arg(myHelpFileName));
592 //=======================================================================
593 // function : onTextChange()
595 //=======================================================================
596 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
598 QLineEdit* send = (QLineEdit*)sender();
601 BusyLocker lock( myBusy );
603 if (send == LineEditElements)
606 buttonOk->setEnabled(false);
607 buttonApply->setEnabled(false);
609 // hilight entered elements
610 SMDS_Mesh* aMesh = 0;
612 aMesh = myActor->GetObject()->GetMesh();
615 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
617 TColStd_MapOfInteger newIndices;
619 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
621 if (send == LineEditElements) {
622 for (int i = 0; i < aListId.count(); i++) {
623 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
625 newIndices.Add(e->GetID());
630 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
631 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
632 aViewWindow->highlight( anIO, true, true );
634 myElementsId = theNewText;
637 if (myNbOkElements) {
638 buttonOk->setEnabled(true);
639 buttonApply->setEnabled(true);
643 //=================================================================================
644 // function : SelectionIntoArgument()
645 // purpose : Called when selection as changed or other case
646 //=================================================================================
647 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
650 BusyLocker lock( myBusy );
653 QString aString = "";
655 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
656 LineEditElements->setText(aString);
658 buttonOk->setEnabled(false);
659 buttonApply->setEnabled(false);
662 if (!GroupButtons->isEnabled()) // inactive
667 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
669 int nbSel = aList.Extent();
673 Handle(SALOME_InteractiveObject) IO = aList.First();
674 myMesh = SMESH::GetMeshByIO(IO);
675 if (myMesh->_is_nil())
678 myActor = SMESH::FindActorByObject(myMesh);
680 myActor = SMESH::FindActorByEntry(IO->getEntry());
686 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
689 // MakeGroups is available if there are groups and "Copy"
690 if ( myMesh->NbGroups() == 0 ) {
691 MakeGroupsCheck->setChecked(false);
692 MakeGroupsCheck->setEnabled(false);
694 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
695 MakeGroupsCheck->setEnabled(true);
698 if (CheckBoxMesh->isChecked()) {
699 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
701 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
702 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
708 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
712 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
713 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
715 myElementsId += QString(" %1").arg(i);
719 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
721 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
723 // get IDs from submesh
724 SMESH::long_array_var anElementsIds = new SMESH::long_array;
725 anElementsIds = aSubMesh->GetElementsId();
726 for (int i = 0; i < anElementsIds->length(); i++) {
727 myElementsId += QString(" %1").arg(anElementsIds[i]);
729 aNbUnits = anElementsIds->length();
732 SMESH::SMESH_GroupBase_var aGroup =
733 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
734 if (aGroup->_is_nil())
737 // get IDs from smesh group
738 SMESH::long_array_var anElementsIds = new SMESH::long_array;
739 anElementsIds = aGroup->GetListOfID();
740 for (int i = 0; i < anElementsIds->length(); i++) {
741 myElementsId += QString(" %1").arg(anElementsIds[i]);
743 aNbUnits = anElementsIds->length();
747 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
748 myElementsId = aString;
753 myNbOkElements = true;
755 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
759 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
763 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
771 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
772 SpinBox1_1->SetValue(x);
773 SpinBox1_2->SetValue(y);
774 SpinBox1_3->SetValue(z);
776 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
777 SpinBox_FX->SetValue(x);
778 SpinBox_FY->SetValue(y);
779 SpinBox_FZ->SetValue(z);
783 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
784 LineEditElements->setText(aString);
785 LineEditElements->repaint();
786 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
787 LineEditElements->setEnabled(true);
792 if (myNbOkElements) {
793 buttonOk->setEnabled(true);
794 buttonApply->setEnabled(true);
798 //=================================================================================
799 // function : SetEditCurrentArgument()
801 //=================================================================================
802 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
804 QPushButton* send = (QPushButton*)sender();
806 disconnect(mySelectionMgr, 0, this, 0);
807 mySelectionMgr->clearSelected();
808 mySelectionMgr->clearFilters();
810 if (send == SelectElementsButton) {
811 myEditCurrentArgument = (QWidget*)LineEditElements;
812 SMESH::SetPointRepresentation(false);
813 if (CheckBoxMesh->isChecked()) {
814 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815 aViewWindow->SetSelectionMode( ActorSelection );
816 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
819 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
820 aViewWindow->SetSelectionMode( CellSelection );
823 else if (send == SelectButton1) {
824 myEditCurrentArgument = (QWidget*)SpinBox1_1;
825 SMESH::SetPointRepresentation(true);
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode( NodeSelection );
830 myEditCurrentArgument->setFocus();
831 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
832 SelectionIntoArgument();
835 //=================================================================================
836 // function : DeactivateActiveDialog()
838 //=================================================================================
839 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
841 if (ConstructorsBox->isEnabled()) {
842 ConstructorsBox->setEnabled(false);
843 GroupArguments->setEnabled(false);
844 GroupButtons->setEnabled(false);
845 mySMESHGUI->ResetState();
846 mySMESHGUI->SetActiveDialogBox(0);
850 //=================================================================================
851 // function : ActivateThisDialog()
853 //=================================================================================
854 void SMESHGUI_ScaleDlg::ActivateThisDialog()
856 /* Emit a signal to deactivate the active dialog */
857 mySMESHGUI->EmitSignalDeactivateDialog();
858 ConstructorsBox->setEnabled(true);
859 GroupArguments->setEnabled(true);
860 GroupButtons->setEnabled(true);
862 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
864 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
865 aViewWindow->SetSelectionMode( CellSelection );
867 SelectionIntoArgument();
870 //=================================================================================
871 // function : enterEvent()
873 //=================================================================================
874 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
876 if (!ConstructorsBox->isEnabled())
877 ActivateThisDialog();
880 //=================================================================================
881 // function : closeEvent()
883 //=================================================================================
884 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
886 /* same than click on cancel button */
890 //=======================================================================
891 //function : hideEvent
892 //purpose : caused by ESC key
893 //=======================================================================
894 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
900 //=======================================================================
901 //function : onSelectMesh
903 //=======================================================================
904 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
907 TextLabelElements->setText(tr("SMESH_NAME"));
909 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
910 myFilterBtn->setEnabled(!toSelectMesh);
912 if (myEditCurrentArgument != LineEditElements) {
913 LineEditElements->clear();
917 mySelectionMgr->clearFilters();
918 SMESH::SetPointRepresentation(false);
921 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
922 aViewWindow->SetSelectionMode( ActorSelection );
923 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
924 LineEditElements->setReadOnly(true);
925 LineEditElements->setValidator(0);
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode( CellSelection );
929 LineEditElements->setReadOnly(false);
930 LineEditElements->setValidator(myIdValidator);
931 onTextChange(LineEditElements->text());
934 SelectionIntoArgument();
937 //=======================================================================
938 //function : onActionClicked
939 //purpose : slot called when an action type changed
940 //=======================================================================
942 void SMESHGUI_ScaleDlg::onActionClicked(int button)
945 case MOVE_ELEMS_BUTTON:
946 MakeGroupsCheck->setEnabled(false);
947 LineEditNewMesh->setEnabled(false);
949 case COPY_ELEMS_BUTTON:
950 LineEditNewMesh->setEnabled(false);
951 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
952 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
953 MakeGroupsCheck->setEnabled(true);
955 MakeGroupsCheck->setEnabled(false);
957 case MAKE_MESH_BUTTON:
958 LineEditNewMesh->setEnabled(true);
959 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
960 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961 MakeGroupsCheck->setEnabled(true);
963 MakeGroupsCheck->setEnabled(false);
969 //=======================================================================
970 //function : setNewMeshName
971 //purpose : update contents of LineEditNewMesh
972 //=======================================================================
974 void SMESHGUI_ScaleDlg::setNewMeshName()
976 LineEditNewMesh->setText("");
977 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
979 if ( CheckBoxMesh->isChecked() ) {
980 name = LineEditElements->text();
983 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
984 name = meshSO->GetName().c_str();
986 if ( !name.isEmpty() )
987 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
991 //=================================================================================
992 // function : GetConstructorId()
994 //=================================================================================
995 int SMESHGUI_ScaleDlg::GetConstructorId()
997 return GroupConstructors->checkedId();
1000 //=================================================================================
1001 // function : keyPressEvent()
1003 //=================================================================================
1004 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1006 QDialog::keyPressEvent( e );
1007 if ( e->isAccepted() )
1010 if ( e->key() == Qt::Key_F1 ) {
1016 //=================================================================================
1017 // function : setFilters()
1018 // purpose : SLOT. Called when "Filter" button pressed.
1019 //=================================================================================
1020 void SMESHGUI_ScaleDlg::setFilters()
1022 if(myMesh->_is_nil()) {
1023 SUIT_MessageBox::critical(this,
1025 tr("NO_MESH_SELECTED"));
1029 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1031 myFilterDlg->SetSelection();
1032 myFilterDlg->SetMesh( myMesh );
1033 myFilterDlg->SetSourceWg( LineEditElements );
1035 myFilterDlg->show();
1038 //=================================================================================
1039 // function : isValid
1041 //=================================================================================
1042 bool SMESHGUI_ScaleDlg::isValid()
1047 ok = SpinBox1_1->isValid( msg, true ) && ok;
1048 ok = SpinBox1_2->isValid( msg, true ) && ok;
1049 ok = SpinBox1_3->isValid( msg, true ) && ok;
1050 ok = SpinBox_FX->isValid( msg, true ) && ok;
1051 if (GetConstructorId() == 1) {
1052 ok = SpinBox_FY->isValid( msg, true ) && ok;
1053 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1057 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1058 if ( !msg.isEmpty() )
1060 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );