1 // Copyright (C) 2007-2011 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>
53 // SALOME KERNEL includes
54 #include <SALOMEDSClient_SObject.hxx>
57 #include <TColStd_MapOfInteger.hxx>
60 #include <QApplication>
61 #include <QButtonGroup>
65 #include <QPushButton>
66 #include <QRadioButton>
68 #include <QHBoxLayout>
69 #include <QVBoxLayout>
70 #include <QGridLayout>
75 #include <SALOMEconfig.h>
76 #include CORBA_SERVER_HEADER(SMESH_Group)
77 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
79 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
83 \brief Simple 'busy state' flag locker.
90 //! Constructor. Sets passed boolean flag to \c true.
91 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
92 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
93 ~BusyLocker() { myBusy = false; }
95 bool& myBusy; //! External 'busy state' boolean flag
101 //To disable automatic genericobj management, the following line should be commented.
102 //Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
103 #define WITHGENERICOBJ
105 //=================================================================================
106 // class : SMESHGUI_ScaleDlg()
108 //=================================================================================
109 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule ) :
110 SMESHGUI_PreviewDlg( theModule ),
111 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
113 mySelectedObject(SMESH::SMESH_IDSource::_nil())
115 QPixmap image0 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_MESH_SCALE")));
116 QPixmap image1 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_DLG_SCALE_ALONG_AXES")));
117 QPixmap image2 (SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap("SMESH", tr("ICON_SELECT")));
120 setAttribute(Qt::WA_DeleteOnClose, true);
121 setWindowTitle(tr("SMESH_SCALE_TITLE"));
122 setSizeGripEnabled(true);
124 QVBoxLayout* SMESHGUI_ScaleDlgLayout = new QVBoxLayout(this);
125 SMESHGUI_ScaleDlgLayout->setSpacing(SPACING);
126 SMESHGUI_ScaleDlgLayout->setMargin(MARGIN);
128 /***************************************************************/
129 ConstructorsBox = new QGroupBox(tr("SMESH_SCALE"), this);
130 GroupConstructors = new QButtonGroup(this);
131 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
132 ConstructorsBoxLayout->setSpacing(SPACING);
133 ConstructorsBoxLayout->setMargin(MARGIN);
135 RadioButton1= new QRadioButton(ConstructorsBox);
136 RadioButton1->setIcon(image0);
137 RadioButton2= new QRadioButton(ConstructorsBox);
138 RadioButton2->setIcon(image1);
140 ConstructorsBoxLayout->addWidget(RadioButton1);
141 ConstructorsBoxLayout->addWidget(RadioButton2);
142 GroupConstructors->addButton(RadioButton1, 0);
143 GroupConstructors->addButton(RadioButton2, 1);
145 /***************************************************************/
146 GroupArguments = new QGroupBox(tr("SMESH_ARGUMENTS"), this);
147 QGridLayout* GroupArgumentsLayout = new QGridLayout(GroupArguments);
148 GroupArgumentsLayout->setSpacing(SPACING);
149 GroupArgumentsLayout->setMargin(MARGIN);
151 myIdValidator = new SMESHGUI_IdValidator(this);
153 // Controls for elements selection
154 TextLabelElements = new QLabel(tr("SMESH_ID_ELEMENTS"), GroupArguments);
155 SelectElementsButton = new QPushButton(GroupArguments);
156 SelectElementsButton->setIcon(image2);
157 LineEditElements = new QLineEdit(GroupArguments);
158 LineEditElements->setValidator(myIdValidator);
159 LineEditElements->setMaxLength(-1);
160 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
161 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
163 // Control for the whole mesh selection
164 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
166 // Controls for vector and points selection
167 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
168 SelectButton1 = new QPushButton(GroupArguments);
169 SelectButton1->setIcon(image2);
171 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
172 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
173 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
174 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
175 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
176 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
178 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
179 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
181 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
182 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
184 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
185 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
188 // switch of action type
189 ActionBox = new QGroupBox(GroupArguments);
190 ActionGroup = new QButtonGroup(GroupArguments);
191 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
192 ActionBoxLayout->addSpacing(SPACING);
193 ActionBoxLayout->setMargin(MARGIN);
195 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
196 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
197 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
199 ActionBoxLayout->addWidget(aMoveElements);
200 ActionBoxLayout->addWidget(aCopyElements);
201 ActionBoxLayout->addWidget(aCreateMesh);
202 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
203 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
204 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
206 // CheckBox for groups generation
207 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
208 MakeGroupsCheck->setChecked(false);
210 // Name of a mesh to create
211 LineEditNewMesh = new QLineEdit(GroupArguments);
214 myPreviewCheckBox = new QCheckBox(tr("PREVIEW"), GroupArguments);
217 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
218 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
219 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
220 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
221 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
222 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
223 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
224 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
225 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
226 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
227 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
228 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
229 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
230 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
231 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
232 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
233 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
234 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
235 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
236 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
237 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 8, 5, 1, 4);
238 GroupArgumentsLayout->addWidget(LineEditNewMesh, 9, 5, 1, 4);
239 GroupArgumentsLayout->addWidget(myPreviewCheckBox, 10, 0);
241 /***************************************************************/
242 GroupButtons = new QGroupBox(this);
243 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
244 GroupButtonsLayout->setSpacing(SPACING);
245 GroupButtonsLayout->setMargin(MARGIN);
247 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
248 buttonOk->setAutoDefault(true);
249 buttonOk->setDefault(true);
250 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
251 buttonApply->setAutoDefault(true);
252 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
253 buttonCancel->setAutoDefault(true);
254 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
255 buttonHelp->setAutoDefault(true);
257 GroupButtonsLayout->addWidget(buttonOk);
258 GroupButtonsLayout->addSpacing(10);
259 GroupButtonsLayout->addWidget(buttonApply);
260 GroupButtonsLayout->addSpacing(10);
261 GroupButtonsLayout->addStretch();
262 GroupButtonsLayout->addWidget(buttonCancel);
263 GroupButtonsLayout->addWidget(buttonHelp);
265 /***************************************************************/
266 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
267 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
268 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
270 /* Initialisations */
271 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
272 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
273 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
274 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
275 SpinBox_FX->SetStep(0.1);
276 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
277 SpinBox_FY->SetStep(0.1);
278 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
279 SpinBox_FZ->SetStep(0.1);
281 RadioButton1->setChecked(true);
283 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
285 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
287 // Costruction of the logical filter
288 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
291 QList<SUIT_SelectionFilter*> aListOfFilters;
292 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
293 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
295 myMeshOrSubMeshOrGroupFilter =
296 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
298 myHelpFileName = "scale_page.html";
302 /* signals and slots connections */
303 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
304 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
305 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
306 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
307 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
309 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
312 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
313 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
314 /* to close dialog if study change */
315 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
316 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
317 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
318 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
320 connect(SpinBox1_1, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
321 connect(SpinBox1_2, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
322 connect(SpinBox1_3, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
324 connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
325 connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
326 connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(toDisplaySimulation()));
328 //To Connect preview check box
329 connectPreviewControl();
331 ConstructorsClicked(0);
332 SelectionIntoArgument();
333 onActionClicked(MOVE_ELEMS_BUTTON);
336 //=================================================================================
337 // function : ~SMESHGUI_ScaleDlg()
338 // purpose : Destroys the object and frees any allocated resources
339 //=================================================================================
340 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
343 myFilterDlg->setParent( 0 );
349 //=================================================================================
352 //=================================================================================
353 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
357 myEditCurrentArgument = 0;
358 LineEditElements->clear();
362 buttonOk->setEnabled(false);
363 buttonApply->setEnabled(false);
366 myMesh = SMESH::SMESH_Mesh::_nil();
369 SpinBox1_1->SetValue(0.0);
370 SpinBox1_2->SetValue(0.0);
371 SpinBox1_3->SetValue(0.0);
372 SpinBox_FX->SetValue(1.0);
373 SpinBox_FY->SetValue(1.0);
374 SpinBox_FZ->SetValue(1.0);
375 myPreviewCheckBox->setChecked(false);
376 onDisplaySimulation(false);
378 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
379 CheckBoxMesh->setChecked(false);
384 //=================================================================================
385 // function : ConstructorsClicked()
386 // purpose : Radio button management
387 //=================================================================================
388 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
390 disconnect(mySelectionMgr, 0, this, 0);
392 switch (constructorId) {
395 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
404 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
413 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
414 SMESH::SetPointRepresentation(false);
415 if (!CheckBoxMesh->isChecked())
416 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
417 aViewWindow->SetSelectionMode( CellSelection );
420 myEditCurrentArgument = (QWidget*)LineEditElements;
421 LineEditElements->setFocus();
423 if (CheckBoxMesh->isChecked())
426 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
428 QApplication::instance()->processEvents();
433 //=================================================================================
434 // function : ClickOnApply()
436 //=================================================================================
437 bool SMESHGUI_ScaleDlg::ClickOnApply()
439 if (mySMESHGUI->isActiveStudyLocked())
445 if (myNbOkElements) {
446 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
448 SMESH::long_array_var anElementsId = new SMESH::long_array;
450 anElementsId->length(aListElementsId.count());
451 for (int i = 0; i < aListElementsId.count(); i++)
452 anElementsId[i] = aListElementsId[i].toInt();
454 SMESH::PointStruct aPoint;
455 SMESH::double_array_var aScaleFact = new SMESH::double_array;
456 getScale(aPoint, aScaleFact);
458 QStringList aParameters;
459 aParameters << SpinBox1_1->text();
460 aParameters << SpinBox1_2->text();
461 aParameters << SpinBox1_3->text();
462 aParameters << SpinBox_FX->text();
463 if (GetConstructorId() == 1) {
464 aParameters << SpinBox_FX->text();
465 aParameters << SpinBox_FX->text();
468 aParameters << SpinBox_FY->text();
469 aParameters << SpinBox_FZ->text();
472 int actionButton = ActionGroup->checkedId();
473 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
474 QStringList anEntryList;
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 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
509 anEntryList.append( aSObject->GetID().c_str() );
510 #ifdef WITHGENERICOBJ
511 // obj has been published in study. Its refcount has been incremented.
512 // It is safe to decrement its refcount
513 // so that it will be destroyed when the entry in study will be removed
524 if ( ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ) ||
525 actionButton == MAKE_MESH_BUTTON ) {
526 mySMESHGUI->updateObjBrowser(true); // new groups may appear
527 if( LightApp_Application* anApp =
528 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
529 anApp->browseObjects( anEntryList, isApplyAndClose() );
532 ConstructorsClicked(GetConstructorId());
533 mySelectedObject = SMESH::SMESH_IDSource::_nil();
534 SelectionIntoArgument();
536 SMESHGUI::Modified();
542 //=================================================================================
543 // function : ClickOnOk()
545 //=================================================================================
546 void SMESHGUI_ScaleDlg::ClickOnOk()
548 setIsApplyAndClose( true );
553 //=================================================================================
554 // function : ClickOnCancel()
556 //=================================================================================
557 void SMESHGUI_ScaleDlg::ClickOnCancel()
559 disconnect(mySelectionMgr, 0, this, 0);
560 mySelectionMgr->clearFilters();
561 //mySelectionMgr->clearSelected();
562 if (SMESH::GetCurrentVtkView()) {
563 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
564 SMESH::SetPointRepresentation(false);
566 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
567 aViewWindow->SetSelectionMode( ActorSelection );
568 mySMESHGUI->ResetState();
572 //=================================================================================
573 // function : ClickOnHelp()
575 //=================================================================================
576 void SMESHGUI_ScaleDlg::ClickOnHelp()
578 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
580 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
584 platform = "winapplication";
586 platform = "application";
588 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
589 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
590 arg(app->resourceMgr()->stringValue("ExternalBrowser",
592 arg(myHelpFileName));
596 //=======================================================================
597 // function : onTextChange()
599 //=======================================================================
600 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
602 QLineEdit* send = (QLineEdit*)sender();
605 BusyLocker lock( myBusy );
607 if (send == LineEditElements)
610 buttonOk->setEnabled(false);
611 buttonApply->setEnabled(false);
613 // hilight entered elements
614 SMDS_Mesh* aMesh = 0;
616 aMesh = myActor->GetObject()->GetMesh();
619 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
621 TColStd_MapOfInteger newIndices;
623 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
625 if (send == LineEditElements) {
626 for (int i = 0; i < aListId.count(); i++) {
627 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
629 newIndices.Add(e->GetID());
634 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
635 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
636 aViewWindow->highlight( anIO, true, true );
638 myElementsId = theNewText;
641 if (myNbOkElements) {
642 buttonOk->setEnabled(true);
643 buttonApply->setEnabled(true);
647 //=================================================================================
648 // function : SelectionIntoArgument()
649 // purpose : Called when selection as changed or other case
650 //=================================================================================
651 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
654 BusyLocker lock( myBusy );
657 QString aString = "";
659 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
660 LineEditElements->setText(aString);
662 buttonOk->setEnabled(false);
663 buttonApply->setEnabled(false);
666 if (!GroupButtons->isEnabled()) // inactive
671 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
673 int nbSel = aList.Extent();
677 Handle(SALOME_InteractiveObject) IO = aList.First();
678 myMesh = SMESH::GetMeshByIO(IO);
679 if (myMesh->_is_nil())
682 myActor = SMESH::FindActorByObject(myMesh);
684 myActor = SMESH::FindActorByEntry(IO->getEntry());
685 if (!myActor && !CheckBoxMesh->isChecked())
690 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
693 // MakeGroups is available if there are groups and "Copy"
694 if ( myMesh->NbGroups() == 0 ) {
695 MakeGroupsCheck->setChecked(false);
696 MakeGroupsCheck->setEnabled(false);
698 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
699 MakeGroupsCheck->setEnabled(true);
702 if (CheckBoxMesh->isChecked()) {
703 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
705 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
706 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
712 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
716 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
717 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
719 myElementsId += QString(" %1").arg(i);
723 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
725 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
727 // get IDs from submesh
728 SMESH::long_array_var anElementsIds = new SMESH::long_array;
729 anElementsIds = aSubMesh->GetElementsId();
730 for (int i = 0; i < anElementsIds->length(); i++) {
731 myElementsId += QString(" %1").arg(anElementsIds[i]);
733 aNbUnits = anElementsIds->length();
736 SMESH::SMESH_GroupBase_var aGroup =
737 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
738 if (aGroup->_is_nil())
741 // get IDs from smesh group
742 SMESH::long_array_var anElementsIds = new SMESH::long_array;
743 anElementsIds = aGroup->GetListOfID();
744 for (int i = 0; i < anElementsIds->length(); i++) {
745 myElementsId += QString(" %1").arg(anElementsIds[i]);
747 aNbUnits = anElementsIds->length();
751 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
752 myElementsId = aString;
757 myNbOkElements = true;
759 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
763 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
767 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
775 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
776 SpinBox1_1->SetValue(x);
777 SpinBox1_2->SetValue(y);
778 SpinBox1_3->SetValue(z);
780 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
781 SpinBox_FX->SetValue(x);
782 SpinBox_FY->SetValue(y);
783 SpinBox_FZ->SetValue(z);
787 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
788 LineEditElements->setText(aString);
789 LineEditElements->repaint();
790 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
791 LineEditElements->setEnabled(true);
796 if (myNbOkElements) {
797 buttonOk->setEnabled(true);
798 buttonApply->setEnabled(true);
801 onDisplaySimulation(true);
804 //=================================================================================
805 // function : SetEditCurrentArgument()
807 //=================================================================================
808 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
810 QPushButton* send = (QPushButton*)sender();
812 disconnect(mySelectionMgr, 0, this, 0);
813 mySelectionMgr->clearSelected();
814 mySelectionMgr->clearFilters();
816 if (send == SelectElementsButton) {
817 myEditCurrentArgument = (QWidget*)LineEditElements;
818 SMESH::SetPointRepresentation(false);
819 if (CheckBoxMesh->isChecked()) {
820 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
821 aViewWindow->SetSelectionMode( ActorSelection );
822 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
825 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
826 aViewWindow->SetSelectionMode( CellSelection );
829 else if (send == SelectButton1) {
830 myEditCurrentArgument = (QWidget*)SpinBox1_1;
831 SMESH::SetPointRepresentation(true);
832 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
833 aViewWindow->SetSelectionMode( NodeSelection );
836 myEditCurrentArgument->setFocus();
837 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
838 SelectionIntoArgument();
841 //=================================================================================
842 // function : DeactivateActiveDialog()
844 //=================================================================================
845 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
847 if (ConstructorsBox->isEnabled()) {
848 ConstructorsBox->setEnabled(false);
849 GroupArguments->setEnabled(false);
850 GroupButtons->setEnabled(false);
851 mySMESHGUI->ResetState();
852 mySMESHGUI->SetActiveDialogBox(0);
856 //=================================================================================
857 // function : ActivateThisDialog()
859 //=================================================================================
860 void SMESHGUI_ScaleDlg::ActivateThisDialog()
862 /* Emit a signal to deactivate the active dialog */
863 mySMESHGUI->EmitSignalDeactivateDialog();
864 ConstructorsBox->setEnabled(true);
865 GroupArguments->setEnabled(true);
866 GroupButtons->setEnabled(true);
868 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
870 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
871 aViewWindow->SetSelectionMode( CellSelection );
873 SelectionIntoArgument();
876 //=================================================================================
877 // function : enterEvent()
879 //=================================================================================
880 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
882 if (!ConstructorsBox->isEnabled())
883 ActivateThisDialog();
886 //=================================================================================
887 // function : closeEvent()
889 //=================================================================================
890 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
892 /* same than click on cancel button */
896 //=======================================================================
897 //function : hideEvent
898 //purpose : caused by ESC key
899 //=======================================================================
900 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
906 //=======================================================================
907 //function : onSelectMesh
909 //=======================================================================
910 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
913 TextLabelElements->setText(tr("SMESH_NAME"));
915 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
916 myFilterBtn->setEnabled(!toSelectMesh);
918 if (myEditCurrentArgument != LineEditElements) {
919 LineEditElements->clear();
923 mySelectionMgr->clearFilters();
924 SMESH::SetPointRepresentation(false);
927 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
928 aViewWindow->SetSelectionMode( ActorSelection );
929 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
930 LineEditElements->setReadOnly(true);
931 LineEditElements->setValidator(0);
933 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
934 aViewWindow->SetSelectionMode( CellSelection );
935 LineEditElements->setReadOnly(false);
936 LineEditElements->setValidator(myIdValidator);
937 onTextChange(LineEditElements->text());
941 SelectionIntoArgument();
944 //=======================================================================
945 //function : onActionClicked
946 //purpose : slot called when an action type changed
947 //=======================================================================
949 void SMESHGUI_ScaleDlg::onActionClicked(int button)
952 case MOVE_ELEMS_BUTTON:
953 MakeGroupsCheck->setEnabled(false);
954 LineEditNewMesh->setEnabled(false);
956 case COPY_ELEMS_BUTTON:
957 LineEditNewMesh->setEnabled(false);
958 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
959 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
960 MakeGroupsCheck->setEnabled(true);
962 MakeGroupsCheck->setEnabled(false);
964 case MAKE_MESH_BUTTON:
965 LineEditNewMesh->setEnabled(true);
966 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
967 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
968 MakeGroupsCheck->setEnabled(true);
970 MakeGroupsCheck->setEnabled(false);
974 toDisplaySimulation();
977 //=======================================================================
978 //function : setNewMeshName
979 //purpose : update contents of LineEditNewMesh
980 //=======================================================================
982 void SMESHGUI_ScaleDlg::setNewMeshName()
984 LineEditNewMesh->setText("");
985 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
987 if ( CheckBoxMesh->isChecked() ) {
988 name = LineEditElements->text();
991 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
992 name = meshSO->GetName().c_str();
994 if ( !name.isEmpty() )
995 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
999 //=================================================================================
1000 // function : GetConstructorId()
1002 //=================================================================================
1003 int SMESHGUI_ScaleDlg::GetConstructorId()
1005 return GroupConstructors->checkedId();
1008 //=================================================================================
1009 // function : keyPressEvent()
1011 //=================================================================================
1012 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1014 QDialog::keyPressEvent( e );
1015 if ( e->isAccepted() )
1018 if ( e->key() == Qt::Key_F1 ) {
1024 //=================================================================================
1025 // function : setFilters()
1026 // purpose : SLOT. Called when "Filter" button pressed.
1027 //=================================================================================
1028 void SMESHGUI_ScaleDlg::setFilters()
1030 if(myMesh->_is_nil()) {
1031 SUIT_MessageBox::critical(this,
1033 tr("NO_MESH_SELECTED"));
1037 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1039 myFilterDlg->SetSelection();
1040 myFilterDlg->SetMesh( myMesh );
1041 myFilterDlg->SetSourceWg( LineEditElements );
1043 myFilterDlg->show();
1046 //=================================================================================
1047 // function : isValid
1049 //=================================================================================
1050 bool SMESHGUI_ScaleDlg::isValid()
1055 ok = SpinBox1_1->isValid( msg, true ) && ok;
1056 ok = SpinBox1_2->isValid( msg, true ) && ok;
1057 ok = SpinBox1_3->isValid( msg, true ) && ok;
1058 ok = SpinBox_FX->isValid( msg, true ) && ok;
1059 if (GetConstructorId() == 1) {
1060 ok = SpinBox_FY->isValid( msg, true ) && ok;
1061 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1065 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1066 if ( !msg.isEmpty() )
1068 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1074 //=================================================================================
1075 // function : onDisplaySimulation
1076 // purpose : Show/Hide preview
1077 //=================================================================================
1078 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1079 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1080 if ( myNbOkElements && isValid() ) {
1081 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1083 SMESH::long_array_var anElementsId = new SMESH::long_array;
1085 anElementsId->length(aListElementsId.count());
1086 for (int i = 0; i < aListElementsId.count(); i++)
1087 anElementsId[i] = aListElementsId[i].toInt();
1089 SMESH::PointStruct aPoint;
1090 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1091 getScale(aPoint, aScaleFact);
1094 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1095 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1096 SUIT_OverrideCursor aWaitCursor;
1097 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1098 SMESH::SMESH_IDSource_var obj;
1099 if ( CheckBoxMesh->isChecked() )
1100 obj = mySelectedObject;
1102 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1103 aMeshEditor->Scale(obj, aPoint, aScaleFact, copy);
1105 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1106 mySimulation->SetData(aMeshPreviewStruct._retn());
1119 //=================================================================================
1120 // function : getScale
1121 // purpose : get scale parameters
1122 //=================================================================================
1123 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1124 thePoint.x = SpinBox1_1->GetValue();
1125 thePoint.y = SpinBox1_2->GetValue();
1126 thePoint.z = SpinBox1_3->GetValue();
1128 theScaleFact->length(3);
1129 theScaleFact[0] = SpinBox_FX->GetValue();
1130 if (GetConstructorId() == 0) {
1131 theScaleFact[1] = SpinBox_FX->GetValue();
1132 theScaleFact[2] = SpinBox_FX->GetValue();
1135 theScaleFact[1] = SpinBox_FY->GetValue();
1136 theScaleFact[2] = SpinBox_FZ->GetValue();