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