1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // SMESH SMESHGUI : GUI for SMESH component
20 // File : SMESHGUI_ScaleDlg.cxx
21 // Author : Michael ZORIN, Open CASCADE S.A.S.
24 #include "SMESHGUI_ScaleDlg.h"
27 #include "SMESHGUI_SpinBox.h"
28 #include "SMESHGUI_Utils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_IdValidator.h"
32 #include "SMESHGUI_FilterDlg.h"
33 #include "SMESHGUI_MeshEditPreview.h"
35 #include <SMESH_Actor.h>
36 #include <SMESH_TypeFilter.hxx>
37 #include <SMESH_LogicalFilter.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GUI includes
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ResourceMgr.h>
43 #include <SUIT_Session.h>
44 #include <SUIT_MessageBox.h>
45 #include <SUIT_OverrideCursor.h>
47 #include <LightApp_Application.h>
48 #include <LightApp_SelectionMgr.h>
50 #include <SVTK_ViewModel.h>
51 #include <SVTK_ViewWindow.h>
52 #include <SALOME_ListIO.hxx>
54 // SALOME KERNEL includes
55 #include <SALOMEDSClient_SObject.hxx>
58 #include <TColStd_MapOfInteger.hxx>
61 #include <QApplication>
62 #include <QButtonGroup>
66 #include <QPushButton>
67 #include <QRadioButton>
69 #include <QHBoxLayout>
70 #include <QVBoxLayout>
71 #include <QGridLayout>
76 #include <SALOMEconfig.h>
77 #include CORBA_SERVER_HEADER(SMESH_Group)
78 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
80 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
84 \brief Simple 'busy state' flag locker.
91 //! Constructor. Sets passed boolean flag to \c true.
92 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
93 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
94 ~BusyLocker() { myBusy = false; }
96 bool& myBusy; //! External 'busy state' boolean flag
102 //To disable automatic genericobj management, the following line should be commented.
103 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
104 #define WITHGENERICOBJ
106 //=================================================================================
107 // class : SMESHGUI_ScaleDlg()
109 //=================================================================================
110 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule ) :
111 SMESHGUI_PreviewDlg( theModule ),
112 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
114 mySelectedObject(SMESH::SMESH_IDSource::_nil())
116 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
117 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
118 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
121 setAttribute(Qt::WA_DeleteOnClose, true);
122 setWindowTitle(tr("SMESH_SCALE_TITLE"));
123 setSizeGripEnabled(true);
125 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
126 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
127 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
129 /***************************************************************/
130 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
131 GroupConstructors = new QButtonGroup(this);
132 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
133 ConstructorsBoxLayout->setSpacing(SPACING);
134 ConstructorsBoxLayout->setMargin(MARGIN);
136 RadioButton1= new QRadioButton(ConstructorsBox);
137 RadioButton1->setIcon(image0);
138 RadioButton2= new QRadioButton(ConstructorsBox);
139 RadioButton2->setIcon(image1);
141 ConstructorsBoxLayout->addWidget(RadioButton1);
142 ConstructorsBoxLayout->addWidget(RadioButton2);
143 GroupConstructors->addButton(RadioButton1, 0);
144 GroupConstructors->addButton(RadioButton2, 1);
146 /***************************************************************/
147 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
148 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
149 GroupArgumentsLayout->setSpacing(SPACING);
150 GroupArgumentsLayout->setMargin(MARGIN);
152 myIdValidator = new SMESHGUI_IdValidator(this);
154 // Controls for elements selection
155 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
156 SelectElementsButton = new QPushButton(GroupArguments);
157 SelectElementsButton->setIcon(image2);
158 LineEditElements = new QLineEdit(GroupArguments);
159 LineEditElements->setValidator(myIdValidator);
160 LineEditElements->setMaxLength(-1);
161 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
162 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
164 // Control for the whole mesh selection
165 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
167 // Controls for vector and points selection
168 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
169 SelectButton1 = new QPushButton(GroupArguments);
170 SelectButton1->setIcon(image2);
172 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
173 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
175 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
176 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
177 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
179 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
180 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
182 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
183 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
185 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
186 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
189 // switch of action type
190 ActionBox = new QGroupBox(GroupArguments);
191 ActionGroup = new QButtonGroup(GroupArguments);
192 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
193 ActionBoxLayout->addSpacing(SPACING);
194 ActionBoxLayout->setMargin(MARGIN);
196 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
197 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
198 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
200 ActionBoxLayout->addWidget(aMoveElements);
201 ActionBoxLayout->addWidget(aCopyElements);
202 ActionBoxLayout->addWidget(aCreateMesh);
203 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
204 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
205 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
207 // CheckBox for groups generation
208 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
209 MakeGroupsCheck->setChecked(false);
211 // Name of a mesh to create
212 LineEditNewMesh = new QLineEdit(GroupArguments);
215 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 (MESHorSUBMESH);
290 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (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(ClickOnCancel()));
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(ClickOnCancel()));
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 myEditCurrentArgument = 0;
359 LineEditElements->clear();
363 buttonOk->setEnabled(false);
364 buttonApply->setEnabled(false);
367 myMesh = SMESH::SMESH_Mesh::_nil();
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();
434 //=================================================================================
435 // function : ClickOnApply()
437 //=================================================================================
438 bool SMESHGUI_ScaleDlg::ClickOnApply()
440 if (mySMESHGUI->isActiveStudyLocked())
446 if (myNbOkElements) {
447 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
449 SMESH::long_array_var anElementsId = new SMESH::long_array;
451 anElementsId->length(aListElementsId.count());
452 for (int i = 0; i < aListElementsId.count(); i++)
453 anElementsId[i] = aListElementsId[i].toInt();
455 SMESH::PointStruct aPoint;
456 SMESH::double_array_var aScaleFact = new SMESH::double_array;
457 getScale(aPoint, aScaleFact);
459 QStringList aParameters;
460 aParameters << SpinBox1_1->text();
461 aParameters << SpinBox1_2->text();
462 aParameters << SpinBox1_3->text();
463 aParameters << SpinBox_FX->text();
464 if (GetConstructorId() == 1) {
465 aParameters << SpinBox_FX->text();
466 aParameters << SpinBox_FX->text();
469 aParameters << SpinBox_FY->text();
470 aParameters << SpinBox_FZ->text();
473 int actionButton = ActionGroup->checkedId();
474 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
475 QStringList anEntryList;
477 SUIT_OverrideCursor aWaitCursor;
478 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
479 SMESH::SMESH_IDSource_var obj;
480 if ( CheckBoxMesh->isChecked() )
481 obj = mySelectedObject;
483 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
485 switch ( actionButton ) {
487 case MOVE_ELEMS_BUTTON:
488 aMeshEditor->Scale(obj, aPoint, aScaleFact, false);
489 if( !myMesh->_is_nil())
490 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
493 case COPY_ELEMS_BUTTON:
495 SMESH::ListOfGroups_var groups =
496 aMeshEditor->ScaleMakeGroups(obj, aPoint, aScaleFact);
498 aMeshEditor->Scale(obj, aPoint, aScaleFact, true);
499 if( !myMesh->_is_nil())
500 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
503 case MAKE_MESH_BUTTON: {
504 SMESH::SMESH_Mesh_var mesh =
505 aMeshEditor->ScaleMakeMesh(obj, aPoint, aScaleFact, makeGroups,
506 LineEditNewMesh->text().toLatin1().data());
507 if (!mesh->_is_nil()) {
508 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
509 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
510 anEntryList.append( aSObject->GetID().c_str() );
511 #ifdef WITHGENERICOBJ
512 // obj has been published in study. Its refcount has been incremented.
513 // It is safe to decrement its refcount
514 // so that it will be destroyed when the entry in study will be removed
525 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
526 actionButton == MAKE_MESH_BUTTON ) {
527 mySMESHGUI->updateObjBrowser(true); // new groups may appear
528 if( LightApp_Application* anApp =
529 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
530 anApp->browseObjects( anEntryList, isApplyAndClose() );
533 ConstructorsClicked(GetConstructorId());
534 mySelectedObject = SMESH::SMESH_IDSource::_nil();
535 SelectionIntoArgument();
537 SMESHGUI::Modified();
543 //=================================================================================
544 // function : ClickOnOk()
546 //=================================================================================
547 void SMESHGUI_ScaleDlg::ClickOnOk()
549 setIsApplyAndClose( true );
554 //=================================================================================
555 // function : ClickOnCancel()
557 //=================================================================================
558 void SMESHGUI_ScaleDlg::ClickOnCancel()
560 disconnect(mySelectionMgr, 0, this, 0);
561 mySelectionMgr->clearFilters();
562 //mySelectionMgr->clearSelected();
563 if (SMESH::GetCurrentVtkView()) {
564 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
565 SMESH::SetPointRepresentation(false);
567 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
568 aViewWindow->SetSelectionMode( ActorSelection );
569 mySMESHGUI->ResetState();
573 //=================================================================================
574 // function : ClickOnHelp()
576 //=================================================================================
577 void SMESHGUI_ScaleDlg::ClickOnHelp()
579 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
581 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
585 platform = "winapplication";
587 platform = "application";
589 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
590 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
591 arg(app->resourceMgr()->stringValue("ExternalBrowser",
593 arg(myHelpFileName));
597 //=======================================================================
598 // function : onTextChange()
600 //=======================================================================
601 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
603 QLineEdit* send = (QLineEdit*)sender();
606 BusyLocker lock( myBusy );
608 if (send == LineEditElements)
611 buttonOk->setEnabled(false);
612 buttonApply->setEnabled(false);
614 // hilight entered elements
615 SMDS_Mesh* aMesh = 0;
617 aMesh = myActor->GetObject()->GetMesh();
620 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
622 TColStd_MapOfInteger newIndices;
624 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
626 if (send == LineEditElements) {
627 for (int i = 0; i < aListId.count(); i++) {
628 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
630 newIndices.Add(e->GetID());
635 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
636 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
637 aViewWindow->highlight( anIO, true, true );
639 myElementsId = theNewText;
642 if (myNbOkElements) {
643 buttonOk->setEnabled(true);
644 buttonApply->setEnabled(true);
648 //=================================================================================
649 // function : SelectionIntoArgument()
650 // purpose : Called when selection as changed or other case
651 //=================================================================================
652 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
655 BusyLocker lock( myBusy );
658 QString aString = "";
660 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
661 LineEditElements->setText(aString);
663 buttonOk->setEnabled(false);
664 buttonApply->setEnabled(false);
667 if (!GroupButtons->isEnabled()) // inactive
672 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
674 int nbSel = aList.Extent();
678 Handle(SALOME_InteractiveObject) IO = aList.First();
679 myMesh = SMESH::GetMeshByIO(IO);
680 if (myMesh->_is_nil())
683 myActor = SMESH::FindActorByObject(myMesh);
685 myActor = SMESH::FindActorByEntry(IO->getEntry());
686 if (!myActor && !CheckBoxMesh->isChecked())
691 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
694 // MakeGroups is available if there are groups and "Copy"
695 if ( myMesh->NbGroups() == 0 ) {
696 MakeGroupsCheck->setChecked(false);
697 MakeGroupsCheck->setEnabled(false);
699 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
700 MakeGroupsCheck->setEnabled(true);
703 if (CheckBoxMesh->isChecked()) {
704 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
706 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
707 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
713 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
717 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
718 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
720 myElementsId += QString(" %1").arg(i);
724 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
726 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
728 // get IDs from submesh
729 SMESH::long_array_var anElementsIds = new SMESH::long_array;
730 anElementsIds = aSubMesh->GetElementsId();
731 for (int i = 0; i < anElementsIds->length(); i++) {
732 myElementsId += QString(" %1").arg(anElementsIds[i]);
734 aNbUnits = anElementsIds->length();
737 SMESH::SMESH_GroupBase_var aGroup =
738 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
739 if (aGroup->_is_nil())
742 // get IDs from smesh group
743 SMESH::long_array_var anElementsIds = new SMESH::long_array;
744 anElementsIds = aGroup->GetListOfID();
745 for (int i = 0; i < anElementsIds->length(); i++) {
746 myElementsId += QString(" %1").arg(anElementsIds[i]);
748 aNbUnits = anElementsIds->length();
752 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
753 myElementsId = aString;
758 myNbOkElements = true;
760 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
764 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
768 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
776 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
777 SpinBox1_1->SetValue(x);
778 SpinBox1_2->SetValue(y);
779 SpinBox1_3->SetValue(z);
781 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
782 SpinBox_FX->SetValue(x);
783 SpinBox_FY->SetValue(y);
784 SpinBox_FZ->SetValue(z);
788 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
789 LineEditElements->setText(aString);
790 LineEditElements->repaint();
791 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
792 LineEditElements->setEnabled(true);
797 if (myNbOkElements) {
798 buttonOk->setEnabled(true);
799 buttonApply->setEnabled(true);
802 onDisplaySimulation(true);
805 //=================================================================================
806 // function : SetEditCurrentArgument()
808 //=================================================================================
809 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
811 QPushButton* send = (QPushButton*)sender();
813 disconnect(mySelectionMgr, 0, this, 0);
814 mySelectionMgr->clearSelected();
815 mySelectionMgr->clearFilters();
817 if (send == SelectElementsButton) {
818 myEditCurrentArgument = (QWidget*)LineEditElements;
819 SMESH::SetPointRepresentation(false);
820 if (CheckBoxMesh->isChecked()) {
821 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822 aViewWindow->SetSelectionMode( ActorSelection );
823 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
826 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
827 aViewWindow->SetSelectionMode( CellSelection );
830 else if (send == SelectButton1) {
831 myEditCurrentArgument = (QWidget*)SpinBox1_1;
832 SMESH::SetPointRepresentation(true);
833 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
834 aViewWindow->SetSelectionMode( NodeSelection );
837 myEditCurrentArgument->setFocus();
838 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
839 SelectionIntoArgument();
842 //=================================================================================
843 // function : DeactivateActiveDialog()
845 //=================================================================================
846 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
848 if (ConstructorsBox->isEnabled()) {
849 ConstructorsBox->setEnabled(false);
850 GroupArguments->setEnabled(false);
851 GroupButtons->setEnabled(false);
852 mySMESHGUI->ResetState();
853 mySMESHGUI->SetActiveDialogBox(0);
857 //=================================================================================
858 // function : ActivateThisDialog()
860 //=================================================================================
861 void SMESHGUI_ScaleDlg::ActivateThisDialog()
863 /* Emit a signal to deactivate the active dialog */
864 mySMESHGUI->EmitSignalDeactivateDialog();
865 ConstructorsBox->setEnabled(true);
866 GroupArguments->setEnabled(true);
867 GroupButtons->setEnabled(true);
869 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
871 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
872 aViewWindow->SetSelectionMode( CellSelection );
874 SelectionIntoArgument();
877 //=================================================================================
878 // function : enterEvent()
880 //=================================================================================
881 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
883 if (!ConstructorsBox->isEnabled())
884 ActivateThisDialog();
887 //=================================================================================
888 // function : closeEvent()
890 //=================================================================================
891 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
893 /* same than click on cancel button */
897 //=======================================================================
898 //function : hideEvent
899 //purpose : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
907 //=======================================================================
908 //function : onSelectMesh
910 //=======================================================================
911 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
914 TextLabelElements->setText(tr("SMESH_NAME"));
916 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
917 myFilterBtn->setEnabled(!toSelectMesh);
919 if (myEditCurrentArgument != LineEditElements) {
920 LineEditElements->clear();
924 mySelectionMgr->clearFilters();
925 SMESH::SetPointRepresentation(false);
928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
929 aViewWindow->SetSelectionMode( ActorSelection );
930 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
931 LineEditElements->setReadOnly(true);
932 LineEditElements->setValidator(0);
934 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
935 aViewWindow->SetSelectionMode( CellSelection );
936 LineEditElements->setReadOnly(false);
937 LineEditElements->setValidator(myIdValidator);
938 onTextChange(LineEditElements->text());
942 SelectionIntoArgument();
945 //=======================================================================
946 //function : onActionClicked
947 //purpose : slot called when an action type changed
948 //=======================================================================
950 void SMESHGUI_ScaleDlg::onActionClicked(int button)
953 case MOVE_ELEMS_BUTTON:
954 MakeGroupsCheck->setEnabled(false);
955 LineEditNewMesh->setEnabled(false);
957 case COPY_ELEMS_BUTTON:
958 LineEditNewMesh->setEnabled(false);
959 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
960 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961 MakeGroupsCheck->setEnabled(true);
963 MakeGroupsCheck->setEnabled(false);
965 case MAKE_MESH_BUTTON:
966 LineEditNewMesh->setEnabled(true);
967 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
968 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
969 MakeGroupsCheck->setEnabled(true);
971 MakeGroupsCheck->setEnabled(false);
975 toDisplaySimulation();
978 //=======================================================================
979 //function : setNewMeshName
980 //purpose : update contents of LineEditNewMesh
981 //=======================================================================
983 void SMESHGUI_ScaleDlg::setNewMeshName()
985 LineEditNewMesh->setText("");
986 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
988 if ( CheckBoxMesh->isChecked() ) {
989 name = LineEditElements->text();
992 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
993 name = meshSO->GetName().c_str();
995 if ( !name.isEmpty() )
996 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
1000 //=================================================================================
1001 // function : GetConstructorId()
1003 //=================================================================================
1004 int SMESHGUI_ScaleDlg::GetConstructorId()
1006 return GroupConstructors->checkedId();
1009 //=================================================================================
1010 // function : keyPressEvent()
1012 //=================================================================================
1013 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1015 QDialog::keyPressEvent( e );
1016 if ( e->isAccepted() )
1019 if ( e->key() == Qt::Key_F1 ) {
1025 //=================================================================================
1026 // function : setFilters()
1027 // purpose : SLOT. Called when "Filter" button pressed.
1028 //=================================================================================
1029 void SMESHGUI_ScaleDlg::setFilters()
1031 if(myMesh->_is_nil()) {
1032 SUIT_MessageBox::critical(this,
1034 tr("NO_MESH_SELECTED"));
1038 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1040 myFilterDlg->SetSelection();
1041 myFilterDlg->SetMesh( myMesh );
1042 myFilterDlg->SetSourceWg( LineEditElements );
1044 myFilterDlg->show();
1047 //=================================================================================
1048 // function : isValid
1050 //=================================================================================
1051 bool SMESHGUI_ScaleDlg::isValid()
1056 ok = SpinBox1_1->isValid( msg, true ) && ok;
1057 ok = SpinBox1_2->isValid( msg, true ) && ok;
1058 ok = SpinBox1_3->isValid( msg, true ) && ok;
1059 ok = SpinBox_FX->isValid( msg, true ) && ok;
1060 if (GetConstructorId() == 1) {
1061 ok = SpinBox_FY->isValid( msg, true ) && ok;
1062 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1066 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1067 if ( !msg.isEmpty() )
1069 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1075 //=================================================================================
1076 // function : onDisplaySimulation
1077 // purpose : Show/Hide preview
1078 //=================================================================================
1079 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1080 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1081 if ( myNbOkElements && isValid() ) {
1082 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1084 SMESH::long_array_var anElementsId = new SMESH::long_array;
1086 anElementsId->length(aListElementsId.count());
1087 for (int i = 0; i < aListElementsId.count(); i++)
1088 anElementsId[i] = aListElementsId[i].toInt();
1090 SMESH::PointStruct aPoint;
1091 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1092 getScale(aPoint, aScaleFact);
1095 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1096 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1097 SUIT_OverrideCursor aWaitCursor;
1098 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1099 SMESH::SMESH_IDSource_var obj;
1100 if ( CheckBoxMesh->isChecked() )
1101 obj = mySelectedObject;
1103 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1104 aMeshEditor->Scale(obj, aPoint, aScaleFact, copy);
1106 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1107 mySimulation->SetData(aMeshPreviewStruct._retn());
1120 //=================================================================================
1121 // function : getScale
1122 // purpose : get scale parameters
1123 //=================================================================================
1124 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1125 thePoint.x = SpinBox1_1->GetValue();
1126 thePoint.y = SpinBox1_2->GetValue();
1127 thePoint.z = SpinBox1_3->GetValue();
1129 theScaleFact->length(3);
1130 theScaleFact[0] = SpinBox_FX->GetValue();
1131 if (GetConstructorId() == 0) {
1132 theScaleFact[1] = SpinBox_FX->GetValue();
1133 theScaleFact[2] = SpinBox_FX->GetValue();
1136 theScaleFact[1] = SpinBox_FY->GetValue();
1137 theScaleFact[2] = SpinBox_FZ->GetValue();