]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_DocumentPanel.cxx
Salome HOME
91c790c46548e0be701e4da1004236cfc9027e2d
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentPanel.cxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <OCCViewer_ViewWindow.h>
21 #include "HEXABLOCKGUI_DocumentPanel.hxx"
22 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_SalomeTools.hxx"
24 #include "HEXABLOCKGUI.hxx"
25
26
27 #include <iostream>
28 #include <QtGui>
29 #include <QFlags>
30
31 #include <SalomeApp_Application.h>
32 #include <SalomeApp_Study.h>
33 #include <PyConsole_Console.h>
34 #include <SalomeApp_Tools.h>
35
36 #include <Standard_GUID.hxx>
37 #include <TDF_Label.hxx>
38
39 #include <OCCViewer_ViewWindow.h>
40 #include <OCCViewer_ViewManager.h>
41 // #include <OCCViewer_ViewModel.h>
42
43
44 #include <TopExp.hxx>
45 #include <TopExp_Explorer.hxx>
46 #include <TopoDS_Iterator.hxx>
47 #include <TopTools_MapOfShape.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
50
51
52 #include <SUIT_Session.h>
53 #include <SUIT_Desktop.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <SUIT_MessageBox.h>
56 #include <SUIT_Session.h>
57 #include "SVTK_Selection.h"
58 #include <SVTK_ViewModel.h>
59 #include <VTKViewer_ViewModel.h>
60
61 #include <SUIT_ResourceMgr.h>
62
63
64 // #include <GeometryGUI.h>
65
66 #include <GEOMBase.h>
67 #include <GEOMImpl_Types.hxx>
68
69
70
71 #include "MyGEOMBase_Helper.hxx"
72 #include "GEOMBase.h"
73 #include "GEOM_Operation.h"
74
75
76 #define VERTEX_COORD_MIN -1000000
77 #define VERTEX_COORD_MAX  1000000
78
79
80 using namespace std;
81 using namespace HEXABLOCK::GUI;
82
83
84 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
85 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
86
87 //General SpinBox Delegate
88 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate  {
89 public:
90         HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
91
92         QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
93                         const QModelIndex &index) const{
94                 return new QDoubleSpinBox( parent );
95         }
96 };
97
98 //Angle SpinBox Delegate
99 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate  {
100 public:
101         HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
102
103         QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
104                         const QModelIndex &index) const{
105                 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
106                 sb->setMinimum(0);
107                 sb->setMaximum(360);
108                 return sb;
109         }
110 };
111
112
113 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
114 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate  {
115 public:
116         HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
117
118         QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
119                         const QModelIndex &index) const{
120                 QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
121                 sb->setMinimum(0);
122                 /////// sb->setMaximum(1000000000000000); //10e15   Abu : Pb en 32 bits
123                 sb->setMaximum(1000000000);       //10e9
124                 return sb;
125         }
126 };
127
128
129 // ======================================================== Constructeur
130 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
131                                                                 //   _model(0),
132                                                                 //   _selectionModel(0),
133                                                                   QDialog(parent, f),
134                                                                   MyGEOMBase_Helper( dynamic_cast<SUIT_Desktop*>(parent->parent()) ),
135                                                                   _editMode( editmode ),
136                                                                   _documentModel(0),
137                                                                   //   _patternDataModel(0),
138                                                                   //   _patternBuilderModel(0),
139                                                                   _patternDataSelectionModel(0),
140                                                                   _patternBuilderSelectionModel(0),
141                                                                   _groupsSelectionModel(0),
142                                                                   _meshSelectionModel(0),
143                                                                   _mgr(0),
144                                                                   _vtkVm(0),
145                                                                   _occVm(0),
146                                                                   _currentObj(0),
147                                                                   _expectedSelection(-1),
148                                                                   _selectionMutex( false ),
149                                                                   // _applyCloseButton(0),
150                                                                   _applyButton(0)
151 {
152         MESSAGE("HexaBaseDialog::HexaBaseDialog() dynamic_cast<SUIT_Desktop*>(parent->parent()) =>" << dynamic_cast<SUIT_Desktop*>(parent->parent()) );
153         _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
154         _strHexaWidgetType[EDGE_TREE]   = tr( "EDGE" );
155         _strHexaWidgetType[QUAD_TREE]   = tr( "QUAD" );
156         _strHexaWidgetType[HEXA_TREE]   = tr( "HEXA" );
157
158         _strHexaWidgetType[VECTOR_TREE]   = tr( "VECTOR" );
159         _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
160         _strHexaWidgetType[PIPE_TREE]     = tr( "PIPE" );
161         _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
162         _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
163
164         _strHexaWidgetType[GROUP_TREE]      = tr( "GROUP" );
165         _strHexaWidgetType[LAW_TREE]        = tr( "LAW" );
166         _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
167
168 }
169
170 // ============================================================= Destructeur
171 HexaBaseDialog::~HexaBaseDialog()
172 {
173         //   _mgr->clearSelectionCache();
174         //   _mgr->clearSelected();
175         //   globalSelection();
176         //   erasePreview();
177 }
178
179 // ============================================================== _initButtonBox
180 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
181 {
182         if ( editmode == INFO_MODE )
183                 return NULL;
184
185         //QDialogButtonBox* buttonBox = new QDialogButtonBox(this);
186         QGroupBox* buttonBox = new QGroupBox();
187         buttonBox->setMinimumWidth(5);
188         buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
189         //buttonBox->setOrientation(Qt::Horizontal);
190         QHBoxLayout* buttonsHLayout = new QHBoxLayout();
191         _applyButton      = new QPushButton(tr("Apply"));
192         QPushButton* closeButton = new QPushButton(tr("Close"));
193         QPushButton* helpButton  = new QPushButton(tr("Help"));
194         //_applyCloseButton = new QPushButton(tr("Apply And Close"));
195
196         //connect( buttonBox, SIGNAL(clicked()), this, SLOT(applyAndClose()) );
197         connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()) );
198         connect( closeButton, SIGNAL(clicked()), this, SLOT(close()) );
199         connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()) );
200
201         buttonsHLayout->addWidget( _applyButton );
202         buttonsHLayout->addWidget( closeButton );
203         buttonsHLayout->addStretch(1);
204         buttonsHLayout->addWidget( helpButton );
205         //buttonsHLayout->addButton( _applyCloseButton );
206         buttonBox->setLayout(buttonsHLayout);
207         layout()->addWidget(buttonBox);
208
209         return buttonBox;
210 }
211
212 // ============================================================== _initWidget
213 void HexaBaseDialog::_initWidget( Mode editmode )
214 {
215         _initInputWidget( editmode );
216         _initButtonBox( editmode );
217 }
218
219
220 // ============================================================== _initViewManager
221 void HexaBaseDialog::_initViewManager()
222 {
223         SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
224         _mgr   = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
225         _vtkVm = anApp->getViewManager( SVTK_Viewer::Type(),      true );
226         _occVm = anApp->getViewManager( OCCViewer_Viewer::Type(), true );
227         SUIT_ViewManager* activeVm = anApp->activeViewManager();
228
229         onWindowActivated ( activeVm );
230 }
231
232
233 // ============================================================== apply
234 bool HexaBaseDialog::apply()
235 {
236         MESSAGE("HexaBaseDialog::apply()");
237         QModelIndex iNew;
238         bool applied = apply(iNew);
239         if ( applied ){
240                 // clear all selection
241                 if (_patternDataSelectionModel)    _patternDataSelectionModel->clearSelection();
242                 if (_patternBuilderSelectionModel) _patternBuilderSelectionModel->clearSelection();
243                 if (_groupsSelectionModel)         _groupsSelectionModel->clearSelection();
244                 if (_meshSelectionModel)           _meshSelectionModel->clearSelection();
245                 // select and highlight in vtk view the result
246                 _selectAndHighlight( iNew );
247                 // reinitialization
248                 _currentObj = NULL;
249         }
250         return applied;
251 }
252
253 // ============================================================== accept
254 //void HexaBaseDialog::accept()
255 //{
256 //  bool applied = apply();
257 //  if ( applied ){
258 //    QDialog::accept();
259 //    _disallowSelection();
260 //  }
261 //}
262
263 // ============================================================== close
264 void HexaBaseDialog::close()
265 {
266         _currentObj = NULL;
267         _disallowSelection();
268         //resize(300, 350);
269         QDialog::close();
270 }
271
272 // ============================================================== onHelpRequested
273 void HexaBaseDialog::onHelpRequested()
274 {
275         LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
276         if ( app )
277                 //     app->onHelpContextModule( myGeometryGUI ? app->moduleName( myGeometryGUI->moduleName() ) : QString( "" ), _helpFileName );
278                 app->onHelpContextModule( "HEXABLOCK", _helpFileName );
279
280         else {
281                 QString platform;
282 #ifdef WIN32
283                 platform = "winapplication";
284 #else
285                 platform = "application";
286 #endif
287
288                 SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
289                                 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
290                                 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
291                                 QObject::tr( "BUT_OK" ) );
292         }
293
294 }
295
296 // ============================================================== _selectAndHighlight
297 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
298 {
299         if ( !i.isValid() ) return;
300         setProperty("QModelIndex",  QVariant::fromValue(i));
301         setFocus();
302 }
303
304
305 // ============================================================== _allowSelection
306 void HexaBaseDialog::_allowSelection()
307 {
308         MESSAGE("HexaBaseDialog::_allowSelection(){");
309         if ( _documentModel ){
310                 _documentModel->disallowEdition();
311         }
312         MESSAGE("}");
313 }
314
315 // ============================================================== _disallowSelection
316 void HexaBaseDialog::_disallowSelection()
317 {
318         MESSAGE("HexaBaseDialog::_disallowSelection(){");
319         if ( _documentModel ){
320                 _documentModel->allowEdition();
321         }
322         if ( _patternDataSelectionModel ){
323                 _patternDataSelectionModel->setAllSelection();
324         }
325         MESSAGE("}");
326 }
327
328
329 // ============================================================== _allowVTKSelection
330 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
331 {
332         MESSAGE("HexaBaseDialog::_allowModelSelection(){");
333         if ( !_patternDataSelectionModel ) return false;
334         bool isOk = false;
335
336         HexaWidgetType wType;
337         QVariant v  = obj->property("HexaWidgetType");
338         if ( !v.isValid() ) {
339                 MESSAGE("*  no HexaWidgetType property");
340                 return false;
341         }
342         MESSAGE("*  HEXABLOCKGUI::currentVtkView->raise()");
343         HEXABLOCKGUI::currentVtkView->raise();
344         //   HEXABLOCKGUI::currentVtkView->setFocus();
345         wType = v.value<HexaWidgetType>();
346         MESSAGE("*  HexaWidgetType property is " << wType );
347
348         switch (wType){
349         case VERTEX_TREE:
350                 _patternDataSelectionModel->setVertexSelection(); isOk = true;
351                 break;
352         case EDGE_TREE:
353                 _patternDataSelectionModel->setEdgeSelection(); isOk = true;
354                 break;
355         case QUAD_TREE:
356                 _patternDataSelectionModel->setQuadSelection(); isOk = true;
357                 break;
358         case HEXA_TREE:
359                 _patternDataSelectionModel->setHexaSelection(); isOk = true;
360                 break;
361                 //    case VECTOR_TREE:
362                 //    case CYLINDER_TREE:
363                 //    case PIPE_TREE:
364                 //    case ELEMENTS_TREE:
365                 //    case CROSSELEMENTS_TREE: //selector = _patternBuilderSelectionModel;
366                 //    case GROUP_TREE:      //selector = _groupsSelectionModel;
367                 //    case LAW_TREE:
368                 //    case PROPAGATION_TREE: // selector = _meshSelectionModel;
369         default : MESSAGE("NOT YET");
370         }
371         MESSAGE("}");
372         return isOk;
373 }
374
375 // ============================================================== _allowOCCSelection
376 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
377 {
378         MESSAGE("HexaBaseDialog::_allowOCCCSelection(){");
379         if ( !HEXABLOCKGUI::currentOccView ) return false;
380
381         //We do not allow occ selection when the occ viewer is not activated
382         SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
383         bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
384         if (!isOCC) return false;
385
386
387         GeomWidgetType wType;
388         QVariant v = obj->property("GeomWidgetType");
389         if ( !v.isValid() ) {
390                 MESSAGE("*  no GeomWidgetType property");
391                 return false;
392         }
393         MESSAGE("*  HEXABLOCKGUI::currentOccView->raise()");
394         HEXABLOCKGUI::currentOccView->raise();
395         wType = v.value<GeomWidgetType>();
396         MESSAGE("*  GeomWidgetType property is " << wType );
397         MESSAGE("*  TopAbs_VERTEX           is " << TopAbs_VERTEX );
398         MESSAGE("*  TopAbs_EDGE             is " << TopAbs_EDGE );
399         MESSAGE("*  TopAbs_FACE             is " << TopAbs_FACE );
400
401         globalSelection(); // close local contexts, if any
402         localSelection(GEOM::GEOM_Object::_nil(), wType/*TopAbs_EDGE*/);
403         return true;
404 }
405
406
407 // ============================================================== _getSelector
408 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
409 {
410         QItemSelectionModel* selector = NULL;
411         MESSAGE("HexaBaseDialog::getSelector(){");
412
413         QString objectName = obj->objectName();
414         QString className = obj->metaObject()->className();
415         MESSAGE("*  obj->objectName() is "<< objectName.toStdString() ); //toStdString()
416         MESSAGE("*  obj->metaObject()->className() is "<< className.toStdString() );
417
418         HexaWidgetType wtype;
419         QVariant v  = obj->property("HexaWidgetType");
420         if ( !v.isValid() ) {
421                 MESSAGE("*  no HexaWidgetType property");
422                 return NULL;
423         }
424
425         wtype = v.value<HexaWidgetType>();
426         MESSAGE("*  HexaWidgetType property is " << wtype);
427
428         switch (wtype){
429         case VERTEX_TREE:
430         case EDGE_TREE:
431         case QUAD_TREE:
432         case HEXA_TREE:
433                 selector = _patternDataSelectionModel; break;
434         case VECTOR_TREE:
435         case CYLINDER_TREE:
436         case PIPE_TREE:
437         case ELEMENTS_TREE:
438         case CROSSELEMENTS_TREE:
439                 selector = _patternBuilderSelectionModel; break;
440         case GROUP_TREE:
441                 selector = _groupsSelectionModel; break;
442         case LAW_TREE:
443         case PROPAGATION_TREE:
444                 selector = _meshSelectionModel; break;
445         default : MESSAGE("NOT YET");
446         }
447         MESSAGE("}");
448         return selector;
449 }
450
451
452 // ============================================================== _onSelectionChanged
453
454 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit*  le )
455 {
456         MESSAGE("HexaBaseDialog::_onSelectionChanged(const QItemSelection& sel, QLineEdit*  le)");
457         MESSAGE("*  le is "<< le->objectName().toStdString() );
458         QModelIndexList l = sel.indexes();
459         if ( l.count() == 0 ) return false;
460
461         //type from selection (first)
462         QModelIndex selected = l[0];
463         int selType = selected.data(HEXA_TREE_ROLE).toInt();
464
465         //type of widget
466         QVariant v = le->property("HexaWidgetType");
467         if ( !v.isValid() ) return false;
468         HexaWidgetType wType = v.value<HexaWidgetType>();
469
470         // check selection compatibility between selection and widget
471         if ( selType != wType ){
472                 MESSAGE("*  bad selection : " << selType << " is not  " << wType );
473                 SUIT_MessageBox::information( 0,
474                                 tr("HEXA_INFO"),
475                                 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
476                 return false;
477         }
478
479         //fill the lineEdit if selection is OK
480         le->setText( selected.data().toString() );// name
481         le->setProperty("QModelIndex",  QVariant::fromValue(selected) );
482         _index[le] = selected;
483         MESSAGE("}");
484         return true;
485 }
486
487
488 // ============================================================== _onSelectionChanged
489 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
490 {
491         MESSAGE("HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )");
492         MESSAGE("*  lw is "<< lw->objectName().toStdString() );
493         QModelIndexList l = sel.indexes();
494
495         if ( l.count() == 0 ) return false;
496
497         //type of widget
498         QVariant v = lw->property("HexaWidgetType");
499         if ( !v.isValid() ) return false;
500         HexaWidgetType wType = v.value<HexaWidgetType>();
501
502         //fill the listWidget
503         QListWidgetItem* item = NULL;
504         int selType;
505         QString selName;
506         //   int maxSize = 8;
507         foreach( const QModelIndex& isel, l ){
508                 //     if ( lw->count() == maxSize) break;
509                 selType = isel.data(HEXA_TREE_ROLE).toInt();
510                 if ( selType != wType ){ // check selection compatibility between selection and widget
511                         MESSAGE("*  bad selection : " << selType<< " is not  " << wType );
512                         SUIT_MessageBox::information( 0,
513                                         tr("HEXA_INFO"),
514                                         tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
515                         return false;
516                 }
517                 // add selection to listWidget if selection is OK
518                 selName = isel.data().toString();
519                 QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
520                 if ( twice.count() == 0 ){
521                         item = new QListWidgetItem( selName );
522                         item->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
523                         lw->addItem(item);
524                         updateButtonBox();
525                 }
526         }
527         MESSAGE("}");
528         return true;
529 }
530
531 // ============================================================== onCurrentSelectionChanged
532 void HexaBaseDialog::onCurrentSelectionChanged()
533 {
534 }
535
536
537 // ============================================================== setDocumentModel
538 void HexaBaseDialog::setDocumentModel(DocumentModel* m)
539 {
540         _documentModel = m;
541 }
542
543 // ============================================================== clear
544 void HexaBaseDialog::clear()
545 {
546 }
547
548
549 // ============================================================== setPatternDataSelectionModel
550 void HexaBaseDialog::setPatternDataSelectionModel(PatternDataSelectionModel* s)
551 {
552         _patternDataSelectionModel = s;
553 }
554
555
556 // ============================================================== setPatternBuilderSelectionModel
557 void HexaBaseDialog::setPatternBuilderSelectionModel(PatternBuilderSelectionModel* s)
558 {
559         _patternBuilderSelectionModel = s;
560 }
561
562 // ============================================================== setGroupsSelectionModel
563 void HexaBaseDialog::setGroupsSelectionModel( GroupsSelectionModel* s )
564 {
565         _groupsSelectionModel = s;
566 }
567
568
569 // ============================================================== setMeshSelectionModel
570 void HexaBaseDialog::setMeshSelectionModel( MeshSelectionModel* s )
571 {
572         _meshSelectionModel = s;
573 }
574
575
576 // ============================================================== onSelectionChanged
577 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
578 {
579         MESSAGE( "HexaBaseDialog::onSelectionChanged(){" );
580         QString className = metaObject()->className();
581         MESSAGE( "*  I am                          : " << className.toStdString() );
582         MESSAGE( "*  sender is                     : " << sender() );
583         MESSAGE( "*  _patternDataSelectionModel    : " << _patternDataSelectionModel );
584         MESSAGE( "*  _patternBuilderSelectionModel : " << _patternBuilderSelectionModel );
585         MESSAGE( "*  _groupsSelectionModel         : " << _groupsSelectionModel );
586         MESSAGE( "*  _meshSelectionModel           : " << _meshSelectionModel );
587
588
589         QItemSelectionModel* selector = dynamic_cast<QItemSelectionModel*>(sender());
590         MESSAGE( "*  selector           : " << selector);
591
592         foreach( const QModelIndex& isel, sel.indexes() ){
593                 MESSAGE("*  selected : " << isel.data().toString().toStdString());
594         }
595         foreach( const QModelIndex& iunsel, unsel.indexes() ){
596                 MESSAGE("*  unselected : " << iunsel.data().toString().toStdString());
597         }
598
599         if ( _selectionMutex )
600                 return;
601
602
603         bool selOk = false;
604         QLineEdit*   aLineEdit   = 0;
605         QListWidget* aListWidget = 0;
606         aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
607         if ( aLineEdit){ //fill the lineedit with selection
608                 selOk = _onSelectionChanged( sel, aLineEdit );
609         }
610         aListWidget = dynamic_cast<QListWidget*>(_currentObj);
611         if ( aListWidget){ //fill the listWidget with selection
612                 selOk = _onSelectionChanged( sel, aListWidget );
613         }
614
615         if ( !selOk && selector && ( aLineEdit || aListWidget ) ){
616                 selector->clearSelection();
617         }
618
619         MESSAGE("}");
620 }
621
622 // ============================================================== onWindowActivated
623 void HexaBaseDialog::onWindowActivated( SUIT_ViewManager* vm )
624 {
625 }
626
627 // ============================================================== hideEvent
628 void HexaBaseDialog::hideEvent ( QHideEvent * event )
629 {
630         MESSAGE("HexaBaseDialog::hideEvent(){");
631         QString className = metaObject()->className();
632         MESSAGE( "*  I am                          : " << className.toStdString() );
633
634         if ( _patternDataSelectionModel )
635                 disconnect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
636                                 this,                         SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
637         if ( _patternBuilderSelectionModel )
638                 disconnect( _patternBuilderSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
639                                 this,                            SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
640         if ( _groupsSelectionModel )
641                 disconnect( _groupsSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
642                                 this,                    SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
643         if ( _meshSelectionModel )
644                 disconnect( _meshSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
645                                 this,                SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
646         //   if ( _mgr )
647         //     disconnect( _mgr, 0/*SIGNAL(currentSelectionChanged())*/, this, 0/*SLOT(onCurrentSelectionChanged())*/ );
648         disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(onCurrentSelectionChanged()) );
649         if ( _vtkVm )
650                 disconnect( _vtkVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
651         if ( _occVm )
652                 disconnect( _occVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
653
654         _documentModel->allowEdition();
655
656         QDialog::hideEvent( event );
657         MESSAGE("}");
658 }
659
660 // ============================================================== showEvent
661 void HexaBaseDialog::showEvent( QShowEvent * event )
662 {
663         MESSAGE("HexaBaseDialog::showEvent(){");
664         QString className = metaObject()->className();
665         MESSAGE( "*  I am                          : " << className.toStdString() );
666
667         if ( _editMode == INFO_MODE ){
668                 _documentModel->allowEdition();
669         } else {
670                 _documentModel->disallowEdition();
671         }
672
673         if ( _patternDataSelectionModel ){
674                 _patternDataSelectionModel->clearSelection();
675                 connect( _patternDataSelectionModel, SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
676                                 this,                    SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
677         }
678         if ( _patternBuilderSelectionModel ){
679                 _patternBuilderSelectionModel->clearSelection();
680                 connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
681                                 this,                            SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
682         }
683         if ( _groupsSelectionModel ){
684                 _groupsSelectionModel->clearSelection();
685                 connect( _groupsSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
686                                 this,                    SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
687         }
688         if ( _meshSelectionModel ){
689                 _meshSelectionModel->clearSelection();
690                 connect( _meshSelectionModel, SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
691                                 this,                SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
692         }
693         if ( _mgr )
694                 connect( _mgr, SIGNAL(currentSelectionChanged()), this, SLOT(onCurrentSelectionChanged()) );
695
696         if ( _vtkVm )
697                 connect( _vtkVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
698         if ( _occVm )
699                 connect( _occVm, SIGNAL( activated(SUIT_ViewManager*) ), this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
700
701         QDialog::showEvent ( event );
702         MESSAGE("}");
703 }
704
705
706
707 // ============================================================== updateButtonBox
708 void HexaBaseDialog::updateButtonBox()
709 {
710 }
711
712 void HexaBaseDialog::updateName()
713 {
714         if (!_documentModel) return;
715         if ( !_patternDataSelectionModel )  return;
716         const PatternDataModel*   patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
717
718         QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
719         if (!lineEdit) return;
720         QString newName = lineEdit->text();
721         if ( newName.isEmpty() ) return;
722
723         QVariant v = lineEdit->property("QModelIndex");
724         if ( !v.isValid() ) return;
725
726         QModelIndex index = v.value<QModelIndex>();
727         if ( index.isValid() )
728                 _documentModel->setName( patternDataModel->mapToSource(index), newName );
729 }
730
731
732
733 // ============================================================== selectElementOfModel
734 void HexaBaseDialog::selectElementOfModel()
735 {
736         MESSAGE("HexaBaseDialog::selectElementOfModel()");
737         if (!_patternDataSelectionModel) return;
738
739         QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
740         if ( !currentListWidget ) return;
741
742         _selectionMutex = true;
743
744         QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
745         QModelIndex index;
746         _patternDataSelectionModel->clearSelection();
747         foreach ( QListWidgetItem *item, sel ){
748                 MESSAGE( "*  selecting the element : " << index.data().toString().toStdString() );
749                 index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
750                 if ( index.isValid() )
751                         _patternDataSelectionModel->select( index, QItemSelectionModel::Select );
752         }
753         _selectionMutex = false;
754
755         MESSAGE("}");
756 }
757
758 // ============================================================== eventFilter
759 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
760 {
761         QLineEdit       *lineEdit = dynamic_cast<QLineEdit*>(obj);
762         QListWidget *listWidget = dynamic_cast<QListWidget*>(obj);
763         HexaBaseDialog  *dialog = dynamic_cast<HexaBaseDialog*>(obj);
764
765         if ( event->type() == QEvent::FocusIn ){
766                 QString className  = obj->metaObject()->className();
767                 QString objectName = obj->objectName();
768                 MESSAGE("QEvent::FocusIn : I am "<< objectName.toStdString() );
769                 MESSAGE("QEvent::FocusIn : I am "<< className.toStdString() );
770
771                 // Highlight the input widget
772                 if ( lineEdit || listWidget ){
773                         QWidget* w = dynamic_cast<QWidget*>(obj);
774                         QPalette palette1 = w->palette();
775                         palette1.setColor(w->backgroundRole(), Qt::yellow);
776                         w->setPalette(palette1);
777                 }
778         }
779
780         if ( event->type() == QEvent::FocusOut ){
781                 QString className = obj->metaObject()->className();
782                 QString objectName = obj->objectName();
783                 MESSAGE("QEvent::FocusOut : I am "<< objectName.toStdString() );
784                 MESSAGE("QEvent::FocusOut : I am "<< className.toStdString() );
785
786                 // UnHighlight the input widget
787                 if ( lineEdit || listWidget ){
788                         QWidget* w = dynamic_cast<QWidget*>(obj);
789                         QPalette palette1 = w->palette();
790                         palette1.setColor(w->backgroundRole(), Qt::white);
791                         w->setPalette(palette1);
792                 }
793         }
794
795         if ( event->type() != QEvent::FocusIn ){ //QEvent::KeyPress) {
796                 return false;
797                 //              return QObject::eventFilter(obj, event);
798         }
799
800         MESSAGE("HexaBaseDialog::eventFilter{");
801         MESSAGE("*  QEvent::FocusIn");
802
803         /* ON FOCUS ON A WIDGET*/
804         QVariant v;
805         QModelIndex index;
806
807
808         QItemSelectionModel *selector = 0;
809         _allowVTKSelection( obj );
810
811         //geom selection
812         _allowOCCSelection( obj );
813
814         //Depending of focused widget type, get the right selector for it
815         selector = _getSelector( obj );
816         if ( !selector ) return false;
817
818         // Highlight the input widget
819         if ( _currentObj != obj && (lineEdit || listWidget) ){
820                 selector->clearSelection();
821         }
822         _currentObj = obj;
823
824
825         //If there is a current selection fill the widget with it
826         if ( selector->hasSelection() ){
827                 QItemSelection currentSelection  = selector->selection();
828                 bool selOk = false;
829                 if ( lineEdit ){ //element can be from lineEdit
830                         selOk = _onSelectionChanged( currentSelection, lineEdit );
831                 } else if ( listWidget ){
832                         selOk = _onSelectionChanged( currentSelection, listWidget );
833                 }
834                 if ( !selOk &&  ( lineEdit || listWidget ) ){
835                         selector->clearSelection();
836                 }
837
838         } else { //If the widget contains an hexa element, select it in model/view
839                 if ( lineEdit ){ //element can be from lineEdit
840                         MESSAGE("*  on QLineEdit");
841                         v = lineEdit->property("QModelIndex");
842                         if ( !v.isValid() ) {
843                                 //return QObject::eventFilter(obj, event);
844                                 return false;
845                         }
846                         index = v.value<QModelIndex>();
847
848                         _selectionMutex = true;
849                         MESSAGE("*  selecting the element : " << index.data().toString().toStdString());
850                         MESSAGE("*  with selector : " << selector);
851                         MESSAGE( "*  _patternDataSelectionModel    : " << _patternDataSelectionModel );
852                         MESSAGE( "*  _patternBuilderSelectionModel : " << _patternBuilderSelectionModel );
853                         MESSAGE( "*  _groupsSelectionModel         : " << _groupsSelectionModel );
854                         MESSAGE( "*  _meshSelectionModel           : " << _meshSelectionModel );
855                         selector->select( index, QItemSelectionModel::Clear );
856                         selector->select( index, QItemSelectionModel::Select );
857                         _selectionMutex = false;
858                 }
859
860
861                 if ( dialog ){ //element can be from a dialog box
862                         MESSAGE("*  on Dialog");
863                         v = dialog->property("QModelIndex");
864                         if ( !v.isValid() ) {
865                                 //return QObject::eventFilter(obj, event);
866                                 return false;
867                         }
868                         index = v.value<QModelIndex>();
869                         _selectionMutex = true;
870                         MESSAGE("*  selecting the element : " << index.data().toString().toStdString());
871                         selector->select( index, QItemSelectionModel::Clear );
872                         selector->select( index, QItemSelectionModel::Select );
873                         _selectionMutex = false;
874                 }
875
876         }
877         MESSAGE("}");
878         return false;
879 }
880
881
882 // ------------------------- VERTEX ----------------------------------
883
884 // ============================================================== Constructeur
885 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
886                                                                   HexaBaseDialog(parent, editmode, f),
887                                                                   _value(0)
888 {
889         _helpFileName = "gui_vertex.html";
890         setupUi( this );
891         _initWidget(editmode);
892         //   setFocusProxy( name_le );
893
894         if ( editmode  == NEW_MODE ){
895                 setWindowTitle( tr("Vertex Construction") );
896         } else if ( editmode == UPDATE_MODE ){
897                 setWindowTitle( tr("Vertex Modification") );
898         }
899 }
900
901 // ============================================================== Destructeur
902 VertexDialog::~VertexDialog()
903 {
904 }
905
906
907 // ============================================================== _initInputWidget
908 void VertexDialog::_initInputWidget( Mode editmode )
909 {
910         x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
911         y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
912         z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
913
914         setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
915         installEventFilter(this);
916         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
917         name_le->installEventFilter(this);
918
919         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
920 }
921
922 // ============================================================== clear
923 void VertexDialog::clear()
924 {
925         //   name_le->clear();
926 }
927
928 // ============================================================== setValue
929 void VertexDialog::setValue(HEXA_NS::Vertex* v)
930 {
931         MESSAGE("*  setValue : " << v);
932         //0) Name
933         name_le->setText( v->getName() );
934
935         //1) Value (x,y,z)
936         x_spb->setValue( v->getX() );
937         y_spb->setValue( v->getY() );
938         z_spb->setValue( v->getZ() );
939
940         MESSAGE("*  _patternDataSelectionModel  : " << _patternDataSelectionModel );
941         if ( _patternDataSelectionModel ){
942                 QModelIndex iv = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
943                 MESSAGE("*  selecting the element : " << iv.data().toString().toStdString());
944
945                 setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(iv) );
946                 name_le->setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(iv) );
947         }
948         _value = v;
949 }
950
951
952 // ============================================================== getValue
953 HEXA_NS::Vertex* VertexDialog::getValue()
954 {
955         return _value;
956 }
957
958
959
960 // ============================================================== apply
961 bool VertexDialog::apply(QModelIndex& result)
962 {
963         SUIT_OverrideCursor wc;
964         if ( !_documentModel ) return false;
965         if ( !_patternDataSelectionModel ) return false;
966         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
967         if ( !patternDataModel ) return false;
968         _currentObj = NULL;
969
970         bool isOk = false;
971
972         QModelIndex iVertex;
973         double newX = x_spb->value();
974         double newY = y_spb->value();
975         double newZ = z_spb->value();
976
977         if ( _editMode == UPDATE_MODE){
978                 QVariant v = property("QModelIndex");
979                 if ( v.isValid() ){
980                         iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
981                         if ( iVertex.isValid() )
982                                 isOk = _documentModel->updateVertex( iVertex, newX, newY, newZ );
983                 }
984         } else if ( _editMode == NEW_MODE){
985                 iVertex = _documentModel->addVertex( newX, newY, newZ );
986                 if ( iVertex.isValid() )
987                         isOk = true;
988         }
989         if (!isOk) {
990                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) );
991                 return false;
992         }
993
994         QString newName = name_le->text();
995         if ( !newName.isEmpty() )/*{*/
996                 _documentModel->setName( iVertex, newName );
997
998         // to select/highlight result
999         result = patternDataModel->mapFromSource(iVertex);
1000
1001         return isOk;
1002 }
1003
1004
1005 // ------------------------- EDGE ----------------------------------
1006
1007 // ============================================================== Constructeur
1008 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1009                                                                   HexaBaseDialog(parent, editmode, f),
1010                                                                   _value(0)
1011 {
1012         _helpFileName = "gui_edge.html";
1013         setupUi( this );
1014         _initWidget(editmode);
1015
1016         rb0->setFocusProxy( v0_le_rb0 );
1017         rb1->setFocusProxy( vex_le_rb1 );
1018         rb0->click();
1019
1020         if  ( editmode == INFO_MODE ){
1021                 setWindowTitle( tr("Edge Information") );
1022                 rb1->hide();
1023         }
1024 }
1025
1026
1027
1028 // ============================================================== Destructeur
1029 EdgeDialog::~EdgeDialog()
1030 {
1031 }
1032
1033
1034 // ============================================================== _initInputWidget
1035 void EdgeDialog::_initInputWidget( Mode editmode )
1036 {
1037         QRegExp rx("");
1038         QValidator *validator = new QRegExpValidator(rx, this);
1039
1040         setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1041         installEventFilter(this);
1042
1043         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1044         name_le->installEventFilter(this);
1045
1046         v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1047         v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1048         v0_le_rb0->setValidator( validator );
1049         v1_le_rb0->setValidator( validator );
1050         v0_le_rb0->installEventFilter(this);
1051         v1_le_rb0->installEventFilter(this);
1052
1053         vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1054         vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1055         vex_le_rb1->setValidator( validator );
1056         vec_le_rb1->setValidator( validator );
1057         vex_le_rb1->installEventFilter(this);
1058         vec_le_rb1->installEventFilter(this);
1059
1060         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1061 }
1062
1063
1064 // ============================================================== Clear
1065 void EdgeDialog::clear()
1066 {
1067         name_le->clear();
1068         v0_le_rb0->clear();
1069         v1_le_rb0->clear();
1070         vex_le_rb1->clear();
1071         vec_le_rb1->clear();
1072 }
1073
1074
1075
1076 // ============================================================== setValue
1077 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1078 {
1079         HEXA_NS::Vertex* v0 = e->getVertex(0);
1080         HEXA_NS::Vertex* v1 = e->getVertex(1);
1081
1082         name_le->setText( e->getName() );
1083         v0_le_rb0->setText( v0->getName() );
1084         v1_le_rb0->setText( v1->getName() );
1085
1086         if ( _patternDataSelectionModel ){
1087                 QModelIndex ie  = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1088                 QModelIndex iv0 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1089                 QModelIndex iv1 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1090
1091                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(ie) );
1092                 v0_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv0) );
1093                 v1_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv1) );
1094         }
1095         _value = e;
1096 }
1097
1098
1099 // ============================================================== getValue
1100 HEXA_NS::Edge* EdgeDialog::getValue()
1101 {
1102         return _value;
1103 }
1104
1105 // ============================================================== apply
1106 bool EdgeDialog::apply(QModelIndex& result)
1107 {
1108         SUIT_OverrideCursor wc;
1109         //if ( !_documentModel ) return;
1110         if ( !_patternDataSelectionModel )    return false;
1111         if ( !_patternBuilderSelectionModel ) return false;
1112         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1113         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
1114         if ( !patternDataModel ) return false;
1115         if ( !patternBuilderModel ) return false;
1116         _currentObj = NULL;
1117
1118         QModelIndex iEdge;
1119
1120         if ( rb0->isChecked() ){
1121                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1122                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1123                 if ( iv0.isValid()&& iv1.isValid() ){
1124                         iEdge = _documentModel->addEdgeVertices( iv0, iv1 );
1125                 }
1126         } else if ( rb1->isChecked() ){
1127                 QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1128                 QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1129                 if ( ivex.isValid() && ivec.isValid() ){
1130                         iEdge = _documentModel->addEdgeVector( ivex, ivec );
1131                 }
1132         }
1133
1134         if ( !iEdge.isValid() ){
1135                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" ) );
1136                 return false;
1137         }
1138         _value  = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1139
1140         QString newName = name_le->text();
1141         if ( !newName.isEmpty() )/*{*/
1142                 _documentModel->setName( iEdge, newName );
1143
1144         result = patternDataModel->mapFromSource(iEdge);
1145
1146         return true;
1147 }
1148
1149
1150 // ------------------------- QUAD ----------------------------------
1151
1152 // ============================================================== Constructeur
1153 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1154                                                                   HexaBaseDialog(parent, editmode, f),
1155                                                                   _value(0)
1156 {
1157         _helpFileName = "gui_quadrangle.html";
1158         setupUi( this );
1159         _initWidget(editmode);
1160         rb0->setFocusProxy( v0_le_rb0 );
1161         rb1->setFocusProxy( e0_le_rb1 );
1162         rb0->click();
1163
1164         if  ( editmode == INFO_MODE ){
1165                 setWindowTitle( tr("Quad Information") );
1166         }
1167 }
1168
1169 // ============================================================== Destructeur
1170 QuadDialog::~QuadDialog()
1171 {
1172 }
1173
1174 // ============================================================== _initInputWidget
1175 void QuadDialog::_initInputWidget( Mode editmode )
1176 {
1177         QRegExp rx("");
1178         QValidator *validator = new QRegExpValidator(rx, this);
1179
1180         setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
1181         installEventFilter(this);
1182
1183         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
1184         name_le->installEventFilter(this);
1185
1186         v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1187         v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1188         v2_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1189         v3_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1190
1191         v0_le_rb0->setValidator( validator );
1192         v1_le_rb0->setValidator( validator );
1193         v2_le_rb0->setValidator( validator );
1194         v3_le_rb0->setValidator( validator );
1195         v0_le_rb0->installEventFilter(this);
1196         v1_le_rb0->installEventFilter(this);
1197         v2_le_rb0->installEventFilter(this);
1198         v3_le_rb0->installEventFilter(this);
1199
1200         e0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1201         e1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1202         e2_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1203         e3_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1204
1205         e0_le_rb1->setValidator( validator );
1206         e1_le_rb1->setValidator( validator );
1207         e2_le_rb1->setValidator( validator );
1208         e3_le_rb1->setValidator( validator );
1209
1210         e0_le_rb1->installEventFilter(this);
1211         e1_le_rb1->installEventFilter(this);
1212         e2_le_rb1->installEventFilter(this);
1213         e3_le_rb1->installEventFilter(this);
1214
1215         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1216 }
1217
1218
1219 // ============================================================== clear
1220 void QuadDialog::clear()
1221 {
1222         v0_le_rb0->clear();
1223         v1_le_rb0->clear();
1224         v2_le_rb0->clear();
1225         v3_le_rb0->clear();
1226
1227         e0_le_rb1->clear();
1228         e1_le_rb1->clear();
1229         e2_le_rb1->clear();
1230         e3_le_rb1->clear();
1231
1232         name_le->clear();
1233 }
1234
1235
1236 // ============================================================== setValue
1237 void QuadDialog::setValue(HEXA_NS::Quad* q)
1238 {
1239         Q_ASSERT( q->countEdge() == 4 );
1240         Q_ASSERT( q->countVertex() == 4 );
1241
1242         //0) Name
1243         name_le->setText( q->getName() );
1244
1245         //1) Vertices
1246         HEXA_NS::Vertex* v0 = q->getVertex(0);
1247         HEXA_NS::Vertex* v1 = q->getVertex(1);
1248         HEXA_NS::Vertex* v2 = q->getVertex(2);
1249         HEXA_NS::Vertex* v3 = q->getVertex(3);
1250
1251         v0_le_rb0->setText( v0->getName() );
1252         v1_le_rb0->setText( v1->getName() );
1253         v2_le_rb0->setText( v2->getName() );
1254         v3_le_rb0->setText( v3->getName() );
1255
1256
1257         //2) Edges
1258         HEXA_NS::Edge* e0 = q->getEdge(0);
1259         HEXA_NS::Edge* e1 = q->getEdge(1);
1260         HEXA_NS::Edge* e2 = q->getEdge(2);
1261         HEXA_NS::Edge* e3 = q->getEdge(3);
1262
1263         e0_le_rb1->setText( e0->getName() );
1264         e1_le_rb1->setText( e1->getName() );
1265         e2_le_rb1->setText( e2->getName() );
1266         e3_le_rb1->setText( e3->getName() );
1267
1268         if ( _patternDataSelectionModel ){
1269                 QModelIndex iq = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1270
1271                 QModelIndex iv0 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1272                 QModelIndex iv1 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1273                 QModelIndex iv2 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1274                 QModelIndex iv3 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1275
1276                 QModelIndex ie0 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1277                 QModelIndex ie1 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1278                 QModelIndex ie2 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1279                 QModelIndex ie3 = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1280
1281                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(iq) );
1282
1283                 v0_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv0) );
1284                 v1_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv1) );
1285                 v2_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv2) );
1286                 v3_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv3) );
1287
1288                 e0_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie0) );
1289                 e1_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie1) );
1290                 e2_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie2) );
1291                 e3_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie3) );
1292         }
1293         _value = q;
1294
1295 }
1296
1297 // ============================================================== getValue
1298 HEXA_NS::Quad* QuadDialog::getValue()
1299 {
1300         return _value;
1301 }
1302
1303
1304 // ============================================================== apply
1305 bool QuadDialog::apply(QModelIndex& result)
1306 {
1307         SUIT_OverrideCursor wc;
1308         //if ( !_documentModel ) return;
1309         if ( !_patternDataSelectionModel ) return false;
1310         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1311         if ( !patternDataModel ) return false;
1312         _currentObj = NULL;
1313
1314         QModelIndex iQuad;
1315
1316         if ( rb0->isChecked() ){ //vertices
1317                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1318                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1319                 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1320                 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1321
1322                 if ( iv0.isValid()
1323                                 && iv1.isValid()
1324                                 && iv2.isValid()
1325                                 && iv3.isValid() ){
1326                         iQuad = _documentModel->addQuadVertices( iv0, iv1, iv2, iv3 );
1327                 }
1328         } else if ( rb1->isChecked() ){ //edges
1329                 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1330                 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1331                 QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1332                 QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1333
1334                 if ( ie0.isValid()
1335                                 && ie1.isValid()
1336                                 && ie2.isValid()
1337                                 && ie3.isValid() ){
1338                         iQuad = _documentModel->addQuadEdges( ie0, ie1, ie2, ie3 );
1339                 }
1340         }
1341
1342         if ( !iQuad.isValid() ){
1343                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" ) );
1344                 return false;
1345         }
1346         _value  = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1347
1348         QString newName = name_le->text();
1349         if ( !newName.isEmpty() )/*{*/
1350                 _documentModel->setName( iQuad, newName );
1351
1352         // to select/highlight result
1353         result = patternDataModel->mapFromSource(iQuad);
1354
1355         return true;
1356 }
1357
1358
1359
1360 // ------------------------- HEXA ----------------------------------
1361
1362 // ============================================================== HexaDialog
1363
1364 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1365                                                                   HexaBaseDialog(parent, editmode, f),
1366                                                                   _value(0)
1367 {
1368         _helpFileName = "gui_hexahedron.html";
1369         setupUi( this );
1370         _initWidget(editmode);
1371         quads_rb->setFocusProxy( quads_lw );
1372         vertices_rb->setFocusProxy( vertices_lw );
1373         quads_rb->click();
1374         //   quads_rb->setFocus();
1375
1376         if  ( editmode == INFO_MODE ){
1377                 setWindowTitle( tr("Hexahedron Information") );
1378         }
1379 }
1380
1381 // ============================================================== Destructeur
1382 HexaDialog::~HexaDialog()
1383 {
1384 }
1385
1386
1387 // ============================================================== _initInputWidget
1388 void HexaDialog::_initInputWidget( Mode editmode )
1389 {
1390         QRegExp rx("");
1391         QValidator *validator = new QRegExpValidator(rx, this);
1392
1393         setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
1394         installEventFilter(this);
1395
1396         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
1397         name_le->installEventFilter(this);
1398
1399         quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
1400         quads_lw->installEventFilter(this);
1401
1402         vertices_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1403         vertices_lw->installEventFilter(this);
1404
1405
1406         if ( editmode != INFO_MODE ) {
1407                 // delete item from listwidget
1408                 QShortcut* delQuadShortcut   = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1409                 QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1410                 delQuadShortcut->setContext( Qt::WidgetShortcut );
1411                 delVertexShortcut->setContext( Qt::WidgetShortcut );
1412                 connect(delQuadShortcut,   SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1413                 connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1414         }
1415         // edit name
1416         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1417         // highlight item on model view (VTK) from listwidget
1418         connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
1419         connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
1420 }
1421
1422 // ============================================================== clear
1423 void HexaDialog::clear()
1424 {
1425         name_le->clear();
1426         quads_lw->clear();
1427         vertices_lw->clear();
1428 }
1429
1430 // ============================================================== updateButtonBox
1431 void HexaDialog::updateButtonBox()
1432 {
1433         if ( quads_rb->isChecked() ){  // build from quads count() must be between [2,6]
1434                 int nbQuads = quads_lw->count();
1435                 //std::cout << "nbQuads => " <<  nbQuads << std::endl;
1436                 if ( nbQuads >= 2 && nbQuads <= 6 ){
1437                         //_applyCloseButton->setEnabled(true);
1438                         _applyButton->setEnabled(true);
1439                         //       _applyCloseButton->setFlat( false );
1440                         //       _applyButton->setFlat( false );
1441                 } else {
1442                         //_applyCloseButton->setEnabled(false);
1443                         _applyButton->setEnabled(false);
1444                         //       _applyCloseButton->setFlat( true );
1445                         //       _applyButton->setFlat( true );
1446                 }
1447         } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1448                 int nbVertices = vertices_lw->count();
1449                 //std::cout << "nbVertices => " <<  nbVertices << std::endl;
1450                 if ( nbVertices == 8 ){
1451                         //_applyCloseButton->setEnabled(true);
1452                         _applyButton->setEnabled(true);
1453                         //       _applyCloseButton->setFlat( false );
1454                         //       _applyButton->setFlat( false );
1455                 } else {
1456                         //_applyCloseButton->setEnabled(false);
1457                         _applyButton->setEnabled(false);
1458                         //       _applyCloseButton->setFlat( true );
1459                         //       _applyButton->setFlat( true );
1460                 }
1461         }
1462 }
1463
1464 // ============================================================== deleteQuadItem
1465 void HexaDialog::deleteQuadItem()
1466 {
1467         delete quads_lw->currentItem();
1468         updateButtonBox();
1469 }
1470
1471 // ============================================================== deleteVertexItem
1472 void HexaDialog::deleteVertexItem()
1473 {
1474         delete vertices_lw->currentItem();
1475         updateButtonBox();
1476 }
1477
1478 // ============================================================== _setValueQuads
1479 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1480 {
1481         QListWidgetItem *qItem = NULL;
1482         HEXA_NS::Quad   *q     = NULL;
1483         QModelIndex      qIndex;
1484
1485         quads_lw->clear();
1486         for( int i = 0; i <= 5; ++i ){
1487                 q      = h->getQuad(i);
1488                 qIndex = _patternDataSelectionModel->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1489                 qItem  = new QListWidgetItem( q->getName() );
1490                 qItem->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1491                 quads_lw->addItem( qItem );
1492         }
1493 }
1494
1495 // ============================================================== _setValueVertices
1496 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1497 {
1498         QListWidgetItem *vItem = NULL;
1499         HEXA_NS::Vertex* v     = NULL;
1500         QModelIndex      vIndex;
1501
1502         vertices_lw->clear();
1503         for( int i = 0; i <= 7; ++i ){
1504                 v = h->getVertex(i);
1505                 vIndex = _patternDataSelectionModel->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1506                 vItem  = new QListWidgetItem( v->getName() );
1507                 vItem->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1508                 vertices_lw->addItem( vItem );
1509         }
1510 }
1511
1512 // ============================================================== setValue
1513 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1514 {
1515         // 0) name
1516         name_le->setText( h->getName() );
1517
1518         if ( _patternDataSelectionModel){
1519                 QModelIndex hIndex = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1520                 _setValueVertices(h);
1521                 _setValueQuads(h);
1522                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(hIndex) );
1523         }
1524         _value = h;
1525 }
1526
1527 // ============================================================== getValue
1528 HEXA_NS::Hexa* HexaDialog::getValue()
1529 {
1530         return _value;
1531 }
1532
1533 // ============================================================== apply
1534 bool HexaDialog::apply(QModelIndex& result)
1535 {
1536         SUIT_OverrideCursor wc;
1537         if ( !_documentModel ) return false;
1538         if ( !_patternDataSelectionModel ) return false;
1539         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1540         if ( !patternDataModel ) return false;
1541         _currentObj = NULL;
1542
1543         QModelIndex  iHexa;
1544
1545         QListWidget* currentLw = NULL;
1546         QListWidgetItem*  item = NULL;
1547
1548         if ( quads_rb->isChecked() )
1549                 currentLw = dynamic_cast<QListWidget*>( quads_lw );
1550         else if ( vertices_rb->isChecked() )
1551                 currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1552
1553         QModelIndex     iElt;
1554         QModelIndexList iElts;
1555         for ( int r = 0; r < currentLw->count(); ++r){
1556                 item = currentLw->item(r);
1557                 iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1558                 if ( iElt.isValid() )
1559                         iElts << iElt;
1560         }
1561
1562         if ( quads_rb->isChecked() and (iElts.count()>=2 and iElts.count()<=6) ){ // build from quads iElts.count() should be between [2,6]
1563                 iHexa = _documentModel->addHexaQuads( iElts );
1564         } else if ( vertices_rb->isChecked() and iElts.count()== 8 ){ // build from vertices
1565                 iHexa = _documentModel->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1566                                 iElts[4], iElts[5], iElts[6], iElts[7] );
1567         }
1568
1569         if ( !iHexa.isValid() ){
1570                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) );
1571                 return false;
1572         }
1573         _value  = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1574
1575         QString newName = name_le->text();
1576         if ( !newName.isEmpty() )/*{*/
1577                 _documentModel->setName( iHexa, newName );
1578
1579         // to select/highlight result
1580         result = patternDataModel->mapFromSource(iHexa);
1581
1582         return true;
1583 }
1584
1585
1586 // ------------------------- VECTOR ----------------------------------
1587
1588 // ============================================================== Constructeur
1589
1590 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1591                                                                   HexaBaseDialog(parent, editmode, f),
1592                                                                   _value(0)
1593 {
1594         _helpFileName = "gui_vector.html";
1595         setupUi( this );
1596         _initWidget(editmode);
1597
1598         rb0->setFocusProxy( dx_spb_rb0 );
1599         rb1->setFocusProxy( v0_le_rb1 );
1600         rb0->click();
1601         //   setFocusProxy( rb0 );
1602
1603         if ( editmode == INFO_MODE ){
1604                 setWindowTitle( tr("Vector Information") );
1605                 rb1->hide();
1606         }
1607 }
1608
1609 // ============================================================== Destructeur
1610 VectorDialog::~VectorDialog()
1611 {
1612 }
1613
1614 // ============================================================== _initInputWidget
1615 void VectorDialog::_initInputWidget( Mode editmode )
1616 {
1617         QRegExp rx("");
1618         QValidator *validator = new QRegExpValidator(rx, this);
1619
1620         setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1621         installEventFilter(this);
1622
1623         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1624         name_le->installEventFilter(this);
1625
1626         v0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1627         v0_le_rb1->setValidator( validator );
1628         v0_le_rb1->installEventFilter(this);
1629
1630         v1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1631         v1_le_rb1->setValidator( validator );
1632         v1_le_rb1->installEventFilter(this);
1633
1634         if ( editmode == INFO_MODE ){
1635                 dx_spb_rb0->setReadOnly(true);
1636                 dy_spb_rb0->setReadOnly(true);
1637                 dz_spb_rb0->setReadOnly(true);
1638         }
1639
1640         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1641 }
1642
1643 // ============================================================== clear
1644 void VectorDialog::clear()
1645 {
1646         name_le->clear();
1647         dx_spb_rb0->clear();
1648         dy_spb_rb0->clear();
1649         dz_spb_rb0->clear();
1650         v0_le_rb1->clear();
1651         v1_le_rb1->clear();
1652 }
1653
1654 // ============================================================== setValue
1655 void VectorDialog::setValue(HEXA_NS::Vector* v)
1656 {
1657         name_le->setText( v->getName() );
1658         dx_spb_rb0->setValue( v->getDx() );
1659         dy_spb_rb0->setValue( v->getDy() );
1660         dz_spb_rb0->setValue( v->getDz() );
1661
1662         if ( _patternDataSelectionModel ){
1663                 QModelIndex ivec = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1664                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(ivec) );
1665         }
1666         _value = v;
1667 }
1668
1669 // ============================================================== getValue
1670 HEXA_NS::Vector* VectorDialog::getValue()
1671 {
1672         return _value;
1673 }
1674
1675 // ============================================================== apply
1676 bool VectorDialog::apply(QModelIndex& result)
1677 {
1678         SUIT_OverrideCursor wc;
1679         if ( !_documentModel ) return false;
1680         if ( !_patternDataSelectionModel )  return false;
1681         if ( !_patternBuilderSelectionModel ) return false;
1682         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1683         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
1684         if ( !patternDataModel ) return false;
1685         if ( !patternBuilderModel ) return false;
1686         _currentObj = NULL;
1687
1688         QModelIndex iVector;
1689
1690         if ( rb0->isChecked() ){ //scalar
1691                 double dx = dx_spb_rb0->value();
1692                 double dy = dy_spb_rb0->value();
1693                 double dz = dz_spb_rb0->value();
1694
1695                 iVector = _documentModel->addVector( dx, dy, dz );
1696         } else if ( rb1->isChecked() ){ //vertices
1697                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1698                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1699
1700                 if ( iv0.isValid()
1701                                 && iv1.isValid() ){
1702                         iVector = _documentModel->addVectorVertices( iv0, iv1 );
1703                 }
1704         }
1705
1706         if ( !iVector.isValid() ){
1707                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) );
1708                 return false;
1709         }
1710
1711         _value  = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1712
1713         QString newName = name_le->text();
1714         if ( !newName.isEmpty() )/*{*/
1715                 _documentModel->setName( iVector, newName );
1716
1717         // to select/highlight result
1718         result = patternBuilderModel->mapFromSource(iVector);
1719
1720         return true;
1721 }
1722
1723
1724 // ============================================================== Constructeur
1725 CylinderDialog::CylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1726 : HexaBaseDialog(parent, editmode, f),
1727   _value(0)
1728 {
1729         _helpFileName = "gui_cyl.html";
1730         setupUi( this );
1731         _initWidget(editmode);
1732
1733         if ( editmode == INFO_MODE ){
1734                 setWindowTitle( tr("Cylinder Information") );
1735         }
1736 }
1737
1738 // ============================================================== Destructeur
1739 CylinderDialog::~CylinderDialog()
1740 {
1741 }
1742
1743 // ============================================================== _initInputWidget
1744 void CylinderDialog::_initInputWidget( Mode editmode )
1745 {
1746         QRegExp rx("");
1747         QValidator *validator = new QRegExpValidator(rx, this);
1748
1749         setProperty( "HexaWidgetType",  QVariant::fromValue(CYLINDER_TREE) );
1750         installEventFilter(this);
1751
1752         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(CYLINDER_TREE) );
1753         name_le->installEventFilter(this);
1754
1755         vex_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1756         vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1757
1758         vex_le->setValidator( validator );
1759         vec_le->setValidator( validator );
1760
1761         vex_le->installEventFilter(this);
1762         vec_le->installEventFilter(this);
1763
1764         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1765 }
1766
1767 // ============================================================== clear
1768 void CylinderDialog::clear()
1769 {
1770         name_le->clear();
1771         vex_le->clear();
1772         vec_le->clear();
1773         r_spb->clear();
1774         h_spb->clear();
1775 }
1776
1777 // ============================================================== setValue
1778 void CylinderDialog::setValue(HEXA_NS::Cylinder* c)
1779 {
1780         HEXA_NS::Vertex* base      = c->getBase();
1781         HEXA_NS::Vector* direction = c->getDirection();
1782         double  r = c->getRadius();
1783         double  h = c->getHeight();
1784
1785         name_le->setText( c->getName() );
1786         vex_le->setText( base->getName() );
1787         vec_le->setText( direction->getName() );
1788         r_spb->setValue(r);
1789         h_spb->setValue(h);
1790
1791         if ( _patternDataSelectionModel ){
1792                 QModelIndex iCyl       = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(c) );
1793                 QModelIndex iBase      = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
1794                 QModelIndex iDirection = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
1795
1796                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(iCyl) );
1797                 vex_le->setProperty( "QModelIndex",  QVariant::fromValue(iBase) );
1798                 vec_le->setProperty( "QModelIndex",  QVariant::fromValue(iDirection) );
1799         }
1800         _value = c;
1801 }
1802
1803 // ============================================================== getValue
1804 HEXA_NS::Cylinder* CylinderDialog::getValue()
1805 {
1806         return _value;
1807 }
1808
1809
1810
1811 // ============================================================== apply
1812 bool CylinderDialog::apply(QModelIndex& result)
1813 {
1814         SUIT_OverrideCursor wc;
1815         if ( !_documentModel ) return false;
1816         if ( !_patternDataSelectionModel ) return false;
1817         if ( !_patternBuilderSelectionModel ) return false;
1818         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1819         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
1820         if ( !patternDataModel ) return false;
1821         if ( !patternBuilderModel ) return false;
1822         _currentObj = NULL;
1823
1824         QModelIndex iCyl;
1825         QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
1826         QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
1827         double r = r_spb->value();
1828         double h = h_spb->value();
1829
1830         if ( ivex.isValid()
1831                         && ivec.isValid() ){
1832                 iCyl = _documentModel->addCylinder( ivex, ivec, r,  h );
1833         }
1834
1835         if ( !iCyl.isValid() ){
1836                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD CYLINDER" ) );
1837                 return false;
1838         }
1839
1840         _value  = iCyl.model()->data(iCyl, HEXA_DATA_ROLE).value<HEXA_NS::Cylinder *>();
1841
1842         QString newName = name_le->text();
1843         if (!newName.isEmpty()) /*{*/
1844                 _documentModel->setName( iCyl, newName );
1845
1846         // to select/highlight result
1847         result = patternBuilderModel->mapFromSource(iCyl);
1848
1849         return true;
1850 }
1851
1852
1853 //------------------------------- PipeDialog -----------------------------------
1854
1855 // ============================================================== Constructeur
1856
1857 PipeDialog::PipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1858 : HexaBaseDialog(parent, editmode, f),
1859   _value(0)
1860 {
1861         _helpFileName = "gui_pipe.html";
1862         setupUi( this );
1863         _initWidget(editmode);
1864         //   setFocusProxy( vex_le );
1865
1866         if ( editmode == INFO_MODE ){
1867                 setWindowTitle( tr("Pipe Information") );
1868         }
1869
1870 }
1871
1872 // ============================================================== Destructeur
1873 PipeDialog::~PipeDialog()
1874 {
1875 }
1876
1877 // ============================================================== _initInputWidget
1878 void PipeDialog::_initInputWidget( Mode editmode )
1879 {
1880         QRegExp rx("");
1881         QValidator *validator = new QRegExpValidator(rx, this);
1882
1883
1884         setProperty( "HexaWidgetType",  QVariant::fromValue(PIPE_TREE) );
1885         installEventFilter(this);
1886
1887         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(PIPE_TREE) );
1888         name_le->installEventFilter(this);
1889
1890         //Vertex Field config
1891         vex_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1892         vex_le->installEventFilter(this);
1893         vex_le->setValidator( validator );
1894
1895         //Vector Field config
1896         vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1897         vec_le->installEventFilter(this);
1898         vec_le->setValidator( validator );
1899
1900
1901         if ( editmode == INFO_MODE ){
1902                 ir_spb->setReadOnly(true);
1903                 er_spb->setReadOnly(true);
1904                 h_spb->setReadOnly(true);
1905         }
1906
1907         connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
1908 }
1909
1910
1911 // ============================================================== clear
1912 void PipeDialog::clear()
1913 {
1914         name_le->clear();
1915         vex_le->clear();
1916         vec_le->clear();
1917 }
1918
1919 // ============================================================== setValue
1920 void PipeDialog::setValue(HEXA_NS::Pipe* p)
1921 {
1922         HEXA_NS::Vertex* base      = p->getBase();
1923         HEXA_NS::Vector* direction = p->getDirection();
1924         double  ir = p->getInternalRadius();
1925         double  er = p->getRadius();
1926         double  h  = p->getHeight();
1927
1928         name_le->setText( p->getName() );
1929         vex_le->setText( base->getName() );
1930         vec_le->setText( direction->getName() );
1931         ir_spb->setValue(ir);
1932         er_spb->setValue(er);
1933         h_spb->setValue(h);
1934
1935         if ( _patternDataSelectionModel ){
1936                 QModelIndex iPipe      = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
1937                 QModelIndex iBase      = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
1938                 QModelIndex iDirection = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
1939
1940                 name_le->setProperty( "QModelIndex",  QVariant::fromValue(iPipe) );
1941                 vex_le->setProperty( "QModelIndex",  QVariant::fromValue(iBase) );
1942                 vec_le->setProperty( "QModelIndex",  QVariant::fromValue(iDirection) );
1943         }
1944         _value = p;
1945 }
1946
1947 // ============================================================== getValue
1948 HEXA_NS::Pipe* PipeDialog::getValue()
1949 {
1950         return _value;
1951 }
1952
1953
1954 // ============================================================== apply
1955 bool PipeDialog::apply(QModelIndex& result)
1956 {
1957         SUIT_OverrideCursor wc;
1958         //if ( !_documentModel ) return;
1959         if ( !_patternDataSelectionModel )    return false;
1960         if ( !_patternBuilderSelectionModel ) return false;
1961         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
1962         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
1963         if ( !patternDataModel )    return false;
1964         if ( !patternBuilderModel ) return false;
1965         _currentObj = NULL;
1966
1967         QModelIndex iPipe;
1968         QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
1969         QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
1970         double ir = ir_spb->value();
1971         double er = er_spb->value();
1972         double h  = h_spb->value();
1973
1974         if (ir >= er) {
1975                 SUIT_MessageBox::information( this, tr( "CANNOT ADD PIPE" ), tr( "External radius must be greather than Internal radius!" ) );
1976                 return false;
1977         }
1978
1979
1980         if ( ivex.isValid()
1981                         && ivec.isValid() ){
1982                 iPipe = _documentModel->addPipe( ivex, ivec, ir, er, h );
1983         }
1984
1985         if ( !iPipe.isValid() ){
1986                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD PIPE" ) );
1987                 return false;
1988         }
1989         _value  = iPipe.model()->data(iPipe, HEXA_DATA_ROLE).value<HEXA_NS::Pipe *>();
1990
1991         QString newName = name_le->text();
1992         if ( !newName.isEmpty() )/*{*/
1993                 _documentModel->setName( iPipe, newName );
1994
1995         // to select/highlight result
1996         result = patternBuilderModel->mapFromSource(iPipe);
1997
1998         return true;
1999 }
2000
2001
2002 // ------------------------- MakeGridDialog ----------------------------------
2003 //                  ( Cartesian, Cylindrical, Spherical )
2004
2005 // ============================================================== Constructeur
2006
2007 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2008 : HexaBaseDialog(parent, editmode, f)
2009 {
2010         setupUi( this );
2011         _initWidget(editmode);
2012         rb0->click();// Default : cartesian grid
2013         uniform_rb->click();
2014         rb0->setFocusProxy( vex_le_rb0 );
2015         rb1->setFocusProxy( center_le_rb1 );
2016         rb2->setFocusProxy( vex_le_rb2 );
2017         //   setFocusProxy( rb0 );
2018
2019         _helpFileName = "creategrids.html#guicartgrid";
2020         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2021         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2022         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2023 }
2024
2025
2026 // ============================================================== Destructeur
2027 MakeGridDialog::~MakeGridDialog()
2028 {
2029 }
2030
2031 // ============================================================== _initInputWidget
2032 void MakeGridDialog::_initInputWidget( Mode editmode )
2033 {
2034
2035         QRegExp rx("");
2036         QValidator *validator = new QRegExpValidator(rx, this);
2037
2038         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
2039         installEventFilter(this);
2040
2041         vex_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2042         vec_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2043         vex_le_rb0->setValidator( validator );
2044         vec_le_rb0->setValidator( validator );
2045         vex_le_rb0->installEventFilter(this);
2046         vec_le_rb0->installEventFilter(this);
2047
2048         center_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2049         base_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2050         height_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2051         center_le_rb1->setValidator( validator );
2052         base_le_rb1->setValidator( validator );
2053         height_le_rb1->setValidator( validator );
2054         center_le_rb1->installEventFilter(this);
2055         base_le_rb1->installEventFilter(this);
2056         height_le_rb1->installEventFilter(this);
2057
2058         vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2059         vex_le_rb2->setValidator( validator );
2060         vex_le_rb2->installEventFilter(this);
2061
2062
2063         if ( editmode != INFO_MODE ){
2064                 //Cylindrical
2065                 radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2066                 radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2067
2068                 angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2069                 angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2070
2071                 height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2072                 height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2073
2074                 connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2075                 connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2076                 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2077                 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2078                 connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2079                 connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2080         }
2081
2082 }
2083
2084 // ============================================================== clear
2085 void MakeGridDialog::clear()
2086 {
2087         vex_le_rb0->clear();
2088         vec_le_rb0->clear();
2089         base_le_rb1->clear();
2090         center_le_rb1->clear();
2091         height_le_rb1->clear();
2092         random_param_w->clear();
2093         radius_lw->clear();
2094         angle_lw->clear();
2095         height_lw->clear();
2096         vex_le_rb2->clear();
2097 }
2098
2099 // ============================================================== updateHelpFileName
2100 void MakeGridDialog::updateHelpFileName()
2101 {
2102         if ( sender() == rb0 ){
2103                 _helpFileName = "creategrids.html#guicartgrid";
2104         } else if ( sender() == rb1 ){
2105                 _helpFileName = "creategrids.html#guicylgrid";
2106         } else if ( sender() == rb2 ){
2107                 _helpFileName = "creategrids.html#guisphergrid";
2108         }
2109 }
2110
2111
2112 // ============================================================== updateButtonBox
2113 void MakeGridDialog::updateButtonBox() //CS_TODO?
2114 {
2115         //   int nbQuads  = quads_lw->count();
2116         //   int nbAngles = angles_lw->count();
2117         //
2118         //   if ( nbQuads>0 && nbAngles> 0 ){
2119         //     _applyCloseButton->setEnabled(true);
2120         //     _applyButton->setEnabled(true);
2121         //   } else {
2122         //     _applyCloseButton->setEnabled(false);
2123         //     _applyButton->setEnabled(false);
2124         //   }
2125
2126         //   if ( rb0->isChecked() ){ //cartesian
2127         //   } else if ( rb1->isChecked() ){ //cylindrical
2128         //     nb_radius = radius_lw->item(r);
2129         //     nb_angle  = angle_lw->item(r);
2130         //     nb_height = height_lw->item(r);
2131         //   } else if ( rb2->isChecked() ){ //spherical
2132         //   }
2133 }
2134
2135 // ============================================================== addRadiusItem
2136 void MakeGridDialog::addRadiusItem()
2137 {
2138         QListWidgetItem* previousItem = radius_lw->currentItem();
2139         QListWidgetItem* newItem      = new QListWidgetItem();
2140
2141         double defaultValue = 0.;
2142         if ( previousItem )
2143                 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2144
2145         newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2146         newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2147         radius_lw->addItem(newItem);
2148
2149         updateButtonBox();
2150 }
2151
2152 // ============================================================== delRadiusItem
2153 void MakeGridDialog::delRadiusItem()
2154 {
2155         delete radius_lw->currentItem();
2156         updateButtonBox();
2157 }
2158
2159 // ============================================================== addAngleItem
2160 void MakeGridDialog::addAngleItem()
2161 {
2162         QListWidgetItem* previousItem = angle_lw->currentItem();
2163         QListWidgetItem* newItem      = new QListWidgetItem();
2164
2165         double defaultValue = 0.;
2166         if ( previousItem )
2167                 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2168
2169         newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2170         newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2171         angle_lw->addItem(newItem);
2172
2173         updateButtonBox();
2174 }
2175
2176 // ============================================================== delAngleItem
2177 void MakeGridDialog::delAngleItem()
2178 {
2179         //std::cout << "delAngleItem()" << std::endl;
2180         delete angle_lw->currentItem();
2181         updateButtonBox();
2182 }
2183
2184 // ============================================================== addHeightItem
2185 void MakeGridDialog::addHeightItem()
2186 {
2187         QListWidgetItem* previousItem = height_lw->currentItem();
2188         QListWidgetItem* newItem      = new QListWidgetItem();
2189
2190         double defaultValue = 0.;
2191         if ( previousItem )
2192                 defaultValue = previousItem->data(Qt::EditRole).toDouble();
2193
2194         newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2195         newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2196         height_lw->addItem(newItem);
2197
2198         updateButtonBox();
2199 }
2200
2201 // ============================================================== delHeightItem
2202 void MakeGridDialog::delHeightItem()
2203 {
2204         //std::cout << "delHeightItem()" << std::endl;
2205         delete height_lw->currentItem();
2206         updateButtonBox();
2207 }
2208
2209 // ============================================================== apply
2210 bool MakeGridDialog::apply(QModelIndex& result)
2211 {
2212         SUIT_OverrideCursor wc;
2213         //if ( !_documentModel ) return;
2214         if ( !_patternDataSelectionModel )    return false;
2215         if ( !_patternBuilderSelectionModel ) return false;
2216         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
2217         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2218         if ( !patternDataModel )    return false;
2219         if ( !patternBuilderModel ) return false;
2220         _currentObj = NULL;
2221
2222         QModelIndex iNewElts;
2223         if ( rb0->isChecked() ){ //cartesian
2224                 QModelIndex ivex_rb0 = patternDataModel->mapToSource( _index[vex_le_rb0] );
2225                 QModelIndex ivec_rb0 = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
2226                 long nx = nx_spb_rb0->value();
2227                 long ny = ny_spb_rb0->value();
2228                 long nz = nz_spb_rb0->value();
2229
2230                 if ( ivex_rb0.isValid()
2231                                 && ivec_rb0.isValid() ){
2232                         iNewElts = _documentModel->makeCartesian( ivex_rb0, ivec_rb0, nx, ny, nz );
2233                 }
2234
2235         } else if ( rb1->isChecked() ){ //cylindrical
2236                 QModelIndex icenter_rb1 = patternDataModel->mapToSource( _index[center_le_rb1] );
2237                 QModelIndex ibase_rb1   = patternBuilderModel->mapToSource( _index[base_le_rb1] );
2238                 QModelIndex iheight_rb1 = patternBuilderModel->mapToSource( _index[height_le_rb1] );
2239
2240                 if ( icenter_rb1.isValid()
2241                                 && ibase_rb1.isValid()
2242                                 && iheight_rb1.isValid() ){
2243
2244                         bool fill = fill_cb_rb1->isChecked();
2245                         if ( uniform_rb->isChecked() ){
2246                                 double dr = dr_spb_rb1->value();
2247                                 double da = da_spb_rb1->value();
2248                                 double dl = dl_spb_rb1->value();
2249                                 double nr = nr_spb_rb1->value();
2250                                 double na = na_spb_rb1->value();
2251                                 double nl = nl_spb_rb1->value();
2252
2253                                 iNewElts = _documentModel->makeCylindrical( icenter_rb1,
2254                                                 ibase_rb1, iheight_rb1,
2255                                                 dr, da, dl, nr, na, nl, fill );
2256                         }
2257                         if ( random_rb->isChecked() ){
2258                                 QListWidgetItem* item = NULL;
2259                                 QDoubleSpinBox*   spb = NULL;
2260
2261                                 QList<double> radius;
2262                                 QList<double> angles;
2263                                 QList<double> heights;
2264
2265                                 for ( int r = 0; r < radius_lw->count(); ++r){
2266                                         item = radius_lw->item(r);
2267                                         //std::cout << "radius : " << item->data(Qt::EditRole).toDouble()<< std::endl;
2268                                         radius << item->data(Qt::EditRole).toDouble();
2269                                 }
2270
2271                                 for ( int r = 0; r < angle_lw->count(); ++r){
2272                                         item = angle_lw->item(r);
2273                                         angles << item->data(Qt::EditRole).toDouble();
2274                                 }
2275
2276                                 for ( int r = 0; r < height_lw->count(); ++r){
2277                                         item = height_lw->item(r);
2278                                         heights << item->data(Qt::EditRole).toDouble();
2279                                 }
2280
2281                                 iNewElts =  _documentModel->makeCylindricals(
2282                                                 icenter_rb1, ibase_rb1, iheight_rb1,
2283                                                 radius, angles, heights,
2284                                                 fill ); //NEW HEXA3
2285
2286                         }
2287                 }
2288
2289         } else if ( rb2->isChecked() ){ //spherical
2290                 QModelIndex ivex_rb2  = patternDataModel->mapToSource( _index[vex_le_rb2] );
2291                 //     QModelIndex ivecx_rb2 = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
2292                 double radius = radius_spb_rb2->value();
2293                 int    nb     = nb_spb_rb2->value();
2294                 int    k      = k_spb_rb2->value();
2295
2296                 if ( ivex_rb2.isValid() ){
2297                         iNewElts = _documentModel->makeSpherical( ivex_rb2, radius, nb, k );
2298                 }
2299         }
2300
2301         if ( !iNewElts.isValid() ){
2302                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) );
2303                 return false;
2304         }
2305
2306
2307         // to select/highlight result
2308         result = patternBuilderModel->mapFromSource( iNewElts );
2309
2310         return true;
2311 }
2312
2313
2314
2315 // ============================================================== Constructeur
2316
2317 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2318 : HexaBaseDialog(parent, editmode, f)
2319 {
2320         _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinder";
2321         setupUi( this );
2322         _initWidget(editmode);
2323         //   setFocusProxy( cyl_le );
2324 }
2325
2326 // ============================================================== Destructeur
2327 MakeCylinderDialog::~MakeCylinderDialog()
2328 {
2329 }
2330
2331 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2332 {
2333         QRegExp rx("");
2334         QValidator *validator = new QRegExpValidator(rx, this);
2335
2336         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
2337         installEventFilter(this);
2338
2339         cyl_le->setProperty( "HexaWidgetType",  QVariant::fromValue(CYLINDER_TREE) );
2340         vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2341         cyl_le->setValidator( validator );
2342         vec_le->setValidator( validator );
2343         cyl_le->installEventFilter(this);
2344         vec_le->installEventFilter(this);
2345 }
2346
2347 // ============================================================== clear
2348 void MakeCylinderDialog::clear()
2349 {
2350         cyl_le->clear();
2351         vec_le->clear();
2352 }
2353
2354
2355 // ============================================================== apply
2356 bool MakeCylinderDialog::apply(QModelIndex& result)
2357 {
2358         SUIT_OverrideCursor wc;
2359         //if ( !_documentModel ) return;
2360         if ( !_patternBuilderSelectionModel ) return false;
2361         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2362         if ( !patternBuilderModel ) return false;
2363         _currentObj = NULL;
2364
2365         QModelIndex iElts;
2366         QModelIndex icyl = patternBuilderModel->mapToSource( _index[cyl_le] );
2367         QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
2368         double nr = nr_spb->value();
2369         double na = na_spb->value();
2370         double nl = nl_spb->value();
2371
2372         if ( icyl.isValid()
2373                         && ivec.isValid() ){
2374                 iElts = _documentModel->makeCylinder( icyl, ivec, nr, na, nl );
2375         }
2376
2377         if ( !iElts.isValid() ){
2378                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) );
2379                 return false;
2380         }
2381
2382         // to select/highlight result
2383         result = patternBuilderModel->mapFromSource(iElts);
2384
2385         return true;
2386 }
2387
2388
2389 //---------------------------------- MakePipeDialog -----------------------------
2390
2391 // ============================================================== Constructeur
2392
2393 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2394 : HexaBaseDialog(parent, editmode, f)
2395 {
2396         _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipe";
2397         setupUi( this );
2398         _initWidget(editmode);
2399         //   setFocusProxy( pipe_le );
2400 }
2401
2402 // ============================================================== Destructeur
2403 MakePipeDialog::~MakePipeDialog()
2404 {
2405 }
2406
2407 // ============================================================== _initInputWidget
2408 void MakePipeDialog::_initInputWidget( Mode editmode )
2409 {
2410         QRegExp rx("");
2411         QValidator *validator = new QRegExpValidator(rx, this);
2412
2413         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
2414         installEventFilter(this);
2415
2416         pipe_le->setProperty( "HexaWidgetType", QVariant::fromValue(PIPE_TREE) );
2417         vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2418
2419         pipe_le->setValidator( validator );
2420         vec_le->setValidator( validator );
2421
2422         pipe_le->installEventFilter(this);
2423         vec_le->installEventFilter(this);
2424
2425 }
2426
2427 // ============================================================== clear
2428 void MakePipeDialog::clear()
2429 {
2430         pipe_le->clear();
2431         vec_le->clear();
2432 }
2433
2434
2435 // ============================================================== apply
2436 bool MakePipeDialog::apply(QModelIndex& result)
2437 {
2438         SUIT_OverrideCursor wc;
2439         //if ( !_documentModel ) return;
2440         if ( !_patternBuilderSelectionModel ) return false;
2441         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2442         if ( !patternBuilderModel ) return false;
2443         _currentObj = NULL;
2444
2445         QModelIndex iElts;
2446         QModelIndex ipipe = patternBuilderModel->mapToSource( _index[pipe_le] );
2447         QModelIndex ivec  = patternBuilderModel->mapToSource( _index[vec_le] );
2448         double nr = nr_spb->value();
2449         double na = na_spb->value();
2450         double nl = nl_spb->value();
2451
2452         if ( ipipe.isValid()
2453                         && ivec.isValid() ){
2454                 iElts = _documentModel->makePipe( ipipe, ivec, nr, na, nl );
2455         }
2456         if ( !iElts.isValid() ){
2457                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) );
2458                 return false;
2459         }
2460
2461         // to select/highlight result
2462         result = patternBuilderModel->mapFromSource(iElts);
2463
2464         return true;
2465 }
2466
2467 //---------------------------------- MakeCylindersDialog -----------------------------
2468
2469 // ============================================================== Constructeur
2470
2471 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2472 : HexaBaseDialog(parent, editmode, f)
2473 {
2474         _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinders";
2475         setupUi( this );
2476         _initWidget(editmode);
2477         //   setFocusProxy( cyl1_le );
2478 }
2479
2480 // ============================================================== Destructeur
2481 MakeCylindersDialog::~MakeCylindersDialog()
2482 {
2483 }
2484
2485 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2486 {
2487         QRegExp rx("");
2488         QValidator *validator = new QRegExpValidator(rx, this);
2489
2490         setProperty( "HexaWidgetType",  QVariant::fromValue(CROSSELEMENTS_TREE) );
2491         installEventFilter(this);
2492
2493         cyl1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(CYLINDER_TREE) );
2494         cyl2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(CYLINDER_TREE) );
2495
2496         cyl1_le->setValidator( validator );
2497         cyl2_le->setValidator( validator );
2498
2499         cyl1_le->installEventFilter(this);
2500         cyl2_le->installEventFilter(this);
2501 }
2502
2503 // ============================================================== clear
2504 void MakeCylindersDialog::clear()
2505 {
2506         cyl1_le->clear();
2507         cyl2_le->clear();
2508 }
2509
2510
2511 // ============================================================== apply
2512 bool MakeCylindersDialog::apply(QModelIndex& result)
2513 {
2514         SUIT_OverrideCursor wc;
2515         //if ( !_documentModel ) return;
2516         if ( !_patternBuilderSelectionModel ) return false;
2517         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2518         if ( !patternBuilderModel ) return false;
2519         _currentObj = NULL;
2520
2521         QModelIndex iCrossElts;
2522         QModelIndex icyl1 = patternBuilderModel->mapToSource( _index[cyl1_le] );
2523         QModelIndex icyl2 = patternBuilderModel->mapToSource( _index[cyl2_le] );
2524
2525         if ( icyl1.isValid()
2526                         && icyl2.isValid() ){
2527                 iCrossElts = _documentModel->makeCylinders( icyl1, icyl2 );
2528         }
2529
2530         if ( !iCrossElts.isValid() ){
2531                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) );
2532                 return false;
2533         }
2534
2535         // to select/highlight result
2536         result = patternBuilderModel->mapFromSource(iCrossElts);
2537
2538         return true;
2539 }
2540
2541
2542
2543 //---------------------------------- MakePipesDialog -----------------------------
2544
2545 // ============================================================== Constructeur
2546
2547 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2548 : HexaBaseDialog(parent, editmode, f)
2549 {
2550         _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipes";
2551         setupUi( this );
2552         _initWidget(editmode);
2553         //   setFocusProxy( pipe1_le );
2554 }
2555
2556 // ============================================================== Destructeur
2557 MakePipesDialog::~MakePipesDialog()
2558 {
2559 }
2560
2561 // ============================================================== _initInputWidget
2562 void MakePipesDialog::_initInputWidget( Mode editmode )
2563 {
2564         QRegExp rx("");
2565         QValidator *validator = new QRegExpValidator(rx, this);
2566
2567         pipe1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(PIPE_TREE) );
2568         pipe2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(PIPE_TREE) );
2569
2570         pipe1_le->setValidator( validator );
2571         pipe2_le->setValidator( validator );
2572
2573         pipe1_le->installEventFilter(this);
2574         pipe2_le->installEventFilter(this);
2575 }
2576
2577
2578 // ============================================================== clear
2579 void MakePipesDialog::clear()
2580 {
2581         pipe1_le->clear();
2582         pipe2_le->clear();
2583 }
2584
2585
2586 // ============================================================== apply
2587 bool MakePipesDialog::apply(QModelIndex& result)
2588 {
2589         SUIT_OverrideCursor wc;
2590         //if ( !_documentModel ) return;
2591         if ( !_patternBuilderSelectionModel ) return false;
2592         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2593         if ( !patternBuilderModel ) return false;
2594         _currentObj = NULL;
2595
2596         QModelIndex iCrossElts;
2597         QModelIndex ipipe1 = patternBuilderModel->mapToSource( _index[pipe1_le] );
2598         QModelIndex ipipe2 = patternBuilderModel->mapToSource( _index[pipe2_le] );
2599
2600         if ( ipipe1.isValid()
2601                         && ipipe2.isValid() ){
2602                 iCrossElts = _documentModel->makePipes( ipipe1, ipipe2 );
2603         }
2604         if ( !iCrossElts.isValid() ){
2605                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) );
2606                 return false;
2607         }
2608         result = patternBuilderModel->mapFromSource(iCrossElts);
2609
2610         return true;
2611 }
2612
2613
2614 //---------------------------------- RemoveHexaDialog -----------------------------
2615
2616 // ============================================================== Constructeur
2617
2618 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2619 : HexaBaseDialog(parent, editmode, f)
2620 {
2621         _helpFileName = "gui_remove.html";
2622         setupUi( this );
2623         _initWidget(editmode);
2624         //   setFocusProxy( hexa_le );
2625 }
2626
2627
2628 // ============================================================== Destructeur
2629 RemoveHexaDialog::~RemoveHexaDialog()
2630 {
2631 }
2632
2633 // ============================================================== _initInputWidget
2634 void RemoveHexaDialog::_initInputWidget( Mode editmode )
2635 {
2636         QRegExp rx("");
2637         QValidator *validator = new QRegExpValidator(rx, this);
2638
2639         hexa_le->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
2640         hexa_le->setValidator( validator );
2641         hexa_le->installEventFilter(this);
2642 }
2643
2644 // ============================================================== clear
2645 void RemoveHexaDialog::clear()
2646 {
2647         hexa_le->clear();
2648 }
2649
2650
2651 // ============================================================== apply
2652 bool RemoveHexaDialog::apply(QModelIndex& result)
2653 {
2654         SUIT_OverrideCursor wc;
2655         //if ( !_documentModel ) return;
2656         if ( !_patternDataSelectionModel ) return false;
2657         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
2658         if ( !patternDataModel ) return false;
2659         _currentObj = NULL;
2660
2661         QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
2662
2663         bool removed = false;
2664         if ( ihexa.isValid() ){
2665                 if ( connected_cb->isChecked() ){
2666                         removed = _documentModel->removeConnectedHexa( ihexa );
2667                 } else {
2668                         removed = _documentModel->removeHexa( ihexa );
2669                 }
2670         }
2671
2672         if ( removed == false ){
2673                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) );
2674                 return false;
2675         }
2676         return true;
2677 }
2678
2679
2680 //---------------------------------- PrismQuadDialog -----------------------------
2681
2682 // ============================================================== Constructeur
2683
2684 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2685 : HexaBaseDialog(parent, editmode, f)
2686 {
2687         _helpFileName = "gui_prism_join_quad.html#prism-quadrangles";
2688         setupUi( this );
2689         _initWidget(editmode);
2690         setFocusProxy( quads_lw );
2691 }
2692
2693
2694 // ============================================================== Destructeur
2695 PrismQuadDialog::~PrismQuadDialog()
2696 {
2697 }
2698
2699
2700 // ============================================================== _initInputWidget
2701 void PrismQuadDialog::_initInputWidget( Mode editmode )
2702 {
2703         QRegExp rx("");
2704         QValidator *validator = new QRegExpValidator(rx, this);
2705
2706         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
2707         installEventFilter(this);
2708
2709         vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2710         quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
2711
2712         vec_le->setValidator( validator );
2713
2714         vec_le->installEventFilter(this);
2715         quads_lw->installEventFilter(this);
2716
2717         if ( editmode != INFO_MODE ){
2718                 QShortcut* delQuadShortcut   = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2719                 delQuadShortcut->setContext( Qt::WidgetShortcut );
2720                 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
2721         }
2722
2723         connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
2724 }
2725
2726 // ============================================================== clear
2727 void PrismQuadDialog::clear()
2728 {
2729         vec_le->clear();
2730         quads_lw->clear();
2731 }
2732
2733 // ============================================================== removeQuad
2734 void PrismQuadDialog::removeQuad()
2735 {
2736         QListWidgetItem *item = quads_lw->currentItem();
2737
2738         if (item) {
2739                 int r = quads_lw->row(item);
2740                 quads_lw->takeItem(r);
2741                 delete item;
2742         }
2743
2744 }
2745
2746 // void PrismQuadDialog::clearQuads()
2747 // {
2748 //   if (quads_lw->count() != 0)
2749 //     quads_lw->clear();
2750 // }
2751
2752
2753 // ============================================================== apply
2754 bool PrismQuadDialog::apply(QModelIndex& result)
2755 {
2756         SUIT_OverrideCursor wc;
2757         //if ( !_documentModel ) return;
2758         if ( !_patternDataSelectionModel )    return false;
2759         if ( !_patternBuilderSelectionModel ) return false;
2760         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
2761         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2762         if ( !patternDataModel )    return false;
2763         if ( !patternBuilderModel ) return false;
2764         _currentObj = NULL;
2765
2766         /////
2767         QModelIndexList iquads;
2768         QModelIndex     iquad;
2769         QListWidgetItem* item = NULL;
2770         for ( int r = 0; r < quads_lw->count(); ++r){
2771                 item = quads_lw->item(r);
2772                 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2773                 iquads << iquad;
2774         }
2775         QModelIndex ivec  = patternBuilderModel->mapToSource( _index[vec_le] );
2776
2777         QModelIndex iElts;
2778         if ( ivec.isValid() ){
2779                 int nb = nb_spb->value();
2780                 if ( iquads.count() == 1 ){
2781                         iElts = _documentModel->prismQuad( iquads[0], ivec, nb );
2782                 } else if ( iquads.count() > 1 ){
2783                         iElts = _documentModel->prismQuads( iquads, ivec, nb );
2784                 }
2785         }
2786
2787         if ( !iElts.isValid() ){
2788                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) );
2789                 return false;
2790         }
2791
2792         result = patternBuilderModel->mapFromSource(iElts);
2793
2794         return true;
2795 }
2796
2797 //---------------------------------- JoinQuadDialog -----------------------------
2798
2799 // ============================================================== Constructeur
2800
2801 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2802 : HexaBaseDialog(parent, editmode, f)
2803 {
2804         _helpFileName = "gui_prism_join_quad.html#join-quadrangles";
2805         setupUi( this );
2806         _initWidget(editmode);
2807         //   setFocusProxy( quads_lw );
2808 }
2809
2810
2811 // ============================================================== Destructeur
2812 JoinQuadDialog::~JoinQuadDialog()
2813 {
2814 }
2815
2816 // ============================================================== _initInputWidget
2817 void JoinQuadDialog::_initInputWidget( Mode editmode )
2818 {
2819         QRegExp rx("");
2820         QValidator *validator = new QRegExpValidator(rx, this);
2821
2822         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
2823         installEventFilter(this);
2824
2825         vex0_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2826         vex1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2827         vex2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2828         vex3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2829         quad_dest_le->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
2830         quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
2831
2832         vex0_le->setValidator( validator );
2833         vex1_le->setValidator( validator );
2834         vex2_le->setValidator( validator );
2835         vex3_le->setValidator( validator );
2836         quad_dest_le->setValidator( validator );
2837
2838         vex0_le->installEventFilter(this);
2839         vex1_le->installEventFilter(this);
2840         vex2_le->installEventFilter(this);
2841         vex3_le->installEventFilter(this);
2842         quad_dest_le->installEventFilter(this);
2843         quads_lw->installEventFilter(this);
2844
2845         if ( editmode != INFO_MODE ){
2846                 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2847                 delQuadShortcut->setContext( Qt::WidgetShortcut );
2848                 connect( delQuadShortcut,   SIGNAL(activated()), this, SLOT(removeQuad()) );
2849         }
2850         connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
2851 }
2852
2853
2854 // ============================================================== clear
2855 void JoinQuadDialog::clear()
2856 {
2857         quads_lw->clear();
2858         vex0_le->clear();
2859         vex2_le->clear();
2860
2861
2862         quad_dest_le->clear();
2863         vex1_le->clear();
2864         vex3_le->clear();
2865 }
2866
2867
2868 // ============================================================== removeQuad
2869 void JoinQuadDialog::removeQuad()
2870 {
2871         QListWidgetItem *item = quads_lw->currentItem();
2872
2873         if (item) {
2874                 int r = quads_lw->row(item);
2875                 quads_lw->takeItem(r);
2876                 delete item;
2877         }
2878
2879 }
2880
2881 // void JoinQuadDialog::clearQuads()
2882 // {
2883 //   if (quads_lw->count() != 0)
2884 //     quads_lw->clear();
2885 // }
2886
2887
2888 // ============================================================== apply
2889 bool JoinQuadDialog::apply(QModelIndex& result)
2890 {
2891         SUIT_OverrideCursor wc;
2892         //if ( !_documentModel ) return;
2893         if ( !_patternDataSelectionModel )    return false;
2894         if ( !_patternBuilderSelectionModel ) return false;
2895         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
2896         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
2897         if ( !patternDataModel )    return false;
2898         if ( !patternBuilderModel ) return false;
2899         _currentObj = NULL;
2900
2901         /////
2902         QModelIndexList iquads;
2903         QModelIndex     iquad;
2904         QListWidgetItem* item = NULL;
2905         for ( int r = 0; r < quads_lw->count(); ++r){
2906                 item = quads_lw->item(r);
2907                 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2908                 if ( iquad.isValid() ) iquads << iquad;
2909         }
2910         QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
2911         QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
2912         QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
2913         QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
2914         QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
2915
2916         QModelIndex iElts;
2917         if ( iquaddest.isValid()
2918                         && ivex0.isValid()
2919                         && ivex1.isValid()
2920                         && ivex2.isValid()
2921                         && ivex3.isValid() ){
2922                 int nb = nb_spb->value();
2923                 if ( iquads.count() == 1 ){
2924                         iElts = _documentModel->joinQuad( iquads[0], iquaddest,
2925                                         ivex0, ivex1, ivex2, ivex3,
2926                                         nb );
2927                 } else if ( iquads.count() > 1 ){
2928                         iElts = _documentModel->joinQuads( iquads, iquaddest,
2929                                         ivex0, ivex1, ivex2, ivex3,
2930                                         nb );
2931                 }
2932         }
2933
2934         if ( !iElts.isValid() ){
2935                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) );
2936                 return false;
2937         }
2938
2939         result = patternBuilderModel->mapFromSource(iElts);
2940
2941         return true;
2942 }
2943
2944
2945 // void JoinQuadDialog::reject()
2946 // {
2947 //   QDialog::reject();
2948 //   _disallowSelection();
2949 // }
2950
2951
2952
2953 // ------------------------- MergeDialog ----------------------------------
2954
2955 // ============================================================== Constructeur
2956
2957 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2958 : HexaBaseDialog(parent, editmode, f)
2959 {
2960         setupUi( this );
2961         _initWidget(editmode);
2962         rb0->setFocusProxy( v0_le_rb0 );
2963         rb1->setFocusProxy( e0_le_rb1 );
2964         rb2->setFocusProxy( q0_le_rb2 );
2965         //   setFocusProxy( rb0 );
2966         rb0->click();
2967
2968         _helpFileName = "gui_merge_elmts.html#merge-2-vertices";
2969         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2970         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2971         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
2972 }
2973
2974 // ============================================================== Destructeur
2975 MergeDialog::~MergeDialog()
2976 {
2977 }
2978
2979 // ============================================================== _initInputWidget
2980 void MergeDialog::_initInputWidget( Mode editmode )
2981 {
2982         QRegExp rx("");
2983         QValidator *validator = new QRegExpValidator(rx, this);
2984
2985
2986         v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2987         v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2988         v0_le_rb0->setValidator( validator );
2989         v1_le_rb0->setValidator( validator );
2990         v0_le_rb0->installEventFilter(this);
2991         v1_le_rb0->installEventFilter(this);
2992
2993         v0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2994         v1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2995         e0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
2996         e1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
2997
2998         v0_le_rb1->setValidator( validator );
2999         v1_le_rb1->setValidator( validator );
3000         e0_le_rb1->setValidator( validator );
3001         e1_le_rb1->setValidator( validator );
3002
3003         v0_le_rb1->installEventFilter(this);
3004         v1_le_rb1->installEventFilter(this);
3005         e0_le_rb1->installEventFilter(this);
3006         e1_le_rb1->installEventFilter(this);
3007
3008
3009         v0_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3010         v1_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3011         v2_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3012         v3_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3013         q0_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3014         q1_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3015
3016
3017         v0_le_rb2->setValidator( validator );
3018         v1_le_rb2->setValidator( validator );
3019         v2_le_rb2->setValidator( validator );
3020         v3_le_rb2->setValidator( validator );
3021         q0_le_rb2->setValidator( validator );
3022         q1_le_rb2->setValidator( validator );
3023
3024         v0_le_rb2->installEventFilter(this);
3025         v1_le_rb2->installEventFilter(this);
3026         v2_le_rb2->installEventFilter(this);
3027         v3_le_rb2->installEventFilter(this);
3028         q0_le_rb2->installEventFilter(this);
3029         q1_le_rb2->installEventFilter(this);
3030 }
3031
3032
3033 // ============================================================== clear
3034 void MergeDialog::clear()
3035 {
3036         v0_le_rb0->clear();
3037         v1_le_rb0->clear();
3038         v0_le_rb1->clear();
3039         v1_le_rb1->clear();
3040         v0_le_rb2->clear();
3041         v1_le_rb2->clear();
3042         v2_le_rb2->clear();
3043         v3_le_rb2->clear();
3044         e0_le_rb1->clear();
3045         e1_le_rb1->clear();
3046         q0_le_rb2->clear();
3047         q1_le_rb2->clear();
3048 }
3049
3050 // ============================================================== updateHelpFileName
3051 void MergeDialog::updateHelpFileName()
3052 {
3053         if ( sender() == rb0 ){
3054                 _helpFileName = "gui_merge_elmts.html#merge-2-vertices";
3055         } else if ( sender() == rb1 ){
3056                 _helpFileName = "gui_merge_elmts.html#merge-2-edges";
3057         } else if ( sender() == rb2 ){
3058                 _helpFileName = "gui_merge_elmts.html#merge-2-quadrangles";
3059         }
3060 }
3061
3062
3063 // ============================================================== apply
3064 bool MergeDialog::apply(QModelIndex& result)
3065 {
3066         SUIT_OverrideCursor wc;
3067         if ( !_patternDataSelectionModel ) return false;
3068         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3069         if ( !patternDataModel ) return false;
3070         _currentObj = NULL;
3071
3072         bool merged = false;
3073
3074         if ( rb0->isChecked() ){
3075                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3076                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3077
3078                 if ( iv0.isValid()
3079                                 && iv1.isValid() ){
3080                         merged = _documentModel->mergeVertices( iv0, iv1 );
3081                 }
3082         } else if ( rb1->isChecked() ){
3083                 QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3084                 QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3085                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3086                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3087
3088                 if ( ie0.isValid()
3089                                 && ie1.isValid()
3090                                 && iv0.isValid()
3091                                 && iv1.isValid() ){
3092                         merged =  _documentModel->mergeEdges( ie0, ie1, iv0, iv1);
3093                 }
3094         } else if ( rb2->isChecked() ){
3095
3096                 QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3097                 QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3098                 QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3099                 QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3100                 QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3101                 QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3102
3103                 if ( iq0.isValid()
3104                                 && iq1.isValid()
3105                                 && iv0.isValid()
3106                                 && iv1.isValid()
3107                                 && iv2.isValid()
3108                                 && iv3.isValid() ){
3109                         merged =  _documentModel->mergeQuads( iq0, iq1,
3110                                         iv0, iv1, iv2, iv3 );
3111                 }
3112         }
3113
3114         if ( merged == false ){
3115                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) );
3116                 return false;
3117         }
3118
3119         return true;
3120 }
3121
3122
3123 // ------------------------- DisconnectDialog ----------------------------------
3124
3125 // ============================================================== Constructeur
3126
3127 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3128 : HexaBaseDialog(parent, editmode, f)
3129 {
3130         setupUi( this );
3131         _initWidget(editmode);
3132         rb0->setFocusProxy( v_le_rb0 );
3133         rb1->setFocusProxy( e_le_rb1 );
3134         rb2->setFocusProxy( q_le_rb2 );
3135         rb3->setFocusProxy( d_edges_lw);
3136         rb0->click();
3137         //   setFocusProxy( rb0 );
3138
3139         _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3140
3141         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3142         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3143         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3144         connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3145 }
3146
3147 // ============================================================== Destructeur
3148 DisconnectDialog::~DisconnectDialog()
3149 {
3150 }
3151
3152 // ============================================================== _initInputWidget
3153 void DisconnectDialog::_initInputWidget( Mode editmode )
3154 {
3155         QRegExp rx("");
3156         QValidator *validator = new QRegExpValidator(rx, this);
3157
3158         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3159         installEventFilter(this);
3160
3161         //vertex
3162         v_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3163         h_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3164         v_le_rb0->setValidator( validator );
3165         h_le_rb0->setValidator( validator );
3166         v_le_rb0->installEventFilter(this);
3167         h_le_rb0->installEventFilter(this);
3168
3169         //edge
3170         e_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3171         h_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3172         e_le_rb1->setValidator( validator );
3173         h_le_rb1->setValidator( validator );
3174         e_le_rb1->installEventFilter(this);
3175         h_le_rb1->installEventFilter(this);
3176
3177         //quad
3178         q_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3179         h_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3180         q_le_rb2->setValidator( validator );
3181         h_le_rb2->setValidator( validator );
3182         q_le_rb2->installEventFilter(this);
3183         h_le_rb2->installEventFilter(this);
3184
3185         //edges
3186         d_edges_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3187         hexas_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3188         d_edges_lw->installEventFilter(this);
3189         hexas_lw->installEventFilter(this);
3190
3191         QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3192         QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3193         delEdgeShortcut->setContext( Qt::WidgetShortcut );
3194         delHexaShortcut->setContext( Qt::WidgetShortcut );
3195
3196         connect( d_edges_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
3197         connect( hexas_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
3198         connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3199         connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3200
3201 }
3202
3203
3204 // ============================================================== clear
3205 void DisconnectDialog::clear()
3206 {
3207         v_le_rb0->clear();
3208         e_le_rb1->clear();
3209         q_le_rb2->clear();
3210         h_le_rb0->clear();
3211         h_le_rb1->clear();
3212         h_le_rb2->clear();
3213         d_edges_lw->clear();
3214         hexas_lw->clear();
3215 }
3216
3217 // ============================================================== deleteEdgeItem
3218 void DisconnectDialog::deleteEdgeItem()
3219 {
3220         delete d_edges_lw->currentItem();
3221 }
3222
3223 // ============================================================== deleteHexaItem
3224 void DisconnectDialog::deleteHexaItem()
3225 {
3226         delete hexas_lw->currentItem();
3227 }
3228
3229
3230 // ============================================================== updateHelpFileName
3231 void DisconnectDialog::updateHelpFileName()
3232 {
3233         if ( sender() == rb0 ){
3234                 _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3235         } else if ( sender() == rb1 ){
3236                 _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3237         } else if ( sender() == rb2 ){
3238                 _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3239         } else if (sender() == rb3 ){
3240                 _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3241         }
3242 }
3243
3244
3245 // ============================================================== apply
3246 bool DisconnectDialog::apply(QModelIndex& result)
3247 {
3248         SUIT_OverrideCursor wc;
3249
3250         if ( !_patternDataSelectionModel )    return false;
3251         if ( !_patternBuilderSelectionModel ) return false;
3252         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3253         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3254         if ( !patternDataModel )    return false;
3255         if ( !patternBuilderModel ) return false;
3256         _currentObj = NULL;
3257
3258         QModelIndex iElts;
3259
3260         if ( rb0->isChecked() ){
3261                 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3262                 QModelIndex ivex  = patternDataModel->mapToSource( _index[v_le_rb0] );
3263
3264                 if ( ihexa.isValid()
3265                                 && ivex.isValid() ){
3266                         iElts = _documentModel->disconnectVertex( ihexa, ivex );
3267                 }
3268         } else if ( rb1->isChecked() ){
3269                 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3270                 QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3271
3272                 if ( ihexa.isValid()
3273                                 && iedge.isValid() ){
3274                         iElts = _documentModel->disconnectEdge( ihexa, iedge );
3275                 }
3276         } else if ( rb2->isChecked() ){
3277                 QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3278                 QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3279
3280                 if ( ihexa.isValid()
3281                                 && iquad.isValid() ){
3282                         iElts = _documentModel->disconnectQuad( ihexa, iquad );
3283                 }
3284         } else if ( rb3->isChecked() ){ //
3285
3286                 QModelIndex iedge, ihexa;
3287                 QModelIndexList iedges, ihexas;
3288                 QListWidgetItem* item = NULL;
3289
3290                 //Liste des edges
3291                 for (int r = 0; r < d_edges_lw->count(); ++r){
3292                         item = d_edges_lw->item(r);
3293                         iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3294                         if ( iedge.isValid() )
3295                                 iedges << iedge;
3296                 }
3297
3298                 //Liste des hexas
3299                 for (int r = 0; r < hexas_lw->count(); ++r){
3300                         item = hexas_lw->item(r);
3301                         ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3302                         if ( ihexa.isValid() )
3303                                 ihexas << ihexa;
3304                 }
3305
3306                 iElts = _documentModel->disconnectEdges( ihexas, iedges );
3307         }
3308
3309         if ( !iElts.isValid() ){
3310                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) );
3311                 return false;
3312         }
3313
3314         result = patternBuilderModel->mapFromSource(iElts);
3315
3316         return true;
3317 }
3318
3319
3320
3321
3322 // ------------------------- CutEdgeDialog ----------------------------------
3323
3324 // ============================================================== Constructeur
3325
3326 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3327                                                                 HexaBaseDialog(parent, editmode, f)
3328 {
3329         _helpFileName = "gui_cut_hexa.html";
3330         setupUi( this );
3331         _initWidget(editmode);
3332         //   setFocusProxy( e_le );
3333 }
3334
3335 // ============================================================== Destructeur
3336 CutEdgeDialog::~CutEdgeDialog()
3337 {
3338 }
3339
3340 // ============================================================== _initInputWidget
3341 void CutEdgeDialog::_initInputWidget( Mode editmode )
3342 {
3343         QRegExp rx("");
3344         QValidator *validator = new QRegExpValidator(rx, this);
3345
3346         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3347         installEventFilter(this);
3348
3349         e_le->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3350         e_le->setValidator( validator );
3351         e_le->installEventFilter(this);
3352 }
3353
3354 // ============================================================== clear
3355 void CutEdgeDialog::clear()
3356 {
3357         e_le->clear();
3358 }
3359
3360
3361 // ============================================================== apply
3362 bool CutEdgeDialog::apply(QModelIndex& result)
3363 {
3364         SUIT_OverrideCursor wc;
3365         //if ( !_documentModel ) return;
3366         if ( !_patternDataSelectionModel )    return false;
3367         if ( !_patternBuilderSelectionModel ) return false;
3368         const PatternDataModel*    patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3369         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3370         if ( !patternDataModel )    return false;
3371         if ( !patternBuilderModel ) return false;
3372         _currentObj = NULL;
3373
3374         int nbCut = nb_cut_spb->value();
3375         QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
3376
3377         QModelIndex iElts;
3378         if ( iedge.isValid() ){
3379                 iElts = _documentModel->cutEdge( iedge, nbCut );
3380         }
3381
3382         if ( !iElts.isValid() ){
3383                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) );
3384                 return false;
3385         }
3386
3387         result = patternBuilderModel->mapFromSource(iElts);
3388
3389         return true;
3390 }
3391
3392
3393
3394
3395 // // ------------------------- MakeTransformationDialog ----------------------------------
3396
3397 // ============================================================== Constructeur
3398
3399 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3400 : HexaBaseDialog(parent, editmode, f)
3401 {
3402         setupUi( this );
3403         _initWidget(editmode);
3404         rb0->setFocusProxy( elts_le_rb0 );
3405         rb1->setFocusProxy( elts_le_rb1 );
3406         rb2->setFocusProxy( elts_le_rb2 );
3407         setFocusProxy( rb0 );
3408         rb0->click();
3409
3410         _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3411         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3412         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3413         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3414 }
3415
3416 // ============================================================== Destructeur
3417 MakeTransformationDialog::~MakeTransformationDialog()
3418 {
3419 }
3420
3421 // ============================================================== _initInputWidget
3422 void MakeTransformationDialog::_initInputWidget( Mode editmode )
3423 {
3424         QRegExp rx("");
3425         QValidator *validator = new QRegExpValidator(rx, this);
3426
3427         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3428         installEventFilter(this);
3429
3430         vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3431         elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3432
3433         vec_le_rb0->setValidator( validator );
3434         elts_le_rb0->setValidator( validator );
3435         vec_le_rb0->installEventFilter(this);
3436         elts_le_rb0->installEventFilter(this);
3437
3438         vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3439         elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3440         vex_le_rb1->setValidator( validator );
3441         elts_le_rb1->setValidator( validator );
3442         vex_le_rb1->installEventFilter(this);
3443         elts_le_rb1->installEventFilter(this);
3444
3445         vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3446         vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3447         elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3448         vex_le_rb2->setValidator( validator );
3449         vec_le_rb2->setValidator( validator );
3450         elts_le_rb2->setValidator( validator );
3451         vex_le_rb2->installEventFilter(this);
3452         vec_le_rb2->installEventFilter(this);
3453         elts_le_rb2->installEventFilter(this);
3454
3455 }
3456
3457 // ============================================================== clear
3458 void MakeTransformationDialog::clear()
3459 {
3460         vex_le_rb1->clear();
3461         vex_le_rb2->clear();
3462         vec_le_rb0->clear();
3463         vec_le_rb2->clear();
3464         elts_le_rb0->clear();
3465         elts_le_rb1->clear();
3466         elts_le_rb2->clear();
3467 }
3468
3469
3470 // ============================================================== updateHelpFileName
3471 void MakeTransformationDialog::updateHelpFileName()
3472 {
3473         if ( sender() == rb0 ){
3474                 _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3475         } else if ( sender() == rb1 ){
3476                 _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
3477         } else if ( sender() == rb2 ){
3478                 _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
3479         }
3480 }
3481
3482 // ============================================================== apply
3483 bool MakeTransformationDialog::apply(QModelIndex& result)
3484 {
3485         SUIT_OverrideCursor wc;
3486         if ( !_patternDataSelectionModel )    return false;
3487         if ( !_patternBuilderSelectionModel ) return false;
3488         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3489         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3490         if ( !patternDataModel )    return false;
3491         if ( !patternBuilderModel ) return false;
3492         _currentObj = NULL;
3493
3494         QModelIndex iNewElts;
3495
3496         if ( rb0->isChecked() ){
3497                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3498                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3499
3500                 if ( ielts.isValid()
3501                                 && ivec.isValid() )
3502                         iNewElts = _documentModel->makeTranslation( ielts, ivec );
3503
3504         } else if ( rb1->isChecked() ){
3505                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3506                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3507                 double          k = k_spb->value();
3508
3509                 if ( ielts.isValid()
3510                                 && ivex.isValid() )
3511                         iNewElts = _documentModel->makeScale( ielts, ivex, k );
3512
3513         } else if ( rb2->isChecked() ){
3514                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3515                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3516                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3517                 double      angle = angle_spb->value();
3518
3519                 if ( ielts.isValid()
3520                                 && ivex.isValid()
3521                                 && ivec.isValid() )
3522                         iNewElts = _documentModel->makeRotation( ielts, ivex, ivec, angle );
3523         }
3524
3525         if ( !iNewElts.isValid() ){
3526                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) );
3527                 return false;
3528         }
3529
3530         result = patternBuilderModel->mapFromSource(iNewElts);
3531
3532         return true;
3533 }
3534
3535
3536
3537 // // ------------------------- MakeSymmetryDialog ----------------------------------
3538
3539 // ============================================================== Constructeur
3540
3541 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3542                                                                 HexaBaseDialog(parent, editmode, f)
3543 {
3544         setupUi( this );
3545         _initWidget(editmode);
3546         rb0->setFocusProxy( elts_le_rb0 );
3547         rb1->setFocusProxy( elts_le_rb1 );
3548         rb2->setFocusProxy( elts_le_rb2 );
3549         rb0->click();
3550         //     setFocusProxy( rb0 );
3551
3552         _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
3553         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3554         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3555         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3556 }
3557
3558
3559 // ============================================================== Destructeur
3560 MakeSymmetryDialog::~MakeSymmetryDialog()
3561 {
3562 }
3563
3564 // ============================================================== _initInputWidget
3565 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
3566 {
3567         QRegExp rx("");
3568         QValidator *validator = new QRegExpValidator(rx, this);
3569
3570         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3571         installEventFilter(this);
3572
3573         vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3574         elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3575         vex_le_rb0->setValidator( validator );
3576         elts_le_rb0->setValidator( validator );
3577         vex_le_rb0->installEventFilter(this);
3578         elts_le_rb0->installEventFilter(this);
3579
3580         vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3581         vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3582         elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3583         vex_le_rb1->setValidator( validator );
3584         vec_le_rb1->setValidator( validator );
3585         elts_le_rb1->setValidator( validator );
3586         vex_le_rb1->installEventFilter(this);
3587         vec_le_rb1->installEventFilter(this);
3588         elts_le_rb1->installEventFilter(this);
3589
3590
3591         vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3592         vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3593         elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3594         vex_le_rb2->setValidator( validator );
3595         vec_le_rb2->setValidator( validator );
3596         elts_le_rb2->setValidator( validator );
3597         vex_le_rb2->installEventFilter(this);
3598         vec_le_rb2->installEventFilter(this);
3599         elts_le_rb2->installEventFilter(this);
3600
3601 }
3602
3603 // ============================================================== clear
3604 void MakeSymmetryDialog::clear()
3605 {
3606         vex_le_rb0->clear();
3607         vex_le_rb1->clear();
3608         vex_le_rb2->clear();
3609
3610         vec_le_rb1->clear();
3611         vec_le_rb2->clear();
3612
3613         elts_le_rb0->clear();
3614         elts_le_rb1->clear();
3615         elts_le_rb2->clear();
3616 }
3617
3618
3619 // ============================================================== updateHelpFileName
3620 void MakeSymmetryDialog::updateHelpFileName()
3621 {
3622         if ( sender() == rb0 ){
3623                 _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
3624         } else if ( sender() == rb1 ){
3625                 _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
3626         } else if ( sender() == rb2 ){
3627                 _helpFileName = "gui_make_symmetry.html#make-elements-by-plan-symmetry";
3628         }
3629 }
3630
3631
3632 // ============================================================== apply
3633 bool MakeSymmetryDialog::apply(QModelIndex& result)
3634 {
3635         SUIT_OverrideCursor wc;
3636         if ( !_patternDataSelectionModel )    return false;
3637         if ( !_patternBuilderSelectionModel ) return false;
3638         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3639         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3640         if ( !patternDataModel )    return false;
3641         if ( !patternBuilderModel ) return false;
3642         _currentObj = NULL;
3643
3644         QModelIndex iNewElts;
3645
3646         if ( rb0->isChecked() ){
3647                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3648                 QModelIndex  ivex = patternBuilderModel->mapToSource( _index[vex_le_rb0] );
3649
3650                 if ( ielts.isValid()
3651                                 && ivex.isValid() )
3652                         iNewElts = _documentModel->makeSymmetryPoint( ielts, ivex );
3653
3654         } else if ( rb1->isChecked() ){
3655                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3656                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3657                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
3658
3659                 if ( ielts.isValid()
3660                                 && ivex.isValid()
3661                                 && ivec.isValid() )
3662                         iNewElts = _documentModel->makeSymmetryLine( ielts, ivex, ivec );
3663
3664         } else if ( rb2->isChecked() ){
3665                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3666                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3667                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3668
3669                 if ( ielts.isValid()
3670                                 && ivex.isValid()
3671                                 && ivec.isValid() )
3672                         iNewElts = _documentModel->makeSymmetryPlane( ielts, ivex, ivec );
3673         }
3674
3675         if ( !iNewElts.isValid() ){
3676                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) );
3677                 return false;
3678         }
3679
3680         result = patternBuilderModel->mapFromSource(iNewElts);
3681
3682         return true;
3683 }
3684
3685
3686
3687
3688
3689 // // ------------------------- PerformTransformationDialog ----------------------------------
3690
3691 // ============================================================== Constructeur
3692
3693 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3694                                                                                 HexaBaseDialog(parent, editmode, f)
3695 {
3696         setupUi( this );
3697         _initWidget(editmode);
3698         rb0->setFocusProxy( elts_le_rb0 );
3699         rb1->setFocusProxy( elts_le_rb1 );
3700         rb2->setFocusProxy( elts_le_rb2 );
3701         //   setFocusProxy( rb0 );
3702         rb0->click();
3703
3704         _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
3705         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3706         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3707         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3708 }
3709
3710
3711 // ============================================================== Destructeur
3712 PerformTransformationDialog::~PerformTransformationDialog()
3713 {
3714 }
3715
3716 // ============================================================== _initInputWidget
3717 void PerformTransformationDialog::_initInputWidget( Mode editmode )
3718 {
3719         QRegExp rx("");
3720         QValidator *validator = new QRegExpValidator(rx, this);
3721
3722         vec_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3723         elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3724         vec_le_rb0->setValidator( validator );
3725         elts_le_rb0->setValidator( validator );
3726         vec_le_rb0->installEventFilter(this);
3727         elts_le_rb0->installEventFilter(this);
3728
3729         vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3730         elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3731         vex_le_rb1->setValidator( validator );
3732         elts_le_rb1->setValidator( validator );
3733         vex_le_rb1->installEventFilter(this);
3734         elts_le_rb1->installEventFilter(this);
3735
3736
3737         vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3738         vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3739         elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3740         vex_le_rb2->setValidator( validator );
3741         vec_le_rb2->setValidator( validator );
3742         elts_le_rb2->setValidator( validator );
3743         vex_le_rb2->installEventFilter(this);
3744         vec_le_rb2->installEventFilter(this);
3745         elts_le_rb2->installEventFilter(this);
3746
3747 }
3748
3749 // ============================================================== clear
3750 void PerformTransformationDialog::clear()
3751 {
3752         vex_le_rb1->clear(); vex_le_rb2->clear();
3753         vec_le_rb0->clear(); vec_le_rb2->clear();
3754         elts_le_rb0->clear(); elts_le_rb1->clear(); elts_le_rb2->clear();
3755 }
3756
3757 // ============================================================== updateHelpFileName
3758 void PerformTransformationDialog::updateHelpFileName()
3759 {
3760         if ( sender() == rb0 ){
3761                 _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
3762         } else if ( sender() == rb1 ){
3763                 _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
3764         } else if ( sender() == rb2 ){
3765                 _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
3766         }
3767 }
3768
3769
3770 // ============================================================== apply
3771 bool PerformTransformationDialog::apply(QModelIndex& result)
3772 {
3773         SUIT_OverrideCursor wc;
3774         if ( !_patternDataSelectionModel )    return false;
3775         if ( !_patternBuilderSelectionModel ) return false;
3776         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3777         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3778         if ( !patternDataModel )    return false;
3779         if ( !patternBuilderModel ) return false;
3780         _currentObj = NULL;
3781
3782         bool performed = false;
3783
3784         if ( rb0->isChecked() ){
3785                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3786                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3787
3788                 if ( ielts.isValid()
3789                                 && ivec.isValid() )
3790                         performed = _documentModel->performTranslation( ielts, ivec );
3791
3792         } else if ( rb1->isChecked() ){
3793                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3794                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3795                 double          k = k_spb->value();
3796
3797                 if ( ielts.isValid()
3798                                 && ivex.isValid() )
3799                         performed = _documentModel->performScale( ielts, ivex, k );
3800
3801         } else if ( rb2->isChecked() ){
3802                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3803                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3804                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3805                 double      angle = angle_spb->value();
3806
3807                 if ( ielts.isValid()
3808                                 && ivex.isValid()
3809                                 && ivec.isValid() )
3810                         performed = _documentModel->performRotation( ielts, ivex, ivec, angle );
3811         }
3812
3813         if ( performed == false){
3814                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) );
3815                 return false;
3816         }
3817
3818
3819         return true;
3820 }
3821
3822
3823
3824
3825
3826 // // ------------------------- PerformSymmetryDialog ----------------------------------
3827
3828 // ============================================================== Constructeur
3829
3830 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3831 : HexaBaseDialog(parent, editmode, f)
3832 {
3833         setupUi( this );
3834         _initWidget( editmode );
3835         rb0->setFocusProxy( elts_le_rb0 );
3836         rb1->setFocusProxy( elts_le_rb1 );
3837         rb2->setFocusProxy( elts_le_rb2 );
3838         //   setFocusProxy( rb0 );
3839         rb0->click();
3840
3841         _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
3842         connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3843         connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3844         connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3845 }
3846
3847 // ============================================================== Destructeur
3848 PerformSymmetryDialog::~PerformSymmetryDialog()
3849 {
3850 }
3851
3852 // ============================================================== _initInputWidget
3853 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
3854 {
3855         QRegExp rx("");
3856         QValidator *validator = new QRegExpValidator(rx, this);
3857
3858         vex_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3859         elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3860         vex_le_rb0->setValidator( validator );
3861         elts_le_rb0->setValidator( validator );
3862         vex_le_rb0->installEventFilter(this);
3863         elts_le_rb0->installEventFilter(this);
3864
3865         vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3866         vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3867         elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3868         vex_le_rb1->setValidator( validator );
3869         vec_le_rb1->setValidator( validator );
3870         elts_le_rb1->setValidator( validator );
3871         vex_le_rb1->installEventFilter(this);
3872         vec_le_rb1->installEventFilter(this);
3873         elts_le_rb1->installEventFilter(this);
3874
3875
3876         vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3877         vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3878         elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3879         vex_le_rb2->setValidator( validator );
3880         vec_le_rb2->setValidator( validator );
3881         elts_le_rb2->setValidator( validator );
3882         vex_le_rb2->installEventFilter(this);
3883         vec_le_rb2->installEventFilter(this);
3884         elts_le_rb2->installEventFilter(this);
3885
3886 }
3887
3888 // ============================================================== clear
3889 void PerformSymmetryDialog::clear()
3890 {
3891         vex_le_rb0->clear(); vex_le_rb1->clear(); vex_le_rb2->clear();
3892         vec_le_rb1->clear(); vec_le_rb2->clear();
3893         elts_le_rb0->clear(); elts_le_rb1->clear(); elts_le_rb2->clear();
3894 }
3895
3896 // ============================================================== updateHelpFileName
3897 void PerformSymmetryDialog::updateHelpFileName()
3898 {
3899         if ( sender() == rb0 ){
3900                 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
3901         } else if ( sender() == rb1 ){
3902                 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
3903         } else if ( sender() == rb2 ){
3904                 _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plan-symmetry";
3905         }
3906 }
3907
3908 // ============================================================== apply
3909 bool PerformSymmetryDialog::apply(QModelIndex& result)
3910 {
3911         SUIT_OverrideCursor wc;
3912         if ( !_patternDataSelectionModel )    return false;
3913         if ( !_patternBuilderSelectionModel ) return false;
3914         const PatternDataModel*    patternDataModel    = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
3915         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
3916         if ( !patternDataModel )    return false;
3917         if ( !patternBuilderModel ) return false;
3918         _currentObj = NULL;
3919
3920         bool performed = false;
3921
3922         if ( rb0->isChecked() ){
3923                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3924                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
3925
3926                 if ( ielts.isValid()
3927                                 && ivex.isValid() )
3928                         performed = _documentModel->performSymmetryPoint( ielts, ivex );
3929
3930         } else if ( rb1->isChecked() ){
3931                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3932                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3933                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
3934
3935                 if ( ielts.isValid()
3936                                 && ivex.isValid()
3937                                 && ivec.isValid() )
3938                         performed = _documentModel->performSymmetryLine( ielts, ivex, ivec );
3939
3940         } else if ( rb2->isChecked() ){
3941                 QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3942                 QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3943                 QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3944
3945                 if ( ielts.isValid()
3946                                 && ivex.isValid()
3947                                 && ivec.isValid() )
3948                         performed = _documentModel->performSymmetryPlane( ielts, ivex, ivec );
3949         }
3950
3951         if ( performed == false ){
3952                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) );
3953                 return false;
3954         }
3955
3956         return true;
3957 }
3958
3959
3960
3961 // // ------------------------- EdgeAssocDialog ----------------------------------
3962
3963 // ============================================================== Constructeur
3964
3965 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3966                                                                                 HexaBaseDialog( parent, editmode, f )
3967 {
3968         _helpFileName ="gui_asso_quad_to_geom.html#associate-to-edges-or-wires-of-the-geometry";
3969         setupUi( this );
3970         _initWidget(editmode);
3971         _initViewManager();
3972         setFocusProxy( edges_lw );
3973
3974         myLine.nullify();
3975
3976         _currentParameter = 0.;
3977         single_rb->click();
3978 }
3979
3980 // ============================================================== Destructeur
3981 EdgeAssocDialog::~EdgeAssocDialog()
3982 {
3983         //   disconnect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3984         //   disconnect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
3985         disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addLine()) );
3986         disconnect( pstart_spb, SIGNAL(valueChanged(double)), this, SLOT( pstartChanged(double)) );
3987         disconnect( pend_spb,   SIGNAL(valueChanged(double)), this, SLOT( pendChanged(double)) );
3988 }
3989
3990
3991 // ============================================================== _initInputWidget
3992 void EdgeAssocDialog::_initInputWidget( Mode editmode )
3993 {
3994         QRegExp rx("");
3995         QValidator *validator = new QRegExpValidator(rx, this);
3996
3997         //model
3998         first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3999         first_vex_le->installEventFilter(this);
4000         first_vex_le->setValidator( validator );
4001
4002         single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4003         single_edge_le->installEventFilter(this);
4004
4005         edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4006         edges_lw->installEventFilter(this);
4007
4008
4009         //geom
4010         lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4011         lines_lw->installEventFilter(this);
4012
4013         single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4014         single_line_le->installEventFilter(this);
4015
4016
4017         QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4018         QShortcut* delLineShortcut = new QShortcut(QKeySequence(Qt::Key_X), lines_lw);
4019         delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4020         delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4021
4022         pend_spb->setValue(1.);
4023
4024         connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4025         connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4026         connect( pstart_spb, SIGNAL(valueChanged(double)), this, SLOT( pstartChanged(double)) );
4027         connect( pend_spb,   SIGNAL(valueChanged(double)), this, SLOT( pendChanged(double)) );
4028         connect( edges_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
4029
4030 }
4031
4032 // ============================================================== clear
4033 void EdgeAssocDialog::clear()
4034 {
4035         first_vex_le->clear();
4036         edges_lw->clear();
4037         lines_lw->clear();
4038         single_edge_le->setText("");
4039         single_line_le->setText("");
4040 }
4041
4042 // ============================================================== deleteEdgeItem
4043 void EdgeAssocDialog::deleteEdgeItem()
4044 {
4045         delete edges_lw->currentItem();
4046 }
4047
4048 // ============================================================== deleteLineItem
4049 void EdgeAssocDialog::deleteLineItem()
4050 {
4051         delete lines_lw->currentItem();
4052 }
4053
4054
4055 // ============================================================== setGeomEngine
4056 void EdgeAssocDialog::setGeomEngine( GEOM::GEOM_Gen_var geomEngine )
4057 {
4058         _geomEngine = geomEngine;
4059 }
4060
4061 // ============================================================== onWindowActivated
4062 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4063 {
4064         SUIT_ViewWindow* v = vm->getActiveView();
4065         QString vmType = vm->getType();
4066         if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
4067                 edges_lw->setFocus();
4068         } else if ( vmType == OCCViewer_Viewer::Type() ){
4069                 lines_lw->setFocus();
4070         }
4071 }
4072
4073 // ============================================================== createOperation
4074 GEOM::GEOM_IOperations_ptr EdgeAssocDialog::createOperation()
4075 {
4076         return _geomEngine->GetIBasicOperations(getStudyId());
4077 }
4078
4079 // ============================================================== execute
4080 bool EdgeAssocDialog::execute(ObjectList& objects)
4081 {
4082         MESSAGE("execute(){");
4083         MESSAGE("*    objects.size()" << objects.size() );
4084
4085         bool res = false;
4086
4087         GEOM::GEOM_Object_var anObj;
4088         QStringList aParameters;
4089
4090         GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
4091         anObj = anOper->MakePointOnCurve( _currentLine.get(), _currentParameter );
4092         if ( !anObj->_is_nil() ) {
4093                 objects.push_back(anObj._retn());
4094                 res = true;
4095         }
4096         MESSAGE("}execute()");
4097         return res;
4098 }
4099
4100 // ============================================================== pstartChanged
4101 void EdgeAssocDialog::pstartChanged( double val )
4102 {
4103         MESSAGE("pstartChanged("<<val<<") { ");
4104         QListWidgetItem* lineItem = lines_lw->item( 0 );
4105         if (!lineItem) return;
4106         //   MESSAGE("data : "<<lineItem->text().toStdString());
4107         _currentLine = lineItem->data(LW_GEOM_OBJ_ROLE).value<GEOM::GeomObjPtr>();
4108         _currentParameter = pstart_spb->value();
4109         displayPreview(true);
4110         MESSAGE("}pstartChanged()");
4111 }
4112
4113 // ============================================================== pendChanged
4114 void EdgeAssocDialog::pendChanged( double val )
4115 {
4116         MESSAGE("pendChanged("<<val<<") { ");
4117         //   if ( _lastLine->_is_nil() ) return;
4118         QListWidgetItem* lineItem = lines_lw->item( lines_lw->count()-1 );
4119         if (!lineItem) return;
4120         //   MESSAGE("data : "<<lineItem->text().toStdString());
4121         _currentLine      = lineItem->data(LW_GEOM_OBJ_ROLE).value<GEOM::GeomObjPtr>();
4122         _currentParameter = pend_spb->value();
4123         displayPreview(true);
4124         MESSAGE("}pendChanged()");
4125 }
4126
4127 // ============================================================== onCurrentSelectionChanged
4128 void EdgeAssocDialog::onCurrentSelectionChanged()
4129 {
4130         if ( !isVisible() ) return;
4131
4132         SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
4133         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
4134
4135         bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
4136         //   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
4137
4138         if (!isOCC) return;
4139
4140
4141         GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_EDGE);
4142         TopoDS_Shape aShape;
4143
4144         if ( !(aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull()) )
4145                 return;
4146
4147         if (single_rb->isChecked()) {
4148                 QString aName = GEOMBase::GetName(aSelectedObject.get());
4149                 single_line_le->setText(aName);
4150                 myLine = aSelectedObject;
4151         }
4152         else if( multiple_rb->isChecked() ) {
4153
4154                 DocumentModel::GeomObj aLine;
4155                 QListWidgetItem* item = NULL;
4156                 QString mainShapeEntry;
4157                 int     subId = -1;
4158                 QString brep;
4159
4160                 if ( aSelectedObject->IsMainShape() ){
4161                         mainShapeEntry = aSelectedObject->GetStudyEntry();
4162                         brep =  shape2string( aShape ).c_str();
4163                 } else {
4164                         TopoDS_Shape shape;
4165                         TopoDS_Shape subshape;
4166                         GEOM::GEOM_Object_var mainShape = aSelectedObject->GetMainShape();
4167                         mainShapeEntry = mainShape->GetStudyEntry();
4168                         // CS_TODO : à optimiser
4169                         bool okShape = GEOMBase::GetShape( mainShape , shape);//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4170                         bool oksubShape = GEOMBase::GetShape( aSelectedObject.get(), subshape );//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4171                         if ( okShape && oksubShape ){
4172                                 brep =  shape2string( subshape ).c_str();
4173                                 subId = GEOMBase::GetIndex( subshape, shape );
4174                         }
4175                 }
4176                 aLine.name  = GEOMBase::GetName( aSelectedObject.get() );
4177                 aLine.entry = mainShapeEntry;
4178                 aLine.subid = QString::number(subId);
4179                 aLine.brep  = brep;
4180                 aLine.start = 0.;
4181                 aLine.end   = 1.;
4182
4183                 item  = new QListWidgetItem( aLine.name );
4184                 item->setData(  LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(aLine) );
4185                 item->setData(  LW_GEOM_OBJ_ROLE, QVariant::fromValue<GEOM::GeomObjPtr>(aSelectedObject) );
4186                 lines_lw->addItem(item);
4187         }
4188 }
4189
4190
4191 // ============================================================== apply
4192 bool EdgeAssocDialog::apply(QModelIndex& result)
4193 {
4194         SUIT_OverrideCursor wc;
4195         bool assocOk = false;
4196
4197         if ( !_patternDataSelectionModel ) return false;
4198         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
4199         if ( !patternDataModel ) return false;
4200         _currentObj = NULL;
4201
4202         QListWidgetItem* item = NULL;
4203
4204         QModelIndex     iEdge;
4205         QModelIndexList iEdges;
4206         QList<DocumentModel::GeomObj> assocs;
4207         DocumentModel::GeomObj aLine;
4208
4209         if (single_rb->isChecked()){ //Single edge and/or line association
4210
4211                 QString mainShapeEntry;
4212                 int     subId = -1;
4213                 QString brep;
4214                 GEOM::GeomObjPtr aSelectedObject = myLine;
4215                 TopoDS_Shape aShape;
4216
4217                 if ( aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull() ){
4218                         if ( aSelectedObject->IsMainShape() ){
4219                                 mainShapeEntry = aSelectedObject->GetStudyEntry();
4220                                 brep =  shape2string( aShape ).c_str();
4221                         }
4222                         else {
4223                                 TopoDS_Shape shape;
4224                                 TopoDS_Shape subshape;
4225                                 GEOM::GEOM_Object_var mainShape = aSelectedObject->GetMainShape();
4226                                 mainShapeEntry = mainShape->GetStudyEntry();
4227                                 // CS_TODO : à optimiser
4228                                 bool okShape = GEOMBase::GetShape( mainShape , shape);//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4229                                 bool oksubShape = GEOMBase::GetShape( aSelectedObject.get(), subshape );//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4230                                 if ( okShape && oksubShape ){
4231                                         brep =  shape2string( subshape ).c_str();
4232                                         subId = GEOMBase::GetIndex( subshape, shape );
4233                                 }
4234                         }
4235                         aLine.name  = GEOMBase::GetName( aSelectedObject.get() );
4236                         aLine.entry = mainShapeEntry;
4237                         aLine.subid = QString::number(subId);
4238                         aLine.brep  = brep;
4239                         aLine.start = pstart_spb->value();
4240                         aLine.end   = pend_spb->value();
4241                         iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
4242                         if (!iEdge.isValid()) return false;
4243                         _documentModel->addAssociation(iEdge, aLine);
4244                         assocOk = true;
4245                 }
4246         }
4247         else { //Multiple edge and/or line association
4248
4249                 // edges
4250                 for ( int r = 0; r < edges_lw->count(); ++r){
4251                         item = edges_lw->item(r);
4252                         iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4253                         if ( iEdge.isValid() )
4254                                 iEdges << iEdge;
4255                 }
4256
4257                 // lines
4258                 for ( int r = 0; r < lines_lw->count(); ++r){
4259                         item = lines_lw->item(r);
4260                         aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4261                         //std::cout << " line added : " << aLine.name.toStdString() << std::endl;
4262                         MESSAGE(" assocs => " << aLine.name.toStdString() );
4263                         MESSAGE(" assocs => " << aLine.brep.toStdString() );
4264                         assocs << aLine;
4265                 }
4266
4267                 if ( close_cb->isChecked() ){ //closed line
4268                         QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
4269                         // if (inverse_cb->isChecked())
4270                         //      assocOk = _documentModel->associateClosedLine( iFirstVertex, iEdges, assocs, pstart_spb->value(), true );
4271                         // else
4272                         assocOk = _documentModel->associateClosedLine( iFirstVertex, iEdges, assocs, pstart_spb->value() );
4273                 } else {
4274                         //opened line
4275                         assocOk = _documentModel->associateOpenedLine( iEdges, assocs, pstart_spb->value(), pend_spb->value() );
4276                 }
4277         }
4278
4279         if ( !assocOk ){
4280                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4281                 return false;
4282         }
4283
4284         return true;
4285 }
4286
4287
4288
4289 // // ------------------------- QuadAssocDialog ----------------------------------
4290
4291 // ============================================================== Constructeur
4292
4293 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4294                                                                 HexaBaseDialog(parent, editmode, f)
4295 {
4296         _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
4297         setupUi( this );
4298         _initWidget(editmode);
4299         _initViewManager();
4300         setFocusProxy( quad_le );
4301 }
4302
4303 // ============================================================== Destructeur
4304 QuadAssocDialog::~QuadAssocDialog()
4305 {
4306         disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4307         disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
4308         delete _delFaceShortcut;
4309 }
4310
4311 // ============================================================== _initInputWidget
4312 void QuadAssocDialog::_initInputWidget( Mode editmode )
4313 {
4314         QRegExp rx("");
4315         QValidator *validator = new QRegExpValidator(rx, this);
4316
4317         quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
4318         quad_le->installEventFilter(this);
4319         quad_le->setValidator( validator );
4320
4321
4322         faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
4323         faces_lw->installEventFilter(this);
4324         _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
4325         _delFaceShortcut->setContext( Qt::WidgetShortcut );
4326
4327         connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4328 }
4329
4330 // ============================================================== clear
4331 void QuadAssocDialog::clear()
4332 {
4333         quad_le->clear();
4334         faces_lw->clear();
4335 }
4336
4337 // ============================================================== onCurrentSelectionChanged
4338 void QuadAssocDialog::onCurrentSelectionChanged()
4339 {
4340
4341         if ( !isVisible() ) return;
4342
4343         SUIT_ViewWindow* window = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
4344         SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
4345
4346         bool isOCC = (window && window->getViewManager()->getType() == OCCViewer_Viewer::Type());
4347         //   bool isVTK = (window && window->getViewManager()->getType() == SVTK_Viewer::Type());
4348
4349         if (!isOCC) return;
4350
4351         GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_FACE);
4352         TopoDS_Shape aShape;
4353
4354         if ( aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull() ){
4355                 DocumentModel::GeomObj aFace;
4356                 QListWidgetItem* item = NULL;
4357                 QString mainShapeEntry;
4358                 int     subId = -1;
4359                 QString brep;
4360
4361                 if ( aSelectedObject->IsMainShape() ){
4362                         mainShapeEntry = aSelectedObject->GetStudyEntry();
4363                         brep =  shape2string( aShape ).c_str();
4364                 } else {
4365                         TopoDS_Shape shape;
4366                         TopoDS_Shape subshape;
4367                         GEOM::GEOM_Object_var mainShape = aSelectedObject->GetMainShape();
4368                         mainShapeEntry = mainShape->GetStudyEntry();
4369                         // CS_TODO : à optimiser
4370                         bool okShape = GEOMBase::GetShape( mainShape , shape);//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4371                         bool oksubShape = GEOMBase::GetShape( aSelectedObject.get(), subshape );//,const TopAbs_ShapeEnum type = TopAbs_SHAPE );
4372                         if ( okShape && oksubShape ){
4373                                 brep =  shape2string( subshape ).c_str();
4374                                 subId = GEOMBase::GetIndex( subshape, shape );
4375                         }
4376                 }
4377                 aFace.name  = GEOMBase::GetName( aSelectedObject.get() );
4378                 aFace.entry = mainShapeEntry;
4379                 aFace.subid = QString::number(subId);
4380                 aFace.brep  = brep;
4381                 aFace.start = 0.;
4382                 aFace.end   = 1.;
4383
4384                 item  = new QListWidgetItem( aFace.name );
4385                 item->setData(  LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(aFace) );
4386                 faces_lw->addItem(item);
4387                 //     faces_lw->setCurrentRow( faces_lw->count() - 1 );
4388         }
4389
4390 }
4391
4392 // ============================================================== onWindowActivated
4393 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4394 {
4395         SUIT_ViewWindow* v = vm->getActiveView();
4396         QString     vmType = vm->getType();
4397         if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) ){
4398                 quad_le->setFocus();
4399         } else if ( vmType == OCCViewer_Viewer::Type() ){
4400                 faces_lw->setFocus();
4401         }
4402 }
4403
4404 // ============================================================== deleteFaceItem
4405 void QuadAssocDialog::deleteFaceItem()
4406 {
4407         delete faces_lw->currentItem();
4408 }
4409
4410
4411 // ============================================================== apply
4412 bool QuadAssocDialog::apply(QModelIndex& result)
4413 {
4414         SUIT_OverrideCursor wc;
4415         //if ( !_documentModel ) return;
4416         if ( !_patternDataSelectionModel ) return false;
4417         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
4418         if ( !patternDataModel )           return false;
4419         _currentObj = NULL;
4420
4421         // quad
4422         QModelIndex iQuad = patternDataModel->mapToSource( _index[quad_le] );
4423
4424         // faces
4425         QListWidgetItem* item = NULL;
4426         DocumentModel::GeomObj aFace;
4427         for ( int r = 0; r < faces_lw->count(); ++r ){
4428                 item = faces_lw->item(r);
4429                 aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4430                 _documentModel->addAssociation( iQuad, aFace );
4431         }
4432
4433         result = patternDataModel->mapFromSource(iQuad);
4434
4435         return true;
4436 }
4437
4438
4439
4440 // ------------------------- GroupDialog ----------------------------------
4441
4442 // ============================================================== Constructeur
4443
4444 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4445                                                                 HexaBaseDialog(parent, editmode, f),
4446                                                                 _value(NULL)
4447 {
4448         _helpFileName = "gui_groups.html#add-group";
4449         setupUi( this );
4450         _initWidget(editmode);
4451         //   setFocusProxy( name_le/*eltBase_lw */);
4452
4453         if ( editmode  == NEW_MODE ){
4454                 setWindowTitle( tr("Group Construction") );
4455         } else if ( editmode == UPDATE_MODE ){
4456                 setWindowTitle( tr("Group Modification") );
4457         } else if ( editmode == INFO_MODE ){
4458                 setWindowTitle( tr("Group Information") );
4459         }
4460 }
4461
4462 // ============================================================== Destructeur
4463 GroupDialog::~GroupDialog()
4464 {
4465 }
4466
4467
4468 // ============================================================== _initInputWidget
4469 void GroupDialog::_initInputWidget( Mode editmode )
4470 {
4471         setProperty( "HexaWidgetType",  QVariant::fromValue(GROUP_TREE) );
4472         installEventFilter(this);
4473
4474         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(GROUP_TREE) );
4475         name_le->installEventFilter(this);
4476
4477         // kind checkbox
4478         strKind[ HEXA_NS::HexaCell ] = "HexaCell";
4479         strKind[ HEXA_NS::QuadCell ] = "QuadCell";
4480         strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
4481         strKind[ HEXA_NS::HexaNode ] = "HexaNode";
4482         strKind[ HEXA_NS::QuadNode ] = "QuadNode";
4483         strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
4484         strKind[ HEXA_NS::VertexNode ] = "VertexNode";
4485         kind_cb->clear();
4486         QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
4487         for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
4488                 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
4489
4490         onKindChanged( kind_cb->currentIndex() );
4491         eltBase_lw->installEventFilter(this);
4492
4493         if ( editmode != INFO_MODE ){
4494                 QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
4495                 delEltShortcut->setContext( Qt::WidgetShortcut );
4496                 connect(delEltShortcut,   SIGNAL(activated()), this, SLOT(removeEltBase()));
4497                 connect(kind_cb,  SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
4498         }
4499
4500         connect(eltBase_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()));
4501 }
4502
4503 // ============================================================== clear
4504 void GroupDialog::clear()
4505 {
4506         name_le->clear();
4507         eltBase_lw->clear();
4508 }
4509
4510 // ============================================================== onKindChanged
4511 void GroupDialog::onKindChanged(int index)
4512 {
4513         //   onKind
4514         MESSAGE("GroupDialog::onKindChanged(" << index << ") ");
4515         switch ( kind_cb->itemData(index).toInt() ){
4516         case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE)); MESSAGE("====>HEXA_TREE"); break;
4517         case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE)); MESSAGE("====>QUAD_TREE"); break;
4518         case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE)); MESSAGE("====>EDGE_TREE"); break;
4519         case HEXA_NS::VertexNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE)); MESSAGE("====>VERTEX_TREE"); break;
4520         default:Q_ASSERT( false );
4521         }
4522         eltBase_lw->clear();
4523         eltBase_lw->setFocus();
4524 }
4525
4526 // ============================================================== setValue
4527 void GroupDialog::setValue(HEXA_NS::Group* g)
4528 {
4529         //0) name
4530         name_le->setText( g->getName() );
4531
4532         //1) kind
4533         kind_cb->clear();
4534         kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
4535         //   onKindChanged( kind_cb->currentIndex() );
4536
4537         //2) elts
4538         HEXA_NS::EltBase* eltBase = NULL;
4539         QListWidgetItem* item = NULL;
4540         QModelIndex iEltBase;
4541         QList<QStandardItem *> eltBaseItems;
4542         QVariant v;
4543
4544         if ( !_patternDataSelectionModel ) return;
4545         if ( !_groupsSelectionModel ) return;
4546
4547         QModelIndex iGroup = _groupsSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
4548         name_le->setProperty( "QModelIndex",  QVariant::fromValue(iGroup) );
4549
4550
4551         for ( int nr = 0; nr < g->countElement(); ++nr ){
4552                 eltBase = g->getElement( nr );
4553                 switch ( g->getKind() ){
4554                 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
4555                 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
4556                 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
4557                 case HEXA_NS::VertexNode:                       v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
4558                 }
4559                 iEltBase  = _patternDataSelectionModel->indexBy( HEXA_DATA_ROLE, v);
4560                 if ( iEltBase.isValid() ){
4561                         item = new QListWidgetItem( eltBase->getName() );
4562                         item->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
4563                         eltBase_lw->addItem( item );
4564                 }
4565         }
4566
4567         _value = g;
4568 }
4569
4570 // ============================================================== getValue
4571 HEXA_NS::Group* GroupDialog::getValue()
4572 {
4573         return _value;
4574 }
4575
4576
4577 // ============================================================== removeEltBase
4578 void GroupDialog::removeEltBase()
4579 {
4580         QListWidgetItem *item = eltBase_lw->currentItem();
4581
4582         if (item) {
4583                 int r = eltBase_lw->row(item);
4584                 eltBase_lw->takeItem(r);
4585                 delete item;
4586         }
4587
4588 }
4589
4590 // ============================================================== apply
4591 bool GroupDialog::apply(QModelIndex& result)
4592 {
4593         SUIT_OverrideCursor wc;
4594
4595         if ( !_documentModel ) return false;
4596         if ( !_patternDataSelectionModel ) return false;
4597         if ( !_groupsSelectionModel )      return false;
4598         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
4599         const GroupsModel*      groupsModel = dynamic_cast<const GroupsModel*>( _groupsSelectionModel->model() );
4600         _currentObj = NULL;
4601
4602         QString               grpName = name_le->text();
4603         DocumentModel::Group  grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
4604         QModelIndex iGrp;
4605         if ( _value == NULL ){ // create group
4606                 iGrp = _documentModel->addGroup( grpName, grpKind );
4607         } else {
4608                 QModelIndexList iGrps = _documentModel->match(
4609                                 _documentModel->index(0, 0),
4610                                 HEXA_DATA_ROLE,
4611                                 QVariant::fromValue( _value ),
4612                                 1,
4613                                 Qt::MatchRecursive );
4614                 if ( !iGrps.isEmpty() )
4615                         iGrp = iGrps[0];
4616         }
4617
4618         //   kind_cb->
4619         if ( !iGrp.isValid() ){
4620                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) );
4621                 return false;
4622         }
4623
4624         //fill it and select it
4625         QModelIndex iEltBase;
4626         QListWidgetItem* item = NULL;
4627         bool eltAdded = false;
4628         _documentModel->clearGroupElement(iGrp);
4629         for ( int r = 0; r < eltBase_lw->count(); ++r){
4630                 item     = eltBase_lw->item(r);
4631                 iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4632                 if ( iEltBase.isValid() )
4633                         eltAdded = _documentModel->addGroupElement( iGrp, iEltBase );
4634                 //    if ( eltAdded == false ){
4635                 //      //SUIT_MessageBox::information( this, tr( "HEXA_INFO" ), tr( "ELEMENT NOT ADDED : %1" ).arg( iEltBase.data().toString() ));
4636                 //    }
4637         }
4638
4639         QString newName = name_le->text();
4640         if ( !newName.isEmpty() )/*{*/
4641                 _documentModel->setName( iGrp, newName );
4642
4643         result = groupsModel->mapFromSource(iGrp);
4644
4645         return true;
4646 }
4647
4648
4649
4650 // ------------------------- LawDialog ----------------------------------
4651
4652 // ============================================================== Constructeur
4653
4654 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4655 : HexaBaseDialog(parent, editmode, f),
4656   _value(NULL)
4657 {
4658         _helpFileName = "gui_discret_law.html#add-law";
4659         setupUi( this );
4660         _initWidget(editmode);
4661         if ( editmode  == NEW_MODE ){
4662                 setWindowTitle( tr("Law Construction") );
4663         } else if ( editmode == UPDATE_MODE ){
4664                 setWindowTitle( tr("Law Modification") );
4665         }
4666 }
4667
4668 // ============================================================== Destructeur
4669 LawDialog::~LawDialog()
4670 {
4671 }
4672
4673 // ============================================================== _initInputWidget
4674 void LawDialog::_initInputWidget( Mode editmode )
4675 {
4676         QRegExp rx("");
4677         QValidator *validator = new QRegExpValidator(rx, this);
4678
4679         setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
4680         installEventFilter(this);
4681
4682         name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
4683         name_le->installEventFilter(this);
4684
4685         // kind checkbox
4686         strKind[ HEXA_NS::Uniform ]    = "Uniform";
4687         strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
4688         strKind[ HEXA_NS::Geometric ]  = "Geometric";
4689
4690         kind_cb->clear();
4691         QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind;
4692         for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
4693                 kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
4694
4695 }
4696
4697 // ============================================================== clear
4698 void LawDialog::clear()
4699 {
4700         name_le->clear();
4701 }
4702
4703 // ============================================================== setValue
4704 void LawDialog::setValue(HEXA_NS::Law* l)
4705 {
4706         // 0) name
4707         name_le->setText( l->getName() );
4708
4709         nb_nodes_spb->setValue( l->getNodes() );
4710         coeff_spb->setValue( l->getCoefficient() );
4711
4712         HEXA_NS::KindLaw k = l->getKind();
4713         kind_cb->setCurrentIndex( kind_cb->findData(k) );
4714
4715         _value = l;
4716 }
4717
4718 // ============================================================== getValue
4719 HEXA_NS::Law* LawDialog::getValue()
4720 {
4721         return _value;
4722 }
4723
4724
4725
4726 // ============================================================== apply
4727 bool LawDialog::apply(QModelIndex& result)
4728 {
4729         SUIT_OverrideCursor wc;
4730         if ( !_documentModel ) return false;
4731         if ( !_meshSelectionModel ) return false;
4732
4733         _currentObj = NULL;
4734         const MeshModel* meshModel = dynamic_cast<const MeshModel*>( _meshSelectionModel->model() );
4735
4736         QString lawName = name_le->text();
4737         int     nbnodes = nb_nodes_spb->value();
4738         double  coeff   = coeff_spb->value();
4739         DocumentModel::KindLaw  lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
4740
4741
4742         QModelIndex iLaw;
4743         if ( _value == NULL ){ // create Law
4744                 iLaw = _documentModel->addLaw( lawName, nbnodes );
4745         } else {
4746                 QModelIndexList iLaws = _documentModel->match(
4747                                 _documentModel->index(0, 0),
4748                                 HEXA_DATA_ROLE,
4749                                 QVariant::fromValue( _value ),
4750                                 1,
4751                                 Qt::MatchRecursive );
4752                 if ( !iLaws.isEmpty() )
4753                         iLaw = iLaws[0];
4754         }
4755
4756         if ( !iLaw.isValid() ){
4757                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) );
4758                 return false;
4759         }
4760         //fill it and select it
4761         bool setOk = _documentModel->setLaw( iLaw, nbnodes, coeff, lawKind );
4762         if ( !setOk ){
4763                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) );
4764                 return false;
4765         }
4766
4767         QString newName = name_le->text();
4768         if ( !newName.isEmpty() )/*{*/
4769                 _documentModel->setName( iLaw, newName );
4770
4771         result = meshModel->mapFromSource(iLaw);
4772
4773         return true;
4774 }
4775
4776
4777
4778
4779 // ------------------------- PropagationDialog ----------------------------------
4780
4781 // ============================================================== Constructeur
4782
4783 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4784 : HexaBaseDialog(parent, editmode, f),
4785   _value(NULL)
4786 {
4787         _helpFileName = "gui_propag.html";
4788         setupUi( this );
4789         _initWidget(editmode);
4790         //   setFocusProxy( law_le );
4791         setFocusProxy( propagations_lw );
4792
4793         if ( editmode == INFO_MODE ){
4794                 setWindowTitle( tr("Propagation Information") );
4795                 if (groupBox_2)
4796                         delete groupBox_2;
4797         } else if ( editmode == UPDATE_MODE ){
4798                 setWindowTitle( tr("Propagation Modification") );
4799                 if (groupBox_2)
4800                         delete groupBox_2;
4801         } else if ( editmode == NEW_MODE ){
4802                 setWindowTitle( tr("Propagation(s) Setting") );
4803         }
4804 }
4805
4806
4807 // ============================================================== Destructeur
4808 PropagationDialog::~PropagationDialog()
4809 {
4810 }
4811
4812
4813 // ============================================================== _initInputWidget
4814 void PropagationDialog::_initInputWidget( Mode editmode )
4815 {
4816         QRegExp rx("");
4817         QValidator *validator = new QRegExpValidator(rx, this);
4818
4819         setProperty( "HexaWidgetType",  QVariant::fromValue(PROPAGATION_TREE) );
4820         installEventFilter(this);
4821
4822
4823         law_le->setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
4824         law_le->installEventFilter(this);
4825         law_le->setValidator( validator );
4826
4827         propagations_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(PROPAGATION_TREE) );
4828         propagations_lw->installEventFilter(this);
4829
4830         QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
4831         delPropagationShortcut->setContext( Qt::WidgetShortcut );
4832
4833         connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
4834         connect( propagations_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()) );
4835 }
4836
4837
4838 // ============================================================== clear
4839 void PropagationDialog::clear()
4840 {
4841         propagations_lw->clear();
4842         law_le->clear();
4843 }
4844
4845 // ============================================================== deletePropagationItem
4846 void PropagationDialog::deletePropagationItem()
4847 {
4848         delete propagations_lw->currentItem();
4849 }
4850
4851
4852 // ============================================================== setValue
4853 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
4854 {
4855         HEXA_NS::Law* l = p->getLaw();
4856         bool way = p->getWay();
4857
4858         // propagation
4859         QModelIndex ip = _meshSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
4860         setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(ip) );
4861
4862
4863         // law on propagation
4864         if ( l != NULL ){
4865                 law_le->setText( l->getName() );
4866                 QModelIndex il = _meshSelectionModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
4867                 law_le->setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(il) );
4868         }
4869
4870         // way of propagation
4871         way_cb->setChecked(way);
4872
4873         _value = p;
4874 }
4875
4876 // ============================================================== getValue
4877 HEXA_NS::Propagation* PropagationDialog::getValue()
4878 {
4879         return _value;
4880 }
4881
4882
4883 // ============================================================== apply
4884 bool PropagationDialog::apply(QModelIndex& result)
4885 {
4886         bool isOk = false;
4887         SUIT_OverrideCursor wc;
4888         if ( !_documentModel ) return false;
4889         if ( !_meshSelectionModel ) return false;
4890         _currentObj = NULL;
4891
4892         const MeshModel* meshModel = dynamic_cast<const MeshModel*>( _meshSelectionModel->model() );
4893         bool way = way_cb->isChecked();
4894         QListWidgetItem* item = NULL;
4895
4896         QModelIndex iPropagation;
4897         QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
4898         if (!iLaw.isValid() ){
4899                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
4900                 return false;
4901         }
4902         MESSAGE("iLaw.isValid()         => " << iLaw.isValid() );
4903
4904         for (int r = 0; r < propagations_lw->count(); ++r){
4905                 item = propagations_lw->item(r);
4906                 iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4907                 if ( !iPropagation.isValid() ){
4908                         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
4909                         return false;
4910                 }
4911                 MESSAGE("iPropagation.isValid() => " << iPropagation.isValid() );
4912
4913                 //fill it and select it
4914                 isOk = _documentModel->setPropagation( iPropagation, iLaw, way );
4915                 if ( !isOk ){
4916                         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
4917                         return false;
4918                 }
4919
4920                 result = meshModel->mapFromSource(iPropagation);
4921         }
4922
4923         return true;
4924 }
4925
4926
4927 // ------------------------- ComputeMeshDialog ----------------------------------
4928
4929 // ============================================================== Constructeur
4930
4931 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4932                                                                 HexaBaseDialog(parent, editmode, f)
4933 {
4934         _helpFileName = "gui_mesh.html";
4935         setWindowTitle( tr("Compute mesh") );
4936         QVBoxLayout* layout = new QVBoxLayout;
4937         setLayout(layout);
4938
4939         QHBoxLayout* up   = new QHBoxLayout;
4940         QHBoxLayout* down = new QHBoxLayout;
4941
4942         layout->addLayout(up);
4943         layout->addLayout(down);
4944
4945         QVBoxLayout* vlg = new QVBoxLayout;
4946         QVBoxLayout* vld = new QVBoxLayout;
4947
4948         up->addLayout(vlg);
4949         up->addLayout(vld);
4950
4951         vlg->addWidget(new QLabel("Name"));
4952         vlg->addWidget(new QLabel("Dimension"));
4953         vlg->addWidget(new QLabel("Container"));
4954
4955         _name = new QLineEdit("Mesh");
4956         _dim  = new QSpinBox();
4957         _fact = new QLineEdit("FactoryServer");
4958
4959         vld->addWidget(_name);
4960         vld->addWidget(_dim);
4961         vld->addWidget(_fact);
4962
4963         _dim->setRange(1, 3);
4964         _dim->setValue(3);
4965
4966         _initWidget(editmode);
4967
4968 }
4969
4970 // ============================================================== Destructeur
4971 ComputeMeshDialog::~ComputeMeshDialog()
4972 {
4973 }
4974
4975
4976 // ============================================================== _initInputWidget
4977 void ComputeMeshDialog::_initInputWidget( Mode editmode )
4978 {
4979 }
4980
4981 // ============================================================== setDocumentModel
4982 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
4983 {
4984         HexaBaseDialog::setDocumentModel(m);
4985         _name->setText(_documentModel->getName());
4986 }
4987
4988 // ============================================================== clear
4989 void ComputeMeshDialog::clear()
4990 {
4991 }
4992
4993 // ============================================================== apply
4994 bool ComputeMeshDialog::apply(QModelIndex& result)
4995 {
4996         SUIT_OverrideCursor wc;
4997
4998         QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
4999                                                                   .arg( _name->text() )
5000                                                                   .arg( _documentModel->documentEntry() )
5001                                                                   .arg( _dim->value() )
5002                                                                   .arg( _fact->text() );
5003         //std::cout << "command: " << command.toStdString() << std::endl;
5004
5005         SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5006         PyConsole_Console* pyConsole = app->pythonConsole();
5007
5008         if ( pyConsole )
5009                 pyConsole->exec( command );
5010         else
5011                 return false;
5012
5013         //   clear();
5014         return true;
5015 }
5016
5017 // void  ComputeMeshDialog::accept() {
5018 //     _disallowSelection();
5019 //     QDialog::accept();
5020 //
5021 //     QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%1\", \"%2\", %3, \"%4\")")
5022 //       .arg( _name->text() )
5023 //       .arg( _documentModel->documentEntry() )
5024 //       .arg( _dim->value() )
5025 //       .arg( _fact->text() );
5026 //     std::cout << "command: " << command.toStdString() << std::endl;
5027 //
5028 //     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5029 //     PyConsole_Console* pyConsole = app->pythonConsole();
5030 //
5031 //     if ( pyConsole ) pyConsole->exec( command );
5032 // }
5033
5034 // void ComputeMeshDialog::reject() {
5035 //     _disallowSelection();
5036 //     QDialog::reject();
5037 // }
5038
5039
5040
5041 // ------------------------- ReplaceHexaDialog ----------------------------------
5042
5043 // ============================================================== Constructeur
5044
5045 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5046                                                                 HexaBaseDialog(parent, editmode, f)
5047 {
5048         _helpFileName = "gui_replace_hexa.html";
5049         setupUi( this );
5050         _initWidget(editmode);
5051         setFocusProxy( quads_lw );
5052 }
5053
5054 // ============================================================== Destructeur
5055 ReplaceHexaDialog::~ReplaceHexaDialog()
5056 {
5057 }
5058
5059 // ============================================================== _initInputWidget
5060 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5061 {
5062         QRegExp rx("");
5063         QValidator *validator = new QRegExpValidator(rx, this);
5064
5065         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
5066         installEventFilter(this);
5067
5068         c1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5069         c2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5070         c3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5071
5072         p1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5073         p2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5074         p3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5075
5076         c1_le->installEventFilter(this);
5077         c2_le->installEventFilter(this);
5078         c3_le->installEventFilter(this);
5079
5080         p1_le->installEventFilter(this);
5081         p2_le->installEventFilter(this);
5082         p3_le->installEventFilter(this);
5083
5084         quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
5085         quads_lw->installEventFilter(this);
5086
5087         if ( editmode == NEW_MODE ){
5088                 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5089                 delQuadShortcut->setContext( Qt::WidgetShortcut );
5090
5091                 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5092                 connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5093         }
5094
5095         connect(quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()));
5096 }
5097
5098 // ============================================================== clear
5099 void ReplaceHexaDialog::clear()
5100 {
5101 }
5102
5103 // ============================================================== updateButtonBox
5104 void ReplaceHexaDialog::updateButtonBox()
5105 {
5106         int nbQuad = quads_lw->count();
5107
5108         if ( nbQuad > 0 ){
5109                 //_applyCloseButton->setEnabled(true);
5110                 _applyButton->setEnabled(true);
5111         } else {
5112                 //_applyCloseButton->setEnabled(false);
5113                 _applyButton->setEnabled(false);
5114         }
5115 }
5116
5117 // ============================================================== deleteQuadItem
5118 void ReplaceHexaDialog::deleteQuadItem()
5119 {
5120         delete quads_lw->currentItem();
5121         updateButtonBox();
5122 }
5123
5124 // ============================================================== apply
5125 bool ReplaceHexaDialog::apply(QModelIndex& result)
5126 {
5127         SUIT_OverrideCursor wc;
5128         if ( !_documentModel ) return false;
5129         if ( !_patternDataSelectionModel ) return false;
5130         if ( !_patternBuilderSelectionModel ) return false;
5131         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
5132         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
5133         if ( !patternDataModel )    return false;
5134         if ( !patternBuilderModel ) return false;
5135         _currentObj = NULL;
5136
5137         QModelIndex ielts; //result
5138
5139         QListWidgetItem* item = NULL;
5140         QModelIndexList iquads;
5141         QModelIndex     iquad;
5142         for ( int r = 0; r < quads_lw->count(); ++r){
5143                 item = quads_lw->item(r);
5144                 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5145                 //std::cout << "iquad => " << iquad.data().toString().toStdString() << std::endl;
5146                 if ( iquad.isValid() )
5147                         iquads << iquad;
5148         }
5149
5150         QModelIndex ic1 = patternDataModel->mapToSource( _index[c1_le] );
5151         QModelIndex ic2 = patternDataModel->mapToSource( _index[c2_le] );
5152         QModelIndex ic3 = patternDataModel->mapToSource( _index[c3_le] );
5153
5154         QModelIndex ip1 = patternDataModel->mapToSource( _index[p1_le] );
5155         QModelIndex ip2 = patternDataModel->mapToSource( _index[p2_le] );
5156         QModelIndex ip3 = patternDataModel->mapToSource( _index[p3_le] );
5157
5158         //   std::cout << "nbHexa => " << nbHexa << std::endl;
5159
5160         if ( ic1.isValid() && ic2.isValid() && ic3.isValid()
5161                         && ip1.isValid() && ip2.isValid() && ip3.isValid() ){
5162                 ielts = _documentModel->replace( iquads,
5163                                 ip1, ic1,
5164                                 ip2, ic2,
5165                                 ip3, ic3 );
5166         }
5167
5168         if ( !ielts.isValid() ){
5169                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) );
5170                 return false;
5171         }
5172         _value  = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5173
5174         QString newName = name_le->text();
5175         if ( !newName.isEmpty() )/*{*/
5176                 _documentModel->setName( ielts, newName );
5177
5178         result = patternBuilderModel->mapFromSource(ielts);
5179
5180         return true;
5181 }
5182
5183
5184
5185
5186 // ------------------------- QuadRevolutionDialog ----------------------------------
5187
5188 // ============================================================== Constructeur
5189
5190 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5191                                                                 HexaBaseDialog(parent, editmode, f)
5192 {
5193         _helpFileName = "gui_quad_revolution.html";
5194         setupUi( this );
5195         _initWidget(editmode);
5196         setFocusProxy( quads_lw );
5197 }
5198
5199 // ============================================================== Destructeur
5200 QuadRevolutionDialog::~QuadRevolutionDialog()
5201 {
5202 }
5203
5204 // ============================================================== _initInputWidget
5205 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
5206 {
5207         QRegExp rx("");
5208         QValidator *validator = new QRegExpValidator(rx, this);
5209
5210         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
5211         installEventFilter(this);
5212
5213         center_pt_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5214         axis_vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5215         quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
5216
5217         center_pt_le->setValidator( validator );
5218         axis_vec_le->setValidator( validator );
5219         //   quads_lw->setValidator( validator );
5220
5221         center_pt_le->installEventFilter(this);
5222         axis_vec_le->installEventFilter(this);
5223         quads_lw->installEventFilter(this);
5224
5225         if ( editmode == NEW_MODE ){
5226                 angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
5227                 angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
5228
5229                 QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5230                 delQuadShortcut->setContext( Qt::WidgetShortcut );
5231                 connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
5232                 connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
5233                 connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
5234                 //     connect(clear_pb, SIGNAL(clicked()), this, SLOT(clearQuads()));
5235         }
5236
5237         connect(quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()));
5238 }
5239
5240 // ============================================================== clear
5241 void QuadRevolutionDialog::clear()
5242 {
5243 }
5244
5245
5246 // ============================================================== updateButtonBox
5247 void QuadRevolutionDialog::updateButtonBox() //CS_TODO? : check center, axis
5248 {
5249         int nbQuads  = quads_lw->count();
5250         int nbAngles = angles_lw->count();
5251
5252         if ( nbQuads>0 && nbAngles> 0 ){
5253                 //_applyCloseButton->setEnabled(true);
5254                 _applyButton->setEnabled(true);
5255         } else {
5256                 //_applyCloseButton->setEnabled(false);
5257                 _applyButton->setEnabled(false);
5258         }
5259 }
5260
5261
5262 // ============================================================== addAngleItem
5263 void QuadRevolutionDialog::addAngleItem() //CS_TODO
5264 {
5265         QListWidgetItem* previousItem = angles_lw->currentItem();
5266         QListWidgetItem* newItem      = new QListWidgetItem();
5267
5268         double defaultValue = 0.;
5269         if ( previousItem )
5270                 defaultValue =  previousItem->data(Qt::EditRole).toDouble();
5271
5272         newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
5273         newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
5274         angles_lw->addItem(newItem);
5275
5276         updateButtonBox();
5277 }
5278
5279 // ============================================================== delAngleItem
5280 void QuadRevolutionDialog::delAngleItem()
5281 {
5282         delete angles_lw->currentItem();
5283         updateButtonBox();
5284 }
5285
5286 // ============================================================== delQuadItem
5287 void QuadRevolutionDialog::delQuadItem()
5288 {
5289         delete quads_lw->currentItem();
5290         updateButtonBox();
5291 }
5292
5293 // ============================================================== apply
5294 bool QuadRevolutionDialog::apply(QModelIndex& result)
5295 {
5296         SUIT_OverrideCursor wc;
5297         if ( !_documentModel ) return false;
5298         if ( !_patternDataSelectionModel )    return false;
5299         if ( !_patternBuilderSelectionModel ) return false;
5300         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
5301         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
5302         if ( !patternDataModel )    return false;
5303         if ( !patternBuilderModel ) return false;
5304         _currentObj = NULL;
5305
5306         QModelIndex ielts; //result
5307         QListWidgetItem* item = NULL;
5308
5309         QModelIndexList istartquads;
5310         QModelIndex     iquad;
5311         for ( int r = 0; r < quads_lw->count(); ++r){
5312                 item = quads_lw->item(r);
5313                 iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5314                 if ( iquad.isValid() )
5315                         istartquads << iquad;
5316         }
5317
5318         QModelIndex icenter_pt = patternDataModel->mapToSource( _index[center_pt_le] );
5319         QModelIndex iaxis_vec  = patternBuilderModel->mapToSource( _index[axis_vec_le] );
5320
5321         QList<double> angles;
5322         for ( int r = 0; r < angles_lw->count(); ++r){
5323                 item = angles_lw->item(r);
5324                 angles << item->data(Qt::EditRole).toDouble();
5325         }
5326
5327         if ( icenter_pt.isValid() && iaxis_vec.isValid() ){
5328                 ielts = _documentModel->revolutionQuads( istartquads, icenter_pt, iaxis_vec, angles );
5329         }
5330
5331         if ( !ielts.isValid() ){
5332                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) );
5333                 return false;
5334         }
5335         _value  = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5336
5337         QString newName = name_le->text();
5338         if ( !newName.isEmpty() )/*{*/
5339                 _documentModel->setName( ielts, newName );
5340
5341         result = patternBuilderModel->mapFromSource(ielts);
5342
5343         return true;
5344 }
5345
5346
5347
5348 // ------------------------- QuadRevolutionDialog ----------------------------------
5349
5350 // ============================================================== Constructeur
5351
5352 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5353                                                                 HexaBaseDialog(parent, editmode, f)
5354 {
5355         _helpFileName = "gui_hemisphere.html";
5356         setupUi( this );
5357         _initWidget(editmode);
5358 }
5359
5360 // ============================================================== Destructeur
5361 MakeHemiSphereDialog::~MakeHemiSphereDialog()
5362 {
5363 }
5364
5365 // ============================================================== _initInputWidget
5366 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
5367 {
5368         QRegExp rx("");
5369         QValidator *validator = new QRegExpValidator(rx, this);
5370
5371         setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
5372         installEventFilter(this);
5373
5374         sphere_center_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5375         cross_pt_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5376         hole_axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5377         cross_vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5378         radial_vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5379
5380         sphere_center_le->setValidator( validator );
5381         cross_pt_le->setValidator( validator );
5382         hole_axis_le->setValidator( validator );
5383         cross_vec_le->setValidator( validator );
5384         radial_vec_le->setValidator( validator );
5385
5386
5387         sphere_center_le->installEventFilter(this);
5388         cross_pt_le->installEventFilter(this);
5389         hole_axis_le->installEventFilter(this);
5390         cross_vec_le->installEventFilter(this);
5391         radial_vec_le->installEventFilter(this);
5392 }
5393
5394 // ============================================================== clear
5395 void MakeHemiSphereDialog::clear()
5396 {
5397 }
5398
5399 // ============================================================== apply
5400 bool MakeHemiSphereDialog::apply(QModelIndex& result)
5401 {
5402         SUIT_OverrideCursor wc;
5403         if ( !_documentModel ) return false;
5404         if ( !_patternBuilderSelectionModel ) return false;
5405         if ( !_patternDataSelectionModel )    return false;
5406         const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
5407         const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
5408         if ( !patternBuilderModel ) return false;
5409         if ( !patternDataModel )    return false;
5410         _currentObj = NULL;
5411
5412         QModelIndex iElts;
5413         QModelIndex icenter = patternDataModel->mapToSource( _index[sphere_center_le] );
5414         QModelIndex iplorig = patternDataModel->mapToSource( _index[cross_pt_le] );
5415         QModelIndex ivecx  = patternBuilderModel->mapToSource( _index[radial_vec_le] );
5416         QModelIndex ivecz  = patternBuilderModel->mapToSource( _index[hole_axis_le] );
5417
5418         double radext  = sphere_radext_spb->value();
5419         double radhole = hole_rad_spb->value();
5420
5421         int nrad  = ngrid_rad_spb->value();
5422         int nang  = ngrid_ang_spb->value();
5423         int nhaut = ngrid_height_spb->value();
5424
5425
5426         if ( icenter.isValid() && ivecx.isValid() && ivecz.isValid() && iplorig.isValid() ){
5427                 if ( sphere_rind_cb->isChecked() ){ // rind
5428                         double radint  = sphere_radint_spb->value();
5429                         if ( radial_partial_cb->isChecked() ){
5430                                 double angle = radial_angle_spb->value();
5431                                 iElts = _documentModel->makePartRind( icenter, ivecx, ivecz,
5432                                                 radext, radint, radhole,
5433                                                 iplorig,      angle,
5434                                                 nrad, nang, nhaut );
5435                         } else {
5436                                 iElts = _documentModel->makeRind( icenter,
5437                                                 ivecx, ivecz,
5438                                                 radext, radint, radhole,
5439                                                 iplorig,
5440                                                 nrad, nang, nhaut );
5441                         }
5442                 } else { // sphere
5443                         if ( radial_partial_cb->isChecked() ){
5444                                 double angle = radial_angle_spb->value();
5445                                 iElts = _documentModel->makePartSphere( icenter, ivecx, ivecz,
5446                                                 radext, radhole,
5447                                                 iplorig, angle,
5448                                                 nrad, nang, nhaut );
5449                         } else {
5450                                 iElts = _documentModel->makeSphere( icenter,
5451                                                 ivecx, ivecz,
5452                                                 radext, radhole,
5453                                                 iplorig,
5454                                                 nrad, nang, nhaut );
5455                         }
5456                 }
5457         }
5458
5459
5460         if ( !iElts.isValid() ){
5461                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) );
5462                 return false;
5463         }
5464         _value  = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5465
5466         QString newName = name_le->text();
5467         if ( !newName.isEmpty() )/*{*/
5468                 _documentModel->setName( iElts, newName );
5469
5470         result = patternBuilderModel->mapFromSource(iElts);
5471
5472         return true;
5473 }
5474 // ==============================================================
5475
5476
5477 // MakeRindDialog::MakeRindDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5478 // HexaBaseDialog(parent, editmode, f)
5479 // {
5480 // //   _helpFileName()
5481 //   setupUi( this );
5482 //   setWindowTitle( tr("MAKE RIND") );
5483 //
5484 //   if ( editmode == NEW_MODE ){
5485 //     _initButtonBox( editmode );
5486 //
5487 //     //selection management
5488 //     _vertexLineEdits << center_le << plorig_le;
5489 //     _vectorLineEdits << vx_le << vz_le;
5490 //
5491 //     center_le->installEventFilter(this);
5492 //     plorig_le->installEventFilter(this);
5493 //     vx_le->installEventFilter(this);
5494 //     vz_le->installEventFilter(this);
5495 //   }
5496 // }
5497 //
5498 //
5499 // MakeRindDialog::~MakeRindDialog()
5500 // {
5501 // }
5502 //
5503 //
5504 //
5505 // bool MakeRindDialog::apply(QModelIndex& result)
5506 // {
5507 //   SUIT_OverrideCursor wc;
5508 //   if ( !_documentModel ) return false;
5509 //   if ( !_patternBuilderSelectionModel ) return false;
5510 //   if ( !_patternDataSelectionModel )    return false;
5511 //   const PatternBuilderModel* patternBuilderModel = dynamic_cast<const PatternBuilderModel*>( _patternBuilderSelectionModel->model() );
5512 //   const PatternDataModel* patternDataModel = dynamic_cast<const PatternDataModel*>( _patternDataSelectionModel->model() );
5513 //   if ( !patternBuilderModel ) return false;
5514 //   if ( !patternDataModel )    return false;
5515 //
5516 //   QModelIndex iElts;
5517 //   QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
5518 //   QModelIndex iplorig = patternDataModel->mapToSource( _index[plorig_le] );
5519 //   QModelIndex ivecx  = patternBuilderModel->mapToSource( _index[vx_le] );
5520 //   QModelIndex ivecz  = patternBuilderModel->mapToSource( _index[vz_le] );
5521 //
5522 //   double radext = radext_spb->value();
5523 //   double radint = radint_spb->value();
5524 //   double radhole = radhole_spb->value();
5525 //
5526 //   int nrad = nrad_spb->value();
5527 //   int nang = nang_spb->value();
5528 //   int nhaut = nhaut_spb->value();
5529 //
5530 //   if ( icenter.isValid() && ivecx.isValid() && ivecz.isValid() && iplorig.isValid() ){
5531 //     if ( partial_cb->isChecked() ){
5532 //       double angle = angle_spb->value(); // Part Rind only
5533 //       iElts = _documentModel->makePartRind( icenter, ivecx, ivecz,
5534 //                                         radext, radint, radhole,
5535 //                                         iplorig,      angle,
5536 //                                         nrad, nang, nhaut );
5537 //     } else {
5538 //       iElts = _documentModel->makeRind( icenter,
5539 //                                         ivecx, ivecz,
5540 //                                         radext, radint, radhole,
5541 //                                         iplorig,
5542 //                                         nrad, nang, nhaut );
5543 //     }
5544 //   }
5545 //
5546 //   if ( !iElts.isValid() ){
5547 //     SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) );
5548 //     return false;
5549 //   }
5550 //
5551 //   QString newName = name_le->text();
5552 //   if (!newName.isEmpty()) _documentModel->setName( iElts, newName );
5553 //
5554 //   return true;
5555 // }
5556
5557 // QVariant v = lineEdit->property("index");
5558 //           if ( v.isValid() ){
5559 //             MESSAGE("*  get index ... " );
5560 //             QModelIndex i = v.value<QModelIndex>();
5561 //             _selectionMutex = true;
5562 //             _patternDataSelectionModel->select( i, QItemSelectionModel::Clear );
5563 //             _patternDataSelectionModel->select( i, QItemSelectionModel::Select );
5564 //             _selectionMutex = false;
5565 //           }