1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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 // File : SMESHGUI_ScaleDlg.cxx
20 // Author : Michael ZORIN, Open CASCADE S.A.S.
23 #include "SMESHGUI_ScaleDlg.h"
26 #include "SMESHGUI_SpinBox.h"
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESHGUI_MeshUtils.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_MeshEditPreview.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.hxx>
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 SMESHGUI_MultiPreviewDlg( theModule ),
108 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
111 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
112 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
113 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
116 setAttribute(Qt::WA_DeleteOnClose, true);
117 setWindowTitle(tr("SMESH_SCALE_TITLE"));
118 setSizeGripEnabled(true);
120 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
121 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
122 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
124 /***************************************************************/
125 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
126 GroupConstructors = new QButtonGroup(this);
127 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
128 ConstructorsBoxLayout->setSpacing(SPACING);
129 ConstructorsBoxLayout->setMargin(MARGIN);
131 RadioButton1= new QRadioButton(ConstructorsBox);
132 RadioButton1->setIcon(image0);
133 RadioButton2= new QRadioButton(ConstructorsBox);
134 RadioButton2->setIcon(image1);
136 ConstructorsBoxLayout->addWidget(RadioButton1);
137 ConstructorsBoxLayout->addWidget(RadioButton2);
138 GroupConstructors->addButton(RadioButton1, 0);
139 GroupConstructors->addButton(RadioButton2, 1);
141 /***************************************************************/
142 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
143 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
144 GroupArgumentsLayout->setSpacing(SPACING);
145 GroupArgumentsLayout->setMargin(MARGIN);
147 myIdValidator = new SMESHGUI_IdValidator(this);
149 // Controls for elements selection
150 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
151 SelectElementsButton = new QPushButton(GroupArguments);
152 SelectElementsButton->setIcon(image2);
153 LineEditElements = new QLineEdit(GroupArguments);
154 LineEditElements->setValidator(myIdValidator);
155 LineEditElements->setMaxLength(-1);
156 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
157 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
159 // Control for the whole mesh selection
160 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
162 // Controls for vector and points selection
163 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
164 SelectButton1 = new QPushButton(GroupArguments);
165 SelectButton1->setIcon(image2);
167 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
168 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
169 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
170 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
171 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
172 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
175 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
178 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
181 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
184 // switch of action type
185 ActionBox = new QGroupBox(GroupArguments);
186 ActionGroup = new QButtonGroup(GroupArguments);
187 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
188 ActionBoxLayout->addSpacing(SPACING);
189 ActionBoxLayout->setMargin(MARGIN);
191 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
192 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
193 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
195 ActionBoxLayout->addWidget(aMoveElements);
196 ActionBoxLayout->addWidget(aCopyElements);
197 ActionBoxLayout->addWidget(aCreateMesh);
198 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
199 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
200 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
202 // CheckBox for groups generation
203 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
204 MakeGroupsCheck->setChecked(false);
206 // Name of a mesh to create
207 LineEditNewMesh = new QLineEdit(GroupArguments);
210 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
213 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
214 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
216 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
217 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
218 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
219 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
220 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
221 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
222 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
223 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
224 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
225 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
226 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
227 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
228 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
229 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
230 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
231 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
232 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 5, 1, 4);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 9, 5, 1, 4);
235 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 10, 0);
237 /***************************************************************/
238 GroupButtons = new QGroupBox(this);
239 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
240 GroupButtonsLayout->setSpacing(SPACING);
241 GroupButtonsLayout->setMargin(MARGIN);
243 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
244 buttonOk->setAutoDefault(true);
245 buttonOk->setDefault(true);
246 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
247 buttonApply->setAutoDefault(true);
248 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
249 buttonCancel->setAutoDefault(true);
250 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
251 buttonHelp->setAutoDefault(true);
253 GroupButtonsLayout->addWidget(buttonOk);
254 GroupButtonsLayout->addSpacing(10);
255 GroupButtonsLayout->addWidget(buttonApply);
256 GroupButtonsLayout->addSpacing(10);
257 GroupButtonsLayout->addStretch();
258 GroupButtonsLayout->addWidget(buttonCancel);
259 GroupButtonsLayout->addWidget(buttonHelp);
261 /***************************************************************/
262 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
263 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
264 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
266 /* Initialisations */
267 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
270 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
271 SpinBox_FX->SetStep(0.1);
272 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
273 SpinBox_FY->SetStep(0.1);
274 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
275 SpinBox_FZ->SetStep(0.1);
277 RadioButton1->setChecked(true);
279 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
281 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
283 // Costruction of the logical filter
284 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
285 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
287 QList<SUIT_SelectionFilter*> aListOfFilters;
288 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
289 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
291 myMeshOrSubMeshOrGroupFilter =
292 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
294 myHelpFileName = "scale.html";
298 /* signals and slots connections */
299 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
300 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
301 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
302 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
303 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
305 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
306 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
308 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
309 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
310 /* to close dialog if study change */
311 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(reject()));
312 connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
313 connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
315 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
316 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
317 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
319 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
320 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 //To Connect preview check box
328 connectPreviewControl();
330 ConstructorsClicked(0);
331 SelectionIntoArgument();
332 onActionClicked(MOVE_ELEMS_BUTTON);
335 //=================================================================================
336 // function : ~SMESHGUI_ScaleDlg()
337 // purpose : Destroys the object and frees any allocated resources
338 //=================================================================================
339 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
342 myFilterDlg->setParent( 0 );
348 //=================================================================================
351 //=================================================================================
352 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
356 myObjectsNames.clear();
359 myEditCurrentArgument = 0;
360 LineEditElements->clear();
364 buttonOk->setEnabled(false);
365 buttonApply->setEnabled(false);
370 SpinBox1_1->SetValue(0.0);
371 SpinBox1_2->SetValue(0.0);
372 SpinBox1_3->SetValue(0.0);
373 SpinBox_FX->SetValue(1.0);
374 SpinBox_FY->SetValue(1.0);
375 SpinBox_FZ->SetValue(1.0);
376 myPreviewCheckBox->setChecked(false);
377 onDisplaySimulation(false);
379 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
380 CheckBoxMesh->setChecked(false);
385 //=================================================================================
386 // function : ConstructorsClicked()
387 // purpose : Radio button management
388 //=================================================================================
389 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
391 disconnect(mySelectionMgr, 0, this, 0);
393 switch (constructorId) {
396 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
405 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
414 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
415 SMESH::SetPointRepresentation(false);
416 if (!CheckBoxMesh->isChecked())
417 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
418 aViewWindow->SetSelectionMode( CellSelection );
421 myEditCurrentArgument = (QWidget*)LineEditElements;
422 LineEditElements->setFocus();
424 if (CheckBoxMesh->isChecked())
427 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
429 QApplication::instance()->processEvents();
430 myEditCurrentArgument->hide();
431 myEditCurrentArgument->show();
436 //=================================================================================
437 // function : ClickOnApply()
439 //=================================================================================
440 bool SMESHGUI_ScaleDlg::ClickOnApply()
442 if (SMESHGUI::isStudyLocked())
448 if (myNbOkElements) {
449 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
451 SMESH::smIdType_array_var anElementsId = new SMESH::smIdType_array;
453 anElementsId->length(aListElementsId.count());
454 for (int i = 0; i < aListElementsId.count(); i++)
455 anElementsId[i] = aListElementsId[i].toInt();
457 SMESH::PointStruct aPoint;
458 SMESH::double_array_var aScaleFact = new SMESH::double_array;
459 getScale(aPoint, aScaleFact);
461 QStringList aParameters;
462 aParameters << SpinBox1_1->text();
463 aParameters << SpinBox1_2->text();
464 aParameters << SpinBox1_3->text();
465 aParameters << SpinBox_FX->text();
466 if (GetConstructorId() == 1) {
467 aParameters << SpinBox_FX->text();
468 aParameters << SpinBox_FX->text();
471 aParameters << SpinBox_FY->text();
472 aParameters << SpinBox_FZ->text();
475 int actionButton = ActionGroup->checkedId();
476 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
477 QStringList anEntryList;
479 SUIT_OverrideCursor aWaitCursor;
481 switch ( actionButton ) {
483 case MOVE_ELEMS_BUTTON:
484 if ( CheckBoxMesh->isChecked() )
485 for ( int i = 0; i < myObjects.count(); i++ ) {
486 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
487 myMeshes[i]->SetParameters( aParameters.join( ":" ).toUtf8().constData() );
488 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, false);
491 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
492 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
493 myMeshes[0]->SetParameters( aParameters.join( ":" ).toUtf8().constData() );
494 aMeshEditor->Scale( src, aPoint, aScaleFact, false);
498 case COPY_ELEMS_BUTTON:
500 SMESH::ListOfGroups_var groups;
501 if(CheckBoxMesh->isChecked())
502 for ( int i = 0; i < myObjects.count(); i++ ) {
503 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
504 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
505 groups = aMeshEditor->ScaleMakeGroups(myObjects[i], aPoint, aScaleFact);
508 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
509 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
510 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
511 groups = aMeshEditor->ScaleMakeGroups( src, aPoint, aScaleFact);
515 if(CheckBoxMesh->isChecked()) {
516 for ( int i = 0; i < myObjects.count(); i++ ) {
517 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
518 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
519 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, true);
523 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
524 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
525 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
526 aMeshEditor->Scale( src, aPoint, aScaleFact, true);
531 case MAKE_MESH_BUTTON: {
532 SMESH::SMESH_Mesh_var mesh;
533 if (CheckBoxMesh->isChecked()) {
534 for ( int i = 0; i < myObjects.count(); i++ ) {
535 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
536 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
537 myMeshes[i]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
538 mesh = aMeshEditor->ScaleMakeMesh(myObjects[i], aPoint, aScaleFact, makeGroups,
539 aName.toUtf8().data());
540 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
541 anEntryList.append( aSObject->GetID().c_str() );
545 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
546 myMeshes[0]->SetParameters(aParameters.join( ":" ).toUtf8().constData());
547 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
548 mesh = aMeshEditor->ScaleMakeMesh( src, aPoint, aScaleFact, makeGroups,
549 LineEditNewMesh->text().toUtf8().data());
550 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
551 anEntryList.append( aSObject->GetID().c_str() );
559 for ( int i = 0; i < myObjects.count(); i++ ) {
560 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
561 if ( actor ) SMESH::Update( actor->getIO(), true );
564 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
565 actionButton == MAKE_MESH_BUTTON ) {
566 mySMESHGUI->updateObjBrowser(true); // new groups may appear
567 if( LightApp_Application* anApp =
568 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
569 anApp->browseObjects( anEntryList, isApplyAndClose() );
572 ConstructorsClicked(GetConstructorId());
573 SelectionIntoArgument();
575 SMESHGUI::Modified();
581 //=================================================================================
582 // function : ClickOnOk()
584 //=================================================================================
585 void SMESHGUI_ScaleDlg::ClickOnOk()
587 setIsApplyAndClose( true );
592 //=================================================================================
593 // function : reject()
595 //=================================================================================
596 void SMESHGUI_ScaleDlg::reject()
598 disconnect(mySelectionMgr, 0, this, 0);
599 mySelectionMgr->clearFilters();
600 //mySelectionMgr->clearSelected();
601 if (SMESH::GetCurrentVtkView()) {
602 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
603 SMESH::SetPointRepresentation(false);
605 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
606 aViewWindow->SetSelectionMode( ActorSelection );
607 mySMESHGUI->ResetState();
611 //=================================================================================
612 // function : onOpenView()
614 //=================================================================================
615 void SMESHGUI_ScaleDlg::onOpenView()
618 SMESH::SetPointRepresentation(false);
621 mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
622 ActivateThisDialog();
626 //=================================================================================
627 // function : onCloseView()
629 //=================================================================================
630 void SMESHGUI_ScaleDlg::onCloseView()
632 DeactivateActiveDialog();
636 //=================================================================================
637 // function : ClickOnHelp()
639 //=================================================================================
640 void SMESHGUI_ScaleDlg::ClickOnHelp()
642 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
644 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
648 platform = "winapplication";
650 platform = "application";
652 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
653 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
654 arg(app->resourceMgr()->stringValue("ExternalBrowser",
656 arg(myHelpFileName));
660 //=======================================================================
661 // function : onTextChange()
663 //=======================================================================
664 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
666 QLineEdit* send = (QLineEdit*)sender();
669 BusyLocker lock( myBusy );
671 if (send == LineEditElements)
674 buttonOk->setEnabled(false);
675 buttonApply->setEnabled(false);
677 // highlight entered elements
678 SMDS_Mesh* aMesh = 0;
680 aMesh = myActor->GetObject()->GetMesh();
683 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
685 SVTK_TVtkIDsMap newIndices;
687 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
689 if (send == LineEditElements) {
690 for (int i = 0; i < aListId.count(); i++) {
691 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
693 newIndices.Add(e->GetID());
698 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
699 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
700 aViewWindow->highlight( anIO, true, true );
702 myElementsId = theNewText;
705 if (myNbOkElements) {
706 buttonOk->setEnabled(true);
707 buttonApply->setEnabled(true);
711 //=================================================================================
712 // function : SelectionIntoArgument()
713 // purpose : Called when selection as changed or other case
714 //=================================================================================
715 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
718 if (myFilterDlg && myFilterDlg->isVisible()) return; // filter dlg active
720 BusyLocker lock( myBusy );
723 QString aString = "";
724 onDisplaySimulation(false);
726 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
727 LineEditElements->setText(aString);
729 buttonOk->setEnabled(false);
730 buttonApply->setEnabled(false);
733 if (!GroupButtons->isEnabled()) // inactive
738 mySelectionMgr->selectedObjects(aList);
740 int nbSel = aList.Extent();
746 if (myEditCurrentArgument == (QWidget*)LineEditElements)
750 myObjectsNames.clear();
753 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() )
755 Handle(SALOME_InteractiveObject) IO = it.Value();
756 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
757 if ( aMesh->_is_nil() )
760 myActor = SMESH::FindActorByObject( aMesh );
762 myActor = SMESH::FindActorByEntry( IO->getEntry() );
763 // if ( !myActor && !CheckBoxMesh->isChecked() ) -- elems can be selected by Filter
766 SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
767 if ( _PTR(SObject) obj = SMESH::FindSObject( idSrc ))
769 std::string name = obj->GetName();
773 myObjectsNames << name.c_str();
779 // MakeGroups is available if there are groups and "Copy"
781 for ( int i = 0; i < myMeshes.count(); i++ )
782 aNbGroups += myMeshes[i]->NbGroups();
784 if ( aNbGroups == 0 ) {
785 MakeGroupsCheck->setChecked(false);
786 MakeGroupsCheck->setEnabled(false);
788 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
789 MakeGroupsCheck->setEnabled(true);
792 if (CheckBoxMesh->isChecked()) {
793 if (myMeshes.isEmpty())
795 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
798 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
799 myElementsId = aString;
804 myNbOkElements = true;
807 else // set coordinates by a picked node
809 Handle(SALOME_InteractiveObject) IO = aList.First();
811 SMESH_Actor* anActor = SMESH::FindActorByEntry( IO->getEntry() );
815 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
819 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
823 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
831 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
832 SpinBox1_1->SetValue(x);
833 SpinBox1_2->SetValue(y);
834 SpinBox1_3->SetValue(z);
836 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
837 SpinBox_FX->SetValue(x);
838 SpinBox_FY->SetValue(y);
839 SpinBox_FZ->SetValue(z);
843 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
844 LineEditElements->setText(aString);
845 LineEditElements->repaint();
846 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
847 LineEditElements->setEnabled(true);
852 if (myNbOkElements) {
853 buttonOk->setEnabled(true);
854 buttonApply->setEnabled(true);
857 onDisplaySimulation(true);
860 //=================================================================================
861 // function : SetEditCurrentArgument()
863 //=================================================================================
864 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
866 QPushButton* send = (QPushButton*)sender();
868 disconnect(mySelectionMgr, 0, this, 0);
869 mySelectionMgr->clearSelected();
870 mySelectionMgr->clearFilters();
872 if (send == SelectElementsButton) {
873 myEditCurrentArgument = (QWidget*)LineEditElements;
874 SMESH::SetPointRepresentation(false);
875 if (CheckBoxMesh->isChecked()) {
876 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
877 aViewWindow->SetSelectionMode( ActorSelection );
878 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
881 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
882 aViewWindow->SetSelectionMode( CellSelection );
885 else if (send == SelectButton1) {
886 myEditCurrentArgument = (QWidget*)SpinBox1_1;
887 SMESH::SetPointRepresentation(true);
888 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
889 aViewWindow->SetSelectionMode( NodeSelection );
892 myEditCurrentArgument->setFocus();
893 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
894 SelectionIntoArgument();
897 //=================================================================================
898 // function : DeactivateActiveDialog()
900 //=================================================================================
901 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
903 if (ConstructorsBox->isEnabled()) {
904 ConstructorsBox->setEnabled(false);
905 GroupArguments->setEnabled(false);
906 GroupButtons->setEnabled(false);
907 mySMESHGUI->ResetState();
908 mySMESHGUI->SetActiveDialogBox(0);
912 //=================================================================================
913 // function : ActivateThisDialog()
915 //=================================================================================
916 void SMESHGUI_ScaleDlg::ActivateThisDialog()
918 /* Emit a signal to deactivate the active dialog */
919 mySMESHGUI->EmitSignalDeactivateDialog();
920 ConstructorsBox->setEnabled(true);
921 GroupArguments->setEnabled(true);
922 GroupButtons->setEnabled(true);
924 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
926 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
927 aViewWindow->SetSelectionMode( CellSelection );
929 SelectionIntoArgument();
932 //=================================================================================
933 // function : enterEvent()
935 //=================================================================================
936 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
938 if (!ConstructorsBox->isEnabled()) {
939 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
940 if ( aViewWindow && !mySelector) {
941 mySelector = aViewWindow->GetSelector();
943 ActivateThisDialog();
947 //=======================================================================
948 //function : onSelectMesh
950 //=======================================================================
951 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
954 TextLabelElements->setText(tr("SMESH_NAME"));
956 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
957 myFilterBtn->setEnabled(!toSelectMesh);
959 if (myEditCurrentArgument != LineEditElements) {
960 LineEditElements->clear();
964 mySelectionMgr->clearFilters();
965 SMESH::SetPointRepresentation(false);
968 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
969 aViewWindow->SetSelectionMode( ActorSelection );
970 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
971 LineEditElements->setReadOnly(true);
972 LineEditElements->setValidator(0);
974 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
975 aViewWindow->SetSelectionMode( CellSelection );
976 LineEditElements->setReadOnly(false);
977 LineEditElements->setValidator(myIdValidator);
978 onTextChange(LineEditElements->text());
982 SelectionIntoArgument();
985 //=======================================================================
986 //function : onActionClicked
987 //purpose : slot called when an action type changed
988 //=======================================================================
990 void SMESHGUI_ScaleDlg::onActionClicked(int button)
993 for ( int i = 0; i < myMeshes.count(); i++ )
994 aNbGroups += myMeshes[i]->NbGroups();
997 case MOVE_ELEMS_BUTTON:
998 MakeGroupsCheck->setEnabled(false);
999 LineEditNewMesh->setEnabled(false);
1001 case COPY_ELEMS_BUTTON:
1002 LineEditNewMesh->setEnabled(false);
1003 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1004 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1006 case MAKE_MESH_BUTTON:
1007 LineEditNewMesh->setEnabled(true);
1008 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1009 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1013 toDisplaySimulation();
1016 //=======================================================================
1017 //function : setNewMeshName
1018 //purpose : update contents of LineEditNewMesh
1019 //=======================================================================
1021 void SMESHGUI_ScaleDlg::setNewMeshName()
1023 LineEditNewMesh->setText("");
1024 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1026 if ( CheckBoxMesh->isChecked() ) {
1027 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1030 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1031 name = meshSO->GetName().c_str();
1033 if ( !name.isEmpty() )
1034 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1038 //=================================================================================
1039 // function : GetConstructorId()
1041 //=================================================================================
1042 int SMESHGUI_ScaleDlg::GetConstructorId()
1044 return GroupConstructors->checkedId();
1047 //=================================================================================
1048 // function : keyPressEvent()
1050 //=================================================================================
1051 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1053 QDialog::keyPressEvent( e );
1054 if ( e->isAccepted() )
1057 if ( e->key() == Qt::Key_F1 ) {
1063 //=================================================================================
1064 // function : setFilters()
1065 // purpose : SLOT. Called when "Filter" button pressed.
1066 //=================================================================================
1067 void SMESHGUI_ScaleDlg::setFilters()
1069 if ( myMeshes.isEmpty() ) {
1070 SUIT_MessageBox::critical(this, tr("SMESH_ERROR"), tr("NO_MESH_SELECTED"));
1073 if ( !myFilterDlg ) {
1074 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1075 connect(myFilterDlg, SIGNAL(Accepted()), SLOT(onFilterAccepted()));
1079 if ( myMeshes[0]->NbEdges() ) types << SMESH::EDGE;
1080 if ( myMeshes[0]->NbFaces() ) types << SMESH::FACE;
1081 if ( myMeshes[0]->NbVolumes() ) types << SMESH::VOLUME;
1082 if ( myMeshes[0]->NbBalls() ) types << SMESH::BALL;
1083 if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1084 if ( types.count() > 1 ) types << SMESH::ALL;
1086 myFilterDlg->Init( types );
1087 myFilterDlg->SetSelection();
1088 myFilterDlg->SetMesh( myMeshes[0] );
1089 myFilterDlg->SetSourceWg( LineEditElements );
1091 myFilterDlg->show();
1094 //=======================================================================
1095 // name : onFilterAccepted()
1096 // Purpose : SLOT. Called when Filter dlg closed with OK button.
1097 // Activate [Apply] if no Actor is available
1098 //=======================================================================
1099 void SMESHGUI_ScaleDlg::onFilterAccepted()
1101 if ( myMeshes.length() > 0 && !buttonOk->isEnabled() )
1103 myElementsId = LineEditElements->text();
1104 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1105 myNbOkElements = aListElementsId.count();
1106 buttonOk->setEnabled ( myNbOkElements );
1107 buttonApply->setEnabled( myNbOkElements );
1111 //=================================================================================
1112 // function : isValid
1114 //=================================================================================
1115 bool SMESHGUI_ScaleDlg::isValid()
1120 ok = SpinBox1_1->isValid( msg, true ) && ok;
1121 ok = SpinBox1_2->isValid( msg, true ) && ok;
1122 ok = SpinBox1_3->isValid( msg, true ) && ok;
1123 ok = SpinBox_FX->isValid( msg, true ) && ok;
1124 if (GetConstructorId() == 1) {
1125 ok = SpinBox_FY->isValid( msg, true ) && ok;
1126 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1130 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1131 if ( !msg.isEmpty() )
1133 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1139 //=================================================================================
1140 // function : onDisplaySimulation
1141 // purpose : Show/Hide preview
1142 //=================================================================================
1143 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1144 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1145 if ( myNbOkElements && isValid() ) {
1146 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1148 SMESH::smIdType_array_var anElementsId = new SMESH::smIdType_array;
1150 anElementsId->length(aListElementsId.count());
1151 for (int i = 0; i < aListElementsId.count(); i++)
1152 anElementsId[i] = aListElementsId[i].toInt();
1154 SMESH::PointStruct aPoint;
1155 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1156 getScale(aPoint, aScaleFact);
1159 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1160 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1161 SUIT_OverrideCursor aWaitCursor;
1162 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1164 if(CheckBoxMesh->isChecked())
1165 for ( int i = 0; i < myObjects.count(); i++ ) {
1166 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1167 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, copy);
1168 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1171 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1172 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1173 aMeshEditor->Scale( src, aPoint, aScaleFact, copy);
1174 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1176 setSimulationPreview(aMeshPreviewStruct);
1188 //=================================================================================
1189 // function : getScale
1190 // purpose : get scale parameters
1191 //=================================================================================
1192 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1193 thePoint.x = SpinBox1_1->GetValue();
1194 thePoint.y = SpinBox1_2->GetValue();
1195 thePoint.z = SpinBox1_3->GetValue();
1197 theScaleFact->length(3);
1198 theScaleFact[0] = SpinBox_FX->GetValue();
1199 if (GetConstructorId() == 0) {
1200 theScaleFact[1] = SpinBox_FX->GetValue();
1201 theScaleFact[2] = SpinBox_FX->GetValue();
1204 theScaleFact[1] = SpinBox_FY->GetValue();
1205 theScaleFact[2] = SpinBox_FZ->GetValue();