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