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