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