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 );
249 SMESHGUI_SewingDlgLayout->addWidget( GroupArguments, 1, 0 );
251 /* Initialisations */
252 GroupArguments->show();
253 RadioButton1->setChecked( TRUE );
256 LineEdit2->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
257 LineEdit3->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
258 LineEdit5->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
259 LineEdit6->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
261 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
262 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
265 /* signals and slots connections */
266 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
267 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( ClickOnCancel() ) ) ;
268 connect( buttonApply, SIGNAL( clicked() ), this, SLOT(ClickOnApply() ) );
269 connect( GroupConstructors, SIGNAL(clicked(int) ), SLOT( ConstructorsClicked(int) ) );
271 connect( SelectButton1, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
272 connect( SelectButton2, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
273 connect( SelectButton3, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
274 connect( SelectButton4, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
275 connect( SelectButton5, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
276 connect( SelectButton6, SIGNAL (clicked() ), this, SLOT( SetEditCurrentArgument() ) ) ;
278 connect( mySMESHGUI, SIGNAL ( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) ) ;
279 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
280 /* to close dialog if study change */
281 connect( mySMESHGUI, SIGNAL ( SignalCloseAllDialogs() ), this, SLOT( ClickOnCancel() ) ) ;
283 connect( LineEdit1, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
284 connect( LineEdit2, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
285 connect( LineEdit3, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
286 connect( LineEdit4, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
287 connect( LineEdit5, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
288 connect( LineEdit6, SIGNAL( textChanged( const QString& )), SLOT( onTextChange( const QString& )));
290 /* Move widget on the botton right corner of main widget */
292 mySMESHGUI->DefineDlgPosition( this, x, y ) ;
294 this->show() ; /* displays Dialog */
296 ConstructorsClicked(0);
300 //=================================================================================
301 // function : ~SMESHGUI_SewingDlg()
302 // purpose : Destroys the object and frees any allocated resources
303 //=================================================================================
304 SMESHGUI_SewingDlg::~SMESHGUI_SewingDlg()
306 // no need to delete child widgets, Qt does it all for us
310 //=================================================================================
313 //=================================================================================
314 void SMESHGUI_SewingDlg::Init()
318 myEditCurrentArgument = LineEdit1;
319 LineEdit1->setFocus();
321 myMesh = SMESH::SMESH_Mesh::_nil();
322 CheckBoxMerge->setChecked(false);
323 SelectionIntoArgument();
327 //=================================================================================
328 // function : ConstructorsClicked()
329 // purpose : Radio button management
330 //=================================================================================
331 void SMESHGUI_SewingDlg::ConstructorsClicked(int constructorId)
333 disconnect(mySelection, 0, this, 0);
334 mySelection->ClearIObjects();
335 LineEdit1->setText("");
336 LineEdit2->setText("");
337 LineEdit3->setText("");
338 LineEdit4->setText("");
339 LineEdit5->setText("");
340 LineEdit6->setText("");
341 myOk1 = myOk2 = myOk3 = myOk4 = myOk5 = myOk6 = false;
342 myEditCurrentArgument = LineEdit1;
343 myEditCurrentArgument->setFocus();
345 if (!TextLabel5->isEnabled())
347 TextLabel5->setEnabled(true);
348 SelectButton5->setEnabled(true);
349 LineEdit5->setEnabled(true);
351 else if (!TextLabel6->isEnabled())
353 TextLabel6->setEnabled(true);
354 SelectButton6->setEnabled(true);
355 LineEdit6->setEnabled(true);
358 switch(constructorId)
362 GroupArguments->setTitle( tr( "SEW_FREE_BORDERS" ) );
363 SubGroup1->setTitle( tr( "BORDER_1" ) );
364 SubGroup2->setTitle( tr( "BORDER_2" ) );
370 GroupArguments->setTitle( tr( "SEW_CONFORM_FREE_BORDERS" ) );
371 SubGroup1->setTitle( tr( "BORDER_1" ) );
372 SubGroup2->setTitle( tr( "BORDER_2" ) );
374 TextLabel6->setEnabled(false);
375 SelectButton6->setEnabled(false);
376 LineEdit6->setEnabled(false);
384 GroupArguments->setTitle( tr( "SEW_BORDER_TO_SIDE" ) );
385 SubGroup1->setTitle( tr( "BORDER" ) );
386 SubGroup2->setTitle( tr( "SIDE" ) );
388 TextLabel5->setEnabled(false);
389 SelectButton5->setEnabled(false);
390 LineEdit5->setEnabled(false);
398 GroupArguments->setTitle( tr( "SEW_SIDE_ELEMENTS" ) );
399 SubGroup1->setTitle( tr( "SIDE_1" ) );
400 SubGroup2->setTitle( tr( "SIDE_2" ) );
402 TextLabel1->setText( tr( "SMESH_ID_ELEMENTS" ) );
403 TextLabel2->setText( tr( "NODE1_TO_MERGE" ) );
404 TextLabel3->setText( tr( "NODE2_TO_MERGE" ) );
405 TextLabel4->setText( tr( "SMESH_ID_ELEMENTS" ) );
406 TextLabel5->setText( tr( "NODE1_TO_MERGE" ) );
407 TextLabel6->setText( tr( "NODE2_TO_MERGE" ) );
409 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator"));
410 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator"));
412 SMESH::SetPointRepresentation(false);
413 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
418 if (constructorId != 3)
420 TextLabel1->setText( tr( "FIRST_NODE_ID" ) );
421 TextLabel2->setText( tr( "SECOND_NODE_ID" ) );
422 TextLabel3->setText( tr( "LAST_NODE_ID" ) );
423 TextLabel4->setText( tr( "FIRST_NODE_ID" ) );
424 TextLabel5->setText( tr( "SECOND_NODE_ID" ) );
425 TextLabel6->setText( tr( "LAST_NODE_ID" ) );
427 LineEdit1->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
428 LineEdit4->setValidator( new SMESHGUI_IdValidator( this, "validator", 1));
430 SMESH::SetPointRepresentation(true);
431 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
434 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
438 //=================================================================================
439 // function : ClickOnApply()
441 //=================================================================================
442 bool SMESHGUI_SewingDlg::ClickOnApply()
444 if (mySMESHGUI->ActiveStudyLocked())
447 bool aResult = false;
451 bool toMerge = CheckBoxMerge->isChecked();
455 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
456 QApplication::setOverrideCursor(Qt::waitCursor);
458 int aConstructorId = GetConstructorId();
459 SMESH::SMESH_MeshEditor::Sew_Error anError;
461 if (aConstructorId == 0)
462 anError = aMeshEditor->SewFreeBorders(LineEdit1->text().toLong(),
463 LineEdit2->text().toLong(),
464 LineEdit3->text().toLong(),
465 LineEdit4->text().toLong(),
466 LineEdit5->text().toLong(),
467 LineEdit6->text().toLong());
468 else if (aConstructorId == 1)
469 anError = aMeshEditor->SewConformFreeBorders(LineEdit1->text().toLong(),
470 LineEdit2->text().toLong(),
471 LineEdit3->text().toLong(),
472 LineEdit4->text().toLong(),
473 LineEdit5->text().toLong());
474 else if (aConstructorId == 2)
475 anError = aMeshEditor->SewBorderToSide(LineEdit1->text().toLong(),
476 LineEdit2->text().toLong(),
477 LineEdit3->text().toLong(),
478 LineEdit4->text().toLong(),
479 LineEdit6->text().toLong());
480 else if (aConstructorId == 3)
482 QStringList aListElementsId1 = QStringList::split( " ", LineEdit1->text(), false);
483 QStringList aListElementsId2 = QStringList::split( " ", LineEdit4->text(), false);
485 SMESH::long_array_var anElementsId1 = new SMESH::long_array;
486 SMESH::long_array_var anElementsId2 = new SMESH::long_array;
488 anElementsId1->length( aListElementsId1.count() );
489 anElementsId2->length( aListElementsId2.count() );
491 for ( int i = 0; i < aListElementsId1.count(); i++ )
492 anElementsId1[i] = aListElementsId1[i].toInt();
493 for ( int i = 0; i < aListElementsId2.count(); i++ )
494 anElementsId2[i] = aListElementsId2[i].toInt();
496 anError = aMeshEditor->SewSideElements(anElementsId1.inout(),
497 anElementsId2.inout(),
498 LineEdit2->text().toLong(),
499 LineEdit5->text().toLong(),
500 LineEdit3->text().toLong(),
501 LineEdit6->text().toLong());
503 aResult = ( anError == SMESH::SMESH_MeshEditor::SEW_OK );
505 if (toMerge && aResult)
506 aMeshEditor->MergeEqualElements();
508 QApplication::restoreOverrideCursor();
511 QString msg = tr(QString("ERROR_%1").arg(anError));
512 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
513 tr("SMESH_WRN_WARNING"),msg,tr("SMESH_BUT_OK"));
522 Handle(SALOME_InteractiveObject) anIO = myActor->getIO();
523 mySelection->ClearIObjects();
525 mySelection->AddIObject( anIO, false );
527 ConstructorsClicked(GetConstructorId());
534 //=================================================================================
535 // function : ClickOnOk()
537 //=================================================================================
538 void SMESHGUI_SewingDlg::ClickOnOk()
545 //=================================================================================
546 // function : ClickOnCancel()
548 //=================================================================================
549 void SMESHGUI_SewingDlg::ClickOnCancel()
551 mySelection->ClearIObjects();
552 SMESH::SetPointRepresentation(false);
553 QAD_Application::getDesktop()->SetSelectionMode( ActorSelection );
554 disconnect( mySelection, 0, this, 0 );
555 mySMESHGUI->ResetState() ;
559 //=======================================================================
560 //function : onTextChange
562 //=======================================================================
564 void SMESHGUI_SewingDlg::onTextChange(const QString& theNewText)
566 QLineEdit* send = (QLineEdit*)sender();
568 if ( myBusy ) return;
572 myEditCurrentArgument = send;
574 if (send == LineEdit1)
576 else if (send == LineEdit2)
578 else if (send == LineEdit3)
580 else if (send == LineEdit4)
582 else if (send == LineEdit5)
584 else if (send == LineEdit6)
587 buttonOk->setEnabled( false );
588 buttonApply->setEnabled( false );
590 // hilight entered elements/nodes
591 SMDS_Mesh* aMesh = 0;
594 aMesh = myActor->GetObject()->GetMesh();
599 mySelection->ClearIObjects();
600 mySelection->AddIObject( myActor->getIO() );
602 if (GetConstructorId() != 3 || (send != LineEdit1 && send != LineEdit4))
604 SMESH::SetPointRepresentation(true);
605 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
607 const SMDS_MeshNode * n = aMesh->FindNode( theNewText.toInt() );
609 if ( !mySelection->IsIndexSelected( myActor->getIO(), n->GetID() ))
610 mySelection->AddOrRemoveIndex (myActor->getIO(), n->GetID(), true);
612 if (send == LineEdit1)
614 else if (send == LineEdit2)
616 else if (send == LineEdit3)
618 else if (send == LineEdit4)
620 else if (send == LineEdit5)
622 else if (send == LineEdit6)
628 SMESH::SetPointRepresentation(false);
629 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
631 QStringList aListId = QStringList::split( " ", theNewText, false);
633 bool isEvenOneExists = false;
635 for ( int i = 0; i < aListId.count(); i++ ) {
636 const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() );
638 if ( !mySelection->IsIndexSelected( myActor->getIO(), e->GetID() ))
639 mySelection->AddOrRemoveIndex (myActor->getIO(), e->GetID(), true);
640 if (!isEvenOneExists)
641 isEvenOneExists = true;
647 if (send == LineEdit1)
649 else if(send == LineEdit4)
658 buttonOk->setEnabled( true );
659 buttonApply->setEnabled( true );
666 //=================================================================================
667 // function : SelectionIntoArgument()
668 // purpose : Called when selection as changed or other case
669 //=================================================================================
670 void SMESHGUI_SewingDlg::SelectionIntoArgument(bool isSelectionChanged)
672 if ( myBusy ) return;
675 if (isSelectionChanged)
678 QString aString = "";
681 myEditCurrentArgument->setText( aString );
684 if ( !GroupButtons->isEnabled() ) // inactive
687 buttonOk->setEnabled( false );
688 buttonApply->setEnabled( false );
691 int nbSel = mySelection->IObjectCount();
695 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
696 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO) ;
697 myActor = SMESH::FindActorByEntry( mySelection->firstIObject()->getEntry() );
699 if (myMesh->_is_nil() || !myActor)
702 // get selected elements/nodes
706 if (GetConstructorId() != 3 || (myEditCurrentArgument != LineEdit1 && myEditCurrentArgument != LineEdit4))
708 aNbUnits = SMESH::GetNameOfSelectedNodes(mySelection, aString);
714 aNbUnits = SMESH::GetNameOfSelectedElements(mySelection, aString);
720 myEditCurrentArgument->setText( aString );
724 if (myEditCurrentArgument == LineEdit1)
726 else if(myEditCurrentArgument == LineEdit2)
728 else if(myEditCurrentArgument == LineEdit3)
730 else if(myEditCurrentArgument == LineEdit4)
732 else if(myEditCurrentArgument == LineEdit5)
734 else if(myEditCurrentArgument == LineEdit6)
739 buttonOk->setEnabled( true );
740 buttonApply->setEnabled( true );
745 //=================================================================================
746 // function : SetEditCurrentArgument()
748 //=================================================================================
749 void SMESHGUI_SewingDlg::SetEditCurrentArgument()
751 QPushButton* send = (QPushButton*)sender();
753 disconnect( mySelection, 0, this, 0 );
754 mySelection->ClearIObjects();
756 if(send == SelectButton1) {
757 myEditCurrentArgument = LineEdit1;
760 else if (send == SelectButton2) {
761 myEditCurrentArgument = LineEdit2;
764 else if (send == SelectButton3) {
765 myEditCurrentArgument = LineEdit3;
768 else if (send == SelectButton4) {
769 myEditCurrentArgument = LineEdit4;
772 else if (send == SelectButton5) {
773 myEditCurrentArgument = LineEdit5;
776 else if (send == SelectButton6) {
777 myEditCurrentArgument = LineEdit6;
781 if (GetConstructorId() != 3 || (send != SelectButton1 && send != SelectButton4))
783 SMESH::SetPointRepresentation(true);
784 QAD_Application::getDesktop()->SetSelectionMode( NodeSelection, true );
788 SMESH::SetPointRepresentation(false);
789 QAD_Application::getDesktop()->SetSelectionMode( CellSelection, true );
792 myEditCurrentArgument->setFocus();
793 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
794 SelectionIntoArgument(false) ;
797 //=================================================================================
798 // function : DeactivateActiveDialog()
800 //=================================================================================
801 void SMESHGUI_SewingDlg::DeactivateActiveDialog()
803 if ( GroupConstructors->isEnabled() ) {
804 GroupConstructors->setEnabled(false) ;
805 GroupArguments->setEnabled(false) ;
806 GroupButtons->setEnabled(false) ;
807 mySMESHGUI->ResetState() ;
808 mySMESHGUI->SetActiveDialogBox(0) ;
813 //=================================================================================
814 // function : ActivateThisDialog()
816 //=================================================================================
817 void SMESHGUI_SewingDlg::ActivateThisDialog()
819 /* Emit a signal to deactivate the active dialog */
820 mySMESHGUI->EmitSignalDeactivateDialog() ;
821 GroupConstructors->setEnabled(true) ;
822 GroupArguments->setEnabled(true) ;
823 GroupButtons->setEnabled(true) ;
825 mySMESHGUI->SetActiveDialogBox( (QDialog*)this ) ;
827 ConstructorsClicked(GetConstructorId());
828 SelectionIntoArgument();
832 //=================================================================================
833 // function : enterEvent()
835 //=================================================================================
836 void SMESHGUI_SewingDlg::enterEvent(QEvent* e)
838 if ( GroupConstructors->isEnabled() )
840 ActivateThisDialog() ;
844 //=================================================================================
845 // function : closeEvent()
847 //=================================================================================
848 void SMESHGUI_SewingDlg::closeEvent( QCloseEvent* e )
850 /* same than click on cancel button */
851 this->ClickOnCancel() ;
855 //=======================================================================
856 //function : hideEvent
857 //purpose : caused by ESC key
858 //=======================================================================
860 void SMESHGUI_SewingDlg::hideEvent ( QHideEvent * e )
862 if ( !isMinimized() )
867 //=================================================================================
868 // function : GetConstructorId()
870 //=================================================================================
871 int SMESHGUI_SewingDlg::GetConstructorId()
873 if ( GroupConstructors != NULL && GroupConstructors->selected() != NULL )
874 return GroupConstructors->id( GroupConstructors->selected() );
879 //=================================================================================
880 // function : GetConstructorId()
882 //=================================================================================
883 bool SMESHGUI_SewingDlg::IsValid()
885 return (myOk1 && myOk2 && myOk3 && myOk4 && myOk5 && myOk6);