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