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_SewingDlg.cxx
24 // Author : Michael ZORIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_SewingDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_IdValidator.h"
35 #include <SMESH_Actor.h>
36 #include <SMDS_Mesh.hxx>
38 // SALOME GUI includes
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_OverrideCursor.h>
45 #include <LightApp_Application.h>
46 #include <LightApp_SelectionMgr.h>
48 #include <SVTK_ViewModel.h>
49 #include <SVTK_ViewWindow.h>
50 #include <SALOME_ListIO.hxx>
53 #include <TColStd_MapOfInteger.hxx>
56 #include <QApplication>
57 #include <QButtonGroup>
61 #include <QPushButton>
62 #include <QRadioButton>
64 #include <QHBoxLayout>
65 #include <QVBoxLayout>
66 #include <QGridLayout>
70 #include <SALOMEconfig.h>
71 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
76 //=================================================================================
77 // class : SMESHGUI_SewingDlg()
79 //=================================================================================
80 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule )
81 : QDialog( SMESH::GetDesktop( theModule ) ),
82 mySMESHGUI( theModule ),
83 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
85 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
86 QPixmap image0 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
87 QPixmap image1 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
88 QPixmap image2 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
89 QPixmap image3 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
90 QPixmap image4 (mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
93 setAttribute(Qt::WA_DeleteOnClose, true);
94 setWindowTitle(tr("SMESH_SEWING"));
95 setSizeGripEnabled(true);
97 QVBoxLayout* SMESHGUI_SewingDlgLayout = new QVBoxLayout(this);
98 SMESHGUI_SewingDlgLayout->setSpacing(SPACING);
99 SMESHGUI_SewingDlgLayout->setMargin(MARGIN);
101 /***************************************************************/
102 ConstructorsBox = new QGroupBox(tr("SMESH_SEWING"), this);
103 GroupConstructors = new QButtonGroup(this);
104 QHBoxLayout* ConstructorsBoxLayout = new QHBoxLayout(ConstructorsBox);
105 ConstructorsBoxLayout->setSpacing(SPACING);
106 ConstructorsBoxLayout->setMargin(MARGIN);
108 RadioButton1 = new QRadioButton(ConstructorsBox);
109 RadioButton1->setIcon(image0);
110 RadioButton2 = new QRadioButton(ConstructorsBox);
111 RadioButton2->setIcon(image1);
112 RadioButton3 = new QRadioButton(ConstructorsBox);
113 RadioButton3->setIcon(image2);
114 RadioButton4 = new QRadioButton(ConstructorsBox);
115 RadioButton4->setIcon(image3);
117 ConstructorsBoxLayout->addWidget(RadioButton1);
118 ConstructorsBoxLayout->addWidget(RadioButton2);
119 ConstructorsBoxLayout->addWidget(RadioButton3);
120 ConstructorsBoxLayout->addWidget(RadioButton4);
121 GroupConstructors->addButton(RadioButton1, 0);
122 GroupConstructors->addButton(RadioButton2, 1);
123 GroupConstructors->addButton(RadioButton3, 2);
124 GroupConstructors->addButton(RadioButton4, 3);
126 /***************************************************************/
127 GroupArguments = new QGroupBox(this);
128 QVBoxLayout* GroupArgumentsLayout = new QVBoxLayout(GroupArguments);
129 GroupArgumentsLayout->setSpacing(SPACING);
130 GroupArgumentsLayout->setMargin(MARGIN);
133 SubGroup1 = new QGroupBox(GroupArguments);
134 QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1);
135 SubGroup1Layout->setSpacing(SPACING);
136 SubGroup1Layout->setMargin(MARGIN);
138 // Controls of the first subgroup
139 TextLabel1 = new QLabel(SubGroup1);
140 SelectButton1 = new QPushButton(SubGroup1);
141 SelectButton1->setIcon(image4);
142 LineEdit1 = new QLineEdit(SubGroup1);
144 TextLabel2 = new QLabel(SubGroup1);
145 SelectButton2 = new QPushButton(SubGroup1);
146 SelectButton2->setIcon(image4);
147 LineEdit2 = new QLineEdit(SubGroup1);
149 TextLabel3 = new QLabel(SubGroup1);
150 SelectButton3 = new QPushButton(SubGroup1);
151 SelectButton3->setIcon(image4);
152 LineEdit3 = new QLineEdit(SubGroup1);
154 SubGroup1Layout->addWidget(TextLabel1, 0, 0);
155 SubGroup1Layout->addWidget(SelectButton1, 0, 1);
156 SubGroup1Layout->addWidget(LineEdit1, 0, 2);
157 SubGroup1Layout->addWidget(TextLabel2, 1, 0);
158 SubGroup1Layout->addWidget(SelectButton2, 1, 1);
159 SubGroup1Layout->addWidget(LineEdit2, 1, 2);
160 SubGroup1Layout->addWidget(TextLabel3, 2, 0);
161 SubGroup1Layout->addWidget(SelectButton3, 2, 1);
162 SubGroup1Layout->addWidget(LineEdit3, 2, 2);
165 SubGroup2 = new QGroupBox(GroupArguments);
166 QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2);
167 SubGroup2Layout->setSpacing(SPACING);
168 SubGroup2Layout->setMargin(MARGIN);
170 // Controls of the first subgroup
171 TextLabel4 = new QLabel(SubGroup2);
172 SelectButton4 = new QPushButton(SubGroup2);
173 SelectButton4->setIcon(image4);
174 LineEdit4 = new QLineEdit(SubGroup2);
176 TextLabel5 = new QLabel(SubGroup2);
177 SelectButton5 = new QPushButton(SubGroup2);
178 SelectButton5->setIcon(image4);
179 LineEdit5 = new QLineEdit(SubGroup2);
181 TextLabel6 = new QLabel(SubGroup2);
182 SelectButton6 = new QPushButton(SubGroup2);
183 SelectButton6->setIcon(image4);
184 LineEdit6 = new QLineEdit(SubGroup2);
186 SubGroup2Layout->addWidget(TextLabel4, 0, 0);
187 SubGroup2Layout->addWidget(SelectButton4, 0, 1);
188 SubGroup2Layout->addWidget(LineEdit4, 0, 2);
189 SubGroup2Layout->addWidget(TextLabel5, 1, 0);
190 SubGroup2Layout->addWidget(SelectButton5, 1, 1);
191 SubGroup2Layout->addWidget(LineEdit5, 1, 2);
192 SubGroup2Layout->addWidget(TextLabel6, 2, 0);
193 SubGroup2Layout->addWidget(SelectButton6, 2, 1);
194 SubGroup2Layout->addWidget(LineEdit6, 2, 2);
196 // Control for the merging equal elements
197 CheckBoxMerge = new QCheckBox(tr("MERGE_EQUAL_ELEMENTS"), GroupArguments);
199 // Control for the polygons creation instead of splitting
200 CheckBoxPolygons = new QCheckBox(tr("CREATE_POLYGONS_INSTEAD_SPLITTING"), GroupArguments);
202 // Control for the polyedres creation to obtain conform mesh
203 CheckBoxPolyedrs = new QCheckBox(tr("CREATE_POLYEDRS_NEAR_BOUNDARY"), GroupArguments);
206 GroupArgumentsLayout->addWidget(SubGroup1);
207 GroupArgumentsLayout->addWidget(SubGroup2);
208 GroupArgumentsLayout->addWidget(CheckBoxMerge);
209 GroupArgumentsLayout->addWidget(CheckBoxPolygons);
210 GroupArgumentsLayout->addWidget(CheckBoxPolyedrs);
212 /***************************************************************/
213 GroupButtons = new QGroupBox(this);
214 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
215 GroupButtonsLayout->setSpacing(SPACING);
216 GroupButtonsLayout->setMargin(MARGIN);
218 buttonOk = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), GroupButtons);
219 buttonOk->setAutoDefault(true);
220 buttonOk->setDefault(true);
221 buttonApply = new QPushButton(tr("SMESH_BUT_APPLY"), GroupButtons);
222 buttonApply->setAutoDefault(true);
223 buttonCancel = new QPushButton(tr("SMESH_BUT_CLOSE"), GroupButtons);
224 buttonCancel->setAutoDefault(true);
225 buttonHelp = new QPushButton(tr("SMESH_BUT_HELP"), GroupButtons);
226 buttonHelp->setAutoDefault(true);
228 GroupButtonsLayout->addWidget(buttonOk);
229 GroupButtonsLayout->addSpacing(10);
230 GroupButtonsLayout->addWidget(buttonApply);
231 GroupButtonsLayout->addSpacing(10);
232 GroupButtonsLayout->addStretch();
233 GroupButtonsLayout->addWidget(buttonCancel);
234 GroupButtonsLayout->addWidget(buttonHelp);
236 /***************************************************************/
237 SMESHGUI_SewingDlgLayout->addWidget(ConstructorsBox);
238 SMESHGUI_SewingDlgLayout->addWidget(GroupArguments);
239 SMESHGUI_SewingDlgLayout->addWidget(GroupButtons);
241 /* Initialisations */
242 RadioButton1->setChecked(true);
244 LineEdit2->setValidator(new SMESHGUI_IdValidator(this, 1));
245 LineEdit3->setValidator(new SMESHGUI_IdValidator(this, 1));
246 LineEdit5->setValidator(new SMESHGUI_IdValidator(this, 1));
247 LineEdit6->setValidator(new SMESHGUI_IdValidator(this, 1));
249 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
251 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
253 myHelpFileName = "sewing_meshes_page.html";
257 /* signals and slots connections */
258 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
259 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
260 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
261 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
262 connect(GroupConstructors, SIGNAL(buttonClicked(int)), SLOT(ConstructorsClicked(int)));
264 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
265 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
266 connect(SelectButton3, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
267 connect(SelectButton4, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
268 connect(SelectButton5, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
269 connect(SelectButton6, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
271 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
272 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
273 /* to close dialog if study change */
274 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
276 connect(LineEdit1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
277 connect(LineEdit2, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
278 connect(LineEdit3, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
279 connect(LineEdit4, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
280 connect(LineEdit5, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
281 connect(LineEdit6, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
283 ConstructorsClicked(0);
286 //=================================================================================
287 // function : ~SMESHGUI_SewingDlg()
288 // purpose : Destroys the object and frees any allocated resources
289 //=================================================================================
290 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
294 //=================================================================================
297 //=================================================================================
298 void SMESHGUI_SewingDlg::Init()
302 myEditCurrentArgument = LineEdit1;
303 LineEdit1->setFocus();
305 myMesh = SMESH::SMESH_Mesh::_nil();
306 CheckBoxMerge->setChecked(false);
307 CheckBoxPolygons->setChecked(false);
308 CheckBoxPolyedrs->setChecked(false);
309 SelectionIntoArgument();
312 //=================================================================================
313 // function : ConstructorsClicked()
314 // purpose : Radio button management
315 //=================================================================================
316 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
318 disconnect(mySelectionMgr, 0, this, 0);
320 mySelectionMgr->selectedObjects( io );
321 mySelectionMgr->clearSelected();
322 LineEdit1->setText("");
323 LineEdit2->setText("");
324 LineEdit3->setText("");
325 LineEdit4->setText("");
326 LineEdit5->setText("");
327 LineEdit6->setText("");
328 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
329 myEditCurrentArgument = LineEdit1;
330 myEditCurrentArgument->setFocus();
332 if (!TextLabel5->isEnabled()) {
333 TextLabel5->setEnabled(true);
334 SelectButton5->setEnabled(true);
335 LineEdit5->setEnabled(true);
336 } else if (!TextLabel6->isEnabled()) {
337 TextLabel6->setEnabled(true);
338 SelectButton6->setEnabled(true);
339 LineEdit6->setEnabled(true);
342 if (constructorId == 1 || constructorId == 3) {
343 if (CheckBoxPolygons->isVisible())
344 CheckBoxPolygons->hide();
345 if (CheckBoxPolyedrs->isVisible())
346 CheckBoxPolyedrs->hide();
349 switch (constructorId) {
352 GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
353 SubGroup1->setTitle(tr("BORDER_1"));
354 SubGroup2->setTitle(tr("BORDER_2"));
356 if (!CheckBoxPolygons->isVisible())
357 CheckBoxPolygons->show();
358 if (!CheckBoxPolyedrs->isVisible())
359 CheckBoxPolyedrs->show();
365 GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
366 SubGroup1->setTitle(tr("BORDER_1"));
367 SubGroup2->setTitle(tr("BORDER_2"));
369 TextLabel6->setEnabled(false);
370 SelectButton6->setEnabled(false);
371 LineEdit6->setEnabled(false);
379 GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
380 SubGroup1->setTitle(tr("BORDER"));
381 SubGroup2->setTitle(tr("SIDE"));
383 TextLabel5->setEnabled(false);
384 SelectButton5->setEnabled(false);
385 LineEdit5->setEnabled(false);
387 if (!CheckBoxPolygons->isVisible())
388 CheckBoxPolygons->show();
389 if (!CheckBoxPolyedrs->isVisible())
390 CheckBoxPolyedrs->show();
398 GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
399 SubGroup1->setTitle(tr("SIDE_1"));
400 SubGroup2->setTitle(tr("SIDE_2"));
402 TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
403 TextLabel2->setText(tr("NODE1_TO_MERGE"));
404 TextLabel3->setText(tr("NODE2_TO_MERGE"));
405 TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
406 TextLabel5->setText(tr("NODE1_TO_MERGE"));
407 TextLabel6->setText(tr("NODE2_TO_MERGE"));
409 LineEdit1->setValidator(new SMESHGUI_IdValidator(this));
410 LineEdit4->setValidator(new SMESHGUI_IdValidator(this));
412 SMESH::SetPointRepresentation(false);
414 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
415 aViewWindow->SetSelectionMode(CellSelection);
420 if (constructorId != 3) {
421 TextLabel1->setText(tr("FIRST_NODE_ID"));
422 TextLabel2->setText(tr("SECOND_NODE_ID"));
423 TextLabel3->setText(tr("LAST_NODE_ID"));
424 TextLabel4->setText(tr("FIRST_NODE_ID"));
425 TextLabel5->setText(tr("SECOND_NODE_ID"));
426 TextLabel6->setText(tr("LAST_NODE_ID"));
428 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, 1));
429 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, 1));
431 SMESH::SetPointRepresentation(true);
433 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
434 aViewWindow->SetSelectionMode(NodeSelection);
437 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
438 mySelectionMgr->setSelectedObjects( io );
440 QApplication::instance()->processEvents();
445 //=================================================================================
446 // function : ClickOnApply()
448 //=================================================================================
449 bool SMESHGUI_SewingDlg::ClickOnApply()
451 if (mySMESHGUI->isActiveStudyLocked())
454 bool aResult = false;
457 bool toMerge = CheckBoxMerge->isChecked();
458 bool toCreatePolygons = CheckBoxPolygons->isChecked();
459 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
462 SUIT_OverrideCursor aWaitCursor;
463 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
465 int aConstructorId = GetConstructorId();
466 SMESH::SMESH_MeshEditor::Sew_Error anError;
468 if (aConstructorId == 0)
469 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
470 LineEdit2->text().toLong(),
471 LineEdit3->text().toLong(),
472 LineEdit4->text().toLong(),
473 LineEdit5->text().toLong(),
474 LineEdit6->text().toLong(),
477 else if (aConstructorId == 1)
478 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
479 LineEdit2->text().toLong(),
480 LineEdit3->text().toLong(),
481 LineEdit4->text().toLong(),
482 LineEdit5->text().toLong());
483 else if (aConstructorId == 2)
484 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
485 LineEdit2->text().toLong(),
486 LineEdit3->text().toLong(),
487 LineEdit4->text().toLong(),
488 LineEdit6->text().toLong(),
491 else if (aConstructorId == 3) {
492 QStringList aListElementsId1 = LineEdit1->text().split(" ", QString::SkipEmptyParts);
493 QStringList aListElementsId2 = LineEdit4->text().split(" ", QString::SkipEmptyParts);
495 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
496 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
498 anElementsId1->length(aListElementsId1.count());
499 anElementsId2->length(aListElementsId2.count());
501 for (int i = 0; i < aListElementsId1.count(); i++)
502 anElementsId1[i] = aListElementsId1[i].toInt();
503 for (int i = 0; i < aListElementsId2.count(); i++)
504 anElementsId2[i] = aListElementsId2[i].toInt();
506 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
507 anElementsId2.inout(),
508 LineEdit2->text().toLong(),
509 LineEdit5->text().toLong(),
510 LineEdit3->text().toLong(),
511 LineEdit6->text().toLong());
513 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
515 if (toMerge && aResult)
516 aMeshEditor->MergeEqualElements();
519 QString msg = tr(QString("ERROR_%1").arg(anError).toLatin1().data());
520 SUIT_MessageBox::warning(this, tr("SMESH_WRN_WARNING"), msg);
526 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
530 mySelectionMgr->setSelectedObjects(aList, false);
534 ConstructorsClicked(GetConstructorId());
541 //=================================================================================
542 // function : ClickOnOk()
544 //=================================================================================
545 void SMESHGUI_SewingDlg::ClickOnOk()
551 //=================================================================================
552 // function : ClickOnCancel()
554 //=================================================================================
555 void SMESHGUI_SewingDlg::ClickOnCancel()
557 //mySelectionMgr->clearSelected();
558 SMESH::SetPointRepresentation(false);
559 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
560 aViewWindow->SetSelectionMode(ActorSelection);
561 disconnect(mySelectionMgr, 0, this, 0);
562 mySMESHGUI->ResetState();
566 //=================================================================================
567 // function : ClickOnHelp()
569 //=================================================================================
570 void SMESHGUI_SewingDlg::ClickOnHelp()
572 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
574 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
578 platform = "winapplication";
580 platform = "application";
582 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
583 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
584 arg(app->resourceMgr()->stringValue("ExternalBrowser",
586 arg(myHelpFileName));
590 //=======================================================================
591 //function : onTextChange
593 //=======================================================================
594 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
596 QLineEdit* send = (QLineEdit*)sender();
602 myEditCurrentArgument = send;
604 if (send == LineEdit1)
606 else if (send == LineEdit2)
608 else if (send == LineEdit3)
610 else if (send == LineEdit4)
612 else if (send == LineEdit5)
614 else if (send == LineEdit6)
617 buttonOk->setEnabled(false);
618 buttonApply->setEnabled(false);
620 // hilight entered elements/nodes
621 SMDS_Mesh* aMesh = 0;
624 aMesh = myActor->GetObject()->GetMesh();
629 TColStd_MapOfInteger newIndices;
631 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
632 SMESH::SetPointRepresentation(true);
634 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
635 aViewWindow->SetSelectionMode(NodeSelection);
637 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
639 newIndices.Add(n->GetID());
640 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
641 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
642 aViewWindow->highlight( myActor->getIO(), true, true );
644 if (send == LineEdit1)
646 else if (send == LineEdit2)
648 else if (send == LineEdit3)
650 else if (send == LineEdit4)
652 else if (send == LineEdit5)
654 else if (send == LineEdit6)
658 SMESH::SetPointRepresentation(false);
660 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
661 aViewWindow->SetSelectionMode(CellSelection);
663 QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
665 bool isEvenOneExists = false;
667 for (int i = 0; i < aListId.count(); i++) {
668 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
670 newIndices.Add(e->GetID());
672 if (!isEvenOneExists)
673 isEvenOneExists = true;
677 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
678 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
679 aViewWindow->highlight( myActor->getIO(), true, true );
681 if (isEvenOneExists) {
682 if (send == LineEdit1)
684 else if(send == LineEdit4)
693 buttonOk->setEnabled(true);
694 buttonApply->setEnabled(true);
700 //=================================================================================
701 // function : SelectionIntoArgument()
702 // purpose : Called when selection as changed or other case
703 //=================================================================================
704 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
709 if (isSelectionChanged)
712 QString aString = "";
715 myEditCurrentArgument->setText(aString);
718 if (!GroupButtons->isEnabled()) // inactive
721 buttonOk->setEnabled(false);
722 buttonApply->setEnabled(false);
726 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
728 int nbSel = aList.Extent();
732 Handle(SALOME_InteractiveObject) IO = aList.First();
733 myMesh = SMESH::GetMeshByIO(IO); //@ SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
734 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
736 if (myMesh->_is_nil() || !myActor)
739 // get selected elements/nodes
742 if (GetConstructorId() != 3 ||
743 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
744 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
748 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
754 myEditCurrentArgument->setText(aString);
758 if (myEditCurrentArgument == LineEdit1)
760 else if (myEditCurrentArgument == LineEdit2)
762 else if (myEditCurrentArgument == LineEdit3)
764 else if (myEditCurrentArgument == LineEdit4)
766 else if (myEditCurrentArgument == LineEdit5)
768 else if (myEditCurrentArgument == LineEdit6)
772 buttonOk->setEnabled(true);
773 buttonApply->setEnabled(true);
777 //=================================================================================
778 // function : SetEditCurrentArgument()
780 //=================================================================================
781 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
783 QPushButton* send = (QPushButton*)sender();
785 disconnect(mySelectionMgr, 0, this, 0);
786 mySelectionMgr->clearSelected();
788 if (send == SelectButton1) {
789 myEditCurrentArgument = LineEdit1;
792 else if (send == SelectButton2) {
793 myEditCurrentArgument = LineEdit2;
796 else if (send == SelectButton3) {
797 myEditCurrentArgument = LineEdit3;
800 else if (send == SelectButton4) {
801 myEditCurrentArgument = LineEdit4;
804 else if (send == SelectButton5) {
805 myEditCurrentArgument = LineEdit5;
808 else if (send == SelectButton6) {
809 myEditCurrentArgument = LineEdit6;
813 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
814 SMESH::SetPointRepresentation(true);
816 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
817 aViewWindow->SetSelectionMode(NodeSelection);
820 SMESH::SetPointRepresentation(false);
821 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
822 aViewWindow->SetSelectionMode(CellSelection);
825 myEditCurrentArgument->setFocus();
826 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
827 SelectionIntoArgument(false);
830 //=================================================================================
831 // function : DeactivateActiveDialog()
833 //=================================================================================
834 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
836 if (ConstructorsBox->isEnabled()) {
837 ConstructorsBox->setEnabled(false);
838 GroupArguments->setEnabled(false);
839 GroupButtons->setEnabled(false);
840 mySMESHGUI->ResetState();
841 mySMESHGUI->SetActiveDialogBox(0);
845 //=================================================================================
846 // function : ActivateThisDialog()
848 //=================================================================================
849 void SMESHGUI_SewingDlg::ActivateThisDialog()
851 /* Emit a signal to deactivate the active dialog */
852 mySMESHGUI->EmitSignalDeactivateDialog();
853 ConstructorsBox->setEnabled(true);
854 GroupArguments->setEnabled(true);
855 GroupButtons->setEnabled(true);
857 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
859 ConstructorsClicked(GetConstructorId());
860 SelectionIntoArgument();
863 //=================================================================================
864 // function : enterEvent()
866 //=================================================================================
867 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
869 if (!ConstructorsBox->isEnabled())
870 ActivateThisDialog();
873 //=================================================================================
874 // function : closeEvent()
876 //=================================================================================
877 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
879 /* same than click on cancel button */
883 //=======================================================================
884 //function : hideEvent
885 //purpose : caused by ESC key
886 //=======================================================================
887 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
893 //=================================================================================
894 // function : GetConstructorId()
896 //=================================================================================
897 int SMESHGUI_SewingDlg::GetConstructorId()
899 return GroupConstructors->checkedId();
902 //=================================================================================
903 // function : GetConstructorId()
905 //=================================================================================
906 bool SMESHGUI_SewingDlg::IsValid()
908 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
911 //=================================================================================
912 // function : keyPressEvent()
914 //=================================================================================
915 void SMESHGUI_SewingDlg::keyPressEvent( QKeyEvent* e )
917 QDialog::keyPressEvent( e );
918 if ( e->isAccepted() )
921 if ( e->key() == Qt::Key_F1 ) {