1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0030507: Visualization - introduce AIS_ViewController

ViewerTest_EventManager now inherits AIS_ViewController.
Platform-dependent user input handling within ViewerTest has been revised
to process events in common way through AIS_ViewController.
The mouse navigation has been changed, so that left mouse clicked
without modifers now rotates View.
The rubber-band selection can be activated via Alt+LeftMouseButton.
Selection is now done on mouse unclick and keyboard short-cuts take effect on unclick.

Aspect_Window::SetTitle() - added new method configuring Window title.
Introduced new types Aspect_Touch, Aspect_VKey, Aspect_ScrollDelta
for processing window events in platform-independent way.
This commit is contained in:
kgv
2019-06-10 21:03:41 +03:00
committed by bugmaster
parent 61aef3ce05
commit 49582f9dbf
40 changed files with 5791 additions and 1486 deletions

View File

@@ -8,10 +8,11 @@ ViewerTest_DoubleMapIteratorOfDoubleMapOfInteractiveAndName.hxx
ViewerTest_DoubleMapOfInteractiveAndName.hxx
ViewerTest_EventManager.cxx
ViewerTest_EventManager.hxx
ViewerTest_EventManager.lxx
ViewerTest_FilletCommands.cxx
ViewerTest_ObjectCommands.cxx
ViewerTest_OpenGlCommands.cxx
ViewerTest_RelationCommands.cxx
ViewerTest_ViewerCommands.cxx
ViewerTest_ViewerCommands_1.mm
ViewerTest_V3dView.cxx
ViewerTest_V3dView.hxx

View File

