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