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