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