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