2016-03-25 08:26:11 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
2017-04-18 15:14:10 +00:00
|
|
|
* Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-03-25 08:26:11 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BASIC_GAL_H
|
|
|
|
#define BASIC_GAL_H
|
|
|
|
|
2018-01-29 10:37:29 +00:00
|
|
|
#include <eda_rect.h>
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
#include <gal/stroke_font.h>
|
|
|
|
#include <gal/graphics_abstraction_layer.h>
|
|
|
|
#include <newstroke_font.h>
|
|
|
|
|
2017-04-18 15:14:10 +00:00
|
|
|
class PLOTTER;
|
|
|
|
|
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
/*
|
2020-01-10 14:31:00 +00:00
|
|
|
* BASIC_GAL is a minimal GAL implementation to draw, plot and convert
|
2016-03-25 08:26:11 +00:00
|
|
|
* stroke texts to a set of segments for DRC tests, and to calculate text sizes.
|
|
|
|
*
|
2018-07-08 12:12:38 +00:00
|
|
|
* Currently it allows one to use GAL and STROKE_FONT methods in legacy draw mode
|
2016-03-25 08:26:11 +00:00
|
|
|
* (using wxDC functions) in plot functions only for texts.
|
|
|
|
* It is used also to calculate the text bounding boxes
|
|
|
|
*
|
2019-06-01 11:11:05 +00:00
|
|
|
* The main purpose is to avoid duplicate code to do the same thing in GAL canvas,
|
|
|
|
* print & plotter canvasses and DRC.
|
2016-03-25 08:26:11 +00:00
|
|
|
*
|
|
|
|
* It will be certainly removed when a full GAL canvas using wxDC is implemented
|
|
|
|
* (or at least restricted to plotter and DRC "canvas")
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct TRANSFORM_PRM // A helper class to transform coordinates in BASIC_GAL canvas
|
|
|
|
{
|
|
|
|
VECTOR2D m_rotCenter;
|
|
|
|
VECTOR2D m_moveOffset;
|
|
|
|
double m_rotAngle;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BASIC_GAL: public KIGFX::GAL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxDC* m_DC;
|
2017-02-20 16:57:41 +00:00
|
|
|
COLOR4D m_Color;
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
TRANSFORM_PRM m_transform;
|
|
|
|
std::stack <TRANSFORM_PRM> m_transformHistory;
|
|
|
|
|
|
|
|
public:
|
2017-02-13 11:43:28 +00:00
|
|
|
BASIC_GAL( KIGFX::GAL_DISPLAY_OPTIONS& aDisplayOptions ) :
|
|
|
|
GAL( aDisplayOptions )
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
|
|
|
m_DC = NULL;
|
|
|
|
m_Color = RED;
|
|
|
|
m_plotter = NULL;
|
|
|
|
m_callback = NULL;
|
2018-04-06 13:30:52 +00:00
|
|
|
m_callbackData = nullptr;
|
2016-04-07 11:09:31 +00:00
|
|
|
m_isClipped = false;
|
2016-03-25 08:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetPlotter( PLOTTER* aPlotter )
|
|
|
|
{
|
|
|
|
m_plotter = aPlotter;
|
|
|
|
}
|
|
|
|
|
2018-04-06 13:30:52 +00:00
|
|
|
void SetCallback( void (* aCallback)( int x0, int y0, int xf, int yf, void* aData ), void* aData )
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
|
|
|
m_callback = aCallback;
|
2018-04-06 13:30:52 +00:00
|
|
|
m_callbackData = aData;
|
2016-03-25 08:26:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Set a clip box for drawings
|
|
|
|
/// If NULL, no clip will be made
|
|
|
|
void SetClipBox( EDA_RECT* aClipBox )
|
|
|
|
{
|
|
|
|
m_isClipped = aClipBox != NULL;
|
|
|
|
|
|
|
|
if( aClipBox )
|
|
|
|
m_clipBox = *aClipBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Save the context.
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Save() override
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
|
|
|
m_transformHistory.push( m_transform );
|
|
|
|
}
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Restore() override
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
|
|
|
m_transform = m_transformHistory.top();
|
|
|
|
m_transformHistory.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Draw a polyline
|
|
|
|
* @param aPointList is a list of 2D-Vectors containing the polyline points.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawPolyline( const std::deque<VECTOR2D>& aPointList ) override;
|
2016-03-25 08:26:11 +00:00
|
|
|
|
2020-11-20 10:21:59 +00:00
|
|
|
virtual void DrawPolyline( const VECTOR2D aPointList[], int aListSize ) override;
|
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
/** Start and end points are defined as 2D-Vectors.
|
|
|
|
* @param aStartPoint is the start point of the line.
|
|
|
|
* @param aEndPoint is the end point of the line.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void DrawLine( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) override;
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Translate the context.
|
|
|
|
*
|
|
|
|
* @param aTranslation is the translation vector.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Translate( const VECTOR2D& aTranslation ) override
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
|
|
|
m_transform.m_moveOffset += aTranslation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Rotate the context.
|
|
|
|
*
|
|
|
|
* @param aAngle is the rotation angle in radians.
|
|
|
|
*/
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual void Rotate( double aAngle ) override
|
2016-03-25 08:26:11 +00:00
|
|
|
{
|
2016-04-29 09:37:33 +00:00
|
|
|
m_transform.m_rotAngle = aAngle;
|
2016-03-25 08:26:11 +00:00
|
|
|
m_transform.m_rotCenter = m_transform.m_moveOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-11-20 10:21:59 +00:00
|
|
|
void doDrawPolyline( const std::vector<wxPoint>& aLocalPointList );
|
|
|
|
|
2016-03-25 08:26:11 +00:00
|
|
|
// Apply the roation/translation transform to aPoint
|
|
|
|
const VECTOR2D transform( const VECTOR2D& aPoint ) const;
|
|
|
|
|
|
|
|
// A clip box, to clip drawings in a wxDC (mandatory to avoid draw issues)
|
|
|
|
EDA_RECT m_clipBox; // The clip box
|
|
|
|
bool m_isClipped; // Allows/disallows clipping
|
|
|
|
|
|
|
|
// When calling the draw functions outside a wxDC, to get the basic drawings
|
|
|
|
// lines / polylines ..., a callback function (used in DRC) to store
|
|
|
|
// coordinates of each segment:
|
2018-04-06 13:30:52 +00:00
|
|
|
void (* m_callback)( int x0, int y0, int xf, int yf, void* aData );
|
|
|
|
void* m_callbackData; // a optional parameter for m_callback
|
2016-03-25 08:26:11 +00:00
|
|
|
|
|
|
|
// When calling the draw functions for plot, the plotter acts as a wxDC
|
|
|
|
// to plot basic items
|
|
|
|
PLOTTER* m_plotter;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
extern BASIC_GAL basic_gal;
|
|
|
|
|
|
|
|
#endif // define BASIC_GAL_H
|