1 // Copyright (C) 2007-2013 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 // 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>
52 #include <SALOME_ListIteratorOfListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient.hxx>
56 #include <SALOMEDSClient_SObject.hxx>
59 #include <TColStd_MapOfInteger.hxx>
62 #include <QApplication>
63 #include <QButtonGroup>
67 #include <QPushButton>
68 #include <QRadioButton>
70 #include <QHBoxLayout>
71 #include <QVBoxLayout>
72 #include <QGridLayout>
77 #include <SALOMEconfig.h>
78 #include CORBA_SERVER_HEADER(SMESH_Group)
79 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
81 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
85 \brief Simple 'busy state' flag locker.
92 //! Constructor. Sets passed boolean flag to \c true.
93 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
94 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
95 ~BusyLocker() { myBusy = false; }
97 bool& myBusy; //! External 'busy state' boolean flag
103 //To disable automatic genericobj management, the following line should be commented.
104 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
105 #define WITHGENERICOBJ
107 //=================================================================================
108 // class : SMESHGUI_ScaleDlg()
110 //=================================================================================
111 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule ) :
112 SMESHGUI_MultiPreviewDlg( theModule ),
113 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
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 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
218 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
219 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
220 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
221 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
222 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
223 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
224 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
225 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
226 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
227 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
228 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
229 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
230 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
231 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
232 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
233 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
234 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
235 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
236 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
237 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
238 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 5, 1, 4);
239 GroupArgumentsLayout->addWidget(LineEditNewMesh, 9, 5, 1, 4);
240 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 10, 0);
242 /***************************************************************/
243 GroupButtons = new QGroupBox(this);
244 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
245 GroupButtonsLayout->setSpacing(SPACING);
246 GroupButtonsLayout->setMargin(MARGIN);
248 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
249 buttonOk->setAutoDefault(true);
250 buttonOk->setDefault(true);
251 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
252 buttonApply->setAutoDefault(true);
253 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
254 buttonCancel->setAutoDefault(true);
255 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
256 buttonHelp->setAutoDefault(true);
258 GroupButtonsLayout->addWidget(buttonOk);
259 GroupButtonsLayout->addSpacing(10);
260 GroupButtonsLayout->addWidget(buttonApply);
261 GroupButtonsLayout->addSpacing(10);
262 GroupButtonsLayout->addStretch();
263 GroupButtonsLayout->addWidget(buttonCancel);
264 GroupButtonsLayout->addWidget(buttonHelp);
266 /***************************************************************/
267 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
268 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
269 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
271 /* Initialisations */
272 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
275 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
276 SpinBox_FX->SetStep(0.1);
277 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
278 SpinBox_FY->SetStep(0.1);
279 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
280 SpinBox_FZ->SetStep(0.1);
282 RadioButton1->setChecked(true);
284 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
286 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
288 // Costruction of the logical filter
289 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (SMESH::MESHorSUBMESH);
290 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::GROUP);
292 QList<SUIT_SelectionFilter*> aListOfFilters;
293 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
294 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
296 myMeshOrSubMeshOrGroupFilter =
297 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
299 myHelpFileName = "scale_page.html";
303 /* signals and slots connections */
304 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
305 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
306 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
307 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
308 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
310 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
314 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
315 /* to close dialog if study change */
316 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(reject()));
317 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
318 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
319 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
321 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
323 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
327 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
329 //To Connect preview check box
330 connectPreviewControl();
332 ConstructorsClicked(0);
333 SelectionIntoArgument();
334 onActionClicked(MOVE_ELEMS_BUTTON);
337 //=================================================================================
338 // function : ~SMESHGUI_ScaleDlg()
339 // purpose : Destroys the object and frees any allocated resources
340 //=================================================================================
341 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
344 myFilterDlg->setParent( 0 );
350 //=================================================================================
353 //=================================================================================
354 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
358 myObjectsNames.clear();
361 myEditCurrentArgument = 0;
362 LineEditElements->clear();
366 buttonOk->setEnabled(false);
367 buttonApply->setEnabled(false);
372 SpinBox1_1->SetValue(0.0);
373 SpinBox1_2->SetValue(0.0);
374 SpinBox1_3->SetValue(0.0);
375 SpinBox_FX->SetValue(1.0);
376 SpinBox_FY->SetValue(1.0);
377 SpinBox_FZ->SetValue(1.0);
378 myPreviewCheckBox->setChecked(false);
379 onDisplaySimulation(false);
381 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
382 CheckBoxMesh->setChecked(false);
387 //=================================================================================
388 // function : ConstructorsClicked()
389 // purpose : Radio button management
390 //=================================================================================
391 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
393 disconnect(mySelectionMgr, 0, this, 0);
395 switch (constructorId) {
398 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
407 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
416 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
417 SMESH::SetPointRepresentation(false);
418 if (!CheckBoxMesh->isChecked())
419 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
420 aViewWindow->SetSelectionMode( CellSelection );
423 myEditCurrentArgument = (QWidget*)LineEditElements;
424 LineEditElements->setFocus();
426 if (CheckBoxMesh->isChecked())
429 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
431 QApplication::instance()->processEvents();
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 myMeshes[0]->SetParameters( aParameters.join( ":" ).toLatin1().constData() );
493 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, false);
497 case COPY_ELEMS_BUTTON:
499 SMESH::ListOfGroups_var groups;
500 if(CheckBoxMesh->isChecked())
501 for ( int i = 0; i < myObjects.count(); i++ ) {
502 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
503 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
504 groups = aMeshEditor->ScaleMakeGroups(myObjects[i], aPoint, aScaleFact);
507 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
508 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
509 groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact);
513 if(CheckBoxMesh->isChecked()) {
514 for ( int i = 0; i < myObjects.count(); i++ ) {
515 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
516 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
517 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, true);
521 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
522 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
523 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, true);
528 case MAKE_MESH_BUTTON: {
529 SMESH::SMESH_Mesh_var mesh;
530 if (CheckBoxMesh->isChecked()) {
531 for ( int i = 0; i < myObjects.count(); i++ ) {
532 QString aName = SMESH::UniqueMeshName( LineEditNewMesh->text().replace( "*", myObjectsNames[i] ) );
533 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditor();
534 myMeshes[i]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
535 mesh = aMeshEditor->ScaleMakeMesh(myObjects[i], aPoint, aScaleFact, makeGroups,
536 aName.toLatin1().data());
537 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
538 anEntryList.append( aSObject->GetID().c_str() );
539 #ifdef WITHGENERICOBJ
540 // obj has been published in study. Its refcount has been incremented.
541 // It is safe to decrement its refcount
542 // so that it will be destroyed when the entry in study will be removed
548 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditor();
549 myMeshes[0]->SetParameters(aParameters.join( ":" ).toLatin1().constData());
550 mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, makeGroups,
551 LineEditNewMesh->text().toLatin1().data());
552 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
553 anEntryList.append( aSObject->GetID().c_str() );
554 #ifdef WITHGENERICOBJ
555 // obj has been published in study. Its refcount has been incremented.
556 // It is safe to decrement its refcount
557 // so that it will be destroyed when the entry in study will be removed
567 for ( int i = 0; i < myObjects.count(); i++ ) {
568 SMESH_Actor* actor = SMESH::FindActorByObject( myObjects[i] );
569 if ( actor ) SMESH::Update( actor->getIO(), true );
572 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
573 actionButton == MAKE_MESH_BUTTON ) {
574 mySMESHGUI->updateObjBrowser(true); // new groups may appear
575 if( LightApp_Application* anApp =
576 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
577 anApp->browseObjects( anEntryList, isApplyAndClose() );
580 ConstructorsClicked(GetConstructorId());
581 SelectionIntoArgument();
583 SMESHGUI::Modified();
589 //=================================================================================
590 // function : ClickOnOk()
592 //=================================================================================
593 void SMESHGUI_ScaleDlg::ClickOnOk()
595 setIsApplyAndClose( true );
600 //=================================================================================
601 // function : reject()
603 //=================================================================================
604 void SMESHGUI_ScaleDlg::reject()
606 disconnect(mySelectionMgr, 0, this, 0);
607 mySelectionMgr->clearFilters();
608 //mySelectionMgr->clearSelected();
609 if (SMESH::GetCurrentVtkView()) {
610 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
611 SMESH::SetPointRepresentation(false);
613 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
614 aViewWindow->SetSelectionMode( ActorSelection );
615 mySMESHGUI->ResetState();
619 //=================================================================================
620 // function : ClickOnHelp()
622 //=================================================================================
623 void SMESHGUI_ScaleDlg::ClickOnHelp()
625 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
627 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
631 platform = "winapplication";
633 platform = "application";
635 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
636 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
637 arg(app->resourceMgr()->stringValue("ExternalBrowser",
639 arg(myHelpFileName));
643 //=======================================================================
644 // function : onTextChange()
646 //=======================================================================
647 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
649 QLineEdit* send = (QLineEdit*)sender();
652 BusyLocker lock( myBusy );
654 if (send == LineEditElements)
657 buttonOk->setEnabled(false);
658 buttonApply->setEnabled(false);
660 // hilight entered elements
661 SMDS_Mesh* aMesh = 0;
663 aMesh = myActor->GetObject()->GetMesh();
666 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
668 TColStd_MapOfInteger newIndices;
670 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
672 if (send == LineEditElements) {
673 for (int i = 0; i < aListId.count(); i++) {
674 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
676 newIndices.Add(e->GetID());
681 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
682 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
683 aViewWindow->highlight( anIO, true, true );
685 myElementsId = theNewText;
688 if (myNbOkElements) {
689 buttonOk->setEnabled(true);
690 buttonApply->setEnabled(true);
694 //=================================================================================
695 // function : SelectionIntoArgument()
696 // purpose : Called when selection as changed or other case
697 //=================================================================================
698 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
701 BusyLocker lock( myBusy );
704 QString aString = "";
705 onDisplaySimulation(false);
707 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
708 LineEditElements->setText(aString);
710 buttonOk->setEnabled(false);
711 buttonApply->setEnabled(false);
714 if (!GroupButtons->isEnabled()) // inactive
719 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
721 int nbSel = aList.Extent();
727 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
730 myObjectsNames.clear();
733 for ( SALOME_ListIteratorOfListIO it( aList ); it.More(); it.Next() ) {
734 Handle(SALOME_InteractiveObject) IO = it.Value();
735 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO( IO );
736 if ( aMesh->_is_nil() )
739 myActor = SMESH::FindActorByObject( aMesh );
741 myActor = SMESH::FindActorByEntry( IO->getEntry() );
742 if ( !myActor && !CheckBoxMesh->isChecked() )
745 if ( !SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO )->_is_nil() ) {
746 if ( _PTR(Study) aStudy = SMESH::GetActiveStudyDocument() ) {
747 _PTR(SObject) obj = aStudy->FindObjectID( qPrintable( QString( IO->getEntry() ) ) );
748 _PTR(GenericAttribute) anAttr;
749 if ( obj && obj->FindAttribute( anAttr, "AttributeName" ) ) {
750 _PTR(AttributeName) aNameAttr( anAttr );
751 myObjects << SMESH::IObjectToInterface<SMESH::SMESH_IDSource>( IO );
752 myObjectsNames << aNameAttr->Value().c_str();
759 // MakeGroups is available if there are groups and "Copy"
761 for ( int i = 0; i < myMeshes.count(); i++ )
762 aNbGroups += myMeshes[i]->NbGroups();
764 if ( aNbGroups == 0 ) {
765 MakeGroupsCheck->setChecked(false);
766 MakeGroupsCheck->setEnabled(false);
768 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
769 MakeGroupsCheck->setEnabled(true);
772 if (CheckBoxMesh->isChecked()) {
773 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
774 if (myMeshes.isEmpty())
778 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
782 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
783 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
785 myElementsId += QString(" %1").arg(i);
789 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
791 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
793 // get IDs from submesh
794 SMESH::long_array_var anElementsIds = new SMESH::long_array;
795 anElementsIds = aSubMesh->GetElementsId();
796 for (int i = 0; i < anElementsIds->length(); i++) {
797 myElementsId += QString(" %1").arg(anElementsIds[i]);
799 aNbUnits = anElementsIds->length();
802 SMESH::SMESH_GroupBase_var aGroup =
803 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
804 if (aGroup->_is_nil())
807 // get IDs from smesh group
808 SMESH::long_array_var anElementsIds = new SMESH::long_array;
809 anElementsIds = aGroup->GetListOfID();
810 for (int i = 0; i < anElementsIds->length(); i++) {
811 myElementsId += QString(" %1").arg(anElementsIds[i]);
813 aNbUnits = anElementsIds->length();
817 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, aList.First(), aString);
818 myElementsId = aString;
823 myNbOkElements = true;
825 Handle(SALOME_InteractiveObject) IO = aList.First();
826 if ((SMESH::GetMeshByIO(IO))->_is_nil())
829 SMESH_Actor* anActor = SMESH::FindActorByObject(SMESH::GetMeshByIO(IO));
831 anActor = SMESH::FindActorByEntry(IO->getEntry());
832 if (!anActor && !CheckBoxMesh->isChecked())
835 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
839 SMDS_Mesh* aMesh = anActor->GetObject()->GetMesh();
843 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
851 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
852 SpinBox1_1->SetValue(x);
853 SpinBox1_2->SetValue(y);
854 SpinBox1_3->SetValue(z);
856 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
857 SpinBox_FX->SetValue(x);
858 SpinBox_FY->SetValue(y);
859 SpinBox_FZ->SetValue(z);
863 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
864 LineEditElements->setText(aString);
865 LineEditElements->repaint();
866 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
867 LineEditElements->setEnabled(true);
872 if (myNbOkElements) {
873 buttonOk->setEnabled(true);
874 buttonApply->setEnabled(true);
877 onDisplaySimulation(true);
880 //=================================================================================
881 // function : SetEditCurrentArgument()
883 //=================================================================================
884 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
886 QPushButton* send = (QPushButton*)sender();
888 disconnect(mySelectionMgr, 0, this, 0);
889 mySelectionMgr->clearSelected();
890 mySelectionMgr->clearFilters();
892 if (send == SelectElementsButton) {
893 myEditCurrentArgument = (QWidget*)LineEditElements;
894 SMESH::SetPointRepresentation(false);
895 if (CheckBoxMesh->isChecked()) {
896 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
897 aViewWindow->SetSelectionMode( ActorSelection );
898 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
901 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
902 aViewWindow->SetSelectionMode( CellSelection );
905 else if (send == SelectButton1) {
906 myEditCurrentArgument = (QWidget*)SpinBox1_1;
907 SMESH::SetPointRepresentation(true);
908 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
909 aViewWindow->SetSelectionMode( NodeSelection );
912 myEditCurrentArgument->setFocus();
913 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
914 SelectionIntoArgument();
917 //=================================================================================
918 // function : DeactivateActiveDialog()
920 //=================================================================================
921 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
923 if (ConstructorsBox->isEnabled()) {
924 ConstructorsBox->setEnabled(false);
925 GroupArguments->setEnabled(false);
926 GroupButtons->setEnabled(false);
927 mySMESHGUI->ResetState();
928 mySMESHGUI->SetActiveDialogBox(0);
932 //=================================================================================
933 // function : ActivateThisDialog()
935 //=================================================================================
936 void SMESHGUI_ScaleDlg::ActivateThisDialog()
938 /* Emit a signal to deactivate the active dialog */
939 mySMESHGUI->EmitSignalDeactivateDialog();
940 ConstructorsBox->setEnabled(true);
941 GroupArguments->setEnabled(true);
942 GroupButtons->setEnabled(true);
944 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
946 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
947 aViewWindow->SetSelectionMode( CellSelection );
949 SelectionIntoArgument();
952 //=================================================================================
953 // function : enterEvent()
955 //=================================================================================
956 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
958 if (!ConstructorsBox->isEnabled())
959 ActivateThisDialog();
962 //=======================================================================
963 //function : onSelectMesh
965 //=======================================================================
966 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
969 TextLabelElements->setText(tr("SMESH_NAME"));
971 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
972 myFilterBtn->setEnabled(!toSelectMesh);
974 if (myEditCurrentArgument != LineEditElements) {
975 LineEditElements->clear();
979 mySelectionMgr->clearFilters();
980 SMESH::SetPointRepresentation(false);
983 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
984 aViewWindow->SetSelectionMode( ActorSelection );
985 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
986 LineEditElements->setReadOnly(true);
987 LineEditElements->setValidator(0);
989 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
990 aViewWindow->SetSelectionMode( CellSelection );
991 LineEditElements->setReadOnly(false);
992 LineEditElements->setValidator(myIdValidator);
993 onTextChange(LineEditElements->text());
997 SelectionIntoArgument();
1000 //=======================================================================
1001 //function : onActionClicked
1002 //purpose : slot called when an action type changed
1003 //=======================================================================
1005 void SMESHGUI_ScaleDlg::onActionClicked(int button)
1008 for ( int i = 0; i < myMeshes.count(); i++ )
1009 aNbGroups += myMeshes[i]->NbGroups();
1012 case MOVE_ELEMS_BUTTON:
1013 MakeGroupsCheck->setEnabled(false);
1014 LineEditNewMesh->setEnabled(false);
1016 case COPY_ELEMS_BUTTON:
1017 LineEditNewMesh->setEnabled(false);
1018 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
1019 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1021 case MAKE_MESH_BUTTON:
1022 LineEditNewMesh->setEnabled(true);
1023 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
1024 MakeGroupsCheck->setEnabled( myMeshes.isEmpty() || aNbGroups > 0 );
1028 toDisplaySimulation();
1031 //=======================================================================
1032 //function : setNewMeshName
1033 //purpose : update contents of LineEditNewMesh
1034 //=======================================================================
1036 void SMESHGUI_ScaleDlg::setNewMeshName()
1038 LineEditNewMesh->setText("");
1039 if ( LineEditNewMesh->isEnabled() && !myMeshes.isEmpty() ) {
1041 if ( CheckBoxMesh->isChecked() ) {
1042 name = myObjects.count() > 1 ? "*" : LineEditElements->text();
1045 _PTR(SObject) meshSO = SMESH::FindSObject( myMeshes[0] );
1046 name = meshSO->GetName().c_str();
1048 if ( !name.isEmpty() )
1049 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1053 //=================================================================================
1054 // function : GetConstructorId()
1056 //=================================================================================
1057 int SMESHGUI_ScaleDlg::GetConstructorId()
1059 return GroupConstructors->checkedId();
1062 //=================================================================================
1063 // function : keyPressEvent()
1065 //=================================================================================
1066 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1068 QDialog::keyPressEvent( e );
1069 if ( e->isAccepted() )
1072 if ( e->key() == Qt::Key_F1 ) {
1078 //=================================================================================
1079 // function : setFilters()
1080 // purpose : SLOT. Called when "Filter" button pressed.
1081 //=================================================================================
1082 void SMESHGUI_ScaleDlg::setFilters()
1084 if(myMeshes.isEmpty()) {
1085 SUIT_MessageBox::critical(this,
1087 tr("NO_MESH_SELECTED"));
1091 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1093 myFilterDlg->SetSelection();
1094 myFilterDlg->SetMesh( myMeshes[0] );
1095 myFilterDlg->SetSourceWg( LineEditElements );
1097 myFilterDlg->show();
1100 //=================================================================================
1101 // function : isValid
1103 //=================================================================================
1104 bool SMESHGUI_ScaleDlg::isValid()
1109 ok = SpinBox1_1->isValid( msg, true ) && ok;
1110 ok = SpinBox1_2->isValid( msg, true ) && ok;
1111 ok = SpinBox1_3->isValid( msg, true ) && ok;
1112 ok = SpinBox_FX->isValid( msg, true ) && ok;
1113 if (GetConstructorId() == 1) {
1114 ok = SpinBox_FY->isValid( msg, true ) && ok;
1115 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1119 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1120 if ( !msg.isEmpty() )
1122 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1128 //=================================================================================
1129 // function : onDisplaySimulation
1130 // purpose : Show/Hide preview
1131 //=================================================================================
1132 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1133 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1134 if ( myNbOkElements && isValid() ) {
1135 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1137 SMESH::long_array_var anElementsId = new SMESH::long_array;
1139 anElementsId->length(aListElementsId.count());
1140 for (int i = 0; i < aListElementsId.count(); i++)
1141 anElementsId[i] = aListElementsId[i].toInt();
1143 SMESH::PointStruct aPoint;
1144 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1145 getScale(aPoint, aScaleFact);
1148 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1149 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1150 SUIT_OverrideCursor aWaitCursor;
1151 QList<SMESH::MeshPreviewStruct_var> aMeshPreviewStruct;
1153 if(CheckBoxMesh->isChecked())
1154 for ( int i = 0; i < myObjects.count(); i++ ) {
1155 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[i]->GetMeshEditPreviewer();
1156 aMeshEditor->Scale(myObjects[i], aPoint, aScaleFact, copy);
1157 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1160 SMESH::SMESH_MeshEditor_var aMeshEditor = myMeshes[0]->GetMeshEditPreviewer();
1161 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL), aPoint, aScaleFact, copy);
1162 aMeshPreviewStruct << aMeshEditor->GetPreviewData();
1164 setSimulationPreview(aMeshPreviewStruct);
1176 //=================================================================================
1177 // function : getScale
1178 // purpose : get scale parameters
1179 //=================================================================================
1180 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1181 thePoint.x = SpinBox1_1->GetValue();
1182 thePoint.y = SpinBox1_2->GetValue();
1183 thePoint.z = SpinBox1_3->GetValue();
1185 theScaleFact->length(3);
1186 theScaleFact[0] = SpinBox_FX->GetValue();
1187 if (GetConstructorId() == 0) {
1188 theScaleFact[1] = SpinBox_FX->GetValue();
1189 theScaleFact[2] = SpinBox_FX->GetValue();
1192 theScaleFact[1] = SpinBox_FY->GetValue();
1193 theScaleFact[2] = SpinBox_FZ->GetValue();