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