← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH] Changed the 3d model previewer to use spinboxes

 

Hello!

The patch now works under windows, mac and linux.

-Kristoffer

On 2017-01-27 16:40, Wayne Stambaugh wrote:
This doesn't work on windows at all.  Changing any of the values either
with the spin buttons or direct entry into the edit control does not
update 3D view of the model.  This issue will need to be resolved before
the patch can be committed.

On 1/27/2017 8:16 AM, Kristoffer Ödmark wrote:
Glad to hear it!

Also, I found that incrementing in steps of 10 for the rotations misses
45 deegrees, so changed that to 5 and made it wrap around at 180 as well.

Attaching that one!

 -Kristoffer

On 2017-01-27 13:47, Wayne Stambaugh wrote:
It's on my list for today.  It would be nice if an osx dev could test it
before it's committed just in case there is some unexpected behavior
on osx.

On 1/27/2017 7:43 AM, Chris Pavlina wrote:
Just tried this. It's REALLY nice to be able to nudge the model around
by turning the scroll wheel over the fields. <3

Anyone test this on something other than Linux yet? I'd like to see this
merged.

On Thu, Jan 26, 2017 at 05:24:17PM +0100, Kristoffer Ödmark wrote:
Yes, you can still manually change the values, I tried that.

The only change I did to the code was to change the stepping of the
offset
to 0.1mm instead of 1 in this patch. the best thing is that you can
now use
the scrollwheel as well. Wich makes rotating stuff a breeze.

- Kristoffer

On 2017-01-26 17:09, Chris Pavlina wrote:
On Thu, Jan 26, 2017 at 09:49:40AM -0500, Wayne Stambaugh wrote:
If no one is opposed to adding spin controls to the 3D model
selection
dialog, I'll commit this patch when I get a chance.  I've never been
convinced that using a spin control to change a floating point
number is
terribly useful but I'm guessing some users will prefer this over
manual
entry of calculated values used by old curmudgeons like me.

I can see value in it. When you're moving around a 3D model, you don't
want to type in a specific value, you want to move it until it's
aligned. If the model is far off it can be hard to guess what the
offset
should be like, so having a button to nudge it up and down could be
nice.

Might want to hold off for a bit though as I think there was talk
about
an updated patch in IRC, this might not be final


On 1/26/2017 6:11 AM, Kristoffer Ödmark wrote:
Hello!

One thing that has always bothered me is that when aligning 3D
models to
fit the footprint, one have to type the value and test, delete
characters and test again. Very minor issue, but it still bothers
me.

With a spinbox the values can be changed using the mouse only.

attaching the patch for this minor change.

- Kristoffer



_______________________________________________
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


_______________________________________________
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

_______________________________________________
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



_______________________________________________
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



_______________________________________________
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



_______________________________________________
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



_______________________________________________
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 1e58022e6e7aee7574a957a43135c80c89017ca3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= <kristoffer.odmark90@xxxxxxxxx>
Date: Thu, 26 Jan 2017 11:57:54 +0100
Subject: [PATCH] Changed so that the 3d viewer uses spinboxes instead of text
 inputs.

---
 3d-viewer/3d_cache/dialogs/panel_prev_model.cpp | 156 +++++++++++-------------
 3d-viewer/3d_cache/dialogs/panel_prev_model.h   |  22 ++--
 2 files changed, 80 insertions(+), 98 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..f966c5ea1 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
