2020-04-14 12:25:00 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-06-10 13:09:22 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.TXT for contributors.
|
2020-04-14 12:25:00 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RENDER_SETTINGS_H
|
|
|
|
#define RENDER_SETTINGS_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <gal/color4d.h>
|
2021-07-29 09:47:43 +00:00
|
|
|
#include <layer_ids.h>
|
2020-04-14 12:25:00 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-10-18 11:31:07 +00:00
|
|
|
#include <wx/dc.h>
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
class COLOR_SETTINGS;
|
|
|
|
|
|
|
|
namespace KIGFX
|
|
|
|
{
|
|
|
|
class VIEW_ITEM;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Container for all the knowledge about how graphical objects are drawn on any output
|
|
|
|
* surface/device.
|
|
|
|
*
|
|
|
|
* This includes:
|
|
|
|
* - color/transparency settings
|
|
|
|
* - highlighting and high contrast mode control
|
|
|
|
* - drawing quality control (sketch/outline mode)
|
|
|
|
* - text processing flags
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* The class acts as an interface between the PAINTER object and the GUI (i.e. Layers/Items
|
|
|
|
* widget or display options dialog).
|
|
|
|
*/
|
|
|
|
class RENDER_SETTINGS
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RENDER_SETTINGS();
|
|
|
|
virtual ~RENDER_SETTINGS();
|
|
|
|
|
|
|
|
virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Set the specified layer as high-contrast.
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @param aLayerId is a layer number that should be displayed in a specific mode.
|
|
|
|
* @param aEnabled is the new layer state ( true = active or false = not active).
|
|
|
|
*/
|
2020-10-03 21:26:44 +00:00
|
|
|
inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
|
|
|
if( aEnabled )
|
2020-10-03 21:26:44 +00:00
|
|
|
m_highContrastLayers.insert( aLayerId );
|
2020-04-14 12:25:00 +00:00
|
|
|
else
|
2020-10-03 21:26:44 +00:00
|
|
|
m_highContrastLayers.erase( aLayerId );
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return information whether the queried layer is marked as high-contrast.
|
|
|
|
*
|
2020-10-03 21:26:44 +00:00
|
|
|
* @return True if the queried layer is marked as active.
|
|
|
|
*/
|
|
|
|
inline bool GetLayerIsHighContrast( int aLayerId ) const
|
|
|
|
{
|
|
|
|
return ( m_highContrastLayers.count( aLayerId ) > 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the set of currently high-contrast layers.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
2020-10-03 21:26:44 +00:00
|
|
|
const std::set<unsigned int> GetHighContrastLayers() const
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
2020-10-03 21:26:44 +00:00
|
|
|
return m_highContrastLayers;
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return the board layer which is in high-contrast mode.
|
|
|
|
*
|
|
|
|
* There should only be one board layer which is high-contrast at any given time, although
|
|
|
|
* there might be many high-contrast synthetic (GAL) layers.
|
2020-10-03 21:26:44 +00:00
|
|
|
*/
|
|
|
|
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
|
2020-09-26 23:11:07 +00:00
|
|
|
{
|
2020-10-03 21:26:44 +00:00
|
|
|
for( int layer : m_highContrastLayers )
|
2020-09-26 23:11:07 +00:00
|
|
|
{
|
|
|
|
if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
|
|
|
|
return (PCB_LAYER_ID) layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNDEFINED_LAYER;
|
|
|
|
}
|
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
PCB_LAYER_ID GetActiveLayer() const { return m_activeLayer; }
|
|
|
|
void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2022-06-10 13:09:22 +00:00
|
|
|
const wxString& GetLayerName() const { return m_layerName; }
|
|
|
|
void SetLayerName( const wxString& aLayerName ) { m_layerName = aLayerName; }
|
|
|
|
|
2022-06-19 10:57:29 +00:00
|
|
|
LSET GetPrintLayers() const { return m_printLayers; }
|
|
|
|
void SetPrintLayers( LSET aLayerSet ) { m_printLayers = aLayerSet; }
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Clear the list of active layers.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
2020-10-03 21:26:44 +00:00
|
|
|
inline void ClearHighContrastLayers()
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
2020-10-03 21:26:44 +00:00
|
|
|
m_highContrastLayers.clear();
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return current highlight setting.
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @return True if highlight is enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
inline bool IsHighlightEnabled() const
|
|
|
|
{
|
|
|
|
return m_highlightEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return the netcode of currently highlighted net.
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @return Netcode of currently highlighted net.
|
|
|
|
*/
|
2020-05-24 17:30:23 +00:00
|
|
|
inline const std::set<int>& GetHighlightNetCodes() const
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
2020-05-24 17:30:23 +00:00
|
|
|
return m_highlightNetcodes;
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Turns on/off highlighting.
|
|
|
|
*
|
|
|
|
* It may be done for the active layer or the specified net(s)..
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @param aEnabled tells if highlighting should be enabled.
|
2020-12-21 15:17:52 +00:00
|
|
|
* @param aNetcode is optional and if specified, turns on highlighting only for the net with
|
|
|
|
* number given as the parameter.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
2020-06-27 16:06:01 +00:00
|
|
|
inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
|
2020-04-14 12:25:00 +00:00
|
|
|
{
|
|
|
|
m_highlightEnabled = aEnabled;
|
2020-05-24 17:30:23 +00:00
|
|
|
|
|
|
|
if( aEnabled )
|
|
|
|
{
|
|
|
|
if( !aMulti )
|
|
|
|
m_highlightNetcodes.clear();
|
|
|
|
|
|
|
|
m_highlightNetcodes.insert( aNetcode );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_highlightNetcodes.clear();
|
2020-04-14 12:25:00 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 15:53:55 +00:00
|
|
|
/**
|
|
|
|
* Turns on highlighting and highlights multiple nets
|
|
|
|
* @param aHighlight is a set of netcodes to highlight
|
|
|
|
* @param aEnabled tells if highlighting should be enabled.
|
|
|
|
*/
|
|
|
|
inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
|
|
|
|
{
|
|
|
|
m_highlightEnabled = aEnabled;
|
|
|
|
|
|
|
|
if( aEnabled )
|
|
|
|
m_highlightNetcodes = aHighlight;
|
|
|
|
else
|
|
|
|
m_highlightNetcodes.clear();
|
|
|
|
}
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
/**
|
|
|
|
* Turns on/off high contrast display mode.
|
|
|
|
*/
|
|
|
|
void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
|
|
|
|
bool GetHighContrast() const { return m_hiContrastEnabled; }
|
|
|
|
|
2022-01-17 11:55:55 +00:00
|
|
|
void SetDrawBoundingBoxes( bool aEnabled ) { m_drawBoundingBoxes = aEnabled; }
|
|
|
|
bool GetDrawBoundingBoxes() const { return m_drawBoundingBoxes; }
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
/**
|
|
|
|
* Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer
|
|
|
|
* using currently used render settings.
|
2020-12-21 15:17:52 +00:00
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @param aItem is the VIEW_ITEM.
|
|
|
|
* @param aLayer is the layer.
|
|
|
|
* @return The color.
|
|
|
|
*/
|
2020-07-11 17:42:00 +00:00
|
|
|
virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2021-02-22 16:37:43 +00:00
|
|
|
float GetDrawingSheetLineWidth() const { return m_drawingSheetLineWidth; }
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
int GetDefaultPenWidth() const { return m_defaultPenWidth; }
|
|
|
|
void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
|
|
|
|
|
2020-09-08 19:18:50 +00:00
|
|
|
int GetMinPenWidth() const { return m_minPenWidth; }
|
|
|
|
void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
|
|
|
|
|
2021-07-17 19:56:18 +00:00
|
|
|
double GetDashLengthRatio() const { return m_dashLengthRatio; }
|
|
|
|
void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
|
|
|
|
double GetDashLength( int aLineWidth ) const;
|
|
|
|
double GetDotLength( int aLineWidth ) const;
|
|
|
|
|
|
|
|
double GetGapLengthRatio() const { return m_gapLengthRatio; }
|
|
|
|
void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
|
|
|
|
double GetGapLength( int aLineWidth ) const;
|
|
|
|
|
2021-09-07 20:34:10 +00:00
|
|
|
virtual bool GetShowPageLimits() const { return true; }
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2021-02-02 15:36:45 +00:00
|
|
|
bool IsPrinting() const { return m_isPrinting; }
|
|
|
|
void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return current background color settings.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
2022-09-16 16:20:36 +00:00
|
|
|
virtual const COLOR4D& GetBackgroundColor() const = 0;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Set the background color.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
|
|
|
virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return current grid color settings.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
|
|
|
virtual const COLOR4D& GetGridColor() = 0;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return current cursor color settings.
|
2020-04-14 12:25:00 +00:00
|
|
|
*/
|
|
|
|
virtual const COLOR4D& GetCursorColor() = 0;
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Return the color used to draw a layer.
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @param aLayer is the layer number.
|
|
|
|
*/
|
|
|
|
inline const COLOR4D& GetLayerColor( int aLayer ) const
|
|
|
|
{
|
2022-08-29 10:23:40 +00:00
|
|
|
// We don't (yet?) have a separate color for intersheet refs
|
|
|
|
if( aLayer == LAYER_INTERSHEET_REFS )
|
|
|
|
aLayer = LAYER_GLOBLABEL;
|
|
|
|
|
2020-04-14 12:25:00 +00:00
|
|
|
return m_layerColors[aLayer];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-12-21 15:17:52 +00:00
|
|
|
* Change the color used to draw a layer.
|
|
|
|
*
|
2020-04-14 12:25:00 +00:00
|
|
|
* @param aLayer is the layer number.
|
|
|
|
* @param aColor is the new color.
|
|
|
|
*/
|
|
|
|
inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
|
|
|
|
{
|
|
|
|
m_layerColors[aLayer] = aColor;
|
|
|
|
|
|
|
|
update(); // recompute other shades of the color
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsBackgroundDark() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set line width used for drawing outlines.
|
|
|
|
*
|
|
|
|
* @param aWidth is the new width.
|
|
|
|
*/
|
|
|
|
void SetOutlineWidth( float aWidth )
|
|
|
|
{
|
|
|
|
m_outlineWidth = aWidth;
|
|
|
|
}
|
|
|
|
|
2020-08-19 00:44:01 +00:00
|
|
|
void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
|
|
|
|
void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
|
|
|
|
const wxString& GetDefaultFont() const { return m_defaultFont; }
|
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
// TODO: these can go away once the drawing sheet is moved to Cairo-based printing
|
2020-12-20 18:44:13 +00:00
|
|
|
wxDC* GetPrintDC() const { return m_printDC; }
|
2020-04-14 12:25:00 +00:00
|
|
|
void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Precalculates extra colors for layers (e.g. highlighted, darkened and any needed version
|
|
|
|
* of base colors).
|
|
|
|
*/
|
|
|
|
virtual void update();
|
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
|
2022-06-10 13:09:22 +00:00
|
|
|
wxString m_layerName;
|
2020-10-03 21:26:44 +00:00
|
|
|
std::set<unsigned int> m_highContrastLayers; // High-contrast layers (both board layers and
|
|
|
|
// synthetic GAL layers)
|
|
|
|
COLOR4D m_layerColors[LAYER_ID_COUNT]; // Layer colors
|
|
|
|
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
|
|
|
|
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
|
|
|
|
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-10-03 21:26:44 +00:00
|
|
|
COLOR4D m_backgroundColor; // The background color
|
2020-04-14 12:25:00 +00:00
|
|
|
|
|
|
|
/// Parameters for display modes
|
2020-06-27 16:06:01 +00:00
|
|
|
bool m_hiContrastEnabled; // High contrast display mode on/off
|
|
|
|
float m_hiContrastFactor; // Factor used for computing high contrast color
|
2020-05-24 17:30:23 +00:00
|
|
|
|
2020-06-27 16:06:01 +00:00
|
|
|
bool m_highlightEnabled; // Highlight display mode on/off
|
|
|
|
std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
|
|
|
|
float m_highlightFactor; // Factor used for computing highlight color
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2022-01-17 11:55:55 +00:00
|
|
|
bool m_drawBoundingBoxes; // Visual aid for debugging
|
|
|
|
|
2020-06-27 16:06:01 +00:00
|
|
|
float m_selectFactor; // Specifies how color of selected items is changed
|
|
|
|
float m_outlineWidth; // Line width used when drawing outlines
|
2021-02-22 16:37:43 +00:00
|
|
|
float m_drawingSheetLineWidth;// Line width used for borders and titleblock
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2020-06-27 16:06:01 +00:00
|
|
|
int m_defaultPenWidth;
|
2020-09-08 19:18:50 +00:00
|
|
|
int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
|
|
|
|
// lines. This sets an absolute minimum.
|
2021-07-17 19:56:18 +00:00
|
|
|
double m_dashLengthRatio;
|
|
|
|
double m_gapLengthRatio;
|
|
|
|
|
2022-10-22 20:32:10 +00:00
|
|
|
wxString m_defaultFont;
|
|
|
|
|
2021-02-02 15:36:45 +00:00
|
|
|
bool m_isPrinting;
|
2022-06-19 10:57:29 +00:00
|
|
|
LSET m_printLayers;
|
2020-04-14 12:25:00 +00:00
|
|
|
|
2021-05-30 22:56:24 +00:00
|
|
|
wxDC* m_printDC; // This can go away once the drawing sheet is moved to
|
2020-10-19 22:14:46 +00:00
|
|
|
// Cairo-based printing.
|
2020-04-14 12:25:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* RENDER_SETTINGS_H */
|