Header clean up round 5.

This commit is contained in:
Wayne Stambaugh 2020-12-21 18:42:21 -05:00
parent 23eaf32019
commit 60ebd177fd
21 changed files with 889 additions and 881 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2020 KiCad Developers, see AUTHORS.txt for contributors.
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -25,7 +25,7 @@
/** /**
* @file cairo_compositor.h * @file cairo_compositor.h
* @brief Class that handles multitarget rendering (ie. to different textures/surfaces) and * Class that handles multitarget rendering (ie. to different textures/surfaces) and
* later compositing into a single image (Cairo flavour). * later compositing into a single image (Cairo flavour).
*/ */
@ -94,8 +94,7 @@ public:
} }
/** /**
* Function SetMainContext() * Set a context to be treated as the main context (ie. as a target of buffers rendering and
* Sets a context to be treated as the main context (ie. as a target of buffers rendering and
* as a source of settings for newly created buffers). * as a source of settings for newly created buffers).
* *
* @param aMainContext is the context that should be treated as the main one. * @param aMainContext is the context that should be treated as the main one.
@ -109,6 +108,17 @@ public:
} }
protected: protected:
/**
* Perform freeing of resources.
*/
void clean();
/// Return number of currently used buffers.
unsigned int usedBuffers()
{
return m_buffers.size();
}
typedef uint32_t* BitmapPtr; typedef uint32_t* BitmapPtr;
typedef struct typedef struct
{ {
@ -136,18 +146,6 @@ protected:
unsigned int m_bufferSize; ///< Amount of memory needed to store a buffer unsigned int m_bufferSize; ///< Amount of memory needed to store a buffer
cairo_antialias_t m_currentAntialiasingMode; cairo_antialias_t m_currentAntialiasingMode;
/**
* Function clean()
* performs freeing of resources.
*/
void clean();
/// Returns number of currently used buffers
unsigned int usedBuffers()
{
return m_buffers.size();
}
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -40,16 +40,15 @@
#include <memory> #include <memory>
/** /**
* @brief Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer. * Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
* *
* Quote from Wikipedia: * Quote from Wikipedia:
* " Cairo is a software library used to provide a vector graphics-based, device-independent * " Cairo is a software library used to provide a vector graphics-based, device-independent
* API for software developers. It is designed to provide primitives for 2-dimensional * API for software developers. It is designed to provide primitives for 2-dimensional
* drawing across a number of different backends. " * drawing across a number of different backends. "
* <br> *
* Cairo offers also backends for PostScript and PDF surfaces. So it can be used for printing * Cairo offers also backends for PostScript and PDF surfaces. So it can be used for printing
* of KiCad graphics surfaces as well. * of KiCad graphics surfaces as well.
*
*/ */
namespace KIGFX namespace KIGFX
{ {
@ -72,7 +71,8 @@ public:
void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override; void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;
/// @copydoc GAL::DrawSegment() /// @copydoc GAL::DrawSegment()
void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth ) override; void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
double aWidth ) override;
/// @copydoc GAL::DrawCircle() /// @copydoc GAL::DrawCircle()
void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) override; void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) override;
@ -90,12 +90,20 @@ public:
/// @copydoc GAL::DrawPolyline() /// @copydoc GAL::DrawPolyline()
void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override { drawPoly( aPointList ); } void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override { drawPoly( aPointList ); }
void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override { drawPoly( aPointList, aListSize ); } void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override
{
drawPoly( aPointList, aListSize );
}
void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) override { drawPoly( aLineChain ); } void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) override { drawPoly( aLineChain ); }
/// @copydoc GAL::DrawPolygon() /// @copydoc GAL::DrawPolygon()
void DrawPolygon( const std::deque<VECTOR2D>& aPointList ) override { drawPoly( aPointList ); } void DrawPolygon( const std::deque<VECTOR2D>& aPointList ) override { drawPoly( aPointList ); }
void DrawPolygon( const VECTOR2D aPointList[], int aListSize ) override { drawPoly( aPointList, aListSize ); } void DrawPolygon( const VECTOR2D aPointList[], int aListSize ) override
{
drawPoly( aPointList, aListSize );
}
void DrawPolygon( const SHAPE_POLY_SET& aPolySet ) override; void DrawPolygon( const SHAPE_POLY_SET& aPolySet ) override;
void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) override; void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) override;
@ -111,7 +119,7 @@ public:
// Screen methods // Screen methods
// -------------- // --------------
/// @brief Resizes the canvas. /// Resizes the canvas.
void ResizeScreen( int aWidth, int aHeight ) override; void ResizeScreen( int aWidth, int aHeight ) override;
/// @copydoc GAL::Flush() /// @copydoc GAL::Flush()
@ -215,14 +223,18 @@ protected:
const VECTOR2D xform( double x, double y ); // rotation, scale and offset const VECTOR2D xform( double x, double y ); // rotation, scale and offset
const VECTOR2D xform( const VECTOR2D& aP ); // rotation, scale and offset const VECTOR2D xform( const VECTOR2D& aP ); // rotation, scale and offset
/** Transform according to the rotation from currentWorld2Screen transform matrix: /**
* @param aAngle is the angle in radians to transform * Transform according to the rotation from currentWorld2Screen transform matrix.
* @return the modified angle *
* @param aAngle is the angle in radians to transform.
* @return the modified angle.
*/ */
const double angle_xform( const double aAngle ); const double angle_xform( const double aAngle );
/** Transform according to the rotation from currentWorld2Screen transform matrix /**
* for the start angle and the end angle of an arc * Transform according to the rotation from currentWorld2Screen transform matrix
* for the start angle and the end angle of an arc.
*
* @param aStartAngle is the arc starting point in radians to transform * @param aStartAngle is the arc starting point in radians to transform
* @param aEndAngle is the arc ending point in radians to transform * @param aEndAngle is the arc ending point in radians to transform
*/ */
@ -237,7 +249,7 @@ protected:
void resetContext(); void resetContext();
/** /**
* @brief Draw a grid line (usually a simplified line function). * Draw a grid line (usually a simplified line function).
* *
* @param aStartPoint is the start point of the line. * @param aStartPoint is the start point of the line.
* @param aEndPoint is the end point of the line. * @param aEndPoint is the end point of the line.
@ -247,6 +259,31 @@ protected:
void drawGridPoint( const VECTOR2D& aPoint, double aWidth, double aHeight ); void drawGridPoint( const VECTOR2D& aPoint, double aWidth, double aHeight );
void drawAxes( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ); void drawAxes( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint );
void flushPath();
void storePath(); ///< Store the actual path
/**
* Blits cursor into the current screen.
*/
void blitCursor( wxMemoryDC& clientDC );
/// Drawing polygons & polylines is the same in cairo, so here is the common code
void drawPoly( const std::deque<VECTOR2D>& aPointList );
void drawPoly( const VECTOR2D aPointList[], int aListSize );
void drawPoly( const SHAPE_LINE_CHAIN& aLineChain );
/**
* Returns a valid key that can be used as a new group number.
*
* @return An unique group number that is not used by any other group.
*/
unsigned int getNewGroupNumber();
void syncLineWidth( bool aForceWidth = false, double aWidth = 0.0 );
void updateWorldScreenMatrix();
const VECTOR2D roundp( const VECTOR2D& v );
/// Super class definition /// Super class definition
typedef GAL super; typedef GAL super;
@ -307,32 +344,6 @@ protected:
std::vector<cairo_surface_t*> imageSurfaces; std::vector<cairo_surface_t*> imageSurfaces;
std::vector<cairo_matrix_t> xformStack; std::vector<cairo_matrix_t> xformStack;
void flushPath();
void storePath(); ///< Store the actual path
/**
* @brief Blits cursor into the current screen.
*/
void blitCursor( wxMemoryDC& clientDC );
/// Drawing polygons & polylines is the same in cairo, so here is the common code
void drawPoly( const std::deque<VECTOR2D>& aPointList );
void drawPoly( const VECTOR2D aPointList[], int aListSize );
void drawPoly( const SHAPE_LINE_CHAIN& aLineChain );
/**
* @brief Returns a valid key that can be used as a new group number.
*
* @return An unique group number that is not used by any other group.
*/
unsigned int getNewGroupNumber();
void syncLineWidth( bool aForceWidth = false, double aWidth = 0.0 );
void updateWorldScreenMatrix();
const VECTOR2D roundp( const VECTOR2D& v );
/// Format used to store pixels /// Format used to store pixels
static constexpr cairo_format_t GAL_FORMAT = CAIRO_FORMAT_ARGB32; static constexpr cairo_format_t GAL_FORMAT = CAIRO_FORMAT_ARGB32;
}; };
@ -342,23 +353,19 @@ class CAIRO_GAL : public CAIRO_GAL_BASE, public wxWindow
{ {
public: public:
/** /**
* Constructor CAIRO_GAL_BASE
*
* @param aParent is the wxWidgets immediate wxWindow parent of this object. * @param aParent is the wxWidgets immediate wxWindow parent of this object.
* @param aMouseListener is the wxEvtHandler that should receive the mouse events, this
* can be can be any wxWindow, but is often a wxFrame container.
* @param aPaintListener is the wxEvtHandler that should receive the paint event. This
* can be any wxWindow, but is often a derived instance of this
* class or a containing wxFrame. The "paint event" here is a
* wxCommandEvent holding EVT_GAL_REDRAW, as sent by PostPaint().
* *
* @param aMouseListener is the wxEvtHandler that should receive the mouse events, * @param aName is the name of this window for use by wxWindow::FindWindowByName().
* this can be can be any wxWindow, but is often a wxFrame container.
*
* @param aPaintListener is the wxEvtHandler that should receive the paint
* event. This can be any wxWindow, but is often a derived instance
* of this class or a containing wxFrame. The "paint event" here is
* a wxCommandEvent holding EVT_GAL_REDRAW, as sent by PostPaint().
*
* @param aName is the name of this window for use by wxWindow::FindWindowByName()
*/ */
CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, CAIRO_GAL( GAL_DISPLAY_OPTIONS& aDisplayOptions, wxWindow* aParent,
wxWindow* aParent, wxEvtHandler* aMouseListener = NULL, wxEvtHandler* aMouseListener = nullptr, wxEvtHandler* aPaintListener = nullptr,
wxEvtHandler* aPaintListener = NULL, const wxString& aName = wxT( "CairoCanvas" ) ); const wxString& aName = wxT( "CairoCanvas" ) );
~CAIRO_GAL(); ~CAIRO_GAL();
@ -383,10 +390,10 @@ public:
void ClearTarget( RENDER_TARGET aTarget ) override; void ClearTarget( RENDER_TARGET aTarget ) override;
/** /**
* Function PostPaint * Post an event to m_paint_listener.
* posts an event to m_paint_listener. A post is used so that the actual drawing *
* function can use a device context type that is not specific to the wxEVT_PAINT event, * A post is used so that the actual drawing function can use a device context type that
* just by changing the PostPaint code. * is not specific to the wxEVT_PAINT event, just by changing the PostPaint code.
*/ */
void PostPaint( wxPaintEvent& aEvent ); void PostPaint( wxPaintEvent& aEvent );
@ -400,28 +407,6 @@ public:
paintListener = aPaintListener; paintListener = aPaintListener;
} }
protected:
// Compositor related variables
std::shared_ptr<CAIRO_COMPOSITOR> compositor; ///< Object for layers compositing
unsigned int mainBuffer; ///< Handle to the main buffer
unsigned int overlayBuffer; ///< Handle to the overlay buffer
RENDER_TARGET currentTarget; ///< Current rendering target
bool validCompositor; ///< Compositor initialization flag
// Variables related to wxWidgets
wxWindow* parentWindow; ///< Parent window
wxEvtHandler* mouseListener; ///< Mouse listener
wxEvtHandler* paintListener; ///< Paint listener
unsigned int bufferSize; ///< Size of buffers cairoOutput, bitmapBuffers
unsigned char* wxOutput; ///< wxImage comaptible buffer
// Variables related to Cairo <-> wxWidgets
unsigned char* bitmapBuffer; ///< Storage of the cairo image
int stride; ///< Stride value for Cairo
int wxBufferWidth;
bool isInitialized; ///< Are Cairo image & surface ready to use
COLOR4D backgroundColor; ///< Background color
/// @copydoc GAL::BeginDrawing() /// @copydoc GAL::BeginDrawing()
void beginDrawing() override; void beginDrawing() override;
@ -445,14 +430,14 @@ protected:
// Event handlers // Event handlers
/** /**
* @brief Paint event handler. * Paint event handler.
* *
* @param aEvent is the paint event. * @param aEvent is the paint event.
*/ */
void onPaint( wxPaintEvent& aEvent ); void onPaint( wxPaintEvent& aEvent );
/** /**
* @brief Mouse event handler, forwards the event to the child. * Mouse event handler, forwards the event to the child.
* *
* @param aEvent is the mouse event to be forwarded. * @param aEvent is the mouse event to be forwarded.
*/ */
@ -460,6 +445,28 @@ protected:
///> Cairo-specific update handlers ///> Cairo-specific update handlers
bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override; bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions ) override;
protected:
// Compositor related variables
std::shared_ptr<CAIRO_COMPOSITOR> compositor; ///< Object for layers compositing
unsigned int mainBuffer; ///< Handle to the main buffer
unsigned int overlayBuffer; ///< Handle to the overlay buffer
RENDER_TARGET currentTarget; ///< Current rendering target
bool validCompositor; ///< Compositor initialization flag
// Variables related to wxWidgets
wxWindow* parentWindow; ///< Parent window
wxEvtHandler* mouseListener; ///< Mouse listener
wxEvtHandler* paintListener; ///< Paint listener
unsigned int bufferSize; ///< Size of buffers cairoOutput, bitmapBuffers
unsigned char* wxOutput; ///< wxImage compatible buffer
// Variables related to Cairo <-> wxWidgets
unsigned char* bitmapBuffer; ///< Storage of the cairo image
int stride; ///< Stride value for Cairo
int wxBufferWidth;
bool isInitialized; ///< Are Cairo image & surface ready to use
COLOR4D backgroundColor; ///< Background color
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -1,5 +1,7 @@
/* /*
* Copyright (C) 2018 CERN * Copyright (C) 2018 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* Author: Maciej Suminski <maciej.suminski@cern.ch> * Author: Maciej Suminski <maciej.suminski@cern.ch>
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch> * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* *
@ -29,7 +31,8 @@ class wxGCDC;
namespace KIGFX namespace KIGFX
{ {
/** /**
* CAIRO_PRINT_CTX provides a Cairo context created from wxPrintDC. * Provide a Cairo context created from wxPrintDC.
*
* It allows one to prepare printouts using the Cairo library and let wxWidgets handle the rest. * It allows one to prepare printouts using the Cairo library and let wxWidgets handle the rest.
*/ */
class CAIRO_PRINT_CTX : public PRINT_CONTEXT class CAIRO_PRINT_CTX : public PRINT_CONTEXT
@ -96,8 +99,8 @@ public:
/** /**
* @param aSize is the printing sheet size expressed in inches. * @param aSize is the printing sheet size expressed in inches.
* @param aRotateIfLandscape true if the platform requires 90 degrees * @param aRotateIfLandscape true if the platform requires 90 degrees rotation in order
* rotation in order to print in landscape format. * to print in landscape format.
*/ */
void SetNativePaperSize( const VECTOR2D& aSize, bool aRotateIfLandscape ) override; void SetNativePaperSize( const VECTOR2D& aSize, bool aRotateIfLandscape ) override;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2017-2019 Kicad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2017-2020 Kicad Developers, see AUTHORS.txt for contributors.
* *
* Color class * Color class
* *
@ -36,8 +36,7 @@
#endif #endif
/** /**
* Legacy color enumeration. Also contains a flag and the alpha value in * Legacy color enumeration. Also contains a flag and the alpha value in the upper bits
* the upper bits
*/ */
enum EDA_COLOR_T enum EDA_COLOR_T
{ {
@ -94,8 +93,7 @@ const StructColors* colorRefs();
namespace KIGFX namespace KIGFX
{ {
/** /**
* COLOR4D * A color representation with 4 components: red, green, blue, alpha.
* is the color representation with 4 components: red, green, blue, alpha.
*/ */
class COLOR4D class COLOR4D
{ {
@ -107,8 +105,6 @@ public:
} }
/** /**
* @brief Constructor
*
* @param aRed is the red component [0.0 .. 1.0]. * @param aRed is the red component [0.0 .. 1.0].
* @param aGreen is the green component [0.0 .. 1.0]. * @param aGreen is the green component [0.0 .. 1.0].
* @param aBlue is the blue component [0.0 .. 1.0]. * @param aBlue is the blue component [0.0 .. 1.0].
@ -124,34 +120,31 @@ public:
} }
/** /**
* @brief Constructor
*
* @param aColor is one of KiCad's palette colors. * @param aColor is one of KiCad's palette colors.
* @see EDA_COLOR_T * @see EDA_COLOR_T
*/ */
COLOR4D( EDA_COLOR_T aColor ); COLOR4D( EDA_COLOR_T aColor );
/** /**
* Initializes the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha. * Initialize the color from a RGBA value with 0-255 red/green/blue and 0-1 alpha.
* Suitable for taking the values directly from the "CSS syntax" from ToWxString *
* @return this color * Suitable for taking the values directly from the "CSS syntax" from ToWxString.
*
* @return this color.
*/ */
COLOR4D& FromCSSRGBA( int aRed, int aGreen, int aBlue, double aAlpha = 1.0 ); COLOR4D& FromCSSRGBA( int aRed, int aGreen, int aBlue, double aAlpha = 1.0 );
#ifdef WX_COMPATIBILITY #ifdef WX_COMPATIBILITY
/** /**
* @brief Constructor
*
* @param aColor is the color type used by wxWidgets. * @param aColor is the color type used by wxWidgets.
*/ */
COLOR4D( const wxColour& aColor ); COLOR4D( const wxColour& aColor );
/** /**
* Function SetFromWxString * Set color values by parsing a string using wxColour::Set().
* Sets color values by parsing a string using wxColour::Set()
* *
* @param aColorString is a color string that wxColour can understand * @param aColorString is a color string that wxColour can understand.
* @return true if color was set successfully * @return true if color was set successfully.
*/ */
bool SetFromWxString( const wxString& aColorString ); bool SetFromWxString( const wxString& aColorString );
@ -160,12 +153,10 @@ public:
wxColour ToColour() const; wxColour ToColour() const;
/** /**
* Function LegacyMix() * Mix this COLOR4D with an input COLOR4D using the OR-mixing of legacy canvas.
* Mixes this COLOR4D with an input COLOR4D using the OR-mixing of legacy canvas.
* *
* Can be removed once legacy canvas is removed. * Can be removed once legacy canvas is removed. Depends on wxColour for simplicity,
* Depends on wxColour for simplicity, but could be re-written to avoid * but could be re-written to avoid this dependency if desired.
* this dependency if desired.
* *
* @param aColor The color to mix with this one * @param aColor The color to mix with this one
*/ */
@ -173,22 +164,22 @@ public:
/** /**
* Packs the color into an unsigned int for compatibility with legacy canvas. * Packs the color into an unsigned int for compatibility with legacy canvas.
* Note that this is a lossy downsampling and also that the alpha channel is lost. *
* @note This is a lossy downsampling and also that the alpha channel is lost.
*/ */
unsigned int ToU32() const; unsigned int ToU32() const;
/** /**
* Unpacks from a unsigned int in the legacy EDA_COLOR_T format. * Unpack from a unsigned int in the legacy EDA_COLOR_T format.
*/ */
void FromU32( unsigned int aPackedColor ); void FromU32( unsigned int aPackedColor );
#endif /* WX_COMPATIBLITY */ #endif /* WX_COMPATIBLITY */
/** /**
* Function ToHSL()
* Converts current color (stored in RGB) to HSL format. * Converts current color (stored in RGB) to HSL format.
* *
* @param aOutHue is the conversion result for hue component, in degrees 0 ... 360.0 * @param aOutHue is the conversion result for hue component, in degrees 0 ... 360.0.
* @param aOutSaturation is the conversion result for saturation component (0 ... 1.0). * @param aOutSaturation is the conversion result for saturation component (0 ... 1.0).
* @param aOutLightness is conversion result for value component (0 ... 1.0). * @param aOutLightness is conversion result for value component (0 ... 1.0).
* @note saturation is set to 0.0 for black color if r = g = b, * @note saturation is set to 0.0 for black color if r = g = b,
@ -196,18 +187,17 @@ public:
void ToHSL( double& aOutHue, double& aOutSaturation, double& aOutValue ) const; void ToHSL( double& aOutHue, double& aOutSaturation, double& aOutValue ) const;
/** /**
* Function FromHSL() * Change currently used color to the one given by hue, saturation and lightness parameters.
* Changes currently used color to the one given by hue, saturation and lightness parameters.
* *
* @param aInHue is hue component, in degrees (0.0 - 360.0) * @param aInHue is hue component, in degrees (0.0 - 360.0).
* @param aInSaturation is saturation component (0.0 - 1.0) * @param aInSaturation is saturation component (0.0 - 1.0).
* @param aInLightness is lightness component (0.0 - 1.0) * @param aInLightness is lightness component (0.0 - 1.0).
*/ */
void FromHSL( double aInHue, double aInSaturation, double aInLightness ); void FromHSL( double aInHue, double aInSaturation, double aInLightness );
/** /**
* Function Brighten
* Makes the color brighter by a given factor. * Makes the color brighter by a given factor.
*
* @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0). * @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D& Brightened color. * @return COLOR4D& Brightened color.
*/ */
@ -223,8 +213,8 @@ public:
} }
/** /**
* Function Darken
* Makes the color darker by a given factor. * Makes the color darker by a given factor.
*
* @param aFactor Specifies how dark the color should become (valid values: 0.0 .. 1.0). * @param aFactor Specifies how dark the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D& Darkened color. * @return COLOR4D& Darkened color.
*/ */
@ -240,8 +230,8 @@ public:
} }
/** /**
* Function Invert
* Makes the color inverted, alpha remains the same. * Makes the color inverted, alpha remains the same.
*
* @return COLOR4D& Inverted color. * @return COLOR4D& Inverted color.
*/ */
COLOR4D& Invert() COLOR4D& Invert()
@ -259,8 +249,8 @@ public:
COLOR4D& Saturate( double aFactor ); COLOR4D& Saturate( double aFactor );
/** /**
* Function Brightened * Return a color that is brighter by a given factor, without modifying object.
* Returns a color that is brighter by a given factor, without modifying object. *
* @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0). * @param aFactor Specifies how bright the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D Highlighted color. * @return COLOR4D Highlighted color.
*/ */
@ -268,15 +258,13 @@ public:
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 ); assert( aFactor >= 0.0 && aFactor <= 1.0 );
return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor, b * ( 1.0 - aFactor ) + aFactor, a );
b * ( 1.0 - aFactor ) + aFactor,
a );
} }
/** /**
* Function Darkened * Return a color that is darker by a given factor, without modifying object.
* Returns a color that is darker by a given factor, without modifying object. *
* @param aFactor Specifies how dark the color should become (valid values: 0.0 .. 1.0). * @param aFactor Specifies how dark the color should become (valid values: 0.0 .. 1.0).
* @return COLOR4D Darkened color. * @return COLOR4D Darkened color.
*/ */
@ -284,15 +272,12 @@ public:
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 ); assert( aFactor >= 0.0 && aFactor <= 1.0 );
return COLOR4D( r * ( 1.0 - aFactor ), return COLOR4D( r * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ), a );
g * ( 1.0 - aFactor ),
b * ( 1.0 - aFactor ),
a );
} }
/** /**
* Function Mix * Return a color that is mixed with the input by a factor.
* Returns a color that is mixed with the input by a factor *
* @param aFactor Specifies how much of the original color to keep (valid values: 0.0 .. 1.0). * @param aFactor Specifies how much of the original color to keep (valid values: 0.0 .. 1.0).
* @return COLOR4D Mixed color. * @return COLOR4D Mixed color.
*/ */
@ -307,8 +292,8 @@ public:
} }
/** /**
* Function WithAlpha * Return a color with the same color, but the given alpha.
* Returns a colour with the same colour, but the given alpha *
* @param aAlpha specifies the alpha of the new color * @param aAlpha specifies the alpha of the new color
* @return COLOR4D color with that alpha * @return COLOR4D color with that alpha
*/ */
@ -320,8 +305,8 @@ public:
} }
/** /**
* Function Inverted
* Returns an inverted color, alpha remains the same. * Returns an inverted color, alpha remains the same.
*
* @return COLOR4D& Inverted color. * @return COLOR4D& Inverted color.
*/ */
COLOR4D Inverted() const COLOR4D Inverted() const
@ -330,8 +315,8 @@ public:
} }
/** /**
* Function GetBrightness
* Returns the brightness value of the color ranged from 0.0 to 1.0. * Returns the brightness value of the color ranged from 0.0 to 1.0.
*
* @return The brightness value. * @return The brightness value.
*/ */
double GetBrightness() const double GetBrightness() const
@ -341,22 +326,21 @@ public:
} }
/** /**
* Function ToHSV() * Convert current color (stored in RGB) to HSV format.
* Converts current color (stored in RGB) to HSV format.
* *
* @param aOutHue is the conversion result for hue component, in degrees 0 ... 360.0 * @param aOutHue is the conversion result for hue component, in degrees 0 ... 360.0.
* @param aOutSaturation is the conversion result for saturation component (0 ... 1.0). * @param aOutSaturation is the conversion result for saturation component (0 ... 1.0).
* @param aOutValue is conversion result for value component (0 ... 1.0). * @param aOutValue is conversion result for value component (0 ... 1.0).
* @param aAlwaysDefineHue controls the way hue is defined when r = v = b * @param aAlwaysDefineHue controls the way hue is defined when r = v = b
* @note saturation is set to 0.0 for black color (r = v = b = 0), and if r = v = b, * @note saturation is set to 0.0 for black color (r = v = b = 0), and if r = v = b,
* hue is set to 0.0 if aAlwaysDefineHue = true, and set to NAN if aAlwaysDefineHue = false. * hue is set to 0.0 if aAlwaysDefineHue = true, and set to NAN if aAlwaysDefineHue = false.
* this option is usefull to convert a 4D color to a legacy color, because Red has hue = 0, * this option is useful to convert a 4D color to a legacy color, because Red has hue = 0,
* therefore aAlwaysDefineHue = false makes difference between Red and Gray colors. * therefore aAlwaysDefineHue = false makes difference between Red and Gray colors.
*/ */
void ToHSV( double& aOutHue, double& aOutSaturation, double& aOutValue, bool aAlwaysDefineHue = false ) const; void ToHSV( double& aOutHue, double& aOutSaturation, double& aOutValue,
bool aAlwaysDefineHue = false ) const;
/** /**
* Function FromHSV()
* Changes currently used color to the one given by hue, saturation and value parameters. * Changes currently used color to the one given by hue, saturation and value parameters.
* *
* @param aInH is hue component, in degrees. * @param aInH is hue component, in degrees.

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 Kicad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -33,7 +35,6 @@
namespace KIGFX namespace KIGFX
{ {
class COLOR4D; class COLOR4D;
class COMPOSITOR class COMPOSITOR
@ -49,14 +50,12 @@ public:
} }
/** /**
* Function Reset() * Perform primary initialization, necessary to use the object.
* performs primary initialiation, necessary to use the object.
*/ */
virtual void Initialize() = 0; virtual void Initialize() = 0;
/** /**
* Function Resize() * Clear the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.
* clears the state of COMPOSITOR, so it has to be reinitialized again with the new dimensions.
* *
* @param aWidth is the framebuffer width (in pixels). * @param aWidth is the framebuffer width (in pixels).
* @param aHeight is the framebuffer height (in pixels). * @param aHeight is the framebuffer height (in pixels).
@ -64,25 +63,23 @@ public:
virtual void Resize( unsigned int aWidth, unsigned int aHeight ) = 0; virtual void Resize( unsigned int aWidth, unsigned int aHeight ) = 0;
/** /**
* Function CreateBuffer() * Prepare a new buffer that may be used as a rendering target.
* prepares a new buffer that may be used as a rendering target.
* *
* @return is the handle of the buffer. In case of failure 0 (zero) is returned as the handle. * @return is the handle of the buffer. In case of failure 0 (zero) is returned as the handle.
*/ */
virtual unsigned int CreateBuffer() = 0; virtual unsigned int CreateBuffer() = 0;
/** /**
* Function GetBuffer() * Return currently used buffer handle.
* returns currently used buffer handle.
* *
* @return Currently used buffer handle. * @return Currently used buffer handle.
*/ */
virtual unsigned int GetBuffer() const = 0; virtual unsigned int GetBuffer() const = 0;
/** /**
* Function SetBuffer() * Set the selected buffer as the rendering target.
* sets the selected buffer as the rendering target. All the following drawing functions are *
* going to be rendered in the selected buffer. * All the following drawing functions are going to be rendered in the selected buffer.
* *
* @param aBufferHandle is the handle of the buffer or 0 in case of rendering directly to the * @param aBufferHandle is the handle of the buffer or 0 in case of rendering directly to the
* display. * display.
@ -90,27 +87,23 @@ public:
virtual void SetBuffer( unsigned int aBufferHandle ) = 0; virtual void SetBuffer( unsigned int aBufferHandle ) = 0;
/** /**
* Function ClearBuffer() * Clear the selected buffer (set by the SetBuffer() function).
* clears the selected buffer (set by the SetBuffer() function).
*/ */
virtual void ClearBuffer( const COLOR4D& aColor ) = 0; virtual void ClearBuffer( const COLOR4D& aColor ) = 0;
/** /**
* Function Begin() * Call this at the beginning of each frame.
* Call this at the beginning of each frame
*/ */
virtual void Begin() = 0; virtual void Begin() = 0;
/** /**
* Function DrawBuffer() * Draw the selected buffer to the output buffer.
* draws the selected buffer to the output buffer.
* *
* @param aBufferHandle is the handle of the buffer to be drawn. * @param aBufferHandle is the handle of the buffer to be drawn.
*/ */
virtual void DrawBuffer( unsigned int aBufferHandle ) = 0; virtual void DrawBuffer( unsigned int aBufferHandle ) = 0;
/** /**
* Function Present()
* Call this to present the output buffer to the screen. * Call this to present the output buffer to the screen.
*/ */
virtual void Present() = 0; virtual void Present() = 0;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* Graphics Abstraction Layer (GAL) - base class * Graphics Abstraction Layer (GAL) - base class
* *
@ -47,13 +47,13 @@ namespace KIGFX
{ {
/** /**
* @brief Class GAL is the abstract interface for drawing on a 2D-surface. * Class GAL is the abstract interface for drawing on a 2D-surface.
* *
* The functions are optimized for drawing shapes of an EDA-program such as KiCad. Most methods * The functions are optimized for drawing shapes of an EDA-program such as KiCad. Most methods
* are abstract and need to be implemented by a lower layer, for example by a cairo or OpenGL implementation. * are abstract and need to be implemented by a lower layer, for example by a cairo or OpenGL
* <br> * implementation. Almost all methods use world coordinates as arguments. The board design is
* Almost all methods use world coordinates as arguments. The board design is defined in world space units; * defined in world space units for drawing purposes these are transformed to screen units with
* for drawing purposes these are transformed to screen units with this layer. So zooming is handled here as well. * this layer. So zooming is handled here as well.
* *
*/ */
class GAL : GAL_DISPLAY_OPTIONS_OBSERVER class GAL : GAL_DISPLAY_OPTIONS_OBSERVER
@ -69,16 +69,16 @@ public:
GAL( GAL_DISPLAY_OPTIONS& aOptions ); GAL( GAL_DISPLAY_OPTIONS& aOptions );
virtual ~GAL(); virtual ~GAL();
/// @brief Returns the initalization status for the canvas. /// Returns the initialization status for the canvas.
virtual bool IsInitialized() const { return true; } virtual bool IsInitialized() const { return true; }
/// @brief Returns true if the GAL canvas is visible on the screen. /// Returns true if the GAL canvas is visible on the screen.
virtual bool IsVisible() const { return true; } virtual bool IsVisible() const { return true; }
/// @brief Returns true if the GAL engine is a cairo based type. /// Returns true if the GAL engine is a cairo based type.
virtual bool IsCairoEngine() { return false; } virtual bool IsCairoEngine() { return false; }
/// @brief Returns true if the GAL engine is a opengl based type. /// Returns true if the GAL engine is a OpenGL based type.
virtual bool IsOpenGlEngine() { return false; } virtual bool IsOpenGlEngine() { return false; }
// --------------- // ---------------
@ -86,7 +86,7 @@ public:
// --------------- // ---------------
/** /**
* @brief Draw a line. * Draw a line.
* *
* Start and end points are defined as 2D-Vectors. * Start and end points are defined as 2D-Vectors.
* *
@ -96,7 +96,7 @@ public:
virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {}; virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
/** /**
* @brief Draw a rounded segment. * Draw a rounded segment.
* *
* Start and end points are defined as 2D-Vectors. * Start and end points are defined as 2D-Vectors.
* *
@ -104,10 +104,11 @@ public:
* @param aEndPoint is the end point of the segment. * @param aEndPoint is the end point of the segment.
* @param aWidth is a width of the segment * @param aWidth is a width of the segment
*/ */
virtual void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth ) {}; virtual void DrawSegment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint,
double aWidth ) {};
/** /**
* @brief Draw a polyline * Draw a polyline
* *
* @param aPointList is a list of 2D-Vectors containing the polyline points. * @param aPointList is a list of 2D-Vectors containing the polyline points.
*/ */
@ -116,7 +117,7 @@ public:
virtual void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) {}; virtual void DrawPolyline( const SHAPE_LINE_CHAIN& aLineChain ) {};
/** /**
* @brief Draw a circle using world coordinates. * Draw a circle using world coordinates.
* *
* @param aCenterPoint is the center point of the circle. * @param aCenterPoint is the center point of the circle.
* @param aRadius is the radius of the circle. * @param aRadius is the radius of the circle.
@ -124,7 +125,7 @@ public:
virtual void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) {}; virtual void DrawCircle( const VECTOR2D& aCenterPoint, double aRadius ) {};
/** /**
* @brief Draw an arc. * Draw an arc.
* *
* @param aCenterPoint is the center point of the arc. * @param aCenterPoint is the center point of the arc.
* @param aRadius is the arc radius. * @param aRadius is the arc radius.
@ -132,10 +133,11 @@ public:
* @param aEndAngle is the end angle of the arc. * @param aEndAngle is the end angle of the arc.
*/ */
virtual void virtual void
DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, double aEndAngle ) {}; DrawArc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle,
double aEndAngle ) {};
/** /**
* @brief Draw an arc segment. * Draw an arc segment.
* *
* This method differs from DrawArc() in what happens when fill/stroke are on or off. * This method differs from DrawArc() in what happens when fill/stroke are on or off.
* DrawArc() draws a "pie piece" when fill is turned on, and a thick stroke when fill is off. * DrawArc() draws a "pie piece" when fill is turned on, and a thick stroke when fill is off.
@ -155,7 +157,7 @@ public:
double aEndAngle, double aWidth ) {}; double aEndAngle, double aWidth ) {};
/** /**
* @brief Draw a rectangle. * Draw a rectangle.
* *
* @param aStartPoint is the start point of the rectangle. * @param aStartPoint is the start point of the rectangle.
* @param aEndPoint is the end point of the rectangle. * @param aEndPoint is the end point of the rectangle.
@ -163,7 +165,7 @@ public:
virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {}; virtual void DrawRectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) {};
/** /**
* @brief Draw a polygon. * Draw a polygon.
* *
* @param aPointList is the list of the polygon points. * @param aPointList is the list of the polygon points.
*/ */
@ -173,7 +175,7 @@ public:
virtual void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) {}; virtual void DrawPolygon( const SHAPE_LINE_CHAIN& aPolySet ) {};
/** /**
* @brief Draw a cubic bezier spline. * Draw a cubic bezier spline.
* *
* @param startPoint is the start point of the spline. * @param startPoint is the start point of the spline.
* @param controlPointA is the first control point. * @param controlPointA is the first control point.
@ -188,7 +190,7 @@ public:
double aFilterValue = 0.0 ) {}; double aFilterValue = 0.0 ) {};
/** /**
* @brief Draw a bitmap image. * Draw a bitmap image.
*/ */
virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) {}; virtual void DrawBitmap( const BITMAP_BASE& aBitmap ) {};
@ -196,19 +198,19 @@ public:
// Screen methods // Screen methods
// -------------- // --------------
/// @brief Resizes the canvas. /// Resizes the canvas.
virtual void ResizeScreen( int aWidth, int aHeight ) {}; virtual void ResizeScreen( int aWidth, int aHeight ) {};
/// @brief Shows/hides the GAL canvas /// Shows/hides the GAL canvas
virtual bool Show( bool aShow ) { return true; }; virtual bool Show( bool aShow ) { return true; };
/// @brief Returns GAL canvas size in pixels /// Returns GAL canvas size in pixels
const VECTOR2I& GetScreenPixelSize() const const VECTOR2I& GetScreenPixelSize() const
{ {
return screenSize; return screenSize;
} }
/// @brief Force all remaining objects to be drawn. /// Force all remaining objects to be drawn.
virtual void Flush() {}; virtual void Flush() {};
void SetClearColor( const COLOR4D& aColor ) void SetClearColor( const COLOR4D& aColor )
@ -222,7 +224,8 @@ public:
} }
/** /**
* @brief Clear the screen. * Clear the screen.
*
* @param aColor is the color used for clearing. * @param aColor is the color used for clearing.
*/ */
virtual void ClearScreen() {}; virtual void ClearScreen() {};
@ -232,7 +235,7 @@ public:
// ----------------- // -----------------
/** /**
* @brief Enable/disable fill. * Enable/disable fill.
* *
* @param aIsFillEnabled is true, when the graphics objects should be filled, else false. * @param aIsFillEnabled is true, when the graphics objects should be filled, else false.
*/ */
@ -242,7 +245,7 @@ public:
} }
/** /**
* @brief Enable/disable stroked outlines. * Enable/disable stroked outlines.
* *
* @param aIsStrokeEnabled is true, if the outline of an object should be stroked. * @param aIsStrokeEnabled is true, if the outline of an object should be stroked.
*/ */
@ -252,7 +255,7 @@ public:
} }
/** /**
* @brief Set the fill color. * Set the fill color.
* *
* @param aColor is the color for filling. * @param aColor is the color for filling.
*/ */
@ -262,7 +265,7 @@ public:
} }
/** /**
* @brief Get the fill color. * Get the fill color.
* *
* @return the color for filling a outline. * @return the color for filling a outline.
*/ */
@ -272,7 +275,7 @@ public:
} }
/** /**
* @brief Set the stroke color. * Set the stroke color.
* *
* @param aColor is the color for stroking the outline. * @param aColor is the color for stroking the outline.
*/ */
@ -282,7 +285,7 @@ public:
} }
/** /**
* @brief Get the stroke color. * Get the stroke color.
* *
* @return the color for stroking the outline. * @return the color for stroking the outline.
*/ */
@ -292,7 +295,7 @@ public:
} }
/** /**
* @brief Set the line width. * Set the line width.
* *
* @param aLineWidth is the line width. * @param aLineWidth is the line width.
*/ */
@ -302,7 +305,7 @@ public:
} }
/** /**
* @brief Get the line width. * Get the line width.
* *
* @return the actual line width. * @return the actual line width.
*/ */
@ -312,7 +315,7 @@ public:
} }
/** /**
* @brief Set the depth of the layer (position on the z-axis) * Set the depth of the layer (position on the z-axis)
* *
* @param aLayerDepth the layer depth for the objects. * @param aLayerDepth the layer depth for the objects.
*/ */
@ -334,7 +337,7 @@ public:
} }
/** /**
* @brief Draws a vector type text using preloaded Newstroke font. * Draws a vector type text using preloaded Newstroke font.
* *
* @param aText is the text to be drawn. * @param aText is the text to be drawn.
* @param aPosition is the text position in world coordinates. * @param aPosition is the text position in world coordinates.
@ -347,7 +350,7 @@ public:
} }
/** /**
* @brief Draws a text using a bitmap font. It should be faster than StrokeText(), * Draws a text using a bitmap font. It should be faster than StrokeText(),
* but can be used only for non-Gerber elements. * but can be used only for non-Gerber elements.
* *
* @param aText is the text to be drawn. * @param aText is the text to be drawn.
@ -370,7 +373,7 @@ public:
} }
/** /**
* @brief Compute the X and Y size of a given text. The text is expected to be * Compute the X and Y size of a given text. The text is expected to be
* a only one line text. * a only one line text.
* *
* @param aText is the text string (one line). * @param aText is the text string (one line).
@ -379,7 +382,7 @@ public:
VECTOR2D GetTextLineSize( const UTF8& aText ) const; VECTOR2D GetTextLineSize( const UTF8& aText ) const;
/** /**
* @brief Loads attributes of the given text (bold/italic/underline/mirrored and so on). * Loads attributes of the given text (bold/italic/underline/mirrored and so on).
* *
* @param aText is the text item. * @param aText is the text item.
*/ */
@ -394,7 +397,7 @@ public:
void ResetTextAttributes(); void ResetTextAttributes();
/** /**
* @brief Set the font glyph size. * Set the font glyph size.
* *
* @param aGlyphSize is the new font glyph size. * @param aGlyphSize is the new font glyph size.
*/ */
@ -402,7 +405,7 @@ public:
const VECTOR2D& GetGlyphSize() const { return textProperties.m_glyphSize; } const VECTOR2D& GetGlyphSize() const { return textProperties.m_glyphSize; }
/** /**
* @brief Set bold property of current font. * Set bold property of current font.
* *
* @param aBold tells if the font should be bold or not. * @param aBold tells if the font should be bold or not.
*/ */
@ -410,7 +413,7 @@ public:
inline bool IsFontBold() const { return textProperties.m_bold; } inline bool IsFontBold() const { return textProperties.m_bold; }
/** /**
* @brief Set italic property of current font. * Set italic property of current font.
* *
* @param aItalic tells if the font should be italic or not. * @param aItalic tells if the font should be italic or not.
*/ */
@ -421,7 +424,7 @@ public:
inline bool IsFontUnderlined() const { return textProperties.m_underlined; } inline bool IsFontUnderlined() const { return textProperties.m_underlined; }
/** /**
* @brief Set a mirrored property of text. * Set a mirrored property of text.
* *
* @param aMirrored tells if the text should be mirrored or not. * @param aMirrored tells if the text should be mirrored or not.
*/ */
@ -429,7 +432,7 @@ public:
inline bool IsTextMirrored() const { return textProperties.m_mirrored; } inline bool IsTextMirrored() const { return textProperties.m_mirrored; }
/** /**
* @brief Set the horizontal justify for text drawing. * Set the horizontal justify for text drawing.
* *
* @param aHorizontalJustify is the horizontal justify value. * @param aHorizontalJustify is the horizontal justify value.
*/ */
@ -439,7 +442,7 @@ public:
} }
/** /**
* @brief Returns current text horizontal justification setting. * Returns current text horizontal justification setting.
*/ */
inline EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const inline EDA_TEXT_HJUSTIFY_T GetHorizontalJustify() const
{ {
@ -447,7 +450,7 @@ public:
} }
/** /**
* @brief Set the vertical justify for text drawing. * Set the vertical justify for text drawing.
* *
* @param aVerticalJustify is the vertical justify value. * @param aVerticalJustify is the vertical justify value.
*/ */
@ -457,7 +460,7 @@ public:
} }
/** /**
* @brief Returns current text vertical justification setting. * Returns current text vertical justification setting.
*/ */
inline EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const inline EDA_TEXT_VJUSTIFY_T GetVerticalJustify() const
{ {
@ -470,37 +473,37 @@ public:
// -------------- // --------------
/** /**
* @brief Transform the context. * Transform the context.
* *
* @param aTransformation is the transformation matrix. * @param aTransformation is the transformation matrix.
*/ */
virtual void Transform( const MATRIX3x3D& aTransformation ) {}; virtual void Transform( const MATRIX3x3D& aTransformation ) {};
/** /**
* @brief Rotate the context. * Rotate the context.
* *
* @param aAngle is the rotation angle in radians. * @param aAngle is the rotation angle in radians.
*/ */
virtual void Rotate( double aAngle ) {}; virtual void Rotate( double aAngle ) {};
/** /**
* @brief Translate the context. * Translate the context.
* *
* @param aTranslation is the translation vector. * @param aTranslation is the translation vector.
*/ */
virtual void Translate( const VECTOR2D& aTranslation ) {}; virtual void Translate( const VECTOR2D& aTranslation ) {};
/** /**
* @brief Scale the context. * Scale the context.
* *
* @param aScale is the scale factor for the x- and y-axis. * @param aScale is the scale factor for the x- and y-axis.
*/ */
virtual void Scale( const VECTOR2D& aScale ) {}; virtual void Scale( const VECTOR2D& aScale ) {};
/// @brief Save the context. /// Save the context.
virtual void Save() {}; virtual void Save() {};
/// @brief Restore the context. /// Restore the context.
virtual void Restore() {}; virtual void Restore() {};
// -------------------------------------------- // --------------------------------------------
@ -508,7 +511,7 @@ public:
// --------------------------------------------- // ---------------------------------------------
/** /**
* @brief Begin a group. * Begin a group.
* *
* A group is a collection of graphic items. * A group is a collection of graphic items.
* Hierarchical groups are possible, attributes and transformations can be used. * Hierarchical groups are possible, attributes and transformations can be used.
@ -517,18 +520,18 @@ public:
*/ */
virtual int BeginGroup() { return 0; }; virtual int BeginGroup() { return 0; };
/// @brief End the group. /// End the group.
virtual void EndGroup() {}; virtual void EndGroup() {};
/** /**
* @brief Draw the stored group. * Draw the stored group.
* *
* @param aGroupNumber is the group number. * @param aGroupNumber is the group number.
*/ */
virtual void DrawGroup( int aGroupNumber ) {}; virtual void DrawGroup( int aGroupNumber ) {};
/** /**
* @brief Changes the color used to draw the group. * Changes the color used to draw the group.
* *
* @param aGroupNumber is the group number. * @param aGroupNumber is the group number.
* @param aNewColor is the new color. * @param aNewColor is the new color.
@ -536,7 +539,7 @@ public:
virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) {}; virtual void ChangeGroupColor( int aGroupNumber, const COLOR4D& aNewColor ) {};
/** /**
* @brief Changes the depth (Z-axis position) of the group. * Changes the depth (Z-axis position) of the group.
* *
* @param aGroupNumber is the group number. * @param aGroupNumber is the group number.
* @param aDepth is the new depth. * @param aDepth is the new depth.
@ -544,14 +547,14 @@ public:
virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) {}; virtual void ChangeGroupDepth( int aGroupNumber, int aDepth ) {};
/** /**
* @brief Delete the group from the memory. * Delete the group from the memory.
* *
* @param aGroupNumber is the group number. * @param aGroupNumber is the group number.
*/ */
virtual void DeleteGroup( int aGroupNumber ) {}; virtual void DeleteGroup( int aGroupNumber ) {};
/** /**
* @brief Delete all data created during caching of graphic items. * Delete all data created during caching of graphic items.
*/ */
virtual void ClearCache() {}; virtual void ClearCache() {};
@ -559,11 +562,11 @@ public:
// Handling the world <-> screen transformation // Handling the world <-> screen transformation
// -------------------------------------------------------- // --------------------------------------------------------
/// @brief Compute the world <-> screen transformation matrix /// Compute the world <-> screen transformation matrix
virtual void ComputeWorldScreenMatrix(); virtual void ComputeWorldScreenMatrix();
/** /**
* @brief Get the world <-> screen transformation matrix. * Get the world <-> screen transformation matrix.
* *
* @return the transformation matrix. * @return the transformation matrix.
*/ */
@ -573,7 +576,7 @@ public:
} }
/** /**
* @brief Get the screen <-> world transformation matrix. * Get the screen <-> world transformation matrix.
* *
* @return the transformation matrix. * @return the transformation matrix.
*/ */
@ -583,7 +586,7 @@ public:
} }
/** /**
* @brief Set the world <-> screen transformation matrix. * Set the world <-> screen transformation matrix.
* *
* @param aMatrix is the 3x3 world <-> screen transformation matrix. * @param aMatrix is the 3x3 world <-> screen transformation matrix.
*/ */
@ -593,7 +596,7 @@ public:
} }
/** /**
* @brief Set the unit length. * Set the unit length.
* *
* This defines the length [inch] per one integer. For instance a value 0.001 means * This defines the length [inch] per one integer. For instance a value 0.001 means
* that the coordinate [1000, 1000] corresponds with a point at (1 inch, 1 inch) or * that the coordinate [1000, 1000] corresponds with a point at (1 inch, 1 inch) or
@ -612,7 +615,7 @@ public:
} }
/** /**
* @brief Set the dots per inch of the screen. * Set the dots per inch of the screen.
* *
* This value depends on the user screen, it should be configurable by the application. * This value depends on the user screen, it should be configurable by the application.
* For instance a typical notebook with HD+ resolution (1600x900) has 106 DPI. * For instance a typical notebook with HD+ resolution (1600x900) has 106 DPI.
@ -625,7 +628,7 @@ public:
} }
/** /**
* @brief Set the Point in world space to look at. * Set the Point in world space to look at.
* *
* This point corresponds with the center of the actual drawing area. * This point corresponds with the center of the actual drawing area.
* *
@ -637,7 +640,7 @@ public:
} }
/** /**
* @brief Get the look at point. * Get the look at point.
* *
* @return the look at point. * @return the look at point.
*/ */
@ -647,7 +650,7 @@ public:
} }
/** /**
* @brief Set the zoom factor of the scene. * Set the zoom factor of the scene.
* *
* @param aZoomFactor is the zoom factor. * @param aZoomFactor is the zoom factor.
*/ */
@ -657,7 +660,7 @@ public:
} }
/** /**
* @brief Get the zoom factor * Get the zoom factor
* *
* @return the zoom factor. * @return the zoom factor.
*/ */
@ -667,7 +670,7 @@ public:
} }
/** /**
* @brief Set the rotation angle. * Set the rotation angle.
* *
* @param aRotation is the new rotation angle (radians). * @param aRotation is the new rotation angle (radians).
*/ */
@ -687,7 +690,7 @@ public:
} }
/** /**
* @brief Set the range of the layer depth. * Set the range of the layer depth.
* *
* Usually required for the OpenGL implementation, any object outside this range is not drawn. * Usually required for the OpenGL implementation, any object outside this range is not drawn.
* *
@ -700,7 +703,7 @@ public:
} }
/** /**
* @brief Returns the minimum depth in the currently used range (the top). * Returns the minimum depth in the currently used range (the top).
*/ */
inline double GetMinDepth() const inline double GetMinDepth() const
{ {
@ -708,7 +711,7 @@ public:
} }
/** /**
* @brief Returns the maximum depth in the currently used range (the bottom). * Returns the maximum depth in the currently used range (the bottom).
*/ */
inline double GetMaxDepth() const inline double GetMaxDepth() const
{ {
@ -716,7 +719,7 @@ public:
} }
/** /**
* @brief Get the world scale. * Get the world scale.
* *
* @return the actual world scale factor. * @return the actual world scale factor.
*/ */
@ -726,7 +729,7 @@ public:
} }
/** /**
* @brief Sets flipping of the screen. * Sets flipping of the screen.
* *
* @param xAxis is the flip flag for the X axis. * @param xAxis is the flip flag for the X axis.
* @param yAxis is the flip flag for the Y axis. * @param yAxis is the flip flag for the Y axis.
@ -758,28 +761,28 @@ public:
// --------------------------- // ---------------------------
/** /**
* @brief Sets the target for rendering. * Sets the target for rendering.
* *
* @param aTarget is the new target for rendering. * @param aTarget is the new target for rendering.
*/ */
virtual void SetTarget( RENDER_TARGET aTarget ) {}; virtual void SetTarget( RENDER_TARGET aTarget ) {};
/** /**
* @brief Gets the currently used target for rendering. * Gets the currently used target for rendering.
* *
* @return The current rendering target. * @return The current rendering target.
*/ */
virtual RENDER_TARGET GetTarget() const { return TARGET_CACHED; }; virtual RENDER_TARGET GetTarget() const { return TARGET_CACHED; };
/** /**
* @brief Clears the target for rendering. * Clears the target for rendering.
* *
* @param aTarget is the target to be cleared. * @param aTarget is the target to be cleared.
*/ */
virtual void ClearTarget( RENDER_TARGET aTarget ) {}; virtual void ClearTarget( RENDER_TARGET aTarget ) {};
/** /**
* @brief Returns true if the target exists. * Returns true if the target exists.
* *
* @param aTarget is the target to be checked. * @param aTarget is the target to be checked.
*/ */
@ -789,7 +792,7 @@ public:
}; };
/** /**
* @brief Sets negative draw mode in the renderer * Sets negative draw mode in the renderer
* *
* When negative mode is enabled, drawn items will subtract from * When negative mode is enabled, drawn items will subtract from
* previously drawn items. This is mainly needed for Gerber * previously drawn items. This is mainly needed for Gerber
@ -806,7 +809,7 @@ public:
// ------------- // -------------
/** /**
* @brief Sets the visibility setting of the grid. * Sets the visibility setting of the grid.
* *
* @param aVisibility is the new visibility setting of the grid. * @param aVisibility is the new visibility setting of the grid.
*/ */
@ -820,7 +823,7 @@ public:
( gridVisibility && options.m_gridSnapping == KIGFX::GRID_SNAPPING::WITH_GRID ) ); ( gridVisibility && options.m_gridSnapping == KIGFX::GRID_SNAPPING::WITH_GRID ) );
} }
/** /**
* @brief Set the origin point for the grid. * Set the origin point for the grid.
* *
* @param aGridOrigin is a vector containing the grid origin point, in world coordinates. * @param aGridOrigin is a vector containing the grid origin point, in world coordinates.
*/ */
@ -841,7 +844,7 @@ public:
} }
/** /**
* @brief Set the grid size. * Set the grid size.
* *
* @param aGridSize is a vector containing the grid size in x and y direction. * @param aGridSize is a vector containing the grid size in x and y direction.
*/ */
@ -858,7 +861,7 @@ public:
} }
/** /**
* @brief Returns the grid size. * Returns the grid size.
* *
* @return A vector containing the grid size in x and y direction. * @return A vector containing the grid size in x and y direction.
*/ */
@ -868,7 +871,7 @@ public:
} }
/** /**
* @brief Set the grid color. * Set the grid color.
* *
* @param aGridColor is the grid color, it should have a low alpha value for the best effect. * @param aGridColor is the grid color, it should have a low alpha value for the best effect.
*/ */
@ -878,7 +881,7 @@ public:
} }
/** /**
* @brief Set the axes color. * Set the axes color.
* *
* @param aAxesColor is the color to draw the axes if enabled. * @param aAxesColor is the color to draw the axes if enabled.
*/ */
@ -888,7 +891,7 @@ public:
} }
/** /**
* @brief Enables drawing the axes. * Enables drawing the axes.
*/ */
inline void SetAxesEnabled( bool aAxesEnabled ) inline void SetAxesEnabled( bool aAxesEnabled )
{ {
@ -896,7 +899,7 @@ public:
} }
/** /**
* @brief Draw every tick line wider. * Draw every tick line wider.
* *
* @param aInterval increase the width of every aInterval line, if 0 do not use this feature. * @param aInterval increase the width of every aInterval line, if 0 do not use this feature.
*/ */
@ -906,7 +909,7 @@ public:
} }
/** /**
* @brief Get the grid line width. * Get the grid line width.
* *
* @return the grid line width * @return the grid line width
*/ */
@ -915,11 +918,10 @@ public:
return gridLineWidth; return gridLineWidth;
} }
///> @brief Draw the grid ///> Draw the grid
virtual void DrawGrid() {}; virtual void DrawGrid() {};
/** /**
* Function GetGridPoint()
* For a given point it returns the nearest point belonging to the grid in world coordinates. * For a given point it returns the nearest point belonging to the grid in world coordinates.
* *
* @param aPoint is the point for which the grid point is searched. * @param aPoint is the point for which the grid point is searched.
@ -928,7 +930,7 @@ public:
VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const; VECTOR2D GetGridPoint( const VECTOR2D& aPoint ) const;
/** /**
* @brief Compute the point position in world coordinates from given screen coordinates. * Compute the point position in world coordinates from given screen coordinates.
* *
* @param aPoint the pointposition in screen coordinates. * @param aPoint the pointposition in screen coordinates.
* @return the point position in world coordinates. * @return the point position in world coordinates.
@ -939,7 +941,7 @@ public:
} }
/** /**
* @brief Compute the point position in screen coordinates from given world coordinates. * Compute the point position in screen coordinates from given world coordinates.
* *
* @param aPoint the pointposition in world coordinates. * @param aPoint the pointposition in world coordinates.
* @return the point position in screen coordinates. * @return the point position in screen coordinates.
@ -950,7 +952,7 @@ public:
} }
/** /**
* @brief Enable/disable cursor. * Enable/disable cursor.
* *
* @param aCursorEnabled is true if the cursor should be drawn, else false. * @param aCursorEnabled is true if the cursor should be drawn, else false.
*/ */
@ -960,7 +962,8 @@ public:
} }
/** /**
* @brief Returns information about cursor visibility. * Returns information about cursor visibility.
*
* @return True if cursor is visible. * @return True if cursor is visible.
*/ */
bool IsCursorEnabled() const bool IsCursorEnabled() const
@ -969,7 +972,7 @@ public:
} }
/** /**
* @brief Set the cursor color. * Set the cursor color.
* *
* @param aCursorColor is the color of the cursor. * @param aCursorColor is the color of the cursor.
*/ */
@ -979,14 +982,14 @@ public:
} }
/** /**
* @brief Draw the cursor. * Draw the cursor.
* *
* @param aCursorPosition is the cursor position in screen coordinates. * @param aCursorPosition is the cursor position in screen coordinates.
*/ */
virtual void DrawCursor( const VECTOR2D& aCursorPosition ) {}; virtual void DrawCursor( const VECTOR2D& aCursorPosition ) {};
/** /**
* @brief Changes the current depth to deeper, so it is possible to draw objects right beneath * Changes the current depth to deeper, so it is possible to draw objects right beneath
* other. * other.
*/ */
inline void AdvanceDepth() inline void AdvanceDepth()
@ -995,7 +998,7 @@ public:
} }
/** /**
* @brief Stores current drawing depth on the depth stack. * Stores current drawing depth on the depth stack.
*/ */
inline void PushDepth() inline void PushDepth()
{ {
@ -1003,7 +1006,7 @@ public:
} }
/** /**
* @brief Restores previously stored drawing depth for the depth stack. * Restores previously stored drawing depth for the depth stack.
*/ */
inline void PopDepth() inline void PopDepth()
{ {
@ -1014,6 +1017,68 @@ public:
virtual void EnableDepthTest( bool aEnabled = false ) {}; virtual void EnableDepthTest( bool aEnabled = false ) {};
protected: protected:
/// Private: use GAL_CONTEXT_LOCKER RAII object
virtual void lockContext( int aClientCookie ) {}
virtual void unlockContext( int aClientCookie ) {}
/// Enables item update mode.
/// Private: use GAL_UPDATE_CONTEXT RAII object
virtual void beginUpdate() {}
/// Disables item update mode.
virtual void endUpdate() {}
/// Begin the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void beginDrawing() {};
/// End the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void endDrawing() {};
/// Compute the scaling factor for the world->screen matrix
inline void computeWorldScale()
{
worldScale = screenDPI * worldUnitLength * zoomFactor;
}
/**
* compute minimum grid spacing from the grid settings
*
* @return the minimum spacing to use for drawing the grid
*/
double computeMinGridSpacing() const;
/// Possible depth range
static const int MIN_DEPTH;
static const int MAX_DEPTH;
/// Depth level on which the grid is drawn
static const int GRID_DEPTH;
/**
* Gets the actual cursor color to draw
*/
COLOR4D getCursorColor() const;
// ---------------
// Settings observer interface
// ---------------
/**
* Handler for observer settings changes
*/
void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions ) override;
/**
* Handle updating display options.
*
* Derived classes should call up to this to set base-class methods.
*
* @return true if the new settings changed something. Derived classes can use this
* information to refresh themselves
*/
virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
GAL_DISPLAY_OPTIONS& options; GAL_DISPLAY_OPTIONS& options;
UTIL::LINK observerLink; UTIL::LINK observerLink;
@ -1070,70 +1135,6 @@ protected:
/// Instance of object that stores information about how to draw texts /// Instance of object that stores information about how to draw texts
STROKE_FONT strokeFont; STROKE_FONT strokeFont;
/// Private: use GAL_CONTEXT_LOCKER RAII object
virtual void lockContext( int aClientCookie ) {}
virtual void unlockContext( int aClientCookie ) {}
/// @brief Enables item update mode.
/// Private: use GAL_UPDATE_CONTEXT RAII object
virtual void beginUpdate() {}
/// @brief Disables item update mode.
virtual void endUpdate() {}
/// @brief Begin the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void beginDrawing() {};
/// @brief End the drawing, needs to be called for every new frame.
/// Private: use GAL_DRAWING_CONTEXT RAII object
virtual void endDrawing() {};
/// Compute the scaling factor for the world->screen matrix
inline void computeWorldScale()
{
worldScale = screenDPI * worldUnitLength * zoomFactor;
}
/**
* @brief compute minimum grid spacing from the grid settings
*
* @return the minimum spacing to use for drawing the grid
*/
double computeMinGridSpacing() const;
/// Possible depth range
static const int MIN_DEPTH;
static const int MAX_DEPTH;
/// Depth level on which the grid is drawn
static const int GRID_DEPTH;
/**
* Gets the actual cursor color to draw
*/
COLOR4D getCursorColor() const;
// ---------------
// Settings observer interface
// ---------------
/**
* Handler for observer settings changes
*/
void OnGalDisplayOptionsChanged( const GAL_DISPLAY_OPTIONS& aOptions ) override;
/**
* Function updatedGalDisplayOptions
*
* @brief handler for updated display options. Derived classes
* should call up to this to set base-class methods.
*
* @return true if the new settings changed something. Derived classes
* can use this information to refresh themselves
*/
virtual bool updatedGalDisplayOptions( const GAL_DISPLAY_OPTIONS& aOptions );
private: private:
struct TEXT_PROPERTIES struct TEXT_PROPERTIES
{ {

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2017 Bernhard Stegmaier <stegmaier@sw-systems.de> * Copyright (C) 2017 Bernhard Stegmaier <stegmaier@sw-systems.de>
* Copyright (C) 2016-2017 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2016-2020 Kicad Developers, see AUTHORS.txt for contributors.
* *
* Base class for HiDPI aware wxGLCanvas implementations. * Base class for HiDPI aware wxGLCanvas implementations.
* *
@ -31,7 +31,7 @@
/** /**
* @brief wxGLCanvas wrapper for HiDPI/Retina support. * wxGLCanvas wrapper for HiDPI/Retina support.
* *
* This is a small wrapper class to enable HiDPI/Retina support for wxGLCanvas. * This is a small wrapper class to enable HiDPI/Retina support for wxGLCanvas.
*/ */
@ -39,16 +39,11 @@ class HIDPI_GL_CANVAS : public wxGLCanvas
{ {
public: public:
// wxGLCanvas constructor // wxGLCanvas constructor
HIDPI_GL_CANVAS( wxWindow *parent, HIDPI_GL_CANVAS( wxWindow *parent, wxWindowID id = wxID_ANY, const int *attribList = NULL,
wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
const int *attribList = NULL, long style = 0, const wxString& name = wxGLCanvasName,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxGLCanvasName,
const wxPalette& palette = wxNullPalette ); const wxPalette& palette = wxNullPalette );
virtual wxSize GetNativePixelSize() const; virtual wxSize GetNativePixelSize() const;
/** /**

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright 2013-2017 CERN * Copyright 2013-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -35,8 +37,9 @@ class VERTEX_ITEM;
class SHADER; class SHADER;
/** /**
* @brief Class to store VERTEX instances with caching. It associates VERTEX * Class to store VERTEX instances with caching.
* objects and with VERTEX_ITEMs. Caching vertices data in the memory and a *
* It associates VERTEX objects and with VERTEX_ITEMs. Caching vertices data in the memory and a
* enables fast reuse of that data. * enables fast reuse of that data.
*/ */
@ -67,12 +70,12 @@ public:
virtual void Clear() override; virtual void Clear() override;
/** /**
* Returns handle to the vertex buffer. It might be negative if the buffer is not initialized. * Return handle to the vertex buffer. It might be negative if the buffer is not initialized.
*/ */
virtual unsigned int GetBufferHandle() const = 0; virtual unsigned int GetBufferHandle() const = 0;
/** /**
* Returns true if vertex buffer is currently mapped. * Return true if vertex buffer is currently mapped.
*/ */
virtual bool IsMapped() const = 0; virtual bool IsMapped() const = 0;
@ -90,7 +93,67 @@ protected:
/// List of all the stored items /// List of all the stored items
typedef std::set<VERTEX_ITEM*> ITEMS; typedef std::set<VERTEX_ITEM*> ITEMS;
///> Stores size & offset of free chunks. /**
* Resize the chunk that stores the current item to the given size. The current item has
* its offset adjusted after the call, and the new chunk parameters are stored
* in m_chunkOffset and m_chunkSize.
*
* @param aSize is the requested chunk size.
* @return true in case of success, false otherwise.
*/
bool reallocate( unsigned int aSize );
/**
* Remove empty spaces between chunks and optionally resizes the container.
*
* After the operation there is continuous space for storing vertices at the end of the
* container.
*
* @param aNewSize is the new size of container, expressed in number of vertices.
* @return false in case of failure (e.g. memory shortage).
*/
virtual bool defragmentResize( unsigned int aNewSize ) = 0;
/**
* Transfer all stored data to a new buffer, removing empty spaces between the data chunks
* in the container.
*
* @param aTarget is the destination for the defragmented data.
*/
void defragment( VERTEX* aTarget );
/**
* Look for consecutive free memory chunks and merges them, decreasing fragmentation of
* memory.
*/
void mergeFreeChunks();
/**
* Return the size of a chunk.
*
* @param aChunk is the chunk.
*/
inline int getChunkSize( const CHUNK& aChunk ) const
{
return aChunk.first;
}
/**
* Return the offset of a chunk.
*
* @param aChunk is the chunk.
*/
inline unsigned int getChunkOffset( const CHUNK& aChunk ) const
{
return aChunk.second;
}
/**
* Add a chunk marked as a free space.
*/
void addFreeChunk( unsigned int aOffset, unsigned int aSize );
///> Store size & offset of free chunks.
FREE_CHUNK_MAP m_freeChunks; FREE_CHUNK_MAP m_freeChunks;
///> Stored VERTEX_ITEMs ///> Stored VERTEX_ITEMs
@ -106,63 +169,6 @@ protected:
///> Maximal vertex index number stored in the container ///> Maximal vertex index number stored in the container
unsigned int m_maxIndex; unsigned int m_maxIndex;
/**
* Resizes the chunk that stores the current item to the given size. The current item has
* its offset adjusted after the call, and the new chunk parameters are stored
* in m_chunkOffset and m_chunkSize.
*
* @param aSize is the requested chunk size.
* @return true in case of success, false otherwise
*/
bool reallocate( unsigned int aSize );
/**
* Removes empty spaces between chunks and optionally resizes the container.
* After the operation there is continous space for storing vertices at the end of the container.
*
* @param aNewSize is the new size of container, expressed in number of vertices
* @return false in case of failure (e.g. memory shortage)
*/
virtual bool defragmentResize( unsigned int aNewSize ) = 0;
/**
* Transfers all stored data to a new buffer, removing empty spaces between the data chunks
* in the container.
* @param aTarget is the destination for the defragmented data.
*/
void defragment( VERTEX* aTarget );
/**
* Looks for consecutive free memory chunks and merges them, decreasing fragmentation of
* memory.
*/
void mergeFreeChunks();
/**
* Returns the size of a chunk.
*
* @param aChunk is the chunk.
*/
inline int getChunkSize( const CHUNK& aChunk ) const
{
return aChunk.first;
}
/**
* Returns the offset of a chunk.
*
* @param aChunk is the chunk.
*/
inline unsigned int getChunkOffset( const CHUNK& aChunk ) const
{
return aChunk.second;
}
/**
* Adds a chunk marked as a free space.
*/
void addFreeChunk( unsigned int aOffset, unsigned int aSize );
private: private:
/// Debug & test functions /// Debug & test functions
void showFreeChunks(); void showFreeChunks();

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright 2013-2017 CERN * Copyright 2013-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -31,7 +33,7 @@ namespace KIGFX
{ {
/** /**
* @brief Specialization of CACHED_CONTAINER that stores data in video memory via memory mapping. * Specialization of CACHED_CONTAINER that stores data in video memory via memory mapping.
*/ */
class CACHED_CONTAINER_GPU : public CACHED_CONTAINER class CACHED_CONTAINER_GPU : public CACHED_CONTAINER
@ -57,6 +59,18 @@ public:
void Unmap() override; void Unmap() override;
protected: protected:
/**
* Remove empty spaces between chunks and optionally resizes the container.
*
* After the operation there is continuous space for storing vertices at the end of
* the container.
*
* @param aNewSize is the new size of container, expressed in number of vertices.
* @return false in case of failure (e.g. memory shortage).
*/
bool defragmentResize( unsigned int aNewSize ) override;
bool defragmentResizeMemcpy( unsigned int aNewSize );
///> Flag saying if vertex buffer is currently mapped ///> Flag saying if vertex buffer is currently mapped
bool m_isMapped; bool m_isMapped;
@ -65,17 +79,6 @@ protected:
///> Flag saying whether it is safe to use glCopyBufferSubData ///> Flag saying whether it is safe to use glCopyBufferSubData
bool m_useCopyBuffer; bool m_useCopyBuffer;
/**
* Function defragmentResize()
* removes empty spaces between chunks and optionally resizes the container.
* After the operation there is continous space for storing vertices at the end of the container.
*
* @param aNewSize is the new size of container, expressed in number of vertices
* @return false in case of failure (e.g. memory shortage)
*/
bool defragmentResize( unsigned int aNewSize ) override;
bool defragmentResizeMemcpy( unsigned int aNewSize );
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright 2013-2017 CERN * Copyright 2013-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -35,8 +37,9 @@ class VERTEX_ITEM;
class SHADER; class SHADER;
/** /**
* @brief Specialization of CACHED_CONTAINER that stores data in RAM. This is mainly for * Specialization of CACHED_CONTAINER that stores data in RAM.
* video cards/drivers that do not cope well with video memory mapping. *
* This is mainly for video cards/drivers that do not cope well with video memory mapping.
*/ */
class CACHED_CONTAINER_RAM : public CACHED_CONTAINER class CACHED_CONTAINER_RAM : public CACHED_CONTAINER
@ -57,8 +60,9 @@ public:
} }
/** /**
* Function GetBufferHandle() * Return handle to the vertex buffer.
* returns handle to the vertex buffer. It might be negative if the buffer is not initialized. *
* It might be negative if the buffer is not initialized.
*/ */
unsigned int GetBufferHandle() const override unsigned int GetBufferHandle() const override
{ {
@ -66,15 +70,16 @@ public:
} }
protected: protected:
///> Handle to vertices buffer
GLuint m_verticesBuffer;
/** /**
* Defragments the currently stored data and resizes the buffer. * Defragment the currently stored data and resizes the buffer.
*
* @param aNewSize is the new buffer vertex buffer size, expressed as the number of vertices. * @param aNewSize is the new buffer vertex buffer size, expressed as the number of vertices.
* @return true on success. * @return true on success.
*/ */
bool defragmentResize( unsigned int aNewSize ) override; bool defragmentResize( unsigned int aNewSize ) override;
///> Handle to vertices buffer
GLuint m_verticesBuffer;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -36,9 +38,8 @@ class CACHED_CONTAINER;
class NONCACHED_CONTAINER; class NONCACHED_CONTAINER;
/** /**
* @brief Class to handle uploading vertices and indices to GPU in drawing purposes. * Class to handle uploading vertices and indices to GPU in drawing purposes.
*/ */
class GPU_MANAGER class GPU_MANAGER
{ {
public: public:
@ -47,41 +48,37 @@ public:
virtual ~GPU_MANAGER(); virtual ~GPU_MANAGER();
/** /**
* Function BeginDrawing() * Prepare the stored data to be drawn.
* Prepares the stored data to be drawn.
*/ */
virtual void BeginDrawing() = 0; virtual void BeginDrawing() = 0;
/** /**
* Function DrawIndices() * Make the GPU draw given range of vertices.
* Makes the GPU draw given range of vertices. *
* @param aOffset is the beginning of the range. * @param aOffset is the beginning of the range.
* @param aSize is the number of vertices to be drawn. * @param aSize is the number of vertices to be drawn.
*/ */
virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) = 0; virtual void DrawIndices( unsigned int aOffset, unsigned int aSize ) = 0;
/** /**
* Function DrawIndices() * Make the GPU draw all the vertices stored in the container.
* Makes the GPU draw all the vertices stored in the container.
*/ */
virtual void DrawAll() = 0; virtual void DrawAll() = 0;
/** /**
* Function EndDrawing()
* Clears the container after drawing routines. * Clears the container after drawing routines.
*/ */
virtual void EndDrawing() = 0; virtual void EndDrawing() = 0;
/** /**
* Function SetShader() * Allow using shaders with the stored data.
* Allows using shaders with the stored data. *
* @param aShader is the object that allows using shaders. * @param aShader is the object that allows using shaders.
*/ */
virtual void SetShader( SHADER& aShader ); virtual void SetShader( SHADER& aShader );
/** /**
* Function EnableDepthTest() * Enable/disable Z buffer depth test.
* Enables/disables Z buffer depth test.
*/ */
void EnableDepthTest( bool aEnabled ); void EnableDepthTest( bool aEnabled );

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,8 +26,8 @@
/** /**
* @file opengl_compositor.h * @file opengl_compositor.h
* @brief Class that handles multitarget rendering (ie. to different textures/surfaces) and * Handle multitarget rendering (ie. to different textures/surfaces) and later compositing
* later compositing into a single image (OpenGL flavour). * into a single image (OpenGL flavor).
*/ */
#ifndef OPENGL_COMPOSITOR_H_ #ifndef OPENGL_COMPOSITOR_H_
@ -83,7 +85,6 @@ public:
// Constant used by glBindFramebuffer to turn off rendering to framebuffers // Constant used by glBindFramebuffer to turn off rendering to framebuffers
static const unsigned int DIRECT_RENDERING = 0; static const unsigned int DIRECT_RENDERING = 0;
public:
VECTOR2U GetScreenSize() const; VECTOR2U GetScreenSize() const;
GLenum GetBufferTexture( unsigned int aBufferHandle ); GLenum GetBufferTexture( unsigned int aBufferHandle );
void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle ); void DrawBuffer( unsigned int aSourceHandle, unsigned int aDestHandle );
@ -95,6 +96,20 @@ public:
int GetAntialiasSupersamplingFactor() const; int GetAntialiasSupersamplingFactor() const;
protected: protected:
/// Binds a specific Framebuffer Object.
void bindFb( unsigned int aFb );
/**
* Perform freeing of resources.
*/
void clean();
/// Returns number of used buffers
inline unsigned int usedBuffers()
{
return m_buffers.size();
}
// Buffers are simply textures storing a result of certain target rendering. // Buffers are simply textures storing a result of certain target rendering.
typedef struct typedef struct
{ {
@ -117,21 +132,6 @@ protected:
OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode; OPENGL_ANTIALIASING_MODE m_currentAntialiasingMode;
std::unique_ptr<OPENGL_PRESENTOR> m_antialiasing; std::unique_ptr<OPENGL_PRESENTOR> m_antialiasing;
/// Binds a specific Framebuffer Object.
void bindFb( unsigned int aFb );
/**
* Function clean()
* performs freeing of resources.
*/
void clean();
/// Returns number of used buffers
inline unsigned int usedBuffers()
{
return m_buffers.size();
}
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,7 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * This program source code file is part of KICAD, a free EDA CAD application.
* *
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2012 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2012-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* Graphics Abstraction Layer (GAL) for OpenGL * Graphics Abstraction Layer (GAL) for OpenGL
* *
@ -64,12 +64,12 @@ inline const char* translateStringArg( const char* str )
/** /**
* @brief Class SHADER provides the access to the OpenGL shaders. * Provide the access to the OpenGL shaders.
* *
* The purpose of this class is advanced drawing with OpenGL. One example is using the pixel * The purpose of this class is advanced drawing with OpenGL. One example is using the pixel
* shader for drawing exact circles or for anti-aliasing. This class supports vertex, geometry * shader for drawing exact circles or for anti-aliasing. This class supports vertex, geometry
* and fragment shaders. * and fragment shaders.
* <br> *
* Make sure that the hardware supports these features. This can be identified with the "GLEW" * Make sure that the hardware supports these features. This can be identified with the "GLEW"
* library. * library.
*/ */
@ -77,21 +77,15 @@ class SHADER
{ {
public: public:
/**
* @brief Constructor
*/
SHADER(); SHADER();
/**
* @brief Destructor
*/
virtual ~SHADER(); virtual ~SHADER();
/** /**
* @brief Add a shader and compile the shader sources. * Add a shader and compile the shader sources.
* *
* @param aArgs is the list of strings (std::string or convertible to const char*) which * @param aArgs is the list of strings (std::string or convertible to const char*) which
are concatenated and compiled as a single shader source code. * are concatenated and compiled as a single shader source code.
* @param aShaderType is the type of the shader. * @param aShaderType is the type of the shader.
* @return True in case of success, false otherwise. * @return True in case of success, false otherwise.
*/ */
@ -103,7 +97,7 @@ public:
} }
/** /**
* @brief Loads one of the built-in shaders and compiles it. * Load one of the built-in shaders and compiles it.
* *
* @param aShaderSourceName is the shader source file name. * @param aShaderSourceName is the shader source file name.
* @param aShaderType is the type of the shader. * @param aShaderType is the type of the shader.
@ -112,14 +106,14 @@ public:
bool LoadShaderFromFile( SHADER_TYPE aShaderType, const std::string& aShaderSourceName ); bool LoadShaderFromFile( SHADER_TYPE aShaderType, const std::string& aShaderSourceName );
/** /**
* @brief Link the shaders. * Link the shaders.
* *
* @return true in case of success, false otherwise. * @return true in case of success, false otherwise.
*/ */
bool Link(); bool Link();
/** /**
* @brief Returns true if shaders are linked correctly. * Return true if shaders are linked correctly.
*/ */
bool IsLinked() const bool IsLinked() const
{ {
@ -127,7 +121,7 @@ public:
} }
/** /**
* @brief Use the shader. * Use the shader.
*/ */
inline void Use() inline void Use()
{ {
@ -136,7 +130,7 @@ public:
} }
/** /**
* @brief Deactivate the shader and use the default OpenGL program. * Deactivate the shader and use the default OpenGL program.
*/ */
inline void Deactivate() inline void Deactivate()
{ {
@ -145,7 +139,7 @@ public:
} }
/** /**
* @brief Returns the current state of the shader. * Return the current state of the shader.
* *
* @return True if any of shaders is enabled. * @return True if any of shaders is enabled.
*/ */
@ -155,7 +149,7 @@ public:
} }
/** /**
* @brief Configure the geometry shader - has to be done before linking! * Configure the geometry shader - has to be done before linking!
* *
* @param maxVertices is the maximum of vertices to be generated. * @param maxVertices is the maximum of vertices to be generated.
* @param geometryInputType is the input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.] * @param geometryInputType is the input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
@ -165,7 +159,7 @@ public:
GLuint geometryOutputType ); GLuint geometryOutputType );
/** /**
* @brief Add a parameter to the parameter queue. * Add a parameter to the parameter queue.
* *
* To communicate with the shader use this function to set up the names for the uniform * To communicate with the shader use this function to set up the names for the uniform
* variables. These are queued in a list and can be assigned with the SetParameter(..) * variables. These are queued in a list and can be assigned with the SetParameter(..)
@ -177,7 +171,7 @@ public:
int AddParameter( const std::string& aParameterName ); int AddParameter( const std::string& aParameterName );
/** /**
* @brief Set a parameter of the shader. * Set a parameter of the shader.
* *
* @param aParameterNumber is the number of the parameter. * @param aParameterNumber is the number of the parameter.
* @param aValue is the value of the parameter. * @param aValue is the value of the parameter.
@ -188,7 +182,7 @@ public:
void SetParameter( int aParameterNumber, float f0, float f1, float f2, float f3 ) const; void SetParameter( int aParameterNumber, float f0, float f1, float f2, float f3 ) const;
/** /**
* @brief Gets an attribute location. * Get an attribute location.
* *
* @param aAttributeName is the name of the attribute. * @param aAttributeName is the name of the attribute.
* @return the location. * @return the location.
@ -196,7 +190,7 @@ public:
int GetAttribute( const std::string& aAttributeName ) const; int GetAttribute( const std::string& aAttributeName ) const;
/** /**
* @brief Read the shader source file * Read the shader source file
* *
* @param aShaderSourceName is the shader source file name. * @param aShaderSourceName is the shader source file name.
* @return the source as string * @return the source as string
@ -204,22 +198,20 @@ public:
static std::string ReadSource( const std::string& aShaderSourceName ); static std::string ReadSource( const std::string& aShaderSourceName );
private: private:
/** /**
* @brief Compile vertex of fragment shader source code into the program. * Compile vertex of fragment shader source code into the program.
*/ */
bool loadShaderFromStringArray( SHADER_TYPE aShaderType, const char** aArray, bool loadShaderFromStringArray( SHADER_TYPE aShaderType, const char** aArray, size_t aSize );
size_t aSize );
/** /**
* @brief Get the shader program information. * Get the shader program information.
* *
* @param aProgram is the program number. * @param aProgram is the program number.
*/ */
void programInfo( GLuint aProgram ); void programInfo( GLuint aProgram );
/** /**
* @brief Get the shader information. * Get the shader information.
* *
* @param aShader is the shader number. * @param aShader is the shader number.
*/ */
@ -231,8 +223,12 @@ private:
bool isShaderLinked; ///< Is the shader linked? bool isShaderLinked; ///< Is the shader linked?
bool active; ///< Is any of shaders used? bool active; ///< Is any of shaders used?
GLuint maximumVertices; ///< The maximum of vertices to be generated GLuint maximumVertices; ///< The maximum of vertices to be generated
GLuint geomInputType; ///< Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
GLuint geomOutputType; ///< Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.] ///< Input type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
GLuint geomInputType;
///< Output type [e.g. GL_LINES, GL_TRIANGLES, GL_QUADS etc.]
GLuint geomOutputType;
std::deque<GLint> parameterLocation; ///< Location of the parameter std::deque<GLint> parameterLocation; ///< Location of the parameter
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright 2013-2017 CERN * Copyright 2013-2017 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,7 +26,7 @@
/** /**
* @file vertex_container.h * @file vertex_container.h
* @brief Class to store vertices and handle transfers between system memory and GPU memory. * Class to store vertices and handle transfers between system memory and GPU memory.
*/ */
#ifndef VERTEX_CONTAINER_H_ #ifndef VERTEX_CONTAINER_H_
@ -41,30 +43,31 @@ class VERTEX_CONTAINER
{ {
public: public:
/** /**
* Returns a pointer to a new container of an appropriate type. * Return a pointer to a new container of an appropriate type.
*/ */
static VERTEX_CONTAINER* MakeContainer( bool aCached ); static VERTEX_CONTAINER* MakeContainer( bool aCached );
virtual ~VERTEX_CONTAINER(); virtual ~VERTEX_CONTAINER();
/** /**
* Returns true if the container caches vertex data in RAM or video memory. * Return true if the container caches vertex data in RAM or video memory.
* Otherwise it is a single batch draw which is later discarded. * Otherwise it is a single batch draw which is later discarded.
*/ */
virtual bool IsCached() const = 0; virtual bool IsCached() const = 0;
/** /**
* Prepares the container for vertices updates. * Prepare the container for vertices updates.
*/ */
virtual void Map() {} virtual void Map() {}
/** /**
* Finishes the vertices updates stage. * Finish the vertices updates stage.
*/ */
virtual void Unmap() {} virtual void Unmap() {}
/** /**
* Sets the item for the further actions. * Set the item for the further actions.
*
* @param aItem is the item or NULL in case of finishing the item. * @param aItem is the item or NULL in case of finishing the item.
*/ */
virtual void SetItem( VERTEX_ITEM* aItem ) = 0; virtual void SetItem( VERTEX_ITEM* aItem ) = 0;
@ -75,27 +78,31 @@ public:
virtual void FinishItem() {}; virtual void FinishItem() {};
/** /**
* Returns allocated space for the requested number of vertices associated with the * Return allocated space for the requested number of vertices associated with the
* current item (set with SetItem()). The allocated space is added at the end of the chunk * current item (set with SetItem()).
* used by the current item and may serve to store new vertices. *
* The allocated space is added at the end of the chunk used by the current item and
* may serve to store new vertices.
*
* @param aSize is the number of vertices to be allocated. * @param aSize is the number of vertices to be allocated.
* @return Pointer to the allocated space or NULL in case of failure. * @return Pointer to the allocated space or NULL in case of failure.
*/ */
virtual VERTEX* Allocate( unsigned int aSize ) = 0; virtual VERTEX* Allocate( unsigned int aSize ) = 0;
/** /**
* Erases the data related to an item. * Erase the data related to an item.
*
* @param aItem is the item to be erased. * @param aItem is the item to be erased.
*/ */
virtual void Delete( VERTEX_ITEM* aItem ) = 0; virtual void Delete( VERTEX_ITEM* aItem ) = 0;
/** /**
* Removes all data stored in the container and restores its original state. * Remove all data stored in the container and restores its original state.
*/ */
virtual void Clear() = 0; virtual void Clear() = 0;
/** /**
* Returns pointer to the vertices stored in the container. * Return pointer to the vertices stored in the container.
*/ */
VERTEX* GetAllVertices() const VERTEX* GetAllVertices() const
{ {
@ -103,8 +110,8 @@ public:
} }
/** /**
* Function GetVertices() * Return vertices stored at the specific offset.
* returns vertices stored at the specific offset. *
* @param aOffset is the offset. * @param aOffset is the offset.
*/ */
virtual VERTEX* GetVertices( unsigned int aOffset ) const virtual VERTEX* GetVertices( unsigned int aOffset ) const
@ -113,8 +120,7 @@ public:
} }
/** /**
* Function GetSize() * Return amount of vertices currently stored in the container.
* returns amount of vertices currently stored in the container.
*/ */
virtual unsigned int GetSize() const virtual unsigned int GetSize() const
{ {
@ -122,7 +128,8 @@ public:
} }
/** /**
* Returns information about the container cache state. * Return information about the container cache state.
*
* @return True in case the vertices have to be reuploaded. * @return True in case the vertices have to be reuploaded.
*/ */
bool IsDirty() const bool IsDirty() const
@ -131,7 +138,7 @@ public:
} }
/** /**
* Sets the dirty flag, so vertices in the container are going to be reuploaded to the GPU on * Set the dirty flag, so vertices in the container are going to be reuploaded to the GPU on
* the next frame. * the next frame.
*/ */
void SetDirty() void SetDirty()
@ -140,7 +147,7 @@ public:
} }
/** /**
* Clears the dirty flag to prevent reuploading vertices to the GPU memory. * Clear the dirty flag to prevent reuploading vertices to the GPU memory.
*/ */
void ClearDirty() void ClearDirty()
{ {
@ -150,6 +157,16 @@ public:
protected: protected:
VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE ); VERTEX_CONTAINER( unsigned int aSize = DEFAULT_SIZE );
/**
* Return size of the used memory space.
*
* @return Size of the used memory space (expressed as a number of vertices).
*/
unsigned int usedSpace() const
{
return m_currentSize - m_freeSpace;
}
///> Free space left in the container, expressed in vertices ///> Free space left in the container, expressed in vertices
unsigned int m_freeSpace; unsigned int m_freeSpace;
@ -166,16 +183,6 @@ protected:
bool m_failed; bool m_failed;
bool m_dirty; bool m_dirty;
/**
* Function usedSpace()
* returns size of the used memory space.
* @return Size of the used memory space (expressed as a number of vertices).
*/
unsigned int usedSpace() const
{
return m_currentSize - m_freeSpace;
}
///< Default initial size of a container (expressed in vertices) ///< Default initial size of a container (expressed in vertices)
static constexpr unsigned int DEFAULT_SIZE = 1048576; static constexpr unsigned int DEFAULT_SIZE = 1048576;
}; };

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,7 +26,7 @@
/** /**
* @file vertex_item.h * @file vertex_item.h
* @brief Class to handle an item held in a container. * Class to handle an item held in a container.
*/ */
#ifndef VERTEX_ITEM_H_ #ifndef VERTEX_ITEM_H_
@ -49,8 +51,8 @@ public:
virtual ~VERTEX_ITEM(); virtual ~VERTEX_ITEM();
/** /**
* Function GetSize() * Return information about number of vertices stored.
* Returns information about number of vertices stored. *
* @return Number of vertices. * @return Number of vertices.
*/ */
inline unsigned int GetSize() const inline unsigned int GetSize() const
@ -59,8 +61,8 @@ public:
} }
/** /**
* Function GetOffset() * Return data offset in the container.
* Returns data offset in the container. *
* @return Data offset expressed as a number of vertices. * @return Data offset expressed as a number of vertices.
*/ */
inline unsigned int GetOffset() const inline unsigned int GetOffset() const
@ -69,19 +71,14 @@ public:
} }
/** /**
* Function GetVertices() * Return pointer to the data used by the VERTEX_ITEM.
* Returns pointer to the data used by the VERTEX_ITEM.
*/ */
VERTEX* GetVertices() const; VERTEX* GetVertices() const;
private: private:
const VERTEX_MANAGER& m_manager;
unsigned int m_offset;
unsigned int m_size;
/** /**
* Function SetOffset() * Set data offset in the container.
* Sets data offset in the container. *
* @param aOffset is the offset expressed as a number of vertices. * @param aOffset is the offset expressed as a number of vertices.
*/ */
inline void setOffset( unsigned int aOffset ) inline void setOffset( unsigned int aOffset )
@ -90,14 +87,18 @@ private:
} }
/** /**
* Function SetSize() * Set data size in the container.
* Sets data size in the container. *
* @param aSize is the size expressed as a number of vertices. * @param aSize is the size expressed as a number of vertices.
*/ */
inline void setSize( unsigned int aSize ) inline void setSize( unsigned int aSize )
{ {
m_size = aSize; m_size = aSize;
} }
const VERTEX_MANAGER& m_manager;
unsigned int m_offset;
unsigned int m_size;
}; };
} // namespace KIGFX } // namespace KIGFX

