]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_DocumentPanel.cxx
Salome HOME
9c5ef829ce710419596ad9747b1094760e985bf6
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentPanel.cxx
1 // Copyright (C) 2009-2013  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_VtkDocumentGraphicView.hxx"
23 #include "HEXABLOCKGUI_OccGraphicView.hxx"
24 #include "HEXABLOCKGUI_SalomeTools.hxx"
25
26 #include "Hex.hxx"
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_ViewManager.h>
40
41 #include <TopExp.hxx>
42 #include <TopExp_Explorer.hxx>
43 #include <TopoDS_Iterator.hxx>
44 #include <TopTools_MapOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
47
48 #include <SUIT_Session.h>
49 #include <SUIT_Desktop.h>
50 #include <SUIT_OverrideCursor.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_Session.h>
53 #include "SVTK_Selection.h"
54 #include <SVTK_ViewModel.h>
55 #include <VTKViewer_ViewModel.h>
56 #include <SVTK_View.h>
57
58 #include <SUIT_ResourceMgr.h>
59
60 #include <GEOMBase.h>
61
62 #define BUTTON_BOX_MIN_WIDTH 5
63 #define VERTEX_COORD_MIN -1000000
64 #define VERTEX_COORD_MAX  1000000
65 #define SPINBOX_ANGLE_MAX 360
66 #define SPINBOX_DOUBLE_MAX 1000000000
67 #define SPINBOX_POSITIVE_DOUBLE_MIN 0
68 #define NB_DECIMALS 6
69
70
71 using namespace std;
72 using namespace HEXABLOCK::GUI;
73
74
75 Q_DECLARE_METATYPE(HEXABLOCK::GUI::HexaTreeRole);
76 Q_DECLARE_METATYPE(DocumentModel::GeomObj);
77 Q_DECLARE_METATYPE(TopAbs_ShapeEnum);
78 Q_DECLARE_METATYPE(TopoDS_Shape);
79
80 //General SpinBox Delegate
81 class HexaDoubleSpinBoxDelegate : public QStyledItemDelegate  {
82 public:
83     HexaDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
84
85     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
86             const QModelIndex &index) const{
87         QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
88         sb->setDecimals(NB_DECIMALS);
89         return sb;
90     }
91 };
92
93 //Angle SpinBox Delegate
94 class HexaAngleDoubleSpinBoxDelegate : public QStyledItemDelegate  {
95 public:
96     HexaAngleDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
97
98     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
99             const QModelIndex &index) const{
100         QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
101         sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
102         sb->setMaximum(SPINBOX_ANGLE_MAX);
103         sb->setDecimals(NB_DECIMALS);
104         return sb;
105     }
106 };
107
108
109 //Positive DoubleSpinBox Delegate (for heigth, radius, ...)
110 class HexaPositiveDoubleSpinBoxDelegate : public QStyledItemDelegate  {
111 public:
112     HexaPositiveDoubleSpinBoxDelegate(QObject *parent=0) : QStyledItemDelegate (parent){}
113
114     QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
115             const QModelIndex &index) const{
116         QDoubleSpinBox *sb = new QDoubleSpinBox( parent );
117         sb->setMinimum(SPINBOX_POSITIVE_DOUBLE_MIN);
118         /////// sb->setMaximum(1000000000000000); //10e15   Abu : Pb en 32 bits
119         sb->setMaximum(SPINBOX_DOUBLE_MAX);       //10e9
120         sb->setDecimals(NB_DECIMALS);
121         return sb;
122     }
123 };
124
125 // ======================================================== Constructeur
126 HexaBaseDialog::HexaBaseDialog( QWidget * parent, Mode editmode, Qt::WindowFlags f ):
127                           QDialog(parent, f),
128                           _editMode( editmode ),
129                           _currentObj(NULL),
130                           _applyButton(NULL),
131                           debugEdgeAssoc(false),
132                           autoFocusSwitch(true)
133 {
134     _strHexaWidgetType[VERTEX_TREE] = tr( "VERTEX" );
135     _strHexaWidgetType[EDGE_TREE]   = tr( "EDGE" );
136     _strHexaWidgetType[QUAD_TREE]   = tr( "QUAD" );
137     _strHexaWidgetType[HEXA_TREE]   = tr( "HEXA" );
138
139     _strHexaWidgetType[VECTOR_TREE]   = tr( "VECTOR" );
140     _strHexaWidgetType[CYLINDER_TREE] = tr( "CYLINDER" );
141     _strHexaWidgetType[PIPE_TREE]     = tr( "PIPE" );
142     _strHexaWidgetType[ELEMENTS_TREE] = tr( "ELEMENTS" );
143     _strHexaWidgetType[CROSSELEMENTS_TREE]= tr( "CROSSELEMENTS" );
144
145     //geom
146     _strHexaWidgetType[GEOMSHAPE_TREE] = tr( "GEOMSHAPE" );
147     _strHexaWidgetType[GEOMPOINT_TREE]   = tr( "GEOMPOINT" );
148     _strHexaWidgetType[GEOMEDGE_TREE]   = tr( "GEOMEDGE" );
149     _strHexaWidgetType[GEOMFACE_TREE]   = tr( "GEOMFACE" );
150
151
152     _strHexaWidgetType[GROUP_TREE]      = tr( "GROUP" );
153     _strHexaWidgetType[LAW_TREE]        = tr( "LAW" );
154     _strHexaWidgetType[PROPAGATION_TREE]= tr( "PROPAGATION" );
155 }
156
157 // ============================================================= getIndexList
158 QModelIndexList HexaBaseDialog::getIndexList(QListWidget* itemsList, bool mapToSource)
159 {
160     QModelIndexList iItems;
161     QModelIndex     iItem;
162     QListWidgetItem* item = NULL;
163
164     const PatternDataModel*    patternDataModel = getPatternDataModel();
165     if (patternDataModel == NULL || itemsList == NULL) return iItems;
166
167     unsigned int nbItems = itemsList->count();
168     for ( int r = 0; r < nbItems; ++r){
169         item = itemsList->item(r);
170         if (mapToSource)
171             iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
172         else
173             iItem = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
174         iItems << iItem;
175     }
176     return iItems;
177 }
178
179 // ============================================================= lockSizeToSizeHint
180 void HexaBaseDialog::lockSizeToSizeHint()
181 {
182     setMaximumHeight(sizeHint().height());
183     //   setMaximumWidth(sizeHint().width());
184     //  setMinimumHeight(sizeHint().height());
185     //  setMinimumWidth(sizeHint().width());
186 }
187
188 // ============================================================= unlockSizeModification
189 void HexaBaseDialog::unlockSizeModification()
190 {
191     setMaximumHeight(MAX_HEIGHT);
192     //   setMaximumWidth(MAX_WIDTH);
193     //  setMinimumHeight(MIN_HEIGHT);
194     //  setMinimumWidth(MIN_WIDTH);
195 }
196
197 // ============================================================= resetSizeAndShow
198 void HexaBaseDialog::resetSizeAndShow(QDockWidget* parent)
199 {
200     //force the dialog to fit its contain
201     lockSizeToSizeHint();
202
203     //set the dialog in the dockwidget
204     parent->setWidget(this);
205     parent->setWindowTitle(windowTitle());
206     parent->setVisible(true);
207     show();
208
209     unlockSizeModification();
210 }
211
212 QString HexaBaseDialog::getErrorMsg()
213 {
214     DocumentModel* docModel = getDocumentModel();
215     Hex::Hex* hex = docModel->getHexaRoot();
216     int nbErrorMsg = hex->sizeofMessage();
217     QString msg, newLine = "\n";
218     for (int i = 1; i < nbErrorMsg; ++i)
219         msg +=  newLine + hex->getMessageLine(i);
220
221     return msg;
222 }
223
224 //unlink the widget from the model
225 void HexaBaseDialog::modelUnregister(QWidget* widget)
226 {
227     if (widget == NULL) return;
228
229     if (widget->property("GeomWidgetType").isValid())
230     {
231         widget->setProperty("GeomObj", QVariant());
232         widget->setProperty("TopoDS_Shape", QVariant());
233     }
234
235     widget->setProperty("HexaData", QVariant());
236     widget->setProperty("QModelIndex",  QVariant());
237     _index[widget] = QModelIndex();
238
239     HexaBaseDialog* diag = dynamic_cast<HexaBaseDialog*>(widget);
240     if (diag != NULL)
241         diag->clearWidgetsIndexes();
242 }
243
244 // ============================================================= connectDocumentGraphicView
245 void HexaBaseDialog::connectDocumentGraphicView(VtkDocumentGraphicView* docGView)
246 {
247     if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
248     if (docGView == NULL) return;
249
250     disconnectDocumentGraphicView(docGView); //to avoid double connect
251
252     //Connect the graphic view and its model to the dialog box
253     connect( docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
254             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
255     connect( docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
256             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
257     connect( docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
258             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
259     connect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
260             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
261     connect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
262             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
263 }
264
265 // ============================================================= disconnectDocumentGraphicView
266 void HexaBaseDialog::disconnectDocumentGraphicView(VtkDocumentGraphicView* docGView)
267 {
268     if (docGView == NULL) docGView = HEXABLOCKGUI::currentDocGView;
269     if (docGView == NULL) return;
270
271
272     //Disconnect graphic view signals form the dialog box
273     disconnect(docGView->getPatternDataSelectionModel(), SIGNAL( selectionChanged ( const QItemSelection &, const QItemSelection &) ),
274             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
275
276     disconnect(docGView->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
277             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
278
279     disconnect(docGView->getPatternGeomSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
280             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
281
282     disconnect( docGView->getGroupsSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
283             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
284
285     disconnect( docGView->getMeshSelectionModel(), SIGNAL( selectionChanged( const QItemSelection &, const QItemSelection &) ),
286             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
287 }
288
289 // ============================================================= onCurrentSelectionChanged
290 void HexaBaseDialog::onCurrentSelectionChanged()
291 {
292     highlightSelectedAssocs();
293 }
294
295 void HexaBaseDialog::clearCurrentObjectFocus()
296 {
297     QWidget* currentWidget = dynamic_cast<QWidget*>(_currentObj);
298     if (currentWidget != NULL)
299     {
300         currentWidget->clearFocus();
301         _currentObj = NULL;
302     }
303 }
304
305 // ============================================================= setFocusToNextField
306 //Sets focus to the next field of the current object
307 void HexaBaseDialog::setFocusToNextField()
308 {
309     activateWindow ();
310
311     if (!HEXABLOCKGUI::assocInProgress && autoFocusSwitch)
312     {
313         _highlightWidget(_currentObj, Qt::white);
314         focusNextChild ();
315     }
316 }
317
318 // ============================================================== _initButtonBox
319 QGroupBox* HexaBaseDialog::_initButtonBox( Mode editmode )
320 {
321     if ( editmode == INFO_MODE )
322         return NULL;
323
324     QGroupBox* buttonBox = new QGroupBox();
325     buttonBox->setMinimumWidth(BUTTON_BOX_MIN_WIDTH);
326     buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
327     QHBoxLayout* buttonsHLayout = new QHBoxLayout();
328     _applyButton      = new QPushButton(tr("Apply"));
329     QPushButton* closeButton = new QPushButton(tr("Close"));
330     QPushButton* helpButton  = new QPushButton(tr("Help"));
331
332     connect( _applyButton, SIGNAL(clicked()), this, SLOT(apply()), Qt::UniqueConnection );
333     connect( closeButton, SIGNAL(clicked()), this, SLOT(close()), Qt::UniqueConnection );
334     connect( helpButton, SIGNAL(clicked()), this, SLOT(onHelpRequested()), Qt::UniqueConnection );
335
336     buttonsHLayout->addWidget( _applyButton );
337     buttonsHLayout->addWidget( closeButton );
338     buttonsHLayout->addStretch(1);
339     buttonsHLayout->addWidget( helpButton );
340     buttonBox->setLayout(buttonsHLayout);
341     layout()->addWidget(buttonBox);
342     buttonBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
343     return buttonBox;
344 }
345
346 // ============================================================== _initWidget
347 void HexaBaseDialog::_initWidget( Mode editmode )
348 {
349     _initInputWidget( editmode );
350     _initButtonBox( editmode );
351 }
352
353 // ============================================================== apply
354 bool HexaBaseDialog::apply()
355 {
356     QModelIndex iNew;
357     bool applied = apply(iNew);
358     if ( applied )
359     {
360         _selectAndHighlight( iNew );
361         if (!HEXABLOCKGUI::assocInProgress)
362             getDocumentModel()->updateGeomTree();
363     }
364     return applied;
365 }
366
367 void HexaBaseDialog::clearVTKSelection()
368 {
369     HEXABLOCKGUI::currentDocGView->clearSelection();
370     _highlightWidget(_currentObj, Qt::white);
371 }
372
373 void HexaBaseDialog::clearOCCSelection()
374 {
375         HEXABLOCKGUI::currentOccGView->clearSelection();
376 }
377
378 // ============================================================== close
379 void HexaBaseDialog::close()
380 {
381     //reset the data selection pattern (forget all selections of the current context)
382     getPatternDataSelectionModel()->reset();
383     getPatternBuilderSelectionModel()->reset();
384     getPatternGeomSelectionModel()->reset();
385
386     //Clear vtk selection
387         clearVTKSelection();
388
389     //Clear occ selection
390         clearOCCSelection();
391
392     //Close the dialog box
393     if (parentWidget())
394         parentWidget()->close();
395 }
396
397 // ============================================================== onHelpRequested
398 void HexaBaseDialog::onHelpRequested()
399 {
400     LightApp_Application* app = (LightApp_Application*)( SUIT_Session::session()->activeApplication() );
401     if ( app )
402         app->onHelpContextModule( "HEXABLOCK", _helpFileName );
403     else {
404         QString platform;
405 #ifdef WIN32
406         platform = "winapplication";
407 #else
408         platform = "application";
409 #endif
410
411         SUIT_MessageBox::warning( 0, QObject::tr( "WRN_WARNING" ),
412                 QObject::tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
413                 arg( app->resourceMgr()->stringValue( "ExternalBrowser", platform ) ).arg( _helpFileName ),
414                 QObject::tr( "BUT_OK" ) );
415     }
416 }
417
418 // ============================================================== highlightSelectedAssocs
419 void HexaBaseDialog::highlightSelectedAssocs()
420 {
421     QMultiMap<QString, int> geomAssocs = getAssocsGEOM();
422     QModelIndexList vtkAssocs = getAssocsVTK();
423
424 //    HEXABLOCKGUI::selectionMgr()->clearSelected();
425     //highlight geom selected elts
426     if (geomAssocs.size() > 0)
427         HEXABLOCKGUI::currentOccGView->highlight(geomAssocs, false);
428
429     //highlight vtk selected elts
430     if (!vtkAssocs.isEmpty())
431         HEXABLOCKGUI::currentDocGView->highlight(vtkAssocs);
432 }
433
434 // ============================================================== refreshHighlight
435 void HexaBaseDialog::refreshHighlight()
436 {
437     HEXABLOCKGUI::selectionMgr()->clearSelected();
438     highlightSelectedAssocs();
439 }
440
441 // ============================================================== getObjectViewType
442 HEXABLOCKGUI::ViewType HexaBaseDialog::getObjectViewType(QObject* obj)
443 {
444     if (obj == NULL)
445         return HEXABLOCKGUI::UNKNOWN;
446
447     QVariant v = obj->property("GeomWidgetType");
448     if ( v.isValid() )
449         return HEXABLOCKGUI::OCC;
450
451     v  = obj->property("HexaWidgetType");
452     if ( v.isValid() )
453         return HEXABLOCKGUI::VTK;
454
455     return HEXABLOCKGUI::UNKNOWN;
456 }
457
458 // ============================================================== _selectAndHighlight
459 void HexaBaseDialog::_selectAndHighlight( const QModelIndex& i )
460 {
461     if ( !i.isValid() ) return;
462     setProperty("QModelIndex",  QVariant::fromValue(i));
463     setFocus();
464 }
465
466 // ============================================================== _allowSelection
467 void HexaBaseDialog::_allowSelection()
468 {
469     if ( getDocumentModel() )
470         getDocumentModel()->disallowEdition();
471 }
472
473 // ============================================================== _disallowSelection
474 void HexaBaseDialog::_disallowSelection()
475 {
476     if ( getDocumentModel() ){
477         getDocumentModel()->allowEdition();
478     }
479     HEXABLOCKGUI::currentDocGView->setAllSelection();
480 }
481
482 // ============================================================== _allowVTKSelection
483 bool HexaBaseDialog::_allowVTKSelection( QObject* obj )
484 {
485
486     bool isOk = false;
487
488     QVariant v  = obj->property("HexaWidgetType");
489     HexaWidgetType wType = v.value<HexaWidgetType>();
490
491     switch (wType){
492     case VERTEX_TREE:
493         HEXABLOCKGUI::currentDocGView->setVertexSelection(); isOk = true;
494         break;
495     case EDGE_TREE:
496         HEXABLOCKGUI::currentDocGView->setEdgeSelection(); isOk = true;
497         break;
498     case QUAD_TREE:
499         HEXABLOCKGUI::currentDocGView->setQuadSelection(); isOk = true;
500         break;
501     case HEXA_TREE:
502         HEXABLOCKGUI::currentDocGView->setHexaSelection(); isOk = true;
503         break;
504     default: HEXABLOCKGUI::currentDocGView->setAllSelection();
505     }
506     return isOk;
507 }
508
509 // ============================================================== _allowOCCSelection
510 bool HexaBaseDialog::_allowOCCSelection( QObject* obj )
511 {
512     QVariant v  = obj->property("GeomWidgetType");
513     GeomWidgetType wType = v.value<GeomWidgetType>();
514     HEXABLOCKGUI::currentOccGView->setSelectionMode(wType);
515
516     return true;
517 }
518
519 // ============================================================== _getSelector
520 QItemSelectionModel* HexaBaseDialog::_getSelector( QObject* obj )
521 {
522     QItemSelectionModel* selector = NULL;
523
524     HexaWidgetType wtype;
525     QVariant v  = obj->property("HexaWidgetType");
526     if ( !v.isValid() ) {
527         return NULL;
528     }
529
530     wtype = v.value<HexaWidgetType>();
531
532     switch (wtype){
533     case VERTEX_TREE:
534     case EDGE_TREE:
535     case QUAD_TREE:
536     case HEXA_TREE: selector = getPatternDataSelectionModel(); break;
537     case VECTOR_TREE:
538     case CYLINDER_TREE:
539     case PIPE_TREE:
540     case ELEMENTS_TREE:
541     case CROSSELEMENTS_TREE: selector = getPatternBuilderSelectionModel(); break;
542     case GEOMPOINT_TREE:
543     case GEOMEDGE_TREE:
544     case GEOMFACE_TREE: selector = getPatternGeomSelectionModel(); break;
545     case GROUP_TREE: selector = getGroupsSelectionModel(); break;
546     case LAW_TREE:
547     case PROPAGATION_TREE: selector = getMeshSelectionModel(); break;
548     default : ;
549     }
550
551     return selector;
552 }
553
554 DocumentModel::GeomObj* HexaBaseDialog::getGeomObj(const QModelIndex& index)
555 {
556     HEXA_NS::NewShape* aSh  = getDocumentModel()->getHexaPtr<HEXA_NS::NewShape*>(index);
557     DocumentModel::GeomObj* geomObj = NULL;
558     if (aSh != NULL)
559     {
560         geomObj = new DocumentModel::GeomObj;
561         geomObj->shapeName = aSh->getName();
562         geomObj->subId = QString::number(-1);
563     }
564     else
565     {
566         HEXA_NS::EltBase*  aSShElt = getDocumentModel()->getHexaPtr(index);
567         HEXA_NS::SubShape* aSSh = dynamic_cast<HEXA_NS::SubShape*>(aSShElt);
568         if (aSSh != NULL)
569         {
570             geomObj = new DocumentModel::GeomObj;
571             QString shapeName;
572             if (aSSh->getParentShape() != NULL)
573                 shapeName = aSSh->getParentShape()->getName();
574             geomObj->shapeName = shapeName;
575             geomObj->subId = QString::number(aSSh->getIdent());
576         }
577     }
578     return geomObj;
579 }
580
581 // ============================================================== _onSelectionChanged
582 /*
583  * Puts elements selected in the model (treeview) in the corresponding
584  * line edit widget (the one that has the focus) of the current dialog box.
585  */
586 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QLineEdit*  le )
587 {
588     QModelIndexList l = sel.indexes();
589     if ( l.count() == 0 ) return false;
590
591     // mono selection mode: we just get the first selected element
592     QModelIndex selected = l[0];
593
594     // we just return if the selection is not valid or the selection and the
595     // line content are the same
596     if ( !selected.isValid() || le->property("HexaData") == selected.data(HEXA_DATA_ROLE) )
597         return false;
598
599     // type of selection
600     int selType = selected.data(HEXA_TREE_ROLE).toInt();
601
602     // type of widget
603     QVariant v = le->property("HexaWidgetType");
604     if ( !v.isValid() ) return false;
605     HexaWidgetType wType = v.value<HexaWidgetType>();
606
607     // check selection compatibility between selection and widget
608     if ( selType != wType ){
609         SUIT_MessageBox::information( 0, tr("HEXA_INFO"),
610                 tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg(_strHexaWidgetType[wType]));
611         return false;
612     }
613     if (le->property("GeomWidgetType").isValid())
614     {
615         DocumentModel::GeomObj* geomObj = getGeomObj(selected);
616         if (geomObj != NULL)
617         {
618             le->setProperty("GeomObj", QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
619
620             DocumentModel* docModel = getDocumentModel();
621             QString objId =  geomObj->shapeName + "," + geomObj->subId;
622             HEXA_NS::SubShape* ssh = docModel->getGeomPtr(objId);
623             if (ssh != NULL)
624             {
625                 TopoDS_Shape shape = ssh->getShape();
626                 if (!shape.IsNull())
627                     le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(shape));
628             }
629             setCurrentGeomObj(geomObj);
630         }
631     }
632
633     //fill the lineEdit if selection is OK
634     le->setText( selected.data().toString() );// name
635     le->setProperty("QModelIndex",  QVariant::fromValue(selected));
636     le->setProperty("HexaData", selected.data(HEXA_DATA_ROLE));
637     _index[le] = selected;
638
639     QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(_currentObj);
640     if (selected.isValid() && lineEdit != NULL)
641         setFocusToNextField();
642
643     return true;
644 }
645
646 // ============================================================== _onSelectionChanged
647 /*
648  * Puts elements selected in the model (treeview) in the corresponding list widget
649  * of the current dialog box.
650  */
651 bool HexaBaseDialog::_onSelectionChanged( const QItemSelection& sel, QListWidget* lw )
652 {
653     QModelIndexList l = sel.indexes();
654
655     if ( l.count() == 0 ) return false;
656
657     //type of widget
658     QVariant v = lw->property("HexaWidgetType");
659     if ( !v.isValid() ) return false;
660     HexaWidgetType wType = v.value<HexaWidgetType>();
661
662     //fill the listWidget
663     QListWidgetItem* item = NULL;
664     int selType;
665     QString selName;
666     //   int maxSize = 8;
667     foreach( const QModelIndex& isel, l ){
668         //     if ( lw->count() == maxSize) break;
669         selType = isel.data(HEXA_TREE_ROLE).toInt();
670         if ( selType != wType ){ // check selection compatibility between selection and widget
671             SUIT_MessageBox::information( 0,
672                     tr("HEXA_INFO"),
673                     tr("%1: Bad type selected\nPlease select a %2.").arg(windowTitle()).arg( _strHexaWidgetType[wType]) );
674             return false;
675         }
676         // add selection to listWidget if selection is OK
677         selName = isel.data().toString();
678         QList<QListWidgetItem *> twice = lw->findItems( selName, Qt::MatchExactly);
679         if ( twice.count() == 0 ){
680             item = new QListWidgetItem( selName );
681             item->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(isel) );
682             item->setData(LW_DATA_ROLE, isel.data(HEXA_DATA_ROLE));
683             if (lw->property("GeomWidgetType").isValid())
684             {
685                 DocumentModel::GeomObj* geomObj = getGeomObj(isel);
686                 if (geomObj != NULL)
687                     item->setData(LW_ASSOC_ROLE, QVariant::fromValue<DocumentModel::GeomObj>(*geomObj));
688             }
689             lw->addItem(item);
690             updateButtonBox();
691         }
692     }
693     return true;
694 }
695
696 // ============================================================== onSelectionChanged
697 /*
698  * Puts elements selected in the model in the corresponding widget (list widget or line edit)
699  * of the current dialog box.
700  */
701 void HexaBaseDialog::onSelectionChanged( const QItemSelection& sel, const QItemSelection& unsel )
702 {
703     // * no edition for Info Dialogs
704     if ( _editMode == INFO_MODE )
705         return;
706
707     QLineEdit*   aLineEdit   = NULL;
708     QListWidget* aListWidget = NULL;
709
710     // * fill the lineedit with selection
711     aLineEdit = dynamic_cast<QLineEdit*>(_currentObj);
712     if ( aLineEdit)
713     {
714         _onSelectionChanged( sel, aLineEdit );
715         return;
716     }
717
718     // * fill the listWidget with selection
719     aListWidget = dynamic_cast<QListWidget*>(_currentObj);
720     if ( aListWidget)
721         _onSelectionChanged( sel, aListWidget );
722 }
723
724 // ============================================================== showEvent
725 void HexaBaseDialog::showEvent( QShowEvent * event )
726 {
727     if ( _editMode == INFO_MODE )
728         getDocumentModel()->allowEdition();
729     else
730         getDocumentModel()->disallowEdition();
731
732     //Connect to salome selection signals
733     if (HEXABLOCKGUI::selectionMgr() != NULL)
734     {
735         connect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
736                 this, SLOT(onCurrentSelectionChanged()), Qt::UniqueConnection );
737     }
738
739     //connect model selection signals
740     connectDocumentGraphicView();
741
742     QDialog::showEvent ( event );
743 }
744
745
746 // ============================================================== hideEvent
747 void HexaBaseDialog::hideEvent ( QHideEvent * event )
748 {
749     //Disconnection salome selection signals
750     if (HEXABLOCKGUI::selectionMgr() != NULL)
751     {
752         disconnect(  HEXABLOCKGUI::selectionMgr() , SIGNAL(currentSelectionChanged()),
753                 this, SLOT(onCurrentSelectionChanged()) );
754     }
755
756     //Disconnect vtk window activation signals
757 //    if (HEXABLOCKGUI::currentDocGView->getViewWindow() != NULL)
758 //        disconnect( HEXABLOCKGUI::currentDocGView->getViewWindow()->getViewManager(),
759 //                SIGNAL( activated(SUIT_ViewManager*) ),
760 //                this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
761
762     //Disconnect occ window activation signals
763 //    if (HEXABLOCKGUI::currentOccGView->getViewWindow() != NULL)
764 //        disconnect( HEXABLOCKGUI::currentOccGView->getViewWindow()->getViewManager(),
765 //                SIGNAL( activated(SUIT_ViewManager*) ),
766 //                this, SLOT( onWindowActivated(SUIT_ViewManager*) ) );
767
768     //Disconnect model selection signals
769     disconnectDocumentGraphicView();
770
771     getDocumentModel()->allowEdition();
772
773     QDialog::hideEvent( event );
774 }
775
776 // ============================================================== updateButtonBox
777 void HexaBaseDialog::updateButtonBox()
778 {
779 }
780
781 // ============================================================== updateName
782 void HexaBaseDialog::updateName()
783 {
784     const PatternDataModel*   patternDataModel = getPatternDataModel();
785
786     QLineEdit* lineEdit = dynamic_cast<QLineEdit*>(sender());
787     if (!lineEdit) return;
788     QString newName = lineEdit->text();
789     if ( newName.isEmpty() ) return;
790
791     QVariant v = lineEdit->property("QModelIndex");
792     if ( !v.isValid() ) return;
793
794     QModelIndex index = v.value<QModelIndex>();
795     if ( index.isValid() )
796         getDocumentModel()->setName( patternDataModel->mapToSource(index), newName );
797 }
798
799 // ============================================================== updateDefaultName
800 void HexaBaseDialog::updateDefaultName(QLineEdit* name_field, HEXA_NS::EnumElt type)
801 {
802     if (name_field == NULL) return;
803
804     HEXA_NS::Document* doc = getDocumentModel()->getHexaDocument();
805     if (doc == NULL) return;
806
807     name_field->setText(doc->getNextName(type).c_str());
808 }
809
810 // ============================================================== selectElementOfModel
811 /*Selects in the model (treeview) elements selected in a listwidget,
812  *  or an element in a line edit.*/
813 void HexaBaseDialog::selectElementOfModel()
814 {
815     if (getPatternDataSelectionModel() == NULL) return;
816
817     QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
818     if ( !currentListWidget ) return;
819
820     QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
821     QModelIndex index;
822     getPatternDataSelectionModel()->clearSelection();
823     foreach ( QListWidgetItem *item, sel ){
824         //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
825         index = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
826         if ( index.isValid() )
827             getPatternDataSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
828     }
829 }
830
831 // ============================================================== _isLineOrListWidget
832 /*
833  * Return true is the widget is a line or a list
834  * false otherwise.
835  */
836 bool HexaBaseDialog::_isLineOrListWidget(QObject *widget)
837 {
838     if (widget == NULL) return false;
839
840     QLineEdit           *lineEdit = dynamic_cast<QLineEdit*>(widget);
841     QListWidget *listWidget = dynamic_cast<QListWidget*>(widget);
842     return (lineEdit != NULL) || (listWidget != NULL);
843
844 }//_isLineOrListWidget
845
846
847 // ============================================================== _highlightWidget
848 /*
849  * Highlight the given widget with the given color.
850  */
851 void HexaBaseDialog::_highlightWidget(QObject *obj, Qt::GlobalColor clr)
852 {
853     if (!_isLineOrListWidget(obj)) return;
854
855     QWidget *widget = dynamic_cast<QWidget*>(obj); //sure it's not NULL (_isLineOrListWidget(obj))
856     QPalette palette1 = widget->palette();
857     palette1.setColor(widget->backgroundRole(), clr);
858     widget->setPalette(palette1);
859
860 }//_highlightWidget
861
862
863 // ============================================================== _updateCurrentObject
864 void HexaBaseDialog::_updateCurrentObject(QObject* obj)
865 {
866     _highlightWidget(_currentObj, Qt::white);
867     _currentObj = obj;
868     _highlightWidget(obj, Qt::yellow);
869 }
870
871 // ============================================================== eventFilter
872 /*
873  * Handles events from the treeview and the dialog boxes.
874  */
875 bool HexaBaseDialog::eventFilter(QObject *obj, QEvent *event)
876 {
877     QLineEdit           *lineEdit = dynamic_cast<QLineEdit*>(obj);
878     QListWidget     *listWidget = dynamic_cast<QListWidget*>(obj);
879
880     // * Enter key press ------
881     if ( event->type() == QEvent::KeyPress &&
882             ((QKeyEvent*)event)->key() == Qt::Key_Return)
883     {
884         setFocusToNextField();
885         return true;
886     }
887
888     // * Focus out from a list widget ------
889     if ( event->type() == QEvent::FocusOut && listWidget != NULL)
890     {
891         QItemSelectionModel * selectionModel = listWidget->selectionModel();
892         selectionModel->clearSelection();
893     }
894
895     if ( event->type() != QEvent::FocusIn )
896         return false;
897
898     // * Focus In ------
899
900     // allow vtk selection
901     if (getObjectViewType(obj) == HEXABLOCKGUI::VTK)
902         _allowVTKSelection( obj );
903
904     //allow occ selection
905     if (getObjectViewType(obj) == HEXABLOCKGUI::OCC)
906         _allowOCCSelection( obj );
907
908     //Depending on the focused widget type, get the right selector for it
909     QVariant v;
910     QModelIndex index;
911     QItemSelectionModel* selector = _getSelector( obj );
912     if ( selector == NULL )
913     {
914         _updateCurrentObject(obj);
915         return false;
916     }
917
918     if ( _currentObj != obj && (lineEdit == NULL || listWidget == NULL) )
919         selector->clearSelection();
920
921     _updateCurrentObject(obj);
922
923     //If the widget contains an element, select it in model/view
924     if ( lineEdit != NULL ){ //element can be from lineEdit
925         v = lineEdit->property("HexaData");
926         if ( !v.isValid() )
927             return QObject::eventFilter(obj, event);
928         index = ((SelectionModel*)selector)->indexBy( HEXA_DATA_ROLE, v);
929         if (index.isValid())
930             selector->select( index, QItemSelectionModel::SelectCurrent );
931     }
932
933     return QObject::eventFilter(obj, event);
934 }
935
936 // ------------------------- VERTEX ----------------------------------
937 // ============================================================== Constructeur
938 VertexDialog::VertexDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
939            HexaBaseDialog(parent, editmode, f),
940            _value(0)
941 {
942     _helpFileName = "gui_vertex.html";
943     setupUi( this );
944     _initWidget(editmode);
945     //   setFocusProxy( name_le );
946
947     if ( editmode  == NEW_MODE ){
948         setWindowTitle( tr("Vertex Construction") );
949     } else if ( editmode == UPDATE_MODE ){
950         setWindowTitle( tr("Vertex Modification") );
951     }
952     else if ( editmode == INFO_MODE){
953         setWindowTitle( tr("Vertex Information") );
954     }
955 }
956
957 // ============================================================== Destructeur
958 VertexDialog::~VertexDialog()
959 {
960 }
961
962 // ============================================================== _initInputWidget
963 void VertexDialog::_initInputWidget( Mode editmode )
964 {
965 //    x_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
966 //    y_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
967 //    z_spb->setRange(VERTEX_COORD_MIN, VERTEX_COORD_MAX);
968     QDoubleValidator *doubleValidator = new QDoubleValidator(widget_2);
969     x_spb->setValidator(doubleValidator);
970     y_spb->setValidator(doubleValidator);
971     z_spb->setValidator(doubleValidator);
972
973     //   setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
974     installEventFilter(this);
975     //   name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
976     name_le->installEventFilter(this);
977
978     if (editmode == INFO_MODE)
979     {
980         name_le->setReadOnly(true);
981         x_spb->setReadOnly(true);
982         y_spb->setReadOnly(true);
983         z_spb->setReadOnly(true);
984     }
985
986     //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
987 }
988
989 // ============================================================== clear
990 void VertexDialog::clear()
991 {
992     name_le->clear();
993
994     modelUnregister(this);
995 }
996
997 // ============================================================== setValue
998 void VertexDialog::setValue(HEXA_NS::Vertex* v)
999 {
1000     //0) Name
1001     name_le->setText( v->getName() );
1002
1003     //1) Value (x,y,z)
1004 //    x_spb->setValue( v->getX() );
1005 //    y_spb->setValue( v->getY() );
1006 //    z_spb->setValue( v->getZ() );
1007     x_spb->setText( QString::number(v->getX()) );
1008     y_spb->setText( QString::number(v->getY()) );
1009     z_spb->setText( QString::number(v->getZ()) );
1010
1011     if ( getPatternDataSelectionModel() != NULL ){
1012         QModelIndex iv = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1013
1014         setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(iv) );
1015         name_le->setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(iv) );
1016     }
1017     _value = v;
1018 }
1019
1020 // ============================================================== getValue
1021 HEXA_NS::Vertex* VertexDialog::getValue()
1022 {
1023     return _value;
1024 }
1025
1026
1027 // ============================================================== apply
1028 bool VertexDialog::apply(QModelIndex& result)
1029 {
1030     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1031     _currentObj = NULL;
1032
1033     if ( !getDocumentModel() ) return false;
1034     if ( !getPatternDataSelectionModel() ) return false;
1035     const PatternDataModel* patternDataModel = getPatternDataModel();
1036     if ( !patternDataModel ) return false;
1037
1038     QModelIndex iVertex;
1039
1040     QString xStr = x_spb->text();
1041     QString yStr = y_spb->text();
1042     QString zStr = z_spb->text();
1043     bool isOk = false, validArgs = !xStr.isEmpty() && !yStr.isEmpty() && !zStr.isEmpty();
1044
1045     double newX, newY, newZ;
1046     if (validArgs)
1047     {
1048         newX = xStr.toDouble();
1049         newY = yStr.toDouble();
1050         newZ = zStr.toDouble();
1051     }
1052
1053     if ( _editMode == UPDATE_MODE && validArgs){
1054         QVariant v = property("QModelIndex");
1055         if ( v.isValid() ){
1056             iVertex = patternDataModel->mapToSource( v.value<QModelIndex>() );
1057             if ( iVertex.isValid() )
1058                 isOk = getDocumentModel()->updateVertex( iVertex, newX, newY, newZ );
1059         }
1060     } else if ( _editMode == NEW_MODE && validArgs){
1061         iVertex = getDocumentModel()->addVertex( newX, newY, newZ );
1062         if ( iVertex.isValid() )
1063             isOk = true;
1064     }
1065     if (!isOk) {
1066         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "VERTEX UPDATE/CONSTRUCTION" ) + "\n" + getErrorMsg() );
1067         return false;
1068     }
1069
1070     QString newName = name_le->text();
1071     if ( !newName.isEmpty() )/*{*/
1072         getDocumentModel()->setName( iVertex, newName );
1073
1074     //the default name in the dialog box
1075     HEXA_NS::Vertex* v = getDocumentModel()->getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1076     if (v != NULL)
1077         updateDefaultName(name_le, v->getType());
1078
1079     // to select/highlight result
1080     result = patternDataModel->mapFromSource(iVertex);
1081
1082     //  updateDialogBoxName(name_le, result);
1083     //  const char *defaultName = getDocumentModel()->getHexaPtr(last)->getName();
1084     return isOk;
1085 }
1086
1087 // ------------------------- EDGE ----------------------------------
1088
1089 // ============================================================== Constructeur
1090 EdgeDialog::EdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1091          HexaBaseDialog(parent, editmode, f),
1092          _value(0)
1093 {
1094     _helpFileName = "gui_edge.html";
1095     setupUi( this );
1096     _initWidget(editmode);
1097
1098     //  rb0->setFocusProxy( v0_le_rb0 );
1099     //  rb1->setFocusProxy( vex_le_rb1 );
1100
1101     if  ( editmode == INFO_MODE ){
1102         setWindowTitle( tr("Edge Information") );
1103         rb1->hide();
1104     }
1105     else if ( editmode == UPDATE_MODE ){
1106         setWindowTitle( tr("Edge Modification") );
1107     }
1108
1109     rb0->click();
1110 }
1111
1112 // ============================================================== Destructeur
1113 EdgeDialog::~EdgeDialog()
1114 {
1115 }
1116
1117
1118 // ============================================================== _initInputWidget
1119 void EdgeDialog::_initInputWidget( Mode editmode )
1120 {
1121     QRegExp rx("");
1122     QValidator *validator = new QRegExpValidator(rx, this);
1123
1124     //   setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1125     installEventFilter(this);
1126
1127     //   name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1128     name_le->installEventFilter(this);
1129
1130     v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1131     v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1132     v0_le_rb0->setValidator( validator );
1133     v1_le_rb0->setValidator( validator );
1134     v0_le_rb0->installEventFilter(this);
1135     v1_le_rb0->installEventFilter(this);
1136
1137     vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1138     vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1139     vex_le_rb1->setValidator( validator );
1140     vec_le_rb1->setValidator( validator );
1141     vex_le_rb1->installEventFilter(this);
1142     vec_le_rb1->installEventFilter(this);
1143
1144     v0_le_rb0->setReadOnly(true);
1145     v1_le_rb0->setReadOnly(true);
1146     vex_le_rb1->setReadOnly(true);
1147     vec_le_rb1->setReadOnly(true);
1148
1149     if (editmode == INFO_MODE)
1150         name_le->setReadOnly(true);
1151
1152     //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()) );
1153
1154 }
1155
1156 // ============================================================== Clear
1157 void EdgeDialog::clear()
1158 {
1159     name_le->clear();
1160
1161     v0_le_rb0->clear();
1162     modelUnregister(v0_le_rb0);
1163
1164     v1_le_rb0->clear();
1165     modelUnregister(v1_le_rb0);
1166
1167     vex_le_rb1->clear();
1168     modelUnregister(vex_le_rb1);
1169
1170     vec_le_rb1->clear();
1171     modelUnregister(vec_le_rb1);
1172
1173     modelUnregister(this);
1174 }
1175
1176 // ============================================================== setValue
1177 void EdgeDialog::setValue(HEXA_NS::Edge* e)
1178 {
1179     HEXA_NS::Vertex* v0 = e->getVertex(0);
1180     HEXA_NS::Vertex* v1 = e->getVertex(1);
1181
1182     name_le->setText( e->getName() );
1183     v0_le_rb0->setText( v0->getName() );
1184     v1_le_rb0->setText( v1->getName() );
1185
1186     if ( getPatternDataSelectionModel() ){
1187         QModelIndex ie  = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e) );
1188         QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1189         QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1190
1191         name_le->setProperty( "QModelIndex",  QVariant::fromValue(ie) );
1192         v0_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv0) );
1193         v1_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv1) );
1194     }
1195     _value = e;
1196 }
1197
1198 // ============================================================== getValue
1199 HEXA_NS::Edge* EdgeDialog::getValue()
1200 {
1201     return _value;
1202 }
1203
1204 // ============================================================== apply
1205 bool EdgeDialog::apply(QModelIndex& result)
1206 {
1207     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1208     _currentObj = NULL;
1209
1210     if ( !getDocumentModel() ) return false;
1211     const PatternDataModel*    patternDataModel = getPatternDataModel();
1212     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1213     if ( !patternDataModel || !patternBuilderModel ) return false;
1214
1215     QModelIndex iEdge;
1216
1217     if ( rb0->isChecked() ){
1218         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1219         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1220         if ( iv0.isValid()&& iv1.isValid() ){
1221             iEdge = getDocumentModel()->addEdgeVertices( iv0, iv1 );
1222         }
1223     } else if ( rb1->isChecked() ){
1224         QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
1225         QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
1226         if ( ivex.isValid() && ivec.isValid() ){
1227             iEdge = getDocumentModel()->addEdgeVector( ivex, ivec );
1228         }
1229     }
1230
1231     if ( !iEdge.isValid() ){
1232         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD EDGE" )  + "\n" + getErrorMsg() );
1233         return false;
1234     }
1235     _value  = iEdge.model()->data(iEdge, HEXA_DATA_ROLE).value<HEXA_NS::Edge*>();
1236
1237     QString newName = name_le->text();
1238     if ( !newName.isEmpty() )/*{*/
1239         getDocumentModel()->setName( iEdge, newName );
1240
1241     //update the default name in the dialog box
1242     if (_value != NULL)
1243         updateDefaultName(name_le, _value->getType());
1244
1245     result = patternDataModel->mapFromSource(iEdge);
1246
1247     return true;
1248 }
1249
1250 // ------------------------- QUAD ----------------------------------
1251
1252 // ============================================================== Constructeur
1253 QuadDialog::QuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1254 HexaBaseDialog(parent, editmode, f),
1255 _value(0)
1256 {
1257     _helpFileName = "gui_quadrangle.html";
1258     setupUi( this );
1259     _initWidget(editmode);
1260     rb0->click();
1261
1262     if  ( editmode == INFO_MODE ){
1263         setWindowTitle( tr("Quad Information") );
1264     }
1265 }
1266
1267 // ============================================================== Destructeur
1268 QuadDialog::~QuadDialog()
1269 {
1270 }
1271
1272 // ============================================================== _initInputWidget
1273 void QuadDialog::_initInputWidget( Mode editmode )
1274 {
1275     QRegExp rx("");
1276     QValidator *validator = new QRegExpValidator(rx, this);
1277
1278     installEventFilter(this);
1279     name_le->installEventFilter(this);
1280
1281     v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1282     v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1283     v2_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1284     v3_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1285
1286     v0_le_rb0->setValidator( validator );
1287     v1_le_rb0->setValidator( validator );
1288     v2_le_rb0->setValidator( validator );
1289     v3_le_rb0->setValidator( validator );
1290     v0_le_rb0->installEventFilter(this);
1291     v1_le_rb0->installEventFilter(this);
1292     v2_le_rb0->installEventFilter(this);
1293     v3_le_rb0->installEventFilter(this);
1294
1295     e0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1296     e1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1297     e2_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1298     e3_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
1299
1300     e0_le_rb1->setValidator( validator );
1301     e1_le_rb1->setValidator( validator );
1302     e2_le_rb1->setValidator( validator );
1303     e3_le_rb1->setValidator( validator );
1304
1305     e0_le_rb1->installEventFilter(this);
1306     e1_le_rb1->installEventFilter(this);
1307     e2_le_rb1->installEventFilter(this);
1308     e3_le_rb1->installEventFilter(this);
1309
1310     v0_le_rb0->setReadOnly(true);
1311     v1_le_rb0->setReadOnly(true);
1312     v2_le_rb0->setReadOnly(true);
1313     v3_le_rb0->setReadOnly(true);
1314
1315     e0_le_rb1->setReadOnly(true);
1316     e1_le_rb1->setReadOnly(true);
1317     e2_le_rb1->setReadOnly(true);
1318     e3_le_rb1->setReadOnly(true);
1319
1320     if (editmode == INFO_MODE)
1321         name_le->setReadOnly(true);
1322 }
1323
1324 // ============================================================== clear
1325 void QuadDialog::clear()
1326 {
1327     //Clear the dialog and unregister it from the model
1328     QModelIndex invalidIndex;
1329
1330     name_le->clear();
1331
1332     v0_le_rb0->clear();
1333     modelUnregister(v0_le_rb0);
1334
1335     v1_le_rb0->clear();
1336     modelUnregister(v1_le_rb0);
1337
1338     v2_le_rb0->clear();
1339     modelUnregister(v2_le_rb0);
1340
1341     v3_le_rb0->clear();
1342     modelUnregister(v3_le_rb0);
1343
1344     e0_le_rb1->clear();
1345     modelUnregister(e0_le_rb1);
1346
1347     e1_le_rb1->clear();
1348     modelUnregister(e1_le_rb1);
1349
1350     e2_le_rb1->clear();
1351     modelUnregister(e2_le_rb1);
1352
1353     e3_le_rb1->clear();
1354     modelUnregister(e3_le_rb1);
1355
1356     modelUnregister(this);
1357
1358 }
1359
1360 // ============================================================== setValue
1361 void QuadDialog::setValue(HEXA_NS::Quad* q)
1362 {
1363     Q_ASSERT( q->countEdge() == 4 );
1364     Q_ASSERT( q->countVertex() == 4 );
1365
1366     //0) Name
1367     name_le->setText( q->getName() );
1368
1369     //1) Vertices
1370     HEXA_NS::Vertex* v0 = q->getVertex(0);
1371     HEXA_NS::Vertex* v1 = q->getVertex(1);
1372     HEXA_NS::Vertex* v2 = q->getVertex(2);
1373     HEXA_NS::Vertex* v3 = q->getVertex(3);
1374
1375     v0_le_rb0->setText( v0->getName() );
1376     v1_le_rb0->setText( v1->getName() );
1377     v2_le_rb0->setText( v2->getName() );
1378     v3_le_rb0->setText( v3->getName() );
1379
1380
1381     //2) Edges
1382     HEXA_NS::Edge* e0 = q->getEdge(0);
1383     HEXA_NS::Edge* e1 = q->getEdge(1);
1384     HEXA_NS::Edge* e2 = q->getEdge(2);
1385     HEXA_NS::Edge* e3 = q->getEdge(3);
1386
1387     e0_le_rb1->setText( e0->getName() );
1388     e1_le_rb1->setText( e1->getName() );
1389     e2_le_rb1->setText( e2->getName() );
1390     e3_le_rb1->setText( e3->getName() );
1391
1392     if ( getPatternDataSelectionModel() ){
1393         QModelIndex iq = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(q) );
1394
1395         QModelIndex iv0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v0) );
1396         QModelIndex iv1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v1) );
1397         QModelIndex iv2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v2) );
1398         QModelIndex iv3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v3) );
1399
1400         QModelIndex ie0 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e0) );
1401         QModelIndex ie1 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e1) );
1402         QModelIndex ie2 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e2) );
1403         QModelIndex ie3 = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(e3) );
1404
1405         name_le->setProperty( "QModelIndex",  QVariant::fromValue(iq) );
1406
1407         v0_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv0) );
1408         v1_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv1) );
1409         v2_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv2) );
1410         v3_le_rb0->setProperty( "QModelIndex",  QVariant::fromValue(iv3) );
1411
1412         e0_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie0) );
1413         e1_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie1) );
1414         e2_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie2) );
1415         e3_le_rb1->setProperty( "QModelIndex",  QVariant::fromValue(ie3) );
1416     }
1417     _value = q;
1418
1419 }
1420
1421 // ============================================================== getValue
1422 HEXA_NS::Quad* QuadDialog::getValue()
1423 {
1424     return _value;
1425 }
1426
1427
1428 // ============================================================== apply
1429 bool QuadDialog::apply(QModelIndex& result)
1430 {
1431     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1432     _currentObj = NULL;
1433
1434     if ( !getDocumentModel() ) return false;
1435     const PatternDataModel* patternDataModel = getPatternDataModel();
1436     if ( !patternDataModel ) return false;
1437
1438     QModelIndex iQuad;
1439
1440     if ( rb0->isChecked() ){ //vertices
1441         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
1442         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
1443         QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb0] );
1444         QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb0] );
1445
1446         if ( iv0.isValid()
1447                 && iv1.isValid()
1448                 && iv2.isValid()
1449                 && iv3.isValid() ){
1450             iQuad = getDocumentModel()->addQuadVertices( iv0, iv1, iv2, iv3 );
1451         }
1452     } else if ( rb1->isChecked() ){ //edges
1453         QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
1454         QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
1455         QModelIndex ie2 = patternDataModel->mapToSource( _index[e2_le_rb1] );
1456         QModelIndex ie3 = patternDataModel->mapToSource( _index[e3_le_rb1] );
1457
1458         if ( ie0.isValid()
1459                 && ie1.isValid()
1460                 && ie2.isValid()
1461                 && ie3.isValid() ){
1462             iQuad = getDocumentModel()->addQuadEdges( ie0, ie1, ie2, ie3 );
1463         }
1464     }
1465
1466     if ( !iQuad.isValid() ){
1467         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD QUAD" )  + "\n" + getErrorMsg());
1468         return false;
1469     }
1470     _value  = iQuad.model()->data(iQuad, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1471
1472     QString newName = name_le->text();
1473     if ( !newName.isEmpty() )/*{*/
1474         getDocumentModel()->setName( iQuad, newName );
1475
1476     //the default name in the dialog box
1477     if (_value != NULL)
1478         updateDefaultName(name_le, _value->getType());
1479
1480     // to select/highlight result
1481     result = patternDataModel->mapFromSource(iQuad);
1482
1483     return true;
1484 }
1485
1486
1487 // ------------------------- HEXA ----------------------------------
1488
1489 // ============================================================== HexaDialog
1490
1491 HexaDialog::HexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1492         HexaBaseDialog(parent, editmode, f),
1493         _value(0)
1494 {
1495     _helpFileName = "gui_hexahedron.html";
1496     setupUi( this );
1497     _initWidget(editmode);
1498     quads_rb->click();
1499
1500     if  ( editmode == INFO_MODE ){
1501         setWindowTitle( tr("Hexahedron Information") );
1502     }
1503 }
1504
1505 // ============================================================== Destructeur
1506 HexaDialog::~HexaDialog()
1507 {
1508 }
1509
1510 // ============================================================== _initInputWidget
1511 void HexaDialog::_initInputWidget( Mode editmode )
1512 {
1513     QRegExp rx("");
1514
1515     installEventFilter(this);
1516     name_le->installEventFilter(this);
1517
1518     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
1519     quads_lw->installEventFilter(this);
1520
1521     vertices_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1522     vertices_lw->installEventFilter(this);
1523
1524
1525     if ( editmode != INFO_MODE ) {
1526         // delete item from listwidget
1527         QShortcut* delQuadShortcut   = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
1528         QShortcut* delVertexShortcut = new QShortcut( QKeySequence(Qt::Key_X), vertices_lw );
1529         delQuadShortcut->setContext( Qt::WidgetShortcut );
1530         delVertexShortcut->setContext( Qt::WidgetShortcut );
1531         connect(delQuadShortcut,   SIGNAL(activated()), this, SLOT(deleteQuadItem()));
1532         connect(delVertexShortcut, SIGNAL(activated()), this, SLOT(deleteVertexItem()));
1533     }
1534     // highlight item on model view (VTK) from listwidget
1535     connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1536     connect( vertices_lw, SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
1537
1538     if ( editmode != INFO_MODE)
1539     {
1540         connect( vertices_rb, SIGNAL(clicked()), vertices_lw, SLOT(setFocus()));
1541         connect( quads_rb, SIGNAL(clicked()), quads_lw, SLOT(setFocus()));
1542     }
1543
1544     connect( vertices_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1545     connect( quads_rb, SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection);
1546
1547     if (editmode == INFO_MODE)
1548         name_le->setReadOnly(true);
1549
1550 }
1551
1552 // ============================================================== clear
1553 void HexaDialog::clear()
1554 {
1555     name_le->clear();
1556
1557     quads_lw->clear();
1558     modelUnregister(quads_lw);
1559
1560     vertices_lw->clear();
1561     modelUnregister(vertices_lw);
1562
1563     modelUnregister(this);
1564 }
1565
1566 // ============================================================== getAssocsVTK
1567 /*
1568  * Returns elements currently associated to vtk
1569  */
1570 QModelIndexList HexaDialog::getAssocsVTK()
1571 {
1572     QModelIndexList assocs;
1573     QModelIndex iQuad, iVertex;
1574     QListWidgetItem* item = NULL;
1575
1576     const PatternDataModel* patternDataModel = getPatternDataModel();
1577     if (patternDataModel == NULL) return assocs;
1578     if (quads_rb->isChecked())
1579     {
1580         //ListWidget content
1581         int nbQuads = quads_lw->count();
1582         for ( int r = 0; r < nbQuads; ++r ){
1583             item = quads_lw->item(r);
1584             iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1585             if ( iQuad.isValid() )
1586                 assocs << iQuad;
1587         }
1588         return assocs;
1589     }
1590     else if (vertices_rb->isChecked())
1591     {
1592         //ListWidget content
1593         int nbVertices = vertices_lw->count();
1594         for ( int r = 0; r < nbVertices; ++r ){
1595             item = vertices_lw->item(r);
1596             iVertex = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1597             if ( iVertex.isValid() )
1598                 assocs << iVertex;
1599         }
1600         return assocs;
1601     }
1602     else return assocs;
1603 }
1604
1605
1606 // ============================================================== updateButtonBox
1607 void HexaDialog::updateButtonBox()
1608 {
1609     if ( _editMode == INFO_MODE )
1610         return;
1611
1612     if ( quads_rb->isChecked() ){  // build from quads count() must be between [2,6]
1613         int nbQuads = quads_lw->count();
1614         if ( nbQuads >= 2 && nbQuads <= 6 ){
1615             _applyButton->setEnabled(true);
1616         } else {
1617             _applyButton->setEnabled(false);
1618         }
1619     } else if ( vertices_rb->isChecked() ){ // build from vertices count() must be equals to 8
1620         int nbVertices = vertices_lw->count();
1621         if ( nbVertices == 8 ){
1622             _applyButton->setEnabled(true);
1623         } else {
1624             _applyButton->setEnabled(false);
1625         }
1626     }
1627 }
1628
1629 // ============================================================== deleteQuadItem
1630 void HexaDialog::deleteQuadItem()
1631 {
1632     delete quads_lw->currentItem();
1633     updateButtonBox();
1634 }
1635
1636 // ============================================================== deleteVertexItem
1637 void HexaDialog::deleteVertexItem()
1638 {
1639     delete vertices_lw->currentItem();
1640     updateButtonBox();
1641 }
1642
1643 // ============================================================== _setValueQuads
1644 void HexaDialog::_setValueQuads( HEXA_NS::Hexa* h )
1645 {
1646     QListWidgetItem *qItem = NULL;
1647     HEXA_NS::Quad   *q     = NULL;
1648     QModelIndex      qIndex;
1649     if (getPatternDataSelectionModel() == NULL) return;
1650     quads_lw->clear();
1651     for( int i = 0; i <= 5; ++i ){
1652         q      = h->getQuad(i);
1653         qIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(q)) );
1654         qItem  = new QListWidgetItem( q->getName() );
1655         qItem->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(qIndex) );
1656         qItem->setData(LW_DATA_ROLE, qIndex.data(HEXA_DATA_ROLE));
1657         quads_lw->addItem( qItem );
1658     }
1659 }
1660
1661 // ============================================================== _setValueVertices
1662 void HexaDialog::_setValueVertices( HEXA_NS::Hexa* h )
1663 {
1664     QListWidgetItem *vItem = NULL;
1665     HEXA_NS::Vertex* v     = NULL;
1666     QModelIndex      vIndex;
1667     if (getPatternDataSelectionModel() == NULL) return;
1668     vertices_lw->clear();
1669     for( int i = 0; i <= 7; ++i ){
1670         v = h->getVertex(i);
1671         vIndex = getPatternDataSelectionModel()->indexBy( HEXA_ENTRY_ROLE, QString::number(reinterpret_cast<intptr_t>(v)) );
1672         vItem  = new QListWidgetItem( v->getName() );
1673         vItem->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(vIndex) );
1674         vItem->setData(LW_DATA_ROLE, vIndex.data(HEXA_DATA_ROLE));
1675         vertices_lw->addItem( vItem );
1676     }
1677 }
1678
1679 // ============================================================== setValue
1680 void HexaDialog::setValue(HEXA_NS::Hexa* h)
1681 {
1682     // 0) name
1683     name_le->setText( h->getName() );
1684
1685     if ( getPatternDataSelectionModel()){
1686         QModelIndex hIndex = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(h) );
1687         _setValueVertices(h);
1688         _setValueQuads(h);
1689         name_le->setProperty( "QModelIndex",  QVariant::fromValue(hIndex) );
1690     }
1691     _value = h;
1692 }
1693
1694 // ============================================================== getValue
1695 HEXA_NS::Hexa* HexaDialog::getValue()
1696 {
1697     return _value;
1698 }
1699
1700 // ============================================================== apply
1701 bool HexaDialog::apply(QModelIndex& result)
1702 {
1703     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1704     _currentObj = NULL;
1705
1706     if ( !getDocumentModel() ) return false;
1707     const PatternDataModel* patternDataModel = getPatternDataModel();
1708     if ( !patternDataModel ) return false;
1709
1710     QModelIndex  iHexa;
1711
1712     QListWidget* currentLw = NULL;
1713     QListWidgetItem*  item = NULL;
1714
1715     if ( quads_rb->isChecked() )
1716         currentLw = dynamic_cast<QListWidget*>( quads_lw );
1717     else if ( vertices_rb->isChecked() )
1718         currentLw = dynamic_cast<QListWidget*>( vertices_lw );
1719
1720     QModelIndex     iElt;
1721     QModelIndexList iElts;
1722     int nbItems = currentLw->count();
1723     for ( int r = 0; r < nbItems; ++r){
1724         item = currentLw->item(r);
1725         iElt = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
1726         if ( iElt.isValid() )
1727             iElts << iElt;
1728     }
1729
1730     nbItems = iElts.count();
1731     if ( quads_rb->isChecked() and (nbItems>=2 and nbItems<=6) ){ // build from quads iElts.count() should be between [2,6]
1732         iHexa = getDocumentModel()->addHexaQuads( iElts );
1733     } else if ( vertices_rb->isChecked() and nbItems== 8 ){ // build from vertices
1734         iHexa = getDocumentModel()->addHexaVertices( iElts[0], iElts[1], iElts[2], iElts[3],
1735                 iElts[4], iElts[5], iElts[6], iElts[7] );
1736     }
1737
1738     if ( !iHexa.isValid() ){
1739         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD HEXA" ) + "\n" + getErrorMsg() );
1740         return false;
1741     }
1742     _value  = iHexa.model()->data(iHexa, HEXA_DATA_ROLE).value<HEXA_NS::Hexa*>();
1743
1744     QString newName = name_le->text();
1745     if ( !newName.isEmpty() )/*{*/
1746         getDocumentModel()->setName( iHexa, newName );
1747
1748     //update the default name in the dialog box
1749     if (_value != NULL)
1750         updateDefaultName(name_le, _value->getType());
1751
1752     // to select/highlight result
1753     result = patternDataModel->mapFromSource(iHexa);
1754
1755     return true;
1756 }
1757
1758
1759 // ------------------------- VECTOR ----------------------------------
1760
1761 // ============================================================== Constructeur
1762
1763 VectorDialog::VectorDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
1764 HexaBaseDialog(parent, editmode, f),
1765 _value(0)
1766 {
1767     _helpFileName = "gui_vector.html";
1768     setupUi( this );
1769     _initWidget(editmode);
1770
1771     rb0->click();
1772
1773     if ( editmode == INFO_MODE ){
1774         setWindowTitle( tr("Vector Information") );
1775         rb1->hide();
1776     }
1777 }
1778
1779 // ============================================================== Destructeur
1780 VectorDialog::~VectorDialog()
1781 {
1782 }
1783
1784 // ============================================================== _initInputWidget
1785 void VectorDialog::_initInputWidget( Mode editmode )
1786 {
1787     QRegExp rx("");
1788     QValidator *validator = new QRegExpValidator(rx, this);
1789
1790     installEventFilter(this);
1791     name_le->installEventFilter(this);
1792
1793     v0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1794     v0_le_rb1->setValidator( validator );
1795     v0_le_rb1->installEventFilter(this);
1796
1797     v1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1798     v1_le_rb1->setValidator( validator );
1799     v1_le_rb1->installEventFilter(this);
1800
1801     if ( editmode == INFO_MODE ){
1802         name_le->setReadOnly(true);
1803         dx_spb_rb0->setReadOnly(true);
1804         dy_spb_rb0->setReadOnly(true);
1805         dz_spb_rb0->setReadOnly(true);
1806     }
1807
1808     v0_le_rb1->setReadOnly(true);
1809     v1_le_rb1->setReadOnly(true);
1810 }
1811
1812 // ============================================================== clear
1813 void VectorDialog::clear()
1814 {
1815     name_le->clear();
1816     v0_le_rb1->clear();
1817     modelUnregister(v0_le_rb1);
1818
1819     v1_le_rb1->clear();
1820     modelUnregister(v1_le_rb1);
1821
1822     modelUnregister(this);
1823 }
1824
1825 // ============================================================== setValue
1826 void VectorDialog::setValue(HEXA_NS::Vector* v)
1827 {
1828     name_le->setText( v->getName() );
1829     dx_spb_rb0->setValue( v->getDx() );
1830     dy_spb_rb0->setValue( v->getDy() );
1831     dz_spb_rb0->setValue( v->getDz() );
1832
1833     if ( getPatternDataSelectionModel() ){
1834         QModelIndex ivec = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(v) );
1835         name_le->setProperty( "QModelIndex",  QVariant::fromValue(ivec) );
1836     }
1837     _value = v;
1838 }
1839
1840 // ============================================================== getValue
1841 HEXA_NS::Vector* VectorDialog::getValue()
1842 {
1843     return _value;
1844 }
1845
1846 // ============================================================== apply
1847 bool VectorDialog::apply(QModelIndex& result)
1848 {
1849     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
1850     _currentObj = NULL;
1851
1852     if ( !getDocumentModel() ) return false;
1853     const PatternDataModel*    patternDataModel    = getPatternDataModel();
1854     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
1855     if ( !patternDataModel || !patternBuilderModel) return false;
1856
1857     QModelIndex iVector;
1858
1859     if ( rb0->isChecked() ){ //scalar
1860         double dx = dx_spb_rb0->value();
1861         double dy = dy_spb_rb0->value();
1862         double dz = dz_spb_rb0->value();
1863
1864         iVector = getDocumentModel()->addVector( dx, dy, dz );
1865     } else if ( rb1->isChecked() ){ //vertices
1866         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
1867         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
1868
1869         if ( iv0.isValid()
1870                 && iv1.isValid() ){
1871             iVector = getDocumentModel()->addVectorVertices( iv0, iv1 );
1872         }
1873     }
1874
1875     if ( !iVector.isValid() ){
1876         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT BUILD VECTOR" ) + "\n" + getErrorMsg());
1877         return false;
1878     }
1879
1880     _value  = iVector.model()->data(iVector, HEXA_DATA_ROLE).value<HEXA_NS::Vector *>();
1881
1882     QString newName = name_le->text();
1883     if ( !newName.isEmpty() )/*{*/
1884         getDocumentModel()->setName( iVector, newName );
1885
1886     //update the default name in the dialog box
1887     if (_value != NULL)
1888         updateDefaultName(name_le, _value->getType());
1889
1890     // to select/highlight result
1891     result = patternBuilderModel->mapFromSource(iVector);
1892
1893     return true;
1894 }
1895
1896 // ------------------------- MakeGridDialog ----------------------------------
1897 // ============================================================== Constructeur
1898
1899 MakeGridDialog::MakeGridDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
1900 : HexaBaseDialog(parent, editmode, f)
1901 {
1902     setupUi( this );
1903     _initWidget(editmode);
1904     rb0->click();
1905
1906     _helpFileName = "creategrids.html#guicartgrid";
1907     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1908     connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1909     connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1910
1911     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1912     connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1913     connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1914
1915     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
1916     connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
1917     connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
1918 }
1919
1920 // ============================================================== Destructeur
1921 MakeGridDialog::~MakeGridDialog()
1922 {
1923 }
1924
1925 // ============================================================== _initInputWidget
1926 void MakeGridDialog::_initInputWidget( Mode editmode )
1927 {
1928     center_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
1929     axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
1930     base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1931     vec_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
1932
1933     center_le->setReadOnly(true);
1934     axis_le->setReadOnly(true);
1935     base_le->setReadOnly(true);
1936     vec_le->setReadOnly(true);
1937
1938     installEventFilter(this);
1939     center_le->installEventFilter(this);
1940     axis_le->installEventFilter(this);
1941     base_le->installEventFilter(this);
1942     vec_le->installEventFilter(this);
1943
1944     radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
1945     radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1946
1947     angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
1948     angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1949
1950     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
1951     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
1952
1953     connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
1954     connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
1955
1956     connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
1957     connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
1958
1959     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
1960     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
1961 }
1962
1963 // ============================================================== clear
1964 void MakeGridDialog::clear()
1965 {
1966     center_le->clear();
1967     modelUnregister(center_le);
1968
1969     axis_le->clear();
1970     modelUnregister(axis_le);
1971
1972     base_le->clear();
1973     modelUnregister(base_le);
1974
1975     vec_le->clear();
1976     modelUnregister(vec_le);
1977
1978     modelUnregister(this);
1979 }
1980
1981 // ============================================================== updateHelpFileName
1982 void MakeGridDialog::updateHelpFileName()
1983 {
1984     if ( sender() == rb0 ){
1985         _helpFileName = "creategrids.html#guicartgrid";
1986     } else if ( sender() == rb1 ){
1987         _helpFileName = "creategrids.html#guicylgrid";
1988     } else if ( sender() == rb2 ){
1989         _helpFileName = "creategrids.html#guisphergrid";
1990     }
1991 }
1992
1993 // ============================================================== addRadiusItem
1994 void MakeGridDialog::addRadiusItem()
1995 {
1996     QListWidgetItem* previousItem = radius_lw->currentItem();
1997     QListWidgetItem* newItem      = new QListWidgetItem();
1998
1999     double defaultValue = 1.;
2000     if ( previousItem )
2001         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2002
2003     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2004     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2005     radius_lw->addItem(newItem);
2006 }
2007
2008 // ============================================================== delRadiusItem
2009 void MakeGridDialog::delRadiusItem()
2010 {
2011     delete radius_lw->currentItem();
2012 }
2013
2014 // ============================================================== addAngleItem
2015 void MakeGridDialog::addAngleItem()
2016 {
2017     QListWidgetItem* previousItem = angle_lw->currentItem();
2018     QListWidgetItem* newItem      = new QListWidgetItem();
2019
2020     double defaultValue = 180.;
2021     if ( previousItem )
2022         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2023
2024     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2025     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2026     angle_lw->addItem(newItem);
2027 }
2028
2029 // ============================================================== delAngleItem
2030 void MakeGridDialog::delAngleItem()
2031 {
2032     delete angle_lw->currentItem();
2033 }
2034
2035 // ============================================================== addHeightItem
2036 void MakeGridDialog::addHeightItem()
2037 {
2038     QListWidgetItem* previousItem = height_lw->currentItem();
2039     QListWidgetItem* newItem      = new QListWidgetItem();
2040
2041     double defaultValue = 1.;
2042     if ( previousItem )
2043         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2044
2045     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2046     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2047     height_lw->addItem(newItem);
2048 }
2049
2050 // ============================================================== delHeightItem
2051 void MakeGridDialog::delHeightItem()
2052 {
2053     delete height_lw->currentItem();
2054 }
2055
2056 // ============================================================== apply
2057 bool MakeGridDialog::apply(QModelIndex& result)
2058 {
2059     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2060     _currentObj = NULL;
2061
2062     DocumentModel* docModel = getDocumentModel();
2063     PatternDataModel*    patternDataModel    = getPatternDataModel();
2064     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2065
2066     QModelIndex iNewElts;
2067     if ( rb0->isChecked() )
2068     {
2069         long nx = nx_spb->value();
2070         long ny = ny_spb->value();
2071         long nz = nz_spb->value();
2072         iNewElts = docModel->makeCartesianTop(nx, ny, nz);
2073     }
2074     else if ( rb1->isChecked() )
2075     {
2076         QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2077         QModelIndex iaxis   = patternBuilderModel->mapToSource( _index[axis_le] );
2078         QModelIndex ibase   = patternBuilderModel->mapToSource( _index[base_le] );
2079         QModelIndex ivec    = patternBuilderModel->mapToSource( _index[vec_le] );
2080
2081         if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2082         {
2083                 double nx = nx_spb->value();
2084                 double ny = ny_spb->value();
2085                 double nz = nz_spb->value();
2086                 double lx = lx_spb->value();
2087                 double ly = ly_spb->value();
2088                 double lz = lz_spb->value();
2089
2090                 iNewElts = docModel->makeCartesianUni( icenter, ibase, ivec, iaxis,
2091                                                        nx, ny, nz, lx, ly, lz);
2092         }
2093
2094     } else if ( rb2->isChecked() )
2095     {
2096         QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2097         QModelIndex iaxis   = patternBuilderModel->mapToSource( _index[axis_le] );
2098         QModelIndex ibase   = patternBuilderModel->mapToSource( _index[base_le] );
2099         QModelIndex ivec    = patternBuilderModel->mapToSource( _index[vec_le] );
2100
2101         if ( icenter.isValid() && iaxis.isValid() && ibase.isValid() && ivec.isValid() )
2102         {
2103             QListWidgetItem* item = NULL;
2104
2105             vector<double> radius;
2106             vector<double> angles;
2107             vector<double> heights;
2108
2109             double somme = 0.;
2110             int nbAngles = angle_lw->count();
2111             for ( int r = 0; r < nbAngles; ++r){
2112                 item = angle_lw->item(r);
2113                 double itemValue = item->data(Qt::EditRole).toDouble();
2114                 angles.push_back(itemValue);
2115                 somme += itemValue;
2116             }
2117             if (somme > 360.01)
2118             {
2119                 SUIT_MessageBox::information( 0,
2120                         tr("HEXA_INFO"),
2121                         tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2122                 return false;
2123             }
2124
2125             int nbRadius = radius_lw->count();
2126             for ( int r = 0; r < nbRadius; ++r){
2127                 item = radius_lw->item(r);
2128                 radius.push_back(item->data(Qt::EditRole).toDouble());
2129             }
2130
2131             int nbHeight = height_lw->count();
2132             for ( int r = 0; r < nbHeight; ++r){
2133                 item = height_lw->item(r);
2134                 heights.push_back(item->data(Qt::EditRole).toDouble());
2135             }
2136
2137             iNewElts =  docModel->makeCartesian( icenter, ibase, ivec, iaxis,
2138                                                  radius, angles, heights);
2139         }
2140
2141     }
2142
2143     if ( !iNewElts.isValid() )
2144     {
2145         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE GRID" ) + "\n" + getErrorMsg() );
2146         return false;
2147     }
2148
2149     result = patternBuilderModel->mapFromSource( iNewElts );
2150
2151     return true;
2152 }
2153
2154 // ============================================================== Constructeur
2155
2156 MakeCylinderDialog::MakeCylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2157 : HexaBaseDialog(parent, editmode, f)
2158 {
2159     _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinder";
2160     setupUi( this );
2161     _initWidget(editmode);
2162
2163     rb0->click();
2164 }
2165
2166 // ============================================================== Destructeur
2167 MakeCylinderDialog::~MakeCylinderDialog()
2168 {
2169 }
2170
2171 void MakeCylinderDialog::_initInputWidget( Mode editmode )
2172 {
2173     origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
2174     axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2175     base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE));
2176
2177     installEventFilter(this);
2178     origin_le->installEventFilter(this);
2179     axis_le->installEventFilter(this);
2180     base_le->installEventFilter(this);
2181
2182     origin_le->setReadOnly(true);
2183     axis_le->setReadOnly(true);
2184     base_le->setReadOnly(true);
2185
2186     radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2187     radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2188
2189     angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2190     angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2191
2192     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2193     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2194
2195     connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2196     connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2197
2198     connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2199     connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2200
2201     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2202     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2203 }
2204
2205 // ============================================================== addRadiusItem
2206 void MakeCylinderDialog::addRadiusItem()
2207 {
2208     QListWidgetItem* previousItem = radius_lw->currentItem();
2209     QListWidgetItem* newItem      = new QListWidgetItem();
2210
2211     double defaultValue = 1.;
2212     if ( previousItem )
2213         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2214
2215     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2216     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2217     radius_lw->addItem(newItem);
2218 }
2219
2220 // ============================================================== delRadiusItem
2221 void MakeCylinderDialog::delRadiusItem()
2222 {
2223     delete radius_lw->currentItem();
2224 }
2225
2226 // ============================================================== addAngleItem
2227 void MakeCylinderDialog::addAngleItem()
2228 {
2229     QListWidgetItem* previousItem = angle_lw->currentItem();
2230     QListWidgetItem* newItem      = new QListWidgetItem();
2231
2232     double defaultValue = 180.;
2233     if ( previousItem )
2234         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2235
2236     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2237     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2238     angle_lw->addItem(newItem);
2239 }
2240
2241 // ============================================================== delAngleItem
2242 void MakeCylinderDialog::delAngleItem()
2243 {
2244     delete angle_lw->currentItem();
2245 }
2246
2247 // ============================================================== addHeightItem
2248 void MakeCylinderDialog::addHeightItem()
2249 {
2250     QListWidgetItem* previousItem = height_lw->currentItem();
2251     QListWidgetItem* newItem      = new QListWidgetItem();
2252
2253     double defaultValue = 1.;
2254     if ( previousItem )
2255         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2256
2257     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2258     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2259     height_lw->addItem(newItem);
2260 }
2261
2262 // ============================================================== delHeightItem
2263 void MakeCylinderDialog::delHeightItem()
2264 {
2265     delete height_lw->currentItem();
2266 }
2267
2268 // ============================================================== clear
2269 void MakeCylinderDialog::clear()
2270 {
2271     origin_le->clear();
2272     modelUnregister(origin_le);
2273
2274     axis_le->clear();
2275     modelUnregister(axis_le);
2276
2277     base_le->clear();
2278     modelUnregister(base_le);
2279
2280     modelUnregister(this);
2281 }
2282
2283 // ============================================================== apply
2284 bool MakeCylinderDialog::apply(QModelIndex& result)
2285 {
2286     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2287     _currentObj = NULL;
2288
2289     DocumentModel* docModel = getDocumentModel();
2290     PatternDataModel* patternDataModel = getPatternDataModel();
2291     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2292
2293     QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2294     QModelIndex iaxis = patternBuilderModel->mapToSource( _index[axis_le] );
2295     QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2296     double rext = ext_radius_spb->value();
2297     double rint = int_radius_spb->value();
2298     double angle = angle_spb->value();
2299     double height = height_spb->value();
2300     double nr = nr_spb->value();
2301     double na = na_spb->value();
2302     double nh = nh_spb->value();
2303
2304     QModelIndex iElts;
2305     if (rb0->isChecked())
2306         iElts = docModel->makeCylinderTop(nr, na, nh);
2307     else if (rb1->isChecked())
2308     {
2309         if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2310                 iElts = docModel->makeCylinderUni(iorigin, ibase, iaxis, rint,
2311                                                   rext, angle, height, nr, na, nh);
2312     }
2313     else if (rb2->isChecked())
2314     {
2315         QListWidgetItem* item = NULL;
2316
2317         vector<double> radius;
2318         vector<double> angles;
2319         vector<double> heights;
2320
2321         double somme = 0.;
2322         int nbAngles = angle_lw->count();
2323         for ( int r = 0; r < nbAngles; ++r){
2324             item = angle_lw->item(r);
2325             double itemValue = item->data(Qt::EditRole).toDouble();
2326             angles.push_back(itemValue);
2327             somme += itemValue;
2328         }
2329         if (somme > 360.01)
2330         {
2331             SUIT_MessageBox::information( 0,
2332                     tr("HEXA_INFO"),
2333                     tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2334             return false;
2335         }
2336
2337         int nbRadius = radius_lw->count();
2338         for ( int r = 0; r < nbRadius; ++r){
2339             item = radius_lw->item(r);
2340             radius.push_back(item->data(Qt::EditRole).toDouble());
2341         }
2342
2343         int nbHeight = height_lw->count();
2344         for ( int r = 0; r < nbHeight; ++r){
2345             item = height_lw->item(r);
2346             heights.push_back(item->data(Qt::EditRole).toDouble());
2347         }
2348
2349         if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2350                     iElts = docModel->makeCylinder( iorigin, ibase, iaxis, radius, angles, heights);
2351     }
2352
2353
2354     if ( !iElts.isValid() ){
2355         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDER" ) + "\n" + getErrorMsg() );
2356         return false;
2357     }
2358
2359     result = patternBuilderModel->mapFromSource(iElts);
2360
2361     return true;
2362 }
2363
2364 //---------------------------------- MakePipeDialog -----------------------------
2365 // ============================================================== Constructeur
2366
2367 MakePipeDialog::MakePipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2368 : HexaBaseDialog(parent, editmode, f)
2369 {
2370     _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipe";
2371     setupUi( this );
2372     _initWidget(editmode);
2373     rb0->click();
2374 }
2375
2376 // ============================================================== Destructeur
2377 MakePipeDialog::~MakePipeDialog()
2378 {
2379 }
2380
2381 // ============================================================== _initInputWidget
2382 void MakePipeDialog::_initInputWidget( Mode editmode )
2383 {
2384     origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2385     axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2386     base_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2387
2388     installEventFilter(this);
2389     origin_le->installEventFilter(this);
2390     axis_le->installEventFilter(this);
2391     base_le->installEventFilter(this);
2392
2393     origin_le->setReadOnly(true);
2394     axis_le->setReadOnly(true);
2395     base_le->setReadOnly(true);
2396
2397     radius_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw));
2398     radius_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2399
2400     angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
2401     angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2402
2403     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2404     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2405
2406     connect( add_radius_pb, SIGNAL(clicked()), this, SLOT(addRadiusItem()) );
2407     connect( del_radius_pb, SIGNAL(clicked()), this, SLOT(delRadiusItem()) );
2408
2409     connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
2410     connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
2411
2412     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2413     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2414 }
2415
2416 // ============================================================== addRadiusItem
2417 void MakePipeDialog::addRadiusItem()
2418 {
2419     QListWidgetItem* previousItem = radius_lw->currentItem();
2420     QListWidgetItem* newItem      = new QListWidgetItem();
2421
2422     double defaultValue = 1.;
2423     if ( previousItem )
2424         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2425
2426     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2427     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2428     radius_lw->addItem(newItem);
2429 }
2430
2431 // ============================================================== delRadiusItem
2432 void MakePipeDialog::delRadiusItem()
2433 {
2434     delete radius_lw->currentItem();
2435 }
2436
2437 // ============================================================== addAngleItem
2438 void MakePipeDialog::addAngleItem()
2439 {
2440     QListWidgetItem* previousItem = angle_lw->currentItem();
2441     QListWidgetItem* newItem      = new QListWidgetItem();
2442
2443     double defaultValue = 180.;
2444     if ( previousItem )
2445         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2446
2447     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2448     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2449     angle_lw->addItem(newItem);
2450 }
2451
2452 // ============================================================== delAngleItem
2453 void MakePipeDialog::delAngleItem()
2454 {
2455     delete angle_lw->currentItem();
2456 }
2457
2458 // ============================================================== addHeightItem
2459 void MakePipeDialog::addHeightItem()
2460 {
2461     QListWidgetItem* previousItem = height_lw->currentItem();
2462     QListWidgetItem* newItem      = new QListWidgetItem();
2463
2464     double defaultValue = 1.;
2465     if ( previousItem )
2466         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2467
2468     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2469     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2470     height_lw->addItem(newItem);
2471 }
2472
2473 // ============================================================== delHeightItem
2474 void MakePipeDialog::delHeightItem()
2475 {
2476     delete height_lw->currentItem();
2477 }
2478
2479 // ============================================================== clear
2480 void MakePipeDialog::clear()
2481 {
2482     origin_le->clear();
2483     modelUnregister(origin_le);
2484
2485     axis_le->clear();
2486     modelUnregister(axis_le);
2487
2488     base_le->clear();
2489     modelUnregister(base_le);
2490
2491     modelUnregister(this);
2492 }
2493
2494 // ============================================================== apply
2495 bool MakePipeDialog::apply(QModelIndex& result)
2496 {
2497     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2498     _currentObj = NULL;
2499
2500     DocumentModel* docModel = getDocumentModel();
2501     PatternDataModel* patternDataModel = getPatternDataModel();
2502     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2503
2504     QModelIndex iorigin = patternDataModel->mapToSource( _index[origin_le] );
2505     QModelIndex iaxis  = patternBuilderModel->mapToSource( _index[axis_le] );
2506     QModelIndex ibase = patternBuilderModel->mapToSource( _index[base_le] );
2507     double rext = ext_radius_spb->value();
2508     double rint = int_radius_spb->value();
2509     double angle = angle_spb->value();
2510     double height = height_spb->value();
2511     int nr = nr_spb->value();
2512     int na = na_spb->value();
2513     int nh = nh_spb->value();
2514
2515     QModelIndex iElts;
2516
2517     if (rb0->isChecked())
2518         iElts = docModel->makePipeTop(nr, na, nh);
2519     else if (rb1->isChecked())
2520     {
2521         if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2522             iElts = docModel->makePipeUni(iorigin, ibase, iaxis, rint, rext, angle, height,
2523                                           nr, na, nh);
2524     }
2525     else if (rb2->isChecked())
2526     {
2527         QListWidgetItem* item = NULL;
2528
2529         vector<double> radius;
2530         vector<double> angles;
2531         vector<double> heights;
2532
2533         double somme = 0.;
2534         int nbAngles = angle_lw->count();
2535         for ( int r = 0; r < nbAngles; ++r){
2536             item = angle_lw->item(r);
2537             double itemValue = item->data(Qt::EditRole).toDouble();
2538             angles.push_back(itemValue);
2539             somme += itemValue;
2540         }
2541         if (somme > 360.01)
2542         {
2543             SUIT_MessageBox::information( 0,
2544                     tr("HEXA_INFO"),
2545                     tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
2546             return false;
2547         }
2548
2549         int nbRadius = radius_lw->count();
2550         for ( int r = 0; r < nbRadius; ++r){
2551             item = radius_lw->item(r);
2552             radius.push_back(item->data(Qt::EditRole).toDouble());
2553         }
2554
2555         int nbHeight = height_lw->count();
2556         for ( int r = 0; r < nbHeight; ++r){
2557             item = height_lw->item(r);
2558             heights.push_back(item->data(Qt::EditRole).toDouble());
2559         }
2560         if ( iorigin.isValid() && iaxis.isValid() && ibase.isValid())
2561             iElts = docModel->makePipe( iorigin, ibase, iaxis, radius, angles, heights );
2562     }
2563
2564     if ( !iElts.isValid() ){
2565         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPE" ) + "\n" + getErrorMsg() );
2566         return false;
2567     }
2568
2569     // to select/highlight result
2570     result = patternBuilderModel->mapFromSource(iElts);
2571
2572     return true;
2573 }
2574
2575 //---------------------------------- MakeCylindersDialog -----------------------------
2576 // ============================================================== Constructeur
2577
2578 MakeCylindersDialog::MakeCylindersDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2579 : HexaBaseDialog(parent, editmode, f)
2580 {
2581     _helpFileName = "gui_blocks_for_cyl_pipe.html#make-cylinders";
2582     setupUi( this );
2583     _initWidget(editmode);
2584 }
2585
2586 // ============================================================== Destructeur
2587 MakeCylindersDialog::~MakeCylindersDialog()
2588 {
2589 }
2590
2591 void MakeCylindersDialog::_initInputWidget( Mode editmode )
2592 {
2593     center_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2594     center2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
2595     direction_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2596     direction2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
2597
2598     installEventFilter(this);
2599     center_le->installEventFilter(this);
2600     center2_le->installEventFilter(this);
2601     direction_le->installEventFilter(this);
2602     direction2_le->installEventFilter(this);
2603
2604     center_le->setReadOnly(true);
2605     center2_le->setReadOnly(true);
2606     direction_le->setReadOnly(true);
2607     direction2_le->setReadOnly(true);
2608 }
2609
2610 // ============================================================== clear
2611 void MakeCylindersDialog::clear()
2612 {
2613     center_le->clear();
2614     modelUnregister(center_le);
2615
2616     center2_le->clear();
2617     modelUnregister(center2_le);
2618
2619     direction_le->clear();
2620     modelUnregister(direction_le);
2621
2622     direction2_le->clear();
2623     modelUnregister(direction2_le);
2624
2625     modelUnregister(this);
2626 }
2627
2628 // ============================================================== apply
2629 bool MakeCylindersDialog::apply(QModelIndex& result)
2630 {
2631     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2632     _currentObj = NULL;
2633
2634     DocumentModel* docModel = getDocumentModel();
2635     PatternDataModel* patternDataModel = getPatternDataModel();
2636     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2637
2638     QModelIndex iElts;
2639     QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
2640     QModelIndex icenter2 = patternDataModel->mapToSource( _index[center2_le] );
2641     QModelIndex idir = patternBuilderModel->mapToSource( _index[direction_le] );
2642     QModelIndex idir2 = patternBuilderModel->mapToSource( _index[direction2_le] );
2643
2644     if ( icenter.isValid() && icenter2.isValid() && idir.isValid() && idir2.isValid()){
2645         double r1 = radius_spb->value();
2646         double h1 = height_spb->value();
2647         double r2 = radius2_spb->value();
2648         double h2 = height2_spb->value();
2649         iElts = docModel->makeCylinders( icenter, idir, r1, h1, icenter2, idir2, r2, h2 );
2650     }
2651
2652     if ( !iElts.isValid() ){
2653         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE CYLINDERS" ) + "\n" + getErrorMsg() );
2654         return false;
2655     }
2656
2657     result = patternBuilderModel->mapFromSource(iElts);
2658
2659     return true;
2660 }
2661
2662 //---------------------------------- MakePipesDialog -----------------------------
2663 // ============================================================== Constructeur
2664
2665 MakePipesDialog::MakePipesDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2666 : HexaBaseDialog(parent, editmode, f)
2667 {
2668     _helpFileName = "gui_blocks_for_cyl_pipe.html#make-pipes";
2669     setupUi( this );
2670     _initWidget(editmode);
2671 }
2672
2673 // ============================================================== Destructeur
2674 MakePipesDialog::~MakePipesDialog()
2675 {
2676 }
2677
2678 // ============================================================== _initInputWidget
2679 void MakePipesDialog::_initInputWidget( Mode editmode )
2680 {
2681     origin_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2682     origin2_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
2683     dir_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2684     dir2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2685
2686     installEventFilter(this);
2687     origin_le->installEventFilter(this);
2688     origin2_le->installEventFilter(this);
2689     dir_le->installEventFilter(this);
2690     dir2_le->installEventFilter(this);
2691
2692     origin_le->setReadOnly(true);
2693     origin2_le->setReadOnly(true);
2694     dir_le->setReadOnly(true);
2695     dir2_le->setReadOnly(true);
2696 }
2697
2698 // ============================================================== clear
2699 void MakePipesDialog::clear()
2700 {
2701     origin_le->clear();
2702     modelUnregister(origin_le);
2703
2704     origin2_le->clear();
2705     modelUnregister(origin2_le);
2706
2707     dir_le->clear();
2708     modelUnregister(dir_le);
2709
2710     dir2_le->clear();
2711     modelUnregister(dir2_le);
2712
2713     modelUnregister(this);
2714 }
2715
2716 // ============================================================== apply
2717 bool MakePipesDialog::apply(QModelIndex& result)
2718 {
2719     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2720     _currentObj = NULL;
2721
2722     DocumentModel* docModel = getDocumentModel();
2723     PatternDataModel* patternDataModel = getPatternDataModel();
2724     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2725
2726     QModelIndex iorigin1 = patternDataModel->mapToSource( _index[origin_le] );
2727     QModelIndex iorigin2 = patternDataModel->mapToSource( _index[origin2_le] );
2728     QModelIndex idir1 = patternBuilderModel->mapToSource( _index[dir_le] );
2729     QModelIndex idir2 = patternBuilderModel->mapToSource( _index[dir2_le] );
2730     double rint1 = int_radius_spb->value();
2731     double rext1 = ext_radius_spb->value();
2732     double height1 = height_spb->value();
2733     double rint2 = int_radius2_spb->value();
2734     double rext2 = ext_radius2_spb->value();
2735     double height2 = height_spb->value();
2736
2737     QModelIndex iElts;
2738
2739     if ( iorigin1.isValid() && iorigin2.isValid() && idir1.isValid() && idir2.isValid())
2740         iElts = docModel->makePipes( iorigin1, idir1, rint1, rext1, height1,
2741                                      iorigin2, idir2, rint2, rext2, height2);
2742
2743     if ( !iElts.isValid() ){
2744         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE PIPES" ) + "\n" + getErrorMsg() );
2745         return false;
2746     }
2747
2748     result = patternBuilderModel->mapFromSource(iElts);
2749
2750     return true;
2751 }
2752
2753 //---------------------------------- RemoveHexaDialog -----------------------------
2754 // ============================================================== Constructeur
2755
2756 RemoveHexaDialog::RemoveHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2757 : HexaBaseDialog(parent, editmode, f)
2758 {
2759     _helpFileName = "gui_remove.html";
2760     setupUi( this );
2761     _initWidget(editmode);
2762 }
2763
2764 // ============================================================== Destructeur
2765 RemoveHexaDialog::~RemoveHexaDialog()
2766 {
2767 }
2768
2769 // ============================================================== _initInputWidget
2770 void RemoveHexaDialog::_initInputWidget( Mode editmode )
2771 {
2772     QRegExp rx("");
2773     QValidator *validator = new QRegExpValidator(rx, this);
2774
2775     hexa_le->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
2776     hexa_le->setValidator( validator );
2777     hexa_le->installEventFilter(this);
2778     hexa_le->setReadOnly(true);
2779     autoFocusSwitch = false;
2780 }
2781
2782 // ============================================================== clear
2783 void RemoveHexaDialog::clear()
2784 {
2785     hexa_le->clear();
2786     modelUnregister(hexa_le);
2787
2788     modelUnregister(this);
2789 }
2790
2791 // ============================================================== apply
2792 bool RemoveHexaDialog::apply(QModelIndex& result)
2793 {
2794     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2795     _currentObj = NULL;
2796
2797     if ( !getDocumentModel() ) return false;
2798     const PatternDataModel*    patternDataModel = getPatternDataModel();
2799     if ( !patternDataModel ) return false;
2800
2801     QModelIndex ihexa = patternDataModel->mapToSource( _index[hexa_le] );
2802
2803     bool removed = false;
2804     if ( ihexa.isValid() ){
2805         if ( connected_cb->isChecked() ){
2806             removed = getDocumentModel()->removeConnectedHexa( ihexa );
2807         } else {
2808             removed = getDocumentModel()->removeHexa( ihexa );
2809         }
2810     }
2811
2812     if ( removed == false ){
2813         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE HEXA" ) + "\n" + getErrorMsg() );
2814         return false;
2815     }
2816
2817     clear();
2818
2819     return true;
2820 }
2821
2822 //---------------------------------- PrismQuadDialog -----------------------------
2823 // ============================================================== Constructeur
2824
2825 PrismQuadDialog::PrismQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2826 : HexaBaseDialog(parent, editmode, f)
2827 {
2828     _helpFileName = "gui_prism_join_quad.html#prism-quadrangles";
2829     setupUi( this );
2830     _initWidget(editmode);
2831     extrudeTop_rb->click();
2832 }
2833
2834 // ============================================================== Destructeur
2835 PrismQuadDialog::~PrismQuadDialog()
2836 {
2837 }
2838
2839 // ============================================================== getAssocsVTK
2840 /*
2841  * Returns elements currently associated to vtk
2842  */
2843 QModelIndexList PrismQuadDialog::getAssocsVTK()
2844 {
2845     QModelIndexList assocs;
2846     QModelIndex iQuad;
2847     QListWidgetItem* item = NULL;
2848
2849     //ListWidget content
2850     const PatternDataModel* patternDataModel = getPatternDataModel();
2851     if ( !patternDataModel ) return assocs;
2852     int nbQuads = quads_lw->count();
2853     for ( int r = 0; r < nbQuads; ++r ){
2854         item = quads_lw->item(r);
2855         iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
2856         if ( iQuad.isValid() )
2857             assocs << iQuad;
2858     }
2859     return assocs;
2860 }
2861
2862 // ============================================================== _initInputWidget
2863 void PrismQuadDialog::_initInputWidget( Mode editmode )
2864 {
2865     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
2866     axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
2867
2868     installEventFilter(this);
2869     quads_lw->installEventFilter(this);
2870     axis_le->installEventFilter(this);
2871
2872     axis_le->setReadOnly(true);
2873
2874     QShortcut* delQuadShortcut   = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
2875     delQuadShortcut->setContext( Qt::WidgetShortcut );
2876     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
2877     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
2878
2879     connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(removeQuad()) );
2880     connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
2881     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
2882     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
2883 }
2884
2885 // ============================================================== clear
2886 void PrismQuadDialog::clear()
2887 {
2888     quads_lw->clear();
2889     modelUnregister(quads_lw);
2890
2891     axis_le->clear();
2892     modelUnregister(axis_le);
2893
2894     modelUnregister(this);
2895 }
2896
2897 // ============================================================== removeQuad
2898 void PrismQuadDialog::removeQuad()
2899 {
2900     QListWidgetItem *item = quads_lw->currentItem();
2901
2902     if (item) {
2903         int r = quads_lw->row(item);
2904         quads_lw->takeItem(r);
2905         delete item;
2906     }
2907 }
2908
2909 // ============================================================== addHeightItem
2910 void PrismQuadDialog::addHeightItem()
2911 {
2912     QListWidgetItem* previousItem = height_lw->currentItem();
2913     QListWidgetItem* newItem      = new QListWidgetItem();
2914
2915     double defaultValue = 1.;
2916     if ( previousItem )
2917         defaultValue = previousItem->data(Qt::EditRole).toDouble();
2918
2919     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
2920     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
2921     height_lw->addItem(newItem);
2922 }
2923
2924 // ============================================================== delHeightItem
2925 void PrismQuadDialog::delHeightItem()
2926 {
2927     delete height_lw->currentItem();
2928 }
2929
2930 // ============================================================== apply
2931 bool PrismQuadDialog::apply(QModelIndex& result)
2932 {
2933     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
2934     _currentObj = NULL;
2935
2936     DocumentModel* docModel = getDocumentModel();
2937     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
2938
2939     QModelIndexList iquads = getIndexList(quads_lw);
2940     QModelIndex iaxis  = patternBuilderModel->mapToSource( _index[axis_le] );
2941     double length = length_spb->value();
2942     int nb = nb_spb->value();
2943
2944     vector<double> heights;
2945     QListWidgetItem* item = NULL;
2946     int nbItems = height_lw->count();
2947
2948     for ( int r = 0; r < nbItems; ++r){
2949         item = height_lw->item(r);
2950         heights.push_back( item->data(Qt::EditRole).toDouble() );
2951     }
2952
2953     QModelIndex iElts;
2954     int nbQuads = iquads.count();
2955
2956     if (nbQuads == 1 && iquads[0].isValid())
2957     {
2958         if (extrudeTop_rb->isChecked())
2959             iElts = docModel->extrudeQuadTop(iquads[0], nb);
2960         else if (extrudeUni_rb->isChecked() && iaxis.isValid())
2961             iElts = docModel->extrudeQuadUni(iquads[0], iaxis, length, nb);
2962         else if (extrude_rb->isChecked() && iaxis.isValid())
2963             iElts = docModel->extrudeQuad(iquads[0], iaxis, heights);
2964     }
2965     else if (nbQuads > 1)
2966     {
2967         if (extrudeTop_rb->isChecked())
2968             iElts = docModel->extrudeQuadsTop(iquads, nb);
2969         else if (extrudeUni_rb->isChecked() && iaxis.isValid())
2970             iElts = docModel->extrudeQuadsUni(iquads, iaxis, length, nb);
2971         else if (extrude_rb->isChecked() && iaxis.isValid())
2972             iElts = docModel->extrudeQuads(iquads, iaxis, heights);
2973     }
2974
2975     if ( !iElts.isValid() ){
2976         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PRISM QUAD(S)" ) + "\n" + getErrorMsg() );
2977         return false;
2978     }
2979
2980     result = patternBuilderModel->mapFromSource(iElts);
2981
2982     return true;
2983 }
2984
2985 //---------------------------------- JoinQuadDialog -----------------------------
2986 // ============================================================== Constructeur
2987
2988 JoinQuadDialog::JoinQuadDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
2989 : HexaBaseDialog(parent, editmode, f)
2990 {
2991     _helpFileName = "gui_prism_join_quad.html#join-quadrangles";
2992     setupUi( this );
2993     _initWidget(editmode);
2994     joinUni_rb->click();
2995 }
2996
2997 // ============================================================== Destructeur
2998 JoinQuadDialog::~JoinQuadDialog()
2999 {
3000 }
3001
3002 // ============================================================== getAssocsVTK
3003 /*
3004  * Returns elements currently associated to vtk
3005  */
3006 QModelIndexList JoinQuadDialog::getAssocsVTK()
3007 {
3008     QModelIndexList assocs;
3009     QModelIndex iQuad;
3010     QListWidgetItem* item = NULL;
3011
3012     if (getPatternDataSelectionModel() == NULL) return assocs;
3013
3014     //ListWidget content
3015     const PatternDataModel* patternDataModel = getPatternDataModel();
3016     if ( !patternDataModel ) return assocs;
3017     int nbQuads = quads_lw->count();
3018     for ( int r = 0; r < nbQuads; ++r ){
3019         item = quads_lw->item(r);
3020         //              iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
3021         iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
3022         if ( iQuad.isValid() ) assocs << iQuad;
3023     }
3024     return assocs;
3025 }
3026
3027 // ============================================================== _initInputWidget
3028 void JoinQuadDialog::_initInputWidget( Mode editmode )
3029 {
3030     quad_dest_le->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3031     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3032     vex0_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3033     vex1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3034     vex2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3035     vex3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3036
3037     installEventFilter(this);
3038     quad_dest_le->installEventFilter(this);
3039     quads_lw->installEventFilter(this);
3040     vex0_le->installEventFilter(this);
3041     vex1_le->installEventFilter(this);
3042     vex2_le->installEventFilter(this);
3043     vex3_le->installEventFilter(this);
3044
3045     QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
3046     delQuadShortcut->setContext( Qt::WidgetShortcut );
3047     connect( delQuadShortcut,   SIGNAL(activated()), this, SLOT(removeQuad()) );
3048
3049     quad_dest_le->setReadOnly(true);
3050     vex0_le->setReadOnly(true);
3051     vex1_le->setReadOnly(true);
3052     vex2_le->setReadOnly(true);
3053     vex3_le->setReadOnly(true);
3054
3055     _currentObj = quads_lw;
3056     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3057     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3058
3059     connect( quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3060
3061     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3062     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3063 }
3064
3065 // ============================================================== addHeightItem
3066 void JoinQuadDialog::addHeightItem()
3067 {
3068     QListWidgetItem* previousItem = height_lw->currentItem();
3069     QListWidgetItem* newItem      = new QListWidgetItem();
3070
3071     double defaultValue = 1.;
3072     if ( previousItem )
3073         defaultValue = previousItem->data(Qt::EditRole).toDouble();
3074
3075     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
3076     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3077     height_lw->addItem(newItem);
3078 }
3079
3080 // ============================================================== delHeightItem
3081 void JoinQuadDialog::delHeightItem()
3082 {
3083     delete height_lw->currentItem();
3084 }
3085
3086 // ============================================================== clear
3087 void JoinQuadDialog::clear()
3088 {
3089     quad_dest_le->clear();
3090     modelUnregister(quad_dest_le);
3091
3092     quads_lw->clear();
3093     modelUnregister(quads_lw);
3094
3095     vex0_le->clear();
3096     modelUnregister(vex0_le);
3097
3098     vex1_le->clear();
3099     modelUnregister(vex1_le);
3100
3101     vex2_le->clear();
3102     modelUnregister(vex2_le);
3103
3104     vex3_le->clear();
3105     modelUnregister(vex3_le);
3106
3107     modelUnregister(this);
3108 }
3109
3110 // ============================================================== removeQuad
3111 void JoinQuadDialog::removeQuad()
3112 {
3113     QListWidgetItem *item = quads_lw->currentItem();
3114
3115     if (item) {
3116         int r = quads_lw->row(item);
3117         quads_lw->takeItem(r);
3118         delete item;
3119     }
3120 }
3121
3122 // ============================================================== apply
3123 bool JoinQuadDialog::apply(QModelIndex& result)
3124 {
3125     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3126     _currentObj = NULL;
3127
3128     DocumentModel* docModel = getDocumentModel();
3129     PatternDataModel*    patternDataModel    = getPatternDataModel();
3130     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3131
3132     QModelIndexList iquads;
3133     QModelIndex     iquad;
3134     QListWidgetItem* item = NULL;
3135     int nbQuads = quads_lw->count();
3136     for ( int r = 0; r < nbQuads; ++r){
3137         item = quads_lw->item(r);
3138         iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3139         if ( iquad.isValid() )
3140             iquads << iquad;
3141     }
3142     QModelIndex iquaddest = patternDataModel->mapToSource( _index[quad_dest_le] );
3143     QModelIndex ivex0 = patternDataModel->mapToSource( _index[vex0_le] );
3144     QModelIndex ivex1 = patternDataModel->mapToSource( _index[vex1_le] );
3145     QModelIndex ivex2 = patternDataModel->mapToSource( _index[vex2_le] );
3146     QModelIndex ivex3 = patternDataModel->mapToSource( _index[vex3_le] );
3147     double nb = nb_spb->value();
3148
3149     vector<double> heights;
3150     int nbHeight = height_lw->count();
3151     for ( int r = 0; r < nbHeight; ++r){
3152         item = height_lw->item(r);
3153         heights.push_back(item->data(Qt::EditRole).toDouble());
3154     }
3155
3156     QModelIndex iElts;
3157     if (nbQuads == 1 && iquads[0].isValid() && iquaddest.isValid() && ivex0.isValid() &&
3158         ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3159     {
3160         if (joinUni_rb->isChecked())
3161             iElts = docModel->joinQuadUni(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3162         else if (join_rb->isChecked())
3163             iElts = docModel->joinQuad(iquads[0], iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3164     }
3165     else if (nbQuads > 1 && iquaddest.isValid() && ivex0.isValid() &&
3166             ivex1.isValid() && ivex2.isValid() && ivex3.isValid())
3167     {
3168         if (joinUni_rb->isChecked())
3169             iElts = docModel->joinQuadsUni(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, nb);
3170         else if (join_rb->isChecked())
3171             iElts = docModel->joinQuads(iquads, iquaddest, ivex0, ivex1, ivex2, ivex3, heights);
3172     }
3173
3174     if ( !iElts.isValid() ){
3175         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT JOIN QUAD(S)" ) + "\n" + getErrorMsg() );
3176         return false;
3177     }
3178     result = patternBuilderModel->mapFromSource(iElts);
3179
3180     return true;
3181 }
3182
3183 // ------------------------- MergeDialog ----------------------------------
3184 // ============================================================== Constructeur
3185
3186 MergeDialog::MergeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3187 : HexaBaseDialog(parent, editmode, f)
3188 {
3189     setupUi( this );
3190     _initWidget(editmode);
3191     rb0->click();
3192
3193     _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3194     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3195     connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3196     connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3197
3198     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3199     connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3200     connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3201
3202     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3203     connect( rb2, SIGNAL(cliked()), this, SLOT(clearVTKSelection()) );
3204     connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3205 }
3206
3207 // ============================================================== Destructeur
3208 MergeDialog::~MergeDialog()
3209 {
3210 }
3211
3212 // ============================================================== _initInputWidget
3213 void MergeDialog::_initInputWidget( Mode editmode )
3214 {
3215     QRegExp rx("");
3216     QValidator *validator = new QRegExpValidator(rx, this);
3217
3218     v0_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3219     v1_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3220     v0_le_rb0->setValidator( validator );
3221     v1_le_rb0->setValidator( validator );
3222     v0_le_rb0->installEventFilter(this);
3223     v1_le_rb0->installEventFilter(this);
3224
3225     v0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3226     v1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3227     e0_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3228     e1_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3229
3230     v0_le_rb1->setValidator( validator );
3231     v1_le_rb1->setValidator( validator );
3232     e0_le_rb1->setValidator( validator );
3233     e1_le_rb1->setValidator( validator );
3234
3235     v0_le_rb1->installEventFilter(this);
3236     v1_le_rb1->installEventFilter(this);
3237     e0_le_rb1->installEventFilter(this);
3238     e1_le_rb1->installEventFilter(this);
3239
3240     v0_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3241     v1_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3242     v2_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3243     v3_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3244     q0_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3245     q1_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3246
3247     v0_le_rb2->setValidator( validator );
3248     v1_le_rb2->setValidator( validator );
3249     v2_le_rb2->setValidator( validator );
3250     v3_le_rb2->setValidator( validator );
3251     q0_le_rb2->setValidator( validator );
3252     q1_le_rb2->setValidator( validator );
3253
3254     v0_le_rb2->installEventFilter(this);
3255     v1_le_rb2->installEventFilter(this);
3256     v2_le_rb2->installEventFilter(this);
3257     v3_le_rb2->installEventFilter(this);
3258     q0_le_rb2->installEventFilter(this);
3259     q1_le_rb2->installEventFilter(this);
3260
3261     v0_le_rb0->setReadOnly(true);
3262     v1_le_rb0->setReadOnly(true);
3263
3264     v0_le_rb1->setReadOnly(true);
3265     v1_le_rb1->setReadOnly(true);
3266     e0_le_rb1->setReadOnly(true);
3267     e1_le_rb1->setReadOnly(true);
3268
3269     v0_le_rb2->setReadOnly(true);
3270     v1_le_rb2->setReadOnly(true);
3271     v2_le_rb2->setReadOnly(true);
3272     v3_le_rb2->setReadOnly(true);
3273     q0_le_rb2->setReadOnly(true);
3274     q1_le_rb2->setReadOnly(true);
3275 }
3276
3277 // ============================================================== clear
3278 void MergeDialog::clear()
3279 {
3280     v0_le_rb0->clear();
3281     modelUnregister(v0_le_rb0);
3282
3283     v1_le_rb0->clear();
3284     modelUnregister(v1_le_rb0);
3285
3286     e0_le_rb1->clear();
3287     modelUnregister(e0_le_rb1);
3288
3289     e1_le_rb1->clear();
3290     modelUnregister(e1_le_rb1);
3291
3292     v0_le_rb1->clear();
3293     modelUnregister(v0_le_rb1);
3294
3295     v1_le_rb1->clear();
3296     modelUnregister(v1_le_rb1);
3297
3298     q0_le_rb2->clear();
3299     modelUnregister(q0_le_rb2);
3300
3301     q1_le_rb2->clear();
3302     modelUnregister(q1_le_rb2);
3303
3304     v0_le_rb2->clear();
3305     modelUnregister(v0_le_rb2);
3306
3307     v1_le_rb2->clear();
3308     modelUnregister(v1_le_rb2);
3309
3310     v2_le_rb2->clear();
3311     modelUnregister(v2_le_rb2);
3312
3313     v3_le_rb2->clear();
3314     modelUnregister(v3_le_rb2);
3315
3316     modelUnregister(this);
3317 }
3318
3319 // ============================================================== updateHelpFileName
3320 void MergeDialog::updateHelpFileName()
3321 {
3322     if ( sender() == rb0 ){
3323         _helpFileName = "gui_merge_elmts.html#merge-two-vertices";
3324     } else if ( sender() == rb1 ){
3325         _helpFileName = "gui_merge_elmts.html#merge-two-edges";
3326     } else if ( sender() == rb2 ){
3327         _helpFileName = "gui_merge_elmts.html#merge-two-quadrangles";
3328     }
3329 }
3330
3331 // ============================================================== apply
3332 bool MergeDialog::apply(QModelIndex& result)
3333 {
3334     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3335     _currentObj = NULL;
3336
3337     if (getDocumentModel() == NULL) return false;
3338     const PatternDataModel*    patternDataModel = getPatternDataModel();
3339     if ( !patternDataModel ) return false;
3340
3341     bool merged = false;
3342
3343     if ( rb0->isChecked() ){
3344         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb0] );
3345         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb0] );
3346
3347         if ( iv0.isValid()
3348                 && iv1.isValid() ){
3349             merged = getDocumentModel()->mergeVertices( iv0, iv1 );
3350         }
3351     } else if ( rb1->isChecked() ){
3352         QModelIndex ie0 = patternDataModel->mapToSource( _index[e0_le_rb1] );
3353         QModelIndex ie1 = patternDataModel->mapToSource( _index[e1_le_rb1] );
3354         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb1] );
3355         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb1] );
3356
3357         if ( ie0.isValid()
3358                 && ie1.isValid()
3359                 && iv0.isValid()
3360                 && iv1.isValid() ){
3361             merged =  getDocumentModel()->mergeEdges( ie0, ie1, iv0, iv1);
3362         }
3363     } else if ( rb2->isChecked() ){
3364
3365         QModelIndex iq0 = patternDataModel->mapToSource( _index[q0_le_rb2] );
3366         QModelIndex iq1 = patternDataModel->mapToSource( _index[q1_le_rb2] );
3367         QModelIndex iv0 = patternDataModel->mapToSource( _index[v0_le_rb2] );
3368         QModelIndex iv1 = patternDataModel->mapToSource( _index[v1_le_rb2] );
3369         QModelIndex iv2 = patternDataModel->mapToSource( _index[v2_le_rb2] );
3370         QModelIndex iv3 = patternDataModel->mapToSource( _index[v3_le_rb2] );
3371
3372         if ( iq0.isValid()
3373                 && iq1.isValid()
3374                 && iv0.isValid()
3375                 && iv1.isValid()
3376                 && iv2.isValid()
3377                 && iv3.isValid() ){
3378             merged =  getDocumentModel()->mergeQuads( iq0, iq1,
3379                     iv0, iv1, iv2, iv3 );
3380         }
3381     }
3382
3383     if ( merged == false ){
3384         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MERGE" ) + "\n" + getErrorMsg() );
3385         return false;
3386     }
3387
3388     return true;
3389 }
3390
3391 // ------------------------- DisconnectDialog ----------------------------------
3392 // ============================================================== Constructeur
3393
3394 DisconnectDialog::DisconnectDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3395 : HexaBaseDialog(parent, editmode, f)
3396 {
3397     setupUi( this );
3398     _initWidget(editmode);
3399     rb0->click();
3400
3401     _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3402
3403     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3404     connect( rb0, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3405     connect( rb0, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3406
3407     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3408     connect( rb1, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3409     connect( rb1, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3410
3411     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3412     connect( rb2, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3413     connect( rb2, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3414
3415     connect( rb3, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3416     connect( rb3, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
3417     connect( rb3, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
3418
3419 }
3420
3421 // ============================================================== Destructeur
3422 DisconnectDialog::~DisconnectDialog()
3423 {
3424 }
3425
3426 // ============================================================== _initInputWidget
3427 void DisconnectDialog::_initInputWidget( Mode editmode )
3428 {
3429     QRegExp rx("");
3430     QValidator *validator = new QRegExpValidator(rx, this);
3431
3432     installEventFilter(this);
3433
3434     //vertex
3435     v_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3436     h_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3437     v_le_rb0->setValidator( validator );
3438     h_le_rb0->setValidator( validator );
3439     v_le_rb0->installEventFilter(this);
3440     h_le_rb0->installEventFilter(this);
3441
3442     //edge
3443     e_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3444     h_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3445     e_le_rb1->setValidator( validator );
3446     h_le_rb1->setValidator( validator );
3447     e_le_rb1->installEventFilter(this);
3448     h_le_rb1->installEventFilter(this);
3449
3450     //quad
3451     q_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
3452     h_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3453     q_le_rb2->setValidator( validator );
3454     h_le_rb2->setValidator( validator );
3455     q_le_rb2->installEventFilter(this);
3456     h_le_rb2->installEventFilter(this);
3457
3458     //edges
3459     d_edges_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3460     hexas_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(HEXA_TREE) );
3461     d_edges_lw->installEventFilter(this);
3462     hexas_lw->installEventFilter(this);
3463
3464     QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), d_edges_lw);
3465     QShortcut* delHexaShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), hexas_lw);
3466     delEdgeShortcut->setContext( Qt::WidgetShortcut );
3467     delHexaShortcut->setContext( Qt::WidgetShortcut );
3468
3469     v_le_rb0->setReadOnly(true);
3470     h_le_rb0->setReadOnly(true);
3471
3472     e_le_rb1->setReadOnly(true);
3473     h_le_rb1->setReadOnly(true);
3474
3475     q_le_rb2->setReadOnly(true);
3476     h_le_rb2->setReadOnly(true);
3477
3478     connect( d_edges_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3479     connect( hexas_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
3480     connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
3481     connect( delHexaShortcut, SIGNAL(activated()), this, SLOT(deleteHexaItem()) );
3482     autoFocusSwitch = false;
3483
3484 }
3485
3486 // =============================================== getAssocsVTK
3487 /*
3488  * Returns elements in the list
3489  */
3490 QModelIndexList DisconnectDialog::getAssocsVTK()
3491 {
3492     QModelIndexList iElts;
3493     QModelIndex index;
3494     QListWidgetItem* item = NULL;
3495
3496     const PatternDataModel* patternDataModel = getPatternDataModel();
3497     if (patternDataModel == NULL || !rb3->isChecked())
3498         return iElts;
3499     //ListWidget content
3500     if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == EDGE_TREE)
3501     {
3502         int nbEdges = d_edges_lw->count();
3503         for ( int r = 0; r < nbEdges; ++r )
3504         {
3505                 item = d_edges_lw->item(r);
3506                 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3507                 if ( index.isValid() )
3508                         iElts << index;
3509         }
3510     }
3511     else if (HEXABLOCKGUI::currentDocGView->getSelectionMode() == HEXA_TREE)
3512     {
3513         int nbHexas = hexas_lw->count();
3514         for ( int r = 0; r < nbHexas; ++r )
3515         {
3516                 item = hexas_lw->item(r);
3517                 index = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3518                 if ( index.isValid() )
3519                         iElts << index;
3520         }
3521     }
3522     return iElts;
3523 }
3524
3525 // ============================================================== clear
3526 void DisconnectDialog::clear()
3527 {
3528     v_le_rb0->clear();
3529     modelUnregister(v_le_rb0);
3530
3531     h_le_rb0->clear();
3532     modelUnregister(h_le_rb0);
3533
3534     e_le_rb1->clear();
3535     modelUnregister(e_le_rb1);
3536
3537     h_le_rb1->clear();
3538     modelUnregister(h_le_rb1);
3539
3540     d_edges_lw->clear();
3541     modelUnregister(d_edges_lw);
3542
3543     hexas_lw->clear();
3544     modelUnregister(hexas_lw);
3545
3546     q_le_rb2->clear();
3547     modelUnregister(q_le_rb2);
3548
3549     h_le_rb2->clear();
3550     modelUnregister(h_le_rb2);
3551
3552     modelUnregister(this);
3553 }
3554
3555 // ============================================================== deleteEdgeItem
3556 void DisconnectDialog::deleteEdgeItem()
3557 {
3558     delete d_edges_lw->currentItem();
3559 }
3560
3561 // ============================================================== deleteHexaItem
3562 void DisconnectDialog::deleteHexaItem()
3563 {
3564     delete hexas_lw->currentItem();
3565 }
3566
3567 // ============================================================== updateHelpFileName
3568 void DisconnectDialog::updateHelpFileName()
3569 {
3570     if ( sender() == rb0 ){
3571         _helpFileName = "gui_disc_elmts.html#disconnect-a-vertex";
3572     } else if ( sender() == rb1 ){
3573         _helpFileName = "gui_disc_elmts.html#disconnect-an-edge";
3574     } else if ( sender() == rb2 ){
3575         _helpFileName = "gui_disc_elmts.html#disconnect-a-quadrangle";
3576     } else if (sender() == rb3 ){
3577         _helpFileName = "gui_disc_elmts.html#disconnect-edges";
3578     }
3579 }
3580
3581 // ============================================================== apply
3582 bool DisconnectDialog::apply(QModelIndex& result)
3583 {
3584     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3585     _currentObj = NULL;
3586     if (getDocumentModel() == NULL) return false;
3587     const PatternDataModel*    patternDataModel    = getPatternDataModel();
3588     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3589     if ( !patternDataModel || !patternBuilderModel)    return false;
3590
3591     QModelIndex iElts;
3592
3593     if ( rb0->isChecked() ){
3594         QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb0] );
3595         QModelIndex ivex  = patternDataModel->mapToSource( _index[v_le_rb0] );
3596
3597         if ( ihexa.isValid()
3598                 && ivex.isValid() ){
3599             iElts = getDocumentModel()->disconnectVertex( ihexa, ivex );
3600         }
3601     } else if ( rb1->isChecked() ){
3602         QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb1] );
3603         QModelIndex iedge = patternDataModel->mapToSource( _index[e_le_rb1] );
3604
3605         if ( ihexa.isValid()
3606                 && iedge.isValid() ){
3607             iElts = getDocumentModel()->disconnectEdge( ihexa, iedge );
3608         }
3609     } else if ( rb2->isChecked() ){
3610         QModelIndex ihexa = patternDataModel->mapToSource( _index[h_le_rb2] );
3611         QModelIndex iquad = patternDataModel->mapToSource( _index[q_le_rb2] );
3612
3613         if ( ihexa.isValid()
3614                 && iquad.isValid() ){
3615             iElts = getDocumentModel()->disconnectQuad( ihexa, iquad );
3616         }
3617     } else if ( rb3->isChecked() ){ //
3618
3619         QModelIndex iedge, ihexa;
3620         QModelIndexList iedges, ihexas;
3621         QListWidgetItem* item = NULL;
3622
3623         //Liste des edges
3624         int nbEdges = d_edges_lw->count();
3625         for (int r = 0; r < nbEdges; ++r){
3626             item = d_edges_lw->item(r);
3627             iedge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3628             if ( iedge.isValid() )
3629                 iedges << iedge;
3630         }
3631
3632         //Liste des hexas
3633         int nbHexas = hexas_lw->count();
3634         for (int r = 0; r < nbHexas; ++r){
3635             item = hexas_lw->item(r);
3636             ihexa = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
3637             if ( ihexa.isValid() )
3638                 ihexas << ihexa;
3639         }
3640
3641         iElts = getDocumentModel()->disconnectEdges( ihexas, iedges );
3642     }
3643
3644     if ( !iElts.isValid() ){
3645         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT DISCONNECT" ) + "\n" + getErrorMsg() );
3646         return false;
3647     }
3648
3649     result = patternBuilderModel->mapFromSource(iElts);
3650
3651     return true;
3652 }
3653
3654
3655 // ------------------------- CutEdgeDialog ----------------------------------
3656 // ============================================================== Constructeur
3657
3658 CutEdgeDialog::CutEdgeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3659 HexaBaseDialog(parent, editmode, f)
3660 {
3661     _helpFileName = "gui_cut_hexa.html";
3662     setupUi( this );
3663     _initWidget(editmode);
3664
3665     cutUni_rb->click();
3666 }
3667
3668 // ============================================================== Destructeur
3669 CutEdgeDialog::~CutEdgeDialog()
3670 {
3671 }
3672
3673 // ============================================================== _initInputWidget
3674 void CutEdgeDialog::_initInputWidget( Mode editmode )
3675 {
3676     installEventFilter(this);
3677
3678     e_le->setProperty( "HexaWidgetType",  QVariant::fromValue(EDGE_TREE) );
3679     e_le->installEventFilter(this);
3680
3681     e_le->setReadOnly(true);
3682
3683     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
3684     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
3685
3686     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
3687     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
3688 }
3689
3690 // ============================================================== clear
3691 void CutEdgeDialog::clear()
3692 {
3693     e_le->clear();
3694     modelUnregister(e_le);
3695
3696     modelUnregister(this);
3697 }
3698
3699 // ============================================================== addHeightItem
3700 void CutEdgeDialog::addHeightItem()
3701 {
3702     QListWidgetItem* previousItem = height_lw->currentItem();
3703     QListWidgetItem* newItem      = new QListWidgetItem();
3704
3705     double defaultValue = 1.;
3706     if ( previousItem )
3707         defaultValue = previousItem->data(Qt::EditRole).toDouble();
3708
3709     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
3710     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
3711     height_lw->addItem(newItem);
3712 }
3713
3714 // ============================================================== delHeightItem
3715 void CutEdgeDialog::delHeightItem()
3716 {
3717     delete height_lw->currentItem();
3718 }
3719
3720 // ============================================================== apply
3721 bool CutEdgeDialog::apply(QModelIndex& result)
3722 {
3723     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3724     _currentObj = NULL;
3725
3726     DocumentModel* docModel = getDocumentModel();
3727     PatternDataModel*    patternDataModel    = getPatternDataModel();
3728     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3729
3730     QModelIndex iElts;
3731     QModelIndex iedge = patternDataModel->mapToSource( _index[e_le] );
3732
3733     if (cutUni_rb->isChecked() && iedge.isValid())
3734     {
3735         int nbCut = nb_cut_spb->value();
3736         iElts = docModel->cutUni(iedge, nbCut);
3737     }
3738     else if (cut_rb->isChecked() && iedge.isValid())
3739     {
3740         vector<double> heights;
3741         QListWidgetItem* item = NULL;
3742         int nbItems = height_lw->count();
3743
3744         for ( int r = 0; r < nbItems; ++r){
3745             item = height_lw->item(r);
3746             heights.push_back( item->data(Qt::EditRole).toDouble() );
3747         }
3748
3749         iElts = docModel->cut(iedge, heights);
3750     }
3751
3752     if ( !iElts.isValid() ){
3753         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT CUT EDGE" ) + "\n" + getErrorMsg() );
3754         return false;
3755     }
3756
3757     result = patternBuilderModel->mapFromSource(iElts);
3758
3759     //Update the line edit
3760     QVariant invalid;
3761     e_le->setProperty("QModelIndex",  invalid );
3762
3763     QModelIndex invalidIndex;
3764     _index[e_le] = invalidIndex;
3765
3766     clear();
3767
3768     return true;
3769 }
3770
3771 // // ------------------------- MakeTransformationDialog ----------------------------------
3772 // ============================================================== Constructeur
3773
3774 MakeTransformationDialog::MakeTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
3775 : HexaBaseDialog(parent, editmode, f)
3776 {
3777     setupUi( this );
3778     _initWidget(editmode);
3779     rb0->click();
3780
3781     _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3782     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3783     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3784     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3785 }
3786
3787 // ============================================================== Destructeur
3788 MakeTransformationDialog::~MakeTransformationDialog()
3789 {
3790 }
3791
3792 // ============================================================== _initInputWidget
3793 void MakeTransformationDialog::_initInputWidget( Mode editmode )
3794 {
3795     QRegExp rx("");
3796     QValidator *validator = new QRegExpValidator(rx, this);
3797
3798     installEventFilter(this);
3799
3800     vec_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VECTOR_TREE) );
3801     elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3802
3803     vec_le_rb0->setValidator( validator );
3804     elts_le_rb0->setValidator( validator );
3805     vec_le_rb0->installEventFilter(this);
3806     elts_le_rb0->installEventFilter(this);
3807
3808     vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3809     elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3810     vex_le_rb1->setValidator( validator );
3811     elts_le_rb1->setValidator( validator );
3812     vex_le_rb1->installEventFilter(this);
3813     elts_le_rb1->installEventFilter(this);
3814
3815     vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3816     vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3817     elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3818     vex_le_rb2->setValidator( validator );
3819     vec_le_rb2->setValidator( validator );
3820     elts_le_rb2->setValidator( validator );
3821     vex_le_rb2->installEventFilter(this);
3822     vec_le_rb2->installEventFilter(this);
3823     elts_le_rb2->installEventFilter(this);
3824
3825     vec_le_rb0->setReadOnly(true);
3826     elts_le_rb0->setReadOnly(true);
3827
3828     vex_le_rb1->setReadOnly(true);
3829     elts_le_rb1->setReadOnly(true);
3830
3831     vex_le_rb2->setReadOnly(true);
3832     vec_le_rb2->setReadOnly(true);
3833     elts_le_rb2->setReadOnly(true);
3834
3835 }
3836
3837 // ============================================================== clear
3838 void MakeTransformationDialog::clear()
3839 {
3840     elts_le_rb0->clear();
3841     modelUnregister(elts_le_rb0);
3842
3843     vec_le_rb0->clear();
3844     modelUnregister(vec_le_rb0);
3845
3846     elts_le_rb1->clear();
3847     modelUnregister(elts_le_rb1);
3848
3849     vex_le_rb1->clear();
3850     modelUnregister(vex_le_rb1);
3851
3852     elts_le_rb2->clear();
3853     modelUnregister(elts_le_rb2);
3854
3855     vex_le_rb2->clear();
3856     modelUnregister(vex_le_rb2);
3857
3858     vec_le_rb2->clear();
3859     modelUnregister(vec_le_rb2);
3860
3861     modelUnregister(this);
3862 }
3863
3864 // ============================================================== updateHelpFileName
3865 void MakeTransformationDialog::updateHelpFileName()
3866 {
3867     if ( sender() == rb0 ){
3868         _helpFileName = "gui_make_elmts.html#make-elements-by-translation";
3869     } else if ( sender() == rb1 ){
3870         _helpFileName = "gui_make_elmts.html#make-elements-by-scaling";
3871     } else if ( sender() == rb2 ){
3872         _helpFileName = "gui_make_elmts.html#make-elements-by-rotation";
3873     }
3874 }
3875
3876 // ============================================================== apply
3877 bool MakeTransformationDialog::apply(QModelIndex& result)
3878 {
3879     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
3880     _currentObj = NULL;
3881
3882     if (getDocumentModel() == NULL) return false;
3883     const PatternDataModel*    patternDataModel    = getPatternDataModel();
3884     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
3885     if ( !patternDataModel || !patternBuilderModel)    return false;
3886
3887     QModelIndex iNewElts;
3888
3889     if ( rb0->isChecked() ){
3890         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
3891         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
3892
3893         if ( ielts.isValid()
3894                 && ivec.isValid() )
3895             iNewElts = getDocumentModel()->makeTranslation( ielts, ivec );
3896
3897     } else if ( rb1->isChecked() ){
3898         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
3899         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
3900         double          k = k_spb->value();
3901
3902         if ( ielts.isValid()
3903                 && ivex.isValid() )
3904             iNewElts = getDocumentModel()->makeScale( ielts, ivex, k );
3905
3906     } else if ( rb2->isChecked() ){
3907         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
3908         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
3909         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
3910         double      angle = angle_spb->value();
3911
3912         if ( ielts.isValid()
3913                 && ivex.isValid()
3914                 && ivec.isValid() )
3915             iNewElts = getDocumentModel()->makeRotation( ielts, ivex, ivec, angle );
3916     }
3917
3918     if ( !iNewElts.isValid() ){
3919         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
3920         return false;
3921     }
3922
3923     result = patternBuilderModel->mapFromSource(iNewElts);
3924
3925     return true;
3926 }
3927
3928 // // ------------------------- MakeSymmetryDialog ----------------------------------
3929 // ============================================================== Constructeur
3930
3931 MakeSymmetryDialog::MakeSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
3932 HexaBaseDialog(parent, editmode, f)
3933 {
3934     setupUi( this );
3935     _initWidget(editmode);
3936     rb0->click();
3937
3938     _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
3939     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3940     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3941     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
3942 }
3943
3944 // ============================================================== Destructeur
3945 MakeSymmetryDialog::~MakeSymmetryDialog()
3946 {
3947 }
3948
3949 // ============================================================== _initInputWidget
3950 void MakeSymmetryDialog::_initInputWidget( Mode editmode )
3951 {
3952     QRegExp rx("");
3953     QValidator *validator = new QRegExpValidator(rx, this);
3954
3955     installEventFilter(this);
3956
3957     vex_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
3958     elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
3959     vex_le_rb0->setValidator( validator );
3960     elts_le_rb0->setValidator( validator );
3961     vex_le_rb0->installEventFilter(this);
3962     elts_le_rb0->installEventFilter(this);
3963
3964     vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3965     vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3966     elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3967     vex_le_rb1->setValidator( validator );
3968     vec_le_rb1->setValidator( validator );
3969     elts_le_rb1->setValidator( validator );
3970     vex_le_rb1->installEventFilter(this);
3971     vec_le_rb1->installEventFilter(this);
3972     elts_le_rb1->installEventFilter(this);
3973
3974     vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
3975     vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
3976     elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
3977     vex_le_rb2->setValidator( validator );
3978     vec_le_rb2->setValidator( validator );
3979     elts_le_rb2->setValidator( validator );
3980     vex_le_rb2->installEventFilter(this);
3981     vec_le_rb2->installEventFilter(this);
3982     elts_le_rb2->installEventFilter(this);
3983
3984     vex_le_rb0->setReadOnly(true);
3985     elts_le_rb0->setReadOnly(true);
3986     vex_le_rb1->setReadOnly(true);
3987     vec_le_rb1->setReadOnly(true);
3988     elts_le_rb1->setReadOnly(true);
3989     vex_le_rb2->setReadOnly(true);
3990     vec_le_rb2->setReadOnly(true);
3991     elts_le_rb2->setReadOnly(true);
3992 }
3993
3994 // ============================================================== clear
3995 void MakeSymmetryDialog::clear()
3996 {
3997     elts_le_rb0->clear();
3998     modelUnregister(elts_le_rb0);
3999
4000     vex_le_rb0->clear();
4001     modelUnregister(vex_le_rb0);
4002
4003     elts_le_rb1->clear();
4004     modelUnregister(elts_le_rb1);
4005
4006     vex_le_rb1->clear();
4007     modelUnregister(vex_le_rb1);
4008
4009     vec_le_rb1->clear();
4010     modelUnregister(vec_le_rb1);
4011
4012     elts_le_rb2->clear();
4013     modelUnregister(elts_le_rb2);
4014
4015     vex_le_rb2->clear();
4016     modelUnregister(vex_le_rb2);
4017
4018     vec_le_rb2->clear();
4019     modelUnregister(vec_le_rb2);
4020
4021     modelUnregister(this);
4022 }
4023
4024 // ============================================================== updateHelpFileName
4025 void MakeSymmetryDialog::updateHelpFileName()
4026 {
4027     if ( sender() == rb0 ){
4028         _helpFileName = "gui_make_symmetry.html#make-elements-by-point-symmetry";
4029     } else if ( sender() == rb1 ){
4030         _helpFileName = "gui_make_symmetry.html#make-elements-by-line-symmetry";
4031     } else if ( sender() == rb2 ){
4032         _helpFileName = "gui_make_symmetry.html#make-elements-by-plane-symmetry";
4033     }
4034 }
4035
4036 // ============================================================== apply
4037 bool MakeSymmetryDialog::apply(QModelIndex& result)
4038 {
4039     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4040     _currentObj = NULL;
4041     if (getDocumentModel() == NULL) return false;
4042     const PatternDataModel*    patternDataModel    = getPatternDataModel();
4043     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4044     if ( !patternDataModel || !patternBuilderModel)    return false;
4045
4046     QModelIndex iNewElts;
4047
4048     if ( rb0->isChecked() ){
4049         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4050         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4051
4052         if ( ielts.isValid()
4053                 && ivex.isValid() )
4054             iNewElts = getDocumentModel()->makeSymmetryPoint( ielts, ivex );
4055
4056
4057     } else if ( rb1->isChecked() ){
4058         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4059         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4060         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4061
4062         if ( ielts.isValid()
4063                 && ivex.isValid()
4064                 && ivec.isValid() )
4065             iNewElts = getDocumentModel()->makeSymmetryLine( ielts, ivex, ivec );
4066
4067     } else if ( rb2->isChecked() ){
4068         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4069         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4070         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4071
4072         if ( ielts.isValid()
4073                 && ivex.isValid()
4074                 && ivec.isValid() )
4075             iNewElts = getDocumentModel()->makeSymmetryPlane( ielts, ivex, ivec );
4076     }
4077
4078     if ( !iNewElts.isValid() ){
4079         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE TRANSFORMATION" ) + "\n" + getErrorMsg() );
4080         return false;
4081     }
4082
4083     result = patternBuilderModel->mapFromSource(iNewElts);
4084
4085     return true;
4086 }
4087
4088 // // ------------------------- PerformTransformationDialog ----------------------------------
4089 // ============================================================== Constructeur
4090 PerformTransformationDialog::PerformTransformationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4091 HexaBaseDialog(parent, editmode, f)
4092 {
4093     setupUi( this );
4094     _initWidget(editmode);
4095     rb0->click();
4096
4097     _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4098     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4099     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4100     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4101 }
4102
4103 // ============================================================== Destructeur
4104 PerformTransformationDialog::~PerformTransformationDialog()
4105 {
4106 }
4107
4108 // ============================================================== _initInputWidget
4109 void PerformTransformationDialog::_initInputWidget( Mode editmode )
4110 {
4111     QRegExp rx("");
4112     QValidator *validator = new QRegExpValidator(rx, this);
4113
4114     vec_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
4115     elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4116     vec_le_rb0->setValidator( validator );
4117     elts_le_rb0->setValidator( validator );
4118     vec_le_rb0->installEventFilter(this);
4119     elts_le_rb0->installEventFilter(this);
4120
4121     vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
4122     elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
4123     vex_le_rb1->setValidator( validator );
4124     elts_le_rb1->setValidator( validator );
4125     vex_le_rb1->installEventFilter(this);
4126     elts_le_rb1->installEventFilter(this);
4127
4128
4129     vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
4130     vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
4131     elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
4132     vex_le_rb2->setValidator( validator );
4133     vec_le_rb2->setValidator( validator );
4134     elts_le_rb2->setValidator( validator );
4135     vex_le_rb2->installEventFilter(this);
4136     vec_le_rb2->installEventFilter(this);
4137     elts_le_rb2->installEventFilter(this);
4138
4139     vec_le_rb0->setReadOnly(true);
4140     elts_le_rb0->setReadOnly(true);
4141     vex_le_rb1->setReadOnly(true);
4142     elts_le_rb1->setReadOnly(true);
4143     vex_le_rb2->setReadOnly(true);
4144     vec_le_rb2->setReadOnly(true);
4145     elts_le_rb2->setReadOnly(true);
4146
4147 }
4148
4149 // ============================================================== clear
4150 void PerformTransformationDialog::clear()
4151 {
4152     vec_le_rb0->clear();
4153     modelUnregister(vec_le_rb0);
4154
4155     elts_le_rb0->clear();
4156     modelUnregister(elts_le_rb0);
4157
4158     vex_le_rb1->clear();
4159     modelUnregister(vex_le_rb1);
4160
4161     elts_le_rb1->clear();
4162     modelUnregister(elts_le_rb1);
4163
4164     vex_le_rb2->clear();
4165     modelUnregister(vex_le_rb2);
4166
4167     vec_le_rb2->clear();
4168     modelUnregister(vec_le_rb2);
4169
4170     elts_le_rb2->clear();
4171     modelUnregister(elts_le_rb2);
4172
4173     modelUnregister(this);
4174 }
4175
4176 // ============================================================== updateHelpFileName
4177 void PerformTransformationDialog::updateHelpFileName()
4178 {
4179     if ( sender() == rb0 ){
4180         _helpFileName = "gui_modify_elmts.html#modify-elements-by-translation";
4181     } else if ( sender() == rb1 ){
4182         _helpFileName = "gui_modify_elmts.html#modify-elements-by-scaling";
4183     } else if ( sender() == rb2 ){
4184         _helpFileName = "gui_modify_elmts.html#modify-elements-by-rotation";
4185     }
4186 }
4187
4188 // ============================================================== apply
4189 bool PerformTransformationDialog::apply(QModelIndex& result)
4190 {
4191     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4192     _currentObj = NULL;
4193
4194     if (getDocumentModel() == NULL) return false;
4195     const PatternDataModel*    patternDataModel    = getPatternDataModel();
4196     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4197     if ( !patternDataModel || !patternBuilderModel)    return false;
4198
4199     bool performed = false;
4200
4201     if ( rb0->isChecked() ){
4202         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4203         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb0] );
4204
4205         if ( ielts.isValid()
4206                 && ivec.isValid() )
4207             performed = getDocumentModel()->performTranslation( ielts, ivec );
4208
4209     } else if ( rb1->isChecked() ){
4210         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4211         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4212         double          k = k_spb->value();
4213
4214         if ( ielts.isValid()
4215                 && ivex.isValid() )
4216             performed = getDocumentModel()->performScale( ielts, ivex, k );
4217
4218     } else if ( rb2->isChecked() ){
4219         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4220         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4221         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4222         double      angle = angle_spb->value();
4223
4224         if ( ielts.isValid()
4225                 && ivex.isValid()
4226                 && ivec.isValid() )
4227             performed = getDocumentModel()->performRotation( ielts, ivex, ivec, angle );
4228     }
4229
4230     if ( performed == false){
4231         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM TRANSFORMATION" ) + "\n" + getErrorMsg() );
4232         return false;
4233     }
4234
4235     return true;
4236 }
4237
4238 // // ------------------------- PerformSymmetryDialog ----------------------------------
4239 // ============================================================== Constructeur
4240 PerformSymmetryDialog::PerformSymmetryDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
4241 : HexaBaseDialog(parent, editmode, f)
4242 {
4243     setupUi( this );
4244     _initWidget( editmode );
4245     rb0->click();
4246
4247     _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4248     connect( rb0, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4249     connect( rb1, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4250     connect( rb2, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
4251 }
4252
4253 // ============================================================== Destructeur
4254 PerformSymmetryDialog::~PerformSymmetryDialog()
4255 {
4256 }
4257
4258 // ============================================================== _initInputWidget
4259 void PerformSymmetryDialog::_initInputWidget( Mode editmode )
4260 {
4261     QRegExp rx("");
4262     QValidator *validator = new QRegExpValidator(rx, this);
4263
4264     vex_le_rb0->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
4265     elts_le_rb0->setProperty( "HexaWidgetType", QVariant::fromValue(ELEMENTS_TREE) );
4266     vex_le_rb0->setValidator( validator );
4267     elts_le_rb0->setValidator( validator );
4268     vex_le_rb0->installEventFilter(this);
4269     elts_le_rb0->installEventFilter(this);
4270
4271     vex_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
4272     vec_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
4273     elts_le_rb1->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
4274     vex_le_rb1->setValidator( validator );
4275     vec_le_rb1->setValidator( validator );
4276     elts_le_rb1->setValidator( validator );
4277     vex_le_rb1->installEventFilter(this);
4278     vec_le_rb1->installEventFilter(this);
4279     elts_le_rb1->installEventFilter(this);
4280
4281     vex_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
4282     vec_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
4283     elts_le_rb2->setProperty( "HexaWidgetType",  QVariant::fromValue(ELEMENTS_TREE) );
4284     vex_le_rb2->setValidator( validator );
4285     vec_le_rb2->setValidator( validator );
4286     elts_le_rb2->setValidator( validator );
4287     vex_le_rb2->installEventFilter(this);
4288     vec_le_rb2->installEventFilter(this);
4289     elts_le_rb2->installEventFilter(this);
4290
4291     vex_le_rb0->setReadOnly(true);
4292     elts_le_rb0->setReadOnly(true);
4293     vex_le_rb1->setReadOnly(true);
4294     vec_le_rb1->setReadOnly(true);
4295     elts_le_rb1->setReadOnly(true);
4296     vex_le_rb2->setReadOnly(true);
4297     vec_le_rb2->setReadOnly(true);
4298     elts_le_rb2->setReadOnly(true);
4299
4300 }
4301
4302 // ============================================================== clear
4303 void PerformSymmetryDialog::clear()
4304 {
4305     vex_le_rb0->clear();
4306     modelUnregister(vex_le_rb0);
4307
4308     elts_le_rb0->clear();
4309     modelUnregister(elts_le_rb0);
4310
4311     elts_le_rb1->clear();
4312     modelUnregister(elts_le_rb1);
4313
4314     vex_le_rb1->clear();
4315     modelUnregister(vex_le_rb1);
4316
4317     vec_le_rb1->clear();
4318     modelUnregister(vec_le_rb1);
4319
4320     elts_le_rb2->clear();
4321     modelUnregister(elts_le_rb2);
4322
4323     vex_le_rb2->clear();
4324     modelUnregister(vex_le_rb2);
4325
4326     vec_le_rb2->clear();
4327     modelUnregister(vec_le_rb2);
4328
4329     modelUnregister(this);
4330 }
4331
4332 // ============================================================== updateHelpFileName
4333 void PerformSymmetryDialog::updateHelpFileName()
4334 {
4335     if ( sender() == rb0 ){
4336         _helpFileName = "gui_modify_symmetry.html#modify-elements-by-point-symmetry";
4337     } else if ( sender() == rb1 ){
4338         _helpFileName = "gui_modify_symmetry.html#modify-elements-by-line-symmetry";
4339     } else if ( sender() == rb2 ){
4340         _helpFileName = "gui_modify_symmetry.html#modify-elements-by-plane-symmetry";
4341     }
4342 }
4343
4344 // ============================================================== apply
4345 bool PerformSymmetryDialog::apply(QModelIndex& result)
4346 {
4347     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4348     _currentObj = NULL;
4349
4350     if (getDocumentModel() == NULL) return false;
4351     const PatternDataModel*    patternDataModel    = getPatternDataModel();
4352     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
4353     if ( !patternDataModel || !patternBuilderModel)    return false;
4354
4355     bool performed = false;
4356
4357     if ( rb0->isChecked() ){
4358         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb0] );
4359         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb0] );
4360
4361         if ( ielts.isValid()
4362                 && ivex.isValid() )
4363             performed = getDocumentModel()->performSymmetryPoint( ielts, ivex );
4364
4365     } else if ( rb1->isChecked() ){
4366         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb1] );
4367         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb1] );
4368         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb1] );
4369
4370         if ( ielts.isValid()
4371                 && ivex.isValid()
4372                 && ivec.isValid() )
4373             performed = getDocumentModel()->performSymmetryLine( ielts, ivex, ivec );
4374
4375     } else if ( rb2->isChecked() ){
4376         QModelIndex ielts = patternBuilderModel->mapToSource( _index[elts_le_rb2] );
4377         QModelIndex  ivex = patternDataModel->mapToSource( _index[vex_le_rb2] );
4378         QModelIndex  ivec = patternBuilderModel->mapToSource( _index[vec_le_rb2] );
4379
4380         if ( ielts.isValid()
4381                 && ivex.isValid()
4382                 && ivec.isValid() )
4383             performed = getDocumentModel()->performSymmetryPlane( ielts, ivex, ivec );
4384     }
4385
4386     if ( performed == false ){
4387         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT PERFORM SYMMETRY" ) + "\n" + getErrorMsg() );
4388         return false;
4389     }
4390
4391     return true;
4392 }
4393
4394 // // ------------------------- EdgeAssocDialog ----------------------------------
4395 // ============================================================== Constructeur
4396 EdgeAssocDialog::EdgeAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4397 HexaBaseDialog( parent, editmode, f )
4398 {
4399     _helpFileName ="gui_asso_quad_to_geom.html#one-edge";
4400     setupUi( this );
4401     _initWidget(editmode);
4402     myLine = NULL;
4403     single_rb->click();
4404 }
4405
4406 // ============================================================== Destructeur
4407 EdgeAssocDialog::~EdgeAssocDialog()
4408 {
4409 }
4410
4411 // ============================================================== close
4412 void EdgeAssocDialog::close()
4413 {
4414     HEXABLOCKGUI::assocInProgress = false;
4415     HexaBaseDialog::close();
4416 }
4417
4418 // ============================================================== _initInputWidget
4419 void EdgeAssocDialog::_initInputWidget( Mode editmode )
4420 {
4421     QRegExp rx("");
4422     QValidator *validator = new QRegExpValidator(rx, this);
4423
4424     //model
4425     first_vex_le->setProperty( "HexaWidgetType", QVariant::fromValue(VERTEX_TREE) );
4426     first_vex_le->installEventFilter(this);
4427     first_vex_le->setValidator( validator );
4428
4429     single_edge_le->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4430     single_edge_le->installEventFilter(this);
4431
4432     edges_lw->setProperty( "HexaWidgetType", QVariant::fromValue(EDGE_TREE) );
4433     edges_lw->installEventFilter(this);
4434
4435
4436     //geom
4437     lines_lw->setProperty("HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4438     lines_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4439     lines_lw->installEventFilter(this);
4440
4441     single_line_le->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMEDGE_TREE) );
4442     single_line_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_EDGE) );
4443     single_line_le->installEventFilter(this);
4444
4445
4446     QShortcut* delEdgeShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), edges_lw);
4447     QShortcut* delLineShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X), lines_lw);
4448     delLineShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4449     delEdgeShortcut->setContext( Qt::WidgetWithChildrenShortcut );
4450
4451     pend_spb->setValue(1.);
4452
4453     first_vex_le->setReadOnly(true);
4454     single_edge_le->setReadOnly(true);
4455     single_line_le->setReadOnly(true);
4456
4457     connect( delEdgeShortcut, SIGNAL(activated()), this, SLOT(deleteEdgeItem()) );
4458     connect( delLineShortcut, SIGNAL(activated()), this, SLOT(deleteLineItem()) );
4459     connect( edges_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
4460     connect( lines_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4461     connect( single_rb,   SIGNAL(clicked()), this, SLOT( refreshHighlight()), Qt::UniqueConnection );
4462     connect( multiple_rb,   SIGNAL(clicked()), this, SLOT(refreshHighlight()), Qt::UniqueConnection );
4463     connect( single_rb,   SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4464     connect( multiple_rb,   SIGNAL(clicked()), this, SLOT( updateHelpFileName() ) );
4465 }
4466
4467 // ============================================================== updateHelpFileName
4468 void EdgeAssocDialog::updateHelpFileName()
4469 {
4470     if ( sender() == single_rb ){
4471         _helpFileName = "gui_asso_quad_to_geom.html#one-edge";
4472     } else if ( sender() == multiple_rb ){
4473         _helpFileName = "gui_asso_quad_to_geom.html#line";
4474     }
4475 }
4476
4477 // ============================================================== getAssocsVTK
4478 /*
4479  * Returns elements currently being associated in vtk side
4480  */
4481 QModelIndexList EdgeAssocDialog::getAssocsVTK()
4482 {
4483     QModelIndexList assocs;
4484     QModelIndex iEdge;
4485     QListWidgetItem* item = NULL;
4486
4487     if (getPatternDataSelectionModel() == NULL) return assocs;
4488     if (single_rb->isChecked())
4489     {
4490         //LineEdit content
4491         QVariant v = single_edge_le->property("QModelIndex");
4492         if ( !v.isValid() ) return assocs;
4493         assocs << v.value<QModelIndex>();
4494         return assocs;
4495     }
4496     else if (multiple_rb->isChecked())
4497     {
4498         //ListWidget content
4499         const PatternDataModel* patternDataModel = getPatternDataModel();
4500         if ( !patternDataModel ) return assocs;
4501         int nbEdges = edges_lw->count();
4502         for ( int r = 0; r < nbEdges; ++r){
4503             item = edges_lw->item(r);
4504             iEdge = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4505             if ( iEdge.isValid() ) assocs << iEdge;
4506         }
4507         return assocs;
4508     }
4509     else return assocs;
4510 }
4511
4512 // ============================================================== getAssocsGEOM
4513 /*
4514  * Returns elements currently being associated in geom side
4515  */
4516 QMultiMap<QString, int> EdgeAssocDialog::getAssocsGEOM()
4517 {
4518     QMultiMap<QString, int> assocs;
4519     QListWidgetItem* item = NULL;
4520     DocumentModel::GeomObj geomObj;
4521
4522     if (single_rb->isChecked())
4523     {
4524         //LineEdit content
4525         QVariant v = single_line_le->property("GeomObj");
4526         if ( !v.isValid() ) return assocs;
4527         geomObj = v.value<DocumentModel::GeomObj>();
4528         assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4529         return assocs;
4530     }
4531     else if (multiple_rb->isChecked())
4532     {
4533         //ListWidget content
4534         unsigned int nbEdges = lines_lw->count();
4535         for ( int r = 0; r < nbEdges; ++r){
4536             item = lines_lw->item(r);
4537             geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4538             assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4539         }
4540         return assocs;
4541     }
4542     else return assocs;
4543 }
4544
4545 // ============================================================== selectElementOfGeom
4546 /*Highlight in the OCC view selected elements in a listwidget,
4547  *  or an element in a line edit.*/
4548 void EdgeAssocDialog::selectElementOfGeom()
4549 {
4550     QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4551     if ( !currentListWidget )
4552         return;
4553
4554     QModelIndex index;
4555     QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4556     PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4557     pgsm->clearSelection();
4558     if (sel.count() == 0)
4559         return;
4560
4561     QListWidgetItem *item = sel[0];
4562 //    index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
4563     index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4564     if ( index.isValid() )
4565         pgsm->select( index, QItemSelectionModel::SelectCurrent );
4566 }
4567
4568 // ============================================================== clear
4569 void EdgeAssocDialog::clear()
4570 {
4571     first_vex_le->clear();
4572     modelUnregister(first_vex_le);
4573
4574     edges_lw->clear();
4575     modelUnregister(edges_lw);
4576
4577     lines_lw->clear();
4578
4579     single_edge_le->clear();
4580     modelUnregister(single_edge_le);
4581
4582     single_line_le->clear();
4583     modelUnregister(single_line_le);
4584
4585     modelUnregister(this);
4586 }
4587
4588 // ============================================================== onWindowActivated
4589 void EdgeAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4590 {
4591     QString vmType = vm->getType();
4592     if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4593     {
4594         if (single_rb->isChecked())
4595             single_edge_le->setFocus();
4596         else if (multiple_rb->isChecked() && focusWidget() != first_vex_le )
4597             edges_lw->setFocus();
4598     }
4599     else if ( vmType == OCCViewer_Viewer::Type() ){
4600         if (single_rb->isChecked())
4601             single_line_le->setFocus();
4602         else if (multiple_rb->isChecked() && focusWidget() != first_vex_le)
4603             lines_lw->setFocus();
4604     }
4605 }
4606
4607 // ============================================================== apply
4608 bool EdgeAssocDialog::apply(QModelIndex& result)
4609 {
4610     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4611     _currentObj = NULL;
4612
4613     bool assocOk = false;
4614
4615     PatternDataModel* patternDataModel = getPatternDataModel();
4616     PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4617     PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4618
4619     QModelIndex     iEdge, iGeomEdge;
4620     QModelIndexList iEdges;
4621     QListWidgetItem* item = NULL;
4622     QList<DocumentModel::GeomObj> assocs;
4623     DocumentModel::GeomObj aLine;
4624     HEXA_NS::SubShape* ssh;
4625     HEXA_NS::EdgeShape* sh;
4626     HEXA_NS::NewShapes shapes;
4627     HEXA_NS::IntVector subIds;
4628     QString id;
4629     QModelIndexList edges, lines;
4630
4631     if (single_rb->isChecked()){ //Single edge and/or line association
4632
4633         iEdge = patternDataModel->mapToSource( _index[single_edge_le] );
4634         if  ( !iEdge.isValid() || myLine == NULL)
4635         {
4636             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4637             return false;
4638         }
4639         id = myLine->shapeName+","+myLine->subId;
4640         ssh = getDocumentModel()->getGeomPtr(id);
4641         sh  = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4642         iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4643         if (!iGeomEdge.isValid())
4644         {
4645             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4646             return false;
4647         }
4648         assocOk = getDocumentModel()->addEdgeAssociation(iEdge, iGeomEdge, pstart_spb->value(), pend_spb->value());
4649         edges << _index[single_edge_le];
4650         lines << iGeomEdge;
4651     }
4652     else { //Multiple edge and/or line association
4653
4654         // edges
4655         iEdges = getIndexList(edges_lw, true);
4656         int nbLines = lines_lw->count();
4657         if  (iEdges.count() == 0 || nbLines == 0)
4658         {
4659             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4660             return false;
4661         }
4662         edges = getIndexList(edges_lw, false);
4663         // lines
4664         for (int r = 0; r < nbLines; ++r){
4665             item = lines_lw->item(r);
4666             aLine = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4667             id = aLine.shapeName+","+aLine.subId;
4668             ssh = getDocumentModel()->getGeomPtr(id);
4669             sh  = dynamic_cast<HEXA_NS::EdgeShape*>(ssh);
4670             if (sh == NULL)
4671             {
4672                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4673                 return false;
4674             }
4675             shapes.push_back(sh->getParentShape());
4676             subIds.push_back(sh->getIdent());
4677             iGeomEdge = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4678             if (iGeomEdge.isValid())
4679                 lines << iGeomEdge;
4680         }
4681
4682         if ( close_cb->isChecked() ){ //closed line
4683             QModelIndex iFirstVertex = patternDataModel->mapToSource( _index[first_vex_le] );
4684             if  ( !iFirstVertex.isValid() )
4685             {
4686                 SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) );
4687                 return false;
4688             }
4689             bool inv = inverse_cb->isChecked();
4690             assocOk = getDocumentModel()->associateClosedLine( iFirstVertex, iEdges, shapes, subIds, pstart_spb->value(), inv );
4691
4692         } else
4693             //opened line
4694             assocOk = getDocumentModel()->associateOpenedLine( iEdges, shapes, subIds, pstart_spb->value(), pend_spb->value() );
4695     }
4696
4697     if ( !assocOk ){
4698         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE EDGE ASSOCIATION" ) + "\n" + getErrorMsg() );
4699         return false;
4700     }
4701
4702     // highlight associated items in the trees
4703     pdsm->unhighlightTreeItems();
4704     pgsm->unhighlightTreeItems();
4705     pdsm->highlightTreeItems(edges);
4706     pgsm->highlightTreeItems(lines);
4707
4708     // highlight associated items in the views
4709     highlightSelectedAssocs();
4710
4711     return true;
4712 }
4713
4714 // ------------------------- QuadAssocDialog ----------------------------------
4715 // ============================================================== Constructeur
4716 QuadAssocDialog::QuadAssocDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4717 HexaBaseDialog(parent, editmode, f)
4718 {
4719     _helpFileName = "gui_asso_quad_to_geom.html#associate-to-a-face-or-a-shell-of-the-geometry";
4720     setupUi( this );
4721     _initWidget(editmode);
4722 }
4723
4724 // ============================================================== Destructeur
4725 QuadAssocDialog::~QuadAssocDialog()
4726 {
4727     disconnect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4728     disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()), this, SLOT(addFace()) );
4729     delete _delFaceShortcut;
4730 }
4731
4732 // ============================================================== close
4733 void QuadAssocDialog::close()
4734 {
4735     HEXABLOCKGUI::assocInProgress = false;
4736     HexaBaseDialog::close();
4737 }
4738
4739 // ============================================================== _initInputWidget
4740 void QuadAssocDialog::_initInputWidget( Mode editmode )
4741 {
4742     QRegExp rx("");
4743     QValidator *validator = new QRegExpValidator(rx, this);
4744
4745     quad_le->setProperty( "HexaWidgetType", QVariant::fromValue(QUAD_TREE) );
4746     quad_le->installEventFilter(this);
4747     quad_le->setValidator( validator );
4748
4749
4750     faces_lw->setProperty( "HexaWidgetType", QVariant::fromValue(GEOMFACE_TREE) );
4751     faces_lw->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_FACE) );
4752     faces_lw->installEventFilter(this);
4753     _delFaceShortcut = new QShortcut( QKeySequence(Qt::Key_X/*Qt::Key_Delete*/), faces_lw );
4754     _delFaceShortcut->setContext( Qt::WidgetShortcut );
4755
4756     quad_le->setReadOnly(true);
4757
4758     connect( _delFaceShortcut, SIGNAL(activated()), this, SLOT(deleteFaceItem()) );
4759     connect( faces_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfGeom()), Qt::UniqueConnection );
4760 }
4761
4762 // ============================================================== getAssocsVTK
4763 /*
4764  * Returns elements currently being associated in vtk side
4765  */
4766 QModelIndexList QuadAssocDialog::getAssocsVTK()
4767 {
4768     QModelIndexList assocs;
4769     QModelIndex iQuad;
4770
4771     //LineEdit content
4772     QVariant v = quad_le->property("QModelIndex");
4773     if ( !v.isValid() )
4774         return assocs;
4775     assocs << v.value<QModelIndex>();
4776     return assocs;
4777 }
4778
4779 // ============================================================== getAssocsGEOM
4780 /*
4781  * Returns elements currently being associated in geom side
4782  */
4783 QMultiMap<QString, int> QuadAssocDialog::getAssocsGEOM()
4784 {
4785     QMultiMap<QString, int> assocs;
4786     QListWidgetItem* item = NULL;
4787     DocumentModel::GeomObj geomObj;
4788
4789     //ListWidget content
4790     unsigned int nbFaces = faces_lw->count();
4791     for ( int r = 0; r < nbFaces; ++r){
4792         item = faces_lw->item(r);
4793         geomObj = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4794         assocs.insert( geomObj.shapeName, geomObj.subId.toInt() );
4795     }
4796     return assocs;
4797 }
4798
4799 // ============================================================== selectElementOfGeom
4800 /*Highlight in the OCC view selected elements in a listwidget,
4801  *  or an element in a line edit.*/
4802
4803 void QuadAssocDialog::selectElementOfGeom()
4804 {
4805     QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
4806     if ( !currentListWidget )
4807         return;
4808
4809     QModelIndex index;
4810     QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
4811     PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4812     pgsm->clearSelection();
4813     if (sel.count() == 0)
4814         return;
4815     QListWidgetItem *item = sel[0];
4816 //    index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>();
4817     index = pgsm->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
4818     if ( index.isValid() )
4819         pgsm->select( index, QItemSelectionModel::SelectCurrent );
4820 }
4821
4822 void QuadAssocDialog::clear()
4823 {
4824     quad_le->clear();
4825     modelUnregister(quad_le);
4826
4827     faces_lw->clear();
4828
4829     modelUnregister(this);
4830 }
4831
4832 // ============================================================== onWindowActivated
4833 void QuadAssocDialog::onWindowActivated(SUIT_ViewManager* vm)
4834 {
4835     QString vmType = vm->getType();
4836     if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
4837         quad_le->setFocus();
4838     else if ( vmType == OCCViewer_Viewer::Type() ){
4839         faces_lw->setFocus();
4840     }
4841 }
4842
4843 // ============================================================== deleteFaceItem
4844 void QuadAssocDialog::deleteFaceItem()
4845 {
4846     delete faces_lw->currentItem();
4847 }
4848
4849 // ============================================================== apply
4850 bool QuadAssocDialog::apply(QModelIndex& result)
4851 {
4852     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
4853     _currentObj = NULL;
4854
4855     PatternDataModel* patternDataModel = getPatternDataModel();
4856     PatternDataSelectionModel* pdsm = getPatternDataSelectionModel();
4857     PatternGeomSelectionModel* pgsm = getPatternGeomSelectionModel();
4858
4859
4860     QModelIndex iQuad, iGeomFace;
4861     HEXA_NS::SubShape* ssh;
4862     HEXA_NS::FaceShape* sh;
4863     QString id;
4864
4865     // quad
4866     iQuad = patternDataModel->mapToSource( _index[quad_le] );
4867
4868     // faces
4869     QListWidgetItem* item = NULL;
4870     DocumentModel::GeomObj aFace;
4871     QModelIndexList quads, faces;
4872     int nbFaces = faces_lw->count();
4873     for ( int r = 0; r < nbFaces; ++r ){
4874         item = faces_lw->item(r);
4875         aFace = item->data(LW_ASSOC_ROLE).value<DocumentModel::GeomObj>();
4876         id = aFace.shapeName+","+aFace.subId;
4877         ssh = getDocumentModel()->getGeomPtr(id);
4878         sh  = dynamic_cast<HEXA_NS::FaceShape*>(ssh);
4879         if (sh == NULL)
4880         {
4881             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) );
4882             return false;
4883         }
4884         iGeomFace = pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(sh));
4885         if (!getDocumentModel()->addQuadAssociation(iQuad, iGeomFace))
4886         {
4887             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD ASSOCIATION" ) + "\n" + getErrorMsg() );
4888             return false;
4889         }
4890         else if (iGeomFace.isValid())
4891             faces << iGeomFace;
4892     }
4893     result = iQuad;
4894
4895     if (iQuad.isValid())
4896         quads << _index[quad_le];
4897
4898     // highlight associated items in the trees
4899     pdsm->highlightTreeItems(quads);
4900     pgsm->highlightTreeItems(faces);
4901
4902     // highlight associated items in the views
4903     highlightSelectedAssocs();
4904
4905     return true;
4906 }
4907
4908 // ------------------------- GroupDialog ----------------------------------
4909 // ============================================================== Constructeur
4910 GroupDialog::GroupDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
4911 HexaBaseDialog(parent, editmode, f),
4912 _value(NULL)
4913 {
4914     _helpFileName = "gui_groups.html#add-group";
4915     setupUi( this );
4916     _initWidget(editmode);
4917     //   setFocusProxy( name_le/*eltBase_lw */);
4918
4919     if ( editmode  == NEW_MODE ){
4920         setWindowTitle( tr("Group Construction") );
4921     } else if ( editmode == UPDATE_MODE ){
4922         setWindowTitle( tr("Group Modification") );
4923     } else if ( editmode == INFO_MODE ){
4924         setWindowTitle( tr("Group Information") );
4925     }
4926 }
4927
4928 // ============================================================== Destructeur
4929 GroupDialog::~GroupDialog()
4930 {
4931 }
4932
4933 // ============================================================== getAssocsVTK
4934 /*
4935  * Returns elements currently being associated in vtk side
4936  */
4937 QModelIndexList GroupDialog::getAssocsVTK()
4938 {
4939     QModelIndexList assocs;
4940     QModelIndex iItem;
4941     QListWidgetItem* item = NULL;
4942     if (getPatternDataSelectionModel() == NULL) return assocs;
4943     //ListWidget content
4944     const PatternDataModel* patternDataModel = getPatternDataModel();
4945     if ( !patternDataModel ) return assocs;
4946     int nbElts = eltBase_lw->count();
4947     for ( int r = 0; r < nbElts; ++r){
4948         item = eltBase_lw->item(r);
4949         iItem = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
4950         if ( iItem.isValid() ) assocs << iItem;
4951     }
4952     return assocs;
4953 }
4954
4955 // ============================================================== _initInputWidget
4956 void GroupDialog::_initInputWidget( Mode editmode )
4957 {
4958     installEventFilter(this);
4959     name_le->installEventFilter(this);
4960
4961     // kind checkbox
4962     strKind[ HEXA_NS::HexaCell ] = "HexaCell";
4963     strKind[ HEXA_NS::QuadCell ] = "QuadCell";
4964     strKind[ HEXA_NS::EdgeCell ] = "EdgeCell";
4965     strKind[ HEXA_NS::HexaNode ] = "HexaNode";
4966     strKind[ HEXA_NS::QuadNode ] = "QuadNode";
4967     strKind[ HEXA_NS::EdgeNode ] = "EdgeNode";
4968     strKind[ HEXA_NS::VertexNode ] = "VertexNode";
4969     kind_cb->clear();
4970     QMap<HEXA_NS::EnumGroup, QString>::ConstIterator iKind;
4971     for( iKind = strKind.constBegin(); iKind != strKind.constEnd(); ++iKind )
4972         kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
4973
4974     onKindChanged( kind_cb->currentIndex() );
4975     eltBase_lw->installEventFilter(this);
4976
4977     if ( editmode != INFO_MODE ){
4978         QShortcut* delEltShortcut = new QShortcut( QKeySequence(Qt::Key_X), eltBase_lw );
4979         delEltShortcut->setContext( Qt::WidgetShortcut );
4980         connect(delEltShortcut,   SIGNAL(activated()), this, SLOT(removeEltBase()));
4981         connect(kind_cb,  SIGNAL(activated(int)), this, SLOT(onKindChanged(int)) );
4982     }
4983
4984     if ( editmode == INFO_MODE)
4985     {
4986         name_le->setReadOnly(true);
4987         kind_cb->setEnabled(false);
4988     }
4989
4990     connect(eltBase_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
4991 }
4992
4993 // ============================================================== clear
4994 void GroupDialog::clear()
4995 {
4996     name_le->clear();
4997
4998     eltBase_lw->clear();
4999     modelUnregister(eltBase_lw);
5000
5001     modelUnregister(this);
5002 }
5003
5004 // ============================================================== onKindChanged
5005 void GroupDialog::onKindChanged(int index)
5006 {
5007     //   onKind
5008     switch ( kind_cb->itemData(index).toInt() ){
5009     case HEXA_NS::HexaCell:
5010     case HEXA_NS::HexaNode:
5011         eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(HEXA_TREE));
5012         break;
5013
5014     case HEXA_NS::QuadCell:
5015     case HEXA_NS::QuadNode:
5016         eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(QUAD_TREE));
5017         break;
5018
5019     case HEXA_NS::EdgeCell:
5020     case HEXA_NS::EdgeNode: eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(EDGE_TREE));
5021     break;
5022
5023     case HEXA_NS::VertexNode:
5024         eltBase_lw->setProperty("HexaWidgetType", QVariant::fromValue(VERTEX_TREE));
5025         break;
5026
5027     default:Q_ASSERT(false);
5028     }
5029     eltBase_lw->clear();
5030     eltBase_lw->setFocus();
5031 }
5032
5033 // ============================================================== setValue
5034 void GroupDialog::setValue(HEXA_NS::Group* g)
5035 {
5036     //0) name
5037     name_le->setText( g->getName() );
5038
5039     //1) kind
5040     kind_cb->clear();
5041     kind_cb->addItem ( strKind[g->getKind()], QVariant( g->getKind() ) );
5042
5043     //2) elts
5044     HEXA_NS::EltBase* eltBase = NULL;
5045     QListWidgetItem* item = NULL;
5046     QModelIndex iEltBase;
5047     QList<QStandardItem *> eltBaseItems;
5048     QVariant v;
5049
5050     if ( !getPatternDataSelectionModel() ) return;
5051     if ( !getGroupsSelectionModel() ) return;
5052
5053     QModelIndex iGroup = getGroupsSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(g) );
5054     name_le->setProperty( "QModelIndex",  QVariant::fromValue(iGroup) );
5055
5056
5057     int nbElts = g->countElement();
5058     for ( int nr = 0; nr < nbElts; ++nr ){
5059         eltBase = g->getElement( nr );
5060         switch ( g->getKind() ){
5061         case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: v = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
5062         case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: v = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
5063         case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: v = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
5064         case HEXA_NS::VertexNode: v = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
5065         }
5066         iEltBase  = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, v);
5067         if ( iEltBase.isValid() ){
5068             item = new QListWidgetItem( eltBase->getName() );
5069             item->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iEltBase) );
5070             item->setData(LW_DATA_ROLE, iEltBase.data(HEXA_DATA_ROLE));
5071             eltBase_lw->addItem( item );
5072         }
5073     }
5074     _value = g;
5075 }
5076
5077 // ============================================================== getValue
5078 HEXA_NS::Group* GroupDialog::getValue()
5079 {
5080     return _value;
5081 }
5082
5083 // ============================================================== removeEltBase
5084 void GroupDialog::removeEltBase()
5085 {
5086     QListWidgetItem *item = eltBase_lw->currentItem();
5087
5088     if (item) {
5089         int r = eltBase_lw->row(item);
5090         eltBase_lw->takeItem(r);
5091         delete item;
5092     }
5093
5094 }
5095
5096 // ============================================================== apply
5097 bool GroupDialog::apply(QModelIndex& result)
5098 {
5099     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5100     _currentObj = NULL;
5101
5102     if ( !getDocumentModel() ) return false;
5103     const PatternDataModel* patternDataModel = getPatternDataModel();
5104     const GroupsModel*      groupsModel = getGroupsModel();
5105     if (patternDataModel == NULL || groupsModel == NULL) return false;
5106
5107     QString               grpName = name_le->text();
5108     DocumentModel::Group  grpKind = static_cast<DocumentModel::Group>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5109     QModelIndex iGrp;
5110     if ( _value == NULL ){ // create group
5111         iGrp = getDocumentModel()->addGroup( grpName, grpKind );
5112     } else {
5113         QModelIndexList iGrps = getDocumentModel()->match(
5114                 getDocumentModel()->index(0, 0),
5115                 HEXA_DATA_ROLE,
5116                 QVariant::fromValue( _value ),
5117                 1,
5118                 Qt::MatchRecursive );
5119         if ( !iGrps.isEmpty() )
5120             iGrp = iGrps[0];
5121     }
5122
5123     //   kind_cb->
5124     if ( !iGrp.isValid() ){
5125         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD GROUP" ) + "\n" + getErrorMsg() );
5126         return false;
5127     }
5128
5129     //fill it and select it
5130     QModelIndex iEltBase;
5131     QListWidgetItem* item = NULL;
5132     bool eltAdded = false;
5133     getDocumentModel()->clearGroupElement(iGrp);
5134     int nbElts = eltBase_lw->count();
5135     for ( int r = 0; r < nbElts; ++r){
5136         item     = eltBase_lw->item(r);
5137         iEltBase = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5138         if ( iEltBase.isValid() )
5139             eltAdded = getDocumentModel()->addGroupElement( iGrp, iEltBase );
5140     }
5141
5142     QString newName = name_le->text();
5143     if ( !newName.isEmpty() )
5144         getDocumentModel()->setName( iGrp, newName );
5145
5146     HEXA_NS::Group* hGroup = getDocumentModel()->data(iGrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
5147     if (hGroup != NULL)
5148     {
5149         QString groupName = QString::fromStdString(hGroup->getNextName());
5150         name_le->setText(groupName);
5151     }
5152
5153     result = groupsModel->mapFromSource(iGrp);
5154
5155     return true;
5156 }
5157
5158 // ------------------------- LawDialog ----------------------------------
5159 // ============================================================== Constructeur
5160
5161 LawDialog::LawDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5162 : HexaBaseDialog(parent, editmode, f),
5163   _value(NULL)
5164 {
5165     _helpFileName = "gui_discret_law.html#add-law";
5166     setupUi( this );
5167     _initWidget(editmode);
5168     if ( editmode  == NEW_MODE ){
5169         setWindowTitle( tr("Law Construction") );
5170     } else if ( editmode == UPDATE_MODE ){
5171         setWindowTitle( tr("Law Modification") );
5172     }
5173     else if ( editmode == INFO_MODE){
5174         setWindowTitle( tr("Law Information") );
5175     }
5176 }
5177
5178 // ============================================================== Destructeur
5179 LawDialog::~LawDialog()
5180 {
5181 }
5182
5183 // ============================================================== _initInputWidget
5184 void LawDialog::_initInputWidget( Mode editmode )
5185 {
5186     QRegExp rx("");
5187
5188     //   setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
5189     installEventFilter(this);
5190
5191     //   name_le->setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
5192     name_le->installEventFilter(this);
5193
5194     // kind checkbox
5195     strKind[ HEXA_NS::Uniform ]    = "Uniform";
5196     strKind[ HEXA_NS::Arithmetic ] = "Arithmetic";
5197     strKind[ HEXA_NS::Geometric ]  = "Geometric";
5198
5199     kind_cb->clear();
5200     QMap<HEXA_NS::KindLaw, QString>::ConstIterator iKind, iEnd;
5201     for( iKind = strKind.constBegin(), iEnd = strKind.constEnd(); iKind != iEnd; ++iKind )
5202         kind_cb->addItem( iKind.value(), QVariant(iKind.key()) );
5203
5204     if (editmode == INFO_MODE)
5205     {
5206         name_le->setReadOnly(true);
5207         nb_nodes_spb->setReadOnly(true);
5208         coeff_spb->setReadOnly(true);
5209         kind_cb->setEnabled(false);
5210     }
5211 }
5212
5213 // ============================================================== clear
5214 void LawDialog::clear()
5215 {
5216     name_le->clear();
5217
5218     modelUnregister(this);
5219 }
5220
5221 // ============================================================== setValue
5222 void LawDialog::setValue(HEXA_NS::Law* l)
5223 {
5224     // 0) name
5225     name_le->setText( l->getName() );
5226
5227     nb_nodes_spb->setValue( l->getNodes() );
5228     coeff_spb->setValue( l->getCoefficient() );
5229
5230     HEXA_NS::KindLaw k = l->getKind();
5231     kind_cb->setCurrentIndex( kind_cb->findData(k) );
5232
5233     _value = l;
5234 }
5235
5236 // ============================================================== getValue
5237 HEXA_NS::Law* LawDialog::getValue()
5238 {
5239     return _value;
5240 }
5241
5242 // ============================================================== apply
5243 bool LawDialog::apply(QModelIndex& result)
5244 {
5245     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5246     _currentObj = NULL;
5247
5248     if ( !getDocumentModel() ) return false;
5249
5250     const MeshModel* meshModel = getMeshModel();
5251     if (meshModel == NULL) return false;
5252
5253     QString lawName = name_le->text();
5254     int     nbnodes = nb_nodes_spb->value();
5255     double  coeff   = coeff_spb->value();
5256     DocumentModel::KindLaw  lawKind = static_cast<DocumentModel::KindLaw>( kind_cb->itemData( kind_cb->currentIndex() ).toInt());
5257
5258     QModelIndex iLaw;
5259     if ( _value == NULL ){ // create Law
5260         iLaw = getDocumentModel()->addLaw( lawName, nbnodes );
5261     } else {
5262         QModelIndexList iLaws = getDocumentModel()->match(
5263                 getDocumentModel()->index(0, 0),
5264                 HEXA_DATA_ROLE,
5265                 QVariant::fromValue( _value ),
5266                 1,
5267                 Qt::MatchRecursive );
5268         if ( !iLaws.isEmpty() )
5269             iLaw = iLaws[0];
5270     }
5271
5272     if ( !iLaw.isValid() ){
5273         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5274         return false;
5275     }
5276     //fill it and select it
5277     bool setOk = getDocumentModel()->setLaw( iLaw, nbnodes, coeff, lawKind );
5278     if ( !setOk ){
5279         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD LAW" ) + "\n" + getErrorMsg() );
5280         return false;
5281     }
5282
5283     QString newName = name_le->text();
5284     if ( !newName.isEmpty() )/*{*/
5285         getDocumentModel()->setName( iLaw, newName );
5286
5287     HEXA_NS::Law* hLaw = getDocumentModel()->data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
5288     if (hLaw != NULL)
5289     {
5290         char buffer [16];
5291         name_le->setText(hLaw->getNextName(buffer));
5292
5293     }
5294
5295     result = meshModel->mapFromSource(iLaw);
5296
5297     return true;
5298 }
5299
5300 // ------------------------- PropagationDialog ----------------------------------
5301 // ============================================================== Constructeur
5302 PropagationDialog::PropagationDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
5303 : HexaBaseDialog(parent, editmode, f),
5304   _value(NULL)
5305 {
5306     _helpFileName = "gui_propag.html";
5307     setupUi( this );
5308     _initWidget(editmode);
5309
5310     if ( editmode == INFO_MODE ){
5311         setWindowTitle( tr("Propagation Information") );
5312         if (groupBox_2)
5313             delete groupBox_2;
5314     } else if ( editmode == UPDATE_MODE ){
5315         setWindowTitle( tr("Propagation Modification") );
5316         if (groupBox_2)
5317             delete groupBox_2;
5318     } else if ( editmode == NEW_MODE ){
5319         setWindowTitle( tr("Propagation(s) Setting") );
5320     }
5321 }
5322
5323 // ============================================================== Destructeur
5324 PropagationDialog::~PropagationDialog()
5325 {
5326 }
5327
5328 // ============================================================== _initInputWidget
5329 void PropagationDialog::_initInputWidget( Mode editmode )
5330 {
5331     QRegExp rx("");
5332     QValidator *validator = new QRegExpValidator(rx, this);
5333
5334     installEventFilter(this);
5335
5336
5337     law_le->setProperty( "HexaWidgetType",  QVariant::fromValue(LAW_TREE) );
5338     law_le->installEventFilter(this);
5339     law_le->setValidator( validator );
5340
5341     propagations_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(PROPAGATION_TREE) );
5342     propagations_lw->installEventFilter(this);
5343
5344     QShortcut* delPropagationShortcut = new QShortcut(QKeySequence(/*Qt::Key_Delete*/Qt::Key_X/*Qt::Key_Alt*//*Qt::Key_Space*/), propagations_lw);
5345     delPropagationShortcut->setContext( Qt::WidgetShortcut );
5346
5347     law_le->setReadOnly(true);
5348
5349     if ( editmode == INFO_MODE)
5350         way_cb->setEnabled(false);
5351
5352     connect( delPropagationShortcut, SIGNAL(activated()), this, SLOT(deletePropagationItem()) );
5353     connect( propagations_lw,   SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection );
5354 }
5355
5356 // ============================================================== clear
5357 void PropagationDialog::clear()
5358 {
5359     propagations_lw->clear();
5360     modelUnregister(propagations_lw);
5361
5362     law_le->clear();
5363     modelUnregister(law_le);
5364
5365     modelUnregister(this);
5366 }
5367
5368 // ============================================================== deletePropagationItem
5369 void PropagationDialog::deletePropagationItem()
5370 {
5371     delete propagations_lw->currentItem();
5372 }
5373
5374 // ============================================================== setValue
5375 void PropagationDialog::setValue(HEXA_NS::Propagation* p)
5376 {
5377     if (getMeshSelectionModel() == NULL) return;
5378     HEXA_NS::Law* l = p->getLaw();
5379     bool way = p->getWay();
5380
5381     // propagation
5382     QModelIndex ip = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
5383     setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(ip) );
5384
5385     // law on propagation
5386     if ( l != NULL ){
5387         law_le->setText( l->getName() );
5388         QModelIndex il = getMeshSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(l) );
5389         law_le->setProperty( "QModelIndex",  QVariant::fromValue<QModelIndex>(il) );
5390     }
5391
5392     // way of propagation
5393     way_cb->setChecked(way);
5394
5395     _value = p;
5396 }
5397
5398 // ============================================================== selectElementOfModel
5399
5400 /*Selects in the model (treeview) elements selected in a listwidget,
5401  *  or an element in a line edit.*/
5402
5403 void PropagationDialog::selectElementOfModel()
5404 {
5405     if (!getMeshSelectionModel()) return;
5406
5407     QListWidget* currentListWidget = dynamic_cast<QListWidget*>( sender() );
5408     if ( !currentListWidget ) return;
5409
5410     QList<QListWidgetItem *> sel = currentListWidget->selectedItems();
5411     QModelIndex index;
5412     getMeshSelectionModel()->clearSelection();
5413     foreach ( QListWidgetItem *item, sel ){
5414         //index = item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>(); //unsafe: index can change in the tree
5415         index = getMeshSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5416         if ( index.isValid() )
5417             getMeshSelectionModel()->select( index, QItemSelectionModel::SelectCurrent );
5418     }
5419 }
5420
5421 // ============================================================== getValue
5422 HEXA_NS::Propagation* PropagationDialog::getValue()
5423 {
5424     return _value;
5425 }
5426
5427 // ============================================================== apply
5428 bool PropagationDialog::apply(QModelIndex& result)
5429 {
5430     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5431     _currentObj = NULL;
5432
5433     bool isOk = false;
5434     if ( !getDocumentModel() ) return false;
5435     const MeshModel* meshModel = getMeshModel();
5436     if (meshModel == NULL) return false;
5437
5438     bool way = way_cb->isChecked();
5439     QListWidgetItem* item = NULL;
5440
5441     QModelIndex iPropagation;
5442     QModelIndex iLaw = meshModel->mapToSource( law_le->property("QModelIndex").value<QModelIndex>() );
5443     if (!iLaw.isValid() ){
5444         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5445         return false;
5446     }
5447
5448     int nbPropagations = propagations_lw->count();
5449     for (int r = 0; r < nbPropagations; ++r){
5450         item = propagations_lw->item(r);
5451         iPropagation = meshModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5452         if ( !iPropagation.isValid() ){
5453             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) );
5454             return false;
5455         }
5456
5457         //fill it and select it
5458         isOk = getDocumentModel()->setPropagation( iPropagation, iLaw, way );
5459         if ( !isOk ){
5460             SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT SET PROPAGATION" ) + "\n" + getErrorMsg() );
5461             return false;
5462         }
5463
5464         result = meshModel->mapFromSource(iPropagation);
5465     }
5466
5467     return true;
5468 }
5469
5470 // ------------------------- ComputeMeshDialog ----------------------------------
5471 // ============================================================== Constructeur
5472 ComputeMeshDialog::ComputeMeshDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5473 HexaBaseDialog(parent, editmode, f)
5474 {
5475     _helpFileName = "gui_mesh.html";
5476     setWindowTitle( tr("Compute mesh") );
5477     QVBoxLayout* layout = new QVBoxLayout;
5478     setLayout(layout);
5479
5480     QHBoxLayout* up   = new QHBoxLayout;
5481     QHBoxLayout* down = new QHBoxLayout;
5482
5483     layout->addLayout(up);
5484     layout->addLayout(down);
5485
5486     QVBoxLayout* vlg = new QVBoxLayout;
5487     QVBoxLayout* vld = new QVBoxLayout;
5488
5489     up->addLayout(vlg);
5490     up->addLayout(vld);
5491
5492     vlg->addWidget(new QLabel("Name"));
5493     vlg->addWidget(new QLabel("Dimension"));
5494     vlg->addWidget(new QLabel("Container"));
5495
5496     _name = new QLineEdit("Mesh");
5497     _dim  = new QSpinBox();
5498     _fact = new QLineEdit("FactoryServer");
5499
5500     vld->addWidget(_name);
5501     vld->addWidget(_dim);
5502     vld->addWidget(_fact);
5503
5504     _dim->setRange(1, 3);
5505     _dim->setValue(3);
5506
5507     _initWidget(editmode);
5508 }
5509
5510 // ============================================================== Destructeur
5511 ComputeMeshDialog::~ComputeMeshDialog()
5512 {
5513 }
5514
5515 // ============================================================== _initInputWidget
5516 void ComputeMeshDialog::_initInputWidget( Mode editmode )
5517 {
5518 }
5519
5520 // ============================================================== setDocumentModel
5521 void ComputeMeshDialog::setDocumentModel(DocumentModel* m)
5522 {
5523     if (m == NULL) return;
5524     _name->setText(m->getName());
5525 }
5526
5527 // ============================================================== clear
5528 void ComputeMeshDialog::clear()
5529 {
5530     modelUnregister(this);
5531 }
5532
5533 // ============================================================== apply
5534 bool ComputeMeshDialog::apply(QModelIndex& result)
5535 {
5536     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5537     _currentObj = NULL;
5538
5539     if (getDocumentModel() == NULL) return false;
5540     QString command = QString("import hexablock ; %1 = hexablock.mesh(\"%2\", \"%1\", %3, \"%4\")")
5541                                                                                                           .arg( _name->text() )
5542                                                                                                           .arg( getDocumentModel()->getName() )
5543                                                                                                           .arg( _dim->value() )
5544                                                                                                           .arg( _fact->text() );
5545
5546     SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
5547     PyConsole_Console* pyConsole = app->pythonConsole();
5548
5549     if ( pyConsole )
5550         pyConsole->exec( command );
5551     else
5552         return false;
5553
5554     return true;
5555 }
5556
5557 // ------------------------- ReplaceHexaDialog ----------------------------------
5558 // ============================================================== Constructeur
5559 ReplaceHexaDialog::ReplaceHexaDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5560 HexaBaseDialog(parent, editmode, f)
5561 {
5562     _helpFileName = "gui_replace_hexa.html";
5563     setupUi( this );
5564     _initWidget(editmode);
5565 }
5566
5567 // ============================================================== Destructeur
5568 ReplaceHexaDialog::~ReplaceHexaDialog()
5569 {
5570 }
5571
5572 // ============================================================== getAssocsVTK
5573 /*
5574  * Returns elements currently associated to vtk
5575  */
5576 QModelIndexList ReplaceHexaDialog::getAssocsVTK()
5577 {
5578     QModelIndexList assocs;
5579     QModelIndex iQuad;
5580     QListWidgetItem* item = NULL;
5581
5582     //ListWidget content
5583     const PatternDataModel* patternDataModel = getPatternDataModel();
5584     if ( !patternDataModel ) return assocs;
5585     int nbQuads = quads_lw->count();
5586     for ( int r = 0; r < nbQuads; ++r ){
5587         item = quads_lw->item(r);
5588         //              iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() ); //unsafe
5589         iQuad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5590         if ( iQuad.isValid() ) assocs << iQuad;
5591     }
5592     return assocs;
5593 }
5594
5595 // ============================================================== _initInputWidget
5596 void ReplaceHexaDialog::_initInputWidget( Mode editmode )
5597 {
5598     QRegExp rx("");
5599
5600     installEventFilter(this);
5601
5602     c1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5603     c2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5604     c3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5605
5606     p1_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5607     p2_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5608     p3_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5609
5610     c1_le->installEventFilter(this);
5611     c2_le->installEventFilter(this);
5612     c3_le->installEventFilter(this);
5613
5614     p1_le->installEventFilter(this);
5615     p2_le->installEventFilter(this);
5616     p3_le->installEventFilter(this);
5617
5618     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
5619     quads_lw->installEventFilter(this);
5620
5621     if ( editmode == NEW_MODE ){
5622         QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5623         delQuadShortcut->setContext( Qt::WidgetShortcut );
5624
5625         connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(deleteQuadItem()) );
5626         connect( quads_lw, SIGNAL(currentRowChanged(int)), this, SLOT(updateButtonBox(int)) );
5627     }
5628
5629     c1_le->setReadOnly(true);
5630     c2_le->setReadOnly(true);
5631     c3_le->setReadOnly(true);
5632
5633     p1_le->setReadOnly(true);
5634     p2_le->setReadOnly(true);
5635     p3_le->setReadOnly(true);
5636
5637     connect(quads_lw,    SIGNAL(itemSelectionChanged()),
5638             this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5639 }
5640
5641 // ============================================================== clear
5642 void ReplaceHexaDialog::clear()
5643 {
5644     quads_lw->clear();
5645     modelUnregister(quads_lw);
5646
5647     p1_le->clear();
5648     modelUnregister(p1_le);
5649
5650     p2_le->clear();
5651     modelUnregister(p2_le);
5652
5653     p3_le->clear();
5654     modelUnregister(p3_le);
5655
5656     c1_le->clear();
5657     modelUnregister(c1_le);
5658
5659     c2_le->clear();
5660     modelUnregister(c2_le);
5661
5662     c3_le->clear();
5663     modelUnregister(c3_le);
5664
5665     modelUnregister(this);
5666 }
5667
5668 // ============================================================== updateButtonBox
5669 void ReplaceHexaDialog::updateButtonBox()
5670 {
5671     int nbQuad = quads_lw->count();
5672
5673     if ( nbQuad > 0 ){
5674         _applyButton->setEnabled(true);
5675     } else {
5676         _applyButton->setEnabled(false);
5677     }
5678 }
5679
5680 // ============================================================== deleteQuadItem
5681 void ReplaceHexaDialog::deleteQuadItem()
5682 {
5683     delete quads_lw->currentItem();
5684     updateButtonBox();
5685 }
5686
5687 // ============================================================== apply
5688 bool ReplaceHexaDialog::apply(QModelIndex& result)
5689 {
5690     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5691     _currentObj = NULL;
5692
5693     if ( !getDocumentModel() ) return false;
5694     const PatternDataModel* patternDataModel = getPatternDataModel();
5695     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5696     if ( !patternDataModel || !patternBuilderModel)    return false;
5697
5698     QModelIndex ielts; //result
5699
5700     QListWidgetItem* item = NULL;
5701     QModelIndexList iquads;
5702     QModelIndex     iquad;
5703     int nbQuads = quads_lw->count();
5704     for ( int r = 0; r < nbQuads; ++r){
5705         item = quads_lw->item(r);
5706         iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5707         if ( iquad.isValid() )
5708             iquads << iquad;
5709     }
5710
5711     QModelIndex ic1 = patternDataModel->mapToSource( _index[c1_le] );
5712     QModelIndex ic2 = patternDataModel->mapToSource( _index[c2_le] );
5713     QModelIndex ic3 = patternDataModel->mapToSource( _index[c3_le] );
5714
5715     QModelIndex ip1 = patternDataModel->mapToSource( _index[p1_le] );
5716     QModelIndex ip2 = patternDataModel->mapToSource( _index[p2_le] );
5717     QModelIndex ip3 = patternDataModel->mapToSource( _index[p3_le] );
5718
5719     if ( ic1.isValid() && ic2.isValid() && ic3.isValid()
5720             && ip1.isValid() && ip2.isValid() && ip3.isValid() ){
5721         ielts = getDocumentModel()->replace( iquads,
5722                 ip1, ic1,
5723                 ip2, ic2,
5724                 ip3, ic3 );
5725     }
5726
5727     if ( !ielts.isValid() ){
5728         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT REPLACE HEXA" ) + "\n" + getErrorMsg() );
5729         return false;
5730     }
5731     _value  = ielts.model()->data(ielts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5732     result = patternBuilderModel->mapFromSource(ielts);
5733
5734     //update the list (indexes)
5735     for ( int r = 0; r < nbQuads; ++r ){
5736         item = quads_lw->item(r);
5737         iquad = getPatternDataSelectionModel()->indexBy(HEXA_DATA_ROLE, item->data(LW_DATA_ROLE));
5738         item->setData(  LW_QMODELINDEX_ROLE, QVariant::fromValue<QModelIndex>(iquad) );
5739         item->setData(LW_DATA_ROLE, iquad.data(HEXA_DATA_ROLE));
5740     }
5741
5742     return true;
5743 }
5744
5745 // ------------------------- QuadRevolutionDialog ----------------------------------
5746 // ============================================================== Constructeur
5747
5748 QuadRevolutionDialog::QuadRevolutionDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5749          HexaBaseDialog(parent, editmode, f)
5750 {
5751     _helpFileName = "gui_quad_revolution.html";
5752     setupUi( this );
5753     _initWidget(editmode);
5754     revolutionUni_rb->click();
5755 }
5756
5757 // ============================================================== getAssocsVTK
5758 /*
5759  * Returns elements currently associated to vtk
5760  */
5761 QModelIndexList QuadRevolutionDialog::getAssocsVTK()
5762 {
5763     QModelIndexList assocs;
5764     QModelIndex iQuad;
5765     QListWidgetItem* item = NULL;
5766     if (getPatternDataSelectionModel() == NULL) return assocs;
5767
5768     //ListWidget content
5769     const PatternDataModel* patternDataModel = getPatternDataModel();
5770     if ( !patternDataModel ) return assocs;
5771     int nbQuads = quads_lw->count();
5772     for ( int r = 0; r < nbQuads; ++r ){
5773         item = quads_lw->item(r);
5774         iQuad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5775         if ( iQuad.isValid() )
5776             assocs << iQuad;
5777     }
5778     return assocs;
5779 }
5780
5781 // ============================================================== Destructeur
5782 QuadRevolutionDialog::~QuadRevolutionDialog()
5783 {
5784 }
5785
5786 // ============================================================== _initInputWidget
5787 void QuadRevolutionDialog::_initInputWidget( Mode editmode )
5788 {
5789     quads_lw->setProperty( "HexaWidgetType",  QVariant::fromValue(QUAD_TREE) );
5790     center_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5791     axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5792
5793     installEventFilter(this);
5794     quads_lw->installEventFilter(this);
5795     center_le->installEventFilter(this);
5796     axis_le->installEventFilter(this);
5797
5798     center_le->setReadOnly(true);
5799     axis_le->setReadOnly(true);
5800
5801     angles_lw->setItemDelegate( new HexaAngleDoubleSpinBoxDelegate(angles_lw) );
5802     angles_lw->setEditTriggers( QAbstractItemView::DoubleClicked );
5803
5804     QShortcut* delQuadShortcut = new QShortcut( QKeySequence(Qt::Key_X), quads_lw );
5805     delQuadShortcut->setContext( Qt::WidgetShortcut );
5806     connect( delQuadShortcut, SIGNAL(activated()), this, SLOT(delQuadItem()) );
5807     connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()));
5808     connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()));
5809
5810     connect(quads_lw,    SIGNAL(itemSelectionChanged()), this, SLOT(selectElementOfModel()), Qt::UniqueConnection);
5811 }
5812
5813 // ============================================================== clear
5814 void QuadRevolutionDialog::clear()
5815 {
5816     quads_lw->clear();
5817     modelUnregister(quads_lw);
5818
5819     center_le->clear();
5820     modelUnregister(center_le);
5821
5822     axis_le->clear();
5823     modelUnregister(axis_le);
5824
5825     modelUnregister(this);
5826 }
5827
5828 // ============================================================== addAngleItem
5829 void QuadRevolutionDialog::addAngleItem() //CS_TODO
5830 {
5831     QListWidgetItem* previousItem = angles_lw->currentItem();
5832     QListWidgetItem* newItem      = new QListWidgetItem();
5833
5834     double defaultValue = 180.;
5835     if ( previousItem )
5836         defaultValue =  previousItem->data(Qt::EditRole).toDouble();
5837
5838     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
5839     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
5840     angles_lw->addItem(newItem);
5841
5842     updateButtonBox();
5843 }
5844
5845 // ============================================================== delAngleItem
5846 void QuadRevolutionDialog::delAngleItem()
5847 {
5848     delete angles_lw->currentItem();
5849     updateButtonBox();
5850 }
5851
5852 // ============================================================== delQuadItem
5853 void QuadRevolutionDialog::delQuadItem()
5854 {
5855     delete quads_lw->currentItem();
5856     updateButtonBox();
5857 }
5858
5859 // ============================================================== apply
5860 bool QuadRevolutionDialog::apply(QModelIndex& result)
5861 {
5862     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
5863     _currentObj = NULL;
5864
5865     DocumentModel* docModel = getDocumentModel();
5866     PatternDataModel* patternDataModel = getPatternDataModel();
5867     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
5868
5869     QListWidgetItem* item = NULL;
5870
5871     QModelIndexList istartquads;
5872     QModelIndex     iquad;
5873     int nbQuads = quads_lw->count();
5874     for ( int r = 0; r < nbQuads; ++r){
5875         item = quads_lw->item(r);
5876         iquad = patternDataModel->mapToSource( item->data(LW_QMODELINDEX_ROLE).value<QModelIndex>() );
5877         if ( iquad.isValid() )
5878             istartquads << iquad;
5879     }
5880
5881     QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
5882     QModelIndex iaxis   = patternBuilderModel->mapToSource( _index[axis_le] );
5883     int angle = angle_spb->value();
5884     int nbre = nbre_spb->value();
5885
5886     vector<double> angles;
5887     int nbAngles = angles_lw->count();
5888     for ( int r = 0; r < nbAngles; ++r){
5889         item = angles_lw->item(r);
5890         angles.push_back(item->data(Qt::EditRole).toDouble());
5891     }
5892
5893     QModelIndex iElts; //result
5894     if (nbQuads == 1 && istartquads[0].isValid() && icenter.isValid() && iaxis.isValid())
5895     {
5896         if (revolutionUni_rb->isChecked())
5897             iElts = docModel->revolutionQuadUni(istartquads[0], icenter, iaxis, angle, nbre);
5898         else if (revolution_rb->isChecked())
5899             iElts = docModel->revolutionQuad(istartquads[0], icenter, iaxis, angles);
5900     }
5901     else if (nbQuads > 1 && icenter.isValid() && iaxis.isValid())
5902     {
5903         if (revolutionUni_rb->isChecked())
5904             iElts = docModel->revolutionQuadsUni(istartquads, icenter, iaxis, angle, nbre);
5905         else if (revolution_rb->isChecked())
5906             iElts = docModel->revolutionQuads(istartquads, icenter, iaxis, angles);
5907     }
5908
5909     if ( !iElts.isValid() ){
5910         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE QUAD REVOLUTION" ) + "\n" + getErrorMsg() );
5911         return false;
5912     }
5913     _value  = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
5914     result = patternBuilderModel->mapFromSource(iElts);
5915
5916     return true;
5917 }
5918
5919 // ------------------------- MakeHemiSphereDialog ----------------------------------
5920 // ============================================================== Constructeur
5921 MakeHemiSphereDialog::MakeHemiSphereDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f ):
5922          HexaBaseDialog(parent, editmode, f)
5923 {
5924     _helpFileName = "gui_hemisphere.html";
5925     setupUi( this );
5926     _initWidget(editmode);
5927     sphere_rb->click();
5928
5929     connect( sphereTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5930     connect( sphereUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5931     connect( sphere2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5932     connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5933     connect( sphere_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5934
5935     connect( sphericalTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5936     connect( sphericalUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5937     connect( spherical2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5938     connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5939     connect( spherical_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5940
5941     connect( rindTop_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5942     connect( rindUni_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5943     connect( rind2_rb, SIGNAL(clicked()), this, SLOT(updateHelpFileName()) );
5944     connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearVTKSelection()) );
5945     connect( rind_rb, SIGNAL(clicked()), this, SLOT(clearCurrentObjectFocus()) );
5946 }
5947
5948 // ============================================================== Destructeur
5949 MakeHemiSphereDialog::~MakeHemiSphereDialog()
5950 {
5951 }
5952
5953 // ============================================================== _initInputWidget
5954 void MakeHemiSphereDialog::_initInputWidget( Mode editmode )
5955 {
5956     center_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5957     hole_axis_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5958     base_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
5959     vplan_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
5960
5961     installEventFilter(this);
5962     center_le->installEventFilter(this);
5963     hole_axis_le->installEventFilter(this);
5964     base_le->installEventFilter(this);
5965     vplan_le->installEventFilter(this);
5966
5967     center_le->setReadOnly(true);
5968     hole_axis_le->setReadOnly(true);
5969     base_le->setReadOnly(true);
5970     vplan_le->setReadOnly(true);
5971
5972     radius_lw_1->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_1));
5973     radius_lw_1->setEditTriggers(QAbstractItemView::DoubleClicked);
5974
5975     radius_lw_2->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(radius_lw_2));
5976     radius_lw_2->setEditTriggers(QAbstractItemView::DoubleClicked);
5977
5978     angle_lw->setItemDelegate(new HexaAngleDoubleSpinBoxDelegate(angle_lw));
5979     angle_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
5980
5981     height_lw->setItemDelegate(new HexaPositiveDoubleSpinBoxDelegate(height_lw));
5982     height_lw->setEditTriggers(QAbstractItemView::DoubleClicked);
5983
5984     connect( add_radius_pb_1, SIGNAL(clicked()), this, SLOT(addRadiusItem1()) );
5985     connect( del_radius_pb_1, SIGNAL(clicked()), this, SLOT(delRadiusItem1()) );
5986
5987     connect( add_radius_pb_2, SIGNAL(clicked()), this, SLOT(addRadiusItem2()) );
5988     connect( del_radius_pb_2, SIGNAL(clicked()), this, SLOT(delRadiusItem2()) );
5989
5990     connect( add_angle_pb, SIGNAL(clicked()), this, SLOT(addAngleItem()) );
5991     connect( del_angle_pb, SIGNAL(clicked()), this, SLOT(delAngleItem()) );
5992
5993     connect( add_height_pb, SIGNAL(clicked()), this, SLOT(addHeightItem()) );
5994     connect( del_height_pb, SIGNAL(clicked()), this, SLOT(delHeightItem()) );
5995 }
5996
5997 // ============================================================== addRadiusItem
5998 void MakeHemiSphereDialog::addRadiusItem1()
5999 {
6000     QListWidgetItem* previousItem = radius_lw_1->currentItem();
6001     QListWidgetItem* newItem      = new QListWidgetItem();
6002
6003     double defaultValue = 1.;
6004     if ( previousItem )
6005         defaultValue = previousItem->data(Qt::EditRole).toDouble();
6006
6007     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
6008     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6009     radius_lw_1->addItem(newItem);
6010 }
6011
6012 // ============================================================== delRadiusItem
6013 void MakeHemiSphereDialog::delRadiusItem1()
6014 {
6015     delete radius_lw_1->currentItem();
6016 }
6017
6018 // ============================================================== addRadiusItem
6019 void MakeHemiSphereDialog::addRadiusItem2()
6020 {
6021     QListWidgetItem* previousItem = radius_lw_2->currentItem();
6022     QListWidgetItem* newItem      = new QListWidgetItem();
6023
6024     double defaultValue = 1.;
6025     if ( previousItem )
6026         defaultValue = previousItem->data(Qt::EditRole).toDouble();
6027
6028     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
6029     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6030     radius_lw_2->addItem(newItem);
6031 }
6032
6033 // ============================================================== delRadiusItem
6034 void MakeHemiSphereDialog::delRadiusItem2()
6035 {
6036     delete radius_lw_2->currentItem();
6037 }
6038
6039 // ============================================================== addAngleItem
6040 void MakeHemiSphereDialog::addAngleItem()
6041 {
6042     QListWidgetItem* previousItem = angle_lw->currentItem();
6043     QListWidgetItem* newItem      = new QListWidgetItem();
6044
6045     double defaultValue = 180.;
6046     if ( previousItem )
6047         defaultValue = previousItem->data(Qt::EditRole).toDouble();
6048
6049     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
6050     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6051     angle_lw->addItem(newItem);
6052 }
6053
6054 // ============================================================== delAngleItem
6055 void MakeHemiSphereDialog::delAngleItem()
6056 {
6057     delete angle_lw->currentItem();
6058 }
6059
6060 // ============================================================== addHeightItem
6061 void MakeHemiSphereDialog::addHeightItem()
6062 {
6063     QListWidgetItem* previousItem = height_lw->currentItem();
6064     QListWidgetItem* newItem      = new QListWidgetItem();
6065
6066     double defaultValue = 1.;
6067     if ( previousItem )
6068         defaultValue = previousItem->data(Qt::EditRole).toDouble();
6069
6070     newItem->setData(  Qt::EditRole, QVariant(defaultValue) );
6071     newItem->setFlags( newItem->flags () | Qt::ItemIsEditable);
6072     height_lw->addItem(newItem);
6073 }
6074
6075 // ============================================================== delHeightItem
6076 void MakeHemiSphereDialog::delHeightItem()
6077 {
6078     delete height_lw->currentItem();
6079 }
6080
6081 // ============================================================== updateHelpFileName
6082 void MakeHemiSphereDialog::updateHelpFileName()
6083 {
6084 }
6085
6086 // ============================================================== clear
6087 void MakeHemiSphereDialog::clear()
6088 {
6089     center_le->clear();
6090     modelUnregister(center_le);
6091
6092     hole_axis_le->clear();
6093     modelUnregister(hole_axis_le);
6094
6095     base_le->clear();
6096     modelUnregister(base_le);
6097
6098     vplan_le->clear();
6099     modelUnregister(vplan_le);
6100
6101     modelUnregister(this);
6102 }
6103
6104 // ============================================================== apply
6105 bool MakeHemiSphereDialog::apply(QModelIndex& result)
6106 {
6107     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6108     _currentObj = NULL;
6109
6110     DocumentModel* docModel = getDocumentModel();
6111     PatternDataModel* patternDataModel = getPatternDataModel();
6112     PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6113
6114     QModelIndex iElts;
6115     QModelIndex icenter = patternDataModel->mapToSource( _index[center_le] );
6116     QModelIndex ivplan  = patternDataModel->mapToSource( _index[vplan_le] );
6117     QModelIndex ivecx   = patternBuilderModel->mapToSource( _index[base_le] );
6118     QModelIndex ivecz   = patternBuilderModel->mapToSource( _index[hole_axis_le] );
6119
6120     double radhole  = hole_rad_spb->value();
6121     double radext   = sphere_radext_spb->value();
6122     double radint   = sphere_radint_spb->value();
6123     double radang = radial_angle_spb->value();
6124
6125     int crit  =  crit_spb->value();
6126     int nb    = nbre_spb->value();
6127     int nrad  = ngrid_rad_spb->value();
6128     int nang  = ngrid_ang_spb->value();
6129     int nhaut = ngrid_height_spb->value();
6130
6131     //radius, angles and heights collection
6132     QListWidgetItem* item = NULL;
6133
6134     vector<double> radius1;
6135     vector<double> radius2;
6136     vector<double> angles;
6137     vector<double> heights;
6138
6139     //angles collection
6140     double somme = 0.;
6141     int nbAngles = angle_lw->count();
6142     for ( int r = 0; r < nbAngles; ++r){
6143         item = angle_lw->item(r);
6144         double itemValue = item->data(Qt::EditRole).toDouble();
6145         angles.push_back(itemValue);
6146         somme += itemValue;
6147     }
6148
6149     //radius1 collection
6150     int nbRadius = radius_lw_1->count();
6151     for ( int r = 0; r < nbRadius; ++r){
6152         item = radius_lw_1->item(r);
6153         radius1.push_back(item->data(Qt::EditRole).toDouble());
6154     }
6155
6156     //radius2 collection
6157     nbRadius = radius_lw_2->count();
6158     for ( int r = 0; r < nbRadius; ++r){
6159         item = radius_lw_2->item(r);
6160         radius2.push_back(item->data(Qt::EditRole).toDouble());
6161     }
6162
6163     //heights collection
6164     int nbHeight = height_lw->count();
6165     for ( int r = 0; r < nbHeight; ++r){
6166         item = height_lw->item(r);
6167         heights.push_back(item->data(Qt::EditRole).toDouble());
6168     }
6169
6170     if (sphere_rb->isChecked())
6171     {
6172         if (sphereTop_rb->isChecked())
6173             iElts = docModel->makeSphereTop( nrad, nang, nhaut );
6174         else if (sphereUni_rb->isChecked())
6175         {
6176             if (icenter.isValid() && ivplan.isValid() && ivecx.isValid() && ivecz.isValid())
6177                 iElts = docModel->makeSphereUni(icenter, ivecx, ivecz, radhole, radext, radang,
6178                                                 ivplan, nrad, nang, nhaut);
6179         }
6180         else if (sphere2_rb->isChecked())
6181         {
6182             if (somme > 360.01)
6183             {
6184                 SUIT_MessageBox::information( 0,
6185                         tr("HEXA_INFO"),
6186                         tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6187                 return false;
6188             }
6189             if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6190                 iElts = docModel->makeSphere(icenter, ivecx, ivecz, radius2, angles, heights);
6191         }
6192     }
6193     else if (spherical_rb->isChecked())
6194     {
6195         if (sphericalTop_rb->isChecked())
6196             iElts = docModel->makeSphericalTop(nb, crit);
6197         else if (sphericalUni_rb->isChecked())
6198         {
6199             if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6200                 iElts = docModel->makeSphericalUni(icenter, ivecx, ivecz, radhole, nb, crit);
6201         }
6202         else if (spherical2_rb->isChecked())
6203         {
6204             if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6205                 iElts = docModel->makeSpherical(icenter, ivecx, ivecz, radius1, crit);
6206         }
6207     }
6208     else if (rind_rb->isChecked())
6209     {
6210         if (rindTop_rb->isChecked())
6211             iElts = docModel->makeRindTop(nrad, nang, nhaut);
6212         else if (rindUni_rb->isChecked())
6213         {
6214             if (icenter.isValid() && ivecx.isValid() && ivecz.isValid() && ivplan.isValid())
6215                 iElts = docModel->makeRindUni(icenter, ivecx, ivecz,
6216                                               radhole, radint, radext, radang,
6217                                               ivplan, nrad, nang, nhaut);
6218         }
6219         else if (rind2_rb->isChecked())
6220         {
6221             if (somme > 360.01)
6222             {
6223                 SUIT_MessageBox::information( 0,
6224                         tr("HEXA_INFO"),
6225                         tr("The sum of the picked angles has to be \nless or equal than %1 degrees.").arg(360));
6226                 return false;
6227             }
6228             if (icenter.isValid() && ivecx.isValid() && ivecz.isValid())
6229                 iElts = docModel->makeRind(icenter, ivecx, ivecz, radius2, angles, heights);
6230         }
6231     }
6232
6233     if ( !iElts.isValid() ){
6234         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT MAKE RIND" ) + "\n" + getErrorMsg() );
6235         return false;
6236     }
6237     _value  = iElts.model()->data(iElts, HEXA_DATA_ROLE).value<HEXA_NS::Elements*>();
6238     result = patternBuilderModel->mapFromSource(iElts);
6239
6240     return true;
6241 }
6242
6243 // ------------------------- ModelInfoDialog ----------------------------------
6244 ModelInfoDialog::ModelInfoDialog(QWidget* parent, Qt::WindowFlags wf):
6245                  HexaBaseDialog(parent, INFO_MODE, wf)
6246 {
6247     setupUi( this );
6248     setWindowTitle(HEXABLOCKGUI::tr("MODEL_INFO"));
6249 }
6250
6251 void ModelInfoDialog::updateInfo()
6252 {
6253     DocumentModel* docModel = getDocumentModel();
6254     if (docModel == NULL) return;
6255
6256     //Model name
6257     model_name_le->setText(docModel->getName());
6258
6259     //Nb of elements in the model
6260     total_vertices_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_VERTEX)));
6261     total_edges_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_EDGE)));
6262     total_quads_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_QUAD)));
6263     total_hexas_le->setText(QString::number(docModel->getNbrElt(HEXA_NS::EL_HEXA)));
6264
6265     ///Nb of used elements in the model
6266     used_vertices_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_VERTEX)));
6267     used_edges_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_EDGE)));
6268     used_quads_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_QUAD)));
6269     used_hexas_le->setText(QString::number(docModel->getNbrUsedElt(HEXA_NS::EL_HEXA)));
6270
6271     //Nb of unused elements in the model
6272     unused_vertices_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_VERTEX)));
6273     unused_edges_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_EDGE)));
6274     unused_quads_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_QUAD)));
6275     unused_hexas_le->setText(QString::number(docModel->getNbrUnusedElt(HEXA_NS::EL_HEXA)));
6276 }
6277
6278 void ModelInfoDialog::showEvent( QShowEvent * event )
6279 {
6280     updateInfo();
6281     QDialog::showEvent ( event );
6282 }
6283
6284 // ============================================================== hideEvent
6285 void ModelInfoDialog::hideEvent ( QHideEvent * event )
6286 {
6287     QDialog::hideEvent( event );
6288 }
6289
6290 // ------------------------- AddShapeDialog ----------------------------------
6291 AddShapeDialog::AddShapeDialog(QWidget* parent, Mode editmode, Qt::WindowFlags wf):
6292                  HexaBaseDialog(parent, editmode, wf)
6293 {
6294     _helpFileName = "";
6295     setupUi( this );
6296     _initWidget(editmode);
6297     setWindowTitle(HEXABLOCKGUI::tr("ADD_SHAPE"));
6298 }
6299
6300 // ============================================================== Destructeur
6301 AddShapeDialog::~AddShapeDialog()
6302 {
6303     disconnect( HEXABLOCKGUI::selectionMgr(), SIGNAL(currentSelectionChanged()),
6304             this, SLOT(onCurrentSelectionChanged()) );
6305 }
6306
6307 // ============================================================== close
6308 void AddShapeDialog::close()
6309 {
6310     HEXABLOCKGUI::assocInProgress = false;
6311     HexaBaseDialog::close();
6312 }
6313
6314 // ============================================================== _initInputWidget
6315 void AddShapeDialog::_initInputWidget( Mode editmode )
6316 {
6317     shape_le->setProperty( "HexaWidgetType",  QVariant::fromValue(GEOMSHAPE_TREE) );
6318     shape_le->setProperty( "GeomWidgetType", QVariant::fromValue(TopAbs_SHAPE) );
6319     shape_le->installEventFilter(this);
6320     shape_le->setReadOnly(true);
6321 }
6322
6323 void AddShapeDialog::clear()
6324 {
6325     shape_le->clear();
6326     shape_le->setProperty("GeomObj", QVariant());
6327
6328     modelUnregister(this);
6329 }
6330
6331 // ============================================================== onCurrentSelectionChanged
6332 void AddShapeDialog::onCurrentSelectionChanged()
6333 {
6334        SALOME_ListIO selectedObjects;
6335        HEXABLOCKGUI::currentDocGView->getSelected(selectedObjects);
6336        if (selectedObjects.IsEmpty())
6337            return;
6338
6339        // * extract the TopoDS_Shape of the selected object
6340        TopoDS_Shape selectedTopoShape = GEOMBase::GetTopoFromSelection( selectedObjects );
6341        if (selectedTopoShape.IsNull())
6342            return;
6343        shape_le->setProperty("TopoDS_Shape", QVariant::fromValue<TopoDS_Shape>(selectedTopoShape));
6344
6345        // * extract the name of the selected shape
6346        QString name;
6347        GEOMBase::GetNameOfSelectedIObjects( selectedObjects, name, true );
6348        shape_le->setText(name);
6349 }
6350
6351 // ============================================================== onWindowActivated
6352 void AddShapeDialog::onWindowActivated(SUIT_ViewManager* vm)
6353 {
6354     QString vmType = vm->getType();
6355     if ( vmType == OCCViewer_Viewer::Type() )
6356         shape_le->setFocus();
6357 }
6358
6359 // ============================================================== apply
6360 bool AddShapeDialog::apply(QModelIndex& result)
6361 {
6362     bool assocOk;
6363     QString shapeName = shape_le->text();
6364     QVariant v = shape_le->property("TopoDS_Shape");
6365     if ( !v.isValid() || shapeName.isEmpty())
6366         assocOk = false;
6367     else
6368     {
6369         TopoDS_Shape shape = v.value<TopoDS_Shape>();
6370         if (shape.IsNull())
6371             assocOk = false;
6372         else
6373             assocOk = getDocumentModel()->addShape(shape, shapeName);
6374     }
6375
6376     if ( !assocOk ){
6377         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), HEXABLOCKGUI::tr("ADD_SHAPE_FAILED") + "\n" + getErrorMsg() );
6378         return false;
6379     }
6380
6381     return true;
6382 }
6383
6384
6385
6386
6387
6388
6389 //*****************************  OBSOLETE: A SUPPRIMER !!!!  ************************************//
6390
6391 // ============================================================== Constructeur
6392 CylinderDialog::CylinderDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6393 : HexaBaseDialog(parent, editmode, f),
6394   _value(0)
6395 {
6396     _helpFileName = "gui_cyl.html";
6397     setupUi( this );
6398     _initWidget(editmode);
6399
6400     if ( editmode == INFO_MODE ){
6401         setWindowTitle( tr("Cylinder Information") );
6402     }
6403 }
6404
6405 // ============================================================== Destructeur
6406 CylinderDialog::~CylinderDialog()
6407 {
6408 }
6409
6410 // ============================================================== _initInputWidget
6411 void CylinderDialog::_initInputWidget( Mode editmode )
6412 {
6413     QRegExp rx("");
6414     QValidator *validator = new QRegExpValidator(rx, this);
6415
6416     installEventFilter(this);
6417     name_le->installEventFilter(this);
6418
6419     vex_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
6420     vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
6421
6422     vex_le->setValidator( validator );
6423     vec_le->setValidator( validator );
6424
6425     vex_le->installEventFilter(this);
6426     vec_le->installEventFilter(this);
6427
6428     vex_le->setReadOnly(true);
6429     vec_le->setReadOnly(true);
6430
6431     if (editmode == INFO_MODE)
6432     {
6433         name_le->setReadOnly(true);
6434         r_spb->setReadOnly(true);
6435         h_spb->setReadOnly(true);
6436     }
6437
6438 }
6439
6440 // ============================================================== clear
6441 void CylinderDialog::clear()
6442 {
6443     name_le->clear();
6444
6445     vex_le->clear();
6446     modelUnregister(vex_le);
6447
6448     vec_le->clear();
6449     modelUnregister(vec_le);
6450
6451     r_spb->clear();
6452     h_spb->clear();
6453
6454     modelUnregister(this);
6455
6456 }
6457
6458 // ============================================================== setValue
6459 void CylinderDialog::setValue(HEXA_NS::Cylinder* c)
6460 {
6461     HEXA_NS::Vertex* base      = c->getBase();
6462     HEXA_NS::Vector* direction = c->getDirection();
6463     double  r = c->getRadius();
6464     double  h = c->getHeight();
6465
6466     name_le->setText( c->getName() );
6467     vex_le->setText( base->getName() );
6468     vec_le->setText( direction->getName() );
6469     r_spb->setValue(r);
6470     h_spb->setValue(h);
6471
6472     if ( getPatternDataSelectionModel() ){
6473         QModelIndex iCyl       = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(c) );
6474         QModelIndex iBase      = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6475         QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6476
6477         name_le->setProperty( "QModelIndex",  QVariant::fromValue(iCyl) );
6478         vex_le->setProperty( "QModelIndex",  QVariant::fromValue(iBase) );
6479         vec_le->setProperty( "QModelIndex",  QVariant::fromValue(iDirection) );
6480     }
6481     _value = c;
6482 }
6483
6484 // ============================================================== getValue
6485 HEXA_NS::Cylinder* CylinderDialog::getValue()
6486 {
6487     return _value;
6488 }
6489
6490 // ============================================================== apply
6491 bool CylinderDialog::apply(QModelIndex& result)
6492 {
6493     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6494     _currentObj = NULL;
6495
6496     if ( !getDocumentModel() ) return false;
6497     const PatternDataModel*    patternDataModel    = getPatternDataModel();
6498     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6499     if ( !patternDataModel || !patternBuilderModel) return false;
6500
6501     QModelIndex iCyl;
6502     QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6503     QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6504     double r = r_spb->value();
6505     double h = h_spb->value();
6506
6507     if ( ivex.isValid()
6508             && ivec.isValid() ){
6509         iCyl = getDocumentModel()->addCylinder( ivex, ivec, r,  h );
6510     }
6511
6512     if ( !iCyl.isValid() ){
6513         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD CYLINDER" ) );
6514         return false;
6515     }
6516
6517     _value  = iCyl.model()->data(iCyl, HEXA_DATA_ROLE).value<HEXA_NS::Cylinder *>();
6518
6519     QString newName = name_le->text();
6520     if (!newName.isEmpty()) /*{*/
6521         getDocumentModel()->setName( iCyl, newName );
6522
6523     //update the default name in the dialog box
6524     if (_value != NULL)
6525         updateDefaultName(name_le, _value->getType());
6526
6527     // to select/highlight result
6528     result = patternBuilderModel->mapFromSource(iCyl);
6529
6530     return true;
6531 }
6532
6533 //------------------------------- PipeDialog -----------------------------------
6534
6535 // ============================================================== Constructeur
6536
6537 PipeDialog::PipeDialog( QWidget* parent, Mode editmode, Qt::WindowFlags f )
6538 : HexaBaseDialog(parent, editmode, f),
6539   _value(0)
6540 {
6541     _helpFileName = "gui_pipe.html";
6542     setupUi( this );
6543     _initWidget(editmode);
6544     //   setFocusProxy( vex_le );
6545
6546     if ( editmode == INFO_MODE ){
6547         setWindowTitle( tr("Pipe Information") );
6548     }
6549
6550 }
6551
6552 // ============================================================== Destructeur
6553 PipeDialog::~PipeDialog()
6554 {
6555 }
6556
6557 // ============================================================== _initInputWidget
6558 void PipeDialog::_initInputWidget( Mode editmode )
6559 {
6560     QRegExp rx("");
6561     QValidator *validator = new QRegExpValidator(rx, this);
6562
6563     installEventFilter(this);
6564     name_le->installEventFilter(this);
6565
6566     //Vertex Field config
6567     vex_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VERTEX_TREE) );
6568     vex_le->installEventFilter(this);
6569     vex_le->setValidator( validator );
6570
6571     //Vector Field config
6572     vec_le->setProperty( "HexaWidgetType",  QVariant::fromValue(VECTOR_TREE) );
6573     vec_le->installEventFilter(this);
6574     vec_le->setValidator( validator );
6575
6576
6577     if ( editmode == INFO_MODE ){
6578         name_le->setReadOnly(true);
6579         ir_spb->setReadOnly(true);
6580         er_spb->setReadOnly(true);
6581         h_spb->setReadOnly(true);
6582     }
6583
6584     vex_le->setReadOnly(true);
6585     vec_le->setReadOnly(true);
6586
6587     //connect( name_le, SIGNAL(returnPressed()), this, SLOT(updateName()));
6588 }
6589
6590 // ============================================================== clear
6591 void PipeDialog::clear()
6592 {
6593     name_le->clear();
6594
6595     vex_le->clear();
6596     modelUnregister(vex_le);
6597
6598     vec_le->clear();
6599     modelUnregister(vec_le);
6600
6601     modelUnregister(this);
6602 }
6603
6604 // ============================================================== setValue
6605 void PipeDialog::setValue(HEXA_NS::Pipe* p)
6606 {
6607     HEXA_NS::Vertex* base      = p->getBase();
6608     HEXA_NS::Vector* direction = p->getDirection();
6609     double  ir = p->getInternalRadius();
6610     double  er = p->getRadius();
6611     double  h  = p->getHeight();
6612
6613     name_le->setText( p->getName() );
6614     vex_le->setText( base->getName() );
6615     vec_le->setText( direction->getName() );
6616     ir_spb->setValue(ir);
6617     er_spb->setValue(er);
6618     h_spb->setValue(h);
6619
6620     if ( getPatternDataSelectionModel() ){
6621         QModelIndex iPipe      = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(p) );
6622         QModelIndex iBase      = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(base) );
6623         QModelIndex iDirection = getPatternDataSelectionModel()->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(direction) );
6624
6625         name_le->setProperty( "QModelIndex",  QVariant::fromValue(iPipe) );
6626         vex_le->setProperty( "QModelIndex",  QVariant::fromValue(iBase) );
6627         vec_le->setProperty( "QModelIndex",  QVariant::fromValue(iDirection) );
6628     }
6629     _value = p;
6630 }
6631
6632 // ============================================================== getValue
6633 HEXA_NS::Pipe* PipeDialog::getValue()
6634 {
6635     return _value;
6636 }
6637
6638 // ============================================================== apply
6639 bool PipeDialog::apply(QModelIndex& result)
6640 {
6641     if (_currentObj != NULL) _highlightWidget(_currentObj, Qt::white);
6642     _currentObj = NULL;
6643
6644     if ( !getDocumentModel() ) return false;
6645     const PatternDataModel*    patternDataModel    = getPatternDataModel();
6646     const PatternBuilderModel* patternBuilderModel = getPatternBuilderModel();
6647     if ( !patternDataModel || !patternBuilderModel)    return false;
6648
6649     QModelIndex iPipe;
6650     QModelIndex ivex = patternDataModel->mapToSource( _index[vex_le] );
6651     QModelIndex ivec = patternBuilderModel->mapToSource( _index[vec_le] );
6652     double ir = ir_spb->value();
6653     double er = er_spb->value();
6654     double h  = h_spb->value();
6655
6656     if (ir >= er) {
6657         SUIT_MessageBox::information( this, tr( "CANNOT ADD PIPE" ), tr( "External radius must be greather than Internal radius!" ) );
6658         return false;
6659     }
6660
6661
6662     if ( ivex.isValid()
6663             && ivec.isValid() ){
6664         iPipe = getDocumentModel()->addPipe( ivex, ivec, ir, er, h );
6665     }
6666
6667     if ( !iPipe.isValid() ){
6668         SUIT_MessageBox::critical( this, tr( "ERR_ERROR" ), tr( "CANNOT ADD PIPE" ) );
6669         return false;
6670     }
6671     _value  = iPipe.model()->data(iPipe, HEXA_DATA_ROLE).value<HEXA_NS::Pipe *>();
6672
6673     QString newName = name_le->text();
6674     if ( !newName.isEmpty() )/*{*/
6675         getDocumentModel()->setName( iPipe, newName );
6676
6677     //update the default name in the dialog box
6678     if (_value != NULL)
6679         updateDefaultName(name_le, _value->getType());
6680
6681     // to select/highlight result
6682     result = patternBuilderModel->mapFromSource(iPipe);
6683
6684     return true;
6685 }
6686 // ************************************** FIN A SUPPRIMER ******************************************//
6687