0030790: [REGRESSION] Modeling Algorithms - Crash when loading specific step file
[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>
49582f9d 20#include <AIS_Shape.hxx>
679ecdee 21#include <Aspect_Grid.hxx>
49582f9d 22#include <Draw.hxx>
23#include <ViewerTest_V3dView.hxx>
24
25Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
7fd59977 26
25e59720 27IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
92efcf78 28
7fd59977 29//=======================================================================
30//function : ViewerTest_EventManager
679ecdee 31//purpose :
7fd59977 32//=======================================================================
679ecdee 33ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView,
34 const Handle(AIS_InteractiveContext)& theCtx)
35: myCtx (theCtx),
36 myView (theView),
49582f9d 37 myToPickPnt (Standard_False)
7fd59977 38{}
39
40//=======================================================================
49582f9d 41//function : UpdateMouseButtons
679ecdee 42//purpose :
7fd59977 43//=======================================================================
49582f9d 44bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
45 Aspect_VKeyMouse theButtons,
46 Aspect_VKeyFlags theModifiers,
47 bool theIsEmulated)
7fd59977 48{
49582f9d 49 SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode());
50
51 if (theButtons == Aspect_VKeyMouse_LeftButton)
679ecdee 52 {
49582f9d 53 if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0)
679ecdee 54 {
49582f9d 55 Graphic3d_Vec3d anXYZ;
56 myView->Convert (thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z());
57 Draw::Set (myPickPntArgVec[0].ToCString(), anXYZ.x());
58 Draw::Set (myPickPntArgVec[1].ToCString(), anXYZ.y());
59 Draw::Set (myPickPntArgVec[2].ToCString(), anXYZ.z());
60 myToPickPnt = false;
679ecdee 61 }
62 }
63
49582f9d 64 return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated);
7fd59977 65}
66
49582f9d 67//==============================================================================
68//function : ProcessExpose
679ecdee 69//purpose :
49582f9d 70//==============================================================================
71void ViewerTest_EventManager::ProcessExpose()
7fd59977 72{
49582f9d 73 if (!myView.IsNull())
780ee4e2 74 {
49582f9d 75 myView->Invalidate();
76 FlushViewEvents (myCtx, myView, true);
679ecdee 77 }
7fd59977 78}
79
49582f9d 80//==============================================================================
81//function : ProcessConfigure
679ecdee 82//purpose :
49582f9d 83//==============================================================================
84void ViewerTest_EventManager::ProcessConfigure()
679ecdee 85{
49582f9d 86 if (!myView.IsNull())
679ecdee 87 {
49582f9d 88 myView->MustBeResized();
89 FlushViewEvents (myCtx, myView, true);
679ecdee 90 }
7fd59977 91}
92
93//=======================================================================
49582f9d 94//function : KeyUp
679ecdee 95//purpose :
7fd59977 96//=======================================================================
49582f9d 97void ViewerTest_EventManager::KeyUp (Aspect_VKey theKey,
98 double theTime)
7fd59977 99{
49582f9d 100 AIS_ViewController::KeyUp (theKey, theTime);
101 ProcessKeyPress (theKey);
7fd59977 102}
103
49582f9d 104//==============================================================================
105//function : ProcessKeyPress
679ecdee 106//purpose :
49582f9d 107//==============================================================================
108void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
7fd59977 109{
49582f9d 110 if (myCtx.IsNull()
111 || myView.IsNull())
679ecdee 112 {
113 return;
114 }
679ecdee 115
49582f9d 116 switch (theKey)
679ecdee 117 {
49582f9d 118 case Aspect_VKey_A: // AXO
119 {
120 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
121 {
122 myView->SetProj(V3d_XposYnegZpos);
123 }
124 break;
125 }
126 case Aspect_VKey_D: // Reset
127 {
128 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
129 {
130 myView->Reset();
131 }
132 break;
133 }
134 case Aspect_VKey_F:
135 {
136 if (myCtx->NbSelected() > 0)
137 {
138 myCtx->FitSelected (myView);
139 }
140 else
141 {
142 myView->FitAll();
143 }
144 break;
145 }
146 case Aspect_VKey_H: // HLR
147 {
148 std::cout << "HLR\n";
149 myView->SetComputedMode (!myView->ComputedMode());
150 myView->Redraw();
151 break;
152 }
153 case Aspect_VKey_P: // Type of HLR
154 {
155 myCtx->DefaultDrawer()->SetTypeOfHLR (myCtx->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo
156 ? Prs3d_TOH_PolyAlgo
157 : Prs3d_TOH_Algo);
158 if (myCtx->NbSelected() == 0)
159 {
160 AIS_ListOfInteractive aListOfShapes;
161 myCtx->DisplayedObjects (aListOfShapes);
162 for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
163 {
164 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()))
165 {
166 aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
167 ? Prs3d_TOH_Algo
168 : Prs3d_TOH_PolyAlgo);
169 myCtx->Redisplay (aShape, Standard_False);
170 }
171 }
172 }
173 else
174 {
175 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
176 {
177 if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (myCtx->SelectedInteractive()))
178 {
179 aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
180 ? Prs3d_TOH_Algo
181 : Prs3d_TOH_PolyAlgo);
182 myCtx->Redisplay (aShape, Standard_False);
183 }
184 }
185 }
186 myCtx->UpdateCurrentViewer();
187 break;
188 }
189 case Aspect_VKey_S:
190 case Aspect_VKey_W:
191 {
192 Standard_Integer aDispMode = AIS_Shaded;
193 if (theKey == Aspect_VKey_S)
194 {
195 aDispMode = AIS_Shaded;
196 std::cout << "setup Shaded display mode\n";
197 }
198 else
199 {
200 aDispMode = AIS_WireFrame;
201 std::cout << "setup WireFrame display mode\n";
202 }
4754e164 203
49582f9d 204 if (myCtx->NbSelected() == 0)
205 {
206 myCtx->SetDisplayMode (aDispMode, true);
207 }
208 else
209 {
210 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
211 {
212 myCtx->SetDisplayMode (myCtx->SelectedInteractive(), aDispMode, false);
213 }
214 myCtx->UpdateCurrentViewer();
215 }
216 break;
217 }
218 case Aspect_VKey_U: // Unset display mode
219 {
220 std::cout << "reset display mode to defaults\n";
221 if (myCtx->NbSelected() == 0)
222 {
223 myCtx->SetDisplayMode (AIS_WireFrame, true);
224 }
225 else
226 {
227 for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
228 {
229 myCtx->UnsetDisplayMode (myCtx->SelectedInteractive(), false);
230 }
231 myCtx->UpdateCurrentViewer();
232 }
233 break;
234 }
235 case Aspect_VKey_T:
236 {
237 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
238 {
239 myView->SetProj (V3d_TypeOfOrientation_Zup_Top);
240 }
241 break;
242 }
243 case Aspect_VKey_B:
244 {
245 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
246 {
247 myView->SetProj (V3d_TypeOfOrientation_Zup_Bottom);
248 }
249 break;
250 }
251 case Aspect_VKey_L:
252 {
253 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
254 {
255 myView->SetProj (V3d_TypeOfOrientation_Zup_Left);
256 }
257 break;
258 }
259 case Aspect_VKey_R:
260 {
261 if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
262 {
263 myView->SetProj (V3d_TypeOfOrientation_Zup_Right);
264 }
265 break;
266 }
267 case Aspect_VKey_Comma:
268 {
269 myCtx->HilightNextDetected (myView);
270 break;
271 }
272 case Aspect_VKey_Period:
273 {
274 myCtx->HilightPreviousDetected (myView);
275 break;
276 }
277 case Aspect_VKey_Slash:
278 case Aspect_VKey_NumpadDivide:
279 {
280 Handle(Graphic3d_Camera) aCamera = myView->Camera();
281 if (aCamera->IsStereo())
282 {
283 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
284 myView->Redraw();
285 }
286 break;
287 }
288 case Aspect_VKey_NumpadMultiply:
289 {
290 Handle(Graphic3d_Camera) aCamera = myView->Camera();
291 if (aCamera->IsStereo())
292 {
293 aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
294 myView->Redraw();
295 }
296 break;
297 }
298 case Aspect_VKey_Delete:
299 {
300 if (!myCtx.IsNull()
301 && myCtx->NbSelected() > 0)
302 {
303 Draw_Interprete ("verase");
304 }
305 break;
306 }
307 case Aspect_VKey_Escape:
308 {
309 if (!myCtx.IsNull()
310 && ViewerTest_EventManager::ToCloseViewOnEscape())
311 {
312 Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose");
313 }
314 }
315 }
4754e164 316
49582f9d 317 if (theKey >= Aspect_VKey_0
318 && theKey <= Aspect_VKey_7)
679ecdee 319 {
49582f9d 320 const Standard_Integer aSelMode = theKey - Aspect_VKey_0;
321 bool toEnable = true;
322 if (!myCtx.IsNull())
323 {
324 AIS_ListOfInteractive aPrsList;
325 myCtx->DisplayedObjects (aPrsList);
326 for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
327 {
328 TColStd_ListOfInteger aModes;
329 myCtx->ActivatedModes (aPrsIter.Value(), aModes);
330 for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
331 {
332 if (aModeIter.Value() == aSelMode)
333 {
334 toEnable = false;
335 }
336 }
337 }
338 }
339 TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
340 Draw_Interprete (aCmd.ToCString());
679ecdee 341 }
c398b00e 342}