Salome HOME
Remove QT4 compatibility.
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.cxx
1 // Copyright (C) 2009-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //#define _DEVDEBUG_
21
22 #include <cassert>
23
24 #include <QDir>
25 #include <QInputDialog>
26 #include <QIcon>
27 #include <QStackedWidget>
28 #include <QMenu>
29 #include <QSplitter>
30
31 #include <QtxTreeView.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ViewManager.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SUIT_DataObject.h>
39 #include <SUIT_DataBrowser.h>
40 #include <SUIT_FileDlg.h>
41
42 #include <SVTK_ViewManager.h>
43 #include <SVTK_ViewModel.h>
44 #include <SVTK_ViewWindow.h>
45
46 #include <VTKViewer_ViewModel.h>
47 #include <vtkActor.h>
48 #include <vtkActorCollection.h>
49 #include <VTKViewer_Algorithm.h>
50 #include <vtkRenderer.h>
51
52
53
54 #include <SOCC_ViewModel.h>
55 #include <SOCC_ViewWindow.h>
56 #include <OCCViewer_ViewWindow.h>
57 #include <SALOME_Prs.h>
58 #include <SOCC_Prs.h>
59 #include <SOCC.h>
60
61 // SALOME KERNEL includes
62 #include <SALOMEDS_Study.hxx>
63 #include <SALOMEDSClient_StudyBuilder.hxx>
64 #include <SALOMEDSClient_SComponent.hxx>
65 #include <SALOMEDSClient_ClientFactory.hxx>
66 #include <SALOMEDSClient_IParameters.hxx>
67
68
69
70 #include <SalomeApp_Study.h>
71 #include <SalomeApp_Module.h>
72 #include <SalomeApp_Application.h>
73 #include <SalomeApp_DataModel.h>
74
75
76 #include <SALOME_ListIO.hxx>
77
78
79 #include <SALOME_LifeCycleCORBA.hxx>
80
81 #include <LightApp_VTKSelector.h>
82
83 #include <OCCViewer_ViewManager.h>
84
85 #include <QtxPopupMgr.h>
86
87 #include "Resource.hxx"
88
89 #include "HEXABLOCKGUI.hxx"
90 #include "HEXABLOCKGUI_Export.hxx"
91 #include "HEXABLOCKGUI_Trace.hxx"
92 #include "HEXABLOCKGUI_Resource.hxx"
93
94 #include "HEXABLOCKGUI_DocumentModel.hxx"
95 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
96 //#include "HEXABLOCKGUI_DocumentDelegate.hxx"
97 #include "HEXABLOCKGUI_DocumentPanel.hxx"
98 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
99 #include "HEXABLOCKGUI_OccGraphicView.hxx"
100 #include "HEXABLOCKGUI_GraphicViewsHandler.hxx"
101
102 #include "HEXABLOCK_version.h"
103
104 #include "MyBasicGUI_PointDlg.hxx"
105
106 // #include "HEXABLOCK.hxx"                del Hexa6
107 // #include "HexDocument_impl.hxx"         del Hexa6
108 #include "Hex.hxx"
109
110 //#include <V3d_PerspectiveView.hxx>
111 #include <V3d_AmbientLight.hxx>
112 #include <V3d_DirectionalLight.hxx>
113 #include <Xw_Window.hxx>
114 #include <V3d_TypeOfShadingModel.hxx>
115 #include <TCollection_ExtendedString.hxx>
116
117 #include <BRepAlgoAPI_Fuse.hxx>
118
119 #include <AIS_ListIteratorOfListOfInteractive.hxx>
120
121 #include <utilities.h>
122
123 #define DW_MINIMUM_WIDTH       50
124 #define DWINPUT_MINIMUM_HEIGHT 50
125 #define DWINPUT_MINIMUM_WIDTH  50//255
126
127 using namespace std;
128 using namespace HEXABLOCK::GUI;
129
130 // HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine  = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
131 //
132 VtkDocumentGraphicView* HEXABLOCKGUI::currentDocGView = NULL;
133 OccGraphicView*         HEXABLOCKGUI::currentOccGView = NULL;
134 bool                    HEXABLOCKGUI::assocInProgress = false;
135 SalomeApp_Application*  HEXABLOCKGUI::myApplication = NULL;
136
137 HEXABLOCKGUI::HEXABLOCKGUI() :
138           SalomeApp_Module( "HEXABLOCK" ),
139 //          LightApp_Module( "HEXABLOCK" ),
140           _menuId(190),
141           _dwPattern(0),
142           _dwAssociation(0),
143           _dwGroups(0),
144           _dwMesh(0),
145           _dwObjectBrowser(0),
146           _dwInputPanel(0),
147           _patternDataTreeView(0),
148 //          _patternBuilderTreeView(0),
149           _patternGeomTreeView(0),
150           _groupsTreeView(0),
151           _meshTreeView(0),
152 //          _treeViewDelegate(0),
153           _isSaved( false ),
154           moduleActivatedOnce(false),
155           menusEnabled(true),
156           _vertexDiag(0),
157           _edgeDiag(0),
158           _quadDiag(0),
159           _hexaDiag(0),
160           _vectorDiag(0),
161           _cylinderDiag(0),
162           _pipeDiag(0),
163           _makeGridDiag(0),
164           _makeCylinderDiag(0),
165           _makePipeDiag(0),
166           _makeCylindersDiag(0),
167           _makePipesDiag(0),
168           _removeHexaDiag(0),
169           _prismQuadDiag(0),
170           _joinQuadDiag(0),
171           _mergeDiag(0),
172           _disconnectDiag(0),
173           _cutEdgeDiag(0),
174           _makeTransformationDiag(0),
175           _makeSymmetryDiag(0),
176           _performTransformationDiag(0),
177           _performSymmetryDiag(0),
178           _vertexAssocDiag(0),
179           _edgeAssocDiag(0),
180           _quadAssocDiag(0),
181           _groupDiag(0),
182           _lawDiag(0),
183           _propagationDiag(0),
184           _computeMeshDiag(0),
185           _replaceHexaDiag(0),
186           _quadRevolutionDiag(0),
187           _makeHemiSphereDiag(0),
188           _modelInfoDiag(NULL),
189           _addShapeDiag(NULL),
190           _vertexInfoDialog(NULL),
191           _edgeInfoDialog(NULL),
192           _quadInfoDialog(NULL),
193           _hexaInfoDialog(NULL),
194           _vectorInfoDialog(NULL),
195           _groupInfoDialog(NULL),
196           _lawInfoDialog(NULL),
197           _propagationInfoDialog(NULL),
198           currentDialog(NULL),
199           lastOccPrs(NULL),
200           lastVtkDocGView(NULL)
201 {
202     DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
203
204     graphicViewsHandler = new GraphicViewsHandler();
205     loadDocLastPath = new QDir();
206     saveDocLastPath = new QDir();
207     hexa_root       = HEXA_NS::Hex::getInstance ();
208 }
209
210 HEXABLOCKGUI::~HEXABLOCKGUI()
211 {
212 }
213
214
215 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
216 {
217     SUIT_Application* app = SUIT_Session::session()->activeApplication();
218     if( app )
219         return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
220     else
221         return NULL;
222 }
223
224
225 // Gets an reference to the module's engine
226 /****************************************************
227 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
228 {
229     Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
230     HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
231     ASSERT(!CORBA::is_nil(clr));
232     return clr;
233 }
234  **************************************************** */
235
236 void HEXABLOCKGUI::initialize( CAM_Application* app )
237 {
238         MESSAGE("HEXABLOCKGUI::initialize");
239     DEBTRACE("HEXABLOCKGUI::initialize");
240     SalomeApp_Module::initialize( app );
241
242     // _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
243
244     DEBTRACE(app << "  " << application() << " " << application()->desktop() << " " << aParent);
245
246     SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
247     setResource(aResourceMgr);
248
249     createAndFillDockWidget();
250     createActions();
251     createMenus();
252     createTools();
253 }
254
255 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
256 {
257     DEBTRACE("HEXABLOCKGUI::viewManagers");
258     //   list.append( QxScene_Viewer::Type() );
259     //   list.append( OCCViewer_Viewer::Type() );
260     //   list.append( SVTK_Viewer::Type() );
261 }
262
263
264 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
265 {
266     DEBTRACE("HEXABLOCKGUI::activateModule");
267
268     /*HexaBlock can be launched in only one application*/
269     if (myApplication == NULL)
270         //remember the first application
271         myApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
272
273     //application verification: if it's not the one known by HexaBlock,
274     //leave without activating
275     SalomeApp_Application* currentApplication =  dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
276     if (myApplication != currentApplication) return false;
277
278     bool bOk = SalomeApp_Module::activateModule( theStudy );
279     if ( !bOk ) return false;
280
281     showDockWidgets(true);
282
283     connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
284             this, SLOT(onWindowActivated( SUIT_ViewWindow* )), Qt::UniqueConnection );
285     if ( getApp()->objectBrowser() ) {
286       connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
287                this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
288     }
289
290     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
291
292     SUIT_ViewManager* vm;
293     ViewManagerList OCCViewManagers, VTKViewManagers;
294
295     application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
296     QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
297     while ( itOCC.hasNext() && (vm = itOCC.next()) )
298         myOCCSelectors.append( new HEXABLOCKGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
299
300     application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
301     QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
302     while ( itVTK.hasNext() && (vm = itVTK.next()) )
303         myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
304
305     //NPAL 19674
306     SALOME_ListIO selected;
307     sm->selectedObjects( selected );
308     sm->clearSelected();
309
310     // disable OCC selectors
311     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
312     QListIterator<HEXABLOCKGUI_OCCSelector*> itOCCSel( myOCCSelectors );
313     while ( itOCCSel.hasNext() )
314         if ( HEXABLOCKGUI_OCCSelector* sr = itOCCSel.next() )
315             sr->setEnabled(true);
316
317     // disable VTK selectors
318     getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
319     QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
320     while ( itVTKSel.hasNext() )
321         if ( LightApp_VTKSelector* sr = itVTKSel.next() )
322             sr->setEnabled(true);
323
324     sm->setSelectedObjects( selected, true );   //NPAL 19674
325
326     //connect close signal to vtk view manager
327     vm = getApp()->getViewManager(SVTK_Viewer::Type(), false);
328     if (vm != NULL)
329     {
330         connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
331                 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
332     }
333
334     //connect close signal to occ view manager
335     vm = getApp()->getViewManager(OCCViewer_Viewer::Type(), false);
336     if (vm != NULL)
337     {
338         connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
339                 this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
340     }
341
342     if (currentOccGView != NULL && currentOccGView->getViewWindow() != NULL)
343             currentOccGView->getViewWindow()->installEventFilter(this);
344
345     if (currentDocGView != NULL)
346     {
347         switchModel(currentDocGView);
348         showAllMenus();
349
350         if (currentDocGView->getViewWindow() != NULL)
351             currentDocGView->getViewWindow()->installEventFilter(this);
352     }
353     else
354     {
355         newDocument();
356 //        initialMenus();
357     }
358
359     return bOk;
360 }
361
362
363 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
364 {
365     disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
366             this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
367     disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
368             this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
369
370     SVTK_ViewWindow* vtkView = (currentDocGView != NULL) ? currentDocGView->getViewWindow() : NULL;
371     if ( vtkView != NULL)
372     {
373         //default selectionMode in VTKView
374         vtkView->SetSelectionMode( ActorSelection );
375         vtkView->removeEventFilter(this);
376 //        vtkView->close();
377     }
378
379     OCCViewer_ViewWindow* occView = (currentOccGView != NULL) ? currentOccGView->getViewWindow() : NULL;
380     if (occView != NULL)
381     {
382         //defaut selectionMode in OccView
383         selectionMgr()->clearSelected();
384         currentOccGView->globalSelection();
385         occView->removeEventFilter(this);
386 //        occView->close();
387     }
388
389     qDeleteAll(myOCCSelectors);
390     myOCCSelectors.clear();
391     getApp()->selectionMgr()->setEnabled( true, OCCViewer_Viewer::Type() );
392
393     qDeleteAll(myVTKSelectors);
394     myVTKSelectors.clear();
395     getApp()->selectionMgr()->setEnabled( true, SVTK_Viewer::Type() );
396
397     bool bOk = SalomeApp_Module::deactivateModule( theStudy );
398
399     //switch off current document graphic view
400     switchOffGraphicView(currentDocGView);
401
402     //...and hide menus
403     setMenuShown( false );
404     setToolShown( false );
405     showDockWidgets( false );
406     if (_dwInputPanel)
407         _dwInputPanel->close();
408
409     hideActor();
410
411     return bOk;
412 }
413
414 SALOMEDS::Study_var HEXABLOCKGUI::getStudyServant()
415 {
416   SALOME_NamingService *aNamingService = SalomeApp_Application::namingService();
417   CORBA::Object_var aSMObject = aNamingService->Resolve("/Study");
418   SALOMEDS::Study_var aDSStudy = SALOMEDS::Study::_narrow(aSMObject);
419   return aDSStudy._retn();
420 }
421
422 void HEXABLOCKGUI::addInStudy(QMap<QString, TopoDS_Shape>& topo_shapes,
423                               QMap<QString, QString>& docShapesEntry,
424                               QMap<QString, QString>& docShapesName)
425 {
426     if (topo_shapes.size() == 0 || currentOccGView == NULL || currentDocGView == NULL)
427         return; //there's nothing to publish in this case
428
429     SalomeApp_Study* appStudy = HEXABLOCKGUI::activeStudy();
430     if(!appStudy) return;
431     SALOMEDS::Study_var aDSStudy = getStudyServant();
432     SALOMEDS::StudyBuilder_var     aBuilder (aDSStudy->NewBuilder());
433     QString entry = currentDocGView->getDocumentModel()->documentEntry();
434     SALOMEDS::SObject_var aFatherSO = aDSStudy->FindObjectID( qPrintable(entry) );
435     if (aFatherSO->_is_nil())
436         return;
437
438     // * get a presentation
439     bool isNewPrs = false;
440     SOCC_Prs* prs = getOccPrs(currentDocGView);
441     if (prs == NULL)
442     {
443         prs = new SOCC_Prs(0);
444         isNewPrs = true;
445     }
446
447     // * init the presentation with the given shapes
448     QMap<QString, TopoDS_Shape>::const_iterator i = topo_shapes.constBegin();
449     while (i != topo_shapes.constEnd())
450     {
451         QString shapeName  = i.key();
452         TopoDS_Shape shapeValue = i.value();
453         Handle(AIS_Shape) ais_shape = new AIS_Shape(shapeValue);
454         SALOMEDS::SObject_var aSO = aBuilder->NewObject(aFatherSO);
455         QString objStudyEntry = aSO->GetID(); //the entry of the published object
456         Handle( SALOME_InteractiveObject ) io = new SALOME_InteractiveObject(objStudyEntry.toStdString().c_str(),
457                                                                     "HEXABLOCK", shapeName.toStdString().c_str());
458         ais_shape->SetOwner(io);
459         prs->AddObject(ais_shape);
460         aSO->SetAttrString("AttributeName", shapeName.toStdString().c_str());
461         docShapesEntry[shapeName] = objStudyEntry;
462         docShapesName[objStudyEntry] = shapeName;
463         currentOccGView->addShape(objStudyEntry, ais_shape);
464         i++; //handle next shape
465     }
466     // * set the preview
467     if (isNewPrs)
468         prs->AddObject(currentOccGView->getPreviewShape());
469
470     occPrs[currentDocGView] = prs;
471     getApp()->updateObjectBrowser();
472     showOnlyActor();
473 }
474
475
476 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
477 {
478     SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
479     SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
480     SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
481
482     return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
483 }
484
485
486 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
487 {
488     bool result = false;
489
490     // Pas de renommage des shapes pour le moment, juste les documents
491     VtkDocumentGraphicView* dgview = getDocGViewByEntry(entry);
492     if (dgview == NULL || dgview->getDocumentModel() == NULL)
493         return result;
494
495     _PTR(SObject) obj ( SalomeApp_Application::getStudy()->FindObjectID(qPrintable(entry)) );
496     _PTR(GenericAttribute) anAttr;
497     if ( obj ){
498       if ( obj->FindAttribute(anAttr, "AttributeName") ) {
499         _PTR(AttributeName) aName (anAttr);
500         DocumentModel* docModel = dgview->getDocumentModel();
501         docModel->setName( name );
502         aName->SetValue( name.toLatin1().data() );
503         getApp()->updateObjectBrowser();
504 //        _dwPattern->setWindowTitle( name );
505         result = true;
506       }
507     }
508     return result;
509 }
510
511 // --- Default windows
512 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
513 {
514     DEBTRACE("HEXABLOCKGUI::windows");
515     theMap.clear();
516     theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
517 #ifndef DISABLE_PYCONSOLE
518     theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
519 #endif
520 }
521
522 QString  HEXABLOCKGUI::engineIOR() const
523 {
524     DEBTRACE("HEXABLOCKGUI::engineIOR");
525
526     /* ************************************   TODO Hexa6
527     CORBA::ORB_var anORB = getApp()->orb();
528     CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
529     return QString( anIOR.in() );
530        ************************************ */
531     return "";
532 }
533
534 VtkDocumentGraphicView* HEXABLOCKGUI::getOrCreateDocument(SalomeApp_DataObject* studyObject)
535 {
536     if (docs.count(studyObject->entry()) == 0)
537     {
538         //Object's document not acquired yet
539         VtkDocumentGraphicView* dgview;
540         HEXA_NS::Hex* directory = HEXA_NS::Hex::getInstance();
541         if (directory == NULL)
542             return NULL;    //No working director found
543
544         //------------------ Load the document -----------------
545         HEXA_NS::Document* document = directory->findDocument(studyObject->name().toStdString());
546         if (document == NULL)
547             return NULL;    //No document found
548
549         DocumentModel* docModel = new DocumentModel(document, studyObject->entry(), this );
550         if (!docModel) {
551             MESSAGE("Doc model creation failed!");
552             return NULL;
553         }
554         dgview = graphicViewsHandler->createDocumentGraphicView( docModel, NULL, application()->desktop() );
555         if (dgview == NULL) return NULL;
556
557         //update the data tree
558         docs[studyObject->entry()] = dgview;
559     }
560
561     return docs[studyObject->entry()];
562 }
563
564 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
565 {
566     // ** we want to switch automatically to the right view windows
567
568     //first, find selected item
569     QString itemEntry;
570     DataObjectList dol = getApp()->objectBrowser()->getSelected();
571     if (dol.isEmpty()) return;
572     SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
573     if (!item || item->parent()->name().compare(tr("HEXABLOCK")) != 0 ||
574             item->entry().isEmpty())
575         return;
576
577     // find the document corresponding to it
578     VtkDocumentGraphicView* docGView = NULL;
579     if (docs.contains(item->entry()))
580         docGView = docs[item->entry()];
581     else
582         docGView = getOrCreateDocument(item);
583
584     //Init OCC if necessary
585     if (currentOccGView == NULL)
586     {
587         currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(), application()->desktop());
588         currentOccGView->getViewWindow()->installEventFilter(this);
589     }
590     else if (currentOccGView->getViewWindow() == NULL)
591     {
592         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
593         currentOccGView->getViewWindow()->installEventFilter(this);
594     }
595
596     //Init the vtk view if necessary
597     if (docGView->getViewWindow() == NULL)
598     {
599         if (currentDocGView == NULL || currentDocGView->getViewWindow() == NULL)
600         {
601             docGView->setViewWindow(graphicViewsHandler->createVtkWindow());
602             docGView->getViewWindow()->installEventFilter(this);
603             showAllMenus();
604             if (!menusEnabled)
605                 setAllMenusEnabled(true);
606         }
607         else
608             docGView->setViewWindow(currentDocGView->getViewWindow());
609
610         if (docGView->getDocumentActor() == NULL)
611             docGView->update();
612     }
613
614     if (docGView == NULL || docGView == currentDocGView)
615     {
616         showOnlyActor();
617         return;
618     }
619
620     //update the current document
621     switchModel(docGView);
622 }
623
624
625 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
626 {
627     DEBTRACE("HEXABLOCKGUI::onWindowActivated");
628 }
629
630 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
631 {
632     DEBTRACE("HEXABLOCKGUI::onWindowClosed");
633
634     //Decharger le model correspondant (VTK)
635     SVTK_ViewWindow* window = dynamic_cast<SVTK_ViewWindow*>(svw);
636     if (window != NULL)
637     {
638         //VTK clean close
639         if (currentDocGView != NULL && currentDocGView->getViewWindow() == window)
640         { //HexaBlock Vtk Window has been closed
641
642             if (currentDialog != NULL) currentDialog->close();
643 //            if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
644             if (currentDocGView != NULL)
645                 currentDocGView->setViewWindow(NULL);
646
647 //            initialMenus();
648             setAllMenusEnabled(false);
649             enableDocumentMenus(true);
650
651             return;
652         }
653
654         //SAVE DOCUMENT
655         /*VtkDocumentGraphicView* dgview = graphicViewsHandler->getDocumentGraphicView(window);
656         if (dgview == NULL) return; //The window has no document to close
657
658         //Save the document? (Ask only if the document is not empty
659         int answerCode = SUIT_MessageBox::question(
660                             0,
661                             tr("Close"),
662                             tr("Save the document ?"),
663                             SUIT_MessageBox::Yes | SUIT_MessageBox::Cancel,
664                             SUIT_MessageBox::Cancel);
665         if ( answerCode == SUIT_MessageBox::Cancel) return; //abort closing
666         else if (answerCode == SUIT_MessageBox::Yes)
667             saveDocument(); //Save the document
668         */
669 //        switchOffGraphicView(window); //disconnect all connected signals
670 //        currentVtkView = NULL;
671 //        graphicViewsHandler->closeDocumentGraphicView(window);
672
673         //create a new one (empty document)
674 //        newDocument();
675 //        currentVtkView->setWindowTitle(tr("HEXABLOCK") + " : " + currentVtkView->windowTitle());
676     }
677
678     //OCC clean close
679     if (currentOccGView != NULL && svw == currentOccGView->getViewWindow())
680     {
681         if (_vertexAssocDiag != NULL) _vertexAssocDiag->clear();
682         if (_edgeAssocDiag != NULL) _edgeAssocDiag->clear();
683         if (_quadAssocDiag != NULL) _quadAssocDiag->clear();
684         if (currentDialog != NULL) currentDialog->close();
685 //        if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
686
687         currentOccGView->getViewWindow()->removeEventFilter(this);
688         currentOccGView->setViewWindow(NULL);
689     }
690 }
691
692 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager*  vm)
693 {
694     DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
695
696     connect( vm, SIGNAL( tryCloseView( SUIT_ViewWindow * ) ),
697             this, SLOT( onWindowClosed(SUIT_ViewWindow *) ), Qt::UniqueConnection );
698
699     if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
700       {
701         LightApp_SelectionMgr* sm = getApp()->selectionMgr();
702         myOCCSelectors.append( new HEXABLOCKGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
703         // disable OCC selectors
704         getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
705         QListIterator<HEXABLOCKGUI_OCCSelector*> itOCCSel( myOCCSelectors );
706         while ( itOCCSel.hasNext() )
707           if ( HEXABLOCKGUI_OCCSelector* sr = itOCCSel.next() )
708             sr->setEnabled(true);
709       }
710       else if ( vm->getType() == SVTK_Viewer::Type() )
711       {
712         LightApp_SelectionMgr* sm = getApp()->selectionMgr();
713         myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
714
715         // disable VTK selectors
716         getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
717         QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
718         while ( itVTKSel.hasNext() )
719           if ( LightApp_VTKSelector* sr = itVTKSel.next() )
720             sr->setEnabled(true);
721       }
722 }
723
724 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
725 {
726     DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
727
728     SUIT_ViewModel* viewer = vm->getViewModel();
729     if (vm != NULL && vm->getType() == SVTK_Viewer::Type())
730     {
731         //VTK View Manager removed
732         if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") == 0)
733         {
734             //Process only if it's our view manager
735             SUIT_ViewManager* myVm = NULL;
736             if (currentDocGView != NULL && currentDocGView->getViewWindow() != NULL)
737                 myVm = currentDocGView->getViewWindow()->getViewManager();
738
739             if (myVm == vm)
740             {
741                 //close opened dialog
742                 if (currentDialog != NULL) currentDialog->close();
743 //                if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
744
745                 initialMenus();
746             }
747         }
748
749         //remove its selector
750         QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
751         while ( itVTKSel.hasNext() )
752             if ( LightApp_VTKSelector* sr = itVTKSel.next() )
753                 if ( sr->viewer() == viewer )
754                 {
755                     delete myVTKSelectors.takeAt( myVTKSelectors.indexOf( sr ) );
756                     break;
757                 }
758         return;
759     }
760
761     //OCC
762     if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
763     {
764         //OCC View removed: remove its selector
765         QListIterator<HEXABLOCKGUI_OCCSelector*> itOCCSel( myOCCSelectors );
766         while ( itOCCSel.hasNext() )
767             if ( HEXABLOCKGUI_OCCSelector* sr = itOCCSel.next() )
768                 if ( sr->viewer() == viewer )
769                 {
770                     delete myOCCSelectors.takeAt( myOCCSelectors.indexOf( sr ) );
771                     break;
772                 }
773     }
774 }
775
776 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected  )
777 {
778     QModelIndexList l = selected.indexes();
779     if ( l.count() == 0 ) return;
780     if ( !l[0].isValid() ) return;
781     VtkDocumentGraphicView* currentGraphicView = getCurrentVtkGraphicView();
782     if ( currentGraphicView == NULL) return;
783
784     QTreeView* theTree = NULL;
785     if ( sender() == currentGraphicView->getPatternDataSelectionModel() ){
786         theTree = _patternDataTreeView;
787     }
788     /*else if ( sender() == currentGraphicView->getPatternBuilderSelectionModel() ){
789         theTree = _patternBuilderTreeView;
790     }*/
791     else if ( sender() == currentGraphicView->getPatternGeomSelectionModel() ) {
792         theTree =  _patternGeomTreeView;
793     }
794     else if ( sender() == currentGraphicView->getGroupsSelectionModel() ){
795         theTree = _groupsTreeView;
796     } else if ( sender() == currentGraphicView->getMeshSelectionModel() ){
797         theTree = _meshTreeView;
798     }
799     if ( theTree ){
800         theTree->scrollTo ( l[0] );
801     }
802 }
803
804 bool HEXABLOCKGUI::createSComponent() //addComponent
805 {
806     DEBTRACE("HEXABLOCKGUI::createSComponent");
807     // --- Find or create (if not done yet) "HEXABLOCK" SComponent in the study
808
809     _PTR(Study)            aStudy = SalomeApp_Application::getStudy();
810     _PTR(StudyBuilder)     aBuilder (aStudy->NewBuilder());
811     _PTR(GenericAttribute) anAttr;
812     _PTR(AttributeName)    aName;
813     _PTR(AttributeGraphic) aGraphic;
814
815     _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
816     if ( !aComponent ){ //Create hexablock component if there's not one yet
817         aComponent = aBuilder->NewComponent("HEXABLOCK");
818         anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
819         aName = _PTR(AttributeName) (anAttr);
820         aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
821
822         anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
823         _PTR(AttributePixMap) aPixmap(anAttr);
824         aPixmap->SetPixMap(tr("ICO_MODULE_HEXABLOCK_SMALL").toStdString());
825
826         aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
827         DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
828         return true;
829     }
830     return false;
831 }
832
833 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
834 {
835     DEBTRACE("HEXABLOCKGUI::setResource");
836     _myresource = new HEXABLOCKGUI_Resource(r);
837     _myresource->preferencesChanged();
838 }
839
840 void HEXABLOCKGUI::createPreferences()
841 {
842     DEBTRACE("HEXABLOCKGUI::createPreferences");
843     _myresource->createPreferences(this);
844 }
845
846 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
847 {
848     DEBTRACE("HEXABLOCKGUI::preferencesChanged");
849     _myresource->preferencesChanged(sect, name);
850 //    if(name=="userCatalog")
851 //        _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
852 }
853
854 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
855 {
856     QModelIndex currentIndex = _patternDataTreeView->currentIndex();
857     QVariant currentAssocVariant;
858     QString currentAssocEntry;
859
860     currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
861     currentAssocEntry    = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
862     if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
863         QMenu menu( _patternDataTreeView );
864         //Remove association
865         QAction *clearAct = menu.addAction( "Remove association(s)" );
866         connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()), Qt::UniqueConnection );
867         menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
868     }
869     else {
870
871         VtkDocumentGraphicView* currentVtkGraphicView = getCurrentVtkGraphicView();
872         if (currentVtkGraphicView == NULL) return;
873         QStandardItem *item = currentVtkGraphicView->getPatternDataModel()->itemFromIndex(currentIndex);
874
875         //We don't do anything for single items
876         if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
877                 item->type() == QUADITEM || item->type() == HEXAITEM)
878             return;
879
880         //No associations for HEXA
881         QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
882         if ( !treeVariant.isValid() ) return;
883         int eltType = treeVariant.toInt();
884         if (eltType == HEXA_DIR_TREE) return;
885         QMenu menu( _patternDataTreeView );
886
887         //Show association(s)
888         QAction *showAssocAct = menu.addAction( "Show associations" );
889         connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()), Qt::UniqueConnection );
890
891         //Clear all associations
892         QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
893         connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()), Qt::UniqueConnection );
894
895         menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
896     }
897 }
898
899
900 void HEXABLOCKGUI::createAndFillDockWidget()
901 {
902
903     QMainWindow *aParent = application()->desktop();
904
905     // Create dock widget (3 dock)
906
907     //1) *********** user input panel ( contain user's edit dialog box )
908     _dwInputPanel = new QDockWidget(aParent);
909     _dwInputPanel->setVisible(false);
910     _dwInputPanel->setWindowTitle("Input Panel");
911     _dwInputPanel->setObjectName("hexablockInputPanelDock");
912 //    _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
913
914 //    _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
915
916     //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
917     //      Pattern
918     _dwPattern = new QDockWidget(aParent);
919     _dwPattern->setVisible(false);
920     _dwPattern->setWindowTitle("Model");
921     _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
922     _dwPattern->setObjectName("hexablockModelDock");
923
924     QFrame*      patternFrame  = new QFrame(_dwPattern);
925     patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
926     QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
927     patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
928     QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
929     _patternDataTreeView    = new QTreeView(patternFrame);//_dwPattern);
930 //    _patternBuilderTreeView = new QTreeView(patternFrame);                  // ---> TO REMOVE
931     _patternGeomTreeView    = new QTreeView(patternFrame);
932     splitter->addWidget(_patternDataTreeView);
933 //    splitter->addWidget(_patternBuilderTreeView);                           // ---> TO REMOVE
934     splitter->addWidget(_patternGeomTreeView);
935     patternLayout->addWidget(splitter);
936
937     _patternDataTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers/*QAbstractItemView::DoubleClicked*/);
938     _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
939 //    _patternDataTreeView->setItemDelegate(_treeViewDelegate);
940
941
942 //    _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
943 //    _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
944
945     _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
946     _patternGeomTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
947
948     _dwPattern->setWidget(patternFrame);
949     patternFrame->show();
950
951     //      Groups
952     _dwGroups = new QDockWidget(aParent);
953
954     _dwGroups->setVisible(false);
955     _dwGroups->setWindowTitle("Groups");
956     _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
957     _dwGroups->setObjectName("hexablockGroupsDock");
958     _groupsTreeView = new QTreeView(_dwGroups);
959     _groupsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
960 //    _groupsTreeView->setItemDelegate(_treeViewDelegate);
961     _dwGroups->setWidget(_groupsTreeView);
962     _groupsTreeView->show();
963
964     //      Mesh
965     _dwMesh = new QDockWidget(aParent);
966     _dwMesh->setVisible(false);
967     _dwMesh->setWindowTitle("Mesh");
968     _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
969     _dwMesh->setObjectName("hexablockMeshDock");
970     _meshTreeView = new QTreeView(_dwMesh);
971     _meshTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
972     _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
973 //    _meshTreeView->setItemDelegate(_treeViewDelegate);
974     _dwMesh->setWidget(_meshTreeView);
975     _meshTreeView->show();
976
977 //    QDockWidget *_dwObjectBrowser = 0;
978     QWidget* wid = 0;
979     if ( getApp()->objectBrowser() )
980       wid = getApp()->objectBrowser()->treeView();
981     while ( wid && !_dwObjectBrowser ) {
982         _dwObjectBrowser = ::qobject_cast<QDockWidget*>( wid );
983         wid = wid->parentWidget();
984     }
985     
986     if ( _dwObjectBrowser ) {
987       _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
988       _dwObjectBrowser->setWindowTitle("Study");
989     }
990
991     // dock widget position
992     if ( _dwObjectBrowser ) {
993       aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
994     }
995     aParent->addDockWidget( Qt::RightDockWidgetArea, _dwInputPanel );
996
997 //    aParent->tabifyDockWidget( _dwPattern, _dwObjectBrowser );
998 //    aParent->tabifyDockWidget( _dwGroups, _dwPattern );
999 //    aParent->tabifyDockWidget( _dwMesh, _dwGroups );
1000
1001     if ( _dwObjectBrowser ) {
1002       aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
1003     }
1004     aParent->tabifyDockWidget( _dwPattern, _dwGroups );
1005     aParent->tabifyDockWidget( _dwGroups, _dwMesh );
1006     aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
1007
1008     // popup menu on data tree view
1009     _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
1010     connect(_patternDataTreeView,
1011             SIGNAL(customContextMenuRequested(const QPoint &)),
1012             this,
1013             SLOT(treeContextMenu(const QPoint &)),
1014             Qt::UniqueConnection );
1015 }
1016
1017 void HEXABLOCKGUI::createActions()
1018 {
1019     QMainWindow *aParent = application()->desktop();
1020     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1021
1022     // Document
1023     _newAct = createAction(_menuId++,
1024             tr("Create a new document"),
1025             resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
1026             tr("New Document"),
1027             tr("Create a new document"),
1028             0, aParent, false, this, SLOT(newDocument()));
1029     _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1030
1031     _importAct = createAction(_menuId++,
1032             tr("Load a document"),
1033             resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
1034             tr("Load Document"),
1035             tr("Load a document"),
1036             0, aParent, false, this, SLOT(loadDocument()));
1037     _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
1038
1039     _saveAct = createAction(_menuId++,
1040             tr("Save the document"),
1041             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
1042             tr("Save Document"),
1043             tr("Save the document"),
1044             0, aParent, false, this, SLOT(saveDocument()));
1045
1046     // Pattern Data creation
1047     _addVertex = createAction(_menuId++,
1048             tr("Create a vertex"),
1049             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
1050             tr("Add Vertex"),
1051             tr("Create a new vertex"),
1052             0, aParent, false, this, SLOT(addVertex()));
1053
1054     _addEdge = createAction(_menuId++,
1055             tr("Create an edge"),
1056             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
1057             tr("Add Edge"),
1058             tr("Create a new edge"),
1059             0, aParent, false, this, SLOT(addEdge()));
1060
1061     _addQuad = createAction(_menuId++,
1062             tr("Create a quadrangle"),
1063             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1064             tr("Add Quadrangle"),
1065             tr("Create a new quadrangle"),
1066             0, aParent, false, this, SLOT(addQuad()));
1067
1068     _addHexa = createAction(_menuId++,
1069             tr("Create an hexahedron"),
1070             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1071             tr("Add Hexahedron"),
1072             tr("Create a new hexahedron"),
1073             0, aParent, false, this, SLOT(addHexa()));
1074
1075     // Builder Data creation
1076     _addVector = createAction(_menuId++,
1077             tr("Create a vector"),
1078             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1079             tr("Add Vector"),
1080             tr("Create a new vector"),
1081             0, aParent, false, this, SLOT(addVector()));
1082
1083 //    _addCylinder = createAction(_menuId++,
1084 //            tr("Create a cylinder"),
1085 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1086 //            tr("Add Cylinder"),
1087 //            tr("Create a new cylinder"),
1088 //            0, aParent, false, this,  SLOT(addCylinder()));
1089
1090 //    _addPipe = createAction(_menuId++,
1091 //            tr("Create a pipe"),
1092 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1093 //            tr("Add Pipe"),
1094 //            tr("Create a new pipe"),
1095 //            0, aParent, false, this, SLOT(addPipe()));
1096
1097     _makeGrid = createAction(_menuId++,
1098             tr("Make a grid"),
1099             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1100             tr("Make Grid"),
1101             tr("Make a grid"),
1102             0, aParent, false, this,  SLOT(makeGrid()));
1103
1104     _makeCylinder = createAction(_menuId++,
1105             tr("Make a cylinder"),
1106             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1107             tr("Make Cylinder"),
1108             tr("Make a cylinder"),
1109             0, aParent, false, this, SLOT(makeCylinder()));
1110
1111     _makePipe = createAction(_menuId++,
1112             tr("Make a pipe"),
1113             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1114             tr("Make Pipe"),
1115             tr("Make a pipe"),
1116             0, aParent, false, this, SLOT(makePipe()));
1117
1118     _makeCylinders = createAction(_menuId++,
1119             tr("Make cylinders"),
1120             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1121             tr("Make Cylinders"),
1122             tr("Make cylinders"),
1123             0, aParent, false, this, SLOT(makeCylinders()));
1124
1125     _makePipes = createAction(_menuId++,
1126             tr("Make pipes"),
1127             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1128             tr("Make Pipes"),
1129             tr("Make pipes"),
1130             0, aParent, false, this, SLOT(makePipes()));
1131
1132     _makeHemiSphere = createAction(_menuId++,
1133             tr("Make an hemisphere"),
1134             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1135             tr("Make Hemisphere"),
1136             tr("Make an hemisphere"),
1137             0, aParent, false, this, SLOT(makeHemiSphere()));
1138
1139     // Pattern Data edition
1140     _removeHexa = createAction(_menuId++,
1141             tr("Remove hexahedra"),
1142             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1143             tr("Remove Hexahedra"),
1144             tr("Remove hexahedra"),
1145             0, aParent, false, this, SLOT(removeHexa()));
1146
1147     _prismQuad = createAction(_menuId++,
1148             tr("Prism quadrangles"),
1149             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1150             tr("Prism Quadrangles"),
1151             tr("Prism quadrangles"),
1152             0, aParent, false, this, SLOT(prismQuad()));
1153
1154     _joinQuad = createAction(_menuId++,
1155             tr("Join quadrangles"),
1156             resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1157             tr("Join Quadrangles"),
1158             tr("Join quadrangles with hexahedra"),
1159             0, aParent, false, this, SLOT(joinQuad()));
1160
1161     _merge = createAction(_menuId++,
1162             tr("Merge"),
1163             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1164             tr("Merge"),
1165             tr("Merge"),
1166             0, aParent, false, this, SLOT(merge()));
1167
1168     _disconnect = createAction(_menuId++,
1169             tr("Disconnect"),
1170             resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1171             tr("Disconnect"),
1172             tr("Disconnect edges, vertexes or quadrangles"),
1173             0, aParent, false, this, SLOT(disconnectElts()));
1174
1175     _cutEdge = createAction(_menuId++,
1176             tr("Cut edge"),
1177             resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1178             tr("Cut Edge"),
1179             tr("Cut edge"),
1180             0, aParent, false, this, SLOT(cutEdge()));
1181
1182     _makeTransformation = createAction(_menuId++,
1183             tr("Make transformation"),
1184             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1185             tr("Make Transformation"),
1186             tr("Make transformation"),
1187             0, aParent, false, this, SLOT(makeTransformation()));
1188
1189     _makeSymmetry = createAction(_menuId++,
1190             tr("Make symmetry"),
1191             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1192             tr("Make Symmetry"),
1193             tr("Make symmetry"),
1194             0, aParent, false, this, SLOT(makeSymmetry()));
1195
1196     _performTransformation = createAction(_menuId++,
1197             tr("Perform transformation"),
1198             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1199             tr("Perform Transformation"),
1200             tr("Perform transformation"),
1201             0, aParent, false, this, SLOT(performTransformation()));
1202
1203     _performSymmetry = createAction(_menuId++,
1204             tr("Perform symmetry"),
1205             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1206             tr("Perform Symmetry"),
1207             tr("Perform symmetry"),
1208             0, aParent, false, this, SLOT(performSymmetry()));
1209
1210     _replaceHexa = createAction(_menuId++,
1211             tr("Replace hexahedron"),
1212             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1213             tr("Replace Hexahedron"),
1214             tr("Replace hexahedron"),
1215             0, aParent, false, this, SLOT(replaceHexa()));
1216
1217     _quadRevolution = createAction(_menuId++,
1218             tr("Quad revolution"),
1219             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1220             tr("Quad Revolution"),
1221             tr("Quad revolution"),
1222             0, aParent, false, this, SLOT(quadRevolution()));
1223
1224     // Association
1225     _assocVertex = createAction(_menuId++,
1226             tr("Make vertex association"),
1227             resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1228             tr("Make Vertex association"),
1229             tr("Make vertex association"),
1230             0, aParent, false, this, SLOT(assocVertex()));
1231
1232     _assocEdge = createAction(_menuId++,
1233             tr("Make edge association"),
1234             resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1235             tr("Make Edge Association"),
1236             tr("Make edge association"),
1237             0, aParent, false, this, SLOT(assocEdge()));
1238
1239     _assocQuad = createAction(_menuId++,
1240             tr("Make quad association"),
1241             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1242             tr("Make Quad Association"),
1243             tr("Make quad association"),
1244             0, aParent, false, this, SLOT(assocQuad()));
1245
1246     // Group
1247     _addGroup = createAction(_menuId++,
1248             tr("Add a group"),
1249             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1250             tr("Add Group"),
1251             tr("Add a group"),
1252             0, aParent, false, this, SLOT(addGroup()));
1253
1254     _removeGroup = createAction(_menuId++,
1255             tr("Remove a group"),
1256             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1257             tr("Remove Group"),
1258             tr("Remove a group"),
1259             0, aParent, false, this, SLOT(removeGroup()));
1260
1261     // Mesh
1262     _addLaw = createAction(_menuId++,
1263             tr("Add a law"),
1264             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1265             tr("Add Law"),
1266             tr("Add a law"),
1267             0, aParent, false, this, SLOT(addLaw()));
1268
1269     _removeLaw = createAction(_menuId++,
1270             tr("Remove a law"),
1271             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1272             tr("Remove Law"),
1273             tr("Remove a law"),
1274             0, aParent, false, this, SLOT(removeLaw()));
1275
1276     _setPropagation = createAction(_menuId++,
1277             tr("Set propagation"),
1278             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1279             tr("Set Propagation"),
1280             tr("Set propagation"),
1281             0, aParent, false, this, SLOT(setPropagation()));
1282
1283     _computeMesh = createAction(_menuId++,
1284             tr("Compute mesh"),
1285             resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1286             tr("Compute Mesh"),
1287             tr("Compute mesh"),
1288             0, aParent, false, this, SLOT(computeMesh()));
1289
1290     _showModelInfoAct = createAction(_menuId++,
1291             tr("Show Model Info"),
1292             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MODEL_INFO")),
1293             tr("MODEL_INFO"),
1294             tr("MODEL_INFO"),
1295             0, aParent, false, this, SLOT(showModelInfo()));
1296
1297     _addShapeAct = createAction(_menuId++,
1298             tr("Add Shape"),
1299             resMgr->loadPixmap("HEXABLOCK", tr("ICON_GEOM_ASSOCIATION")),
1300             tr("ADD_SHAPE"),
1301             tr("ADD_SHAPE"),
1302             0, aParent, false, this, SLOT(addShape()));
1303
1304 //   _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1305 //   QAction* createAction(const int id,
1306 //                         const QString& toolTip,
1307 //                         const QIcon& icon,
1308 //                         const QString& menu,
1309 //                         const QString& status,
1310 //                         const int shortCut,
1311 //                         QObject* parent =0,
1312 //                         bool checkable = false,
1313 //                         QObject* receiver =0,
1314 //                         const char* member =0);
1315
1316     _sep1 =  separator();
1317     _sep2 =  separator();
1318     _sep3 =  separator();
1319     _sep4 =  separator();
1320 }
1321
1322
1323 void HEXABLOCKGUI::createMenus()
1324 {
1325     int aMenuId, subMenuId,aMenuIdMain;
1326
1327     aMenuIdMain = createMenu( tr("MEN_FILE"), -1, -1);
1328
1329     aMenuId = createMenu( tr("HEXABLOCK"), aMenuIdMain, -1, 10 );
1330     createMenu( actionId(_newAct), aMenuId );
1331     createMenu( actionId(_importAct), aMenuId );
1332     createMenu( _saveAct, aMenuId );
1333
1334
1335     int aMenuDocId = createMenu( tr( "Document" ), -1, -1, 30 );
1336     createMenu( _newAct, aMenuDocId );//, 10
1337     createMenu( _importAct, aMenuDocId );
1338     createMenu( _saveAct, aMenuDocId );
1339
1340     aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1341     subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1342     createMenu( _addVertex, subMenuId );
1343     createMenu( _addEdge,   subMenuId );
1344     createMenu( _addQuad,   subMenuId );
1345     createMenu( _addHexa,   subMenuId );
1346     createMenu( _sep1, subMenuId);
1347
1348     // Pattern Builder
1349     createMenu( _addVector, subMenuId );
1350 //    createMenu( _addCylinder, subMenuId );
1351 //    createMenu( _addPipe, subMenuId );
1352
1353     createMenu( _sep2, subMenuId);
1354
1355     createMenu( _makeGrid,  subMenuId ); //Cartesian, Cylindrical, Spherical
1356     createMenu( _makeHemiSphere,subMenuId );
1357
1358     createMenu( _sep3, subMenuId);
1359
1360     createMenu( _makeCylinder, subMenuId );
1361     createMenu( _makePipe,     subMenuId );
1362     createMenu( _makeCylinders,subMenuId );
1363     createMenu( _makePipes,    subMenuId );
1364
1365     // Pattern Data Edition
1366     subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1367     createMenu( _removeHexa, subMenuId );
1368     createMenu( _prismQuad,  subMenuId );
1369     createMenu( _joinQuad,   subMenuId );
1370     createMenu( _merge,      subMenuId );
1371     createMenu( _disconnect, subMenuId );
1372     createMenu( _cutEdge,    subMenuId );
1373     createMenu( _makeTransformation, subMenuId );
1374     createMenu( _makeSymmetry,       subMenuId );
1375     createMenu( _performTransformation,   subMenuId );
1376     createMenu( _performSymmetry,         subMenuId );
1377     createMenu( _replaceHexa,    subMenuId );
1378     createMenu( _quadRevolution, subMenuId );
1379     createMenu( _sep4, aMenuId );
1380     createMenu( _showModelInfoAct, aMenuId );
1381
1382     // Association
1383     aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1384     createMenu( _addShapeAct, aMenuId );
1385     createMenu( _assocVertex, aMenuId );
1386     createMenu( _assocEdge,   aMenuId );
1387     createMenu( _assocQuad,   aMenuId );
1388
1389     // Group
1390     aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1391     createMenu( _addGroup,    aMenuId );
1392     createMenu( _removeGroup, aMenuId ); //CS_TODO
1393
1394     // Law
1395     aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1396     createMenu( _addLaw,    aMenuId );
1397     createMenu( _removeLaw, aMenuId );
1398     createMenu( _setPropagation, aMenuId );
1399     createMenu( _computeMesh, aMenuId );
1400
1401     //show model infomation menu
1402     QString aRule = "$component={'HEXABLOCK'}";
1403     popupMgr()->insert( _showModelInfoAct, -1, -1 );
1404     popupMgr()->setRule( _showModelInfoAct, aRule);
1405
1406     //associate shape to a document menu
1407     popupMgr()->insert( _addShapeAct, -1, -1 );
1408     popupMgr()->setRule( _addShapeAct, aRule );
1409
1410     //-------------------------------------------------
1411     // Display / Erase
1412     //-------------------------------------------------
1413     //  QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
1414     //  QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
1415     //  QString isNotEmpty("numberOfNodes <> 0");
1416     //  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
1417     //  QString aType = QString( "%1type in {%2}" ).arg( lc );
1418     ////  aType = aType.arg( mesh_part );
1419     //
1420     //  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
1421     //  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
1422     //  QString aSelCount = QString( "%1 > 0" ).arg( dc );
1423
1424 //    popupMgr()->insert( separator(), -1, -1 );
1425 //    QString aRule = "$component={'HEXABLOCK'}";/* and  ( type='(" + aClient + " and " +
1426 //                aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";*/
1427 //    //  MESSAGE("aClient = " << aClient.toStdString());
1428 //    //  MESSAGE("aType = " << aType.toStdString());
1429 //    //  MESSAGE("aSelCount = " << aSelCount.toStdString());
1430 //    //  MESSAGE("anActiveVTK = " << anActiveVTK.toStdString());
1431 //    //  MESSAGE("isNotEmpty = " << isNotEmpty.toStdString());
1432 //    //  MESSAGE("aRule = " << aRule.toStdString());
1433 //    popupMgr()->insert( _showAct, -1, -1 ); // DISPLAY
1434 //    popupMgr()->setRule( _showAct, aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
1435 //
1436 //    popupMgr()->insert( _hideAct, -1, -1 ); // ERASE
1437 //    popupMgr()->setRule( _hideAct, aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
1438 //
1439 //    popupMgr()->insert( _showOnlyAct, -1, -1 ); // DISPLAY_ONLY
1440 //    popupMgr()->setRule(_showOnlyAct, aRule.arg( "" ), QtxPopupMgr::VisibleRule );
1441 //
1442 //    popupMgr()->insert( separator(), -1, -1 );
1443 }
1444
1445
1446 void HEXABLOCKGUI::createTools()
1447 {
1448     int aToolId;
1449
1450     aToolId = createTool ( tr( "HexaBlock Toolbar" ), QString( "HexaBlockMain" ) );
1451     createTool( _newAct, aToolId );
1452     createTool( _importAct, aToolId );
1453     createTool( _saveAct, aToolId );
1454     createTool( _showModelInfoAct, aToolId );
1455     //   createTool( _testAct, aToolId );
1456     //createTool( separator(), aToolId );
1457
1458     // Pattern Data
1459     aToolId = createTool ( tr( "Construction" ), QString( "HexaBlockConstruction" ) );
1460     createTool( _addVertex, aToolId );
1461     createTool( _addEdge, aToolId );
1462     createTool( _addQuad, aToolId );
1463     createTool( _addHexa, aToolId );
1464
1465     createTool( _sep1, aToolId );
1466
1467     // Pattern Builder
1468     createTool( _addVector, aToolId );
1469 //    createTool( _addCylinder, aToolId );
1470 //    createTool( _addPipe, aToolId );
1471
1472     createTool( _sep2, aToolId );
1473
1474     createTool( _makeGrid,  aToolId );
1475     createTool( _makeHemiSphere,   aToolId );
1476
1477     createTool( _sep3, aToolId );
1478
1479     createTool( _makeCylinder, aToolId );
1480     createTool( _makePipe,     aToolId );
1481     createTool( _makeCylinders,aToolId );
1482     createTool( _makePipes,    aToolId );
1483
1484     // Pattern Data Edition
1485     aToolId = createTool ( tr( "Operation" ), QString( "HexaBlockOperation" ) );
1486     createTool( _removeHexa, aToolId );
1487     createTool( _prismQuad,  aToolId );
1488     createTool( _joinQuad,   aToolId );
1489     createTool( _merge,      aToolId );
1490     createTool( _disconnect, aToolId );
1491     createTool( _cutEdge,    aToolId );
1492     createTool( _makeTransformation, aToolId );
1493     createTool( _makeSymmetry,       aToolId );
1494     createTool( _performTransformation,   aToolId );
1495     createTool( _performSymmetry,         aToolId );
1496     createTool( _replaceHexa,    aToolId );
1497     createTool( _quadRevolution, aToolId );
1498
1499     // Association
1500     aToolId = createTool ( tr( "Association" ), QString( "HexaBlockAssociation" ) );
1501     createTool( _assocVertex, aToolId );
1502     createTool( _assocEdge, aToolId );
1503     createTool( _assocQuad, aToolId );
1504     createTool( _addShapeAct, aToolId );
1505
1506     // Group
1507     aToolId = createTool ( tr( "Group" ), QString( "HexaBlockGroup" ) );
1508     createTool( _addGroup,    aToolId );
1509     createTool( _removeGroup, aToolId ); //CS_TODO
1510
1511     // Law
1512     aToolId = createTool ( tr( "Mesh" ), QString( "HexaBlockMesh" ) );
1513     createTool( _addLaw,    aToolId );
1514     createTool( _removeLaw, aToolId );
1515     createTool( _setPropagation, aToolId );
1516     createTool( _computeMesh, aToolId );
1517
1518 }
1519
1520 void HEXABLOCKGUI::initialMenus()
1521 {
1522     showDocumentMenus( true );
1523     showPatternMenus( false );
1524     showAssociationMenus( false );
1525     showGroupsMenus( false );
1526     showMeshMenus( false );
1527 }
1528
1529 void HEXABLOCKGUI::showAllMenus()
1530 {
1531     showDocumentMenus( true );
1532     showPatternMenus( true );
1533     showAssociationMenus( true );
1534     showGroupsMenus( true );
1535     showMeshMenus( true );
1536 }
1537
1538 void HEXABLOCKGUI::setAllMenusEnabled(bool enable)
1539 {
1540     enableDocumentMenus( enable );
1541     enablePatternMenus( enable );
1542     enableAssociationMenus( enable );
1543     enableGroupsMenus( enable );
1544     enableMeshMenus( enable );
1545
1546     menusEnabled = enable;
1547 }
1548
1549 void HEXABLOCKGUI::showDocumentMenus(bool show)
1550 {
1551     DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1552     show = true; //
1553     setMenuShown(_newAct, show);
1554     setToolShown(_newAct, show);
1555     setMenuShown(_importAct, show);
1556     setToolShown(_importAct, show);
1557     setMenuShown(_showModelInfoAct, show);
1558     setToolShown(_showModelInfoAct, show);
1559     setMenuShown(_saveAct, show);
1560     setToolShown(_saveAct, show);
1561 }
1562
1563 void HEXABLOCKGUI::enableDocumentMenus(bool enable)
1564 {
1565     _newAct->setEnabled(enable);
1566 //    setToolShown(_newAct, enable);
1567
1568     _importAct->setEnabled(enable);
1569 //    setToolShown(_importAct, enable);
1570
1571     _showModelInfoAct->setEnabled(enable);
1572 //    setToolShown(_showModelInfoAct, enable);
1573
1574     _saveAct->setEnabled(enable);
1575 //    setToolShown(_saveAct, enable);
1576 }
1577
1578
1579 void HEXABLOCKGUI::showPatternMenus(bool show)
1580 {
1581     DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1582     DEBTRACE("getCurrentModel()  " << getCurrentModel()  );
1583     if ( show && !getCurrentModel() ) return;
1584
1585     setMenuShown(_addVertex, show );
1586     setToolShown(_addVertex, show);
1587     setMenuShown(_addEdge,  show );
1588     setToolShown(_addEdge, show);
1589     setMenuShown(_addQuad,  show );
1590     setToolShown(_addQuad, show);
1591     setMenuShown(_addHexa,  show );
1592     setToolShown(_addHexa, show);
1593
1594     setMenuShown(_sep1, show );
1595     setToolShown(_sep1, show);
1596
1597     setMenuShown( _addVector,  show );
1598     setToolShown( _addVector, show);
1599 //    setMenuShown( _addCylinder,  show );
1600 //    setToolShown( _addCylinder, show);
1601 //    setMenuShown( _addPipe,  show );
1602 //    setToolShown( _addPipe, show);
1603
1604     setMenuShown(_sep2, show );
1605     setToolShown(_sep2, show);
1606
1607     setMenuShown( _makeGrid,  show );
1608     setToolShown( _makeGrid, show);
1609     setMenuShown( _makePipe,  show );
1610     setToolShown( _makePipe, show);
1611
1612     setMenuShown(_sep3, show );
1613     setToolShown(_sep3, show);
1614
1615     setMenuShown( _makeCylinder,  show );
1616     setToolShown( _makeCylinder, show);
1617     setMenuShown( _makeCylinders,  show );
1618     setToolShown( _makeCylinders, show);
1619     setMenuShown( _makePipes,  show );
1620     setToolShown( _makePipes, show);
1621     setMenuShown( _makeHemiSphere,  show );
1622     setToolShown( _makeHemiSphere, show);
1623
1624     // Pattern Data Edition
1625     setMenuShown( _removeHexa,  show );
1626     setToolShown( _removeHexa, show);
1627     setMenuShown( _prismQuad,  show );
1628     setToolShown( _prismQuad, show);
1629     setMenuShown( _joinQuad,  show );
1630     setToolShown( _joinQuad, show);
1631     setMenuShown( _merge,  show );
1632     setToolShown( _merge, show);
1633     setMenuShown( _disconnect,  show );
1634     setToolShown( _disconnect, show);
1635     setMenuShown( _cutEdge,  show );
1636     setToolShown( _cutEdge, show);
1637     setMenuShown( _makeTransformation,  show );
1638     setToolShown( _makeTransformation, show);
1639     setMenuShown( _makeSymmetry,  show );
1640     setToolShown( _makeSymmetry, show);
1641     setMenuShown( _performTransformation,  show );
1642     setToolShown( _performTransformation, show);
1643     setMenuShown( _performSymmetry,  show );
1644     setToolShown( _performSymmetry, show);
1645     setMenuShown( _replaceHexa,  show );
1646     setToolShown( _replaceHexa, show);
1647     setMenuShown( _quadRevolution,  show );
1648     setToolShown( _quadRevolution, show);
1649
1650     setMenuShown( _sep4, show );
1651     setMenuShown( _showModelInfoAct, show );
1652 }
1653
1654 void HEXABLOCKGUI::enablePatternMenus(bool enable)
1655 {
1656     if ( enable && !getCurrentModel() ) return;
1657
1658     _addVertex->setEnabled(enable);
1659 //    setToolShown(_addVertex, enable);
1660
1661     _addEdge->setEnabled(enable);
1662 //    setToolShown(_addEdge, enable);
1663
1664     _addQuad->setEnabled(enable);
1665 //    setToolShown(_addQuad, enable);
1666
1667     _addHexa->setEnabled(enable);
1668 //    setToolShown(_addHexa, enable);
1669
1670 //    setMenuShown(_sep1, enable );
1671 //    setToolShown(_sep1, enable);
1672
1673     _addVector->setEnabled(enable);
1674 //    setToolShown( _addVector, enable);
1675
1676 //    setMenuShown(_sep2, enable );
1677 //    setToolShown(_sep2, enable);
1678
1679     _makeGrid->setEnabled(enable);
1680 //    setToolShown( _makeGrid, enable);
1681
1682     _makePipe->setEnabled(enable);
1683 //    setToolShown( _makePipe, enable);
1684
1685 //    setMenuShown(_sep3, enable );
1686 //    setToolShown(_sep3, enable);
1687
1688     _makeCylinder->setEnabled(enable);
1689 //    setToolShown( _makeCylinder, enable);
1690
1691     _makeCylinders->setEnabled(enable);
1692 //    setToolShown( _makeCylinders, enable);
1693
1694     _makePipes->setEnabled(enable);
1695 //    setToolShown( _makePipes, enable);
1696
1697     _makeHemiSphere->setEnabled(enable);
1698 //    setToolShown( _makeHemiSphere, enable);
1699
1700     // Pattern Data Edition
1701     _removeHexa->setEnabled(enable);
1702 //    setToolShown( _removeHexa, enable);
1703
1704     _prismQuad->setEnabled(enable);
1705 //    setToolShown( _prismQuad, enable);
1706
1707     _joinQuad->setEnabled(enable);
1708 //    setToolShown( _joinQuad, enable);
1709
1710     _merge->setEnabled(enable);
1711 //    setToolShown( _merge, enable);
1712
1713     _disconnect->setEnabled(enable);
1714 //    setToolShown( _disconnect, enable);
1715
1716     _cutEdge->setEnabled(enable);
1717 //    setToolShown( _cutEdge, enable);
1718
1719     _makeTransformation->setEnabled(enable);
1720 //    setToolShown( _makeTransformation, enable);
1721
1722     _makeSymmetry->setEnabled(enable);
1723 //    setToolShown( _makeSymmetry, enable);
1724
1725     _performTransformation->setEnabled(enable);
1726 //    setToolShown( _performTransformation, enable);
1727
1728     _performSymmetry->setEnabled(enable);
1729 //    setToolShown( _performSymmetry, enable);
1730
1731     _replaceHexa->setEnabled(enable);
1732 //    setToolShown( _replaceHexa, enable);
1733
1734     _quadRevolution->setEnabled(enable);
1735 //    setToolShown( _quadRevolution, enable);
1736
1737 //    setMenuShown( _sep4, enable );
1738     _showModelInfoAct->setEnabled(enable);
1739 }
1740
1741
1742 void HEXABLOCKGUI::showAssociationMenus(bool show)
1743 {
1744     DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1745     if ( show && !getCurrentModel() ) return;
1746
1747     // Association Edition
1748     setMenuShown( _assocVertex,  show );
1749     setToolShown( _assocVertex, show );
1750
1751     setMenuShown( _assocEdge,  show );
1752     setToolShown( _assocEdge, show );
1753
1754     setMenuShown( _assocQuad,  show );
1755     setToolShown( _assocQuad, show );
1756
1757     setMenuShown( _addShapeAct, show );
1758     setToolShown( _addShapeAct, show );
1759 }
1760
1761 void HEXABLOCKGUI::enableAssociationMenus(bool enable)
1762 {
1763     if ( enable && !getCurrentModel() )
1764         return;
1765
1766     // Association Edition
1767      _assocVertex->setEnabled(enable);
1768  //    setToolShown( _assocVertex, enable );
1769
1770      _assocEdge->setEnabled(enable);
1771  //    setToolShown( _assocEdge, enable );
1772
1773      _assocQuad->setEnabled(enable);
1774  //    setToolShown( _assocQuad, enable );
1775
1776      _addShapeAct->setEnabled(enable);
1777  //    setToolShown( _addShapeAct, enable );
1778 }
1779
1780 void HEXABLOCKGUI::showGroupsMenus(bool show)
1781 {
1782     DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1783     if ( show && !getCurrentModel() ) return;
1784     setMenuShown( _addGroup,  show );
1785     setToolShown( _addGroup, show);
1786     setMenuShown( _removeGroup ,  show );
1787     setToolShown( _removeGroup , show);
1788 }
1789
1790 void HEXABLOCKGUI::enableGroupsMenus(bool enable)
1791 {
1792     if ( enable && !getCurrentModel() )
1793         return;
1794
1795     _addGroup->setEnabled(enable);
1796 //    setToolShown( _addGroup, enable);
1797
1798     _removeGroup->setEnabled(enable);
1799 //    setToolShown( _removeGroup , enable);
1800 }
1801
1802 void HEXABLOCKGUI::showMeshMenus(bool show)
1803 {
1804     DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1805     if ( show && !getCurrentModel() ) return;
1806     setMenuShown( _addLaw,  show );
1807     setToolShown( _addLaw, show);
1808     setMenuShown( _removeLaw,  show );
1809     setToolShown( _removeLaw, show);;
1810     setMenuShown( _setPropagation,  show );
1811     setToolShown( _setPropagation, show);
1812     setMenuShown( _computeMesh, show);
1813     setToolShown( _computeMesh, show);
1814 }
1815
1816 void HEXABLOCKGUI::enableMeshMenus(bool enable)
1817 {
1818     if ( enable && !getCurrentModel() )
1819         return;
1820
1821     _addLaw->setEnabled(enable);
1822 //    setToolShown( _addLaw, enable);
1823
1824     _removeLaw->setEnabled(enable);
1825 //    setToolShown( _removeLaw, enable);
1826
1827     _setPropagation->setEnabled(enable);
1828 //    setToolShown( _setPropagation, enable);
1829
1830     _computeMesh->setEnabled(enable);
1831 //    setToolShown( _computeMesh, enable);
1832 }
1833
1834 void HEXABLOCKGUI::showVtkActor()
1835 {
1836     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1837     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1838             currentVtkGView->getDocumentActor() == NULL)
1839         return;
1840
1841     SVTK_ViewWindow* vtkView = currentVtkGView->getViewWindow();
1842     if (vtkView == NULL)
1843         return;
1844
1845     SUIT_ViewManager* vman = vtkView->getViewManager();
1846     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1847
1848     //show only the current actor -----------------
1849     vtkView->setFocus();
1850     //    vtkView->DisplayOnly(currentVtkGView->getDocumentActor()->getIO());
1851     Document_Actor *lastDocActor;
1852     if (lastVtkDocGView != NULL)
1853     {
1854         lastDocActor = lastVtkDocGView->getDocumentActor();
1855         Handle(SALOME_InteractiveObject) lastActorIO = lastDocActor->getIO();
1856         if (!lastActorIO.IsNull() && lastActorIO->hasEntry())
1857         {
1858             vtkView->Erase(lastActorIO);
1859             aStudy->setObjectProperty(vman->getId(), lastActorIO->getEntry(),  "Visibility", 0 );
1860             displayer()->setVisibilityState(lastActorIO->getEntry(), Qtx::HiddenState);
1861         }
1862     }
1863     currentVtkGView->update();
1864     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1865     if (!anIO.IsNull() && anIO->hasEntry())
1866     {
1867         vtkView->Display(anIO);
1868         aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 1 );
1869         displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1870     }
1871     vtkView->onFitAll();
1872 }
1873
1874 void HEXABLOCKGUI::showOccActor()
1875 {
1876     if (currentOccGView == NULL)
1877         return;
1878     OCCViewer_ViewWindow* occView = currentOccGView->getViewWindow();
1879     if (occView == NULL)
1880         return;
1881     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1882     if (vf == NULL)
1883         return;
1884
1885     if (lastOccPrs != NULL)
1886         vf->Erase(lastOccPrs);
1887     currentOccGView->globalSelection();
1888     SOCC_Prs* prs = getOccPrs(currentDocGView);
1889     currentOccGView->setPrs(prs);
1890     vf->Display(prs);
1891     vf->Repaint();
1892     occView->onFitAll();
1893 }
1894
1895 void HEXABLOCKGUI::hideVtkActor()
1896 {
1897     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1898     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1899         currentVtkGView->getViewWindow() == NULL ||
1900         currentVtkGView->getDocumentActor() == NULL) return;
1901
1902     currentVtkGView->getViewWindow()->Erase(currentVtkGView->getDocumentActor()->getIO());
1903     currentVtkGView->getViewWindow()->onResetView();
1904
1905     //update the visibility state now
1906     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1907     SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1908     if (aStudy == NULL || vman == NULL) return;
1909
1910     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1911     aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 0 );
1912     displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1913 }
1914
1915 void HEXABLOCKGUI::hideOccActor()
1916 {
1917     OCCViewer_ViewWindow* occView = currentOccGView == NULL ? NULL : currentOccGView->getViewWindow();
1918     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1919     DocumentModel* docModel = (currentVtkGView == NULL ? NULL : currentVtkGView->getDocumentModel());
1920     if (occView == NULL || docModel == NULL)
1921         return;
1922     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1923     if (vf == NULL)
1924         return;
1925
1926     SOCC_Prs* currentOccPrs = getOccPrs(currentDocGView);
1927     if (currentOccPrs != NULL)
1928         vf->Erase(currentOccPrs);
1929     vf->Repaint();
1930     occView->onResetView();
1931 }
1932
1933 void HEXABLOCKGUI::showOnlyActor()
1934 {
1935     showVtkActor();
1936     showOccActor();
1937 }
1938
1939 void HEXABLOCKGUI::hideActor()
1940 {
1941     hideVtkActor();
1942     hideOccActor();
1943 }
1944
1945
1946 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1947 {
1948     DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1949
1950     if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1951
1952     if (_dwPattern) _dwPattern->setVisible(isVisible);
1953     if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1954
1955     if (_dwMesh) _dwMesh->setVisible(isVisible);
1956     if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1957
1958     if (_dwGroups) _dwGroups->setVisible(isVisible);
1959     if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1960 }
1961
1962
1963 //clear all used dialogs by the current model
1964 void HEXABLOCKGUI::clearDialogs()
1965 {
1966     std::set<HexaBaseDialog*>::const_iterator debut (currentModelDialogs.begin()),
1967                                               fin   (currentModelDialogs.end());
1968     for(;debut!=fin;++debut) (*debut)->clear();
1969
1970     currentModelDialogs.clear(); //empty the used dialogs list
1971 }
1972
1973 HexaBaseDialog* HEXABLOCKGUI::getDlgBox(VtkDocumentGraphicView* dgview)
1974 {
1975     if (!gViewDlgBox.contains(dgview)) return NULL;
1976     return gViewDlgBox[dgview];
1977 }
1978
1979 void HEXABLOCKGUI::switchOnGraphicView(VtkDocumentGraphicView* dgview)
1980 {
1981    if (dgview == NULL) return;
1982
1983    switchOffGraphicView(dgview, false); //to avoid double connect
1984
1985    //connect signals
1986    connect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
1987          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ), Qt::UniqueConnection );
1988    connect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1989          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1990 //   connect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1991 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1992    connect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1993             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1994    connect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1995          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1996    connect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1997          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1998
1999    showAllMenus();
2000 }
2001
2002 void HEXABLOCKGUI::switchOffGraphicView(VtkDocumentGraphicView* dgview, bool saveCurrentDlg)
2003 {
2004    if (dgview == NULL) return;
2005
2006    //disconnect signals
2007    disconnect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2008          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ) );
2009    disconnect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2010          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2011 //   disconnect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2012 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2013    disconnect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2014             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2015    disconnect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2016          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2017    disconnect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2018          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2019
2020    if (saveCurrentDlg)
2021        gViewDlgBox[dgview] = currentDialog;
2022
2023    //close opened dialog
2024    if (currentDialog != NULL) currentDialog->close();
2025 //   if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2026
2027    initialMenus();
2028
2029 }
2030
2031 void HEXABLOCKGUI::switchModel(VtkDocumentGraphicView* dgview)
2032 {
2033     DEBTRACE("HEXABLOCKGUI::switchModel " << dgview);
2034
2035     if (dgview == NULL)
2036     {
2037         MESSAGE("HEXABLOCKGUI::switchModel : no need to switch!");
2038         return;
2039     }
2040
2041     //switch off the current document graphic view (disconnect signals...)
2042     if (currentDocGView != NULL)
2043     {
2044         //Hide current actor
2045         hideActor();
2046         switchOffGraphicView(currentDocGView);
2047     }
2048
2049     //clear the dialogs used by the current model so they can be used by the new model
2050     if (currentDocGView != dgview) clearDialogs();
2051
2052     _patternDataTreeView->setModel(dgview->getPatternDataModel());
2053 //    _patternBuilderTreeView->setModel(dgview->getPatternBuilderModel());
2054     _patternGeomTreeView->setModel(dgview->getPatternGeomModel());
2055     _groupsTreeView->setModel(dgview->getGroupsModel());
2056     _meshTreeView->setModel(dgview->getMeshModel());
2057
2058     _patternDataTreeView->setSelectionModel(dgview->getPatternDataSelectionModel());
2059     _patternDataTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2060
2061 //    _patternBuilderTreeView->setSelectionModel(dgview->getPatternBuilderSelectionModel());
2062 //    _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2063
2064     _patternGeomTreeView->setSelectionModel(dgview->getPatternGeomSelectionModel());
2065     _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2066
2067     _groupsTreeView->setSelectionModel(dgview->getGroupsSelectionModel());
2068     _groupsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2069
2070     _meshTreeView->setSelectionModel(dgview->getMeshSelectionModel());
2071     _meshTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2072
2073
2074     // = * init occ view * =
2075     if (currentOccGView != NULL && currentOccGView->getViewWindow() == NULL)
2076     {
2077         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2078         currentOccGView->getViewWindow()->installEventFilter(this);
2079     }
2080     // ==
2081
2082
2083     // = * init vtk view * =
2084     if (currentDocGView != NULL)
2085     {
2086         if (currentDocGView->getViewWindow() != NULL)
2087             dgview->setViewWindow(currentDocGView->getViewWindow());
2088         else
2089         {
2090             dgview->setViewWindow(graphicViewsHandler->createVtkWindow());
2091             dgview->getViewWindow()->installEventFilter(this);
2092         }
2093     }
2094
2095     // ==
2096
2097     switchOnGraphicView(dgview);
2098
2099     if (currentDocGView != NULL)
2100     {
2101         lastVtkDocGView = currentDocGView;
2102         lastOccPrs = getOccPrs(currentDocGView);
2103     }
2104     else
2105     {
2106         lastVtkDocGView = dgview;
2107         lastOccPrs = getOccPrs(dgview);
2108     }
2109
2110     currentDocGView = dgview;
2111     showOnlyActor();
2112     currentDocGView->getDocumentModel()->refresh();
2113 //    _dwPattern->setWindowTitle(currentDocGView->getDocumentModel()->getName());
2114     showAllMenus();
2115     if (!menusEnabled)
2116         setAllMenusEnabled(true);
2117 }
2118
2119 DocumentModel* HEXABLOCKGUI::getCurrentModel()
2120 {
2121     if (currentDocGView == NULL) return NULL;
2122     return currentDocGView->getDocumentModel();
2123 }
2124
2125
2126 HEXABLOCKGUI::ViewType HEXABLOCKGUI::getActiveViewType()
2127 {
2128     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2129     if (anApp == NULL) return UNKNOWN;
2130     SUIT_ViewManager* activeVm = anApp->activeViewManager();
2131     if (activeVm == NULL) return UNKNOWN;
2132
2133    QString vmType = activeVm->getType();
2134    if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
2135        return VTK;
2136    else if ( vmType == OCCViewer_Viewer::Type() )
2137        return OCC;
2138
2139    return UNKNOWN;
2140 }
2141
2142 HEXABLOCKGUI* HEXABLOCKGUI::getInstance()
2143 {
2144     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2145     if (anApp == NULL)
2146         return NULL;
2147
2148     return  dynamic_cast<HEXABLOCKGUI*>(anApp->activeModule());
2149 }
2150
2151 pair <QString, HEXA_NS::Document*> HEXABLOCKGUI::newHexaDocument()
2152 {
2153     // Create Document from HEXABLOCK ENGINE
2154     // WARNING : IN HEXABLOCK component,  GUI and ENGINE share the same process
2155     // HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default"); // Perime  Hexa6
2156
2157     // looking doc impl ( c++ )
2158     // ^Hexa6 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2159     // ^Hexa6 ASSERT( dServant );
2160     // ^Hexa6 if ( dServant)
2161         // ^Hexa6 doc = dServant->GetImpl();
2162
2163     HEXA_NS::Document* doc = hexa_root->addDocument ("default");
2164     QString docEntry = addDocInStudy (doc);
2165
2166     // looking for docEntry
2167     /* ****************************************************************
2168     if ( !CORBA::is_nil(docIn) ){
2169         CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2170         QString docIOR = anIOR.in();
2171         SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2172         if ( !docIOR.isEmpty() ) {
2173             _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2174             if ( SO )
2175                 docEntry = SO->GetID().c_str();
2176         }
2177     }
2178        **************************************************************** */
2179     DEBTRACE("HEXABLOCKGUI::newHexaDocument docEntry "<<docEntry.toStdString());
2180
2181     return make_pair (docEntry, doc);
2182 }
2183
2184
2185 void HEXABLOCKGUI::newDocument()
2186 {
2187     DEBTRACE("HEXABLOCKGUI::newDocument");
2188
2189     createSComponent();
2190     QMainWindow *aParent = application()->desktop();
2191     QWidget *central = aParent->centralWidget();
2192     if (central)
2193         central->setFocus();
2194     else
2195         DEBTRACE("No Central Widget");
2196
2197     //Init OCC
2198     if (currentOccGView == NULL)
2199     {
2200         currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
2201                 application()->desktop());
2202         currentOccGView->getViewWindow()->installEventFilter(this);
2203     }
2204     else if (currentOccGView->getViewWindow() == NULL)
2205     {
2206         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2207         currentOccGView->getViewWindow()->installEventFilter(this);
2208     }
2209
2210     //NEW DOCUMENT
2211     // Create Document from HEXABLOCK ENGINE
2212     pair <QString, HEXA_NS::Document*> docEntry_Doc ( newHexaDocument() );
2213
2214     VtkDocumentGraphicView* newGraphicView = NULL;
2215     //One document at a time
2216     if (currentDocGView != NULL)
2217     {
2218         if (currentDocGView->getViewWindow() == NULL)
2219         {
2220             currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2221             currentDocGView->getViewWindow()->installEventFilter(this);
2222         }
2223
2224           // Create a new document with the current window
2225           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2226                                         new DocumentModel( docEntry_Doc.second,
2227                                         docEntry_Doc.first, this ),
2228                                         currentDocGView->getViewWindow(),
2229                                         application()->desktop() );
2230     }
2231     else
2232     {
2233           // Create the new Document Graphic View with a new window
2234           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2235                                         new DocumentModel( docEntry_Doc.second,
2236                                         docEntry_Doc.first, this ),
2237                                         graphicViewsHandler->createVtkWindow(),
2238                                         application()->desktop() );
2239           newGraphicView->getViewWindow()->installEventFilter(this);
2240     }
2241
2242     if (newGraphicView == NULL)
2243         //We couldn't create a new document graphic view
2244         //we'd better show a dialog box info to inform the user
2245         return;
2246
2247     docs[docEntry_Doc.first] = newGraphicView;
2248     switchModel(newGraphicView); //select the corresponding document in the browser instead
2249
2250     getApp()->updateObjectBrowser();
2251     showAllMenus();
2252 }
2253
2254
2255 //Loads the model from the xmlFile in the current graphic view
2256 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2257 {
2258     DEBTRACE("HEXABLOCKGUI::loadDocument");
2259
2260     createSComponent();
2261     QMainWindow *aParent = application()->desktop();
2262     QString selectedFile;
2263
2264     if ( inFile.isNull() ){
2265         QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2266                 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2267         dialog.setHistory( getQuickDirList() );
2268
2269         //use the last path as default
2270         if (!(loadDocLastPath->absolutePath()).isEmpty())
2271             dialog.setDirectory(*loadDocLastPath);
2272
2273         if (dialog.exec()){
2274             QStringList selectedFiles = dialog.selectedFiles();
2275             if (!selectedFiles.isEmpty())
2276                 selectedFile = selectedFiles.first();
2277
2278             //remember the selected path
2279             *loadDocLastPath = dialog.directory();
2280         }
2281     } else
2282         selectedFile = inFile;
2283
2284     if (selectedFile.isEmpty())
2285         return;
2286
2287     //we create a new document if necessary
2288     if (currentDocGView == NULL)
2289         //Need a new document
2290         newDocument();
2291     else if (currentDocGView->getViewWindow() == NULL) //there's a document without a view
2292     {
2293         currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2294         currentDocGView->getViewWindow()->installEventFilter(this);
2295     }
2296
2297     if (!currentDocGView->isEmpty())
2298         //we can only have one document for a graphic view
2299         newDocument();
2300
2301     //we load the selected file in the current graphic view
2302     currentDocGView->loadDocument(selectedFile);
2303     DocumentModel* currentModel = getCurrentModel();
2304     renameObject( currentModel->documentEntry(), currentModel->getName() );
2305
2306     showOnlyActor();
2307 }
2308
2309 void HEXABLOCKGUI::saveDocument()
2310 {
2311     QMainWindow *aParent = application()->desktop();
2312
2313     QString aDocName = "document", aFilename;
2314     QStringList filter;
2315     filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2316     filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2317
2318     //use the last selected directory as default path for file selection
2319     aFilename =  saveDocLastPath->absolutePath();
2320     if (!aFilename.isEmpty())
2321         aFilename += QString("/") + aDocName;
2322
2323     //show the dialog for file selection
2324     aFilename = SUIT_FileDlg::getFileName( aParent,
2325             aFilename,
2326             filter,
2327             tr( "Save HexaBlock Document" ),
2328             false );
2329
2330     //save the document in the selected file
2331     if ( !aFilename.isEmpty() ) {
2332         getCurrentVtkGraphicView()->saveDocument( aFilename );
2333
2334         //Remember the path for next save
2335         QFileInfo fileInfo(aFilename);
2336         *saveDocLastPath = fileInfo.dir();
2337     }
2338     //CS_TODO save doc
2339 }
2340
2341
2342 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight)
2343 {
2344     _patternDataTreeView->openPersistentEditor( topLeft );
2345 }
2346
2347 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2348 {
2349     if (diag == NULL || _dwInputPanel == NULL ||
2350             getCurrentVtkGraphicView() == NULL) return;
2351
2352     //mark this dialog as used by the current model
2353     currentModelDialogs.insert(diag);
2354
2355     //close the current dialog box info
2356 //    if (_treeViewDelegate != NULL)
2357 //        _treeViewDelegate->closeDialog();
2358
2359 //    if (_dwInputPanel->widget())
2360 //        _dwInputPanel->widget()->close();
2361
2362     //Temporary for debugging EdgeAssoc Faked InfoDialog
2363     if (diag == _edgeAssocDiag)
2364         diag->debugEdgeAssoc = true;
2365     else
2366         diag->debugEdgeAssoc = false;
2367
2368     if (diag == _vertexAssocDiag || diag ==  _edgeAssocDiag ||
2369                 diag ==  _quadAssocDiag || diag == _addShapeDiag)
2370         assocInProgress = true;
2371     else
2372         assocInProgress = false;
2373
2374     //show the dialog box in the dockwidget
2375     diag->resetSizeAndShow(_dwInputPanel);
2376
2377     //clear the current selections
2378     selectionMgr()->clearSelected();
2379
2380     currentDialog = diag;
2381     diag->setFocus();
2382
2383     if (currentDocGView != NULL)
2384         currentDocGView->getPatternDataSelectionModel()->setInfoMode(false);
2385 }
2386
2387 void HEXABLOCKGUI::showVertexInfoDialog(HEXA_NS::Vertex* vertex)
2388 {
2389     if (vertex == NULL || _dwInputPanel == NULL)
2390         return;
2391
2392     if (_vertexInfoDialog == NULL)
2393         _vertexInfoDialog = new VertexDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2394
2395     _vertexInfoDialog->setValue(vertex);
2396     _vertexInfoDialog->resetSizeAndShow(_dwInputPanel);
2397     currentDialog = _vertexInfoDialog;
2398 }
2399
2400 void HEXABLOCKGUI::showEdgeInfoDialog(HEXA_NS::Edge* edge)
2401 {
2402     if (edge == NULL || _dwInputPanel == NULL)
2403         return;
2404
2405     if (_edgeInfoDialog == NULL)
2406         _edgeInfoDialog = new EdgeDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2407
2408     _edgeInfoDialog->setValue(edge);
2409     _edgeInfoDialog->resetSizeAndShow(_dwInputPanel);
2410     currentDialog = _edgeInfoDialog;
2411 }
2412
2413 void HEXABLOCKGUI::showQuadInfoDialog(HEXA_NS::Quad* quad)
2414 {
2415     if (quad == NULL || _dwInputPanel == NULL)
2416         return;
2417
2418     if (_quadInfoDialog == NULL)
2419         _quadInfoDialog = new QuadDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2420
2421     _quadInfoDialog->setValue(quad);
2422     _quadInfoDialog->resetSizeAndShow(_dwInputPanel);
2423     currentDialog = _quadInfoDialog;
2424 }
2425
2426 void HEXABLOCKGUI::showHexaInfoDialog(HEXA_NS::Hexa* hexa)
2427 {
2428     if (hexa == NULL || _dwInputPanel == NULL)
2429         return;
2430
2431     if (_hexaInfoDialog == NULL)
2432         _hexaInfoDialog = new HexaDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2433
2434     _hexaInfoDialog->setValue(hexa);
2435     _hexaInfoDialog->resetSizeAndShow(_dwInputPanel);
2436     currentDialog = _hexaInfoDialog;
2437 }
2438
2439 void HEXABLOCKGUI::showVectorInfoDialog(HEXA_NS::Vector* vector)
2440 {
2441     if (vector == NULL || _dwInputPanel == NULL)
2442         return;
2443
2444     if (_vectorInfoDialog == NULL)
2445         _vectorInfoDialog = new VectorDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2446
2447     _vectorInfoDialog->setValue(vector);
2448     _vectorInfoDialog->resetSizeAndShow(_dwInputPanel);
2449     currentDialog = _vectorInfoDialog;
2450 }
2451
2452 void HEXABLOCKGUI::showGroupInfoDialog(HEXA_NS::Group* group)
2453 {
2454     if (group == NULL || _dwInputPanel == NULL)
2455         return;
2456
2457     if (_groupInfoDialog == NULL)
2458         _groupInfoDialog = new GroupDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2459
2460     _groupInfoDialog->setValue(group);
2461     _groupInfoDialog->resetSizeAndShow(_dwInputPanel);
2462     currentDialog = _groupInfoDialog;
2463 }
2464
2465 void HEXABLOCKGUI::showLawInfoDialog(HEXA_NS::Law* law)
2466 {
2467     if (law == NULL || _dwInputPanel == NULL)
2468         return;
2469
2470     if (_lawInfoDialog == NULL)
2471         _lawInfoDialog = new LawDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2472
2473     _lawInfoDialog->setValue(law);
2474     _lawInfoDialog->resetSizeAndShow(_dwInputPanel);
2475     currentDialog = _lawInfoDialog;
2476 }
2477
2478 void HEXABLOCKGUI::showPropagationInfoDialog(HEXA_NS::Propagation* propagation)
2479 {
2480     if (propagation == NULL || _dwInputPanel == NULL)
2481         return;
2482
2483     if (_propagationInfoDialog == NULL)
2484         _propagationInfoDialog = new PropagationDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2485
2486     _propagationInfoDialog->setValue(propagation);
2487     _propagationInfoDialog->resetSizeAndShow(_dwInputPanel);
2488     currentDialog = _propagationInfoDialog;
2489 }
2490
2491 void HEXABLOCKGUI::addVertex()
2492 {
2493     if ( !_vertexDiag ){
2494         _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2495     }
2496     _showDialogBox( _vertexDiag );
2497
2498     //set default name
2499     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2500     if (_vertexDiag != NULL && doc != NULL)
2501         _vertexDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VERTEX).c_str());
2502 }
2503
2504 void HEXABLOCKGUI::addEdge()
2505 {
2506     if ( !_edgeDiag ){
2507         _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2508     }
2509     _showDialogBox( _edgeDiag );
2510
2511     //set default name
2512     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2513     if (_edgeDiag != NULL && doc != NULL)
2514         _edgeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_EDGE).c_str());
2515 }
2516
2517 void HEXABLOCKGUI::addQuad()
2518 {
2519     if ( !_quadDiag ){
2520         _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2521
2522     }
2523     _showDialogBox( _quadDiag );
2524
2525     //set default name
2526     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2527     if (_quadDiag != NULL && doc != NULL)
2528         _quadDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_QUAD).c_str());
2529 }
2530
2531 void HEXABLOCKGUI::addHexa()
2532 {
2533     if ( !_hexaDiag ){
2534         _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2535     }
2536     _showDialogBox( _hexaDiag );
2537
2538     //set default name
2539     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2540     if (_hexaDiag != NULL && doc != NULL)
2541         _hexaDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_HEXA).c_str());
2542 }
2543
2544 void HEXABLOCKGUI::addVector()
2545 {
2546     if ( !_vectorDiag ){
2547         _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2548     }
2549     _showDialogBox( _vectorDiag );
2550
2551     //set default name
2552     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2553     if (_vectorDiag != NULL && doc != NULL)
2554         _vectorDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VECTOR).c_str());
2555 }
2556
2557 //void HEXABLOCKGUI::addCylinder()
2558 //{
2559 //    if ( !_cylinderDiag ){
2560 //        _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2561 //    }
2562 //    _showDialogBox( _cylinderDiag );
2563 //
2564 //    //set default name
2565 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2566 //    if (_cylinderDiag != NULL && doc != NULL)
2567 //        _cylinderDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2568 //}
2569
2570
2571 //void HEXABLOCKGUI::addPipe()
2572 //{
2573 //    if ( !_pipeDiag){
2574 //        _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2575 //    }
2576 //    _showDialogBox( _pipeDiag );
2577 //
2578 //    //set default name
2579 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2580 //    if (_pipeDiag != NULL && doc != NULL)
2581 //        _pipeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2582 //}
2583
2584
2585 void HEXABLOCKGUI::makeGrid()
2586 {
2587     if ( !_makeGridDiag ){
2588         _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2589     }
2590     _showDialogBox( _makeGridDiag );
2591 }
2592
2593
2594 void HEXABLOCKGUI::makeCylinder()
2595 {
2596     if ( !_makeCylinderDiag ){
2597         _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2598     }
2599     _showDialogBox( _makeCylinderDiag );
2600 }
2601
2602 void HEXABLOCKGUI::makePipe()
2603 {
2604     if ( !_makePipeDiag ){
2605         _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2606     }
2607     _showDialogBox( _makePipeDiag );
2608 }
2609
2610 void HEXABLOCKGUI::makeCylinders()
2611 {
2612     if ( !_makeCylindersDiag ){
2613         _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2614     }
2615     _showDialogBox( _makeCylindersDiag );
2616 }
2617
2618 void HEXABLOCKGUI::makePipes()
2619 {
2620     if ( !_makePipesDiag ){
2621         _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2622     }
2623     _showDialogBox( _makePipesDiag );
2624 }
2625
2626
2627 void HEXABLOCKGUI::makeHemiSphere()  // NEW HEXA3
2628 {
2629     if ( !_makeHemiSphereDiag ){
2630         _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2631     }
2632     _showDialogBox( _makeHemiSphereDiag );
2633 }
2634
2635
2636 void HEXABLOCKGUI::removeHexa()
2637 {
2638     if ( !_removeHexaDiag ){
2639         _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2640     }
2641     _showDialogBox( _removeHexaDiag );
2642 }
2643
2644
2645 void HEXABLOCKGUI::prismQuad()
2646 {
2647     if ( !_prismQuadDiag ){
2648         _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2649     }
2650     _showDialogBox( _prismQuadDiag );
2651 }
2652
2653
2654 void HEXABLOCKGUI::joinQuad()
2655 {
2656     if ( !_joinQuadDiag ){
2657         _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2658     }
2659     _showDialogBox( _joinQuadDiag );
2660 }
2661
2662 void HEXABLOCKGUI::merge()
2663 {
2664     if ( !_mergeDiag ){
2665         _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2666     }
2667     _showDialogBox( _mergeDiag );
2668 }
2669
2670 void HEXABLOCKGUI::disconnectElts()
2671 {
2672     if ( !_disconnectDiag ){
2673         _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2674     }
2675     _showDialogBox( _disconnectDiag );
2676 }
2677
2678 void HEXABLOCKGUI::cutEdge()
2679 {
2680     if ( !_cutEdgeDiag ){
2681         _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2682     }
2683     _showDialogBox( _cutEdgeDiag );
2684 }
2685
2686 void HEXABLOCKGUI::makeTransformation()
2687 {
2688     if ( !_makeTransformationDiag ){
2689         _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2690     }
2691     _showDialogBox( _makeTransformationDiag );
2692 }
2693
2694
2695 void HEXABLOCKGUI::makeSymmetry()
2696 {
2697     if ( !_makeSymmetryDiag ){
2698         _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2699     }
2700     _showDialogBox( _makeSymmetryDiag );
2701 }
2702
2703
2704 void HEXABLOCKGUI::performTransformation()
2705 {
2706     if ( !_performTransformationDiag ){
2707         _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2708     }
2709     _showDialogBox( _performTransformationDiag );
2710 }
2711
2712
2713 void HEXABLOCKGUI::performSymmetry()
2714 {
2715     if ( !_performSymmetryDiag ){
2716         _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2717     }
2718     _showDialogBox( _performSymmetryDiag );
2719 }
2720
2721
2722 void HEXABLOCKGUI::replaceHexa()    // NEW HEXA3
2723 {
2724     if ( !_replaceHexaDiag ){
2725         _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2726     }
2727     _showDialogBox( _replaceHexaDiag );
2728 }
2729
2730
2731 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2732 {
2733     if ( !_quadRevolutionDiag ){
2734         _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2735     }
2736     _showDialogBox( _quadRevolutionDiag );
2737 }
2738
2739
2740 void HEXABLOCKGUI::assocVertex()
2741 {
2742         if (!_dwInputPanel) return;
2743         QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2744         if ( !_vertexAssocDiag  )
2745                 _vertexAssocDiag  = new VertexAssocDialog( d /*_dwInputPanel*/);
2746         _showDialogBox( _vertexAssocDiag );
2747 }
2748
2749
2750 void HEXABLOCKGUI::assocEdge()
2751 {
2752     if ( !_edgeAssocDiag )
2753         _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2754     _showDialogBox( _edgeAssocDiag );
2755 }
2756
2757 void HEXABLOCKGUI::assocQuad()
2758 {
2759     if ( !_quadAssocDiag )
2760         _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2761     _showDialogBox( _quadAssocDiag );
2762 }
2763
2764
2765 void HEXABLOCKGUI::addGroup()
2766 {
2767     if ( !_groupDiag ){
2768         _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2769     }
2770     _showDialogBox( _groupDiag );
2771     if (_groupDiag != NULL && getCurrentModel() != NULL)
2772     {
2773         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2774         if (doc == NULL) return;
2775         char defaultName[16];
2776         sprintf (defaultName, "g%04d", doc->countGroup());
2777         _groupDiag->name_le->setText(defaultName);
2778     }
2779 }
2780
2781 void HEXABLOCKGUI::removeGroup()
2782 {
2783     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2784     if (currentDGView == NULL) return;
2785
2786     QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2787     QModelIndexList l = groupsSelectionModel->selectedIndexes();
2788     int nbGroupsRemoved = 0;
2789
2790     if ( l.isEmpty() ){
2791         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2792                 tr( "No group selected!" ) );
2793         return;
2794     }
2795
2796     foreach( QModelIndex selected, l ){
2797         if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2798             selected = currentDGView->getGroupsModel()->mapToSource( selected );
2799             Q_ASSERT(selected.isValid());
2800
2801             //Confirm the deletion of the group
2802             if (SUIT_MessageBox::question(
2803                     0,
2804                     tr("Remove Group"),
2805                     tr("Remove group : %1 ?").arg(selected.data().toString()),
2806                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2807                     SUIT_MessageBox::Cancel
2808             ) == SUIT_MessageBox::Cancel) return;
2809
2810             bool removed = getCurrentModel()->removeGroup( selected );
2811             if ( !removed ) {
2812                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2813                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2814                 return;
2815             }
2816             nbGroupsRemoved++;
2817         }
2818     }
2819     if (!nbGroupsRemoved)
2820         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2821                 tr( "No group selected!" ) );
2822 }
2823
2824 void HEXABLOCKGUI::addLaw()
2825 {
2826     if ( !_lawDiag ){
2827         _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2828     }
2829     _showDialogBox( _lawDiag );
2830     if (_lawDiag != NULL && getCurrentModel() != NULL)
2831     {
2832         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2833         if (doc == NULL) return;
2834         char defaultName[16];
2835         sprintf (defaultName, "l%04d", doc->countLaw());
2836         _lawDiag->name_le->setText(defaultName);
2837     }
2838 }
2839
2840 void HEXABLOCKGUI::removeLaw()
2841 {
2842     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2843     if (currentDGView == NULL) return;
2844
2845     QModelIndexList l = currentDGView->getMeshSelectionModel()->selectedIndexes();
2846     int nbLawsRemoved = 0;
2847
2848     if ( l.isEmpty() ){
2849         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2850                 tr( "No law selected!" ) );
2851         return;
2852     }
2853
2854     foreach( QModelIndex selected, l ){
2855         if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2856             selected = currentDGView->getMeshModel()->mapToSource( selected );
2857             Q_ASSERT(selected.isValid());
2858
2859             //Confirm the deletion of the law
2860             if (SUIT_MessageBox::question(
2861                     0,
2862                     tr("Remove Law"),
2863                     tr("Remove law : %1 ?\nAll propagations having this law will have the default law.").arg(selected.data().toString()),
2864                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2865                     SUIT_MessageBox::Cancel
2866             ) == SUIT_MessageBox::Cancel) return;
2867
2868             bool removed = getCurrentModel()->removeLaw(selected);
2869             if ( !removed ) {
2870                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2871                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2872                 return;
2873             }
2874             nbLawsRemoved++;
2875         }
2876     }
2877     if (!nbLawsRemoved)
2878         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2879                                          tr( "No law selected!" ) );
2880
2881 }
2882
2883
2884 void HEXABLOCKGUI::setPropagation()
2885 {
2886     if ( !_propagationDiag )
2887         _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2888
2889     _showDialogBox( _propagationDiag );
2890 }
2891
2892 // Dialog box to compute a mesh from a document
2893 // --------------------------------------------
2894 void HEXABLOCKGUI::computeMesh()
2895 {
2896     if ( !_computeMeshDiag )
2897         _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2898
2899     _showDialogBox( _computeMeshDiag );
2900 }
2901
2902 void HEXABLOCKGUI::clearAssociations()
2903 {
2904     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2905     if (currentDGView == NULL) return;
2906
2907     //   QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2908     QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2909     QModelIndex iModel     = currentDGView->getPatternDataModel()->mapToSource(iDataModel);
2910
2911     getCurrentModel()->clearEltAssociations(iModel);
2912
2913     //  SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2914 }
2915
2916 void HEXABLOCKGUI::showModelInfo()
2917 {
2918     //create the info dialog if not yet
2919     if (_modelInfoDiag == NULL)
2920         _modelInfoDiag = new ModelInfoDialog(_dwInputPanel);
2921
2922     //show the model informations dialog
2923     _showDialogBox( _modelInfoDiag );
2924 }
2925
2926 void HEXABLOCKGUI::addShape()
2927 {
2928     //create the info dialog if not yet
2929     if (_addShapeDiag == NULL)
2930         _addShapeDiag = new AddShapeDialog(_dwInputPanel);
2931
2932     //show the model informations dialog
2933     _showDialogBox( _addShapeDiag );
2934 }
2935
2936 void HEXABLOCKGUI::clearAllAssociations()
2937 {
2938     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2939     if (currentDGView == NULL) return;
2940
2941     QModelIndex currentIndex = currentDGView->getPatternDataModel()->mapToSource(_patternDataTreeView->currentIndex());
2942     if (!currentIndex.isValid()) return;
2943     QVariant currentAssocVariant;
2944     QString currentAssocEntry;
2945
2946     //Confirm the deletion of the associations
2947     QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
2948     if ( !treeVariant.isValid() ) return;
2949     int eltType = treeVariant.toInt();
2950     QString typeStr = "";
2951     HEXA_NS::EnumElt hexaType;
2952     if (eltType == VERTEX_DIR_TREE)
2953     {
2954         typeStr = tr("TREE_ITEM_VERTEX").toUpper();
2955         hexaType = HEXA_NS::EL_VERTEX;
2956     }
2957     else if (eltType == EDGE_DIR_TREE)
2958     {
2959         typeStr = tr("TREE_ITEM_EDGE").toUpper();
2960         hexaType = HEXA_NS::EL_EDGE;
2961     }
2962     else if (eltType == QUAD_DIR_TREE)
2963     {
2964         typeStr = tr("TREE_ITEM_QUAD").toUpper();
2965         hexaType = HEXA_NS::EL_QUAD;
2966     }
2967
2968     if (SUIT_MessageBox::question(
2969             0,
2970             tr("CLEAR_ASSOCIATIONS"),
2971             tr("CLEAR_ALL_ASSOCIATIONS_ON") + " " + typeStr + "?",
2972             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2973             SUIT_MessageBox::Cancel
2974     ) == SUIT_MessageBox::Cancel) return;
2975
2976
2977     DocumentModel* docModel = getCurrentModel();
2978     if (docModel == NULL) return;
2979     docModel->clearAssociation(hexaType);
2980 }
2981
2982 void HEXABLOCKGUI::showAssociations()
2983 {
2984     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2985     if (currentDGView == NULL) return;
2986
2987     QModelIndexList elts;
2988     int currentChildIndex = 0;
2989     QVariant currentAssocVariant;
2990     QString currentAssocEntry;
2991     QModelIndex currentIndex = _patternDataTreeView->currentIndex();
2992     QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2993
2994     while( currentChild.isValid() ) {
2995
2996         currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2997         currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2998         if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2999             elts << currentChild;
3000
3001         currentChild = currentChild.sibling(currentChildIndex++, 0);
3002     }
3003     currentDocGView->highlight(elts);
3004     currentOccGView->highlight(elts, false);
3005 }
3006
3007
3008 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
3009 {
3010     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3011     if( anApp )
3012         return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3013     else
3014         return NULL;
3015 }
3016
3017 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
3018 {
3019     if ( event->type() == QEvent::Enter )
3020     {   // *** ENTER EVENT
3021
3022         if (currentDialog == NULL || !currentDialog->isVisible())
3023             return QObject::eventFilter(obj, event);
3024
3025         //  ** The window acquire the focus when the cursor enter
3026
3027             //OCC - window enter
3028         OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
3029         if ( occWindow != NULL)
3030             currentDialog->onWindowActivated(occWindow->getViewManager());
3031         else
3032             //VTK - window enter
3033         {
3034             SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
3035             if ( vtkWindow != NULL)
3036                 currentDialog->onWindowActivated(vtkWindow->getViewManager());
3037         }
3038     }
3039
3040     //standard event processing
3041     return QObject::eventFilter(obj, event);
3042 }
3043
3044 QStringList HEXABLOCKGUI::getQuickDirList()
3045 {
3046     QStringList dirList;
3047     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
3048     if ( resMgr )
3049         dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
3050
3051     return dirList;
3052 }
3053
3054
3055 // --- Export the module
3056
3057 extern "C"
3058 {
3059     HEXABLOCK_EXPORT CAM_Module* createModule()
3060     {
3061         return new HEXABLOCKGUI();
3062     }
3063
3064     HEXABLOCK_EXPORT char* getModuleVersion()
3065     {
3066         return (char*)HEXABLOCK_VERSION_STR;
3067     }
3068 }
3069
3070
3071
3072 // ******************** TESTS ***************************************************
3073
3074 void HEXABLOCKGUI::testDocument()
3075 {
3076     //CS_TEST
3077     // ----------
3078     //   QStandardItem *parentItem = getCurrentModel()->invisibleRootItem();
3079     //   QStandardItem *myItem =  new QStandardItem("MyItem");
3080     //   parentItem->appendRow(myItem);
3081     // //   ----------
3082     //   QModelIndex v0 = getCurrentModel()->addVertex(0., 0., 0.);
3083     //   QModelIndex v1 = getCurrentModel()->addVertex(5., 0., 0.);
3084     //   QModelIndex v2 = getCurrentModel()->addVertex(5., 5., 0.);
3085     //   QModelIndex v3 = getCurrentModel()->addVertex(0., 5., 0.);
3086     //   QModelIndex v4 = getCurrentModel()->addVertex(0., 0., 5.);
3087     //   QModelIndex v5 = getCurrentModel()->addVertex(5., 0., 5.);
3088     //   QModelIndex v6 = getCurrentModel()->addVertex(5., 5., 5.);
3089     //   QModelIndex v7 = getCurrentModel()->addVertex(0., 5., 5.);
3090     // //
3091     // //
3092     //   QModelIndex q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
3093     //   QModelIndex q1 = getCurrentModel()->addQuadVertices( v4, v5, v6, v7 );
3094     //   QModelIndex q2 = getCurrentModel()->addQuadVertices( v0, v3, v7, v4 );
3095     //   QModelIndex q3 = getCurrentModel()->addQuadVertices( v1, v2, v6, v5 );
3096     //   QModelIndex q4 = getCurrentModel()->addQuadVertices( v0, v1, v5, v4 );
3097     //   QModelIndex q5 = getCurrentModel()->addQuadVertices( v3, v2, v6, v7 );
3098     //
3099     //   QModelIndex h0 = getCurrentModel()->addHexaQuad( q0, q1, q2, q3, q4, q5 );
3100     //   QModelIndex vx = getCurrentModel()->addVector(1., 0., 0.);
3101     //   QModelIndex vy = getCurrentModel()->addVector(0., 1., 0.);
3102     //   QModelIndex vz = getCurrentModel()->addVector(0., 0., 1.);
3103     //
3104
3105
3106
3107     // //   QModelIndex orig1 = getCurrentModel()->addVertex (0, 0,0);
3108     // //   QModelIndex orig2 = getCurrentModel()->addVertex (50,0,0);
3109     // //   QModelIndex vz    = getCurrentModel()->addVector (0,0,1);
3110     // //   QModelIndex vx    = getCurrentModel()->addVector (1,0,0);
3111     // //
3112     // //   int nr  = 4;
3113     // //   int nri = 3;
3114     // //   int nre = nr;
3115     // //   int na = 9;
3116     // //   int nl = 5;
3117     // //
3118     // //   QModelIndex  cyl  = getCurrentModel()->addCylinder   (orig1, vz, nr, nl);
3119     // //   QModelIndex  pipe = getCurrentModel()->addPipe       (orig2, vz, nri, nre, nl);
3120     // //
3121     // //   getCurrentModel()->makeCylinder (cyl,  vx, nr, na, nl);
3122     // //   getCurrentModel()->makePipe(pipe, vx, nr, na, nl);
3123
3124
3125
3126     //   newMesh( "toto", 3, "FactoryServer");
3127     // newMesh
3128 }
3129
3130 void HEXABLOCKGUI::test_make_cart_grid()
3131 {
3132     QModelIndex orig1 = getCurrentModel()->addVertex( 0, 0, 0);
3133     QModelIndex orig2 = getCurrentModel()->addVertex( 10, 0, 0);
3134     QModelIndex orig3 = getCurrentModel()->addVertex( 0, 10, 0);
3135     QModelIndex orig4 = getCurrentModel()->addVertex( 10, 10, 0);
3136     QModelIndex orig5 = getCurrentModel()->addVertex( 0, 20, 0);
3137     QModelIndex orig6 = getCurrentModel()->addVertex( 10, 20, 0);
3138
3139     QModelIndex vz = getCurrentModel()->addVector(0, 0, 1);
3140     QModelIndex vx = getCurrentModel()->addVector(1, 0, 0);
3141
3142     //int dr = 1;
3143     //int dl = 1;
3144     //int nr = 2;
3145     //int nl = 3;
3146
3147     // QModelIndex c1 = getCurrentModel()->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
3148     // QModelIndex c2 = getCurrentModel()->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
3149     // QModelIndex c3 = getCurrentModel()->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
3150     // QModelIndex c4 = getCurrentModel()->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
3151     // QModelIndex c5 = getCurrentModel()->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
3152     // QModelIndex c6 = getCurrentModel()->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
3153
3154 }
3155
3156
3157 void HEXABLOCKGUI::test_make_elmts_transform()
3158 {
3159
3160 //    int size_x = 1;
3161 //    int size_y = 1;
3162 //    int size_z = 2;
3163 //
3164 //    QModelIndex orig = getCurrentModel()->addVertex(0, 0, 0);
3165 //    QModelIndex dirVr = getCurrentModel()->addVector(1, 1, 1);
3166
3167     //obsolete
3168 //    QModelIndex grid = getCurrentModel()->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
3169     // orig.setScalar(2);
3170
3171     // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
3172     // getCurrentModel()->saveVtk(file_name)
3173
3174 //    QModelIndex devant = getCurrentModel()->addVector(5, 0, 0);
3175 //    QModelIndex grid2  = getCurrentModel()->makeTranslation(grid, devant);
3176
3177     // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
3178     // getCurrentModel()->saveVtk(file_name)
3179
3180 //    QModelIndex grid4 = getCurrentModel()->makeRotation(grid2, orig, dirVr, 45);
3181
3182
3183     // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
3184     // getCurrentModel()->saveVtk(file_name);
3185
3186
3187     // print "...test make elements by transforming elements OK"
3188 }
3189 // =============================================================== addDocInSudy
3190 QString HEXABLOCKGUI::addDocInStudy (HEXA_NS::Document* document)
3191 {
3192     QString docEntry;
3193
3194     if (document == NULL)
3195         return docEntry;
3196
3197     QString docName  = document->getName ();
3198
3199     SalomeApp_Study* app_study = HEXABLOCKGUI::activeStudy();
3200     if (app_study == NULL)
3201         return docEntry;
3202
3203     SALOMEDS::Study_var ds_study = getStudyServant();
3204     SALOMEDS::StudyBuilder_var aBuilder (ds_study->NewBuilder());
3205     QString entry = app_study->centry("HEXABLOCK");
3206     SALOMEDS::SObject_var aFatherSO = ds_study->FindObjectID( qPrintable(entry) );
3207     if (aFatherSO->_is_nil())
3208         return docEntry;
3209
3210     SALOMEDS::SObject_var aSO = aBuilder->NewObject(aFatherSO);
3211     if (aSO->_is_nil())
3212         return docEntry;
3213     aSO->SetAttrString("AttributeName", docName.toStdString().c_str());
3214     docEntry = aSO->GetID(); //the entry of the published object
3215
3216     return docEntry;
3217 }
3218
3219 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
3220
3221 void HEXABLOCKGUI::test()
3222 {
3223     DEBTRACE("HEXABLOCKGUI::test");
3224     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3225     if (currentDGView == NULL) return;
3226     currentDGView->update();
3227
3228 }
3229
3230 void HEXABLOCKGUI::test_association()
3231 {
3232     DEBTRACE("HEXABLOCKGUI::test_association");
3233     newDocument();
3234
3235     QModelIndex v0, v1, v2, v3, e0, e1, q0;
3236
3237     DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
3238     DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
3239     DocumentModel::GeomObj q0AssocA, q0AssocB;
3240
3241     DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
3242     QList<DocumentModel::GeomObj> e1Assocs_test;
3243     DocumentModel::GeomObj q0Assoc_test;
3244
3245     v0 = getCurrentModel()->addVertex(0, 0, 0);
3246     v1 = getCurrentModel()->addVertex(1, 0, 0);
3247     v2 = getCurrentModel()->addVertex(1, 1, 0);
3248     v3 = getCurrentModel()->addVertex(0, 1, 0);
3249     e0  = getCurrentModel()->addEdgeVertices(v0, v1);
3250     e1  = getCurrentModel()->addEdgeVertices(v1, v2);
3251     q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
3252
3253
3254     // >>> face3.GetEntry()'0:1:4'
3255     // >>> e1.GetEntry()'0:1:8'
3256     // >>> e2.GetEntry()'0:1:9'
3257     // >>> e3.GetEntry()'0:1:10'
3258     // >>> e4.GetEntry()'0:1:11'
3259     // >>> v1.GetEntry()'0:1:12'
3260     // >>> v2.GetEntry()'0:1:13'
3261     // >>> v3.GetEntry()'0:1:14'
3262     // >>> v4.GetEntry()'0:1:15'
3263
3264
3265     //   v0Assoc.name  = "geomV0";
3266     //   v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
3267     //   v0Assoc.brep  = "brepV0";
3268     //   v1Assoc.name  = "geomV1";
3269     //   v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
3270     //   v1Assoc.brep  = "brepV1";
3271     //   v2Assoc.name  = "geomV2";
3272     //   v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
3273     //   v2Assoc.brep  = "brepV2";
3274     //   v3Assoc.name  = "geomV3";
3275     //   v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
3276     //   v3Assoc.brep  = "brepV3";
3277     //
3278     //
3279     //
3280     //   e0AssocA.name   = "geomE0a";
3281     //   e0AssocA.entry  = "0:1:1:1:3:5";//"0:1:8";
3282     //   e0AssocA.brep  = "brepE0a";
3283     //   e0AssocA.start  = 0.10;
3284     //   e0AssocA.end    = 0.95;
3285     //
3286     //
3287     //
3288     //   e1AssocA.name   = "geomE1a";
3289     //   e1AssocA.entry  = "0:1:1:1:3:2";//"0:1:8";
3290     //   e1AssocA.brep  = "brepE1a";
3291     //   e1AssocA.start  = 0.12;
3292     //   e1AssocA.end    = 0.89;
3293     //   e1AssocB.name   = "geomE1b";
3294     //   e1AssocB.entry  = "0:1:1:1:3:3";//"0:1:9";
3295     //   e1AssocB.brep  = "brepE1b";
3296     //   e1AssocB.start  = 0.20;
3297     //   e1AssocB.end    = 0.80;
3298     //   e1AssocC.name   = "geomE1c";
3299     //   e1AssocC.entry  = "0:1:1:1:3:4";//"0:1:10";
3300     //   e1AssocC.brep  = "brepE1c";
3301     //   e1AssocC.start  = 0.16;
3302     //   e1AssocC.end    = 0.96;
3303     //
3304     //   q0AssocA.name   = "geomQuad";
3305     //   q0AssocA.entry  = "0:1:1:1:3";
3306     //   q0AssocA.brep   = "brepq0";
3307     //
3308     //   q0AssocB.name   = "geomQuad";
3309     //   q0AssocB.entry  = "0:1:1:1:4";
3310     //   q0AssocB.brep   = "brepq0";
3311     //
3312     //   getCurrentModel()->addAssociation( v0, v0Assoc );
3313     //   getCurrentModel()->addAssociation( v1, v1Assoc );
3314     //   getCurrentModel()->addAssociation( v2, v2Assoc );
3315     //   getCurrentModel()->addAssociation( v3, v3Assoc );
3316     //
3317     //
3318     //   getCurrentModel()->addAssociation( e0, e0AssocA );
3319     //
3320     //   getCurrentModel()->addAssociation( e1, e1AssocA );
3321     //   getCurrentModel()->addAssociation( e1, e1AssocB );
3322     //   getCurrentModel()->addAssociation( e1, e1AssocC );
3323     //
3324     //   getCurrentModel()->addAssociation( q0, q0AssocA );
3325     //   getCurrentModel()->addAssociation( q0, q0AssocB );
3326
3327
3328
3329
3330
3331     //   v0Assoc_test = getCurrentModel()->getAssociations( v0 )[0];
3332     //   v1Assoc_test = getCurrentModel()->getAssociations( v1 )[0];
3333     //   v2Assoc_test = getCurrentModel()->getAssociations( v2 )[0];
3334     //   v3Assoc_test = getCurrentModel()->getAssociations( v3 )[0];
3335     //   ASSERT( v0Assoc.name == v0Assoc_test.name );
3336     //   ASSERT( v1Assoc.name == v1Assoc_test.name );
3337     //   ASSERT( v2Assoc.name == v2Assoc_test.name );
3338     //   ASSERT( v3Assoc.name == v3Assoc_test.name );
3339     //   ASSERT( v0Assoc.entry == v0Assoc_test.entry );
3340     //   ASSERT( v1Assoc.entry == v1Assoc_test.entry );
3341     //   ASSERT( v2Assoc.entry == v2Assoc_test.entry );
3342     //   ASSERT( v3Assoc.entry == v3Assoc_test.entry );
3343     //
3344     //
3345     //   e1Assocs_test = getCurrentModel()->getAssociations( e1 );
3346     //   ASSERT( e1Assocs_test[0].name == e1AssocA.name );
3347     //   ASSERT( e1Assocs_test[1].name == e1AssocB.name );
3348     //   ASSERT( e1Assocs_test[2].name == e1AssocC.name );
3349     //   ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
3350     //   ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
3351     //   ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
3352     //   ASSERT( e1Assocs_test[0].start == e1AssocA.start );
3353     //   ASSERT( e1Assocs_test[1].start == e1AssocB.start );
3354     //   ASSERT( e1Assocs_test[2].start == e1AssocC.start );
3355     //   ASSERT( e1Assocs_test[0].end == e1AssocA.end );
3356     //   ASSERT( e1Assocs_test[1].end == e1AssocB.end );
3357     //   ASSERT( e1Assocs_test[2].end == e1AssocC.end );
3358     //
3359     //   q0Assoc_test = getCurrentModel()->getAssociations( q0 )[0];
3360     //   ASSERT( q0Assoc_test.name  == q0Assoc.name );
3361     //   ASSERT( q0Assoc_test.entry == q0Assoc.entry );
3362
3363
3364     DEBTRACE("HEXABLOCKGUI::test_association fin");
3365 }