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 /* 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 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
456 aViewWindow->SetSelectionMode(CellSelection);
461 if (constructorId != 3) {
462 TextLabel1->setText(tr("FIRST_NODE_ID"));
463 TextLabel2->setText(tr("SECOND_NODE_ID"));
464 TextLabel3->setText(tr("LAST_NODE_ID"));
465 TextLabel4->setText(tr("FIRST_NODE_ID"));
466 TextLabel5->setText(tr("SECOND_NODE_ID"));
467 TextLabel6->setText(tr("LAST_NODE_ID"));
469 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
470 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
472 SMESH::SetPointRepresentation(true);
474 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
475 aViewWindow->SetSelectionMode(NodeSelection);
478 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
481 //=================================================================================
482 // function : ClickOnApply()
484 //=================================================================================
485 bool SMESHGUI_SewingDlg::ClickOnApply()
487 if (mySMESHGUI->isActiveStudyLocked())
490 bool aResult = false;
493 bool toMerge = CheckBoxMerge->isChecked();
494 bool toCreatePolygons = CheckBoxPolygons->isChecked();
495 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
498 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
499 QApplication::setOverrideCursor(Qt::waitCursor);
501 int aConstructorId = GetConstructorId();
502 SMESH::SMESH_MeshEditor::Sew_Error anError;
504 if (aConstructorId == 0)
505 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
506 LineEdit2->text().toLong(),
507 LineEdit3->text().toLong(),
508 LineEdit4->text().toLong(),
509 LineEdit5->text().toLong(),
510 LineEdit6->text().toLong(),
513 else if (aConstructorId == 1)
514 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
515 LineEdit2->text().toLong(),
516 LineEdit3->text().toLong(),
517 LineEdit4->text().toLong(),
518 LineEdit5->text().toLong());
519 else if (aConstructorId == 2)
520 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
521 LineEdit2->text().toLong(),
522 LineEdit3->text().toLong(),
523 LineEdit4->text().toLong(),
524 LineEdit6->text().toLong(),
527 else if (aConstructorId == 3) {
528 QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
529 QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
531 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
532 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
534 anElementsId1->length(aListElementsId1.count());
535 anElementsId2->length(aListElementsId2.count());
537 for (int i = 0; i < aListElementsId1.count(); i++)
538 anElementsId1[i] = aListElementsId1[i].toInt();
539 for (int i = 0; i < aListElementsId2.count(); i++)
540 anElementsId2[i] = aListElementsId2[i].toInt();
542 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
543 anElementsId2.inout(),
544 LineEdit2->text().toLong(),
545 LineEdit5->text().toLong(),
546 LineEdit3->text().toLong(),
547 LineEdit6->text().toLong());
549 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
551 if (toMerge && aResult)
552 aMeshEditor->MergeEqualElements();
554 QApplication::restoreOverrideCursor();
557 QString msg = tr(QString("ERROR_%1").arg(anError));
558 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
559 msg, tr("SMESH_BUT_OK"));
565 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
569 mySelectionMgr->setSelectedObjects(aList, false);
573 ConstructorsClicked(GetConstructorId());
580 //=================================================================================
581 // function : ClickOnOk()
583 //=================================================================================
584 void SMESHGUI_SewingDlg::ClickOnOk()
590 //=================================================================================
591 // function : ClickOnCancel()
593 //=================================================================================
594 void SMESHGUI_SewingDlg::ClickOnCancel()
596 mySelectionMgr->clearSelected();
597 SMESH::SetPointRepresentation(false);
598 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
599 aViewWindow->SetSelectionMode(ActorSelection);
600 disconnect(mySelectionMgr, 0, this, 0);
601 mySMESHGUI->ResetState();
605 //=======================================================================
606 //function : onTextChange
608 //=======================================================================
609 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
611 QLineEdit* send = (QLineEdit*)sender();
617 myEditCurrentArgument = send;
619 if (send == LineEdit1)
621 else if (send == LineEdit2)
623 else if (send == LineEdit3)
625 else if (send == LineEdit4)
627 else if (send == LineEdit5)
629 else if (send == LineEdit6)
632 buttonOk->setEnabled(false);
633 buttonApply->setEnabled(false);
635 // hilight entered elements/nodes
636 SMDS_Mesh* aMesh = 0;
639 aMesh = myActor->GetObject()->GetMesh();
644 TColStd_MapOfInteger newIndices;
646 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
647 SMESH::SetPointRepresentation(true);
649 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
650 aViewWindow->SetSelectionMode(NodeSelection);
652 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
654 newIndices.Add(n->GetID());
655 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
656 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
657 aViewWindow->highlight( myActor->getIO(), true, true );
659 if (send == LineEdit1)
661 else if (send == LineEdit2)
663 else if (send == LineEdit3)
665 else if (send == LineEdit4)
667 else if (send == LineEdit5)
669 else if (send == LineEdit6)
673 SMESH::SetPointRepresentation(false);
675 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
676 aViewWindow->SetSelectionMode(CellSelection);
678 QStringList aListId = QStringList::split(" ", theNewText, false);
680 bool isEvenOneExists = false;
682 for (int i = 0; i < aListId.count(); i++) {
683 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
685 newIndices.Add(e->GetID());
687 if (!isEvenOneExists)
688 isEvenOneExists = true;
692 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
693 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
694 aViewWindow->highlight( myActor->getIO(), true, true );
696 if (isEvenOneExists) {
697 if (send == LineEdit1)
699 else if(send == LineEdit4)
708 buttonOk->setEnabled(true);
709 buttonApply->setEnabled(true);
715 //=================================================================================
716 // function : SelectionIntoArgument()
717 // purpose : Called when selection as changed or other case
718 //=================================================================================
719 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
724 if (isSelectionChanged)
727 QString aString = "";
730 myEditCurrentArgument->setText(aString);
733 if (!GroupButtons->isEnabled()) // inactive
736 buttonOk->setEnabled(false);
737 buttonApply->setEnabled(false);
741 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
743 int nbSel = aList.Extent();
747 Handle(SALOME_InteractiveObject) IO = aList.First();
748 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
749 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
751 if (myMesh->_is_nil() || !myActor)
754 // get selected elements/nodes
757 if (GetConstructorId() != 3 ||
758 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
759 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, myActor->getIO(), aString);
763 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, myActor->getIO(), aString);
769 myEditCurrentArgument->setText(aString);
773 if (myEditCurrentArgument == LineEdit1)
775 else if (myEditCurrentArgument == LineEdit2)
777 else if (myEditCurrentArgument == LineEdit3)
779 else if (myEditCurrentArgument == LineEdit4)
781 else if (myEditCurrentArgument == LineEdit5)
783 else if (myEditCurrentArgument == LineEdit6)
787 buttonOk->setEnabled(true);
788 buttonApply->setEnabled(true);
792 //=================================================================================
793 // function : SetEditCurrentArgument()
795 //=================================================================================
796 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
798 QPushButton* send = (QPushButton*)sender();
800 disconnect(mySelectionMgr, 0, this, 0);
801 mySelectionMgr->clearSelected();
803 if (send == SelectButton1) {
804 myEditCurrentArgument = LineEdit1;
807 else if (send == SelectButton2) {
808 myEditCurrentArgument = LineEdit2;
811 else if (send == SelectButton3) {
812 myEditCurrentArgument = LineEdit3;
815 else if (send == SelectButton4) {
816 myEditCurrentArgument = LineEdit4;
819 else if (send == SelectButton5) {
820 myEditCurrentArgument = LineEdit5;
823 else if (send == SelectButton6) {
824 myEditCurrentArgument = LineEdit6;
828 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
829 SMESH::SetPointRepresentation(true);
831 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
832 aViewWindow->SetSelectionMode(NodeSelection);
835 SMESH::SetPointRepresentation(false);
836 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
837 aViewWindow->SetSelectionMode(CellSelection);
840 myEditCurrentArgument->setFocus();
841 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
842 SelectionIntoArgument(false);
845 //=================================================================================
846 // function : DeactivateActiveDialog()
848 //=================================================================================
849 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
851 if (GroupConstructors->isEnabled()) {
852 GroupConstructors->setEnabled(false);
853 GroupArguments->setEnabled(false);
854 GroupButtons->setEnabled(false);
855 mySMESHGUI->ResetState();
856 mySMESHGUI->SetActiveDialogBox(0);
860 //=================================================================================
861 // function : ActivateThisDialog()
863 //=================================================================================
864 void SMESHGUI_SewingDlg::ActivateThisDialog()
866 /* Emit a signal to deactivate the active dialog */
867 mySMESHGUI->EmitSignalDeactivateDialog();
868 GroupConstructors->setEnabled(true);
869 GroupArguments->setEnabled(true);
870 GroupButtons->setEnabled(true);
872 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
874 ConstructorsClicked(GetConstructorId());
875 SelectionIntoArgument();
878 //=================================================================================
879 // function : enterEvent()
881 //=================================================================================
882 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
884 if (!GroupConstructors->isEnabled())
885 ActivateThisDialog();
888 //=================================================================================
889 // function : closeEvent()
891 //=================================================================================
892 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
894 /* same than click on cancel button */
895 this->ClickOnCancel();
898 //=======================================================================
899 //function : hideEvent
900 //purpose : caused by ESC key
901 //=======================================================================
902 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
908 //=================================================================================
909 // function : GetConstructorId()
911 //=================================================================================
912 int SMESHGUI_SewingDlg::GetConstructorId()
914 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
915 return GroupConstructors->id(GroupConstructors->selected());
919 //=================================================================================
920 // function : GetConstructorId()
922 //=================================================================================
923 bool SMESHGUI_SewingDlg::IsValid()
925 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);