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