From b9596a0a5d25ef3e4350f6d47d5fda4253f180c4 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 30 Sep 2021 15:44:35 +0100 Subject: [PATCH] Update dangling flags in color settings' preview. --- .../dialogs/panel_eeschema_color_settings.cpp | 62 ++++++++++++------- eeschema/sch_painter.cpp | 16 ++--- eeschema/sch_painter.h | 2 + eeschema/sch_preview_panel.cpp | 6 +- eeschema/symbol_editor/symbol_edit_frame.cpp | 1 + 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/eeschema/dialogs/panel_eeschema_color_settings.cpp b/eeschema/dialogs/panel_eeschema_color_settings.cpp index 9f549144d8..155bb8c417 100644 --- a/eeschema/dialogs/panel_eeschema_color_settings.cpp +++ b/eeschema/dialogs/panel_eeschema_color_settings.cpp @@ -223,21 +223,12 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::onNewThemeSelected() } -class SCH_BUS_WIRE_ENTRY_PREVIEW_ITEM : public SCH_BUS_WIRE_ENTRY -{ -public: - SCH_BUS_WIRE_ENTRY_PREVIEW_ITEM() : - SCH_BUS_WIRE_ENTRY() - { - m_isDanglingStart = m_isDanglingEnd = false; - }; -}; - - void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() { KIGFX::VIEW* view = m_preview->GetView(); + std::vector endPoints; + m_page = new PAGE_INFO( PAGE_INFO::Custom ); m_titleBlock = new TITLE_BLOCK; m_titleBlock->SetTitle( _( "Color Preview" ) ); @@ -246,11 +237,11 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() m_page->SetHeightMils( 5000 ); m_page->SetWidthMils( 6000 ); - m_drawingSheet = new DS_PROXY_VIEW_ITEM((int) IU_PER_MILS, m_page, nullptr, m_titleBlock ); + m_drawingSheet = new DS_PROXY_VIEW_ITEM( (int) IU_PER_MILS, m_page, nullptr, m_titleBlock ); m_drawingSheet->SetColorLayer( LAYER_SCHEMATIC_DRAWINGSHEET ); view->Add( m_drawingSheet ); - // NOTE: It would be nice to parse a schematic file here. + // TODO: It would be nice to parse a schematic file here. // This is created from the color_settings.sch file in demos folder auto addItem = [&]( EDA_ITEM* aItem ) @@ -276,7 +267,7 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() { LAYER_NOTES, { { 2950, 2300 }, { 2350, 2300 } } } }; - for( const auto& line : lines ) + for( const std::pair>& line : lines ) { SCH_LINE* wire = new SCH_LINE; wire->SetLayer( line.first ); @@ -293,11 +284,11 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() nc->SetPosition( MILS_POINT( 2525, 1300 ) ); addItem( nc ); - SCH_BUS_WIRE_ENTRY* e1 = new SCH_BUS_WIRE_ENTRY_PREVIEW_ITEM; + SCH_BUS_WIRE_ENTRY* e1 = new SCH_BUS_WIRE_ENTRY; e1->SetPosition( MILS_POINT( 1850, 1400 ) ); addItem( e1 ); - SCH_BUS_WIRE_ENTRY* e2 = new SCH_BUS_WIRE_ENTRY_PREVIEW_ITEM; + SCH_BUS_WIRE_ENTRY* e2 = new SCH_BUS_WIRE_ENTRY; e2->SetPosition( MILS_POINT( 1850, 2500 ) ); addItem( e2 ); @@ -315,7 +306,7 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() t3->SetIsDangling( false ); addItem( t3 ); - SCH_GLOBALLABEL* t4 = new SCH_GLOBALLABEL( MILS_POINT( 1750, 1400 ), wxT( "GLOBAL[3..0]" ) ); + SCH_GLOBALLABEL* t4 = new SCH_GLOBALLABEL( MILS_POINT( 1750, 1400 ), wxT( "GLOBAL[0..3]" ) ); t4->SetLabelSpinStyle( LABEL_SPIN_STYLE::SPIN::LEFT ); t4->SetIsDangling( false ); addItem( t4 ); @@ -331,6 +322,12 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() t2->SetSelected(); { + auto mapLibItemPosition = + []( const wxPoint& aLibPosition ) -> wxPoint + { + return wxPoint( aLibPosition.x, -aLibPosition.y ); + }; + LIB_SYMBOL* symbol = new LIB_SYMBOL( wxEmptyString ); wxPoint p( 2625, -1600 ); @@ -365,35 +362,38 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() LIB_PIN* pin = new LIB_PIN( symbol ); - pin->SetPosition( MILS_POINT( p.x - 200, p.y + 100 ) ); + pin->SetPosition( MILS_POINT( p.x - 300, p.y + 100 ) ); pin->SetLength( Mils2iu( 100 ) ); - pin->SetOrientation( PIN_LEFT ); + pin->SetOrientation( PIN_RIGHT ); pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT ); pin->SetNumber( wxT( "1" ) ); pin->SetName( wxT( "-" ) ); + endPoints.emplace_back( PIN_END, pin, mapLibItemPosition( pin->GetPosition() ) ); symbol->AddDrawItem( pin ); pin = new LIB_PIN( symbol ); - pin->SetPosition( MILS_POINT( p.x - 200, p.y - 100 ) ); + pin->SetPosition( MILS_POINT( p.x - 300, p.y - 100 ) ); pin->SetLength( Mils2iu( 100 ) ); - pin->SetOrientation( PIN_LEFT ); + pin->SetOrientation( PIN_RIGHT ); pin->SetType( ELECTRICAL_PINTYPE::PT_INPUT ); pin->SetNumber( wxT( "2" ) ); pin->SetName( wxT( "+" ) ); + endPoints.emplace_back( PIN_END, pin, mapLibItemPosition( pin->GetPosition() ) ); symbol->AddDrawItem( pin ); pin = new LIB_PIN( symbol ); - pin->SetPosition( MILS_POINT( p.x + 200, p.y ) ); + pin->SetPosition( MILS_POINT( p.x + 300, p.y ) ); pin->SetLength( Mils2iu( 100 ) ); - pin->SetOrientation( PIN_RIGHT ); + pin->SetOrientation( PIN_LEFT ); pin->SetType( ELECTRICAL_PINTYPE::PT_OUTPUT ); pin->SetNumber( wxT( "3" ) ); pin->SetName( wxT( "OUT" ) ); + endPoints.emplace_back( PIN_END, pin, mapLibItemPosition( pin->GetPosition() ) ); symbol->AddDrawItem( pin ); addItem( symbol ); @@ -409,6 +409,22 @@ void PANEL_EESCHEMA_COLOR_SETTINGS::createPreviewItems() SCH_SHEET_PIN* sp = new SCH_SHEET_PIN( s, MILS_POINT( 4500, 1500 ), wxT( "SHEET PIN" ) ); addItem( sp ); + for( EDA_ITEM* item : m_previewItems ) + { + SCH_ITEM* sch_item = dynamic_cast( item ); + + if( sch_item && sch_item->IsConnectable() ) + sch_item->GetEndPoints( endPoints ); + } + + for( EDA_ITEM* item : m_previewItems ) + { + SCH_ITEM* sch_item = dynamic_cast( item ); + + if( sch_item && sch_item->IsConnectable() ) + sch_item->UpdateDanglingState( endPoints, nullptr ); + } + zoomFitPreview(); } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index cb716d9600..796aa1caef 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -70,6 +70,7 @@ namespace KIGFX { SCH_RENDER_SETTINGS::SCH_RENDER_SETTINGS() : + m_IsSymbolEditor( false ), m_ShowUnit( 0 ), m_ShowConvert( 0 ), m_ShowHiddenText( true ), @@ -783,11 +784,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) return; bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS; -#if 1 - bool dangling = !m_schematic || aPin->HasFlag(IS_DANGLING ); -#else - bool dangling = aPin->HasFlag( IS_DANGLING ); -#endif + bool dangling = m_schSettings.m_IsSymbolEditor || aPin->HasFlag( IS_DANGLING ); if( drawingShadows && !aPin->IsSelected() ) return; @@ -988,7 +985,7 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) nameStrokeWidth = Clamp_Text_PenSize( nameStrokeWidth, aPin->GetNameTextSize(), false ); numStrokeWidth = Clamp_Text_PenSize( numStrokeWidth, aPin->GetNumberTextSize(), false ); - #define PIN_TEXT_MARGIN 4.0 + int PIN_TEXT_MARGIN = KiROUND( 24 * m_schSettings.m_TextOffsetRatio ); // Four locations around a pin where text can be drawn enum { INSIDE = 0, OUTSIDE, ABOVE, BELOW }; @@ -1810,14 +1807,13 @@ void SCH_PAINTER::draw( const SCH_NO_CONNECT *aNC, int aLayer ) void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer ) { - SCH_LINE line; - bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS; + SCH_LAYER_ID layer = aEntry->Type() == SCH_BUS_WIRE_ENTRY_T ? LAYER_WIRE : LAYER_BUS; + SCH_LINE line( wxPoint(), layer ); + bool drawingShadows = aLayer == LAYER_SELECTION_SHADOWS; if( drawingShadows && !aEntry->IsSelected() ) return; - line.SetLayer( aEntry->Type() == SCH_BUS_WIRE_ENTRY_T ? LAYER_WIRE : LAYER_BUS ); - if( aEntry->IsSelected() ) line.SetSelected(); else if( aEntry->IsBrightened() ) diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 3ecf231c8e..83d61a76f6 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -105,6 +105,8 @@ public: const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_SCHEMATIC_CURSOR ]; } + bool m_IsSymbolEditor; + int m_ShowUnit; // Show all units if 0 int m_ShowConvert; // Show all conversions if 0 diff --git a/eeschema/sch_preview_panel.cpp b/eeschema/sch_preview_panel.cpp index 7af6bc06e9..a7a9b0e469 100644 --- a/eeschema/sch_preview_panel.cpp +++ b/eeschema/sch_preview_panel.cpp @@ -53,7 +53,11 @@ SCH_PREVIEW_PANEL::SCH_PREVIEW_PANEL( wxWindow* aParentWindow, wxWindowID aWindo m_gal->SetWorldUnitLength( SCH_WORLD_UNIT ); m_painter.reset( new KIGFX::SCH_PAINTER( m_gal ) ); - m_painter->GetSettings()->LoadColors( Pgm().GetSettingsManager().GetColorSettings() ); + + auto* renderSettings = static_cast( m_painter->GetSettings() ); + renderSettings->LoadColors( Pgm().GetSettingsManager().GetColorSettings() ); + renderSettings->m_ShowPinsElectricalType = false; + renderSettings->m_TextOffsetRatio = 0.30; m_view->SetPainter( m_painter.get() ); // This fixes the zoom in and zoom out limits: diff --git a/eeschema/symbol_editor/symbol_edit_frame.cpp b/eeschema/symbol_editor/symbol_edit_frame.cpp index d11c3f3017..aaa8635784 100644 --- a/eeschema/symbol_editor/symbol_edit_frame.cpp +++ b/eeschema/symbol_editor/symbol_edit_frame.cpp @@ -137,6 +137,7 @@ SYMBOL_EDIT_FRAME::SYMBOL_EDIT_FRAME( KIWAY* aKiway, wxWindow* aParent ) : GetCanvas()->GetViewControls()->SetCrossHairCursorPosition( VECTOR2D( 0, 0 ), false ); GetRenderSettings()->LoadColors( GetColorSettings() ); + GetRenderSettings()->m_IsSymbolEditor = true; GetCanvas()->GetGAL()->SetAxesColor( m_colorSettings->GetColor( LAYER_SCHEMATIC_GRID_AXES ) ); setupTools();