Salome HOME
Update from V7_dev
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.hxx
1 // Copyright (C) 2009-2015  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, or (at your option) any later version.
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 #ifndef _HEXABLOCKGUI_HXX_
21 #define _HEXABLOCKGUI_HXX_
22
23 #include "HEXABLOCKGUI_Export.hxx"
24
25 #include <iostream>
26 #include <map>
27 #include <set>
28
29 #include <QTreeView>
30 #include <QModelIndex>
31 #include <QDockWidget>
32
33 #include "klinkitemselectionmodel.hxx"
34
35 #include <OB_Browser.h>
36 #include <SalomeApp_Module.h>
37 #include <SalomeApp_DataObject.h>
38
39 #include <LightApp_SelectionMgr.h>
40 #include <LightApp_DataModel.h>
41 #include <SOCC_Prs.h>
42 #include <SALOMEconfig.h>
43
44 #include "HEXABLOCKGUI_Resource.hxx"
45 #include "HEXABLOCKGUI_OCCSelector.h"
46 #include "hexa_base.hxx"
47
48 class QDir;
49
50 // #include CORBA_CLIENT_HEADER(HEXABLOCK_Gen)  // Abu Juin 2013
51
52 namespace HEXABLOCK
53 {
54   namespace GUI
55   {
56     class VtkDocumentGraphicView;
57     class OccGraphicView;
58     class GraphicViewsHandler;
59 //    class DocumentDelegate;
60     class DocumentModel;
61     class PatternDataModel;
62 //    class PatternBuilderModel;
63     class AssociationsModel;
64     class GroupsModel;
65     class MeshModel;
66     class PatternDataSelectionModel;
67 //    class PatternBuilderSelectionModel;
68     class GroupsSelectionModel;
69     class MeshSelectionModel;
70
71     class HexaBaseDialog;
72     class VertexDialog;
73     class EdgeDialog;
74     class QuadDialog;
75     class HexaDialog;
76     class VectorDialog;
77     class CylinderDialog;
78     class PipeDialog;
79     class MakeGridDialog;
80     class MakeCylinderDialog;
81     class MakePipeDialog;
82     class MakeCylindersDialog;
83     class MakePipesDialog;
84     class RemoveHexaDialog;
85     class PrismQuadDialog;
86     class JoinQuadDialog;
87     class MergeDialog;
88     class DisconnectDialog;
89     class CutEdgeDialog;
90     class MakeTransformationDialog;
91     class MakeSymmetryDialog;
92     class PerformTransformationDialog;
93     class PerformSymmetryDialog;
94     typedef class MyBasicGUI_PointDlg VertexAssocDialog;
95     class EdgeAssocDialog;
96     class QuadAssocDialog;
97     class GroupDialog;
98     class LawDialog;
99     class PropagationDialog;
100     class ComputeMeshDialog;
101     class ReplaceHexaDialog;
102     class QuadRevolutionDialog;
103     class MakeHemiSphereDialog;
104     class ModelInfoDialog;
105     class AddShapeDialog;
106   }
107 }
108
109 class HEXABLOCKGUI_Resource;//SUIT_ResourceMgr;
110 class SalomeApp_Study;
111 class SalomeApp_Application;
112 class SUIT_ViewWindow;
113 class SVTK_ViewWindow;
114 class OCCViewer_ViewWindow;
115 class LightApp_VTKSelector;
116
117
118 class HEXABLOCK_EXPORT HEXABLOCKGUI : public SalomeApp_Module
119 {
120   Q_OBJECT
121
122   friend class HEXABLOCKGUI_Resource;
123
124 public:
125   HEXABLOCKGUI();
126   virtual ~HEXABLOCKGUI();
127
128   enum ViewType {
129       VTK,
130       OCC,
131       VTK_OCC,
132       UNKNOWN
133   };
134
135   static SalomeApp_Study*         activeStudy();
136
137   // static HEXABLOCK_ORB::HEXABLOCK_Gen_ptr InitHEXABLOCKGen( SalomeApp_Application* );
138   static LightApp_SelectionMgr*   selectionMgr();
139   static SALOMEDS::Study_var  ClientStudyToStudy (_PTR(Study) theStudy);
140   static ViewType getActiveViewType();
141   static HEXABLOCKGUI*  getInstance();
142
143   //add an object in the study
144   void addInStudy(QMap<QString, TopoDS_Shape>& topo_shapes,
145                          QMap<QString, QString>& docShapesEntry,
146                          QMap<QString, QString>& docShapesName);
147
148   static HEXABLOCK::GUI::VtkDocumentGraphicView* currentDocGView;
149   static HEXABLOCK::GUI::OccGraphicView* currentOccGView;
150   static bool assocInProgress;
151   static SalomeApp_Application* myApplication;
152
153   virtual void initialize( CAM_Application* app);
154
155   virtual bool renameAllowed( const QString& ) const;
156   virtual bool renameObject( const QString& entry, const QString& name);
157   virtual void windows( QMap<int, int>& theMap) const;
158   virtual QString  engineIOR() const;
159
160   virtual void viewManagers(QStringList& list) const;
161   virtual void setResource(SUIT_ResourceMgr* r);
162   virtual void createPreferences();
163   virtual void preferencesChanged( const QString& sect, const QString& name );
164   virtual void studyActivated();
165
166   ///Returns a new HEXA_NS::Document and it's entry in the study
167   std::pair <QString, HEXA_NS::Document*> newHexaDocument();
168
169   //------------------------------------
170   void createAndFillDockWidget();
171   void createActions();
172   void createMenus();
173   void createTools();
174
175   void initialMenus();
176   void showAllMenus();
177   void setAllMenusEnabled(bool enable);
178   void updateSelectors();
179
180   void switchModel(HEXABLOCK::GUI::VtkDocumentGraphicView* dgview);
181   void switchOnGraphicView(HEXABLOCK::GUI::VtkDocumentGraphicView* dgview);
182   void switchOffGraphicView(HEXABLOCK::GUI::VtkDocumentGraphicView* dgview,
183                               bool saveCurrentDlg = true);
184   void showDockWidgets(bool isVisible);
185
186   HEXABLOCK::GUI::VtkDocumentGraphicView* getCurrentVtkGraphicView() const { return currentDocGView; }
187   HEXABLOCK::GUI::VtkDocumentGraphicView* getOrCreateDocument(SalomeApp_DataObject* studyObject);
188   HEXABLOCK::GUI::VtkDocumentGraphicView* getDocGViewByEntry(const QString& entry) const
189   {
190       return ( (docs.contains(entry) ? docs[entry] : NULL ) );
191   }
192   HEXABLOCK::GUI::DocumentModel* getCurrentModel();
193   HEXABLOCK::GUI::HexaBaseDialog* getDlgBox(HEXABLOCK::GUI::VtkDocumentGraphicView* view);
194   QTreeView* getPatternDataTreeView() const { return _patternDataTreeView; }
195   QTreeView* getPatternGeomTreeView() const { return _patternGeomTreeView; }
196
197   void showVertexInfoDialog(HEXA_NS::Vertex* vertex);
198   void showEdgeInfoDialog(HEXA_NS::Edge* edge);
199   void showQuadInfoDialog(HEXA_NS::Quad* quad);
200   void showHexaInfoDialog(HEXA_NS::Hexa* hexa);
201   void showVectorInfoDialog(HEXA_NS::Vector* vector);
202   void showGroupInfoDialog(HEXA_NS::Group* group);
203   void showLawInfoDialog(HEXA_NS::Law* law);
204   void showPropagationInfoDialog(HEXA_NS::Propagation* propagation);
205
206   void showVtkActor();
207   void showOccActor();
208   void hideVtkActor();
209   void hideOccActor();
210
211 public slots:
212   bool deactivateModule( SUIT_Study* theStudy);
213   bool activateModule( SUIT_Study* theStudy);
214   void onObjectBrowserClick(const QModelIndex& index);
215
216   void showDocumentMenus(bool show);
217   void showPatternMenus(bool show);
218   void showAssociationMenus(bool show);
219   void showGroupsMenus(bool show);
220   void showMeshMenus(bool show);
221
222   void enableDocumentMenus(bool enable);
223   void enablePatternMenus(bool enable);
224   void enableAssociationMenus(bool enable);
225   void enableGroupsMenus(bool enable);
226   void enableMeshMenus(bool enable);
227
228 protected slots:
229   void onWindowActivated( SUIT_ViewWindow* svw);
230   void onWindowClosed( SUIT_ViewWindow* svw);
231
232   virtual void                        onViewManagerAdded( SUIT_ViewManager* );
233   virtual void                        onViewManagerRemoved( SUIT_ViewManager* );
234
235   void onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
236   void hideActor();
237   void showOnlyActor();
238
239 protected:
240   bool createSComponent();
241   virtual bool eventFilter(QObject *obj, QEvent *event);
242
243   void _showDialogBox( HEXABLOCK::GUI::HexaBaseDialog* diag );
244   HEXABLOCK::GUI::HexaBaseDialog* currentDialog;
245
246   SOCC_Prs* lastOccPrs;
247   HEXABLOCK::GUI::VtkDocumentGraphicView* lastVtkDocGView;
248
249   HEXABLOCKGUI_Resource* _myresource;
250   static int _oldStudyId;
251   // static HEXABLOCK_ORB::HEXABLOCK_Gen_var _hexaEngine;  // Hexa6 TODo
252 private slots:
253
254   void slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight);
255
256   void treeContextMenu(const QPoint& aPosition);
257
258   void test_association();
259   void test();
260
261   void newDocument();
262   void loadDocument( const QString &path = QString() );
263   void saveDocument();
264
265   // new
266   void addVertex();
267   void addEdge();
268   void addQuad();
269   void addHexa();
270
271   void addVector();
272 //  void addCylinder();
273 //  void addPipe();
274   void makeGrid();
275   void makeCylinder();
276   void makePipe();
277   void makeCylinders();
278   void makePipes();
279
280   void makeHemiSphere();  // NEW HEXA3
281
282   void removeHexa();
283   void prismQuad();
284   void joinQuad();
285   void merge();
286   void disconnectElts();
287   void cutEdge();
288   void makeTransformation();
289   void makeSymmetry();
290   void performTransformation();
291   void performSymmetry();
292
293   void replaceHexa();    // NEW HEXA3
294   void quadRevolution(); // NEW HEXA3
295
296
297   void assocVertex();
298   void assocEdge();
299   void assocQuad();
300
301   void addGroup();
302   void removeGroup (); //CS_TODO
303   void addLaw();
304   void removeLaw();
305   void setPropagation();
306   void computeMesh();
307
308   //show the current model's information (nb vertex, edge, ... and more)
309   void showModelInfo();
310
311   //associate a shape to a document
312   void addShape();
313
314   //Clears associations of a single element (VERTEX, EDGE, QUAD, ...)
315   void clearAssociations();
316
317   //Clears associations under a tree (VERTEX_TREE, EDGE_TREE, ...)
318   void clearAllAssociations();
319
320   void showAssociations();
321
322 private:
323
324   QList<HEXABLOCKGUI_OCCSelector*>  myOCCSelectors;
325   QList<LightApp_VTKSelector*> myVTKSelectors;
326
327
328   QStringList getQuickDirList();
329   void clearDialogs();
330
331   SOCC_Prs* getOccPrs(HEXABLOCK::GUI::VtkDocumentGraphicView* docGView)
332   {
333       if (docGView == NULL)
334           return NULL;
335       if (!occPrs.contains(docGView))
336           occPrs[docGView] = new SOCC_Prs(0);
337       return occPrs[docGView];
338   }
339
340   // -------------------------------------------------------------------------------------------------
341   //          MainWindow presentation
342   // -------------------------------------------------------------------------------------------------
343   QDockWidget *_dwPattern;       // Hexablock model edition
344   QDockWidget *_dwAssociation;   // Hexablock association edition
345   QDockWidget *_dwGroups;        // Hexablock groups edition
346   QDockWidget *_dwMesh;          // Hexablock meshing edtion
347   QDockWidget *_dwObjectBrowser; // Salome study
348   QDockWidget *_dwInputPanel;    // user Input
349
350
351   // ** Elements creation and modification Dialogs **
352
353   // Dialog Box ( to keep persistent values )
354   HEXABLOCK::GUI::VertexDialog*                 _vertexDiag;
355   HEXABLOCK::GUI::EdgeDialog*                   _edgeDiag;
356   HEXABLOCK::GUI::QuadDialog*                   _quadDiag;
357   HEXABLOCK::GUI::HexaDialog*                   _hexaDiag;
358   HEXABLOCK::GUI::VectorDialog*                 _vectorDiag;
359   HEXABLOCK::GUI::CylinderDialog*               _cylinderDiag;
360   HEXABLOCK::GUI::PipeDialog*                   _pipeDiag;
361   HEXABLOCK::GUI::MakeGridDialog*               _makeGridDiag;
362   HEXABLOCK::GUI::MakeCylinderDialog*           _makeCylinderDiag;
363   HEXABLOCK::GUI::MakePipeDialog*               _makePipeDiag;
364   HEXABLOCK::GUI::MakeCylindersDialog*          _makeCylindersDiag;
365   HEXABLOCK::GUI::MakePipesDialog*              _makePipesDiag;
366   HEXABLOCK::GUI::RemoveHexaDialog*             _removeHexaDiag;
367   HEXABLOCK::GUI::PrismQuadDialog*              _prismQuadDiag;
368   HEXABLOCK::GUI::JoinQuadDialog*               _joinQuadDiag;
369   HEXABLOCK::GUI::MergeDialog*                  _mergeDiag;
370   HEXABLOCK::GUI::DisconnectDialog*             _disconnectDiag;
371   HEXABLOCK::GUI::CutEdgeDialog*                _cutEdgeDiag;
372   HEXABLOCK::GUI::MakeTransformationDialog*     _makeTransformationDiag;
373   HEXABLOCK::GUI::MakeSymmetryDialog*           _makeSymmetryDiag;
374   HEXABLOCK::GUI::PerformTransformationDialog*  _performTransformationDiag;
375   HEXABLOCK::GUI::PerformSymmetryDialog*        _performSymmetryDiag;
376   HEXABLOCK::GUI::VertexAssocDialog*            _vertexAssocDiag;
377   HEXABLOCK::GUI::EdgeAssocDialog*              _edgeAssocDiag;
378   HEXABLOCK::GUI::QuadAssocDialog*              _quadAssocDiag;
379   HEXABLOCK::GUI::GroupDialog*                  _groupDiag;
380   HEXABLOCK::GUI::LawDialog*                    _lawDiag;
381   HEXABLOCK::GUI::PropagationDialog*            _propagationDiag;
382   HEXABLOCK::GUI::ComputeMeshDialog*            _computeMeshDiag;
383   HEXABLOCK::GUI::ReplaceHexaDialog*            _replaceHexaDiag;
384   HEXABLOCK::GUI::QuadRevolutionDialog*         _quadRevolutionDiag;
385   HEXABLOCK::GUI::MakeHemiSphereDialog*         _makeHemiSphereDiag;
386   HEXABLOCK::GUI::ModelInfoDialog*              _modelInfoDiag;
387   HEXABLOCK::GUI::AddShapeDialog*               _addShapeDiag;
388
389   // ** Elements information dialogs **
390   HEXABLOCK::GUI::VertexDialog*                 _vertexInfoDialog;
391   HEXABLOCK::GUI::EdgeDialog*                   _edgeInfoDialog;
392   HEXABLOCK::GUI::QuadDialog*                   _quadInfoDialog;
393   HEXABLOCK::GUI::HexaDialog*                   _hexaInfoDialog;
394   HEXABLOCK::GUI::VectorDialog*                 _vectorInfoDialog;
395   HEXABLOCK::GUI::GroupDialog*                  _groupInfoDialog;
396   HEXABLOCK::GUI::LawDialog*                    _lawInfoDialog;
397   HEXABLOCK::GUI::PropagationDialog*            _propagationInfoDialog;
398
399
400   std::set<HEXABLOCK::GUI::HexaBaseDialog*> currentModelDialogs;
401   // Actions
402   int _menuId;
403   // Object Browser
404   QAction *_newAct;
405   QAction *_importAct;
406   QAction *_saveAct;
407   QAction *_testAct;
408
409   // Pattern Data
410   QAction *_addVertex;
411   QAction *_addEdge;
412   QAction *_addQuad;
413   QAction *_addHexa;
414
415   // Pattern Builder
416   QAction *_addVector;
417 //  QAction *_addCylinder;
418 //  QAction *_addPipe;
419   QAction *_makeGrid; //Cartesian, Cylindrical, Spherical
420   QAction *_makeCylinder;
421   QAction *_makePipe;
422   QAction *_makeCylinders;
423   QAction *_makePipes;
424
425   QAction *_makeHemiSphere; // NEW HEXA3
426
427
428   // Pattern Data Edition
429   QAction *_removeHexa;
430   QAction *_prismQuad;
431   QAction *_joinQuad;
432   QAction *_merge;//   QAction *_mergeVertices; //   QAction *_mergeEdges;
433   QAction *_disconnect;
434   QAction *_cutEdge;
435   QAction *_makeTransformation; //   QAction *_makeTranslation;
436   QAction *_makeSymmetry;
437   QAction *_performTransformation;
438   QAction *_performSymmetry;
439
440   QAction *_replaceHexa;    // NEW HEXA3
441   QAction *_quadRevolution; // NEW HEXA3
442
443   // Pattern Data Association
444   QAction *_assocVertex;
445   QAction *_assocEdge;
446   QAction *_assocQuad;
447
448   // Group
449   QAction *_addGroup;
450   QAction *_removeGroup ; //CS_TODO
451
452   // Law
453   QAction *_addLaw;
454   QAction *_removeLaw;
455
456   // Propagation
457   QAction *_setPropagation;
458
459   // Meshing
460   QAction *_computeMesh;
461   QAction* _showModelInfoAct;
462   QAction* _addShapeAct;
463
464
465   QAction* _sep1; // tmonin
466   QAction* _sep2; // tmonin
467   QAction* _sep3; // tmonin
468   QAction* _sep4; // ...... tparti
469
470   // -------------------------------------------------------------------------------------------------
471   //          Model/View implementation
472   // -------------------------------------------------------------------------------------------------
473
474   HEXABLOCK::GUI::AssociationsModel   *_associationsModel;    // sub-part of DocumentModel
475
476   //      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW
477   QTreeView* _patternDataTreeView;    //  document's pattern : 1 ( only one view )
478 //  QTreeView* _patternBuilderTreeView; //  document's pattern : 1 ( only one view )
479   QTreeView* _patternGeomTreeView; // the geometries' tree view
480   QTreeView* _associationTreeView;    //  document's association : 1 ( only one view )
481   QTreeView* _groupsTreeView; //  document's groups
482   QTreeView* _meshTreeView;   //  document's mesh property: 1 ( only one view )
483
484   //      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE
485 //  HEXABLOCK::GUI::DocumentDelegate    *_treeViewDelegate;  // specific editor for each item of the tree
486
487   HEXABLOCK::GUI::GraphicViewsHandler*  graphicViewsHandler; //vtk views hanlder (create, close, ...)
488
489   //  SALOME   SALOME    SALOME   SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME
490   QMap<QString, HEXABLOCK::GUI::VtkDocumentGraphicView*>  docs; //  key = entry
491   QMap<HEXABLOCK::GUI::VtkDocumentGraphicView*, HEXABLOCK::GUI::HexaBaseDialog*>  gViewDlgBox; //  key = entry
492   QMap<HEXABLOCK::GUI::VtkDocumentGraphicView*, SOCC_Prs*> occPrs;
493
494   bool _isSaved;
495   bool moduleActivatedOnce;
496   bool menusEnabled;
497
498   QDir* loadDocLastPath;
499   QDir* saveDocLastPath;
500
501   void testDocument();
502   void test_make_cart_grid();
503   void test_make_elmts_transform();
504
505   QString       addDocInStudy (HEXA_NS::Document* doc);  // Hexa6
506   HEXA_NS::Hex* hexa_root;                               // Hexa6
507 };
508
509 #endif