@@ -83,15 +83,15 @@ enum {
 
 
 wxBEGIN_EVENT_TABLE( PANEL_PREV_3D, wxPanel)
-    EVT_TEXT( ID_SCALEX, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_SCALEY, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_SCALEZ, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_ROTX, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_ROTY, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_ROTZ, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_OFFX, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_OFFY, PANEL_PREV_3D::updateOrientation )
-    EVT_TEXT( ID_OFFZ, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_SCALEX, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_SCALEY, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_SCALEZ, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_ROTX, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_ROTY, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_ROTZ, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_OFFX, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_OFFY, PANEL_PREV_3D::updateOrientation )
+    EVT_SPINCTRLDOUBLE( ID_OFFZ, PANEL_PREV_3D::updateOrientation )
 
     EVT_TOGGLEBUTTON( ID_3D_ISO, PANEL_PREV_3D::View3DISO )
     EVT_BUTTON( ID_3D_UPDATE, PANEL_PREV_3D::View3DUpdate )
@@ -133,13 +133,6 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent,
     wxBoxSizer* mainBox = new wxBoxSizer( wxVERTICAL );
     wxStaticBoxSizer* vbox = new wxStaticBoxSizer( wxVERTICAL, this, _( "3D Preview" ) );
 
-    wxFloatingPointValidator< float > valScale( 4 );
-    valScale.SetRange( 0.0f, 9999.0f );
-    wxFloatingPointValidator< float > valRotate( 2 );
-    valRotate.SetRange( -180.0f, 180.0f );
-    wxFloatingPointValidator< float > valOffset( 4 );
-    valOffset.SetRange( -9999.0f, 9999.0f );
-
     wxStaticBoxSizer* vbScale  = new wxStaticBoxSizer( wxVERTICAL, this, _( "Scale" )  );
     wxStaticBoxSizer* vbRotate = new wxStaticBoxSizer( wxVERTICAL, this, _( "Rotation (degrees)" ) );
 
@@ -158,16 +151,16 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent,
     wxStaticText* txtS2 = new wxStaticText( modScale, -1, wxT( "Y:" ) );
     wxStaticText* txtS3 = new wxStaticText( modScale, -1, wxT( "Z:" ) );
 
-    xscale = new wxTextCtrl( modScale, ID_SCALEX, "1", wxDefaultPosition, wxDefaultSize,
-        wxTE_PROCESS_ENTER, valScale );
-    yscale = new wxTextCtrl( modScale, ID_SCALEY, "1", wxDefaultPosition, wxDefaultSize,
-        wxTE_PROCESS_ENTER, valScale );
-    zscale = new wxTextCtrl( modScale, ID_SCALEZ, "1", wxDefaultPosition, wxDefaultSize,
-        wxTE_PROCESS_ENTER, valScale );
+    xscale = new wxSpinCtrlDouble( modScale, ID_SCALEX, "1", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, 0, 999, 1, 0.1 );
+    yscale = new wxSpinCtrlDouble( modScale, ID_SCALEY, "1", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, 0, 999, 1, 0.1 );
+    zscale = new wxSpinCtrlDouble( modScale, ID_SCALEZ, "1", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, 0, 999, 1, 0.1 );
 
-    xscale->SetMaxLength( 9 );
-    yscale->SetMaxLength( 9 );
-    zscale->SetMaxLength( 9 );
+    xscale->SetDigits( 5 );
+    yscale->SetDigits( 5 );
+    zscale->SetDigits( 5 );
     hbS1->Add( txtS1, 0, wxALIGN_CENTER, 2 );
     hbS1->Add( xscale, 0, wxEXPAND | wxLEFT | wxRIGHT, 2 );
     hbS2->Add( txtS2, 0, wxALIGN_CENTER, 2 );
@@ -185,16 +178,16 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent,
     wxStaticText* txtR2 = new wxStaticText( modRotate, -1, wxT( "Y:" ) );
     wxStaticText* txtR3 = new wxStaticText( modRotate, -1, wxT( "Z:" ) );
 
-    xrot = new wxTextCtrl( modRotate, ID_ROTX, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valRotate );
-    yrot = new wxTextCtrl( modRotate, ID_ROTY, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valRotate );
-    zrot = new wxTextCtrl( modRotate, ID_ROTZ, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valRotate );
+    xrot = new wxSpinCtrlDouble( modRotate, ID_ROTX, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS | wxSP_WRAP, -180, 180, 1, 5 );
+    yrot = new wxSpinCtrlDouble( modRotate, ID_ROTY, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS | wxSP_WRAP, -180, 180, 1, 5 );
+    zrot = new wxSpinCtrlDouble( modRotate, ID_ROTZ, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS | wxSP_WRAP, -180, 180, 1, 5 );
 
-    xrot->SetMaxLength( 9 );
-    yrot->SetMaxLength( 9 );
-    zrot->SetMaxLength( 9 );
+    xrot->SetDigits( 5 );
+    yrot->SetDigits( 5 );
+    zrot->SetDigits( 5 );
     hbR1->Add( txtR1, 1, wxALIGN_CENTER, 2 );
     hbR1->Add( xrot, 0, wxEXPAND | wxLEFT | wxRIGHT, 2 );
     hbR2->Add( txtR2, 1, wxALIGN_CENTER, 2 );
@@ -213,15 +206,17 @@ PANEL_PREV_3D::PANEL_PREV_3D( wxWindow* aParent,
     wxStaticText* txtO3 = new wxStaticText( modOffset, -1, wxT( "Z:" ) );
 
     // The default offset is 0.0 or 0,0, depending on floating point separator:
-    xoff = new wxTextCtrl( modOffset, ID_OFFX, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valOffset );
-    yoff = new wxTextCtrl( modOffset, ID_OFFY, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valOffset );
-    zoff = new wxTextCtrl( modOffset, ID_OFFZ, "0", wxDefaultPosition, wxDefaultSize,
-                           wxTE_PROCESS_ENTER, valOffset );
-    xoff->SetMaxLength( 10 );
-    yoff->SetMaxLength( 10 );
-    zoff->SetMaxLength( 10 );
+    xoff = new wxSpinCtrlDouble( modOffset, ID_OFFX, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, -999999, 999999, 1, 0.1 );
+    yoff = new wxSpinCtrlDouble( modOffset, ID_OFFY, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, -999999, 999999, 1, 0.1 );
+    zoff = new wxSpinCtrlDouble( modOffset, ID_OFFZ, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, -999999, 999999, 1, 0.1 );
+
+    xoff->SetDigits( 6 );
+    yoff->SetDigits( 6 );
+    zoff->SetDigits( 6 );
+
     hbO1->Add( txtO1, 0, wxALIGN_CENTER, 2 );
     hbO1->Add( xoff, 0, wxEXPAND | wxLEFT | wxRIGHT, 2 );
     hbO2->Add( txtO2, 0, wxALIGN_CENTER, 2 );
@@ -444,26 +439,26 @@ void PANEL_PREV_3D::SetModelDataIdx( int idx, bool aReloadPreviewModule )
 
             const S3D_INFO *aModel = (const S3D_INFO *)&((*m_parentInfoList)[idx]);
 
-            xscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.x ) );
-            yscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.y ) );
-            zscale->SetValue( wxString::Format( "%.4f", aModel->m_Scale.z ) );
+            xscale->SetValue( aModel->m_Scale.x );
+            yscale->SetValue( aModel->m_Scale.y );
+            zscale->SetValue( aModel->m_Scale.z );
 
-            xrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.x ) );
-            yrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.y ) );
-            zrot->SetValue( wxString::Format( "%.2f", aModel->m_Rotation.z ) );
+            xrot->SetValue( aModel->m_Rotation.x );
+            yrot->SetValue( aModel->m_Rotation.y );
+            zrot->SetValue( aModel->m_Rotation.z );
 
             switch( g_UserUnit )
             {
             case MILLIMETRES:
-                xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x * 25.4 ) );
-                yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y * 25.4 ) );
-                zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z * 25.4 ) );
+                xoff->SetValue( aModel->m_Offset.x * 25.4 );
+                yoff->SetValue( aModel->m_Offset.y * 25.4 );
+                zoff->SetValue( aModel->m_Offset.z * 25.4 );
                 break;
 
             case INCHES:
-                xoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.x ) );
-                yoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.y ) );
-                zoff->SetValue( wxString::Format( "%.4f", aModel->m_Offset.z ) );
+                xoff->SetValue( aModel->m_Offset.x );
+                yoff->SetValue( aModel->m_Offset.y );
+                zoff->SetValue( aModel->m_Offset.z );
                 break;
 
             case DEGREES:
@@ -497,17 +492,17 @@ void PANEL_PREV_3D::ResetModelData( bool aReloadPreviewModule )
 {
     m_currentSelectedIdx = -1;
 
-    xscale->SetValue( wxString::FromDouble( 1.0 ) );
-    yscale->SetValue( wxString::FromDouble( 1.0 ) );
-    zscale->SetValue( wxString::FromDouble( 1.0 ) );
+    xscale->SetValue( 1.0 );
+    yscale->SetValue( 1.0 );
+    zscale->SetValue( 1.0 );
 
-    xrot->SetValue( wxString::FromDouble( 0.0 ) );
-    yrot->SetValue( wxString::FromDouble( 0.0 ) );
-    zrot->SetValue( wxString::FromDouble( 0.0 ) );
+    xrot->SetValue( 0.0 );
+    yrot->SetValue( 0.0 );
+    zrot->SetValue( 0.0 );
 
-    xoff->SetValue( wxString::FromDouble( 0.0 ) );
-    yoff->SetValue( wxString::FromDouble( 0.0 ) );
-    zoff->SetValue( wxString::FromDouble( 0.0 ) );
+    xoff->SetValue( 0.0 );
+    yoff->SetValue( 0.0 );
+    zoff->SetValue( 0.0 );
 
     // This will update the model on the preview board with the current list of 3d shapes
     if( aReloadPreviewModule )
@@ -577,21 +572,8 @@ void PANEL_PREV_3D::UpdateModelName( wxString const& aModelName )
 }
 
 
