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