0030483: Visualization, Path Tracing - make Tile Size configurable
[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
780ee4e2 17#include <ViewerTest_EventManager.hxx>
42cf5bc1 18
7fd59977 19#include <AIS_InteractiveContext.hxx>
679ecdee 20#include <Aspect_Grid.hxx>
42cf5bc1 21#include <Standard_Type.hxx>
d09dda09 22#include <V3d_View.hxx>
7fd59977 23
25e59720 24IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
92efcf78 25
7fd59977 26//=======================================================================
27//function : ViewerTest_EventManager
679ecdee 28//purpose :
7fd59977 29//=======================================================================
679ecdee 30ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
31 const Handle(AIS_InteractiveContext)& theCtx)
32: myCtx (theCtx),
33 myView (theView),
34 myX (-1),
35 myY (-1)
7fd59977 36{}
37
38//=======================================================================
39//function : MoveTo
679ecdee 40//purpose :
7fd59977 41//=======================================================================
42
679ecdee 43void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix,
44 const Standard_Integer theYPix)
7fd59977 45{
679ecdee 46 Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0};
47 if (!myCtx.IsNull()
48 && !myView.IsNull())
49 {
50 const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive()
51 && myView->Viewer()->GridEcho();
52 switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid))
53 {
54 case AIS_SOD_Nothing:
55 {
56 if (toEchoGrid)
57 {
58 myView->ConvertToGrid (theXPix, theYPix, aPnt3d[0], aPnt3d[1], aPnt3d[2]);
59 myView->Viewer()->ShowGridEcho (myView, Graphic3d_Vertex (aPnt3d[0], aPnt3d[1], aPnt3d[2]));
60 myView->RedrawImmediate();
61 }
62 break;
63 }
64 default:
65 {
66 if (toEchoGrid)
67 {
68 myView->Viewer()->HideGridEcho (myView);
69 myView->RedrawImmediate();
70 }
71 break;
72 }
73 }
74 }
75
76 myX = theXPix;
77 myY = theYPix;
7fd59977 78}
79
80//=======================================================================
81//function : Select
679ecdee 82//purpose :
7fd59977 83//=======================================================================
84
2157d6ac 85void ViewerTest_EventManager::Select (const Standard_Integer theXPressed,
86 const Standard_Integer theYPressed,
87 const Standard_Integer theXMotion,
88 const Standard_Integer theYMotion,
89 const Standard_Boolean theIsAutoAllowOverlap)
7fd59977 90{
8abada55 91 if (myView.IsNull()
780ee4e2 92 || myCtx.IsNull()
2157d6ac 93 || Abs (theXPressed - theXMotion) < 2
94 || Abs (theYPressed - theYMotion) < 2)
679ecdee 95 {
96 return;
97 }
780ee4e2 98
99 if (theIsAutoAllowOverlap)
679ecdee 100 {
780ee4e2 101 const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
102 myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
103 }
104 myCtx->Select (Min (theXPressed, theXMotion),
105 Min (theYPressed, theYMotion),
106 Max (theXPressed, theXMotion),
107 Max (theYPressed, theYMotion),
108 myView,
109 Standard_False);
110
111 // to restore default state of viewer selector
112 if (theIsAutoAllowOverlap)
113 {
114 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
679ecdee 115 }
679ecdee 116 myView->Redraw();
7fd59977 117}
118
119//=======================================================================
120//function : ShiftSelect
679ecdee 121//purpose :
7fd59977 122//=======================================================================
123
2157d6ac 124void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed,
125 const Standard_Integer theYPressed,
126 const Standard_Integer theXMotion,
127 const Standard_Integer theYMotion,
128 const Standard_Boolean theIsAutoAllowOverlap)
679ecdee 129{
8abada55 130 if (myView.IsNull()
780ee4e2 131 || myCtx.IsNull()
2157d6ac 132 || Abs (theXPressed - theXMotion) < 2
133 || Abs (theYPressed - theYMotion) < 2)
679ecdee 134 {
135 return;
136 }
780ee4e2 137
138 if (theIsAutoAllowOverlap)
679ecdee 139 {
780ee4e2 140 const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
141 myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
142 }
143 myCtx->ShiftSelect (Min (theXPressed, theXMotion),
144 Min (theYPressed, theYMotion),
145 Max (theXPressed, theXMotion),
146 Max (theYPressed, theYMotion),
147 myView,
148 Standard_False);
149
150 // to restore default state of viewer selector
151 if (theIsAutoAllowOverlap)
152 {
153 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
679ecdee 154 }
679ecdee 155 myView->Redraw();
7fd59977 156}
157
158//=======================================================================
159//function : Select
679ecdee 160//purpose :
7fd59977 161//=======================================================================
162
163void ViewerTest_EventManager::Select()
164{
780ee4e2 165 if (myView.IsNull()
166 || myCtx.IsNull())
679ecdee 167 {
168 return;
169 }
679ecdee 170
780ee4e2 171 myCtx->Select (Standard_False);
679ecdee 172 myView->Redraw();
7fd59977 173}
174
175//=======================================================================
176//function : ShiftSelect
679ecdee 177//purpose :
7fd59977 178//=======================================================================
179
180void ViewerTest_EventManager::ShiftSelect()
181{
780ee4e2 182 if (myView.IsNull()
183 || myCtx.IsNull())
679ecdee 184 {
185 return;
186 }
679ecdee 187
780ee4e2 188 myCtx->ShiftSelect (Standard_False);
679ecdee 189 myView->Redraw();
7fd59977 190}
4754e164 191
192//=======================================================================
193//function : Select
194//purpose : Selection with polyline
195//=======================================================================
196
679ecdee 197void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 198{
780ee4e2 199 if (myView.IsNull()
200 || myCtx.IsNull())
679ecdee 201 {
202 return;
203 }
679ecdee 204
780ee4e2 205 myCtx->Select (thePolyline, myView, Standard_False);
679ecdee 206 myView->Redraw();
4754e164 207}
208
209//=======================================================================
210//function : ShiftSelect
211//purpose : Selection with polyline without erasing of current selection
212//=======================================================================
213
679ecdee 214void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 215{
780ee4e2 216 if (myView.IsNull()
217 || myCtx.IsNull())
679ecdee 218 {
219 return;
220 }
679ecdee 221
780ee4e2 222 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
679ecdee 223 myView->Redraw();
4754e164 224}
c398b00e 225
780ee4e2 226//=======================================================================
227//function : GetCurrentPosition
228//purpose :
229//=======================================================================
c398b00e 230void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const
231{
232 theXPix = myX;
233 theYPix = myY;
234}