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