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