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