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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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_MeshUtils.h"
35 #include "SMESHGUI_IdValidator.h"
37 #include "SMESH_Actor.h"
38 #include "SMDS_Mesh.hxx"
40 #include "SUIT_Session.h"
41 #include "SUIT_ResourceMgr.h"
42 #include "SUIT_Desktop.h"
43 #include "SUIT_MessageBox.h"
45 #include "LightApp_Application.h"
47 #include "SVTK_ViewModel.h"
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_Selector.h"
50 #include "SVTK_Selection.h"
51 #include "SALOME_ListIO.hxx"
53 #include "utilities.h"
56 #include <TColStd_MapOfInteger.hxx>
57 #include <TColStd_IndexedMapOfInteger.hxx>
60 #include <qapplication.h>
61 #include <qbuttongroup.h>
62 #include <qgroupbox.h>
64 #include <qlineedit.h>
65 #include <qpushbutton.h>
66 #include <qradiobutton.h>
67 #include <qcheckbox.h>
73 //=================================================================================
74 // class : SMESHGUI_SewingDlg()
76 //=================================================================================
77 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( SMESHGUI* theModule, const char* name,
78 bool modal, WFlags fl)
79 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
80 WStyle_Title | WStyle_SysMenu | Qt::WDestructiveClose),
81 mySMESHGUI( theModule ),
82 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
84 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
85 QPixmap image0 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_FREEBORDERS")));
86 QPixmap image1 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
87 QPixmap image2 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
88 QPixmap image3 (mgr->loadPixmap("SMESH", tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
89 QPixmap image4 (mgr->loadPixmap("SMESH", tr("ICON_SELECT")));
92 setName("SMESHGUI_SewingDlg");
94 setCaption(tr("SMESH_SEWING"));
95 setSizeGripEnabled(TRUE);
96 SMESHGUI_SewingDlgLayout = new QGridLayout(this);
97 SMESHGUI_SewingDlgLayout->setSpacing(6);
98 SMESHGUI_SewingDlgLayout->setMargin(11);
100 /***************************************************************/
101 GroupConstructors = new QButtonGroup(this, "GroupConstructors");
102 GroupConstructors->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)5,
103 (QSizePolicy::SizeType)0, 0, 0,
104 GroupConstructors->sizePolicy().hasHeightForWidth()));
105 GroupConstructors->setTitle(tr("SMESH_SEWING"));
106 GroupConstructors->setExclusive(TRUE);
107 GroupConstructors->setColumnLayout(0, Qt::Vertical);
108 GroupConstructors->layout()->setSpacing(0);
109 GroupConstructors->layout()->setMargin(0);
110 GroupConstructorsLayout = new QGridLayout(GroupConstructors->layout());
111 GroupConstructorsLayout->setAlignment(Qt::AlignTop);
112 GroupConstructorsLayout->setSpacing(6);
113 GroupConstructorsLayout->setMargin(11);
114 QHBoxLayout* RBLayout = new QHBoxLayout(0, 0, 6, "Layout2");
115 RadioButton1= new QRadioButton(GroupConstructors, "RadioButton1");
116 RadioButton1->setText(tr("" ));
117 RadioButton1->setPixmap(image0);
118 RBLayout->addWidget(RadioButton1);
119 RadioButton2= new QRadioButton(GroupConstructors, "RadioButton2");
120 RadioButton2->setText(tr("" ));
121 RadioButton2->setPixmap(image1);
122 RBLayout->addWidget(RadioButton2);
123 RadioButton3= new QRadioButton(GroupConstructors, "RadioButton3");
124 RadioButton3->setText(tr("" ));
125 RadioButton3->setPixmap(image2);
126 RBLayout->addWidget(RadioButton3);
127 RadioButton4= new QRadioButton(GroupConstructors, "RadioButton4");
128 RadioButton4->setText(tr("" ));
129 RadioButton4->setPixmap(image3);
130 RBLayout->addWidget(RadioButton4);
131 GroupConstructorsLayout->addLayout(RBLayout, 0, 0);
132 SMESHGUI_SewingDlgLayout->addWidget(GroupConstructors, 0, 0);
134 /***************************************************************/
135 GroupButtons = new QGroupBox(this, "GroupButtons");
136 GroupButtons->setSizePolicy(QSizePolicy((QSizePolicy::SizeType)7,
137 (QSizePolicy::SizeType)0, 0, 0,
138 GroupButtons->sizePolicy().hasHeightForWidth()));
139 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
140 GroupButtons->setTitle(tr("" ));
141 GroupButtons->setColumnLayout(0, Qt::Vertical);
142 GroupButtons->layout()->setSpacing(0);
143 GroupButtons->layout()->setMargin(0);
144 GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
145 GroupButtonsLayout->setAlignment(Qt::AlignTop);
146 GroupButtonsLayout->setSpacing(6);
147 GroupButtonsLayout->setMargin(11);
148 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
149 buttonHelp->setText(tr("SMESH_BUT_HELP" ));
150 buttonHelp->setAutoDefault(TRUE);
151 GroupButtonsLayout->addWidget(buttonHelp, 0, 4);
152 buttonCancel = new QPushButton(GroupButtons, "buttonCancel");
153 buttonCancel->setText(tr("SMESH_BUT_CLOSE"));
154 buttonCancel->setAutoDefault(TRUE);
155 GroupButtonsLayout->addWidget(buttonCancel, 0, 3);
156 buttonApply = new QPushButton(GroupButtons, "buttonApply");
157 buttonApply->setText(tr("SMESH_BUT_APPLY"));
158 buttonApply->setAutoDefault(TRUE);
159 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
160 QSpacerItem* spacer_9 = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
161 GroupButtonsLayout->addItem(spacer_9, 0, 2);
162 buttonOk = new QPushButton(GroupButtons, "buttonOk");
163 buttonOk->setText(tr("SMESH_BUT_OK"));
164 buttonOk->setAutoDefault(TRUE);
165 buttonOk->setDefault(TRUE);
166 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
167 SMESHGUI_SewingDlgLayout->addWidget(GroupButtons, 2, 0);
169 /***************************************************************/
170 GroupArguments = new QGroupBox(this, "GroupArguments");
171 GroupArguments->setColumnLayout(0, Qt::Vertical);
172 GroupArguments->layout()->setSpacing(0);
173 GroupArguments->layout()->setMargin(0);
174 GroupArgumentsLayout = new QGridLayout(GroupArguments->layout());
175 GroupArgumentsLayout->setAlignment(Qt::AlignTop);
176 GroupArgumentsLayout->setSpacing(6);
177 GroupArgumentsLayout->setMargin(11);
180 SubGroup1 = new QGroupBox(GroupArguments, "SubGroup1");
181 SubGroup1->setColumnLayout(0, Qt::Vertical);
182 SubGroup1->layout()->setSpacing(0);
183 SubGroup1->layout()->setMargin(0);
184 QGridLayout* SubGroup1Layout = new QGridLayout(SubGroup1->layout());
185 SubGroup1Layout->setAlignment(Qt::AlignTop);
186 SubGroup1Layout->setSpacing(6);
187 SubGroup1Layout->setMargin(11);
189 // Controls of the first subgroup
190 TextLabel1 = new QLabel(SubGroup1, "TextLabel1");
191 TextLabel1->setFixedWidth(104);
192 SubGroup1Layout->addWidget(TextLabel1, 0, 0);
194 SelectButton1 = new QPushButton(SubGroup1, "SelectButton1");
195 SelectButton1->setPixmap(image4);
196 SubGroup1Layout->addWidget(SelectButton1, 0, 1);
198 LineEdit1 = new QLineEdit(SubGroup1, "LineEdit1");
199 SubGroup1Layout->addWidget(LineEdit1, 0, 2);
201 TextLabel2 = new QLabel(SubGroup1, "TextLabel2");
202 SubGroup1Layout->addWidget(TextLabel2, 1, 0);
204 SelectButton2 = new QPushButton(SubGroup1, "SelectButton2");
205 SelectButton2->setPixmap(image4);
206 SubGroup1Layout->addWidget(SelectButton2, 1, 1);
208 LineEdit2 = new QLineEdit(SubGroup1, "LineEdit2");
209 SubGroup1Layout->addWidget(LineEdit2, 1, 2);
211 TextLabel3 = new QLabel(SubGroup1, "TextLabel3");
212 SubGroup1Layout->addWidget(TextLabel3, 2, 0);
214 SelectButton3 = new QPushButton(SubGroup1, "SelectButton3");
215 SelectButton3->setPixmap(image4);
216 SubGroup1Layout->addWidget(SelectButton3, 2, 1);
218 LineEdit3 = new QLineEdit(SubGroup1, "LineEdit3");
219 SubGroup1Layout->addWidget(LineEdit3, 2, 2);
222 SubGroup2 = new QGroupBox(GroupArguments, "SubGroup2");
223 SubGroup2->setColumnLayout(0, Qt::Vertical);
224 SubGroup2->layout()->setSpacing(0);
225 SubGroup2->layout()->setMargin(0);
226 QGridLayout* SubGroup2Layout = new QGridLayout(SubGroup2->layout());
227 SubGroup2Layout->setAlignment(Qt::AlignTop);
228 SubGroup2Layout->setSpacing(6);
229 SubGroup2Layout->setMargin(11);
231 // Controls of the first subgroup
232 TextLabel4 = new QLabel(SubGroup2, "TextLabel4");
233 SubGroup2Layout->addWidget(TextLabel4, 0, 0);
235 SelectButton4 = new QPushButton(SubGroup2, "SelectButton4");
236 SelectButton4->setPixmap(image4);
237 SubGroup2Layout->addWidget(SelectButton4, 0, 1);
239 LineEdit4 = new QLineEdit(SubGroup2, "LineEdit4");
240 SubGroup2Layout->addWidget(LineEdit4, 0, 2);
242 TextLabel5 = new QLabel(SubGroup2, "TextLabel5");
243 SubGroup2Layout->addWidget(TextLabel5, 1, 0);
245 SelectButton5 = new QPushButton(SubGroup2, "SelectButton5");
246 SelectButton5->setPixmap(image4);
247 SubGroup2Layout->addWidget(SelectButton5, 1, 1);
249 LineEdit5 = new QLineEdit(SubGroup2, "LineEdit5");
250 SubGroup2Layout->addWidget(LineEdit5, 1, 2);
252 TextLabel6 = new QLabel(SubGroup2, "TextLabel6");
253 SubGroup2Layout->addWidget(TextLabel6, 2, 0);
255 SelectButton6 = new QPushButton(SubGroup2, "SelectButton6");
256 SelectButton6->setPixmap(image4);
257 SubGroup2Layout->addWidget(SelectButton6, 2, 1);
259 LineEdit6 = new QLineEdit(SubGroup2, "LineEdit6");
260 SubGroup2Layout->addWidget(LineEdit6, 2, 2);
262 // Add subgroups to the group of arguments
263 GroupArgumentsLayout->addWidget(SubGroup1, 0, 0);
264 GroupArgumentsLayout->addWidget(SubGroup2, 1, 0);
266 // Control for the merging equal elements
267 CheckBoxMerge = new QCheckBox(GroupArguments, "CheckBoxMerge");
268 CheckBoxMerge->setText(tr("MERGE_EQUAL_ELEMENTS" ));
269 GroupArgumentsLayout->addWidget(CheckBoxMerge, 2, 0);
271 // Control for the polygons creation instead of splitting
272 CheckBoxPolygons = new QCheckBox( GroupArguments, "CheckBoxPolygons" );
273 CheckBoxPolygons->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
274 GroupArgumentsLayout->addWidget( CheckBoxPolygons, 3, 0 );
276 // Control for the polyedres creation to obtain conform mesh
277 CheckBoxPolyedrs = new QCheckBox( GroupArguments, "CheckBoxPolyedrs" );
278 CheckBoxPolyedrs->setText( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ) );
279 GroupArgumentsLayout->addWidget( CheckBoxPolyedrs, 4, 0 );
282 SMESHGUI_SewingDlgLayout->addWidget(GroupArguments, 1, 0);
284 /* Initialisations */
285 GroupArguments->show();
286 RadioButton1->setChecked(TRUE);
288 LineEdit2->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
289 LineEdit3->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
290 LineEdit5->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
291 LineEdit6->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
293 mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector();
295 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
297 myHelpFileName = "/files/sewing_meshes.htm";
301 /* signals and slots connections */
302 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
303 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
304 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
305 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
306 connect(GroupConstructors, SIGNAL(clicked(int)), SLOT(ConstructorsClicked(int)));
308 connect(SelectButton1, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
309 connect(SelectButton2, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
310 connect(SelectButton3, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
311 connect(SelectButton4, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
312 connect(SelectButton5, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
313 connect(SelectButton6, SIGNAL (clicked()), this, SLOT(SetEditCurrentArgument()));
315 connect(mySMESHGUI, SIGNAL (SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
316 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
317 /* to close dialog if study change */
318 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
320 connect(LineEdit1, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
321 connect(LineEdit2, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
322 connect(LineEdit3, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
323 connect(LineEdit4, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
324 connect(LineEdit5, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
325 connect(LineEdit6, SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
327 this->show(); /* displays Dialog */
329 ConstructorsClicked(0);
333 //=================================================================================
334 // function : ~SMESHGUI_SewingDlg()
335 // purpose : Destroys the object and frees any allocated resources
336 //=================================================================================
337 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
339 // no need to delete child widgets, Qt does it all for us
342 //=================================================================================
345 //=================================================================================
346 void SMESHGUI_SewingDlg::Init()
350 myEditCurrentArgument = LineEdit1;
351 LineEdit1->setFocus();
353 myMesh = SMESH::SMESH_Mesh::_nil();
354 CheckBoxMerge->setChecked(false);
355 CheckBoxPolygons->setChecked(false);
356 CheckBoxPolyedrs->setChecked(false);
357 SelectionIntoArgument();
360 //=================================================================================
361 // function : ConstructorsClicked()
362 // purpose : Radio button management
363 //=================================================================================
364 void SMESHGUI_SewingDlg::ConstructorsClicked (int constructorId)
366 disconnect(mySelectionMgr, 0, this, 0);
368 mySelectionMgr->selectedObjects( io );
369 mySelectionMgr->clearSelected();
370 LineEdit1->setText("");
371 LineEdit2->setText("");
372 LineEdit3->setText("");
373 LineEdit4->setText("");
374 LineEdit5->setText("");
375 LineEdit6->setText("");
376 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
377 myEditCurrentArgument = LineEdit1;
378 myEditCurrentArgument->setFocus();
380 if (!TextLabel5->isEnabled()) {
381 TextLabel5->setEnabled(true);
382 SelectButton5->setEnabled(true);
383 LineEdit5->setEnabled(true);
384 } else if (!TextLabel6->isEnabled()) {
385 TextLabel6->setEnabled(true);
386 SelectButton6->setEnabled(true);
387 LineEdit6->setEnabled(true);
390 if (constructorId == 1 || constructorId == 3) {
391 if (CheckBoxPolygons->isVisible())
392 CheckBoxPolygons->hide();
393 if (CheckBoxPolyedrs->isVisible())
394 CheckBoxPolyedrs->hide();
397 switch (constructorId) {
400 GroupArguments->setTitle(tr("SEW_FREE_BORDERS"));
401 SubGroup1->setTitle(tr("BORDER_1"));
402 SubGroup2->setTitle(tr("BORDER_2"));
404 if (!CheckBoxPolygons->isVisible())
405 CheckBoxPolygons->show();
406 if (!CheckBoxPolyedrs->isVisible())
407 CheckBoxPolyedrs->show();
414 GroupArguments->setTitle(tr("SEW_CONFORM_FREE_BORDERS"));
415 SubGroup1->setTitle(tr("BORDER_1"));
416 SubGroup2->setTitle(tr("BORDER_2"));
418 TextLabel6->setEnabled(false);
419 SelectButton6->setEnabled(false);
420 LineEdit6->setEnabled(false);
428 GroupArguments->setTitle(tr("SEW_BORDER_TO_SIDE"));
429 SubGroup1->setTitle(tr("BORDER"));
430 SubGroup2->setTitle(tr("SIDE"));
432 TextLabel5->setEnabled(false);
433 SelectButton5->setEnabled(false);
434 LineEdit5->setEnabled(false);
436 if (!CheckBoxPolygons->isVisible())
437 CheckBoxPolygons->show();
438 if (!CheckBoxPolyedrs->isVisible())
439 CheckBoxPolyedrs->show();
448 GroupArguments->setTitle(tr("SEW_SIDE_ELEMENTS"));
449 SubGroup1->setTitle(tr("SIDE_1"));
450 SubGroup2->setTitle(tr("SIDE_2"));
452 TextLabel1->setText(tr("SMESH_ID_ELEMENTS"));
453 TextLabel2->setText(tr("NODE1_TO_MERGE"));
454 TextLabel3->setText(tr("NODE2_TO_MERGE"));
455 TextLabel4->setText(tr("SMESH_ID_ELEMENTS"));
456 TextLabel5->setText(tr("NODE1_TO_MERGE"));
457 TextLabel6->setText(tr("NODE2_TO_MERGE"));
459 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator"));
460 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator"));
462 SMESH::SetPointRepresentation(false);
464 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
465 aViewWindow->SetSelectionMode(CellSelection);
470 if (constructorId != 3) {
471 TextLabel1->setText(tr("FIRST_NODE_ID"));
472 TextLabel2->setText(tr("SECOND_NODE_ID"));
473 TextLabel3->setText(tr("LAST_NODE_ID"));
474 TextLabel4->setText(tr("FIRST_NODE_ID"));
475 TextLabel5->setText(tr("SECOND_NODE_ID"));
476 TextLabel6->setText(tr("LAST_NODE_ID"));
478 LineEdit1->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
479 LineEdit4->setValidator(new SMESHGUI_IdValidator(this, "validator", 1));
481 SMESH::SetPointRepresentation(true);
483 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
484 aViewWindow->SetSelectionMode(NodeSelection);
487 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
488 mySelectionMgr->setSelectedObjects( io );
491 //=================================================================================
492 // function : ClickOnApply()
494 //=================================================================================
495 bool SMESHGUI_SewingDlg::ClickOnApply()
497 if (mySMESHGUI->isActiveStudyLocked())
500 bool aResult = false;
503 bool toMerge = CheckBoxMerge->isChecked();
504 bool toCreatePolygons = CheckBoxPolygons->isChecked();
505 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
508 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
509 QApplication::setOverrideCursor(Qt::waitCursor);
511 int aConstructorId = GetConstructorId();
512 SMESH::SMESH_MeshEditor::Sew_Error anError;
514 if (aConstructorId == 0)
515 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
516 LineEdit2->text().toLong(),
517 LineEdit3->text().toLong(),
518 LineEdit4->text().toLong(),
519 LineEdit5->text().toLong(),
520 LineEdit6->text().toLong(),
523 else if (aConstructorId == 1)
524 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
525 LineEdit2->text().toLong(),
526 LineEdit3->text().toLong(),
527 LineEdit4->text().toLong(),
528 LineEdit5->text().toLong());
529 else if (aConstructorId == 2)
530 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
531 LineEdit2->text().toLong(),
532 LineEdit3->text().toLong(),
533 LineEdit4->text().toLong(),
534 LineEdit6->text().toLong(),
537 else if (aConstructorId == 3) {
538 QStringList aListElementsId1 = QStringList::split(" ", LineEdit1->text(), false);
539 QStringList aListElementsId2 = QStringList::split(" ", LineEdit4->text(), false);
541 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
542 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
544 anElementsId1->length(aListElementsId1.count());
545 anElementsId2->length(aListElementsId2.count());
547 for (int i = 0; i < aListElementsId1.count(); i++)
548 anElementsId1[i] = aListElementsId1[i].toInt();
549 for (int i = 0; i < aListElementsId2.count(); i++)
550 anElementsId2[i] = aListElementsId2[i].toInt();
552 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
553 anElementsId2.inout(),
554 LineEdit2->text().toLong(),
555 LineEdit5->text().toLong(),
556 LineEdit3->text().toLong(),
557 LineEdit6->text().toLong());
559 aResult = (anError == SMESH::SMESH_MeshEditor::SEW_OK);
561 if (toMerge && aResult)
562 aMeshEditor->MergeEqualElements();
564 QApplication::restoreOverrideCursor();
567 QString msg = tr(QString("ERROR_%1").arg(anError));
568 SUIT_MessageBox::warn1(SMESHGUI::desktop(), tr("SMESH_WRN_WARNING"),
569 msg, tr("SMESH_BUT_OK"));
575 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
579 mySelectionMgr->setSelectedObjects(aList, false);
583 ConstructorsClicked(GetConstructorId());
590 //=================================================================================
591 // function : ClickOnOk()
593 //=================================================================================
594 void SMESHGUI_SewingDlg::ClickOnOk()
600 //=================================================================================
601 // function : ClickOnCancel()
603 //=================================================================================
604 void SMESHGUI_SewingDlg::ClickOnCancel()
606 //mySelectionMgr->clearSelected();
607 SMESH::SetPointRepresentation(false);
608 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
609 aViewWindow->SetSelectionMode(ActorSelection);
610 disconnect(mySelectionMgr, 0, this, 0);
611 mySMESHGUI->ResetState();
615 //=================================================================================
616 // function : ClickOnHelp()
618 //=================================================================================
619 void SMESHGUI_SewingDlg::ClickOnHelp()
621 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
623 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
625 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
626 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
627 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
628 QObject::tr("BUT_OK"));
632 //=======================================================================
633 //function : onTextChange
635 //=======================================================================
636 void SMESHGUI_SewingDlg::onTextChange (const QString& theNewText)
638 QLineEdit* send = (QLineEdit*)sender();
644 myEditCurrentArgument = send;
646 if (send == LineEdit1)
648 else if (send == LineEdit2)
650 else if (send == LineEdit3)
652 else if (send == LineEdit4)
654 else if (send == LineEdit5)
656 else if (send == LineEdit6)
659 buttonOk->setEnabled(false);
660 buttonApply->setEnabled(false);
662 // hilight entered elements/nodes
663 SMDS_Mesh* aMesh = 0;
666 aMesh = myActor->GetObject()->GetMesh();
671 TColStd_MapOfInteger newIndices;
673 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4)) {
674 SMESH::SetPointRepresentation(true);
676 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
677 aViewWindow->SetSelectionMode(NodeSelection);
679 const SMDS_MeshNode * n = aMesh->FindNode(theNewText.toInt());
681 newIndices.Add(n->GetID());
682 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
683 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
684 aViewWindow->highlight( myActor->getIO(), true, true );
686 if (send == LineEdit1)
688 else if (send == LineEdit2)
690 else if (send == LineEdit3)
692 else if (send == LineEdit4)
694 else if (send == LineEdit5)
696 else if (send == LineEdit6)
700 SMESH::SetPointRepresentation(false);
702 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
703 aViewWindow->SetSelectionMode(CellSelection);
705 QStringList aListId = QStringList::split(" ", theNewText, false);
707 bool isEvenOneExists = false;
709 for (int i = 0; i < aListId.count(); i++) {
710 const SMDS_MeshElement * e = aMesh->FindElement(aListId[ i ].toInt());
712 newIndices.Add(e->GetID());
714 if (!isEvenOneExists)
715 isEvenOneExists = true;
719 mySelector->AddOrRemoveIndex(myActor->getIO(), newIndices, false);
720 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
721 aViewWindow->highlight( myActor->getIO(), true, true );
723 if (isEvenOneExists) {
724 if (send == LineEdit1)
726 else if(send == LineEdit4)
735 buttonOk->setEnabled(true);
736 buttonApply->setEnabled(true);
742 //=================================================================================
743 // function : SelectionIntoArgument()
744 // purpose : Called when selection as changed or other case
745 //=================================================================================
746 void SMESHGUI_SewingDlg::SelectionIntoArgument (bool isSelectionChanged)
751 if (isSelectionChanged)
754 QString aString = "";
757 myEditCurrentArgument->setText(aString);
760 if (!GroupButtons->isEnabled()) // inactive
763 buttonOk->setEnabled(false);
764 buttonApply->setEnabled(false);
768 mySelectionMgr->selectedObjects(aList,SVTK_Viewer::Type());
770 int nbSel = aList.Extent();
774 Handle(SALOME_InteractiveObject) IO = aList.First();
775 myMesh = SMESH::GetMeshByIO(IO); //@ SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
776 myActor = SMESH::FindActorByEntry(aList.First()->getEntry());
778 if (myMesh->_is_nil() || !myActor)
781 // get selected elements/nodes
784 if (GetConstructorId() != 3 ||
785 (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4)) {
786 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelector, IO, aString);
790 aNbUnits = SMESH::GetNameOfSelectedElements(mySelector, IO, aString);
796 myEditCurrentArgument->setText(aString);
800 if (myEditCurrentArgument == LineEdit1)
802 else if (myEditCurrentArgument == LineEdit2)
804 else if (myEditCurrentArgument == LineEdit3)
806 else if (myEditCurrentArgument == LineEdit4)
808 else if (myEditCurrentArgument == LineEdit5)
810 else if (myEditCurrentArgument == LineEdit6)
814 buttonOk->setEnabled(true);
815 buttonApply->setEnabled(true);
819 //=================================================================================
820 // function : SetEditCurrentArgument()
822 //=================================================================================
823 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
825 QPushButton* send = (QPushButton*)sender();
827 disconnect(mySelectionMgr, 0, this, 0);
828 mySelectionMgr->clearSelected();
830 if (send == SelectButton1) {
831 myEditCurrentArgument = LineEdit1;
834 else if (send == SelectButton2) {
835 myEditCurrentArgument = LineEdit2;
838 else if (send == SelectButton3) {
839 myEditCurrentArgument = LineEdit3;
842 else if (send == SelectButton4) {
843 myEditCurrentArgument = LineEdit4;
846 else if (send == SelectButton5) {
847 myEditCurrentArgument = LineEdit5;
850 else if (send == SelectButton6) {
851 myEditCurrentArgument = LineEdit6;
855 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4)) {
856 SMESH::SetPointRepresentation(true);
858 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
859 aViewWindow->SetSelectionMode(NodeSelection);
862 SMESH::SetPointRepresentation(false);
863 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
864 aViewWindow->SetSelectionMode(CellSelection);
867 myEditCurrentArgument->setFocus();
868 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
869 SelectionIntoArgument(false);
872 //=================================================================================
873 // function : DeactivateActiveDialog()
875 //=================================================================================
876 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
878 if (GroupConstructors->isEnabled()) {
879 GroupConstructors->setEnabled(false);
880 GroupArguments->setEnabled(false);
881 GroupButtons->setEnabled(false);
882 mySMESHGUI->ResetState();
883 mySMESHGUI->SetActiveDialogBox(0);
887 //=================================================================================
888 // function : ActivateThisDialog()
890 //=================================================================================
891 void SMESHGUI_SewingDlg::ActivateThisDialog()
893 /* Emit a signal to deactivate the active dialog */
894 mySMESHGUI->EmitSignalDeactivateDialog();
895 GroupConstructors->setEnabled(true);
896 GroupArguments->setEnabled(true);
897 GroupButtons->setEnabled(true);
899 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
901 ConstructorsClicked(GetConstructorId());
902 SelectionIntoArgument();
905 //=================================================================================
906 // function : enterEvent()
908 //=================================================================================
909 void SMESHGUI_SewingDlg::enterEvent (QEvent* e)
911 if (!GroupConstructors->isEnabled())
912 ActivateThisDialog();
915 //=================================================================================
916 // function : closeEvent()
918 //=================================================================================
919 void SMESHGUI_SewingDlg::closeEvent (QCloseEvent*)
921 /* same than click on cancel button */
922 this->ClickOnCancel();
925 //=======================================================================
926 //function : hideEvent
927 //purpose : caused by ESC key
928 //=======================================================================
929 void SMESHGUI_SewingDlg::hideEvent (QHideEvent*)
935 //=================================================================================
936 // function : GetConstructorId()
938 //=================================================================================
939 int SMESHGUI_SewingDlg::GetConstructorId()
941 if (GroupConstructors != NULL && GroupConstructors->selected() != NULL)
942 return GroupConstructors->id(GroupConstructors->selected());
946 //=================================================================================
947 // function : GetConstructorId()
949 //=================================================================================
950 bool SMESHGUI_SewingDlg::IsValid()
952 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);
955 //=================================================================================
956 // function : keyPressEvent()
958 //=================================================================================
959 void SMESHGUI_SewingDlg::keyPressEvent( QKeyEvent* e )
961 QDialog::keyPressEvent( e );
962 if ( e->isAccepted() )
965 if ( e->key() == Key_F1 )