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