Salome HOME
5fe0be383819ede7a8b7f2dfe95e8c76778ac3eb
[modules/shaper.git] / src / NewGeom / NewGeom_SalomeViewer.cpp
1
2 #include "NewGeom_SalomeViewer.h"
3 #include "NewGeom_OCCSelector.h"
4
5 #include <OCCViewer_ViewWindow.h>
6 #include <OCCViewer_ViewPort3d.h>
7
8 #include <SUIT_ViewManager.h>
9
10 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
11 : XGUI_SalomeViewer(theParent), mySelector(0)
12 {
13 }
14
15 //**********************************************
16 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
17 {
18   return mySelector->viewer()->getAISContext();
19 }
20
21 //**********************************************
22 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
23 {
24   return mySelector->viewer()->getViewer3d();
25 }
26
27 //**********************************************
28 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
29 {
30   OCCViewer_Viewer* aViewer = mySelector->viewer();
31   SUIT_ViewManager* aMgr = aViewer->getViewManager();
32   OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
33   return aWnd->getViewPort()->getView();
34 }
35
36 //**********************************************
37 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
38 {
39   if (mySelector) {
40     if (mySelector == theSel)
41       return;
42     else {
43       mySelector->viewer()->getViewManager()->disconnect(this);
44     }
45   }
46   mySelector = theSel;
47   OCCViewer_Viewer* aViewer = mySelector->viewer();
48   SUIT_ViewManager* aMgr = aViewer->getViewManager();
49
50   connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)),
51           this, SIGNAL(lastViewClosed()));
52   connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)),
53           this, SIGNAL(tryCloseView()));
54   connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)),
55           this, SIGNAL(deleteView()));
56   connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)),
57           this, SIGNAL(viewCreated()));
58   connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)),
59           this, SIGNAL(activated()));
60
61   connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
62           this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
63   connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
64           this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
65   connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)),
66           this, SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
67   connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
68           this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
69   connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
70           this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
71   connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)),
72           this, SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
73 }
74
75 //**********************************************
76 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
77 {
78   emit mousePress(theEvent);
79 }
80
81 //**********************************************
82 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
83 {
84   emit mouseRelease(theEvent);
85 }
86
87 //**********************************************
88 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
89 {
90   emit mouseDoubleClick(theEvent);
91 }
92
93 //**********************************************
94 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
95 {
96   emit mouseMove(theEvent);
97 }
98
99 //**********************************************
100 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
101 {
102   emit keyPress(theEvent);
103 }
104
105 //**********************************************
106 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
107 {
108   emit keyRelease(theEvent);
109 }
110
111 //**********************************************
112 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
113 {
114   mySelector->viewer()->enableSelection(isEnabled);
115 }
116
117 //**********************************************
118 bool NewGeom_SalomeViewer::isSelectionEnabled() const
119 {
120   return mySelector->viewer()->isSelectionEnabled();
121 }
122
123 //**********************************************
124 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
125 {
126   mySelector->viewer()->enableMultiselection(isEnable);
127 }
128
129 //**********************************************
130 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
131 {
132   return mySelector->viewer()->isMultiSelectionEnabled();
133 }