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