Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI.hxx
1 // Copyright (C) 2009-2012  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
26 #include <QTreeView>
27 #include <QModelIndex>
28 #include <QDockWidget>
29
30
31 #include "klinkitemselectionmodel.hxx"
32
33 #include <OB_Browser.h>
34 #include <SalomeApp_Module.h>
35 // #include <LightApp_Module.h>
36
37 #include <LightApp_SelectionMgr.h>
38 #include <LightApp_DataModel.h>
39
40 #include <SALOMEconfig.h>
41
42
43 // #include "MyBasicGUI_PointDlg.hxx"
44 // #include "Resource.hxx"
45 #include "HEXABLOCKGUI_Resource.hxx"
46
47 #include "GEOMGUI_OCCSelector.h"
48
49
50
51
52 #include CORBA_CLIENT_HEADER(HEXABLOCK_Gen)
53 // #include CORBA_CLIENT_HEADER(GEOM_Gen)
54 // #include CORBA_CLIENT_HEADER(SMESH_Gen)
55
56
57 namespace HEXABLOCK
58 {
59   namespace GUI
60   {
61     class DocumentGraphicView;
62     class DocumentDelegate;
63     class DocumentModel;
64     class PatternDataModel;
65     class PatternBuilderModel;
66     class AssociationsModel;
67     class GroupsModel;
68     class MeshModel;
69     class PatternDataSelectionModel;
70     class PatternBuilderSelectionModel;
71     class GroupsSelectionModel;
72     class MeshSelectionModel;
73
74     class HexaBaseDialog;
75     class VertexDialog;
76     class EdgeDialog;
77     class QuadDialog;
78     class HexaDialog;
79     class VectorDialog;
80     class CylinderDialog;
81     class PipeDialog;
82     class MakeGridDialog;
83     class MakeCylinderDialog;
84     class MakePipeDialog;
85     class MakeCylindersDialog;
86     class MakePipesDialog;
87     class RemoveHexaDialog;
88     class PrismQuadDialog;
89     class JoinQuadDialog;
90     class MergeDialog;
91     class DisconnectDialog;
92     class CutEdgeDialog;
93     class MakeTransformationDialog;
94     class MakeSymmetryDialog;
95     class PerformTransformationDialog;
96     class PerformSymmetryDialog;
97     typedef class MyBasicGUI_PointDlg VertexAssocDialog;
98     class EdgeAssocDialog;
99     class QuadAssocDialog;
100     class GroupDialog;
101     class LawDialog;
102     class PropagationDialog;
103     class ComputeMeshDialog;
104     class ReplaceHexaDialog;
105     class QuadRevolutionDialog;
106     class MakeHemiSphereDialog;
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 // // SALOME KERNEL includes
119 // #include <SALOMEDS_Study.hxx>
120 // #include <SALOMEDSClient_StudyBuilder.hxx>
121 // #include <SALOMEDSClient_SComponent.hxx>
122 // #include <SALOMEDSClient_ClientFactory.hxx>
123 // #include <SALOMEDSClient_IParameters.hxx>
124
125
126 class HEXABLOCKGUI : public SalomeApp_Module
127 {
128   Q_OBJECT
129
130   friend class HEXABLOCKGUI_Resource;
131
132 public:
133   HEXABLOCKGUI();
134   virtual ~HEXABLOCKGUI();
135
136   static SalomeApp_Study*         activeStudy();
137
138   static HEXABLOCK_ORB::HEXABLOCK_Gen_ptr InitHEXABLOCKGen( SalomeApp_Application* );
139 //   static SMESH::SMESH_Gen_ptr             InitSMESHGen( SalomeApp_Application* app, const std::string& container = "FactoryServer" );
140   static GEOM::GEOM_Gen_ptr InitGEOMGen( SalomeApp_Application* app, const std::string& container = "FactoryServer" );
141
142   static LightApp_SelectionMgr*   selectionMgr();
143
144
145   static SVTK_ViewWindow*      currentVtkView;
146   static OCCViewer_ViewWindow* currentOccView;
147
148  //HEXABLOCK::GUI::DocumentModel*
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 LightApp_Displayer* displayer();
156   virtual QString  engineIOR() const;
157
158   virtual void viewManagers(QStringList& list) const;
159   virtual void setResource(SUIT_ResourceMgr* r);
160   virtual void createPreferences();
161   virtual void preferencesChanged( const QString& sect, const QString& name );
162   virtual void studyActivated();
163
164   //------------------------------------
165   void createAndFillDockWidget();
166   void createActions();
167   void createMenus();
168   void createTools();
169
170   void initialMenus();
171   void showAllMenus();
172
173 //   void showBaseMenus(bool show);
174 //   void showEditionMenus(bool show);
175 //   void showExecMenus(bool show);
176 //   void showCommonMenus(bool show);
177
178   void switchModel(SUIT_ViewWindow *view);
179   void showDockWidgets(bool isVisible);
180
181
182 public slots:
183   bool deactivateModule( SUIT_Study* theStudy);
184   bool activateModule( SUIT_Study* theStudy);
185   void onObjectBrowserClick(const QModelIndex& index);
186
187   void showDocumentMenus(bool show);
188   void showPatternMenus(bool show);
189   void showAssociationMenus(bool show);
190   void showGroupsMenus(bool show);
191   void showMeshMenus(bool show);
192   
193 protected slots:
194   void onWindowActivated( SUIT_ViewWindow* svw);
195   void onWindowClosed( SUIT_ViewWindow* svw);
196
197   virtual void                        onViewManagerAdded( SUIT_ViewManager* );
198   virtual void                        onViewManagerRemoved( SUIT_ViewManager* );
199 //   void onTryClose(bool &isClosed, QxScene_ViewWindow* window);
200
201   void onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
202
203 protected:
204 //   virtual  CAM_DataModel* createDataModel();
205   bool createSComponent();
206 //   virtual bool isSelectionCompatible();
207
208   void _showDialogBox( HEXABLOCK::GUI::HexaBaseDialog* diag );
209
210
211 //   bool _selectFromTree;
212   HEXABLOCKGUI_Resource* _myresource;
213 //   SUIT_ResourceMgr* _myresource;
214   static int _oldStudyId;
215   static HEXABLOCK_ORB::HEXABLOCK_Gen_var _hexaEngine;
216 //   static SMESH::SMESH_Gen_var             _smeshEngine;
217   static GEOM::GEOM_Gen_var               _geomEngine;
218 private slots:
219
220   void slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight);
221
222   void treeContextMenu(const QPoint& aPosition);
223
224   void test_association();
225   void test();
226
227   void newDocument();
228   void loadDocument( const QString &path = QString() );
229   void saveDocument();
230
231   // new
232   void addVertex();
233   void addEdge();
234   void addQuad();
235   void addHexa();
236
237   void addVector();
238   void addCylinder();
239   void addPipe();
240 //   void makeCartesian();
241 //   void makeCylindrical();
242   void makeGrid();
243   void makeCylinder();
244   void makePipe();
245   void makeCylinders();
246   void makePipes();
247
248 //   void makeRind();    // NEW HEXA3
249   void makeHemiSphere();  // NEW HEXA3
250
251   void removeHexa();
252   void prismQuad();
253   void joinQuad();
254 //   void mergeVertices();
255 //   void mergeEdges();
256   void merge();
257   void disconnectElts();
258   void cutEdge();
259 //   void makeTranslation();
260   void makeTransformation();
261   void makeSymmetry();
262   void performTransformation();
263   void performSymmetry();
264
265   void replaceHexa();    // NEW HEXA3
266   void quadRevolution(); // NEW HEXA3
267
268
269   void assocVertex();
270   void assocEdge();
271   void assocQuad();
272
273   void addGroup();
274   void removeGroup (); //CS_TODO
275   void addLaw();
276   void removeLaw();
277   void setPropagation();
278   void computeMesh();
279
280   //Clears associations of a single element (VERTEX, EDGE, QUAD, ...)
281   void clearAssociations();
282
283   //Clears associations under a tree (VERTEX_TREE, EDGE_TREE, ...)
284   void clearAllAssociations();
285
286   void showAssociations();
287
288 private:
289
290   QList<GEOMGUI_OCCSelector*>  myOCCSelectors;
291   QList<LightApp_VTKSelector*> myVTKSelectors;
292
293
294   QStringList getQuickDirList();
295   HEXABLOCK::GUI::DocumentGraphicView* newGraphicView();
296
297
298   // -------------------------------------------------------------------------------------------------
299   //          MainWindow presentation
300   // -------------------------------------------------------------------------------------------------
301   QDockWidget *_dwPattern;       // Hexablock model edition
302   QDockWidget *_dwAssociation;   // Hexablock association edition
303   QDockWidget *_dwGroups;        // Hexablock groups edition
304   QDockWidget *_dwMesh;          // Hexablock meshing edtion
305   QDockWidget *_dwObjectBrowser; // Salome study
306   QDockWidget *_dwInputPanel;    // user Input
307
308   // Dialog Box ( to keep persistent values )
309   HEXABLOCK::GUI::VertexDialog*                 _vertexDiag;
310   HEXABLOCK::GUI::EdgeDialog*                   _edgeDiag;
311   HEXABLOCK::GUI::QuadDialog*                   _quadDiag;
312   HEXABLOCK::GUI::HexaDialog*                   _hexaDiag;
313   HEXABLOCK::GUI::VectorDialog*                 _vectorDiag;
314   HEXABLOCK::GUI::CylinderDialog*               _cylinderDiag;
315   HEXABLOCK::GUI::PipeDialog*                   _pipeDiag;
316   HEXABLOCK::GUI::MakeGridDialog*               _makeGridDiag;
317   HEXABLOCK::GUI::MakeCylinderDialog*           _makeCylinderDiag;
318   HEXABLOCK::GUI::MakePipeDialog*               _makePipeDiag;
319   HEXABLOCK::GUI::MakeCylindersDialog*          _makeCylindersDiag;
320   HEXABLOCK::GUI::MakePipesDialog*              _makePipesDiag;
321   HEXABLOCK::GUI::RemoveHexaDialog*             _removeHexaDiag;
322   HEXABLOCK::GUI::PrismQuadDialog*              _prismQuadDiag;
323   HEXABLOCK::GUI::JoinQuadDialog*               _joinQuadDiag;
324   HEXABLOCK::GUI::MergeDialog*                  _mergeDiag;
325   HEXABLOCK::GUI::DisconnectDialog*             _disconnectDiag;
326   HEXABLOCK::GUI::CutEdgeDialog*                _cutEdgeDiag;
327   HEXABLOCK::GUI::MakeTransformationDialog*     _makeTransformationDiag;
328   HEXABLOCK::GUI::MakeSymmetryDialog*           _makeSymmetryDiag;
329   HEXABLOCK::GUI::PerformTransformationDialog*  _performTransformationDiag;
330   HEXABLOCK::GUI::PerformSymmetryDialog*        _performSymmetryDiag;
331   HEXABLOCK::GUI::VertexAssocDialog*            _vertexAssocDiag;
332   HEXABLOCK::GUI::EdgeAssocDialog*              _edgeAssocDiag;
333   HEXABLOCK::GUI::QuadAssocDialog*              _quadAssocDiag;
334   HEXABLOCK::GUI::GroupDialog*                  _groupDiag;
335   HEXABLOCK::GUI::LawDialog*                    _lawDiag;
336   HEXABLOCK::GUI::PropagationDialog*            _propagationDiag;
337   HEXABLOCK::GUI::ComputeMeshDialog*            _computeMeshDiag;
338   HEXABLOCK::GUI::ReplaceHexaDialog*            _replaceHexaDiag;
339   HEXABLOCK::GUI::QuadRevolutionDialog*         _quadRevolutionDiag;
340   HEXABLOCK::GUI::MakeHemiSphereDialog*         _makeHemiSphereDiag;
341
342
343   // Actions
344   int _menuId;
345   // Object Browser
346   QAction *_newAct;
347   QAction *_importAct;
348   QAction *_saveAct;
349   QAction *_testAct;
350
351   // Pattern Data
352   QAction *_addVertex;
353   QAction *_addEdge;
354   QAction *_addQuad;
355   QAction *_addHexa;
356
357   // Pattern Builder
358   QAction *_addVector;
359   QAction *_addCylinder;
360   QAction *_addPipe;
361   QAction *_makeGrid; //Cartesian, Cylindrical, Spherical
362   QAction *_makeCylinder;
363   QAction *_makePipe;
364   QAction *_makeCylinders;
365   QAction *_makePipes;
366
367 //   QAction *_makeRind;   // NEW HEXA3
368   QAction *_makeHemiSphere; // NEW HEXA3
369
370
371   // Pattern Data Edition
372   QAction *_removeHexa;
373   QAction *_prismQuad;
374   QAction *_joinQuad;
375   QAction *_merge;//   QAction *_mergeVertices; //   QAction *_mergeEdges;
376   QAction *_disconnect;
377   QAction *_cutEdge;
378   QAction *_makeTransformation; //   QAction *_makeTranslation;
379   QAction *_makeSymmetry;
380   QAction *_performTransformation;
381   QAction *_performSymmetry;
382
383   QAction *_replaceHexa;    // NEW HEXA3
384   QAction *_quadRevolution; // NEW HEXA3
385
386   // Pattern Data Association
387   QAction *_assocVertex;
388   QAction *_assocEdge;
389   QAction *_assocQuad;
390
391   // Group
392   QAction *_addGroup;
393   QAction *_removeGroup ; //CS_TODO
394
395   // Law
396   QAction *_addLaw;
397   QAction *_removeLaw;
398
399   // Propagation
400   QAction *_setPropagation;
401
402   // Meshing
403   QAction *_computeMesh;
404
405   // -------------------------------------------------------------------------------------------------
406   //          Model/View implementation  
407   // -------------------------------------------------------------------------------------------------
408
409   //      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL
410   HEXABLOCK::GUI::DocumentModel       *_currentModel;//  a model for each document : 1..n  ( multiple document allowed )
411   HEXABLOCK::GUI::PatternDataModel    *_patternDataModel;     // sub-part of DocumentModel
412   HEXABLOCK::GUI::PatternBuilderModel *_patternBuilderModel;  // sub-part of DocumentModel
413   HEXABLOCK::GUI::AssociationsModel   *_associationsModel;    // sub-part of DocumentModel
414   HEXABLOCK::GUI::GroupsModel         *_groupsModel;    // sub-part of DocumentModel
415   HEXABLOCK::GUI::MeshModel           *_meshModel;      // sub-part of DocumentModel
416
417   //      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW
418   QTreeView                           *_patternDataTreeView;    //  document's pattern : 1 ( only one view )
419   QTreeView                           *_patternBuilderTreeView; //  document's pattern : 1 ( only one view )
420   QTreeView                           *_associationTreeView;    //  document's association : 1 ( only one view )
421   QTreeView                           *_groupsTreeView; //  document's groups
422   QTreeView                           *_meshTreeView;   //  document's mesh property: 1 ( only one view )
423   HEXABLOCK::GUI::DocumentGraphicView *_currentGraphicView;// graphical view (SVTK view) of the document : 1..n ( multiple view )
424
425   //      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE
426   HEXABLOCK::GUI::DocumentDelegate    *_treeViewDelegate;  // specific editor for each item of the tree 
427
428   //    SELECTION_MODEL      SELECTION_MODEL      SELECTION_MODEL      SELECTION_MODEL     SELECTION_MODEL
429   HEXABLOCK::GUI::PatternDataSelectionModel    *_patternDataSelectionModel;   // 1..n   selection
430   HEXABLOCK::GUI::PatternBuilderSelectionModel *_patternBuilderSelectionModel;// 1..n   selection
431   HEXABLOCK::GUI::GroupsSelectionModel         *_groupsSelectionModel;
432   HEXABLOCK::GUI::MeshSelectionModel           *_meshSelectionModel;
433
434   //  SALOME   SALOME    SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME
435   SUIT_ViewManager *_suitVM;
436   std::map<QString, SUIT_ViewWindow*>  _salomeViewWindows; //  key = entry
437
438   // SALOME/QT    SALOME/QT  SALOME/QT    SALOME/QT   SALOME/QT    SALOME/QT  
439   std::map<SUIT_ViewWindow*, HEXABLOCK::GUI::DocumentModel*>       _documentModels;
440   std::map<SUIT_ViewWindow*, HEXABLOCK::GUI::DocumentGraphicView*> _documentView;
441
442 //   static std::map<HEXABLOCK::GUI::DocumentModel*,  SUIT_ViewWindow*> _salomeViews;
443
444 //   int _documentCnt;
445   bool _isSaved;
446
447
448   void testDocument();
449   void test_make_cart_grid();
450   void test_make_elmts_transform();
451   
452
453 };
454
455 #endif