Salome HOME
ParaView 4.1 / VTK 6.1 porting
[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->setObjectName("InputPanelDockWidget");
945 //    _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
946
947 //    _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
948
949     //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
950     //      Pattern
951     _dwPattern = new QDockWidget(aParent);
952     _dwPattern->setVisible(false);
953     _dwPattern->setWindowTitle("Model");
954     _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
955     _dwPattern->setObjectName("ModelDockWidget");
956
957     QFrame*      patternFrame  = new QFrame(_dwPattern);
958     patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
959     QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
960     patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
961     QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
962     _patternDataTreeView    = new QTreeView(patternFrame);//_dwPattern);
963 //    _patternBuilderTreeView = new QTreeView(patternFrame);                  // ---> TO REMOVE
964     _patternGeomTreeView    = new QTreeView(patternFrame);
965     splitter->addWidget(_patternDataTreeView);
966 //    splitter->addWidget(_patternBuilderTreeView);                           // ---> TO REMOVE
967     splitter->addWidget(_patternGeomTreeView);
968     patternLayout->addWidget(splitter);
969
970     _patternDataTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers/*QAbstractItemView::DoubleClicked*/);
971     _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
972 //    _patternDataTreeView->setItemDelegate(_treeViewDelegate);
973
974
975 //    _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
976 //    _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
977
978     _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
979     _patternGeomTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);
980
981     _dwPattern->setWidget(patternFrame);
982     patternFrame->show();
983
984     //      Groups
985     _dwGroups = new QDockWidget(aParent);
986
987     _dwGroups->setVisible(false);
988     _dwGroups->setWindowTitle("Groups");
989     _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
990     _dwGroups->setObjectName("GroupsDockWidget");
991     _groupsTreeView = new QTreeView(_dwGroups);
992     _groupsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
993 //    _groupsTreeView->setItemDelegate(_treeViewDelegate);
994     _dwGroups->setWidget(_groupsTreeView);
995     _groupsTreeView->show();
996
997     //      Mesh
998     _dwMesh = new QDockWidget(aParent);
999     _dwMesh->setVisible(false);
1000     _dwMesh->setWindowTitle("Mesh");
1001     _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1002     _dwMesh->setObjectName("MeshDockWidget");
1003     _meshTreeView = new QTreeView(_dwMesh);
1004     _meshTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1005     _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
1006 //    _meshTreeView->setItemDelegate(_treeViewDelegate);
1007     _dwMesh->setWidget(_meshTreeView);
1008     _meshTreeView->show();
1009
1010 //    QDockWidget *_dwObjectBrowser = 0;
1011     QWidget* wid = getApp()->objectBrowser()->treeView();
1012     QWidget *w   = wid->parentWidget();
1013     while ( w && !_dwObjectBrowser ) {
1014         _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
1015         w = w->parentWidget();
1016     }
1017     _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
1018     _dwObjectBrowser->setWindowTitle("Study");
1019
1020     // dock widget position
1021     aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
1022     aParent->addDockWidget( Qt::RightDockWidgetArea, _dwInputPanel );
1023
1024 //    aParent->tabifyDockWidget( _dwPattern, _dwObjectBrowser );
1025 //    aParent->tabifyDockWidget( _dwGroups, _dwPattern );
1026 //    aParent->tabifyDockWidget( _dwMesh, _dwGroups );
1027
1028     aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
1029     aParent->tabifyDockWidget( _dwPattern, _dwGroups );
1030     aParent->tabifyDockWidget( _dwGroups, _dwMesh );
1031
1032 #if QT_VERSION >= 0x040500
1033     aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
1034 #endif
1035
1036     // popup menu on data tree view
1037     _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
1038     connect(_patternDataTreeView,
1039             SIGNAL(customContextMenuRequested(const QPoint &)),
1040             this,
1041             SLOT(treeContextMenu(const QPoint &)),
1042             Qt::UniqueConnection );
1043 }
1044
1045 void HEXABLOCKGUI::createActions()
1046 {
1047     QMainWindow *aParent = application()->desktop();
1048     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
1049
1050     // Document
1051     _newAct = createAction(_menuId++,
1052             tr("Create a new document"),
1053             resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
1054             tr("New Document"),
1055             tr("Create a new document"),
1056             0, aParent, false, this, SLOT(newDocument()));
1057     _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1058
1059     _importAct = createAction(_menuId++,
1060             tr("Load a document"),
1061             resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
1062             tr("Load Document"),
1063             tr("Load a document"),
1064             0, aParent, false, this, SLOT(loadDocument()));
1065     _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
1066
1067     _saveAct = createAction(_menuId++,
1068             tr("Save the document"),
1069             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
1070             tr("Save Document"),
1071             tr("Save the document"),
1072             0, aParent, false, this, SLOT(saveDocument()));
1073
1074     // Pattern Data creation
1075     _addVertex = createAction(_menuId++,
1076             tr("Create a vertex"),
1077             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
1078             tr("Add Vertex"),
1079             tr("Create a new vertex"),
1080             0, aParent, false, this, SLOT(addVertex()));
1081
1082     _addEdge = createAction(_menuId++,
1083             tr("Create an edge"),
1084             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
1085             tr("Add Edge"),
1086             tr("Create a new edge"),
1087             0, aParent, false, this, SLOT(addEdge()));
1088
1089     _addQuad = createAction(_menuId++,
1090             tr("Create a quadrangle"),
1091             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1092             tr("Add Quadrangle"),
1093             tr("Create a new quadrangle"),
1094             0, aParent, false, this, SLOT(addQuad()));
1095
1096     _addHexa = createAction(_menuId++,
1097             tr("Create an hexahedron"),
1098             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1099             tr("Add Hexahedron"),
1100             tr("Create a new hexahedron"),
1101             0, aParent, false, this, SLOT(addHexa()));
1102
1103     // Builder Data creation
1104     _addVector = createAction(_menuId++,
1105             tr("Create a vector"),
1106             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1107             tr("Add Vector"),
1108             tr("Create a new vector"),
1109             0, aParent, false, this, SLOT(addVector()));
1110
1111 //    _addCylinder = createAction(_menuId++,
1112 //            tr("Create a cylinder"),
1113 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1114 //            tr("Add Cylinder"),
1115 //            tr("Create a new cylinder"),
1116 //            0, aParent, false, this,  SLOT(addCylinder()));
1117
1118 //    _addPipe = createAction(_menuId++,
1119 //            tr("Create a pipe"),
1120 //            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1121 //            tr("Add Pipe"),
1122 //            tr("Create a new pipe"),
1123 //            0, aParent, false, this, SLOT(addPipe()));
1124
1125     _makeGrid = createAction(_menuId++,
1126             tr("Make a grid"),
1127             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1128             tr("Make Grid"),
1129             tr("Make a grid"),
1130             0, aParent, false, this,  SLOT(makeGrid()));
1131
1132     _makeCylinder = createAction(_menuId++,
1133             tr("Make a cylinder"),
1134             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1135             tr("Make Cylinder"),
1136             tr("Make a cylinder"),
1137             0, aParent, false, this, SLOT(makeCylinder()));
1138
1139     _makePipe = createAction(_menuId++,
1140             tr("Make a pipe"),
1141             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1142             tr("Make Pipe"),
1143             tr("Make a pipe"),
1144             0, aParent, false, this, SLOT(makePipe()));
1145
1146     _makeCylinders = createAction(_menuId++,
1147             tr("Make cylinders"),
1148             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1149             tr("Make Cylinders"),
1150             tr("Make cylinders"),
1151             0, aParent, false, this, SLOT(makeCylinders()));
1152
1153     _makePipes = createAction(_menuId++,
1154             tr("Make pipes"),
1155             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1156             tr("Make Pipes"),
1157             tr("Make pipes"),
1158             0, aParent, false, this, SLOT(makePipes()));
1159
1160     _makeHemiSphere = createAction(_menuId++,
1161             tr("Make an hemisphere"),
1162             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1163             tr("Make Hemisphere"),
1164             tr("Make an hemisphere"),
1165             0, aParent, false, this, SLOT(makeHemiSphere()));
1166
1167     // Pattern Data edition
1168     _removeHexa = createAction(_menuId++,
1169             tr("Remove hexahedra"),
1170             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1171             tr("Remove Hexahedra"),
1172             tr("Remove hexahedra"),
1173             0, aParent, false, this, SLOT(removeHexa()));
1174
1175     _prismQuad = createAction(_menuId++,
1176             tr("Prism quadrangles"),
1177             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1178             tr("Prism Quadrangles"),
1179             tr("Prism quadrangles"),
1180             0, aParent, false, this, SLOT(prismQuad()));
1181
1182     _joinQuad = createAction(_menuId++,
1183             tr("Join quadrangles"),
1184             resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1185             tr("Join Quadrangles"),
1186             tr("Join quadrangles with hexahedra"),
1187             0, aParent, false, this, SLOT(joinQuad()));
1188
1189     _merge = createAction(_menuId++,
1190             tr("Merge"),
1191             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1192             tr("Merge"),
1193             tr("Merge"),
1194             0, aParent, false, this, SLOT(merge()));
1195
1196     _disconnect = createAction(_menuId++,
1197             tr("Disconnect"),
1198             resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1199             tr("Disconnect"),
1200             tr("Disconnect edges, vertexes or quadrangles"),
1201             0, aParent, false, this, SLOT(disconnectElts()));
1202
1203     _cutEdge = createAction(_menuId++,
1204             tr("Cut edge"),
1205             resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1206             tr("Cut Edge"),
1207             tr("Cut edge"),
1208             0, aParent, false, this, SLOT(cutEdge()));
1209
1210     _makeTransformation = createAction(_menuId++,
1211             tr("Make transformation"),
1212             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1213             tr("Make Transformation"),
1214             tr("Make transformation"),
1215             0, aParent, false, this, SLOT(makeTransformation()));
1216
1217     _makeSymmetry = createAction(_menuId++,
1218             tr("Make symmetry"),
1219             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1220             tr("Make Symmetry"),
1221             tr("Make symmetry"),
1222             0, aParent, false, this, SLOT(makeSymmetry()));
1223
1224     _performTransformation = createAction(_menuId++,
1225             tr("Perform transformation"),
1226             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1227             tr("Perform Transformation"),
1228             tr("Perform transformation"),
1229             0, aParent, false, this, SLOT(performTransformation()));
1230
1231     _performSymmetry = createAction(_menuId++,
1232             tr("Perform symmetry"),
1233             resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1234             tr("Perform Symmetry"),
1235             tr("Perform symmetry"),
1236             0, aParent, false, this, SLOT(performSymmetry()));
1237
1238     _replaceHexa = createAction(_menuId++,
1239             tr("Replace hexahedron"),
1240             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1241             tr("Replace Hexahedron"),
1242             tr("Replace hexahedron"),
1243             0, aParent, false, this, SLOT(replaceHexa()));
1244
1245     _quadRevolution = createAction(_menuId++,
1246             tr("Quad revolution"),
1247             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1248             tr("Quad Revolution"),
1249             tr("Quad revolution"),
1250             0, aParent, false, this, SLOT(quadRevolution()));
1251
1252     // Association
1253     _assocVertex = createAction(_menuId++,
1254             tr("Make vertex association"),
1255             resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1256             tr("Make Vertex association"),
1257             tr("Make vertex association"),
1258             0, aParent, false, this, SLOT(assocVertex()));
1259
1260     _assocEdge = createAction(_menuId++,
1261             tr("Make edge association"),
1262             resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1263             tr("Make Edge Association"),
1264             tr("Make edge association"),
1265             0, aParent, false, this, SLOT(assocEdge()));
1266
1267     _assocQuad = createAction(_menuId++,
1268             tr("Make quad association"),
1269             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1270             tr("Make Quad Association"),
1271             tr("Make quad association"),
1272             0, aParent, false, this, SLOT(assocQuad()));
1273
1274     // Group
1275     _addGroup = createAction(_menuId++,
1276             tr("Add a group"),
1277             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1278             tr("Add Group"),
1279             tr("Add a group"),
1280             0, aParent, false, this, SLOT(addGroup()));
1281
1282     _removeGroup = createAction(_menuId++,
1283             tr("Remove a group"),
1284             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1285             tr("Remove Group"),
1286             tr("Remove a group"),
1287             0, aParent, false, this, SLOT(removeGroup()));
1288
1289     // Mesh
1290     _addLaw = createAction(_menuId++,
1291             tr("Add a law"),
1292             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1293             tr("Add Law"),
1294             tr("Add a law"),
1295             0, aParent, false, this, SLOT(addLaw()));
1296
1297     _removeLaw = createAction(_menuId++,
1298             tr("Remove a law"),
1299             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1300             tr("Remove Law"),
1301             tr("Remove a law"),
1302             0, aParent, false, this, SLOT(removeLaw()));
1303
1304     _setPropagation = createAction(_menuId++,
1305             tr("Set propagation"),
1306             resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1307             tr("Set Propagation"),
1308             tr("Set propagation"),
1309             0, aParent, false, this, SLOT(setPropagation()));
1310
1311     _computeMesh = createAction(_menuId++,
1312             tr("Compute mesh"),
1313             resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1314             tr("Compute Mesh"),
1315             tr("Compute mesh"),
1316             0, aParent, false, this, SLOT(computeMesh()));
1317
1318     _showModelInfoAct = createAction(_menuId++,
1319             tr("Show Model Info"),
1320             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MODEL_INFO")),
1321             tr("MODEL_INFO"),
1322             tr("MODEL_INFO"),
1323             0, aParent, false, this, SLOT(showModelInfo()));
1324
1325     _addShapeAct = createAction(_menuId++,
1326             tr("Add Shape"),
1327             resMgr->loadPixmap("HEXABLOCK", tr("ICON_GEOM_ASSOCIATION")),
1328             tr("ADD_SHAPE"),
1329             tr("ADD_SHAPE"),
1330             0, aParent, false, this, SLOT(addShape()));
1331
1332 //   _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1333 //   QAction* createAction(const int id,
1334 //                         const QString& toolTip,
1335 //                         const QIcon& icon,
1336 //                         const QString& menu,
1337 //                         const QString& status,
1338 //                         const int shortCut,
1339 //                         QObject* parent =0,
1340 //                         bool checkable = false,
1341 //                         QObject* receiver =0,
1342 //                         const char* member =0);
1343
1344     _sep1 =  separator();
1345     _sep2 =  separator();
1346     _sep3 =  separator();
1347     _sep4 =  separator();
1348 }
1349
1350
1351 void HEXABLOCKGUI::createMenus()
1352 {
1353     int aMenuId, subMenuId,aMenuIdMain;
1354
1355     aMenuIdMain = createMenu( tr("MEN_FILE"), -1, -1);
1356
1357     aMenuId = createMenu( tr("HEXABLOCK"), aMenuIdMain, -1, 10 );
1358     createMenu( actionId(_newAct), aMenuId );
1359     createMenu( actionId(_importAct), aMenuId );
1360     createMenu( _saveAct, aMenuId );
1361
1362
1363     int aMenuDocId = createMenu( tr( "Document" ), -1, -1, 30 );
1364     createMenu( _newAct, aMenuDocId );//, 10
1365     createMenu( _importAct, aMenuDocId );
1366     createMenu( _saveAct, aMenuDocId );
1367
1368     aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1369     subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1370     createMenu( _addVertex, subMenuId );
1371     createMenu( _addEdge,   subMenuId );
1372     createMenu( _addQuad,   subMenuId );
1373     createMenu( _addHexa,   subMenuId );
1374     createMenu( _sep1, subMenuId);
1375
1376     // Pattern Builder
1377     createMenu( _addVector, subMenuId );
1378 //    createMenu( _addCylinder, subMenuId );
1379 //    createMenu( _addPipe, subMenuId );
1380
1381     createMenu( _sep2, subMenuId);
1382
1383     createMenu( _makeGrid,  subMenuId ); //Cartesian, Cylindrical, Spherical
1384     createMenu( _makeHemiSphere,subMenuId );
1385
1386     createMenu( _sep3, subMenuId);
1387
1388     createMenu( _makeCylinder, subMenuId );
1389     createMenu( _makePipe,     subMenuId );
1390     createMenu( _makeCylinders,subMenuId );
1391     createMenu( _makePipes,    subMenuId );
1392
1393     // Pattern Data Edition
1394     subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1395     createMenu( _removeHexa, subMenuId );
1396     createMenu( _prismQuad,  subMenuId );
1397     createMenu( _joinQuad,   subMenuId );
1398     createMenu( _merge,      subMenuId );
1399     createMenu( _disconnect, subMenuId );
1400     createMenu( _cutEdge,    subMenuId );
1401     createMenu( _makeTransformation, subMenuId );
1402     createMenu( _makeSymmetry,       subMenuId );
1403     createMenu( _performTransformation,   subMenuId );
1404     createMenu( _performSymmetry,         subMenuId );
1405     createMenu( _replaceHexa,    subMenuId );
1406     createMenu( _quadRevolution, subMenuId );
1407     createMenu( _sep4, aMenuId );
1408     createMenu( _showModelInfoAct, aMenuId );
1409
1410     // Association
1411     aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1412     createMenu( _addShapeAct, aMenuId );
1413     createMenu( _assocVertex, aMenuId );
1414     createMenu( _assocEdge,   aMenuId );
1415     createMenu( _assocQuad,   aMenuId );
1416
1417     // Group
1418     aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1419     createMenu( _addGroup,    aMenuId );
1420     createMenu( _removeGroup, aMenuId ); //CS_TODO
1421
1422     // Law
1423     aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1424     createMenu( _addLaw,    aMenuId );
1425     createMenu( _removeLaw, aMenuId );
1426     createMenu( _setPropagation, aMenuId );
1427     createMenu( _computeMesh, aMenuId );
1428
1429     //show model infomation menu
1430     QString aRule = "$component={'HEXABLOCK'}";
1431     popupMgr()->insert( _showModelInfoAct, -1, -1 );
1432     popupMgr()->setRule( _showModelInfoAct, aRule);
1433
1434     //associate shape to a document menu
1435     popupMgr()->insert( _addShapeAct, -1, -1 );
1436     popupMgr()->setRule( _addShapeAct, aRule );
1437
1438     //-------------------------------------------------
1439     // Display / Erase
1440     //-------------------------------------------------
1441     //  QString lc = "$";        // VSR : instead of QtxPopupSelection::defEquality();
1442     //  QString dc = "selcount"; // VSR : instead of QtxPopupSelection::defSelCountParam()
1443     //  QString isNotEmpty("numberOfNodes <> 0");
1444     //  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
1445     //  QString aType = QString( "%1type in {%2}" ).arg( lc );
1446     ////  aType = aType.arg( mesh_part );
1447     //
1448     //  aClient = "($client in {'VTKViewer' 'ObjectBrowser'})";
1449     //  QString anActiveVTK = QString("activeView = '%1'").arg(SVTK_Viewer::Type());
1450     //  QString aSelCount = QString( "%1 > 0" ).arg( dc );
1451
1452 //    popupMgr()->insert( separator(), -1, -1 );
1453 //    QString aRule = "$component={'HEXABLOCK'}";/* and  ( type='(" + aClient + " and " +
1454 //                aType + " and " + aSelCount + " and " + anActiveVTK + " and " + isNotEmpty + " %1 ) )";*/
1455 //    //  MESSAGE("aClient = " << aClient.toStdString());
1456 //    //  MESSAGE("aType = " << aType.toStdString());
1457 //    //  MESSAGE("aSelCount = " << aSelCount.toStdString());
1458 //    //  MESSAGE("anActiveVTK = " << anActiveVTK.toStdString());
1459 //    //  MESSAGE("isNotEmpty = " << isNotEmpty.toStdString());
1460 //    //  MESSAGE("aRule = " << aRule.toStdString());
1461 //    popupMgr()->insert( _showAct, -1, -1 ); // DISPLAY
1462 //    popupMgr()->setRule( _showAct, aRule.arg( "and (not isVisible)" ), QtxPopupMgr::VisibleRule );
1463 //
1464 //    popupMgr()->insert( _hideAct, -1, -1 ); // ERASE
1465 //    popupMgr()->setRule( _hideAct, aRule.arg( "and isVisible" ), QtxPopupMgr::VisibleRule );
1466 //
1467 //    popupMgr()->insert( _showOnlyAct, -1, -1 ); // DISPLAY_ONLY
1468 //    popupMgr()->setRule(_showOnlyAct, aRule.arg( "" ), QtxPopupMgr::VisibleRule );
1469 //
1470 //    popupMgr()->insert( separator(), -1, -1 );
1471 }
1472
1473
1474 void HEXABLOCKGUI::createTools()
1475 {
1476     int aToolId;
1477
1478     aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1479     createTool( _newAct, aToolId );
1480     createTool( _importAct, aToolId );
1481     createTool( _saveAct, aToolId );
1482     createTool( _showModelInfoAct, aToolId );
1483     //   createTool( _testAct, aToolId );
1484     //createTool( separator(), aToolId );
1485
1486     // Pattern Data
1487     aToolId = createTool ( tr( "Construction" ) );
1488     createTool( _addVertex, aToolId );
1489     createTool( _addEdge, aToolId );
1490     createTool( _addQuad, aToolId );
1491     createTool( _addHexa, aToolId );
1492
1493     createTool( _sep1, aToolId );
1494
1495     // Pattern Builder
1496     createTool( _addVector, aToolId );
1497 //    createTool( _addCylinder, aToolId );
1498 //    createTool( _addPipe, aToolId );
1499
1500     createTool( _sep2, aToolId );
1501
1502     createTool( _makeGrid,  aToolId );
1503     createTool( _makeHemiSphere,   aToolId );
1504
1505     createTool( _sep3, aToolId );
1506
1507     createTool( _makeCylinder, aToolId );
1508     createTool( _makePipe,     aToolId );
1509     createTool( _makeCylinders,aToolId );
1510     createTool( _makePipes,    aToolId );
1511
1512     // Pattern Data Edition
1513     aToolId = createTool ( tr( "Operation" ) );
1514     createTool( _removeHexa, aToolId );
1515     createTool( _prismQuad,  aToolId );
1516     createTool( _joinQuad,   aToolId );
1517     createTool( _merge,      aToolId );
1518     createTool( _disconnect, aToolId );
1519     createTool( _cutEdge,    aToolId );
1520     createTool( _makeTransformation, aToolId );
1521     createTool( _makeSymmetry,       aToolId );
1522     createTool( _performTransformation,   aToolId );
1523     createTool( _performSymmetry,         aToolId );
1524     createTool( _replaceHexa,    aToolId );
1525     createTool( _quadRevolution, aToolId );
1526
1527     // Association
1528     aToolId = createTool ( tr( "Association" ) );
1529     createTool( _assocVertex, aToolId );
1530     createTool( _assocEdge, aToolId );
1531     createTool( _assocQuad, aToolId );
1532     createTool( _addShapeAct, aToolId );
1533
1534     // Group
1535     aToolId = createTool ( tr( "Group" ) );
1536     createTool( _addGroup,    aToolId );
1537     createTool( _removeGroup, aToolId ); //CS_TODO
1538
1539     // Law
1540     aToolId = createTool ( tr( "Mesh" ) );
1541     createTool( _addLaw,    aToolId );
1542     createTool( _removeLaw, aToolId );
1543     createTool( _setPropagation, aToolId );
1544     createTool( _computeMesh, aToolId );
1545
1546 }
1547
1548 void HEXABLOCKGUI::initialMenus()
1549 {
1550     showDocumentMenus( true );
1551     showPatternMenus( false );
1552     showAssociationMenus( false );
1553     showGroupsMenus( false );
1554     showMeshMenus( false );
1555 }
1556
1557 void HEXABLOCKGUI::showAllMenus()
1558 {
1559     showDocumentMenus( true );
1560     showPatternMenus( true );
1561     showAssociationMenus( true );
1562     showGroupsMenus( true );
1563     showMeshMenus( true );
1564 }
1565
1566
1567 void HEXABLOCKGUI::showDocumentMenus(bool show)
1568 {
1569     DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1570     show = true; //
1571     setMenuShown(_newAct, show);
1572     setToolShown(_newAct, show);
1573     setMenuShown(_importAct, show);
1574     setToolShown(_importAct, show);
1575     setMenuShown(_showModelInfoAct, show);
1576     setToolShown(_showModelInfoAct, show);
1577     setMenuShown(_saveAct, show);
1578     setToolShown(_saveAct, show);
1579 }
1580
1581 void HEXABLOCKGUI::showPatternMenus(bool show)
1582 {
1583     DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1584     DEBTRACE("getCurrentModel()  " << getCurrentModel()  );
1585     if ( show && !getCurrentModel() ) return;
1586
1587     setMenuShown(_addVertex, show );
1588     setToolShown(_addVertex, show);
1589     setMenuShown(_addEdge,  show );
1590     setToolShown(_addEdge, show);
1591     setMenuShown(_addQuad,  show );
1592     setToolShown(_addQuad, show);
1593     setMenuShown(_addHexa,  show );
1594     setToolShown(_addHexa, show);
1595
1596     setMenuShown(_sep1, show );
1597     setToolShown(_sep1, show);
1598
1599     setMenuShown( _addVector,  show );
1600     setToolShown( _addVector, show);
1601 //    setMenuShown( _addCylinder,  show );
1602 //    setToolShown( _addCylinder, show);
1603 //    setMenuShown( _addPipe,  show );
1604 //    setToolShown( _addPipe, show);
1605
1606     setMenuShown(_sep2, show );
1607     setToolShown(_sep2, show);
1608
1609     setMenuShown( _makeGrid,  show );
1610     setToolShown( _makeGrid, show);
1611     setMenuShown( _makePipe,  show );
1612     setToolShown( _makePipe, show);
1613
1614     setMenuShown(_sep3, show );
1615     setToolShown(_sep3, show);
1616
1617     setMenuShown( _makeCylinder,  show );
1618     setToolShown( _makeCylinder, show);
1619     setMenuShown( _makeCylinders,  show );
1620     setToolShown( _makeCylinders, show);
1621     setMenuShown( _makePipes,  show );
1622     setToolShown( _makePipes, show);
1623     setMenuShown( _makeHemiSphere,  show );
1624     setToolShown( _makeHemiSphere, show);
1625
1626     // Pattern Data Edition
1627     setMenuShown( _removeHexa,  show );
1628     setToolShown( _removeHexa, show);
1629     setMenuShown( _prismQuad,  show );
1630     setToolShown( _prismQuad, show);
1631     setMenuShown( _joinQuad,  show );
1632     setToolShown( _joinQuad, show);
1633     setMenuShown( _merge,  show );
1634     setToolShown( _merge, show);
1635     setMenuShown( _disconnect,  show );
1636     setToolShown( _disconnect, show);
1637     setMenuShown( _cutEdge,  show );
1638     setToolShown( _cutEdge, show);
1639     setMenuShown( _makeTransformation,  show );
1640     setToolShown( _makeTransformation, show);
1641     setMenuShown( _makeSymmetry,  show );
1642     setToolShown( _makeSymmetry, show);
1643     setMenuShown( _performTransformation,  show );
1644     setToolShown( _performTransformation, show);
1645     setMenuShown( _performSymmetry,  show );
1646     setToolShown( _performSymmetry, show);
1647     setMenuShown( _replaceHexa,  show );
1648     setToolShown( _replaceHexa, show);
1649     setMenuShown( _quadRevolution,  show );
1650     setToolShown( _quadRevolution, show);
1651
1652     setMenuShown( _sep4, show );
1653     setMenuShown( _showModelInfoAct, show );
1654 }
1655
1656
1657 void HEXABLOCKGUI::showAssociationMenus(bool show)
1658 {
1659     DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1660     if ( show && !getCurrentModel() ) return;
1661
1662     // Association Edition
1663     setMenuShown( _assocVertex,  show );
1664     setToolShown( _assocVertex, show );
1665     setMenuShown( _assocEdge,  show );
1666     setToolShown( _assocEdge, show );
1667     setMenuShown( _assocQuad,  show );
1668     setToolShown( _assocQuad, show );
1669     setMenuShown( _addShapeAct, show );
1670     setToolShown( _addShapeAct, show );
1671
1672 }
1673
1674 void HEXABLOCKGUI::showGroupsMenus(bool show)
1675 {
1676     DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1677     if ( show && !getCurrentModel() ) return;
1678     setMenuShown( _addGroup,  show );
1679     setToolShown( _addGroup, show);
1680     setMenuShown( _removeGroup ,  show );
1681     setToolShown( _removeGroup , show);
1682 }
1683
1684 void HEXABLOCKGUI::showMeshMenus(bool show)
1685 {
1686     DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1687     if ( show && !getCurrentModel() ) return;
1688     setMenuShown( _addLaw,  show );
1689     setToolShown( _addLaw, show);
1690     setMenuShown( _removeLaw,  show );
1691     setToolShown( _removeLaw, show);;
1692     setMenuShown( _setPropagation,  show );
1693     setToolShown( _setPropagation, show);
1694     setMenuShown( _computeMesh, show);
1695     setToolShown( _computeMesh, show);
1696 }
1697
1698 void HEXABLOCKGUI::showVtkActor()
1699 {
1700     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1701     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1702             currentVtkGView->getDocumentActor() == NULL)
1703         return;
1704
1705     SVTK_ViewWindow* vtkView = currentVtkGView->getViewWindow();
1706     if (vtkView == NULL)
1707         return;
1708
1709     SUIT_ViewManager* vman = vtkView->getViewManager();
1710     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1711
1712     //show only the current actor -----------------
1713     vtkView->setFocus();
1714     //    vtkView->DisplayOnly(currentVtkGView->getDocumentActor()->getIO());
1715     Document_Actor *lastDocActor;
1716     if (lastVtkDocGView != NULL)
1717     {
1718         lastDocActor = lastVtkDocGView->getDocumentActor();
1719         Handle(SALOME_InteractiveObject) lastActorIO = lastDocActor->getIO();
1720         if (!lastActorIO.IsNull() && lastActorIO->hasEntry())
1721         {
1722             vtkView->Erase(lastActorIO);
1723             aStudy->setObjectProperty(vman->getId(), lastActorIO->getEntry(),  "Visibility", 0 );
1724             displayer()->setVisibilityState(lastActorIO->getEntry(), Qtx::HiddenState);
1725         }
1726     }
1727     currentVtkGView->update();
1728     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1729     if (!anIO.IsNull() && anIO->hasEntry())
1730     {
1731         vtkView->Display(anIO);
1732         aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 1 );
1733         displayer()->setVisibilityState(anIO->getEntry(), Qtx::ShownState);
1734     }
1735     vtkView->onFitAll();
1736 }
1737
1738 void HEXABLOCKGUI::showOccActor()
1739 {
1740     if (currentOccGView == NULL)
1741         return;
1742     OCCViewer_ViewWindow* occView = currentOccGView->getViewWindow();
1743     if (occView == NULL)
1744         return;
1745     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1746     if (vf == NULL)
1747         return;
1748
1749     if (lastOccPrs != NULL)
1750         vf->Erase(lastOccPrs);
1751     currentOccGView->globalSelection();
1752     SOCC_Prs* prs = getOccPrs(currentDocGView);
1753     currentOccGView->setPrs(prs);
1754     vf->Display(prs);
1755     vf->Repaint();
1756     occView->onFitAll();
1757 }
1758
1759 void HEXABLOCKGUI::hideVtkActor()
1760 {
1761     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1762     if (currentVtkGView == NULL || currentVtkGView->isEmpty() ||
1763         currentVtkGView->getViewWindow() == NULL ||
1764         currentVtkGView->getDocumentActor() == NULL) return;
1765
1766     currentVtkGView->getViewWindow()->Erase(currentVtkGView->getDocumentActor()->getIO());
1767     currentVtkGView->getViewWindow()->onResetView();
1768
1769     //update the visibility state now
1770     SalomeApp_Study* aStudy = HEXABLOCKGUI::activeStudy();
1771     SUIT_ViewManager* vman = currentVtkGView->getViewWindow()->getViewManager();
1772     if (aStudy == NULL || vman == NULL) return;
1773
1774     Handle(SALOME_InteractiveObject) anIO = currentVtkGView->getDocumentActor()->getIO();
1775     aStudy->setObjectProperty(vman->getId(), anIO->getEntry(),  "Visibility", 0 );
1776     displayer()->setVisibilityState(anIO->getEntry(), Qtx::HiddenState);
1777 }
1778
1779 void HEXABLOCKGUI::hideOccActor()
1780 {
1781     OCCViewer_ViewWindow* occView = currentOccGView == NULL ? NULL : currentOccGView->getViewWindow();
1782     VtkDocumentGraphicView* currentVtkGView = getCurrentVtkGraphicView();
1783     DocumentModel* docModel = (currentVtkGView == NULL ? NULL : currentVtkGView->getDocumentModel());
1784     if (occView == NULL || docModel == NULL)
1785         return;
1786     SALOME_View* vf = dynamic_cast<SALOME_View*>(occView->getViewManager()->getViewModel());
1787     if (vf == NULL)
1788         return;
1789
1790     SOCC_Prs* currentOccPrs = getOccPrs(currentDocGView);
1791     if (currentOccPrs != NULL)
1792         vf->Erase(currentOccPrs);
1793     vf->Repaint();
1794     occView->onResetView();
1795 }
1796
1797 void HEXABLOCKGUI::showOnlyActor()
1798 {
1799     showVtkActor();
1800     showOccActor();
1801 }
1802
1803 void HEXABLOCKGUI::hideActor()
1804 {
1805     hideVtkActor();
1806     hideOccActor();
1807 }
1808
1809
1810 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1811 {
1812     DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1813
1814     if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1815     if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1816
1817     if (_dwPattern) _dwPattern->setVisible(isVisible);
1818     if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1819
1820     if (_dwMesh) _dwMesh->setVisible(isVisible);
1821     if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1822
1823     if (_dwGroups) _dwGroups->setVisible(isVisible);
1824     if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1825 }
1826
1827
1828 //clear all used dialogs by the current model
1829 void HEXABLOCKGUI::clearDialogs()
1830 {
1831     std::set<HexaBaseDialog*>::const_iterator debut (currentModelDialogs.begin()),
1832                                               fin   (currentModelDialogs.end());
1833     for(;debut!=fin;++debut) (*debut)->clear();
1834
1835     currentModelDialogs.clear(); //empty the used dialogs list
1836 }
1837
1838 HexaBaseDialog* HEXABLOCKGUI::getDlgBox(VtkDocumentGraphicView* dgview)
1839 {
1840     if (!gViewDlgBox.contains(dgview)) return NULL;
1841     return gViewDlgBox[dgview];
1842 }
1843
1844 void HEXABLOCKGUI::switchOnGraphicView(VtkDocumentGraphicView* dgview)
1845 {
1846    if (dgview == NULL) return;
1847
1848    switchOffGraphicView(dgview, false); //to avoid double connect
1849
1850    //connect signals
1851    connect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
1852          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ), Qt::UniqueConnection );
1853    connect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1854          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1855 //   connect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1856 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1857    connect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1858             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1859    connect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1860          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1861    connect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1862          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ), Qt::UniqueConnection );
1863
1864    showAllMenus();
1865 }
1866
1867 void HEXABLOCKGUI::switchOffGraphicView(VtkDocumentGraphicView* dgview, bool saveCurrentDlg)
1868 {
1869    if (dgview == NULL) return;
1870
1871    //disconnect signals
1872    disconnect( selectionMgr(), SIGNAL( currentSelectionChanged() ),
1873          dgview->getPatternDataSelectionModel(), SLOT( salomeSelectionChanged() ) );
1874    disconnect( dgview->getPatternDataSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1875          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1876 //   disconnect( dgview->getPatternBuilderSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1877 //         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1878    disconnect( dgview->getPatternGeomSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1879             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1880    disconnect( dgview->getGroupsSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1881          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1882    disconnect( dgview->getMeshSelectionModel(), SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1883          this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1884
1885    if (saveCurrentDlg)
1886        gViewDlgBox[dgview] = currentDialog;
1887
1888    //close opened dialog
1889    if (currentDialog != NULL) currentDialog->close();
1890 //   if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
1891
1892    initialMenus();
1893
1894 }
1895
1896 void HEXABLOCKGUI::switchModel(VtkDocumentGraphicView* dgview)
1897 {
1898     DEBTRACE("HEXABLOCKGUI::switchModel " << dgview);
1899
1900     if (dgview == NULL)
1901     {
1902         MESSAGE("HEXABLOCKGUI::switchModel : no need to switch!");
1903         return;
1904     }
1905
1906     //switch off the current document graphic view (disconnect signals...)
1907     if (currentDocGView != NULL)
1908     {
1909         //Hide current actor
1910         hideActor();
1911         switchOffGraphicView(currentDocGView);
1912     }
1913
1914     //clear the dialogs used by the current model so they can be used by the new model
1915     if (currentDocGView != dgview) clearDialogs();
1916
1917     _patternDataTreeView->setModel(dgview->getPatternDataModel());
1918 //    _patternBuilderTreeView->setModel(dgview->getPatternBuilderModel());
1919     _patternGeomTreeView->setModel(dgview->getPatternGeomModel());
1920     _groupsTreeView->setModel(dgview->getGroupsModel());
1921     _meshTreeView->setModel(dgview->getMeshModel());
1922
1923     _patternDataTreeView->setSelectionModel(dgview->getPatternDataSelectionModel());
1924     _patternDataTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1925
1926 //    _patternBuilderTreeView->setSelectionModel(dgview->getPatternBuilderSelectionModel());
1927 //    _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1928
1929     _patternGeomTreeView->setSelectionModel(dgview->getPatternGeomSelectionModel());
1930     _patternGeomTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1931
1932     _groupsTreeView->setSelectionModel(dgview->getGroupsSelectionModel());
1933     _groupsTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1934
1935     _meshTreeView->setSelectionModel(dgview->getMeshSelectionModel());
1936     _meshTreeView->setEditTriggers(QAbstractItemView::NoEditTriggers);
1937
1938
1939     // = * init occ view * =
1940     if (currentOccGView != NULL && currentOccGView->getViewWindow() == NULL)
1941     {
1942         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
1943         currentOccGView->getViewWindow()->installEventFilter(this);
1944     }
1945     // ==
1946
1947
1948     // = * init vtk view * =
1949     if (currentDocGView != NULL)
1950     {
1951         if (currentDocGView->getViewWindow() != NULL)
1952             dgview->setViewWindow(currentDocGView->getViewWindow());
1953         else
1954         {
1955             dgview->setViewWindow(graphicViewsHandler->createVtkWindow());
1956             dgview->getViewWindow()->installEventFilter(this);
1957         }
1958     }
1959
1960     // ==
1961
1962     switchOnGraphicView(dgview);
1963
1964     if (currentDocGView != NULL)
1965     {
1966         lastVtkDocGView = currentDocGView;
1967         lastOccPrs = getOccPrs(currentDocGView);
1968     }
1969     else
1970     {
1971         lastVtkDocGView = dgview;
1972         lastOccPrs = getOccPrs(dgview);
1973     }
1974
1975     currentDocGView = dgview;
1976     showOnlyActor();
1977     currentDocGView->getDocumentModel()->refresh();
1978 //    _dwPattern->setWindowTitle(currentDocGView->getDocumentModel()->getName());
1979     showAllMenus();
1980 }
1981
1982 DocumentModel* HEXABLOCKGUI::getCurrentModel()
1983 {
1984     if (currentDocGView == NULL) return NULL;
1985     return currentDocGView->getDocumentModel();
1986 }
1987
1988
1989 HEXABLOCKGUI::ViewType HEXABLOCKGUI::getActiveViewType()
1990 {
1991     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
1992     if (anApp == NULL) return UNKNOWN;
1993     SUIT_ViewManager* activeVm = anApp->activeViewManager();
1994     if (activeVm == NULL) return UNKNOWN;
1995
1996    QString vmType = activeVm->getType();
1997    if ( (vmType == SVTK_Viewer::Type()) || (vmType == VTKViewer_Viewer::Type()) )
1998        return VTK;
1999    else if ( vmType == OCCViewer_Viewer::Type() )
2000        return OCC;
2001
2002    return UNKNOWN;
2003 }
2004
2005 HEXABLOCKGUI* HEXABLOCKGUI::getInstance()
2006 {
2007     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2008     if (anApp == NULL)
2009         return NULL;
2010
2011     return  dynamic_cast<HEXABLOCKGUI*>(anApp->activeModule());
2012 }
2013
2014 pair <QString, HEXA_NS::Document*> HEXABLOCKGUI::newHexaDocument()
2015 {
2016     // Create Document from HEXABLOCK ENGINE
2017     // WARNING : IN HEXABLOCK component,  GUI and ENGINE share the same process
2018     // HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default"); // Perime  Hexa6
2019
2020     // looking doc impl ( c++ )
2021     // ^Hexa6 Document_impl* dServant = DownCast<Document_impl*>( docIn );
2022     // ^Hexa6 ASSERT( dServant );
2023     // ^Hexa6 if ( dServant)
2024         // ^Hexa6 doc = dServant->GetImpl();
2025
2026     HEXA_NS::Document* doc = hexa_root->addDocument ("default");
2027     QString docEntry = addDocInStudy (doc);
2028
2029     // looking for docEntry
2030     /* ****************************************************************
2031     if ( !CORBA::is_nil(docIn) ){
2032         CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2033         QString docIOR = anIOR.in();
2034         SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2035         if ( !docIOR.isEmpty() ) {
2036             _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2037             if ( SO )
2038                 docEntry = SO->GetID().c_str();
2039         }
2040     }
2041        **************************************************************** */
2042     DEBTRACE("HEXABLOCKGUI::newHexaDocument docEntry "<<docEntry.toStdString());
2043
2044     return make_pair (docEntry, doc);
2045 }
2046
2047
2048 void HEXABLOCKGUI::newDocument()
2049 {
2050     DEBTRACE("HEXABLOCKGUI::newDocument");
2051
2052     createSComponent();
2053     QMainWindow *aParent = application()->desktop();
2054     QWidget *central = aParent->centralWidget();
2055     if (central)
2056         central->setFocus();
2057     else
2058         DEBTRACE("No Central Widget");
2059
2060     //Init OCC
2061     if (currentOccGView == NULL)
2062     {
2063         currentOccGView = new OccGraphicView(graphicViewsHandler->createOccWindow(),
2064                 application()->desktop());
2065         currentOccGView->getViewWindow()->installEventFilter(this);
2066     }
2067     else if (currentOccGView->getViewWindow() == NULL)
2068     {
2069         currentOccGView->setViewWindow(graphicViewsHandler->createOccWindow());
2070         currentOccGView->getViewWindow()->installEventFilter(this);
2071     }
2072
2073     //NEW DOCUMENT
2074     // Create Document from HEXABLOCK ENGINE
2075     pair <QString, HEXA_NS::Document*> docEntry_Doc ( newHexaDocument() );
2076
2077     VtkDocumentGraphicView* newGraphicView = NULL;
2078     //One document at a time
2079     if (currentDocGView != NULL)
2080     {
2081         if (currentDocGView->getViewWindow() == NULL)
2082         {
2083             currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2084             currentDocGView->getViewWindow()->installEventFilter(this);
2085         }
2086
2087           // Create a new document with the current window
2088           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2089                                         new DocumentModel( docEntry_Doc.second,
2090                                         docEntry_Doc.first, this ),
2091                                         currentDocGView->getViewWindow(),
2092                                         application()->desktop() );
2093     }
2094     else
2095     {
2096           // Create the new Document Graphic View with a new window
2097           newGraphicView = graphicViewsHandler->createDocumentGraphicView(
2098                                         new DocumentModel( docEntry_Doc.second,
2099                                         docEntry_Doc.first, this ),
2100                                         graphicViewsHandler->createVtkWindow(),
2101                                         application()->desktop() );
2102           newGraphicView->getViewWindow()->installEventFilter(this);
2103     }
2104
2105     if (newGraphicView == NULL)
2106         //We couldn't create a new document graphic view
2107         //we'd better show a dialog box info to inform the user
2108         return;
2109
2110     docs[docEntry_Doc.first] = newGraphicView;
2111     switchModel(newGraphicView); //select the corresponding document in the browser instead
2112
2113     getApp()->updateObjectBrowser();
2114     showAllMenus();
2115 }
2116
2117
2118 //Loads the model from the xmlFile in the current graphic view
2119 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2120 {
2121     DEBTRACE("HEXABLOCKGUI::loadDocument");
2122
2123     createSComponent();
2124     QMainWindow *aParent = application()->desktop();
2125     QString selectedFile;
2126
2127     if ( inFile.isNull() ){
2128         QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2129                 QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2130         dialog.setHistory( getQuickDirList() );
2131
2132         //use the last path as default
2133         if (!(loadDocLastPath->absolutePath()).isEmpty())
2134             dialog.setDirectory(*loadDocLastPath);
2135
2136         if (dialog.exec()){
2137             QStringList selectedFiles = dialog.selectedFiles();
2138             if (!selectedFiles.isEmpty())
2139                 selectedFile = selectedFiles.first();
2140
2141             //remember the selected path
2142             *loadDocLastPath = dialog.directory();
2143         }
2144     } else
2145         selectedFile = inFile;
2146
2147     if (selectedFile.isEmpty())
2148         return;
2149
2150     //we create a new document if necessary
2151     if (currentDocGView == NULL)
2152         //Need a new document
2153         newDocument();
2154     else if (currentDocGView->getViewWindow() == NULL) //there's a document without a view
2155     {
2156         currentDocGView->setViewWindow(graphicViewsHandler->createVtkWindow());
2157         currentDocGView->getViewWindow()->installEventFilter(this);
2158     }
2159
2160     if (!currentDocGView->isEmpty())
2161         //we can only have one document for a graphic view
2162         newDocument();
2163
2164     //we load the selected file in the current graphic view
2165     currentDocGView->loadDocument(selectedFile);
2166     DocumentModel* currentModel = getCurrentModel();
2167     renameObject( currentModel->documentEntry(), currentModel->getName() );
2168
2169     showOnlyActor();
2170 }
2171
2172 void HEXABLOCKGUI::saveDocument()
2173 {
2174     QMainWindow *aParent = application()->desktop();
2175
2176     QString aDocName = "document", aFilename;
2177     QStringList filter;
2178     filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2179     filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2180
2181     //use the last selected directory as default path for file selection
2182     aFilename =  saveDocLastPath->absolutePath();
2183     if (!aFilename.isEmpty())
2184         aFilename += QString("/") + aDocName;
2185
2186     //show the dialog for file selection
2187     aFilename = SUIT_FileDlg::getFileName( aParent,
2188             aFilename,
2189             filter,
2190             tr( "Save HexaBlock Document" ),
2191             false );
2192
2193     //save the document in the selected file
2194     if ( !aFilename.isEmpty() ) {
2195         getCurrentVtkGraphicView()->saveDocument( aFilename );
2196
2197         //Remember the path for next save
2198         QFileInfo fileInfo(aFilename);
2199         *saveDocLastPath = fileInfo.dir();
2200     }
2201     //CS_TODO save doc
2202 }
2203
2204
2205 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight)
2206 {
2207     _patternDataTreeView->openPersistentEditor( topLeft );
2208 }
2209
2210 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2211 {
2212     if (diag == NULL || _dwInputPanel == NULL ||
2213             getCurrentVtkGraphicView() == NULL) return;
2214
2215     //mark this dialog as used by the current model
2216     currentModelDialogs.insert(diag);
2217
2218     //close the current dialog box info
2219 //    if (_treeViewDelegate != NULL)
2220 //        _treeViewDelegate->closeDialog();
2221
2222 //    if (_dwInputPanel->widget())
2223 //        _dwInputPanel->widget()->close();
2224
2225     //Temporary for debugging EdgeAssoc Faked InfoDialog
2226     if (diag == _edgeAssocDiag)
2227         diag->debugEdgeAssoc = true;
2228     else
2229         diag->debugEdgeAssoc = false;
2230
2231     if (diag == _vertexAssocDiag || diag ==  _edgeAssocDiag ||
2232                 diag ==  _quadAssocDiag || diag == _addShapeDiag)
2233         assocInProgress = true;
2234     else
2235         assocInProgress = false;
2236
2237     //show the dialog box in the dockwidget
2238     diag->resetSizeAndShow(_dwInputPanel);
2239
2240     //clear the current selections
2241     selectionMgr()->clearSelected();
2242
2243     currentDialog = diag;
2244     diag->setFocus();
2245
2246     if (currentDocGView != NULL)
2247         currentDocGView->getPatternDataSelectionModel()->setInfoMode(false);
2248 }
2249
2250 void HEXABLOCKGUI::showVertexInfoDialog(HEXA_NS::Vertex* vertex)
2251 {
2252     if (vertex == NULL || _dwInputPanel == NULL)
2253         return;
2254
2255     if (_vertexInfoDialog == NULL)
2256         _vertexInfoDialog = new VertexDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2257
2258     _vertexInfoDialog->setValue(vertex);
2259     _vertexInfoDialog->resetSizeAndShow(_dwInputPanel);
2260     currentDialog = _vertexInfoDialog;
2261 }
2262
2263 void HEXABLOCKGUI::showEdgeInfoDialog(HEXA_NS::Edge* edge)
2264 {
2265     if (edge == NULL || _dwInputPanel == NULL)
2266         return;
2267
2268     if (_edgeInfoDialog == NULL)
2269         _edgeInfoDialog = new EdgeDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2270
2271     _edgeInfoDialog->setValue(edge);
2272     _edgeInfoDialog->resetSizeAndShow(_dwInputPanel);
2273     currentDialog = _edgeInfoDialog;
2274 }
2275
2276 void HEXABLOCKGUI::showQuadInfoDialog(HEXA_NS::Quad* quad)
2277 {
2278     if (quad == NULL || _dwInputPanel == NULL)
2279         return;
2280
2281     if (_quadInfoDialog == NULL)
2282         _quadInfoDialog = new QuadDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2283
2284     _quadInfoDialog->setValue(quad);
2285     _quadInfoDialog->resetSizeAndShow(_dwInputPanel);
2286     currentDialog = _quadInfoDialog;
2287 }
2288
2289 void HEXABLOCKGUI::showHexaInfoDialog(HEXA_NS::Hexa* hexa)
2290 {
2291     if (hexa == NULL || _dwInputPanel == NULL)
2292         return;
2293
2294     if (_hexaInfoDialog == NULL)
2295         _hexaInfoDialog = new HexaDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2296
2297     _hexaInfoDialog->setValue(hexa);
2298     _hexaInfoDialog->resetSizeAndShow(_dwInputPanel);
2299     currentDialog = _hexaInfoDialog;
2300 }
2301
2302 void HEXABLOCKGUI::showVectorInfoDialog(HEXA_NS::Vector* vector)
2303 {
2304     if (vector == NULL || _dwInputPanel == NULL)
2305         return;
2306
2307     if (_vectorInfoDialog == NULL)
2308         _vectorInfoDialog = new VectorDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2309
2310     _vectorInfoDialog->setValue(vector);
2311     _vectorInfoDialog->resetSizeAndShow(_dwInputPanel);
2312     currentDialog = _vectorInfoDialog;
2313 }
2314
2315 void HEXABLOCKGUI::showGroupInfoDialog(HEXA_NS::Group* group)
2316 {
2317     if (group == NULL || _dwInputPanel == NULL)
2318         return;
2319
2320     if (_groupInfoDialog == NULL)
2321         _groupInfoDialog = new GroupDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2322
2323     _groupInfoDialog->setValue(group);
2324     _groupInfoDialog->resetSizeAndShow(_dwInputPanel);
2325     currentDialog = _groupInfoDialog;
2326 }
2327
2328 void HEXABLOCKGUI::showLawInfoDialog(HEXA_NS::Law* law)
2329 {
2330     if (law == NULL || _dwInputPanel == NULL)
2331         return;
2332
2333     if (_lawInfoDialog == NULL)
2334         _lawInfoDialog = new LawDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2335
2336     _lawInfoDialog->setValue(law);
2337     _lawInfoDialog->resetSizeAndShow(_dwInputPanel);
2338     currentDialog = _lawInfoDialog;
2339 }
2340
2341 void HEXABLOCKGUI::showPropagationInfoDialog(HEXA_NS::Propagation* propagation)
2342 {
2343     if (propagation == NULL || _dwInputPanel == NULL)
2344         return;
2345
2346     if (_propagationInfoDialog == NULL)
2347         _propagationInfoDialog = new PropagationDialog(_dwInputPanel, HexaBaseDialog::INFO_MODE);
2348
2349     _propagationInfoDialog->setValue(propagation);
2350     _propagationInfoDialog->resetSizeAndShow(_dwInputPanel);
2351     currentDialog = _propagationInfoDialog;
2352 }
2353
2354 void HEXABLOCKGUI::addVertex()
2355 {
2356     if ( !_vertexDiag ){
2357         _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2358     }
2359     _showDialogBox( _vertexDiag );
2360
2361     //set default name
2362     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2363     if (_vertexDiag != NULL && doc != NULL)
2364         _vertexDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VERTEX).c_str());
2365 }
2366
2367 void HEXABLOCKGUI::addEdge()
2368 {
2369     if ( !_edgeDiag ){
2370         _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2371     }
2372     _showDialogBox( _edgeDiag );
2373
2374     //set default name
2375     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2376     if (_edgeDiag != NULL && doc != NULL)
2377         _edgeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_EDGE).c_str());
2378 }
2379
2380 void HEXABLOCKGUI::addQuad()
2381 {
2382     if ( !_quadDiag ){
2383         _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2384
2385     }
2386     _showDialogBox( _quadDiag );
2387
2388     //set default name
2389     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2390     if (_quadDiag != NULL && doc != NULL)
2391         _quadDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_QUAD).c_str());
2392 }
2393
2394 void HEXABLOCKGUI::addHexa()
2395 {
2396     if ( !_hexaDiag ){
2397         _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2398     }
2399     _showDialogBox( _hexaDiag );
2400
2401     //set default name
2402     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2403     if (_hexaDiag != NULL && doc != NULL)
2404         _hexaDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_HEXA).c_str());
2405 }
2406
2407 void HEXABLOCKGUI::addVector()
2408 {
2409     if ( !_vectorDiag ){
2410         _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2411     }
2412     _showDialogBox( _vectorDiag );
2413
2414     //set default name
2415     HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2416     if (_vectorDiag != NULL && doc != NULL)
2417         _vectorDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_VECTOR).c_str());
2418 }
2419
2420 //void HEXABLOCKGUI::addCylinder()
2421 //{
2422 //    if ( !_cylinderDiag ){
2423 //        _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2424 //    }
2425 //    _showDialogBox( _cylinderDiag );
2426 //
2427 //    //set default name
2428 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2429 //    if (_cylinderDiag != NULL && doc != NULL)
2430 //        _cylinderDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2431 //}
2432
2433
2434 //void HEXABLOCKGUI::addPipe()
2435 //{
2436 //    if ( !_pipeDiag){
2437 //        _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2438 //    }
2439 //    _showDialogBox( _pipeDiag );
2440 //
2441 //    //set default name
2442 //    HEXA_NS::Document* doc = getCurrentModel() ? getCurrentModel()->getHexaDocument() : NULL;
2443 //    if (_pipeDiag != NULL && doc != NULL)
2444 //        _pipeDiag->name_le->setText(doc->getNextName(HEXA_NS::EL_CYLINDER).c_str());
2445 //}
2446
2447
2448 void HEXABLOCKGUI::makeGrid()
2449 {
2450     if ( !_makeGridDiag ){
2451         _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2452     }
2453     _showDialogBox( _makeGridDiag );
2454 }
2455
2456
2457 void HEXABLOCKGUI::makeCylinder()
2458 {
2459     if ( !_makeCylinderDiag ){
2460         _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2461     }
2462     _showDialogBox( _makeCylinderDiag );
2463 }
2464
2465 void HEXABLOCKGUI::makePipe()
2466 {
2467     if ( !_makePipeDiag ){
2468         _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2469     }
2470     _showDialogBox( _makePipeDiag );
2471 }
2472
2473 void HEXABLOCKGUI::makeCylinders()
2474 {
2475     if ( !_makeCylindersDiag ){
2476         _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2477     }
2478     _showDialogBox( _makeCylindersDiag );
2479 }
2480
2481 void HEXABLOCKGUI::makePipes()
2482 {
2483     if ( !_makePipesDiag ){
2484         _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2485     }
2486     _showDialogBox( _makePipesDiag );
2487 }
2488
2489
2490 void HEXABLOCKGUI::makeHemiSphere()  // NEW HEXA3
2491 {
2492     if ( !_makeHemiSphereDiag ){
2493         _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2494     }
2495     _showDialogBox( _makeHemiSphereDiag );
2496 }
2497
2498
2499 void HEXABLOCKGUI::removeHexa()
2500 {
2501     if ( !_removeHexaDiag ){
2502         _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2503     }
2504     _showDialogBox( _removeHexaDiag );
2505 }
2506
2507
2508 void HEXABLOCKGUI::prismQuad()
2509 {
2510     if ( !_prismQuadDiag ){
2511         _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2512     }
2513     _showDialogBox( _prismQuadDiag );
2514 }
2515
2516
2517 void HEXABLOCKGUI::joinQuad()
2518 {
2519     if ( !_joinQuadDiag ){
2520         _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2521     }
2522     _showDialogBox( _joinQuadDiag );
2523 }
2524
2525 void HEXABLOCKGUI::merge()
2526 {
2527     if ( !_mergeDiag ){
2528         _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2529     }
2530     _showDialogBox( _mergeDiag );
2531 }
2532
2533 void HEXABLOCKGUI::disconnectElts()
2534 {
2535     if ( !_disconnectDiag ){
2536         _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2537     }
2538     _showDialogBox( _disconnectDiag );
2539 }
2540
2541 void HEXABLOCKGUI::cutEdge()
2542 {
2543     if ( !_cutEdgeDiag ){
2544         _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2545     }
2546     _showDialogBox( _cutEdgeDiag );
2547 }
2548
2549 void HEXABLOCKGUI::makeTransformation()
2550 {
2551     if ( !_makeTransformationDiag ){
2552         _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2553     }
2554     _showDialogBox( _makeTransformationDiag );
2555 }
2556
2557
2558 void HEXABLOCKGUI::makeSymmetry()
2559 {
2560     if ( !_makeSymmetryDiag ){
2561         _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2562     }
2563     _showDialogBox( _makeSymmetryDiag );
2564 }
2565
2566
2567 void HEXABLOCKGUI::performTransformation()
2568 {
2569     if ( !_performTransformationDiag ){
2570         _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2571     }
2572     _showDialogBox( _performTransformationDiag );
2573 }
2574
2575
2576 void HEXABLOCKGUI::performSymmetry()
2577 {
2578     if ( !_performSymmetryDiag ){
2579         _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2580     }
2581     _showDialogBox( _performSymmetryDiag );
2582 }
2583
2584
2585 void HEXABLOCKGUI::replaceHexa()    // NEW HEXA3
2586 {
2587     if ( !_replaceHexaDiag ){
2588         _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2589     }
2590     _showDialogBox( _replaceHexaDiag );
2591 }
2592
2593
2594 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2595 {
2596     if ( !_quadRevolutionDiag ){
2597         _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2598     }
2599     _showDialogBox( _quadRevolutionDiag );
2600 }
2601
2602
2603 void HEXABLOCKGUI::assocVertex()
2604 {
2605         if (!_dwInputPanel) return;
2606         QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2607         if ( !_vertexAssocDiag  )
2608                 _vertexAssocDiag  = new VertexAssocDialog( d /*_dwInputPanel*/);
2609         _showDialogBox( _vertexAssocDiag );
2610 }
2611
2612
2613 void HEXABLOCKGUI::assocEdge()
2614 {
2615     if ( !_edgeAssocDiag )
2616         _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2617     _showDialogBox( _edgeAssocDiag );
2618 }
2619
2620 void HEXABLOCKGUI::assocQuad()
2621 {
2622     if ( !_quadAssocDiag )
2623         _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2624     _showDialogBox( _quadAssocDiag );
2625 }
2626
2627
2628 void HEXABLOCKGUI::addGroup()
2629 {
2630     if ( !_groupDiag ){
2631         _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2632     }
2633     _showDialogBox( _groupDiag );
2634     if (_groupDiag != NULL && getCurrentModel() != NULL)
2635     {
2636         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2637         if (doc == NULL) return;
2638         char defaultName[16];
2639         sprintf (defaultName, "g%04d", doc->countGroup());
2640         _groupDiag->name_le->setText(defaultName);
2641     }
2642 }
2643
2644 void HEXABLOCKGUI::removeGroup()
2645 {
2646     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2647     if (currentDGView == NULL) return;
2648
2649     QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2650     QModelIndexList l = groupsSelectionModel->selectedIndexes();
2651     int nbGroupsRemoved = 0;
2652
2653     if ( l.isEmpty() ){
2654         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2655                 tr( "No group selected!" ) );
2656         return;
2657     }
2658
2659     foreach( QModelIndex selected, l ){
2660         if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2661             selected = currentDGView->getGroupsModel()->mapToSource( selected );
2662             Q_ASSERT(selected.isValid());
2663
2664             //Confirm the deletion of the group
2665             if (SUIT_MessageBox::question(
2666                     0,
2667                     tr("Remove Group"),
2668                     tr("Remove group : %1 ?").arg(selected.data().toString()),
2669                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2670                     SUIT_MessageBox::Cancel
2671             ) == SUIT_MessageBox::Cancel) return;
2672
2673             bool removed = getCurrentModel()->removeGroup( selected );
2674             if ( !removed ) {
2675                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2676                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2677                 return;
2678             }
2679             nbGroupsRemoved++;
2680         }
2681     }
2682     if (!nbGroupsRemoved)
2683         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ),
2684                 tr( "No group selected!" ) );
2685 }
2686
2687 void HEXABLOCKGUI::addLaw()
2688 {
2689     if ( !_lawDiag ){
2690         _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2691     }
2692     _showDialogBox( _lawDiag );
2693     if (_lawDiag != NULL && getCurrentModel() != NULL)
2694     {
2695         HEXA_NS::Document* doc = getCurrentModel()->getHexaDocument();
2696         if (doc == NULL) return;
2697         char defaultName[16];
2698         sprintf (defaultName, "l%04d", doc->countLaw());
2699         _lawDiag->name_le->setText(defaultName);
2700     }
2701 }
2702
2703 void HEXABLOCKGUI::removeLaw()
2704 {
2705     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2706     if (currentDGView == NULL) return;
2707
2708     QModelIndexList l = currentDGView->getMeshSelectionModel()->selectedIndexes();
2709     int nbLawsRemoved = 0;
2710
2711     if ( l.isEmpty() ){
2712         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2713                 tr( "No law selected!" ) );
2714         return;
2715     }
2716
2717     foreach( QModelIndex selected, l ){
2718         if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2719             selected = currentDGView->getMeshModel()->mapToSource( selected );
2720             Q_ASSERT(selected.isValid());
2721
2722             //Confirm the deletion of the law
2723             if (SUIT_MessageBox::question(
2724                     0,
2725                     tr("Remove Law"),
2726                     tr("Remove law : %1 ?\nAll propagations having this law will have the default law.").arg(selected.data().toString()),
2727                     SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2728                     SUIT_MessageBox::Cancel
2729             ) == SUIT_MessageBox::Cancel) return;
2730
2731             bool removed = getCurrentModel()->removeLaw(selected);
2732             if ( !removed ) {
2733                 SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ),
2734                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2735                 return;
2736             }
2737             nbLawsRemoved++;
2738         }
2739     }
2740     if (!nbLawsRemoved)
2741         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ),
2742                                          tr( "No law selected!" ) );
2743
2744 }
2745
2746
2747 void HEXABLOCKGUI::setPropagation()
2748 {
2749     if ( !_propagationDiag )
2750         _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2751
2752     _showDialogBox( _propagationDiag );
2753 }
2754
2755 // Dialog box to compute a mesh from a document
2756 // --------------------------------------------
2757 void HEXABLOCKGUI::computeMesh()
2758 {
2759     if ( !_computeMeshDiag )
2760         _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2761
2762     _showDialogBox( _computeMeshDiag );
2763 }
2764
2765 void HEXABLOCKGUI::clearAssociations()
2766 {
2767     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2768     if (currentDGView == NULL) return;
2769
2770     //   QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2771     QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2772     QModelIndex iModel     = currentDGView->getPatternDataModel()->mapToSource(iDataModel);
2773
2774     getCurrentModel()->clearEltAssociations(iModel);
2775
2776     //  SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2777 }
2778
2779 void HEXABLOCKGUI::showModelInfo()
2780 {
2781     //create the info dialog if not yet
2782     if (_modelInfoDiag == NULL)
2783         _modelInfoDiag = new ModelInfoDialog(_dwInputPanel);
2784
2785     //show the model informations dialog
2786     _showDialogBox( _modelInfoDiag );
2787 }
2788
2789 void HEXABLOCKGUI::addShape()
2790 {
2791     //create the info dialog if not yet
2792     if (_addShapeDiag == NULL)
2793         _addShapeDiag = new AddShapeDialog(_dwInputPanel);
2794
2795     //show the model informations dialog
2796     _showDialogBox( _addShapeDiag );
2797 }
2798
2799 void HEXABLOCKGUI::clearAllAssociations()
2800 {
2801     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2802     if (currentDGView == NULL) return;
2803
2804     QModelIndex currentIndex = currentDGView->getPatternDataModel()->mapToSource(_patternDataTreeView->currentIndex());
2805     if (!currentIndex.isValid()) return;
2806     QVariant currentAssocVariant;
2807     QString currentAssocEntry;
2808
2809     //Confirm the deletion of the associations
2810     QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
2811     if ( !treeVariant.isValid() ) return;
2812     int eltType = treeVariant.toInt();
2813     QString typeStr = "";
2814     HEXA_NS::EnumElt hexaType;
2815     if (eltType == VERTEX_DIR_TREE)
2816     {
2817         typeStr = tr("TREE_ITEM_VERTEX").toUpper();
2818         hexaType = HEXA_NS::EL_VERTEX;
2819     }
2820     else if (eltType == EDGE_DIR_TREE)
2821     {
2822         typeStr = tr("TREE_ITEM_EDGE").toUpper();
2823         hexaType = HEXA_NS::EL_EDGE;
2824     }
2825     else if (eltType == QUAD_DIR_TREE)
2826     {
2827         typeStr = tr("TREE_ITEM_QUAD").toUpper();
2828         hexaType = HEXA_NS::EL_QUAD;
2829     }
2830
2831     if (SUIT_MessageBox::question(
2832             0,
2833             tr("CLEAR_ASSOCIATIONS"),
2834             tr("CLEAR_ALL_ASSOCIATIONS_ON") + " " + typeStr + "?",
2835             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2836             SUIT_MessageBox::Cancel
2837     ) == SUIT_MessageBox::Cancel) return;
2838
2839
2840     DocumentModel* docModel = getCurrentModel();
2841     if (docModel == NULL) return;
2842     docModel->clearAssociation(hexaType);
2843 }
2844
2845 void HEXABLOCKGUI::showAssociations()
2846 {
2847     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
2848     if (currentDGView == NULL) return;
2849
2850     QModelIndexList elts;
2851     int currentChildIndex = 0;
2852     QVariant currentAssocVariant;
2853     QString currentAssocEntry;
2854     QModelIndex currentIndex = _patternDataTreeView->currentIndex();
2855     QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2856
2857     while( currentChild.isValid() ) {
2858
2859         currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2860         currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2861         if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2862             elts << currentChild;
2863
2864         currentChild = currentChild.sibling(currentChildIndex++, 0);
2865     }
2866     currentDocGView->highlight(elts);
2867     currentOccGView->highlight(elts, false);
2868 }
2869
2870
2871 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
2872 {
2873     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2874     if( anApp )
2875         return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2876     else
2877         return NULL;
2878 }
2879
2880 bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
2881 {
2882     if ( event->type() == QEvent::Enter )
2883     {   // *** ENTER EVENT
2884
2885         if (currentDialog == NULL || !currentDialog->isVisible())
2886             return QObject::eventFilter(obj, event);
2887
2888         //  ** The window acquire the focus when the cursor enter
2889
2890             //OCC - window enter
2891         OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
2892         if ( occWindow != NULL)
2893             currentDialog->onWindowActivated(occWindow->getViewManager());
2894         else
2895             //VTK - window enter
2896         {
2897             SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
2898             if ( vtkWindow != NULL)
2899                 currentDialog->onWindowActivated(vtkWindow->getViewManager());
2900         }
2901     }
2902
2903     //standard event processing
2904     return QObject::eventFilter(obj, event);
2905 }
2906
2907 QStringList HEXABLOCKGUI::getQuickDirList()
2908 {
2909     QStringList dirList;
2910     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2911     if ( resMgr )
2912         dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
2913
2914     return dirList;
2915 }
2916
2917
2918 // --- Export the module
2919
2920 extern "C"
2921 {
2922     HEXABLOCK_EXPORT CAM_Module* createModule()
2923     {
2924         return new HEXABLOCKGUI();
2925     }
2926
2927     HEXABLOCK_EXPORT char* getModuleVersion()
2928     {
2929         return (char*)HEXABLOCK_VERSION_STR;
2930     }
2931 }
2932
2933
2934
2935 // ******************** TESTS ***************************************************
2936
2937 void HEXABLOCKGUI::testDocument()
2938 {
2939     //CS_TEST
2940     // ----------
2941     //   QStandardItem *parentItem = getCurrentModel()->invisibleRootItem();
2942     //   QStandardItem *myItem =  new QStandardItem("MyItem");
2943     //   parentItem->appendRow(myItem);
2944     // //   ----------
2945     //   QModelIndex v0 = getCurrentModel()->addVertex(0., 0., 0.);
2946     //   QModelIndex v1 = getCurrentModel()->addVertex(5., 0., 0.);
2947     //   QModelIndex v2 = getCurrentModel()->addVertex(5., 5., 0.);
2948     //   QModelIndex v3 = getCurrentModel()->addVertex(0., 5., 0.);
2949     //   QModelIndex v4 = getCurrentModel()->addVertex(0., 0., 5.);
2950     //   QModelIndex v5 = getCurrentModel()->addVertex(5., 0., 5.);
2951     //   QModelIndex v6 = getCurrentModel()->addVertex(5., 5., 5.);
2952     //   QModelIndex v7 = getCurrentModel()->addVertex(0., 5., 5.);
2953     // //
2954     // //
2955     //   QModelIndex q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
2956     //   QModelIndex q1 = getCurrentModel()->addQuadVertices( v4, v5, v6, v7 );
2957     //   QModelIndex q2 = getCurrentModel()->addQuadVertices( v0, v3, v7, v4 );
2958     //   QModelIndex q3 = getCurrentModel()->addQuadVertices( v1, v2, v6, v5 );
2959     //   QModelIndex q4 = getCurrentModel()->addQuadVertices( v0, v1, v5, v4 );
2960     //   QModelIndex q5 = getCurrentModel()->addQuadVertices( v3, v2, v6, v7 );
2961     //
2962     //   QModelIndex h0 = getCurrentModel()->addHexaQuad( q0, q1, q2, q3, q4, q5 );
2963     //   QModelIndex vx = getCurrentModel()->addVector(1., 0., 0.);
2964     //   QModelIndex vy = getCurrentModel()->addVector(0., 1., 0.);
2965     //   QModelIndex vz = getCurrentModel()->addVector(0., 0., 1.);
2966     //
2967
2968
2969
2970     // //   QModelIndex orig1 = getCurrentModel()->addVertex (0, 0,0);
2971     // //   QModelIndex orig2 = getCurrentModel()->addVertex (50,0,0);
2972     // //   QModelIndex vz    = getCurrentModel()->addVector (0,0,1);
2973     // //   QModelIndex vx    = getCurrentModel()->addVector (1,0,0);
2974     // //
2975     // //   int nr  = 4;
2976     // //   int nri = 3;
2977     // //   int nre = nr;
2978     // //   int na = 9;
2979     // //   int nl = 5;
2980     // //
2981     // //   QModelIndex  cyl  = getCurrentModel()->addCylinder   (orig1, vz, nr, nl);
2982     // //   QModelIndex  pipe = getCurrentModel()->addPipe       (orig2, vz, nri, nre, nl);
2983     // //
2984     // //   getCurrentModel()->makeCylinder (cyl,  vx, nr, na, nl);
2985     // //   getCurrentModel()->makePipe(pipe, vx, nr, na, nl);
2986
2987
2988
2989     //   newMesh( "toto", 3, "FactoryServer");
2990     // newMesh
2991 }
2992
2993 void HEXABLOCKGUI::test_make_cart_grid()
2994 {
2995     QModelIndex orig1 = getCurrentModel()->addVertex( 0, 0, 0);
2996     QModelIndex orig2 = getCurrentModel()->addVertex( 10, 0, 0);
2997     QModelIndex orig3 = getCurrentModel()->addVertex( 0, 10, 0);
2998     QModelIndex orig4 = getCurrentModel()->addVertex( 10, 10, 0);
2999     QModelIndex orig5 = getCurrentModel()->addVertex( 0, 20, 0);
3000     QModelIndex orig6 = getCurrentModel()->addVertex( 10, 20, 0);
3001
3002     QModelIndex vz = getCurrentModel()->addVector(0, 0, 1);
3003     QModelIndex vx = getCurrentModel()->addVector(1, 0, 0);
3004
3005     //int dr = 1;
3006     //int dl = 1;
3007     //int nr = 2;
3008     //int nl = 3;
3009
3010     // QModelIndex c1 = getCurrentModel()->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
3011     // QModelIndex c2 = getCurrentModel()->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
3012     // QModelIndex c3 = getCurrentModel()->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
3013     // QModelIndex c4 = getCurrentModel()->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
3014     // QModelIndex c5 = getCurrentModel()->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
3015     // QModelIndex c6 = getCurrentModel()->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
3016
3017 }
3018
3019
3020 void HEXABLOCKGUI::test_make_elmts_transform()
3021 {
3022
3023 //    int size_x = 1;
3024 //    int size_y = 1;
3025 //    int size_z = 2;
3026 //
3027 //    QModelIndex orig = getCurrentModel()->addVertex(0, 0, 0);
3028 //    QModelIndex dirVr = getCurrentModel()->addVector(1, 1, 1);
3029
3030     //obsolete
3031 //    QModelIndex grid = getCurrentModel()->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
3032     // orig.setScalar(2);
3033
3034     // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
3035     // getCurrentModel()->saveVtk(file_name)
3036
3037 //    QModelIndex devant = getCurrentModel()->addVector(5, 0, 0);
3038 //    QModelIndex grid2  = getCurrentModel()->makeTranslation(grid, devant);
3039
3040     // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
3041     // getCurrentModel()->saveVtk(file_name)
3042
3043 //    QModelIndex grid4 = getCurrentModel()->makeRotation(grid2, orig, dirVr, 45);
3044
3045
3046     // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
3047     // getCurrentModel()->saveVtk(file_name);
3048
3049
3050     // print "...test make elements by transforming elements OK"
3051 }
3052 // =============================================================== addDocInSudy
3053 QString HEXABLOCKGUI::addDocInStudy (HEXA_NS::Document* document)
3054 {
3055     QString docEntry;
3056
3057     if (document == NULL)
3058         return docEntry;
3059
3060     QString docName  = document->getName ();
3061
3062     SalomeApp_Study* app_study = HEXABLOCKGUI::activeStudy();
3063     if (app_study == NULL)
3064         return docEntry;
3065
3066     _PTR(Study)         study    = app_study->studyDS();
3067     SALOMEDS::Study_var ds_study = ClientStudyToStudy (study);
3068     SALOMEDS::StudyBuilder_var aBuilder (ds_study->NewBuilder());
3069     QString entry = app_study->centry("HEXABLOCK");
3070     SALOMEDS::SObject_var aFatherSO = ds_study->FindObjectID( qPrintable(entry) );
3071     if (aFatherSO->_is_nil())
3072         return docEntry;
3073
3074     SALOMEDS::SObject_var aSO = aBuilder->NewObject(aFatherSO);
3075     if (aSO->_is_nil())
3076         return docEntry;
3077     aSO->SetAttrString("AttributeName", docName.toStdString().c_str());
3078     docEntry = aSO->GetID(); //the entry of the published object
3079
3080     return docEntry;
3081 }
3082
3083 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
3084
3085 void HEXABLOCKGUI::test()
3086 {
3087     DEBTRACE("HEXABLOCKGUI::test");
3088     VtkDocumentGraphicView* currentDGView = getCurrentVtkGraphicView();
3089     if (currentDGView == NULL) return;
3090     currentDGView->update();
3091
3092 }
3093
3094 void HEXABLOCKGUI::test_association()
3095 {
3096     DEBTRACE("HEXABLOCKGUI::test_association");
3097     newDocument();
3098
3099     QModelIndex v0, v1, v2, v3, e0, e1, q0;
3100
3101     DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
3102     DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
3103     DocumentModel::GeomObj q0AssocA, q0AssocB;
3104
3105     DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
3106     QList<DocumentModel::GeomObj> e1Assocs_test;
3107     DocumentModel::GeomObj q0Assoc_test;
3108
3109     v0 = getCurrentModel()->addVertex(0, 0, 0);
3110     v1 = getCurrentModel()->addVertex(1, 0, 0);
3111     v2 = getCurrentModel()->addVertex(1, 1, 0);
3112     v3 = getCurrentModel()->addVertex(0, 1, 0);
3113     e0  = getCurrentModel()->addEdgeVertices(v0, v1);
3114     e1  = getCurrentModel()->addEdgeVertices(v1, v2);
3115     q0 = getCurrentModel()->addQuadVertices( v0, v1, v2, v3 );
3116
3117
3118     // >>> face3.GetEntry()'0:1:4'
3119     // >>> e1.GetEntry()'0:1:8'
3120     // >>> e2.GetEntry()'0:1:9'
3121     // >>> e3.GetEntry()'0:1:10'
3122     // >>> e4.GetEntry()'0:1:11'
3123     // >>> v1.GetEntry()'0:1:12'
3124     // >>> v2.GetEntry()'0:1:13'
3125     // >>> v3.GetEntry()'0:1:14'
3126     // >>> v4.GetEntry()'0:1:15'
3127
3128
3129     //   v0Assoc.name  = "geomV0";
3130     //   v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
3131     //   v0Assoc.brep  = "brepV0";
3132     //   v1Assoc.name  = "geomV1";
3133     //   v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
3134     //   v1Assoc.brep  = "brepV1";
3135     //   v2Assoc.name  = "geomV2";
3136     //   v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
3137     //   v2Assoc.brep  = "brepV2";
3138     //   v3Assoc.name  = "geomV3";
3139     //   v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
3140     //   v3Assoc.brep  = "brepV3";
3141     //
3142     //
3143     //
3144     //   e0AssocA.name   = "geomE0a";
3145     //   e0AssocA.entry  = "0:1:1:1:3:5";//"0:1:8";
3146     //   e0AssocA.brep  = "brepE0a";
3147     //   e0AssocA.start  = 0.10;
3148     //   e0AssocA.end    = 0.95;
3149     //
3150     //
3151     //
3152     //   e1AssocA.name   = "geomE1a";
3153     //   e1AssocA.entry  = "0:1:1:1:3:2";//"0:1:8";
3154     //   e1AssocA.brep  = "brepE1a";
3155     //   e1AssocA.start  = 0.12;
3156     //   e1AssocA.end    = 0.89;
3157     //   e1AssocB.name   = "geomE1b";
3158     //   e1AssocB.entry  = "0:1:1:1:3:3";//"0:1:9";
3159     //   e1AssocB.brep  = "brepE1b";
3160     //   e1AssocB.start  = 0.20;
3161     //   e1AssocB.end    = 0.80;
3162     //   e1AssocC.name   = "geomE1c";
3163     //   e1AssocC.entry  = "0:1:1:1:3:4";//"0:1:10";
3164     //   e1AssocC.brep  = "brepE1c";
3165     //   e1AssocC.start  = 0.16;
3166     //   e1AssocC.end    = 0.96;
3167     //
3168     //   q0AssocA.name   = "geomQuad";
3169     //   q0AssocA.entry  = "0:1:1:1:3";
3170     //   q0AssocA.brep   = "brepq0";
3171     //
3172     //   q0AssocB.name   = "geomQuad";
3173     //   q0AssocB.entry  = "0:1:1:1:4";
3174     //   q0AssocB.brep   = "brepq0";
3175     //
3176     //   getCurrentModel()->addAssociation( v0, v0Assoc );
3177     //   getCurrentModel()->addAssociation( v1, v1Assoc );
3178     //   getCurrentModel()->addAssociation( v2, v2Assoc );
3179     //   getCurrentModel()->addAssociation( v3, v3Assoc );
3180     //
3181     //
3182     //   getCurrentModel()->addAssociation( e0, e0AssocA );
3183     //
3184     //   getCurrentModel()->addAssociation( e1, e1AssocA );
3185     //   getCurrentModel()->addAssociation( e1, e1AssocB );
3186     //   getCurrentModel()->addAssociation( e1, e1AssocC );
3187     //
3188     //   getCurrentModel()->addAssociation( q0, q0AssocA );
3189     //   getCurrentModel()->addAssociation( q0, q0AssocB );
3190
3191
3192
3193
3194
3195     //   v0Assoc_test = getCurrentModel()->getAssociations( v0 )[0];
3196     //   v1Assoc_test = getCurrentModel()->getAssociations( v1 )[0];
3197     //   v2Assoc_test = getCurrentModel()->getAssociations( v2 )[0];
3198     //   v3Assoc_test = getCurrentModel()->getAssociations( v3 )[0];
3199     //   ASSERT( v0Assoc.name == v0Assoc_test.name );
3200     //   ASSERT( v1Assoc.name == v1Assoc_test.name );
3201     //   ASSERT( v2Assoc.name == v2Assoc_test.name );
3202     //   ASSERT( v3Assoc.name == v3Assoc_test.name );
3203     //   ASSERT( v0Assoc.entry == v0Assoc_test.entry );
3204     //   ASSERT( v1Assoc.entry == v1Assoc_test.entry );
3205     //   ASSERT( v2Assoc.entry == v2Assoc_test.entry );
3206     //   ASSERT( v3Assoc.entry == v3Assoc_test.entry );
3207     //
3208     //
3209     //   e1Assocs_test = getCurrentModel()->getAssociations( e1 );
3210     //   ASSERT( e1Assocs_test[0].name == e1AssocA.name );
3211     //   ASSERT( e1Assocs_test[1].name == e1AssocB.name );
3212     //   ASSERT( e1Assocs_test[2].name == e1AssocC.name );
3213     //   ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
3214     //   ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
3215     //   ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
3216     //   ASSERT( e1Assocs_test[0].start == e1AssocA.start );
3217     //   ASSERT( e1Assocs_test[1].start == e1AssocB.start );
3218     //   ASSERT( e1Assocs_test[2].start == e1AssocC.start );
3219     //   ASSERT( e1Assocs_test[0].end == e1AssocA.end );
3220     //   ASSERT( e1Assocs_test[1].end == e1AssocB.end );
3221     //   ASSERT( e1Assocs_test[2].end == e1AssocC.end );
3222     //
3223     //   q0Assoc_test = getCurrentModel()->getAssociations( q0 )[0];
3224     //   ASSERT( q0Assoc_test.name  == q0Assoc.name );
3225     //   ASSERT( q0Assoc_test.entry == q0Assoc.entry );
3226
3227
3228     DEBTRACE("HEXABLOCKGUI::test_association fin");
3229 }