← Back to team overview

kicad-developers team mailing list archive

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

 

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

>From 06990db0b28aadaa709d0e1c4ffbc00e4b51dbe0 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 | 123 ++++++++++++------------
 3d-viewer/3d_cache/dialogs/panel_prev_model.h   |  20 ++--
 2 files changed, 69 insertions(+), 74 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..971f386cd 100644
--- a/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
+++ b/3d-viewer/3d_cache/dialogs/panel_prev_model.cpp
@@ -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, -180, 180, 1, 10 );
+    yrot = new wxSpinCtrlDouble( modRotate, ID_ROTY, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, -180, 180, 1, 10 );
+    zrot = new wxSpinCtrlDouble( modRotate, ID_ROTZ, "0", wxDefaultPosition, wxDefaultSize,
+        wxSP_ARROW_KEYS, -180, 180, 1, 10 );
 
-    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 )
@@ -627,21 +622,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..5399b7d89 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;
 
-- 
2.11.0


Follow ups

References