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

0031621: Draw Harness - handle navigation keys

AIS_ViewController::handleNavigationKeys() - added an interface for processing navigation keys.
ViewerTest_EventManager now maps WASD+Arrows navigation keys.
Axonometric view hotkey A has been replaced by Backspace.
Shaded/Wireframe are now mapped with hotkeys W+Ctrl/S+Ctrl.
Hotkey D (reset view to undefined default state) has been removed.
This commit is contained in:
kgv
2020-06-20 14:57:02 +03:00
committed by bugmaster
parent 2ff1d580f1
commit d22962e4e0
6 changed files with 304 additions and 18 deletions

View File

@@ -50,6 +50,28 @@ ViewerTest_EventManager::ViewerTest_EventManager (const Handle(V3d_View)&
myIsTmpContRedraw (Standard_False)
{
myViewAnimation = GlobalViewAnimation();
addActionHotKeys (Aspect_VKey_NavForward, Aspect_VKey_W, Aspect_VKey_W | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavBackward , Aspect_VKey_S, Aspect_VKey_S | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSlideLeft, Aspect_VKey_A, Aspect_VKey_A | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSlideRight, Aspect_VKey_D, Aspect_VKey_D | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavRollCCW, Aspect_VKey_Q, Aspect_VKey_Q | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavRollCW, Aspect_VKey_E, Aspect_VKey_E | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSpeedIncrease, Aspect_VKey_Plus, Aspect_VKey_Plus | Aspect_VKeyFlags_SHIFT,
Aspect_VKey_Equal,
Aspect_VKey_NumpadAdd, Aspect_VKey_NumpadAdd | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSpeedDecrease, Aspect_VKey_Minus, Aspect_VKey_Minus | Aspect_VKeyFlags_SHIFT,
Aspect_VKey_NumpadSubtract, Aspect_VKey_NumpadSubtract | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavLookUp, Aspect_VKey_Up);
addActionHotKeys (Aspect_VKey_NavLookDown, Aspect_VKey_Down);
addActionHotKeys (Aspect_VKey_NavLookLeft, Aspect_VKey_Left);
addActionHotKeys (Aspect_VKey_NavLookRight, Aspect_VKey_Right);
addActionHotKeys (Aspect_VKey_NavSlideLeft, Aspect_VKey_Left | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSlideRight, Aspect_VKey_Right | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSlideUp, Aspect_VKey_Up | Aspect_VKeyFlags_SHIFT);
addActionHotKeys (Aspect_VKey_NavSlideDown, Aspect_VKey_Down | Aspect_VKeyFlags_SHIFT);
}
//=======================================================================
@@ -153,6 +175,69 @@ void ViewerTest_EventManager::ProcessConfigure()
}
}
// =======================================================================
// function : navigationKeyModifierSwitch
// purpose :
// =======================================================================
bool ViewerTest_EventManager::navigationKeyModifierSwitch (unsigned int theModifOld,
unsigned int theModifNew,
double theTimeStamp)
{
bool hasActions = false;
for (unsigned int aKeyIter = 0; aKeyIter < Aspect_VKey_ModifiersLower; ++aKeyIter)
{
if (!myKeys.IsKeyDown (aKeyIter))
{
continue;
}
Aspect_VKey anActionOld = Aspect_VKey_UNKNOWN, anActionNew = Aspect_VKey_UNKNOWN;
myNavKeyMap.Find (aKeyIter | theModifOld, anActionOld);
myNavKeyMap.Find (aKeyIter | theModifNew, anActionNew);
if (anActionOld == anActionNew)
{
continue;
}
if (anActionOld != Aspect_VKey_UNKNOWN)
{
myKeys.KeyUp (anActionOld, theTimeStamp);
}
if (anActionNew != Aspect_VKey_UNKNOWN)
{
hasActions = true;
myKeys.KeyDown (anActionNew, theTimeStamp);
}
}
return hasActions;
}
//=======================================================================
//function : KeyDown
//purpose :
//=======================================================================
void ViewerTest_EventManager::KeyDown (Aspect_VKey theKey,
double theTime,
double thePressure)
{
const unsigned int aModifOld = myKeys.Modifiers();
AIS_ViewController::KeyDown (theKey, theTime, thePressure);
const unsigned int aModifNew = myKeys.Modifiers();
if (aModifNew != aModifOld
&& navigationKeyModifierSwitch (aModifOld, aModifNew, theTime))
{
// modifier key just pressed
}
Aspect_VKey anAction = Aspect_VKey_UNKNOWN;
if (myNavKeyMap.Find (theKey | myKeys.Modifiers(), anAction)
&& anAction != Aspect_VKey_UNKNOWN)
{
AIS_ViewController::KeyDown (anAction, theTime, thePressure);
}
}
//=======================================================================
//function : KeyUp
//purpose :
@@ -160,8 +245,25 @@ void ViewerTest_EventManager::ProcessConfigure()
void ViewerTest_EventManager::KeyUp (Aspect_VKey theKey,
double theTime)
{
const unsigned int aModifOld = myKeys.Modifiers();
AIS_ViewController::KeyUp (theKey, theTime);
ProcessKeyPress (theKey);
Aspect_VKey anAction = Aspect_VKey_UNKNOWN;
if (myNavKeyMap.Find (theKey | myKeys.Modifiers(), anAction)
&& anAction != Aspect_VKey_UNKNOWN)
{
AIS_ViewController::KeyUp (anAction, theTime);
ProcessKeyPress (anAction);
}
const unsigned int aModifNew = myKeys.Modifiers();
if (aModifNew != aModifOld
&& navigationKeyModifierSwitch (aModifOld, aModifNew, theTime))
{
// modifier key released
}
ProcessKeyPress (theKey | aModifNew);
}
//==============================================================================
@@ -178,7 +280,7 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
switch (theKey)
{
case Aspect_VKey_A: // AXO
case Aspect_VKey_Backspace: // AXO
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
@@ -186,14 +288,6 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
}
break;
}
case Aspect_VKey_D: // Reset
{
if (!ViewerTest_V3dView::IsCurrentViewIn2DMode())
{
myView->Reset();
}
break;
}
case Aspect_VKey_F:
{
if (myCtx->NbSelected() > 0)
@@ -249,11 +343,11 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
myCtx->UpdateCurrentViewer();
break;
}
case Aspect_VKey_S:
case Aspect_VKey_W:
case Aspect_VKey_S | Aspect_VKeyFlags_CTRL:
case Aspect_VKey_W | Aspect_VKeyFlags_CTRL:
{
Standard_Integer aDispMode = AIS_Shaded;
if (theKey == Aspect_VKey_S)
if (theKey == (Aspect_VKey_S | Aspect_VKeyFlags_CTRL))
{
aDispMode = AIS_Shaded;
std::cout << "setup Shaded display mode\n";
@@ -374,6 +468,25 @@ void ViewerTest_EventManager::ProcessKeyPress (Aspect_VKey theKey)
{
Draw_Interprete (ViewerTest_EventManager::ToExitOnCloseView() ? "exit" : "vclose");
}
break;
}
case Aspect_VKey_NavSpeedDecrease:
case Aspect_VKey_NavSpeedIncrease:
{
// handle slide speed
float aNewSpeed = theKey == Aspect_VKey_NavSpeedDecrease
? myWalkSpeedRelative * 0.5f
: myWalkSpeedRelative * 2.0f;
if (aNewSpeed >= 0.00001f
&& aNewSpeed <= 10.0f)
{
if (Abs (aNewSpeed - 0.1f) < 0.001f)
{
aNewSpeed = 0.1f;
}
myWalkSpeedRelative = aNewSpeed;
}
break;
}
}

View File

@@ -81,6 +81,11 @@ public:
Aspect_VKeyFlags theModifiers,
bool theIsEmulated) Standard_OVERRIDE;
//! Release key.
Standard_EXPORT virtual void KeyDown (Aspect_VKey theKey,
double theTime,
double thePressure = 1.0) Standard_OVERRIDE;
//! Release key.
Standard_EXPORT virtual void KeyUp (Aspect_VKey theKey,
double theTime) Standard_OVERRIDE;
@@ -98,10 +103,33 @@ public:
//! Handle KeyPress event.
Standard_EXPORT void ProcessKeyPress (Aspect_VKey theKey);
protected:
//! Register hot-keys for specified Action.
void addActionHotKeys (Aspect_VKey theAction,
unsigned int theHotKey1 = 0,
unsigned int theHotKey2 = 0,
unsigned int theHotKey3 = 0,
unsigned int theHotKey4 = 0,
unsigned int theHotKey5 = 0)
{
if (theHotKey1 != 0) { myNavKeyMap.Bind (theHotKey1, theAction); }
if (theHotKey2 != 0) { myNavKeyMap.Bind (theHotKey2, theAction); }
if (theHotKey3 != 0) { myNavKeyMap.Bind (theHotKey3, theAction); }
if (theHotKey4 != 0) { myNavKeyMap.Bind (theHotKey4, theAction); }
if (theHotKey5 != 0) { myNavKeyMap.Bind (theHotKey5, theAction); }
}
//! Handle modifier key changes.
Standard_EXPORT bool navigationKeyModifierSwitch (unsigned int theModifOld,
unsigned int theModifNew,
double theTimeStamp);
private:
Handle(AIS_InteractiveContext) myCtx;
Handle(V3d_View) myView;
NCollection_DataMap<unsigned int, Aspect_VKey> myNavKeyMap; //!< map of Hot-Key (key+modifiers) to Action
TCollection_AsciiString myPickPntArgVec[3];
Standard_Boolean myToPickPnt;

View File

@@ -3021,12 +3021,19 @@ static int VHelp(Draw_Interpretor& di, Standard_Integer , const char** )
di << "B : BottomView\n";
di << "R : RightView\n";
di << "L : LeftView\n";
di << "A : AxonometricView\n";
di << "D : ResetView\n";
di << "Backspace : AxonometricView\n";
di << "=========================\n";
di << "S : Shading\n";
di << "W : Wireframe\n";
di << "W, S : Fly forward/backward\n";
di << "A, D : Slide left/right\n";
di << "Q, E : Bank left/right\n";
di << "-, + : Change flying speed\n";
di << "Arrows : look left/right/up/down\n";
di << "Arrows+Shift : slide left/right/up/down\n";
di << "=========================\n";
di << "S + Ctrl : Shading\n";
di << "W + Ctrl : Wireframe\n";
di << "H : HiddenLineRemoval\n";
di << "U : Unset display mode\n";
di << "Delete : Remove selection from viewer\n";