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