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