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