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