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() );
476 SUIT_OverrideCursor aWaitCursor;
477 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
478 SMESH::SMESH_IDSource_var obj;
479 if ( CheckBoxMesh->isChecked() )
480 obj = mySelectedObject;
482 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
484 switch ( actionButton ) {
486 case MOVE_ELEMS_BUTTON:
487 aMeshEditor->Scale(obj, aPoint, aScaleFact, false);
488 if( !myMesh->_is_nil())
489 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
492 case COPY_ELEMS_BUTTON:
494 SMESH::ListOfGroups_var groups =
495 aMeshEditor->ScaleMakeGroups(obj, aPoint, aScaleFact);
497 aMeshEditor->Scale(obj, aPoint, aScaleFact, true);
498 if( !myMesh->_is_nil())
499 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
502 case MAKE_MESH_BUTTON: {
503 SMESH::SMESH_Mesh_var mesh =
504 aMeshEditor->ScaleMakeMesh(obj, aPoint, aScaleFact, makeGroups,
505 LineEditNewMesh->text().toLatin1().data());
506 if (!mesh->_is_nil()) {
507 mesh->SetParameters(aParameters.join(":").toLatin1().constData());
508 #ifdef WITHGENERICOBJ
509 // obj has been published in study. Its refcount has been incremented.
510 // It is safe to decrement its refcount
511 // so that it will be destroyed when the entry in study will be removed
522 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
523 actionButton == MAKE_MESH_BUTTON )
524 mySMESHGUI->updateObjBrowser(true); // new groups may appear
526 ConstructorsClicked(GetConstructorId());
527 mySelectedObject = SMESH::SMESH_IDSource::_nil();
528 SelectionIntoArgument();
530 SMESHGUI::Modified();
536 //=================================================================================
537 // function : ClickOnOk()
539 //=================================================================================
540 void SMESHGUI_ScaleDlg::ClickOnOk()
546 //=================================================================================
547 // function : ClickOnCancel()
549 //=================================================================================
550 void SMESHGUI_ScaleDlg::ClickOnCancel()
552 disconnect(mySelectionMgr, 0, this, 0);
553 mySelectionMgr->clearFilters();
554 //mySelectionMgr->clearSelected();
555 if (SMESH::GetCurrentVtkView()) {
556 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
557 SMESH::SetPointRepresentation(false);
559 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560 aViewWindow->SetSelectionMode( ActorSelection );
561 mySMESHGUI->ResetState();
565 //=================================================================================
566 // function : ClickOnHelp()
568 //=================================================================================
569 void SMESHGUI_ScaleDlg::ClickOnHelp()
571 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
573 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
577 platform = "winapplication";
579 platform = "application";
581 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
582 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
583 arg(app->resourceMgr()->stringValue("ExternalBrowser",
585 arg(myHelpFileName));
589 //=======================================================================
590 // function : onTextChange()
592 //=======================================================================
593 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
595 QLineEdit* send = (QLineEdit*)sender();
598 BusyLocker lock( myBusy );
600 if (send == LineEditElements)
603 buttonOk->setEnabled(false);
604 buttonApply->setEnabled(false);
606 // hilight entered elements
607 SMDS_Mesh* aMesh = 0;
609 aMesh = myActor->GetObject()->GetMesh();
612 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
614 TColStd_MapOfInteger newIndices;
616 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
618 if (send == LineEditElements) {
619 for (int i = 0; i < aListId.count(); i++) {
620 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
622 newIndices.Add(e->GetID());
627 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
628 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
629 aViewWindow->highlight( anIO, true, true );
631 myElementsId = theNewText;
634 if (myNbOkElements) {
635 buttonOk->setEnabled(true);
636 buttonApply->setEnabled(true);
640 //=================================================================================
641 // function : SelectionIntoArgument()
642 // purpose : Called when selection as changed or other case
643 //=================================================================================
644 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
647 BusyLocker lock( myBusy );
650 QString aString = "";
652 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
653 LineEditElements->setText(aString);
655 buttonOk->setEnabled(false);
656 buttonApply->setEnabled(false);
659 if (!GroupButtons->isEnabled()) // inactive
664 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
666 int nbSel = aList.Extent();
670 Handle(SALOME_InteractiveObject) IO = aList.First();
671 myMesh = SMESH::GetMeshByIO(IO);
672 if (myMesh->_is_nil())
675 myActor = SMESH::FindActorByObject(myMesh);
677 myActor = SMESH::FindActorByEntry(IO->getEntry());
678 if (!myActor && !CheckBoxMesh->isChecked())
683 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
686 // MakeGroups is available if there are groups and "Copy"
687 if ( myMesh->NbGroups() == 0 ) {
688 MakeGroupsCheck->setChecked(false);
689 MakeGroupsCheck->setEnabled(false);
691 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
692 MakeGroupsCheck->setEnabled(true);
695 if (CheckBoxMesh->isChecked()) {
696 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
698 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
699 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
705 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
709 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
710 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
712 myElementsId += QString(" %1").arg(i);
716 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
718 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
720 // get IDs from submesh
721 SMESH::long_array_var anElementsIds = new SMESH::long_array;
722 anElementsIds = aSubMesh->GetElementsId();
723 for (int i = 0; i < anElementsIds->length(); i++) {
724 myElementsId += QString(" %1").arg(anElementsIds[i]);
726 aNbUnits = anElementsIds->length();
729 SMESH::SMESH_GroupBase_var aGroup =
730 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
731 if (aGroup->_is_nil())
734 // get IDs from smesh group
735 SMESH::long_array_var anElementsIds = new SMESH::long_array;
736 anElementsIds = aGroup->GetListOfID();
737 for (int i = 0; i < anElementsIds->length(); i++) {
738 myElementsId += QString(" %1").arg(anElementsIds[i]);
740 aNbUnits = anElementsIds->length();
744 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
745 myElementsId = aString;
750 myNbOkElements = true;
752 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
756 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
760 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
768 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
769 SpinBox1_1->SetValue(x);
770 SpinBox1_2->SetValue(y);
771 SpinBox1_3->SetValue(z);
773 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
774 SpinBox_FX->SetValue(x);
775 SpinBox_FY->SetValue(y);
776 SpinBox_FZ->SetValue(z);
780 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
781 LineEditElements->setText(aString);
782 LineEditElements->repaint();
783 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
784 LineEditElements->setEnabled(true);
789 if (myNbOkElements) {
790 buttonOk->setEnabled(true);
791 buttonApply->setEnabled(true);
794 onDisplaySimulation(true);
797 //=================================================================================
798 // function : SetEditCurrentArgument()
800 //=================================================================================
801 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
803 QPushButton* send = (QPushButton*)sender();
805 disconnect(mySelectionMgr, 0, this, 0);
806 mySelectionMgr->clearSelected();
807 mySelectionMgr->clearFilters();
809 if (send == SelectElementsButton) {
810 myEditCurrentArgument = (QWidget*)LineEditElements;
811 SMESH::SetPointRepresentation(false);
812 if (CheckBoxMesh->isChecked()) {
813 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
814 aViewWindow->SetSelectionMode( ActorSelection );
815 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode( CellSelection );
822 else if (send == SelectButton1) {
823 myEditCurrentArgument = (QWidget*)SpinBox1_1;
824 SMESH::SetPointRepresentation(true);
825 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
826 aViewWindow->SetSelectionMode( NodeSelection );
829 myEditCurrentArgument->setFocus();
830 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
831 SelectionIntoArgument();
834 //=================================================================================
835 // function : DeactivateActiveDialog()
837 //=================================================================================
838 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
840 if (ConstructorsBox->isEnabled()) {
841 ConstructorsBox->setEnabled(false);
842 GroupArguments->setEnabled(false);
843 GroupButtons->setEnabled(false);
844 mySMESHGUI->ResetState();
845 mySMESHGUI->SetActiveDialogBox(0);
849 //=================================================================================
850 // function : ActivateThisDialog()
852 //=================================================================================
853 void SMESHGUI_ScaleDlg::ActivateThisDialog()
855 /* Emit a signal to deactivate the active dialog */
856 mySMESHGUI->EmitSignalDeactivateDialog();
857 ConstructorsBox->setEnabled(true);
858 GroupArguments->setEnabled(true);
859 GroupButtons->setEnabled(true);
861 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
863 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
864 aViewWindow->SetSelectionMode( CellSelection );
866 SelectionIntoArgument();
869 //=================================================================================
870 // function : enterEvent()
872 //=================================================================================
873 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
875 if (!ConstructorsBox->isEnabled())
876 ActivateThisDialog();
879 //=================================================================================
880 // function : closeEvent()
882 //=================================================================================
883 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
885 /* same than click on cancel button */
889 //=======================================================================
890 //function : hideEvent
891 //purpose : caused by ESC key
892 //=======================================================================
893 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
899 //=======================================================================
900 //function : onSelectMesh
902 //=======================================================================
903 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
906 TextLabelElements->setText(tr("SMESH_NAME"));
908 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
909 myFilterBtn->setEnabled(!toSelectMesh);
911 if (myEditCurrentArgument != LineEditElements) {
912 LineEditElements->clear();
916 mySelectionMgr->clearFilters();
917 SMESH::SetPointRepresentation(false);
920 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
921 aViewWindow->SetSelectionMode( ActorSelection );
922 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
923 LineEditElements->setReadOnly(true);
924 LineEditElements->setValidator(0);
926 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
927 aViewWindow->SetSelectionMode( CellSelection );
928 LineEditElements->setReadOnly(false);
929 LineEditElements->setValidator(myIdValidator);
930 onTextChange(LineEditElements->text());
934 SelectionIntoArgument();
937 //=======================================================================
938 //function : onActionClicked
939 //purpose : slot called when an action type changed
940 //=======================================================================
942 void SMESHGUI_ScaleDlg::onActionClicked(int button)
945 case MOVE_ELEMS_BUTTON:
946 MakeGroupsCheck->setEnabled(false);
947 LineEditNewMesh->setEnabled(false);
949 case COPY_ELEMS_BUTTON:
950 LineEditNewMesh->setEnabled(false);
951 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
952 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
953 MakeGroupsCheck->setEnabled(true);
955 MakeGroupsCheck->setEnabled(false);
957 case MAKE_MESH_BUTTON:
958 LineEditNewMesh->setEnabled(true);
959 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
960 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
961 MakeGroupsCheck->setEnabled(true);
963 MakeGroupsCheck->setEnabled(false);
967 toDisplaySimulation();
970 //=======================================================================
971 //function : setNewMeshName
972 //purpose : update contents of LineEditNewMesh
973 //=======================================================================
975 void SMESHGUI_ScaleDlg::setNewMeshName()
977 LineEditNewMesh->setText("");
978 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
980 if ( CheckBoxMesh->isChecked() ) {
981 name = LineEditElements->text();
984 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
985 name = meshSO->GetName().c_str();
987 if ( !name.isEmpty() )
988 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
992 //=================================================================================
993 // function : GetConstructorId()
995 //=================================================================================
996 int SMESHGUI_ScaleDlg::GetConstructorId()
998 return GroupConstructors->checkedId();
1001 //=================================================================================
1002 // function : keyPressEvent()
1004 //=================================================================================
1005 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1007 QDialog::keyPressEvent( e );
1008 if ( e->isAccepted() )
1011 if ( e->key() == Qt::Key_F1 ) {
1017 //=================================================================================
1018 // function : setFilters()
1019 // purpose : SLOT. Called when "Filter" button pressed.
1020 //=================================================================================
1021 void SMESHGUI_ScaleDlg::setFilters()
1023 if(myMesh->_is_nil()) {
1024 SUIT_MessageBox::critical(this,
1026 tr("NO_MESH_SELECTED"));
1030 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1032 myFilterDlg->SetSelection();
1033 myFilterDlg->SetMesh( myMesh );
1034 myFilterDlg->SetSourceWg( LineEditElements );
1036 myFilterDlg->show();
1039 //=================================================================================
1040 // function : isValid
1042 //=================================================================================
1043 bool SMESHGUI_ScaleDlg::isValid()
1048 ok = SpinBox1_1->isValid( msg, true ) && ok;
1049 ok = SpinBox1_2->isValid( msg, true ) && ok;
1050 ok = SpinBox1_3->isValid( msg, true ) && ok;
1051 ok = SpinBox_FX->isValid( msg, true ) && ok;
1052 if (GetConstructorId() == 1) {
1053 ok = SpinBox_FY->isValid( msg, true ) && ok;
1054 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1058 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1059 if ( !msg.isEmpty() )
1061 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1067 //=================================================================================
1068 // function : onDisplaySimulation
1069 // purpose : Show/Hide preview
1070 //=================================================================================
1071 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1072 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1073 if ( myNbOkElements && isValid() ) {
1074 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1076 SMESH::long_array_var anElementsId = new SMESH::long_array;
1078 anElementsId->length(aListElementsId.count());
1079 for (int i = 0; i < aListElementsId.count(); i++)
1080 anElementsId[i] = aListElementsId[i].toInt();
1082 SMESH::PointStruct aPoint;
1083 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1084 getScale(aPoint, aScaleFact);
1087 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1088 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1089 SUIT_OverrideCursor aWaitCursor;
1090 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1091 SMESH::SMESH_IDSource_var obj;
1092 if ( CheckBoxMesh->isChecked() )
1093 obj = mySelectedObject;
1095 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1096 aMeshEditor->Scale(obj, aPoint, aScaleFact, copy);
1098 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1099 mySimulation->SetData(aMeshPreviewStruct._retn());
1112 //=================================================================================
1113 // function : getScale
1114 // purpose : get scale parameters
1115 //=================================================================================
1116 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1117 thePoint.x = SpinBox1_1->GetValue();
1118 thePoint.y = SpinBox1_2->GetValue();
1119 thePoint.z = SpinBox1_3->GetValue();
1121 theScaleFact->length(3);
1122 theScaleFact[0] = SpinBox_FX->GetValue();
1123 if (GetConstructorId() == 0) {
1124 theScaleFact[1] = SpinBox_FX->GetValue();
1125 theScaleFact[2] = SpinBox_FX->GetValue();
1128 theScaleFact[1] = SpinBox_FY->GetValue();
1129 theScaleFact[2] = SpinBox_FZ->GetValue();