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 ) ),
79 myViewWindow( SMESH::GetViewWindow( theModule ) ),
80 mySelector( myViewWindow->GetSelector() )
82 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
83 QPixmap image0 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
84 QPixmap image1 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
85 QPixmap image2 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
86 QPixmap image3 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
87 QPixmap image4 (mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
90 setName("SMESHGUI_SewingDlg");
92 setCaption(tr("SMESH_SEWING"));
93 setSizeGripEnabled(TRUE);
94 SMESHGUI_SewingDlgLayout = new QGridLayout(this);
95 SMESHGUI_SewingDlgLayout->setSpacing(6);
96 SMESHGUI_SewingDlgLayout->setMargin(11);
98 /***************************************************************/
99 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
100 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
101 (QSizePolicy::SizeType)0, 0, 0,
102 GroupConstructors->sizePolicy().hasHeightForWidth()));
103 GroupConstructors->setTitle(tr("SMESH_SEWING"));
104 GroupConstructors->setExclusive(TRUE);
105 GroupConstructors->setColumnLayout(0, Qt::Vertical);
106 GroupConstructors->layout()->setSpacing(0);
107 GroupConstructors->layout()->setMargin(0);
108 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
109 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
110 GroupConstructorsLayout->setSpacing(6);
111 GroupConstructorsLayout->setMargin(11);
112 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
113 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
114 RadioButton1->setText(tr("" ));
115 RadioButton1->setPixmap(image0);
116 RBLayout->addWidget(RadioButton1);
117 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
118 RadioButton2->setText(tr("" ));
119 RadioButton2->setPixmap(image1);
120 RBLayout->addWidget(RadioButton2);
121 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
122 RadioButton3->setText(tr("" ));
123 RadioButton3->setPixmap(image2);
124 RBLayout->addWidget(RadioButton3);
125 RadioButton4= new QRadioButton(GroupConstructors, "RadioButton4");
126 RadioButton4->setText(tr("" ));
127 RadioButton4->setPixmap(image3);
128 RBLayout->addWidget(RadioButton4);
129 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
130 SMESHGUI_SewingDlgLayout->addWidget(GroupConstructors, 0, 0);
132 /***************************************************************/
133 GroupButtons = new QGroupBox(this, "GroupButtons");
134 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
135 (QSizePolicy::SizeType)0, 0, 0,
136 GroupButtons->sizePolicy().hasHeightForWidth()));
137 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
138 GroupButtons->setTitle(tr("" ));
139 GroupButtons->setColumnLayout(0, Qt::Vertical);
140 GroupButtons->layout()->setSpacing(0);
141 GroupButtons->layout()->setMargin(0);
142 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
143 GroupButtonsLayout->setAlignment(Qt::AlignTop);
144 GroupButtonsLayout->setSpacing(6);
145 GroupButtonsLayout->setMargin(11);
146 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
147 buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
148 buttonCancel->setAutoDefault(TRUE);
149 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
150 buttonApply = new QPushButton(GroupButtons, "buttonApply");
151 buttonApply->setText(tr("SMESH_BUT_APPLY"));
152 buttonApply->setAutoDefault(TRUE);
153 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
154 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
155 GroupButtonsLayout->addItem(spacer_9, 0, 2);
156 buttonOk = new QPushButton(GroupButtons, "buttonOk");
157 buttonOk->setText(tr("SMESH_BUT_OK"));
158 buttonOk->setAutoDefault(TRUE);
159 buttonOk->setDefault(TRUE);
160 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
161 SMESHGUI_SewingDlgLayout->addWidget(GroupButtons, 2, 0);
163 /***************************************************************/
164 GroupArguments = new QGroupBox(this, "GroupArguments");
165 GroupArguments->setColumnLayout(0, Qt::Vertical);
166 GroupArguments->layout()->setSpacing(0);
167 GroupArguments->layout()->setMargin(0);
168 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
169 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
170 GroupArgumentsLayout->setSpacing(6);
171 GroupArgumentsLayout->setMargin(11);
174 SubGroup1 = new QGroupBox(GroupArguments, "SubGroup1");
175 SubGroup1->setColumnLayout(0, Qt::Vertical);
176 SubGroup1->layout()->setSpacing(0);
177 SubGroup1->layout()->setMargin(0);
178 QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1->layout());
179 SubGroup1Layout->setAlignment(Qt::AlignTop);
180 SubGroup1Layout->setSpacing(6);
181 SubGroup1Layout->setMargin(11);
183 // Controls of the first subgroup
184 TextLabel1 = new QLabel(SubGroup1, "TextLabel1");
185 TextLabel1->setFixedWidth(104);
186 SubGroup1Layout->addWidget(TextLabel1, 0, 0);
188 SelectButton1 = new QPushButton(SubGroup1, "SelectButton1");
189 SelectButton1->setPixmap(image4);
190 SubGroup1Layout->addWidget(SelectButton1, 0, 1);
192 LineEdit1 = new QLineEdit(SubGroup1, "LineEdit1");
193 SubGroup1Layout->addWidget(LineEdit1, 0, 2);
195 TextLabel2 = new QLabel(SubGroup1, "TextLabel2");
196 SubGroup1Layout->addWidget(TextLabel2, 1, 0);
198 SelectButton2 = new QPushButton(SubGroup1, "SelectButton2");
199 SelectButton2->setPixmap(image4);
200 SubGroup1Layout->addWidget(SelectButton2, 1, 1);
202 LineEdit2 = new QLineEdit(SubGroup1, "LineEdit2");
203 SubGroup1Layout->addWidget(LineEdit2, 1, 2);
205 TextLabel3 = new QLabel(SubGroup1, "TextLabel3");
206 SubGroup1Layout->addWidget(TextLabel3, 2, 0);
208 SelectButton3 = new QPushButton(SubGroup1, "SelectButton3");
209 SelectButton3->setPixmap(image4);
210 SubGroup1Layout->addWidget(SelectButton3, 2, 1);
212 LineEdit3 = new QLineEdit(SubGroup1, "LineEdit3");
213 SubGroup1Layout->addWidget(LineEdit3, 2, 2);
216 SubGroup2 = new QGroupBox(GroupArguments, "SubGroup2");
217 SubGroup2->setColumnLayout(0, Qt::Vertical);
218 SubGroup2->layout()->setSpacing(0);
219 SubGroup2->layout()->setMargin(0);
220 QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2->layout());
221 SubGroup2Layout->setAlignment(Qt::AlignTop);
222 SubGroup2Layout->setSpacing(6);
223 SubGroup2Layout->setMargin(11);
225 // Controls of the first subgroup
226 TextLabel4 = new QLabel(SubGroup2, "TextLabel4");
227 SubGroup2Layout->addWidget(TextLabel4, 0, 0);
229 SelectButton4 = new QPushButton(SubGroup2, "SelectButton4");
230 SelectButton4->setPixmap(image4);
231 SubGroup2Layout->addWidget(SelectButton4, 0, 1);
233 LineEdit4 = new QLineEdit(SubGroup2, "LineEdit4");
234 SubGroup2Layout->addWidget(LineEdit4, 0, 2);
236 TextLabel5 = new QLabel(SubGroup2, "TextLabel5");
237 SubGroup2Layout->addWidget(TextLabel5, 1, 0);
239 SelectButton5 = new QPushButton(SubGroup2, "SelectButton5");
240 SelectButton5->setPixmap(image4);
241 SubGroup2Layout->addWidget(SelectButton5, 1, 1);
243 LineEdit5 = new QLineEdit(SubGroup2, "LineEdit5");
244 SubGroup2Layout->addWidget(LineEdit5, 1, 2);
246 TextLabel6 = new QLabel(SubGroup2, "TextLabel6");
247 SubGroup2Layout->addWidget(TextLabel6, 2, 0);
249 SelectButton6 = new QPushButton(SubGroup2, "SelectButton6");
250 SelectButton6->setPixmap(image4);
251 SubGroup2Layout->addWidget(SelectButton6, 2, 1);
253 LineEdit6 = new QLineEdit(SubGroup2, "LineEdit6");
254 SubGroup2Layout->addWidget(LineEdit6, 2, 2);
256 // Add subgroups to the group of arguments
257 GroupArgumentsLayout->addWidget(SubGroup1, 0, 0);
258 GroupArgumentsLayout->addWidget(SubGroup2, 1, 0);
260 // Control for the merging equal elements
261 CheckBoxMerge = new QCheckBox(GroupArguments, "CheckBoxMerge");
262 CheckBoxMerge->setText(tr("MERGE_EQUAL_ELEMENTS" ));
263 GroupArgumentsLayout->addWidget(CheckBoxMerge, 2, 0);
265 // Control for the polygons creation instead of splitting
266 CheckBoxPolygons = new QCheckBox( GroupArguments, "CheckBoxPolygons" );
267 CheckBoxPolygons->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
268 GroupArgumentsLayout->addWidget( CheckBoxPolygons, 3, 0 );
270 // Control for the polyedres creation to obtain conform mesh
271 CheckBoxPolyedrs = new QCheckBox( GroupArguments, "CheckBoxPolyedrs" );
272 CheckBoxPolyedrs->setText( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ) );
273 GroupArgumentsLayout->addWidget( CheckBoxPolyedrs, 4, 0 );
276 SMESHGUI_SewingDlgLayout->addWidget(GroupArguments, 1, 0);
278 /* Initialisations */
279 GroupArguments->show();
280 RadioButton1->setChecked(TRUE);
282 LineEdit2->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
283 LineEdit3->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
284 LineEdit5->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
285 LineEdit6->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
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 /* Move widget on the botton right corner of main widget */
318 mySMESHGUI->DefineDlgPosition(this, x, y);
320 this->show(); /* displays Dialog */
322 ConstructorsClicked(0);
326 //=================================================================================
327 // function : ~SMESHGUI_SewingDlg()
328 // purpose : Destroys the object and frees any allocated resources
329 //=================================================================================
330 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
332 // no need to delete child widgets, Qt does it all for us
335 //=================================================================================
338 //=================================================================================
339 void SMESHGUI_SewingDlg::Init()
343 myEditCurrentArgument = LineEdit1;
344 LineEdit1->setFocus();
346 myMesh = SMESH::SMESH_Mesh::_nil();
347 CheckBoxMerge->setChecked(false);
348 CheckBoxPolygons->setChecked(false);
349 CheckBoxPolyedrs->setChecked(false);
350 SelectionIntoArgument();
353 //=================================================================================
354 // function : ConstructorsClicked()
355 // purpose : Radio button management
356 //=================================================================================
357 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
359 disconnect(mySelectionMgr, 0, this, 0);
360 mySelectionMgr->clearSelected();
361 LineEdit1->setText("");
362 LineEdit2->setText("");
363 LineEdit3->setText("");
364 LineEdit4->setText("");
365 LineEdit5->setText("");
366 LineEdit6->setText("");
367 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
368 myEditCurrentArgument = LineEdit1;
369 myEditCurrentArgument->setFocus();
371 if (!TextLabel5->isEnabled()) {
372 TextLabel5->setEnabled(true);
373 SelectButton5->setEnabled(true);
374 LineEdit5->setEnabled(true);
375 } else if (!TextLabel6->isEnabled()) {
376 TextLabel6->setEnabled(true);
377 SelectButton6->setEnabled(true);
378 LineEdit6->setEnabled(true);
381 if (constructorId == 1 || constructorId == 3) {
382 if (CheckBoxPolygons->isVisible())
383 CheckBoxPolygons->hide();
384 if (CheckBoxPolyedrs->isVisible())
385 CheckBoxPolyedrs->hide();
388 switch (constructorId) {
391 GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
392 SubGroup1->setTitle(tr("BORDER_1"));
393 SubGroup2->setTitle(tr("BORDER_2"));
395 if (!CheckBoxPolygons->isVisible())
396 CheckBoxPolygons->show();
397 if (!CheckBoxPolyedrs->isVisible())
398 CheckBoxPolyedrs->show();
405 GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
406 SubGroup1->setTitle(tr("BORDER_1"));
407 SubGroup2->setTitle(tr("BORDER_2"));
409 TextLabel6->setEnabled(false);
410 SelectButton6->setEnabled(false);
411 LineEdit6->setEnabled(false);
419 GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
420 SubGroup1->setTitle(tr("BORDER"));
421 SubGroup2->setTitle(tr("SIDE"));
423 TextLabel5->setEnabled(false);
424 SelectButton5->setEnabled(false);
425 LineEdit5->setEnabled(false);
427 if (!CheckBoxPolygons->isVisible())
428 CheckBoxPolygons->show();
429 if (!CheckBoxPolyedrs->isVisible())
430 CheckBoxPolyedrs->show();
439 GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
440 SubGroup1->setTitle(tr("SIDE_1"));
441 SubGroup2->setTitle(tr("SIDE_2"));
443 TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
444 TextLabel2->setText(tr("NODE1_TO_MERGE"));
445 TextLabel3->setText(tr("NODE2_TO_MERGE"));
446 TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
447 TextLabel5->setText(tr("NODE1_TO_MERGE"));
448 TextLabel6->setText(tr("NODE2_TO_MERGE"));
450 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
451 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator"));
453 SMESH::SetPointRepresentation(false);
455 myViewWindow->SetSelectionMode(CellSelection);
460 if (constructorId != 3) {
461 TextLabel1->setText(tr("FIRST_NODE_ID"));
462 TextLabel2->setText(tr("SECOND_NODE_ID"));
463 TextLabel3->setText(tr("LAST_NODE_ID"));
464 TextLabel4->setText(tr("FIRST_NODE_ID"));
465 TextLabel5->setText(tr("SECOND_NODE_ID"));
466 TextLabel6->setText(tr("LAST_NODE_ID"));
468 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
469 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
471 SMESH::SetPointRepresentation(true);
473 myViewWindow->SetSelectionMode(NodeSelection);
476 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
479 //=================================================================================
480 // function : ClickOnApply()
482 //=================================================================================
483 bool SMESHGUI_SewingDlg::ClickOnApply()
485 if (mySMESHGUI->isActiveStudyLocked())
488 bool aResult = false;
491 bool toMerge = CheckBoxMerge->isChecked();
492 bool toCreatePolygons = CheckBoxPolygons->isChecked();
493 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
496 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
497 QApplication::setOverrideCursor(Qt::waitCursor);
499 int aConstructorId = GetConstructorId();
500 SMESH::SMESH_MeshEditor::Sew_Error anError;
502 if (aConstructorId == 0)
503 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
504 LineEdit2->text().toLong(),
505 LineEdit3->text().toLong(),
506 LineEdit4->text().toLong(),
507 LineEdit5->text().toLong(),
508 LineEdit6->text().toLong(),
511 else if (aConstructorId == 1)
512 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
513 LineEdit2->text().toLong(),
514 LineEdit3->text().toLong(),
515 LineEdit4->text().toLong(),
516 LineEdit5->text().toLong());
517 else if (aConstructorId == 2)
518 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
519 LineEdit2->text().toLong(),
520 LineEdit3->text().toLong(),
521 LineEdit4->text().toLong(),
522 LineEdit6->text().toLong(),
525 else if (aConstructorId == 3) {
526 QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
527 QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
529 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
530 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
532 anElementsId1->length(aListElementsId1.count());
533 anElementsId2->length(aListElementsId2.count());
535 for (int i = 0; i < aListElementsId1.count(); i++)
536 anElementsId1[i] = aListElementsId1[i].toInt();
537 for (int i = 0; i < aListElementsId2.count(); i++)
538 anElementsId2[i] = aListElementsId2[i].toInt();
540 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
541 anElementsId2.inout(),
542 LineEdit2->text().toLong(),
543 LineEdit5->text().toLong(),
544 LineEdit3->text().toLong(),
545 LineEdit6->text().toLong());
547 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
549 if (toMerge && aResult)
550 aMeshEditor->MergeEqualElements();
552 QApplication::restoreOverrideCursor();
555 QString msg = tr(QString("ERROR_%1").arg(anError));
556 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
557 msg, tr("SMESH_BUT_OK"));
563 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
567 mySelectionMgr->setSelectedObjects(aList, false);
571 ConstructorsClicked(GetConstructorId());
578 //=================================================================================
579 // function : ClickOnOk()
581 //=================================================================================
582 void SMESHGUI_SewingDlg::ClickOnOk()
588 //=================================================================================
589 // function : ClickOnCancel()
591 //=================================================================================
592 void SMESHGUI_SewingDlg::ClickOnCancel()
594 mySelectionMgr->clearSelected();
595 SMESH::SetPointRepresentation(false);
596 myViewWindow->SetSelectionMode(ActorSelection);
597 disconnect(mySelectionMgr, 0, this, 0);
598 mySMESHGUI->ResetState();
602 //=======================================================================
603 //function : onTextChange
605 //=======================================================================
606 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
608 QLineEdit* send = (QLineEdit*)sender();
614 myEditCurrentArgument = send;
616 if (send == LineEdit1)
618 else if (send == LineEdit2)
620 else if (send == LineEdit3)
622 else if (send == LineEdit4)
624 else if (send == LineEdit5)
626 else if (send == LineEdit6)
629 buttonOk->setEnabled(false);
630 buttonApply->setEnabled(false);
632 // hilight entered elements/nodes
633 SMDS_Mesh* aMesh = 0;
636 aMesh = myActor->GetObject()->GetMesh();
641 TColStd_MapOfInteger newIndices;
643 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
644 SMESH::SetPointRepresentation(true);
646 myViewWindow->SetSelectionMode(NodeSelection);
648 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
650 newIndices.Add(n->GetID());
651 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
652 myViewWindow->highlight( myActor->getIO(), true, true );
654 if (send == LineEdit1)
656 else if (send == LineEdit2)
658 else if (send == LineEdit3)
660 else if (send == LineEdit4)
662 else if (send == LineEdit5)
664 else if (send == LineEdit6)
668 SMESH::SetPointRepresentation(false);
670 myViewWindow->SetSelectionMode(CellSelection);
672 QStringList aListId = QStringList::split(" ", theNewText, false);
674 bool isEvenOneExists = false;
676 for (int i = 0; i < aListId.count(); i++) {
677 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
679 newIndices.Add(e->GetID());
681 if (!isEvenOneExists)
682 isEvenOneExists = true;
686 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
687 myViewWindow->highlight( myActor->getIO(), true, true );
689 if (isEvenOneExists) {
690 if (send == LineEdit1)
692 else if(send == LineEdit4)
701 buttonOk->setEnabled(true);
702 buttonApply->setEnabled(true);
708 //=================================================================================
709 // function : SelectionIntoArgument()
710 // purpose : Called when selection as changed or other case
711 //=================================================================================
712 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
717 if (isSelectionChanged)
720 QString aString = "";
723 myEditCurrentArgument->setText(aString);
726 if (!GroupButtons->isEnabled()) // inactive
729 buttonOk->setEnabled(false);
730 buttonApply->setEnabled(false);
734 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
736 int nbSel = aList.Extent();
740 Handle(SALOME_InteractiveObject) IO = aList.First();
741 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
742 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
744 if (myMesh->_is_nil() || !myActor)
747 // get selected elements/nodes
750 if (GetConstructorId() != 3 ||
751 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
752 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
756 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
762 myEditCurrentArgument->setText(aString);
766 if (myEditCurrentArgument == LineEdit1)
768 else if (myEditCurrentArgument == LineEdit2)
770 else if (myEditCurrentArgument == LineEdit3)
772 else if (myEditCurrentArgument == LineEdit4)
774 else if (myEditCurrentArgument == LineEdit5)
776 else if (myEditCurrentArgument == LineEdit6)
780 buttonOk->setEnabled(true);
781 buttonApply->setEnabled(true);
785 //=================================================================================
786 // function : SetEditCurrentArgument()
788 //=================================================================================
789 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
791 QPushButton* send = (QPushButton*)sender();
793 disconnect(mySelectionMgr, 0, this, 0);
794 mySelectionMgr->clearSelected();
796 if (send == SelectButton1) {
797 myEditCurrentArgument = LineEdit1;
800 else if (send == SelectButton2) {
801 myEditCurrentArgument = LineEdit2;
804 else if (send == SelectButton3) {
805 myEditCurrentArgument = LineEdit3;
808 else if (send == SelectButton4) {
809 myEditCurrentArgument = LineEdit4;
812 else if (send == SelectButton5) {
813 myEditCurrentArgument = LineEdit5;
816 else if (send == SelectButton6) {
817 myEditCurrentArgument = LineEdit6;
821 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
822 SMESH::SetPointRepresentation(true);
824 myViewWindow->SetSelectionMode(NodeSelection);
827 SMESH::SetPointRepresentation(false);
828 myViewWindow->SetSelectionMode(CellSelection);
831 myEditCurrentArgument->setFocus();
832 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
833 SelectionIntoArgument(false);
836 //=================================================================================
837 // function : DeactivateActiveDialog()
839 //=================================================================================
840 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
842 if (GroupConstructors->isEnabled()) {
843 GroupConstructors->setEnabled(false);
844 GroupArguments->setEnabled(false);
845 GroupButtons->setEnabled(false);
846 mySMESHGUI->ResetState();
847 mySMESHGUI->SetActiveDialogBox(0);
851 //=================================================================================
852 // function : ActivateThisDialog()
854 //=================================================================================
855 void SMESHGUI_SewingDlg::ActivateThisDialog()
857 /* Emit a signal to deactivate the active dialog */
858 mySMESHGUI->EmitSignalDeactivateDialog();
859 GroupConstructors->setEnabled(true);
860 GroupArguments->setEnabled(true);
861 GroupButtons->setEnabled(true);
863 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
865 ConstructorsClicked(GetConstructorId());
866 SelectionIntoArgument();
869 //=================================================================================
870 // function : enterEvent()
872 //=================================================================================
873 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
875 if (!GroupConstructors->isEnabled())
876 ActivateThisDialog();
879 //=================================================================================
880 // function : closeEvent()
882 //=================================================================================
883 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
885 /* same than click on cancel button */
886 this->ClickOnCancel();
889 //=======================================================================
890 //function : hideEvent
891 //purpose : caused by ESC key
892 //=======================================================================
893 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
899 //=================================================================================
900 // function : GetConstructorId()
902 //=================================================================================
903 int SMESHGUI_SewingDlg::GetConstructorId()
905 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
906 return GroupConstructors->id(GroupConstructors->selected());
910 //=================================================================================
911 // function : GetConstructorId()
913 //=================================================================================
914 bool SMESHGUI_SewingDlg::IsValid()
916 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);