View File

@ -2,6 +2,8 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2016 CERN * Copyright (C) 2013-2016 CERN
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors.
*
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -24,8 +26,6 @@
/** /**
* @file vertex_manager.h * @file vertex_manager.h
* @brief Class to control vertex container and GPU with possibility of emulating old-style OpenGL
* 1.0 state machine using modern OpenGL methods.
*/ */
#ifndef VERTEX_MANAGER_H_ #ifndef VERTEX_MANAGER_H_
@ -47,32 +47,31 @@ class VERTEX_ITEM;
class VERTEX_CONTAINER; class VERTEX_CONTAINER;
class GPU_MANAGER; class GPU_MANAGER;
/**
* Class to control vertex container and GPU with possibility of emulating old-style OpenGL
* 1.0 state machine using modern OpenGL methods.
*/
class VERTEX_MANAGER class VERTEX_MANAGER
{ {
public: public:
/** /**
* @brief Constructor.
*
* @param aCached says if vertices should be cached in GPU or system memory. For data that * @param aCached says if vertices should be cached in GPU or system memory. For data that
* does not change every frame, it is better to store vertices in GPU memory. * does not change every frame, it is better to store vertices in GPU memory.
*/ */
VERTEX_MANAGER( bool aCached ); VERTEX_MANAGER( bool aCached );
/** /**
* Function Map() * Map vertex buffer.
* maps vertex buffer.
*/ */
void Map(); void Map();
/** /**
* Function Unmap() * Unmap vertex buffer.
* unmaps vertex buffer.
*/ */
void Unmap(); void Unmap();
/** /**
* Function Reserve() * Allocate space for vertices, so it will be used with subsequent Vertex() calls.
* allocates space for vertices, so it will be used with subsequent Vertex() calls.
* *
* @param aSize is the number of vertices that should be available in the reserved space. * @param aSize is the number of vertices that should be available in the reserved space.
* @return True if successful, false otherwise. * @return True if successful, false otherwise.
@ -80,11 +79,11 @@ public:
bool Reserve( unsigned int aSize ); bool Reserve( unsigned int aSize );
/** /**
* Function Vertex() * Add a vertex with the given coordinates to the currently set item.
* adds a vertex with the given coordinates to the currently set item. Color & shader *
* parameters stored in aVertex are ignored, instead color & shader set by Color() and * Color & shader parameters stored in aVertex are ignored, instead color & shader set
* Shader() functions are used. Vertex coordinates will have the current transformation * by Color() and Shader() functions are used. Vertex coordinates will have the current
* matrix applied. * transformation matrix applied.
* *
* @param aVertex contains vertex coordinates. * @param aVertex contains vertex coordinates.
* @return True if successful, false otherwise. * @return True if successful, false otherwise.
@ -95,9 +94,9 @@ public:
} }
/** /**
* Function Vertex() * Add a vertex with the given coordinates to the currently set item.
* adds a vertex with the given coordinates to the currently set item. Vertex coordinates will *
* have the current transformation matrix applied. * Vertex coordinates will have the current transformation matrix applied.
* *
* @param aX is the X coordinate of the new vertex. * @param aX is the X coordinate of the new vertex.
* @param aY is the Y coordinate of the new vertex. * @param aY is the Y coordinate of the new vertex.
@ -107,9 +106,9 @@ public:
bool Vertex( GLfloat aX, GLfloat aY, GLfloat aZ ); bool Vertex( GLfloat aX, GLfloat aY, GLfloat aZ );
/** /**
* Function Vertex() * Add a vertex with the given coordinates to the currently set item.
* adds a vertex with the given coordinates to the currently set item. Vertex coordinates will *
* have the current transformation matrix applied. * Vertex coordinates will have the current transformation matrix applied.
* *
* @param aXY are the XY coordinates of the new vertex. * @param aXY are the XY coordinates of the new vertex.
* @param aZ is the Z coordinate of the new vertex. * @param aZ is the Z coordinate of the new vertex.
@ -121,22 +120,21 @@ public:
} }
/** /**
* Function Vertices() * Add one or more vertices to the currently set item.
* adds one or more vertices to the currently set item. It takes advantage of allocating memory
* in advance, so should be faster than adding vertices one by one. Color & shader
* parameters stored in aVertices are ignored, instead color & shader set by Color() and
* Shader() functions are used. All the vertex coordinates will have the current
* transformation matrix applied.
* *
* @param aVertices contains vertices to be added * It takes advantage of allocating memory in advance, so should be faster than
* adding vertices one by one. Color & shader parameters stored in aVertices are
* ignored, instead color & shader set by Color() and Shader() functions are used.
* All the vertex coordinates will have the current transformation matrix applied.
*
* @param aVertices contains vertices to be added.
* @param aSize is the number of vertices to be added. * @param aSize is the number of vertices to be added.
* @return True if successful, false otherwise. * @return True if successful, false otherwise.
*/ */
bool Vertices( const VERTEX aVertices[], unsigned int aSize ); bool Vertices( const VERTEX aVertices[], unsigned int aSize );
/** /**
* Function Color() * Changes currently used color that will be applied to newly added vertices.
* changes currently used color that will be applied to newly added vertices.
* *
* @param aColor is the new color. * @param aColor is the new color.
*/ */
@ -149,9 +147,10 @@ public:
} }
/** /**
* Function Color() * Change currently used color that will be applied to newly added vertices.
* changes currently used color that will be applied to newly added vertices. It is the *
* equivalent of glColor4f() function. * It is the equivalent of glColor4f() function.
*
* @param aRed is the red component of the new color. * @param aRed is the red component of the new color.
* @param aGreen is the green component of the new color. * @param aGreen is the green component of the new color.
* @param aBlue is the blue component of the new color. * @param aBlue is the blue component of the new color.
@ -166,10 +165,11 @@ public:
} }
/** /**
* Function Shader() * Change currently used shader and its parameters that will be applied to newly added
* changes currently used shader and its parameters that will be applied to newly added * vertices.
* vertices. Parameters depend on shader, for more information have a look at shaders source *
* code. * Parameters depend on shader, for more information have a look at shaders source code.
*
* @see SHADER_TYPE * @see SHADER_TYPE
* *
* @param aShaderType is the a shader type to be applied. * @param aShaderType is the a shader type to be applied.
@ -177,8 +177,8 @@ public:
* @param aParam2 is the optional parameter for a shader. * @param aParam2 is the optional parameter for a shader.
* @param aParam3 is the optional parameter for a shader. * @param aParam3 is the optional parameter for a shader.
*/ */
inline void Shader( GLfloat aShaderType, GLfloat aParam1 = 0.0f, inline void Shader( GLfloat aShaderType, GLfloat aParam1 = 0.0f, GLfloat aParam2 = 0.0f,
GLfloat aParam2 = 0.0f, GLfloat aParam3 = 0.0f ) GLfloat aParam3 = 0.0f )
{ {
m_shader[0] = aShaderType; m_shader[0] = aShaderType;
m_shader[1] = aParam1; m_shader[1] = aParam1;
@ -187,9 +187,10 @@ public:
} }
/** /**
* Function Translate() * Multiply the current matrix by a translation matrix, so newly vertices will be
* multiplies the current matrix by a translation matrix, so newly vertices will be * translated by the given vector.
* translated by the given vector. It is the equivalent of the glTranslatef() function. *
* It is the equivalent of the glTranslatef() function.
* *
* @param aX is the X coordinate of a translation vector. * @param aX is the X coordinate of a translation vector.
* @param aY is the X coordinate of a translation vector. * @param aY is the X coordinate of a translation vector.
@ -201,9 +202,10 @@ public:
} }
/** /**
* Function Rotate() * Multiply the current matrix by a rotation matrix, so the newly vertices will be
* multiplies the current matrix by a rotation matrix, so the newly vertices will be * rotated by the given angles.
* rotated by the given angles. It is the equivalent of the glRotatef() function. *
* It is the equivalent of the glRotatef() function.
* *
* @param aAngle is the angle of rotation, in radians. * @param aAngle is the angle of rotation, in radians.
* @param aX is a multiplier for the X axis * @param aX is a multiplier for the X axis
@ -216,9 +218,10 @@ public:
} }
/** /**
* Function Scale() * Multiply the current matrix by a scaling matrix, so the newly vertices will be
* multiplies the current matrix by a scaling matrix, so the newly vertices will be * scaled by the given factors.
* scaled by the given factors. It is the equivalent of the glScalef() function. *
* It is the equivalent of the glScalef() function.
* *
* @param aX is the X axis scaling factor. * @param aX is the X axis scaling factor.
* @param aY is the Y axis scaling factor. * @param aY is the Y axis scaling factor.
@ -230,9 +233,9 @@ public:
} }
/** /**
* Function PushMatrix() * Push the current transformation matrix stack.
* pushes the current transformation matrix stack. It is the equivalent of the glPushMatrix() *
* function. * It is the equivalent of the glPushMatrix() function.
*/ */
inline void PushMatrix() inline void PushMatrix()
{ {
@ -243,9 +246,9 @@ public:
} }
/** /**
* Function PopMatrix() * Pop the current transformation matrix stack.
* pops the current transformation matrix stack. It is the equivalent of the glPopMatrix() *
* function. * It is the equivalent of the glPopMatrix() function.
*/ */
void PopMatrix() void PopMatrix()
{ {
@ -262,31 +265,28 @@ public:
} }
/** /**
* Function SetItem() * Set an item to start its modifications.
* sets an item to start its modifications. After calling the function it is possible to add *
* vertices using function Add(). * After calling the function it is possible to add vertices using function Add().
* *
* @param aItem is the item that is going to store vertices in the container. * @param aItem is the item that is going to store vertices in the container.
*/ */
void SetItem( VERTEX_ITEM& aItem ) const; void SetItem( VERTEX_ITEM& aItem ) const;
/** /**
* Function FinishItem() * Clean after adding an item.
* does the cleaning after adding an item.
*/ */
void FinishItem() const; void FinishItem() const;
/** /**
* Function FreeItem() * Free the memory occupied by the item, so it is no longer stored in the container.
* frees the memory occupied by the item, so it is no longer stored in the container.
* *
* @param aItem is the item to be freed * @param aItem is the item to be freed
*/ */
void FreeItem( VERTEX_ITEM& aItem ) const; void FreeItem( VERTEX_ITEM& aItem ) const;
/** /**
* Function ChangeItemColor() * Change the color of all vertices owned by an item.
* changes the color of all vertices owned by an item.
* *
* @param aItem is the item to change. * @param aItem is the item to change.
* @param aColor is the new color to be applied. * @param aColor is the new color to be applied.
@ -294,8 +294,7 @@ public:
void ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& aColor ) const; void ChangeItemColor( const VERTEX_ITEM& aItem, const COLOR4D& aColor ) const;
/** /**
* Function ChangeItemDepth() * Change the depth of all vertices owned by an item.
* changes the depth of all vertices owned by an item.
* *
* @param aItem is the item to change. * @param aItem is the item to change.
* @param aDepth is the new color to be applied. * @param aDepth is the new color to be applied.
@ -303,8 +302,7 @@ public:
void ChangeItemDepth( const VERTEX_ITEM& aItem, GLfloat aDepth ) const; void ChangeItemDepth( const VERTEX_ITEM& aItem, GLfloat aDepth ) const;
/** /**
* Function GetVertices() * Return a pointer to the vertices owned by an item.
* returns a pointer to the vertices owned by an item.
* *
* @param aItem is the owner of vertices that are going to be returned. * @param aItem is the owner of vertices that are going to be returned.
* @return Pointer to the vertices or NULL if the item is not stored at the container. * @return Pointer to the vertices or NULL if the item is not stored at the container.
@ -317,48 +315,42 @@ public:
} }
/** /**
* Function SetShader() * Set a shader program that is going to be used during rendering.
* sets a shader program that is going to be used during rendering. *
* @param aShader is the object containing compiled and linked shader program. * @param aShader is the object containing compiled and linked shader program.
*/ */
void SetShader( SHADER& aShader ) const; void SetShader( SHADER& aShader ) const;
/** /**
* Function Clear() * Remove all the stored vertices from the container.
* removes all the stored vertices from the container.
*/ */
void Clear() const; void Clear() const;
/** /**
* Function BeginDrawing() * Prepare buffers and items to start drawing.
* prepares buffers and items to start drawing.
*/ */
void BeginDrawing() const; void BeginDrawing() const;
/** /**
* Function DrawItem() * Draw an item to the buffer.
* draws an item to the buffer.
* *
* @param aItem is the item to be drawn. * @param aItem is the item to be drawn.
*/ */
void DrawItem( const VERTEX_ITEM& aItem ) const; void DrawItem( const VERTEX_ITEM& aItem ) const;
/** /**
* Function EndDrawing() * Finish drawing operations.
* finishes drawing operations.
*/ */
void EndDrawing() const; void EndDrawing() const;
/** /**
* Function EnableDepthTest() * Enable/disable Z buffer depth test.
* Enables/disables Z buffer depth test.
*/ */
void EnableDepthTest( bool aEnabled ); void EnableDepthTest( bool aEnabled );
protected: protected:
/** /**
* Function putVertex() * Apply all transformation to the given coordinates and store them at the specified target.
* applies all transformation to the given coordinates and store them at the specified target.
* *
* @param aTarget is the place where the new vertex is going to be stored (it has to be * @param aTarget is the place where the new vertex is going to be stored (it has to be
* allocated first). * allocated first).

View File

@ -4,7 +4,7 @@
* Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de * Copyright (C) 2012 Torsten Hueter, torstenhtr <at> gmx.de
* Copyright (C) 2013 CERN * Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch> * @author Maciej Suminski <maciej.suminski@cern.ch>
* Copyright (C) 2016 Kicad Developers, see change_log.txt for contributors. * Copyright (C) 2016-2020 Kicad Developers, see AUTHORS.txt for contributors.
* *
* Stroke font class * Stroke font class
* *
@ -46,7 +46,7 @@ typedef std::vector<std::vector<VECTOR2D>*> GLYPH;
typedef std::vector<GLYPH*> GLYPH_LIST; typedef std::vector<GLYPH*> GLYPH_LIST;
/** /**
* @brief Class STROKE_FONT implements stroke font drawing. * Class STROKE_FONT implements stroke font drawing.
* *
* A stroke font is composed of lines. * A stroke font is composed of lines.
*/ */
@ -59,7 +59,7 @@ public:
STROKE_FONT( GAL* aGal ); STROKE_FONT( GAL* aGal );
/** /**
* @brief Load the new stroke font. * Load the new stroke font.
* *
* @param aNewStrokeFont is the pointer to the font data. * @param aNewStrokeFont is the pointer to the font data.
* @param aNewStrokeFontSize is the size of the font data. * @param aNewStrokeFontSize is the size of the font data.
@ -68,7 +68,7 @@ public:
bool LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNewStrokeFontSize ); bool LoadNewStrokeFont( const char* const aNewStrokeFont[], int aNewStrokeFontSize );
/** /**
* @brief Draw a string. * Draw a string.
* *
* @param aText is the text to be drawn. * @param aText is the text to be drawn.
* @param aPosition is the text position in world coordinates. * @param aPosition is the text position in world coordinates.
@ -77,8 +77,8 @@ public:
void Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle ); void Draw( const UTF8& aText, const VECTOR2D& aPosition, double aRotationAngle );
/** /**
* Function SetGAL
* Changes Graphics Abstraction Layer used for drawing items for a new one. * Changes Graphics Abstraction Layer used for drawing items for a new one.
*
* @param aGal is the new GAL instance. * @param aGal is the new GAL instance.
*/ */
void SetGAL( GAL* aGal ) void SetGAL( GAL* aGal )
@ -88,7 +88,9 @@ public:
/** /**
* Compute the boundary limits of aText (the bounding box of all shapes). * Compute the boundary limits of aText (the bounding box of all shapes).
*
* The overbar and alignment are not taken in account, '~' characters are skipped. * The overbar and alignment are not taken in account, '~' characters are skipped.
*
* @return a VECTOR2D giving the width and height of text. * @return a VECTOR2D giving the width and height of text.
*/ */
VECTOR2D ComputeStringBoundaryLimits( const UTF8& aText, const VECTOR2D& aGlyphSize, VECTOR2D ComputeStringBoundaryLimits( const UTF8& aText, const VECTOR2D& aGlyphSize,
@ -96,29 +98,25 @@ public:
/** /**
* Compute the vertical position of an overbar, sometimes used in texts. * Compute the vertical position of an overbar, sometimes used in texts.
*
* This is the distance between the text base line and the overbar. * This is the distance between the text base line and the overbar.
*
* @param aGlyphHeight is the height (vertical size) of the text. * @param aGlyphHeight is the height (vertical size) of the text.
* @return the relative position of the overbar axis. * @return the relative position of the overbar axis.
*/ */
double ComputeOverbarVerticalPosition( double aGlyphHeight ) const; double ComputeOverbarVerticalPosition( double aGlyphHeight ) const;
/** /**
* @brief Compute the distance (interline) between 2 lines of text (for multiline texts). * Compute the distance (interline) between 2 lines of text (for multiline texts).
* *
* @param aGlyphHeight is the height (vertical size) of the text. * @param aGlyphHeight is the height (vertical size) of the text.
* @return the interline. * @return the interline.
*/ */
static double GetInterline( double aGlyphHeight ); static double GetInterline( double aGlyphHeight );
private: private:
GAL* m_gal; ///< Pointer to the GAL
const GLYPH_LIST* m_glyphs; ///< Glyph list
const std::vector<BOX2D>* m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
/** /**
* @brief Compute the X and Y size of a given text. The text is expected to be * Compute the X and Y size of a given text. The text is expected to be
* a only one line text. * a only one line text.
* *
* @param aText is the text string (one line). * @param aText is the text string (one line).
@ -135,7 +133,7 @@ private:
double computeUnderlineVerticalPosition() const; double computeUnderlineVerticalPosition() const;
/** /**
* @brief Compute the bounding box of a given glyph. * Compute the bounding box of a given glyph.
* *
* @param aGlyph is the glyph. * @param aGlyph is the glyph.
* @param aGlyphWidth is the x-component of the bounding box size. * @param aGlyphWidth is the x-component of the bounding box size.
@ -144,7 +142,7 @@ private:
BOX2D computeBoundingBox( const GLYPH* aGlyph, double aGlyphWidth ) const; BOX2D computeBoundingBox( const GLYPH* aGlyph, double aGlyphWidth ) const;
/** /**
* @brief Draws a single line of text. Multiline texts should be split before using the * Draws a single line of text. Multiline texts should be split before using the
* function. * function.
* *
* @param aText is the text to be drawn. * @param aText is the text to be drawn.
@ -152,7 +150,7 @@ private:
void drawSingleLineText( const UTF8& aText ); void drawSingleLineText( const UTF8& aText );
/** /**
* @brief Returns number of lines for a given text. * Returns number of lines for a given text.
* *
* @param aText is the text to be checked. * @param aText is the text to be checked.
* @return unsigned - The number of lines in aText. * @return unsigned - The number of lines in aText.
@ -166,6 +164,10 @@ private:
return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1; return std::count( aText.begin(), aText.end() - 1, '\n' ) + 1;
} }
GAL* m_gal; ///< Pointer to the GAL
const GLYPH_LIST* m_glyphs; ///< Glyph list
const std::vector<BOX2D>* m_glyphBoundingBoxes; ///< Bounding boxes of the glyphs
///> Factor that determines relative vertical position of the overbar. ///> Factor that determines relative vertical position of the overbar.
static const double OVERBAR_POSITION_FACTOR; static const double OVERBAR_POSITION_FACTOR;
static const double UNDERLINE_POSITION_FACTOR; static const double UNDERLINE_POSITION_FACTOR;

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -46,8 +46,8 @@ class VIEW;
/** /**
* A coordinate is relative to a page corner. * A coordinate is relative to a page corner.
* Any of the 4 corners can be a reference. *
* The default is the right bottom corner * Any of the 4 corners can be a reference. The default is the right bottom corner.
*/ */
enum CORNER_ANCHOR enum CORNER_ANCHOR
{ {
@ -65,15 +65,14 @@ enum PAGE_OPTION
}; };
/** /**
* A coordinate point * A coordinate point.
* The position is always relative to the corner anchor *
* Note the coordinate is from the anchor point to the opposite corner. * The position is always relative to the corner anchor.
*
* @note The coordinate is from the anchor point to the opposite corner.
*/ */
class POINT_COORD class POINT_COORD
{ {
public:
DPOINT m_Pos;
int m_Anchor;
public: public:
POINT_COORD() { m_Anchor = RB_CORNER; } POINT_COORD() { m_Anchor = RB_CORNER; }
@ -82,11 +81,15 @@ public:
m_Pos = aPos; m_Pos = aPos;
m_Anchor = aAnchor; m_Anchor = aAnchor;
} }
DPOINT m_Pos;
int m_Anchor;
}; };
/** /**
* Work sheet structure type definitions. * Work sheet structure type definitions.
*
* Basic items are: * Basic items are:
* * segment and rect (defined by 2 points) * * segment and rect (defined by 2 points)
* * text (defined by a coordinate), the text and its justifications * * text (defined by a coordinate), the text and its justifications
@ -105,25 +108,6 @@ public:
WS_BITMAP WS_BITMAP
}; };
protected:
WS_ITEM_TYPE m_type;
PAGE_OPTION m_pageOption;
std::vector<WS_DRAW_ITEM_BASE*> m_drawItems;
public:
wxString m_Name; // a item name used in page layout
// editor to identify items
wxString m_Info; // a comment, only useful in page
// layout editor
POINT_COORD m_Pos;
POINT_COORD m_End;
double m_LineWidth;
int m_RepeatCount; // repeat count for duplicate items
DPOINT m_IncrementVector; // For duplicate items: move vector
// for position increment
int m_IncrementLabel;
public: public:
WS_DATA_ITEM( WS_ITEM_TYPE aType ); WS_DATA_ITEM( WS_ITEM_TYPE aType );
@ -147,12 +131,10 @@ public:
m_End.m_Anchor = aAnchor; m_End.m_Anchor = aAnchor;
} }
// Accessors:
WS_ITEM_TYPE GetType() const { return m_type; } WS_ITEM_TYPE GetType() const { return m_type; }
/** /**
* @return true if the item has a end point (segment; rect) * @return true if the item has a end point (segment; rect) of false (text, polygon).
* of false (text, polugon)
*/ */
PAGE_OPTION GetPage1Option() const { return m_pageOption; } PAGE_OPTION GetPage1Option() const { return m_pageOption; }
void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; } void SetPage1Option( PAGE_OPTION aChoice ) { m_pageOption = aChoice; }
@ -166,67 +148,81 @@ public:
virtual int GetPenSizeUi(); virtual int GetPenSizeUi();
/** /**
* move item to a new position * Move item to a new position.
* @param aPosition = the new position of item, in mm *
* @param aPosition the new position of item, in mm.
*/ */
void MoveTo( DPOINT aPosition ); void MoveTo( DPOINT aPosition );
/** /**
* move item to a new position * Move item to a new position.
* @param aPosition = the new position of the starting point in graphic units *
* @param aPosition the new position of the starting point in graphic units.
*/ */
void MoveToUi( wxPoint aPosition ); void MoveToUi( wxPoint aPosition );
/** /**
* move the starting point of the item to a new position * Move the starting point of the item to a new position.
* @param aPosition = the new position of the starting point, in mm *
* @param aPosition the new position of the starting point, in mm.
*/ */
void MoveStartPointTo( DPOINT aPosition ); void MoveStartPointTo( DPOINT aPosition );
/** /**
* move the starting point of the item to a new position * Move the starting point of the item to a new position.
* @param aPosition = the new position of item in graphic units *
* @param aPosition is the new position of item in graphic units.
*/ */
void MoveStartPointToUi( wxPoint aPosition ); void MoveStartPointToUi( wxPoint aPosition );
/** /**
* move the ending point of the item to a new position * Move the ending point of the item to a new position.
* has meaning only for items defined by 2 points *
* (segments and rectangles) * This has meaning only for items defined by 2 points (segments and rectangles).
* @param aPosition = the new position of the ending point, in mm *
* @param aPosition is the new position of the ending point, in mm.
*/ */
void MoveEndPointTo( DPOINT aPosition ); void MoveEndPointTo( DPOINT aPosition );
/** /**
* move the ending point of the item to a new position * Move the ending point of the item to a new position.
* has meaning only for items defined by 2 points *
* (segments and rectangles) * This has meaning only for items defined by 2 points (segments and rectangles).
* @param aPosition = the new position of the ending point in graphic units *
* @param aPosition is the new position of the ending point in graphic units
*/ */
void MoveEndPointToUi( wxPoint aPosition ); void MoveEndPointToUi( wxPoint aPosition );
/** /**
* @return true if the item is inside the rectangle defined by the * @return true if the item is inside the rectangle defined by the 4 corners, false otherwise.
* 4 corners, false otherwise.
*/ */
virtual bool IsInsidePage( int ii ) const; virtual bool IsInsidePage( int ii ) const;
const wxString GetClassName() const; const wxString GetClassName() const;
protected:
WS_ITEM_TYPE m_type;
PAGE_OPTION m_pageOption;
std::vector<WS_DRAW_ITEM_BASE*> m_drawItems;
public:
wxString m_Name; // a item name used in page layout
// editor to identify items
wxString m_Info; // a comment, only useful in page layout editor
POINT_COORD m_Pos;
POINT_COORD m_End;
double m_LineWidth;
int m_RepeatCount; // repeat count for duplicate items
DPOINT m_IncrementVector; // For duplicate items: move vector
// for position increment
int m_IncrementLabel;
}; };
class WS_DATA_ITEM_POLYGONS : public WS_DATA_ITEM class WS_DATA_ITEM_POLYGONS : public WS_DATA_ITEM
{ {
public:
double m_Orient; // Orientation in degrees
std::vector<DPOINT> m_Corners; // corner list
private:
std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
DPOINT m_minCoord; // min coord of corners, relative to m_Pos
DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
public: public:
WS_DATA_ITEM_POLYGONS( ); WS_DATA_ITEM_POLYGONS( );
@ -235,8 +231,9 @@ public:
virtual int GetPenSizeUi() override; virtual int GetPenSizeUi() override;
/** /**
* add a corner in corner list * Add a corner in corner list.
* @param aCorner: the item to append *
* @param aCorner is the item to append.
*/ */
void AppendCorner( const DPOINT& aCorner ) void AppendCorner( const DPOINT& aCorner )
{ {
@ -244,8 +241,8 @@ public:
} }
/** /**
* Closes the current contour, by storing the index of the last corner * Closes the current contour, by storing the index of the last corner of the current
* of the current polygon in m_polyIndexEnd. * polygon in m_polyIndexEnd.
*/ */
void CloseContour() void CloseContour()
{ {
@ -253,13 +250,13 @@ public:
} }
/** /**
* @return the count of contours in the poly polygon * @return the count of contours in the poly polygon.
*/ */
int GetPolyCount() const { return (int) m_polyIndexEnd.size(); } int GetPolyCount() const { return (int) m_polyIndexEnd.size(); }
/** /**
* @return the index of the first corner of the contour aCountour * @param aContour is the index of the contour.
* @param aContour = the index of the contour * @return the index of the first corner of the contour \a aCountour.
*/ */
unsigned GetPolyIndexStart( unsigned aContour) const unsigned GetPolyIndexStart( unsigned aContour) const
{ {
@ -270,8 +267,8 @@ public:
} }
/** /**
* @return the index of the last corner of the contour aCountour * @param aContour is the index of the contour.
* @param aContour = the index of the contour * @return the index of the last corner of the contour \a aCountour.
*/ */
unsigned GetPolyIndexEnd( unsigned aContour) const unsigned GetPolyIndexEnd( unsigned aContour) const
{ {
@ -279,46 +276,35 @@ public:
} }
/** /**
* @return the coordinate (in mm) of the corner aIdx, * @return the coordinate (in mm) of the corner \a aIdx and the repeated item \a aRepeat
* for the repeated item aRepeat
*/ */
const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const; const DPOINT GetCornerPosition( unsigned aIdx, int aRepeat = 0 ) const;
/** /**
* @return the coordinate (in draw/plot units) of the corner aIdx, * @return the coordinate (in draw/plot units) of the corner \a aIdx and the repeated
* for the repeated item aRepeat * item \a aRepeat
*/ */
const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const; const wxPoint GetCornerPositionUi( unsigned aIdx, int aRepeat = 0 ) const;
/** /**
* calculate the bounding box of the set polygons * Calculate the bounding box of the set polygons.
*/ */
void SetBoundingBox(); void SetBoundingBox();
bool IsInsidePage( int ii ) const override; bool IsInsidePage( int ii ) const override;
double m_Orient; // Orientation in degrees
std::vector<DPOINT> m_Corners; // corner list
private:
std::vector<unsigned> m_polyIndexEnd; // index of the last point of each polygon
DPOINT m_minCoord; // min coord of corners, relative to m_Pos
DPOINT m_maxCoord; // max coord of corners, relative to m_Pos
}; };
class WS_DATA_ITEM_TEXT : public WS_DATA_ITEM class WS_DATA_ITEM_TEXT : public WS_DATA_ITEM
{ {
public:
wxString m_TextBase; // The basic text, with format symbols
wxString m_FullText; // The expanded text, shown on screen
double m_Orient; // Orientation in degrees
EDA_TEXT_HJUSTIFY_T m_Hjustify;
EDA_TEXT_VJUSTIFY_T m_Vjustify;
bool m_Italic;
bool m_Bold;
DSIZE m_TextSize;
DSIZE m_BoundingBoxSize; // When not null, this is the max
// size of the full text.
// the text size will be modified
// to keep the full text insite this
// bound.
DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
// the m_BoundingBoxSize constraint
public: public:
WS_DATA_ITEM_TEXT( const wxString& aTextBase ); WS_DATA_ITEM_TEXT( const wxString& aTextBase );
@ -330,7 +316,7 @@ public:
* Try to build text wihich is an increment of m_TextBase * Try to build text wihich is an increment of m_TextBase
* has meaning only if m_TextBase is a basic text (one char) * has meaning only if m_TextBase is a basic text (one char)
* If the basic char is a digit, build a number * If the basic char is a digit, build a number
* If the basic char is a letter, use the letter with ascii code * If the basic char is a letter, use the letter with ASCII code
* aIncr + (basic char ascc code) * aIncr + (basic char ascc code)
* @param aIncr = the increment value * @param aIncr = the increment value
* return the incremented label in m_FullText * return the incremented label in m_FullText
@ -338,7 +324,7 @@ public:
void IncrementLabel( int aIncr ); void IncrementLabel( int aIncr );
/** /**
* Calculates m_ConstrainedTextSize from m_TextSize * Calculate m_ConstrainedTextSize from m_TextSize
* to keep the X size and the full Y size of the text * to keep the X size and the full Y size of the text
* smaller than m_BoundingBoxSize * smaller than m_BoundingBoxSize
* if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0 * if m_BoundingBoxSize.x or m_BoundingBoxSize.y > 0
@ -348,12 +334,27 @@ public:
void SetConstrainedTextSize(); void SetConstrainedTextSize();
/** Replace the '\''n' sequence by EOL /**
* and the sequence '\''\' by only one '\' * Replace the '\''n' sequence by EOL and the sequence '\''\' by only one '\'
* inside m_FullText * inside m_FullText
* @return true if the EOL symbol is found or is inserted (multiline text) * @return true if the EOL symbol is found or is inserted (multiline text).
*/ */
bool ReplaceAntiSlashSequence(); bool ReplaceAntiSlashSequence();
public:
wxString m_TextBase; // The basic text, with format symbols
wxString m_FullText; // The expanded text, shown on screen
double m_Orient; // Orientation in degrees
EDA_TEXT_HJUSTIFY_T m_Hjustify;
EDA_TEXT_VJUSTIFY_T m_Vjustify;
bool m_Italic;
bool m_Bold;
DSIZE m_TextSize;
DSIZE m_BoundingBoxSize; // When not null, this is the max size of the
// full text. The text size will be modified
// to keep the full text inside this bound.
DSIZE m_ConstrainedTextSize; // Actual text size, if constrained by
// the m_BoundingBoxSize constraint
}; };
@ -361,9 +362,6 @@ class BITMAP_BASE;
class WS_DATA_ITEM_BITMAP : public WS_DATA_ITEM class WS_DATA_ITEM_BITMAP : public WS_DATA_ITEM
{ {
public:
BITMAP_BASE* m_ImageBitmap;
public: public:
WS_DATA_ITEM_BITMAP( BITMAP_BASE* aImage ) : WS_DATA_ITEM_BITMAP( BITMAP_BASE* aImage ) :
WS_DATA_ITEM( WS_BITMAP ) WS_DATA_ITEM( WS_BITMAP )
@ -375,6 +373,9 @@ public:
int GetPPI() const; int GetPPI() const;
void SetPPI( int aBitmapPPI ); void SetPPI( int aBitmapPPI );
public:
BITMAP_BASE* m_ImageBitmap;
}; };

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr * Copyright (C) 2013-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
* Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -33,33 +33,10 @@ class WS_DATA_ITEM;
class PAGE_INFO; class PAGE_INFO;
/** /**
* WS_DATA_MODEL handles the graphic items list to draw/plot the frame and title block * Handle the graphic items list to draw/plot the frame and title block.
*/ */
class WS_DATA_MODEL class WS_DATA_MODEL
{ {
std::vector <WS_DATA_ITEM*> m_list;
bool m_allowVoidList; // If false, the default page layout will be loaded the
// first time WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
// is run (useful mainly for page layout editor)
double m_leftMargin; // the left page margin in mm
double m_rightMargin; // the right page margin in mm
double m_topMargin; // the top page margin in mm
double m_bottomMargin; // the bottom page margin in mm
public:
double m_WSunits2Iu; // conversion factor between
// ws units (mils) and draw/plot units
DPOINT m_RB_Corner; // cordinates of the right bottom corner (in mm)
DPOINT m_LT_Corner; // cordinates of the left top corner (in mm)
double m_DefaultLineWidth; // Used when object line width is 0
DSIZE m_DefaultTextSize; // Used when object text size is 0
double m_DefaultTextThickness; // Used when object text stroke width is 0
bool m_EditMode; // Used in page layout editor to toggle variable substution
// In normal mode (m_EditMode = false) the %format is
// replaced by the corresponding text.
// In edit mode (m_EditMode = true) the %format is
// displayed "as this"
public: public:
WS_DATA_MODEL(); WS_DATA_MODEL();
~WS_DATA_MODEL() ~WS_DATA_MODEL()
@ -73,13 +50,12 @@ public:
static WS_DATA_MODEL& GetTheInstance(); static WS_DATA_MODEL& GetTheInstance();
/** /**
* static function: Set an alternate instance of WS_DATA_MODEL * Set an alternate instance of WS_DATA_MODEL.
* mainly used in page setting dialog *
* @param aLayout = the alternate page layout; if null restore the basic page layout * @param aLayout the alternate page layout; if null restore the basic page layout
*/ */
static void SetAltInstance( WS_DATA_MODEL* aLayout = NULL ); static void SetAltInstance( WS_DATA_MODEL* aLayout = NULL );
// Accessors:
double GetLeftMargin() { return m_leftMargin; } double GetLeftMargin() { return m_leftMargin; }
void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; } void SetLeftMargin( double aMargin ) { m_leftMargin = aMargin; }
@ -95,7 +71,7 @@ public:
void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU ); void SetupDrawEnvironment( const PAGE_INFO& aPageInfo, double aMilsToIU );
/** /**
* In Kicad applications, a page layout description is needed * In KiCad applications, a page layout description is needed
* So if the list is empty, a default description is loaded, * So if the list is empty, a default description is loaded,
* the first time a page layout is drawn. * the first time a page layout is drawn.
* However, in page layout editor, an empty list is acceptable. * However, in page layout editor, an empty list is acceptable.
@ -105,29 +81,30 @@ public:
/** /**
* @return true if an empty list is allowed * @return true if an empty list is allowed
* (mainly allowed for page layout editor).
*/ */
bool VoidListAllowed() { return m_allowVoidList; } bool VoidListAllowed() { return m_allowVoidList; }
/** /**
* erase the list of items * Erase the list of items.
*/ */
void ClearList(); void ClearList();
/** /**
* Save the description in a file * Save the description in a file.
* @param aFullFileName the filename of the file to created *
* @param aFullFileName the filename of the file to created.
*/ */
void Save( const wxString& aFullFileName ); void Save( const wxString& aFullFileName );
/** /**
* Save the description in a buffer * Save the description in a buffer.
* @param aOutputString = a wxString to store the S expr string *
* @param aOutputString is a wxString to store the S expr string
*/ */
void SaveInString( wxString& aOutputString ); void SaveInString( wxString& aOutputString );
/** /**
* Fill the given string with an S-expr serialization of the WS_DATA_ITEMs * Fill the given string with an S-expr serialization of the WS_DATA_ITEMs.
*/ */
void SaveInString( std::vector<WS_DATA_ITEM*> aItemsList, wxString& aOutputString ); void SaveInString( std::vector<WS_DATA_ITEM*> aItemsList, wxString& aOutputString );
@ -135,12 +112,12 @@ public:
void Remove( WS_DATA_ITEM* aItem ); void Remove( WS_DATA_ITEM* aItem );
/** /**
* @return the index of aItem, or -1 if does not exist * @return the index of aItem, or -1 if does not exist.
*/ */
int GetItemIndex( WS_DATA_ITEM* aItem ) const; int GetItemIndex( WS_DATA_ITEM* aItem ) const;
/** /**
* @return the item from its index aIdx, or NULL if does not exist * @return is the item from it's index \a aIdx, or NULL if does not exist.
*/ */
WS_DATA_ITEM* GetItem( unsigned aIdx ) const; WS_DATA_ITEM* GetItem( unsigned aIdx ) const;
@ -150,7 +127,7 @@ public:
std::vector<WS_DATA_ITEM*>& GetItems() { return m_list; } std::vector<WS_DATA_ITEM*>& GetItems() { return m_list; }
/** /**
* @return the item count * @return the item count.
*/ */
unsigned GetCount() const { return m_list.size(); } unsigned GetCount() const { return m_list.size(); }
@ -158,50 +135,49 @@ public:
void SetEmptyLayout(); void SetEmptyLayout();
/** /**
* Returns a string containing the empty layout shape * Return a string containing the empty layout shape.
*/ */
static wxString EmptyLayout(); static wxString EmptyLayout();
/** /**
* Returns a string containing the empty layout shape * Return a string containing the empty layout shape.
*/ */
static wxString DefaultLayout(); static wxString DefaultLayout();
/** /**
* Populates the list with a custom layout, or * Populates the list with a custom layout or the default layout if no custom layout
* the default layout, if no custom layout available * is available.
* @param aFullFileName = the custom page layout description file. *
* if empty, loads the file defined by KICAD_WKSFILE * @param aFullFileName is the custom page layout description file. If empty, load the
* and if its is not defined, uses the default internal description * file defined by KICAD_WKSFILE and if its is not defined use the
* @param Append = if true: do not delete old layout, and load only * default internal description.
aFullFileName. * @param Append if true: do not delete old layout, and load only \a aFullFileName.
*/ */
void SetPageLayout( const wxString& aFullFileName = wxEmptyString, bool Append = false ); void SetPageLayout( const wxString& aFullFileName = wxEmptyString, bool Append = false );
/** /**
* Populates the list from a S expr description stored in a string * Populate the list from a S expr description stored in a string.
* @param aPageLayout = the S expr string *
* @param aAppend Do not delete old layout if true and append \a aPageLayout * @param aPageLayout is the S expr string.
* the existing one. * @param aAppend Do not delete old layout if true and append \a aPageLayout the existing
* one.
@param aSource is the layout source description. @param aSource is the layout source description.
*/ */
void SetPageLayout( const char* aPageLayout, bool aAppend = false, void SetPageLayout( const char* aPageLayout, bool aAppend = false,
const wxString& aSource = wxT( "Sexpr_string" ) ); const wxString& aSource = wxT( "Sexpr_string" ) );
/** /**
* @param aFullFileName is the full filename, which can be a relative.
* @param aProjectPath is the current project absolute path (can be empty).
* @return a short filename from a full filename: * @return a short filename from a full filename:
* if the path is the current project path, or if the path * if the path is the current project path, or if the path
* is the same as kicad.pro (in template), returns the shortname * is the same as kicad.pro (in template), returns the shortname
* else do nothing and returns a full filename * else do nothing and returns a full filename
* @param aFullFileName = the full filename, which can be a relative
* @param aProjectPath = the curr project absolute path (can be empty)
*/ */
static const wxString MakeShortFileName( const wxString& aFullFileName, static const wxString MakeShortFileName( const wxString& aFullFileName,
const wxString& aProjectPath ); const wxString& aProjectPath );
/** /**
* Static function
* @return a full filename from a short filename.
* @param aShortFileName = the short filename, which can be a relative * @param aShortFileName = the short filename, which can be a relative
* @param aProjectPath = the curr project absolute path (can be empty) * @param aProjectPath = the curr project absolute path (can be empty)
* or absolute path, and can include env variable reference ( ${envvar} expression ) * or absolute path, and can include env variable reference ( ${envvar} expression )
@ -209,9 +185,35 @@ public:
* or (if aProjectPath is empty or if the file does not exist) * or (if aProjectPath is empty or if the file does not exist)
* relative to kicad.pro (in template) * relative to kicad.pro (in template)
* If aShortFileName is absolute return aShortFileName * If aShortFileName is absolute return aShortFileName
* @return a full filename from a short filename.
*/ */
static const wxString MakeFullFileName( const wxString& aShortFileName, static const wxString MakeFullFileName( const wxString& aShortFileName,
const wxString& aProjectPath ); const wxString& aProjectPath );
double m_WSunits2Iu; // conversion factor between
// ws units (mils) and draw/plot units
DPOINT m_RB_Corner; // coordinates of the right bottom corner (in mm)
DPOINT m_LT_Corner; // coordinates of the left top corner (in mm)
double m_DefaultLineWidth; // Used when object line width is 0
DSIZE m_DefaultTextSize; // Used when object text size is 0
double m_DefaultTextThickness; // Used when object text stroke width is 0
bool m_EditMode; // Used in page layout editor to toggle variable substation
// In normal mode (m_EditMode = false) the %format is
// replaced by the corresponding text.
// In edit mode (m_EditMode = true) the %format is
// displayed "as this"
private:
std::vector <WS_DATA_ITEM*> m_list;
bool m_allowVoidList; // If false, the default page layout will be loaded the
// first time WS_DRAW_ITEM_LIST::BuildWorkSheetGraphicList
// is run (useful mainly for page layout editor)
double m_leftMargin; // the left page margin in mm
double m_rightMargin; // the right page margin in mm
double m_topMargin; // the top page margin in mm
double m_bottomMargin; // the bottom page margin in mm
}; };
#endif // WS_DATA_MODEL_H #endif // WS_DATA_MODEL_H

View File

@ -44,31 +44,19 @@ class EDA_DRAW_FRAME;
class PROJECT; class PROJECT;
/** /**
* Helper classes to handle basic graphic items used to draw/plot * Base class to handle basic graphic items.
* title blocks and frame references *
* segments * Used to draw and/or plot:
* rect * - title blocks and frame references
* polygons (for logos) * - segments
* graphic texts * - rect
* bitmaps (also for logos, but they cannot be plot by SVG, GERBER or HPGL plotters * - polygons (for logos)
* - graphic texts
* - bitmaps (also for logos, but they cannot be plot by SVG, GERBER or HPGL plotters
* where we just plot the bounding box) * where we just plot the bounding box)
*/ */
class WS_DRAW_ITEM_BASE : public EDA_ITEM // This basic class, not directly usable. class WS_DRAW_ITEM_BASE : public EDA_ITEM
{ {
protected:
WS_DATA_ITEM* m_peer; // the parent WS_DATA_ITEM item in the WS_DATA_MODEL
int m_index; // the index in the parent's repeat count
int m_penWidth;
WS_DRAW_ITEM_BASE( WS_DATA_ITEM* aPeer, int aIndex, KICAD_T aType ) :
EDA_ITEM( aType )
{
m_peer = aPeer;
m_index = aIndex;
m_penWidth = 0;
m_flags = 0;
}
public: public:
virtual ~WS_DRAW_ITEM_BASE() {} virtual ~WS_DRAW_ITEM_BASE() {}
@ -110,15 +98,26 @@ public:
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override; bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) override; void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, MSG_PANEL_ITEMS& aList ) override;
protected:
WS_DRAW_ITEM_BASE( WS_DATA_ITEM* aPeer, int aIndex, KICAD_T aType ) :
EDA_ITEM( aType )
{
m_peer = aPeer;
m_index = aIndex;
m_penWidth = 0;
m_flags = 0;
}
WS_DATA_ITEM* m_peer; // the parent WS_DATA_ITEM item in the WS_DATA_MODEL
int m_index; // the index in the parent's repeat count
int m_penWidth;
}; };
// This class draws a thick segment // This class draws a thick segment
class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE
{ {
wxPoint m_start; // start point of line/rect
wxPoint m_end; // end point
public: public:
WS_DRAW_ITEM_LINE( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd, WS_DRAW_ITEM_LINE( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd,
int aPenWidth ) : int aPenWidth ) :
@ -131,7 +130,6 @@ public:
virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_LINE" ); } virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_LINE" ); }
// Accessors:
const wxPoint& GetStart() const { return m_start; } const wxPoint& GetStart() const { return m_start; }
void SetStart( wxPoint aPos ) { m_start = aPos; } void SetStart( wxPoint aPos ) { m_start = aPos; }
const wxPoint& GetEnd() const { return m_end; } const wxPoint& GetEnd() const { return m_end; }
@ -150,22 +148,15 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
private:
wxPoint m_start; // start point of line/rect
wxPoint m_end; // end point
}; };
// This class draws a polygon
class WS_DRAW_ITEM_POLYPOLYGONS : public WS_DRAW_ITEM_BASE class WS_DRAW_ITEM_POLYPOLYGONS : public WS_DRAW_ITEM_BASE
{ {
wxPoint m_pos; // position of reference point, from the
// WS_DATA_ITEM_POLYGONS parent
// (used only in page layout editor to draw anchors)
public:
/** The list of polygons. Because these polygons are only for drawing purposes,
* each polygon is expected having no holes, just a main outline
*/
SHAPE_POLY_SET m_Polygons;
public: public:
WS_DRAW_ITEM_POLYPOLYGONS( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos, int aPenWidth ) : WS_DRAW_ITEM_POLYPOLYGONS( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos, int aPenWidth ) :
WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_POLY_T ) WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_POLY_T )
@ -176,7 +167,6 @@ public:
virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_POLYPOLYGONS" ); } virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_POLYPOLYGONS" ); }
// Accessors:
SHAPE_POLY_SET& GetPolygons() { return m_Polygons; } SHAPE_POLY_SET& GetPolygons() { return m_Polygons; }
wxPoint GetPosition() const override { return m_pos; } wxPoint GetPosition() const override { return m_pos; }
void SetPosition( const wxPoint& aPos ) override; void SetPosition( const wxPoint& aPos ) override;
@ -192,15 +182,28 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
public:
/**
* The list of polygons.
*
* Because these polygons are only for drawing purposes, each polygon is expected to
* have no holes just a main outline.
*/
SHAPE_POLY_SET m_Polygons;
private:
wxPoint m_pos; // position of reference point, from the WS_DATA_ITEM_POLYGONS parent
// (used only in page layout editor to draw anchors)
}; };
// This class draws a not filled rectangle with thick segment /**
* Non filled rectangle with thick segment.
*/
class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_BASE class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_BASE
{ {
wxPoint m_start; // start point of line/rect
wxPoint m_end; // end point
public: public:
WS_DRAW_ITEM_RECT( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd, WS_DRAW_ITEM_RECT( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aStart, wxPoint aEnd,
int aPenWidth ) : int aPenWidth ) :
@ -213,7 +216,6 @@ public:
virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_RECT" ); } virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_RECT" ); }
// Accessors:
const wxPoint& GetStart() const { return m_start; } const wxPoint& GetStart() const { return m_start; }
void SetStart( wxPoint aPos ) { m_start = aPos; } void SetStart( wxPoint aPos ) { m_start = aPos; }
const wxPoint& GetEnd() const { return m_end; } const wxPoint& GetEnd() const { return m_end; }
@ -233,18 +235,22 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
private:
wxPoint m_start; // start point of line/rect
wxPoint m_end; // end point
}; };
// This class draws a rectangle with thick segment showing the page limits /**
// and a marker showing the coord origin. This only a draw item only. * A rectangle with thick segment showing the page limits and a marker showing the coordinate
// Therefore m_peer ( the parent WS_DATA_ITEM item in the WS_DATA_MODEL) is always a nullptr. * origin.
*
* This only a draw item only. Therefore m_peer ( the parent WS_DATA_ITEM item in the
* WS_DATA_MODEL) is always a nullptr.
*/
class WS_DRAW_ITEM_PAGE : public WS_DRAW_ITEM_BASE class WS_DRAW_ITEM_PAGE : public WS_DRAW_ITEM_BASE
{ {
wxPoint m_markerPos; // position of the marker
wxSize m_pageSize; // full size of the page
double m_markerSize;
public: public:
WS_DRAW_ITEM_PAGE( int aPenWidth, double aMarkerSize ) : WS_DRAW_ITEM_PAGE( int aPenWidth, double aMarkerSize ) :
WS_DRAW_ITEM_BASE( nullptr, 0, WSG_PAGE_T ) WS_DRAW_ITEM_BASE( nullptr, 0, WSG_PAGE_T )
@ -255,7 +261,6 @@ public:
virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_PAGE" ); } virtual wxString GetClass() const override { return wxT( "WS_DRAW_ITEM_PAGE" ); }
// Accessors:
void SetPageSize( wxSize aSize ) { m_pageSize = aSize; } void SetPageSize( wxSize aSize ) { m_pageSize = aSize; }
wxSize GetPageSize() const { return m_pageSize; } wxSize GetPageSize() const { return m_pageSize; }
const wxPoint& GetMarkerPos() const { return m_markerPos; } const wxPoint& GetMarkerPos() const { return m_markerPos; }
@ -275,12 +280,20 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
private:
wxPoint m_markerPos; // position of the marker
wxSize m_pageSize; // full size of the page
double m_markerSize;
}; };
// This class draws a graphic text. /**
// it is derived from an EDA_TEXT, so it handle all characteristics * A graphic text.
// of this graphic text (justification, rotation ... ) *
* It is derived from an #EDA_TEXT, so it handle all characteristics of this graphic text
* (justification, rotation ... ).
*/
class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT
{ {
public: public:
@ -318,11 +331,11 @@ public:
}; };
// This class draws a bitmap. /**
* A bitmap.
*/
class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE
{ {
wxPoint m_pos; // position of reference point
public: public:
WS_DRAW_ITEM_BITMAP( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos ) : WS_DRAW_ITEM_BITMAP( WS_DATA_ITEM* aPeer, int aIndex, wxPoint aPos ) :
WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_BITMAP_T ) WS_DRAW_ITEM_BASE( aPeer, aIndex, WSG_BITMAP_T )
@ -348,6 +361,9 @@ public:
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif #endif
private:
wxPoint m_pos; // position of reference point
}; };
@ -359,24 +375,6 @@ public:
*/ */
class WS_DRAW_ITEM_LIST class WS_DRAW_ITEM_LIST
{ {
protected:
std::vector <WS_DRAW_ITEM_BASE*> m_graphicList; // Items to draw/plot
unsigned m_idx; // for GetFirst, GetNext functions
double m_milsToIu; // the scalar to convert pages units ( mils)
// to draw/plot units.
int m_penSize; // The default line width for drawings.
// used when an item has a pen size = 0
bool m_isFirstPage; ///< Is this the first page or not.
int m_sheetCount; ///< The number of sheets
// for basic inscriptions, in schematic
const TITLE_BLOCK* m_titleBlock; // for basic inscriptions
const wxString* m_paperFormat; // for basic inscriptions
wxString m_fileName; // for basic inscriptions
wxString m_sheetFullName; // for basic inscriptions
wxString m_pageNumber; ///< The actual page number displayed in the title block.
const wxString* m_sheetLayer; // for basic inscriptions
const PROJECT* m_project; // for project-based variable substitutions
public: public:
WS_DRAW_ITEM_LIST() WS_DRAW_ITEM_LIST()
{ {
@ -561,6 +559,24 @@ public:
* @return the text, after replacing the format symbols by the actual value * @return the text, after replacing the format symbols by the actual value
*/ */
wxString BuildFullText( const wxString& aTextbase ); wxString BuildFullText( const wxString& aTextbase );
protected:
std::vector <WS_DRAW_ITEM_BASE*> m_graphicList; // Items to draw/plot
unsigned m_idx; // for GetFirst, GetNext functions
double m_milsToIu; // the scalar to convert pages units ( mils)
// to draw/plot units.
int m_penSize; // The default line width for drawings.
// used when an item has a pen size = 0
bool m_isFirstPage; ///< Is this the first page or not.
int m_sheetCount; ///< The number of sheets
// for basic inscriptions, in schematic
const TITLE_BLOCK* m_titleBlock; // for basic inscriptions
const wxString* m_paperFormat; // for basic inscriptions
wxString m_fileName; // for basic inscriptions
wxString m_sheetFullName; // for basic inscriptions
wxString m_pageNumber; ///< The actual page number displayed in the title block.
const wxString* m_sheetLayer; // for basic inscriptions
const PROJECT* m_project; // for project-based variable substitutions
}; };

View File

@ -74,7 +74,6 @@
"invalid_outline": "error", "invalid_outline": "error",
"item_on_disabled_layer": "error", "item_on_disabled_layer": "error",
"items_not_allowed": "error", "items_not_allowed": "error",
"keepout": "error",
"length_out_of_range": "error", "length_out_of_range": "error",
"malformed_courtyard": "error", "malformed_courtyard": "error",
"microvia_drill_too_small": "error", "microvia_drill_too_small": "error",
@ -95,7 +94,6 @@
"unconnected_items": "error", "unconnected_items": "error",
"unresolved_variable": "error", "unresolved_variable": "error",
"via_dangling": "warning", "via_dangling": "warning",
"via_hole_larger_than_pad": "error",
"zone_has_empty_net": "error", "zone_has_empty_net": "error",
"zones_intersect": "error" "zones_intersect": "error"
}, },
@ -105,6 +103,7 @@
"max_error": 0.005, "max_error": 0.005,
"min_clearance": 0.0, "min_clearance": 0.0,
"min_copper_edge_clearance": 0.01, "min_copper_edge_clearance": 0.01,
"min_hole_clearance": 0.0,
"min_hole_to_hole": 0.25, "min_hole_to_hole": 0.25,
"min_microvia_diameter": 0.508, "min_microvia_diameter": 0.508,
"min_microvia_drill": 0.2032, "min_microvia_drill": 0.2032,