From c663965498a818f2f97fac9012203fe15de39c73 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 5 Apr 2020 12:29:58 +0100 Subject: [PATCH] Fix some issues with sheet border color handling. --- eeschema/dialogs/dialog_plot_schematic.cpp | 7 +++ eeschema/dialogs/dialog_plot_schematic.h | 12 ++--- eeschema/plot_schematic_DXF.cpp | 5 +-- eeschema/plot_schematic_PDF.cpp | 5 +-- eeschema/plot_schematic_PS.cpp | 7 +-- eeschema/plot_schematic_SVG.cpp | 34 +++++--------- eeschema/sch_io_mgr.cpp | 31 ------------- eeschema/sch_io_mgr.h | 52 ---------------------- eeschema/sch_painter.cpp | 16 ++++--- eeschema/sch_sheet.cpp | 5 +++ 10 files changed, 41 insertions(+), 133 deletions(-) diff --git a/eeschema/dialogs/dialog_plot_schematic.cpp b/eeschema/dialogs/dialog_plot_schematic.cpp index 1f4d8e564f..4aab70b858 100644 --- a/eeschema/dialogs/dialog_plot_schematic.cpp +++ b/eeschema/dialogs/dialog_plot_schematic.cpp @@ -305,6 +305,13 @@ void DIALOG_PLOT_SCHEMATIC::getPlotOptions( int* aDefaultLineWidth ) } +COLOR_SETTINGS* DIALOG_PLOT_SCHEMATIC::getColorSettings() +{ + int selection = m_colorTheme->GetSelection(); + return static_cast( m_colorTheme->GetClientData( selection ) ); +} + + void DIALOG_PLOT_SCHEMATIC::OnPlotCurrent( wxCommandEvent& event ) { PlotSchematic( false ); diff --git a/eeschema/dialogs/dialog_plot_schematic.h b/eeschema/dialogs/dialog_plot_schematic.h index 60609cbf1a..6b2f40d52d 100644 --- a/eeschema/dialogs/dialog_plot_schematic.h +++ b/eeschema/dialogs/dialog_plot_schematic.h @@ -80,6 +80,8 @@ private: void setModeColor( bool aColor ) { m_ModeColorOption->SetSelection( aColor ? 0 : 1 ); } + COLOR_SETTINGS* getColorSettings(); + /** * Set the m_outputDirectoryName variable to the selected directory from directory dialog. */ @@ -134,6 +136,8 @@ private: // SVG void createSVGFile( bool aPlotAll, bool aPlotFrameRef, int aDefaultLineWidth ); + bool plotOneSheetSVG( const wxString& aFileName, SCH_SCREEN* aScreen, int aDefaultLineWidth, + bool aPlotBlackAndWhite, bool aPlotFrameRef ); /** * Create a file name with an absolute path name @@ -148,12 +152,4 @@ private: wxFileName createPlotFileName( wxTextCtrl* aOutputDirectoryName, wxString& aPlotFileName, wxString& aExtension, REPORTER* aReporter = NULL ); - -public: - // This function is static because it is called by libedit - // outside a dialog. This is the reason we need aFrame as parameter - static bool plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, const wxString& aFileName, - SCH_SCREEN* aScreen, int aDefaultLineWidth, - bool aPlotBlackAndWhite, bool aPlotFrameRef, - bool aPlotBackgroundColor, COLOR_SETTINGS* aColors ); }; diff --git a/eeschema/plot_schematic_DXF.cpp b/eeschema/plot_schematic_DXF.cpp index 09aa0077c6..e5384964f4 100644 --- a/eeschema/plot_schematic_DXF.cpp +++ b/eeschema/plot_schematic_DXF.cpp @@ -112,13 +112,10 @@ bool DIALOG_PLOT_SCHEMATIC::PlotOneSheetDXF( const wxString& aFileName, { DXF_PLOTTER* plotter = new DXF_PLOTTER(); - auto colors = static_cast( - m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) ); - const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); plotter->SetPageSettings( pageInfo ); plotter->SetColorMode( getModeColor() ); - plotter->SetColorSettings( colors ); + plotter->SetColorSettings( getColorSettings() ); // Currently, plot units are in decimil plotter->SetViewport( aPlotOffset, IU_PER_MILS/10, aScale, false ); diff --git a/eeschema/plot_schematic_PDF.cpp b/eeschema/plot_schematic_PDF.cpp index 302132f6df..61d2320a1f 100644 --- a/eeschema/plot_schematic_PDF.cpp +++ b/eeschema/plot_schematic_PDF.cpp @@ -60,14 +60,11 @@ void DIALOG_PLOT_SCHEMATIC::createPDFFile( bool aPlotAll, bool aPlotFrameRef, else sheetList.push_back( m_parent->GetCurrentSheet() ); - auto colors = static_cast( - m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) ); - // Allocate the plotter and set the job level parameter PDF_PLOTTER* plotter = new PDF_PLOTTER(); plotter->SetDefaultLineWidth( aDefaultLineWidth ); plotter->SetColorMode( getModeColor() ); - plotter->SetColorSettings( colors ); + plotter->SetColorSettings( getColorSettings() ); plotter->SetCreator( wxT( "Eeschema-PDF" ) ); plotter->SetTitle( m_parent->GetTitleBlock().GetTitle() ); diff --git a/eeschema/plot_schematic_PS.cpp b/eeschema/plot_schematic_PS.cpp index 6ce9a385f5..ae93747670 100644 --- a/eeschema/plot_schematic_PS.cpp +++ b/eeschema/plot_schematic_PS.cpp @@ -138,14 +138,11 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName, double aScale, bool aPlotFrameRef ) { - auto colors = static_cast( - m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) ); - PS_PLOTTER* plotter = new PS_PLOTTER(); plotter->SetPageSettings( aPageInfo ); plotter->SetDefaultLineWidth( aDefaultLineWidth ); plotter->SetColorMode( getModeColor() ); - plotter->SetColorSettings( colors ); + plotter->SetColorSettings( getColorSettings() ); // Currently, plot units are in decimil plotter->SetViewport( aPlot0ffset, IU_PER_MILS/10, aScale, false ); @@ -162,7 +159,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetPS( const wxString& aFileName, plotter->StartPlot(); - if( m_plotBackgroundColor ) + if( m_plotBackgroundColor->GetValue() ) { plotter->SetColor( plotter->ColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ) ); wxPoint end( plotter->PageSettings().GetWidthIU(), diff --git a/eeschema/plot_schematic_SVG.cpp b/eeschema/plot_schematic_SVG.cpp index ce31ed4526..b20d2cefad 100644 --- a/eeschema/plot_schematic_SVG.cpp +++ b/eeschema/plot_schematic_SVG.cpp @@ -49,9 +49,6 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef, SCH_SHEET_PATH oldsheetpath = m_parent->GetCurrentSheet(); SCH_SHEET_LIST sheetList; - auto colors = static_cast( - m_colorTheme->GetClientData( m_colorTheme->GetSelection() ) ); - if( aPrintAll ) sheetList.BuildSheetList( g_RootSheet ); else @@ -72,10 +69,8 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef, wxFileName plotFileName = createPlotFileName( m_outputDirectoryName, fname, ext, &reporter ); - bool success = plotOneSheetSVG( m_parent, plotFileName.GetFullPath(), screen, - aDefaultLineWidth, getModeColor() ? false : true, - aPrintFrameRef, m_plotBackgroundColor->GetValue(), - colors ); + bool success = plotOneSheetSVG( plotFileName.GetFullPath(), screen, aDefaultLineWidth, + getModeColor() ? false : true, aPrintFrameRef ); if( !success ) { @@ -103,25 +98,18 @@ void DIALOG_PLOT_SCHEMATIC::createSVGFile( bool aPrintAll, bool aPrintFrameRef, } -bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, - const wxString& aFileName, - SCH_SCREEN* aScreen, - int aDefaultLineWidth, - bool aPlotBlackAndWhite, - bool aPlotFrameRef, - bool aPlotBackgroundColor, - COLOR_SETTINGS* aColors ) +bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( const wxString& aFileName, + SCH_SCREEN* aScreen, + int aDefaultLineWidth, + bool aPlotBlackAndWhite, + bool aPlotFrameRef ) { SVG_PLOTTER* plotter = new SVG_PLOTTER(); - - if( !aColors ) - aColors = aFrame->GetColorSettings(); - const PAGE_INFO& pageInfo = aScreen->GetPageSettings(); plotter->SetPageSettings( pageInfo ); plotter->SetDefaultLineWidth( aDefaultLineWidth ); plotter->SetColorMode( aPlotBlackAndWhite ? false : true ); - plotter->SetColorSettings( aColors ); + plotter->SetColorSettings( getColorSettings() ); wxPoint plot_offset; double scale = 1.0; // Currently, plot units are in decimil @@ -140,7 +128,7 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, plotter->StartPlot(); - if( aPlotBackgroundColor ) + if( m_plotBackgroundColor->GetValue() ) { plotter->SetColor( plotter->ColorSettings()->GetColor( LAYER_SCHEMATIC_BACKGROUND ) ); wxPoint end( plotter->PageSettings().GetWidthIU(), @@ -150,9 +138,9 @@ bool DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG( EDA_DRAW_FRAME* aFrame, if( aPlotFrameRef ) { - PlotWorkSheet( plotter, &aScreen->Prj(), aFrame->GetTitleBlock(), pageInfo, + PlotWorkSheet( plotter, &aScreen->Prj(), m_parent->GetTitleBlock(), pageInfo, aScreen->m_ScreenNumber, aScreen->m_NumberOfScreens, - aFrame->GetScreenDesc(), aScreen->GetFileName(), + m_parent->GetScreenDesc(), aScreen->GetFileName(), plotter->GetColorMode() ? COLOR4D::UNSPECIFIED : COLOR4D::BLACK ); } diff --git a/eeschema/sch_io_mgr.cpp b/eeschema/sch_io_mgr.cpp index ffdfd5c371..37a0c457a5 100644 --- a/eeschema/sch_io_mgr.cpp +++ b/eeschema/sch_io_mgr.cpp @@ -184,35 +184,4 @@ SCH_IO_MGR::SCH_FILE_T SCH_IO_MGR::GuessPluginTypeFromSchPath( const wxString& a } -SCH_SHEET* SCH_IO_MGR::Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway, - SCH_SHEET* aAppendToMe, const PROPERTIES* aProperties ) -{ - // release the SCH_PLUGIN even if an exception is thrown. - SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) ); - - if( (SCH_PLUGIN*) pi ) // test pi->plugin - { - return pi->Load( aFileName, aKiway, aAppendToMe, aProperties ); // virtual - } - - THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) ); -} - - -void SCH_IO_MGR::Save( SCH_FILE_T aFileType, const wxString& aFileName, - SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties ) -{ - // release the SCH_PLUGIN even if an exception is thrown. - SCH_PLUGIN::SCH_PLUGIN_RELEASER pi( FindPlugin( aFileType ) ); - - if( (SCH_PLUGIN*) pi ) // test pi->plugin - { - pi->Save( aFileName, aSchematic, aKiway, aProperties ); // virtual - return; - } - - THROW_IO_ERROR( wxString::Format( FMT_NOTFOUND, ShowType( aFileType ).GetData() ) ); -} - - DECLARE_ENUM_VECTOR( SCH_IO_MGR, SCH_FILE_T ) diff --git a/eeschema/sch_io_mgr.h b/eeschema/sch_io_mgr.h index 369e0f04a2..9657f5cfb8 100644 --- a/eeschema/sch_io_mgr.h +++ b/eeschema/sch_io_mgr.h @@ -122,58 +122,6 @@ public: * Return a plugin type given a schematic using the file extension of \a aSchematicPath. */ static SCH_FILE_T GuessPluginTypeFromSchPath( const wxString& aSchematicPath ); - - /** - * Load the requested #SCH_PLUGIN and if found, calls the SCH_PLUGIN->Load(..) function - * on it using the arguments passed to this function. After the SCH_PLUGIN->Load() - * function returns, the #SCH_PLUGIN is Released() as part of this call. - * - * @param aFileType is the #SCH_FILE_T of file to load. - * - * @param aFileName is the name of the file to load. - * - * @param aKiway is the #KIWAY object used to access the component libraries loaded - * by the project. - * - * @param aAppendToMe is an existing #SCH_SHEET to append to, use NULL if a new - * #SCH_SHEET load is wanted. - * - * @param aProperties is an associative array that allows the caller to pass additional - * tuning parameters to the #SCH_PLUGIN. - * - * @return the loaded schematic which the caller owns. This is never NULL because - * exception thrown if an error occurs. - * - * @throw IO_ERROR if the #SCH_PLUGIN cannot be found, file cannot be found - * or file cannot be loaded. - */ - static SCH_SHEET* Load( SCH_FILE_T aFileType, const wxString& aFileName, KIWAY* aKiway, - SCH_SHEET* aAppendToMe = NULL, const PROPERTIES* aProperties = NULL ); - - /** - * Write either a full aSchematic to a storage file in a format that this - * implementation knows about, or it can be used to write a portion of - * aSchematic to a special kind of export file. - * - * @param aFileType is the #SCH_FILE_T of file to save. - * - * @param aFileName is the name of a file to save to on disk. - * - * @param aSchematic is the #SCH_SCREEN document (data tree) to save or export to disk. - * - * @param aKiway is the #KIWAY object used to access the component libraries loaded - * by the project. - * - * @param aProperties is an associative array that can be used to tell the - * saver how to save the file, because it can take any number of - * additional named tuning arguments that the plugin is known to support. - * The caller continues to own this object (plugin may not delete it), and - * plugins should expect it to be optionally NULL. - * - * @throw IO_ERROR if there is a problem saving or exporting. - */ - static void Save( SCH_FILE_T aFileType, const wxString& aFileName, - SCH_SCREEN* aSchematic, KIWAY* aKiway, const PROPERTIES* aProperties = NULL ); }; diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index ca80171121..c0fdc38088 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -248,13 +248,17 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aDr SCH_SHEET* sheet = (SCH_SHEET*) aItem; COLOR4D sheetColor = COLOR4D::UNSPECIFIED; - if( aLayer == LAYER_SHEET ) - sheetColor = sheet->GetBorderColor(); - else if( aLayer == LAYER_SHEET_BACKGROUND ) - sheetColor = sheet->GetBackgroundColor(); + // Lazy fixup of legacy sheets with no color specifications + if( sheet->GetBorderColor() == COLOR4D::UNSPECIFIED ) + sheet->SetBorderColor( m_schSettings.GetLayerColor( LAYER_SHEET ) ); - if( sheetColor != COLOR4D::UNSPECIFIED ) - color = sheetColor; + if( sheet->GetBackgroundColor() == COLOR4D::UNSPECIFIED ) + sheet->SetBackgroundColor( m_schSettings.GetLayerColor( LAYER_SHEET_BACKGROUND ) ); + + if( aLayer == LAYER_SHEET ) + color = sheet->GetBorderColor(); + else if( aLayer == LAYER_SHEET_BACKGROUND ) + color = sheet->GetBackgroundColor(); } if( aItem->IsBrightened() && !aDrawingShadows ) // Selection disambiguation, etc. diff --git a/eeschema/sch_sheet.cpp b/eeschema/sch_sheet.cpp index 32ac8ef077..301fba937b 100644 --- a/eeschema/sch_sheet.cpp +++ b/eeschema/sch_sheet.cpp @@ -909,6 +909,11 @@ void SCH_SHEET::Plot( PLOTTER* aPlotter ) wxString Text; wxPoint pos; + COLOR4D borderColor = GetBorderColor(); + + if( borderColor == COLOR4D::UNSPECIFIED ) + borderColor = aPlotter->ColorSettings()->GetColor( LAYER_SHEET ); + aPlotter->SetColor( GetBorderColor() ); int thickness = GetPenSize();