@@ -766,15 +766,7 @@ Standard_EXPORT Standard_Boolean VDisplayAISObject (const TCollection_AsciiStrin
return ViewerTest::Display (theName, theObject, Standard_True, theReplaceIfExists);
}
static TColStd_MapOfInteger theactivatedmodes(8);
static TColStd_ListOfTransient theEventMgrs;
static void VwrTst_InitEventMgr(const Handle(V3d_View)& aView,
const Handle(AIS_InteractiveContext)& Ctx)
{
theEventMgrs.Clear();
theEventMgrs.Prepend(new ViewerTest_EventManager(aView, Ctx));
}
static NCollection_List<Handle(ViewerTest_EventManager)> theEventMgrs;
static Handle(V3d_View)& a3DView()
{
@@ -831,17 +823,15 @@ void ViewerTest::UnsetEventManager()
void ViewerTest::ResetEventManager()
{
const Handle(V3d_View) aView = ViewerTest::CurrentView();
VwrTst_InitEventMgr(aView, ViewerTest::GetAISContext());
theEventMgrs.Clear();
theEventMgrs.Prepend (new ViewerTest_EventManager (ViewerTest::CurrentView(), ViewerTest::GetAISContext()));
}
Handle(ViewerTest_EventManager) ViewerTest::CurrentEventManager()
{
Handle(ViewerTest_EventManager) EM;
if(theEventMgrs.IsEmpty()) return EM;
Handle(Standard_Transient) Tr = theEventMgrs.First();
EM = Handle(ViewerTest_EventManager)::DownCast (Tr);
return EM;
return !theEventMgrs.IsEmpty()
? theEventMgrs.First()
: Handle(ViewerTest_EventManager)();
}
//=======================================================================

View File

@@ -17,9 +17,12 @@
#include <ViewerTest_EventManager.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <Aspect_Grid.hxx>
#include <Standard_Type.hxx>
#include <V3d_View.hxx>
#include <Draw.hxx>
#include <ViewerTest_V3dView.hxx>
Standard_IMPORT Standard_Boolean Draw_Interprete (const char* theCommand);
IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
@@ -31,204 +34,309 @@ ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)&
const Handle(AIS_InteractiveContext)& theCtx)
: myCtx (theCtx),
myView (theView),
myX (-1),
myY (-1)
myToPickPnt (Standard_False)
{}
//=======================================================================
//function : MoveTo
//function : UpdateMouseButtons
//purpose :
//=======================================================================
void ViewerTest_EventManager::MoveTo (const Standard_Integer theXPix,
const Standard_Integer theYPix)
bool ViewerTest_EventManager::UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
Aspect_VKeyMouse theButtons,
Aspect_VKeyFlags theModifiers,
bool theIsEmulated)
{
Standard_Real aPnt3d[3] = {0.0, 0.0, 0.0};
if (!myCtx.IsNull()
&& !myView.IsNull())
SetAllowRotation (!ViewerTest_V3dView::IsCurrentViewIn2DMode());
if (theButtons == Aspect_VKeyMouse_LeftButton)
{
const Standard_Boolean toEchoGrid = myView->Viewer()->Grid()->IsActive()
&& myView->Viewer()->GridEcho();
switch (myCtx->MoveTo (theXPix, theYPix, myView, !toEchoGrid))
if (myToPickPnt && (theModifiers & Aspect_VKeyFlags_CTRL) != 0)
{
case AIS_SOD_Nothing:
Graphic3d_Vec3d anXYZ;
myView->Convert (thePoint.x(), thePoint.y(), anXYZ.x(), anXYZ.y(), anXYZ.z());
Draw::Set (myPickPntArgVec[0].ToCString(), anXYZ.x());
Draw::Set (myPickPntArgVec[1].ToCString(), anXYZ.y());
Draw::Set (myPickPntArgVec[2].ToCString(), anXYZ.z());
myToPickPnt = false;
}
}
return AIS_ViewController::UpdateMouseButtons (thePoint, theButtons, theModifiers, theIsEmulated);
}
//==============================================================================
//function : ProcessExpose
//purpose :
//==============================================================================
void ViewerTest_EventManager::ProcessExpose()
{
if (!myView.IsNull())
{
myView->Invalidate();
FlushViewEvents (myCtx, myView, true);
}
}
//==============================================================================
//function : ProcessConfigure
//purpose :
//==============================================================================
void ViewerTest_EventManager::ProcessConfigure()
{
if (!myView.IsNull())
{
myView->MustBeResized();
FlushViewEvents (myCtx, myView, true);
}
}
//=======================================================================
//function : KeyUp
//purpose :
//=======================================================================
void ViewerTest_EventManager::KeyUp (Aspect_VKey theKey,
double theTime)
{
AIS_ViewController::KeyUp (theKey, theTime);
ProcessKeyPress (theKey);
}
//==============================================================================
//function : ProcessKeyPress
//purpose :
//==============================================================================
void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
{
if (myCtx.IsNull()
|| myView.IsNull())
{
return;
}
switch (theKey)
{
case Aspect_VKey_A: // AXO
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
if (toEchoGrid)
{
myView->ConvertToGrid (theXPix, theYPix, aPnt3d[0], aPnt3d[1], aPnt3d[2]);
myView->Viewer()->ShowGridEcho (myView, Graphic3d_Vertex (aPnt3d[0], aPnt3d[1], aPnt3d[2]));
myView->RedrawImmediate();
}
break;
myView->SetProj(V3d_XposYnegZpos);
}
default:
break;
}
case Aspect_VKey_D: // Reset
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
if (toEchoGrid)
myView->Reset();
}
break;
}
case Aspect_VKey_F:
{
if (myCtx->NbSelected() > 0)
{
myCtx->FitSelected (myView);
}
else
{
myView->FitAll();
}
break;
}
case Aspect_VKey_H: // HLR
{
std::cout << "HLR\n";
myView->SetComputedMode (!myView->ComputedMode());
myView->Redraw();
break;
}
case Aspect_VKey_P: // Type of HLR
{
myCtx->DefaultDrawer()->SetTypeOfHLR (myCtx->DefaultDrawer()->TypeOfHLR() == Prs3d_TOH_Algo
? Prs3d_TOH_PolyAlgo
: Prs3d_TOH_Algo);
if (myCtx->NbSelected() == 0)
{
AIS_ListOfInteractive aListOfShapes;
myCtx->DisplayedObjects (aListOfShapes);
for (AIS_ListIteratorOfListOfInteractive anIter (aListOfShapes); anIter.More(); anIter.Next())
{
myView->Viewer()->HideGridEcho (myView);
myView->RedrawImmediate();
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (anIter.Value()))
{
aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
? Prs3d_TOH_Algo
: Prs3d_TOH_PolyAlgo);
myCtx->Redisplay (aShape, Standard_False);
}
}
break;
}
else
{
for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
{
if (Handle(AIS_Shape) aShape = Handle(AIS_Shape)::DownCast (myCtx->SelectedInteractive()))
{
aShape->SetTypeOfHLR (aShape->TypeOfHLR() == Prs3d_TOH_PolyAlgo
? Prs3d_TOH_Algo
: Prs3d_TOH_PolyAlgo);
myCtx->Redisplay (aShape, Standard_False);
}
}
}
myCtx->UpdateCurrentViewer();
break;
}
case Aspect_VKey_S:
case Aspect_VKey_W:
{
Standard_Integer aDispMode = AIS_Shaded;
if (theKey == Aspect_VKey_S)
{
aDispMode = AIS_Shaded;
std::cout << "setup Shaded display mode\n";
}
else
{
aDispMode = AIS_WireFrame;
std::cout << "setup WireFrame display mode\n";
}
if (myCtx->NbSelected() == 0)
{
myCtx->SetDisplayMode (aDispMode, true);
}
else
{
for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
{
myCtx->SetDisplayMode (myCtx->SelectedInteractive(), aDispMode, false);
}
myCtx->UpdateCurrentViewer();
}
break;
}
case Aspect_VKey_U: // Unset display mode
{
std::cout << "reset display mode to defaults\n";
if (myCtx->NbSelected() == 0)
{
myCtx->SetDisplayMode (AIS_WireFrame, true);
}
else
{
for (myCtx->InitSelected(); myCtx->MoreSelected(); myCtx->NextSelected())
{
myCtx->UnsetDisplayMode (myCtx->SelectedInteractive(), false);
}
myCtx->UpdateCurrentViewer();
}
break;
}
case Aspect_VKey_T:
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
myView->SetProj (V3d_TypeOfOrientation_Zup_Top);
}
break;
}
case Aspect_VKey_B:
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
myView->SetProj (V3d_TypeOfOrientation_Zup_Bottom);
}
break;
}
case Aspect_VKey_L:
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
myView->SetProj (V3d_TypeOfOrientation_Zup_Left);
}
break;
}
case Aspect_VKey_R:
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
myView->SetProj (V3d_TypeOfOrientation_Zup_Right);
}
break;
}
case Aspect_VKey_Comma:
{
myCtx->HilightNextDetected (myView);
break;
}
case Aspect_VKey_Period:
{
myCtx->HilightPreviousDetected (myView);
break;
}
case Aspect_VKey_Slash:
case Aspect_VKey_NumpadDivide:
{
Handle(Graphic3d_Camera) aCamera = myView->Camera();
if (aCamera->IsStereo())
{
aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() - 0.01);
myView->Redraw();
}
break;
}
case Aspect_VKey_NumpadMultiply:
{
Handle(Graphic3d_Camera) aCamera = myView->Camera();
if (aCamera->IsStereo())
{
aCamera->SetIOD (aCamera->GetIODType(), aCamera->IOD() + 0.01);
myView->Redraw();
}
break;
}
case Aspect_VKey_Delete:
{
if (!myCtx.IsNull()
&& myCtx->NbSelected() > 0)
{
Draw_Interprete ("verase");
}
break;
}
case Aspect_VKey_Escape:
{
if (!myCtx.IsNull()
&& ViewerTest_EventManager::ToCloseViewOnEscape())
{
Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose");
}
}
}
myX = theXPix;
myY = theYPix;
}
//=======================================================================
//function : Select
//purpose :
//=======================================================================
void ViewerTest_EventManager::Select (const Standard_Integer theXPressed,
const Standard_Integer theYPressed,
const Standard_Integer theXMotion,
const Standard_Integer theYMotion,
const Standard_Boolean theIsAutoAllowOverlap)
{
if (myView.IsNull()
|| myCtx.IsNull()
|| Abs (theXPressed - theXMotion) < 2
|| Abs (theYPressed - theYMotion) < 2)
{
return;
}
if (theIsAutoAllowOverlap)
{
const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
}
myCtx->Select (Min (theXPressed, theXMotion),
Min (theYPressed, theYMotion),
Max (theXPressed, theXMotion),
Max (theYPressed, theYMotion),
myView,
Standard_False);
// to restore default state of viewer selector
if (theIsAutoAllowOverlap)
{
myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
}
myView->Redraw();
}
//=======================================================================
//function : ShiftSelect
//purpose :
//=======================================================================
void ViewerTest_EventManager::ShiftSelect (const Standard_Integer theXPressed,
const Standard_Integer theYPressed,
const Standard_Integer theXMotion,
const Standard_Integer theYMotion,
const Standard_Boolean theIsAutoAllowOverlap)
{
if (myView.IsNull()
|| myCtx.IsNull()
|| Abs (theXPressed - theXMotion) < 2
|| Abs (theYPressed - theYMotion) < 2)
{
return;
}
if (theIsAutoAllowOverlap)
{
const Standard_Boolean toAllowOverlap = theYPressed != Min (theYPressed, theYMotion);
myCtx->MainSelector()->AllowOverlapDetection (toAllowOverlap);
}
myCtx->ShiftSelect (Min (theXPressed, theXMotion),
Min (theYPressed, theYMotion),
Max (theXPressed, theXMotion),
Max (theYPressed, theYMotion),
myView,
Standard_False);
// to restore default state of viewer selector
if (theIsAutoAllowOverlap)
{
myCtx->MainSelector()->AllowOverlapDetection (Standard_False);
}
myView->Redraw();
}
//=======================================================================
//function : Select
//purpose :
//=======================================================================
void ViewerTest_EventManager::Select()
{
if (myView.IsNull()
|| myCtx.IsNull())
{
return;
}
myCtx->Select (Standard_False);
myView->Redraw();
}
//=======================================================================
//function : ShiftSelect
//purpose :
//=======================================================================
void ViewerTest_EventManager::ShiftSelect()
{
if (myView.IsNull()
|| myCtx.IsNull())
{
return;
}
myCtx->ShiftSelect (Standard_False);
myView->Redraw();
}
//=======================================================================
//function : Select
//purpose : Selection with polyline
//=======================================================================
void ViewerTest_EventManager::Select (const TColgp_Array1OfPnt2d& thePolyline)
{
if (myView.IsNull()
|| myCtx.IsNull())
{
return;
}
myCtx->Select (thePolyline, myView, Standard_False);
myView->Redraw();
}
//=======================================================================
//function : ShiftSelect
//purpose : Selection with polyline without erasing of current selection
//=======================================================================
void ViewerTest_EventManager::ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline)
{
if (myView.IsNull()
|| myCtx.IsNull())
{
return;
}
myCtx->ShiftSelect (thePolyline, myView, Standard_False);
myView->Redraw();
}
//=======================================================================
//function : GetCurrentPosition
//purpose :
//=======================================================================
void ViewerTest_EventManager::GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const
{
theXPix = myX;
theYPix = myY;
if (theKey >= Aspect_VKey_0
&& theKey <= Aspect_VKey_7)
{
const Standard_Integer aSelMode = theKey - Aspect_VKey_0;
bool toEnable = true;
if (!myCtx.IsNull())
{
AIS_ListOfInteractive aPrsList;
myCtx->DisplayedObjects (aPrsList);
for (AIS_ListOfInteractive::Iterator aPrsIter (aPrsList); aPrsIter.More() && toEnable; aPrsIter.Next())
{
TColStd_ListOfInteger aModes;
myCtx->ActivatedModes (aPrsIter.Value(), aModes);
for (TColStd_ListOfInteger::Iterator aModeIter (aModes); aModeIter.More() && toEnable; aModeIter.Next())
{
if (aModeIter.Value() == aSelMode)
{
toEnable = false;
}
}
}
}
TCollection_AsciiString aCmd = TCollection_AsciiString ("vselmode ") + aSelMode + (toEnable ? " 1" : " 0");
Draw_Interprete (aCmd.ToCString());
}
}

View File

@@ -17,76 +17,85 @@
#ifndef _ViewerTest_EventManager_HeaderFile
#define _ViewerTest_EventManager_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Boolean.hxx>
#include <AIS_ViewController.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TCollection_AsciiString.hxx>
class AIS_InteractiveContext;
class V3d_View;
class ViewerTest_EventManager;
DEFINE_STANDARD_HANDLE(ViewerTest_EventManager, Standard_Transient)
//! used to manage mouse event (move,select,shiftselect)
//! By default the events are transmitted to interactive context.
class ViewerTest_EventManager : public Standard_Transient
class ViewerTest_EventManager : public Standard_Transient, public AIS_ViewController
{
DEFINE_STANDARD_RTTIEXT(ViewerTest_EventManager, Standard_Transient)
public:
//! Return TRUE if View should be closed on escape.
static Standard_Boolean& ToCloseViewOnEscape()
{
static Standard_Boolean Draw_ToCloseViewOnEsc = Standard_False;
return Draw_ToCloseViewOnEsc;
}
//! Return TRUE if Draw Harness should exit on closing View.
static Standard_Boolean& ToExitOnCloseView()
{
static Standard_Boolean Draw_ToExitOnCloseView = Standard_False;
return Draw_ToExitOnCloseView;
}
public:
//! Main constructor.
Standard_EXPORT ViewerTest_EventManager(const Handle(V3d_View)& aView, const Handle(AIS_InteractiveContext)& aCtx);
Standard_EXPORT virtual void MoveTo (const Standard_Integer xpix, const Standard_Integer ypix);
Standard_EXPORT virtual void Select();
Standard_EXPORT virtual void ShiftSelect();
Standard_EXPORT virtual void Select (const Standard_Integer theXPressed, const Standard_Integer theYPressed, const Standard_Integer theXMotion, const Standard_Integer theYMotion, const Standard_Boolean theIsAutoAllowOverlap = Standard_True);
Standard_EXPORT virtual void ShiftSelect (const Standard_Integer theXPressed, const Standard_Integer theYPressed, const Standard_Integer theXMotion, const Standard_Integer theYMotion, const Standard_Boolean theIsAutoAllowOverlap = Standard_True);
Standard_EXPORT virtual void Select (const TColgp_Array1OfPnt2d& thePolyline);
Standard_EXPORT virtual void ShiftSelect (const TColgp_Array1OfPnt2d& thePolyline);
const Handle(AIS_InteractiveContext)& Context() const;
//! Gets current mouse position. It tracks change of mouse position
//! with mouse drugging or with DRAW command call (vmoveto).
Standard_EXPORT void GetCurrentPosition (Standard_Integer& theXPix, Standard_Integer& theYPix) const;
//! Return interactive context.
const Handle(AIS_InteractiveContext)& Context() const { return myCtx; }
//! Returns TRUE if picking point mode has been enabled (for VPick command).
Standard_Boolean ToPickPoint() const { return myToPickPnt; }
//! Start picking point for VPick command.
void StartPickPoint (const char* theArgX,
const char* theArgY,
const char* theArgZ)
{
myToPickPnt = Standard_True;
myPickPntArgVec[0] = theArgX;
myPickPntArgVec[1] = theArgY;
myPickPntArgVec[2] = theArgZ;
}
//! Handle mouse button press/release event.
Standard_EXPORT virtual bool UpdateMouseButtons (const Graphic3d_Vec2i& thePoint,
Aspect_VKeyMouse theButtons,
Aspect_VKeyFlags theModifiers,
bool theIsEmulated) Standard_OVERRIDE;
DEFINE_STANDARD_RTTIEXT(ViewerTest_EventManager,Standard_Transient)
protected:
//! Release key.
Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
double theTime) Standard_OVERRIDE;
//! Redraw the View on an Expose Event
Standard_EXPORT virtual void ProcessExpose();
//! Resize View.
Standard_EXPORT virtual void ProcessConfigure();
//! Handle KeyPress event.
Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey);
private:
Handle(AIS_InteractiveContext) myCtx;
Handle(V3d_View) myView;
Standard_Integer myX;
Standard_Integer myY;
TCollection_AsciiString myPickPntArgVec[3];
Standard_Boolean myToPickPnt;
};
#include <ViewerTest_EventManager.lxx>
#endif // _ViewerTest_EventManager_HeaderFile

View File

@@ -1,18 +0,0 @@
// Created on: 1998-08-27
// Created by: Robert COUBLANC
// Copyright (c) 1998-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline const Handle(AIS_InteractiveContext)& ViewerTest_EventManager::Context() const
{return myCtx;}

View File

@@ -159,7 +159,6 @@ extern ViewerTest_DoubleMapOfInteractiveAndName& GetMapOfAIS();
extern Standard_Boolean VDisplayAISObject (const TCollection_AsciiString& theName,
const Handle(AIS_InteractiveObject)& theAISObj,
Standard_Boolean theReplaceIfExists = Standard_True);
extern int ViewerMainLoop(Standard_Integer argc, const char** argv);
extern Handle(AIS_InteractiveContext)& TheAISContext();
namespace

View File

@@ -0,0 +1,71 @@
// Copyright (c) 2019 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <ViewerTest_V3dView.hxx>
#include <ViewerTest.hxx>
IMPLEMENT_STANDARD_RTTIEXT(ViewerTest_V3dView, V3d_View)
// =======================================================================
// function : ViewerTest_V3dView
// purpose :
// =======================================================================
ViewerTest_V3dView::ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer,
const V3d_TypeOfView theType,
bool theIs2dMode)
: V3d_View (theViewer, theType),
myIs2dMode (theIs2dMode)
{
//
}
// =======================================================================
// function : ViewerTest_V3dView
// purpose :
// =======================================================================
ViewerTest_V3dView::ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer,
const Handle(V3d_View)& theView)
: V3d_View (theViewer, theView),
myIs2dMode (false)
{
if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (theView))
{
myIs2dMode = aV3dView->IsViewIn2DMode();
}
}
// =======================================================================
// function : IsCurrentViewIn2DMode
// purpose :
// =======================================================================
bool ViewerTest_V3dView::IsCurrentViewIn2DMode()
{
if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
{
return aV3dView->IsViewIn2DMode();
}
return false;
}
// =======================================================================
// function : SetCurrentView2DMode
// purpose :
// =======================================================================
void ViewerTest_V3dView::SetCurrentView2DMode (bool theIs2d)
{
if (Handle(ViewerTest_V3dView) aV3dView = Handle(ViewerTest_V3dView)::DownCast (ViewerTest::CurrentView()))
{
aV3dView->SetView2DMode (theIs2d);
}
}

View File

@@ -0,0 +1,53 @@
// Copyright (c) 2019 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _ViewerTest_V3dView_HeaderFile
#define _ViewerTest_V3dView_HeaderFile
#include <V3d_View.hxx>
//! Setting additional flag to store 2D mode of the View to avoid scene rotation by mouse/key events
class ViewerTest_V3dView : public V3d_View
{
DEFINE_STANDARD_RTTIEXT(ViewerTest_V3dView, V3d_View)
public:
//! Initializes the view.
Standard_EXPORT ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer,
const V3d_TypeOfView theType = V3d_ORTHOGRAPHIC,
bool theIs2dMode = false);
//! Initializes the view by copying.
Standard_EXPORT ViewerTest_V3dView (const Handle(V3d_Viewer)& theViewer,
const Handle(V3d_View)& theView);
//! Returns true if 2D mode is set for the view
bool IsViewIn2DMode() const { return myIs2dMode; }
//! Sets 2D mode for the view
void SetView2DMode (bool the2dMode) { myIs2dMode = the2dMode; }
public:
//! Returns true if active view in 2D mode.
Standard_EXPORT static bool IsCurrentViewIn2DMode();
//! Set if active view in 2D mode.
Standard_EXPORT static void SetCurrentView2DMode (bool theIs2d);
private:
Standard_Boolean myIs2dMode; //!< 2D mode flag
};
#endif // _ViewerTest_V3dView_HeaderFile