-void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
+void PANEL_PREV_3D::updateOrientation( wxSpinDoubleEvent &event )
 {
-    wxTextCtrl *textCtrl = (wxTextCtrl *)event.GetEventObject();
-
-    if( textCtrl == NULL )
-        return;
-
-    if( textCtrl->GetLineLength(0) == 0 )   // This will skip the got and event with empty field
-        return;
-
-    if( textCtrl->GetLineLength(0) == 1 )
-        if( (textCtrl->GetLineText(0).compare( "." ) == 0) ||
-            (textCtrl->GetLineText(0).compare( "," ) == 0) )
-            return;
-
     SGPOINT scale;
     SGPOINT rotation;
     SGPOINT offset;
@@ -627,21 +609,21 @@ void PANEL_PREV_3D::getOrientationVars( SGPOINT& aScale, SGPOINT& aRotation, SGP
         return;
     }
 
-    xscale->GetValue().ToDouble( &aScale.x );
-    yscale->GetValue().ToDouble( &aScale.y );
-    zscale->GetValue().ToDouble( &aScale.z );
+    aScale.x = xscale->GetValue();
+    aScale.y = yscale->GetValue();
+    aScale.z = zscale->GetValue();
 
-    xrot->GetValue().ToDouble( &aRotation.x );
-    yrot->GetValue().ToDouble( &aRotation.y );
-    zrot->GetValue().ToDouble( &aRotation.z );
+    aRotation.x = xrot->GetValue();
+    aRotation.y = yrot->GetValue();
+    aRotation.z = zrot->GetValue();
 
     checkRotation( aRotation.x );
     checkRotation( aRotation.y );
     checkRotation( aRotation.z );
 
-    xoff->GetValue().ToDouble( &aOffset.x );
-    yoff->GetValue().ToDouble( &aOffset.y );
-    zoff->GetValue().ToDouble( &aOffset.z );
+    aOffset.x = xoff->GetValue();
+    aOffset.y = yoff->GetValue();
+    aOffset.z = zoff->GetValue();
 
     switch( g_UserUnit )
     {
diff --git a/3d-viewer/3d_cache/dialogs/panel_prev_model.h b/3d-viewer/3d_cache/dialogs/panel_prev_model.h
index 0a2faf88b..083178e1a 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.h
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.h
@@ -36,7 +36,7 @@
 #ifndef PANEL_PREV_MODEL_H
 #define PANEL_PREV_MODEL_H
 
-#include <wx/textctrl.h>
+#include <wx/spinctrl.h>
 #include "../3d_info.h"
 #include <vector>
 
@@ -113,15 +113,15 @@ private:
     S3D_FILENAME_RESOLVER   *m_resolver;        ///< Used to get the full path name
 
     // Parameters
-    wxTextCtrl* xscale;
-    wxTextCtrl* yscale;
-    wxTextCtrl* zscale;
-    wxTextCtrl* xrot;
-    wxTextCtrl* yrot;
-    wxTextCtrl* zrot;
-    wxTextCtrl* xoff;
-    wxTextCtrl* yoff;
-    wxTextCtrl* zoff;
+    wxSpinCtrlDouble* xscale;
+    wxSpinCtrlDouble* yscale;
+    wxSpinCtrlDouble* zscale;
+    wxSpinCtrlDouble* xrot;
+    wxSpinCtrlDouble* yrot;
+    wxSpinCtrlDouble* zrot;
+    wxSpinCtrlDouble* xoff;
+    wxSpinCtrlDouble* yoff;
+    wxSpinCtrlDouble* zoff;
 
     EDA_3D_CANVAS   *m_previewPane;
 
@@ -149,7 +149,7 @@ private:
      * @brief updateOrientation - it will receive the events from editing the fields
      * @param event
      */
-    void updateOrientation( wxCommandEvent &event );
+    void updateOrientation( wxSpinDoubleEvent &event );
 
     /**
      * @brief getOrientationVars - gets the transformation from entries and validate it
-- 
2.11.0


Follow ups

References