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 CheckBoxPoly = new QCheckBox( GroupArguments, "CheckBoxPoly" );
250 CheckBoxPoly->setText( tr( "CREATE_POLYGONS_INSTEAD_SPLITTING" ) );
251 GroupArgumentsLayout->addWidget( CheckBoxPoly, 3, 0 );
254 SMESHGUI_SewingDlgLayout->addWidget( GroupArguments, 1, 0 );
256 /* Initialisations */
257 GroupArguments->show();
258 RadioButton1->setChecked( TRUE );
261 LineEdit2->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
262 LineEdit3->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
263 LineEdit5->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
264 LineEdit6->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
266 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
267 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
270 /* signals and slots connections */
271 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
272 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
273 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
274 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
276 connect( SelectButton1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
277 connect( SelectButton2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
278 connect( SelectButton3, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
279 connect( SelectButton4, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
280 connect( SelectButton5, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
281 connect( SelectButton6, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
283 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
284 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
285 /* to close dialog if study change */
286 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
288 connect( LineEdit1, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
289 connect( LineEdit2, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
290 connect( LineEdit3, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
291 connect( LineEdit4, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
292 connect( LineEdit5, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
293 connect( LineEdit6, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
295 /* Move widget on the botton right corner of main widget */
297 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
299 this->show() ; /* displays Dialog */
301 ConstructorsClicked(0);
305 //=================================================================================
306 // function : ~SMESHGUI_SewingDlg()
307 // purpose : Destroys the object and frees any allocated resources
308 //=================================================================================
309 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
311 // no need to delete child widgets, Qt does it all for us
315 //=================================================================================
318 //=================================================================================
319 void SMESHGUI_SewingDlg::Init()
323 myEditCurrentArgument = LineEdit1;
324 LineEdit1->setFocus();
326 myMesh = SMESH::SMESH_Mesh::_nil();
327 CheckBoxMerge->setChecked(false);
328 CheckBoxPoly->setChecked(false);
329 SelectionIntoArgument();
333 //=================================================================================
334 // function : ConstructorsClicked()
335 // purpose : Radio button management
336 //=================================================================================
337 void SMESHGUI_SewingDlg::ConstructorsClicked(int constructorId)
339 disconnect(mySelection, 0, this, 0);
340 mySelection->ClearIObjects();
341 LineEdit1->setText("");
342 LineEdit2->setText("");
343 LineEdit3->setText("");
344 LineEdit4->setText("");
345 LineEdit5->setText("");
346 LineEdit6->setText("");
347 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
348 myEditCurrentArgument = LineEdit1;
349 myEditCurrentArgument->setFocus();
351 if (!TextLabel5->isEnabled())
353 TextLabel5->setEnabled(true);
354 SelectButton5->setEnabled(true);
355 LineEdit5->setEnabled(true);
357 else if (!TextLabel6->isEnabled())
359 TextLabel6->setEnabled(true);
360 SelectButton6->setEnabled(true);
361 LineEdit6->setEnabled(true);
364 if (constructorId != 0 && CheckBoxPoly->isVisible())
365 CheckBoxPoly->hide();
367 switch(constructorId)
371 GroupArguments->setTitle( tr( "SEW_FREE_BORDERS" ) );
372 SubGroup1->setTitle( tr( "BORDER_1" ) );
373 SubGroup2->setTitle( tr( "BORDER_2" ) );
375 if (!CheckBoxPoly->isVisible())
376 CheckBoxPoly->show();
382 GroupArguments->setTitle( tr( "SEW_CONFORM_FREE_BORDERS" ) );
383 SubGroup1->setTitle( tr( "BORDER_1" ) );
384 SubGroup2->setTitle( tr( "BORDER_2" ) );
386 TextLabel6->setEnabled(false);
387 SelectButton6->setEnabled(false);
388 LineEdit6->setEnabled(false);
396 GroupArguments->setTitle( tr( "SEW_BORDER_TO_SIDE" ) );
397 SubGroup1->setTitle( tr( "BORDER" ) );
398 SubGroup2->setTitle( tr( "SIDE" ) );
400 TextLabel5->setEnabled(false);
401 SelectButton5->setEnabled(false);
402 LineEdit5->setEnabled(false);
410 GroupArguments->setTitle( tr( "SEW_SIDE_ELEMENTS" ) );
411 SubGroup1->setTitle( tr( "SIDE_1" ) );
412 SubGroup2->setTitle( tr( "SIDE_2" ) );
414 TextLabel1->setText( tr( "SMESH_ID_ELEMENTS" ) );
415 TextLabel2->setText( tr( "NODE1_TO_MERGE" ) );
416 TextLabel3->setText( tr( "NODE2_TO_MERGE" ) );
417 TextLabel4->setText( tr( "SMESH_ID_ELEMENTS" ) );
418 TextLabel5->setText( tr( "NODE1_TO_MERGE" ) );
419 TextLabel6->setText( tr( "NODE2_TO_MERGE" ) );
421 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator"));
422 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator"));
424 SMESH::SetPointRepresentation(false);
425 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
430 if (constructorId != 3)
432 TextLabel1->setText( tr( "FIRST_NODE_ID" ) );
433 TextLabel2->setText( tr( "SECOND_NODE_ID" ) );
434 TextLabel3->setText( tr( "LAST_NODE_ID" ) );
435 TextLabel4->setText( tr( "FIRST_NODE_ID" ) );
436 TextLabel5->setText( tr( "SECOND_NODE_ID" ) );
437 TextLabel6->setText( tr( "LAST_NODE_ID" ) );
439 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
440 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
442 SMESH::SetPointRepresentation(true);
443 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
446 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
450 //=================================================================================
451 // function : ClickOnApply()
453 //=================================================================================
454 bool SMESHGUI_SewingDlg::ClickOnApply()
456 if (mySMESHGUI->ActiveStudyLocked())
459 bool aResult = false;
463 bool toMerge = CheckBoxMerge->isChecked();
464 bool toCreatePoly = CheckBoxPoly->isChecked();
468 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
469 QApplication::setOverrideCursor(Qt::waitCursor);
471 int aConstructorId = GetConstructorId();
472 SMESH::SMESH_MeshEditor::Sew_Error anError;
474 if (aConstructorId == 0)
475 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
476 LineEdit2->text().toLong(),
477 LineEdit3->text().toLong(),
478 LineEdit4->text().toLong(),
479 LineEdit5->text().toLong(),
480 LineEdit6->text().toLong(),
482 else if (aConstructorId == 1)
483 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
484 LineEdit2->text().toLong(),
485 LineEdit3->text().toLong(),
486 LineEdit4->text().toLong(),
487 LineEdit5->text().toLong());
488 else if (aConstructorId == 2)
489 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
490 LineEdit2->text().toLong(),
491 LineEdit3->text().toLong(),
492 LineEdit4->text().toLong(),
493 LineEdit6->text().toLong());
494 else if (aConstructorId == 3)
496 QStringList aListElementsId1 = QStringList::split( " ", LineEdit1->text(), false);
497 QStringList aListElementsId2 = QStringList::split( " ", LineEdit4->text(), false);
499 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
500 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
502 anElementsId1->length( aListElementsId1.count() );
503 anElementsId2->length( aListElementsId2.count() );
505 for ( int i = 0; i < aListElementsId1.count(); i++ )
506 anElementsId1[i] = aListElementsId1[i].toInt();
507 for ( int i = 0; i < aListElementsId2.count(); i++ )
508 anElementsId2[i] = aListElementsId2[i].toInt();
510 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
511 anElementsId2.inout(),
512 LineEdit2->text().toLong(),
513 LineEdit5->text().toLong(),
514 LineEdit3->text().toLong(),
515 LineEdit6->text().toLong());
517 aResult = ( anError == SMESH::SMESH_MeshEditor::SEW_OK );
519 if (toMerge && aResult)
520 aMeshEditor->MergeEqualElements();
522 QApplication::restoreOverrideCursor();
525 QString msg = tr(QString("ERROR_%1").arg(anError));
526 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
527 tr("SMESH_WRN_WARNING"),msg,tr("SMESH_BUT_OK"));
536 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
537 mySelection->ClearIObjects();
539 mySelection->AddIObject( anIO, false );
541 ConstructorsClicked(GetConstructorId());
548 //=================================================================================
549 // function : ClickOnOk()
551 //=================================================================================
552 void SMESHGUI_SewingDlg::ClickOnOk()
559 //=================================================================================
560 // function : ClickOnCancel()
562 //=================================================================================
563 void SMESHGUI_SewingDlg::ClickOnCancel()
565 mySelection->ClearIObjects();
566 SMESH::SetPointRepresentation(false);
567 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
568 disconnect( mySelection, 0, this, 0 );
569 mySMESHGUI->ResetState() ;
573 //=======================================================================
574 //function : onTextChange
576 //=======================================================================
578 void SMESHGUI_SewingDlg::onTextChange(const QString& theNewText)
580 QLineEdit* send = (QLineEdit*)sender();
582 if ( myBusy ) return;
586 myEditCurrentArgument = send;
588 if (send == LineEdit1)
590 else if (send == LineEdit2)
592 else if (send == LineEdit3)
594 else if (send == LineEdit4)
596 else if (send == LineEdit5)
598 else if (send == LineEdit6)
601 buttonOk->setEnabled( false );
602 buttonApply->setEnabled( false );
604 // hilight entered elements/nodes
605 SMDS_Mesh* aMesh = 0;
608 aMesh = myActor->GetObject()->GetMesh();
613 mySelection->ClearIObjects();
614 mySelection->AddIObject( myActor->getIO() );
616 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4))
618 SMESH::SetPointRepresentation(true);
619 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
621 const SMDS_MeshNode * n = aMesh->FindNode( theNewText.toInt() );
623 if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
624 mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
626 if (send == LineEdit1)
628 else if (send == LineEdit2)
630 else if (send == LineEdit3)
632 else if (send == LineEdit4)
634 else if (send == LineEdit5)
636 else if (send == LineEdit6)
642 SMESH::SetPointRepresentation(false);
643 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
645 QStringList aListId = QStringList::split( " ", theNewText, false);
647 bool isEvenOneExists = false;
649 for ( int i = 0; i < aListId.count(); i++ ) {
650 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
652 if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
653 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
654 if (!isEvenOneExists)
655 isEvenOneExists = true;
661 if (send == LineEdit1)
663 else if(send == LineEdit4)
672 buttonOk->setEnabled( true );
673 buttonApply->setEnabled( true );
680 //=================================================================================
681 // function : SelectionIntoArgument()
682 // purpose : Called when selection as changed or other case
683 //=================================================================================
684 void SMESHGUI_SewingDlg::SelectionIntoArgument(bool isSelectionChanged)
686 if ( myBusy ) return;
689 if (isSelectionChanged)
692 QString aString = "";
695 myEditCurrentArgument->setText( aString );
698 if ( !GroupButtons->isEnabled() ) // inactive
701 buttonOk->setEnabled( false );
702 buttonApply->setEnabled( false );
705 int nbSel = mySelection->IObjectCount();
709 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
710 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
711 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
713 if (myMesh->_is_nil() || !myActor)
716 // get selected elements/nodes
720 if (GetConstructorId() != 3 || (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4))
722 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
728 aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString);
734 myEditCurrentArgument->setText( aString );
738 if (myEditCurrentArgument == LineEdit1)
740 else if(myEditCurrentArgument == LineEdit2)
742 else if(myEditCurrentArgument == LineEdit3)
744 else if(myEditCurrentArgument == LineEdit4)
746 else if(myEditCurrentArgument == LineEdit5)
748 else if(myEditCurrentArgument == LineEdit6)
753 buttonOk->setEnabled( true );
754 buttonApply->setEnabled( true );
759 //=================================================================================
760 // function : SetEditCurrentArgument()
762 //=================================================================================
763 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
765 QPushButton* send = (QPushButton*)sender();
767 disconnect( mySelection, 0, this, 0 );
768 mySelection->ClearIObjects();
770 if(send == SelectButton1) {
771 myEditCurrentArgument = LineEdit1;
774 else if (send == SelectButton2) {
775 myEditCurrentArgument = LineEdit2;
778 else if (send == SelectButton3) {
779 myEditCurrentArgument = LineEdit3;
782 else if (send == SelectButton4) {
783 myEditCurrentArgument = LineEdit4;
786 else if (send == SelectButton5) {
787 myEditCurrentArgument = LineEdit5;
790 else if (send == SelectButton6) {
791 myEditCurrentArgument = LineEdit6;
795 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4))
797 SMESH::SetPointRepresentation(true);
798 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
802 SMESH::SetPointRepresentation(false);
803 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
806 myEditCurrentArgument->setFocus();
807 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
808 SelectionIntoArgument(false) ;
811 //=================================================================================
812 // function : DeactivateActiveDialog()
814 //=================================================================================
815 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
817 if ( GroupConstructors->isEnabled() ) {
818 GroupConstructors->setEnabled(false) ;
819 GroupArguments->setEnabled(false) ;
820 GroupButtons->setEnabled(false) ;
821 mySMESHGUI->ResetState() ;
822 mySMESHGUI->SetActiveDialogBox(0) ;
827 //=================================================================================
828 // function : ActivateThisDialog()
830 //=================================================================================
831 void SMESHGUI_SewingDlg::ActivateThisDialog()
833 /* Emit a signal to deactivate the active dialog */
834 mySMESHGUI->EmitSignalDeactivateDialog() ;
835 GroupConstructors->setEnabled(true) ;
836 GroupArguments->setEnabled(true) ;
837 GroupButtons->setEnabled(true) ;
839 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
841 ConstructorsClicked(GetConstructorId());
842 SelectionIntoArgument();
846 //=================================================================================
847 // function : enterEvent()
849 //=================================================================================
850 void SMESHGUI_SewingDlg::enterEvent(QEvent* e)
852 if ( GroupConstructors->isEnabled() )
854 ActivateThisDialog() ;
858 //=================================================================================
859 // function : closeEvent()
861 //=================================================================================
862 void SMESHGUI_SewingDlg::closeEvent( QCloseEvent* e )
864 /* same than click on cancel button */
865 this->ClickOnCancel() ;
869 //=======================================================================
870 //function : hideEvent
871 //purpose : caused by ESC key
872 //=======================================================================
874 void SMESHGUI_SewingDlg::hideEvent ( QHideEvent * e )
876 if ( !isMinimized() )
881 //=================================================================================
882 // function : GetConstructorId()
884 //=================================================================================
885 int SMESHGUI_SewingDlg::GetConstructorId()
887 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
888 return GroupConstructors->id( GroupConstructors->selected() );
893 //=================================================================================
894 // function : GetConstructorId()
896 //=================================================================================
897 bool SMESHGUI_SewingDlg::IsValid()
899 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);