1 // Copyright (C) 2007-2015 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_page.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 (mySMESHGUI->isActiveStudyLocked())
448 if (myNbOkElements) {
449 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
451 SMESH::long_array_var anElementsId = new SMESH::long_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( ":" ).toLatin1().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( ":" ).toLatin1().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( ":" ).toLatin1().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( ":" ).toLatin1().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( ":" ).toLatin1().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( ":" ).toLatin1().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( ":" ).toLatin1().constData());
538 mesh = aMeshEditor->ScaleMakeMesh(myObjects[i], aPoint, aScaleFact, makeGroups,
539 aName.toLatin1().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( ":" ).toLatin1().constData());
547 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
548 mesh = aMeshEditor->ScaleMakeMesh( src, aPoint, aScaleFact, makeGroups,
549 LineEditNewMesh->text().toLatin1().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 // hilight entered elements
678 SMDS_Mesh* aMesh = 0;
680 aMesh = myActor->GetObject()->GetMesh();
683 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
685 TColStd_MapOfInteger 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) {
749 myObjectsNames.clear();
752 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
753 Handle(SALOME_InteractiveObject) IO = it.Value();
754 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
755 if ( aMesh->_is_nil() )
758 myActor = SMESH::FindActorByObject( aMesh );
760 myActor = SMESH::FindActorByEntry( IO->getEntry() );
761 if ( !myActor && !CheckBoxMesh->isChecked() )
764 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
765 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
766 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
767 _PTR(GenericAttribute) anAttr;
768 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
769 _PTR(AttributeName) aNameAttr( anAttr );
770 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
771 myObjectsNames << aNameAttr->Value().c_str();
778 // MakeGroups is available if there are groups and "Copy"
780 for ( int i = 0; i < myMeshes.count(); i++ )
781 aNbGroups += myMeshes[i]->NbGroups();
783 if ( aNbGroups == 0 ) {
784 MakeGroupsCheck->setChecked(false);
785 MakeGroupsCheck->setEnabled(false);
787 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
788 MakeGroupsCheck->setEnabled(true);
791 if (CheckBoxMesh->isChecked()) {
792 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
793 if (myMeshes.isEmpty())
797 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
801 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
802 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
804 myElementsId += QString(" %1").arg(i);
808 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
810 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
812 // get IDs from submesh
813 SMESH::long_array_var anElementsIds = new SMESH::long_array;
814 anElementsIds = aSubMesh->GetElementsId();
815 for (int i = 0; i < anElementsIds->length(); i++) {
816 myElementsId += QString(" %1").arg(anElementsIds[i]);
818 aNbUnits = anElementsIds->length();
821 SMESH::SMESH_GroupBase_var aGroup =
822 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
823 if (aGroup->_is_nil())
826 // get IDs from smesh group
827 SMESH::long_array_var anElementsIds = new SMESH::long_array;
828 anElementsIds = aGroup->GetListOfID();
829 for (int i = 0; i < anElementsIds->length(); i++) {
830 myElementsId += QString(" %1").arg(anElementsIds[i]);
832 aNbUnits = anElementsIds->length();
836 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
837 myElementsId = aString;
842 myNbOkElements = true;
844 Handle(SALOME_InteractiveObject) IO = aList.First();
845 if ((SMESH::GetMeshByIO(IO))->_is_nil())
848 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
850 anActor = SMESH::FindActorByEntry(IO->getEntry());
851 if (!anActor && !CheckBoxMesh->isChecked())
854 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
858 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
862 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
870 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
871 SpinBox1_1->SetValue(x);
872 SpinBox1_2->SetValue(y);
873 SpinBox1_3->SetValue(z);
875 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
876 SpinBox_FX->SetValue(x);
877 SpinBox_FY->SetValue(y);
878 SpinBox_FZ->SetValue(z);
882 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
883 LineEditElements->setText(aString);
884 LineEditElements->repaint();
885 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
886 LineEditElements->setEnabled(true);
891 if (myNbOkElements) {
892 buttonOk->setEnabled(true);
893 buttonApply->setEnabled(true);
896 onDisplaySimulation(true);
899 //=================================================================================
900 // function : SetEditCurrentArgument()
902 //=================================================================================
903 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
905 QPushButton* send = (QPushButton*)sender();
907 disconnect(mySelectionMgr, 0, this, 0);
908 mySelectionMgr->clearSelected();
909 mySelectionMgr->clearFilters();
911 if (send == SelectElementsButton) {
912 myEditCurrentArgument = (QWidget*)LineEditElements;
913 SMESH::SetPointRepresentation(false);
914 if (CheckBoxMesh->isChecked()) {
915 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
916 aViewWindow->SetSelectionMode( ActorSelection );
917 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
920 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921 aViewWindow->SetSelectionMode( CellSelection );
924 else if (send == SelectButton1) {
925 myEditCurrentArgument = (QWidget*)SpinBox1_1;
926 SMESH::SetPointRepresentation(true);
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode( NodeSelection );
931 myEditCurrentArgument->setFocus();
932 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
933 SelectionIntoArgument();
936 //=================================================================================
937 // function : DeactivateActiveDialog()
939 //=================================================================================
940 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
942 if (ConstructorsBox->isEnabled()) {
943 ConstructorsBox->setEnabled(false);
944 GroupArguments->setEnabled(false);
945 GroupButtons->setEnabled(false);
946 mySMESHGUI->ResetState();
947 mySMESHGUI->SetActiveDialogBox(0);
951 //=================================================================================
952 // function : ActivateThisDialog()
954 //=================================================================================
955 void SMESHGUI_ScaleDlg::ActivateThisDialog()
957 /* Emit a signal to deactivate the active dialog */
958 mySMESHGUI->EmitSignalDeactivateDialog();
959 ConstructorsBox->setEnabled(true);
960 GroupArguments->setEnabled(true);
961 GroupButtons->setEnabled(true);
963 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
965 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
966 aViewWindow->SetSelectionMode( CellSelection );
968 SelectionIntoArgument();
971 //=================================================================================
972 // function : enterEvent()
974 //=================================================================================
975 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
977 if (!ConstructorsBox->isEnabled()) {
978 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
979 if ( aViewWindow && !mySelector) {
980 mySelector = aViewWindow->GetSelector();
982 ActivateThisDialog();
986 //=======================================================================
987 //function : onSelectMesh
989 //=======================================================================
990 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
993 TextLabelElements->setText(tr("SMESH_NAME"));
995 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
996 myFilterBtn->setEnabled(!toSelectMesh);
998 if (myEditCurrentArgument != LineEditElements) {
999 LineEditElements->clear();
1003 mySelectionMgr->clearFilters();
1004 SMESH::SetPointRepresentation(false);
1007 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1008 aViewWindow->SetSelectionMode( ActorSelection );
1009 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
1010 LineEditElements->setReadOnly(true);
1011 LineEditElements->setValidator(0);
1013 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1014 aViewWindow->SetSelectionMode( CellSelection );
1015 LineEditElements->setReadOnly(false);
1016 LineEditElements->setValidator(myIdValidator);
1017 onTextChange(LineEditElements->text());
1021 SelectionIntoArgument();
1024 //=======================================================================
1025 //function : onActionClicked
1026 //purpose : slot called when an action type changed
1027 //=======================================================================
1029 void SMESHGUI_ScaleDlg::onActionClicked(int button)
1032 for ( int i = 0; i < myMeshes.count(); i++ )
1033 aNbGroups += myMeshes[i]->NbGroups();
1036 case MOVE_ELEMS_BUTTON:
1037 MakeGroupsCheck->setEnabled(false);
1038 LineEditNewMesh->setEnabled(false);
1040 case COPY_ELEMS_BUTTON:
1041 LineEditNewMesh->setEnabled(false);
1042 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1043 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1045 case MAKE_MESH_BUTTON:
1046 LineEditNewMesh->setEnabled(true);
1047 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1048 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1052 toDisplaySimulation();
1055 //=======================================================================
1056 //function : setNewMeshName
1057 //purpose : update contents of LineEditNewMesh
1058 //=======================================================================
1060 void SMESHGUI_ScaleDlg::setNewMeshName()
1062 LineEditNewMesh->setText("");
1063 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1065 if ( CheckBoxMesh->isChecked() ) {
1066 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1069 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1070 name = meshSO->GetName().c_str();
1072 if ( !name.isEmpty() )
1073 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1077 //=================================================================================
1078 // function : GetConstructorId()
1080 //=================================================================================
1081 int SMESHGUI_ScaleDlg::GetConstructorId()
1083 return GroupConstructors->checkedId();
1086 //=================================================================================
1087 // function : keyPressEvent()
1089 //=================================================================================
1090 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1092 QDialog::keyPressEvent( e );
1093 if ( e->isAccepted() )
1096 if ( e->key() == Qt::Key_F1 ) {
1102 //=================================================================================
1103 // function : setFilters()
1104 // purpose : SLOT. Called when "Filter" button pressed.
1105 //=================================================================================
1106 void SMESHGUI_ScaleDlg::setFilters()
1108 if(myMeshes.isEmpty()) {
1109 SUIT_MessageBox::critical(this,
1111 tr("NO_MESH_SELECTED"));
1115 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1118 if ( myMeshes[0]->NbEdges() ) types << SMESH::EDGE;
1119 if ( myMeshes[0]->NbFaces() ) types << SMESH::FACE;
1120 if ( myMeshes[0]->NbVolumes() ) types << SMESH::VOLUME;
1121 if ( myMeshes[0]->NbBalls() ) types << SMESH::BALL;
1122 if ( myMeshes[0]->Nb0DElements()) types << SMESH::ELEM0D;
1123 if ( types.count() > 1 ) types << SMESH::ALL;
1125 myFilterDlg->Init( types );
1126 myFilterDlg->SetSelection();
1127 myFilterDlg->SetMesh( myMeshes[0] );
1128 myFilterDlg->SetSourceWg( LineEditElements );
1130 myFilterDlg->show();
1133 //=================================================================================
1134 // function : isValid
1136 //=================================================================================
1137 bool SMESHGUI_ScaleDlg::isValid()
1142 ok = SpinBox1_1->isValid( msg, true ) && ok;
1143 ok = SpinBox1_2->isValid( msg, true ) && ok;
1144 ok = SpinBox1_3->isValid( msg, true ) && ok;
1145 ok = SpinBox_FX->isValid( msg, true ) && ok;
1146 if (GetConstructorId() == 1) {
1147 ok = SpinBox_FY->isValid( msg, true ) && ok;
1148 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1152 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1153 if ( !msg.isEmpty() )
1155 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1161 //=================================================================================
1162 // function : onDisplaySimulation
1163 // purpose : Show/Hide preview
1164 //=================================================================================
1165 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1166 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1167 if ( myNbOkElements && isValid() ) {
1168 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1170 SMESH::long_array_var anElementsId = new SMESH::long_array;
1172 anElementsId->length(aListElementsId.count());
1173 for (int i = 0; i < aListElementsId.count(); i++)
1174 anElementsId[i] = aListElementsId[i].toInt();
1176 SMESH::PointStruct aPoint;
1177 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1178 getScale(aPoint, aScaleFact);
1181 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1182 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1183 SUIT_OverrideCursor aWaitCursor;
1184 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1186 if(CheckBoxMesh->isChecked())
1187 for ( int i = 0; i < myObjects.count(); i++ ) {
1188 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1189 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, copy);
1190 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1193 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1194 SMESH::IDSource_wrap src = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1195 aMeshEditor->Scale( src, aPoint, aScaleFact, copy);
1196 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1198 setSimulationPreview(aMeshPreviewStruct);
1210 //=================================================================================
1211 // function : getScale
1212 // purpose : get scale parameters
1213 //=================================================================================
1214 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1215 thePoint.x = SpinBox1_1->GetValue();
1216 thePoint.y = SpinBox1_2->GetValue();
1217 thePoint.z = SpinBox1_3->GetValue();
1219 theScaleFact->length(3);
1220 theScaleFact[0] = SpinBox_FX->GetValue();
1221 if (GetConstructorId() == 0) {
1222 theScaleFact[1] = SpinBox_FX->GetValue();
1223 theScaleFact[2] = SpinBox_FX->GetValue();
1226 theScaleFact[1] = SpinBox_FY->GetValue();
1227 theScaleFact[2] = SpinBox_FZ->GetValue();