kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #27432
Re: [PATCH] Changed the 3d model previewer to use spinboxes
The real motivation for doing this was the functionality of the
scrollwheel. Which I got for free in the spinctrldouble, only in linux
though.
But since the implementation of spinctrls was horrible on other os, I
stuck with the textctrl and instead catch the mouse events and also the
keyevents pgup/pgdown and subtract/add.
I did not implement the arrowbuttons, but the increment functionality is
there if anyone wants/cares for the up/down arrowbuttons.
tested on windows and linux.
- Kristoffer
On 2017-01-31 10:01, Mário Luzeiro wrote:
Just and idea:
What about, somehow, this could be implemented with a second pair of widgets?
i.e: keep the line entries as before, and somehow, catching the scroll mouse events on that line entry.. and may add arrow buttons on the side, to work as a spinbox? :S
My 2 cents,
Mario Luzeiro
________________________________________
From: Kicad-developers [kicad-developers-bounces+mrluzeiro=ua.pt@xxxxxxxxxxxxxxxxxxx] on behalf of Wayne Stambaugh [stambaughw@xxxxxxxxx]
Sent: 31 January 2017 01:30
To: kicad-developers@xxxxxxxxxxxxxxxxxxx
Subject: Re: [Kicad-developers] [PATCH] Changed the 3d model previewer to use spinboxes
Manual entry now works on windows but you changed the behavior.
Currently, as you enter a number in the edit control, the changes update
instantly. With your patch, you have to tab to the next control before
the change is made. IMO, this is a step backwards from the current
behavior at least on windows. I'm not sure I'm good with this
regression. Anyone else have any thoughts on this.
_______________________________________________
Mailing list: https://launchpad.net/~kicad-developers
Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
Unsubscribe : https://launchpad.net/~kicad-developers
More help : https://help.launchpad.net/ListHelp
>From 207c60b6958d1a255fb451e2a87b90d224acad09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= <kristoffer.odmark90@xxxxxxxxx>
Date: Tue, 31 Jan 2017 13:30:07 +0100
Subject: [PATCH] Enabled incrementing values by using the scroll wheel or
pgup/pgdown in PANEL_PREV_3D.
---
3d-viewer/3d_cache/dialogs/panel_prev_model.cpp | 112 +++++++++++++++++++++---
3d-viewer/3d_cache/dialogs/panel_prev_model.h | 31 +++++++
2 files changed, 131 insertions(+), 12 deletions(-)
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
index da356df47..0b8f16b68 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
@@ -93,6 +93,9 @@ wxBEGIN_EVENT_TABLE( PANEL_PREV_3D, wxPanel)
EVT_TEXT( ID_OFFY, PANEL_PREV_3D::updateOrientation )
EVT_TEXT( ID_OFFZ, PANEL_PREV_3D::updateOrientation )
+ EVT_MOUSEWHEEL( PANEL_PREV_3D::onScroll )
+ EVT_CHAR_HOOK( PANEL_PREV_3D::onChar )
+
EVT_TOGGLEBUTTON( ID_3D_ISO, PANEL_PREV_3D::View3DISO )
EVT_BUTTON( ID_3D_UPDATE, PANEL_PREV_3D::View3DUpdate )
EVT_BUTTON( ID_3D_LEFT, PANEL_PREV_3D::View3DLeft )
@@ -134,11 +137,11 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent,
wxStaticBoxSizer* vbox = new wxStaticBoxSizer( wxVERTICAL, this, _( "3D Preview" ) );
wxFloatingPointValidator< float > valScale( 4 );
- valScale.SetRange( 0.0f, 9999.0f );
+ valScale.SetRange( MIN_SCALE, MAX_SCALE );
wxFloatingPointValidator< float > valRotate( 2 );
- valRotate.SetRange( -180.0f, 180.0f );
+ valRotate.SetRange( MIN_ROTATION, MAX_ROTATION );
wxFloatingPointValidator< float > valOffset( 4 );
- valOffset.SetRange( -9999.0f, 9999.0f );
+ valOffset.SetRange( MIN_OFFSET, MAX_OFFSET );
wxStaticBoxSizer* vbScale = new wxStaticBoxSizer( wxVERTICAL, this, _( "Scale" ) );
wxStaticBoxSizer* vbRotate = new wxStaticBoxSizer( wxVERTICAL, this, _( "Rotation (degrees)" ) );
@@ -576,21 +579,108 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName )
return;
}
-
-void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
+static bool validateFloatTextCtrl( wxTextCtrl *textCtrl )
{
- wxTextCtrl *textCtrl = (wxTextCtrl *)event.GetEventObject();
-
if( textCtrl == NULL )
- return;
+ return false;
if( textCtrl->GetLineLength(0) == 0 ) // This will skip the got and event with empty field
- return;
+ return false;
if( textCtrl->GetLineLength(0) == 1 )
if( (textCtrl->GetLineText(0).compare( "." ) == 0) ||
(textCtrl->GetLineText(0).compare( "," ) == 0) )
- return;
+ return false;
+ return true;
+
+}
+
+static void incrementTextCtrl( wxTextCtrl *textCtrl, double inc, double minval, double maxval )
+{
+ double current = 0;
+ if( !validateFloatTextCtrl( textCtrl ) )
+ return;
+
+ textCtrl->GetValue().ToDouble( ¤t );
+ double newval = current + inc;
+
+ if ( newval > maxval || newval < minval )
+ return;
+
+ textCtrl->SetValue( wxString::Format( "%.4f", newval ) );
+}
+
+void PANEL_PREV_3D::incrementFocusedTextCtrl( int direction )
+{
+ if( xscale->HasFocus() )
+ {
+ incrementTextCtrl( xscale, direction * SCALE_INCREMENT, MIN_SCALE, MAX_SCALE );
+ }
+ if( yscale->HasFocus() )
+ {
+ incrementTextCtrl( yscale, direction * SCALE_INCREMENT, MIN_SCALE, MAX_SCALE );
+ }
+ if( zscale->HasFocus() )
+ {
+ incrementTextCtrl( zscale, direction * SCALE_INCREMENT, MIN_SCALE, MAX_SCALE );
+ }
+ if( xrot->HasFocus() )
+ {
+ incrementTextCtrl( xrot, direction * ROTATION_INCREMENT, MIN_ROTATION, MAX_ROTATION);
+ }
+ if( yrot->HasFocus() )
+ {
+ incrementTextCtrl( yrot, direction * ROTATION_INCREMENT, MIN_ROTATION, MAX_ROTATION );
+ }
+ if( zrot->HasFocus() )
+ {
+ incrementTextCtrl( zrot, direction * ROTATION_INCREMENT, MIN_ROTATION, MAX_ROTATION );
+ }
+ if( xoff->HasFocus() )
+ {
+ incrementTextCtrl( xoff, direction * OFFSET_INCREMENT, MIN_OFFSET, MAX_OFFSET );
+ }
+ if( yoff->HasFocus() )
+ {
+ incrementTextCtrl( yoff, direction * OFFSET_INCREMENT, MIN_OFFSET, MAX_OFFSET );
+ }
+ if( zoff->HasFocus() )
+ {
+ incrementTextCtrl( zoff, direction * OFFSET_INCREMENT, MIN_OFFSET, MAX_OFFSET );
+ }
+}
+
+void PANEL_PREV_3D::onChar( wxKeyEvent &event )
+{
+ switch ( event.GetKeyCode() )
+ {
+ case WXK_NUMPAD_ADD:
+ case WXK_ADD:
+ case WXK_PAGEUP:
+ incrementFocusedTextCtrl( 1 );
+ break;
+ case WXK_NUMPAD_SUBTRACT:
+ case WXK_SUBTRACT:
+ case WXK_PAGEDOWN:
+ incrementFocusedTextCtrl( -1 );
+ break;
+ }
+ event.Skip();
+}
+
+void PANEL_PREV_3D::onScroll( wxMouseEvent &event )
+{
+ int rotation = event.GetWheelRotation() > 0 ? 1 : -1;
+ incrementFocusedTextCtrl( rotation );
+}
+
+
+void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
+{
+ wxTextCtrl *textCtrl = ( wxTextCtrl * )event.GetEventObject();
+
+ if( !validateFloatTextCtrl( textCtrl ) )
+ return;
SGPOINT scale;
SGPOINT rotation;
@@ -669,8 +759,6 @@ void PANEL_PREV_3D::getOrientationVars( SGPOINT& aScale, SGPOINT& aRotation, SGP
bool PANEL_PREV_3D::ValidateWithMessage( wxString& aErrorMessage )
{
bool invalidScale = false;
- #define MIN_SCALE 0.001
- #define MAX_SCALE 1000.0
for( unsigned int idx = 0; idx < m_parentInfoList->size(); ++idx )
{
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.h b/3d-viewer/3d_cache/dialogs/panel_prev_model.h
index 0a2faf88b..0481144aa 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.h
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.h
@@ -40,6 +40,18 @@
#include "../3d_info.h"
#include <vector>
+
+#define MIN_SCALE 0.001
+#define MAX_SCALE 9999.0
+#define MIN_ROTATION -180.0
+#define MAX_ROTATION 180.0
+#define MIN_OFFSET -9999.0
+#define MAX_OFFSET 9999.0
+
+#define SCALE_INCREMENT 0.1
+#define ROTATION_INCREMENT 15
+#define OFFSET_INCREMENT 0.1
+
// Declared classes to create pointers
class S3D_CACHE;
class S3D_FILENAME_RESOLVER;
@@ -152,6 +164,25 @@ private:
void updateOrientation( wxCommandEvent &event );
/**
+ * @brief onScroll - receives the scroll events and increments fields.
+ * @param event
+ */
+ void onScroll( wxMouseEvent &event );
+
+ /**
+ * @brief onChar - it will intercept the key events and react
+ * Only reacts to PGUP/PGDOWN and ADD/SUBTRACT
+ * @param event
+ */
+ void onChar( wxKeyEvent &event );
+
+ /**
+ * @brief incrementFocusedTextCtrl - updates the field of the currently selected textCtrl
+ * @param event
+ */
+ void incrementFocusedTextCtrl( int direction );
+
+ /**
* @brief getOrientationVars - gets the transformation from entries and validate it
* @param aScale: output scale var
* @param aRotation: output rotation var
--
2.11.0
Follow ups
References
-
[PATCH] Changed the 3d model previewer to use spinboxes
From: Kristoffer Ödmark, 2017-01-26
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Wayne Stambaugh, 2017-01-26
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Chris Pavlina, 2017-01-26
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Kristoffer Ödmark, 2017-01-26
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Chris Pavlina, 2017-01-27
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Wayne Stambaugh, 2017-01-27
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Kristoffer Ödmark, 2017-01-27
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Wayne Stambaugh, 2017-01-27
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Kristoffer Ödmark, 2017-01-30
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Wayne Stambaugh, 2017-01-31
-
Re: [PATCH] Changed the 3d model previewer to use spinboxes
From: Mário Luzeiro, 2017-01-31