Salome HOME
Porting HEXABLOCK module on WIN32 platform.
[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
34 #include "klinkitemselectionmodel.hxx"
35
36 #include <OB_Browser.h>
37 #include <SalomeApp_Module.h>
38 #include <SalomeApp_DataObject.h>
39
40 #include <LightApp_SelectionMgr.h>
41 #include <LightApp_DataModel.h>
42 #include <SOCC_Prs.h>
43 #include <SALOMEconfig.h>
44
45 #include "HEXABLOCKGUI_Resource.hxx"
46 #include "HEXABLOCKGUI_OCCSelector.h"
47 #include "hexa_base.hxx"
48
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       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 public slots:
196   bool deactivateModule( SUIT_Study* theStudy);
197   bool activateModule( SUIT_Study* theStudy);
198   void onObjectBrowserClick(const QModelIndex& index);
199
200   void showDocumentMenus(bool show);
201   void showPatternMenus(bool show);
202   void showAssociationMenus(bool show);
203   void showGroupsMenus(bool show);
204   void showMeshMenus(bool show);
205
206 protected slots:
207   void onWindowActivated( SUIT_ViewWindow* svw);
208   void onWindowClosed( SUIT_ViewWindow* svw);
209
210   virtual void                        onViewManagerAdded( SUIT_ViewManager* );
211   virtual void                        onViewManagerRemoved( SUIT_ViewManager* );
212
213   void onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
214   void showActor();
215   void hideActor();
216   void showOnlyActor();
217
218 protected:
219   bool createSComponent();
220   virtual bool eventFilter(QObject *obj, QEvent *event);
221
222   void _showDialogBox( HEXABLOCK::GUI::HexaBaseDialog* diag );
223   HEXABLOCK::GUI::HexaBaseDialog* currentDialog;
224
225   SOCC_Prs* lastOccPrs;
226   HEXABLOCK::GUI::VtkDocumentGraphicView* lastVtkDocGView;
227
228   HEXABLOCKGUI_Resource* _myresource;
229   static int _oldStudyId;
230   // static HEXABLOCK_ORB::HEXABLOCK_Gen_var _hexaEngine;  // Hexa6 TODo
231 private slots:
232
233   void slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight);
234
235   void treeContextMenu(const QPoint& aPosition);
236
237   void test_association();
238   void test();
239
240   void newDocument();
241   void loadDocument( const QString &path = QString() );
242   void saveDocument();
243
244   // new
245   void addVertex();
246   void addEdge();
247   void addQuad();
248   void addHexa();
249
250   void addVector();
251   void addCylinder();
252   void addPipe();
253   void makeGrid();
254   void makeCylinder();
255   void makePipe();
256   void makeCylinders();
257   void makePipes();
258
259   void makeHemiSphere();  // NEW HEXA3
260
261   void removeHexa();
262   void prismQuad();
263   void joinQuad();
264   void merge();
265   void disconnectElts();
266   void cutEdge();
267   void makeTransformation();
268   void makeSymmetry();
269   void performTransformation();
270   void performSymmetry();
271
272   void replaceHexa();    // NEW HEXA3
273   void quadRevolution(); // NEW HEXA3
274
275
276   void assocVertex();
277   void assocEdge();
278   void assocQuad();
279
280   void addGroup();
281   void removeGroup (); //CS_TODO
282   void addLaw();
283   void removeLaw();
284   void setPropagation();
285   void computeMesh();
286
287   //show the current model's information (nb vertex, edge, ... and more)
288   void showModelInfo();
289
290   //associate a shape to a document
291   void addShape();
292
293   //Clears associations of a single element (VERTEX, EDGE, QUAD, ...)
294   void clearAssociations();
295
296   //Clears associations under a tree (VERTEX_TREE, EDGE_TREE, ...)
297   void clearAllAssociations();
298
299   void showAssociations();
300
301 private:
302
303   QList<HEXABLOCKGUI_OCCSelector*>  myOCCSelectors;
304   QList<LightApp_VTKSelector*> myVTKSelectors;
305
306
307   QStringList getQuickDirList();
308   void clearDialogs();
309
310   SOCC_Prs* getOccPrs(HEXABLOCK::GUI::VtkDocumentGraphicView* docGView)
311   {
312       if (docGView == NULL)
313           return NULL;
314       if (!occPrs.contains(docGView))
315           occPrs[docGView] = new SOCC_Prs();
316       return occPrs[docGView];
317   }
318
319   // -------------------------------------------------------------------------------------------------
320   //          MainWindow presentation
321   // -------------------------------------------------------------------------------------------------
322   QDockWidget *_dwPattern;       // Hexablock model edition
323   QDockWidget *_dwAssociation;   // Hexablock association edition
324   QDockWidget *_dwGroups;        // Hexablock groups edition
325   QDockWidget *_dwMesh;          // Hexablock meshing edtion
326   QDockWidget *_dwObjectBrowser; // Salome study
327   QDockWidget *_dwInputPanel;    // user Input
328
329
330   // Dialog Box ( to keep persistent values )
331   HEXABLOCK::GUI::VertexDialog*                 _vertexDiag;
332   HEXABLOCK::GUI::EdgeDialog*                   _edgeDiag;
333   HEXABLOCK::GUI::QuadDialog*                   _quadDiag;
334   HEXABLOCK::GUI::HexaDialog*                   _hexaDiag;
335   HEXABLOCK::GUI::VectorDialog*                 _vectorDiag;
336   HEXABLOCK::GUI::CylinderDialog*               _cylinderDiag;
337   HEXABLOCK::GUI::PipeDialog*                   _pipeDiag;
338   HEXABLOCK::GUI::MakeGridDialog*               _makeGridDiag;
339   HEXABLOCK::GUI::MakeCylinderDialog*           _makeCylinderDiag;
340   HEXABLOCK::GUI::MakePipeDialog*               _makePipeDiag;
341   HEXABLOCK::GUI::MakeCylindersDialog*          _makeCylindersDiag;
342   HEXABLOCK::GUI::MakePipesDialog*              _makePipesDiag;
343   HEXABLOCK::GUI::RemoveHexaDialog*             _removeHexaDiag;
344   HEXABLOCK::GUI::PrismQuadDialog*              _prismQuadDiag;
345   HEXABLOCK::GUI::JoinQuadDialog*               _joinQuadDiag;
346   HEXABLOCK::GUI::MergeDialog*                  _mergeDiag;
347   HEXABLOCK::GUI::DisconnectDialog*             _disconnectDiag;
348   HEXABLOCK::GUI::CutEdgeDialog*                _cutEdgeDiag;
349   HEXABLOCK::GUI::MakeTransformationDialog*     _makeTransformationDiag;
350   HEXABLOCK::GUI::MakeSymmetryDialog*           _makeSymmetryDiag;
351   HEXABLOCK::GUI::PerformTransformationDialog*  _performTransformationDiag;
352   HEXABLOCK::GUI::PerformSymmetryDialog*        _performSymmetryDiag;
353   HEXABLOCK::GUI::VertexAssocDialog*            _vertexAssocDiag;
354   HEXABLOCK::GUI::EdgeAssocDialog*              _edgeAssocDiag;
355   HEXABLOCK::GUI::QuadAssocDialog*              _quadAssocDiag;
356   HEXABLOCK::GUI::GroupDialog*                  _groupDiag;
357   HEXABLOCK::GUI::LawDialog*                    _lawDiag;
358   HEXABLOCK::GUI::PropagationDialog*            _propagationDiag;
359   HEXABLOCK::GUI::ComputeMeshDialog*            _computeMeshDiag;
360   HEXABLOCK::GUI::ReplaceHexaDialog*            _replaceHexaDiag;
361   HEXABLOCK::GUI::QuadRevolutionDialog*         _quadRevolutionDiag;
362   HEXABLOCK::GUI::MakeHemiSphereDialog*         _makeHemiSphereDiag;
363   HEXABLOCK::GUI::ModelInfoDialog*              _modelInfoDiag;
364   HEXABLOCK::GUI::AddShapeDialog*               _addShapeDiag;
365
366
367   std::set<HEXABLOCK::GUI::HexaBaseDialog*> currentModelDialogs;
368   // Actions
369   int _menuId;
370   // Object Browser
371   QAction *_newAct;
372   QAction *_importAct;
373   QAction *_saveAct;
374   QAction *_testAct;
375
376   // Pattern Data
377   QAction *_addVertex;
378   QAction *_addEdge;
379   QAction *_addQuad;
380   QAction *_addHexa;
381
382   // Pattern Builder
383   QAction *_addVector;
384   QAction *_addCylinder;
385   QAction *_addPipe;
386   QAction *_makeGrid; //Cartesian, Cylindrical, Spherical
387   QAction *_makeCylinder;
388   QAction *_makePipe;
389   QAction *_makeCylinders;
390   QAction *_makePipes;
391
392   QAction *_makeHemiSphere; // NEW HEXA3
393
394
395   // Pattern Data Edition
396   QAction *_removeHexa;
397   QAction *_prismQuad;
398   QAction *_joinQuad;
399   QAction *_merge;//   QAction *_mergeVertices; //   QAction *_mergeEdges;
400   QAction *_disconnect;
401   QAction *_cutEdge;
402   QAction *_makeTransformation; //   QAction *_makeTranslation;
403   QAction *_makeSymmetry;
404   QAction *_performTransformation;
405   QAction *_performSymmetry;
406
407   QAction *_replaceHexa;    // NEW HEXA3
408   QAction *_quadRevolution; // NEW HEXA3
409
410   // Pattern Data Association
411   QAction *_assocVertex;
412   QAction *_assocEdge;
413   QAction *_assocQuad;
414
415   // Group
416   QAction *_addGroup;
417   QAction *_removeGroup ; //CS_TODO
418
419   // Law
420   QAction *_addLaw;
421   QAction *_removeLaw;
422
423   // Propagation
424   QAction *_setPropagation;
425
426   // Meshing
427   QAction *_computeMesh;
428
429   QAction* _showModelInfoAct;
430
431   QAction* _addShapeAct;
432
433
434   QAction* _sep1; // tmonin
435   QAction* _sep2; // tmonin
436   QAction* _sep3; // tmonin
437   QAction* _sep4; // ...... tparti
438
439   // -------------------------------------------------------------------------------------------------
440   //          Model/View implementation
441   // -------------------------------------------------------------------------------------------------
442
443   HEXABLOCK::GUI::AssociationsModel   *_associationsModel;    // sub-part of DocumentModel
444
445   //      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW
446   QTreeView* _patternDataTreeView;    //  document's pattern : 1 ( only one view )
447   QTreeView* _patternBuilderTreeView; //  document's pattern : 1 ( only one view )
448   QTreeView* _patternGeomTreeView; // the geometries' tree view
449   QTreeView* _associationTreeView;    //  document's association : 1 ( only one view )
450   QTreeView* _groupsTreeView; //  document's groups
451   QTreeView* _meshTreeView;   //  document's mesh property: 1 ( only one view )
452
453   //      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE
454   HEXABLOCK::GUI::DocumentDelegate    *_treeViewDelegate;  // specific editor for each item of the tree
455
456   HEXABLOCK::GUI::GraphicViewsHandler*  graphicViewsHandler; //vtk views hanlder (create, close, ...)
457
458   //  SALOME   SALOME    SALOME   SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME
459   QMap<QString, HEXABLOCK::GUI::VtkDocumentGraphicView*>  docs; //  key = entry
460   QMap<HEXABLOCK::GUI::VtkDocumentGraphicView*, HEXABLOCK::GUI::HexaBaseDialog*>  gViewDlgBox; //  key = entry
461   QMap<HEXABLOCK::GUI::VtkDocumentGraphicView*, SOCC_Prs*> occPrs;
462
463   bool _isSaved;
464   bool moduleActivatedOnce;
465
466   QDir* loadDocLastPath;
467   QDir* saveDocLastPath;
468
469   void testDocument();
470   void test_make_cart_grid();
471   void test_make_elmts_transform();
472
473   QString       addDocInStudy (HEXA_NS::Document* doc);  // Hexa6
474   HEXA_NS::Hex* hexa_root;                               // Hexa6
475 };
476
477 #endif