Implement GUI and file R/W for 3D model opacity.

Fixes https://gitlab.com/kicad/code/kicad/issues/2087
This commit is contained in:
Jeff Young 2020-04-19 18:23:40 +01:00
parent a286cb5a8f
commit c08a6adb2a
9 changed files with 310 additions and 1014 deletions

View File

@ -208,6 +208,8 @@ void PANEL_PREV_3D::SetSelectedModel( int idx )
xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) ); xoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.x ) );
yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) ); yoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.y ) );
zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) ); zoff->ChangeValue( formatOffsetValue( modelInfo.m_Offset.z ) );
m_opacity->SetValue( modelInfo.m_Opacity * 100.0 );
} }
else else
{ {
@ -224,6 +226,8 @@ void PANEL_PREV_3D::SetSelectedModel( int idx )
xoff->ChangeValue( wxEmptyString ); xoff->ChangeValue( wxEmptyString );
yoff->ChangeValue( wxEmptyString ); yoff->ChangeValue( wxEmptyString );
zoff->ChangeValue( wxEmptyString ); zoff->ChangeValue( wxEmptyString );
m_opacity->SetValue( 100 );
} }
} }
@ -253,6 +257,21 @@ void PANEL_PREV_3D::updateOrientation( wxCommandEvent &event )
} }
void PANEL_PREV_3D::onOpacitySlider( wxCommandEvent& event )
{
if( m_parentModelList && m_selected >= 0 && m_selected < (int) m_parentModelList->size() )
{
// Write settings back to the parent
MODULE_3D_SETTINGS* modelInfo = &m_parentModelList->at( (unsigned) m_selected );
modelInfo->m_Opacity = m_opacity->GetValue() / 100.0;
// Update the dummy module for the preview
UpdateDummyModule( false );
}
}
void PANEL_PREV_3D::doIncrementScale( wxSpinEvent& event, double aSign ) void PANEL_PREV_3D::doIncrementScale( wxSpinEvent& event, double aSign )
{ {
wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject(); wxSpinButton* spinCtrl = (wxSpinButton*) event.GetEventObject();

View File

@ -134,6 +134,8 @@ private:
doIncrementOffset( event, -1.0 ); doIncrementOffset( event, -1.0 );
} }
void onOpacitySlider( wxCommandEvent& event ) override;
void doIncrementScale( wxSpinEvent& aEvent, double aSign ); void doIncrementScale( wxSpinEvent& aEvent, double aSign );
void doIncrementRotation( wxSpinEvent& aEvent, double aSign ); void doIncrementRotation( wxSpinEvent& aEvent, double aSign );
void doIncrementOffset( wxSpinEvent& aEvent, double aSign ); void doIncrementOffset( wxSpinEvent& aEvent, double aSign );

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2018) // C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -9,7 +9,7 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : wxPanel( parent, id, pos, size, style, name )
{ {
wxBoxSizer* bSizermain; wxBoxSizer* bSizermain;
bSizermain = new wxBoxSizer( wxHORIZONTAL ); bSizermain = new wxBoxSizer( wxHORIZONTAL );
@ -147,7 +147,16 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
sbSizerOffset->Add( fgSizerOffset, 0, wxEXPAND|wxLEFT|wxRIGHT, 10 ); sbSizerOffset->Add( fgSizerOffset, 0, wxEXPAND|wxLEFT|wxRIGHT, 10 );
bSizerLeft->Add( sbSizerOffset, 0, wxEXPAND|wxALL, 5 ); bSizerLeft->Add( sbSizerOffset, 0, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 5 );
wxStaticBoxSizer* sbSizer4;
sbSizer4 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Opacity") ), wxVERTICAL );
m_opacity = new wxSlider( sbSizer4->GetStaticBox(), wxID_ANY, 50, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL|wxSL_LABELS );
sbSizer4->Add( m_opacity, 0, wxEXPAND, 5 );
bSizerLeft->Add( sbSizer4, 1, wxEXPAND|wxALL, 5 );
bSizermain->Add( bSizerLeft, 0, 0, 5 ); bSizermain->Add( bSizerLeft, 0, 0, 5 );
@ -176,30 +185,36 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
bSizer3DButtons->Add( 0, 0, 0, wxEXPAND|wxTOP, 4 ); bSizer3DButtons->Add( 0, 0, 0, wxEXPAND|wxTOP, 4 );
m_bpvISO = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvISO = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
m_bpvISO->SetToolTip( _("Change to isometric perspective") ); m_bpvISO->SetToolTip( _("Change to isometric perspective") );
bSizer3DButtons->Add( m_bpvISO, 0, wxTOP|wxBOTTOM, 5 ); bSizer3DButtons->Add( m_bpvISO, 0, wxTOP|wxBOTTOM, 5 );
m_bpvLeft = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW );
bSizer3DButtons->Add( 0, 0, 1, wxEXPAND, 5 );
m_bpvLeft = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvLeft, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvLeft, 0, 0, 5 );
m_bpvRight = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvRight = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvRight, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvRight, 0, 0, 5 );
m_bpvFront = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvFront = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvFront, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvFront, 0, 0, 5 );
m_bpvBack = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvBack = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvBack, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvBack, 0, 0, 5 );
m_bpvTop = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvTop = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvTop, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvTop, 0, 0, 5 );
m_bpvBottom = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW ); m_bpvBottom = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
bSizer3DButtons->Add( m_bpvBottom, 0, 0, 5 ); bSizer3DButtons->Add( m_bpvBottom, 0, 0, 5 );
m_bpUpdate = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW );
bSizer3DButtons->Add( 0, 0, 1, wxEXPAND, 5 );
m_bpUpdate = new wxBitmapButton( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxSize( 40,40 ), wxBU_AUTODRAW|0 );
m_bpUpdate->SetToolTip( _("Reload board and 3D models") ); m_bpUpdate->SetToolTip( _("Reload board and 3D models") );
bSizer3DButtons->Add( m_bpUpdate, 0, wxTOP, 5 ); bSizer3DButtons->Add( m_bpUpdate, 0, wxTOP, 5 );
@ -249,6 +264,7 @@ PANEL_PREV_3D_BASE::PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id, const w
zoff->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this ); zoff->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this ); m_spinZoffset->Connect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinZoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this ); m_spinZoffset->Connect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
m_opacity->Connect( wxEVT_SLIDER, wxCommandEventHandler( PANEL_PREV_3D_BASE::onOpacitySlider ), NULL, this );
m_bpvISO->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this ); m_bpvISO->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this );
m_bpvLeft->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this ); m_bpvLeft->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this );
m_bpvRight->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this ); m_bpvRight->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this );
@ -298,6 +314,7 @@ PANEL_PREV_3D_BASE::~PANEL_PREV_3D_BASE()
zoff->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this ); zoff->Disconnect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( PANEL_PREV_3D_BASE::updateOrientation ), NULL, this );
m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this ); m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEDOWN, wxSpinEventHandler( PANEL_PREV_3D_BASE::onDecrementOffset ), NULL, this );
m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this ); m_spinZoffset->Disconnect( wxEVT_SCROLL_LINEUP, wxSpinEventHandler( PANEL_PREV_3D_BASE::onIncrementOffset ), NULL, this );
m_opacity->Disconnect( wxEVT_SLIDER, wxCommandEventHandler( PANEL_PREV_3D_BASE::onOpacitySlider ), NULL, this );
m_bpvISO->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this ); m_bpvISO->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DISO ), NULL, this );
m_bpvLeft->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this ); m_bpvLeft->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DLeft ), NULL, this );
m_bpvRight->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this ); m_bpvRight->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( PANEL_PREV_3D_BASE::View3DRight ), NULL, this );

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,11 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2018) // C++ code generated with wxFormBuilder (version Oct 26 2018)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef __PANEL_PREV_3D_BASE_H__ #pragma once
#define __PANEL_PREV_3D_BASE_H__
#include <wx/artprov.h> #include <wx/artprov.h>
#include <wx/xrc/xmlres.h> #include <wx/xrc/xmlres.h>
@ -21,10 +20,11 @@
#include <wx/spinbutt.h> #include <wx/spinbutt.h>
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/statbox.h> #include <wx/statbox.h>
#include <wx/slider.h>
#include <wx/bmpbuttn.h>
#include <wx/bitmap.h> #include <wx/bitmap.h>
#include <wx/image.h> #include <wx/image.h>
#include <wx/icon.h> #include <wx/icon.h>
#include <wx/bmpbuttn.h>
#include <wx/button.h> #include <wx/button.h>
#include <wx/panel.h> #include <wx/panel.h>
@ -65,6 +65,7 @@ class PANEL_PREV_3D_BASE : public wxPanel
wxStaticText* m_staticText32; wxStaticText* m_staticText32;
wxTextCtrl* zoff; wxTextCtrl* zoff;
wxSpinButton* m_spinZoffset; wxSpinButton* m_spinZoffset;
wxSlider* m_opacity;
wxBoxSizer* m_SizerPanelView; wxBoxSizer* m_SizerPanelView;
wxBitmapButton* m_bpvISO; wxBitmapButton* m_bpvISO;
wxBitmapButton* m_bpvLeft; wxBitmapButton* m_bpvLeft;
@ -86,6 +87,7 @@ class PANEL_PREV_3D_BASE : public wxPanel
virtual void onMouseWheelOffset( wxMouseEvent& event ) { event.Skip(); } virtual void onMouseWheelOffset( wxMouseEvent& event ) { event.Skip(); }
virtual void onDecrementOffset( wxSpinEvent& event ) { event.Skip(); } virtual void onDecrementOffset( wxSpinEvent& event ) { event.Skip(); }
virtual void onIncrementOffset( wxSpinEvent& event ) { event.Skip(); } virtual void onIncrementOffset( wxSpinEvent& event ) { event.Skip(); }
virtual void onOpacitySlider( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DISO( wxCommandEvent& event ) { event.Skip(); } virtual void View3DISO( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DLeft( wxCommandEvent& event ) { event.Skip(); } virtual void View3DLeft( wxCommandEvent& event ) { event.Skip(); }
virtual void View3DRight( wxCommandEvent& event ) { event.Skip(); } virtual void View3DRight( wxCommandEvent& event ) { event.Skip(); }
@ -99,9 +101,8 @@ class PANEL_PREV_3D_BASE : public wxPanel
public: public:
wxTextCtrl* yoff; wxTextCtrl* yoff;
PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL ); PANEL_PREV_3D_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString );
~PANEL_PREV_3D_BASE(); ~PANEL_PREV_3D_BASE();
}; };
#endif //__PANEL_PREV_3D_BASE_H__

View File

@ -153,6 +153,7 @@ none
not_allowed not_allowed
np_thru_hole np_thru_hole
offset offset
opacity
options options
other_layers_line_width other_layers_line_width
other_layers_text_dims other_layers_text_dims

View File

@ -85,6 +85,7 @@ class MODULE_3D_SETTINGS
m_Scale { 1, 1, 1 }, m_Scale { 1, 1, 1 },
m_Rotation { 0, 0, 0 }, m_Rotation { 0, 0, 0 },
m_Offset { 0, 0, 0 }, m_Offset { 0, 0, 0 },
m_Opacity( 1.0 ),
m_Show( true ) m_Show( true )
{ {
} }
@ -97,6 +98,7 @@ class MODULE_3D_SETTINGS
VECTOR3D m_Scale; ///< 3D model scaling factor (dimensionless) VECTOR3D m_Scale; ///< 3D model scaling factor (dimensionless)
VECTOR3D m_Rotation; ///< 3D model rotation (degrees) VECTOR3D m_Rotation; ///< 3D model rotation (degrees)
VECTOR3D m_Offset; ///< 3D model offset (mm) VECTOR3D m_Offset; ///< 3D model offset (mm)
double m_Opacity;
wxString m_Filename; ///< The 3D shape filename in 3D library wxString m_Filename; ///< The 3D shape filename in 3D library
bool m_Show; ///< Include module in rendering bool m_Show; ///< Include module in rendering
}; };

View File

@ -1160,6 +1160,9 @@ void PCB_IO::format( MODULE* aModule, int aNestLevel ) const
m_out->Quotew( bs3D->m_Filename ).c_str(), m_out->Quotew( bs3D->m_Filename ).c_str(),
bs3D->m_Show ? "" : " hide" ); bs3D->m_Show ? "" : " hide" );
if( bs3D->m_Opacity != 1.0 )
m_out->Print( aNestLevel+2, "(opacity %0.4f)", bs3D->m_Opacity );
/* Write 3D model offset in mm /* Write 3D model offset in mm
* 4.0.x wrote "at" which was actually in inches * 4.0.x wrote "at" which was actually in inches
* 5.0.x onwards, 3D model offset is written using "offset" * 5.0.x onwards, 3D model offset is written using "offset"

View File

@ -415,6 +415,11 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
n3D->m_Show = false; n3D->m_Show = false;
break; break;
case T_opacity:
n3D->m_Opacity = parseDouble( "opacity value" );
NeedRIGHT();
break;
case T_offset: case T_offset:
NeedLEFT(); NeedLEFT();
token = NextTok(); token = NextTok();
@ -464,7 +469,7 @@ MODULE_3D_SETTINGS* PCB_PARSER::parse3DModel()
break; break;
default: default:
Expecting( "at, hide, offset, scale, or rotate" ); Expecting( "at, hide, opacity, offset, scale, or rotate" );
} }
} }