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