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 QPixmap image0 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
83 QPixmap image1 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
84 QPixmap image2 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
85 QPixmap image3 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
86 QPixmap image4 (SMESHGUI::resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT")));
89 setName("SMESHGUI_SewingDlg");
91 setCaption(tr("SMESH_SEWING"));
92 setSizeGripEnabled(TRUE);
93 SMESHGUI_SewingDlgLayout = new QGridLayout(this);
94 SMESHGUI_SewingDlgLayout->setSpacing(6);
95 SMESHGUI_SewingDlgLayout->setMargin(11);
97 /***************************************************************/
98 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
99 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
100 (QSizePolicy::SizeType)0, 0, 0,
101 GroupConstructors->sizePolicy().hasHeightForWidth()));
102 GroupConstructors->setTitle(tr("SMESH_SEWING"));
103 GroupConstructors->setExclusive(TRUE);
104 GroupConstructors->setColumnLayout(0, Qt::Vertical);
105 GroupConstructors->layout()->setSpacing(0);
106 GroupConstructors->layout()->setMargin(0);
107 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
108 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
109 GroupConstructorsLayout->setSpacing(6);
110 GroupConstructorsLayout->setMargin(11);
111 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
112 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
113 RadioButton1->setText(tr("" ));
114 RadioButton1->setPixmap(image0);
115 RBLayout->addWidget(RadioButton1);
116 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
117 RadioButton2->setText(tr("" ));
118 RadioButton2->setPixmap(image1);
119 RBLayout->addWidget(RadioButton2);
120 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
121 RadioButton3->setText(tr("" ));
122 RadioButton3->setPixmap(image2);
123 RBLayout->addWidget(RadioButton3);
124 RadioButton4= new QRadioButton(GroupConstructors, "RadioButton4");
125 RadioButton4->setText(tr("" ));
126 RadioButton4->setPixmap(image3);
127 RBLayout->addWidget(RadioButton4);
128 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
129 SMESHGUI_SewingDlgLayout->addWidget(GroupConstructors, 0, 0);
131 /***************************************************************/
132 GroupButtons = new QGroupBox(this, "GroupButtons");
133 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
134 (QSizePolicy::SizeType)0, 0, 0,
135 GroupButtons->sizePolicy().hasHeightForWidth()));
136 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
137 GroupButtons->setTitle(tr("" ));
138 GroupButtons->setColumnLayout(0, Qt::Vertical);
139 GroupButtons->layout()->setSpacing(0);
140 GroupButtons->layout()->setMargin(0);
141 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
142 GroupButtonsLayout->setAlignment(Qt::AlignTop);
143 GroupButtonsLayout->setSpacing(6);
144 GroupButtonsLayout->setMargin(11);
145 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
146 buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
147 buttonCancel->setAutoDefault(TRUE);
148 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
149 buttonApply = new QPushButton(GroupButtons, "buttonApply");
150 buttonApply->setText(tr("SMESH_BUT_APPLY"));
151 buttonApply->setAutoDefault(TRUE);
152 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
153 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
154 GroupButtonsLayout->addItem(spacer_9, 0, 2);
155 buttonOk = new QPushButton(GroupButtons, "buttonOk");
156 buttonOk->setText(tr("SMESH_BUT_OK"));
157 buttonOk->setAutoDefault(TRUE);
158 buttonOk->setDefault(TRUE);
159 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
160 SMESHGUI_SewingDlgLayout->addWidget(GroupButtons, 2, 0);
162 /***************************************************************/
163 GroupArguments = new QGroupBox(this, "GroupArguments");
164 GroupArguments->setColumnLayout(0, Qt::Vertical);
165 GroupArguments->layout()->setSpacing(0);
166 GroupArguments->layout()->setMargin(0);
167 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
168 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
169 GroupArgumentsLayout->setSpacing(6);
170 GroupArgumentsLayout->setMargin(11);
173 SubGroup1 = new QGroupBox(GroupArguments, "SubGroup1");
174 SubGroup1->setColumnLayout(0, Qt::Vertical);
175 SubGroup1->layout()->setSpacing(0);
176 SubGroup1->layout()->setMargin(0);
177 QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1->layout());
178 SubGroup1Layout->setAlignment(Qt::AlignTop);
179 SubGroup1Layout->setSpacing(6);
180 SubGroup1Layout->setMargin(11);
182 // Controls of the first subgroup
183 TextLabel1 = new QLabel(SubGroup1, "TextLabel1");
184 TextLabel1->setFixedWidth(104);
185 SubGroup1Layout->addWidget(TextLabel1, 0, 0);
187 SelectButton1 = new QPushButton(SubGroup1, "SelectButton1");
188 SelectButton1->setPixmap(image4);
189 SubGroup1Layout->addWidget(SelectButton1, 0, 1);
191 LineEdit1 = new QLineEdit(SubGroup1, "LineEdit1");
192 SubGroup1Layout->addWidget(LineEdit1, 0, 2);
194 TextLabel2 = new QLabel(SubGroup1, "TextLabel2");
195 SubGroup1Layout->addWidget(TextLabel2, 1, 0);
197 SelectButton2 = new QPushButton(SubGroup1, "SelectButton2");
198 SelectButton2->setPixmap(image4);
199 SubGroup1Layout->addWidget(SelectButton2, 1, 1);
201 LineEdit2 = new QLineEdit(SubGroup1, "LineEdit2");
202 SubGroup1Layout->addWidget(LineEdit2, 1, 2);
204 TextLabel3 = new QLabel(SubGroup1, "TextLabel3");
205 SubGroup1Layout->addWidget(TextLabel3, 2, 0);
207 SelectButton3 = new QPushButton(SubGroup1, "SelectButton3");
208 SelectButton3->setPixmap(image4);
209 SubGroup1Layout->addWidget(SelectButton3, 2, 1);
211 LineEdit3 = new QLineEdit(SubGroup1, "LineEdit3");
212 SubGroup1Layout->addWidget(LineEdit3, 2, 2);
215 SubGroup2 = new QGroupBox(GroupArguments, "SubGroup2");
216 SubGroup2->setColumnLayout(0, Qt::Vertical);
217 SubGroup2->layout()->setSpacing(0);
218 SubGroup2->layout()->setMargin(0);
219 QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2->layout());
220 SubGroup2Layout->setAlignment(Qt::AlignTop);
221 SubGroup2Layout->setSpacing(6);
222 SubGroup2Layout->setMargin(11);
224 // Controls of the first subgroup
225 TextLabel4 = new QLabel(SubGroup2, "TextLabel4");
226 SubGroup2Layout->addWidget(TextLabel4, 0, 0);
228 SelectButton4 = new QPushButton(SubGroup2, "SelectButton4");
229 SelectButton4->setPixmap(image4);
230 SubGroup2Layout->addWidget(SelectButton4, 0, 1);
232 LineEdit4 = new QLineEdit(SubGroup2, "LineEdit4");
233 SubGroup2Layout->addWidget(LineEdit4, 0, 2);
235 TextLabel5 = new QLabel(SubGroup2, "TextLabel5");
236 SubGroup2Layout->addWidget(TextLabel5, 1, 0);
238 SelectButton5 = new QPushButton(SubGroup2, "SelectButton5");
239 SelectButton5->setPixmap(image4);
240 SubGroup2Layout->addWidget(SelectButton5, 1, 1);
242 LineEdit5 = new QLineEdit(SubGroup2, "LineEdit5");
243 SubGroup2Layout->addWidget(LineEdit5, 1, 2);
245 TextLabel6 = new QLabel(SubGroup2, "TextLabel6");
246 SubGroup2Layout->addWidget(TextLabel6, 2, 0);
248 SelectButton6 = new QPushButton(SubGroup2, "SelectButton6");
249 SelectButton6->setPixmap(image4);
250 SubGroup2Layout->addWidget(SelectButton6, 2, 1);
252 LineEdit6 = new QLineEdit(SubGroup2, "LineEdit6");
253 SubGroup2Layout->addWidget(LineEdit6, 2, 2);
255 // Add subgroups to the group of arguments
256 GroupArgumentsLayout->addWidget(SubGroup1, 0, 0);
257 GroupArgumentsLayout->addWidget(SubGroup2, 1, 0);
259 // Control for the merging equal elements
260 CheckBoxMerge = new QCheckBox(GroupArguments, "CheckBoxMerge");
261 CheckBoxMerge->setText(tr("MERGE_EQUAL_ELEMENTS" ));
262 GroupArgumentsLayout->addWidget(CheckBoxMerge, 2, 0);
264 // Control for the polygons creation instead of splitting
265 CheckBoxPolygons = new QCheckBox( GroupArguments, "CheckBoxPolygons" );
266 CheckBoxPolygons->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
267 GroupArgumentsLayout->addWidget( CheckBoxPolygons, 3, 0 );
269 // Control for the polyedres creation to obtain conform mesh
270 CheckBoxPolyedrs = new QCheckBox( GroupArguments, "CheckBoxPolyedrs" );
271 CheckBoxPolyedrs->setText( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ) );
272 GroupArgumentsLayout->addWidget( CheckBoxPolyedrs, 4, 0 );
275 SMESHGUI_SewingDlgLayout->addWidget(GroupArguments, 1, 0);
277 /* Initialisations */
278 GroupArguments->show();
279 RadioButton1->setChecked(TRUE);
281 LineEdit2->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
282 LineEdit3->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
283 LineEdit5->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
284 LineEdit6->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
286 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
290 /* signals and slots connections */
291 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
292 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
293 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
294 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
296 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
297 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
298 connect(SelectButton3, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
299 connect(SelectButton4, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
300 connect(SelectButton5, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
301 connect(SelectButton6, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
303 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
304 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
305 /* to close dialog if study change */
306 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
308 connect(LineEdit1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
309 connect(LineEdit2, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
310 connect(LineEdit3, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
311 connect(LineEdit4, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
312 connect(LineEdit5, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
313 connect(LineEdit6, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
315 /* Move widget on the botton right corner of main widget */
317 mySMESHGUI->DefineDlgPosition(this, x, y);
319 this->show(); /* displays Dialog */
321 ConstructorsClicked(0);
325 //=================================================================================
326 // function : ~SMESHGUI_SewingDlg()
327 // purpose : Destroys the object and frees any allocated resources
328 //=================================================================================
329 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
331 // no need to delete child widgets, Qt does it all for us
334 //=================================================================================
337 //=================================================================================
338 void SMESHGUI_SewingDlg::Init()
342 myEditCurrentArgument = LineEdit1;
343 LineEdit1->setFocus();
345 myMesh = SMESH::SMESH_Mesh::_nil();
346 CheckBoxMerge->setChecked(false);
347 CheckBoxPolygons->setChecked(false);
348 CheckBoxPolyedrs->setChecked(false);
349 SelectionIntoArgument();
352 //=================================================================================
353 // function : ConstructorsClicked()
354 // purpose : Radio button management
355 //=================================================================================
356 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
358 disconnect(mySelectionMgr, 0, this, 0);
359 mySelectionMgr->clearSelected();
360 LineEdit1->setText("");
361 LineEdit2->setText("");
362 LineEdit3->setText("");
363 LineEdit4->setText("");
364 LineEdit5->setText("");
365 LineEdit6->setText("");
366 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
367 myEditCurrentArgument = LineEdit1;
368 myEditCurrentArgument->setFocus();
370 if (!TextLabel5->isEnabled()) {
371 TextLabel5->setEnabled(true);
372 SelectButton5->setEnabled(true);
373 LineEdit5->setEnabled(true);
374 } else if (!TextLabel6->isEnabled()) {
375 TextLabel6->setEnabled(true);
376 SelectButton6->setEnabled(true);
377 LineEdit6->setEnabled(true);
380 if (constructorId == 1 || constructorId == 3) {
381 if (CheckBoxPolygons->isVisible())
382 CheckBoxPolygons->hide();
383 if (CheckBoxPolyedrs->isVisible())
384 CheckBoxPolyedrs->hide();
387 switch (constructorId) {
390 GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
391 SubGroup1->setTitle(tr("BORDER_1"));
392 SubGroup2->setTitle(tr("BORDER_2"));
394 if (!CheckBoxPolygons->isVisible())
395 CheckBoxPolygons->show();
396 if (!CheckBoxPolyedrs->isVisible())
397 CheckBoxPolyedrs->show();
404 GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
405 SubGroup1->setTitle(tr("BORDER_1"));
406 SubGroup2->setTitle(tr("BORDER_2"));
408 TextLabel6->setEnabled(false);
409 SelectButton6->setEnabled(false);
410 LineEdit6->setEnabled(false);
418 GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
419 SubGroup1->setTitle(tr("BORDER"));
420 SubGroup2->setTitle(tr("SIDE"));
422 TextLabel5->setEnabled(false);
423 SelectButton5->setEnabled(false);
424 LineEdit5->setEnabled(false);
426 if (!CheckBoxPolygons->isVisible())
427 CheckBoxPolygons->show();
428 if (!CheckBoxPolyedrs->isVisible())
429 CheckBoxPolyedrs->show();
438 GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
439 SubGroup1->setTitle(tr("SIDE_1"));
440 SubGroup2->setTitle(tr("SIDE_2"));
442 TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
443 TextLabel2->setText(tr("NODE1_TO_MERGE"));
444 TextLabel3->setText(tr("NODE2_TO_MERGE"));
445 TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
446 TextLabel5->setText(tr("NODE1_TO_MERGE"));
447 TextLabel6->setText(tr("NODE2_TO_MERGE"));
449 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
450 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator"));
452 SMESH::SetPointRepresentation(false);
454 myViewWindow->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 myViewWindow->SetSelectionMode(NodeSelection);
475 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
478 //=================================================================================
479 // function : ClickOnApply()
481 //=================================================================================
482 bool SMESHGUI_SewingDlg::ClickOnApply()
484 if (mySMESHGUI->isActiveStudyLocked())
487 bool aResult = false;
490 bool toMerge = CheckBoxMerge->isChecked();
491 bool toCreatePolygons = CheckBoxPolygons->isChecked();
492 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
495 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
496 QApplication::setOverrideCursor(Qt::waitCursor);
498 int aConstructorId = GetConstructorId();
499 SMESH::SMESH_MeshEditor::Sew_Error anError;
501 if (aConstructorId == 0)
502 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
503 LineEdit2->text().toLong(),
504 LineEdit3->text().toLong(),
505 LineEdit4->text().toLong(),
506 LineEdit5->text().toLong(),
507 LineEdit6->text().toLong(),
510 else if (aConstructorId == 1)
511 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
512 LineEdit2->text().toLong(),
513 LineEdit3->text().toLong(),
514 LineEdit4->text().toLong(),
515 LineEdit5->text().toLong());
516 else if (aConstructorId == 2)
517 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
518 LineEdit2->text().toLong(),
519 LineEdit3->text().toLong(),
520 LineEdit4->text().toLong(),
521 LineEdit6->text().toLong(),
524 else if (aConstructorId == 3) {
525 QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
526 QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
528 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
529 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
531 anElementsId1->length(aListElementsId1.count());
532 anElementsId2->length(aListElementsId2.count());
534 for (int i = 0; i < aListElementsId1.count(); i++)
535 anElementsId1[i] = aListElementsId1[i].toInt();
536 for (int i = 0; i < aListElementsId2.count(); i++)
537 anElementsId2[i] = aListElementsId2[i].toInt();
539 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
540 anElementsId2.inout(),
541 LineEdit2->text().toLong(),
542 LineEdit5->text().toLong(),
543 LineEdit3->text().toLong(),
544 LineEdit6->text().toLong());
546 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
548 if (toMerge && aResult)
549 aMeshEditor->MergeEqualElements();
551 QApplication::restoreOverrideCursor();
554 QString msg = tr(QString("ERROR_%1").arg(anError));
555 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
556 msg, tr("SMESH_BUT_OK"));
562 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
566 mySelectionMgr->setSelectedObjects(aList, false);
570 ConstructorsClicked(GetConstructorId());
577 //=================================================================================
578 // function : ClickOnOk()
580 //=================================================================================
581 void SMESHGUI_SewingDlg::ClickOnOk()
587 //=================================================================================
588 // function : ClickOnCancel()
590 //=================================================================================
591 void SMESHGUI_SewingDlg::ClickOnCancel()
593 mySelectionMgr->clearSelected();
594 SMESH::SetPointRepresentation(false);
595 myViewWindow->SetSelectionMode(ActorSelection);
596 disconnect(mySelectionMgr, 0, this, 0);
597 mySMESHGUI->ResetState();
601 //=======================================================================
602 //function : onTextChange
604 //=======================================================================
605 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
607 QLineEdit* send = (QLineEdit*)sender();
613 myEditCurrentArgument = send;
615 if (send == LineEdit1)
617 else if (send == LineEdit2)
619 else if (send == LineEdit3)
621 else if (send == LineEdit4)
623 else if (send == LineEdit5)
625 else if (send == LineEdit6)
628 buttonOk->setEnabled(false);
629 buttonApply->setEnabled(false);
631 // hilight entered elements/nodes
632 SMDS_Mesh* aMesh = 0;
635 aMesh = myActor->GetObject()->GetMesh();
640 //mySelectionMgr->clearSelected();
641 //mySelectionMgr->AddIObject(myActor->getIO());
643 aList.Append(myActor->getIO());
644 mySelectionMgr->setSelectedObjects(aList, false);
646 TColStd_IndexedMapOfInteger selectedIndices;
647 TColStd_MapOfInteger newIndices;
648 mySelector->GetIndex( myActor->getIO(), selectedIndices);
650 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
651 SMESH::SetPointRepresentation(true);
653 myViewWindow->SetSelectionMode(NodeSelection);
655 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
657 //if (!mySelectionMgr->IsIndexSelected(myActor->getIO(), n->GetID())) {
658 if (selectedIndices.Add(n->GetID())) {
659 //mySelectionMgr->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
660 newIndices.Add(n->GetID());
661 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, true);
662 myViewWindow->highlight( myActor->getIO(), true, true );
665 if (send == LineEdit1)
667 else if (send == LineEdit2)
669 else if (send == LineEdit3)
671 else if (send == LineEdit4)
673 else if (send == LineEdit5)
675 else if (send == LineEdit6)
679 SMESH::SetPointRepresentation(false);
681 myViewWindow->SetSelectionMode(CellSelection);
683 QStringList aListId = QStringList::split(" ", theNewText, false);
685 bool isEvenOneExists = false;
687 for (int i = 0; i < aListId.count(); i++) {
688 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
690 //if (!mySelectionMgr->IsIndexSelected(myActor->getIO(), e->GetID())) {
691 if (selectedIndices.Add(e->GetID())) {
692 //mySelectionMgr->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
693 newIndices.Add(e->GetID());
695 if (!isEvenOneExists)
696 isEvenOneExists = true;
700 if (newIndices.Extent() > 0)
702 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, true);
703 myViewWindow->highlight( myActor->getIO(), true, true );
706 if (isEvenOneExists) {
707 if (send == LineEdit1)
709 else if(send == LineEdit4)
718 buttonOk->setEnabled(true);
719 buttonApply->setEnabled(true);
725 //=================================================================================
726 // function : SelectionIntoArgument()
727 // purpose : Called when selection as changed or other case
728 //=================================================================================
729 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
734 if (isSelectionChanged)
737 QString aString = "";
740 myEditCurrentArgument->setText(aString);
743 if (!GroupButtons->isEnabled()) // inactive
746 buttonOk->setEnabled(false);
747 buttonApply->setEnabled(false);
751 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
753 int nbSel = aList.Extent();
757 Handle(SALOME_InteractiveObject) IO = aList.First();
758 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
759 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
761 if (myMesh->_is_nil() || !myActor)
764 // get selected elements/nodes
767 if (GetConstructorId() != 3 ||
768 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
769 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
773 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
779 myEditCurrentArgument->setText(aString);
783 if (myEditCurrentArgument == LineEdit1)
785 else if (myEditCurrentArgument == LineEdit2)
787 else if (myEditCurrentArgument == LineEdit3)
789 else if (myEditCurrentArgument == LineEdit4)
791 else if (myEditCurrentArgument == LineEdit5)
793 else if (myEditCurrentArgument == LineEdit6)
797 buttonOk->setEnabled(true);
798 buttonApply->setEnabled(true);
802 //=================================================================================
803 // function : SetEditCurrentArgument()
805 //=================================================================================
806 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
808 QPushButton* send = (QPushButton*)sender();
810 disconnect(mySelectionMgr, 0, this, 0);
811 mySelectionMgr->clearSelected();
813 if (send == SelectButton1) {
814 myEditCurrentArgument = LineEdit1;
817 else if (send == SelectButton2) {
818 myEditCurrentArgument = LineEdit2;
821 else if (send == SelectButton3) {
822 myEditCurrentArgument = LineEdit3;
825 else if (send == SelectButton4) {
826 myEditCurrentArgument = LineEdit4;
829 else if (send == SelectButton5) {
830 myEditCurrentArgument = LineEdit5;
833 else if (send == SelectButton6) {
834 myEditCurrentArgument = LineEdit6;
838 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
839 SMESH::SetPointRepresentation(true);
841 myViewWindow->SetSelectionMode(NodeSelection);
844 SMESH::SetPointRepresentation(false);
845 myViewWindow->SetSelectionMode(CellSelection);
848 myEditCurrentArgument->setFocus();
849 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
850 SelectionIntoArgument(false);
853 //=================================================================================
854 // function : DeactivateActiveDialog()
856 //=================================================================================
857 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
859 if (GroupConstructors->isEnabled()) {
860 GroupConstructors->setEnabled(false);
861 GroupArguments->setEnabled(false);
862 GroupButtons->setEnabled(false);
863 mySMESHGUI->ResetState();
864 mySMESHGUI->SetActiveDialogBox(0);
868 //=================================================================================
869 // function : ActivateThisDialog()
871 //=================================================================================
872 void SMESHGUI_SewingDlg::ActivateThisDialog()
874 /* Emit a signal to deactivate the active dialog */
875 mySMESHGUI->EmitSignalDeactivateDialog();
876 GroupConstructors->setEnabled(true);
877 GroupArguments->setEnabled(true);
878 GroupButtons->setEnabled(true);
880 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
882 ConstructorsClicked(GetConstructorId());
883 SelectionIntoArgument();
886 //=================================================================================
887 // function : enterEvent()
889 //=================================================================================
890 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
892 if (!GroupConstructors->isEnabled())
893 ActivateThisDialog();
896 //=================================================================================
897 // function : closeEvent()
899 //=================================================================================
900 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
902 /* same than click on cancel button */
903 this->ClickOnCancel();
906 //=======================================================================
907 //function : hideEvent
908 //purpose : caused by ESC key
909 //=======================================================================
910 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
916 //=================================================================================
917 // function : GetConstructorId()
919 //=================================================================================
920 int SMESHGUI_SewingDlg::GetConstructorId()
922 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
923 return GroupConstructors->id(GroupConstructors->selected());
927 //=================================================================================
928 // function : GetConstructorId()
930 //=================================================================================
931 bool SMESHGUI_SewingDlg::IsValid()
933 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);