0024777: Visualization - AIS_InteractiveContext::MoveTo() doesn't keep detected objec...
[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
8abada55 93 if (myView.IsNull()
94 || Abs (theXPMax - theXPMin) < 2
95 || Abs (theYPMax - theYPMin) < 2)
679ecdee 96 {
97 return;
98 }
99 else if (!myCtx.IsNull())
100 {
101 myCtx->Select (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
102 }
103
104 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 105 if (!aView.IsNull())
679ecdee 106 {
107 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_False, IS_FULL_INCLUSION, Standard_False);
108 }
109 myView->Redraw();
7fd59977 110}
111
112//=======================================================================
113//function : ShiftSelect
679ecdee 114//purpose :
7fd59977 115//=======================================================================
116
679ecdee 117void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPMin,
118 const Standard_Integer theYPMin,
119 const Standard_Integer theXPMax,
120 const Standard_Integer theYPMax)
121{
8abada55 122 if (myView.IsNull()
123 || Abs (theXPMax - theXPMin) < 2
124 || Abs (theYPMax - theYPMin) < 2)
679ecdee 125 {
126 return;
127 }
128 else if (!myCtx.IsNull())
129 {
130 myCtx->AIS_InteractiveContext::ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
131 }
132 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 133 if (!aView.IsNull())
679ecdee 134 {
135 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_True, IS_FULL_INCLUSION, Standard_False);
136 }
137 myView->Redraw();
7fd59977 138}
139
140//=======================================================================
141//function : Select
679ecdee 142//purpose :
7fd59977 143//=======================================================================
144
145void ViewerTest_EventManager::Select()
146{
679ecdee 147 if (myView.IsNull())
148 {
149 return;
150 }
151 else if (!myCtx.IsNull())
152 {
153 myCtx->Select (Standard_False);
154 }
155
156 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 157 if (!aView.IsNull())
679ecdee 158 {
159 aView->Select (myX, myY, Standard_False);
160 }
161 myView->Redraw();
7fd59977 162}
163
164//=======================================================================
165//function : ShiftSelect
679ecdee 166//purpose :
7fd59977 167//=======================================================================
168
169void ViewerTest_EventManager::ShiftSelect()
170{
679ecdee 171 if (myView.IsNull())
172 {
173 return;
174 }
175 else if (!myCtx.IsNull())
176 {
177 myCtx->ShiftSelect (Standard_False);
178 }
179
180 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
7fd59977 181 if (!aView.IsNull())
679ecdee 182 {
183 aView->Select (myX, myY, Standard_False);
184 }
185 myView->Redraw();
7fd59977 186}
4754e164 187
188//=======================================================================
189//function : Select
190//purpose : Selection with polyline
191//=======================================================================
192
679ecdee 193void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 194{
679ecdee 195 if (myView.IsNull())
196 {
197 return;
198 }
199 else if (!myCtx.IsNull())
200 {
201 myCtx->Select (thePolyline, myView, Standard_False);
202 }
203
4754e164 204 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast(myView);
205 if (!aView.IsNull())
206 {
207 NCollection_List<gp_XY> aPolylist;
679ecdee 208 for(Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
4754e164 209 {
679ecdee 210 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
4754e164 211 }
679ecdee 212 aView->Select (aPolylist, Standard_False, Standard_False, Standard_False);
4754e164 213 }
679ecdee 214 myView->Redraw();
4754e164 215}
216
217//=======================================================================
218//function : ShiftSelect
219//purpose : Selection with polyline without erasing of current selection
220//=======================================================================
221
679ecdee 222void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
4754e164 223{
679ecdee 224 if (myView.IsNull())
225 {
226 return;
227 }
228 else if (!myCtx.IsNull())
229 {
230 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
231 }
232
233 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
4754e164 234 if (!aView.IsNull())
235 {
236 NCollection_List<gp_XY> aPolylist;
679ecdee 237 for (Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
4754e164 238 {
679ecdee 239 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
4754e164 240 }
679ecdee 241 aView->Select (aPolylist, Standard_True, Standard_False, Standard_False);
4754e164 242 }
679ecdee 243 myView->Redraw();
4754e164 244}