1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ScaleDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_ScaleDlg.h"
30 #include "SMESHGUI_SpinBox.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_MeshUtils.h"
34 #include "SMESHGUI_IdValidator.h"
35 #include "SMESHGUI_FilterDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_TypeFilter.hxx>
39 #include <SMESH_LogicalFilter.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GUI includes
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ResourceMgr.h>
45 #include <SUIT_Session.h>
46 #include <SUIT_MessageBox.h>
47 #include <SUIT_OverrideCursor.h>
49 #include <LightApp_Application.h>
50 #include <LightApp_SelectionMgr.h>
52 #include <SVTK_ViewModel.h>
53 #include <SVTK_ViewWindow.h>
54 #include <SALOME_ListIO.hxx>
56 // SALOME KERNEL includes
57 #include <SALOMEDSClient_SObject.hxx>
60 #include <TColStd_MapOfInteger.hxx>
63 #include <QApplication>
64 #include <QButtonGroup>
68 #include <QPushButton>
69 #include <QRadioButton>
71 #include <QHBoxLayout>
72 #include <QVBoxLayout>
73 #include <QGridLayout>
78 #include <SALOMEconfig.h>
79 #include CORBA_SERVER_HEADER(SMESH_Group)
80 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
82 enum { MOVE_ELEMS_BUTTON = 0, COPY_ELEMS_BUTTON, MAKE_MESH_BUTTON }; //!< action type
86 \brief Simple 'busy state' flag locker.
93 //! Constructor. Sets passed boolean flag to \c true.
94 BusyLocker( bool& busy ) : myBusy( busy ) { myBusy = true; }
95 //! Destructor. Clear external boolean flag passed as parameter to the constructor to \c false.
96 ~BusyLocker() { myBusy = false; }
98 bool& myBusy; //! External 'busy state' boolean flag
104 //=================================================================================
105 // class : SMESHGUI_ScaleDlg()
107 //=================================================================================
108 SMESHGUI_ScaleDlg::SMESHGUI_ScaleDlg( SMESHGUI* theModule )
109 : QDialog( SMESH::GetDesktop( theModule ) ),
110 mySMESHGUI( 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 myFilterBtn = new QPushButton( tr( "SMESH_BUT_FILTER" ), GroupArguments );
160 connect(myFilterBtn, SIGNAL(clicked()), this, SLOT(setFilters()));
162 // Control for the whole mesh selection
163 CheckBoxMesh = new QCheckBox(tr("SMESH_SELECT_WHOLE_MESH"), GroupArguments);
165 // Controls for vector and points selection
166 TextLabel1 = new QLabel(tr("SMESH_BASE_POINT"), GroupArguments);
167 SelectButton1 = new QPushButton(GroupArguments);
168 SelectButton1->setIcon(image2);
170 TextLabel1_1 = new QLabel(tr("SMESH_X"), GroupArguments);
171 SpinBox1_1 = new SMESHGUI_SpinBox(GroupArguments);
172 TextLabel1_2 = new QLabel(tr("SMESH_Y"), GroupArguments);
173 SpinBox1_2 = new SMESHGUI_SpinBox(GroupArguments);
174 TextLabel1_3 = new QLabel(tr("SMESH_Z"), GroupArguments);
175 SpinBox1_3 = new SMESHGUI_SpinBox(GroupArguments);
177 TextLabel2 = new QLabel(tr("SMESH_SCALE_FACTOR"), GroupArguments);
178 SpinBox_FX = new SMESHGUI_SpinBox(GroupArguments);
180 TextLabel3 = new QLabel(tr("SMESH_SCALE_FACTOR_Y"), GroupArguments);
181 SpinBox_FY = new SMESHGUI_SpinBox(GroupArguments);
183 TextLabel4 = new QLabel(tr("SMESH_SCALE_FACTOR_Z"), GroupArguments);
184 SpinBox_FZ = new SMESHGUI_SpinBox(GroupArguments);
187 // switch of action type
188 ActionBox = new QGroupBox(GroupArguments);
189 ActionGroup = new QButtonGroup(GroupArguments);
190 QVBoxLayout* ActionBoxLayout = new QVBoxLayout(ActionBox);
191 ActionBoxLayout->addSpacing(SPACING);
192 ActionBoxLayout->setMargin(MARGIN);
194 QRadioButton* aMoveElements = new QRadioButton(tr("SMESH_MOVE_ELEMENTS"), ActionBox);
195 QRadioButton* aCopyElements = new QRadioButton(tr("SMESH_COPY_ELEMENTS"), ActionBox);
196 QRadioButton* aCreateMesh = new QRadioButton(tr("SMESH_CREATE_MESH"), ActionBox);
198 ActionBoxLayout->addWidget(aMoveElements);
199 ActionBoxLayout->addWidget(aCopyElements);
200 ActionBoxLayout->addWidget(aCreateMesh);
201 ActionGroup->addButton(aMoveElements, MOVE_ELEMS_BUTTON);
202 ActionGroup->addButton(aCopyElements, COPY_ELEMS_BUTTON);
203 ActionGroup->addButton(aCreateMesh, MAKE_MESH_BUTTON);
205 // CheckBox for groups generation
206 MakeGroupsCheck = new QCheckBox(tr("SMESH_MAKE_GROUPS"), GroupArguments);
207 MakeGroupsCheck->setChecked(false);
209 // Name of a mesh to create
210 LineEditNewMesh = new QLineEdit(GroupArguments);
213 GroupArgumentsLayout->addWidget(TextLabelElements, 0, 0);
214 GroupArgumentsLayout->addWidget(SelectElementsButton, 0, 1);
215 GroupArgumentsLayout->addWidget(LineEditElements, 0, 2, 1, 5);
216 GroupArgumentsLayout->addWidget(myFilterBtn, 0, 7);
217 GroupArgumentsLayout->addWidget(CheckBoxMesh, 1, 0, 1, 8);
218 GroupArgumentsLayout->addWidget(TextLabel1, 2, 0);
219 GroupArgumentsLayout->addWidget(SelectButton1, 2, 1);
220 GroupArgumentsLayout->addWidget(TextLabel1_1, 2, 2);
221 GroupArgumentsLayout->addWidget(SpinBox1_1, 2, 3);
222 GroupArgumentsLayout->addWidget(TextLabel1_2, 2, 4);
223 GroupArgumentsLayout->addWidget(SpinBox1_2, 2, 5);
224 GroupArgumentsLayout->addWidget(TextLabel1_3, 2, 6);
225 GroupArgumentsLayout->addWidget(SpinBox1_3, 2, 7);
226 GroupArgumentsLayout->addWidget(TextLabel2, 3, 0);
227 GroupArgumentsLayout->addWidget(SpinBox_FX, 3, 3);
228 GroupArgumentsLayout->addWidget(TextLabel3, 4, 0);
229 GroupArgumentsLayout->addWidget(SpinBox_FY, 4, 3);
230 GroupArgumentsLayout->addWidget(TextLabel4, 5, 0);
231 GroupArgumentsLayout->addWidget(SpinBox_FZ, 5, 3);
232 GroupArgumentsLayout->addWidget(ActionBox, 7, 0, 3, 4);
233 GroupArgumentsLayout->addWidget(MakeGroupsCheck, 7, 5, 1, 4);
234 GroupArgumentsLayout->addWidget(LineEditNewMesh, 8, 5, 1, 4);
236 /***************************************************************/
237 GroupButtons = new QGroupBox(this);
238 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
239 GroupButtonsLayout->setSpacing(SPACING);
240 GroupButtonsLayout->setMargin(MARGIN);
242 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
243 buttonOk->setAutoDefault(true);
244 buttonOk->setDefault(true);
245 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
246 buttonApply->setAutoDefault(true);
247 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
248 buttonCancel->setAutoDefault(true);
249 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
250 buttonHelp->setAutoDefault(true);
252 GroupButtonsLayout->addWidget(buttonOk);
253 GroupButtonsLayout->addSpacing(10);
254 GroupButtonsLayout->addWidget(buttonApply);
255 GroupButtonsLayout->addSpacing(10);
256 GroupButtonsLayout->addStretch();
257 GroupButtonsLayout->addWidget(buttonCancel);
258 GroupButtonsLayout->addWidget(buttonHelp);
260 /***************************************************************/
261 SMESHGUI_ScaleDlgLayout->addWidget(ConstructorsBox);
262 SMESHGUI_ScaleDlgLayout->addWidget(GroupArguments);
263 SMESHGUI_ScaleDlgLayout->addWidget(GroupButtons);
265 /* Initialisations */
266 SpinBox1_1->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
267 SpinBox1_2->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
268 SpinBox1_3->RangeStepAndValidator(COORD_MIN, COORD_MAX, 10.0, "length_precision");
269 SpinBox_FX->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
270 SpinBox_FX->SetStep(0.1);
271 SpinBox_FY->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
272 SpinBox_FY->SetStep(0.1);
273 SpinBox_FZ->RangeStepAndValidator(1.e-6, 1.e+6, 1.0, "parametric_precision");
274 SpinBox_FZ->SetStep(0.1);
276 RadioButton1->setChecked(true);
278 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
280 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
282 // Costruction of the logical filter
283 SMESH_TypeFilter* aMeshOrSubMeshFilter = new SMESH_TypeFilter (MESHorSUBMESH);
284 SMESH_TypeFilter* aSmeshGroupFilter = new SMESH_TypeFilter (GROUP);
286 QList<SUIT_SelectionFilter*> aListOfFilters;
287 if (aMeshOrSubMeshFilter) aListOfFilters.append(aMeshOrSubMeshFilter);
288 if (aSmeshGroupFilter) aListOfFilters.append(aSmeshGroupFilter);
290 myMeshOrSubMeshOrGroupFilter =
291 new SMESH_LogicalFilter(aListOfFilters, SMESH_LogicalFilter::LO_OR);
293 myHelpFileName = "scale_page.html";
297 /* signals and slots connections */
298 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
299 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
300 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
301 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
302 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
304 connect(SelectElementsButton, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
305 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
307 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
308 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
309 /* to close dialog if study change */
310 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
311 connect(LineEditElements, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(CheckBoxMesh, SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
313 connect(ActionGroup, SIGNAL(buttonClicked(int)), SLOT(onActionClicked(int)));
315 ConstructorsClicked(0);
316 SelectionIntoArgument();
317 onActionClicked(MOVE_ELEMS_BUTTON);
320 //=================================================================================
321 // function : ~SMESHGUI_ScaleDlg()
322 // purpose : Destroys the object and frees any allocated resources
323 //=================================================================================
324 SMESHGUI_ScaleDlg::~SMESHGUI_ScaleDlg()
327 myFilterDlg->setParent( 0 );
333 //=================================================================================
336 //=================================================================================
337 void SMESHGUI_ScaleDlg::Init (bool ResetControls)
341 myEditCurrentArgument = 0;
342 LineEditElements->clear();
346 buttonOk->setEnabled(false);
347 buttonApply->setEnabled(false);
350 myMesh = SMESH::SMESH_Mesh::_nil();
353 SpinBox1_1->SetValue(0.0);
354 SpinBox1_2->SetValue(0.0);
355 SpinBox1_3->SetValue(0.0);
356 SpinBox_FX->SetValue(1.0);
357 SpinBox_FY->SetValue(1.0);
358 SpinBox_FZ->SetValue(1.0);
360 ActionGroup->button( MOVE_ELEMS_BUTTON )->setChecked(true);
361 CheckBoxMesh->setChecked(false);
366 //=================================================================================
367 // function : ConstructorsClicked()
368 // purpose : Radio button management
369 //=================================================================================
370 void SMESHGUI_ScaleDlg::ConstructorsClicked (int constructorId)
372 disconnect(mySelectionMgr, 0, this, 0);
374 switch (constructorId) {
377 TextLabel2->setText(tr("SMESH_SCALE_FACTOR"));
386 TextLabel2->setText(tr("SMESH_SCALE_FACTOR_X"));
395 if (myEditCurrentArgument != (QWidget*)LineEditElements) {
396 SMESH::SetPointRepresentation(false);
397 if (!CheckBoxMesh->isChecked())
398 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
399 aViewWindow->SetSelectionMode( CellSelection );
402 myEditCurrentArgument = (QWidget*)LineEditElements;
403 LineEditElements->setFocus();
405 if (CheckBoxMesh->isChecked())
408 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
410 QApplication::instance()->processEvents();
415 //=================================================================================
416 // function : ClickOnApply()
418 //=================================================================================
419 bool SMESHGUI_ScaleDlg::ClickOnApply()
421 if (mySMESHGUI->isActiveStudyLocked())
427 if (myNbOkElements) {
428 QStringList aListElementsId = myElementsId.split(" ", QString::SkipEmptyParts);
430 SMESH::long_array_var anElementsId = new SMESH::long_array;
432 anElementsId->length(aListElementsId.count());
433 for (int i = 0; i < aListElementsId.count(); i++)
434 anElementsId[i] = aListElementsId[i].toInt();
436 SMESH::PointStruct aPoint;
437 aPoint.x = SpinBox1_1->GetValue();
438 aPoint.y = SpinBox1_2->GetValue();
439 aPoint.z = SpinBox1_3->GetValue();
440 SMESH::double_array_var aScaleFact = new SMESH::double_array;
441 aScaleFact->length(3);
442 aScaleFact[0] = SpinBox_FX->GetValue();
443 if (GetConstructorId() == 0) {
444 aScaleFact[1] = SpinBox_FX->GetValue();
445 aScaleFact[2] = SpinBox_FX->GetValue();
448 aScaleFact[1] = SpinBox_FY->GetValue();
449 aScaleFact[2] = SpinBox_FZ->GetValue();
452 QStringList aParameters;
453 aParameters << SpinBox1_1->text();
454 aParameters << SpinBox1_2->text();
455 aParameters << SpinBox1_3->text();
456 aParameters << SpinBox_FX->text();
457 if (GetConstructorId() == 1) {
458 aParameters << SpinBox_FX->text();
459 aParameters << SpinBox_FX->text();
462 aParameters << SpinBox_FY->text();
463 aParameters << SpinBox_FZ->text();
466 int actionButton = ActionGroup->checkedId();
467 bool makeGroups = ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() );
469 SUIT_OverrideCursor aWaitCursor;
470 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
471 switch ( actionButton ) {
472 case MOVE_ELEMS_BUTTON:
473 if(CheckBoxMesh->isChecked()) {
474 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, false);
477 SMESH::SMESH_IDSource_ptr anObj = aMeshEditor->MakeIDSource(anElementsId);
478 aMeshEditor->Scale(anObj, aPoint, aScaleFact, false);
480 if( !myMesh->_is_nil())
481 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
483 case COPY_ELEMS_BUTTON:
485 SMESH::ListOfGroups_var groups;
486 if(CheckBoxMesh->isChecked()) {
487 groups = aMeshEditor->ScaleMakeGroups(mySelectedObject, aPoint, aScaleFact);
490 groups = aMeshEditor->ScaleMakeGroups(aMeshEditor->MakeIDSource(anElementsId),
495 if(CheckBoxMesh->isChecked()) {
496 aMeshEditor->Scale(mySelectedObject, aPoint, aScaleFact, true);
499 aMeshEditor->Scale(aMeshEditor->MakeIDSource(anElementsId),
500 aPoint, aScaleFact, true);
503 if( !myMesh->_is_nil())
504 myMesh->SetParameters( aParameters.join(":").toLatin1().constData() );
506 case MAKE_MESH_BUTTON:
507 SMESH::SMESH_Mesh_var mesh;
508 if(CheckBoxMesh->isChecked()) {
509 mesh = aMeshEditor->ScaleMakeMesh(mySelectedObject, aPoint, aScaleFact, makeGroups,
510 LineEditNewMesh->text().toLatin1().data());
513 mesh = aMeshEditor->ScaleMakeMesh(aMeshEditor->MakeIDSource(anElementsId),
514 aPoint, aScaleFact, makeGroups,
515 LineEditNewMesh->text().toLatin1().data());
517 if( !mesh->_is_nil())
518 mesh->SetParameters( aParameters.join(":").toLatin1().constData() );
524 if ( MakeGroupsCheck->isEnabled() && MakeGroupsCheck->isChecked() ||
525 actionButton == MAKE_MESH_BUTTON )
526 mySMESHGUI->updateObjBrowser(true); // new groups may appear
528 ConstructorsClicked(GetConstructorId());
529 mySelectedObject = SMESH::SMESH_IDSource::_nil();
530 SelectionIntoArgument();
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());
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);
795 //=================================================================================
796 // function : SetEditCurrentArgument()
798 //=================================================================================
799 void SMESHGUI_ScaleDlg::SetEditCurrentArgument()
801 QPushButton* send = (QPushButton*)sender();
803 disconnect(mySelectionMgr, 0, this, 0);
804 mySelectionMgr->clearSelected();
805 mySelectionMgr->clearFilters();
807 if (send == SelectElementsButton) {
808 myEditCurrentArgument = (QWidget*)LineEditElements;
809 SMESH::SetPointRepresentation(false);
810 if (CheckBoxMesh->isChecked()) {
811 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
812 aViewWindow->SetSelectionMode( ActorSelection );
813 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
816 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817 aViewWindow->SetSelectionMode( CellSelection );
820 else if (send == SelectButton1) {
821 myEditCurrentArgument = (QWidget*)SpinBox1_1;
822 SMESH::SetPointRepresentation(true);
823 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
824 aViewWindow->SetSelectionMode( NodeSelection );
827 myEditCurrentArgument->setFocus();
828 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
829 SelectionIntoArgument();
832 //=================================================================================
833 // function : DeactivateActiveDialog()
835 //=================================================================================
836 void SMESHGUI_ScaleDlg::DeactivateActiveDialog()
838 if (ConstructorsBox->isEnabled()) {
839 ConstructorsBox->setEnabled(false);
840 GroupArguments->setEnabled(false);
841 GroupButtons->setEnabled(false);
842 mySMESHGUI->ResetState();
843 mySMESHGUI->SetActiveDialogBox(0);
847 //=================================================================================
848 // function : ActivateThisDialog()
850 //=================================================================================
851 void SMESHGUI_ScaleDlg::ActivateThisDialog()
853 /* Emit a signal to deactivate the active dialog */
854 mySMESHGUI->EmitSignalDeactivateDialog();
855 ConstructorsBox->setEnabled(true);
856 GroupArguments->setEnabled(true);
857 GroupButtons->setEnabled(true);
859 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
861 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
862 aViewWindow->SetSelectionMode( CellSelection );
864 SelectionIntoArgument();
867 //=================================================================================
868 // function : enterEvent()
870 //=================================================================================
871 void SMESHGUI_ScaleDlg::enterEvent (QEvent*)
873 if (!ConstructorsBox->isEnabled())
874 ActivateThisDialog();
877 //=================================================================================
878 // function : closeEvent()
880 //=================================================================================
881 void SMESHGUI_ScaleDlg::closeEvent (QCloseEvent*)
883 /* same than click on cancel button */
887 //=======================================================================
888 //function : hideEvent
889 //purpose : caused by ESC key
890 //=======================================================================
891 void SMESHGUI_ScaleDlg::hideEvent (QHideEvent*)
897 //=======================================================================
898 //function : onSelectMesh
900 //=======================================================================
901 void SMESHGUI_ScaleDlg::onSelectMesh (bool toSelectMesh)
904 TextLabelElements->setText(tr("SMESH_NAME"));
906 TextLabelElements->setText(tr("SMESH_ID_ELEMENTS"));
907 myFilterBtn->setEnabled(!toSelectMesh);
909 if (myEditCurrentArgument != LineEditElements) {
910 LineEditElements->clear();
914 mySelectionMgr->clearFilters();
915 SMESH::SetPointRepresentation(false);
918 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
919 aViewWindow->SetSelectionMode( ActorSelection );
920 mySelectionMgr->installFilter(myMeshOrSubMeshOrGroupFilter);
921 LineEditElements->setReadOnly(true);
922 LineEditElements->setValidator(0);
924 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
925 aViewWindow->SetSelectionMode( CellSelection );
926 LineEditElements->setReadOnly(false);
927 LineEditElements->setValidator(myIdValidator);
928 onTextChange(LineEditElements->text());
931 SelectionIntoArgument();
934 //=======================================================================
935 //function : onActionClicked
936 //purpose : slot called when an action type changed
937 //=======================================================================
939 void SMESHGUI_ScaleDlg::onActionClicked(int button)
942 case MOVE_ELEMS_BUTTON:
943 MakeGroupsCheck->setEnabled(false);
944 LineEditNewMesh->setEnabled(false);
946 case COPY_ELEMS_BUTTON:
947 LineEditNewMesh->setEnabled(false);
948 MakeGroupsCheck->setText( tr("SMESH_MAKE_GROUPS"));
949 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
950 MakeGroupsCheck->setEnabled(true);
952 MakeGroupsCheck->setEnabled(false);
954 case MAKE_MESH_BUTTON:
955 LineEditNewMesh->setEnabled(true);
956 MakeGroupsCheck->setText( tr("SMESH_COPY_GROUPS"));
957 if ( myMesh->_is_nil() || myMesh->NbGroups() > 0)
958 MakeGroupsCheck->setEnabled(true);
960 MakeGroupsCheck->setEnabled(false);
966 //=======================================================================
967 //function : setNewMeshName
968 //purpose : update contents of LineEditNewMesh
969 //=======================================================================
971 void SMESHGUI_ScaleDlg::setNewMeshName()
973 LineEditNewMesh->setText("");
974 if ( LineEditNewMesh->isEnabled() && !myMesh->_is_nil() ) {
976 if ( CheckBoxMesh->isChecked() ) {
977 name = LineEditElements->text();
980 _PTR(SObject) meshSO = SMESH::FindSObject( myMesh );
981 name = meshSO->GetName().c_str();
983 if ( !name.isEmpty() )
984 LineEditNewMesh->setText( SMESH::UniqueMeshName( name, "scaled"));
988 //=================================================================================
989 // function : GetConstructorId()
991 //=================================================================================
992 int SMESHGUI_ScaleDlg::GetConstructorId()
994 return GroupConstructors->checkedId();
997 //=================================================================================
998 // function : keyPressEvent()
1000 //=================================================================================
1001 void SMESHGUI_ScaleDlg::keyPressEvent( QKeyEvent* e )
1003 QDialog::keyPressEvent( e );
1004 if ( e->isAccepted() )
1007 if ( e->key() == Qt::Key_F1 ) {
1013 //=================================================================================
1014 // function : setFilters()
1015 // purpose : SLOT. Called when "Filter" button pressed.
1016 //=================================================================================
1017 void SMESHGUI_ScaleDlg::setFilters()
1019 if(myMesh->_is_nil()) {
1020 SUIT_MessageBox::critical(this,
1022 tr("NO_MESH_SELECTED"));
1026 myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, SMESH::ALL );
1028 myFilterDlg->SetSelection();
1029 myFilterDlg->SetMesh( myMesh );
1030 myFilterDlg->SetSourceWg( LineEditElements );
1032 myFilterDlg->show();
1035 //=================================================================================
1036 // function : isValid
1038 //=================================================================================
1039 bool SMESHGUI_ScaleDlg::isValid()
1044 ok = SpinBox1_1->isValid( msg, true ) && ok;
1045 ok = SpinBox1_2->isValid( msg, true ) && ok;
1046 ok = SpinBox1_3->isValid( msg, true ) && ok;
1047 ok = SpinBox_FX->isValid( msg, true ) && ok;
1048 if (GetConstructorId() == 1) {
1049 ok = SpinBox_FY->isValid( msg, true ) && ok;
1050 ok = SpinBox_FZ->isValid( msg, true ) && ok;
1054 QString str( tr( "SMESH_INCORRECT_INPUT" ) );
1055 if ( !msg.isEmpty() )
1057 SUIT_MessageBox::critical( this, tr( "SMESH_ERROR" ), str );