1 // Created on: 1998-08-27
2 // Created by: Robert COUBLANC
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <ViewerTest_EventManager.hxx>
19 #include <AIS_InteractiveContext.hxx>
20 #include <Aspect_Grid.hxx>
21 #include <Standard_Type.hxx>
22 #include <V3d_View.hxx>
24 IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
26 //=======================================================================
27 //function : ViewerTest_EventManager
29 //=======================================================================
30 ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
31 const Handle(AIS_InteractiveContext)& theCtx)
38 //=======================================================================
41 //=======================================================================
43 void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix,
44 const Standard_Integer theYPix)
46 Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0};
50 const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive()
51 && myView->Viewer()->GridEcho();
52 switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid))
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();
68 myView->Viewer()->HideGridEcho (myView);
69 myView->RedrawImmediate();
80 //=======================================================================
83 //=======================================================================
85 void 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)
93 || Abs (theXPressed - theXMotion) < 2
94 || Abs (theYPressed - theYMotion) < 2)
99 if (theIsAutoAllowOverlap)
101 const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
102 myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
104 myCtx->Select (Min (theXPressed, theXMotion),
105 Min (theYPressed, theYMotion),
106 Max (theXPressed, theXMotion),
107 Max (theYPressed, theYMotion),
111 // to restore default state of viewer selector
112 if (theIsAutoAllowOverlap)
114 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
119 //=======================================================================
120 //function : ShiftSelect
122 //=======================================================================
124 void 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)
132 || Abs (theXPressed - theXMotion) < 2
133 || Abs (theYPressed - theYMotion) < 2)
138 if (theIsAutoAllowOverlap)
140 const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
141 myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
143 myCtx->ShiftSelect (Min (theXPressed, theXMotion),
144 Min (theYPressed, theYMotion),
145 Max (theXPressed, theXMotion),
146 Max (theYPressed, theYMotion),
150 // to restore default state of viewer selector
151 if (theIsAutoAllowOverlap)
153 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
158 //=======================================================================
161 //=======================================================================
163 void ViewerTest_EventManager::Select()
171 myCtx->Select (Standard_False);
175 //=======================================================================
176 //function : ShiftSelect
178 //=======================================================================
180 void ViewerTest_EventManager::ShiftSelect()
188 myCtx->ShiftSelect (Standard_False);
192 //=======================================================================
194 //purpose : Selection with polyline
195 //=======================================================================
197 void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
205 myCtx->Select (thePolyline, myView, Standard_False);
209 //=======================================================================
210 //function : ShiftSelect
211 //purpose : Selection with polyline without erasing of current selection
212 //=======================================================================
214 void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
222 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
226 //=======================================================================
227 //function : GetCurrentPosition
229 //=======================================================================
230 void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const