| 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 |
| 5 | // |
| 6 | // This file is part of Open CASCADE Technology software library. |
| 7 | // |
| 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. |
| 13 | // |
| 14 | // Alternatively, this file may be used under the terms of Open CASCADE |
| 15 | // commercial license or contractual agreement. |
| 16 | |
| 17 | #include <ViewerTest_EventManager.hxx> |
| 18 | |
| 19 | #include <AIS_InteractiveContext.hxx> |
| 20 | #include <AIS_Shape.hxx> |
| 21 | #include <Aspect_Grid.hxx> |
| 22 | #include <Draw.hxx> |
| 23 | #include <ViewerTest_V3dView.hxx> |
| 24 | |
| 25 | Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand); |
| 26 | |
| 27 | IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient) |
| 28 | |
| 29 | //======================================================================= |
| 30 | //function : ViewerTest_EventManager |
| 31 | //purpose : |
| 32 | //======================================================================= |
| 33 | ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)& theView, |
| 34 | const Handle(AIS_InteractiveContext)& theCtx) |
| 35 | : myCtx (theCtx), |
| 36 | myView (theView), |
| 37 | myToPickPnt (Standard_False) |
| 38 | {} |
| 39 | |
| 40 | //======================================================================= |
| 41 | //function : UpdateMouseButtons |
| 42 | //purpose : |
| 43 | //======================================================================= |
| 44 | bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint, |
| 45 | Aspect_VKeyMouse theButtons, |
| 46 | Aspect_VKeyFlags theModifiers, |
| 47 | bool theIsEmulated) |
| 48 | { |
| 49 | SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode()); |
| 50 | |
| 51 | if (theButtons == Aspect_VKeyMouse_LeftButton) |
| 52 | { |
| 53 | if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0) |
| 54 | { |
| 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; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated); |
| 65 | } |
| 66 | |
| 67 | //============================================================================== |
| 68 | //function : ProcessExpose |
| 69 | //purpose : |
| 70 | //============================================================================== |
| 71 | void ViewerTest_EventManager::ProcessExpose() |
| 72 | { |
| 73 | if (!myView.IsNull()) |
| 74 | { |
| 75 | myView->Invalidate(); |
| 76 | FlushViewEvents (myCtx, myView, true); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | //============================================================================== |
| 81 | //function : ProcessConfigure |
| 82 | //purpose : |
| 83 | //============================================================================== |
| 84 | void ViewerTest_EventManager::ProcessConfigure() |
| 85 | { |
| 86 | if (!myView.IsNull()) |
| 87 | { |
| 88 | myView->MustBeResized(); |
| 89 | FlushViewEvents (myCtx, myView, true); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | //======================================================================= |
| 94 | //function : KeyUp |
| 95 | //purpose : |
| 96 | //======================================================================= |
| 97 | void ViewerTest_EventManager::KeyUp (Aspect_VKey theKey, |
| 98 | double theTime) |
| 99 | { |
| 100 | AIS_ViewController::KeyUp (theKey, theTime); |
| 101 | ProcessKeyPress (theKey); |
| 102 | } |
| 103 | |
| 104 | //============================================================================== |
| 105 | //function : ProcessKeyPress |
| 106 | //purpose : |
| 107 | //============================================================================== |
| 108 | void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey) |
| 109 | { |
| 110 | if (myCtx.IsNull() |
| 111 | || myView.IsNull()) |
| 112 | { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | switch (theKey) |
| 117 | { |
| 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 | } |
| 203 | |
| 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 | } |
| 316 | |
| 317 | if (theKey >= Aspect_VKey_0 |
| 318 | && theKey <= Aspect_VKey_7) |
| 319 | { |
| 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()); |
| 341 | } |
| 342 | } |