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.
18 #include <AIS_InteractiveContext.hxx>
19 #include <Aspect_Grid.hxx>
20 #include <Standard_Type.hxx>
21 #include <V3d_View.hxx>
22 #include <ViewerTest_EventManager.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)
91 #define IS_FULL_INCLUSION Standard_True
93 || Abs (theXPressed - theXMotion) < 2
94 || Abs (theYPressed - theYMotion) < 2)
98 else if (!myCtx.IsNull())
100 if (theIsAutoAllowOverlap)
102 if (theYPressed == Min (theYPressed, theYMotion))
104 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
108 myCtx->MainSelector()->AllowOverlapDetection (Standard_True);
111 myCtx->Select (Min (theXPressed, theXMotion),
112 Min (theYPressed, theYMotion),
113 Max (theXPressed, theXMotion),
114 Max (theYPressed, theYMotion),
118 // to restore default state of viewer selector
119 if (theIsAutoAllowOverlap)
121 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
128 //=======================================================================
129 //function : ShiftSelect
131 //=======================================================================
133 void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed,
134 const Standard_Integer theYPressed,
135 const Standard_Integer theXMotion,
136 const Standard_Integer theYMotion,
137 const Standard_Boolean theIsAutoAllowOverlap)
140 || Abs (theXPressed - theXMotion) < 2
141 || Abs (theYPressed - theYMotion) < 2)
145 else if (!myCtx.IsNull())
147 if (theIsAutoAllowOverlap)
149 if (theYPressed == Min (theYPressed, theYMotion))
151 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
155 myCtx->MainSelector()->AllowOverlapDetection (Standard_True);
158 myCtx->ShiftSelect (Min (theXPressed, theXMotion),
159 Min (theYPressed, theYMotion),
160 Max (theXPressed, theXMotion),
161 Max (theYPressed, theYMotion),
165 // to restore default state of viewer selector
166 if (theIsAutoAllowOverlap)
168 myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
174 //=======================================================================
177 //=======================================================================
179 void ViewerTest_EventManager::Select()
185 else if (!myCtx.IsNull())
187 myCtx->Select (Standard_False);
193 //=======================================================================
194 //function : ShiftSelect
196 //=======================================================================
198 void ViewerTest_EventManager::ShiftSelect()
204 else if (!myCtx.IsNull())
206 myCtx->ShiftSelect (Standard_False);
212 //=======================================================================
214 //purpose : Selection with polyline
215 //=======================================================================
217 void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
223 else if (!myCtx.IsNull())
225 myCtx->Select (thePolyline, myView, Standard_False);
231 //=======================================================================
232 //function : ShiftSelect
233 //purpose : Selection with polyline without erasing of current selection
234 //=======================================================================
236 void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
242 else if (!myCtx.IsNull())
244 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
250 void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const