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
19 // SMESH SMESHGUI : GUI for SMESH component
20 // File : SMESHGUI_ScaleDlg.cxx
21 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 #include "SMESHGUI_ScaleDlg.h"
27 #include "SMESHGUI_SpinBox.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_IdValidator.h"
32 #include "SMESHGUI_FilterDlg.h"
34 #include <SMESH_Actor.h>
35 #include <SMESH_TypeFilter.hxx>
36 #include <SMESH_LogicalFilter.hxx>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_OverrideCursor.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
53 // SALOME KERNEL includes
54 #include <SALOMEDSClient_SObject.hxx>
57 #include <TColStd_MapOfInteger.hxx>
60 #include <QApplication>
61 #include <QButtonGroup>
65 #include <QPushButton>
66 #include <QRadioButton>
68 #include <QHBoxLayout>
69 #include <QVBoxLayout>
70 #include <QGridLayout>
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
83 \brief Simple 'busy state' flag locker.
90 //! Constructor. Sets passed boolean flag to \c true.
91 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
92 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
93 ~BusyLocker() { myBusy = false; }
95 bool& myBusy; //! External 'busy state' boolean flag
101 //To disable automatic genericobj management, the following line should be commented.
102 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
103 #define WITHGENERICOBJ
105 //=================================================================================
106 // class : SMESHGUI_ScaleDlg()
108 //=================================================================================
109 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
110 : QDialog( SMESH::GetDesktop( theModule ) ),
111 mySMESHGUI( theModule ),
112 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114 mySelectedObject(SMESH::SMESH_IDSource::_nil())
116 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
117 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
118 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
121 setAttribute(Qt::WA_DeleteOnClose, true);
122 setWindowTitle(tr("SMESH_SCALE_TITLE"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
126 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
127 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
129 /***************************************************************/
130 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
131 GroupConstructors = new QButtonGroup(this);
132 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
133 ConstructorsBoxLayout->setSpacing(SPACING);
134 ConstructorsBoxLayout->setMargin(MARGIN);
136 RadioButton1= new QRadioButton(ConstructorsBox);
137 RadioButton1->setIcon(image0);
138 RadioButton2= new QRadioButton(ConstructorsBox);
139 RadioButton2->setIcon(image1);
141 ConstructorsBoxLayout->addWidget(RadioButton1);
142 ConstructorsBoxLayout->addWidget(RadioButton2);
143 GroupConstructors->addButton(RadioButton1, 0);
144 GroupConstructors->addButton(RadioButton2, 1);
146 /***************************************************************/
147 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149 GroupArgumentsLayout->setSpacing(SPACING);
150 GroupArgumentsLayout->setMargin(MARGIN);
152 myIdValidator = new SMESHGUI_IdValidator(this);
154 // Controls for elements selection
155 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
156 SelectElementsButton = new QPushButton(GroupArguments);
157 SelectElementsButton->setIcon(image2);
158 LineEditElements = new QLineEdit(GroupArguments);
159 LineEditElements->setValidator(myIdValidator);
160 LineEditElements->setMaxLength(-1);
161 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
164 // Control for the whole mesh selection
165 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
167 // Controls for vector and points selection
168 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
169 SelectButton1 = new QPushButton(GroupArguments);
170 SelectButton1->setIcon(image2);
172 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
173 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
175 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
177 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
180 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
183 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
186 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
189 // switch of action type
190 ActionBox = new QGroupBox(GroupArguments);
191 ActionGroup = new QButtonGroup(GroupArguments);
192 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193 ActionBoxLayout->addSpacing(SPACING);
194 ActionBoxLayout->setMargin(MARGIN);
196 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
200 ActionBoxLayout->addWidget(aMoveElements);
201 ActionBoxLayout->addWidget(aCopyElements);
202 ActionBoxLayout->addWidget(aCreateMesh);
203 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
207 // CheckBox for groups generation
208 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209 MakeGroupsCheck->setChecked(false);
211 // Name of a mesh to create
212 LineEditNewMesh = new QLineEdit(GroupArguments);
215 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
216 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
217 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
218 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
219 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
220 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
221 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
222 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
223 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
224 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
225 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
226 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
227 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
228 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
229 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
230 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
231 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
232 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
233 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
234 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
235 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 5, 1, 4);
236 GroupArgumentsLayout->addWidget(LineEditNewMesh, 8, 5, 1, 4);
238 /***************************************************************/
239 GroupButtons = new QGroupBox(this);
240 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
241 GroupButtonsLayout->setSpacing(SPACING);
242 GroupButtonsLayout->setMargin(MARGIN);
244 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
245 buttonOk->setAutoDefault(true);
246 buttonOk->setDefault(true);
247 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
248 buttonApply->setAutoDefault(true);
249 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
250 buttonCancel->setAutoDefault(true);
251 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
252 buttonHelp->setAutoDefault(true);
254 GroupButtonsLayout->addWidget(buttonOk);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addWidget(buttonApply);
257 GroupButtonsLayout->addSpacing(10);
258 GroupButtonsLayout->addStretch();
259 GroupButtonsLayout->addWidget(buttonCancel);
260 GroupButtonsLayout->addWidget(buttonHelp);
262 /***************************************************************/
263 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
264 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
265 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
267 /* Initialisations */
268 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
271 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
272 SpinBox_FX->SetStep(0.1);
273 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
274 SpinBox_FY->SetStep(0.1);
275 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
276 SpinBox_FZ->SetStep(0.1);
278 RadioButton1->setChecked(true);
280 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
282 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
284 // Costruction of the logical filter
285 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
286 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
288 QList<SUIT_SelectionFilter*> aListOfFilters;
289 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
290 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
292 myMeshOrSubMeshOrGroupFilter =
293 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
295 myHelpFileName = "scale_page.html";
299 /* signals and slots connections */
300 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
301 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
302 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
303 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
304 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
306 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
310 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
311 /* to close dialog if study change */
312 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
313 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
315 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
317 ConstructorsClicked(0);
318 SelectionIntoArgument();
319 onActionClicked(MOVE_ELEMS_BUTTON);
322 //=================================================================================
323 // function : ~SMESHGUI_ScaleDlg()
324 // purpose : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
329 myFilterDlg->setParent( 0 );
335 //=================================================================================
338 //=================================================================================
339 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
343 myEditCurrentArgument = 0;
344 LineEditElements->clear();
348 buttonOk->setEnabled(false);
349 buttonApply->setEnabled(false);
352 myMesh = SMESH::SMESH_Mesh::_nil();
355 SpinBox1_1->SetValue(0.0);
356 SpinBox1_2->SetValue(0.0);
357 SpinBox1_3->SetValue(0.0);
358 SpinBox_FX->SetValue(1.0);
359 SpinBox_FY->SetValue(1.0);
360 SpinBox_FZ->SetValue(1.0);
362 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
363 CheckBoxMesh->setChecked(false);
368 //=================================================================================
369 // function : ConstructorsClicked()
370 // purpose : Radio button management
371 //=================================================================================
372 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
374 disconnect(mySelectionMgr, 0, this, 0);
376 switch (constructorId) {
379 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
388 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
397 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
398 SMESH::SetPointRepresentation(false);
399 if (!CheckBoxMesh->isChecked())
400 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
401 aViewWindow->SetSelectionMode( CellSelection );
404 myEditCurrentArgument = (QWidget*)LineEditElements;
405 LineEditElements->setFocus();
407 if (CheckBoxMesh->isChecked())
410 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
412 QApplication::instance()->processEvents();
417 //=================================================================================
418 // function : ClickOnApply()
420 //=================================================================================
421 bool SMESHGUI_ScaleDlg::ClickOnApply()
423 if (mySMESHGUI->isActiveStudyLocked())
429 if (myNbOkElements) {
430 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
432 SMESH::long_array_var anElementsId = new SMESH::long_array;
434 anElementsId->length(aListElementsId.count());
435 for (int i = 0; i < aListElementsId.count(); i++)
436 anElementsId[i] = aListElementsId[i].toInt();
438 SMESH::PointStruct aPoint;
439 aPoint.x = SpinBox1_1->GetValue();
440 aPoint.y = SpinBox1_2->GetValue();
441 aPoint.z = SpinBox1_3->GetValue();
442 SMESH::double_array_var aScaleFact = new SMESH::double_array;
443 aScaleFact->length(3);
444 aScaleFact[0] = SpinBox_FX->GetValue();
445 if (GetConstructorId() == 0) {
446 aScaleFact[1] = SpinBox_FX->GetValue();
447 aScaleFact[2] = SpinBox_FX->GetValue();
450 aScaleFact[1] = SpinBox_FY->GetValue();
451 aScaleFact[2] = SpinBox_FZ->GetValue();
454 QStringList aParameters;
455 aParameters << SpinBox1_1->text();
456 aParameters << SpinBox1_2->text();
457 aParameters << SpinBox1_3->text();
458 aParameters << SpinBox_FX->text();
459 if (GetConstructorId() == 1) {
460 aParameters << SpinBox_FX->text();
461 aParameters << SpinBox_FX->text();
464 aParameters << SpinBox_FY->text();
465 aParameters << SpinBox_FZ->text();
468 int actionButton = ActionGroup->checkedId();
469 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
471 SUIT_OverrideCursor aWaitCursor;
472 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
473 SMESH::SMESH_IDSource_var obj;
474 if ( CheckBoxMesh->isChecked() )
475 obj = mySelectedObject;
477 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
479 switch ( actionButton ) {
481 case MOVE_ELEMS_BUTTON:
482 aMeshEditor->Scale(obj, aPoint, aScaleFact, false);
483 if( !myMesh->_is_nil())
484 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
487 case COPY_ELEMS_BUTTON:
489 SMESH::ListOfGroups_var groups =
490 aMeshEditor->ScaleMakeGroups(obj, aPoint, aScaleFact);
492 aMeshEditor->Scale(obj, aPoint, aScaleFact, true);
493 if( !myMesh->_is_nil())
494 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
497 case MAKE_MESH_BUTTON: {
498 SMESH::SMESH_Mesh_var mesh =
499 aMeshEditor->ScaleMakeMesh(obj, aPoint, aScaleFact, makeGroups,
500 LineEditNewMesh->text().toLatin1().data());
501 if (!mesh->_is_nil()) {
502 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
503 #ifdef WITHGENERICOBJ
504 // obj has been published in study. Its refcount has been incremented.
505 // It is safe to decrement its refcount
506 // so that it will be destroyed when the entry in study will be removed
517 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
518 actionButton == MAKE_MESH_BUTTON )
519 mySMESHGUI->updateObjBrowser(true); // new groups may appear
521 ConstructorsClicked(GetConstructorId());
522 mySelectedObject = SMESH::SMESH_IDSource::_nil();
523 SelectionIntoArgument();
525 SMESHGUI::Modified();
531 //=================================================================================
532 // function : ClickOnOk()
534 //=================================================================================
535 void SMESHGUI_ScaleDlg::ClickOnOk()
541 //=================================================================================
542 // function : ClickOnCancel()
544 //=================================================================================
545 void SMESHGUI_ScaleDlg::ClickOnCancel()
547 disconnect(mySelectionMgr, 0, this, 0);
548 mySelectionMgr->clearFilters();
549 //mySelectionMgr->clearSelected();
550 if (SMESH::GetCurrentVtkView()) {
551 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
552 SMESH::SetPointRepresentation(false);
554 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
555 aViewWindow->SetSelectionMode( ActorSelection );
556 mySMESHGUI->ResetState();
560 //=================================================================================
561 // function : ClickOnHelp()
563 //=================================================================================
564 void SMESHGUI_ScaleDlg::ClickOnHelp()
566 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
568 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
572 platform = "winapplication";
574 platform = "application";
576 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
577 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
578 arg(app->resourceMgr()->stringValue("ExternalBrowser",
580 arg(myHelpFileName));
584 //=======================================================================
585 // function : onTextChange()
587 //=======================================================================
588 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
590 QLineEdit* send = (QLineEdit*)sender();
593 BusyLocker lock( myBusy );
595 if (send == LineEditElements)
598 buttonOk->setEnabled(false);
599 buttonApply->setEnabled(false);
601 // hilight entered elements
602 SMDS_Mesh* aMesh = 0;
604 aMesh = myActor->GetObject()->GetMesh();
607 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
609 TColStd_MapOfInteger newIndices;
611 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
613 if (send == LineEditElements) {
614 for (int i = 0; i < aListId.count(); i++) {
615 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
617 newIndices.Add(e->GetID());
622 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
623 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
624 aViewWindow->highlight( anIO, true, true );
626 myElementsId = theNewText;
629 if (myNbOkElements) {
630 buttonOk->setEnabled(true);
631 buttonApply->setEnabled(true);
635 //=================================================================================
636 // function : SelectionIntoArgument()
637 // purpose : Called when selection as changed or other case
638 //=================================================================================
639 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
642 BusyLocker lock( myBusy );
645 QString aString = "";
647 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
648 LineEditElements->setText(aString);
650 buttonOk->setEnabled(false);
651 buttonApply->setEnabled(false);
654 if (!GroupButtons->isEnabled()) // inactive
659 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
661 int nbSel = aList.Extent();
665 Handle(SALOME_InteractiveObject) IO = aList.First();
666 myMesh = SMESH::GetMeshByIO(IO);
667 if (myMesh->_is_nil())
670 myActor = SMESH::FindActorByObject(myMesh);
672 myActor = SMESH::FindActorByEntry(IO->getEntry());
673 if (!myActor && !CheckBoxMesh->isChecked())
678 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
681 // MakeGroups is available if there are groups and "Copy"
682 if ( myMesh->NbGroups() == 0 ) {
683 MakeGroupsCheck->setChecked(false);
684 MakeGroupsCheck->setEnabled(false);
686 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
687 MakeGroupsCheck->setEnabled(true);
690 if (CheckBoxMesh->isChecked()) {
691 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
693 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
694 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
700 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
704 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
705 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
707 myElementsId += QString(" %1").arg(i);
711 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
713 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
715 // get IDs from submesh
716 SMESH::long_array_var anElementsIds = new SMESH::long_array;
717 anElementsIds = aSubMesh->GetElementsId();
718 for (int i = 0; i < anElementsIds->length(); i++) {
719 myElementsId += QString(" %1").arg(anElementsIds[i]);
721 aNbUnits = anElementsIds->length();
724 SMESH::SMESH_GroupBase_var aGroup =
725 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
726 if (aGroup->_is_nil())
729 // get IDs from smesh group
730 SMESH::long_array_var anElementsIds = new SMESH::long_array;
731 anElementsIds = aGroup->GetListOfID();
732 for (int i = 0; i < anElementsIds->length(); i++) {
733 myElementsId += QString(" %1").arg(anElementsIds[i]);
735 aNbUnits = anElementsIds->length();
739 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
740 myElementsId = aString;
745 myNbOkElements = true;
747 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
751 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
755 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
763 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
764 SpinBox1_1->SetValue(x);
765 SpinBox1_2->SetValue(y);
766 SpinBox1_3->SetValue(z);
768 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
769 SpinBox_FX->SetValue(x);
770 SpinBox_FY->SetValue(y);
771 SpinBox_FZ->SetValue(z);
775 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
776 LineEditElements->setText(aString);
777 LineEditElements->repaint();
778 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
779 LineEditElements->setEnabled(true);
784 if (myNbOkElements) {
785 buttonOk->setEnabled(true);
786 buttonApply->setEnabled(true);
790 //=================================================================================
791 // function : SetEditCurrentArgument()
793 //=================================================================================
794 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
796 QPushButton* send = (QPushButton*)sender();
798 disconnect(mySelectionMgr, 0, this, 0);
799 mySelectionMgr->clearSelected();
800 mySelectionMgr->clearFilters();
802 if (send == SelectElementsButton) {
803 myEditCurrentArgument = (QWidget*)LineEditElements;
804 SMESH::SetPointRepresentation(false);
805 if (CheckBoxMesh->isChecked()) {
806 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
807 aViewWindow->SetSelectionMode( ActorSelection );
808 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode( CellSelection );
815 else if (send == SelectButton1) {
816 myEditCurrentArgument = (QWidget*)SpinBox1_1;
817 SMESH::SetPointRepresentation(true);
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode( NodeSelection );
822 myEditCurrentArgument->setFocus();
823 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
824 SelectionIntoArgument();
827 //=================================================================================
828 // function : DeactivateActiveDialog()
830 //=================================================================================
831 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
833 if (ConstructorsBox->isEnabled()) {
834 ConstructorsBox->setEnabled(false);
835 GroupArguments->setEnabled(false);
836 GroupButtons->setEnabled(false);
837 mySMESHGUI->ResetState();
838 mySMESHGUI->SetActiveDialogBox(0);
842 //=================================================================================
843 // function : ActivateThisDialog()
845 //=================================================================================
846 void SMESHGUI_ScaleDlg::ActivateThisDialog()
848 /* Emit a signal to deactivate the active dialog */
849 mySMESHGUI->EmitSignalDeactivateDialog();
850 ConstructorsBox->setEnabled(true);
851 GroupArguments->setEnabled(true);
852 GroupButtons->setEnabled(true);
854 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
856 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
857 aViewWindow->SetSelectionMode( CellSelection );
859 SelectionIntoArgument();
862 //=================================================================================
863 // function : enterEvent()
865 //=================================================================================
866 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
868 if (!ConstructorsBox->isEnabled())
869 ActivateThisDialog();
872 //=================================================================================
873 // function : closeEvent()
875 //=================================================================================
876 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
878 /* same than click on cancel button */
882 //=======================================================================
883 //function : hideEvent
884 //purpose : caused by ESC key
885 //=======================================================================
886 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
892 //=======================================================================
893 //function : onSelectMesh
895 //=======================================================================
896 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
899 TextLabelElements->setText(tr("SMESH_NAME"));
901 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
902 myFilterBtn->setEnabled(!toSelectMesh);
904 if (myEditCurrentArgument != LineEditElements) {
905 LineEditElements->clear();
909 mySelectionMgr->clearFilters();
910 SMESH::SetPointRepresentation(false);
913 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
914 aViewWindow->SetSelectionMode( ActorSelection );
915 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
916 LineEditElements->setReadOnly(true);
917 LineEditElements->setValidator(0);
919 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
920 aViewWindow->SetSelectionMode( CellSelection );
921 LineEditElements->setReadOnly(false);
922 LineEditElements->setValidator(myIdValidator);
923 onTextChange(LineEditElements->text());
926 SelectionIntoArgument();
929 //=======================================================================
930 //function : onActionClicked
931 //purpose : slot called when an action type changed
932 //=======================================================================
934 void SMESHGUI_ScaleDlg::onActionClicked(int button)
937 case MOVE_ELEMS_BUTTON:
938 MakeGroupsCheck->setEnabled(false);
939 LineEditNewMesh->setEnabled(false);
941 case COPY_ELEMS_BUTTON:
942 LineEditNewMesh->setEnabled(false);
943 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
944 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
945 MakeGroupsCheck->setEnabled(true);
947 MakeGroupsCheck->setEnabled(false);
949 case MAKE_MESH_BUTTON:
950 LineEditNewMesh->setEnabled(true);
951 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
952 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
953 MakeGroupsCheck->setEnabled(true);
955 MakeGroupsCheck->setEnabled(false);
961 //=======================================================================
962 //function : setNewMeshName
963 //purpose : update contents of LineEditNewMesh
964 //=======================================================================
966 void SMESHGUI_ScaleDlg::setNewMeshName()
968 LineEditNewMesh->setText("");
969 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
971 if ( CheckBoxMesh->isChecked() ) {
972 name = LineEditElements->text();
975 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
976 name = meshSO->GetName().c_str();
978 if ( !name.isEmpty() )
979 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
983 //=================================================================================
984 // function : GetConstructorId()
986 //=================================================================================
987 int SMESHGUI_ScaleDlg::GetConstructorId()
989 return GroupConstructors->checkedId();
992 //=================================================================================
993 // function : keyPressEvent()
995 //=================================================================================
996 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
998 QDialog::keyPressEvent( e );
999 if ( e->isAccepted() )
1002 if ( e->key() == Qt::Key_F1 ) {
1008 //=================================================================================
1009 // function : setFilters()
1010 // purpose : SLOT. Called when "Filter" button pressed.
1011 //=================================================================================
1012 void SMESHGUI_ScaleDlg::setFilters()
1014 if(myMesh->_is_nil()) {
1015 SUIT_MessageBox::critical(this,
1017 tr("NO_MESH_SELECTED"));
1021 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1023 myFilterDlg->SetSelection();
1024 myFilterDlg->SetMesh( myMesh );
1025 myFilterDlg->SetSourceWg( LineEditElements );
1027 myFilterDlg->show();
1030 //=================================================================================
1031 // function : isValid
1033 //=================================================================================
1034 bool SMESHGUI_ScaleDlg::isValid()
1039 ok = SpinBox1_1->isValid( msg, true ) && ok;
1040 ok = SpinBox1_2->isValid( msg, true ) && ok;
1041 ok = SpinBox1_3->isValid( msg, true ) && ok;
1042 ok = SpinBox_FX->isValid( msg, true ) && ok;
1043 if (GetConstructorId() == 1) {
1044 ok = SpinBox_FY->isValid( msg, true ) && ok;
1045 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1049 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1050 if ( !msg.isEmpty() )
1052 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );