2014-10-22 15:51:34 +00:00
|
|
|
/*
|
|
|
|
* 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) 1992-2014 KiCad Developers, see CHANGELOG.TXT for contributors.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
/**
|
|
|
|
* @file worksheet_shape_builder.h
|
|
|
|
* @brief classes and function to generate graphics to plt or draw titles blocks
|
|
|
|
* and frame references
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef WORKSHEET_SHAPE_BUILDER_H
|
|
|
|
#define WORKSHEET_SHAPE_BUILDER_H
|
|
|
|
|
2013-07-08 13:05:12 +00:00
|
|
|
#include <math/vector2d.h>
|
2013-06-05 12:03:16 +00:00
|
|
|
#include <eda_text.h>
|
2013-10-18 17:38:03 +00:00
|
|
|
#include <eda_text.h>
|
|
|
|
#include <class_bitmap_base.h>
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
class WORKSHEET_DATAITEM; // Forward declaration
|
|
|
|
class TITLE_BLOCK;
|
2014-12-23 13:01:59 +00:00
|
|
|
class PAGE_INFO;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
|
|
|
#define TB_DEFAULT_TEXTSIZE 1.5 // default worksheet text size in mm
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
/*
|
|
|
|
* Helper classes to handle basic graphic items used to raw/plot
|
|
|
|
* title blocks and frame references
|
|
|
|
* segments
|
|
|
|
* rect
|
|
|
|
* polygons (for logos)
|
|
|
|
* graphic texts
|
2013-10-18 17:38:03 +00:00
|
|
|
* bitmaps, also for logos, but they cannot be plot by SVG, GERBER
|
|
|
|
* and HPGL plotters (In this case, only the bounding box is plotted)
|
2013-05-22 08:45:25 +00:00
|
|
|
*/
|
|
|
|
class WS_DRAW_ITEM_BASE // This basic class, not directly usable.
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum WS_DRAW_TYPE {
|
2013-10-18 17:38:03 +00:00
|
|
|
wsg_line, wsg_rect, wsg_poly, wsg_text, wsg_bitmap
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
2013-07-19 18:27:22 +00:00
|
|
|
int m_Flags; // temporary flgs used in page layout editor
|
|
|
|
// to locate the item;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
protected:
|
|
|
|
WS_DRAW_TYPE m_type; // wsg_line, wsg_rect, wsg_poly, wsg_text
|
|
|
|
EDA_COLOR_T m_color;
|
2013-07-19 18:27:22 +00:00
|
|
|
WORKSHEET_DATAITEM* m_parent; // an unique identifier, used as link
|
|
|
|
// to the parent WORKSHEET_DATAITEM item,
|
|
|
|
// in page layout editor
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_BASE( WORKSHEET_DATAITEM* aParent,
|
|
|
|
WS_DRAW_TYPE aType, EDA_COLOR_T aColor )
|
2013-05-22 08:45:25 +00:00
|
|
|
{
|
|
|
|
m_type = aType;
|
|
|
|
m_color = aColor;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_parent = aParent;
|
|
|
|
m_Flags = 0;
|
2013-05-22 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~WS_DRAW_ITEM_BASE() {}
|
|
|
|
|
|
|
|
// Accessors:
|
2013-09-10 08:47:42 +00:00
|
|
|
EDA_COLOR_T GetColor() const { return m_color; }
|
|
|
|
WS_DRAW_TYPE GetType() const { return m_type; };
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2014-05-04 17:08:36 +00:00
|
|
|
WORKSHEET_DATAITEM* GetParent() const { return m_parent; }
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2013-07-25 18:58:46 +00:00
|
|
|
/** The function to draw a WS_DRAW_ITEM
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC)
|
|
|
|
{
|
|
|
|
wxPoint offset( 0, 0 );
|
|
|
|
DrawWsItem( aClipBox, aDC, offset, UNSPECIFIED_DRAWMODE, UNSPECIFIED_COLOR );
|
|
|
|
}
|
|
|
|
|
|
|
|
/// More advanced version of DrawWsItem. This is what must be
|
|
|
|
/// defined in the derived type.
|
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR ) = 0;
|
2013-07-25 18:58:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Abstract function: should exist for derived items
|
|
|
|
* return true if the point aPosition is on the item
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const = 0;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Abstract function: should exist for derived items
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const = 0;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Abstract function: should exist for derived items
|
|
|
|
* return true if the point aPosition is near the starting point of this item,
|
|
|
|
* for items defined by 2 points (segments, rect)
|
|
|
|
* or the position of the item, for items having only one point
|
|
|
|
* (texts or polygons)
|
|
|
|
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return true if the point aPosition is near the ending point of this item
|
|
|
|
* This is avirtual function which should be overriden for items defien by
|
|
|
|
* 2 points
|
|
|
|
* the maxi dist is WORKSHEET_DATAITEM::GetMarkerSizeUi()/2
|
|
|
|
*/
|
|
|
|
virtual bool HitTestEndPoint( const wxPoint& aPosition)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class draws a thick segment
|
|
|
|
class WS_DRAW_ITEM_LINE : public WS_DRAW_ITEM_BASE
|
|
|
|
{
|
|
|
|
wxPoint m_start; // start point of line/rect
|
|
|
|
wxPoint m_end; // end point
|
|
|
|
int m_penWidth;
|
2013-05-24 08:59:40 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
public:
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_LINE( WORKSHEET_DATAITEM* aParent,
|
|
|
|
wxPoint aStart, wxPoint aEnd,
|
2013-05-22 08:45:25 +00:00
|
|
|
int aPenWidth, EDA_COLOR_T aColor ) :
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_BASE( aParent, wsg_line, aColor )
|
2013-05-22 08:45:25 +00:00
|
|
|
{
|
|
|
|
m_start = aStart;
|
|
|
|
m_end = aEnd;
|
|
|
|
m_penWidth = aPenWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors:
|
2013-09-10 12:31:52 +00:00
|
|
|
int GetPenWidth() const { return m_penWidth; }
|
|
|
|
const wxPoint& GetStart() const { return m_start; }
|
|
|
|
const wxPoint& GetEnd() const { return m_end; }
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2013-07-25 18:58:46 +00:00
|
|
|
/** The function to draw a WS_DRAW_ITEM_LINE
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
|
2013-07-25 18:58:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the point aPosition is on the line
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the starting point of this item.
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the ending point of this item
|
|
|
|
* This is avirtual function which should be overriden for items defien by
|
|
|
|
* 2 points
|
|
|
|
*/
|
|
|
|
virtual bool HitTestEndPoint( const wxPoint& aPosition);
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class draws a polygon
|
|
|
|
class WS_DRAW_ITEM_POLYGON : public WS_DRAW_ITEM_BASE
|
|
|
|
{
|
2013-07-19 18:27:22 +00:00
|
|
|
wxPoint m_pos; // position of reference point, from the
|
|
|
|
// WORKSHEET_DATAITEM_POLYPOLYGON parent
|
|
|
|
// (used only in page layout editor to draw anchors)
|
2013-05-22 08:45:25 +00:00
|
|
|
int m_penWidth;
|
2013-05-23 16:38:17 +00:00
|
|
|
bool m_fill;
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
public:
|
|
|
|
std::vector <wxPoint> m_Corners;
|
2013-06-08 18:19:09 +00:00
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
public:
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_POLYGON( WORKSHEET_DATAITEM* aParent, wxPoint aPos,
|
|
|
|
bool aFill, int aPenWidth, EDA_COLOR_T aColor ) :
|
|
|
|
WS_DRAW_ITEM_BASE( aParent, wsg_poly, aColor )
|
2013-05-22 08:45:25 +00:00
|
|
|
{
|
|
|
|
m_penWidth = aPenWidth;
|
2013-05-23 16:38:17 +00:00
|
|
|
m_fill = aFill;
|
2013-07-19 18:27:22 +00:00
|
|
|
m_pos = aPos;
|
2013-05-22 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Accessors:
|
2013-09-10 12:31:52 +00:00
|
|
|
int GetPenWidth() const { return m_penWidth; }
|
|
|
|
bool IsFilled() const { return m_fill; }
|
|
|
|
const wxPoint& GetPosition() const { return m_pos; }
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2013-07-25 18:58:46 +00:00
|
|
|
/** The function to draw a WS_DRAW_ITEM_POLYGON
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
|
2013-07-25 18:58:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the point aPosition is inside one polygon
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the starting point of this item.
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition);
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class draws a not filled rectangle with thick segment
|
|
|
|
class WS_DRAW_ITEM_RECT : public WS_DRAW_ITEM_LINE
|
|
|
|
{
|
|
|
|
public:
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_RECT( WORKSHEET_DATAITEM* aParent,
|
|
|
|
wxPoint aStart, wxPoint aEnd,
|
2013-05-22 08:45:25 +00:00
|
|
|
int aPenWidth, EDA_COLOR_T aColor ) :
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_LINE( aParent, aStart, aEnd, aPenWidth, aColor )
|
2013-05-22 08:45:25 +00:00
|
|
|
{
|
|
|
|
m_type = wsg_rect;
|
|
|
|
}
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2013-07-25 18:58:46 +00:00
|
|
|
/** The function to draw a WS_DRAW_ITEM_RECT
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
|
2013-07-25 18:58:46 +00:00
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the point aPosition is on one edge of the rectangle
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the starting point of this item.
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the ending point of this item
|
|
|
|
* This is avirtual function which should be overriden for items defien by
|
|
|
|
* 2 points
|
|
|
|
*/
|
|
|
|
virtual bool HitTestEndPoint( const wxPoint& aPosition);
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// This class draws a graphic text.
|
|
|
|
// it is derived from an EDA_TEXT, so it handle all caracteristics
|
|
|
|
// of this graphic text (justification, rotation ... )
|
|
|
|
class WS_DRAW_ITEM_TEXT : public WS_DRAW_ITEM_BASE, public EDA_TEXT
|
|
|
|
{
|
|
|
|
public:
|
2013-07-19 18:27:22 +00:00
|
|
|
WS_DRAW_ITEM_TEXT( WORKSHEET_DATAITEM* aParent,
|
|
|
|
wxString& aText, wxPoint aPos, wxSize aSize,
|
2013-05-22 08:45:25 +00:00
|
|
|
int aPenWidth, EDA_COLOR_T aColor,
|
2013-07-25 18:58:46 +00:00
|
|
|
bool aItalic = false, bool aBold = false );
|
|
|
|
|
|
|
|
/** The function to draw a WS_DRAW_ITEM_TEXT
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
|
2013-05-22 08:45:25 +00:00
|
|
|
|
|
|
|
// Accessors:
|
|
|
|
int GetPenWidth() { return GetThickness(); }
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the point aPosition is on the text
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const;
|
2013-07-19 18:27:22 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const;
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the starting point of this item.
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition);
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
// This class draws a bitmap.
|
|
|
|
class WS_DRAW_ITEM_BITMAP : public WS_DRAW_ITEM_BASE
|
|
|
|
{
|
|
|
|
wxPoint m_pos; // position of reference point
|
|
|
|
|
|
|
|
public:
|
|
|
|
WS_DRAW_ITEM_BITMAP( WORKSHEET_DATAITEM* aParent, wxPoint aPos )
|
|
|
|
:WS_DRAW_ITEM_BASE( aParent, wsg_bitmap, UNSPECIFIED_COLOR )
|
|
|
|
{
|
|
|
|
m_pos = aPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
WS_DRAW_ITEM_BITMAP()
|
|
|
|
:WS_DRAW_ITEM_BASE( NULL, wsg_bitmap, UNSPECIFIED_COLOR )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~WS_DRAW_ITEM_BITMAP() {}
|
|
|
|
|
|
|
|
/** The function to draw a WS_DRAW_ITEM_BITMAP
|
|
|
|
*/
|
2016-06-11 13:51:05 +00:00
|
|
|
virtual void DrawWsItem( EDA_RECT* aClipBox, wxDC* aDC, const wxPoint& aOffset,
|
|
|
|
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
|
2013-10-18 17:38:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the point aPosition is on bitmap
|
|
|
|
*/
|
2014-05-04 17:08:36 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition) const;
|
2013-10-18 17:38:03 +00:00
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
/**
|
|
|
|
* Virtual function
|
|
|
|
* return true if the rect aRect intersects on the item
|
|
|
|
*/
|
|
|
|
virtual bool HitTest( const EDA_RECT& aRect ) const;
|
|
|
|
|
2013-10-18 17:38:03 +00:00
|
|
|
/**
|
|
|
|
* return true if the point aPosition is on the reference point of this item.
|
|
|
|
*/
|
|
|
|
virtual bool HitTestStartPoint( const wxPoint& aPosition);
|
|
|
|
|
|
|
|
const wxPoint& GetPosition() { return m_pos; }
|
|
|
|
};
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
/*
|
2013-05-24 08:59:40 +00:00
|
|
|
* this class stores the list of graphic items:
|
|
|
|
* rect, lines, polygons and texts to draw/plot
|
|
|
|
* the title block and frame references, and parameters to
|
|
|
|
* draw/plot them
|
2013-05-22 08:45:25 +00:00
|
|
|
*/
|
|
|
|
class WS_DRAW_ITEM_LIST
|
|
|
|
{
|
2013-07-22 16:45:22 +00:00
|
|
|
protected:
|
2013-05-22 08:45:25 +00:00
|
|
|
std::vector <WS_DRAW_ITEM_BASE*> m_graphicList; // Items to draw/plot
|
|
|
|
unsigned m_idx; // for GetFirst, GetNext functions
|
|
|
|
wxPoint m_LTmargin; // The left top margin in mils of the page layout.
|
|
|
|
wxPoint m_RBmargin; // The right bottom margin in mils of the page layout.
|
|
|
|
wxSize m_pageSize; // the page size in mils
|
|
|
|
double m_milsToIu; // the scalar to convert pages units ( mils)
|
|
|
|
// to draw/plot units.
|
2013-06-05 12:03:16 +00:00
|
|
|
int m_penSize; // The default line width for drawings.
|
|
|
|
// used when an item has a pen size = 0
|
2013-05-24 08:59:40 +00:00
|
|
|
int m_sheetNumber; // the value of the sheet number, for basic inscriptions
|
|
|
|
int m_sheetCount; // the value of the number of sheets, in schematic
|
|
|
|
// for basic inscriptions, in schematic
|
2013-05-25 09:01:44 +00:00
|
|
|
const TITLE_BLOCK* m_titleBlock; // for basic inscriptions
|
|
|
|
const wxString* m_paperFormat; // for basic inscriptions
|
2013-08-07 13:22:59 +00:00
|
|
|
wxString m_fileName; // for basic inscriptions
|
2013-05-25 09:01:44 +00:00
|
|
|
const wxString* m_sheetFullName; // for basic inscriptions
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
WS_DRAW_ITEM_LIST()
|
|
|
|
{
|
|
|
|
m_idx = 0;
|
2013-05-22 15:08:57 +00:00
|
|
|
m_milsToIu = 1.0;
|
|
|
|
m_penSize = 1;
|
2013-05-24 08:59:40 +00:00
|
|
|
m_sheetNumber = 1;
|
|
|
|
m_sheetCount = 1;
|
2013-05-25 09:01:44 +00:00
|
|
|
m_titleBlock = NULL;
|
|
|
|
m_paperFormat = NULL;
|
|
|
|
m_sheetFullName = NULL;
|
2013-05-22 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~WS_DRAW_ITEM_LIST()
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < m_graphicList.size(); ii++ )
|
|
|
|
delete m_graphicList[ii];
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* Set the filename to draw/plot
|
|
|
|
* @param aFileName = the text to display by the "filename" format
|
|
|
|
*/
|
|
|
|
void SetFileName( const wxString & aFileName )
|
|
|
|
{
|
2013-08-07 13:22:59 +00:00
|
|
|
m_fileName = aFileName;
|
2013-07-19 18:27:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the sheet name to draw/plot
|
|
|
|
* @param aSheetName = the text to draw/plot by the "sheetname" format
|
|
|
|
*/
|
|
|
|
void SetSheetName( const wxString & aSheetName )
|
|
|
|
{
|
|
|
|
m_sheetFullName = &aSheetName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Function SetPenSize
|
|
|
|
* Set the default pen size to draw/plot lines and texts
|
2013-05-22 08:45:25 +00:00
|
|
|
* @param aPenSize the thickness of lines
|
|
|
|
*/
|
|
|
|
void SetPenSize( int aPenSize )
|
|
|
|
{
|
|
|
|
m_penSize = aPenSize;
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/** Function SetMilsToIUfactor
|
2013-05-22 08:45:25 +00:00
|
|
|
* Set the scalar to convert pages units ( mils) to draw/plot units
|
|
|
|
* @param aScale the conversion factor
|
|
|
|
*/
|
|
|
|
void SetMilsToIUfactor( double aScale )
|
|
|
|
{
|
|
|
|
m_milsToIu = aScale;
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/** Function SetPageSize
|
2013-05-22 08:45:25 +00:00
|
|
|
* Set the size of the page layout
|
|
|
|
* @param aPageSize size (in mils) of the page layout.
|
|
|
|
*/
|
|
|
|
void SetPageSize( const wxSize& aPageSize )
|
|
|
|
{
|
|
|
|
m_pageSize = aPageSize;
|
|
|
|
}
|
|
|
|
|
2013-05-24 08:59:40 +00:00
|
|
|
/**
|
|
|
|
* Function SetSheetNumber
|
|
|
|
* Set the value of the sheet number, for basic inscriptions
|
|
|
|
* @param aSheetNumber the number to display.
|
|
|
|
*/
|
|
|
|
void SetSheetNumber( int aSheetNumber )
|
|
|
|
{
|
|
|
|
m_sheetNumber = aSheetNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetSheetCount
|
|
|
|
* Set the value of the count of sheets, for basic inscriptions
|
|
|
|
* @param aSheetCount the number of esheets to display.
|
|
|
|
*/
|
|
|
|
void SetSheetCount( int aSheetCount )
|
|
|
|
{
|
|
|
|
m_sheetCount = aSheetCount;
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/** Function SetMargins
|
2013-05-23 16:38:17 +00:00
|
|
|
* Set the left top margin and the right bottom margin
|
2013-05-22 08:45:25 +00:00
|
|
|
* of the page layout
|
|
|
|
* @param aLTmargin The left top margin of the page layout.
|
|
|
|
* @param aRBmargin The right bottom margin of the page layout.
|
|
|
|
*/
|
|
|
|
void SetMargins( const wxPoint& aLTmargin, const wxPoint& aRBmargin )
|
|
|
|
{
|
|
|
|
m_LTmargin = aLTmargin;
|
|
|
|
m_RBmargin = aRBmargin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Append( WS_DRAW_ITEM_BASE* aItem )
|
|
|
|
{
|
|
|
|
m_graphicList.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
|
|
|
WS_DRAW_ITEM_BASE* GetFirst()
|
|
|
|
{
|
|
|
|
m_idx = 0;
|
|
|
|
|
|
|
|
if( m_graphicList.size() )
|
|
|
|
return m_graphicList[0];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WS_DRAW_ITEM_BASE* GetNext()
|
|
|
|
{
|
|
|
|
m_idx++;
|
|
|
|
|
|
|
|
if( m_graphicList.size() > m_idx )
|
|
|
|
return m_graphicList[m_idx];
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-06-11 13:51:05 +00:00
|
|
|
void GetAllItems( std::vector<WS_DRAW_ITEM_BASE*>* aList )
|
|
|
|
{
|
|
|
|
*aList = m_graphicList;
|
|
|
|
}
|
|
|
|
|
2013-06-29 09:52:22 +00:00
|
|
|
/**
|
2013-07-19 18:27:22 +00:00
|
|
|
* Draws the item list created by BuildWorkSheetGraphicList
|
2013-06-29 09:52:22 +00:00
|
|
|
* @param aClipBox = the clipping rect, or NULL if no clipping
|
|
|
|
* @param aDC = the current Device Context
|
|
|
|
*/
|
|
|
|
void Draw( EDA_RECT* aClipBox, wxDC* aDC );
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
/**
|
|
|
|
* Function BuildWorkSheetGraphicList is a core function for
|
|
|
|
* drawing or plotting the page layout with
|
|
|
|
* the frame and the basic inscriptions.
|
2013-07-19 18:27:22 +00:00
|
|
|
* It populates the list of basic graphic items to draw or plot.
|
2013-05-22 08:45:25 +00:00
|
|
|
* currently lines, rect, polygons and texts
|
2013-07-19 18:27:22 +00:00
|
|
|
* before calling this function, some parameters should be initialized:
|
|
|
|
* by calling:
|
|
|
|
* SetPenSize( aPenWidth );
|
|
|
|
* SetMilsToIUfactor( aScalar );
|
|
|
|
* SetSheetNumber( aSheetNumber );
|
|
|
|
* SetSheetCount( aSheetCount );
|
|
|
|
* SetFileName( aFileName );
|
|
|
|
* SetSheetName( aFullSheetName );
|
2013-05-22 08:45:25 +00:00
|
|
|
*
|
2013-07-19 18:27:22 +00:00
|
|
|
* @param aPageInfo The PAGE_INFO, for page size, margins...
|
2013-05-22 08:45:25 +00:00
|
|
|
* @param aTitleBlock The sheet title block, for basic inscriptions.
|
2013-06-29 09:52:22 +00:00
|
|
|
* @param aColor The color for drawing.
|
|
|
|
* @param aAltColor The color for items which need to be "hightlighted".
|
2013-05-22 08:45:25 +00:00
|
|
|
*/
|
2013-07-19 18:27:22 +00:00
|
|
|
void BuildWorkSheetGraphicList( const PAGE_INFO& aPageInfo,
|
2013-05-22 08:45:25 +00:00
|
|
|
const TITLE_BLOCK& aTitleBlock,
|
2013-06-29 09:52:22 +00:00
|
|
|
EDA_COLOR_T aColor, EDA_COLOR_T aAltColor );
|
2013-05-25 09:01:44 +00:00
|
|
|
/**
|
|
|
|
* Function BuildFullText
|
|
|
|
* returns the full text corresponding to the aTextbase,
|
|
|
|
* after replacing format symbols by the corresponding value
|
|
|
|
*
|
|
|
|
* Basic texts in Ki_WorkSheetData struct use format notation
|
|
|
|
* like "Title %T" to identify at run time the full text
|
|
|
|
* to display.
|
|
|
|
* Currently format identifier is % followed by a letter or 2 letters
|
|
|
|
*
|
|
|
|
* %% = replaced by %
|
|
|
|
* %K = Kicad version
|
|
|
|
* %Z = paper format name (A4, USLetter)
|
|
|
|
* %Y = company name
|
|
|
|
* %D = date
|
|
|
|
* %R = revision
|
|
|
|
* %S = sheet number
|
|
|
|
* %N = number of sheets
|
|
|
|
* %Cx = comment (x = 0 to 9 to identify the comment)
|
|
|
|
* %F = filename
|
|
|
|
* %P = sheet path or sheet full name
|
|
|
|
* %T = title
|
|
|
|
* Other fields like Developer, Verifier, Approver could use %Cx
|
|
|
|
* and are seen as comments for format
|
|
|
|
*
|
|
|
|
* @param aTextbase = the text with format symbols
|
|
|
|
* @return the text, after replacing the format symbols by the actual value
|
|
|
|
*/
|
|
|
|
wxString BuildFullText( const wxString& aTextbase );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate graphic items in m_graphicList at location aPosition
|
|
|
|
* @param aList = the list of items found
|
|
|
|
* @param aPosition the position (in user units) to locate items
|
|
|
|
*/
|
|
|
|
void Locate(std::vector <WS_DRAW_ITEM_BASE*>& aList, const wxPoint& aPosition);
|
2013-05-22 08:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-05 12:03:16 +00:00
|
|
|
/**
|
2013-07-19 18:27:22 +00:00
|
|
|
* WORKSHEET_LAYOUT handles the graphic items list to draw/plot
|
2013-06-05 12:03:16 +00:00
|
|
|
* the title block and other items (page references ...
|
|
|
|
*/
|
|
|
|
class WORKSHEET_LAYOUT
|
|
|
|
{
|
|
|
|
std::vector <WORKSHEET_DATAITEM*> m_list;
|
2013-07-19 18:27:22 +00:00
|
|
|
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)
|
2013-07-20 19:36:19 +00:00
|
|
|
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
|
2013-06-05 12:03:16 +00:00
|
|
|
|
|
|
|
public:
|
2013-07-20 19:36:19 +00:00
|
|
|
WORKSHEET_LAYOUT();
|
2013-06-05 12:03:16 +00:00
|
|
|
~WORKSHEET_LAYOUT() {ClearList(); }
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* static function: returns the instance of WORKSHEET_LAYOUT
|
|
|
|
* used in the application
|
|
|
|
*/
|
2014-12-31 12:31:19 +00:00
|
|
|
static WORKSHEET_LAYOUT& GetTheInstance();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* static function: Set an alternate instance of WORKSHEET_LAYOUT
|
|
|
|
* mainly used in page setting dialog
|
|
|
|
* @param aLayout = the alternate page layout.
|
|
|
|
* if null, restore the basic page layout
|
|
|
|
*/
|
|
|
|
static void SetAltInstance( WORKSHEET_LAYOUT* aLayout = NULL );
|
2013-06-05 12:03:16 +00:00
|
|
|
|
2013-07-20 19:36:19 +00:00
|
|
|
// Accessors:
|
|
|
|
double GetLeftMargin() { return m_leftMargin; }
|
|
|
|
double GetRightMargin() { return m_rightMargin; }
|
|
|
|
double GetTopMargin() { return m_topMargin; }
|
|
|
|
double GetBottomMargin() { return m_bottomMargin; }
|
|
|
|
|
|
|
|
void SetLeftMargin( double aMargin );
|
|
|
|
void SetRightMargin( double aMargin );
|
|
|
|
void SetTopMargin( double aMargin );
|
|
|
|
void SetBottomMargin( double aMargin );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* In Kicad applications, a page layout description is needed
|
|
|
|
* So if the list is empty, a default description is loaded,
|
|
|
|
* the first time a page layout is drawn.
|
|
|
|
* However, in page layout editor, an empty list is acceptable.
|
|
|
|
* AllowVoidList allows or not the empty list
|
|
|
|
*/
|
|
|
|
void AllowVoidList( bool Allow ) { m_allowVoidList = Allow; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if an empty list is allowed
|
|
|
|
* (mainly allowed for page layout editor).
|
|
|
|
*/
|
|
|
|
bool VoidListAllowed() { return m_allowVoidList; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* erase the list of items
|
|
|
|
*/
|
|
|
|
void ClearList();
|
|
|
|
|
|
|
|
/**
|
2013-07-26 12:50:29 +00:00
|
|
|
* Save the description in a file
|
2013-07-19 18:27:22 +00:00
|
|
|
* @param aFullFileName the filename of the file to created
|
|
|
|
*/
|
|
|
|
void Save( const wxString& aFullFileName );
|
|
|
|
|
2013-07-26 12:50:29 +00:00
|
|
|
/**
|
|
|
|
* Save the description in a buffer
|
|
|
|
* @param aOutputString = a wxString to store the S expr string
|
|
|
|
*/
|
|
|
|
void SaveInString( wxString& aOutputString );
|
|
|
|
|
2013-06-05 12:03:16 +00:00
|
|
|
/**
|
|
|
|
* Add an item to the list of items
|
|
|
|
*/
|
|
|
|
void Append( WORKSHEET_DATAITEM* aItem )
|
|
|
|
{
|
|
|
|
m_list.push_back( aItem );
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
*Insert an item to the list of items at position aIdx
|
|
|
|
*/
|
|
|
|
void Insert( WORKSHEET_DATAITEM* aItem, unsigned aIdx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*Remove the item to the list of items at position aIdx
|
|
|
|
*/
|
|
|
|
bool Remove( unsigned aIdx );
|
|
|
|
|
|
|
|
/**
|
|
|
|
*Remove the item to the list of items at position aIdx
|
|
|
|
*/
|
|
|
|
bool Remove( WORKSHEET_DATAITEM* aItem );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the index of aItem, or -1 if does not exist
|
|
|
|
*/
|
|
|
|
int GetItemIndex( WORKSHEET_DATAITEM* aItem ) const;
|
|
|
|
|
2013-06-05 12:03:16 +00:00
|
|
|
/**
|
|
|
|
* @return the item from its index aIdx, or NULL if does not exist
|
|
|
|
*/
|
2013-07-19 18:27:22 +00:00
|
|
|
WORKSHEET_DATAITEM* GetItem( unsigned aIdx ) const;
|
2013-06-05 12:03:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the item count
|
|
|
|
*/
|
|
|
|
unsigned GetCount() const { return m_list.size(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fills the list with the default layout shape
|
|
|
|
*/
|
|
|
|
void SetDefaultLayout();
|
2013-06-07 09:49:36 +00:00
|
|
|
|
|
|
|
/**
|
2013-07-19 18:27:22 +00:00
|
|
|
* Populates the list with a custom layout, or
|
2013-06-07 09:49:36 +00:00
|
|
|
* the default layout, if no custom layout available
|
2013-07-19 18:27:22 +00:00
|
|
|
* @param aFullFileName = the custom page layout description file.
|
|
|
|
* if empty, loads the file defined by KICAD_WKSFILE
|
|
|
|
* and if its is not defined, uses the default internal description
|
|
|
|
* @param Append = if true: do not delete old layout, and load only
|
|
|
|
aFullFileName.
|
2013-06-07 09:49:36 +00:00
|
|
|
*/
|
2013-07-19 18:27:22 +00:00
|
|
|
void SetPageLayout( const wxString& aFullFileName = wxEmptyString,
|
|
|
|
bool Append = false );
|
2013-06-07 09:49:36 +00:00
|
|
|
|
2013-07-26 12:50:29 +00:00
|
|
|
/**
|
|
|
|
* Populates the list from a S expr description stored in a string
|
|
|
|
* @param aPageLayout = the S expr string
|
2013-09-17 00:52:08 +00:00
|
|
|
* @param Append Do not delete old layout if true and append \a aPageLayout
|
|
|
|
* the existing one.
|
2013-07-26 12:50:29 +00:00
|
|
|
*/
|
|
|
|
void SetPageLayout( const char* aPageLayout, bool Append = false );
|
|
|
|
|
2013-07-19 18:27:22 +00:00
|
|
|
/**
|
|
|
|
* @return a short filename from a full filename:
|
2014-12-31 12:31:19 +00:00
|
|
|
* if the path is the current project path, or if the path
|
2013-07-19 18:27:22 +00:00
|
|
|
* is the same as kicad.pro (in template), returns the shortname
|
|
|
|
* else do nothing and returns a full filename
|
2014-12-31 12:31:19 +00:00
|
|
|
* @param aFullFileName = the full filename, which can be a relative
|
|
|
|
* @param aProjectPath = the curr project absolute path (can be empty)
|
2013-07-19 18:27:22 +00:00
|
|
|
*/
|
2014-12-31 12:31:19 +00:00
|
|
|
static const wxString MakeShortFileName( const wxString& aFullFileName,
|
|
|
|
const wxString& aProjectPath );
|
2013-07-19 18:27:22 +00:00
|
|
|
|
|
|
|
/**
|
2014-12-31 12:31:19 +00:00
|
|
|
* Static function
|
|
|
|
* @return a full filename from a short filename.
|
|
|
|
* @param aShortFileName = the short filename, which can be a relative
|
|
|
|
* @param aProjectPath = the curr project absolute path (can be empty)
|
|
|
|
* or absolute path, and can include env variable reference ( ${envvar} expression )
|
|
|
|
* if the short filename path is relative, it is expected relative to the project path
|
|
|
|
* or (if aProjectPath is empty or if the file does not exist)
|
|
|
|
* relative to kicad.pro (in template)
|
|
|
|
* If aShortFileName is absolute return aShortFileName
|
|
|
|
*/
|
|
|
|
static const wxString MakeFullFileName( const wxString& aShortFileName,
|
|
|
|
const wxString& aProjectPath );
|
2013-06-05 12:03:16 +00:00
|
|
|
};
|
|
|
|
|
2013-05-22 08:45:25 +00:00
|
|
|
#endif // WORKSHEET_SHAPE_BUILDER_H
|