diff --git a/eeschema/dialogs/panel_eeschema_display_options.cpp b/eeschema/dialogs/panel_eeschema_display_options.cpp index 5871fbb566..2b8d3285b6 100644 --- a/eeschema/dialogs/panel_eeschema_display_options.cpp +++ b/eeschema/dialogs/panel_eeschema_display_options.cpp @@ -24,7 +24,9 @@ #include #include +#include #include +#include #include #include @@ -108,6 +110,12 @@ 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(); + return true; } diff --git a/eeschema/dialogs/panel_libedit_settings.cpp b/eeschema/dialogs/panel_libedit_settings.cpp index 427d005fe3..7f8a8edcf7 100644 --- a/eeschema/dialogs/panel_libedit_settings.cpp +++ b/eeschema/dialogs/panel_libedit_settings.cpp @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "panel_libedit_settings.h" @@ -81,6 +83,12 @@ 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(); + return true; } diff --git a/eeschema/eeschema_config.cpp b/eeschema/eeschema_config.cpp index 36f9cf6e86..5500454727 100644 --- a/eeschema/eeschema_config.cpp +++ b/eeschema/eeschema_config.cpp @@ -489,6 +489,11 @@ void SCH_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) } } + + auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); + KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); + settings->SetShowPinsElectricalType( false ); + settings->SetShowHiddenPins( m_showAllPins ); } @@ -600,6 +605,11 @@ void LIB_EDIT_FRAME::LoadSettings( wxConfigBase* aCfg ) DBG( printf( "templatefieldnames parsing error: '%s'\n", TO_UTF8( e.What() ) ); ) } } + + auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); + KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); + settings->SetShowPinsElectricalType( m_showPinElectricalTypeName ); + settings->SetShowHiddenPins( true ); // Hidden pins must be editable } diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 5eda6b0f76..180a878f85 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -441,7 +441,7 @@ static int ExternalPinDecoSize( const LIB_PIN &aPin ) void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) { - if( !aPin->IsVisible() ) + if( !aPin->IsVisible() && !m_schSettings.m_showHiddenPins ) return; const COLOR4D& color = m_schSettings.GetLayerColor( LAYER_PIN ); @@ -452,7 +452,7 @@ void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) int shape = aPin->GetShape(); int orient = aPin->GetOrientation(); - switch( orient ) + switch( orient ) { case PIN_UP: //printf("pinUp\n"); @@ -474,64 +474,65 @@ void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) p0 = VECTOR2I( pos.x + len, pos.y ); dir = VECTOR2I(-1, 0); break; - } //printf("pin %p p0 %d %d pos %d %d len %d\n", aPin, p0.x, p0.y, pos.x, pos.y, len); - VECTOR2D pc; + VECTOR2D pc; - m_gal->SetIsStroke ( true ); - m_gal->SetIsFill ( false ); - m_gal->SetLineWidth ( width ); - m_gal->SetStrokeColor ( color ); - m_gal->SetFontBold ( false ); - m_gal->SetFontItalic ( false ); + m_gal->SetIsStroke( true ); + m_gal->SetIsFill( false ); + m_gal->SetLineWidth( width ); + m_gal->SetStrokeColor( color ); + m_gal->SetFontBold( false ); + m_gal->SetFontItalic( false ); - const int radius = ExternalPinDecoSize( *aPin ); - const int clock_size = InternalPinDecoSize( *aPin ); + const int radius = ExternalPinDecoSize( *aPin ); + const int clock_size = InternalPinDecoSize( *aPin ); - if(shape == PINSHAPE_INVERTED) + if( shape == PINSHAPE_INVERTED ) { - - m_gal->DrawCircle ( p0 + dir * radius, radius ); - m_gal->DrawLine ( p0 + dir * ( 2 * radius ), pos ); - } else if (shape == PINSHAPE_FALLING_EDGE_CLOCK ) - { - - pc = p0 + dir * clock_size ; - - triLine( p0 + VECTOR2D ( dir.y, -dir.x) * clock_size, - pc, - p0 + VECTOR2D ( -dir.y, dir.x) * clock_size - ); - - m_gal->DrawLine ( pos, pc ); - } - else { - //printf("DrawLPin\n"); - m_gal->DrawLine ( p0, pos ); - //m_gal->DrawLine ( p0, pos+dir.Perpendicular() * radius); - } - - if(shape == PINSHAPE_CLOCK) - { - if (!dir.y) + m_gal->DrawCircle( p0 + dir * radius, radius ); + m_gal->DrawLine( p0 + dir * ( 2 * radius ), pos ); + } + else if( shape == PINSHAPE_FALLING_EDGE_CLOCK ) { - triLine (p0 + VECTOR2D( 0, clock_size ), - p0 + VECTOR2D( -dir.x * clock_size, 0), - p0 + VECTOR2D( 0, -clock_size )); + pc = p0 + dir * clock_size ; - } else { - triLine ( p0 + VECTOR2D ( clock_size, 0 ), - p0 + VECTOR2D ( 0, -dir.y * clock_size ), - p0 + VECTOR2D ( -clock_size, 0 )); + triLine( p0 + VECTOR2D( dir.y, -dir.x) * clock_size, + pc, + p0 + VECTOR2D( -dir.y, dir.x) * clock_size + ); + + m_gal->DrawLine( pos, pc ); + } + else + { + //printf("DrawLPin\n"); + m_gal->DrawLine ( p0, pos ); + //m_gal->DrawLine ( p0, pos+dir.Perpendicular() * radius); } - } - if( shape == PINSHAPE_INPUT_LOW ) - { - if(!dir.y) + if(shape == PINSHAPE_CLOCK) + { + if (!dir.y) + { + triLine ( p0 + VECTOR2D( 0, clock_size ), + p0 + VECTOR2D( -dir.x * clock_size, 0), + p0 + VECTOR2D( 0, -clock_size )); + + } + else + { + triLine ( p0 + VECTOR2D( clock_size, 0 ), + p0 + VECTOR2D( 0, -dir.y * clock_size ), + p0 + VECTOR2D( -clock_size, 0 )); + } + } + + if( shape == PINSHAPE_INPUT_LOW ) + { + if(!dir.y) { triLine ( p0 + VECTOR2D(dir.x, 0) * radius * 2, p0 + VECTOR2D(dir.x, -1) * radius * 2, @@ -603,11 +604,8 @@ void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) #define PIN_TEXT_MARGIN 4 - - int name_offset = PIN_TEXT_MARGIN + - ( nameLineWidth + GetDefaultLineThickness() ) / 2; - int num_offset = - PIN_TEXT_MARGIN - - ( numLineWidth + GetDefaultLineThickness() ) / 2; + int name_offset = PIN_TEXT_MARGIN + ( nameLineWidth + GetDefaultLineThickness() ) / 2; + int num_offset = - PIN_TEXT_MARGIN - ( numLineWidth + GetDefaultLineThickness() ) / 2; //printf("numoffs %d w %d s %d\n", num_offset, numLineWidth,aPin->GetNumberTextSize() ); @@ -616,28 +614,29 @@ void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) if( textOffset ) /* Draw the text inside, but the pin numbers outside. */ { - m_gal->SetGlyphSize ( VECTOR2D ( nameSize, nameSize ) ); + m_gal->SetGlyphSize( VECTOR2D( nameSize, nameSize ) ); - if(showNames && (nameSize > 0)) + if( showNames && ( nameSize > 0 ) ) { - switch ( orient ) - { - case PIN_LEFT: - m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); - m_gal->StrokeText( aPin->GetName(), pos + VECTOR2D ( -textOffset - len, 0 ), 0 ); - break; - case PIN_RIGHT: - m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); - m_gal->StrokeText( aPin->GetName(), pos + VECTOR2D ( textOffset + len, 0 ), 0 ); - break; - case PIN_DOWN: - m_gal->SetHorizontalJustify ( GR_TEXT_HJUSTIFY_RIGHT ); - m_gal->StrokeText ( aPin->GetName(), pos + VECTOR2D ( 0, textOffset + len), M_PI / 2); - break; - case PIN_UP: - m_gal->SetHorizontalJustify ( GR_TEXT_HJUSTIFY_LEFT ); - m_gal->StrokeText ( aPin->GetName(), pos + VECTOR2D ( 0, - textOffset - len), M_PI / 2); - break; + switch( orient ) + { + case PIN_LEFT: + m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); + m_gal->StrokeText( aPin->GetName(), pos + VECTOR2D ( -textOffset - len, 0 ), 0 ); + break; + case PIN_RIGHT: + m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); + m_gal->StrokeText( aPin->GetName(), pos + VECTOR2D ( textOffset + len, 0 ), 0 ); + break; + case PIN_DOWN: + m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); + m_gal->StrokeText ( aPin->GetName(), pos + VECTOR2D ( 0, textOffset + len), M_PI / 2); + break; + case PIN_UP: + m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); + m_gal->StrokeText ( aPin->GetName(), pos + VECTOR2D ( 0, - textOffset - len), M_PI / 2); + break; + } } } @@ -645,29 +644,31 @@ void SCH_PAINTER::draw ( LIB_PIN *aPin, int aLayer ) int numSize = aPin->GetNumberTextSize(); - if(showNums && numSize > 0) - { - - m_gal->SetGlyphSize ( VECTOR2D ( numSize, numSize ) ); - + if( showNums && numSize > 0 ) + { + m_gal->SetGlyphSize( VECTOR2D ( numSize, numSize ) ); m_gal->SetStrokeColor( numColor ); - m_gal->SetGlyphSize ( VECTOR2D ( numSize, numSize ) ); + m_gal->SetGlyphSize( VECTOR2D ( numSize, numSize ) ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - switch(orient) + switch( orient ) { - case PIN_LEFT: - case PIN_RIGHT: + case PIN_LEFT: + case PIN_RIGHT: m_gal->StrokeText (stringPinNum, VECTOR2D( (p0.x + pos.x) / 2, p0.y + num_offset ), 0 ); break; - case PIN_DOWN: - case PIN_UP: - m_gal->StrokeText (stringPinNum, VECTOR2D ( p0.x - num_offset, (p0.y + pos.y) / 2), M_PI / 2); - break; + case PIN_DOWN: + case PIN_UP: + m_gal->StrokeText (stringPinNum, VECTOR2D( p0.x - num_offset, (p0.y + pos.y) / 2), M_PI / 2 ); + break; } - } + } + + if( m_schSettings.m_showPinsElectricalType ) + { + // JEY TODO: draw pin electrical type names } } diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 94ebf73aad..b716ce293f 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -76,6 +76,9 @@ public: /// @copydoc RENDER_SETTINGS::GetColor() virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override; + 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(); @@ -85,9 +88,9 @@ public: private: + bool m_showHiddenPins; bool m_showPinsElectricalType; - bool m_libraryEditorMode; - + }; diff --git a/eeschema/tool_viewlib.cpp b/eeschema/tool_viewlib.cpp index 17b967ea3a..a62b51b68d 100644 --- a/eeschema/tool_viewlib.cpp +++ b/eeschema/tool_viewlib.cpp @@ -95,16 +95,14 @@ void LIB_VIEW_FRAME::ReCreateHToolbar() m_mainToolBar->AddSeparator(); - m_selpartBox = new wxComboBox( m_mainToolBar, ID_LIBVIEW_SELECT_PART_NUMBER, - wxEmptyString, wxDefaultPosition, - wxSize( 150, -1 ), 0, NULL, wxCB_READONLY ); - m_mainToolBar->AddControl( m_selpartBox ); + m_unitChoice = new wxChoice( m_mainToolBar, ID_LIBVIEW_SELECT_PART_NUMBER, + wxDefaultPosition, wxSize( 150, -1 ) ); + m_mainToolBar->AddControl( m_unitChoice ); m_mainToolBar->AddSeparator(); m_mainToolBar->AddTool( ID_LIBVIEW_VIEWDOC, wxEmptyString, KiScaledBitmap( datasheet_xpm, this ), _( "View symbol documents" ) ); - m_mainToolBar->EnableTool( ID_LIBVIEW_VIEWDOC, false ); if( IsModal() ) { diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index ca88b51445..d5f147c192 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include // Save previous component library viewer state. wxString LIB_VIEW_FRAME::m_libraryName; @@ -68,7 +70,7 @@ BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME ) EVT_TOOL_RANGE( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, LIB_VIEW_FRAME::onSelectSymbolBodyStyle ) EVT_TOOL( ID_LIBVIEW_CMP_EXPORT_TO_SCHEMATIC, LIB_VIEW_FRAME::ExportToSchematicLibraryPart ) - EVT_COMBOBOX( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onSelectSymbolUnit ) + EVT_CHOICE( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onSelectSymbolUnit ) // listbox events EVT_LISTBOX( ID_LIBVIEW_LIB_LIST, LIB_VIEW_FRAME::ClickOnLibList ) @@ -83,48 +85,32 @@ BEGIN_EVENT_TABLE( LIB_VIEW_FRAME, EDA_DRAW_FRAME ) EVT_MENU( ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, LIB_VIEW_FRAME::OnShowElectricalType ) EVT_UPDATE_UI( ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT, LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton ) - EVT_UPDATE_UI( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, - LIB_VIEW_FRAME::onUpdateAlternateBodyStyleButton ) + EVT_UPDATE_UI( ID_LIBVIEW_DE_MORGAN_CONVERT_BUTT, LIB_VIEW_FRAME::onUpdateAltBodyStyleButton ) EVT_UPDATE_UI( ID_LIBVIEW_SHOW_ELECTRICAL_TYPE, LIB_VIEW_FRAME::OnUpdateElectricalType ) - EVT_UPDATE_UI( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::OnUpdateSelectionPartBox ) + EVT_UPDATE_UI( ID_LIBVIEW_SELECT_PART_NUMBER, LIB_VIEW_FRAME::onUpdateUnitChoice ) + EVT_UPDATE_UI( ID_LIBEDIT_VIEW_DOC, LIB_VIEW_FRAME::onUpdateDocButton ) END_EVENT_TABLE() -/* Note: - * LIB_VIEW_FRAME can be created in "modal mode", or as a usual frame. - * In modal mode: - * a tool to export the selected symbol is shown in the toolbar - * the style is wxFRAME_FLOAT_ON_PARENT - * Note: - * On windows, when the frame with type wxFRAME_FLOAT_ON_PARENT is displayed - * its parent frame is sometimes brought to the foreground when closing the - * LIB_VIEW_FRAME frame. - * If it still happens, it could be better to use wxSTAY_ON_TOP - * instead of wxFRAME_FLOAT_ON_PARENT - */ -#ifdef __WINDOWS__ -#define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT // could be wxSTAY_ON_TOP if issues -#else -#define MODAL_MODE_EXTRASTYLE wxFRAME_FLOAT_ON_PARENT -#endif +#define LIB_VIEW_NAME "ViewlibFrame" +#define LIB_VIEW_NAME_MODAL "ViewlibFrameModal" + +#define LIB_VIEW_STYLE ( KICAD_DEFAULT_DRAWFRAME_STYLE ) +#define LIB_VIEW_STYLE_MODAL ( KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT ) -#define LIB_VIEW_FRAME_NAME "ViewlibFrame" -#define LIB_VIEW_FRAME_NAME_MODAL "ViewlibFrameModal" LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrameType, const wxString& aLibraryName ) : SCH_BASE_FRAME( aKiway, aParent, aFrameType, _( "Library Browser" ), - wxDefaultPosition, wxDefaultSize, - aFrameType == FRAME_SCH_VIEWER_MODAL ? - aParent ? KICAD_DEFAULT_DRAWFRAME_STYLE | MODAL_MODE_EXTRASTYLE - : KICAD_DEFAULT_DRAWFRAME_STYLE | wxSTAY_ON_TOP - : KICAD_DEFAULT_DRAWFRAME_STYLE, - aFrameType == FRAME_SCH_VIEWER_MODAL ? - LIB_VIEW_FRAME_NAME_MODAL : LIB_VIEW_FRAME_NAME ) + wxDefaultPosition, wxDefaultSize, + aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_STYLE_MODAL : LIB_VIEW_STYLE, + aFrameType == FRAME_SCH_VIEWER_MODAL ? LIB_VIEW_NAME_MODAL : LIB_VIEW_NAME ), + m_libList( nullptr ), + m_cmpList( nullptr ), + m_previewItem( nullptr ) { - wxASSERT( aFrameType == FRAME_SCH_VIEWER || - aFrameType == FRAME_SCH_VIEWER_MODAL ); + wxASSERT( aFrameType == FRAME_SCH_VIEWER || aFrameType == FRAME_SCH_VIEWER_MODAL ); if( aFrameType == FRAME_SCH_VIEWER_MODAL ) SetModal( true ); @@ -132,7 +118,7 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame // Force the frame name used in config. the lib viewer frame has a name // depending on aFrameType (needed to identify the frame by wxWidgets), // but only one configuration is preferable. - m_configFrameName = LIB_VIEW_FRAME_NAME; + m_configFrameName = LIB_VIEW_NAME; // Give an icon wxIcon icon; @@ -140,8 +126,6 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame SetIcon( icon ); m_hotkeysDescrList = g_Viewlib_Hokeys_Descr; - m_libList = NULL; - m_cmpList = NULL; m_libListWidth = 200; m_cmpListWidth = 300; m_listPowerCmpOnly = false; @@ -223,6 +207,8 @@ LIB_VIEW_FRAME::LIB_VIEW_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame LIB_VIEW_FRAME::~LIB_VIEW_FRAME() { + if( m_previewItem ) + GetCanvas()->GetView()->Remove( m_previewItem ); } @@ -231,10 +217,12 @@ void LIB_VIEW_FRAME::SetUnitAndConvert( int aUnit, int aConvert ) m_unit = aUnit > 0 ? aUnit : 1; m_convert = aConvert > 0 ? aConvert : 1; m_selection_changed = false; + + updatePreviewSymbol(); } -LIB_ALIAS* LIB_VIEW_FRAME::getSelectedAlias() +LIB_ALIAS* LIB_VIEW_FRAME::getSelectedAlias() const { LIB_ALIAS* alias = NULL; @@ -247,7 +235,7 @@ LIB_ALIAS* LIB_VIEW_FRAME::getSelectedAlias() } -LIB_PART* LIB_VIEW_FRAME::getSelectedSymbol() +LIB_PART* LIB_VIEW_FRAME::getSelectedSymbol() const { LIB_PART* symbol = NULL; LIB_ALIAS* alias = getSelectedAlias(); @@ -259,7 +247,37 @@ LIB_PART* LIB_VIEW_FRAME::getSelectedSymbol() } -void LIB_VIEW_FRAME::onUpdateAlternateBodyStyleButton( wxUpdateUIEvent& aEvent ) +void LIB_VIEW_FRAME::updatePreviewSymbol() +{ + LIB_ALIAS* alias = getSelectedAlias(); + KIGFX::SCH_VIEW* view = GetCanvas()->GetView(); + + if( m_previewItem ) + { + view->Remove( m_previewItem ); + m_previewItem = nullptr; + } + + ClearMsgPanel(); + + if( alias ) + { + alias->SetTmpUnit( m_unit ); + alias->SetTmpConversion( m_convert ); + + view->Add( alias ); + m_previewItem = alias; + + AppendMsgPanel( _( "Name" ), alias->GetName(), BLUE, 6 ); + AppendMsgPanel( _( "Description" ), alias->GetDescription(), CYAN, 6 ); + AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKDARKGRAY ); + } + + GetCanvas()->ForceRefresh(); +} + + +void LIB_VIEW_FRAME::onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent ) { LIB_PART* symbol = getSelectedSymbol(); @@ -287,6 +305,8 @@ void LIB_VIEW_FRAME::onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent ) void LIB_VIEW_FRAME::OnCloseWindow( wxCloseEvent& Event ) { + GetCanvas()->StopDrawing(); + if( !IsModal() ) { Destroy(); @@ -320,7 +340,11 @@ void LIB_VIEW_FRAME::OnSetRelativeOffset( wxCommandEvent& event ) void LIB_VIEW_FRAME::OnShowElectricalType( wxCommandEvent& event ) { SetShowElectricalType( not GetShowElectricalType() ); - m_canvas->Refresh(); + + auto painter = dynamic_cast( GetCanvas()->GetView()->GetPainter() ); + KIGFX::SCH_RENDER_SETTINGS* settings = painter->GetSettings(); + settings->SetShowPinsElectricalType( GetShowElectricalType() ); + GetCanvas()->ForceRefresh(); } @@ -330,42 +354,32 @@ void LIB_VIEW_FRAME::OnUpdateElectricalType( wxUpdateUIEvent& aEvent ) } -void LIB_VIEW_FRAME::OnUpdateSelectionPartBox( wxUpdateUIEvent& aEvent ) +void LIB_VIEW_FRAME::onUpdateUnitChoice( wxUpdateUIEvent& aEvent ) { - LIB_PART* part = nullptr; - - if( m_libraryName.size() && m_entryName.size() ) - { - if( Prj().SchSymbolLibTable()->HasLibrary( m_libraryName ) ) - part = GetLibPart( LIB_ID( m_libraryName, m_entryName ) ); - } + LIB_PART* part = getSelectedSymbol(); int unit_count = 1; if( part ) unit_count = std::max( part->GetUnitCount(), 1 ); - m_selpartBox->Enable( unit_count > 1 ); + m_unitChoice->Enable( unit_count > 1 ); if( unit_count > 1 ) { // rebuild the unit list if it is not suitable - if( unit_count != (int)m_selpartBox->GetCount() ) + if( unit_count != (int)m_unitChoice->GetCount() ) { - m_selpartBox->Clear(); + m_unitChoice->Clear(); for( int ii = 0; ii < unit_count; ii++ ) - - m_selpartBox->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) ); - - m_selpartBox->SetSelection( m_unit > 0 ? m_unit - 1 : 0 ); + m_unitChoice->Append( wxString::Format( _( "Unit %c" ), 'A' + ii ) ); } + + m_unitChoice->SetSelection( std::max( 0, m_unit - 1 ) ); } - else - { - if( m_selpartBox->GetCount() ) - m_selpartBox->Clear(); - } + else if( m_unitChoice->GetCount() ) + m_unitChoice->Clear(); } @@ -598,7 +612,7 @@ void LIB_VIEW_FRAME::SetSelectedComponent( const wxString& aComponentName ) } Zoom_Automatique( false ); - m_canvas->Refresh(); + updatePreviewSymbol(); } } @@ -702,6 +716,8 @@ void LIB_VIEW_FRAME::OnActivate( wxActivateEvent& event ) if (changed) m_selection_changed = true; + updatePreviewSymbol(); + DisplayLibInfos(); } @@ -728,18 +744,17 @@ void LIB_VIEW_FRAME::SetFilter( const SCHLIB_FILTER* aFilter ) const BOX2I LIB_VIEW_FRAME::GetDocumentExtents() const { - LIB_PART* part = CurrentPart(); - - printf("part %p\n", part); + LIB_ALIAS* alias = getSelectedAlias(); + LIB_PART* part = alias ? alias->GetPart() : nullptr; if( !part ) { - return BOX2I( VECTOR2I(-100, -100), VECTOR2I( 200, 200 ) ); + return BOX2I( VECTOR2I(-200, -200), VECTOR2I( 400, 400 ) ); } else { - EDA_RECT boundingBox = part->GetUnitBoundingBox( m_unit, m_convert ); - return BOX2I( boundingBox.GetOrigin(), VECTOR2I( boundingBox.GetWidth(), boundingBox.GetHeight() ) ); + EDA_RECT bbox = part->GetUnitBoundingBox( m_unit, m_convert ); + return BOX2I( bbox.GetOrigin(), VECTOR2I( bbox.GetWidth(), bbox.GetHeight() ) ); } } \ No newline at end of file diff --git a/eeschema/viewlib_frame.h b/eeschema/viewlib_frame.h index 9200dece61..58219c58e9 100644 --- a/eeschema/viewlib_frame.h +++ b/eeschema/viewlib_frame.h @@ -141,13 +141,12 @@ public: * @param aConvert - convert; if invalid will be set to 1 */ void SetUnitAndConvert( int aUnit, int aConvert ); - int GetUnit( void ) { return m_unit; } - int GetConvert( void ) { return m_convert; } + int GetUnit() const { return m_unit; } + int GetConvert() const { return m_convert; } - bool GetShowElectricalType() { return m_showPinElectricalTypeName; } + bool GetShowElectricalType() const { return m_showPinElectricalTypeName; } void SetShowElectricalType( bool aShow ) { m_showPinElectricalTypeName = aShow; } - LIB_PART* CurrentPart() const; const BOX2I GetDocumentExtents() const override; private: @@ -165,21 +164,23 @@ private: bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) override; void DClickOnCmpList( wxCommandEvent& event ); - void onUpdateAlternateBodyStyleButton( wxUpdateUIEvent& aEvent ); + void onUpdateAltBodyStyleButton( wxUpdateUIEvent& aEvent ); void onUpdateNormalBodyStyleButton( wxUpdateUIEvent& aEvent ); + void onUpdateDocButton( wxUpdateUIEvent& aEvent ); void OnUpdateElectricalType( wxUpdateUIEvent& aEvent ); - void OnUpdateSelectionPartBox( wxUpdateUIEvent& aEvent ); + void onUpdateUnitChoice( wxUpdateUIEvent& aEvent ); void onSelectNextSymbol( wxCommandEvent& aEvent ); void onSelectPreviousSymbol( wxCommandEvent& aEvent ); void onViewSymbolDocument( wxCommandEvent& aEvent ); void onSelectSymbolBodyStyle( wxCommandEvent& aEvent ); void onSelectSymbolUnit( wxCommandEvent& aEvent ); - LIB_ALIAS* getSelectedAlias(); - LIB_PART* getSelectedSymbol(); + LIB_ALIAS* getSelectedAlias() const; + LIB_PART* getSelectedSymbol() const; + void updatePreviewSymbol(); // Private members: - wxComboBox* m_selpartBox; + wxChoice* m_unitChoice; // List of libraries (for selection ) wxListBox* m_libList; // The list of libs @@ -209,6 +210,8 @@ private: */ bool m_selection_changed; + LIB_ALIAS* m_previewItem; + /** * the option to show the pin electrical name in the component editor */ diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 1e01001610..b03e273d32 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -66,24 +66,15 @@ void LIB_VIEW_FRAME::OnSelectSymbol( wxCommandEvent& aEvent ) if( dlg.ShowQuasiModal() == wxID_CANCEL ) return; - /// @todo: The unit selection gets reset to 1 by SetSelectedComponent() so the unit - /// selection feature of the choose symbol dialog doesn't work. - LIB_ID id = dlg.GetSelectedLibId( &m_unit ); + int unit; + LIB_ID id = dlg.GetSelectedLibId( &unit ); - if( !id.IsValid() || id.GetLibNickname().empty() ) + if( !id.IsValid() ) return; - if( m_libraryName == id.GetLibNickname() ) - { - if( m_entryName != id.GetLibItemName() ) - SetSelectedComponent( id.GetLibItemName() ); - } - else - { - m_entryName = id.GetLibItemName(); - SetSelectedLibrary( id.GetLibNickname() ); - SetSelectedComponent( id.GetLibItemName() ); - } + SetSelectedLibrary( id.GetLibNickname() ); + SetSelectedComponent( id.GetLibItemName() ); + SetUnitAndConvert( unit, 1 ); Zoom_Automatique( false ); } @@ -117,10 +108,17 @@ void LIB_VIEW_FRAME::onSelectPreviousSymbol( wxCommandEvent& aEvent ) } +void LIB_VIEW_FRAME::onUpdateDocButton( wxUpdateUIEvent& aEvent ) +{ + LIB_ALIAS* entry = getSelectedAlias(); + + aEvent.Enable( entry && !entry->GetDocFileName().IsEmpty() ); +} + + void LIB_VIEW_FRAME::onViewSymbolDocument( wxCommandEvent& aEvent ) { - LIB_ID id( m_libraryName, m_entryName ); - LIB_ALIAS* entry = Prj().SchSymbolLibTable()->LoadSymbol( id ); + LIB_ALIAS* entry = getSelectedAlias(); if( entry && !entry->GetDocFileName().IsEmpty() ) { @@ -147,19 +145,20 @@ void LIB_VIEW_FRAME::onSelectSymbolBodyStyle( wxCommandEvent& aEvent ) break; } - m_canvas->Refresh(); + updatePreviewSymbol(); } void LIB_VIEW_FRAME::onSelectSymbolUnit( wxCommandEvent& aEvent ) { - int ii = m_selpartBox->GetCurrentSelection(); + int ii = m_unitChoice->GetSelection(); if( ii < 0 ) return; m_unit = ii + 1; - m_canvas->Refresh(); + + updatePreviewSymbol(); } @@ -187,57 +186,8 @@ void LIB_VIEW_FRAME::DisplayLibInfos() } -LIB_PART* LIB_VIEW_FRAME::CurrentPart() const -{ - LIB_ID id( m_libraryName, m_entryName ); - LIB_ALIAS* entry = nullptr; - - try - { - entry = Prj().SchSymbolLibTable()->LoadSymbol( id ); - } - catch( const IO_ERROR& ) {} // ignore, it is handled below - - if( !entry ) - return nullptr; - - LIB_PART* part = entry->GetPart(); - - if( !entry->IsRoot() ) - { - // Temporarily change the name field text to reflect the alias name. - auto msg = entry->GetName(); - - part->SetName( msg ); - - - m_convert = 1; - } - - return part; -} - void LIB_VIEW_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { - auto part = CurrentPart(); - auto view = GetCanvas()->GetView(); - - printf("Part %p\n", part ); - - if( !part ) - { - view->Clear(); - return; - } - - - view->Add( part ); - - /*if( !tmp.IsEmpty() ) - part->SetName( tmp ); - - ClearMsgPanel(); - AppendMsgPanel( _( "Name" ), part->GetName(), BLUE, 6 ); - AppendMsgPanel( _( "Description" ), entry->GetDescription(), CYAN, 6 ); - AppendMsgPanel( _( "Key words" ), entry->GetKeyWords(), DARKDARKGRAY );*/ + DisplayLibInfos(); + UpdateStatusBar(); } diff --git a/eeschema/widgets/symbol_preview_widget.cpp b/eeschema/widgets/symbol_preview_widget.cpp index ed797a5198..514035f7f9 100644 --- a/eeschema/widgets/symbol_preview_widget.cpp +++ b/eeschema/widgets/symbol_preview_widget.cpp @@ -34,7 +34,8 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ) m_kiway( aKiway ), m_preview( nullptr ), m_status( nullptr ), - m_sizer( nullptr ) + m_sizer( nullptr ), + m_previewItem( nullptr ) { m_galDisplayOptions.ReadConfig( Pgm().CommonSettings(), GAL_DISPLAY_OPTIONS_KEY ); @@ -61,6 +62,13 @@ SYMBOL_PREVIEW_WIDGET::SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ) } +SYMBOL_PREVIEW_WIDGET::~SYMBOL_PREVIEW_WIDGET() +{ + if( m_previewItem ) + m_preview->GetView()->Remove( m_previewItem ); +} + + void SYMBOL_PREVIEW_WIDGET::SetStatusText( wxString const& aText ) { m_status->SetLabel( aText ); @@ -87,7 +95,11 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit ) ioe.What() ) ); } - view->Clear(); + if( m_previewItem ) + { + view->Remove( m_previewItem ); + m_previewItem = nullptr; + } if( alias ) { @@ -99,7 +111,9 @@ void SYMBOL_PREVIEW_WIDGET::DisplaySymbol( const LIB_ID& aSymbolID, int aUnit ) aUnit = 1; alias->SetTmpUnit( aUnit ); + view->Add( alias ); + m_previewItem = alias; // Zoom to fit BOX2I bBox = alias->GetPart()->GetUnitBoundingBox( aUnit, 0 ); diff --git a/eeschema/widgets/symbol_preview_widget.h b/eeschema/widgets/symbol_preview_widget.h index 9e5fc8d4a2..b44da2471b 100644 --- a/eeschema/widgets/symbol_preview_widget.h +++ b/eeschema/widgets/symbol_preview_widget.h @@ -26,6 +26,7 @@ class LIB_ID; +class LIB_ALIAS; class EDA_DRAW_PANEL_GAL; class wxStaticText; class wxSizer; @@ -43,6 +44,8 @@ public: */ SYMBOL_PREVIEW_WIDGET( wxWindow* aParent, KIWAY& aKiway ); + ~SYMBOL_PREVIEW_WIDGET() override; + /** * Set the contents of the status label and display it. */ @@ -61,6 +64,8 @@ private: wxStaticText* m_status; wxSizer* m_sizer; + + LIB_ALIAS* m_previewItem; };