Salome HOME
4032e1b6d86cb24b11ea11765e4771629ac85a38
[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
54
55
56 #include <SOCC_ViewModel.h>
57 #include <SOCC_ViewWindow.h>
58 #include <OCCViewer_ViewWindow.h>
59
60
61
62 // SALOME KERNEL includes
63 #include <SALOMEDS_Study.hxx>
64 #include <SALOMEDSClient_StudyBuilder.hxx>
65 #include <SALOMEDSClient_SComponent.hxx>
66 #include <SALOMEDSClient_ClientFactory.hxx>
67 #include <SALOMEDSClient_IParameters.hxx>
68
69
70
71 #include <SalomeApp_DataObject.h>
72 #include <SalomeApp_Study.h>
73 #include <SalomeApp_Module.h>
74 #include <SalomeApp_Application.h>
75 #include <SalomeApp_DataModel.h>
76
77
78 #include <SALOME_ListIO.hxx>
79 #include <SALOME_ListIteratorOfListIO.hxx>
80
81
82 #include <SALOME_LifeCycleCORBA.hxx>
83
84 #include <LightApp_VTKSelector.h>
85
86 #include <OCCViewer_ViewManager.h>
87
88
89 #include <QtxPopupMgr.h>
90
91
92 #include "Resource.hxx"
93 // #include "QtGuiContext.hxx"
94
95 #include "HEXABLOCKGUI.hxx"
96 #include "HEXABLOCKGUI_Export.hxx"
97 #include "HEXABLOCKGUI_Trace.hxx"
98 #include "HEXABLOCKGUI_Resource.hxx"
99 // #include "HEXABLOCKGUI_DataModel.hxx"
100 #include "HEXABLOCKGUI_DocumentGraphicView.hxx"
101 #include "HEXABLOCKGUI_DocumentModel.hxx"
102 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
103 #include "HEXABLOCKGUI_DocumentDelegate.hxx"
104 #include "HEXABLOCKGUI_DocumentPanel.hxx"
105
106 #include <HEXABLOCK_version.h>
107
108 #include "MyBasicGUI_PointDlg.hxx"
109
110 // #include CORBA_CLIENT_HEADER(HEXABLOCKPlugin_Algorithm)
111
112 #include "HEXABLOCK.hxx"
113 #include "HexDocument_impl.hxx"
114
115
116 #define DW_MINIMUM_WIDTH       50
117 #define DWINPUT_MINIMUM_HEIGHT 50
118 #define DWINPUT_MINIMUM_WIDTH 255
119
120 using namespace std;
121 using namespace HEXABLOCK::GUI;
122
123 int  HEXABLOCKGUI::_oldStudyId = -1;
124
125 HEXABLOCK_ORB::HEXABLOCK_Gen_var HEXABLOCKGUI::_hexaEngine  = HEXABLOCK_ORB::HEXABLOCK_Gen::_nil();
126 // SMESH::SMESH_Gen_var             HEXABLOCKGUI::_smeshEngine = SMESH::SMESH_Gen::_nil();
127 GEOM::GEOM_Gen_var               HEXABLOCKGUI::_geomEngine  = GEOM::GEOM_Gen::_nil();
128
129 // std::map<HEXABLOCK::GUI::DocumentModel*,  SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
130 // std::map<const QAbstractItemModel*,  SVTK_ViewWindow*> HEXABLOCKGUI::svtkViews;
131 // std::map<const QAbstractItemModel*,  SUIT_ViewWindow*> HEXABLOCKGUI::salomeViews;
132 // HEXABLOCK::GUI::DocumentModel       *HEXABLOCKGUI::_currentModel = NULL;
133
134 SVTK_ViewWindow*      HEXABLOCKGUI::currentVtkView = NULL;
135 OCCViewer_ViewWindow* HEXABLOCKGUI::currentOccView = NULL;
136 bool HEXABLOCKGUI::assocInProgress = false;
137
138 HEXABLOCKGUI::HEXABLOCKGUI() :
139   SalomeApp_Module( "HEXABLOCK" ), // default name
140   LightApp_Module( "HEXABLOCK" ),
141   _menuId(190),
142   _dwPattern(0),
143   _dwAssociation(0),
144   _dwGroups(0),
145   _dwMesh(0),
146   _dwObjectBrowser(0),
147   _dwInputPanel(0),
148   _currentModel(0),
149   _patternDataModel(0),
150   _patternBuilderModel(0),
151   _patternDataTreeView(0),
152   _patternBuilderTreeView(0),
153   _associationTreeView(0),
154   _groupsTreeView(0),
155   _meshTreeView(0),
156   _currentGraphicView(0),
157   _treeViewDelegate(0),
158   _patternDataSelectionModel(0),
159   _patternBuilderSelectionModel(0),
160   _meshSelectionModel(0),
161   _groupsSelectionModel(0),
162 //   _documentCnt(0),
163   _isSaved( false ),
164   moduleActivatedOnce(false),
165   vtkViewManager(0),//,
166   occViewManager(0),
167 //   _selectFromTree( false )
168   _vertexDiag(0),
169   _edgeDiag(0),
170   _quadDiag(0),
171   _hexaDiag(0),
172   _vectorDiag(0),
173   _cylinderDiag(0),
174   _pipeDiag(0),
175   _makeGridDiag(0),
176   _makeCylinderDiag(0),
177   _makePipeDiag(0),
178   _makeCylindersDiag(0),
179   _makePipesDiag(0),
180   _removeHexaDiag(0),
181   _prismQuadDiag(0),
182   _joinQuadDiag(0),
183   _mergeDiag(0),
184   _disconnectDiag(0),
185   _cutEdgeDiag(0),
186   _makeTransformationDiag(0),
187   _makeSymmetryDiag(0),
188   _performTransformationDiag(0),
189   _performSymmetryDiag(0),
190   _vertexAssocDiag(0),
191   _edgeAssocDiag(0),
192   _quadAssocDiag(0),
193   _groupDiag(0),
194   _lawDiag(0),
195   _propagationDiag(0),
196   _computeMeshDiag(0),
197   _replaceHexaDiag(0),
198   _quadRevolutionDiag(0),
199   _makeHemiSphereDiag(0),
200   currentDialog(NULL)
201 {
202   DEBTRACE("HEXABLOCKGUI::HEXABLOCKGUI");
203 //   _studyContextMap.clear();
204 }
205
206 HEXABLOCKGUI::~HEXABLOCKGUI()
207 {
208 //   if ( getApp() )
209 //     disconnect( getApp(), SIGNAL(studyClosed()), _genericGui, SLOT  (onCleanOnExit()));
210 }
211
212
213 SalomeApp_Study* HEXABLOCKGUI::activeStudy()
214 {
215   SUIT_Application* app = SUIT_Session::session()->activeApplication();
216   if( app )
217     return dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
218   else
219     return NULL;
220 }
221
222
223 // Gets an reference to the module's engine
224 HEXABLOCK_ORB::HEXABLOCK_Gen_ptr HEXABLOCKGUI::InitHEXABLOCKGen( SalomeApp_Application* app )
225 {
226   Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( "FactoryServer", "HEXABLOCK" );
227   HEXABLOCK_ORB::HEXABLOCK_Gen_ptr clr = HEXABLOCK_ORB::HEXABLOCK_Gen::_narrow(comp);
228   ASSERT(!CORBA::is_nil(clr));
229   return clr;
230 }
231
232 // // Gets an reference to SMESH's engine CS_TO_DELETE
233 // SMESH::SMESH_Gen_ptr HEXABLOCKGUI::InitSMESHGen( SalomeApp_Application* app,
234 //                                                  const std::string& container )
235 // {
236 //   Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "SMESH" );
237 //   SMESH::SMESH_Gen_ptr          clr = SMESH::SMESH_Gen::_narrow(comp);
238 //   ASSERT(!CORBA::is_nil(clr));
239 //   return clr;
240 // }
241 //
242 // // Gets an reference to GEOM's engine CS_TO_DELETE
243 GEOM::GEOM_Gen_ptr HEXABLOCKGUI::InitGEOMGen( SalomeApp_Application* app,
244                                               const std::string& container )
245 {
246   Engines::EngineComponent_var comp = app->lcc()->FindOrLoad_Component( container.c_str(), "GEOM" );
247   MESSAGE("INITINITINITINIT comp : " << comp);
248   GEOM::GEOM_Gen_ptr            clr = GEOM::GEOM_Gen::_narrow(comp);
249   MESSAGE("INITINITINITINIT clr 1: " << clr);
250   ASSERT(!CORBA::is_nil(clr));
251   return clr;
252 }
253
254
255 void HEXABLOCKGUI::initialize( CAM_Application* app )
256 {
257   DEBTRACE("HEXABLOCKGUI::initialize");
258   SalomeApp_Module::initialize( app );
259
260   _hexaEngine = InitHEXABLOCKGen( dynamic_cast<SalomeApp_Application*>( app ) );
261   _geomEngine = InitGEOMGen( dynamic_cast<SalomeApp_Application*>( app ) );
262   MESSAGE("INITINITINITINIT clr 2: " << _geomEngine);
263
264   QWidget* aParent = application()->desktop();
265   DEBTRACE(app << "  " << application() << " " << application()->desktop() << " " << aParent);
266
267   SUIT_ResourceMgr* aResourceMgr = app->resourceMgr();
268   setResource(aResourceMgr);
269
270 //   if ( app && app->desktop() ){
271 //       connect( app->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
272 //                this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
273 //       connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
274 //                this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
275 // //       connect( getApp(),   SIGNAL(studyClosed()), _genericGui,SLOT  (onCleanOnExit()));
276 //   }
277
278 // // TEST
279 //   QGraphicsScene* scene = new QGraphicsScene;
280 //   scene->addText("Hello, philou!");
281 //   QGraphicsView* view = new QGraphicsView(scene);
282 //   view->show();
283 //   app->desktop()->setCentralWidget(view);
284 // // TEST
285
286   createAndFillDockWidget();
287   createActions();
288   createMenus();
289   createTools();
290   studyActivated();
291   // add component to study
292   if (createSComponent()) updateObjBrowser();
293 }
294
295 void HEXABLOCKGUI::viewManagers( QStringList& list ) const
296 {
297   DEBTRACE("HEXABLOCKGUI::viewManagers");
298   MESSAGE("HEXABLOCKGUI::viewManagers");
299 //   foreach (const QString &str, list)
300 //     MESSAGE("HEXABLOCKGUI::viewManagers"<<str.toStdString() );
301 //   list.append( QxScene_Viewer::Type() );
302 //   list.append( OCCViewer_Viewer::Type() );
303 //   list.append( SVTK_Viewer::Type() );
304 }
305
306
307 bool HEXABLOCKGUI::activateModule( SUIT_Study* theStudy )
308 {
309   DEBTRACE("HEXABLOCKGUI::activateModule");
310   bool bOk = SalomeApp_Module::activateModule( theStudy );
311   if ( !bOk ) return false;
312
313 //   setMenuShown( true );
314 //   setToolShown( true );
315   if ( _currentModel == 0 )
316     initialMenus();
317   else
318     showAllMenus();
319
320 //   showDockWidgets(false);
321   showDockWidgets(true);
322   if (_dwInputPanel) _dwInputPanel->close();
323
324 //   // import Python module that manages HEXABLOCK plugins (need to be here because SalomePyQt API uses active module)
325 //   PyGILState_STATE gstate = PyGILState_Ensure();
326 //   PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
327 //   if(pluginsmanager==NULL)
328 //     PyErr_Print();
329 //   else
330 //     {
331 //       PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"hexablock","HEXABLOCK","Plugins");
332 //       if(result==NULL)
333 //         PyErr_Print();
334 //       Py_XDECREF(result);
335 //     }
336 //   PyGILState_Release(gstate);
337 //   // end of HEXABLOCK plugins loading
338
339     connect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
340               this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
341     connect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
342               this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
343 //       connect( getApp(),   SIGNAL(studyClosed()), _genericGui,SLOT  (onCleanOnExit()));
344
345
346 //  vtkViewManager = getApp()->getViewManager(SVTK_Viewer::Type(), true); //create the view manager if it doesn't exist
347   LightApp_SelectionMgr* sm = getApp()->selectionMgr();
348
349   SUIT_ViewManager* vm;
350   ViewManagerList OCCViewManagers, VTKViewManagers;
351
352   application()->viewManagers( OCCViewer_Viewer::Type(), OCCViewManagers );
353   QListIterator<SUIT_ViewManager*> itOCC( OCCViewManagers );
354   while ( itOCC.hasNext() && (vm = itOCC.next()) )
355     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
356
357   application()->viewManagers( SVTK_Viewer::Type(), VTKViewManagers );
358   QListIterator<SUIT_ViewManager*> itVTK( VTKViewManagers );
359   while ( itVTK.hasNext() && (vm = itVTK.next()) )
360     myVTKSelectors.append( new LightApp_VTKSelector( dynamic_cast<SVTK_Viewer*>( vm->getViewModel() ), sm ) );
361
362   //NPAL 19674
363   SALOME_ListIO selected;
364   sm->selectedObjects( selected );
365   sm->clearSelected();
366
367   // disable OCC selectors
368   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
369   QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
370   while ( itOCCSel.hasNext() )
371     if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() )
372       sr->setEnabled(true);
373
374   // disable VTK selectors
375   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
376   QListIterator<LightApp_VTKSelector*> itVTKSel( myVTKSelectors );
377   while ( itVTKSel.hasNext() )
378     if ( LightApp_VTKSelector* sr = itVTKSel.next() )
379       sr->setEnabled(true);
380
381   sm->setSelectedObjects( selected, true );   //NPAL 19674
382
383
384   _hexaEngine->SetCurrentStudy(SALOMEDS::Study::_nil());
385   if ( SalomeApp_Study* s = dynamic_cast<SalomeApp_Study*>( theStudy ))
386     if ( _PTR(Study) aStudy = s->studyDS()) {
387       //define _CAST(Class, shared_ptr_Obj) dynamic_cast<SALOMEDS_##Class*>(shared_ptr_Obj.get())
388       _hexaEngine->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
389       updateObjBrowser(); // objects can be removed
390     }
391
392   if (vtkViewManager==NULL || !vtkViewManager->getViewsCount()) newDocument();
393   if (_currentGraphicView != NULL)
394           _currentGraphicView->get_SUIT_ViewWindow()->setFocus();
395
396   return bOk;
397 }
398
399
400
401 bool HEXABLOCKGUI::deactivateModule( SUIT_Study* theStudy )
402 {
403   MESSAGE("HEXABLOCKGUI::deactivateModule");
404
405   setMenuShown( false );
406   setToolShown( false );
407   if (_dwInputPanel) _dwInputPanel->close();
408   showDockWidgets( false );
409 //   QtGuiContext *context = QtGuiContext::getQtCurrent();
410 //   _studyContextMap[theStudy->id()] = context;
411 //   DEBTRACE("_studyContextMap[theStudy] " << theStudy << " " << context);
412
413   disconnect( getApp()->desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ),
414             this, SLOT(onWindowActivated( SUIT_ViewWindow* )) );
415   disconnect( getApp()->objectBrowser()->treeView(),SIGNAL( clicked(const QModelIndex&) ),
416             this, SLOT( onObjectBrowserClick(const QModelIndex&) ) );
417 //       connect( getApp(),   SIGNAL(studyClosed()), _genericGui,SLOT  (onCleanOnExit()));
418
419
420   if ( HEXABLOCKGUI::currentVtkView ){
421     HEXABLOCKGUI::currentVtkView->SetSelectionMode( ActorSelection ); //default selectionMode in VTKView
422   }
423
424   if (HEXABLOCKGUI::currentOccView != NULL)
425   {
426           getApp()->selectionMgr()->clearSelected();
427           //defaut selectionMode in OccView
428           if (currentDialog != NULL)
429           {
430                   currentDialog->globalSelection();
431                   currentDialog->localSelection(GEOM::GEOM_Object::_nil(), TopAbs_SHAPE);
432           }
433   }
434
435
436 //   if ( _patternDataSelectionModel ){
437 //     delete _patternDataSelectionModel;
438 //     _patternDataSelectionModel = NULL;
439 //   }
440 //   if ( _patternBuilderSelectionModel ){
441 //     delete _patternBuilderSelectionModel;
442 //     _patternBuilderSelectionModel = NULL;
443 //   }
444
445   qDeleteAll(myOCCSelectors);
446   myOCCSelectors.clear();
447   getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
448
449   qDeleteAll(myVTKSelectors);
450   myVTKSelectors.clear();
451   getApp()->selectionMgr()->setEnabled( false, SVTK_Viewer::Type() );
452
453   return SalomeApp_Module::deactivateModule( theStudy );
454 }
455
456
457 bool HEXABLOCKGUI::renameAllowed( const QString& entry) const
458 {
459 //   MESSAGE("HEXABLOCKGUI::renameAllowed");
460   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
461   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
462   SalomeApp_DataObject* obj = appStudy ? dynamic_cast<SalomeApp_DataObject*>(appStudy->findObjectByEntry(entry)) : 0;
463
464   bool res = app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference();
465   return (app && appStudy && obj && !appStudy->isComponent(entry) && !obj->isReference());
466 }
467
468
469 bool HEXABLOCKGUI::renameObject( const QString& entry, const QString& name)
470 {
471   MESSAGE("HEXABLOCKGUI::renameObject");
472 //   bool appRes = SalomeApp_Module::renameObject(entry,name);
473 //   MESSAGE("appRes"<<appRes);
474 //   if( !appRes )
475 //     return false;
476   bool result = false;
477
478   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication());
479   SalomeApp_Study* appStudy = app ? dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) : 0;
480
481   if(!appStudy)
482     return result;
483
484   _PTR(Study) aStudy = appStudy->studyDS();
485
486   if(!aStudy)
487     return result;
488
489   _PTR(SObject) obj ( aStudy->FindObjectID(qPrintable(entry)) );
490   _PTR(GenericAttribute) anAttr;
491   if ( obj ){
492     if ( obj->FindAttribute(anAttr, "AttributeName") ){
493       _PTR(AttributeName) aName (anAttr);
494 //       GEOM::GEOM_Object_var anObj = GEOM::GEOM_Object::_narrow(GeometryGUI::ClientSObjectToObject(obj));
495 //
496 //       HEXABLOCK_Gen_i::Document_var aDoc = HEXABLOCK_Gen_i::Document::_narrow( theIOR );
497 //       if (!CORBA::is_nil(aDoc)) {
498         aName->SetValue( name.toLatin1().data() ); // rename the SObject
499 //         aDoc->setName( name.toLatin1().data() );  // Rename the corresponding GEOM_Object
500         _currentModel->setName( name/*.toLatin1().data()*/ );
501 //      _currentGraphicView->setWindowTitle( _currentModel->getName() );
502         result = true;
503     }
504   }
505   return result;
506 }
507
508 // --- Default windows
509 void HEXABLOCKGUI::windows( QMap<int, int>& theMap ) const
510 {
511   DEBTRACE("HEXABLOCKGUI::windows");
512   theMap.clear();
513   theMap.insert( SalomeApp_Application::WT_ObjectBrowser, Qt::LeftDockWidgetArea );
514   theMap.insert( SalomeApp_Application::WT_PyConsole,     Qt::BottomDockWidgetArea );
515 }
516
517 // LightApp_Displayer* HEXABLOCKGUI::displayer()
518 // {
519 //   DEBTRACE("HEXABLOCKGUI::displayer");
520 //   return _currentGraphicView;
521 // }
522
523
524 // QString  HEXABLOCKGUI::engineIOR() const
525 // {
526 //   DEBTRACE("HEXABLOCKGUI::engineIOR");
527 // //   return getApp()->defaultEngineIOR();
528 // }
529
530
531 QString  HEXABLOCKGUI::engineIOR() const
532 {
533   DEBTRACE("HEXABLOCKGUI::engineIOR");
534   CORBA::ORB_var anORB = getApp()->orb();
535   CORBA::String_var anIOR = anORB->object_to_string(_hexaEngine);
536   return QString( anIOR.in() );
537 }
538
539
540
541 void HEXABLOCKGUI::onObjectBrowserClick(const QModelIndex& index)
542 {
543   DEBTRACE("HEXABLOCKGUI::onObjectBrowserClick");
544   // we want to switch automatically to the right view windows
545   QWidget *viewWindow = NULL;
546
547   //first, find entry of item selected
548   QString itemEntry;
549   DataObjectList dol = getApp()->objectBrowser()->getSelected();
550   if (dol.isEmpty()) return;
551   SalomeApp_DataObject* item = dynamic_cast<SalomeApp_DataObject*>(dol[0]);
552   if (!item) return;
553   itemEntry = item->entry();
554
555 //   DEBTRACE("HEXABLOCKGUI::onClick index.data()  => "<<index.data().toString().toStdString());
556 //   DEBTRACE("HEXABLOCKGUI::onClick index.model() => "<<index.model());
557 //   DEBTRACE("HEXABLOCKGUI::onClick item->name(). => "<<item->name().toStdString());
558 //   DEBTRACE("HEXABLOCKGUI::onClick itemEntry =>"<<itemEntry.toStdString());
559
560   if ( !_salomeViewWindows.count( itemEntry ) ) return;
561   viewWindow = _salomeViewWindows[ itemEntry ];
562   if ( !viewWindow ) return;
563 //   _selectFromTree = true;
564   viewWindow->setFocus();
565   _currentGraphicView->update(); //CS_TEST
566 //   _selectFromTree = false;
567
568 //   if (getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0)
569 //     getApp()->activateModule("HEXABLOCK");
570 }
571
572
573
574
575
576 void HEXABLOCKGUI::onWindowActivated( SUIT_ViewWindow* svw)
577 {
578         DEBTRACE("HEXABLOCKGUI::onWindowActivated");
579         MESSAGE("HEXABLOCKGUI::onWindowActivated");
580         OCCViewer_ViewWindow* anOccVw = dynamic_cast<OCCViewer_ViewWindow*>(svw);
581
582         if ( anOccVw != NULL)
583         {
584                 currentOccView->installEventFilter(this);
585                 if (anOccVw != currentOccView)
586                         currentOccView = anOccVw;
587         }
588
589         // we want to switch automatically to the right model
590         // only VTK view
591         SVTK_ViewWindow* viewWindow = dynamic_cast<SVTK_ViewWindow*>(svw);
592         if (!viewWindow) return;
593
594         if (getApp()->activeModule() && getApp()->activeModule()->moduleName().compare("HEXABLOCK") != 0) //CS_TODO?
595                 getApp()->activateModule("HEXABLOCK");
596
597         if (viewWindow != currentVtkView)
598         {
599                 switchModel( viewWindow );
600                 currentVtkView = viewWindow;
601         }
602 }
603
604 void HEXABLOCKGUI::onWindowClosed( SUIT_ViewWindow* svw)
605 {
606   DEBTRACE("HEXABLOCKGUI::onWindowClosed");
607 }
608
609 void HEXABLOCKGUI::onViewManagerAdded( SUIT_ViewManager*  vm)
610 {
611   DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
612   if ( vm && vm->getType() == OCCViewer_Viewer::Type() )
613   {
614 //     qDebug( "connect" );
615 // //     connect( vm, SIGNAL( keyPress  ( SUIT_ViewWindow*, QKeyEvent* ) ),
616 // //              this, SLOT( OnKeyPress( SUIT_ViewWindow*, QKeyEvent* ) ) );
617 // //     connect( vm, SIGNAL( mousePress( SUIT_ViewWindow*, QMouseEvent* ) ),
618 // //              this, SLOT( OnMousePress( SUIT_ViewWindow*, QMouseEvent* ) ) );
619 //      connect( vm, SIGNAL( mouseMove ( SUIT_ViewWindow*, QMouseEvent* ) ),
620 //               this, SLOT( OnMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
621 //     LightApp_SelectionMgr* sm = getApp()->selectionMgr();
622 //     myOCCSelectors.append( new GEOMGUI_OCCSelector( ((OCCViewer_ViewManager*)vm)->getOCCViewer(), sm ) );
623 //
624 //     // disable OCC selectors
625 //     getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() );
626 //     QListIterator<GEOMGUI_OCCSelector*> itOCCSel( myOCCSelectors );
627 //     while ( itOCCSel.hasNext() )
628 //       if ( GEOMGUI_OCCSelector* sr = itOCCSel.next() ){
629 //         sr->setEnabled(true);
630 //         std::cout<<"HEXABLOCKGUI::onViewManagerAdded sr"<<sr;
631 //       }
632   }
633   DEBTRACE("HEXABLOCKGUI::onViewManagerAdded");
634 }
635
636 void HEXABLOCKGUI::onViewManagerRemoved( SUIT_ViewManager* vm)
637 {
638   DEBTRACE("HEXABLOCKGUI::::onViewManagerRemoved");
639 }
640
641 void HEXABLOCKGUI::onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected  )
642 {
643   QModelIndexList l = selected.indexes();
644   if ( l.count() == 0 ) return;
645   if ( !l[0].isValid() ) return;
646
647   QTreeView* theTree = NULL;
648   if ( sender() == _patternDataSelectionModel ){
649     theTree = _patternDataTreeView;
650   } else if ( sender() == _patternBuilderSelectionModel  ){
651     theTree = _patternBuilderTreeView;
652   } else if ( sender() == _groupsSelectionModel ){
653     theTree = _groupsTreeView;
654   } else if ( sender() == _meshSelectionModel ){
655     theTree = _meshTreeView;
656   }
657   if ( theTree ){
658     theTree->scrollTo ( l[0] );
659   }
660 }
661
662 // void HEXABLOCKGUI::onTryClose(bool &isClosed, QxScene_ViewWindow* window) //CS_TODO
663 // {
664 //   DEBTRACE("HEXABLOCKGUI::onTryClose");
665 //   isClosed = _genericGui->closeContext(window);
666 // }
667
668 // CAM_DataModel* HEXABLOCKGUI::createDataModel()
669 // {
670 //   DEBTRACE("HEXABLOCKGUI::createDataModel");
671 //   return new HEXABLOCKGUI_DataModel(this);
672 // //   return NULL;
673 // }
674
675 bool HEXABLOCKGUI::createSComponent() //addComponent
676 {
677   DEBTRACE("HEXABLOCKGUI::createSComponent");
678   // --- Find or create "HEXABLOCK" SComponent in the study
679
680   _PTR(Study)            aStudy = (( SalomeApp_Study* )(getApp()->activeStudy()))->studyDS();
681   _PTR(StudyBuilder)     aBuilder (aStudy->NewBuilder());
682   _PTR(GenericAttribute) anAttr;
683   _PTR(AttributeName)    aName;
684
685   _PTR(SComponent) aComponent = aStudy->FindComponent("HEXABLOCK");
686   if ( !aComponent ){
687     aComponent = aBuilder->NewComponent("HEXABLOCK");
688     anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
689     aName = _PTR(AttributeName) (anAttr);
690     aName->SetValue(getApp()->moduleTitle("HEXABLOCK").toStdString());
691
692     anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
693     _PTR(AttributePixMap) aPixmap(anAttr);
694     aPixmap->SetPixMap("share/salome/resources/hexablock/ModuleHexablock.png");
695
696     aBuilder->DefineComponentInstance(aComponent, engineIOR().toStdString());
697     DEBTRACE("HEXABLOCKGUI::createSComponent engineIOR=>"<<engineIOR().toStdString());
698 //      aBuilder->DefineComponentInstance(aComponent, getApp()->defaultEngineIOR().toStdString());
699 //      DEBTRACE("HEXABLOCKGUI::createSComponent defaultEngineIOR=>"<<getApp()->defaultEngineIOR().toStdString());
700
701 //     SalomeApp_DataModel::synchronize( aComponent, HEXABLOCKGUI::activeStudy() );
702     return true;
703   }
704   return false;
705 }
706
707
708
709 // bool HEXABLOCKGUI::isSelectionCompatible()
710 // {
711 //   DEBTRACE("HEXABLOCKGUI::isSelectionCompatible");
712 //
713 //   bool isCompatible = true;
714 //   SALOME_ListIO selected;
715 //   if ( LightApp_SelectionMgr *Sel = selectionMgr() )
716 //     Sel->selectedObjects( selected );
717 //
718 //   SALOME_ListIteratorOfListIO It( selected );
719 //   for ( ; isCompatible && It.More(); It.Next())
720 //     isCompatible =
721 //       ( strcmp("GEOM", It.Value()->getComponentDataType()) == 0 ) ||
722 //       ( strcmp("HEXABLOCK", It.Value()->getComponentDataType()) == 0 );
723 //
724 //   return isCompatible;
725 // }
726
727 void HEXABLOCKGUI::setResource(SUIT_ResourceMgr* r)
728 {
729   DEBTRACE("HEXABLOCKGUI::setResource");
730   _myresource = new HEXABLOCKGUI_Resource(r);
731   _myresource->preferencesChanged();
732 }
733
734 void HEXABLOCKGUI::createPreferences()
735 {
736   DEBTRACE("HEXABLOCKGUI::createPreferences");
737   _myresource->createPreferences(this);
738 }
739
740 void HEXABLOCKGUI::preferencesChanged( const QString& sect, const QString& name )
741 {
742   DEBTRACE("HEXABLOCKGUI::preferencesChanged");
743   _myresource->preferencesChanged(sect, name);
744   if(name=="userCatalog")
745     {
746 //       _genericGui->getCatalogWidget()->addCatalogFromFile(Resource::userCatalog.toStdString());
747     }
748 }
749
750 void HEXABLOCKGUI::studyActivated() //CS_TODO
751 {
752   int newStudyId = getApp()->activeStudy()->id();
753   DEBTRACE("HEXABLOCKGUI::studyActivated " << _oldStudyId << " " << newStudyId);
754
755   if (_oldStudyId != -1)
756   {
757 //       _studyContextMap[_oldStudyId] = QtGuiContext::getQtCurrent();
758 //       if (_studyContextMap.count(newStudyId))
759 //         {
760 //           DEBTRACE("switch to valid context " << QtGuiContext::getQtCurrent() << " " << _studyContextMap[newStudyId]);
761 //           QtGuiContext::setQtCurrent(_studyContextMap[newStudyId]);
762 //         }
763 //       else
764 //         {
765 //           DEBTRACE("no switch to null context");
766 //         }
767   }
768   _oldStudyId = newStudyId;
769 }
770
771
772
773 void HEXABLOCKGUI::treeContextMenu(const QPoint& aPosition)
774 {
775   QModelIndex currentIndex = _patternDataTreeView->currentIndex();
776   QVariant currentAssocVariant;
777   QString currentAssocEntry;
778
779   currentAssocVariant = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE );
780   currentAssocEntry    = currentIndex.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
781   if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() ){
782           //   _currentModel->allowEdition();
783             QMenu menu( _patternDataTreeView );
784             //Remove association
785             QAction *clearAct = menu.addAction( "Remove association(s)" );
786             connect( clearAct, SIGNAL(triggered()), this, SLOT(clearAssociations()) );
787             menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
788   }
789   else {
790
791           QStandardItem *item = _patternDataModel->itemFromIndex ( currentIndex );
792
793           //We don't do anything for single items
794           if ( item->type() == VERTEXITEM || item->type() == EDGEITEM ||
795                           item->type() == QUADITEM || item->type() == HEXAITEM)
796                   return;
797
798           //No associations for HEXA
799           QVariant treeVariant = currentIndex.data( HEXA_TREE_ROLE );
800           if ( !treeVariant.isValid() ) return;
801           int eltType = treeVariant.toInt();
802           if (eltType == HEXA_DIR_TREE) return;
803           QMenu menu( _patternDataTreeView );
804
805           //Show association(s)
806           QAction *showAssocAct = menu.addAction( "Show associations" );
807           connect( showAssocAct, SIGNAL(triggered()), this, SLOT(showAssociations()) );
808
809           //Clear all associations
810           QAction *clearAllAssocAct = menu.addAction( "Remove all associations" );
811           connect( clearAllAssocAct, SIGNAL(triggered()), this, SLOT(clearAllAssociations()) );
812
813           menu.exec( _patternDataTreeView->mapToGlobal( aPosition) );
814   }
815 }
816
817
818 void HEXABLOCKGUI::createAndFillDockWidget()
819 {
820   QMainWindow *aParent = application()->desktop();
821
822   // Create dock widget (3 dock)
823
824   //1) *********** user input panel ( contain user's edit dialog box )
825   _dwInputPanel = new QDockWidget(aParent);
826 //  QLayout* inputLayout = new QVBoxLayout(aParent);
827 //  _dwInputPanel->setLayout(inputLayout);
828 //   _dwInputPanel->setWindowFlags(Qt::FramelessWindowHint);
829 //   _dwInputPanel->setWindowFlags(Qt::WindowTitleHint);
830   _dwInputPanel->setVisible(false);
831   _dwInputPanel->setWindowTitle("Input Panel");
832 //   _dwInputPanel->setMinimumHeight(DWINPUT_MINIMUM_HEIGHT);
833   _dwInputPanel->setMinimumWidth(DWINPUT_MINIMUM_WIDTH); // --- force a minimum until display
834   _dwInputPanel->raise();
835
836 //   _stacked = new QStackedWidget(_dwInputPanel);
837 //   _dwInputPanel->setWidget(_stacked);
838
839   _treeViewDelegate = new DocumentDelegate(_dwInputPanel);
840
841   //2) ************* document data ( Pattern, Association, Mesh ) in treeview representation
842   //      Pattern
843   _dwPattern = new QDockWidget(aParent);
844   //   _dwPattern->installEventFilter(this);
845   _dwPattern->setVisible(false);
846   _dwPattern->setWindowTitle("Model");
847   _dwPattern->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
848
849   QFrame*      patternFrame  = new QFrame(_dwPattern);
850   patternFrame->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
851   QVBoxLayout* patternLayout = new QVBoxLayout(patternFrame);
852   patternLayout->setSizeConstraint(QLayout::SetMaximumSize);
853   QSplitter *splitter = new QSplitter(Qt::Vertical,patternFrame);
854   _patternDataTreeView    = new QTreeView(patternFrame);//_dwPattern);
855   _patternBuilderTreeView = new QTreeView(patternFrame);
856   splitter->addWidget(_patternDataTreeView);
857   splitter->addWidget(_patternBuilderTreeView);
858   patternLayout->addWidget(splitter);
859 //   _patternDataTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
860
861   _patternDataTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers/*QAbstractItemView::DoubleClicked*/);
862   _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection/*QAbstractItemView::MultiSelection*/);//);//QAbstractItemView::DoubleClicked, QAbstractItemView::SelectedClicked)
863   _patternDataTreeView->setItemDelegate(_treeViewDelegate);
864
865
866   _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
867   _patternBuilderTreeView->setItemDelegate(_treeViewDelegate);
868   _dwPattern->setWidget(patternFrame);
869   patternFrame->show();
870   //_dwPattern->raise();
871
872   //      Groups
873   _dwGroups = new QDockWidget(aParent);
874 //   _dwGroups->installEventFilter(this);
875
876   _dwGroups->setVisible(false);
877   _dwGroups->setWindowTitle("Groups");
878   _dwGroups->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
879   _groupsTreeView = new QTreeView(_dwGroups);
880 //   _associationTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
881   _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
882   _groupsTreeView->setItemDelegate(_treeViewDelegate);
883   _dwGroups->setWidget(_groupsTreeView);
884   _groupsTreeView->show();
885
886   //      Mesh
887   _dwMesh = new QDockWidget(aParent);
888 //   _dwMesh->installEventFilter(this);
889   _dwMesh->setVisible(false);
890   _dwMesh->setWindowTitle("Mesh");
891   _dwMesh->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
892   _meshTreeView = new QTreeView(_dwMesh);
893   //   _meshTreeView->setMinimumHeight(DW_MINIMUM_WIDTH);
894   _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
895   _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
896   _meshTreeView->setItemDelegate(_treeViewDelegate);
897   _dwMesh->setWidget(_meshTreeView);
898   _meshTreeView->show();
899   //   _dwMesh->raise();
900
901
902
903   //3) ************* documents ( salome objectbrowser )
904   QDockWidget *_dwObjectBrowser = 0;
905   QWidget* wid = getApp()->objectBrowser()->treeView();
906   //   QWidget *wid = application()->objectBrowser()->treeView();
907   QWidget *w   = wid->parentWidget();
908   while ( w && !_dwObjectBrowser ) {
909     _dwObjectBrowser = ::qobject_cast<QDockWidget*>( w );
910     w = w->parentWidget();
911   }
912 //   _dwObjectBrowser->installEventFilter(this);
913 //   _dwObjectBrowser->setVisible(false);
914   _dwObjectBrowser->setMinimumWidth(DW_MINIMUM_WIDTH); // --- force a minimum until display
915   _dwObjectBrowser->setWindowTitle("Study");
916
917
918   // dock widget position
919   //   aParent->addDockWidget(Qt::LeftDockWidgetArea,  _dwPattern);
920   //   aParent->addDockWidget(Qt::RightDockWidgetArea, _dwInputPanel);
921   //   aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwPattern );
922   aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwObjectBrowser );
923   aParent->addDockWidget( Qt::LeftDockWidgetArea, _dwInputPanel );
924
925   aParent->tabifyDockWidget( _dwObjectBrowser, _dwPattern );
926 //  aParent->tabifyDockWidget( _dwPattern, /*_dwAssociation );
927 //  aParent->tabifyDockWidget( _dwAssociation, */_dwGroups );
928   aParent->tabifyDockWidget( _dwPattern, _dwGroups );
929   aParent->tabifyDockWidget( _dwGroups, _dwMesh );
930
931
932 #if QT_VERSION >= 0x040500
933   aParent->setTabPosition(Qt::AllDockWidgetAreas, Resource::tabPanelsUp? QTabWidget::North: QTabWidget::South);
934 #endif
935
936
937 //   connect( _dwPattern, SIGNAL( visibilityChanged(bool) ),     this, SLOT( showPatternMenus(bool) ) );
938 // //   connect( _dwAssociation, SIGNAL( visibilityChanged(bool) ), this, SLOT( showAssociationMenus(bool) ) );
939 //   connect( _dwGroups, SIGNAL( visibilityChanged(bool) ),      this, SLOT( showGroupsMenus(bool) ) );
940 //   connect( _dwMesh, SIGNAL( visibilityChanged(bool) ),        this, SLOT( showMeshMenus(bool) ) );
941
942   // popup menu on data tree view
943  _patternDataTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
944   connect(_patternDataTreeView,
945           SIGNAL(customContextMenuRequested(const QPoint &)),
946           this,
947           SLOT(treeContextMenu(const QPoint &)));
948 }
949
950 void HEXABLOCKGUI::createActions()
951 {
952   QMainWindow *aParent = application()->desktop();
953   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
954
955   // Document
956   _newAct = createAction(_menuId++,
957                          tr("Create a new document"),
958                          resMgr->loadPixmap("HEXABLOCK", tr("ICON_NEW_DOCUMENT")),
959                          tr("New Document"),
960                          tr("Create a new document"),
961                          0, aParent, false, this, SLOT(newDocument()));
962   _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
963
964   _importAct = createAction(_menuId++,
965                             tr("Load a document"),
966                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_LOAD_DOCUMENT")),
967                             tr("Load Document"),
968                             tr("Load a document"),
969                             0, aParent, false, this, SLOT(loadDocument()));
970   _importAct->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_O); // --- QKeySequence::Open ambiguous in SALOME
971
972   _saveAct = createAction(_menuId++,
973                           tr("Save the document"),
974                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_SAVE_DOCUMENT")),
975                           tr("Save Document"),
976                           tr("Save the document"),
977                           0, aParent, false, this, SLOT(saveDocument()));
978
979 //  _testAct = createAction(_menuId++, tr("Test"), resMgr->loadPixmap("HEXABLOCK", tr("ICON_TEST")),
980 //                          tr("Test"),  tr("New test"),
981 //                          0, aParent, false, this, SLOT(test_association()));
982
983   // Pattern Data creation
984   _addVertex = createAction(_menuId++,
985                             tr("Create a vertex"),
986                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_VERTEX")),
987                             tr("Add Vertex"),
988                             tr("Create a new vertex"),
989                             0, aParent, false, this, SLOT(addVertex()));
990
991   _addEdge = createAction(_menuId++,
992                           tr("Create an edge"),
993                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_EDGE")),
994                           tr("Add Edge"),
995                           tr("Create a new edge"),
996                           0, aParent, false, this, SLOT(addEdge()));
997
998   _addQuad = createAction(_menuId++,
999                           tr("Create a quadrangle"),
1000                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_QUAD")),
1001                           tr("Add Quadrangle"),
1002                           tr("Create a new quadrangle"),
1003                           0, aParent, false, this, SLOT(addQuad()));
1004
1005   _addHexa = createAction(_menuId++,
1006                           tr("Create an hexahedron"),
1007                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_HEXA")),
1008                           tr("Add Hexahedron"),
1009                           tr("Create a new hexahedron"),
1010                           0, aParent, false, this, SLOT(addHexa()));
1011
1012   // Builder Data creation
1013   _addVector = createAction(_menuId++,
1014                             tr("Create a vector"),
1015                             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_ADD_VECTOR")),
1016                             tr("Add Vector"),
1017                             tr("Create a new vector"),
1018                             0, aParent, false, this, SLOT(addVector()));
1019
1020   _addCylinder = createAction(_menuId++,
1021                               tr("Create a cylinder"),
1022                               resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_CYLINDER")),
1023                               tr("Add Cylinder"),
1024                               tr("Create a new cylinder"),
1025                               0, aParent, false, this,  SLOT(addCylinder()));
1026
1027   _addPipe = createAction(_menuId++,
1028                           tr("Create a pipe"),
1029                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_PIPE")),
1030                           tr("Add Pipe"),
1031                           tr("Create a new pipe"),
1032                           0, aParent, false, this, SLOT(addPipe()));
1033
1034   _makeGrid = createAction(_menuId++,
1035                            tr("Make a grid"),
1036                            resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_GRID")),
1037                            tr("Make Grid"),
1038                            tr("Make a grid"),
1039                            0, aParent, false, this,  SLOT(makeGrid()));
1040
1041   _makeCylinder = createAction(_menuId++,
1042                                tr("Make a cylinder"),
1043                                resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDER")),
1044                                tr("Make Cylinder"),
1045                                tr("Make a cylinder"),
1046                                0, aParent, false, this, SLOT(makeCylinder()));
1047
1048   _makePipe = createAction(_menuId++,
1049                            tr("Make a pipe"),
1050                            resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPE")),
1051                            tr("Make Pipe"),
1052                            tr("Make a pipe"),
1053                            0, aParent, false, this, SLOT(makePipe()));
1054
1055   _makeCylinders = createAction(_menuId++,
1056                                 tr("Make cylinders"),
1057                                 resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_CYLINDERS")),
1058                                 tr("Make Cylinders"),
1059                                 tr("Make cylinders"),
1060                                 0, aParent, false, this, SLOT(makeCylinders()));
1061
1062   _makePipes = createAction(_menuId++,
1063                             tr("Make pipes"),
1064                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_PIPES")),
1065                             tr("Make Pipes"),
1066                             tr("Make pipes"),
1067                             0, aParent, false, this, SLOT(makePipes()));
1068
1069 // //   _makeRind     = createAction( _menuId++, tr("Make rind"), resMgr->loadPixmap( "HEXABLOCK", tr("ICON_MAKE_RIND")),
1070 // //                                             tr("Make rind"),  tr("Make rind"),
1071 // //                                             0, aParent, false, this, SLOT(makeRind()));
1072
1073   _makeHemiSphere = createAction(_menuId++,
1074                                  tr("Make an hemisphere"),
1075                                  resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_HEMISPHERE")),
1076                                  tr("Make Hemisphere"),
1077                                  tr("Make an hemisphere"),
1078                                  0, aParent, false, this, SLOT(makeHemiSphere()));
1079
1080   // Pattern Data edition
1081   _removeHexa = createAction(_menuId++,
1082                              tr("Remove hexahedra"),
1083                              resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_HEXA")),
1084                              tr("Remove Hexahedra"),
1085                              tr("Remove hexahedra"),
1086                              0, aParent, false, this, SLOT(removeHexa()));
1087
1088   _prismQuad = createAction(_menuId++,
1089                             tr("Prism quadrangles"),
1090                             resMgr->loadPixmap( "HEXABLOCK", tr("ICON_PRISM_QUAD")),
1091                             tr("Prism Quadrangles"),
1092                             tr("Prism quadrangles"),
1093                             0, aParent, false, this, SLOT(prismQuad()));
1094
1095   _joinQuad = createAction(_menuId++,
1096                            tr("Join quadrangles"),
1097                            resMgr->loadPixmap("HEXABLOCK", tr("ICON_JOIN_QUAD")),
1098                            tr("Join Quadrangles"),
1099                            tr("Join quadrangles with hexahedra"),
1100                            0, aParent, false, this, SLOT(joinQuad()));
1101
1102   _merge = createAction(_menuId++,
1103                         tr("Merge"),
1104                         resMgr->loadPixmap("HEXABLOCK", tr("ICON_MERGE")),
1105                         tr("Merge"),
1106                         tr("Merge"),
1107                         0, aParent, false, this, SLOT(merge()));
1108
1109   _disconnect = createAction(_menuId++,
1110                              tr("Disconnect"),
1111                              resMgr->loadPixmap("HEXABLOCK", tr("ICON_DISCONNECT")),
1112                              tr("Disconnect"),
1113                              tr("Disconnect edges, vertexes or quadrangles"),
1114                              0, aParent, false, this, SLOT(disconnectElts()));
1115
1116   _cutEdge = createAction(_menuId++,
1117                           tr("Cut edge"),
1118                           resMgr->loadPixmap("HEXABLOCK", tr("ICON_CUT_EDGE")),
1119                           tr("Cut Edge"),
1120                           tr("Cut edge"),
1121                           0, aParent, false, this, SLOT(cutEdge()));
1122
1123   _makeTransformation = createAction(_menuId++,
1124                                      tr("Make transformation"),
1125                                      resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_TRANSFORMATION")),
1126                                      tr("Make Transformation"),
1127                                      tr("Make transformation"),
1128                                      0, aParent, false, this, SLOT(makeTransformation()));
1129
1130   _makeSymmetry = createAction(_menuId++,
1131                                tr("Make symmetry"),
1132                                resMgr->loadPixmap("HEXABLOCK", tr("ICON_MAKE_SYMMETRY")),
1133                                tr("Make Symmetry"),
1134                                tr("Make symmetry"),
1135                                0, aParent, false, this, SLOT(makeSymmetry()));
1136
1137   _performTransformation = createAction(_menuId++,
1138                                         tr("Perform transformation"),
1139                                         resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_TRANSFORMATION")),
1140                                         tr("Perform Transformation"),
1141                                         tr("Perform transformation"),
1142                                         0, aParent, false, this, SLOT(performTransformation()));
1143
1144   _performSymmetry = createAction(_menuId++,
1145                                   tr("Perform symmetry"),
1146                                   resMgr->loadPixmap("HEXABLOCK", tr("ICON_PERFORM_SYMMETRY")),
1147                                   tr("Perform Symmetry"),
1148                                   tr("Perform symmetry"),
1149                                   0, aParent, false, this, SLOT(performSymmetry()));
1150
1151   _replaceHexa = createAction(_menuId++,
1152                               tr("Replace hexahedron"),
1153                               resMgr->loadPixmap("HEXABLOCK", tr("ICON_REPLACE_HEXA")),
1154                               tr("Replace Hexahedron"),
1155                               tr("Replace hexahedron"),
1156                               0, aParent, false, this, SLOT(replaceHexa()));
1157
1158   _quadRevolution = createAction(_menuId++,
1159                                  tr("Quad revolution"),
1160                                  resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_REVOLUTION")),
1161                                  tr("Quad Revolution"),
1162                                  tr("Quad revolution"),
1163                                  0, aParent, false, this, SLOT(quadRevolution()));
1164
1165   // Association
1166   _assocVertex = createAction(_menuId++,
1167                               tr("Make vertex association"),
1168                               resMgr->loadPixmap("HEXABLOCK", tr("ICON_VERTEX_ASSOCIATION")),
1169                               tr("Make Vertex association"),
1170                               tr("Make vertex association"),
1171                               0, aParent, false, this, SLOT(assocVertex()));
1172
1173   _assocEdge = createAction(_menuId++,
1174                             tr("Make edge association"),
1175                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_EDGE_ASSOCIATION")),
1176                             tr("Make Edge Association"),
1177                             tr("Make edge association"),
1178                             0, aParent, false, this, SLOT(assocEdge()));
1179
1180   _assocQuad = createAction(_menuId++,
1181                             tr("Make quadrangle association"),
1182                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_QUAD_ASSOCIATION")),
1183                             tr("Make Quadrangle Association"),
1184                             tr("Make quadrangle association"),
1185                             0, aParent, false, this, SLOT(assocQuad()));
1186
1187   // Group
1188   _addGroup = createAction(_menuId++,
1189                            tr("Add a group"),
1190                            resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_GROUP")),
1191                            tr("Add Group"),
1192                            tr("Add a group"),
1193                            0, aParent, false, this, SLOT(addGroup()));
1194
1195   _removeGroup = createAction(_menuId++,
1196                               tr("Remove a group"),
1197                               resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_GROUP")),
1198                               tr("Remove Group"),
1199                               tr("Remove a group"),
1200                               0, aParent, false, this, SLOT(removeGroup()));
1201
1202   // Mesh
1203   _addLaw = createAction(_menuId++,
1204                          tr("Add a law"),
1205                          resMgr->loadPixmap("HEXABLOCK", tr("ICON_ADD_LAW")),
1206                          tr("Add Law"),
1207                          tr("Add a law"),
1208                          0, aParent, false, this, SLOT(addLaw()));
1209
1210   _removeLaw = createAction(_menuId++,
1211                             tr("Remove a law"),
1212                             resMgr->loadPixmap("HEXABLOCK", tr("ICON_REMOVE_LAW")),
1213                             tr("Remove Law"),
1214                             tr("Remove a law"),
1215                             0, aParent, false, this, SLOT(removeLaw()));
1216
1217   _setPropagation = createAction(_menuId++,
1218                                  tr("Set propagation"),
1219                                  resMgr->loadPixmap("HEXABLOCK", tr("ICON_SET_PROPAGATION")),
1220                                  tr("Set Propagation"),
1221                                  tr("Set propagation"),
1222                                  0, aParent, false, this, SLOT(setPropagation()));
1223
1224   _computeMesh = createAction(_menuId++,
1225                               tr("Compute mesh"),
1226                               resMgr->loadPixmap("HEXABLOCK", tr("ICON_COMPUTE_MESH")),
1227                               tr("Compute Mesh"),
1228                               tr("Compute mesh"),
1229                               0, aParent, false, this, SLOT(computeMesh()));
1230
1231
1232   //   _newAct->setShortcut( Qt::CTRL + Qt::SHIFT + Qt::Key_N ); // --- QKeySequence::New ambiguous in SALOME
1233   //       QAction* createAction(const int id,
1234   //                             const QString& toolTip,
1235   //                             const QIcon& icon,
1236   //                             const QString& menu,
1237   //                             const QString& status,
1238   //                             const int shortCut,
1239   //                             QObject* parent =0,
1240   //                             bool checkable = false,
1241   //                             QObject* receiver =0,
1242   //                             const char* member =0);
1243 }
1244
1245
1246 void HEXABLOCKGUI::createMenus()
1247 {
1248   int aMenuId, subMenuId;
1249   aMenuId = createMenu( tr("MEN_FILE"), -1, -1 );
1250   createMenu( separator(), aMenuId, -1, 10 );
1251   aMenuId = createMenu( tr("HEXABLOCK"), aMenuId, -1, 10 );
1252   createMenu( _newAct, aMenuId );
1253   createMenu( _importAct, aMenuId );
1254   createMenu( _saveAct, aMenuId );
1255 //   createMenu( _testAct, aMenuId );
1256
1257 //   aMenuId = createMenu( tr( "HEXABLOCK" ), -1, -1, 30 );
1258   aMenuId = createMenu( tr( "Document" ), -1, -1, 30 );
1259   createMenu( _newAct, aMenuId );//, 10
1260   createMenu( _importAct, aMenuId );
1261   createMenu( _saveAct, aMenuId );
1262 //   createMenu( _testAct, aMenuId );
1263
1264   aMenuId = createMenu( tr("Model"), -1, -1, 30 );
1265   subMenuId = createMenu( tr( "Construction" ), aMenuId, -1 );
1266   createMenu( _addVertex, subMenuId );
1267   createMenu( _addEdge,   subMenuId );
1268   createMenu( _addQuad,   subMenuId );
1269   createMenu( _addHexa,   subMenuId );
1270   //createMenu( separator(), aMenuId);
1271
1272   // Pattern Builder
1273   createMenu( _addVector, subMenuId );
1274   createMenu( _addCylinder, subMenuId );
1275   createMenu( _addPipe, subMenuId );
1276   //createMenu( separator(), aMenuId);
1277   createMenu( _makeGrid,  subMenuId ); //Cartesian, Cylindrical, Spherical
1278   createMenu( _makeCylinder, subMenuId );
1279   createMenu( _makePipe,     subMenuId );
1280   createMenu( _makeCylinders,subMenuId );
1281   createMenu( _makePipes,    subMenuId );
1282 //   createMenu( _makeRind,  aMenuId );
1283   createMenu( _makeHemiSphere,subMenuId );
1284   //createMenu( separator(), aMenuId);
1285
1286   // Pattern Data Edition
1287   subMenuId = createMenu( tr( "Operation" ), aMenuId, -1 );
1288   createMenu( _removeHexa, subMenuId );
1289   createMenu( _prismQuad,  subMenuId );
1290   createMenu( _joinQuad,   subMenuId );
1291   createMenu( _merge,      subMenuId );//   createMenu( _mergeVertices,   aMenuId ); //   createMenu( _mergeEdges,   aMenuId );
1292   createMenu( _disconnect, subMenuId );
1293   createMenu( _cutEdge,    subMenuId );
1294   createMenu( _makeTransformation, subMenuId ); //   createMenu( _makeTranslation,   aMenuId );
1295   createMenu( _makeSymmetry,       subMenuId );
1296   createMenu( _performTransformation,   subMenuId );
1297   createMenu( _performSymmetry,         subMenuId );
1298   createMenu( _replaceHexa,    subMenuId );
1299   createMenu( _quadRevolution, subMenuId );
1300
1301   // Association
1302   aMenuId = createMenu( tr("Association"), -1, -1, 30 );
1303   createMenu( _assocVertex, aMenuId );
1304   createMenu( _assocEdge,   aMenuId );
1305   createMenu( _assocQuad,   aMenuId );
1306
1307   // Group
1308   aMenuId = createMenu( tr("Groups"), -1, -1, 30 );
1309   createMenu( _addGroup,    aMenuId );
1310   createMenu( _removeGroup, aMenuId ); //CS_TODO
1311
1312   // Law
1313   aMenuId = createMenu( tr("Mesh "), -1, -1, 30 );
1314   createMenu( _addLaw,    aMenuId );
1315   createMenu( _removeLaw, aMenuId );
1316   createMenu( _setPropagation, aMenuId );
1317   createMenu( _computeMesh, aMenuId );
1318 }
1319
1320
1321 void HEXABLOCKGUI::createTools()
1322 {
1323   int aToolId;
1324
1325   aToolId = createTool ( tr( "HexaBlock Toolbar" ) );
1326   createTool( _newAct, aToolId );
1327   createTool( _importAct, aToolId );
1328   createTool( _saveAct, aToolId );
1329 //   createTool( _testAct, aToolId );
1330   //createTool( separator(), aToolId );
1331
1332   // Pattern Data
1333   aToolId = createTool ( tr( "Construction" ) );
1334   createTool( _addVertex, aToolId );
1335   createTool( _addEdge, aToolId );
1336   createTool( _addQuad, aToolId );
1337   createTool( _addHexa, aToolId );
1338   //createTool( separator(), aToolId );
1339
1340   // Pattern Builder
1341   createTool( _addVector, aToolId );
1342   createTool( _addCylinder, aToolId );
1343   createTool( _addPipe, aToolId );
1344   //createTool( separator(), aToolId );
1345
1346   createTool( _makeGrid,  aToolId );
1347   createTool( _makeCylinder, aToolId );
1348   createTool( _makePipe,     aToolId );
1349   createTool( _makeCylinders,aToolId );
1350   createTool( _makePipes,    aToolId );
1351 //   createTool( _makeRind,     aToolId);
1352   createTool( _makeHemiSphere,   aToolId );
1353   //createTool( separator(), aToolId );
1354
1355   // Pattern Data Edition
1356   aToolId = createTool ( tr( "Operation" ) );
1357   createTool( _removeHexa, aToolId );
1358   createTool( _prismQuad,  aToolId );
1359   createTool( _joinQuad,   aToolId );
1360   createTool( _merge,      aToolId );
1361   createTool( _disconnect, aToolId );
1362   createTool( _cutEdge,    aToolId );
1363   createTool( _makeTransformation, aToolId );
1364   createTool( _makeSymmetry,       aToolId );
1365   createTool( _performTransformation,   aToolId );
1366   createTool( _performSymmetry,         aToolId );
1367   createTool( _replaceHexa,    aToolId );
1368   createTool( _quadRevolution, aToolId );
1369   //createTool( separator(), aToolId );
1370
1371   // Association
1372   aToolId = createTool ( tr( "Association" ) );
1373   createTool( _assocVertex, aToolId );
1374   createTool( _assocEdge, aToolId );
1375   createTool( _assocQuad, aToolId );
1376   //createTool( separator(), aToolId );
1377
1378   // Group
1379   aToolId = createTool ( tr( "Group" ) );
1380   createTool( _addGroup,    aToolId );
1381   createTool( _removeGroup, aToolId ); //CS_TODO
1382   //createTool( separator(), aToolId );
1383
1384   // Law
1385   aToolId = createTool ( tr( "Mesh" ) );
1386   createTool( _addLaw,    aToolId );
1387   createTool( _removeLaw, aToolId );
1388   createTool( _setPropagation, aToolId );
1389   createTool( _computeMesh, aToolId );
1390
1391 }
1392
1393 void HEXABLOCKGUI::initialMenus()
1394 {
1395   showDocumentMenus( true );
1396   showPatternMenus( false );
1397   showAssociationMenus( false );
1398   showGroupsMenus( false );
1399   showMeshMenus( false );
1400 }
1401
1402 void HEXABLOCKGUI::showAllMenus()
1403 {
1404   showDocumentMenus( true );
1405   showPatternMenus( true );
1406   showAssociationMenus( true );
1407   showGroupsMenus( true );
1408   showMeshMenus( true );
1409 }
1410
1411
1412 void HEXABLOCKGUI::showDocumentMenus(bool show)
1413 {
1414   DEBTRACE("HEXABLOCKGUI::showDocumentMenus " << show);
1415   show = true; //
1416   setMenuShown(_newAct, show);
1417   setToolShown(_newAct, show);
1418   setMenuShown(_importAct, show);
1419   setToolShown(_importAct, show);
1420   setMenuShown(_saveAct, show);
1421   setToolShown(_saveAct, show);
1422 //   setMenuShown(_testAct, show);
1423 //   setToolShown(_testAct, show);
1424 }
1425
1426 void HEXABLOCKGUI::showPatternMenus(bool show)
1427 {
1428   DEBTRACE("HEXABLOCKGUI::showPatternMenus " << show);
1429   DEBTRACE("_currentModel  " << _currentModel  );
1430   if ( show && !_currentModel ) return;
1431
1432   setMenuShown(_addVertex, show );//true);
1433   setToolShown(_addVertex, show);
1434   setMenuShown(_addEdge,  show );//true);
1435   setToolShown(_addEdge, show);
1436   setMenuShown(_addQuad,  show );//true);
1437   setToolShown(_addQuad, show);
1438   setMenuShown(_addHexa,  show );//true);
1439   setToolShown(_addHexa, show);
1440
1441
1442   setMenuShown( _addVector,  show );//true);
1443   setToolShown( _addVector, show);
1444   setMenuShown( _addCylinder,  show );//true);
1445   setToolShown( _addCylinder, show);
1446   setMenuShown( _addPipe,  show );//true);
1447   setToolShown( _addPipe, show);
1448   setMenuShown( _makeGrid,  show );//true);
1449   setToolShown( _makeGrid, show);
1450   setMenuShown( _makeCylinder,  show );//true);
1451   setToolShown( _makeCylinder, show);
1452   setMenuShown( _makePipe,  show );//true);
1453   setToolShown( _makePipe, show);
1454   setMenuShown( _makeCylinders,  show );//true);
1455   setToolShown( _makeCylinders, show);
1456   setMenuShown( _makePipes,  show );//true);
1457   setToolShown( _makePipes, show);
1458 //   setMenuShown( _makeRind,  show );//true);
1459 //   setToolShown( _makeRind, show);
1460   setMenuShown( _makeHemiSphere,  show );//true);
1461   setToolShown( _makeHemiSphere, show);
1462
1463   // Pattern Data Edition
1464   setMenuShown( _removeHexa,  show );//true);
1465   setToolShown( _removeHexa, show);
1466   setMenuShown( _prismQuad,  show );//true);
1467   setToolShown( _prismQuad, show);
1468   setMenuShown( _joinQuad,  show );//true);
1469   setToolShown( _joinQuad, show);
1470   setMenuShown( _merge,  show );//true);
1471   setToolShown( _merge, show);
1472   setMenuShown( _disconnect,  show );//true);
1473   setToolShown( _disconnect, show);
1474   setMenuShown( _cutEdge,  show );//true);
1475   setToolShown( _cutEdge, show);
1476   setMenuShown( _makeTransformation,  show );//true);
1477   setToolShown( _makeTransformation, show);
1478   setMenuShown( _makeSymmetry,  show );//true);
1479   setToolShown( _makeSymmetry, show);
1480   setMenuShown( _performTransformation,  show );//true);
1481   setToolShown( _performTransformation, show);
1482   setMenuShown( _performSymmetry,  show );//true);
1483   setToolShown( _performSymmetry, show);
1484   setMenuShown( _replaceHexa,  show );//true);
1485   setToolShown( _replaceHexa, show);
1486   setMenuShown( _quadRevolution,  show );//true);
1487   setToolShown( _quadRevolution, show);
1488
1489 }
1490
1491
1492 void HEXABLOCKGUI::showAssociationMenus(bool show)
1493 {
1494   DEBTRACE("HEXABLOCKGUI::showAssociationMenus" << show);
1495   if ( show && !_currentModel ) return;
1496
1497   // Association Edition
1498   setMenuShown( _assocVertex,  show );
1499   setToolShown( _assocVertex, show);
1500   setMenuShown( _assocEdge,  show );
1501   setToolShown( _assocEdge, show);
1502   setMenuShown( _assocQuad,  show );
1503   setToolShown( _assocQuad, show);
1504
1505 }
1506
1507 void HEXABLOCKGUI::showGroupsMenus(bool show)
1508 {
1509   DEBTRACE("HEXABLOCKGUI::showGroupsMenus" << show);
1510   if ( show && !_currentModel ) return;
1511   setMenuShown( _addGroup,  show );//true);
1512   setToolShown( _addGroup, show);
1513   setMenuShown( _removeGroup ,  show );//true);
1514   setToolShown( _removeGroup , show);
1515 }
1516
1517 void HEXABLOCKGUI::showMeshMenus(bool show)
1518 {
1519   DEBTRACE("HEXABLOCKGUI::showMeshMenus" << show);
1520   if ( show && !_currentModel ) return;
1521   setMenuShown( _addLaw,  show );//true);
1522   setToolShown( _addLaw, show);
1523   setMenuShown( _removeLaw,  show );//true);
1524   setToolShown( _removeLaw, show);;
1525   setMenuShown( _setPropagation,  show );//true);
1526   setToolShown( _setPropagation, show);
1527   setMenuShown( _computeMesh, show); //true);
1528   setToolShown( _computeMesh, show);
1529 }
1530
1531
1532
1533 void HEXABLOCKGUI::switchModel(SUIT_ViewWindow *view)
1534 {
1535   DEBTRACE("HEXABLOCKGUI::switchModel " << view);
1536
1537   if ( _documentModels.count(view) == 0 ){
1538     DEBTRACE("HEXABLOCKGUI::switchModel : no model found, cannot switch");
1539     initialMenus();
1540     return;
1541   }
1542
1543   if ( _currentModel != _documentModels[view] ){ // need to switch
1544     if (_dwInputPanel){
1545       QWidget* w = _dwInputPanel->widget();
1546       if (w) w->close();
1547     }
1548
1549     // models
1550     _currentModel = _documentModels[view];
1551     _patternDataModel->setSourceModel(_currentModel);
1552     _patternBuilderModel->setSourceModel(_currentModel);
1553 //     _associationsModel->setSourceModel(_currentModel);
1554     _groupsModel->setSourceModel(_currentModel);
1555     _meshModel->setSourceModel(_currentModel);
1556
1557     // associate models and views
1558     _currentGraphicView = _documentView[view];
1559 //     _currentGraphicView->setModel(_patternDataModel);
1560 //     connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView,  SLOT ( onPatternDatachanged() ) );
1561     _currentGraphicView->setModel(_currentModel);
1562
1563     _patternDataTreeView->setModel(_patternDataModel); //_currentModel
1564     _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel
1565 //     _associationTreeView->setModel(_associationsModel);;
1566     _groupsTreeView->setModel(_groupsModel);
1567     _meshTreeView->setModel(_meshModel);
1568
1569     // set selections for each view
1570 //    if ( _patternDataSelectionModel )    delete _patternDataSelectionModel;
1571 //    if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
1572 //    if ( _groupsSelectionModel )         delete _groupsSelectionModel;
1573 //    if ( _meshSelectionModel )           delete _meshSelectionModel;
1574
1575     _patternDataSelectionModel    = new PatternDataSelectionModel( _patternDataModel );
1576     _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
1577     _groupsSelectionModel         = new GroupsSelectionModel( _groupsModel );
1578     _meshSelectionModel           = new MeshSelectionModel( _meshModel );
1579
1580     _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1581 //     _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
1582 //     _patternDataSelectionModel->setGeomEngine( _geomEngine );
1583
1584     _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
1585
1586     _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
1587     _patternDataTreeView->setEditTriggers(/*QAbstractItemView::EditKeyPressed*/QAbstractItemView::AllEditTriggers /*QAbstractItemView::NoEditTriggers*/);
1588
1589     _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
1590     _patternBuilderTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1591
1592     _groupsTreeView->setSelectionModel(_groupsSelectionModel);
1593     _groupsTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1594
1595     _meshTreeView->setSelectionModel( _meshSelectionModel );
1596     _meshTreeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
1597
1598
1599     // delegate for edition
1600     _treeViewDelegate->setDocumentModel( _currentModel );
1601     _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
1602     _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
1603     _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel /*_groupsTreeView->selectionModel()*/ );
1604     _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
1605
1606
1607     connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1608                                    this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1609     connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1610                                       this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1611     connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1612                               this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1613     connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
1614                             this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
1615
1616   }
1617
1618   showPatternMenus(true);
1619 }
1620
1621
1622
1623
1624 void HEXABLOCKGUI::showDockWidgets(bool isVisible)
1625 {
1626   DEBTRACE("HEXABLOCKGUI::showDockWidgets " << isVisible);
1627
1628   if (_dwObjectBrowser) _dwObjectBrowser->setVisible(isVisible);
1629   if (_dwObjectBrowser) _dwObjectBrowser->toggleViewAction()->setVisible(isVisible);
1630
1631   if (_dwPattern) _dwPattern->setVisible(isVisible);
1632   if (_dwPattern) _dwPattern->toggleViewAction()->setVisible(isVisible);
1633
1634 //   if (_dwAssociation) _dwAssociation->setVisible(isVisible);
1635 //   if (_dwAssociation) _dwAssociation->toggleViewAction()->setVisible(isVisible);
1636
1637   if (_dwMesh) _dwMesh->setVisible(isVisible);
1638   if (_dwMesh) _dwMesh->toggleViewAction()->setVisible(isVisible);
1639
1640   if (_dwGroups) _dwGroups->setVisible(isVisible);
1641   if (_dwGroups) _dwGroups->toggleViewAction()->setVisible(isVisible);
1642
1643   if (_dwInputPanel) _dwInputPanel->setVisible(isVisible);
1644   if (_dwInputPanel) _dwInputPanel->toggleViewAction()->setVisible(isVisible);
1645
1646   QWidget* w = _dwInputPanel->widget();
1647   if (w) w->show();
1648 //   if ( isVisible ) _dwObjectBrowser->raise();//_dwPattern->raise();
1649 }
1650
1651
1652 // void HEXABLOCKGUI::raiseStacked()
1653 // {
1654 // //   if (_dwStacked) _dwStacked->raise();
1655 // }
1656
1657
1658
1659
1660 DocumentGraphicView* HEXABLOCKGUI::newGraphicView()
1661 {
1662   MESSAGE("HEXABLOCKGUI::newGraphicView");
1663   DocumentGraphicView *newGView = NULL;
1664   SUIT_ViewWindow *suitVW = NULL;
1665
1666   //For the first time initialize occ view manager
1667   if (_documentView.size() == 0)
1668     {
1669           occViewManager = getApp()->getViewManager( OCCViewer_Viewer::Type(), true );
1670           occViewManager->getActiveView()->setClosable(false);
1671           currentOccView = dynamic_cast<OCCViewer_ViewWindow*>(occViewManager->getActiveView());
1672     }
1673
1674   vtkViewManager = getApp()->getViewManager( SVTK_Viewer::Type(), true );
1675   if (_documentView.size() == 0)
1676   {
1677           suitVW = vtkViewManager->getActiveView();
1678           suitVW->setClosable(false);
1679   }
1680   else
1681           suitVW = vtkViewManager->createViewWindow();
1682
1683   currentVtkView = dynamic_cast<SVTK_ViewWindow*>(suitVW);
1684   currentVtkView->installEventFilter(this);
1685   newGView = new DocumentGraphicView(getApp(), suitVW, application()->desktop());
1686   _documentView[suitVW] = newGView;
1687   return newGView;
1688 }
1689
1690 //DocumentGraphicView* HEXABLOCKGUI::newGraphicView()
1691 //{
1692 //  MESSAGE("HEXABLOCKGUI::newGraphicView");
1693 //  DocumentGraphicView *newGView = 0;
1694 //  SUIT_ViewWindow *suitVW = NULL;
1695 //
1696 //  SUIT_ViewManager *vtkViewManager = getApp()->getViewManager(SVTK_Viewer::Type(), true);
1697 //  MESSAGE("suitVM->getViewsCount() => " << suitVM->getViewsCount() );
1698 //  suitVW = suitVM->getActiveView();
1699 //  if ( _documentView.count(suitVW) > 0)
1700 //    suitVW = suitVM->createViewWindow();
1701 //
1702 //  if ( suitVW ){
1703 ////    suitVW->setClosable(false);
1704 //      suitVW->setClosable(true);
1705 //    newGView = new DocumentGraphicView(getApp(), suitVW, application()->desktop());
1706 //    _documentView[suitVW] = newGView;
1707 //  }
1708 //
1709 //  return newGView;
1710 //}
1711
1712
1713 void HEXABLOCKGUI::testDocument()
1714 {
1715   //CS_TEST
1716   // ----------
1717 //   QStandardItem *parentItem = _currentModel->invisibleRootItem();
1718 //   QStandardItem *myItem =  new QStandardItem("MyItem");
1719 //   parentItem->appendRow(myItem);
1720 // //   ----------
1721 //   QModelIndex v0 = _currentModel->addVertex(0., 0., 0.);
1722 //   QModelIndex v1 = _currentModel->addVertex(5., 0., 0.);
1723 //   QModelIndex v2 = _currentModel->addVertex(5., 5., 0.);
1724 //   QModelIndex v3 = _currentModel->addVertex(0., 5., 0.);
1725 //   QModelIndex v4 = _currentModel->addVertex(0., 0., 5.);
1726 //   QModelIndex v5 = _currentModel->addVertex(5., 0., 5.);
1727 //   QModelIndex v6 = _currentModel->addVertex(5., 5., 5.);
1728 //   QModelIndex v7 = _currentModel->addVertex(0., 5., 5.);
1729 // //
1730 // //
1731 //   QModelIndex q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1732 //   QModelIndex q1 = _currentModel->addQuadVertices( v4, v5, v6, v7 );
1733 //   QModelIndex q2 = _currentModel->addQuadVertices( v0, v3, v7, v4 );
1734 //   QModelIndex q3 = _currentModel->addQuadVertices( v1, v2, v6, v5 );
1735 //   QModelIndex q4 = _currentModel->addQuadVertices( v0, v1, v5, v4 );
1736 //   QModelIndex q5 = _currentModel->addQuadVertices( v3, v2, v6, v7 );
1737 //
1738 //   QModelIndex h0 = _currentModel->addHexaQuad( q0, q1, q2, q3, q4, q5 );
1739 //   QModelIndex vx = _currentModel->addVector(1., 0., 0.);
1740 //   QModelIndex vy = _currentModel->addVector(0., 1., 0.);
1741 //   QModelIndex vz = _currentModel->addVector(0., 0., 1.);
1742 //
1743
1744
1745
1746 // //   QModelIndex orig1 = _currentModel->addVertex (0, 0,0);
1747 // //   QModelIndex orig2 = _currentModel->addVertex (50,0,0);
1748 // //   QModelIndex vz    = _currentModel->addVector (0,0,1);
1749 // //   QModelIndex vx    = _currentModel->addVector (1,0,0);
1750 // //
1751 // //   int nr  = 4;
1752 // //   int nri = 3;
1753 // //   int nre = nr;
1754 // //   int na = 9;
1755 // //   int nl = 5;
1756 // //
1757 // //   QModelIndex  cyl  = _currentModel->addCylinder   (orig1, vz, nr, nl);
1758 // //   QModelIndex  pipe = _currentModel->addPipe       (orig2, vz, nri, nre, nl);
1759 // //
1760 // //   _currentModel->makeCylinder (cyl,  vx, nr, na, nl);
1761 // //   _currentModel->makePipe(pipe, vx, nr, na, nl);
1762
1763
1764
1765 //   newMesh( "toto", 3, "FactoryServer");
1766 // newMesh
1767 }
1768
1769 void HEXABLOCKGUI::test_make_cart_grid()
1770 {
1771 QModelIndex orig1 = _currentModel->addVertex( 0, 0, 0);
1772 QModelIndex orig2 = _currentModel->addVertex( 10, 0, 0);
1773 QModelIndex orig3 = _currentModel->addVertex( 0, 10, 0);
1774 QModelIndex orig4 = _currentModel->addVertex( 10, 10, 0);
1775 QModelIndex orig5 = _currentModel->addVertex( 0, 20, 0);
1776 QModelIndex orig6 = _currentModel->addVertex( 10, 20, 0);
1777
1778 QModelIndex vz = _currentModel->addVector(0, 0, 1);
1779 QModelIndex vx = _currentModel->addVector(1, 0, 0);
1780
1781 //int dr = 1;
1782 //int dl = 1;
1783 //int nr = 2;
1784 //int nl = 3;
1785
1786 // QModelIndex c1 = _currentModel->makeCylindrical(orig1, vx, vz, dr, 360, dl, nr, 4, nl, true);
1787 // QModelIndex c2 = _currentModel->makeCylindrical(orig2, vx, vz, dr, 360, dl, nr, 8, nl, true);
1788 // QModelIndex c3 = _currentModel->makeCylindrical(orig3, vx, vz, dr, 270, dl, nr, 8, nl, true);
1789 // QModelIndex c4 = _currentModel->makeCylindrical(orig4, vx, vz, dr, 270, dl, nr, 7, nl, true);
1790 // QModelIndex c5 = _currentModel->makeCylindrical(orig5, vx, vz, dr, 360, dl, nr, 5, nl, true);
1791 // QModelIndex c6 = _currentModel->makeCylindrical(orig6, vx, vz, dr, 360, dl, nr, 6, nl, true);
1792
1793 }
1794
1795
1796 void HEXABLOCKGUI::test_make_elmts_transform()
1797 {
1798
1799 int size_x = 1;
1800 int size_y = 1;
1801 int size_z = 2;
1802
1803 QModelIndex orig = _currentModel->addVertex(0, 0, 0);
1804 QModelIndex dirVr = _currentModel->addVector(1, 1, 1);
1805
1806 QModelIndex grid = _currentModel->makeCartesian(orig, dirVr, size_x, size_y, size_z);//, 0, 0, 0);
1807 // orig.setScalar(2);
1808
1809 // file_name = os.path.join(os.environ['TMP'], 'transfo0.vtk')
1810 // _currentModel->saveVtk(file_name)
1811
1812 QModelIndex devant = _currentModel->addVector(5, 0, 0);
1813 QModelIndex grid2  = _currentModel->makeTranslation(grid, devant);
1814
1815 // file_name = os.path.join(os.environ['TMP'], 'transfo_translation.vtk')
1816 // _currentModel->saveVtk(file_name)
1817
1818 QModelIndex grid4 = _currentModel->makeRotation(grid2, orig, dirVr, 45);
1819
1820
1821 // file_name = os.path.join(os.environ['TMP'], 'transfo_rotation.vtk');
1822 // _currentModel->saveVtk(file_name);
1823
1824
1825 // print "...test make elements by transforming elements OK"
1826 }
1827
1828
1829 void HEXABLOCKGUI::test()
1830 {
1831   DEBTRACE("HEXABLOCKGUI::test");
1832   _currentGraphicView->update();
1833
1834 }
1835
1836 void HEXABLOCKGUI::test_association()
1837 {
1838   DEBTRACE("HEXABLOCKGUI::test_association");
1839   newDocument();
1840
1841   QModelIndex v0, v1, v2, v3, e0, e1, q0;
1842
1843   DocumentModel::GeomObj v0Assoc, v1Assoc, v2Assoc, v3Assoc;
1844   DocumentModel::GeomObj e0AssocA, e1AssocA, e1AssocB, e1AssocC;
1845   DocumentModel::GeomObj q0AssocA, q0AssocB;
1846
1847   DocumentModel::GeomObj v0Assoc_test, v1Assoc_test, v2Assoc_test, v3Assoc_test;
1848   QList<DocumentModel::GeomObj> e1Assocs_test;
1849   DocumentModel::GeomObj q0Assoc_test;
1850
1851   v0 = _currentModel->addVertex(0, 0, 0);
1852   v1 = _currentModel->addVertex(1, 0, 0);
1853   v2 = _currentModel->addVertex(1, 1, 0);
1854   v3 = _currentModel->addVertex(0, 1, 0);
1855   e0  = _currentModel->addEdgeVertices(v0, v1);
1856   e1  = _currentModel->addEdgeVertices(v1, v2);
1857   q0 = _currentModel->addQuadVertices( v0, v1, v2, v3 );
1858
1859
1860 // >>> face3.GetEntry()'0:1:4'
1861 // >>> e1.GetEntry()'0:1:8'
1862 // >>> e2.GetEntry()'0:1:9'
1863 // >>> e3.GetEntry()'0:1:10'
1864 // >>> e4.GetEntry()'0:1:11'
1865 // >>> v1.GetEntry()'0:1:12'
1866 // >>> v2.GetEntry()'0:1:13'
1867 // >>> v3.GetEntry()'0:1:14'
1868 // >>> v4.GetEntry()'0:1:15'
1869
1870
1871 //   v0Assoc.name  = "geomV0";
1872 //   v0Assoc.entry = "0:1:1:1:3:6";//"0:1:12";
1873 //   v0Assoc.brep  = "brepV0";
1874 //   v1Assoc.name  = "geomV1";
1875 //   v1Assoc.entry = "0:1:1:1:3:7";//"0:1:13";
1876 //   v1Assoc.brep  = "brepV1";
1877 //   v2Assoc.name  = "geomV2";
1878 //   v2Assoc.entry = "0:1:1:1:3:8";//"0:1:14";
1879 //   v2Assoc.brep  = "brepV2";
1880 //   v3Assoc.name  = "geomV3";
1881 //   v3Assoc.entry = "0:1:1:1:3:9";//"0:1:15";
1882 //   v3Assoc.brep  = "brepV3";
1883 //
1884 //
1885 //
1886 //   e0AssocA.name   = "geomE0a";
1887 //   e0AssocA.entry  = "0:1:1:1:3:5";//"0:1:8";
1888 //   e0AssocA.brep  = "brepE0a";
1889 //   e0AssocA.start  = 0.10;
1890 //   e0AssocA.end    = 0.95;
1891 //
1892 //
1893 //
1894 //   e1AssocA.name   = "geomE1a";
1895 //   e1AssocA.entry  = "0:1:1:1:3:2";//"0:1:8";
1896 //   e1AssocA.brep  = "brepE1a";
1897 //   e1AssocA.start  = 0.12;
1898 //   e1AssocA.end    = 0.89;
1899 //   e1AssocB.name   = "geomE1b";
1900 //   e1AssocB.entry  = "0:1:1:1:3:3";//"0:1:9";
1901 //   e1AssocB.brep  = "brepE1b";
1902 //   e1AssocB.start  = 0.20;
1903 //   e1AssocB.end    = 0.80;
1904 //   e1AssocC.name   = "geomE1c";
1905 //   e1AssocC.entry  = "0:1:1:1:3:4";//"0:1:10";
1906 //   e1AssocC.brep  = "brepE1c";
1907 //   e1AssocC.start  = 0.16;
1908 //   e1AssocC.end    = 0.96;
1909 //
1910 //   q0AssocA.name   = "geomQuad";
1911 //   q0AssocA.entry  = "0:1:1:1:3";
1912 //   q0AssocA.brep   = "brepq0";
1913 //
1914 //   q0AssocB.name   = "geomQuad";
1915 //   q0AssocB.entry  = "0:1:1:1:4";
1916 //   q0AssocB.brep   = "brepq0";
1917 //
1918 //   _currentModel->addAssociation( v0, v0Assoc );
1919 //   _currentModel->addAssociation( v1, v1Assoc );
1920 //   _currentModel->addAssociation( v2, v2Assoc );
1921 //   _currentModel->addAssociation( v3, v3Assoc );
1922 //
1923 //
1924 //   _currentModel->addAssociation( e0, e0AssocA );
1925 //
1926 //   _currentModel->addAssociation( e1, e1AssocA );
1927 //   _currentModel->addAssociation( e1, e1AssocB );
1928 //   _currentModel->addAssociation( e1, e1AssocC );
1929 //
1930 //   _currentModel->addAssociation( q0, q0AssocA );
1931 //   _currentModel->addAssociation( q0, q0AssocB );
1932
1933
1934
1935
1936
1937 //   v0Assoc_test = _currentModel->getAssociations( v0 )[0];
1938 //   v1Assoc_test = _currentModel->getAssociations( v1 )[0];
1939 //   v2Assoc_test = _currentModel->getAssociations( v2 )[0];
1940 //   v3Assoc_test = _currentModel->getAssociations( v3 )[0];
1941 //   ASSERT( v0Assoc.name == v0Assoc_test.name );
1942 //   ASSERT( v1Assoc.name == v1Assoc_test.name );
1943 //   ASSERT( v2Assoc.name == v2Assoc_test.name );
1944 //   ASSERT( v3Assoc.name == v3Assoc_test.name );
1945 //   ASSERT( v0Assoc.entry == v0Assoc_test.entry );
1946 //   ASSERT( v1Assoc.entry == v1Assoc_test.entry );
1947 //   ASSERT( v2Assoc.entry == v2Assoc_test.entry );
1948 //   ASSERT( v3Assoc.entry == v3Assoc_test.entry );
1949 //
1950 //
1951 //   e1Assocs_test = _currentModel->getAssociations( e1 );
1952 //   ASSERT( e1Assocs_test[0].name == e1AssocA.name );
1953 //   ASSERT( e1Assocs_test[1].name == e1AssocB.name );
1954 //   ASSERT( e1Assocs_test[2].name == e1AssocC.name );
1955 //   ASSERT( e1Assocs_test[0].entry == e1AssocA.entry );
1956 //   ASSERT( e1Assocs_test[1].entry == e1AssocB.entry );
1957 //   ASSERT( e1Assocs_test[2].entry == e1AssocC.entry );
1958 //   ASSERT( e1Assocs_test[0].start == e1AssocA.start );
1959 //   ASSERT( e1Assocs_test[1].start == e1AssocB.start );
1960 //   ASSERT( e1Assocs_test[2].start == e1AssocC.start );
1961 //   ASSERT( e1Assocs_test[0].end == e1AssocA.end );
1962 //   ASSERT( e1Assocs_test[1].end == e1AssocB.end );
1963 //   ASSERT( e1Assocs_test[2].end == e1AssocC.end );
1964 //
1965 //   q0Assoc_test = _currentModel->getAssociations( q0 )[0];
1966 //   ASSERT( q0Assoc_test.name  == q0Assoc.name );
1967 //   ASSERT( q0Assoc_test.entry == q0Assoc.entry );
1968
1969
1970   DEBTRACE("HEXABLOCKGUI::test_association fin");
1971 }
1972
1973
1974 void HEXABLOCKGUI::newDocument()
1975 {
1976         DEBTRACE("HEXABLOCKGUI::newDocument");
1977
1978         SUIT_ViewWindow *suitVW = NULL;
1979         //   std::stringstream name;
1980         //   name << "newDoc_" << ++_documentCnt;
1981         //   QString fileName = name.str().c_str();
1982         QMainWindow *aParent = application()->desktop();
1983         QWidget *central = aParent->centralWidget();
1984         if (central)
1985                 central->setFocus();
1986         else
1987                 DEBTRACE("No Central Widget");
1988
1989         //   BasicGUI_PointDlg* aDlg = new BasicGUI_PointDlg( NULL, aParent );
1990         //   aDlg->show();
1991
1992         // Create Document from HEXABLOCK ENGINE
1993         // WARNING : IN HEXABLOCK component,  GUI and ENGINE share the same process
1994         HEXABLOCK_ORB::Document_ptr docIn = _hexaEngine->addDocument("default");
1995
1996         HEXA_NS::Document* doc = NULL;
1997         QString            docEntry;
1998
1999         // looking doc impl ( c++ )
2000         Document_impl* dServant = DownCast<Document_impl*>( docIn );
2001         ASSERT( dServant );
2002         if ( dServant) doc = dServant->GetImpl();
2003
2004         //   doc->reorderFaces(); //CS_TEST
2005
2006         // looking for docEntry
2007         if ( !CORBA::is_nil(docIn) ){
2008                 CORBA::String_var anIOR = SalomeApp_Application::orb()->object_to_string( docIn );
2009                 QString docIOR = anIOR.in();
2010                 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2011                 if ( !docIOR.isEmpty() ) {
2012                         _PTR(SObject) SO( study->studyDS()->FindObjectIOR( docIOR.toLatin1().constData() ) );
2013                         if ( SO )
2014                                 docEntry = SO->GetID().c_str();
2015                 }
2016         }
2017
2018         DEBTRACE("HEXABLOCKGUI::newDocument docEntry "<<docEntry.toStdString());
2019
2020
2021         // Now create Document Model
2022         _currentModel     = new DocumentModel( doc, docEntry, this ); //CS_TOCHECK this
2023         //   _currentModel->setHeaderData(0, Qt::Horizontal, tr("HELLOH0"));
2024         //   _currentModel->setHeaderData(1, Qt::Horizontal, tr("HELLOH1"));
2025         //   _currentModel->setHeaderData(0, Qt::Vertical, tr("HELLOV0"));
2026         _patternDataModel    = new PatternDataModel(this);
2027         _patternBuilderModel = new PatternBuilderModel(this);
2028         //   _associationsModel   = new AssociationsModel(this);
2029         _groupsModel     = new GroupsModel(this);
2030         _meshModel       = new MeshModel(this);
2031
2032         _patternDataModel->setSourceModel(_currentModel);
2033         _patternBuilderModel->setSourceModel(_currentModel);
2034         //   _associationsModel->setSourceModel(_currentModel);
2035         _groupsModel->setSourceModel(_currentModel);
2036         _meshModel->setSourceModel(_currentModel);
2037
2038         // --- new Graphic view ( SVTK )
2039         _currentGraphicView  = newGraphicView();
2040         suitVW = _currentGraphicView->get_SUIT_ViewWindow();
2041
2042         // --- setting model
2043         _currentGraphicView->setModel(_currentModel);
2044         //   _currentGraphicView->setModel(_patternDataModel);
2045         //   connect( _currentModel, SIGNAL(patternDataChanged() ), _currentGraphicView,  SLOT ( onPatternDatachanged() ) );
2046         _patternDataTreeView->setModel(_patternDataModel);//_currentModel;
2047         //   _patternDataTreeView->setModel(_currentModel);//;
2048         _patternBuilderTreeView->setModel(_patternBuilderModel);//_currentModel;
2049         //   _associationTreeView->setModel(_associationsModel);
2050         _groupsTreeView->setModel(_groupsModel);
2051         _meshTreeView->setModel(_meshModel);
2052
2053
2054         //  if ( _patternDataSelectionModel )    delete _patternDataSelectionModel;
2055         //  if ( _patternBuilderSelectionModel ) delete _patternBuilderSelectionModel;
2056         //  if ( _groupsSelectionModel )         delete _groupsSelectionModel;
2057         //  if ( _meshSelectionModel )           delete _meshSelectionModel;
2058
2059         // --- setting selection model
2060         _patternDataSelectionModel    = new PatternDataSelectionModel(_patternDataModel);
2061         _patternBuilderSelectionModel = new PatternBuilderSelectionModel( _patternBuilderModel, _patternDataSelectionModel );
2062         _groupsSelectionModel         = new GroupsSelectionModel(_groupsModel);
2063         _meshSelectionModel           = new MeshSelectionModel(_meshModel);
2064
2065         _patternDataSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2066         //   _meshSelectionModel->setSalomeSelectionMgr( selectionMgr() );
2067
2068         _currentGraphicView->setSelectionModel(_patternDataSelectionModel);
2069         _patternDataTreeView->setSelectionModel(_patternDataSelectionModel);
2070         _patternDataTreeView->setSelectionMode(QAbstractItemView::SingleSelection); //QAbstractItemView::MultiSelection //CS_TEST
2071         _patternBuilderTreeView->setSelectionModel(_patternBuilderSelectionModel);
2072         _groupsTreeView->setSelectionModel(_groupsSelectionModel);
2073         _meshTreeView->setSelectionModel(_meshSelectionModel);
2074         _meshTreeView->setSelectionMode(QAbstractItemView::SingleSelection);
2075
2076         _treeViewDelegate->setDocumentModel( _currentModel );
2077         _treeViewDelegate->setPatternDataSelectionModel( _patternDataSelectionModel );
2078         _treeViewDelegate->setPatternBuilderSelectionModel( _patternBuilderSelectionModel );
2079         _treeViewDelegate->setGroupsSelectionModel( _groupsSelectionModel/*_groupsTreeView->selectionModel()*/ );
2080         _treeViewDelegate->setMeshSelectionModel( _meshSelectionModel/*_meshTreeView->selectionModel()*/ );
2081
2082
2083         connect( _patternDataSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2084                         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2085         connect( _patternBuilderSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2086                         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2087         connect( _groupsSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2088                         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2089         connect( _meshSelectionModel, SIGNAL( selectionChanged(const QItemSelection &, const QItemSelection &) ),
2090                         this, SLOT( onSelectionChanged(const QItemSelection &, const QItemSelection &) ) );
2091
2092
2093         // salome view/object browser/model management
2094         _documentModels[ suitVW ] = _currentModel;
2095
2096         //   _salomeViews[ _currentModel ] = suitVW;
2097         //   std::map<const QAbstractItemModel*,  SUIT_ViewWindow*> _salomeViews;
2098
2099         _salomeViewWindows[docEntry] = suitVW;
2100         currentVtkView = dynamic_cast<SVTK_ViewWindow*>( _currentGraphicView->get_SUIT_ViewWindow() );
2101         currentVtkView->raise();
2102
2103         //   _currentGraphicView->setWindowTitle( _currentModel->getName() );
2104         //   currentVtkView->setWindowTitle( _currentModel->getName() );
2105         //   showDockWidgets(true);
2106         //   showPatternMenus
2107         //   _dwPattern->setVisible(true);
2108         //   _dwPattern->toggleViewAction()->setVisible(true);
2109         _dwPattern->raise();
2110         //   testDocument();
2111         //   test_make_cart_grid();
2112         //   test_make_elmts_transform();
2113         showAllMenus();
2114         getApp()->updateObjectBrowser();
2115
2116         graphicViewIsEmpty[suitVW] = true;
2117 }
2118
2119
2120 void HEXABLOCKGUI::slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight)
2121 {
2122   //std::cout << "HHHHHHHHHHHHHHHHHH  Model changed." << std::endl;
2123   //std::cout << "HHHHHHHHHHHHHHHHHH  slot_modelChanged topLeft -> " << topLeft.data().toString().toStdString()<<std::endl;
2124   //std::cout << "HHHHHHHHHHHHHHHHHH  slot_modelChanged bottomRight ->" << bottomRight.data().toString().toStdString()<<std::endl;
2125
2126   _patternDataTreeView->openPersistentEditor( topLeft );
2127
2128 //   // Make the combo boxes always displayed.
2129 //   for ( int i = 0; i < _currentModel->rowCount(); ++i )
2130 //     {
2131 //       QModelIndex ind = _currentModel->index(i);
2132 //     _patternDataTreeView->openPersistentEditor( ind );
2133 //     std::cout << "ind" << ind.data() << std::endl;
2134 //     }
2135 }
2136
2137 void HEXABLOCKGUI::loadDocument( const QString &inFile )
2138 {
2139   DEBTRACE("HEXABLOCKGUI::loadDocument");
2140   QMainWindow *aParent = application()->desktop();
2141   QString selectedFile;
2142
2143   if ( inFile.isNull() ){
2144     QFileDialog dialog( aParent, tr("Open HexaBlock Document") ,
2145                         QString::null, tr( "XML-Files (*.xml);;All Files (*)" ) );
2146     dialog.setHistory( getQuickDirList() );
2147     if (dialog.exec()){
2148       QStringList selectedFiles = dialog.selectedFiles();
2149       if (!selectedFiles.isEmpty())
2150         selectedFile = selectedFiles.first();
2151     }
2152   } else
2153           selectedFile = inFile;
2154
2155   if (! selectedFile.isEmpty()){
2156           if (vtkViewManager==NULL || vtkViewManager->getViewsCount()==0 || !graphicViewIsEmpty[vtkViewManager->getActiveView()])
2157                   newDocument();
2158           _currentModel->load(selectedFile);
2159           renameObject( _currentModel->documentEntry(), _currentModel->getName() );
2160           graphicViewIsEmpty[vtkViewManager->getActiveView()] = false;
2161   }
2162 }
2163
2164 void HEXABLOCKGUI::saveDocument()
2165 {
2166   QMainWindow *aParent = application()->desktop();
2167   QString anInitialPath = "";
2168   if ( SUIT_FileDlg::getLastVisitedPath().isEmpty() )
2169     anInitialPath = QDir::currentPath();
2170 //   QString aMeshName = anIO->getName();
2171
2172   QString aDocName = "document";
2173   QStringList filter;
2174   filter.append( QObject::tr( "XML_FILES_FILTER" ) + " (*.xml)" );
2175   filter.append( QObject::tr( "ALL_FILES_FILTER" ) + " (*)" );
2176   QString aFilename =  anInitialPath + QString("/") + aDocName;
2177   aFilename = SUIT_FileDlg::getFileName( aParent,
2178                                          aFilename,
2179                                          filter,
2180                                          tr( "Save HexaBlock Document" ),
2181                                          false );
2182   if ( !aFilename.isEmpty() ) {
2183     _currentModel->save( aFilename );
2184   }
2185   //CS_TODO save doc
2186 }
2187
2188
2189 void HEXABLOCKGUI::_showDialogBox( HexaBaseDialog* diag )
2190 {
2191   MESSAGE("HEXABLOCKGUI::_showDialogBox()");
2192   if (vtkViewManager == NULL || vtkViewManager->getViewsCount() == 0) return;
2193   if (!diag) return;
2194   MESSAGE("if (!diag) return;");
2195   if (!_dwInputPanel) return;
2196   MESSAGE("if (!_dwInputPanel) return;");
2197
2198   currentDialog = diag;
2199   diag->setDocumentModel(_currentModel);
2200   diag->setPatternDataSelectionModel(_patternDataSelectionModel);
2201   diag->setPatternBuilderSelectionModel(_patternBuilderSelectionModel);
2202   diag->setGroupsSelectionModel(_groupsSelectionModel);
2203   diag->setMeshSelectionModel(_meshSelectionModel);
2204
2205   //close the current widget
2206   if (_treeViewDelegate != NULL)
2207           _treeViewDelegate->closeDialog();
2208
2209   if (_dwInputPanel->widget())
2210           _dwInputPanel->widget()->close();
2211
2212   //Temporary for debugging EdgeAssoc Faked InfoDialog
2213   if (diag == _edgeAssocDiag)
2214           diag->debugEdgeAssoc = true;
2215   else
2216           diag->debugEdgeAssoc = false;
2217
2218   if (diag ==  _quadAssocDiag || diag ==  _edgeAssocDiag)
2219           assocInProgress = true;
2220   else
2221           assocInProgress = false;
2222
2223   //show the dialog box in the dockwidget
2224   diag->resetSizeAndShow(_dwInputPanel);
2225   diag->setFocus();
2226 }
2227
2228 void HEXABLOCKGUI::addVertex()
2229 {
2230   if ( !_vertexDiag ){
2231     _vertexDiag = new VertexDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2232   }
2233   _showDialogBox( _vertexDiag );
2234 }
2235
2236 void HEXABLOCKGUI::addEdge()
2237 {
2238   if ( !_edgeDiag ){
2239     _edgeDiag = new EdgeDialog( _dwInputPanel, HexaBaseDialog::NEW_MODE);
2240   }
2241   _showDialogBox( _edgeDiag );
2242 }
2243
2244 void HEXABLOCKGUI::addQuad()
2245 {
2246   if ( !_quadDiag ){
2247     _quadDiag = new QuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2248   }
2249   _showDialogBox( _quadDiag );
2250 }
2251
2252 void HEXABLOCKGUI::addHexa()
2253 {
2254   if ( !_hexaDiag ){
2255     _hexaDiag = new HexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2256   }
2257   _showDialogBox( _hexaDiag );
2258 }
2259
2260 void HEXABLOCKGUI::addVector()
2261 {
2262   if ( !_vectorDiag ){
2263     _vectorDiag = new VectorDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2264   }
2265   _showDialogBox( _vectorDiag );
2266 }
2267
2268 void HEXABLOCKGUI::addCylinder()
2269 {
2270   if ( !_cylinderDiag ){
2271     _cylinderDiag = new CylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2272   }
2273   _showDialogBox( _cylinderDiag );
2274 }
2275
2276
2277 void HEXABLOCKGUI::addPipe()
2278 {
2279   if ( !_pipeDiag){
2280     _pipeDiag = new PipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2281   }
2282   _showDialogBox( _pipeDiag );
2283 }
2284
2285
2286 void HEXABLOCKGUI::makeGrid()
2287 {
2288   if ( !_makeGridDiag ){
2289     _makeGridDiag = new MakeGridDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2290   }
2291   _showDialogBox( _makeGridDiag );
2292 }
2293
2294
2295 void HEXABLOCKGUI::makeCylinder()
2296 {
2297   if ( !_makeCylinderDiag ){
2298     _makeCylinderDiag = new MakeCylinderDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2299   }
2300   _showDialogBox( _makeCylinderDiag );
2301 }
2302
2303 void HEXABLOCKGUI::makePipe()
2304 {
2305   if ( !_makePipeDiag ){
2306     _makePipeDiag = new MakePipeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2307   }
2308   _showDialogBox( _makePipeDiag );
2309 }
2310
2311 void HEXABLOCKGUI::makeCylinders()
2312 {
2313   if ( !_makeCylindersDiag ){
2314     _makeCylindersDiag = new MakeCylindersDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2315   }
2316   _showDialogBox( _makeCylindersDiag );
2317 }
2318
2319 void HEXABLOCKGUI::makePipes()
2320 {
2321   if ( !_makePipesDiag ){
2322     _makePipesDiag = new MakePipesDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2323   }
2324   _showDialogBox( _makePipesDiag );
2325 }
2326
2327
2328 void HEXABLOCKGUI::makeHemiSphere()  // NEW HEXA3
2329 {
2330   if ( !_makeHemiSphereDiag ){
2331     _makeHemiSphereDiag = new MakeHemiSphereDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2332   }
2333   _showDialogBox( _makeHemiSphereDiag );
2334 }
2335
2336
2337 void HEXABLOCKGUI::removeHexa()
2338 {
2339   if ( !_removeHexaDiag ){
2340     _removeHexaDiag = new RemoveHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2341   }
2342   _showDialogBox( _removeHexaDiag );
2343 }
2344
2345
2346 void HEXABLOCKGUI::prismQuad()
2347 {
2348   if ( !_prismQuadDiag ){
2349     _prismQuadDiag = new PrismQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2350   }
2351   _showDialogBox( _prismQuadDiag );
2352 }
2353
2354
2355 void HEXABLOCKGUI::joinQuad()
2356 {
2357   if ( !_joinQuadDiag ){
2358     _joinQuadDiag = new JoinQuadDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2359   }
2360   _showDialogBox( _joinQuadDiag );
2361 }
2362
2363 void HEXABLOCKGUI::merge()
2364 {
2365   if ( !_mergeDiag ){
2366     _mergeDiag = new MergeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2367   }
2368   _showDialogBox( _mergeDiag );
2369 }
2370
2371 void HEXABLOCKGUI::disconnectElts()
2372 {
2373   if ( !_disconnectDiag ){
2374     _disconnectDiag = new DisconnectDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2375   }
2376   _showDialogBox( _disconnectDiag );
2377 }
2378
2379 void HEXABLOCKGUI::cutEdge()
2380 {
2381   if ( !_cutEdgeDiag ){
2382     _cutEdgeDiag = new CutEdgeDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2383   }
2384   _showDialogBox( _cutEdgeDiag );
2385 }
2386
2387 void HEXABLOCKGUI::makeTransformation()
2388 {
2389   if ( !_makeTransformationDiag ){
2390     _makeTransformationDiag = new MakeTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2391   }
2392   _showDialogBox( _makeTransformationDiag );
2393 }
2394
2395
2396 void HEXABLOCKGUI::makeSymmetry()
2397 {
2398   if ( !_makeSymmetryDiag ){
2399     _makeSymmetryDiag = new MakeSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2400   }
2401   _showDialogBox( _makeSymmetryDiag );
2402 }
2403
2404
2405 void HEXABLOCKGUI::performTransformation()
2406 {
2407   if ( !_performTransformationDiag ){
2408     _performTransformationDiag = new PerformTransformationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2409   }
2410   _showDialogBox( _performTransformationDiag );
2411 }
2412
2413
2414 void HEXABLOCKGUI::performSymmetry()
2415 {
2416   if ( !_performSymmetryDiag ){
2417     _performSymmetryDiag = new PerformSymmetryDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2418   }
2419   _showDialogBox( _performSymmetryDiag );
2420 }
2421
2422
2423 void HEXABLOCKGUI::replaceHexa()    // NEW HEXA3
2424 {
2425   if ( !_replaceHexaDiag ){
2426     _replaceHexaDiag = new ReplaceHexaDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2427   }
2428   _showDialogBox( _replaceHexaDiag );
2429 }
2430
2431
2432 void HEXABLOCKGUI::quadRevolution() // NEW HEXA3
2433 {
2434   if ( !_quadRevolutionDiag ){
2435     _quadRevolutionDiag = new QuadRevolutionDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2436   }
2437   _showDialogBox( _quadRevolutionDiag );
2438 }
2439
2440
2441 // void HEXABLOCKGUI::assocVertex()
2442 // {
2443 //   if ( !_vertexAssocDiag ){
2444 //     _vertexAssocDiag = new VertexAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2445 //   }
2446 //   _showDialogBox( vertexAssocDiag );
2447 // }
2448
2449
2450 void HEXABLOCKGUI::assocVertex()
2451 {
2452  MESSAGE("HEXABLOCKGUI::assocVertex()");
2453  if (!_dwInputPanel) return;
2454  QWidget* d = dynamic_cast<SUIT_Desktop*>(_dwInputPanel->parent());
2455
2456   if ( !_vertexAssocDiag  ){
2457     _vertexAssocDiag  = new VertexAssocDialog( NULL, d );
2458     if (!_vertexAssocDiag) return;
2459   }
2460   _vertexAssocDiag->setDocumentModel(_currentModel);
2461   _vertexAssocDiag->setPatternDataSelectionModel(_patternDataSelectionModel);
2462
2463   //close current widget
2464   if (_treeViewDelegate != NULL) _treeViewDelegate->closeDialog();
2465   if (_dwInputPanel->widget()) _dwInputPanel->widget()->close();
2466
2467   //add the vertex assoc dialog in the dockwidget
2468   if ( !_dwInputPanel->isVisible() ) _dwInputPanel->setVisible(true);
2469   _dwInputPanel->setWidget(_vertexAssocDiag);
2470   _dwInputPanel->setWindowTitle(_vertexAssocDiag->windowTitle());
2471   _vertexAssocDiag->adjustSize();
2472   assocInProgress = true;
2473   _vertexAssocDiag->show();
2474 }
2475
2476
2477
2478 void HEXABLOCKGUI::assocEdge()
2479 {
2480   if ( !_edgeAssocDiag ){
2481     _edgeAssocDiag = new EdgeAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2482     _edgeAssocDiag->setGeomEngine( _geomEngine );
2483   }
2484   _showDialogBox( _edgeAssocDiag );
2485 }
2486
2487 void HEXABLOCKGUI::assocQuad()
2488 {
2489   if ( !_quadAssocDiag ){
2490     _quadAssocDiag = new QuadAssocDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2491   }
2492   _showDialogBox( _quadAssocDiag );
2493 }
2494
2495
2496 void HEXABLOCKGUI::addGroup()
2497 {
2498   if ( !_groupDiag ){
2499     _groupDiag = new GroupDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2500   }
2501   _showDialogBox( _groupDiag );
2502 }
2503
2504
2505 /*
2506 void HEXABLOCKGUI::removeGroup()
2507 {
2508   QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2509   QModelIndex selected = groupsSelectionModel->currentIndex();
2510   selected = _groupsModel->mapToSource( selected );
2511
2512 /*
2513   if ( !selected.isValid() ){
2514     SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ), tr( "No group selected!" ) );
2515     return;
2516   }
2517
2518   //Demande de confirmation de la suppression des groupes
2519   if (SUIT_MessageBox::question(
2520             0,
2521             tr("Remove Group"),
2522             tr("Remove group : %1 ?").arg(selected.data().toString()),
2523             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2524             SUIT_MessageBox::Cancel
2525         ) == SUIT_MessageBox::Cancel) return;
2526
2527   groupsSelectionModel->clearSelection();
2528  
2529   std::cout << "//////////////////////////  " << selected.data().toString().toStdString() << std::endl;
2530   bool removed = _currentModel->removeGroup( selected );
2531   //std::cout << "  " << selected.data().toString().toStdString() << std::endl;
2532   if ( !removed ) {
2533      SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ), tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2534      groupsSelectionModel->clearSelection();
2535      return;
2536   }
2537 }*/
2538
2539
2540
2541 void HEXABLOCKGUI::removeGroup()
2542 {
2543   QItemSelectionModel *groupsSelectionModel = _groupsTreeView->selectionModel();
2544   QModelIndexList l = groupsSelectionModel->selectedIndexes();
2545   int nbGroupsRemoved = 0;
2546
2547   if ( l.isEmpty() ){
2548     SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ), 
2549                                                                         tr( "No group selected!" ) );
2550     return;
2551   }
2552
2553   foreach( QModelIndex selected, l ){
2554     if ( selected.data(HEXA_TREE_ROLE) == GROUP_TREE ){
2555       selected = _groupsModel->mapToSource( selected );
2556       Q_ASSERT(selected.isValid());
2557
2558       //Confirm the deletion of the group
2559       if (SUIT_MessageBox::question(
2560             0,
2561             tr("Remove Group"),
2562             tr("Remove group : %1 ?").arg(selected.data().toString()),
2563             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2564             SUIT_MessageBox::Cancel
2565         ) == SUIT_MessageBox::Cancel) return;
2566
2567       bool removed = _currentModel->removeGroup( selected );
2568       if ( !removed ) {
2569         SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ), 
2570                                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2571         return;
2572       }
2573           nbGroupsRemoved++;
2574     }
2575   }
2576   if (!nbGroupsRemoved)
2577         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE GROUP" ), 
2578                                                                         tr( "No group selected!" ) );
2579 }
2580
2581
2582 void HEXABLOCKGUI::addLaw()
2583 {
2584   if ( !_lawDiag ){
2585     _lawDiag = new LawDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2586   }
2587   _showDialogBox( _lawDiag );
2588 }
2589
2590 void HEXABLOCKGUI::removeLaw()
2591 {
2592
2593   QModelIndexList l = _meshSelectionModel->selectedIndexes();
2594   int nbLawsRemoved = 0;
2595
2596   if ( l.isEmpty() ){
2597     SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ), 
2598                                                                         tr( "No law selected!" ) );
2599     return;
2600   }
2601
2602   foreach( QModelIndex selected, l ){
2603     if ( selected.data(HEXA_TREE_ROLE) == LAW_TREE ){
2604       selected = _meshModel->mapToSource( selected );
2605       Q_ASSERT(selected.isValid());
2606
2607       //Confirm the deletion of the law
2608       if (SUIT_MessageBox::question(
2609             0,
2610             tr("Remove Law"),
2611             tr("Remove law : %1 ?\nAll propagations having this law will \
2612 have the default law.").arg(selected.data().toString()),
2613             SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2614             SUIT_MessageBox::Cancel
2615         ) == SUIT_MessageBox::Cancel) return;
2616
2617       bool removed = _currentModel->removeLaw(selected);
2618       if ( !removed ) {
2619         SUIT_MessageBox::critical( 0, tr( "ERR_ERROR" ), 
2620                                         tr( "CANNOT REMOVE %1" ).arg(selected.data().toString()) );
2621         return;
2622       }
2623           nbLawsRemoved++;
2624     }
2625   }
2626   if (!nbLawsRemoved)
2627         SUIT_MessageBox::information( 0, tr( "CANNOT REMOVE LAW" ), 
2628                                                                         tr( "No law selected!" ) );
2629
2630 }
2631
2632
2633 void HEXABLOCKGUI::setPropagation()
2634 {
2635         if ( !_propagationDiag ){
2636                 _propagationDiag = new PropagationDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2637         }
2638         _showDialogBox( _propagationDiag );
2639 }
2640
2641
2642 // Dialog box to compute a mesh from a document
2643 // --------------------------------------------
2644
2645 void HEXABLOCKGUI::computeMesh()
2646 {
2647   if ( !_computeMeshDiag ){
2648     _computeMeshDiag = new ComputeMeshDialog(_dwInputPanel, HexaBaseDialog::NEW_MODE);
2649   }
2650   _computeMeshDiag->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
2651   _showDialogBox( _computeMeshDiag );
2652 }
2653
2654 void HEXABLOCKGUI::clearAssociations()
2655 {
2656 //   QMessageBox::warning( 0, "windowTitle()", "clearAssociations" );
2657   QModelIndex iDataModel = _patternDataTreeView->currentIndex();
2658   QModelIndex iModel     = _patternDataModel->mapToSource(iDataModel);
2659
2660   _currentModel->clearEltAssociations(iModel);
2661
2662 //  SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2663 }
2664
2665 void HEXABLOCKGUI::clearAllAssociations()
2666 {
2667         //Confirm the deletion of the associations
2668         if (SUIT_MessageBox::question(
2669                         0,
2670                         tr("Clear Associations"),
2671                         tr("Clear all associations ?"),
2672                         SUIT_MessageBox::Ok | SUIT_MessageBox::Cancel,
2673                         SUIT_MessageBox::Cancel
2674         ) == SUIT_MessageBox::Cancel) return;
2675
2676         int currentChildIndex = 0;
2677         QModelIndex currentIndex = _patternDataModel->mapToSource(_patternDataTreeView->currentIndex());
2678         QVariant currentAssocVariant;
2679         QString currentAssocEntry;
2680
2681         QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2682         while( currentChild.isValid() ) {
2683
2684                 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2685                 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2686                 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2687                         _currentModel->clearEltAssociations(currentChild);
2688
2689                 currentChild = currentChild.sibling(currentChildIndex++, 0);
2690         }
2691
2692         //SUIT_MessageBox::information( 0, tr( "HEXA_INFO" ), tr( "ASSOCIATION CLEARED" ) );
2693 }
2694
2695 void HEXABLOCKGUI::showAssociations()
2696 {
2697         QModelIndexList elts;
2698         int currentChildIndex = 0;
2699         QVariant currentAssocVariant;
2700         QString currentAssocEntry;
2701         QModelIndex currentIndex = _patternDataTreeView->currentIndex();
2702         QModelIndex currentChild = currentIndex.child(currentChildIndex++, 0);
2703
2704         while( currentChild.isValid() ) {
2705
2706                 currentAssocVariant = currentChild.data( HEXA_ASSOC_ENTRY_ROLE );
2707                 currentAssocEntry = currentChild.data( HEXA_ASSOC_ENTRY_ROLE ).toString();
2708                 if ( currentAssocVariant.isValid() && !currentAssocEntry.isEmpty() )
2709                         elts << currentChild;
2710
2711                 currentChild = currentChild.sibling(currentChildIndex++, 0);
2712         }
2713         _patternDataSelectionModel-> highlightVTKElts( elts );
2714
2715 }
2716
2717
2718 LightApp_SelectionMgr* HEXABLOCKGUI::selectionMgr()
2719 {
2720   SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
2721   if( anApp )
2722     return dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
2723   else
2724     return NULL;
2725 }
2726
2727 QStringList HEXABLOCKGUI::getQuickDirList()
2728 {
2729   QStringList dirList;
2730   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
2731   if ( resMgr )
2732     dirList = resMgr->stringValue( "FileDlg", "QuickDirList" ).split( ';', QString::SkipEmptyParts );
2733   return dirList;
2734 }
2735
2736
2737
2738 // --- Export the module
2739
2740 extern "C"
2741 {
2742   HEXABLOCKGUI_EXPORT CAM_Module* createModule()
2743   {
2744     return new HEXABLOCKGUI();
2745   }
2746
2747   HEXABLOCKGUI_EXPORT char* getModuleVersion()
2748   {
2749     return (char*)HEXABLOCK_VERSION_STR;
2750   }
2751 }
2752
2753
2754 // void  HEXABLOCKGUI::newMesh( const std::string& meshName,
2755 //                                             int dim,
2756 //                              const std::string& container )
2757 // {
2758 //   SalomeApp_Application* app = getApp();
2759 //   int activeStudyId = app->activeStudy()->id();
2760 //
2761 //   if ( CORBA::is_nil(_hexaEngine) ) _hexaEngine  = InitHEXABLOCKGen( app );
2762 //   if ( CORBA::is_nil(_smeshEngine)) _smeshEngine = InitSMESHGen( app, container );
2763 //   if ( CORBA::is_nil(_geomEngine) ) _geomEngine  = InitGEOMGen( app, container );
2764 //
2765 //   std::cout << "_hexaEngine =>" << _hexaEngine << std::endl;
2766 //   std::cout << "_smeshEngine =>" << _smeshEngine << std::endl;
2767 //   std::cout << "_geomEngine =>" << _geomEngine << std::endl;
2768 //
2769 //   HEXA_NS::Document* docImpl = _currentModel->documentImpl();
2770 //   std::cout << "docImpl =>" << docImpl << std::endl;
2771 //   std::cout << "docImpl->getFile() =>" << docImpl->getFile() << std::endl;
2772 //   HEXABLOCK_ORB::Document_var anDocObj=  _hexaEngine->loadDocument( docImpl->getFile() );
2773 //   std::cout << "anDocObj =>" << anDocObj << std::endl;
2774 //
2775 //
2776 //   GEOM::GEOM_I3DPrimOperations_var anGeomOper = _geomEngine->GetI3DPrimOperations( activeStudyId );
2777 //   if ( CORBA::is_nil(anGeomOper) ) return;  //!anGeomOper->_is_nil() ) {
2778 //   std::cout << "anGeomOper =>" << anGeomOper << std::endl;
2779 //   GEOM::GEOM_Object_var            anGeomObj = anGeomOper->MakeBoxDXDYDZ( 5., 5., 5. );
2780 //   std::cout << "anGeomObj =>" << anGeomObj << std::endl;
2781 //
2782 //
2783 //   SALOMEDS::SObject _geomEngine->AddInStudy (in SALOMEDS::Study theStudy,
2784 //                                   in GEOM_Object theObject,
2785 //                                   in string theName,
2786 //
2787 //
2788 //
2789 // // void GEOMBase::PublishSubObject( GEOM::GEOM_Object_ptr object )
2790 // // {
2791 //   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
2792 //   if ( study && !CORBA::is_nil( object ) ) {
2793 //     _PTR(Study) studyDS = study->studyDS();
2794 //     QString entry = GetEntry( object );
2795 //     GEOM::GEOM_Object_var father = object->GetMainShape();
2796 //     QString fatherEntry = GetEntry( father );
2797 //     if ( entry.isEmpty() && !CORBA::is_nil( father ) && !fatherEntry.isEmpty() ) {
2798 //       QString name = GetName( object );
2799 //       GeometryGUI::GetGeomGen()->AddInStudy( GeometryGUI::ClientStudyToStudy( studyDS ),
2800 //                                           object, name.toLatin1().data(), father.in() );
2801 //     }
2802 //   }
2803 // }
2804 //
2805 //
2806 // //     geompy = smesh.geompy
2807 // //     #fkl: shape  = doc.getShape()
2808 // //     shape  = geompy.MakeBox(0, 0, 0,  1, 1, 1)
2809 // //     geompy.addToStudy(shape, name)
2810 // //
2811 // //     component = salome.lcc.FindOrLoadComponent(container, "SMESH")
2812 // //     component.init_smesh(salome.myStudy, geompy.geom)
2813 // //     mesh = component.Mesh(shape, name)
2814 // //
2815 // //     so = "libHexaBlockEngine.so"
2816 // //
2817 // //     algo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_3D", so)
2818 //     SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2819 // //       raises ( SALOME::SALOME_Exception );
2820 // //     mesh.mesh.AddHypothesis(shape, algo)
2821 // //
2822 // //     hypo = smesh.SMESH._objref_SMESH_Gen.CreateHypothesis(component, "HEXABLOCK_Parameters", so)
2823 //     //HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var
2824 //      SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2825 //
2826 //      HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2827 //     ASSERT(!CORBA::is_nil(hexHypo));
2828 //
2829 // //     mesh.mesh.AddHypothesis(shape, hypo)
2830 // //
2831 // //     hexHypo->SetDocument(anDocObj);
2832 // //     hexHypo->SetDimension(dim);
2833 // //
2834 // //     mesh.Compute()
2835 // //
2836 // //     return mesh
2837 //
2838 // }
2839 //
2840 //
2841 //
2842 // void  newMesh( const std::string& meshName, int dim )// const std::string& container )
2843 // {
2844 //
2845 // //     _smeshEngine.init_smesh(salome.myStudy, geompy.geom)
2846 // SMESH::SMESH_var mesh = _smeshEngine->Mesh(shape, name);
2847 // SMESH::SMESH_Hypothesis_var algo = _smeshEngine->CreateHypothesis( "HEXABLOCK_3D", "libHexaBlockEngine.so");
2848 // SMESH::SMESH_Hypothesis_var hypo = _smeshEngine->CreateHypothesis( "HEXABLOCK_Parameters", "libHexaBlockEngine.so");
2849 // HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis_var hexHypo = HEXABLOCKPlugin::HEXABLOCKPlugin_Hypothesis::_narrow(hypo);
2850 // hexHypo->SetDocument(anDocObj);
2851 // hexHypo->SetDimension(dim);
2852 // }
2853
2854 /*
2855 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
2856 {
2857   _PTR(Study) aStudy = SMESH::GetActiveStudyDocument(); //Document OCAF de l'etude active
2858   if ( CORBA::is_nil( myComponentSMESH ) )
2859     {
2860       SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
2861       if ( aStudy )
2862         aGUI.myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2863       return aGUI.myComponentSMESH;
2864     }
2865   if ( aStudy )
2866     myComponentSMESH->SetCurrentStudy(_CAST(Study,aStudy)->GetStudy());
2867   return myComponentSMESH;
2868 }*/
2869
2870  bool HEXABLOCKGUI::eventFilter(QObject *obj, QEvent *event)
2871  {
2872      if ( event->type() == QEvent::Enter ){//QEvent::Show ){ //QEvent::KeyPress) {
2873 //         showDocumentMenus( false );
2874 //         showPatternMenus( false );
2875 //         showAssociationMenus( false );
2876 //         showGroupsMenus( false );
2877 //         showMeshMenus( false );
2878 //         if ( obj == _dwObjectBrowser ) {
2879 //           showDocumentMenus( true );
2880 //         } else if ( obj == _dwPattern  ) {
2881 //           showPatternMenus( true );
2882 //         } else if ( obj == _dwAssociation ) {
2883 //           showAssociationMenus( true );
2884 //         } else if ( obj == _dwGroups ) {
2885 //           showGroupsMenus( true );
2886 //         } else if ( obj == _dwMesh ) {
2887 //
2888 //           showMeshMenus( true );
2889 //         }
2890          OCCViewer_ViewWindow* occWindow = dynamic_cast<OCCViewer_ViewWindow*>(obj);
2891          if ( occWindow != NULL )
2892          {
2893                  occWindow->setFocus();
2894          }
2895          SVTK_ViewWindow* vtkWindow = dynamic_cast<SVTK_ViewWindow*>(obj);
2896          if (vtkWindow != NULL)
2897          {
2898 //               vtkWindow->setFocus();
2899          }
2900          return true;
2901      } else {
2902           // standard event processing
2903           return QObject::eventFilter(obj, event);
2904      }
2905  }
2906
2907 // try {
2908 // //   throw SALOME_Exception(LOCALIZED("assocVertex"));
2909 //   } catch ( SALOME::SALOME_Exception& exc ){
2910 //       INFOS("Following exception was cought:\n\t"<<exc.details.text);
2911 //   } catch( const std::exception& exc){
2912 //       INFOS("Following exception was cought:\n\t"<<exc.what());
2913 //   } catch (Standard_Failure& exc) {
2914 //       MESSAGE("OCCT Exception in SMESH_Pattern: " << exc.GetMessageString());
2915 //   } catch(...){
2916 //       MESSAGE("Unknown exception was cought !!!");
2917 //   }