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_ScaleDlg.cxx
22 // Author : Michael ZORIN, Open CASCADE S.A.S.
25 #include "SMESHGUI_ScaleDlg.h"
28 #include "SMESHGUI_SpinBox.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_IdValidator.h"
33 #include "SMESHGUI_FilterDlg.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_LogicalFilter.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84 \brief Simple 'busy state' flag locker.
91 //! Constructor. Sets passed boolean flag to \c true.
92 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
93 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
94 ~BusyLocker() { myBusy = false; }
96 bool& myBusy; //! External 'busy state' boolean flag
102 //=================================================================================
103 // class : SMESHGUI_ScaleDlg()
105 //=================================================================================
106 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
107 : QDialog( SMESH::GetDesktop( theModule ) ),
108 mySMESHGUI( theModule ),
109 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
111 mySelectedObject(SMESH::SMESH_IDSource::_nil())
113 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
114 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
115 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
118 setAttribute(Qt::WA_DeleteOnClose, true);
119 setWindowTitle(tr("SMESH_SCALE_TITLE"));
120 setSizeGripEnabled(true);
122 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
123 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
124 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
126 /***************************************************************/
127 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
128 GroupConstructors = new QButtonGroup(this);
129 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
130 ConstructorsBoxLayout->setSpacing(SPACING);
131 ConstructorsBoxLayout->setMargin(MARGIN);
133 RadioButton1= new QRadioButton(ConstructorsBox);
134 RadioButton1->setIcon(image0);
135 RadioButton2= new QRadioButton(ConstructorsBox);
136 RadioButton2->setIcon(image1);
138 ConstructorsBoxLayout->addWidget(RadioButton1);
139 ConstructorsBoxLayout->addWidget(RadioButton2);
140 GroupConstructors->addButton(RadioButton1, 0);
141 GroupConstructors->addButton(RadioButton2, 1);
143 /***************************************************************/
144 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
145 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
146 GroupArgumentsLayout->setSpacing(SPACING);
147 GroupArgumentsLayout->setMargin(MARGIN);
149 myIdValidator = new SMESHGUI_IdValidator(this);
151 // Controls for elements selection
152 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
153 SelectElementsButton = new QPushButton(GroupArguments);
154 SelectElementsButton->setIcon(image2);
155 LineEditElements = new QLineEdit(GroupArguments);
156 LineEditElements->setValidator(myIdValidator);
157 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
158 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
160 // Control for the whole mesh selection
161 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
163 // Controls for vector and points selection
164 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
165 SelectButton1 = new QPushButton(GroupArguments);
166 SelectButton1->setIcon(image2);
168 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
169 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
170 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
171 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
172 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
173 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
176 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
179 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
181 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
182 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
185 // switch of action type
186 ActionBox = new QGroupBox(GroupArguments);
187 ActionGroup = new QButtonGroup(GroupArguments);
188 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
189 ActionBoxLayout->addSpacing(SPACING);
190 ActionBoxLayout->setMargin(MARGIN);
192 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
193 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
194 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
196 ActionBoxLayout->addWidget(aMoveElements);
197 ActionBoxLayout->addWidget(aCopyElements);
198 ActionBoxLayout->addWidget(aCreateMesh);
199 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
200 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
201 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
203 // CheckBox for groups generation
204 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
205 MakeGroupsCheck->setChecked(false);
207 // Name of a mesh to create
208 LineEditNewMesh = new QLineEdit(GroupArguments);
211 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
212 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
213 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
214 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
215 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
216 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
217 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
218 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
219 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
220 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
221 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
222 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
223 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
224 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
225 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
226 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
227 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
228 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
229 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
230 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
231 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 5, 1, 4);
232 GroupArgumentsLayout->addWidget(LineEditNewMesh, 8, 5, 1, 4);
234 /***************************************************************/
235 GroupButtons = new QGroupBox(this);
236 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
237 GroupButtonsLayout->setSpacing(SPACING);
238 GroupButtonsLayout->setMargin(MARGIN);
240 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
241 buttonOk->setAutoDefault(true);
242 buttonOk->setDefault(true);
243 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
244 buttonApply->setAutoDefault(true);
245 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
246 buttonCancel->setAutoDefault(true);
247 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
248 buttonHelp->setAutoDefault(true);
250 GroupButtonsLayout->addWidget(buttonOk);
251 GroupButtonsLayout->addSpacing(10);
252 GroupButtonsLayout->addWidget(buttonApply);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addStretch();
255 GroupButtonsLayout->addWidget(buttonCancel);
256 GroupButtonsLayout->addWidget(buttonHelp);
258 /***************************************************************/
259 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
260 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
261 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
263 /* Initialisations */
264 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
265 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
268 SpinBox_FX->SetStep(0.1);
269 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
270 SpinBox_FY->SetStep(0.1);
271 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
272 SpinBox_FZ->SetStep(0.1);
274 RadioButton1->setChecked(true);
276 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
278 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
280 // Costruction of the logical filter
281 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
282 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
284 QList<SUIT_SelectionFilter*> aListOfFilters;
285 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
286 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
288 myMeshOrSubMeshOrGroupFilter =
289 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
291 myHelpFileName = "scale_page.html";
295 /* signals and slots connections */
296 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
297 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
298 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
299 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
300 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
302 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
306 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
307 /* to close dialog if study change */
308 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
309 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
310 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
311 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
313 ConstructorsClicked(0);
314 SelectionIntoArgument();
315 onActionClicked(MOVE_ELEMS_BUTTON);
318 //=================================================================================
319 // function : ~SMESHGUI_ScaleDlg()
320 // purpose : Destroys the object and frees any allocated resources
321 //=================================================================================
322 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
325 myFilterDlg->setParent( 0 );
331 //=================================================================================
334 //=================================================================================
335 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
339 myEditCurrentArgument = 0;
340 LineEditElements->clear();
344 buttonOk->setEnabled(false);
345 buttonApply->setEnabled(false);
348 myMesh = SMESH::SMESH_Mesh::_nil();
351 SpinBox1_1->SetValue(0.0);
352 SpinBox1_2->SetValue(0.0);
353 SpinBox1_3->SetValue(0.0);
354 SpinBox_FX->SetValue(1.0);
355 SpinBox_FY->SetValue(1.0);
356 SpinBox_FZ->SetValue(1.0);
358 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
359 CheckBoxMesh->setChecked(false);
364 //=================================================================================
365 // function : ConstructorsClicked()
366 // purpose : Radio button management
367 //=================================================================================
368 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
370 disconnect(mySelectionMgr, 0, this, 0);
372 switch (constructorId) {
375 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
384 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
393 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
394 SMESH::SetPointRepresentation(false);
395 if (!CheckBoxMesh->isChecked())
396 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
397 aViewWindow->SetSelectionMode( CellSelection );
400 myEditCurrentArgument = (QWidget*)LineEditElements;
401 LineEditElements->setFocus();
403 if (CheckBoxMesh->isChecked())
406 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
408 QApplication::instance()->processEvents();
413 //=================================================================================
414 // function : ClickOnApply()
416 //=================================================================================
417 bool SMESHGUI_ScaleDlg::ClickOnApply()
419 if (mySMESHGUI->isActiveStudyLocked())
425 if (myNbOkElements) {
426 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
428 SMESH::long_array_var anElementsId = new SMESH::long_array;
430 anElementsId->length(aListElementsId.count());
431 for (int i = 0; i < aListElementsId.count(); i++)
432 anElementsId[i] = aListElementsId[i].toInt();
434 SMESH::PointStruct aPoint;
435 aPoint.x = SpinBox1_1->GetValue();
436 aPoint.y = SpinBox1_2->GetValue();
437 aPoint.z = SpinBox1_3->GetValue();
438 SMESH::double_array_var aScaleFact = new SMESH::double_array;
439 aScaleFact->length(3);
440 aScaleFact[0] = SpinBox_FX->GetValue();
441 if (GetConstructorId() == 0) {
442 aScaleFact[1] = SpinBox_FX->GetValue();
443 aScaleFact[2] = SpinBox_FX->GetValue();
446 aScaleFact[1] = SpinBox_FY->GetValue();
447 aScaleFact[2] = SpinBox_FZ->GetValue();
450 QStringList aParameters;
451 aParameters << SpinBox1_1->text();
452 aParameters << SpinBox1_2->text();
453 aParameters << SpinBox1_3->text();
454 aParameters << SpinBox_FX->text();
455 if (GetConstructorId() == 1) {
456 aParameters << SpinBox_FX->text();
457 aParameters << SpinBox_FX->text();
460 aParameters << SpinBox_FY->text();
461 aParameters << SpinBox_FZ->text();
464 int actionButton = ActionGroup->checkedId();
465 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
467 SUIT_OverrideCursor aWaitCursor;
468 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
469 switch ( actionButton ) {
470 case MOVE_ELEMS_BUTTON:
471 if(CheckBoxMesh->isChecked()) {
472 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
475 SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
476 aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
478 if( !myMesh->_is_nil())
479 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
481 case COPY_ELEMS_BUTTON:
483 SMESH::ListOfGroups_var groups;
484 if(CheckBoxMesh->isChecked()) {
485 groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
488 groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
493 if(CheckBoxMesh->isChecked()) {
494 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
497 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
498 aPoint, aScaleFact, true);
501 if( !myMesh->_is_nil())
502 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
504 case MAKE_MESH_BUTTON:
505 SMESH::SMESH_Mesh_var mesh;
506 if(CheckBoxMesh->isChecked()) {
507 mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
508 LineEditNewMesh->text().toLatin1().data());
511 mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
512 aPoint, aScaleFact, makeGroups,
513 LineEditNewMesh->text().toLatin1().data());
515 if( !mesh->_is_nil())
516 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
522 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
523 actionButton == MAKE_MESH_BUTTON )
524 mySMESHGUI->updateObjBrowser(true); // new groups may appear
526 ConstructorsClicked(GetConstructorId());
527 mySelectedObject = SMESH::SMESH_IDSource::_nil();
528 SelectionIntoArgument();
534 //=================================================================================
535 // function : ClickOnOk()
537 //=================================================================================
538 void SMESHGUI_ScaleDlg::ClickOnOk()
544 //=================================================================================
545 // function : ClickOnCancel()
547 //=================================================================================
548 void SMESHGUI_ScaleDlg::ClickOnCancel()
550 disconnect(mySelectionMgr, 0, this, 0);
551 mySelectionMgr->clearFilters();
552 //mySelectionMgr->clearSelected();
553 if (SMESH::GetCurrentVtkView()) {
554 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
555 SMESH::SetPointRepresentation(false);
557 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
558 aViewWindow->SetSelectionMode( ActorSelection );
559 mySMESHGUI->ResetState();
563 //=================================================================================
564 // function : ClickOnHelp()
566 //=================================================================================
567 void SMESHGUI_ScaleDlg::ClickOnHelp()
569 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
571 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
575 platform = "winapplication";
577 platform = "application";
579 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
580 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
581 arg(app->resourceMgr()->stringValue("ExternalBrowser",
583 arg(myHelpFileName));
587 //=======================================================================
588 // function : onTextChange()
590 //=======================================================================
591 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
593 QLineEdit* send = (QLineEdit*)sender();
596 BusyLocker lock( myBusy );
598 if (send == LineEditElements)
601 buttonOk->setEnabled(false);
602 buttonApply->setEnabled(false);
604 // hilight entered elements
605 SMDS_Mesh* aMesh = 0;
607 aMesh = myActor->GetObject()->GetMesh();
610 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
612 TColStd_MapOfInteger newIndices;
614 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
616 if (send == LineEditElements) {
617 for (int i = 0; i < aListId.count(); i++) {
618 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
620 newIndices.Add(e->GetID());
625 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
626 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
627 aViewWindow->highlight( anIO, true, true );
629 myElementsId = theNewText;
632 if (myNbOkElements) {
633 buttonOk->setEnabled(true);
634 buttonApply->setEnabled(true);
638 //=================================================================================
639 // function : SelectionIntoArgument()
640 // purpose : Called when selection as changed or other case
641 //=================================================================================
642 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
645 BusyLocker lock( myBusy );
648 QString aString = "";
650 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
651 LineEditElements->setText(aString);
653 buttonOk->setEnabled(false);
654 buttonApply->setEnabled(false);
657 if (!GroupButtons->isEnabled()) // inactive
662 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
664 int nbSel = aList.Extent();
668 Handle(SALOME_InteractiveObject) IO = aList.First();
669 myMesh = SMESH::GetMeshByIO(IO);
670 if (myMesh->_is_nil())
673 myActor = SMESH::FindActorByObject(myMesh);
675 myActor = SMESH::FindActorByEntry(IO->getEntry());
676 if (!myActor && !CheckBoxMesh->isChecked())
681 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
684 // MakeGroups is available if there are groups and "Copy"
685 if ( myMesh->NbGroups() == 0 ) {
686 MakeGroupsCheck->setChecked(false);
687 MakeGroupsCheck->setEnabled(false);
689 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
690 MakeGroupsCheck->setEnabled(true);
693 if (CheckBoxMesh->isChecked()) {
694 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
696 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
697 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
703 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
707 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
708 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
710 myElementsId += QString(" %1").arg(i);
714 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
716 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
718 // get IDs from submesh
719 SMESH::long_array_var anElementsIds = new SMESH::long_array;
720 anElementsIds = aSubMesh->GetElementsId();
721 for (int i = 0; i < anElementsIds->length(); i++) {
722 myElementsId += QString(" %1").arg(anElementsIds[i]);
724 aNbUnits = anElementsIds->length();
727 SMESH::SMESH_GroupBase_var aGroup =
728 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
729 if (aGroup->_is_nil())
732 // get IDs from smesh group
733 SMESH::long_array_var anElementsIds = new SMESH::long_array;
734 anElementsIds = aGroup->GetListOfID();
735 for (int i = 0; i < anElementsIds->length(); i++) {
736 myElementsId += QString(" %1").arg(anElementsIds[i]);
738 aNbUnits = anElementsIds->length();
742 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
743 myElementsId = aString;
748 myNbOkElements = true;
750 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
754 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
758 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
766 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
767 SpinBox1_1->SetValue(x);
768 SpinBox1_2->SetValue(y);
769 SpinBox1_3->SetValue(z);
771 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
772 SpinBox_FX->SetValue(x);
773 SpinBox_FY->SetValue(y);
774 SpinBox_FZ->SetValue(z);
778 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
779 LineEditElements->setText(aString);
780 LineEditElements->repaint();
781 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
782 LineEditElements->setEnabled(true);
787 if (myNbOkElements) {
788 buttonOk->setEnabled(true);
789 buttonApply->setEnabled(true);
793 //=================================================================================
794 // function : SetEditCurrentArgument()
796 //=================================================================================
797 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
799 QPushButton* send = (QPushButton*)sender();
801 disconnect(mySelectionMgr, 0, this, 0);
802 mySelectionMgr->clearSelected();
803 mySelectionMgr->clearFilters();
805 if (send == SelectElementsButton) {
806 myEditCurrentArgument = (QWidget*)LineEditElements;
807 SMESH::SetPointRepresentation(false);
808 if (CheckBoxMesh->isChecked()) {
809 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
810 aViewWindow->SetSelectionMode( ActorSelection );
811 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
814 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
815 aViewWindow->SetSelectionMode( CellSelection );
818 else if (send == SelectButton1) {
819 myEditCurrentArgument = (QWidget*)SpinBox1_1;
820 SMESH::SetPointRepresentation(true);
821 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822 aViewWindow->SetSelectionMode( NodeSelection );
825 myEditCurrentArgument->setFocus();
826 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
827 SelectionIntoArgument();
830 //=================================================================================
831 // function : DeactivateActiveDialog()
833 //=================================================================================
834 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
836 if (ConstructorsBox->isEnabled()) {
837 ConstructorsBox->setEnabled(false);
838 GroupArguments->setEnabled(false);
839 GroupButtons->setEnabled(false);
840 mySMESHGUI->ResetState();
841 mySMESHGUI->SetActiveDialogBox(0);
845 //=================================================================================
846 // function : ActivateThisDialog()
848 //=================================================================================
849 void SMESHGUI_ScaleDlg::ActivateThisDialog()
851 /* Emit a signal to deactivate the active dialog */
852 mySMESHGUI->EmitSignalDeactivateDialog();
853 ConstructorsBox->setEnabled(true);
854 GroupArguments->setEnabled(true);
855 GroupButtons->setEnabled(true);
857 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
859 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
860 aViewWindow->SetSelectionMode( CellSelection );
862 SelectionIntoArgument();
865 //=================================================================================
866 // function : enterEvent()
868 //=================================================================================
869 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
871 if (!ConstructorsBox->isEnabled())
872 ActivateThisDialog();
875 //=================================================================================
876 // function : closeEvent()
878 //=================================================================================
879 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
881 /* same than click on cancel button */
885 //=======================================================================
886 //function : hideEvent
887 //purpose : caused by ESC key
888 //=======================================================================
889 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
895 //=======================================================================
896 //function : onSelectMesh
898 //=======================================================================
899 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
902 TextLabelElements->setText(tr("SMESH_NAME"));
904 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
905 myFilterBtn->setEnabled(!toSelectMesh);
907 if (myEditCurrentArgument != LineEditElements) {
908 LineEditElements->clear();
912 mySelectionMgr->clearFilters();
913 SMESH::SetPointRepresentation(false);
916 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
917 aViewWindow->SetSelectionMode( ActorSelection );
918 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
919 LineEditElements->setReadOnly(true);
920 LineEditElements->setValidator(0);
922 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
923 aViewWindow->SetSelectionMode( CellSelection );
924 LineEditElements->setReadOnly(false);
925 LineEditElements->setValidator(myIdValidator);
926 onTextChange(LineEditElements->text());
929 SelectionIntoArgument();
932 //=======================================================================
933 //function : onActionClicked
934 //purpose : slot called when an action type changed
935 //=======================================================================
937 void SMESHGUI_ScaleDlg::onActionClicked(int button)
940 case MOVE_ELEMS_BUTTON:
941 MakeGroupsCheck->setEnabled(false);
942 LineEditNewMesh->setEnabled(false);
944 case COPY_ELEMS_BUTTON:
945 LineEditNewMesh->setEnabled(false);
946 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
947 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
948 MakeGroupsCheck->setEnabled(true);
950 MakeGroupsCheck->setEnabled(false);
952 case MAKE_MESH_BUTTON:
953 LineEditNewMesh->setEnabled(true);
954 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
955 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
956 MakeGroupsCheck->setEnabled(true);
958 MakeGroupsCheck->setEnabled(false);
964 //=======================================================================
965 //function : setNewMeshName
966 //purpose : update contents of LineEditNewMesh
967 //=======================================================================
969 void SMESHGUI_ScaleDlg::setNewMeshName()
971 LineEditNewMesh->setText("");
972 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
974 if ( CheckBoxMesh->isChecked() ) {
975 name = LineEditElements->text();
978 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
979 name = meshSO->GetName().c_str();
981 if ( !name.isEmpty() )
982 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
986 //=================================================================================
987 // function : GetConstructorId()
989 //=================================================================================
990 int SMESHGUI_ScaleDlg::GetConstructorId()
992 return GroupConstructors->checkedId();
995 //=================================================================================
996 // function : keyPressEvent()
998 //=================================================================================
999 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1001 QDialog::keyPressEvent( e );
1002 if ( e->isAccepted() )
1005 if ( e->key() == Qt::Key_F1 ) {
1011 //=================================================================================
1012 // function : setFilters()
1013 // purpose : SLOT. Called when "Filter" button pressed.
1014 //=================================================================================
1015 void SMESHGUI_ScaleDlg::setFilters()
1017 if(myMesh->_is_nil()) {
1018 SUIT_MessageBox::critical(this,
1020 tr("NO_MESH_SELECTED"));
1024 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1026 myFilterDlg->SetSelection();
1027 myFilterDlg->SetMesh( myMesh );
1028 myFilterDlg->SetSourceWg( LineEditElements );
1030 myFilterDlg->show();
1033 //=================================================================================
1034 // function : isValid
1036 //=================================================================================
1037 bool SMESHGUI_ScaleDlg::isValid()
1042 ok = SpinBox1_1->isValid( msg, true ) && ok;
1043 ok = SpinBox1_2->isValid( msg, true ) && ok;
1044 ok = SpinBox1_3->isValid( msg, true ) && ok;
1045 ok = SpinBox_FX->isValid( msg, true ) && ok;
1046 if (GetConstructorId() == 1) {
1047 ok = SpinBox_FY->isValid( msg, true ) && ok;
1048 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1052 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1053 if ( !msg.isEmpty() )
1055 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );