Salome HOME
Additional fix for '23531: [CEA] Crash on switching to HEXABLOC from any module witho...
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.cxx
1 // Copyright (C) 2009-2016  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //#define _DEVDEBUG_
21
22 #include <cassert>
23
24 #include <QDir>
25 #include <QInputDialog>
26 #include <QIcon>
27 #include <QStackedWidget>
28 #include <QMenu>
29 #include <QSplitter>
30
31 #include <QtxTreeView.h>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_ViewManager.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SUIT_DataObject.h>
39 #include <SUIT_DataBrowser.h>
40 #include <SUIT_FileDlg.h>
41
42 #include <SVTK_ViewManager.h>
43 #include <SVTK_ViewModel.h>
44 #include <SVTK_ViewWindow.h>
45
46 #include <VTKViewer_ViewModel.h>
47 #include <vtkActor.h>
48 #include <vtkActorCollection.h>
49 #include <VTKViewer_Algorithm.h>
50 #include <vtkRenderer.h>
51
52
53
54 #include <SOCC_ViewModel.h>
55 #include <SOCC_ViewWindow.h>
56 #include <OCCViewer_ViewWindow.h>
57 #include <SALOME_Prs.h>
58 #include <SOCC_Prs.h>
59 #include <SOCC.h>
60
61 // SALOME KERNEL includes
62 #include <SALOMEDS_Study.hxx>
63 #include <SALOMEDSClient_StudyBuilder.hxx>
64 #include <SALOMEDSClient_SComponent.hxx>
65 #include <SALOMEDSClient_ClientFactory.hxx>
66 #include <SALOMEDSClient_IParameters.hxx>
67
68
69
70 #include <SalomeApp_Study.h>
71 #include <SalomeApp_Module.h>
72 #include <SalomeApp_Application.h>
73 #include <SalomeApp_DataModel.h>
74
75
76 #include <SALOME_ListIO.hxx>
77
78
79 #include <SALOME_LifeCycleCORBA.hxx>
80
81 #include <LightApp_VTKSelector.h>
82
83 #include <OCCViewer_ViewManager.h>
84
85 #include <QtxPopupMgr.h>
86
87 #include "Resource.hxx"
88
89 #include "HEXABLOCKGUI.hxx"
90 #include "HEXABLOCKGUI_Export.hxx"
91 #include "HEXABLOCKGUI_Trace.hxx"
92 #include "HEXABLOCKGUI_Resource.hxx"
93
94 #include "HEXABLOCKGUI_DocumentModel.hxx"
95 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
96 //#include "HEXABLOCKGUI_DocumentDelegate.hxx"
97 #include "HEXABLOCKGUI_DocumentPanel.hxx"
98 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
99 #include "HEXABLOCKGUI_OccGraphicView.hxx"
100 #include "HEXABLOCKGUI_GraphicViewsHandler.hxx"
101
102 #include "HEXABLOCK_version.h"
103
104 #include "MyBasicGUI_PointDlg.hxx"
105
106 // #include "HEXABLOCK.hxx"                del Hexa6
107 // #include "HexDocument_impl.hxx"         del Hexa6
108 #include "Hex.hxx"
109
110 //#include <V3d_PerspectiveView.hxx>
111 #include <V3d_AmbientLight.hxx>
112 #include <V3d_DirectionalLight.hxx>
113 #include <Xw_Window.hxx>
114 #include <V3d_TypeOfShadingModel.hxx>
115 #include <TCollection_ExtendedString.hxx>
116
117 #include <BRepAlgoAPI_Fuse.hxx>
118
119 #include <AIS_ListIteratorOfListOfInteractive.hxx>
120
121 #include <utilities.h>
122
123 #define DW_MINIMUM_WIDTH       50
124 #define DWINPUT_MINIMUM_HEIGHT 50
125 #define DWINPUT_MINIMUM_WIDTH  50//255
126
127 using namespace std;
128 using namespace HEXABLOCK::GUI;
129
130 int  HEXABLOCKGUI::_oldStudyId = -1;
131
132 // HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine  = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
133 //
134 VtkDocumentGraphicView* HEXABLOCKGUI::currentDocGView = NULL;
135 OccGraphicView*         HEXABLOCKGUI::currentOccGView = NULL;
136 bool                    HEXABLOCKGUI::assocInProgress = false;
137 SalomeApp_Application*  HEXABLOCKGUI::myApplication = NULL;
138
139 HEXABLOCKGUI::HEXABLOCKGUI() :
140           SalomeApp_Module( "HEXABLOCK" ),
141 //          LightApp_Module( "HEXABLOCK" ),
142           _menuId(190),
143           _dwPattern(0),
144           _dwAssociation(0),
145           _dwGroups(0),
146           _dwMesh(0),
147           _dwObjectBrowser(0),
148           _dwInputPanel(0),
149           _patternDataTreeView(0),
150 //          _patternBuilderTreeView(0),
151           _patternGeomTreeView(0),
152           _groupsTreeView(0),
153           _meshTreeView(0),
154 //          _treeViewDelegate(0),
155           _isSaved( false ),
156           moduleActivatedOnce(false),
157           menusEnabled(true),
158           _vertexDiag(0),
159           _edgeDiag(0),
160           _quadDiag(0),
161           _hexaDiag(0),
162           _vectorDiag(0),
163           _cylinderDiag(0),
164           _pipeDiag(0),
165           _makeGridDiag(0),
166           _makeCylinderDiag(0),
167           _makePipeDiag(0),
168           _makeCylindersDiag(0),
169           _makePipesDiag(0),
170           _removeHexaDiag(0),
171           _prismQuadDiag(0),
172           _joinQuadDiag(0),
173           _mergeDiag(0),
174           _disconnectDiag(0),
175           _cutEdgeDiag(0),
176           _makeTransformationDiag(0),
177           _makeSymmetryDiag(0),
178           _performTransformationDiag(0),
179           _performSymmetryDiag(0),
180           _vertexAssocDiag(0),
181           _edgeAssocDiag(0),
182           _quadAssocDiag(0),
183           _groupDiag(0),
184           _lawDiag(0),
185           _propagationDiag(0),
186           _computeMeshDiag(0),
187           _replaceHexaDiag(0),
188           _quadRevolutionDiag(0),
189           _makeHemiSphereDiag(0),
190           _modelInfoDiag(NULL),
191           _addShapeDiag(NULL),
192           _vertexInfoDialog(NULL),
193           _edgeInfoDialog(NULL),
194           _quadInfoDialog(NULL),
195           _hexaInfoDialog(NULL),
196           _vectorInfoDialog(NULL),
197           _groupInfoDialog(NULL),
198           _lawInfoDialog(NULL),
199           _propagationInfoDialog(NULL),
200           currentDialog(NULL),
201           lastOccPrs(NULL),
202           lastVtkDocGView(NULL)
203 {
204     DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
205
206     graphicViewsHandler = new GraphicViewsHandler();
207     loadDocLastPath = new QDir();
208     saveDocLastPath = new QDir();
209     hexa_root       = HEXA_NS::Hex::getInstance ();
210 }
211
212 HEXABLOCKGUI::~HEXABLOCKGUI()
213 {
214 }
215
216
217 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
218 {
219     SUIT_Application* app = SUIT_Session::session()->activeApplication();
220     if( app )
221         return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
222     else
223         return NULL;
224 }
225
226
227 // Gets an reference to the module's engine
228 /****************************************************
229 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
230 {
231     Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
232     HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
233     ASSERT(!CORBA::is_nil(clr));
234     return clr;
235 }
236  **************************************************** */
237
238 void HEXABLOCKGUI::initialize( CAM_Application* app )
239 {
240         MESSAGE("HEXABLOCKGUI::initialize");
241     DEBTRACE("HEXABLOCKGUI::initialize");
242     SalomeApp_Module::initialize( app );
243
244     // _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
245
246     DEBTRACE(app << "  " << application() << " " << application()->desktop() << " " << aParent);
247
248     SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
249     setResource(aResourceMgr);
250
251     createAndFillDockWidget();
252     createActions();
253     createMenus();
254     createTools();
255     studyActivated();
256 }
257
258 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
259 {
260     DEBTRACE("HEXABLOCKGUI::viewManagers");
261     //   list.append( QxScene_Viewer::Type() );
262     //   list.append( OCCViewer_Viewer::Type() );
263     //   list.append( SVTK_Viewer::Type() );
264 }
265
266
267 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
268 {
269     DEBTRACE("HEXABLOCKGUI::activateModule");
270
271     /*HexaBlock can be launched in only one application*/
272     if (myApplication == NULL)
273         //remember the first application
274         myApplication = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
275
276     //application verification: if it's not the one known by HexaBlock,
277     //leave without activating
278     SalomeApp_Application* currentApplication =  dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
279     if (myApplication != currentApplication) return false;
280
281     bool bOk = SalomeApp_Module::activateModule( theStudy );
282     if ( !bOk ) return false;
283
284     showDockWidgets(true);
285
286     connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
287             this, SLOT(onWindowActivated( SUIT_ViewWindow* )), Qt::UniqueConnection );
288     if ( getApp()->objectBrowser() ) {
289       connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
290                this, SLOT( onObjectBrowserClick(const QModelIndex&) ), Qt::UniqueConnection );
291     }
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 = 0;
1025     if ( getApp()->objectBrowser() )
1026       wid = getApp()->objectBrowser()->treeView();
1027     while ( wid && !_dwObjectBrowser ) {
1028         _dwObjectBrowser = ::qobject_cast<QDockWidget*>( wid );
1029         wid = wid->parentWidget();
1030     }
1031     
1032     if ( _dwObjectBrowser ) {
1033       _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1034       _dwObjectBrowser->setWindowTitle("Study");
1035     }
1036
1037     // dock widget position
1038     if ( _dwObjectBrowser ) {
1039       aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
1040     }
1041     aParent->addDockWidget( Qt::RightDockWidgetArea, _dwInputPanel );
1042
1043 //    aParent->tabifyDockWidget( _dwPattern, _dwObjectBrowser );
1044 //    aParent->tabifyDockWidget( _dwGroups, _dwPattern );
1045 //    aParent->tabifyDockWidget( _dwMesh, _dwGroups );
1046
1047     if ( _dwObjectBrowser ) {
1048       aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
1049     }
1050     aParent->tabifyDockWidget( _dwPattern, _dwGroups );
1051     aParent->tabifyDockWidget( _dwGroups, _dwMesh );
1052
1053 #if QT_VERSION >= 0x040500
1054     aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
1055 #endif
1056
1057     // popup menu on data tree view
1058     _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
1059     connect(_patternDataTreeView,
1060             SIGNAL(customContextMenuRequested(const QPoint &)),
1061             this,
1062             SLOT(treeContextMenu(const QPoint &)),
1063             Qt::UniqueConnection );
1064 }
1065
1066 void HEXABLOCKGUI::createActions()
1067 {
1068     QMainWindow *aParent = application()->desktop();
1069     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1070
1071     // Document
1072     _newAct = createAction(_menuId++,
1073             tr("Create a new document"),
1074             resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
1075             tr("New Document"),
1076             tr("Create a new document"),
1077             0, aParent, false, this, SLOT(newDocument()));
1078     _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1079
1080     _importAct = createAction(_menuId++,
1081             tr("Load a document"),
1082             resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
1083             tr("Load Document"),
1084             tr("Load a document"),
1085             0, aParent, false, this, SLOT(loadDocument()));
1086     _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
1087
1088     _saveAct = createAction(_menuId++,
1089             tr("Save the document"),
1090             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
1091             tr("Save Document"),
1092             tr("Save the document"),
1093             0, aParent, false, this, SLOT(saveDocument()));
1094
1095     // Pattern Data creation
1096     _addVertex = createAction(_menuId++,
1097             tr("Create a vertex"),
1098             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
1099             tr("Add Vertex"),
1100             tr("Create a new vertex"),
1101             0, aParent, false, this, SLOT(addVertex()));
1102
1103     _addEdge = createAction(_menuId++,
1104             tr("Create an edge"),
1105             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
1106             tr("Add Edge"),
1107             tr("Create a new edge"),
1108             0, aParent, false, this, SLOT(addEdge()));
1109
1110     _addQuad = createAction(_menuId++,
1111             tr("Create a quadrangle"),
1112             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1113             tr("Add Quadrangle"),
1114             tr("Create a new quadrangle"),
1115             0, aParent, false, this, SLOT(addQuad()));
1116
1117     _addHexa = createAction(_menuId++,
1118             tr("Create an hexahedron"),
1119             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1120             tr("Add Hexahedron"),
1121             tr("Create a new hexahedron"),
1122             0, aParent, false, this, SLOT(addHexa()));
1123
1124     // Builder Data creation
1125     _addVector = createAction(_menuId++,
1126             tr("Create a vector"),
1127             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1128             tr("Add Vector"),
1129             tr("Create a new vector"),
1130             0, aParent, false, this, SLOT(addVector()));
1131
1132 //    _addCylinder = createAction(_menuId++,
1133 //            tr("Create a cylinder"),
1134 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1135 //            tr("Add Cylinder"),
1136 //            tr("Create a new cylinder"),
1137 //            0, aParent, false, this,  SLOT(addCylinder()));
1138
1139 //    _addPipe = createAction(_menuId++,
1140 //            tr("Create a pipe"),
1141 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1142 //            tr("Add Pipe"),
1143 //            tr("Create a new pipe"),
1144 //            0, aParent, false, this, SLOT(addPipe()));
1145
1146     _makeGrid = createAction(_menuId++,
1147             tr("Make a grid"),
1148             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1149             tr("Make Grid"),
1150             tr("Make a grid"),
1151             0, aParent, false, this,  SLOT(makeGrid()));
1152
1153     _makeCylinder = createAction(_menuId++,
1154             tr("Make a cylinder"),
1155             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1156             tr("Make Cylinder"),
1157             tr("Make a cylinder"),
1158             0, aParent, false, this, SLOT(makeCylinder()));
1159
1160     _makePipe = createAction(_menuId++,
1161             tr("Make a pipe"),
1162             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1163             tr("Make Pipe"),
1164             tr("Make a pipe"),
1165             0, aParent, false, this, SLOT(makePipe()));
1166
1167     _makeCylinders = createAction(_menuId++,
1168             tr("Make cylinders"),
1169             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1170             tr("Make Cylinders"),
1171             tr("Make cylinders"),
1172             0, aParent, false, this, SLOT(makeCylinders()));
1173
1174     _makePipes = createAction(_menuId++,
1175             tr("Make pipes"),
1176             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1177             tr("Make Pipes"),
1178             tr("Make pipes"),
1179             0, aParent, false, this, SLOT(makePipes()));
1180
1181     _makeHemiSphere = createAction(_menuId++,
1182             tr("Make an hemisphere"),
1183             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1184             tr("Make Hemisphere"),
1185             tr("Make an hemisphere"),
1186             0, aParent, false, this, SLOT(makeHemiSphere()));
1187
1188     // Pattern Data edition
1189     _removeHexa = createAction(_menuId++,
1190             tr("Remove hexahedra"),
1191             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1192             tr("Remove Hexahedra"),
1193             tr("Remove hexahedra"),
1194             0, aParent, false, this, SLOT(removeHexa()));
1195
1196     _prismQuad = createAction(_menuId++,
1197             tr("Prism quadrangles"),
1198             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1199             tr("Prism Quadrangles"),
1200             tr("Prism quadrangles"),
1201             0, aParent, false, this, SLOT(prismQuad()));
1202
1203     _joinQuad = createAction(_menuId++,
1204             tr("Join quadrangles"),
1205             resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1206             tr("Join Quadrangles"),
1207             tr("Join quadrangles with hexahedra"),
1208             0, aParent, false, this, SLOT(joinQuad()));
1209
1210     _merge = createAction(_menuId++,
1211             tr("Merge"),
1212             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1213             tr("Merge"),
1214             tr("Merge"),
1215             0, aParent, false, this, SLOT(merge()));
1216
1217     _disconnect = createAction(_menuId++,
1218             tr("Disconnect"),
1219             resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1220             tr("Disconnect"),
1221             tr("Disconnect edges, vertexes or quadrangles"),
1222             0, aParent, false, this, SLOT(disconnectElts()));
1223
1224     _cutEdge = createAction(_menuId++,
1225             tr("Cut edge"),
1226             resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1227             tr("Cut Edge"),
1228             tr("Cut edge"),
1229             0, aParent, false, this, SLOT(cutEdge()));
1230
1231     _makeTransformation = createAction(_menuId++,
1232             tr("Make transformation"),
1233             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1234             tr("Make Transformation"),
1235             tr("Make transformation"),
1236             0, aParent, false, this, SLOT(makeTransformation()));
1237
1238     _makeSymmetry = createAction(_menuId++,
1239             tr("Make symmetry"),
1240             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1241             tr("Make Symmetry"),
1242             tr("Make symmetry"),
1243             0, aParent, false, this, SLOT(makeSymmetry()));
1244
1245     _performTransformation = createAction(_menuId++,
1246             tr("Perform transformation"),
1247             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1248             tr("Perform Transformation"),
1249             tr("Perform transformation"),
1250             0, aParent, false, this, SLOT(performTransformation()));
1251
1252     _performSymmetry = createAction(_menuId++,
1253             tr("Perform symmetry"),
1254             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1255             tr("Perform Symmetry"),
1256             tr("Perform symmetry"),
1257             0, aParent, false, this, SLOT(performSymmetry()));
1258
1259     _replaceHexa = createAction(_menuId++,
1260             tr("Replace hexahedron"),
1261             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1262             tr("Replace Hexahedron"),
1263             tr("Replace hexahedron"),
1264             0, aParent, false, this, SLOT(replaceHexa()));
1265
1266     _quadRevolution = createAction(_menuId++,
1267             tr("Quad revolution"),
1268             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1269             tr("Quad Revolution"),
1270             tr("Quad revolution"),
1271             0, aParent, false, this, SLOT(quadRevolution()));
1272
1273     // Association
1274     _assocVertex = createAction(_menuId++,
1275             tr("Make vertex association"),
1276             resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1277             tr("Make Vertex association"),
1278             tr("Make vertex association"),
1279             0, aParent, false, this, SLOT(assocVertex()));
1280
1281     _assocEdge = createAction(_menuId++,
1282             tr("Make edge association"),
1283             resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1284             tr("Make Edge Association"),
1285             tr("Make edge association"),
1286             0, aParent, false, this, SLOT(assocEdge()));
1287
1288     _assocQuad = createAction(_menuId++,
1289             tr("Make quad association"),
1290             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1291             tr("Make Quad Association"),
1292             tr("Make quad association"),
1293             0, aParent, false, this, SLOT(assocQuad()));
1294
1295     // Group
1296     _addGroup = createAction(_menuId++,
1297             tr("Add a group"),
1298             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1299             tr("Add Group"),
1300             tr("Add a group"),
1301             0, aParent, false, this, SLOT(addGroup()));
1302
1303     _removeGroup = createAction(_menuId++,
1304             tr("Remove a group"),
1305             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1306             tr("Remove Group"),
1307             tr("Remove a group"),
1308             0, aParent, false, this, SLOT(removeGroup()));
1309
1310     // Mesh
1311     _addLaw = createAction(_menuId++,
1312             tr("Add a law"),
1313             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1314             tr("Add Law"),
1315             tr("Add a law"),
1316             0, aParent, false, this, SLOT(addLaw()));
1317
1318     _removeLaw = createAction(_menuId++,
1319             tr("Remove a law"),
1320             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1321             tr("Remove Law"),
1322             tr("Remove a law"),
1323             0, aParent, false, this, SLOT(removeLaw()));
1324
1325     _setPropagation = createAction(_menuId++,
1326             tr("Set propagation"),
1327             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1328             tr("Set Propagation"),
1329             tr("Set propagation"),
1330             0, aParent, false, this, SLOT(setPropagation()));
1331
1332     _computeMesh = createAction(_menuId++,
1333             tr("Compute mesh"),
1334             resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1335             tr("Compute Mesh"),
1336             tr("Compute mesh"),
1337             0, aParent, false, this, SLOT(computeMesh()));
1338
1339     _showModelInfoAct = createAction(_menuId++,
1340             tr("Show Model Info"),
1341             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MODEL_INFO")),
1342             tr("MODEL_INFO"),
1343             tr("MODEL_INFO"),
1344             0, aParent, false, this, SLOT(showModelInfo()));
1345
1346     _addShapeAct = createAction(_menuId++,
1347             tr("Add Shape"),
1348             resMgr->loadPixmap("HEXABLOCK", tr("ICON_GEOM_ASSOCIATION")),
1349             tr("ADD_SHAPE"),
1350             tr("ADD_SHAPE"),
1351             0, aParent, false, this, SLOT(addShape()));
1352
1353 //   _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1354 //   QAction* createAction(const int id,
1355 //                         const QString& toolTip,
1356 //                         const QIcon& icon,
1357 //                         const QString& menu,
1358 //                         const QString& status,
1359 //                         const int shortCut,
1360 //                         QObject* parent =0,
1361 //                         bool checkable = false,
1362 //                         QObject* receiver =0,
1363 //                         const char* member =0);
1364
1365     _sep1 =  separator();
1366     _sep2 =  separator();
1367     _sep3 =  separator();
1368     _sep4 =  separator();
1369 }
1370
1371
1372 void HEXABLOCKGUI::createMenus()
1373 {
1374     int aMenuId, subMenuId,aMenuIdMain;
1375
1376     aMenuIdMain = createMenu( tr("MEN_FILE"), -1, -1);
1377
1378     aMenuId = createMenu( tr("HEXABLOCK"), aMenuIdMain, -1, 10 );
1379     createMenu( actionId(_newAct), aMenuId );
1380     createMenu( actionId(_importAct), aMenuId );
1381     createMenu( _saveAct, aMenuId );
1382
1383
1384     int aMenuDocId = createMenu( tr( "Document" ), -1, -1, 30 );
1385     createMenu( _newAct, aMenuDocId );//, 10
1386     createMenu( _importAct, aMenuDocId );
1387     createMenu( _saveAct, aMenuDocId );
1388
1389     aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1390     subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1391     createMenu( _addVertex, subMenuId );
1392     createMenu( _addEdge,   subMenuId );
1393     createMenu( _addQuad,   subMenuId );
1394     createMenu( _addHexa,   subMenuId );
1395     createMenu( _sep1, subMenuId);
1396
1397     // Pattern Builder
1398     createMenu( _addVector, subMenuId );
1399 //    createMenu( _addCylinder, subMenuId );
1400 //    createMenu( _addPipe, subMenuId );
1401
1402     createMenu( _sep2, subMenuId);
1403
1404     createMenu( _makeGrid,  subMenuId ); //Cartesian, Cylindrical, Spherical
1405     createMenu( _makeHemiSphere,subMenuId );
1406
1407     createMenu( _sep3, subMenuId);
1408
1409     createMenu( _makeCylinder, subMenuId );
1410     createMenu( _makePipe,     subMenuId );
1411     createMenu( _makeCylinders,subMenuId );
1412     createMenu( _makePipes,    subMenuId );
1413
1414     // Pattern Data Edition
1415     subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1416     createMenu( _removeHexa, subMenuId );
1417     createMenu( _prismQuad,  subMenuId );
1418     createMenu( _joinQuad,   subMenuId );
1419     createMenu( _merge,      subMenuId );
1420     createMenu( _disconnect, subMenuId );
1421     createMenu( _cutEdge,    subMenuId );
1422     createMenu( _makeTransformation, subMenuId );
1423     createMenu( _makeSymmetry,       subMenuId );
1424     createMenu( _performTransformation,   subMenuId );
1425     createMenu( _performSymmetry,         subMenuId );
1426     createMenu( _replaceHexa,    subMenuId );
1427     createMenu( _quadRevolution, subMenuId );
1428     createMenu( _sep4, aMenuId );
1429     createMenu( _showModelInfoAct, aMenuId );
1430
1431     // Association
1432     aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1433     createMenu( _addShapeAct, aMenuId );
1434     createMenu( _assocVertex, aMenuId );
1435     createMenu( _assocEdge,   aMenuId );
1436     createMenu( _assocQuad,   aMenuId );
1437
1438     // Group
1439     aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1440     createMenu( _addGroup,    aMenuId );
1441     createMenu( _removeGroup, aMenuId ); //CS_TODO
1442
1443     // Law
1444     aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1445     createMenu( _addLaw,    aMenuId );
1446     createMenu( _removeLaw, aMenuId );
1447     createMenu( _setPropagation, aMenuId );
1448     createMenu( _computeMesh, aMenuId );
1449
1450     //show model infomation menu
1451     QString aRule = "$component={'HEXABLOCK'}";
1452     popupMgr()->insert( _showModelInfoAct, -1, -1 );
1453     popupMgr()->setRule( _showModelInfoAct, aRule);
1454
1455     //associate shape to a document menu
1456     popupMgr()->insert( _addShapeAct, -1, -1 );
1457     popupMgr()->setRule( _addShapeAct, aRule );
1458
1459     //-------------------------------------------------
1460     // Display / Erase
1461     //-------------------------------------------------
1462     //  QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
1463     //  QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
1464     //  QString isNotEmpty("numberOfNodes <> 0");
1465     //  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
1466     //  QString aType = QString( "%1type in {%2}" ).arg( lc );
1467     ////  aType = aType.arg( mesh_part );
1468     //
1469     //  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
1470     //  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
1471     //  QString aSelCount = QString( "%1 > 0" ).arg( dc );
1472
1473 //    popupMgr()->insert( separator(), -1, -1 );
1474 //    QString aRule = "$component={'HEXABLOCK'}";/* and  ( type='(" + aClient + " and " +
1475 //                aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";*/
1476 //    //  MESSAGE("aClient = " << aClient.toStdString());
1477 //    //  MESSAGE("aType = " << aType.toStdString());
1478 //    //  MESSAGE("aSelCount = " << aSelCount.toStdString());
1479 //    //  MESSAGE("anActiveVTK = " << anActiveVTK.toStdString());
1480 //    //  MESSAGE("isNotEmpty = " << isNotEmpty.toStdString());
1481 //    //  MESSAGE("aRule = " << aRule.toStdString());
1482 //    popupMgr()->insert( _showAct, -1, -1 ); // DISPLAY
1483 //    popupMgr()->setRule( _showAct, aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
1484 //
1485 //    popupMgr()->insert( _hideAct, -1, -1 ); // ERASE
1486 //    popupMgr()->setRule( _hideAct, aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
1487 //
1488 //    popupMgr()->insert( _showOnlyAct, -1, -1 ); // DISPLAY_ONLY
1489 //    popupMgr()->setRule(_showOnlyAct, aRule.arg( "" ), QtxPopupMgr::VisibleRule );
1490 //
1491 //    popupMgr()->insert( separator(), -1, -1 );
1492 }
1493
1494
1495 void HEXABLOCKGUI::createTools()
1496 {
1497     int aToolId;
1498
1499     aToolId = createTool ( tr( "HexaBlock Toolbar" ), QString( "HexaBlockMain" ) );
1500     createTool( _newAct, aToolId );
1501     createTool( _importAct, aToolId );
1502     createTool( _saveAct, aToolId );
1503     createTool( _showModelInfoAct, aToolId );
1504     //   createTool( _testAct, aToolId );
1505     //createTool( separator(), aToolId );
1506
1507     // Pattern Data
1508     aToolId = createTool ( tr( "Construction" ), QString( "HexaBlockConstruction" ) );
1509     createTool( _addVertex, aToolId );
1510     createTool( _addEdge, aToolId );
1511     createTool( _addQuad, aToolId );
1512     createTool( _addHexa, aToolId );
1513
1514     createTool( _sep1, aToolId );
1515
1516     // Pattern Builder
1517     createTool( _addVector, aToolId );
1518 //    createTool( _addCylinder, aToolId );
1519 //    createTool( _addPipe, aToolId );
1520
1521     createTool( _sep2, aToolId );
1522
1523     createTool( _makeGrid,  aToolId );
1524     createTool( _makeHemiSphere,   aToolId );
1525
1526     createTool( _sep3, aToolId );
1527
1528     createTool( _makeCylinder, aToolId );
1529     createTool( _makePipe,     aToolId );
1530     createTool( _makeCylinders,aToolId );
1531     createTool( _makePipes,    aToolId );
1532
1533     // Pattern Data Edition
1534     aToolId = createTool ( tr( "Operation" ), QString( "HexaBlockOperation" ) );
1535     createTool( _removeHexa, aToolId );
1536     createTool( _prismQuad,  aToolId );
1537     createTool( _joinQuad,   aToolId );
1538     createTool( _merge,      aToolId );
1539     createTool( _disconnect, aToolId );
1540     createTool( _cutEdge,    aToolId );
1541     createTool( _makeTransformation, aToolId );
1542     createTool( _makeSymmetry,       aToolId );
1543     createTool( _performTransformation,   aToolId );
1544     createTool( _performSymmetry,         aToolId );
1545     createTool( _replaceHexa,    aToolId );
1546     createTool( _quadRevolution, aToolId );
1547
1548     // Association
1549     aToolId = createTool ( tr( "Association" ), QString( "HexaBlockAssociation" ) );
1550     createTool( _assocVertex, aToolId );
1551     createTool( _assocEdge, aToolId );
1552     createTool( _assocQuad, aToolId );
1553     createTool( _addShapeAct, aToolId );
1554
1555     // Group
1556     aToolId = createTool ( tr( "Group" ), QString( "HexaBlockGroup" ) );
1557     createTool( _addGroup,    aToolId );
1558     createTool( _removeGroup, aToolId ); //CS_TODO
1559
1560     // Law
1561     aToolId = createTool ( tr( "Mesh" ), QString( "HexaBlockMesh" ) );
1562     createTool( _addLaw,    aToolId );
1563     createTool( _removeLaw, aToolId );
1564     createTool( _setPropagation, aToolId );
1565     createTool( _computeMesh, aToolId );
1566
1567 }
1568
1569 void HEXABLOCKGUI::initialMenus()
1570 {
1571     showDocumentMenus( true );
1572     showPatternMenus( false );
1573     showAssociationMenus( false );
1574     showGroupsMenus( false );
1575     showMeshMenus( false );
1576 }
1577
1578 void HEXABLOCKGUI::showAllMenus()
1579 {
1580     showDocumentMenus( true );
1581     showPatternMenus( true );
1582     showAssociationMenus( true );
1583     showGroupsMenus( true );
1584     showMeshMenus( true );
1585 }
1586
1587 void HEXABLOCKGUI::setAllMenusEnabled(bool enable)
1588 {
1589     enableDocumentMenus( enable );
1590     enablePatternMenus( enable );
1591     enableAssociationMenus( enable );
1592     enableGroupsMenus( enable );
1593     enableMeshMenus( enable );
1594
1595     menusEnabled = enable;
1596 }
1597
1598 void HEXABLOCKGUI::showDocumentMenus(bool show)
1599 {
1600     DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1601     show = true; //
1602     setMenuShown(_newAct, show);
1603     setToolShown(_newAct, show);
1604     setMenuShown(_importAct, show);
1605     setToolShown(_importAct, show);
1606     setMenuShown(_showModelInfoAct, show);
1607     setToolShown(_showModelInfoAct, show);
1608     setMenuShown(_saveAct, show);
1609     setToolShown(_saveAct, show);
1610 }
1611
1612 void HEXABLOCKGUI::enableDocumentMenus(bool enable)
1613 {
1614     _newAct->setEnabled(enable);
1615 //    setToolShown(_newAct, enable);
1616
1617     _importAct->setEnabled(enable);
1618 //    setToolShown(_importAct, enable);
1619
1620     _showModelInfoAct->setEnabled(enable);
1621 //    setToolShown(_showModelInfoAct, enable);
1622
1623     _saveAct->setEnabled(enable);
1624 //    setToolShown(_saveAct, enable);
1625 }
1626
1627
1628 void HEXABLOCKGUI::showPatternMenus(bool show)
1629 {
1630     DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1631     DEBTRACE("getCurrentModel()  " << getCurrentModel()  );
1632     if ( show && !getCurrentModel() ) return;
1633
1634     setMenuShown(_addVertex, show );
1635     setToolShown(_addVertex, show);
1636     setMenuShown(_addEdge,  show );
1637     setToolShown(_addEdge, show);
1638     setMenuShown(_addQuad,  show );
1639     setToolShown(_addQuad, show);
1640     setMenuShown(_addHexa,  show );
1641     setToolShown(_addHexa, show);
1642
1643     setMenuShown(_sep1, show );
1644     setToolShown(_sep1, show);
1645
1646     setMenuShown( _addVector,  show );
1647     setToolShown( _addVector, show);
1648 //    setMenuShown( _addCylinder,  show );
1649 //    setToolShown( _addCylinder, show);
1650 //    setMenuShown( _addPipe,  show );
1651 //    setToolShown( _addPipe, show);
1652
1653     setMenuShown(_sep2, show );
1654     setToolShown(_sep2, show);
1655
1656     setMenuShown( _makeGrid,  show );
1657     setToolShown( _makeGrid, show);
1658     setMenuShown( _makePipe,  show );
1659     setToolShown( _makePipe, show);
1660
1661     setMenuShown(_sep3, show );
1662     setToolShown(_sep3, show);
1663
1664     setMenuShown( _makeCylinder,  show );
1665     setToolShown( _makeCylinder, show);
1666     setMenuShown( _makeCylinders,  show );
1667     setToolShown( _makeCylinders, show);
1668     setMenuShown( _makePipes,  show );
1669     setToolShown( _makePipes, show);
1670     setMenuShown( _makeHemiSphere,  show );
1671     setToolShown( _makeHemiSphere, show);
1672
1673     // Pattern Data Edition
1674     setMenuShown( _removeHexa,  show );
1675     setToolShown( _removeHexa, show);
1676     setMenuShown( _prismQuad,  show );
1677     setToolShown( _prismQuad, show);
1678     setMenuShown( _joinQuad,  show );
1679     setToolShown( _joinQuad, show);
1680     setMenuShown( _merge,  show );
1681     setToolShown( _merge, show);
1682     setMenuShown( _disconnect,  show );
1683     setToolShown( _disconnect, show);
1684     setMenuShown( _cutEdge,  show );
1685     setToolShown( _cutEdge, show);
1686     setMenuShown( _makeTransformation,  show );
1687     setToolShown( _makeTransformation, show);
1688     setMenuShown( _makeSymmetry,  show );
1689     setToolShown( _makeSymmetry, show);
1690     setMenuShown( _performTransformation,  show );
1691     setToolShown( _performTransformation, show);
1692     setMenuShown( _performSymmetry,  show );
1693     setToolShown( _performSymmetry, show);
1694     setMenuShown( _replaceHexa,  show );
1695     setToolShown( _replaceHexa, show);
1696     setMenuShown( _quadRevolution,  show );
1697     setToolShown( _quadRevolution, show);
1698
1699     setMenuShown( _sep4, show );
1700     setMenuShown( _showModelInfoAct, show );
1701 }
1702
1703 void HEXABLOCKGUI::enablePatternMenus(bool enable)
1704 {
1705     if ( enable && !getCurrentModel() ) return;
1706
1707     _addVertex->setEnabled(enable);
1708 //    setToolShown(_addVertex, enable);
1709
1710     _addEdge->setEnabled(enable);
1711 //    setToolShown(_addEdge, enable);
1712
1713     _addQuad->setEnabled(enable);
1714 //    setToolShown(_addQuad, enable);
1715
1716     _addHexa->setEnabled(enable);
1717 //    setToolShown(_addHexa, enable);
1718
1719 //    setMenuShown(_sep1, enable );
1720 //    setToolShown(_sep1, enable);
1721
1722     _addVector->setEnabled(enable);
1723 //    setToolShown( _addVector, enable);
1724
1725 //    setMenuShown(_sep2, enable );
1726 //    setToolShown(_sep2, enable);
1727
1728     _makeGrid->setEnabled(enable);
1729 //    setToolShown( _makeGrid, enable);
1730
1731     _makePipe->setEnabled(enable);
1732 //    setToolShown( _makePipe, enable);
1733
1734 //    setMenuShown(_sep3, enable );
1735 //    setToolShown(_sep3, enable);
1736
1737     _makeCylinder->setEnabled(enable);
1738 //    setToolShown( _makeCylinder, enable);
1739
1740     _makeCylinders->setEnabled(enable);
1741 //    setToolShown( _makeCylinders, enable);
1742
1743     _makePipes->setEnabled(enable);
1744 //    setToolShown( _makePipes, enable);
1745
1746     _makeHemiSphere->setEnabled(enable);
1747 //    setToolShown( _makeHemiSphere, enable);
1748
1749     // Pattern Data Edition
1750     _removeHexa->setEnabled(enable);
1751 //    setToolShown( _removeHexa, enable);
1752
1753     _prismQuad->setEnabled(enable);
1754 //    setToolShown( _prismQuad, enable);
1755
1756     _joinQuad->setEnabled(enable);
1757 //    setToolShown( _joinQuad, enable);
1758
1759     _merge->setEnabled(enable);
1760 //    setToolShown( _merge, enable);
1761
1762     _disconnect->setEnabled(enable);
1763 //    setToolShown( _disconnect, enable);
1764
1765     _cutEdge->setEnabled(enable);
1766 //    setToolShown( _cutEdge, enable);
1767
1768     _makeTransformation->setEnabled(enable);
1769 //    setToolShown( _makeTransformation, enable);
1770
1771     _makeSymmetry->setEnabled(enable);
1772 //    setToolShown( _makeSymmetry, enable);
1773
1774     _performTransformation->setEnabled(enable);
1775 //    setToolShown( _performTransformation, enable);
1776
1777     _performSymmetry->setEnabled(enable);
1778 //    setToolShown( _performSymmetry, enable);
1779
1780     _replaceHexa->setEnabled(enable);
1781 //    setToolShown( _replaceHexa, enable);
1782
1783     _quadRevolution->setEnabled(enable);
1784 //    setToolShown( _quadRevolution, enable);
1785
1786 //    setMenuShown( _sep4, enable );
1787     _showModelInfoAct->setEnabled(enable);
1788 }
1789
1790
1791 void HEXABLOCKGUI::showAssociationMenus(bool show)
1792 {
1793     DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1794     if ( show && !getCurrentModel() ) return;
1795
1796     // Association Edition
1797     setMenuShown( _assocVertex,  show );
1798     setToolShown( _assocVertex, show );
1799
1800     setMenuShown( _assocEdge,  show );
1801     setToolShown( _assocEdge, show );
1802
1803     setMenuShown( _assocQuad,  show );
1804     setToolShown( _assocQuad, show );
1805
1806     setMenuShown( _addShapeAct, show );
1807     setToolShown( _addShapeAct, show );
1808 }
1809
1810 void HEXABLOCKGUI::enableAssociationMenus(bool enable)
1811 {
1812     if ( enable && !getCurrentModel() )
1813         return;
1814
1815     // Association Edition
1816      _assocVertex->setEnabled(enable);
1817  //    setToolShown( _assocVertex, enable );
1818
1819      _assocEdge->setEnabled(enable);
1820  //    setToolShown( _assocEdge, enable );
1821
1822      _assocQuad->setEnabled(enable);
1823  //    setToolShown( _assocQuad, enable );
1824
1825      _addShapeAct->setEnabled(enable);
1826  //    setToolShown( _addShapeAct, enable );
1827 }
1828
1829 void HEXABLOCKGUI::showGroupsMenus(bool show)
1830 {
1831     DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1832     if ( show && !getCurrentModel() ) return;
1833     setMenuShown( _addGroup,  show );
1834     setToolShown( _addGroup, show);
1835     setMenuShown( _removeGroup ,  show );
1836     setToolShown( _removeGroup , show);
1837 }
1838
1839 void HEXABLOCKGUI::enableGroupsMenus(bool enable)
1840 {
1841     if ( enable && !getCurrentModel() )
1842         return;
1843
1844     _addGroup->setEnabled(enable);
1845 //    setToolShown( _addGroup, enable);
1846
1847     _removeGroup->setEnabled(enable);
1848 //    setToolShown( _removeGroup , enable);
1849 }
1850
1851 void HEXABLOCKGUI::showMeshMenus(bool show)
1852 {
1853     DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1854     if ( show && !getCurrentModel() ) return;
1855     setMenuShown( _addLaw,  show );
1856     setToolShown( _addLaw, show);
1857     setMenuShown( _removeLaw,  show );
1858     setToolShown( _removeLaw, show);;
1859     setMenuShown( _setPropagation,  show );
1860     setToolShown( _setPropagation, show);
1861     setMenuShown( _computeMesh, show);
1862     setToolShown( _computeMesh, show);
1863 }
1864
1865 void HEXABLOCKGUI::enableMeshMenus(bool enable)
1866 {
1867     if ( enable && !getCurrentModel() )
1868         return;
1869
1870     _addLaw->setEnabled(enable);
1871 //    setToolShown( _addLaw, enable);
1872
1873     _removeLaw->setEnabled(enable);
1874 //    setToolShown( _removeLaw, enable);
1875
1876     _setPropagation->setEnabled(enable);
1877 //    setToolShown( _setPropagation, enable);
1878
1879     _computeMesh->setEnabled(enable);
1880 //    setToolShown( _computeMesh, enable);
1881 }
1882
1883 void HEXABLOCKGUI::showVtkActor()
1884 {
1885     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1886     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1887             currentVtkGView->getDocumentActor() == NULL)
1888         return;
1889
1890     SVTK_ViewWindow* vtkView = currentVtkGView->getViewWindow();
1891     if (vtkView == NULL)
1892         return;
1893
1894     SUIT_ViewManager* vman = vtkView->getViewManager();
1895     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1896
1897     //show only the current actor -----------------
1898     vtkView->setFocus();
1899     //    vtkView->DisplayOnly(currentVtkGView->getDocumentActor()->getIO());
1900     Document_Actor *lastDocActor;
1901     if (lastVtkDocGView != NULL)
1902     {
1903         lastDocActor = lastVtkDocGView->getDocumentActor();
1904         Handle(SALOME_InteractiveObject) lastActorIO = lastDocActor->getIO();
1905         if (!lastActorIO.IsNull() && lastActorIO->hasEntry())
1906         {
1907             vtkView->Erase(lastActorIO);
1908             aStudy->setObjectProperty(vman->getId(), lastActorIO->getEntry(),  "Visibility", 0 );
1909             displayer()->setVisibilityState(lastActorIO->getEntry(), Qtx::HiddenState);
1910         }
1911     }
1912     currentVtkGView->update();
1913     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1914     if (!anIO.IsNull() && anIO->hasEntry())
1915     {
1916         vtkView->Display(anIO);
1917         aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 1 );
1918         displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1919     }
1920     vtkView->onFitAll();
1921 }
1922
1923 void HEXABLOCKGUI::showOccActor()
1924 {
1925     if (currentOccGView == NULL)
1926         return;
1927     OCCViewer_ViewWindow* occView = currentOccGView->getViewWindow();
1928     if (occView == NULL)
1929         return;
1930     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1931     if (vf == NULL)
1932         return;
1933
1934     if (lastOccPrs != NULL)
1935         vf->Erase(lastOccPrs);
1936     currentOccGView->globalSelection();
1937     SOCC_Prs* prs = getOccPrs(currentDocGView);
1938     currentOccGView->setPrs(prs);
1939     vf->Display(prs);
1940     vf->Repaint();
1941     occView->onFitAll();
1942 }
1943
1944 void HEXABLOCKGUI::hideVtkActor()
1945 {
1946     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1947     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1948         currentVtkGView->getViewWindow() == NULL ||
1949         currentVtkGView->getDocumentActor() == NULL) return;
1950
1951     currentVtkGView->getViewWindow()->Erase(currentVtkGView->getDocumentActor()->getIO());
1952     currentVtkGView->getViewWindow()->onResetView();
1953
1954     //update the visibility state now
1955     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1956     SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1957     if (aStudy == NULL || vman == NULL) return;
1958
1959     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1960     aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 0 );
1961     displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1962 }
1963
1964 void HEXABLOCKGUI::hideOccActor()
1965 {
1966     OCCViewer_ViewWindow* occView = currentOccGView == NULL ? NULL : currentOccGView->getViewWindow();
1967     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1968     DocumentModel* docModel = (currentVtkGView == NULL ? NULL : currentVtkGView->getDocumentModel());
1969     if (occView == NULL || docModel == NULL)
1970         return;
1971     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1972     if (vf == NULL)
1973         return;
1974
1975     SOCC_Prs* currentOccPrs = getOccPrs(currentDocGView);
1976     if (currentOccPrs != NULL)
1977         vf->Erase(currentOccPrs);
1978     vf->Repaint();
1979     occView->onResetView();
1980 }
1981
1982 void HEXABLOCKGUI::showOnlyActor()
1983 {
1984     showVtkActor();
1985     showOccActor();
1986 }
1987
1988 void HEXABLOCKGUI::hideActor()
1989 {
1990     hideVtkActor();
1991     hideOccActor();
1992 }
1993
1994
1995 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1996 {
1997     DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1998
1999     if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
2000
2001     if (_dwPattern) _dwPattern->setVisible(isVisible);
2002     if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
2003
2004     if (_dwMesh) _dwMesh->setVisible(isVisible);
2005     if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
2006
2007     if (_dwGroups) _dwGroups->setVisible(isVisible);
2008     if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
2009 }
2010
2011
2012 //clear all used dialogs by the current model
2013 void HEXABLOCKGUI::clearDialogs()
2014 {
2015     std::set<HexaBaseDialog*>::const_iterator debut (currentModelDialogs.begin()),
2016                                               fin   (currentModelDialogs.end());
2017     for(;debut!=fin;++debut) (*debut)->clear();
2018
2019     currentModelDialogs.clear(); //empty the used dialogs list
2020 }
2021
2022 HexaBaseDialog* HEXABLOCKGUI::getDlgBox(VtkDocumentGraphicView* dgview)
2023 {
2024     if (!gViewDlgBox.contains(dgview)) return NULL;
2025     return gViewDlgBox[dgview];
2026 }
2027
2028 void HEXABLOCKGUI::switchOnGraphicView(VtkDocumentGraphicView* dgview)
2029 {
2030    if (dgview == NULL) return;
2031
2032    switchOffGraphicView(dgview, false); //to avoid double connect
2033
2034    //connect signals
2035    connect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2036          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ), Qt::UniqueConnection );
2037    connect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2038          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2039 //   connect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2040 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2041    connect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2042             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2043    connect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2044          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2045    connect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2046          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
2047
2048    showAllMenus();
2049 }
2050
2051 void HEXABLOCKGUI::switchOffGraphicView(VtkDocumentGraphicView* dgview, bool saveCurrentDlg)
2052 {
2053    if (dgview == NULL) return;
2054
2055    //disconnect signals
2056    disconnect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
2057          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ) );
2058    disconnect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2059          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2060 //   disconnect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2061 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2062    disconnect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2063             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2064    disconnect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2065          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2066    disconnect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2067          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2068
2069    if (saveCurrentDlg)
2070        gViewDlgBox[dgview] = currentDialog;
2071
2072    //close opened dialog
2073    if (currentDialog != NULL) currentDialog->close();
2074 //   if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2075
2076    initialMenus();
2077
2078 }
2079
2080 void HEXABLOCKGUI::switchModel(VtkDocumentGraphicView* dgview)
2081 {
2082     DEBTRACE("HEXABLOCKGUI::switchModel " << dgview);
2083
2084     if (dgview == NULL)
2085     {
2086         MESSAGE("HEXABLOCKGUI::switchModel : no need to switch!");
2087         return;
2088     }
2089
2090     //switch off the current document graphic view (disconnect signals...)
2091     if (currentDocGView != NULL)
2092     {
2093         //Hide current actor
2094         hideActor();
2095         switchOffGraphicView(currentDocGView);
2096     }
2097
2098     //clear the dialogs used by the current model so they can be used by the new model
2099     if (currentDocGView != dgview) clearDialogs();
2100
2101     _patternDataTreeView->setModel(dgview->getPatternDataModel());
2102 //    _patternBuilderTreeView->setModel(dgview->getPatternBuilderModel());
2103     _patternGeomTreeView->setModel(dgview->getPatternGeomModel());
2104     _groupsTreeView->setModel(dgview->getGroupsModel());
2105     _meshTreeView->setModel(dgview->getMeshModel());
2106
2107     _patternDataTreeView->setSelectionModel(dgview->getPatternDataSelectionModel());
2108     _patternDataTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2109
2110 //    _patternBuilderTreeView->setSelectionModel(dgview->getPatternBuilderSelectionModel());
2111 //    _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
2112
2113     _patternGeomTreeView->setSelectionModel(dgview->getPatternGeomSelectionModel());
2114     _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2115
2116     _groupsTreeView->setSelectionModel(dgview->getGroupsSelectionModel());
2117     _groupsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2118
2119     _meshTreeView->setSelectionModel(dgview->getMeshSelectionModel());
2120     _meshTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
2121
2122
2123     // = * init occ view * =
2124     if (currentOccGView != NULL && currentOccGView->getViewWindow() == NULL)
2125     {
2126         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2127         currentOccGView->getViewWindow()->installEventFilter(this);
2128     }
2129     // ==
2130
2131
2132     // = * init vtk view * =
2133     if (currentDocGView != NULL)
2134     {
2135         if (currentDocGView->getViewWindow() != NULL)
2136             dgview->setViewWindow(currentDocGView->getViewWindow());
2137         else
2138         {
2139             dgview->setViewWindow(graphicViewsHandler->createVtkWindow());
2140             dgview->getViewWindow()->installEventFilter(this);
2141         }
2142     }
2143
2144     // ==
2145
2146     switchOnGraphicView(dgview);
2147
2148     if (currentDocGView != NULL)
2149     {
2150         lastVtkDocGView = currentDocGView;
2151         lastOccPrs = getOccPrs(currentDocGView);
2152     }
2153     else
2154     {
2155         lastVtkDocGView = dgview;
2156         lastOccPrs = getOccPrs(dgview);
2157     }
2158
2159     currentDocGView = dgview;
2160     showOnlyActor();
2161     currentDocGView->getDocumentModel()->refresh();
2162 //    _dwPattern->setWindowTitle(currentDocGView->getDocumentModel()->getName());
2163     showAllMenus();
2164     if (!menusEnabled)
2165         setAllMenusEnabled(true);
2166 }
2167
2168 DocumentModel* HEXABLOCKGUI::getCurrentModel()
2169 {
2170     if (currentDocGView == NULL) return NULL;
2171     return currentDocGView->getDocumentModel();
2172 }
2173
2174
2175 HEXABLOCKGUI::ViewType HEXABLOCKGUI::getActiveViewType()
2176 {
2177     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2178     if (anApp == NULL) return UNKNOWN;
2179     SUIT_ViewManager* activeVm = anApp->activeViewManager();
2180     if (activeVm == NULL) return UNKNOWN;
2181
2182    QString vmType = activeVm->getType();
2183    if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
2184        return VTK;
2185    else if ( vmType == OCCViewer_Viewer::Type() )
2186        return OCC;
2187
2188    return UNKNOWN;
2189 }
2190
2191 HEXABLOCKGUI* HEXABLOCKGUI::getInstance()
2192 {
2193     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2194     if (anApp == NULL)
2195         return NULL;
2196
2197     return  dynamic_cast<HEXABLOCKGUI*>(anApp->activeModule());
2198 }
2199
2200 pair <QString, HEXA_NS::Document*> HEXABLOCKGUI::newHexaDocument()
2201 {
2202     // Create Document from HEXABLOCK ENGINE
2203     // WARNING : IN HEXABLOCK component,  GUI and ENGINE share the same process
2204     // HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default"); // Perime  Hexa6
2205
2206     // looking doc impl ( c++ )
2207     // ^Hexa6 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2208     // ^Hexa6 ASSERT( dServant );
2209     // ^Hexa6 if ( dServant)
2210         // ^Hexa6 doc = dServant->GetImpl();
2211
2212     HEXA_NS::Document* doc = hexa_root->addDocument ("default");
2213     QString docEntry = addDocInStudy (doc);
2214
2215     // looking for docEntry
2216     /* ****************************************************************
2217     if ( !CORBA::is_nil(docIn) ){
2218         CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2219         QString docIOR = anIOR.in();
2220         SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2221         if ( !docIOR.isEmpty() ) {
2222             _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2223             if ( SO )
2224                 docEntry = SO->GetID().c_str();
2225         }
2226     }
2227        **************************************************************** */
2228     DEBTRACE("HEXABLOCKGUI::newHexaDocument docEntry "<<docEntry.toStdString());
2229
2230     return make_pair (docEntry, doc);
2231 }
2232
2233
2234 void HEXABLOCKGUI::newDocument()
2235 {
2236     DEBTRACE("HEXABLOCKGUI::newDocument");
2237
2238     createSComponent();
2239     QMainWindow *aParent = application()->desktop();
2240     QWidget *central = aParent->centralWidget();
2241     if (central)
2242         central->setFocus();
2243     else
2244         DEBTRACE("No Central Widget");
2245
2246     //Init OCC
2247     if (currentOccGView == NULL)
2248     {
2249         currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
2250                 application()->desktop());
2251         currentOccGView->getViewWindow()->installEventFilter(this);
2252     }
2253     else if (currentOccGView->getViewWindow() == NULL)
2254     {
2255         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2256         currentOccGView->getViewWindow()->installEventFilter(this);
2257     }
2258
2259     //NEW DOCUMENT
2260     // Create Document from HEXABLOCK ENGINE
2261     pair <QString, HEXA_NS::Document*> docEntry_Doc ( newHexaDocument() );
2262
2263     VtkDocumentGraphicView* newGraphicView = NULL;
2264     //One document at a time
2265     if (currentDocGView != NULL)
2266     {
2267         if (currentDocGView->getViewWindow() == NULL)
2268         {
2269             currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2270             currentDocGView->getViewWindow()->installEventFilter(this);
2271         }
2272
2273           // Create a new document with the current window
2274           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2275                                         new DocumentModel( docEntry_Doc.second,
2276                                         docEntry_Doc.first, this ),
2277                                         currentDocGView->getViewWindow(),
2278                                         application()->desktop() );
2279     }
2280     else
2281     {
2282           // Create the new Document Graphic View with a new window
2283           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2284                                         new DocumentModel( docEntry_Doc.second,
2285                                         docEntry_Doc.first, this ),
2286                                         graphicViewsHandler->createVtkWindow(),
2287                                         application()->desktop() );
2288           newGraphicView->getViewWindow()->installEventFilter(this);
2289     }
2290
2291     if (newGraphicView == NULL)
2292         //We couldn't create a new document graphic view
2293         //we'd better show a dialog box info to inform the user
2294         return;
2295
2296     docs[docEntry_Doc.first] = newGraphicView;
2297     switchModel(newGraphicView); //select the corresponding document in the browser instead
2298
2299     getApp()->updateObjectBrowser();
2300     showAllMenus();
2301 }
2302
2303
2304 //Loads the model from the xmlFile in the current graphic view
2305 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2306 {
2307     DEBTRACE("HEXABLOCKGUI::loadDocument");
2308
2309     createSComponent();
2310     QMainWindow *aParent = application()->desktop();
2311     QString selectedFile;
2312
2313     if ( inFile.isNull() ){
2314         QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2315                 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2316         dialog.setHistory( getQuickDirList() );
2317
2318         //use the last path as default
2319         if (!(loadDocLastPath->absolutePath()).isEmpty())
2320             dialog.setDirectory(*loadDocLastPath);
2321
2322         if (dialog.exec()){
2323             QStringList selectedFiles = dialog.selectedFiles();
2324             if (!selectedFiles.isEmpty())
2325                 selectedFile = selectedFiles.first();
2326
2327             //remember the selected path
2328             *loadDocLastPath = dialog.directory();
2329         }
2330     } else
2331         selectedFile = inFile;
2332
2333     if (selectedFile.isEmpty())
2334         return;
2335
2336     //we create a new document if necessary
2337     if (currentDocGView == NULL)
2338         //Need a new document
2339         newDocument();
2340     else if (currentDocGView->getViewWindow() == NULL) //there's a document without a view
2341     {
2342         currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2343         currentDocGView->getViewWindow()->installEventFilter(this);
2344     }
2345
2346     if (!currentDocGView->isEmpty())
2347         //we can only have one document for a graphic view
2348         newDocument();
2349
2350     //we load the selected file in the current graphic view
2351     currentDocGView->loadDocument(selectedFile);
2352     DocumentModel* currentModel = getCurrentModel();
2353     renameObject( currentModel->documentEntry(), currentModel->getName() );
2354
2355     showOnlyActor();
2356 }
2357
2358 void HEXABLOCKGUI::saveDocument()
2359 {
2360     QMainWindow *aParent = application()->desktop();
2361
2362     QString aDocName = "document", aFilename;
2363     QStringList filter;
2364     filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2365     filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2366
2367     //use the last selected directory as default path for file selection
2368     aFilename =  saveDocLastPath->absolutePath();
2369     if (!aFilename.isEmpty())
2370         aFilename += QString("/") + aDocName;
2371
2372     //show the dialog for file selection
2373     aFilename = SUIT_FileDlg::getFileName( aParent,
2374             aFilename,
2375             filter,
2376             tr( "Save HexaBlock Document" ),
2377             false );
2378
2379     //save the document in the selected file
2380     if ( !aFilename.isEmpty() ) {
2381         getCurrentVtkGraphicView()->saveDocument( aFilename );
2382
2383         //Remember the path for next save
2384         QFileInfo fileInfo(aFilename);
2385         *saveDocLastPath = fileInfo.dir();
2386     }
2387     //CS_TODO save doc
2388 }
2389
2390
2391 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight)
2392 {
2393     _patternDataTreeView->openPersistentEditor( topLeft );
2394 }
2395
2396 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2397 {
2398     if (diag == NULL || _dwInputPanel == NULL ||
2399             getCurrentVtkGraphicView() == NULL) return;
2400
2401     //mark this dialog as used by the current model
2402     currentModelDialogs.insert(diag);
2403
2404     //close the current dialog box info
2405 //    if (_treeViewDelegate != NULL)
2406 //        _treeViewDelegate->closeDialog();
2407
2408 //    if (_dwInputPanel->widget())
2409 //        _dwInputPanel->widget()->close();
2410
2411     //Temporary for debugging EdgeAssoc Faked InfoDialog
2412     if (diag == _edgeAssocDiag)
2413         diag->debugEdgeAssoc = true;
2414     else
2415         diag->debugEdgeAssoc = false;
2416
2417     if (diag == _vertexAssocDiag || diag ==  _edgeAssocDiag ||
2418                 diag ==  _quadAssocDiag || diag == _addShapeDiag)
2419         assocInProgress = true;
2420     else
2421         assocInProgress = false;
2422
2423     //show the dialog box in the dockwidget
2424     diag->resetSizeAndShow(_dwInputPanel);
2425
2426     //clear the current selections
2427     selectionMgr()->clearSelected();
2428
2429     currentDialog = diag;
2430     diag->setFocus();
2431
2432     if (currentDocGView != NULL)
2433         currentDocGView->getPatternDataSelectionModel()->setInfoMode(false);
2434 }
2435
2436 void HEXABLOCKGUI::showVertexInfoDialog(HEXA_NS::Vertex* vertex)
2437 {
2438     if (vertex == NULL || _dwInputPanel == NULL)
2439         return;
2440
2441     if (_vertexInfoDialog == NULL)
2442         _vertexInfoDialog = new VertexDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2443
2444     _vertexInfoDialog->setValue(vertex);
2445     _vertexInfoDialog->resetSizeAndShow(_dwInputPanel);
2446     currentDialog = _vertexInfoDialog;
2447 }
2448
2449 void HEXABLOCKGUI::showEdgeInfoDialog(HEXA_NS::Edge* edge)
2450 {
2451     if (edge == NULL || _dwInputPanel == NULL)
2452         return;
2453
2454     if (_edgeInfoDialog == NULL)
2455         _edgeInfoDialog = new EdgeDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2456
2457     _edgeInfoDialog->setValue(edge);
2458     _edgeInfoDialog->resetSizeAndShow(_dwInputPanel);
2459     currentDialog = _edgeInfoDialog;
2460 }
2461
2462 void HEXABLOCKGUI::showQuadInfoDialog(HEXA_NS::Quad* quad)
2463 {
2464     if (quad == NULL || _dwInputPanel == NULL)
2465         return;
2466
2467     if (_quadInfoDialog == NULL)
2468         _quadInfoDialog = new QuadDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2469
2470     _quadInfoDialog->setValue(quad);
2471     _quadInfoDialog->resetSizeAndShow(_dwInputPanel);
2472     currentDialog = _quadInfoDialog;
2473 }
2474
2475 void HEXABLOCKGUI::showHexaInfoDialog(HEXA_NS::Hexa* hexa)
2476 {
2477     if (hexa == NULL || _dwInputPanel == NULL)
2478         return;
2479
2480     if (_hexaInfoDialog == NULL)
2481         _hexaInfoDialog = new HexaDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2482
2483     _hexaInfoDialog->setValue(hexa);
2484     _hexaInfoDialog->resetSizeAndShow(_dwInputPanel);
2485     currentDialog = _hexaInfoDialog;
2486 }
2487
2488 void HEXABLOCKGUI::showVectorInfoDialog(HEXA_NS::Vector* vector)
2489 {
2490     if (vector == NULL || _dwInputPanel == NULL)
2491         return;
2492
2493     if (_vectorInfoDialog == NULL)
2494         _vectorInfoDialog = new VectorDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2495
2496     _vectorInfoDialog->setValue(vector);
2497     _vectorInfoDialog->resetSizeAndShow(_dwInputPanel);
2498     currentDialog = _vectorInfoDialog;
2499 }
2500
2501 void HEXABLOCKGUI::showGroupInfoDialog(HEXA_NS::Group* group)
2502 {
2503     if (group == NULL || _dwInputPanel == NULL)
2504         return;
2505
2506     if (_groupInfoDialog == NULL)
2507         _groupInfoDialog = new GroupDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2508
2509     _groupInfoDialog->setValue(group);
2510     _groupInfoDialog->resetSizeAndShow(_dwInputPanel);
2511     currentDialog = _groupInfoDialog;
2512 }
2513
2514 void HEXABLOCKGUI::showLawInfoDialog(HEXA_NS::Law* law)
2515 {
2516     if (law == NULL || _dwInputPanel == NULL)
2517         return;
2518
2519     if (_lawInfoDialog == NULL)
2520         _lawInfoDialog = new LawDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2521
2522     _lawInfoDialog->setValue(law);
2523     _lawInfoDialog->resetSizeAndShow(_dwInputPanel);
2524     currentDialog = _lawInfoDialog;
2525 }
2526
2527 void HEXABLOCKGUI::showPropagationInfoDialog(HEXA_NS::Propagation* propagation)
2528 {
2529     if (propagation == NULL || _dwInputPanel == NULL)
2530         return;
2531
2532     if (_propagationInfoDialog == NULL)
2533         _propagationInfoDialog = new PropagationDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2534
2535     _propagationInfoDialog->setValue(propagation);
2536     _propagationInfoDialog->resetSizeAndShow(_dwInputPanel);
2537     currentDialog = _propagationInfoDialog;
2538 }
2539
2540 void HEXABLOCKGUI::addVertex()
2541 {
2542     if ( !_vertexDiag ){
2543         _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2544     }
2545     _showDialogBox( _vertexDiag );
2546
2547     //set default name
2548     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2549     if (_vertexDiag != NULL && doc != NULL)
2550         _vertexDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VERTEX).c_str());
2551 }
2552
2553 void HEXABLOCKGUI::addEdge()
2554 {
2555     if ( !_edgeDiag ){
2556         _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2557     }
2558     _showDialogBox( _edgeDiag );
2559
2560     //set default name
2561     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2562     if (_edgeDiag != NULL && doc != NULL)
2563         _edgeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_EDGE).c_str());
2564 }
2565
2566 void HEXABLOCKGUI::addQuad()
2567 {
2568     if ( !_quadDiag ){
2569         _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2570
2571     }
2572     _showDialogBox( _quadDiag );
2573
2574     //set default name
2575     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2576     if (_quadDiag != NULL && doc != NULL)
2577         _quadDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_QUAD).c_str());
2578 }
2579
2580 void HEXABLOCKGUI::addHexa()
2581 {
2582     if ( !_hexaDiag ){
2583         _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2584     }
2585     _showDialogBox( _hexaDiag );
2586
2587     //set default name
2588     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2589     if (_hexaDiag != NULL && doc != NULL)
2590         _hexaDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_HEXA).c_str());
2591 }
2592
2593 void HEXABLOCKGUI::addVector()
2594 {
2595     if ( !_vectorDiag ){
2596         _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2597     }
2598     _showDialogBox( _vectorDiag );
2599
2600     //set default name
2601     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2602     if (_vectorDiag != NULL && doc != NULL)
2603         _vectorDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VECTOR).c_str());
2604 }
2605
2606 //void HEXABLOCKGUI::addCylinder()
2607 //{
2608 //    if ( !_cylinderDiag ){
2609 //        _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2610 //    }
2611 //    _showDialogBox( _cylinderDiag );
2612 //
2613 //    //set default name
2614 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2615 //    if (_cylinderDiag != NULL && doc != NULL)
2616 //        _cylinderDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2617 //}
2618
2619
2620 //void HEXABLOCKGUI::addPipe()
2621 //{
2622 //    if ( !_pipeDiag){
2623 //        _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2624 //    }
2625 //    _showDialogBox( _pipeDiag );
2626 //
2627 //    //set default name
2628 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2629 //    if (_pipeDiag != NULL && doc != NULL)
2630 //        _pipeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2631 //}
2632
2633
2634 void HEXABLOCKGUI::makeGrid()
2635 {
2636     if ( !_makeGridDiag ){
2637         _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2638     }
2639     _showDialogBox( _makeGridDiag );
2640 }
2641
2642
2643 void HEXABLOCKGUI::makeCylinder()
2644 {
2645     if ( !_makeCylinderDiag ){
2646         _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2647     }
2648     _showDialogBox( _makeCylinderDiag );
2649 }
2650
2651 void HEXABLOCKGUI::makePipe()
2652 {
2653     if ( !_makePipeDiag ){
2654         _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2655     }
2656     _showDialogBox( _makePipeDiag );
2657 }
2658
2659 void HEXABLOCKGUI::makeCylinders()
2660 {
2661     if ( !_makeCylindersDiag ){
2662         _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2663     }
2664     _showDialogBox( _makeCylindersDiag );
2665 }
2666
2667 void HEXABLOCKGUI::makePipes()
2668 {
2669     if ( !_makePipesDiag ){
2670         _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2671     }
2672     _showDialogBox( _makePipesDiag );
2673 }
2674
2675
2676 void HEXABLOCKGUI::makeHemiSphere()  // NEW HEXA3
2677 {
2678     if ( !_makeHemiSphereDiag ){
2679         _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2680     }
2681     _showDialogBox( _makeHemiSphereDiag );
2682 }
2683
2684
2685 void HEXABLOCKGUI::removeHexa()
2686 {
2687     if ( !_removeHexaDiag ){
2688         _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2689     }
2690     _showDialogBox( _removeHexaDiag );
2691 }
2692
2693
2694 void HEXABLOCKGUI::prismQuad()
2695 {
2696     if ( !_prismQuadDiag ){
2697         _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2698     }
2699     _showDialogBox( _prismQuadDiag );
2700 }
2701
2702
2703 void HEXABLOCKGUI::joinQuad()
2704 {
2705     if ( !_joinQuadDiag ){
2706         _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2707     }
2708     _showDialogBox( _joinQuadDiag );
2709 }
2710
2711 void HEXABLOCKGUI::merge()
2712 {
2713     if ( !_mergeDiag ){
2714         _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2715     }
2716     _showDialogBox( _mergeDiag );
2717 }
2718
2719 void HEXABLOCKGUI::disconnectElts()
2720 {
2721     if ( !_disconnectDiag ){
2722         _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2723     }
2724     _showDialogBox( _disconnectDiag );
2725 }
2726
2727 void HEXABLOCKGUI::cutEdge()
2728 {
2729     if ( !_cutEdgeDiag ){
2730         _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2731     }
2732     _showDialogBox( _cutEdgeDiag );
2733 }
2734
2735 void HEXABLOCKGUI::makeTransformation()
2736 {
2737     if ( !_makeTransformationDiag ){
2738         _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2739     }
2740     _showDialogBox( _makeTransformationDiag );
2741 }
2742
2743
2744 void HEXABLOCKGUI::makeSymmetry()
2745 {
2746     if ( !_makeSymmetryDiag ){
2747         _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2748     }
2749     _showDialogBox( _makeSymmetryDiag );
2750 }
2751
2752
2753 void HEXABLOCKGUI::performTransformation()
2754 {
2755     if ( !_performTransformationDiag ){
2756         _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2757     }
2758     _showDialogBox( _performTransformationDiag );
2759 }
2760
2761
2762 void HEXABLOCKGUI::performSymmetry()
2763 {
2764     if ( !_performSymmetryDiag ){
2765         _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2766     }
2767     _showDialogBox( _performSymmetryDiag );
2768 }
2769
2770
2771 void HEXABLOCKGUI::replaceHexa()    // NEW HEXA3
2772 {
2773     if ( !_replaceHexaDiag ){
2774         _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2775     }
2776     _showDialogBox( _replaceHexaDiag );
2777 }
2778
2779
2780 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2781 {
2782     if ( !_quadRevolutionDiag ){
2783         _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2784     }
2785     _showDialogBox( _quadRevolutionDiag );
2786 }
2787
2788
2789 void HEXABLOCKGUI::assocVertex()
2790 {
2791         if (!_dwInputPanel) return;
2792         QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2793         if ( !_vertexAssocDiag  )
2794                 _vertexAssocDiag  = new VertexAssocDialog( d /*_dwInputPanel*/);
2795         _showDialogBox( _vertexAssocDiag );
2796 }
2797
2798
2799 void HEXABLOCKGUI::assocEdge()
2800 {
2801     if ( !_edgeAssocDiag )
2802         _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2803     _showDialogBox( _edgeAssocDiag );
2804 }
2805
2806 void HEXABLOCKGUI::assocQuad()
2807 {
2808     if ( !_quadAssocDiag )
2809         _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2810     _showDialogBox( _quadAssocDiag );
2811 }
2812
2813
2814 void HEXABLOCKGUI::addGroup()
2815 {
2816     if ( !_groupDiag ){
2817         _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2818     }
2819     _showDialogBox( _groupDiag );
2820     if (_groupDiag != NULL && getCurrentModel() != NULL)
2821     {
2822         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2823         if (doc == NULL) return;
2824         char defaultName[16];
2825         sprintf (defaultName, "g%04d", doc->countGroup());
2826         _groupDiag->name_le->setText(defaultName);
2827     }
2828 }
2829
2830 void HEXABLOCKGUI::removeGroup()
2831 {
2832     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2833     if (currentDGView == NULL) return;
2834
2835     QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2836     QModelIndexList l = groupsSelectionModel->selectedIndexes();
2837     int nbGroupsRemoved = 0;
2838
2839     if ( l.isEmpty() ){
2840         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2841                 tr( "No group selected!" ) );
2842         return;
2843     }
2844
2845     foreach( QModelIndex selected, l ){
2846         if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2847             selected = currentDGView->getGroupsModel()->mapToSource( selected );
2848             Q_ASSERT(selected.isValid());
2849
2850             //Confirm the deletion of the group
2851             if (SUIT_MessageBox::question(
2852                     0,
2853                     tr("Remove Group"),
2854                     tr("Remove group : %1 ?").arg(selected.data().toString()),
2855                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2856                     SUIT_MessageBox::Cancel
2857             ) == SUIT_MessageBox::Cancel) return;
2858
2859             bool removed = getCurrentModel()->removeGroup( selected );
2860             if ( !removed ) {
2861                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2862                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2863                 return;
2864             }
2865             nbGroupsRemoved++;
2866         }
2867     }
2868     if (!nbGroupsRemoved)
2869         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2870                 tr( "No group selected!" ) );
2871 }
2872
2873 void HEXABLOCKGUI::addLaw()
2874 {
2875     if ( !_lawDiag ){
2876         _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2877     }
2878     _showDialogBox( _lawDiag );
2879     if (_lawDiag != NULL && getCurrentModel() != NULL)
2880     {
2881         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2882         if (doc == NULL) return;
2883         char defaultName[16];
2884         sprintf (defaultName, "l%04d", doc->countLaw());
2885         _lawDiag->name_le->setText(defaultName);
2886     }
2887 }
2888
2889 void HEXABLOCKGUI::removeLaw()
2890 {
2891     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2892     if (currentDGView == NULL) return;
2893
2894     QModelIndexList l = currentDGView->getMeshSelectionModel()->selectedIndexes();
2895     int nbLawsRemoved = 0;
2896
2897     if ( l.isEmpty() ){
2898         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2899                 tr( "No law selected!" ) );
2900         return;
2901     }
2902
2903     foreach( QModelIndex selected, l ){
2904         if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2905             selected = currentDGView->getMeshModel()->mapToSource( selected );
2906             Q_ASSERT(selected.isValid());
2907
2908             //Confirm the deletion of the law
2909             if (SUIT_MessageBox::question(
2910                     0,
2911                     tr("Remove Law"),
2912                     tr("Remove law : %1 ?\nAll propagations having this law will have the default law.").arg(selected.data().toString()),
2913                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2914                     SUIT_MessageBox::Cancel
2915             ) == SUIT_MessageBox::Cancel) return;
2916
2917             bool removed = getCurrentModel()->removeLaw(selected);
2918             if ( !removed ) {
2919                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2920                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2921                 return;
2922             }
2923             nbLawsRemoved++;
2924         }
2925     }
2926     if (!nbLawsRemoved)
2927         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2928                                          tr( "No law selected!" ) );
2929
2930 }
2931
2932
2933 void HEXABLOCKGUI::setPropagation()
2934 {
2935     if ( !_propagationDiag )
2936         _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2937
2938     _showDialogBox( _propagationDiag );
2939 }
2940
2941 // Dialog box to compute a mesh from a document
2942 // --------------------------------------------
2943 void HEXABLOCKGUI::computeMesh()
2944 {
2945     if ( !_computeMeshDiag )
2946         _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2947
2948     _showDialogBox( _computeMeshDiag );
2949 }
2950
2951 void HEXABLOCKGUI::clearAssociations()
2952 {
2953     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2954     if (currentDGView == NULL) return;
2955
2956     //   QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2957     QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2958     QModelIndex iModel     = currentDGView->getPatternDataModel()->mapToSource(iDataModel);
2959
2960     getCurrentModel()->clearEltAssociations(iModel);
2961
2962     //  SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2963 }
2964
2965 void HEXABLOCKGUI::showModelInfo()
2966 {
2967     //create the info dialog if not yet
2968     if (_modelInfoDiag == NULL)
2969         _modelInfoDiag = new ModelInfoDialog(_dwInputPanel);
2970
2971     //show the model informations dialog
2972     _showDialogBox( _modelInfoDiag );
2973 }
2974
2975 void HEXABLOCKGUI::addShape()
2976 {
2977     //create the info dialog if not yet
2978     if (_addShapeDiag == NULL)
2979         _addShapeDiag = new AddShapeDialog(_dwInputPanel);
2980
2981     //show the model informations dialog
2982     _showDialogBox( _addShapeDiag );
2983 }
2984
2985 void HEXABLOCKGUI::clearAllAssociations()
2986 {
2987     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2988     if (currentDGView == NULL) return;
2989
2990     QModelIndex currentIndex = currentDGView->getPatternDataModel()->mapToSource(_patternDataTreeView->currentIndex());
2991     if (!currentIndex.isValid()) return;
2992     QVariant currentAssocVariant;
2993     QString currentAssocEntry;
2994
2995     //Confirm the deletion of the associations
2996     QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
2997     if ( !treeVariant.isValid() ) return;
2998     int eltType = treeVariant.toInt();
2999     QString typeStr = "";
3000     HEXA_NS::EnumElt hexaType;
3001     if (eltType == VERTEX_DIR_TREE)
3002     {
3003         typeStr = tr("TREE_ITEM_VERTEX").toUpper();
3004         hexaType = HEXA_NS::EL_VERTEX;
3005     }
3006     else if (eltType == EDGE_DIR_TREE)
3007     {
3008         typeStr = tr("TREE_ITEM_EDGE").toUpper();
3009         hexaType = HEXA_NS::EL_EDGE;
3010     }
3011     else if (eltType == QUAD_DIR_TREE)
3012     {
3013         typeStr = tr("TREE_ITEM_QUAD").toUpper();
3014         hexaType = HEXA_NS::EL_QUAD;
3015     }
3016
3017     if (SUIT_MessageBox::question(
3018             0,
3019             tr("CLEAR_ASSOCIATIONS"),
3020             tr("CLEAR_ALL_ASSOCIATIONS_ON") + " " + typeStr + "?",
3021             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
3022             SUIT_MessageBox::Cancel
3023     ) == SUIT_MessageBox::Cancel) return;
3024
3025
3026     DocumentModel* docModel = getCurrentModel();
3027     if (docModel == NULL) return;
3028     docModel->clearAssociation(hexaType);
3029 }
3030
3031 void HEXABLOCKGUI::showAssociations()
3032 {
3033     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3034     if (currentDGView == NULL) return;
3035
3036     QModelIndexList elts;
3037     int currentChildIndex = 0;
3038     QVariant currentAssocVariant;
3039     QString currentAssocEntry;
3040     QModelIndex currentIndex = _patternDataTreeView->currentIndex();
3041     QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
3042
3043     while( currentChild.isValid() ) {
3044
3045         currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
3046         currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
3047         if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
3048             elts << currentChild;
3049
3050         currentChild = currentChild.sibling(currentChildIndex++, 0);
3051     }
3052     currentDocGView->highlight(elts);
3053     currentOccGView->highlight(elts, false);
3054 }
3055
3056
3057 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
3058 {
3059     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
3060     if( anApp )
3061         return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
3062     else
3063         return NULL;
3064 }
3065
3066 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
3067 {
3068     if ( event->type() == QEvent::Enter )
3069     {   // *** ENTER EVENT
3070
3071         if (currentDialog == NULL || !currentDialog->isVisible())
3072             return QObject::eventFilter(obj, event);
3073
3074         //  ** The window acquire the focus when the cursor enter
3075
3076             //OCC - window enter
3077         OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
3078         if ( occWindow != NULL)
3079             currentDialog->onWindowActivated(occWindow->getViewManager());
3080         else
3081             //VTK - window enter
3082         {
3083             SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
3084             if ( vtkWindow != NULL)
3085                 currentDialog->onWindowActivated(vtkWindow->getViewManager());
3086         }
3087     }
3088
3089     //standard event processing
3090     return QObject::eventFilter(obj, event);
3091 }
3092
3093 QStringList HEXABLOCKGUI::getQuickDirList()
3094 {
3095     QStringList dirList;
3096     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
3097     if ( resMgr )
3098         dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
3099
3100     return dirList;
3101 }
3102
3103
3104 // --- Export the module
3105
3106 extern "C"
3107 {
3108     HEXABLOCK_EXPORT CAM_Module* createModule()
3109     {
3110         return new HEXABLOCKGUI();
3111     }
3112
3113     HEXABLOCK_EXPORT char* getModuleVersion()
3114     {
3115         return (char*)HEXABLOCK_VERSION_STR;
3116     }
3117 }
3118
3119
3120
3121 // ******************** TESTS ***************************************************
3122
3123 void HEXABLOCKGUI::testDocument()
3124 {
3125     //CS_TEST
3126     // ----------
3127     //   QStandardItem *parentItem = getCurrentModel()->invisibleRootItem();
3128     //   QStandardItem *myItem =  new QStandardItem("MyItem");
3129     //   parentItem->appendRow(myItem);
3130     // //   ----------
3131     //   QModelIndex v0 = getCurrentModel()->addVertex(0., 0., 0.);
3132     //   QModelIndex v1 = getCurrentModel()->addVertex(5., 0., 0.);
3133     //   QModelIndex v2 = getCurrentModel()->addVertex(5., 5., 0.);
3134     //   QModelIndex v3 = getCurrentModel()->addVertex(0., 5., 0.);
3135     //   QModelIndex v4 = getCurrentModel()->addVertex(0., 0., 5.);
3136     //   QModelIndex v5 = getCurrentModel()->addVertex(5., 0., 5.);
3137     //   QModelIndex v6 = getCurrentModel()->addVertex(5., 5., 5.);
3138     //   QModelIndex v7 = getCurrentModel()->addVertex(0., 5., 5.);
3139     // //
3140     // //
3141     //   QModelIndex q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
3142     //   QModelIndex q1 = getCurrentModel()->addQuadVertices( v4, v5, v6, v7 );
3143     //   QModelIndex q2 = getCurrentModel()->addQuadVertices( v0, v3, v7, v4 );
3144     //   QModelIndex q3 = getCurrentModel()->addQuadVertices( v1, v2, v6, v5 );
3145     //   QModelIndex q4 = getCurrentModel()->addQuadVertices( v0, v1, v5, v4 );
3146     //   QModelIndex q5 = getCurrentModel()->addQuadVertices( v3, v2, v6, v7 );
3147     //
3148     //   QModelIndex h0 = getCurrentModel()->addHexaQuad( q0, q1, q2, q3, q4, q5 );
3149     //   QModelIndex vx = getCurrentModel()->addVector(1., 0., 0.);
3150     //   QModelIndex vy = getCurrentModel()->addVector(0., 1., 0.);
3151     //   QModelIndex vz = getCurrentModel()->addVector(0., 0., 1.);
3152     //
3153
3154
3155
3156     // //   QModelIndex orig1 = getCurrentModel()->addVertex (0, 0,0);
3157     // //   QModelIndex orig2 = getCurrentModel()->addVertex (50,0,0);
3158     // //   QModelIndex vz    = getCurrentModel()->addVector (0,0,1);
3159     // //   QModelIndex vx    = getCurrentModel()->addVector (1,0,0);
3160     // //
3161     // //   int nr  = 4;
3162     // //   int nri = 3;
3163     // //   int nre = nr;
3164     // //   int na = 9;
3165     // //   int nl = 5;
3166     // //
3167     // //   QModelIndex  cyl  = getCurrentModel()->addCylinder   (orig1, vz, nr, nl);
3168     // //   QModelIndex  pipe = getCurrentModel()->addPipe       (orig2, vz, nri, nre, nl);
3169     // //
3170     // //   getCurrentModel()->makeCylinder (cyl,  vx, nr, na, nl);
3171     // //   getCurrentModel()->makePipe(pipe, vx, nr, na, nl);
3172
3173
3174
3175     //   newMesh( "toto", 3, "FactoryServer");
3176     // newMesh
3177 }
3178
3179 void HEXABLOCKGUI::test_make_cart_grid()
3180 {
3181     QModelIndex orig1 = getCurrentModel()->addVertex( 0, 0, 0);
3182     QModelIndex orig2 = getCurrentModel()->addVertex( 10, 0, 0);
3183     QModelIndex orig3 = getCurrentModel()->addVertex( 0, 10, 0);
3184     QModelIndex orig4 = getCurrentModel()->addVertex( 10, 10, 0);
3185     QModelIndex orig5 = getCurrentModel()->addVertex( 0, 20, 0);
3186     QModelIndex orig6 = getCurrentModel()->addVertex( 10, 20, 0);
3187
3188     QModelIndex vz = getCurrentModel()->addVector(0, 0, 1);
3189     QModelIndex vx = getCurrentModel()->addVector(1, 0, 0);
3190
3191     //int dr = 1;
3192     //int dl = 1;
3193     //int nr = 2;
3194     //int nl = 3;
3195
3196     // QModelIndex c1 = getCurrentModel()->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
3197     // QModelIndex c2 = getCurrentModel()->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
3198     // QModelIndex c3 = getCurrentModel()->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
3199     // QModelIndex c4 = getCurrentModel()->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
3200     // QModelIndex c5 = getCurrentModel()->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
3201     // QModelIndex c6 = getCurrentModel()->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
3202
3203 }
3204
3205
3206 void HEXABLOCKGUI::test_make_elmts_transform()
3207 {
3208
3209 //    int size_x = 1;
3210 //    int size_y = 1;
3211 //    int size_z = 2;
3212 //
3213 //    QModelIndex orig = getCurrentModel()->addVertex(0, 0, 0);
3214 //    QModelIndex dirVr = getCurrentModel()->addVector(1, 1, 1);
3215
3216     //obsolete
3217 //    QModelIndex grid = getCurrentModel()->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
3218     // orig.setScalar(2);
3219
3220     // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
3221     // getCurrentModel()->saveVtk(file_name)
3222
3223 //    QModelIndex devant = getCurrentModel()->addVector(5, 0, 0);
3224 //    QModelIndex grid2  = getCurrentModel()->makeTranslation(grid, devant);
3225
3226     // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
3227     // getCurrentModel()->saveVtk(file_name)
3228
3229 //    QModelIndex grid4 = getCurrentModel()->makeRotation(grid2, orig, dirVr, 45);
3230
3231
3232     // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
3233     // getCurrentModel()->saveVtk(file_name);
3234
3235
3236     // print "...test make elements by transforming elements OK"
3237 }
3238 // =============================================================== addDocInSudy
3239 QString HEXABLOCKGUI::addDocInStudy (HEXA_NS::Document* document)
3240 {
3241     QString docEntry;
3242
3243     if (document == NULL)
3244         return docEntry;
3245
3246     QString docName  = document->getName ();
3247
3248     SalomeApp_Study* app_study = HEXABLOCKGUI::activeStudy();
3249     if (app_study == NULL)
3250         return docEntry;
3251
3252     _PTR(Study)         study    = app_study->studyDS();
3253     SALOMEDS::Study_var ds_study = ClientStudyToStudy (study);
3254     SALOMEDS::StudyBuilder_var aBuilder (ds_study->NewBuilder());
3255     QString entry = app_study->centry("HEXABLOCK");
3256     SALOMEDS::SObject_var aFatherSO = ds_study->FindObjectID( qPrintable(entry) );
3257     if (aFatherSO->_is_nil())
3258         return docEntry;
3259
3260     SALOMEDS::SObject_var aSO = aBuilder->NewObject(aFatherSO);
3261     if (aSO->_is_nil())
3262         return docEntry;
3263     aSO->SetAttrString("AttributeName", docName.toStdString().c_str());
3264     docEntry = aSO->GetID(); //the entry of the published object
3265
3266     return docEntry;
3267 }
3268
3269 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
3270
3271 void HEXABLOCKGUI::test()
3272 {
3273     DEBTRACE("HEXABLOCKGUI::test");
3274     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3275     if (currentDGView == NULL) return;
3276     currentDGView->update();
3277
3278 }
3279
3280 void HEXABLOCKGUI::test_association()
3281 {
3282     DEBTRACE("HEXABLOCKGUI::test_association");
3283     newDocument();
3284
3285     QModelIndex v0, v1, v2, v3, e0, e1, q0;
3286
3287     DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
3288     DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
3289     DocumentModel::GeomObj q0AssocA, q0AssocB;
3290
3291     DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
3292     QList<DocumentModel::GeomObj> e1Assocs_test;
3293     DocumentModel::GeomObj q0Assoc_test;
3294
3295     v0 = getCurrentModel()->addVertex(0, 0, 0);
3296     v1 = getCurrentModel()->addVertex(1, 0, 0);
3297     v2 = getCurrentModel()->addVertex(1, 1, 0);
3298     v3 = getCurrentModel()->addVertex(0, 1, 0);
3299     e0  = getCurrentModel()->addEdgeVertices(v0, v1);
3300     e1  = getCurrentModel()->addEdgeVertices(v1, v2);
3301     q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
3302
3303
3304     // >>> face3.GetEntry()'0:1:4'
3305     // >>> e1.GetEntry()'0:1:8'
3306     // >>> e2.GetEntry()'0:1:9'
3307     // >>> e3.GetEntry()'0:1:10'
3308     // >>> e4.GetEntry()'0:1:11'
3309     // >>> v1.GetEntry()'0:1:12'
3310     // >>> v2.GetEntry()'0:1:13'
3311     // >>> v3.GetEntry()'0:1:14'
3312     // >>> v4.GetEntry()'0:1:15'
3313
3314
3315     //   v0Assoc.name  = "geomV0";
3316     //   v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
3317     //   v0Assoc.brep  = "brepV0";
3318     //   v1Assoc.name  = "geomV1";
3319     //   v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
3320     //   v1Assoc.brep  = "brepV1";
3321     //   v2Assoc.name  = "geomV2";
3322     //   v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
3323     //   v2Assoc.brep  = "brepV2";
3324     //   v3Assoc.name  = "geomV3";
3325     //   v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
3326     //   v3Assoc.brep  = "brepV3";
3327     //
3328     //
3329     //
3330     //   e0AssocA.name   = "geomE0a";
3331     //   e0AssocA.entry  = "0:1:1:1:3:5";//"0:1:8";
3332     //   e0AssocA.brep  = "brepE0a";
3333     //   e0AssocA.start  = 0.10;
3334     //   e0AssocA.end    = 0.95;
3335     //
3336     //
3337     //
3338     //   e1AssocA.name   = "geomE1a";
3339     //   e1AssocA.entry  = "0:1:1:1:3:2";//"0:1:8";
3340     //   e1AssocA.brep  = "brepE1a";
3341     //   e1AssocA.start  = 0.12;
3342     //   e1AssocA.end    = 0.89;
3343     //   e1AssocB.name   = "geomE1b";
3344     //   e1AssocB.entry  = "0:1:1:1:3:3";//"0:1:9";
3345     //   e1AssocB.brep  = "brepE1b";
3346     //   e1AssocB.start  = 0.20;
3347     //   e1AssocB.end    = 0.80;
3348     //   e1AssocC.name   = "geomE1c";
3349     //   e1AssocC.entry  = "0:1:1:1:3:4";//"0:1:10";
3350     //   e1AssocC.brep  = "brepE1c";
3351     //   e1AssocC.start  = 0.16;
3352     //   e1AssocC.end    = 0.96;
3353     //
3354     //   q0AssocA.name   = "geomQuad";
3355     //   q0AssocA.entry  = "0:1:1:1:3";
3356     //   q0AssocA.brep   = "brepq0";
3357     //
3358     //   q0AssocB.name   = "geomQuad";
3359     //   q0AssocB.entry  = "0:1:1:1:4";
3360     //   q0AssocB.brep   = "brepq0";
3361     //
3362     //   getCurrentModel()->addAssociation( v0, v0Assoc );
3363     //   getCurrentModel()->addAssociation( v1, v1Assoc );
3364     //   getCurrentModel()->addAssociation( v2, v2Assoc );
3365     //   getCurrentModel()->addAssociation( v3, v3Assoc );
3366     //
3367     //
3368     //   getCurrentModel()->addAssociation( e0, e0AssocA );
3369     //
3370     //   getCurrentModel()->addAssociation( e1, e1AssocA );
3371     //   getCurrentModel()->addAssociation( e1, e1AssocB );
3372     //   getCurrentModel()->addAssociation( e1, e1AssocC );
3373     //
3374     //   getCurrentModel()->addAssociation( q0, q0AssocA );
3375     //   getCurrentModel()->addAssociation( q0, q0AssocB );
3376
3377
3378
3379
3380
3381     //   v0Assoc_test = getCurrentModel()->getAssociations( v0 )[0];
3382     //   v1Assoc_test = getCurrentModel()->getAssociations( v1 )[0];
3383     //   v2Assoc_test = getCurrentModel()->getAssociations( v2 )[0];
3384     //   v3Assoc_test = getCurrentModel()->getAssociations( v3 )[0];
3385     //   ASSERT( v0Assoc.name == v0Assoc_test.name );
3386     //   ASSERT( v1Assoc.name == v1Assoc_test.name );
3387     //   ASSERT( v2Assoc.name == v2Assoc_test.name );
3388     //   ASSERT( v3Assoc.name == v3Assoc_test.name );
3389     //   ASSERT( v0Assoc.entry == v0Assoc_test.entry );
3390     //   ASSERT( v1Assoc.entry == v1Assoc_test.entry );
3391     //   ASSERT( v2Assoc.entry == v2Assoc_test.entry );
3392     //   ASSERT( v3Assoc.entry == v3Assoc_test.entry );
3393     //
3394     //
3395     //   e1Assocs_test = getCurrentModel()->getAssociations( e1 );
3396     //   ASSERT( e1Assocs_test[0].name == e1AssocA.name );
3397     //   ASSERT( e1Assocs_test[1].name == e1AssocB.name );
3398     //   ASSERT( e1Assocs_test[2].name == e1AssocC.name );
3399     //   ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
3400     //   ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
3401     //   ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
3402     //   ASSERT( e1Assocs_test[0].start == e1AssocA.start );
3403     //   ASSERT( e1Assocs_test[1].start == e1AssocB.start );
3404     //   ASSERT( e1Assocs_test[2].start == e1AssocC.start );
3405     //   ASSERT( e1Assocs_test[0].end == e1AssocA.end );
3406     //   ASSERT( e1Assocs_test[1].end == e1AssocB.end );
3407     //   ASSERT( e1Assocs_test[2].end == e1AssocC.end );
3408     //
3409     //   q0Assoc_test = getCurrentModel()->getAssociations( q0 )[0];
3410     //   ASSERT( q0Assoc_test.name  == q0Assoc.name );
3411     //   ASSERT( q0Assoc_test.entry == q0Assoc.entry );
3412
3413
3414     DEBTRACE("HEXABLOCKGUI::test_association fin");
3415 }