0024637: Visualization - clean up implementation of rendering in immediate mode
[occt.git] / src / ViewerTest / ViewerTest_EventManager.cxx
CommitLineData
b311480e 1// Created on: 1998-08-27
2// Created by: Robert COUBLANC
3// Copyright (c) 1998-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <ViewerTest_EventManager.ixx>
18#include <AIS_InteractiveContext.hxx>
679ecdee 19#include <Aspect_Grid.hxx>
7fd59977 20#include <NIS_View.hxx>
21
22//=======================================================================
23//function : ViewerTest_EventManager
679ecdee 24//purpose :
7fd59977 25//=======================================================================
26
679ecdee 27ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
28 const Handle(AIS_InteractiveContext)& theCtx)
29: myCtx (theCtx),
30 myView (theView),
31 myX (-1),
32 myY (-1)
7fd59977 33{}
34
35//=======================================================================
36//function : MoveTo
679ecdee 37//purpose :
7fd59977 38//=======================================================================
39
679ecdee 40void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix,
41 const Standard_Integer theYPix)
7fd59977 42{
679ecdee 43 Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0};
44 if (!myCtx.IsNull()
45 && !myView.IsNull())
46 {
47 const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive()
48 && myView->Viewer()->GridEcho();
49 switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid))
50 {
51 case AIS_SOD_Nothing:
52 {
53 if (toEchoGrid)
54 {
55 myView->ConvertToGrid (theXPix, theYPix, aPnt3d[0], aPnt3d[1], aPnt3d[2]);
56 myView->Viewer()->ShowGridEcho (myView, Graphic3d_Vertex (aPnt3d[0], aPnt3d[1], aPnt3d[2]));
57 myView->RedrawImmediate();
58 }
59 break;
60 }
61 default:
62 {
63 if (toEchoGrid)
64 {
65 myView->Viewer()->HideGridEcho (myView);
66 myView->RedrawImmediate();
67 }
68 break;
69 }
70 }
71 }
72
73 myX = theXPix;
74 myY = theYPix;
7fd59977 75 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast(myView);
76 if (!aView.IsNull())
679ecdee 77 {
78 aView->DynamicHilight (theXPix, theYPix);
79 }
7fd59977 80}
81
82//=======================================================================
83//function : Select
679ecdee 84//purpose :
7fd59977 85//=======================================================================
86
679ecdee 87void ViewerTest_EventManager::Select (const Standard_Integer theXPMin,
88 const Standard_Integer theYPMin,
89 const Standard_Integer theXPMax,
90 const Standard_Integer theYPMax)
7fd59977 91{
679ecdee 92 #define IS_FULL_INCLUSION Standard_True
93 if (myView.IsNull())
94 {
95 return;
96 }
97 else if (!myCtx.IsNull())
98 {
99 myCtx->Select (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
100 }
101
102 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 103 if (!aView.IsNull())
679ecdee 104 {
105 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_False, IS_FULL_INCLUSION, Standard_False);
106 }
107 myView->Redraw();
7fd59977 108}
109
110//=======================================================================
111//function : ShiftSelect
679ecdee 112//purpose :
7fd59977 113//=======================================================================
114
679ecdee 115void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPMin,
116 const Standard_Integer theYPMin,
117 const Standard_Integer theXPMax,
118 const Standard_Integer theYPMax)
119{
120 if (myView.IsNull())
121 {
122 return;
123 }
124 else if (!myCtx.IsNull())
125 {
126 myCtx->AIS_InteractiveContext::ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
127 }
128 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 129 if (!aView.IsNull())
679ecdee 130 {
131 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_True, IS_FULL_INCLUSION, Standard_False);
132 }
133 myView->Redraw();
7fd59977 134}
135
136//=======================================================================
137//function : Select
679ecdee 138//purpose :
7fd59977 139//=======================================================================
140
141void ViewerTest_EventManager::Select()
142{
679ecdee 143 if (myView.IsNull())
144 {
145 return;
146 }
147 else if (!myCtx.IsNull())
148 {
149 myCtx->Select (Standard_False);
150 }
151
152 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 153 if (!aView.IsNull())
679ecdee 154 {
155 aView->Select (myX, myY, Standard_False);
156 }
157 myView->Redraw();
7fd59977 158}
159
160//=======================================================================
161//function : ShiftSelect
679ecdee 162//purpose :
7fd59977 163//=======================================================================
164
165void ViewerTest_EventManager::ShiftSelect()
166{
679ecdee 167 if (myView.IsNull())
168 {
169 return;
170 }
171 else if (!myCtx.IsNull())
172 {
173 myCtx->ShiftSelect (Standard_False);
174 }
175
176 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 177 if (!aView.IsNull())
679ecdee 178 {
179 aView->Select (myX, myY, Standard_False);
180 }
181 myView->Redraw();
7fd59977 182}
4754e164 183
184//=======================================================================
185//function : Select
186//purpose : Selection with polyline
187//=======================================================================
188
679ecdee 189void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 190{
679ecdee 191 if (myView.IsNull())
192 {
193 return;
194 }
195 else if (!myCtx.IsNull())
196 {
197 myCtx->Select (thePolyline, myView, Standard_False);
198 }
199
4754e164 200 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast(myView);
201 if (!aView.IsNull())
202 {
203 NCollection_List<gp_XY> aPolylist;
679ecdee 204 for(Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
4754e164 205 {
679ecdee 206 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
4754e164 207 }
679ecdee 208 aView->Select (aPolylist, Standard_False, Standard_False, Standard_False);
4754e164 209 }
679ecdee 210 myView->Redraw();
4754e164 211}
212
213//=======================================================================
214//function : ShiftSelect
215//purpose : Selection with polyline without erasing of current selection
216//=======================================================================
217
679ecdee 218void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 219{
679ecdee 220 if (myView.IsNull())
221 {
222 return;
223 }
224 else if (!myCtx.IsNull())
225 {
226 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
227 }
228
229 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
4754e164 230 if (!aView.IsNull())
231 {
232 NCollection_List<gp_XY> aPolylist;
679ecdee 233 for (Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
4754e164 234 {
679ecdee 235 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
4754e164 236 }
679ecdee 237 aView->Select (aPolylist, Standard_True, Standard_False, Standard_False);
4754e164 238 }
679ecdee 239 myView->Redraw();
4754e164 240}