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