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