1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : SMESHGUI_ScaleDlg.cxx
20 // Author : Michael ZORIN, Open CASCADE S.A.S.
23 #include "SMESHGUI_ScaleDlg.h"
26 #include "SMESHGUI_SpinBox.h"
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESHGUI_MeshUtils.h"
30 #include "SMESHGUI_IdValidator.h"
31 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_MeshEditPreview.h"
34 #include <SMESH_Actor.h>
35 #include <SMESH_TypeFilter.hxx>
36 #include <SMESH_LogicalFilter.hxx>
37 #include <SMDS_Mesh.hxx>
39 // SALOME GUI includes
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ResourceMgr.h>
42 #include <SUIT_Session.h>
43 #include <SUIT_MessageBox.h>
44 #include <SUIT_OverrideCursor.h>
46 #include <LightApp_Application.h>
47 #include <LightApp_SelectionMgr.h>
49 #include <SVTK_ViewModel.h>
50 #include <SVTK_ViewWindow.h>
51 #include <SALOME_ListIO.hxx>
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 (SMESH::MESHorSUBMESH);
289 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (SMESH::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(reject()));
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(reject()));
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();
479 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
481 SMESH::SMESH_IDSource_var obj;
482 if ( CheckBoxMesh->isChecked() )
483 obj = mySelectedObject;
485 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
487 switch ( actionButton ) {
489 case MOVE_ELEMS_BUTTON:
490 aMeshEditor->Scale(obj, aPoint, aScaleFact, false);
493 case COPY_ELEMS_BUTTON:
495 SMESH::ListOfGroups_var groups =
496 aMeshEditor->ScaleMakeGroups(obj, aPoint, aScaleFact);
498 aMeshEditor->Scale(obj, aPoint, aScaleFact, true);
501 case MAKE_MESH_BUTTON: {
502 SMESH::SMESH_Mesh_var mesh =
503 aMeshEditor->ScaleMakeMesh(obj, aPoint, aScaleFact, makeGroups,
504 LineEditNewMesh->text().toLatin1().data());
505 if (!mesh->_is_nil()) {
506 if( _PTR(SObject) aSObject = SMESH::ObjectToSObject( mesh ) )
507 anEntryList.append( aSObject->GetID().c_str() );
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
525 if( LightApp_Application* anApp =
526 dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
527 anApp->browseObjects( anEntryList, isApplyAndClose() );
530 ConstructorsClicked(GetConstructorId());
531 mySelectedObject = SMESH::SMESH_IDSource::_nil();
532 SelectionIntoArgument();
534 SMESHGUI::Modified();
540 //=================================================================================
541 // function : ClickOnOk()
543 //=================================================================================
544 void SMESHGUI_ScaleDlg::ClickOnOk()
546 setIsApplyAndClose( true );
551 //=================================================================================
552 // function : reject()
554 //=================================================================================
555 void SMESHGUI_ScaleDlg::reject()
557 disconnect(mySelectionMgr, 0, this, 0);
558 mySelectionMgr->clearFilters();
559 //mySelectionMgr->clearSelected();
560 if (SMESH::GetCurrentVtkView()) {
561 SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
562 SMESH::SetPointRepresentation(false);
564 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
565 aViewWindow->SetSelectionMode( ActorSelection );
566 mySMESHGUI->ResetState();
570 //=================================================================================
571 // function : ClickOnHelp()
573 //=================================================================================
574 void SMESHGUI_ScaleDlg::ClickOnHelp()
576 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
578 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
582 platform = "winapplication";
584 platform = "application";
586 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
587 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
588 arg(app->resourceMgr()->stringValue("ExternalBrowser",
590 arg(myHelpFileName));
594 //=======================================================================
595 // function : onTextChange()
597 //=======================================================================
598 void SMESHGUI_ScaleDlg::onTextChange (const QString& theNewText)
600 QLineEdit* send = (QLineEdit*)sender();
603 BusyLocker lock( myBusy );
605 if (send == LineEditElements)
608 buttonOk->setEnabled(false);
609 buttonApply->setEnabled(false);
611 // hilight entered elements
612 SMDS_Mesh* aMesh = 0;
614 aMesh = myActor->GetObject()->GetMesh();
617 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
619 TColStd_MapOfInteger newIndices;
621 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
623 if (send == LineEditElements) {
624 for (int i = 0; i < aListId.count(); i++) {
625 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
627 newIndices.Add(e->GetID());
632 mySelector->AddOrRemoveIndex( anIO, newIndices, false );
633 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
634 aViewWindow->highlight( anIO, true, true );
636 myElementsId = theNewText;
639 if (myNbOkElements) {
640 buttonOk->setEnabled(true);
641 buttonApply->setEnabled(true);
645 //=================================================================================
646 // function : SelectionIntoArgument()
647 // purpose : Called when selection as changed or other case
648 //=================================================================================
649 void SMESHGUI_ScaleDlg::SelectionIntoArgument()
652 BusyLocker lock( myBusy );
655 QString aString = "";
657 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
658 LineEditElements->setText(aString);
660 buttonOk->setEnabled(false);
661 buttonApply->setEnabled(false);
664 if (!GroupButtons->isEnabled()) // inactive
669 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
671 int nbSel = aList.Extent();
675 Handle(SALOME_InteractiveObject) IO = aList.First();
676 myMesh = SMESH::GetMeshByIO(IO);
677 if (myMesh->_is_nil())
680 myActor = SMESH::FindActorByObject(myMesh);
682 myActor = SMESH::FindActorByEntry(IO->getEntry());
683 if (!myActor && !CheckBoxMesh->isChecked())
688 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
691 // MakeGroups is available if there are groups and "Copy"
692 if ( myMesh->NbGroups() == 0 ) {
693 MakeGroupsCheck->setChecked(false);
694 MakeGroupsCheck->setEnabled(false);
696 else if ( ActionGroup->checkedId() != MOVE_ELEMS_BUTTON ) {
697 MakeGroupsCheck->setEnabled(true);
700 if (CheckBoxMesh->isChecked()) {
701 SMESH::GetNameOfSelectedIObjects( mySelectionMgr, aString );
703 if (!SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO)->_is_nil()) { //MESH, SUBMESH, OR GROUP
704 mySelectedObject = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
710 SMDS_Mesh* aSMDSMesh = myActor->GetObject()->GetMesh();
714 for (int i = aSMDSMesh->MinElementID(); i <= aSMDSMesh->MaxElementID(); i++) {
715 const SMDS_MeshElement * e = aSMDSMesh->FindElement(i);
717 myElementsId += QString(" %1").arg(i);
721 } else if (!SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO)->_is_nil()) { //SUBMESH
723 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(IO);
725 // get IDs from submesh
726 SMESH::long_array_var anElementsIds = new SMESH::long_array;
727 anElementsIds = aSubMesh->GetElementsId();
728 for (int i = 0; i < anElementsIds->length(); i++) {
729 myElementsId += QString(" %1").arg(anElementsIds[i]);
731 aNbUnits = anElementsIds->length();
734 SMESH::SMESH_GroupBase_var aGroup =
735 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
736 if (aGroup->_is_nil())
739 // get IDs from smesh group
740 SMESH::long_array_var anElementsIds = new SMESH::long_array;
741 anElementsIds = aGroup->GetListOfID();
742 for (int i = 0; i < anElementsIds->length(); i++) {
743 myElementsId += QString(" %1").arg(anElementsIds[i]);
745 aNbUnits = anElementsIds->length();
749 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
750 myElementsId = aString;
755 myNbOkElements = true;
757 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
761 SMDS_Mesh* aMesh = myActor->GetObject()->GetMesh();
765 const SMDS_MeshNode * n = aMesh->FindNode(aString.toInt());
773 if (myEditCurrentArgument == (QWidget*)SpinBox1_1) {
774 SpinBox1_1->SetValue(x);
775 SpinBox1_2->SetValue(y);
776 SpinBox1_3->SetValue(z);
778 else if (myEditCurrentArgument == (QWidget*)SpinBox_FX) {
779 SpinBox_FX->SetValue(x);
780 SpinBox_FY->SetValue(y);
781 SpinBox_FZ->SetValue(z);
785 if (myEditCurrentArgument == (QWidget*)LineEditElements) {
786 LineEditElements->setText(aString);
787 LineEditElements->repaint();
788 LineEditElements->setEnabled(false); // to fully update lineedit IPAL 19809
789 LineEditElements->setEnabled(true);
794 if (myNbOkElements) {
795 buttonOk->setEnabled(true);
796 buttonApply->setEnabled(true);
799 onDisplaySimulation(true);
802 //=================================================================================
803 // function : SetEditCurrentArgument()
805 //=================================================================================
806 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
808 QPushButton* send = (QPushButton*)sender();
810 disconnect(mySelectionMgr, 0, this, 0);
811 mySelectionMgr->clearSelected();
812 mySelectionMgr->clearFilters();
814 if (send == SelectElementsButton) {
815 myEditCurrentArgument = (QWidget*)LineEditElements;
816 SMESH::SetPointRepresentation(false);
817 if (CheckBoxMesh->isChecked()) {
818 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
819 aViewWindow->SetSelectionMode( ActorSelection );
820 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
823 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824 aViewWindow->SetSelectionMode( CellSelection );
827 else if (send == SelectButton1) {
828 myEditCurrentArgument = (QWidget*)SpinBox1_1;
829 SMESH::SetPointRepresentation(true);
830 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831 aViewWindow->SetSelectionMode( NodeSelection );
834 myEditCurrentArgument->setFocus();
835 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
836 SelectionIntoArgument();
839 //=================================================================================
840 // function : DeactivateActiveDialog()
842 //=================================================================================
843 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
845 if (ConstructorsBox->isEnabled()) {
846 ConstructorsBox->setEnabled(false);
847 GroupArguments->setEnabled(false);
848 GroupButtons->setEnabled(false);
849 mySMESHGUI->ResetState();
850 mySMESHGUI->SetActiveDialogBox(0);
854 //=================================================================================
855 // function : ActivateThisDialog()
857 //=================================================================================
858 void SMESHGUI_ScaleDlg::ActivateThisDialog()
860 /* Emit a signal to deactivate the active dialog */
861 mySMESHGUI->EmitSignalDeactivateDialog();
862 ConstructorsBox->setEnabled(true);
863 GroupArguments->setEnabled(true);
864 GroupButtons->setEnabled(true);
866 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
868 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
869 aViewWindow->SetSelectionMode( CellSelection );
871 SelectionIntoArgument();
874 //=================================================================================
875 // function : enterEvent()
877 //=================================================================================
878 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
880 if (!ConstructorsBox->isEnabled())
881 ActivateThisDialog();
884 //=======================================================================
885 //function : onSelectMesh
887 //=======================================================================
888 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
891 TextLabelElements->setText(tr("SMESH_NAME"));
893 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
894 myFilterBtn->setEnabled(!toSelectMesh);
896 if (myEditCurrentArgument != LineEditElements) {
897 LineEditElements->clear();
901 mySelectionMgr->clearFilters();
902 SMESH::SetPointRepresentation(false);
905 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
906 aViewWindow->SetSelectionMode( ActorSelection );
907 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
908 LineEditElements->setReadOnly(true);
909 LineEditElements->setValidator(0);
911 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
912 aViewWindow->SetSelectionMode( CellSelection );
913 LineEditElements->setReadOnly(false);
914 LineEditElements->setValidator(myIdValidator);
915 onTextChange(LineEditElements->text());
919 SelectionIntoArgument();
922 //=======================================================================
923 //function : onActionClicked
924 //purpose : slot called when an action type changed
925 //=======================================================================
927 void SMESHGUI_ScaleDlg::onActionClicked(int button)
930 case MOVE_ELEMS_BUTTON:
931 MakeGroupsCheck->setEnabled(false);
932 LineEditNewMesh->setEnabled(false);
934 case COPY_ELEMS_BUTTON:
935 LineEditNewMesh->setEnabled(false);
936 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
937 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
938 MakeGroupsCheck->setEnabled(true);
940 MakeGroupsCheck->setEnabled(false);
942 case MAKE_MESH_BUTTON:
943 LineEditNewMesh->setEnabled(true);
944 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
945 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
946 MakeGroupsCheck->setEnabled(true);
948 MakeGroupsCheck->setEnabled(false);
952 toDisplaySimulation();
955 //=======================================================================
956 //function : setNewMeshName
957 //purpose : update contents of LineEditNewMesh
958 //=======================================================================
960 void SMESHGUI_ScaleDlg::setNewMeshName()
962 LineEditNewMesh->setText("");
963 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
965 if ( CheckBoxMesh->isChecked() ) {
966 name = LineEditElements->text();
969 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
970 name = meshSO->GetName().c_str();
972 if ( !name.isEmpty() )
973 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
977 //=================================================================================
978 // function : GetConstructorId()
980 //=================================================================================
981 int SMESHGUI_ScaleDlg::GetConstructorId()
983 return GroupConstructors->checkedId();
986 //=================================================================================
987 // function : keyPressEvent()
989 //=================================================================================
990 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
992 QDialog::keyPressEvent( e );
993 if ( e->isAccepted() )
996 if ( e->key() == Qt::Key_F1 ) {
1002 //=================================================================================
1003 // function : setFilters()
1004 // purpose : SLOT. Called when "Filter" button pressed.
1005 //=================================================================================
1006 void SMESHGUI_ScaleDlg::setFilters()
1008 if(myMesh->_is_nil()) {
1009 SUIT_MessageBox::critical(this,
1011 tr("NO_MESH_SELECTED"));
1015 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1017 myFilterDlg->SetSelection();
1018 myFilterDlg->SetMesh( myMesh );
1019 myFilterDlg->SetSourceWg( LineEditElements );
1021 myFilterDlg->show();
1024 //=================================================================================
1025 // function : isValid
1027 //=================================================================================
1028 bool SMESHGUI_ScaleDlg::isValid()
1033 ok = SpinBox1_1->isValid( msg, true ) && ok;
1034 ok = SpinBox1_2->isValid( msg, true ) && ok;
1035 ok = SpinBox1_3->isValid( msg, true ) && ok;
1036 ok = SpinBox_FX->isValid( msg, true ) && ok;
1037 if (GetConstructorId() == 1) {
1038 ok = SpinBox_FY->isValid( msg, true ) && ok;
1039 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1043 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1044 if ( !msg.isEmpty() )
1046 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );
1052 //=================================================================================
1053 // function : onDisplaySimulation
1054 // purpose : Show/Hide preview
1055 //=================================================================================
1056 void SMESHGUI_ScaleDlg::onDisplaySimulation( bool toDisplayPreview ) {
1057 if (myPreviewCheckBox->isChecked() && toDisplayPreview) {
1058 if ( myNbOkElements && isValid() ) {
1059 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
1061 SMESH::long_array_var anElementsId = new SMESH::long_array;
1063 anElementsId->length(aListElementsId.count());
1064 for (int i = 0; i < aListElementsId.count(); i++)
1065 anElementsId[i] = aListElementsId[i].toInt();
1067 SMESH::PointStruct aPoint;
1068 SMESH::double_array_var aScaleFact = new SMESH::double_array;
1069 getScale(aPoint, aScaleFact);
1072 bool copy = ( ActionGroup->checkedId() == COPY_ELEMS_BUTTON ||
1073 ActionGroup->checkedId() == MAKE_MESH_BUTTON );
1074 SUIT_OverrideCursor aWaitCursor;
1075 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditPreviewer();
1076 SMESH::SMESH_IDSource_var obj;
1077 if ( CheckBoxMesh->isChecked() )
1078 obj = mySelectedObject;
1080 obj = aMeshEditor->MakeIDSource(anElementsId, SMESH::ALL);
1081 aMeshEditor->Scale(obj, aPoint, aScaleFact, copy);
1083 SMESH::MeshPreviewStruct_var aMeshPreviewStruct = aMeshEditor->GetPreviewData();
1084 mySimulation->SetData(aMeshPreviewStruct._retn());
1097 //=================================================================================
1098 // function : getScale
1099 // purpose : get scale parameters
1100 //=================================================================================
1101 void SMESHGUI_ScaleDlg::getScale( SMESH::PointStruct& thePoint , SMESH::double_array_var& theScaleFact) {
1102 thePoint.x = SpinBox1_1->GetValue();
1103 thePoint.y = SpinBox1_2->GetValue();
1104 thePoint.z = SpinBox1_3->GetValue();
1106 theScaleFact->length(3);
1107 theScaleFact[0] = SpinBox_FX->GetValue();
1108 if (GetConstructorId() == 0) {
1109 theScaleFact[1] = SpinBox_FX->GetValue();
1110 theScaleFact[2] = SpinBox_FX->GetValue();
1113 theScaleFact[1] = SpinBox_FY->GetValue();
1114 theScaleFact[2] = SpinBox_FZ->GetValue();