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.ixx>
18 #include <AIS_InteractiveContext.hxx>
19 #include <Aspect_Grid.hxx>
20 #include <NIS_View.hxx>
22 //=======================================================================
23 //function : ViewerTest_EventManager
25 //=======================================================================
27 ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
28 const Handle(AIS_InteractiveContext)& theCtx)
35 //=======================================================================
38 //=======================================================================
40 void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix,
41 const Standard_Integer theYPix)
43 Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0};
47 const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive()
48 && myView->Viewer()->GridEcho();
49 switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid))
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();
65 myView->Viewer()->HideGridEcho (myView);
66 myView->RedrawImmediate();
75 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast(myView);
78 aView->DynamicHilight (theXPix, theYPix);
82 //=======================================================================
85 //=======================================================================
87 void ViewerTest_EventManager::Select (const Standard_Integer theXPMin,
88 const Standard_Integer theYPMin,
89 const Standard_Integer theXPMax,
90 const Standard_Integer theYPMax)
92 #define IS_FULL_INCLUSION Standard_True
94 || Abs (theXPMax - theXPMin) < 2
95 || Abs (theYPMax - theYPMin) < 2)
99 else if (!myCtx.IsNull())
101 myCtx->Select (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
104 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
107 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_False, IS_FULL_INCLUSION, Standard_False);
112 //=======================================================================
113 //function : ShiftSelect
115 //=======================================================================
117 void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPMin,
118 const Standard_Integer theYPMin,
119 const Standard_Integer theXPMax,
120 const Standard_Integer theYPMax)
123 || Abs (theXPMax - theXPMin) < 2
124 || Abs (theYPMax - theYPMin) < 2)
128 else if (!myCtx.IsNull())
130 myCtx->AIS_InteractiveContext::ShiftSelect (theXPMin, theYPMin, theXPMax, theYPMax, myView, Standard_False);
132 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
135 aView->Select (theXPMin, theYPMin, theXPMax, theYPMax, Standard_True, IS_FULL_INCLUSION, Standard_False);
140 //=======================================================================
143 //=======================================================================
145 void ViewerTest_EventManager::Select()
151 else if (!myCtx.IsNull())
153 myCtx->Select (Standard_False);
156 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
159 aView->Select (myX, myY, Standard_False);
164 //=======================================================================
165 //function : ShiftSelect
167 //=======================================================================
169 void ViewerTest_EventManager::ShiftSelect()
175 else if (!myCtx.IsNull())
177 myCtx->ShiftSelect (Standard_False);
180 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
183 aView->Select (myX, myY, Standard_False);
188 //=======================================================================
190 //purpose : Selection with polyline
191 //=======================================================================
193 void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
199 else if (!myCtx.IsNull())
201 myCtx->Select (thePolyline, myView, Standard_False);
204 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast(myView);
207 NCollection_List<gp_XY> aPolylist;
208 for(Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
210 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
212 aView->Select (aPolylist, Standard_False, Standard_False, Standard_False);
217 //=======================================================================
218 //function : ShiftSelect
219 //purpose : Selection with polyline without erasing of current selection
220 //=======================================================================
222 void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
228 else if (!myCtx.IsNull())
230 myCtx->ShiftSelect (thePolyline, myView, Standard_False);
233 const Handle(NIS_View) aView = Handle(NIS_View)::DownCast (myView);
236 NCollection_List<gp_XY> aPolylist;
237 for (Standard_Integer anIter = thePolyline.Lower(); anIter <= thePolyline.Upper(); ++anIter)
239 aPolylist.Append (gp_XY (thePolyline.Value (anIter).X(), thePolyline.Value (anIter).Y()));
241 aView->Select (aPolylist, Standard_True, Standard_False, Standard_False);