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 LineEditElements->setMaxLength(-1);
158 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
159 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
161 // Control for the whole mesh selection
162 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
164 // Controls for vector and points selection
165 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
166 SelectButton1 = new QPushButton(GroupArguments);
167 SelectButton1->setIcon(image2);
169 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
170 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
171 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
172 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
174 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
177 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
180 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
183 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
186 // switch of action type
187 ActionBox = new QGroupBox(GroupArguments);
188 ActionGroup = new QButtonGroup(GroupArguments);
189 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
190 ActionBoxLayout->addSpacing(SPACING);
191 ActionBoxLayout->setMargin(MARGIN);
193 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
194 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
195 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
197 ActionBoxLayout->addWidget(aMoveElements);
198 ActionBoxLayout->addWidget(aCopyElements);
199 ActionBoxLayout->addWidget(aCreateMesh);
200 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
201 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
202 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
204 // CheckBox for groups generation
205 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
206 MakeGroupsCheck->setChecked(false);
208 // Name of a mesh to create
209 LineEditNewMesh = new QLineEdit(GroupArguments);
212 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
213 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
214 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
215 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
216 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
217 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
218 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
219 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
220 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
221 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
222 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
223 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
224 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
225 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
226 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
227 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
228 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
229 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
230 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
231 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
232 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 5, 1, 4);
233 GroupArgumentsLayout->addWidget(LineEditNewMesh, 8, 5, 1, 4);
235 /***************************************************************/
236 GroupButtons = new QGroupBox(this);
237 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
238 GroupButtonsLayout->setSpacing(SPACING);
239 GroupButtonsLayout->setMargin(MARGIN);
241 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
242 buttonOk->setAutoDefault(true);
243 buttonOk->setDefault(true);
244 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
245 buttonApply->setAutoDefault(true);
246 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
247 buttonCancel->setAutoDefault(true);
248 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
249 buttonHelp->setAutoDefault(true);
251 GroupButtonsLayout->addWidget(buttonOk);
252 GroupButtonsLayout->addSpacing(10);
253 GroupButtonsLayout->addWidget(buttonApply);
254 GroupButtonsLayout->addSpacing(10);
255 GroupButtonsLayout->addStretch();
256 GroupButtonsLayout->addWidget(buttonCancel);
257 GroupButtonsLayout->addWidget(buttonHelp);
259 /***************************************************************/
260 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
261 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
262 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
264 /* Initialisations */
265 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
266 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
269 SpinBox_FX->SetStep(0.1);
270 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
271 SpinBox_FY->SetStep(0.1);
272 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
273 SpinBox_FZ->SetStep(0.1);
275 RadioButton1->setChecked(true);
277 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
279 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
281 // Costruction of the logical filter
282 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
283 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
285 QList<SUIT_SelectionFilter*> aListOfFilters;
286 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
287 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
289 myMeshOrSubMeshOrGroupFilter =
290 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
292 myHelpFileName = "scale_page.html";
296 /* signals and slots connections */
297 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
298 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
299 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
300 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
301 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
303 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
307 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
308 /* to close dialog if study change */
309 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
310 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
311 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
312 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
314 ConstructorsClicked(0);
315 SelectionIntoArgument();
316 onActionClicked(MOVE_ELEMS_BUTTON);
319 //=================================================================================
320 // function : ~SMESHGUI_ScaleDlg()
321 // purpose : Destroys the object and frees any allocated resources
322 //=================================================================================
323 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
326 myFilterDlg->setParent( 0 );
332 //=================================================================================
335 //=================================================================================
336 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
340 myEditCurrentArgument = 0;
341 LineEditElements->clear();
345 buttonOk->setEnabled(false);
346 buttonApply->setEnabled(false);
349 myMesh = SMESH::SMESH_Mesh::_nil();
352 SpinBox1_1->SetValue(0.0);
353 SpinBox1_2->SetValue(0.0);
354 SpinBox1_3->SetValue(0.0);
355 SpinBox_FX->SetValue(1.0);
356 SpinBox_FY->SetValue(1.0);
357 SpinBox_FZ->SetValue(1.0);
359 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
360 CheckBoxMesh->setChecked(false);
365 //=================================================================================
366 // function : ConstructorsClicked()
367 // purpose : Radio button management
368 //=================================================================================
369 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
371 disconnect(mySelectionMgr, 0, this, 0);
373 switch (constructorId) {
376 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
385 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
394 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
395 SMESH::SetPointRepresentation(false);
396 if (!CheckBoxMesh->isChecked())
397 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
398 aViewWindow->SetSelectionMode( CellSelection );
401 myEditCurrentArgument = (QWidget*)LineEditElements;
402 LineEditElements->setFocus();
404 if (CheckBoxMesh->isChecked())
407 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
409 QApplication::instance()->processEvents();
414 //=================================================================================
415 // function : ClickOnApply()
417 //=================================================================================
418 bool SMESHGUI_ScaleDlg::ClickOnApply()
420 if (mySMESHGUI->isActiveStudyLocked())
426 if (myNbOkElements) {
427 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
429 SMESH::long_array_var anElementsId = new SMESH::long_array;
431 anElementsId->length(aListElementsId.count());
432 for (int i = 0; i < aListElementsId.count(); i++)
433 anElementsId[i] = aListElementsId[i].toInt();
435 SMESH::PointStruct aPoint;
436 aPoint.x = SpinBox1_1->GetValue();
437 aPoint.y = SpinBox1_2->GetValue();
438 aPoint.z = SpinBox1_3->GetValue();
439 SMESH::double_array_var aScaleFact = new SMESH::double_array;
440 aScaleFact->length(3);
441 aScaleFact[0] = SpinBox_FX->GetValue();
442 if (GetConstructorId() == 0) {
443 aScaleFact[1] = SpinBox_FX->GetValue();
444 aScaleFact[2] = SpinBox_FX->GetValue();
447 aScaleFact[1] = SpinBox_FY->GetValue();
448 aScaleFact[2] = SpinBox_FZ->GetValue();
451 QStringList aParameters;
452 aParameters << SpinBox1_1->text();
453 aParameters << SpinBox1_2->text();
454 aParameters << SpinBox1_3->text();
455 aParameters << SpinBox_FX->text();
456 if (GetConstructorId() == 1) {
457 aParameters << SpinBox_FX->text();
458 aParameters << SpinBox_FX->text();
461 aParameters << SpinBox_FY->text();
462 aParameters << SpinBox_FZ->text();
465 int actionButton = ActionGroup->checkedId();
466 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
468 SUIT_OverrideCursor aWaitCursor;
469 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
470 switch ( actionButton ) {
471 case MOVE_ELEMS_BUTTON:
472 if(CheckBoxMesh->isChecked()) {
473 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
476 SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
477 aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
479 if( !myMesh->_is_nil())
480 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
482 case COPY_ELEMS_BUTTON:
484 SMESH::ListOfGroups_var groups;
485 if(CheckBoxMesh->isChecked()) {
486 groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
489 groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
494 if(CheckBoxMesh->isChecked()) {
495 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
498 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
499 aPoint, aScaleFact, true);
502 if( !myMesh->_is_nil())
503 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
505 case MAKE_MESH_BUTTON:
506 SMESH::SMESH_Mesh_var mesh;
507 if(CheckBoxMesh->isChecked()) {
508 mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
509 LineEditNewMesh->text().toLatin1().data());
512 mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
513 aPoint, aScaleFact, makeGroups,
514 LineEditNewMesh->text().toLatin1().data());
516 if( !mesh->_is_nil())
517 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
523 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
524 actionButton == MAKE_MESH_BUTTON )
525 mySMESHGUI->updateObjBrowser(true); // new groups may appear
527 ConstructorsClicked(GetConstructorId());
528 mySelectedObject = SMESH::SMESH_IDSource::_nil();
529 SelectionIntoArgument();
531 SMESHGUI::Modified();
537 //=================================================================================
538 // function : ClickOnOk()
540 //=================================================================================
541 void SMESHGUI_ScaleDlg::ClickOnOk()
547 //=================================================================================
548 // function : ClickOnCancel()
550 //=================================================================================
551 void SMESHGUI_ScaleDlg::ClickOnCancel()
553 disconnect(mySelectionMgr, 0, this, 0);
554 mySelectionMgr->clearFilters();
555 //mySelectionMgr->clearSelected();
556 if (SMESH::GetCurrentVtkView()) {
557 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
558 SMESH::SetPointRepresentation(false);
560 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
561 aViewWindow->SetSelectionMode( ActorSelection );
562 mySMESHGUI->ResetState();
566 //=================================================================================
567 // function : ClickOnHelp()
569 //=================================================================================
570 void SMESHGUI_ScaleDlg::ClickOnHelp()
572 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
578 platform = "winapplication";
580 platform = "application";
582 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
583 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
584 arg(app->resourceMgr()->stringValue("ExternalBrowser",
586 arg(myHelpFileName));
590 //=======================================================================
591 // function : onTextChange()
593 //=======================================================================
594 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
596 QLineEdit* send = (QLineEdit*)sender();
599 BusyLocker lock( myBusy );
601 if (send == LineEditElements)
604 buttonOk->setEnabled(false);
605 buttonApply->setEnabled(false);
607 // hilight entered elements
608 SMDS_Mesh* aMesh = 0;
610 aMesh = myActor->GetObject()->GetMesh();
613 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
615 TColStd_MapOfInteger newIndices;
617 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
619 if (send == LineEditElements) {
620 for (int i = 0; i < aListId.count(); i++) {
621 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
623 newIndices.Add(e->GetID());
628 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
629 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
630 aViewWindow->highlight( anIO, true, true );
632 myElementsId = theNewText;
635 if (myNbOkElements) {
636 buttonOk->setEnabled(true);
637 buttonApply->setEnabled(true);
641 //=================================================================================
642 // function : SelectionIntoArgument()
643 // purpose : Called when selection as changed or other case
644 //=================================================================================
645 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
648 BusyLocker lock( myBusy );
651 QString aString = "";
653 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
654 LineEditElements->setText(aString);
656 buttonOk->setEnabled(false);
657 buttonApply->setEnabled(false);
660 if (!GroupButtons->isEnabled()) // inactive
665 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
667 int nbSel = aList.Extent();
671 Handle(SALOME_InteractiveObject) IO = aList.First();
672 myMesh = SMESH::GetMeshByIO(IO);
673 if (myMesh->_is_nil())
676 myActor = SMESH::FindActorByObject(myMesh);
678 myActor = SMESH::FindActorByEntry(IO->getEntry());
679 if (!myActor && !CheckBoxMesh->isChecked())
684 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
687 // MakeGroups is available if there are groups and "Copy"
688 if ( myMesh->NbGroups() == 0 ) {
689 MakeGroupsCheck->setChecked(false);
690 MakeGroupsCheck->setEnabled(false);
692 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
693 MakeGroupsCheck->setEnabled(true);
696 if (CheckBoxMesh->isChecked()) {
697 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
699 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
700 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
706 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
710 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
711 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
713 myElementsId += QString(" %1").arg(i);
717 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
719 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
721 // get IDs from submesh
722 SMESH::long_array_var anElementsIds = new SMESH::long_array;
723 anElementsIds = aSubMesh->GetElementsId();
724 for (int i = 0; i < anElementsIds->length(); i++) {
725 myElementsId += QString(" %1").arg(anElementsIds[i]);
727 aNbUnits = anElementsIds->length();
730 SMESH::SMESH_GroupBase_var aGroup =
731 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
732 if (aGroup->_is_nil())
735 // get IDs from smesh group
736 SMESH::long_array_var anElementsIds = new SMESH::long_array;
737 anElementsIds = aGroup->GetListOfID();
738 for (int i = 0; i < anElementsIds->length(); i++) {
739 myElementsId += QString(" %1").arg(anElementsIds[i]);
741 aNbUnits = anElementsIds->length();
745 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
746 myElementsId = aString;
751 myNbOkElements = true;
753 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
757 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
761 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
769 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
770 SpinBox1_1->SetValue(x);
771 SpinBox1_2->SetValue(y);
772 SpinBox1_3->SetValue(z);
774 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
775 SpinBox_FX->SetValue(x);
776 SpinBox_FY->SetValue(y);
777 SpinBox_FZ->SetValue(z);
781 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
782 LineEditElements->setText(aString);
783 LineEditElements->repaint();
784 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
785 LineEditElements->setEnabled(true);
790 if (myNbOkElements) {
791 buttonOk->setEnabled(true);
792 buttonApply->setEnabled(true);
796 //=================================================================================
797 // function : SetEditCurrentArgument()
799 //=================================================================================
800 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
802 QPushButton* send = (QPushButton*)sender();
804 disconnect(mySelectionMgr, 0, this, 0);
805 mySelectionMgr->clearSelected();
806 mySelectionMgr->clearFilters();
808 if (send == SelectElementsButton) {
809 myEditCurrentArgument = (QWidget*)LineEditElements;
810 SMESH::SetPointRepresentation(false);
811 if (CheckBoxMesh->isChecked()) {
812 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
813 aViewWindow->SetSelectionMode( ActorSelection );
814 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
817 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
818 aViewWindow->SetSelectionMode( CellSelection );
821 else if (send == SelectButton1) {
822 myEditCurrentArgument = (QWidget*)SpinBox1_1;
823 SMESH::SetPointRepresentation(true);
824 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
825 aViewWindow->SetSelectionMode( NodeSelection );
828 myEditCurrentArgument->setFocus();
829 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
830 SelectionIntoArgument();
833 //=================================================================================
834 // function : DeactivateActiveDialog()
836 //=================================================================================
837 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
839 if (ConstructorsBox->isEnabled()) {
840 ConstructorsBox->setEnabled(false);
841 GroupArguments->setEnabled(false);
842 GroupButtons->setEnabled(false);
843 mySMESHGUI->ResetState();
844 mySMESHGUI->SetActiveDialogBox(0);
848 //=================================================================================
849 // function : ActivateThisDialog()
851 //=================================================================================
852 void SMESHGUI_ScaleDlg::ActivateThisDialog()
854 /* Emit a signal to deactivate the active dialog */
855 mySMESHGUI->EmitSignalDeactivateDialog();
856 ConstructorsBox->setEnabled(true);
857 GroupArguments->setEnabled(true);
858 GroupButtons->setEnabled(true);
860 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
862 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
863 aViewWindow->SetSelectionMode( CellSelection );
865 SelectionIntoArgument();
868 //=================================================================================
869 // function : enterEvent()
871 //=================================================================================
872 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
874 if (!ConstructorsBox->isEnabled())
875 ActivateThisDialog();
878 //=================================================================================
879 // function : closeEvent()
881 //=================================================================================
882 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
884 /* same than click on cancel button */
888 //=======================================================================
889 //function : hideEvent
890 //purpose : caused by ESC key
891 //=======================================================================
892 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
898 //=======================================================================
899 //function : onSelectMesh
901 //=======================================================================
902 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
905 TextLabelElements->setText(tr("SMESH_NAME"));
907 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
908 myFilterBtn->setEnabled(!toSelectMesh);
910 if (myEditCurrentArgument != LineEditElements) {
911 LineEditElements->clear();
915 mySelectionMgr->clearFilters();
916 SMESH::SetPointRepresentation(false);
919 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
920 aViewWindow->SetSelectionMode( ActorSelection );
921 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
922 LineEditElements->setReadOnly(true);
923 LineEditElements->setValidator(0);
925 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
926 aViewWindow->SetSelectionMode( CellSelection );
927 LineEditElements->setReadOnly(false);
928 LineEditElements->setValidator(myIdValidator);
929 onTextChange(LineEditElements->text());
932 SelectionIntoArgument();
935 //=======================================================================
936 //function : onActionClicked
937 //purpose : slot called when an action type changed
938 //=======================================================================
940 void SMESHGUI_ScaleDlg::onActionClicked(int button)
943 case MOVE_ELEMS_BUTTON:
944 MakeGroupsCheck->setEnabled(false);
945 LineEditNewMesh->setEnabled(false);
947 case COPY_ELEMS_BUTTON:
948 LineEditNewMesh->setEnabled(false);
949 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
950 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
951 MakeGroupsCheck->setEnabled(true);
953 MakeGroupsCheck->setEnabled(false);
955 case MAKE_MESH_BUTTON:
956 LineEditNewMesh->setEnabled(true);
957 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
958 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
959 MakeGroupsCheck->setEnabled(true);
961 MakeGroupsCheck->setEnabled(false);
967 //=======================================================================
968 //function : setNewMeshName
969 //purpose : update contents of LineEditNewMesh
970 //=======================================================================
972 void SMESHGUI_ScaleDlg::setNewMeshName()
974 LineEditNewMesh->setText("");
975 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
977 if ( CheckBoxMesh->isChecked() ) {
978 name = LineEditElements->text();
981 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
982 name = meshSO->GetName().c_str();
984 if ( !name.isEmpty() )
985 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
989 //=================================================================================
990 // function : GetConstructorId()
992 //=================================================================================
993 int SMESHGUI_ScaleDlg::GetConstructorId()
995 return GroupConstructors->checkedId();
998 //=================================================================================
999 // function : keyPressEvent()
1001 //=================================================================================
1002 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1004 QDialog::keyPressEvent( e );
1005 if ( e->isAccepted() )
1008 if ( e->key() == Qt::Key_F1 ) {
1014 //=================================================================================
1015 // function : setFilters()
1016 // purpose : SLOT. Called when "Filter" button pressed.
1017 //=================================================================================
1018 void SMESHGUI_ScaleDlg::setFilters()
1020 if(myMesh->_is_nil()) {
1021 SUIT_MessageBox::critical(this,
1023 tr("NO_MESH_SELECTED"));
1027 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1029 myFilterDlg->SetSelection();
1030 myFilterDlg->SetMesh( myMesh );
1031 myFilterDlg->SetSourceWg( LineEditElements );
1033 myFilterDlg->show();
1036 //=================================================================================
1037 // function : isValid
1039 //=================================================================================
1040 bool SMESHGUI_ScaleDlg::isValid()
1045 ok = SpinBox1_1->isValid( msg, true ) && ok;
1046 ok = SpinBox1_2->isValid( msg, true ) && ok;
1047 ok = SpinBox1_3->isValid( msg, true ) && ok;
1048 ok = SpinBox_FX->isValid( msg, true ) && ok;
1049 if (GetConstructorId() == 1) {
1050 ok = SpinBox_FY->isValid( msg, true ) && ok;
1051 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1055 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1056 if ( !msg.isEmpty() )
1058 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );