diff --git a/common/draw_panel_gal.cpp b/common/draw_panel_gal.cpp index 0ec6a1130b..93ad978969 100644 --- a/common/draw_panel_gal.cpp +++ b/common/draw_panel_gal.cpp @@ -67,7 +67,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this ); - Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this ); /* Generic events for the Tool Dispatcher */ @@ -184,10 +183,21 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect ) } +void EDA_DRAW_PANEL_GAL::StartDrawing() +{ + m_pendingRefresh = false; + Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + + wxPaintEvent redrawEvent; + wxPostEvent( this, redrawEvent ); +} + + void EDA_DRAW_PANEL_GAL::StopDrawing() { - Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); + m_pendingRefresh = true; m_refreshTimer.Stop(); + Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this ); } @@ -198,8 +208,7 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) return; // Prevent refreshing canvas during backend switch - m_pendingRefresh = true; - m_refreshTimer.Stop(); + StopDrawing(); delete m_gal; @@ -228,7 +237,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType ) m_view->SetGAL( m_gal ); m_currentGal = aGalType; - m_pendingRefresh = false; } diff --git a/common/tool/context_menu.cpp b/common/tool/context_menu.cpp index d45bbb3602..580e876a8b 100644 --- a/common/tool/context_menu.cpp +++ b/common/tool/context_menu.cpp @@ -110,7 +110,7 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction ) { int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK; int mod = aAction.GetHotKey() & MD_MODIFIER_MASK; - wxAcceleratorEntryFlags flags = wxACCEL_NORMAL; + int flags = wxACCEL_NORMAL; switch( mod ) { diff --git a/common/wxunittext.cpp b/common/wxunittext.cpp index 5af3c721ea..f33be9ec5a 100644 --- a/common/wxunittext.cpp +++ b/common/wxunittext.cpp @@ -26,8 +26,12 @@ #include #include #include -#include +#include #include +#if wxCHECK_VERSION( 2, 9, 0 ) +#include +#endif +#include WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aValue, double aStep ) : wxPanel( aParent, wxID_ANY ), @@ -47,22 +51,29 @@ WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aV m_inputLabel->SetMinSize( size ); sizer->Add( m_inputLabel, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 ); - wxFloatingPointValidator validator( 4, NULL, wxNUM_VAL_NO_TRAILING_ZEROES ); - validator.SetRange( 0.0, std::numeric_limits::max() ); - // Main input control m_inputValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); - m_inputValue->SetValidator( validator ); + SetValue( aValue ); sizer->Add( m_inputValue, 0, wxALIGN_CENTER_VERTICAL | wxALL ); +#if wxCHECK_VERSION( 2, 9, 0 ) // Sorry guys, I am tired of dealing with 2.8 compatibility + wxFloatingPointValidator validator( 4, NULL, wxNUM_VAL_NO_TRAILING_ZEROES ); + validator.SetRange( 0.0, std::numeric_limits::max() ); + m_inputValue->SetValidator( validator ); + // Spin buttons for modifying values using the mouse m_spinButton = new wxSpinButton( this, wxID_ANY ); m_spinButton->SetRange( std::numeric_limits::min(), std::numeric_limits::max() ); + m_spinButton->SetCanFocus( false ); sizer->Add( m_spinButton, 0, wxALIGN_CENTER_VERTICAL | wxALL ); + Connect( wxEVT_SPIN_UP, wxSpinEventHandler( WX_UNIT_TEXT::onSpinUpEvent ), NULL, this ); + Connect( wxEVT_SPIN_DOWN, wxSpinEventHandler( WX_UNIT_TEXT::onSpinDownEvent ), NULL, this ); +#endif + sizer->AddSpacer( 5 ); // Create units label @@ -72,10 +83,6 @@ WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aV SetSizer( sizer ); Layout(); - - Connect( wxEVT_SPIN_UP, wxSpinEventHandler( WX_UNIT_TEXT::onSpinUpEvent ), NULL, this ); - Connect( wxEVT_SPIN_DOWN, wxSpinEventHandler( WX_UNIT_TEXT::onSpinDownEvent ), NULL, this ); - Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( WX_UNIT_TEXT::onEnter ), NULL, this ); } @@ -98,49 +105,87 @@ void WX_UNIT_TEXT::SetValue( double aValue ) if( aValue >= 0.0 ) { - m_inputValue->SetValue( Double2Str( aValue ) ); + m_inputValue->SetValue( wxString( Double2Str( aValue ).c_str(), wxConvUTF8 ) ); m_inputValue->MarkDirty(); } } -double WX_UNIT_TEXT::GetValue( EDA_UNITS_T aUnit ) const +/*boost::optional WX_UNIT_TEXT::GetValue( EDA_UNITS_T aUnit ) const { - assert( false ); // TODO + if( aUnit == m_units ) + return GetValue(); // no conversion needed + + switch( m_units ) + { + case MILLIMETRES: + switch( aUnit ) + { + case INCHES: + iu = Mils2iu( GetValue() * 1000.0 ); + break; + + case UNSCALED_UNITS: + iu = GetValue(); + break; + } + break; + + case INCHES: + switch( aUnit ) + { + case MILLIMETRES: + return Mils2mm( GetValue() * 1000.0 ); + break; + + case UNSCALED_UNITS: + return Mils2iu( GetValue() * 1000.0 ); + break; + } + break; + + case UNSCALED_UNITS: + switch( aUnit ) + { + case MILLIMETRES: + return Iu2Mils( GetValue() ) / 1000.0; + break; + +// case INCHES: +// return +// break; + } + break; + } + + assert( false ); // seems that there are some conversions missing return 0.0; -} +}*/ -double WX_UNIT_TEXT::GetValue() const +boost::optional WX_UNIT_TEXT::GetValue() const { wxString text = m_inputValue->GetValue(); double value; if( !text.ToDouble( &value ) ) - value = 0.0; + return boost::optional(); - return value; + return boost::optional( value ); } void WX_UNIT_TEXT::onSpinUpEvent( wxSpinEvent& aEvent ) { - SetValue( GetValue() + m_step ); + SetValue( *GetValue() + m_step ); } void WX_UNIT_TEXT::onSpinDownEvent( wxSpinEvent& aEvent ) { - double newValue = GetValue() - m_step; + double newValue = *GetValue() - m_step; if( newValue >= 0.0 ) SetValue( newValue ); } - - -void WX_UNIT_TEXT::onEnter( wxCommandEvent& aEvent ) -{ - // Move focus to the next widget - Navigate(); -} diff --git a/include/class_draw_panel_gal.h b/include/class_draw_panel_gal.h index 4ec05ed65d..766cb5d630 100644 --- a/include/class_draw_panel_gal.h +++ b/include/class_draw_panel_gal.h @@ -111,9 +111,16 @@ public: m_eventDispatcher = aEventDispatcher; } + /** + * Function StartDrawing() + * Begins drawing if it was stopped previously. + */ + void StartDrawing(); + /** * Function StopDrawing() - * Prevents the GAL canvas from further drawing till it is recreated. + * Prevents the GAL canvas from further drawing till it is recreated + * or StartDrawing() is called. */ void StopDrawing(); diff --git a/include/wxunittext.h b/include/wxunittext.h index 977002e59a..92791f09ff 100644 --- a/include/wxunittext.h +++ b/include/wxunittext.h @@ -28,6 +28,11 @@ #include #include +namespace boost +{ + template + class optional; +} class wxTextCtrl; class wxSpinButton; class wxStaticText; @@ -42,7 +47,7 @@ public: * @param aValue is the initial value for the control. * @param aStep is the step size when using spin buttons. */ - WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = wxString( "Size:" ), + WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = _( "Size:" ), double aValue = 0.0, double aStep = 0.1 ); virtual ~WX_UNIT_TEXT(); @@ -69,13 +74,13 @@ public: * they are converted first). * @param aUnits is the wanted unit. */ - virtual double GetValue( EDA_UNITS_T aUnits ) const; + //virtual double GetValue( EDA_UNITS_T aUnits ) const; /** * Function GetValue * Returns the current value in currently used units. */ - virtual double GetValue() const; + virtual boost::optional GetValue() const; /** * Function GetUnits @@ -114,9 +119,6 @@ protected: ///> Spin down button click event handler. void onSpinDownEvent( wxSpinEvent& aEvent ); - ///> On Enter press event handler. - void onEnter( wxCommandEvent& aEvent ); - ///> Label for the input (e.g. "Size:") wxStaticText* m_inputLabel; diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index 3bbade6770..00fcf088c0 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -159,6 +159,9 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame this, -1, wxPoint( 0, 0 ), m_FrameSize, EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) ); + // GAL should not be active yet + GetGalCanvas()->StopDrawing(); + // Hide by default, it has to be explicitly shown GetGalCanvas()->Hide(); diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index ada7b0d8c7..9f66d54d21 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -673,10 +673,13 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) if( aEnable ) { ViewReloadBoard( m_Pcb ); + GetGalCanvas()->GetView()->RecacheAllItems(); m_toolManager.SetEnvironment( m_Pcb, GetGalCanvas()->GetView(), GetGalCanvas()->GetViewControls(), this ); - m_toolManager.ResetTools( TOOL_BASE::GAL_SWITCH ); + m_toolManager.ResetTools( TOOL_BASE::MODEL_RELOAD ); + + GetGalCanvas()->StartDrawing(); } }