Salome HOME
Merge from V6_main (04/10/2012)
[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   static bool assocInProgress;
148
149  //HEXABLOCK::GUI::DocumentModel*
150
151   virtual void initialize( CAM_Application* app);
152
153   virtual bool renameAllowed( const QString& ) const;
154   virtual bool renameObject( const QString& entry, const QString& name);
155   virtual void windows( QMap<int, int>& theMap) const;
156 //   virtual LightApp_Displayer* displayer();
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   //------------------------------------
166   void createAndFillDockWidget();
167   void createActions();
168   void createMenus();
169   void createTools();
170
171   void initialMenus();
172   void showAllMenus();
173
174 //   void showBaseMenus(bool show);
175 //   void showEditionMenus(bool show);
176 //   void showExecMenus(bool show);
177 //   void showCommonMenus(bool show);
178
179   void switchModel(SUIT_ViewWindow *view);
180   void showDockWidgets(bool isVisible);
181
182
183 public slots:
184   bool deactivateModule( SUIT_Study* theStudy);
185   bool activateModule( SUIT_Study* theStudy);
186   void onObjectBrowserClick(const QModelIndex& index);
187
188   void showDocumentMenus(bool show);
189   void showPatternMenus(bool show);
190   void showAssociationMenus(bool show);
191   void showGroupsMenus(bool show);
192   void showMeshMenus(bool show);
193   
194 protected slots:
195   void onWindowActivated( SUIT_ViewWindow* svw);
196   void onWindowClosed( SUIT_ViewWindow* svw);
197 //  void OnMouseMove( SUIT_ViewWindow*, QMouseEvent* );
198
199   virtual void                        onViewManagerAdded( SUIT_ViewManager* );
200   virtual void                        onViewManagerRemoved( SUIT_ViewManager* );
201 //   void onTryClose(bool &isClosed, QxScene_ViewWindow* window);
202
203   void onSelectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
204
205 protected:
206 //   virtual  CAM_DataModel* createDataModel();
207   bool createSComponent();
208 //   virtual bool isSelectionCompatible();
209   virtual bool eventFilter(QObject *obj, QEvent *event);
210
211   void _showDialogBox( HEXABLOCK::GUI::HexaBaseDialog* diag );
212   HEXABLOCK::GUI::HexaBaseDialog* currentDialog;
213
214 //   bool _selectFromTree;
215   HEXABLOCKGUI_Resource* _myresource;
216 //   SUIT_ResourceMgr* _myresource;
217   static int _oldStudyId;
218   static HEXABLOCK_ORB::HEXABLOCK_Gen_var _hexaEngine;
219 //   static SMESH::SMESH_Gen_var             _smeshEngine;
220   static GEOM::GEOM_Gen_var               _geomEngine;
221 private slots:
222
223   void slot_modelChanged(const QModelIndex &topLeft, const QModelIndex  &bottomRight);
224
225   void treeContextMenu(const QPoint& aPosition);
226
227   void test_association();
228   void test();
229
230   void newDocument();
231   void loadDocument( const QString &path = QString() );
232   void saveDocument();
233
234   // new
235   void addVertex();
236   void addEdge();
237   void addQuad();
238   void addHexa();
239
240   void addVector();
241   void addCylinder();
242   void addPipe();
243 //   void makeCartesian();
244 //   void makeCylindrical();
245   void makeGrid();
246   void makeCylinder();
247   void makePipe();
248   void makeCylinders();
249   void makePipes();
250
251 //   void makeRind();    // NEW HEXA3
252   void makeHemiSphere();  // NEW HEXA3
253
254   void removeHexa();
255   void prismQuad();
256   void joinQuad();
257 //   void mergeVertices();
258 //   void mergeEdges();
259   void merge();
260   void disconnectElts();
261   void cutEdge();
262 //   void makeTranslation();
263   void makeTransformation();
264   void makeSymmetry();
265   void performTransformation();
266   void performSymmetry();
267
268   void replaceHexa();    // NEW HEXA3
269   void quadRevolution(); // NEW HEXA3
270
271
272   void assocVertex();
273   void assocEdge();
274   void assocQuad();
275
276   void addGroup();
277   void removeGroup (); //CS_TODO
278   void addLaw();
279   void removeLaw();
280   void setPropagation();
281   void computeMesh();
282
283   //Clears associations of a single element (VERTEX, EDGE, QUAD, ...)
284   void clearAssociations();
285
286   //Clears associations under a tree (VERTEX_TREE, EDGE_TREE, ...)
287   void clearAllAssociations();
288
289   void showAssociations();
290
291 private:
292
293   QList<GEOMGUI_OCCSelector*>  myOCCSelectors;
294   QList<LightApp_VTKSelector*> myVTKSelectors;
295
296
297   QStringList getQuickDirList();
298   HEXABLOCK::GUI::DocumentGraphicView* newGraphicView();
299
300
301   // -------------------------------------------------------------------------------------------------
302   //          MainWindow presentation
303   // -------------------------------------------------------------------------------------------------
304   QDockWidget *_dwPattern;       // Hexablock model edition
305   QDockWidget *_dwAssociation;   // Hexablock association edition
306   QDockWidget *_dwGroups;        // Hexablock groups edition
307   QDockWidget *_dwMesh;          // Hexablock meshing edtion
308   QDockWidget *_dwObjectBrowser; // Salome study
309   QDockWidget *_dwInputPanel;    // user Input
310
311
312   // Dialog Box ( to keep persistent values )
313   HEXABLOCK::GUI::VertexDialog*                 _vertexDiag;
314   HEXABLOCK::GUI::EdgeDialog*                   _edgeDiag;
315   HEXABLOCK::GUI::QuadDialog*                   _quadDiag;
316   HEXABLOCK::GUI::HexaDialog*                   _hexaDiag;
317   HEXABLOCK::GUI::VectorDialog*                 _vectorDiag;
318   HEXABLOCK::GUI::CylinderDialog*               _cylinderDiag;
319   HEXABLOCK::GUI::PipeDialog*                   _pipeDiag;
320   HEXABLOCK::GUI::MakeGridDialog*               _makeGridDiag;
321   HEXABLOCK::GUI::MakeCylinderDialog*           _makeCylinderDiag;
322   HEXABLOCK::GUI::MakePipeDialog*               _makePipeDiag;
323   HEXABLOCK::GUI::MakeCylindersDialog*          _makeCylindersDiag;
324   HEXABLOCK::GUI::MakePipesDialog*              _makePipesDiag;
325   HEXABLOCK::GUI::RemoveHexaDialog*             _removeHexaDiag;
326   HEXABLOCK::GUI::PrismQuadDialog*              _prismQuadDiag;
327   HEXABLOCK::GUI::JoinQuadDialog*               _joinQuadDiag;
328   HEXABLOCK::GUI::MergeDialog*                  _mergeDiag;
329   HEXABLOCK::GUI::DisconnectDialog*             _disconnectDiag;
330   HEXABLOCK::GUI::CutEdgeDialog*                _cutEdgeDiag;
331   HEXABLOCK::GUI::MakeTransformationDialog*     _makeTransformationDiag;
332   HEXABLOCK::GUI::MakeSymmetryDialog*           _makeSymmetryDiag;
333   HEXABLOCK::GUI::PerformTransformationDialog*  _performTransformationDiag;
334   HEXABLOCK::GUI::PerformSymmetryDialog*        _performSymmetryDiag;
335   HEXABLOCK::GUI::VertexAssocDialog*            _vertexAssocDiag;
336   HEXABLOCK::GUI::EdgeAssocDialog*              _edgeAssocDiag;
337   HEXABLOCK::GUI::QuadAssocDialog*              _quadAssocDiag;
338   HEXABLOCK::GUI::GroupDialog*                  _groupDiag;
339   HEXABLOCK::GUI::LawDialog*                    _lawDiag;
340   HEXABLOCK::GUI::PropagationDialog*            _propagationDiag;
341   HEXABLOCK::GUI::ComputeMeshDialog*            _computeMeshDiag;
342   HEXABLOCK::GUI::ReplaceHexaDialog*            _replaceHexaDiag;
343   HEXABLOCK::GUI::QuadRevolutionDialog*         _quadRevolutionDiag;
344   HEXABLOCK::GUI::MakeHemiSphereDialog*         _makeHemiSphereDiag;
345
346
347   // Actions
348   int _menuId;
349   // Object Browser
350   QAction *_newAct;
351   QAction *_importAct;
352   QAction *_saveAct;
353   QAction *_testAct;
354
355   // Pattern Data
356   QAction *_addVertex;
357   QAction *_addEdge;
358   QAction *_addQuad;
359   QAction *_addHexa;
360
361   // Pattern Builder
362   QAction *_addVector;
363   QAction *_addCylinder;
364   QAction *_addPipe;
365   QAction *_makeGrid; //Cartesian, Cylindrical, Spherical
366   QAction *_makeCylinder;
367   QAction *_makePipe;
368   QAction *_makeCylinders;
369   QAction *_makePipes;
370
371 //   QAction *_makeRind;   // NEW HEXA3
372   QAction *_makeHemiSphere; // NEW HEXA3
373
374
375   // Pattern Data Edition
376   QAction *_removeHexa;
377   QAction *_prismQuad;
378   QAction *_joinQuad;
379   QAction *_merge;//   QAction *_mergeVertices; //   QAction *_mergeEdges;
380   QAction *_disconnect;
381   QAction *_cutEdge;
382   QAction *_makeTransformation; //   QAction *_makeTranslation;
383   QAction *_makeSymmetry;
384   QAction *_performTransformation;
385   QAction *_performSymmetry;
386
387   QAction *_replaceHexa;    // NEW HEXA3
388   QAction *_quadRevolution; // NEW HEXA3
389
390   // Pattern Data Association
391   QAction *_assocVertex;
392   QAction *_assocEdge;
393   QAction *_assocQuad;
394
395   // Group
396   QAction *_addGroup;
397   QAction *_removeGroup ; //CS_TODO
398
399   // Law
400   QAction *_addLaw;
401   QAction *_removeLaw;
402
403   // Propagation
404   QAction *_setPropagation;
405
406   // Meshing
407   QAction *_computeMesh;
408
409   // -------------------------------------------------------------------------------------------------
410   //          Model/View implementation  
411   // -------------------------------------------------------------------------------------------------
412
413   //      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL      MODEL
414   HEXABLOCK::GUI::DocumentModel       *_currentModel;//  a model for each document : 1..n  ( multiple document allowed )
415   HEXABLOCK::GUI::PatternDataModel    *_patternDataModel;     // sub-part of DocumentModel
416   HEXABLOCK::GUI::PatternBuilderModel *_patternBuilderModel;  // sub-part of DocumentModel
417   HEXABLOCK::GUI::AssociationsModel   *_associationsModel;    // sub-part of DocumentModel
418   HEXABLOCK::GUI::GroupsModel         *_groupsModel;    // sub-part of DocumentModel
419   HEXABLOCK::GUI::MeshModel           *_meshModel;      // sub-part of DocumentModel
420
421   //      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW      VIEW
422   QTreeView                           *_patternDataTreeView;    //  document's pattern : 1 ( only one view )
423   QTreeView                           *_patternBuilderTreeView; //  document's pattern : 1 ( only one view )
424   QTreeView                           *_associationTreeView;    //  document's association : 1 ( only one view )
425   QTreeView                           *_groupsTreeView; //  document's groups
426   QTreeView                           *_meshTreeView;   //  document's mesh property: 1 ( only one view )
427   HEXABLOCK::GUI::DocumentGraphicView *_currentGraphicView;// graphical view (SVTK view) of the document : 1..n ( multiple view )
428
429   //      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE      DELEGATE
430   HEXABLOCK::GUI::DocumentDelegate    *_treeViewDelegate;  // specific editor for each item of the tree 
431
432   //    SELECTION_MODEL      SELECTION_MODEL      SELECTION_MODEL      SELECTION_MODEL     SELECTION_MODEL
433   HEXABLOCK::GUI::PatternDataSelectionModel    *_patternDataSelectionModel;   // 1..n   selection
434   HEXABLOCK::GUI::PatternBuilderSelectionModel *_patternBuilderSelectionModel;// 1..n   selection
435   HEXABLOCK::GUI::GroupsSelectionModel         *_groupsSelectionModel;
436   HEXABLOCK::GUI::MeshSelectionModel           *_meshSelectionModel;
437
438   //  SALOME   SALOME    SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME     SALOME
439   SUIT_ViewManager *vtkViewManager;
440   SUIT_ViewManager *occViewManager;
441   std::map<QString, SUIT_ViewWindow*>  _salomeViewWindows; //  key = entry
442
443   // SALOME/QT    SALOME/QT  SALOME/QT    SALOME/QT   SALOME/QT    SALOME/QT  
444   std::map<SUIT_ViewWindow*, HEXABLOCK::GUI::DocumentModel*>       _documentModels;
445   std::map<SUIT_ViewWindow*, HEXABLOCK::GUI::DocumentGraphicView*> _documentView;
446   std::map<SUIT_ViewWindow*, bool> graphicViewIsEmpty;
447 //   static std::map<HEXABLOCK::GUI::DocumentModel*,  SUIT_ViewWindow*> _salomeViews;
448
449 //   int _documentCnt;
450   bool _isSaved;
451   bool moduleActivatedOnce;
452
453
454   void testDocument();
455   void test_make_cart_grid();
456   void test_make_elmts_transform();
457   
458
459 };
460
461 #endif