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