From 1c52824913b028f394f344835da87f331fe7b121 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 2 Sep 2018 21:19:22 +0100 Subject: [PATCH] Rewrite unit/convert handling so it also works for LibEdit. --- eeschema/class_libentry.h | 6 - .../panel_eeschema_display_options.cpp | 9 +- eeschema/dialogs/panel_libedit_settings.cpp | 7 +- eeschema/eeschema_config.cpp | 10 +- eeschema/libedit/block_libedit.cpp | 2 - eeschema/libedit/lib_edit_frame.cpp | 28 ++++- eeschema/sch_base_frame.cpp | 9 +- eeschema/sch_base_frame.h | 9 +- eeschema/sch_painter.cpp | 108 +++++++++++++----- eeschema/sch_painter.h | 19 ++- eeschema/viewlib_frame.cpp | 20 ++-- eeschema/widgets/symbol_preview_widget.cpp | 4 +- 12 files changed, 153 insertions(+), 78 deletions(-) diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index e894afdfd9..eb51cfe143 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -159,12 +159,6 @@ public: */ wxString GetUnitReference( int aUnit ) override; - /** - * A temporary unit designation for rendering, preview, etc. - */ - void SetTmpUnit( int aUnit ) { tmpUnit = aUnit; } - int GetTmpUnit() { return tmpUnit; } - /** * A temporary conversion (deMorgan) designation for rendering, preview, etc. */ diff --git a/eeschema/dialogs/panel_eeschema_display_options.cpp b/eeschema/dialogs/panel_eeschema_display_options.cpp index 2b8d3285b6..1075341d00 100644 --- a/eeschema/dialogs/panel_eeschema_display_options.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options.cpp @@ -110,11 +110,10 @@ bool PANEL_EESCHEMA_DISPLAY_OPTIONS::TransferDataFromWindow() m_frame->SetShowPageLimits( m_checkPageLimits->GetValue() ); m_frame->SetFootprintPreview( m_footprintPreview->GetValue() ); - SCH_DRAW_PANEL* canvas = m_frame->GetCanvas(); - auto painter = dynamic_cast( canvas->GetView()->GetPainter() ); - KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->SetShowHiddenPins( m_checkShowHiddenPins->GetValue() ); - canvas->ForceRefresh(); + // Update canvas + m_frame->GetRenderSettings()->m_ShowHiddenPins = m_checkShowHiddenPins->GetValue(); + m_frame->GetCanvas()->GetView()->MarkDirty(); + m_frame->GetCanvas()->Refresh(); return true; } diff --git a/eeschema/dialogs/panel_libedit_settings.cpp b/eeschema/dialogs/panel_libedit_settings.cpp index 7f8a8edcf7..45c5dc317e 100644 --- a/eeschema/dialogs/panel_libedit_settings.cpp +++ b/eeschema/dialogs/panel_libedit_settings.cpp @@ -83,11 +83,8 @@ bool PANEL_LIBEDIT_SETTINGS::TransferDataFromWindow() m_frame->SetShowElectricalType( m_checkShowPinElectricalType->GetValue() ); - SCH_DRAW_PANEL* canvas = m_frame->GetCanvas(); - auto painter = dynamic_cast( canvas->GetView()->GetPainter() ); - KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->SetShowPinsElectricalType( m_checkShowPinElectricalType->GetValue() ); - canvas->ForceRefresh(); + m_frame->GetRenderSettings()->m_ShowPinsElectricalType = m_frame->GetShowElectricalType(); + m_frame->GetCanvas()->Refresh(); return true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index d105c198d7..280b2fee2f 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -492,8 +492,8 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->SetShowPinsElectricalType( false ); - settings->SetShowHiddenPins( m_showAllPins ); + settings->m_ShowPinsElectricalType = false ; + settings->m_ShowHiddenPins = m_showAllPins; } @@ -608,11 +608,11 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->SetShowPinsElectricalType( m_showPinElectricalTypeName ); + settings->m_ShowPinsElectricalType = m_showPinElectricalTypeName; // Hidden elements must be editable - settings->SetShowHiddenText( true ); - settings->SetShowHiddenPins( true ); + settings->m_ShowHiddenText = true; + settings->m_ShowHiddenPins = true; } diff --git a/eeschema/libedit/block_libedit.cpp b/eeschema/libedit/block_libedit.cpp index bd56ef855a..1bc517e078 100644 --- a/eeschema/libedit/block_libedit.cpp +++ b/eeschema/libedit/block_libedit.cpp @@ -621,8 +621,6 @@ void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& if( component == NULL ) return; - int unit = parent->GetUnit(); - int convert = parent->GetConvert(); auto cp = parent->GetCrossHairPosition( true ); auto lcp = block->GetLastCursorPosition(); diff --git a/eeschema/libedit/lib_edit_frame.cpp b/eeschema/libedit/lib_edit_frame.cpp index b02bdaf45f..618ae285b5 100644 --- a/eeschema/libedit/lib_edit_frame.cpp +++ b/eeschema/libedit/lib_edit_frame.cpp @@ -68,6 +68,7 @@ #include #include #include +#include int LIB_EDIT_FRAME:: m_unit = 1; int LIB_EDIT_FRAME:: m_convert = 1; @@ -377,7 +378,11 @@ void LIB_EDIT_FRAME::UpdatePartSelectList() void LIB_EDIT_FRAME::OnShowElectricalType( wxCommandEvent& event ) { - SetShowElectricalType( not GetShowElectricalType() ); + m_showPinElectricalTypeName = !m_showPinElectricalTypeName; + + // Update canvas + GetRenderSettings()->m_ShowPinsElectricalType = m_showPinElectricalTypeName; + GetCanvas()->GetView()->MarkDirty(); GetCanvas()->Refresh(); } @@ -568,7 +573,12 @@ void LIB_EDIT_FRAME::OnSelectPart( wxCommandEvent& event ) m_lastDrawItem = NULL; m_unit = i + 1; - m_canvas->Refresh(); + + // Update canvas + GetRenderSettings()->m_ShowUnit = m_unit; + GetCanvas()->GetView()->MarkDirty(); + GetCanvas()->Refresh(); + DisplayCmpDoc(); } @@ -621,7 +631,11 @@ void LIB_EDIT_FRAME::OnSelectBodyStyle( wxCommandEvent& event ) m_convert = 2; m_lastDrawItem = NULL; - m_canvas->Refresh(); + + // Update canvas + GetRenderSettings()->m_ShowConvert = m_convert; + GetCanvas()->GetView()->MarkDirty(); + GetCanvas()->Refresh(); } @@ -1691,9 +1705,15 @@ void LIB_EDIT_FRAME::SetScreen( BASE_SCREEN* aScreen ) void LIB_EDIT_FRAME::RebuildView() { - auto view = GetCanvas()->GetView(); + KIGFX::SCH_VIEW* view = GetCanvas()->GetView(); + view->Clear(); + + GetRenderSettings()->m_ShowUnit = m_unit; + GetRenderSettings()->m_ShowConvert = m_convert; + view->DisplayComponent( m_my_part ); + view->HideWorksheet(); view->ClearHiddenFlags(); } diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 716e05fb9d..4b3eeef997 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -409,12 +409,19 @@ void SCH_BASE_FRAME::RedrawScreen2( const wxPoint& posBefore ) GetGalCanvas()->Refresh(); } -SCH_DRAW_PANEL *SCH_BASE_FRAME::GetCanvas() const +SCH_DRAW_PANEL* SCH_BASE_FRAME::GetCanvas() const { return static_cast( GetGalCanvas() ); } +KIGFX::SCH_RENDER_SETTINGS* SCH_BASE_FRAME::GetRenderSettings() +{ + KIGFX::PAINTER* painter = GetGalCanvas()->GetView()->GetPainter(); + return static_cast( painter->GetSettings() ); +} + + bool SCH_BASE_FRAME::HandleBlockBegin( wxDC* aDC, EDA_KEY aKey, const wxPoint& aPosition, int aExplicitCommand ) { diff --git a/eeschema/sch_base_frame.h b/eeschema/sch_base_frame.h index de00e4688e..f7084e4442 100644 --- a/eeschema/sch_base_frame.h +++ b/eeschema/sch_base_frame.h @@ -33,6 +33,11 @@ #include "template_fieldnames.h" +namespace KIGFX +{ + class SCH_RENDER_SETTINGS; +} + class PAGE_INFO; class TITLE_BLOCK; class LIB_VIEW_FRAME; @@ -97,9 +102,11 @@ public: virtual ~SCH_BASE_FRAME(); - SCH_DRAW_PANEL *GetCanvas() const override; + SCH_DRAW_PANEL* GetCanvas() const override; SCH_SCREEN* GetScreen() const override; + KIGFX::SCH_RENDER_SETTINGS* GetRenderSettings(); + /** * @return the increment value of the position of an item * for the repeat command diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 548798f3ef..f8714b1779 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -75,7 +75,9 @@ namespace KIGFX { }; -SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() +SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : + m_ShowUnit( 0 ), + m_ShowConvert( 0 ) { ImportLegacyColors( nullptr ); } @@ -209,9 +211,35 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) } +bool SCH_PAINTER::isUnitAndConversionShown( const LIB_ITEM* aItem ) +{ + if( m_schSettings.m_ShowUnit // showing a specific unit + && aItem->GetUnit() // item is unit-specific + && aItem->GetUnit() != m_schSettings.m_ShowUnit ) + { + return false; + } + + if( m_schSettings.m_ShowConvert // showing a specific conversion + && aItem->GetConvert() // item is conversion-specific + && aItem->GetConvert() != m_schSettings.m_ShowConvert ) + { + return false; + } + + return true; +} + + void SCH_PAINTER::draw( LIB_PART *aComp, int aLayer, bool aDrawFields, int aUnit, int aConvert, std::vector* danglingPinFlags ) { + if( !aUnit ) + aUnit = m_schSettings.m_ShowUnit; + + if( !aConvert ) + aConvert = m_schSettings.m_ShowConvert; + size_t pinIndex = 0; auto visitItem = [&]( LIB_ITEM& item, bool aBackground ) @@ -258,7 +286,7 @@ void SCH_PAINTER::draw( LIB_ALIAS *aAlias, int aLayer ) { LIB_PART* comp = aAlias->GetPart(); - draw( comp, aLayer, false, aAlias->GetTmpUnit(), aAlias->GetTmpConversion() ); + draw( comp, aLayer, false ); LIB_FIELDS fields; comp->GetFields( fields ); @@ -281,13 +309,16 @@ static VECTOR2D mapCoords( const wxPoint& aCoord ) } -void SCH_PAINTER::draw ( LIB_RECTANGLE *aComp, int aLayer ) +void SCH_PAINTER::draw( LIB_RECTANGLE *aRect, int aLayer ) { - defaultColors(aComp); + if( !isUnitAndConversionShown( aRect ) ) + return; + + defaultColors(aRect); + //m_gal->SetIsStroke( true ); - m_gal->SetLineWidth( aComp->GetPenSize() ); - m_gal->DrawRectangle( mapCoords( aComp->GetPosition() ), - mapCoords( aComp->GetEnd() ) ); + m_gal->SetLineWidth( aRect->GetPenSize() ); + m_gal->DrawRectangle( mapCoords( aRect->GetPosition() ), mapCoords( aRect->GetEnd() ) ); } @@ -322,37 +353,46 @@ void SCH_PAINTER::defaultColors ( const LIB_ITEM *aItem ) } } -void SCH_PAINTER::draw ( LIB_CIRCLE *aCircle, int aLayer ) +void SCH_PAINTER::draw( LIB_CIRCLE *aCircle, int aLayer ) { - defaultColors(aCircle); - m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() ); + if( !isUnitAndConversionShown( aCircle ) ) + return; + + defaultColors(aCircle); + + m_gal->DrawCircle( mapCoords( aCircle->GetPosition() ), aCircle->GetRadius() ); } -void SCH_PAINTER::draw ( LIB_ARC *aArc, int aLayer ) +void SCH_PAINTER::draw( LIB_ARC *aArc, int aLayer ) { - defaultColors(aArc); + if( !isUnitAndConversionShown( aArc ) ) + return; - int sai = aArc->GetFirstRadiusAngle(); - int eai = aArc->GetSecondRadiusAngle(); + defaultColors(aArc); - if (TRANSFORM().MapAngles( &sai, &eai )) - std::swap(sai, eai); + int sai = aArc->GetFirstRadiusAngle(); + int eai = aArc->GetSecondRadiusAngle(); - double sa = (double) sai * M_PI / 1800.0; - double ea = (double) eai * M_PI / 1800.0 ; + if (TRANSFORM().MapAngles( &sai, &eai )) + std::swap(sai, eai); - VECTOR2D pos = mapCoords( aArc->GetPosition() ); + double sa = (double) sai * M_PI / 1800.0; + double ea = (double) eai * M_PI / 1800.0 ; - m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea); - /*m_gal->SetStrokeColor(COLOR4D(1.0,0,0,1.0)); - m_gal->DrawLine ( pos - VECTOR2D(20, 20), pos + VECTOR2D(20, 20)); - m_gal->DrawLine ( pos - VECTOR2D(-20, 20), pos + VECTOR2D(-20, 20));*/ + VECTOR2D pos = mapCoords( aArc->GetPosition() ); + m_gal->DrawArc( pos, aArc->GetRadius(), sa, ea); + /*m_gal->SetStrokeColor(COLOR4D(1.0,0,0,1.0)); + m_gal->DrawLine ( pos - VECTOR2D(20, 20), pos + VECTOR2D(20, 20)); + m_gal->DrawLine ( pos - VECTOR2D(-20, 20), pos + VECTOR2D(-20, 20));*/ } void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer ) { + if( !isUnitAndConversionShown( aField ) ) + return; + COLOR4D color; switch( aField->GetId() ) @@ -364,7 +404,7 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer ) if( !aField->IsVisible() ) { - if( m_schSettings.m_showHiddenText ) + if( m_schSettings.m_ShowHiddenText ) color = m_schSettings.GetLayerColor( LAYER_HIDDEN ); else return; @@ -395,7 +435,11 @@ void SCH_PAINTER::draw( LIB_FIELD *aField, int aLayer ) void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer ) { + if( !isUnitAndConversionShown( aLine ) ) + return; + defaultColors( aLine ); + std::deque vtx; for( auto p : aLine->GetPolyPoints() ) @@ -410,11 +454,14 @@ void SCH_PAINTER::draw( LIB_POLYLINE *aLine, int aLayer ) void SCH_PAINTER::draw( LIB_TEXT *aText, int aLayer ) { + if( !isUnitAndConversionShown( aText ) ) + return; + COLOR4D color; if( aText->IsVisible() ) color = m_schSettings.GetLayerColor( LAYER_NOTES ); - else if( m_schSettings.m_showHiddenText ) + else if( m_schSettings.m_ShowHiddenText ) color = m_schSettings.GetLayerColor( LAYER_HIDDEN ); else return; @@ -454,13 +501,16 @@ static int ExternalPinDecoSize( const LIB_PIN &aPin ) void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling ) { + if( !isUnitAndConversionShown( aPin ) ) + return; + COLOR4D color = m_schSettings.GetLayerColor( LAYER_PIN ); if( !aPin->IsVisible() ) { color = m_schSettings.GetLayerColor( LAYER_HIDDEN ); - if( !m_schSettings.m_showHiddenPins ) + if( !m_schSettings.m_ShowHiddenPins ) return; } @@ -639,7 +689,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer, bool isDangling ) text [BELOW] = aPin->GetNumber(); } - if( m_schSettings.m_showPinsElectricalType ) + if( m_schSettings.m_ShowPinsElectricalType ) { size [OUTSIDE] = std::max( aPin->GetNameTextSize() * 3 / 4, Millimeter2iu( 0.7 ) ); thickness[OUTSIDE] = size[OUTSIDE] / 6; @@ -844,7 +894,7 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer ) if( !aText->IsVisible() ) { - if( m_schSettings.m_showHiddenText ) + if( m_schSettings.m_ShowHiddenText ) color = m_schSettings.GetLayerColor( LAYER_HIDDEN ); else return; @@ -975,7 +1025,7 @@ void SCH_PAINTER::draw( SCH_FIELD *aField, int aLayer ) if( !aField->IsVisible() ) { - if( m_schSettings.m_showHiddenText ) + if( m_schSettings.m_ShowHiddenText ) color = m_schSettings.GetLayerColor( LAYER_HIDDEN ); else return; diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 43a6247936..6df6b06764 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -38,7 +38,6 @@ class LIB_ARC; class LIB_FIELD; class LIB_TEXT; class SCH_COMPONENT; -class SCH_PIN; class SCH_FIELD; class SCH_JUNCTION; class SCH_LABEL; @@ -77,10 +76,6 @@ public: /// @copydoc RENDER_SETTINGS::GetColor() virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override; - void SetShowHiddenText( bool aShow ) { m_showHiddenText = aShow; } - void SetShowHiddenPins( bool aShow ) { m_showHiddenPins = aShow; } - void SetShowPinsElectricalType( bool aShow ) { m_showPinsElectricalType = aShow; } - bool IsBackgroundDark() const override { auto luma = m_layerColors[ LAYER_SCHEMATIC_BACKGROUND ].GetBrightness(); @@ -88,10 +83,12 @@ public: return luma < 0.5; } -private: - bool m_showHiddenText; - bool m_showHiddenPins; - bool m_showPinsElectricalType; + int m_ShowUnit; // Show all units if 0 + int m_ShowConvert; // Show all conversions if 0 + + bool m_ShowHiddenText; + bool m_ShowHiddenPins; + bool m_ShowPinsElectricalType; }; @@ -132,7 +129,6 @@ private: void draw( LIB_FIELD *, int ); void draw( LIB_TEXT *, int ); void draw( SCH_COMPONENT *, int ); - void draw( SCH_PIN *, int ); void draw( SCH_JUNCTION *, int ); void draw( SCH_FIELD *, int ); void draw( SCH_TEXT *, int ); @@ -147,8 +143,9 @@ private: void draw( SCH_LINE *, int ); void draw( SCH_BUS_ENTRY_BASE *aEntry, int aLayer ); + bool isUnitAndConversionShown( const LIB_ITEM* aItem ); - void defaultColors( const LIB_ITEM *aItem ); + void defaultColors( const LIB_ITEM* aItem ); void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index d5f147c192..eff1f4ffe0 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -218,7 +218,11 @@ void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert ) m_convert = aConvert > 0 ? aConvert : 1; m_selection_changed = false; - updatePreviewSymbol(); + // Update canvas + GetRenderSettings()->m_ShowUnit = m_unit; + GetRenderSettings()->m_ShowConvert = m_convert; + GetCanvas()->GetView()->MarkDirty(); + GetCanvas()->Refresh(); } @@ -262,8 +266,8 @@ void LIB_VIEW_FRAME::updatePreviewSymbol() if( alias ) { - alias->SetTmpUnit( m_unit ); - alias->SetTmpConversion( m_convert ); + GetRenderSettings()->m_ShowUnit = m_unit; + GetRenderSettings()->m_ShowConvert = m_convert; view->Add( alias ); m_previewItem = alias; @@ -339,12 +343,12 @@ void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event ) void LIB_VIEW_FRAME::OnShowElectricalType( wxCommandEvent& event ) { - SetShowElectricalType( not GetShowElectricalType() ); + m_showPinElectricalTypeName = !m_showPinElectricalTypeName; - auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); - KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); - settings->SetShowPinsElectricalType( GetShowElectricalType() ); - GetCanvas()->ForceRefresh(); + // Update canvas + GetRenderSettings()->m_ShowPinsElectricalType = m_showPinElectricalTypeName; + GetCanvas()->GetView()->MarkDirty(); + GetCanvas()->Refresh(); } diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp index c571a46187..9363638a3d 100644 --- a/eeschema/widgets/symbol_preview_widget.cpp +++ b/eeschema/widgets/symbol_preview_widget.cpp @@ -27,6 +27,7 @@ #include #include #include +#include SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ) : wxPanel( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ), @@ -80,6 +81,7 @@ void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText ) void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit ) { KIGFX::VIEW* view = m_preview->GetView(); + auto settings = static_cast( view->GetPainter()->GetSettings() ); LIB_ALIAS* alias = nullptr; try @@ -109,7 +111,7 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit ) if( part->IsMulti() && aUnit == 0 ) aUnit = 1; - alias->SetTmpUnit( aUnit ); + settings->m_ShowUnit = aUnit; view->Add( alias ); m_previewItem = alias;