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