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