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"
35 #include "SMESH_Actor.h"
36 #include "SMDS_Mesh.hxx"
40 #include "QAD_Application.h"
41 #include "QAD_Desktop.h"
42 #include "QAD_MessageBox.h"
43 #include "utilities.h"
46 #include <qapplication.h>
47 #include <qbuttongroup.h>
48 #include <qgroupbox.h>
50 #include <qlineedit.h>
51 #include <qpushbutton.h>
52 #include <qradiobutton.h>
53 #include <qcheckbox.h>
59 //=================================================================================
60 // class : SMESHGUI_SewingDlg()
62 //=================================================================================
63 SMESHGUI_SewingDlg::SMESHGUI_SewingDlg( QWidget* parent, const char* name, SALOME_Selection* Sel,
64 bool modal, WFlags fl )
65 : QDialog( parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu |
66 Qt::WDestructiveClose)
68 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_FREEBORDERS")));
69 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_CONFORM_FREEBORDERS")));
70 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_BORDERTOSIDE")));
71 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SMESH_SEWING_SIDEELEMENTS")));
72 QPixmap image4(QAD_Desktop::getResourceManager()->loadPixmap( "SMESH",tr("ICON_SELECT")));
75 setName( "SMESHGUI_SewingDlg" );
77 setCaption( tr( "SMESH_SEWING" ) );
78 setSizeGripEnabled( TRUE );
79 SMESHGUI_SewingDlgLayout = new QGridLayout( this );
80 SMESHGUI_SewingDlgLayout->setSpacing( 6 );
81 SMESHGUI_SewingDlgLayout->setMargin( 11 );
83 /***************************************************************/
84 GroupConstructors = new QButtonGroup( this, "GroupConstructors" );
85 GroupConstructors->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)0, 0, 0, GroupConstructors->sizePolicy().hasHeightForWidth() ) );
86 GroupConstructors->setTitle( tr( "SMESH_SEWING" ) );
87 GroupConstructors->setExclusive( TRUE );
88 GroupConstructors->setColumnLayout(0, Qt::Vertical );
89 GroupConstructors->layout()->setSpacing( 0 );
90 GroupConstructors->layout()->setMargin( 0 );
91 GroupConstructorsLayout = new QGridLayout( GroupConstructors->layout() );
92 GroupConstructorsLayout->setAlignment( Qt::AlignTop );
93 GroupConstructorsLayout->setSpacing( 6 );
94 GroupConstructorsLayout->setMargin( 11 );
95 QHBoxLayout* RBLayout = new QHBoxLayout( 0, 0, 6, "Layout2");
96 RadioButton1= new QRadioButton( GroupConstructors, "RadioButton1" );
97 RadioButton1->setText( tr( "" ) );
98 RadioButton1->setPixmap( image0 );
99 RBLayout->addWidget( RadioButton1);
100 RadioButton2= new QRadioButton( GroupConstructors, "RadioButton2" );
101 RadioButton2->setText( tr( "" ) );
102 RadioButton2->setPixmap( image1 );
103 RBLayout->addWidget( RadioButton2);
104 RadioButton3= new QRadioButton( GroupConstructors, "RadioButton3" );
105 RadioButton3->setText( tr( "" ) );
106 RadioButton3->setPixmap( image2 );
107 RBLayout->addWidget( RadioButton3);
108 RadioButton4= new QRadioButton( GroupConstructors, "RadioButton4" );
109 RadioButton4->setText( tr( "" ) );
110 RadioButton4->setPixmap( image3 );
111 RBLayout->addWidget( RadioButton4);
112 GroupConstructorsLayout->addLayout( RBLayout, 0, 0 );
113 SMESHGUI_SewingDlgLayout->addWidget( GroupConstructors, 0, 0 );
115 /***************************************************************/
116 GroupButtons = new QGroupBox( this, "GroupButtons" );
117 GroupButtons->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)0, 0, 0, GroupButtons->sizePolicy().hasHeightForWidth() ) );
118 GroupButtons->setGeometry( QRect( 10, 10, 281, 48 ) );
119 GroupButtons->setTitle( tr( "" ) );
120 GroupButtons->setColumnLayout(0, Qt::Vertical );
121 GroupButtons->layout()->setSpacing( 0 );
122 GroupButtons->layout()->setMargin( 0 );
123 GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
124 GroupButtonsLayout->setAlignment( Qt::AlignTop );
125 GroupButtonsLayout->setSpacing( 6 );
126 GroupButtonsLayout->setMargin( 11 );
127 buttonCancel = new QPushButton( GroupButtons, "buttonCancel" );
128 buttonCancel->setText( tr( "SMESH_BUT_CLOSE" ) );
129 buttonCancel->setAutoDefault( TRUE );
130 GroupButtonsLayout->addWidget( buttonCancel, 0, 3 );
131 buttonApply = new QPushButton( GroupButtons, "buttonApply" );
132 buttonApply->setText( tr( "SMESH_BUT_APPLY" ) );
133 buttonApply->setAutoDefault( TRUE );
134 GroupButtonsLayout->addWidget( buttonApply, 0, 1 );
135 QSpacerItem* spacer_9 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
136 GroupButtonsLayout->addItem( spacer_9, 0, 2 );
137 buttonOk = new QPushButton( GroupButtons, "buttonOk" );
138 buttonOk->setText( tr( "SMESH_BUT_OK" ) );
139 buttonOk->setAutoDefault( TRUE );
140 buttonOk->setDefault( TRUE );
141 GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
142 SMESHGUI_SewingDlgLayout->addWidget( GroupButtons, 2, 0 );
144 /***************************************************************/
145 GroupArguments = new QGroupBox( this, "GroupArguments" );
146 GroupArguments->setColumnLayout(0, Qt::Vertical );
147 GroupArguments->layout()->setSpacing( 0 );
148 GroupArguments->layout()->setMargin( 0 );
149 GroupArgumentsLayout = new QGridLayout( GroupArguments->layout() );
150 GroupArgumentsLayout->setAlignment( Qt::AlignTop );
151 GroupArgumentsLayout->setSpacing( 6 );
152 GroupArgumentsLayout->setMargin( 11 );
155 SubGroup1 = new QGroupBox( GroupArguments, "SubGroup1" );
156 SubGroup1->setColumnLayout(0, Qt::Vertical );
157 SubGroup1->layout()->setSpacing( 0 );
158 SubGroup1->layout()->setMargin( 0 );
159 QGridLayout* SubGroup1Layout = new QGridLayout( SubGroup1->layout() );
160 SubGroup1Layout->setAlignment( Qt::AlignTop );
161 SubGroup1Layout->setSpacing( 6 );
162 SubGroup1Layout->setMargin( 11 );
164 // Controls of the first subgroup
165 TextLabel1 = new QLabel( SubGroup1, "TextLabel1" );
166 TextLabel1->setFixedWidth(104);
167 SubGroup1Layout->addWidget( TextLabel1, 0, 0 );
169 SelectButton1 = new QPushButton( SubGroup1, "SelectButton1" );
170 SelectButton1->setPixmap( image4 );
171 SubGroup1Layout->addWidget( SelectButton1, 0, 1 );
173 LineEdit1 = new QLineEdit( SubGroup1, "LineEdit1" );
174 SubGroup1Layout->addWidget( LineEdit1, 0, 2 );
176 TextLabel2 = new QLabel( SubGroup1, "TextLabel2" );
177 SubGroup1Layout->addWidget( TextLabel2, 1, 0 );
179 SelectButton2 = new QPushButton( SubGroup1, "SelectButton2" );
180 SelectButton2->setPixmap( image4 );
181 SubGroup1Layout->addWidget( SelectButton2, 1, 1 );
183 LineEdit2 = new QLineEdit( SubGroup1, "LineEdit2" );
184 SubGroup1Layout->addWidget( LineEdit2, 1, 2 );
186 TextLabel3 = new QLabel( SubGroup1, "TextLabel3" );
187 SubGroup1Layout->addWidget( TextLabel3, 2, 0 );
189 SelectButton3 = new QPushButton( SubGroup1, "SelectButton3" );
190 SelectButton3->setPixmap( image4 );
191 SubGroup1Layout->addWidget( SelectButton3, 2, 1 );
193 LineEdit3 = new QLineEdit( SubGroup1, "LineEdit3" );
194 SubGroup1Layout->addWidget( LineEdit3, 2, 2 );
198 SubGroup2 = new QGroupBox( GroupArguments, "SubGroup2" );
199 SubGroup2->setColumnLayout(0, Qt::Vertical );
200 SubGroup2->layout()->setSpacing( 0 );
201 SubGroup2->layout()->setMargin( 0 );
202 QGridLayout* SubGroup2Layout = new QGridLayout( SubGroup2->layout() );
203 SubGroup2Layout->setAlignment( Qt::AlignTop );
204 SubGroup2Layout->setSpacing( 6 );
205 SubGroup2Layout->setMargin( 11 );
207 // Controls of the first subgroup
208 TextLabel4 = new QLabel( SubGroup2, "TextLabel4" );
209 SubGroup2Layout->addWidget( TextLabel4, 0, 0 );
211 SelectButton4 = new QPushButton( SubGroup2, "SelectButton4" );
212 SelectButton4->setPixmap( image4 );
213 SubGroup2Layout->addWidget( SelectButton4, 0, 1 );
215 LineEdit4 = new QLineEdit( SubGroup2, "LineEdit4" );
216 SubGroup2Layout->addWidget( LineEdit4, 0, 2 );
218 TextLabel5 = new QLabel( SubGroup2, "TextLabel5" );
219 SubGroup2Layout->addWidget( TextLabel5, 1, 0 );
221 SelectButton5 = new QPushButton( SubGroup2, "SelectButton5" );
222 SelectButton5->setPixmap( image4 );
223 SubGroup2Layout->addWidget( SelectButton5, 1, 1 );
225 LineEdit5 = new QLineEdit( SubGroup2, "LineEdit5" );
226 SubGroup2Layout->addWidget( LineEdit5, 1, 2 );
228 TextLabel6 = new QLabel( SubGroup2, "TextLabel6" );
229 SubGroup2Layout->addWidget( TextLabel6, 2, 0 );
231 SelectButton6 = new QPushButton( SubGroup2, "SelectButton6" );
232 SelectButton6->setPixmap( image4 );
233 SubGroup2Layout->addWidget( SelectButton6, 2, 1 );
235 LineEdit6 = new QLineEdit( SubGroup2, "LineEdit6" );
236 SubGroup2Layout->addWidget( LineEdit6, 2, 2 );
239 // Add subgroups to the group of arguments
240 GroupArgumentsLayout->addWidget( SubGroup1, 0, 0 );
241 GroupArgumentsLayout->addWidget( SubGroup2, 1, 0 );
243 // Control for the merging equal elements
244 CheckBoxMerge = new QCheckBox( GroupArguments, "CheckBoxMerge" );
245 CheckBoxMerge->setText( tr( "MERGE_EQUAL_ELEMENTS" ) );
246 GroupArgumentsLayout->addWidget( CheckBoxMerge, 2, 0 );
248 // Control for the polygons creation instead of splitting
249 CheckBoxPolygons = new QCheckBox( GroupArguments, "CheckBoxPolygons" );
250 CheckBoxPolygons->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
251 GroupArgumentsLayout->addWidget( CheckBoxPolygons, 3, 0 );
253 // Control for the polyedres creation to obtain conform mesh
254 CheckBoxPolyedrs = new QCheckBox( GroupArguments, "CheckBoxPolyedrs" );
255 CheckBoxPolyedrs->setText( tr( "CREATE_POLYEDRS_NEAR_BOUNDARY" ) );
256 GroupArgumentsLayout->addWidget( CheckBoxPolyedrs, 4, 0 );
259 SMESHGUI_SewingDlgLayout->addWidget( GroupArguments, 1, 0 );
261 /* Initialisations */
262 GroupArguments->show();
263 RadioButton1->setChecked( TRUE );
266 LineEdit2->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
267 LineEdit3->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
268 LineEdit5->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
269 LineEdit6->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
271 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
272 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
275 /* signals and slots connections */
276 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
277 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
278 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
279 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
281 connect( SelectButton1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
282 connect( SelectButton2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
283 connect( SelectButton3, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
284 connect( SelectButton4, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
285 connect( SelectButton5, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
286 connect( SelectButton6, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
288 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
289 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
290 /* to close dialog if study change */
291 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
293 connect( LineEdit1, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
294 connect( LineEdit2, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
295 connect( LineEdit3, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
296 connect( LineEdit4, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
297 connect( LineEdit5, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
298 connect( LineEdit6, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
300 /* Move widget on the botton right corner of main widget */
302 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
304 this->show() ; /* displays Dialog */
306 ConstructorsClicked(0);
310 //=================================================================================
311 // function : ~SMESHGUI_SewingDlg()
312 // purpose : Destroys the object and frees any allocated resources
313 //=================================================================================
314 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
316 // no need to delete child widgets, Qt does it all for us
320 //=================================================================================
323 //=================================================================================
324 void SMESHGUI_SewingDlg::Init()
328 myEditCurrentArgument = LineEdit1;
329 LineEdit1->setFocus();
331 myMesh = SMESH::SMESH_Mesh::_nil();
332 CheckBoxMerge->setChecked(false);
333 CheckBoxPolygons->setChecked(false);
334 CheckBoxPolyedrs->setChecked(false);
335 SelectionIntoArgument();
339 //=================================================================================
340 // function : ConstructorsClicked()
341 // purpose : Radio button management
342 //=================================================================================
343 void SMESHGUI_SewingDlg::ConstructorsClicked(int constructorId)
345 disconnect(mySelection, 0, this, 0);
346 mySelection->ClearIObjects();
347 LineEdit1->setText("");
348 LineEdit2->setText("");
349 LineEdit3->setText("");
350 LineEdit4->setText("");
351 LineEdit5->setText("");
352 LineEdit6->setText("");
353 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
354 myEditCurrentArgument = LineEdit1;
355 myEditCurrentArgument->setFocus();
357 if (!TextLabel5->isEnabled())
359 TextLabel5->setEnabled(true);
360 SelectButton5->setEnabled(true);
361 LineEdit5->setEnabled(true);
363 else if (!TextLabel6->isEnabled())
365 TextLabel6->setEnabled(true);
366 SelectButton6->setEnabled(true);
367 LineEdit6->setEnabled(true);
370 if (constructorId == 1 || constructorId == 3) {
371 if (CheckBoxPolygons->isVisible())
372 CheckBoxPolygons->hide();
373 if (CheckBoxPolyedrs->isVisible())
374 CheckBoxPolyedrs->hide();
377 switch(constructorId)
381 GroupArguments->setTitle( tr( "SEW_FREE_BORDERS" ) );
382 SubGroup1->setTitle( tr( "BORDER_1" ) );
383 SubGroup2->setTitle( tr( "BORDER_2" ) );
385 if (!CheckBoxPolygons->isVisible())
386 CheckBoxPolygons->show();
387 if (!CheckBoxPolyedrs->isVisible())
388 CheckBoxPolyedrs->show();
394 GroupArguments->setTitle( tr( "SEW_CONFORM_FREE_BORDERS" ) );
395 SubGroup1->setTitle( tr( "BORDER_1" ) );
396 SubGroup2->setTitle( tr( "BORDER_2" ) );
398 TextLabel6->setEnabled(false);
399 SelectButton6->setEnabled(false);
400 LineEdit6->setEnabled(false);
408 GroupArguments->setTitle( tr( "SEW_BORDER_TO_SIDE" ) );
409 SubGroup1->setTitle( tr( "BORDER" ) );
410 SubGroup2->setTitle( tr( "SIDE" ) );
412 TextLabel5->setEnabled(false);
413 SelectButton5->setEnabled(false);
414 LineEdit5->setEnabled(false);
416 if (!CheckBoxPolygons->isVisible())
417 CheckBoxPolygons->show();
418 if (!CheckBoxPolyedrs->isVisible())
419 CheckBoxPolyedrs->show();
427 GroupArguments->setTitle( tr( "SEW_SIDE_ELEMENTS" ) );
428 SubGroup1->setTitle( tr( "SIDE_1" ) );
429 SubGroup2->setTitle( tr( "SIDE_2" ) );
431 TextLabel1->setText( tr( "SMESH_ID_ELEMENTS" ) );
432 TextLabel2->setText( tr( "NODE1_TO_MERGE" ) );
433 TextLabel3->setText( tr( "NODE2_TO_MERGE" ) );
434 TextLabel4->setText( tr( "SMESH_ID_ELEMENTS" ) );
435 TextLabel5->setText( tr( "NODE1_TO_MERGE" ) );
436 TextLabel6->setText( tr( "NODE2_TO_MERGE" ) );
438 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator"));
439 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator"));
441 SMESH::SetPointRepresentation(false);
442 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
447 if (constructorId != 3)
449 TextLabel1->setText( tr( "FIRST_NODE_ID" ) );
450 TextLabel2->setText( tr( "SECOND_NODE_ID" ) );
451 TextLabel3->setText( tr( "LAST_NODE_ID" ) );
452 TextLabel4->setText( tr( "FIRST_NODE_ID" ) );
453 TextLabel5->setText( tr( "SECOND_NODE_ID" ) );
454 TextLabel6->setText( tr( "LAST_NODE_ID" ) );
456 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
457 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
459 SMESH::SetPointRepresentation(true);
460 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
463 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
467 //=================================================================================
468 // function : ClickOnApply()
470 //=================================================================================
471 bool SMESHGUI_SewingDlg::ClickOnApply()
473 if (mySMESHGUI->ActiveStudyLocked())
476 bool aResult = false;
480 bool toMerge = CheckBoxMerge->isChecked();
481 bool toCreatePolygons = CheckBoxPolygons->isChecked();
482 bool toCreatePolyedrs = CheckBoxPolyedrs->isChecked();
486 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
487 QApplication::setOverrideCursor(Qt::waitCursor);
489 int aConstructorId = GetConstructorId();
490 SMESH::SMESH_MeshEditor::Sew_Error anError;
492 if (aConstructorId == 0)
493 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
494 LineEdit2->text().toLong(),
495 LineEdit3->text().toLong(),
496 LineEdit4->text().toLong(),
497 LineEdit5->text().toLong(),
498 LineEdit6->text().toLong(),
501 else if (aConstructorId == 1)
502 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
503 LineEdit2->text().toLong(),
504 LineEdit3->text().toLong(),
505 LineEdit4->text().toLong(),
506 LineEdit5->text().toLong());
507 else if (aConstructorId == 2)
508 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
509 LineEdit2->text().toLong(),
510 LineEdit3->text().toLong(),
511 LineEdit4->text().toLong(),
512 LineEdit6->text().toLong(),
515 else if (aConstructorId == 3)
517 QStringList aListElementsId1 = QStringList::split( " ", LineEdit1->text(), false);
518 QStringList aListElementsId2 = QStringList::split( " ", LineEdit4->text(), false);
520 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
521 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
523 anElementsId1->length( aListElementsId1.count() );
524 anElementsId2->length( aListElementsId2.count() );
526 for ( int i = 0; i < aListElementsId1.count(); i++ )
527 anElementsId1[i] = aListElementsId1[i].toInt();
528 for ( int i = 0; i < aListElementsId2.count(); i++ )
529 anElementsId2[i] = aListElementsId2[i].toInt();
531 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
532 anElementsId2.inout(),
533 LineEdit2->text().toLong(),
534 LineEdit5->text().toLong(),
535 LineEdit3->text().toLong(),
536 LineEdit6->text().toLong());
538 aResult = ( anError == SMESH::SMESH_MeshEditor::SEW_OK );
540 if (toMerge && aResult)
541 aMeshEditor->MergeEqualElements();
543 QApplication::restoreOverrideCursor();
546 QString msg = tr(QString("ERROR_%1").arg(anError));
547 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
548 tr("SMESH_WRN_WARNING"),msg,tr("SMESH_BUT_OK"));
557 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
558 mySelection->ClearIObjects();
560 mySelection->AddIObject( anIO, false );
562 ConstructorsClicked(GetConstructorId());
569 //=================================================================================
570 // function : ClickOnOk()
572 //=================================================================================
573 void SMESHGUI_SewingDlg::ClickOnOk()
580 //=================================================================================
581 // function : ClickOnCancel()
583 //=================================================================================
584 void SMESHGUI_SewingDlg::ClickOnCancel()
586 mySelection->ClearIObjects();
587 SMESH::SetPointRepresentation(false);
588 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
589 disconnect( mySelection, 0, this, 0 );
590 mySMESHGUI->ResetState() ;
594 //=======================================================================
595 //function : onTextChange
597 //=======================================================================
599 void SMESHGUI_SewingDlg::onTextChange(const QString& theNewText)
601 QLineEdit* send = (QLineEdit*)sender();
603 if ( myBusy ) return;
607 myEditCurrentArgument = send;
609 if (send == LineEdit1)
611 else if (send == LineEdit2)
613 else if (send == LineEdit3)
615 else if (send == LineEdit4)
617 else if (send == LineEdit5)
619 else if (send == LineEdit6)
622 buttonOk->setEnabled( false );
623 buttonApply->setEnabled( false );
625 // hilight entered elements/nodes
626 SMDS_Mesh* aMesh = 0;
629 aMesh = myActor->GetObject()->GetMesh();
634 mySelection->ClearIObjects();
635 mySelection->AddIObject( myActor->getIO() );
637 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4))
639 SMESH::SetPointRepresentation(true);
640 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
642 const SMDS_MeshNode * n = aMesh->FindNode( theNewText.toInt() );
644 if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
645 mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
647 if (send == LineEdit1)
649 else if (send == LineEdit2)
651 else if (send == LineEdit3)
653 else if (send == LineEdit4)
655 else if (send == LineEdit5)
657 else if (send == LineEdit6)
663 SMESH::SetPointRepresentation(false);
664 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
666 QStringList aListId = QStringList::split( " ", theNewText, false);
668 bool isEvenOneExists = false;
670 for ( int i = 0; i < aListId.count(); i++ ) {
671 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
673 if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
674 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
675 if (!isEvenOneExists)
676 isEvenOneExists = true;
682 if (send == LineEdit1)
684 else if(send == LineEdit4)
693 buttonOk->setEnabled( true );
694 buttonApply->setEnabled( true );
701 //=================================================================================
702 // function : SelectionIntoArgument()
703 // purpose : Called when selection as changed or other case
704 //=================================================================================
705 void SMESHGUI_SewingDlg::SelectionIntoArgument(bool isSelectionChanged)
707 if ( myBusy ) return;
710 if (isSelectionChanged)
713 QString aString = "";
716 myEditCurrentArgument->setText( aString );
719 if ( !GroupButtons->isEnabled() ) // inactive
722 buttonOk->setEnabled( false );
723 buttonApply->setEnabled( false );
726 int nbSel = mySelection->IObjectCount();
730 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
731 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
732 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
734 if (myMesh->_is_nil() || !myActor)
737 // get selected elements/nodes
741 if (GetConstructorId() != 3 || (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4))
743 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
749 aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString);
755 myEditCurrentArgument->setText( aString );
759 if (myEditCurrentArgument == LineEdit1)
761 else if(myEditCurrentArgument == LineEdit2)
763 else if(myEditCurrentArgument == LineEdit3)
765 else if(myEditCurrentArgument == LineEdit4)
767 else if(myEditCurrentArgument == LineEdit5)
769 else if(myEditCurrentArgument == LineEdit6)
774 buttonOk->setEnabled( true );
775 buttonApply->setEnabled( true );
780 //=================================================================================
781 // function : SetEditCurrentArgument()
783 //=================================================================================
784 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
786 QPushButton* send = (QPushButton*)sender();
788 disconnect( mySelection, 0, this, 0 );
789 mySelection->ClearIObjects();
791 if(send == SelectButton1) {
792 myEditCurrentArgument = LineEdit1;
795 else if (send == SelectButton2) {
796 myEditCurrentArgument = LineEdit2;
799 else if (send == SelectButton3) {
800 myEditCurrentArgument = LineEdit3;
803 else if (send == SelectButton4) {
804 myEditCurrentArgument = LineEdit4;
807 else if (send == SelectButton5) {
808 myEditCurrentArgument = LineEdit5;
811 else if (send == SelectButton6) {
812 myEditCurrentArgument = LineEdit6;
816 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4))
818 SMESH::SetPointRepresentation(true);
819 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
823 SMESH::SetPointRepresentation(false);
824 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
827 myEditCurrentArgument->setFocus();
828 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
829 SelectionIntoArgument(false) ;
832 //=================================================================================
833 // function : DeactivateActiveDialog()
835 //=================================================================================
836 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
838 if ( GroupConstructors->isEnabled() ) {
839 GroupConstructors->setEnabled(false) ;
840 GroupArguments->setEnabled(false) ;
841 GroupButtons->setEnabled(false) ;
842 mySMESHGUI->ResetState() ;
843 mySMESHGUI->SetActiveDialogBox(0) ;
848 //=================================================================================
849 // function : ActivateThisDialog()
851 //=================================================================================
852 void SMESHGUI_SewingDlg::ActivateThisDialog()
854 /* Emit a signal to deactivate the active dialog */
855 mySMESHGUI->EmitSignalDeactivateDialog() ;
856 GroupConstructors->setEnabled(true) ;
857 GroupArguments->setEnabled(true) ;
858 GroupButtons->setEnabled(true) ;
860 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
862 ConstructorsClicked(GetConstructorId());
863 SelectionIntoArgument();
867 //=================================================================================
868 // function : enterEvent()
870 //=================================================================================
871 void SMESHGUI_SewingDlg::enterEvent(QEvent* e)
873 if ( GroupConstructors->isEnabled() )
875 ActivateThisDialog() ;
879 //=================================================================================
880 // function : closeEvent()
882 //=================================================================================
883 void SMESHGUI_SewingDlg::closeEvent( QCloseEvent* e )
885 /* same than click on cancel button */
886 this->ClickOnCancel() ;
890 //=======================================================================
891 //function : hideEvent
892 //purpose : caused by ESC key
893 //=======================================================================
895 void SMESHGUI_SewingDlg::hideEvent ( QHideEvent * e )
897 if ( !isMinimized() )
902 //=================================================================================
903 // function : GetConstructorId()
905 //=================================================================================
906 int SMESHGUI_SewingDlg::GetConstructorId()
908 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
909 return GroupConstructors->id( GroupConstructors->selected() );
914 //=================================================================================
915 // function : GetConstructorId()
917 //=================================================================================
918 bool SMESHGUI_SewingDlg::IsValid()
920 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);