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