1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_SewingDlg.cxx
25 // Author : Michael ZORIN
29 #include "SMESHGUI_SewingDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_IdValidator.h"
36 #include "SMESH_Actor.h"
37 #include "SMDS_Mesh.hxx"
39 #include "SUIT_ResourceMgr.h"
40 #include "SUIT_Desktop.h"
41 #include "SUIT_MessageBox.h"
43 #include "SVTK_ViewModel.h"
44 #include "SVTK_ViewWindow.h"
45 #include "SVTK_Selector.h"
46 #include "SVTK_Selection.h"
47 #include "SALOME_ListIO.hxx"
49 #include "utilities.h"
52 #include <TColStd_MapOfInteger.hxx>
53 #include <TColStd_IndexedMapOfInteger.hxx>
56 #include <qapplication.h>
57 #include <qbuttongroup.h>
58 #include <qgroupbox.h>
60 #include <qlineedit.h>
61 #include <qpushbutton.h>
62 #include <qradiobutton.h>
63 #include <qcheckbox.h>
69 //=================================================================================
70 // class : SMESHGUI_SewingDlg()
72 //=================================================================================
73 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule, const char* name,
74 bool modal, WFlags fl)
75 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
76 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
77 mySMESHGUI( theModule ),
78 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
80 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
81 QPixmap image0 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
82 QPixmap image1 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
83 QPixmap image2 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
84 QPixmap image3 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
85 QPixmap image4 (mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
88 setName("SMESHGUI_SewingDlg");
90 setCaption(tr("SMESH_SEWING"));
91 setSizeGripEnabled(TRUE);
92 SMESHGUI_SewingDlgLayout = new QGridLayout(this);
93 SMESHGUI_SewingDlgLayout->setSpacing(6);
94 SMESHGUI_SewingDlgLayout->setMargin(11);
96 /***************************************************************/
97 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
98 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
99 (QSizePolicy::SizeType)0, 0, 0,
100 GroupConstructors->sizePolicy().hasHeightForWidth()));
101 GroupConstructors->setTitle(tr("SMESH_SEWING"));
102 GroupConstructors->setExclusive(TRUE);
103 GroupConstructors->setColumnLayout(0, Qt::Vertical);
104 GroupConstructors->layout()->setSpacing(0);
105 GroupConstructors->layout()->setMargin(0);
106 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
107 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
108 GroupConstructorsLayout->setSpacing(6);
109 GroupConstructorsLayout->setMargin(11);
110 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
111 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
112 RadioButton1->setText(tr("" ));
113 RadioButton1->setPixmap(image0);
114 RBLayout->addWidget(RadioButton1);
115 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
116 RadioButton2->setText(tr("" ));
117 RadioButton2->setPixmap(image1);
118 RBLayout->addWidget(RadioButton2);
119 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
120 RadioButton3->setText(tr("" ));
121 RadioButton3->setPixmap(image2);
122 RBLayout->addWidget(RadioButton3);
123 RadioButton4= new QRadioButton(GroupConstructors, "RadioButton4");
124 RadioButton4->setText(tr("" ));
125 RadioButton4->setPixmap(image3);
126 RBLayout->addWidget(RadioButton4);
127 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
128 SMESHGUI_SewingDlgLayout->addWidget(GroupConstructors, 0, 0);
130 /***************************************************************/
131 GroupButtons = new QGroupBox(this, "GroupButtons");
132 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
133 (QSizePolicy::SizeType)0, 0, 0,
134 GroupButtons->sizePolicy().hasHeightForWidth()));
135 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
136 GroupButtons->setTitle(tr("" ));
137 GroupButtons->setColumnLayout(0, Qt::Vertical);
138 GroupButtons->layout()->setSpacing(0);
139 GroupButtons->layout()->setMargin(0);
140 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
141 GroupButtonsLayout->setAlignment(Qt::AlignTop);
142 GroupButtonsLayout->setSpacing(6);
143 GroupButtonsLayout->setMargin(11);
144 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
145 buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
146 buttonCancel->setAutoDefault(TRUE);
147 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
148 buttonApply = new QPushButton(GroupButtons, "buttonApply");
149 buttonApply->setText(tr("SMESH_BUT_APPLY"));
150 buttonApply->setAutoDefault(TRUE);
151 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
152 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
153 GroupButtonsLayout->addItem(spacer_9, 0, 2);
154 buttonOk = new QPushButton(GroupButtons, "buttonOk");
155 buttonOk->setText(tr("SMESH_BUT_OK"));
156 buttonOk->setAutoDefault(TRUE);
157 buttonOk->setDefault(TRUE);
158 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
159 SMESHGUI_SewingDlgLayout->addWidget(GroupButtons, 2, 0);
161 /***************************************************************/
162 GroupArguments = new QGroupBox(this, "GroupArguments");
163 GroupArguments->setColumnLayout(0, Qt::Vertical);
164 GroupArguments->layout()->setSpacing(0);
165 GroupArguments->layout()->setMargin(0);
166 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
167 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
168 GroupArgumentsLayout->setSpacing(6);
169 GroupArgumentsLayout->setMargin(11);
172 SubGroup1 = new QGroupBox(GroupArguments, "SubGroup1");
173 SubGroup1->setColumnLayout(0, Qt::Vertical);
174 SubGroup1->layout()->setSpacing(0);
175 SubGroup1->layout()->setMargin(0);
176 QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1->layout());
177 SubGroup1Layout->setAlignment(Qt::AlignTop);
178 SubGroup1Layout->setSpacing(6);
179 SubGroup1Layout->setMargin(11);
181 // Controls of the first subgroup
182 TextLabel1 = new QLabel(SubGroup1, "TextLabel1");
183 TextLabel1->setFixedWidth(104);
184 SubGroup1Layout->addWidget(TextLabel1, 0, 0);
186 SelectButton1 = new QPushButton(SubGroup1, "SelectButton1");
187 SelectButton1->setPixmap(image4);
188 SubGroup1Layout->addWidget(SelectButton1, 0, 1);
190 LineEdit1 = new QLineEdit(SubGroup1, "LineEdit1");
191 SubGroup1Layout->addWidget(LineEdit1, 0, 2);
193 TextLabel2 = new QLabel(SubGroup1, "TextLabel2");
194 SubGroup1Layout->addWidget(TextLabel2, 1, 0);
196 SelectButton2 = new QPushButton(SubGroup1, "SelectButton2");
197 SelectButton2->setPixmap(image4);
198 SubGroup1Layout->addWidget(SelectButton2, 1, 1);
200 LineEdit2 = new QLineEdit(SubGroup1, "LineEdit2");
201 SubGroup1Layout->addWidget(LineEdit2, 1, 2);
203 TextLabel3 = new QLabel(SubGroup1, "TextLabel3");
204 SubGroup1Layout->addWidget(TextLabel3, 2, 0);
206 SelectButton3 = new QPushButton(SubGroup1, "SelectButton3");
207 SelectButton3->setPixmap(image4);
208 SubGroup1Layout->addWidget(SelectButton3, 2, 1);
210 LineEdit3 = new QLineEdit(SubGroup1, "LineEdit3");
211 SubGroup1Layout->addWidget(LineEdit3, 2, 2);
214 SubGroup2 = new QGroupBox(GroupArguments, "SubGroup2");
215 SubGroup2->setColumnLayout(0, Qt::Vertical);
216 SubGroup2->layout()->setSpacing(0);
217 SubGroup2->layout()->setMargin(0);
218 QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2->layout());
219 SubGroup2Layout->setAlignment(Qt::AlignTop);
220 SubGroup2Layout->setSpacing(6);
221 SubGroup2Layout->setMargin(11);
223 // Controls of the first subgroup
224 TextLabel4 = new QLabel(SubGroup2, "TextLabel4");
225 SubGroup2Layout->addWidget(TextLabel4, 0, 0);
227 SelectButton4 = new QPushButton(SubGroup2, "SelectButton4");
228 SelectButton4->setPixmap(image4);
229 SubGroup2Layout->addWidget(SelectButton4, 0, 1);
231 LineEdit4 = new QLineEdit(SubGroup2, "LineEdit4");
232 SubGroup2Layout->addWidget(LineEdit4, 0, 2);
234 TextLabel5 = new QLabel(SubGroup2, "TextLabel5");
235 SubGroup2Layout->addWidget(TextLabel5, 1, 0);
237 SelectButton5 = new QPushButton(SubGroup2, "SelectButton5");
238 SelectButton5->setPixmap(image4);
239 SubGroup2Layout->addWidget(SelectButton5, 1, 1);
241 LineEdit5 = new QLineEdit(SubGroup2, "LineEdit5");
242 SubGroup2Layout->addWidget(LineEdit5, 1, 2);
244 TextLabel6 = new QLabel(SubGroup2, "TextLabel6");
245 SubGroup2Layout->addWidget(TextLabel6, 2, 0);
247 SelectButton6 = new QPushButton(SubGroup2, "SelectButton6");
248 SelectButton6->setPixmap(image4);
249 SubGroup2Layout->addWidget(SelectButton6, 2, 1);
251 LineEdit6 = new QLineEdit(SubGroup2, "LineEdit6");
252 SubGroup2Layout->addWidget(LineEdit6, 2, 2);
254 // Add subgroups to the group of arguments
255 GroupArgumentsLayout->addWidget(SubGroup1, 0, 0);
256 GroupArgumentsLayout->addWidget(SubGroup2, 1, 0);
258 // Control for the merging equal elements
259 CheckBoxMerge = new QCheckBox(GroupArguments, "CheckBoxMerge");
260 CheckBoxMerge->setText(tr("MERGE_EQUAL_ELEMENTS" ));
261 GroupArgumentsLayout->addWidget(CheckBoxMerge, 2, 0);
263 // Control for the polygons creation instead of splitting
264 CheckBoxPolygons = new QCheckBox( GroupArguments, "CheckBoxPolygons" );
265 CheckBoxPolygons->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
266 GroupArgumentsLayout->addWidget( CheckBoxPolygons, 3, 0 );
268 // Control for the polyedres creation to obtain conform mesh
269 CheckBoxPolyedrs = new QCheckBox( GroupArguments, "CheckBoxPolyedrs" );
270 CheckBoxPolyedrs->setText( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ) );
271 GroupArgumentsLayout->addWidget( CheckBoxPolyedrs, 4, 0 );
274 SMESHGUI_SewingDlgLayout->addWidget(GroupArguments, 1, 0);
276 /* Initialisations */
277 GroupArguments->show();
278 RadioButton1->setChecked(TRUE);
280 LineEdit2->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
281 LineEdit3->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
282 LineEdit5->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
283 LineEdit6->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
285 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
287 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
291 /* signals and slots connections */
292 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
293 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
294 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
295 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
297 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299 connect(SelectButton3, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SelectButton4, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectButton5, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
302 connect(SelectButton6, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
304 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
305 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
306 /* to close dialog if study change */
307 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
309 connect(LineEdit1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
310 connect(LineEdit2, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
311 connect(LineEdit3, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(LineEdit4, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
313 connect(LineEdit5, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
314 connect(LineEdit6, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
316 this->show(); /* displays Dialog */
318 ConstructorsClicked(0);
322 //=================================================================================
323 // function : ~SMESHGUI_SewingDlg()
324 // purpose : Destroys the object and frees any allocated resources
325 //=================================================================================
326 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
328 // no need to delete child widgets, Qt does it all for us
331 //=================================================================================
334 //=================================================================================
335 void SMESHGUI_SewingDlg::Init()
339 myEditCurrentArgument = LineEdit1;
340 LineEdit1->setFocus();
342 myMesh = SMESH::SMESH_Mesh::_nil();
343 CheckBoxMerge->setChecked(false);
344 CheckBoxPolygons->setChecked(false);
345 CheckBoxPolyedrs->setChecked(false);
346 SelectionIntoArgument();
349 //=================================================================================
350 // function : ConstructorsClicked()
351 // purpose : Radio button management
352 //=================================================================================
353 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
355 disconnect(mySelectionMgr, 0, this, 0);
357 mySelectionMgr->selectedObjects( io );
358 mySelectionMgr->clearSelected();
359 LineEdit1->setText("");
360 LineEdit2->setText("");
361 LineEdit3->setText("");
362 LineEdit4->setText("");
363 LineEdit5->setText("");
364 LineEdit6->setText("");
365 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
366 myEditCurrentArgument = LineEdit1;
367 myEditCurrentArgument->setFocus();
369 if (!TextLabel5->isEnabled()) {
370 TextLabel5->setEnabled(true);
371 SelectButton5->setEnabled(true);
372 LineEdit5->setEnabled(true);
373 } else if (!TextLabel6->isEnabled()) {
374 TextLabel6->setEnabled(true);
375 SelectButton6->setEnabled(true);
376 LineEdit6->setEnabled(true);
379 if (constructorId == 1 || constructorId == 3) {
380 if (CheckBoxPolygons->isVisible())
381 CheckBoxPolygons->hide();
382 if (CheckBoxPolyedrs->isVisible())
383 CheckBoxPolyedrs->hide();
386 switch (constructorId) {
389 GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
390 SubGroup1->setTitle(tr("BORDER_1"));
391 SubGroup2->setTitle(tr("BORDER_2"));
393 if (!CheckBoxPolygons->isVisible())
394 CheckBoxPolygons->show();
395 if (!CheckBoxPolyedrs->isVisible())
396 CheckBoxPolyedrs->show();
403 GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
404 SubGroup1->setTitle(tr("BORDER_1"));
405 SubGroup2->setTitle(tr("BORDER_2"));
407 TextLabel6->setEnabled(false);
408 SelectButton6->setEnabled(false);
409 LineEdit6->setEnabled(false);
417 GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
418 SubGroup1->setTitle(tr("BORDER"));
419 SubGroup2->setTitle(tr("SIDE"));
421 TextLabel5->setEnabled(false);
422 SelectButton5->setEnabled(false);
423 LineEdit5->setEnabled(false);
425 if (!CheckBoxPolygons->isVisible())
426 CheckBoxPolygons->show();
427 if (!CheckBoxPolyedrs->isVisible())
428 CheckBoxPolyedrs->show();
437 GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
438 SubGroup1->setTitle(tr("SIDE_1"));
439 SubGroup2->setTitle(tr("SIDE_2"));
441 TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
442 TextLabel2->setText(tr("NODE1_TO_MERGE"));
443 TextLabel3->setText(tr("NODE2_TO_MERGE"));
444 TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
445 TextLabel5->setText(tr("NODE1_TO_MERGE"));
446 TextLabel6->setText(tr("NODE2_TO_MERGE"));
448 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
449 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator"));
451 SMESH::SetPointRepresentation(false);
453 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
454 aViewWindow->SetSelectionMode(CellSelection);
459 if (constructorId != 3) {
460 TextLabel1->setText(tr("FIRST_NODE_ID"));
461 TextLabel2->setText(tr("SECOND_NODE_ID"));
462 TextLabel3->setText(tr("LAST_NODE_ID"));
463 TextLabel4->setText(tr("FIRST_NODE_ID"));
464 TextLabel5->setText(tr("SECOND_NODE_ID"));
465 TextLabel6->setText(tr("LAST_NODE_ID"));
467 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
468 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
470 SMESH::SetPointRepresentation(true);
472 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
473 aViewWindow->SetSelectionMode(NodeSelection);
476 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
477 mySelectionMgr->setSelectedObjects( io );
480 //=================================================================================
481 // function : ClickOnApply()
483 //=================================================================================
484 bool SMESHGUI_SewingDlg::ClickOnApply()
486 if (mySMESHGUI->isActiveStudyLocked())
489 bool aResult = false;
492 bool toMerge = CheckBoxMerge->isChecked();
493 bool toCreatePolygons = CheckBoxPolygons->isChecked();
494 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
497 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
498 QApplication::setOverrideCursor(Qt::waitCursor);
500 int aConstructorId = GetConstructorId();
501 SMESH::SMESH_MeshEditor::Sew_Error anError;
503 if (aConstructorId == 0)
504 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
505 LineEdit2->text().toLong(),
506 LineEdit3->text().toLong(),
507 LineEdit4->text().toLong(),
508 LineEdit5->text().toLong(),
509 LineEdit6->text().toLong(),
512 else if (aConstructorId == 1)
513 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
514 LineEdit2->text().toLong(),
515 LineEdit3->text().toLong(),
516 LineEdit4->text().toLong(),
517 LineEdit5->text().toLong());
518 else if (aConstructorId == 2)
519 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
520 LineEdit2->text().toLong(),
521 LineEdit3->text().toLong(),
522 LineEdit4->text().toLong(),
523 LineEdit6->text().toLong(),
526 else if (aConstructorId == 3) {
527 QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
528 QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
530 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
531 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
533 anElementsId1->length(aListElementsId1.count());
534 anElementsId2->length(aListElementsId2.count());
536 for (int i = 0; i < aListElementsId1.count(); i++)
537 anElementsId1[i] = aListElementsId1[i].toInt();
538 for (int i = 0; i < aListElementsId2.count(); i++)
539 anElementsId2[i] = aListElementsId2[i].toInt();
541 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
542 anElementsId2.inout(),
543 LineEdit2->text().toLong(),
544 LineEdit5->text().toLong(),
545 LineEdit3->text().toLong(),
546 LineEdit6->text().toLong());
548 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
550 if (toMerge && aResult)
551 aMeshEditor->MergeEqualElements();
553 QApplication::restoreOverrideCursor();
556 QString msg = tr(QString("ERROR_%1").arg(anError));
557 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
558 msg, tr("SMESH_BUT_OK"));
564 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
568 mySelectionMgr->setSelectedObjects(aList, false);
572 ConstructorsClicked(GetConstructorId());
579 //=================================================================================
580 // function : ClickOnOk()
582 //=================================================================================
583 void SMESHGUI_SewingDlg::ClickOnOk()
589 //=================================================================================
590 // function : ClickOnCancel()
592 //=================================================================================
593 void SMESHGUI_SewingDlg::ClickOnCancel()
595 //mySelectionMgr->clearSelected();
596 SMESH::SetPointRepresentation(false);
597 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
598 aViewWindow->SetSelectionMode(ActorSelection);
599 disconnect(mySelectionMgr, 0, this, 0);
600 mySMESHGUI->ResetState();
604 //=======================================================================
605 //function : onTextChange
607 //=======================================================================
608 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
610 QLineEdit* send = (QLineEdit*)sender();
616 myEditCurrentArgument = send;
618 if (send == LineEdit1)
620 else if (send == LineEdit2)
622 else if (send == LineEdit3)
624 else if (send == LineEdit4)
626 else if (send == LineEdit5)
628 else if (send == LineEdit6)
631 buttonOk->setEnabled(false);
632 buttonApply->setEnabled(false);
634 // hilight entered elements/nodes
635 SMDS_Mesh* aMesh = 0;
638 aMesh = myActor->GetObject()->GetMesh();
643 TColStd_MapOfInteger newIndices;
645 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
646 SMESH::SetPointRepresentation(true);
648 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
649 aViewWindow->SetSelectionMode(NodeSelection);
651 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
653 newIndices.Add(n->GetID());
654 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
655 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
656 aViewWindow->highlight( myActor->getIO(), true, true );
658 if (send == LineEdit1)
660 else if (send == LineEdit2)
662 else if (send == LineEdit3)
664 else if (send == LineEdit4)
666 else if (send == LineEdit5)
668 else if (send == LineEdit6)
672 SMESH::SetPointRepresentation(false);
674 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
675 aViewWindow->SetSelectionMode(CellSelection);
677 QStringList aListId = QStringList::split(" ", theNewText, false);
679 bool isEvenOneExists = false;
681 for (int i = 0; i < aListId.count(); i++) {
682 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
684 newIndices.Add(e->GetID());
686 if (!isEvenOneExists)
687 isEvenOneExists = true;
691 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
692 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
693 aViewWindow->highlight( myActor->getIO(), true, true );
695 if (isEvenOneExists) {
696 if (send == LineEdit1)
698 else if(send == LineEdit4)
707 buttonOk->setEnabled(true);
708 buttonApply->setEnabled(true);
714 //=================================================================================
715 // function : SelectionIntoArgument()
716 // purpose : Called when selection as changed or other case
717 //=================================================================================
718 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
723 if (isSelectionChanged)
726 QString aString = "";
729 myEditCurrentArgument->setText(aString);
732 if (!GroupButtons->isEnabled()) // inactive
735 buttonOk->setEnabled(false);
736 buttonApply->setEnabled(false);
740 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
742 int nbSel = aList.Extent();
746 Handle(SALOME_InteractiveObject) IO = aList.First();
747 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
748 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
750 if (myMesh->_is_nil() || !myActor)
753 // get selected elements/nodes
756 if (GetConstructorId() != 3 ||
757 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
758 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
762 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
768 myEditCurrentArgument->setText(aString);
772 if (myEditCurrentArgument == LineEdit1)
774 else if (myEditCurrentArgument == LineEdit2)
776 else if (myEditCurrentArgument == LineEdit3)
778 else if (myEditCurrentArgument == LineEdit4)
780 else if (myEditCurrentArgument == LineEdit5)
782 else if (myEditCurrentArgument == LineEdit6)
786 buttonOk->setEnabled(true);
787 buttonApply->setEnabled(true);
791 //=================================================================================
792 // function : SetEditCurrentArgument()
794 //=================================================================================
795 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
797 QPushButton* send = (QPushButton*)sender();
799 disconnect(mySelectionMgr, 0, this, 0);
800 mySelectionMgr->clearSelected();
802 if (send == SelectButton1) {
803 myEditCurrentArgument = LineEdit1;
806 else if (send == SelectButton2) {
807 myEditCurrentArgument = LineEdit2;
810 else if (send == SelectButton3) {
811 myEditCurrentArgument = LineEdit3;
814 else if (send == SelectButton4) {
815 myEditCurrentArgument = LineEdit4;
818 else if (send == SelectButton5) {
819 myEditCurrentArgument = LineEdit5;
822 else if (send == SelectButton6) {
823 myEditCurrentArgument = LineEdit6;
827 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
828 SMESH::SetPointRepresentation(true);
830 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
831 aViewWindow->SetSelectionMode(NodeSelection);
834 SMESH::SetPointRepresentation(false);
835 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
836 aViewWindow->SetSelectionMode(CellSelection);
839 myEditCurrentArgument->setFocus();
840 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
841 SelectionIntoArgument(false);
844 //=================================================================================
845 // function : DeactivateActiveDialog()
847 //=================================================================================
848 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
850 if (GroupConstructors->isEnabled()) {
851 GroupConstructors->setEnabled(false);
852 GroupArguments->setEnabled(false);
853 GroupButtons->setEnabled(false);
854 mySMESHGUI->ResetState();
855 mySMESHGUI->SetActiveDialogBox(0);
859 //=================================================================================
860 // function : ActivateThisDialog()
862 //=================================================================================
863 void SMESHGUI_SewingDlg::ActivateThisDialog()
865 /* Emit a signal to deactivate the active dialog */
866 mySMESHGUI->EmitSignalDeactivateDialog();
867 GroupConstructors->setEnabled(true);
868 GroupArguments->setEnabled(true);
869 GroupButtons->setEnabled(true);
871 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
873 ConstructorsClicked(GetConstructorId());
874 SelectionIntoArgument();
877 //=================================================================================
878 // function : enterEvent()
880 //=================================================================================
881 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
883 if (!GroupConstructors->isEnabled())
884 ActivateThisDialog();
887 //=================================================================================
888 // function : closeEvent()
890 //=================================================================================
891 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
893 /* same than click on cancel button */
894 this->ClickOnCancel();
897 //=======================================================================
898 //function : hideEvent
899 //purpose : caused by ESC key
900 //=======================================================================
901 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
907 //=================================================================================
908 // function : GetConstructorId()
910 //=================================================================================
911 int SMESHGUI_SewingDlg::GetConstructorId()
913 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
914 return GroupConstructors->id(GroupConstructors->selected());
918 //=================================================================================
919 // function : GetConstructorId()
921 //=================================================================================
922 bool SMESHGUI_SewingDlg::IsValid()
924 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);