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