File diff suppressed because it is too large Load Diff

View File

@@ -17,6 +17,7 @@
#include <Cocoa_Window.hxx>
#include <ViewerTest.hxx>
#include <ViewerTest_EventManager.hxx>
#include <V3d_View.hxx>
#include <V3d_Viewer.hxx>
#include <AIS_InteractiveContext.hxx>
@@ -39,41 +40,8 @@
extern void ActivateView (const TCollection_AsciiString& theViewName,
Standard_Boolean theToUpdate = Standard_True);
extern void VT_ProcessExpose();
extern void VT_ProcessConfigure();
extern void VT_ProcessKeyPress (const char* theBuffer);
extern void VT_ProcessMotion();
extern void VT_ProcessButton3Press();
extern void VT_ProcessButton3Release();
extern void VT_ProcessControlButton2Motion();
extern void VT_ProcessControlButton3Motion();
extern Standard_Boolean VT_ProcessButton1Press (Standard_Integer theArgsNb,
const char** theArgsVec,
Standard_Boolean theToPick,
Standard_Boolean theIsShift);
extern void VT_ProcessButton1Release(Standard_Boolean theIsShift);
extern NCollection_DoubleMap <TCollection_AsciiString, Handle(V3d_View)> ViewerTest_myViews;
extern int X_Motion; // Current cursor position
extern int Y_Motion;
extern int X_ButtonPress; // Last ButtonPress position
extern int Y_ButtonPress;
extern Standard_Boolean IsDragged;
// =======================================================================
// function : SetCocoaWindowTitle
// purpose :
// =======================================================================
void SetCocoaWindowTitle (const Handle(Cocoa_Window)& theWindow, Standard_CString theTitle)
{
NSView* aView = theWindow->HView();
NSWindow* aWindow = [aView window];
NSString* aTitleNS = [[NSString alloc] initWithUTF8String: theTitle];
[aWindow setTitle: aTitleNS];
[aTitleNS release];
}
// =======================================================================
// function : GetCocoaScreenResolution
@@ -170,20 +138,41 @@ void ViewerTest_SetCocoaEventManagerView (const Handle(Cocoa_Window)& theWindow)
[aView release];
}
// =======================================================================
// function : getMouseCoords
// purpose : Retrieve cursor position
// =======================================================================
static void getMouseCoords (NSView* theView,
NSEvent* theEvent,
Standard_Integer& theX,
Standard_Integer& theY)
//! Retrieve cursor position
static Graphic3d_Vec2i getMouseCoords (NSView* theView,
NSEvent* theEvent)
{
NSPoint aMouseLoc = [theView convertPoint: [theEvent locationInWindow] fromView: nil];
NSRect aBounds = [theView bounds];
return Graphic3d_Vec2i (Standard_Integer(aMouseLoc.x),
Standard_Integer(aBounds.size.height - aMouseLoc.y));
}
theX = Standard_Integer(aMouseLoc.x);
theY = Standard_Integer(aBounds.size.height - aMouseLoc.y);
//! Convert key flags from mouse event.
static Aspect_VKeyFlags getMouseKeyFlags (NSEvent* theEvent)
{
Aspect_VKeyFlags aFlags = Aspect_VKeyFlags_NONE;
if (([theEvent modifierFlags] & NSEventModifierFlagShift) != 0)
{
aFlags |= Aspect_VKeyFlags_SHIFT;
}
if (([theEvent modifierFlags] & NSEventModifierFlagControl) != 0)
{
aFlags |= Aspect_VKeyFlags_CTRL;
}
if (([theEvent modifierFlags] & NSEventModifierFlagOption) != 0)
{
aFlags |= Aspect_VKeyFlags_ALT;
}
if (([theEvent modifierFlags] & NSEventModifierFlagFunction) != 0)
{
//aFlags |= Aspect_VKeyFlags_FUNC;
}
if (([theEvent modifierFlags] & NSEventModifierFlagCommand) != 0)
{
//aFlags |= Aspect_VKeyFlags_CMD;
}
return aFlags;
}
@implementation ViewerTest_CocoaEventManagerView
@@ -195,7 +184,7 @@ static void getMouseCoords (NSView* theView,
- (void )setFrameSize: (NSSize )theNewSize
{
[super setFrameSize: theNewSize];
VT_ProcessConfigure();
ViewerTest::CurrentEventManager()->ProcessConfigure();
}
// =======================================================================
@@ -205,7 +194,10 @@ static void getMouseCoords (NSView* theView,
- (void )drawRect: (NSRect )theDirtyRect
{
(void )theDirtyRect;
VT_ProcessExpose();
if (!ViewerTest::CurrentEventManager().IsNull())
{
ViewerTest::CurrentEventManager()->ProcessExpose();
}
}
// =======================================================================
@@ -214,8 +206,11 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )mouseMoved: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessMotion();
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
const Aspect_VKeyMouse aButtons = ViewerTest::CurrentEventManager()->PressedMouseButtons();
ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -233,8 +228,10 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )mouseDown: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
VT_ProcessButton1Press (0, NULL, Standard_False, [theEvent modifierFlags] & NSEventModifierFlagShift);
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
ViewerTest::CurrentEventManager()->PressMouseButton (aPos, Aspect_VKeyMouse_LeftButton, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -243,23 +240,23 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )mouseUp: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessButton1Release([theEvent modifierFlags] & NSEventModifierFlagShift);
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, Aspect_VKeyMouse_LeftButton, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
// function : mouseDragged
// purpose :
// =======================================================================
- (void )mouseDragged: (NSEvent* )theEvent
{
IsDragged = Standard_True;
if ([theEvent modifierFlags] & NSEventModifierFlagControl)
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessControlButton2Motion();
}
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
const Aspect_VKeyMouse aButtons = ViewerTest::CurrentEventManager()->PressedMouseButtons();
ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -268,8 +265,10 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )rightMouseDown: (NSEvent* )theEvent
{
getMouseCoords (self, theEvent, X_ButtonPress, Y_ButtonPress);
VT_ProcessButton3Press(); // Start rotation
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
ViewerTest::CurrentEventManager()->PressMouseButton (aPos, Aspect_VKeyMouse_RightButton, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -278,8 +277,10 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )rightMouseUp: (NSEvent* )theEvent
{
(void )theEvent;
VT_ProcessButton3Release();
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
ViewerTest::CurrentEventManager()->ReleaseMouseButton (aPos, Aspect_VKeyMouse_RightButton, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -288,11 +289,11 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )rightMouseDragged: (NSEvent* )theEvent
{
if ([theEvent modifierFlags] & NSEventModifierFlagControl)
{
getMouseCoords (self, theEvent, X_Motion, Y_Motion);
VT_ProcessControlButton3Motion();
}
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
const Aspect_VKeyMouse aButtons = ViewerTest::CurrentEventManager()->PressedMouseButtons();
ViewerTest::CurrentEventManager()->UpdateMousePosition (aPos, aButtons, aFlags, false);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -301,14 +302,18 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )scrollWheel: (NSEvent* )theEvent
{
float aDelta = [theEvent deltaY];
const Graphic3d_Vec2i aPos = getMouseCoords (self, theEvent);
const Aspect_VKeyFlags aFlags = getMouseKeyFlags (theEvent);
const Standard_Real aDelta = [theEvent deltaY];
if (Abs (aDelta) < 0.001)
{
// a lot of values near zero can be generated by touchpad
return;
}
ViewerTest::CurrentView()->Zoom (0, 0, aDelta, aDelta);
ViewerTest::CurrentEventManager()->UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDelta, aFlags));
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
// =======================================================================
@@ -317,14 +322,36 @@ static void getMouseCoords (NSView* theView,
// =======================================================================
- (void )keyDown: (NSEvent* )theEvent
{
NSString* aStringNs = [theEvent characters];
if (aStringNs == NULL || [aStringNs length] == 0)
unsigned int aKeyCode = [theEvent keyCode];
const Aspect_VKey aVKey = Cocoa_Window::VirtualKeyFromNative (aKeyCode);
if (aVKey != Aspect_VKey_UNKNOWN)
{
return;
const double aTimeStamp = [theEvent timestamp];
ViewerTest::CurrentEventManager()->KeyDown (aVKey, aTimeStamp);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
const Standard_CString aString = [aStringNs UTF8String];
VT_ProcessKeyPress (aString);
//NSString* aStringNs = [theEvent characters];
//if (aStringNs != NULL && [aStringNs length] != 1)
//{
// const Standard_CString aString = [aStringNs UTF8String];
//}
}
// =======================================================================
// function : keyUp
// purpose :
// =======================================================================
- (void )keyUp: (NSEvent* )theEvent
{
unsigned int aKeyCode = [theEvent keyCode];
const Aspect_VKey aVKey = Cocoa_Window::VirtualKeyFromNative (aKeyCode);
if (aVKey != Aspect_VKey_UNKNOWN)
{
const double aTimeStamp = [theEvent timestamp];
ViewerTest::CurrentEventManager()->KeyUp (aVKey, aTimeStamp);
ViewerTest::CurrentEventManager()->FlushViewEvents (ViewerTest::GetAISContext(), ViewerTest::CurrentView(), true);
}
}
@end