2011-12-01 16:49:28 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.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
|
|
|
|
*/
|
|
|
|
|
2011-09-07 19:41:04 +00:00
|
|
|
/**
|
|
|
|
* @file base_struct.h
|
2011-09-30 18:15:37 +00:00
|
|
|
* @brief Basic classes for most KiCad items.
|
2011-09-07 19:41:04 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
#ifndef BASE_STRUCT_H_
|
|
|
|
#define BASE_STRUCT_H_
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
#include "colors.h"
|
2011-03-25 19:16:05 +00:00
|
|
|
#include "bitmaps.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
#include <boost/ptr_container/ptr_vector.hpp>
|
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
#if defined(DEBUG)
|
2007-08-06 02:02:39 +00:00
|
|
|
#include <iostream> // needed for Show()
|
2009-11-23 20:18:47 +00:00
|
|
|
extern std::ostream& operator <<( std::ostream& out, const wxSize& size );
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
extern std::ostream& operator <<( std::ostream& out, const wxPoint& pt );
|
2007-08-06 02:02:39 +00:00
|
|
|
#endif
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Id for class identification, at run time */
|
2007-08-24 15:10:46 +00:00
|
|
|
enum KICAD_T {
|
2007-10-31 17:47:44 +00:00
|
|
|
NOT_USED = -1, // the 3d code uses this value
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
EOT = 0, // search types array terminator (End Of Types)
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-04 04:42:49 +00:00
|
|
|
TYPE_NOT_INIT = 0,
|
2011-10-01 19:24:27 +00:00
|
|
|
PCB_T,
|
|
|
|
SCREEN_T, // not really an item, used to identify a screen
|
2007-08-04 04:42:49 +00:00
|
|
|
|
|
|
|
// Items in pcb
|
2011-10-01 19:24:27 +00:00
|
|
|
PCB_MODULE_T, // a footprint
|
|
|
|
PCB_PAD_T, // a pad in a footprint
|
|
|
|
PCB_LINE_T, // a segment not on copper layers
|
|
|
|
PCB_TEXT_T, // a text on a layer
|
|
|
|
PCB_MODULE_TEXT_T, // a text in a footprint
|
|
|
|
PCB_MODULE_EDGE_T, // a footprint edge
|
|
|
|
PCB_TRACE_T, // a track segment (segment on a copper layer)
|
2011-12-01 16:49:28 +00:00
|
|
|
PCB_VIA_T, // a via (like a track segment on a copper layer)
|
2011-10-01 19:24:27 +00:00
|
|
|
PCB_ZONE_T, // a segment used to fill a zone area (segment on a
|
2009-11-23 20:18:47 +00:00
|
|
|
// copper layer)
|
2011-10-01 19:24:27 +00:00
|
|
|
PCB_MARKER_T, // a marker used to show something
|
|
|
|
PCB_DIMENSION_T, // a dimension (graphic item)
|
2011-09-07 19:41:04 +00:00
|
|
|
PCB_TARGET_T, // a target (graphic item)
|
2011-10-01 19:24:27 +00:00
|
|
|
PCB_ZONE_EDGE_T, // in zone outline: a point to define an outline
|
|
|
|
PCB_ZONE_AREA_T, // a zone area
|
|
|
|
PCB_ITEM_LIST_T, // a list of board items
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
// Schematic draw Items. The order of these items effects the sort order.
|
2011-12-01 16:49:28 +00:00
|
|
|
// It is currently ordered to mimic the old Eeschema locate behavior where
|
2011-03-25 19:16:05 +00:00
|
|
|
// the smallest item is the selected item.
|
|
|
|
SCH_MARKER_T,
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_JUNCTION_T,
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_NO_CONNECT_T,
|
|
|
|
SCH_BUS_ENTRY_T,
|
|
|
|
SCH_LINE_T,
|
|
|
|
SCH_POLYLINE_T,
|
2011-08-31 14:59:20 +00:00
|
|
|
SCH_BITMAP_T,
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_TEXT_T,
|
|
|
|
SCH_LABEL_T,
|
|
|
|
SCH_GLOBAL_LABEL_T,
|
|
|
|
SCH_HIERARCHICAL_LABEL_T,
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_FIELD_T,
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_COMPONENT_T,
|
2011-03-30 19:26:05 +00:00
|
|
|
SCH_SHEET_PIN_T,
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_SHEET_T,
|
2007-08-04 04:42:49 +00:00
|
|
|
|
|
|
|
// General
|
2010-12-10 19:47:44 +00:00
|
|
|
SCH_SCREEN_T,
|
2007-08-04 04:42:49 +00:00
|
|
|
BLOCK_LOCATE_STRUCT_TYPE,
|
|
|
|
|
2009-10-05 17:52:41 +00:00
|
|
|
/*
|
|
|
|
* Draw items in library component.
|
|
|
|
*
|
|
|
|
* The order of these items effects the sort order for items inside the
|
|
|
|
* "DRAW/ENDDRAW" section of the component definition in a library file.
|
|
|
|
* If you add a new draw item, type, please make sure you add it so the
|
|
|
|
* sort order is logical.
|
|
|
|
*/
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_COMPONENT_T,
|
|
|
|
LIB_ALIAS_T,
|
2010-12-10 19:47:44 +00:00
|
|
|
LIB_ARC_T,
|
|
|
|
LIB_CIRCLE_T,
|
|
|
|
LIB_TEXT_T,
|
|
|
|
LIB_RECTANGLE_T,
|
|
|
|
LIB_POLYLINE_T,
|
|
|
|
LIB_BEZIER_T,
|
|
|
|
LIB_PIN_T,
|
2009-10-05 17:52:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
|
|
|
|
* types before this line.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
LIB_FIELD_T,
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2010-09-28 14:42:05 +00:00
|
|
|
/*
|
2011-09-30 18:15:37 +00:00
|
|
|
* For GerbView: items type:
|
2010-09-28 14:42:05 +00:00
|
|
|
*/
|
|
|
|
TYPE_GERBER_DRAW_ITEM,
|
|
|
|
|
2007-08-04 04:42:49 +00:00
|
|
|
// End value
|
|
|
|
MAX_STRUCT_TYPE_ID
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
enum SEARCH_RESULT {
|
|
|
|
SEARCH_QUIT,
|
|
|
|
SEARCH_CONTINUE
|
2007-10-31 17:47:44 +00:00
|
|
|
};
|
2007-08-06 20:26:59 +00:00
|
|
|
|
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
class wxFindReplaceData;
|
2010-12-08 20:12:46 +00:00
|
|
|
class EDA_ITEM;
|
2011-01-21 19:30:59 +00:00
|
|
|
class EDA_DRAW_FRAME;
|
2011-03-29 19:33:07 +00:00
|
|
|
class EDA_RECT;
|
2011-01-21 19:30:59 +00:00
|
|
|
class EDA_DRAW_PANEL;
|
2011-11-17 01:06:08 +00:00
|
|
|
class DHEAD;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
/**
|
|
|
|
* Class INSPECTOR
|
2007-10-31 17:47:44 +00:00
|
|
|
* is an abstract class that is used to inspect and possibly collect the
|
2007-08-06 20:26:59 +00:00
|
|
|
* (search) results of Iterating over a list or tree of KICAD_T objects.
|
2007-08-06 21:02:23 +00:00
|
|
|
* Extend from this class and implement the Inspect function and provide for
|
2007-08-06 20:26:59 +00:00
|
|
|
* a way for the extension to collect the results of the search/scan data and
|
|
|
|
* provide them to the caller.
|
|
|
|
*/
|
|
|
|
class INSPECTOR
|
|
|
|
{
|
|
|
|
public:
|
2007-08-20 01:20:48 +00:00
|
|
|
virtual ~INSPECTOR()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
/**
|
|
|
|
* Function Inspect
|
2007-10-31 17:47:44 +00:00
|
|
|
* is the examining function within the INSPECTOR which is passed to the
|
2011-12-08 15:45:01 +00:00
|
|
|
* EDA_ITEM::Iterate() function. It is used primarily for searching, but
|
|
|
|
* not limited to that. It can also collect or modify the scanned objects.
|
2007-08-06 21:02:23 +00:00
|
|
|
*
|
2011-12-08 15:45:01 +00:00
|
|
|
* @param aItem An EDA_ITEM to examine.
|
|
|
|
* @param aTestData is arbitrary data needed by the inspector to determine
|
|
|
|
* if the EDA_ITEM under test meets its match criteria.
|
|
|
|
* @return A #SEARCH_RESULT type #SEARCH_QUIT if the iterator function is to
|
|
|
|
* stop the scan, else #SEARCH_CONTINUE;
|
2007-10-31 17:47:44 +00:00
|
|
|
*/
|
2011-12-08 15:45:01 +00:00
|
|
|
SEARCH_RESULT virtual Inspect( EDA_ITEM* aItem, const void* aTestData ) = 0;
|
2007-08-06 20:26:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-15 04:18:32 +00:00
|
|
|
/**
|
2011-03-29 19:33:07 +00:00
|
|
|
* Class EDA_RECT
|
2008-03-15 04:18:32 +00:00
|
|
|
* handles the component boundary box.
|
|
|
|
* This class is similar to wxRect, but some wxRect functions are very curious,
|
2011-09-30 18:15:37 +00:00
|
|
|
* and are working only if dimensions are >= 0 (not always the case in KiCad)
|
|
|
|
* and also KiCad needs some specific method.
|
2010-12-20 17:44:25 +00:00
|
|
|
* so I prefer this more suitable class
|
2008-03-15 04:18:32 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
class EDA_RECT
|
2008-03-15 04:18:32 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxPoint m_Pos; // Rectangle Origin
|
|
|
|
wxSize m_Size; // Rectangle Size
|
|
|
|
|
|
|
|
public:
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT() { };
|
2008-03-15 04:18:32 +00:00
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT( const wxPoint& aPos, const wxSize& aSize ) :
|
2009-11-23 20:18:47 +00:00
|
|
|
m_Pos( aPos ),
|
|
|
|
m_Size( aSize )
|
2008-12-16 19:44:57 +00:00
|
|
|
{ }
|
2008-03-15 04:18:32 +00:00
|
|
|
|
|
|
|
wxPoint Centre()
|
|
|
|
{
|
2009-11-23 20:18:47 +00:00
|
|
|
return wxPoint( m_Pos.x + ( m_Size.x >> 1 ),
|
|
|
|
m_Pos.y + ( m_Size.y >> 1 ) );
|
2008-03-15 04:18:32 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function Move
|
|
|
|
* moves the rectangle by the \a aMoveVector.
|
|
|
|
* @param aMoveVector A wxPoint that is the value to move this rectangle
|
2009-11-28 09:24:37 +00:00
|
|
|
*/
|
|
|
|
void Move( const wxPoint& aMoveVector );
|
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
/**
|
|
|
|
* Function Normalize
|
2011-12-01 16:49:28 +00:00
|
|
|
* ensures that the height ant width are positive.
|
2010-12-20 17:44:25 +00:00
|
|
|
*/
|
2010-12-21 15:13:09 +00:00
|
|
|
void Normalize();
|
2010-12-20 17:44:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Contains
|
|
|
|
* @param aPoint = the wxPoint to test
|
|
|
|
* @return true if aPoint is inside the boundary box. A point on a edge is seen as inside
|
|
|
|
*/
|
2010-12-21 15:13:09 +00:00
|
|
|
bool Contains( const wxPoint& aPoint ) const;
|
2010-12-20 17:44:25 +00:00
|
|
|
/**
|
|
|
|
* Function Contains
|
|
|
|
* @param x = the x coordinate of the point to test
|
|
|
|
* @param y = the x coordinate of the point to test
|
|
|
|
* @return true if point is inside the boundary box. A point on a edge is seen as inside
|
|
|
|
*/
|
|
|
|
bool Contains( int x, int y ) const { return Contains( wxPoint( x, y ) ); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Contains
|
2011-03-29 19:33:07 +00:00
|
|
|
* @param aRect = the EDA_RECT to test
|
2010-12-20 17:44:25 +00:00
|
|
|
* @return true if aRect is Contained. A common edge is seen as contained
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
bool Contains( const EDA_RECT& aRect ) const;
|
2008-03-15 04:18:32 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
wxSize GetSize() const { return m_Size; }
|
2009-12-30 18:06:12 +00:00
|
|
|
int GetX() const { return m_Pos.x; }
|
|
|
|
int GetY() const { return m_Pos.y; }
|
2010-12-10 19:47:44 +00:00
|
|
|
wxPoint GetOrigin() const { return m_Pos; }
|
|
|
|
wxPoint GetPosition() const { return m_Pos; }
|
2009-12-30 18:06:12 +00:00
|
|
|
wxPoint GetEnd() const { return wxPoint( GetRight(), GetBottom() ); }
|
|
|
|
int GetWidth() const { return m_Size.x; }
|
|
|
|
int GetHeight() const { return m_Size.y; }
|
|
|
|
int GetRight() const { return m_Pos.x + m_Size.x; }
|
|
|
|
int GetBottom() const { return m_Pos.y + m_Size.y; }
|
2008-03-15 04:18:32 +00:00
|
|
|
void SetOrigin( const wxPoint& pos ) { m_Pos = pos; }
|
|
|
|
void SetOrigin( int x, int y ) { m_Pos.x = x; m_Pos.y = y; }
|
|
|
|
void SetSize( const wxSize& size ) { m_Size = size; }
|
|
|
|
void SetSize( int w, int h ) { m_Size.x = w; m_Size.y = h; }
|
|
|
|
void Offset( int dx, int dy ) { m_Pos.x += dx; m_Pos.y += dy; }
|
2009-11-23 20:18:47 +00:00
|
|
|
void Offset( const wxPoint& offset ) { m_Pos.x += offset.x; m_Pos.y +=
|
|
|
|
offset.y; }
|
2008-03-15 04:18:32 +00:00
|
|
|
void SetX( int val ) { m_Pos.x = val; }
|
|
|
|
void SetY( int val ) { m_Pos.y = val; }
|
|
|
|
void SetWidth( int val ) { m_Size.x = val; }
|
|
|
|
void SetHeight( int val ) { m_Size.y = val; }
|
2009-04-05 20:49:15 +00:00
|
|
|
void SetEnd( int x, int y ) { SetEnd( wxPoint( x, y ) ); }
|
2008-03-15 04:18:32 +00:00
|
|
|
void SetEnd( const wxPoint& pos )
|
|
|
|
{
|
|
|
|
m_Size.x = pos.x - m_Pos.x; m_Size.y = pos.y - m_Pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Intersects
|
|
|
|
* @return bool - true if the argument rectangle intersects this rectangle.
|
2010-12-20 17:44:25 +00:00
|
|
|
* (i.e. if the 2 rectangles have at least a common point)
|
2008-03-15 04:18:32 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
bool Intersects( const EDA_RECT& aRect ) const;
|
2008-03-15 04:18:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function operator(wxRect)
|
|
|
|
* overloads the cast operator to return a wxRect
|
|
|
|
*/
|
|
|
|
operator wxRect() const { return wxRect( m_Pos, m_Size ); }
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function Inflate
|
|
|
|
* inflates the rectangle horizontally by \a dx and vertically by \a dy. If \a dx
|
|
|
|
* and/or \a dy is negative the rectangle is deflated.
|
2009-10-21 19:16:25 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT& Inflate( wxCoord dx, wxCoord dy );
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function Inflate
|
|
|
|
* inflates the rectangle horizontally and vertically by \a aDelta. If \a aDelta
|
|
|
|
* is negative the rectangle is deflated.
|
2009-10-21 19:16:25 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT& Inflate( int aDelta );
|
2009-10-21 19:16:25 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function Merge
|
2010-12-21 15:13:09 +00:00
|
|
|
* modifies the position and size of the rectangle in order to contain \a aRect. It is
|
|
|
|
* mainly used to calculate bounding boxes.
|
|
|
|
* @param aRect The rectangle to merge with this rectangle.
|
2008-12-16 19:44:57 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
void Merge( const EDA_RECT& aRect );
|
2010-11-17 18:41:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Merge
|
2010-12-21 15:13:09 +00:00
|
|
|
* modifies the position and size of the rectangle in order to contain the given point.
|
|
|
|
* @param aPoint The point to merge with the rectangle.
|
2010-11-17 18:41:20 +00:00
|
|
|
*/
|
2011-03-25 19:16:05 +00:00
|
|
|
void Merge( const wxPoint& aPoint );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetArea
|
|
|
|
* returns the area of the rectangle.
|
|
|
|
* @return The area of the rectangle.
|
|
|
|
*/
|
|
|
|
double GetArea() const;
|
2008-03-15 04:18:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
|
|
|
|
// These define are used for the .m_Flags and .m_UndoRedoStatus member of the
|
2010-12-08 20:12:46 +00:00
|
|
|
// class EDA_ITEM
|
2011-02-13 17:53:48 +00:00
|
|
|
#define IS_CHANGED (1 << 0) ///< Item was edited, and modified
|
|
|
|
#define IS_LINKED (1 << 1) ///< Used in calculation to mark linked items (temporary use)
|
|
|
|
#define IN_EDIT (1 << 2) ///< Item currently edited
|
|
|
|
#define IS_MOVED (1 << 3) ///< Item being moved
|
|
|
|
#define IS_NEW (1 << 4) ///< New item, just created
|
|
|
|
#define IS_RESIZED (1 << 5) ///< Item being resized
|
|
|
|
#define IS_DRAGGED (1 << 6) ///< Item being dragged
|
2010-10-25 15:43:42 +00:00
|
|
|
#define IS_DELETED (1 << 7)
|
|
|
|
#define IS_WIRE_IMAGE (1 << 8)
|
|
|
|
#define STARTPOINT (1 << 9)
|
|
|
|
#define ENDPOINT (1 << 10)
|
|
|
|
#define SELECTED (1 << 11)
|
|
|
|
#define SELECTEDNODE (1 << 12) ///< flag indicating that the structure has already selected
|
|
|
|
#define STRUCT_DELETED (1 << 13) ///< flag indication structures to be erased
|
|
|
|
#define CANDIDATE (1 << 14) ///< flag indicating that the structure is connected
|
|
|
|
#define SKIP_STRUCT (1 << 15) ///< flag indicating that the structure should be ignored
|
|
|
|
#define DO_NOT_DRAW (1 << 16) ///< Used to disable draw function
|
|
|
|
#define IS_CANCELLED (1 << 17) ///< flag set when edit dialogs are canceled when editing a
|
|
|
|
///< new object
|
2011-02-13 17:53:48 +00:00
|
|
|
#define TRACK_LOCKED (1 << 18) ///< Pcbnew: track locked: protected from global deletion
|
|
|
|
#define TRACK_AR (1 << 19) ///< Pcbnew: autorouted track
|
|
|
|
#define FLAG1 (1 << 20) ///< Pcbnew: flag used in local computations
|
|
|
|
#define FLAG0 (1 << 21) ///< Pcbnew: flag used in local computations
|
|
|
|
#define BEGIN_ONPAD (1 << 22) ///< Pcbnew: flag set for track segment starting on a pad
|
|
|
|
#define END_ONPAD (1 << 23) ///< Pcbnew: flag set for track segment ending on a pad
|
|
|
|
#define BUSY (1 << 24) ///< Pcbnew: flag indicating that the structure has
|
|
|
|
// already been edited, in some functions
|
2011-03-03 01:58:12 +00:00
|
|
|
#define EDA_ITEM_ALL_FLAGS -1
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
/**
|
|
|
|
* Class EDA_ITEM
|
|
|
|
* is a base class for most all the KiCad significant classes, used in
|
|
|
|
* schematics and boards.
|
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
class EDA_ITEM
|
2009-07-23 15:37:00 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Run time identification, _keep private_ so it can never be changed after
|
2009-11-23 20:18:47 +00:00
|
|
|
* a constructor sets it. See comment near SetType() regarding virtual
|
2010-12-08 20:12:46 +00:00
|
|
|
* functions.
|
2009-07-23 15:37:00 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
KICAD_T m_StructType;
|
|
|
|
int m_Status;
|
2009-07-23 15:37:00 +00:00
|
|
|
|
|
|
|
protected:
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* Pnext; /* Linked list: Link (next struct) */
|
|
|
|
EDA_ITEM* Pback; /* Linked list: Link (previous struct) */
|
|
|
|
EDA_ITEM* m_Parent; /* Linked list: Link (parent struct) */
|
|
|
|
EDA_ITEM* m_Son; /* Linked list: Link (son struct) */
|
|
|
|
DHEAD* m_List; ///< which DLIST I am on.
|
2009-07-23 15:37:00 +00:00
|
|
|
|
|
|
|
public:
|
2010-12-08 20:12:46 +00:00
|
|
|
int m_Flags; // flags for editing and other uses.
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
unsigned long m_TimeStamp; // Time stamp used for logical links
|
2011-12-01 16:49:28 +00:00
|
|
|
int m_Selected; /* Used by block commands, and selective editing */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-07-23 15:37:00 +00:00
|
|
|
// member used in undo/redo function
|
2011-04-27 19:44:32 +00:00
|
|
|
EDA_ITEM* m_Image; // Link to an image copy to save a copy of
|
|
|
|
// old parameters values
|
2007-06-05 12:10:51 +00:00
|
|
|
private:
|
2007-08-30 22:20:52 +00:00
|
|
|
void InitVars();
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* @brief Function doClone
|
|
|
|
* is used by the derived class to actually implement the cloning.
|
|
|
|
*
|
|
|
|
* The default version will return NULL in release builds and likely crash the
|
|
|
|
* program. In debug builds, an warning message indicating the derived class
|
|
|
|
* has not implemented cloning. This really should be a pure virtual function.
|
|
|
|
* Due to the fact that there are so many objects derived from EDA_ITEM, the
|
|
|
|
* decision was made to return NULL until all the objects derived from EDA_ITEM
|
|
|
|
* implement cloning. Once that happens, this function should be made pure.
|
|
|
|
*
|
|
|
|
* @return A clone of the item.
|
|
|
|
*/
|
|
|
|
virtual EDA_ITEM* doClone() const;
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
public:
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM( EDA_ITEM* parent, KICAD_T idType );
|
|
|
|
EDA_ITEM( KICAD_T idType );
|
|
|
|
EDA_ITEM( const EDA_ITEM& base );
|
|
|
|
virtual ~EDA_ITEM() { };
|
2007-09-01 12:00:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Type
|
2009-11-23 20:18:47 +00:00
|
|
|
* returns the type of object. This attribute should never be changed
|
|
|
|
* after a constructor sets it, so there is no public "setter" method.
|
2007-09-01 12:00:30 +00:00
|
|
|
* @return KICAD_T - the type of object.
|
|
|
|
*/
|
2007-10-31 17:47:44 +00:00
|
|
|
KICAD_T Type() const { return m_StructType; }
|
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
void SetTimeStamp( unsigned long aNewTimeStamp ) { m_TimeStamp = aNewTimeStamp; }
|
|
|
|
unsigned long GetTimeStamp() const { return m_TimeStamp; }
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* Next() const { return (EDA_ITEM*) Pnext; }
|
|
|
|
EDA_ITEM* Back() const { return (EDA_ITEM*) Pback; }
|
|
|
|
EDA_ITEM* GetParent() const { return m_Parent; }
|
|
|
|
EDA_ITEM* GetSon() const { return m_Son; }
|
2008-12-16 19:44:57 +00:00
|
|
|
DHEAD* GetList() const { return m_List; }
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SetNext( EDA_ITEM* aNext ) { Pnext = aNext; }
|
|
|
|
void SetBack( EDA_ITEM* aBack ) { Pback = aBack; }
|
|
|
|
void SetParent( EDA_ITEM* aParent ) { m_Parent = aParent; }
|
|
|
|
void SetSon( EDA_ITEM* aSon ) { m_Son = aSon; }
|
|
|
|
void SetList( DHEAD* aList ) { m_List = aList; }
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
inline bool IsNew() const { return m_Flags & IS_NEW; }
|
|
|
|
inline bool IsModified() const { return m_Flags & IS_CHANGED; }
|
|
|
|
inline bool IsMoving() const { return m_Flags & IS_MOVED; }
|
|
|
|
inline bool IsDragging() const { return m_Flags & IS_DRAGGED; }
|
2010-11-03 14:13:15 +00:00
|
|
|
inline bool IsSelected() const { return m_Flags & SELECTED; }
|
2011-07-08 19:55:41 +00:00
|
|
|
inline bool IsResized() const { return m_Flags & IS_RESIZED; }
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-12-07 16:10:42 +00:00
|
|
|
void SetModified();
|
|
|
|
|
2007-10-31 06:40:15 +00:00
|
|
|
int GetState( int type ) const
|
|
|
|
{
|
|
|
|
return m_Status & type;
|
|
|
|
}
|
|
|
|
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-10-31 06:40:15 +00:00
|
|
|
void SetState( int type, int state )
|
|
|
|
{
|
|
|
|
if( state )
|
2007-10-31 17:47:44 +00:00
|
|
|
m_Status |= type; // state = ON or OFF
|
2007-10-31 06:40:15 +00:00
|
|
|
else
|
|
|
|
m_Status &= ~type;
|
|
|
|
}
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
int ReturnStatus() const { return m_Status; }
|
2007-08-04 04:42:49 +00:00
|
|
|
|
|
|
|
void SetStatus( int new_status )
|
|
|
|
{
|
|
|
|
m_Status = new_status;
|
|
|
|
}
|
|
|
|
|
2011-03-03 01:58:12 +00:00
|
|
|
void SetFlags( int aMask ) { m_Flags |= aMask; }
|
|
|
|
void ClearFlags( int aMask = EDA_ITEM_ALL_FLAGS ) { m_Flags &= ~aMask; }
|
|
|
|
int GetFlags() const { return m_Flags; }
|
2008-12-16 19:44:57 +00:00
|
|
|
|
2007-08-20 19:33:15 +00:00
|
|
|
/**
|
2009-04-17 08:51:02 +00:00
|
|
|
* Function DisplayInfo
|
2009-11-23 20:18:47 +00:00
|
|
|
* has knowledge about the frame and how and where to put status
|
|
|
|
* information about this object into the frame's message panel.
|
2011-01-21 19:30:59 +00:00
|
|
|
* @param frame A EDA_DRAW_FRAME in which to print status information.
|
2007-10-31 17:47:44 +00:00
|
|
|
*/
|
2011-03-03 01:58:12 +00:00
|
|
|
virtual void DisplayInfo( EDA_DRAW_FRAME* frame )
|
2007-08-20 19:33:15 +00:00
|
|
|
{
|
2007-10-31 17:47:44 +00:00
|
|
|
// derived classes may implement this
|
2007-08-20 19:33:15 +00:00
|
|
|
}
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param refPos A wxPoint to test
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-03-03 01:58:12 +00:00
|
|
|
virtual bool HitTest( const wxPoint& refPos )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
return false; // derived classes should override this function
|
|
|
|
}
|
|
|
|
|
2008-03-05 22:40:52 +00:00
|
|
|
/**
|
2009-11-23 20:18:47 +00:00
|
|
|
* Function HitTest (overlaid)
|
2011-03-29 19:33:07 +00:00
|
|
|
* tests if the given EDA_RECT intersect this object.
|
2008-03-05 22:40:52 +00:00
|
|
|
* For now, an ending point must be inside this rect.
|
2011-03-29 19:33:07 +00:00
|
|
|
* @param refArea : the given EDA_RECT
|
2008-03-05 22:40:52 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
virtual bool HitTest( EDA_RECT& refArea )
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
|
|
|
return false; // derived classes should override this function
|
|
|
|
}
|
|
|
|
|
2008-03-15 04:18:32 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundingBox
|
2009-11-23 20:18:47 +00:00
|
|
|
* returns the orthogonal, bounding box of this object for display
|
|
|
|
* purposes.
|
2008-03-15 04:18:32 +00:00
|
|
|
* This box should be an enclosing perimeter for visible components of this
|
2009-11-23 20:18:47 +00:00
|
|
|
* object, and the units should be in the pcb or schematic coordinate
|
|
|
|
* system.
|
2008-03-15 04:18:32 +00:00
|
|
|
* It is OK to overestimate the size by a few counts.
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
virtual EDA_RECT GetBoundingBox() const
|
2008-03-15 04:18:32 +00:00
|
|
|
{
|
2009-11-23 20:18:47 +00:00
|
|
|
#if defined(DEBUG)
|
2008-12-16 19:44:57 +00:00
|
|
|
printf( "Missing GetBoundingBox()\n" );
|
2010-12-10 19:47:44 +00:00
|
|
|
Show( 0, std::cout ); // tell me which classes still need GetBoundingBox support
|
2008-03-20 01:50:21 +00:00
|
|
|
#endif
|
2008-12-16 19:44:57 +00:00
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
// return a zero-sized box per default. derived classes should override
|
|
|
|
// this
|
2011-03-29 19:33:07 +00:00
|
|
|
return EDA_RECT( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
|
2008-03-15 04:18:32 +00:00
|
|
|
}
|
2007-08-09 21:15:08 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* @brief Function Clone
|
|
|
|
* creates a duplicate of this item with linked list members set to NULL.
|
|
|
|
*
|
|
|
|
* The Clone() function only calls the private virtual doClone() which actually
|
|
|
|
* does the cloning for the derived object.
|
|
|
|
*
|
|
|
|
* @return A clone of the item.
|
|
|
|
*/
|
|
|
|
EDA_ITEM* Clone() const { return doClone(); }
|
2008-12-16 19:44:57 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
/**
|
|
|
|
* Function IterateForward
|
2007-10-31 17:47:44 +00:00
|
|
|
* walks through the object tree calling the inspector() on each object
|
2007-08-09 21:15:08 +00:00
|
|
|
* type requested in scanTypes.
|
|
|
|
*
|
2010-12-08 20:12:46 +00:00
|
|
|
* @param listStart The first in a list of EDA_ITEMs to iterate over.
|
2007-10-31 17:47:44 +00:00
|
|
|
* @param inspector Is an INSPECTOR to call on each object that is one of
|
2011-12-01 16:49:28 +00:00
|
|
|
* the requested scanTypes.
|
|
|
|
* @param testData Is an aid to testFunc, and should be sufficient to allow
|
|
|
|
* it to fully determine if an item meets the match criteria,
|
|
|
|
* but it may also be used to collect output.
|
|
|
|
* @param scanTypes A KICAD_T array that is EOT terminated, and provides both
|
|
|
|
* the order and interest level of of the types of objects to
|
|
|
|
* be iterated over.
|
|
|
|
* @return SEARCH_RESULT SEARCH_QUIT if the called INSPECTOR returned
|
|
|
|
* SEARCH_QUIT, else SCAN_CONTINUE;
|
2007-08-09 21:15:08 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
static SEARCH_RESULT IterateForward( EDA_ITEM* listStart,
|
|
|
|
INSPECTOR* inspector,
|
|
|
|
const void* testData,
|
|
|
|
const KICAD_T scanTypes[] );
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
/**
|
|
|
|
* Function Visit
|
|
|
|
* may be re-implemented for each derived class in order to handle
|
|
|
|
* all the types given by its member data. Implementations should call
|
2009-11-23 20:18:47 +00:00
|
|
|
* inspector->Inspect() on types in scanTypes[], and may use
|
|
|
|
* IterateForward()
|
2007-08-09 21:15:08 +00:00
|
|
|
* to do so on lists of such data.
|
|
|
|
* @param inspector An INSPECTOR instance to use in the inspection.
|
|
|
|
* @param testData Arbitrary data used by the inspector.
|
2007-10-31 17:47:44 +00:00
|
|
|
* @param scanTypes Which KICAD_T types are of interest and the order
|
2011-12-01 16:49:28 +00:00
|
|
|
* is significant too, terminated by EOT.
|
|
|
|
* @return SEARCH_RESULT SEARCH_QUIT if the Iterator is to stop the scan,
|
|
|
|
* else SCAN_CONTINUE, and determined by the inspector.
|
2007-08-09 21:15:08 +00:00
|
|
|
*/
|
2009-11-23 20:18:47 +00:00
|
|
|
virtual SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
|
|
|
|
const KICAD_T scanTypes[] );
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-07 06:21:19 +00:00
|
|
|
/**
|
|
|
|
* Function GetClass
|
|
|
|
* returns the class name.
|
|
|
|
* @return wxString
|
|
|
|
*/
|
|
|
|
virtual wxString GetClass() const
|
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
return wxT( "EDA_ITEM" );
|
2007-08-07 06:21:19 +00:00
|
|
|
}
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
/**
|
|
|
|
* Function GetSelectMenuText
|
|
|
|
* returns the text to display to be used in the selection clarification context menu
|
|
|
|
* when multiple items are found at the current cursor position. The default version
|
|
|
|
* of this function raises an assertion in the debug mode and returns a string to
|
|
|
|
* indicate that it was not overridden to provide the object specific text.
|
|
|
|
*
|
|
|
|
* @return The menu text string.
|
|
|
|
*/
|
|
|
|
virtual wxString GetSelectMenuText() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetMenuImage
|
|
|
|
* returns a pointer to an image to be used in menus. The default version returns
|
2011-12-01 16:49:28 +00:00
|
|
|
* the right arrow image. Override this function to provide object specific menu
|
2011-03-25 19:16:05 +00:00
|
|
|
* images.
|
|
|
|
* @return The menu image associated with the item.
|
|
|
|
*/
|
2011-08-29 03:04:59 +00:00
|
|
|
virtual BITMAP_DEF GetMenuImage() const { return right_xpm; }
|
2011-03-25 19:16:05 +00:00
|
|
|
|
2011-11-17 01:06:08 +00:00
|
|
|
/**
|
|
|
|
* Function Matches
|
|
|
|
* compares the item against the search criteria in \a aSearchData.
|
|
|
|
*
|
|
|
|
* The base class returns false since many of the objects derived from EDA_ITEM
|
|
|
|
* do not have any text to search.
|
|
|
|
*
|
2011-12-01 16:49:28 +00:00
|
|
|
* @param aSearchData A reference to a wxFindReplaceData object containing the
|
2011-11-17 01:06:08 +00:00
|
|
|
* search criteria.
|
|
|
|
* @param aAuxData A pointer to optional data required for the search or NULL
|
|
|
|
* if not used.
|
|
|
|
* @param aFindLocation A pointer to a wxPoint object to store the location of
|
|
|
|
* matched item. The pointer can be NULL is not used.
|
|
|
|
* @return True if this schematic text item matches the search criteria in
|
|
|
|
* \a aSearchData.
|
|
|
|
*/
|
|
|
|
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Matches
|
|
|
|
* compares \a aText against search criteria in \a aSearchData.
|
|
|
|
*
|
2011-12-01 16:49:28 +00:00
|
|
|
* @param aText A reference to a wxString object containing the string to test.
|
2011-11-17 01:06:08 +00:00
|
|
|
* @param aSearchData The criteria to search against.
|
|
|
|
* @return True if \a aText matches the search criteria in \a aSearchData.
|
|
|
|
*/
|
|
|
|
bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function IsReplaceable
|
|
|
|
* <p>
|
|
|
|
* Override this method in any derived object that supports test find and
|
|
|
|
* replace.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @return True if the item has replaceable text that can be modified using
|
|
|
|
* the find and replace dialog.
|
|
|
|
*/
|
|
|
|
virtual bool IsReplaceable() const { return false; }
|
|
|
|
|
2011-04-27 19:44:32 +00:00
|
|
|
/**
|
|
|
|
* Test if another item is less than this object.
|
|
|
|
*
|
|
|
|
* @param aItem - Item to compare against.
|
|
|
|
* @return - True if \a aItem is less than the item.
|
|
|
|
*/
|
|
|
|
bool operator<( const EDA_ITEM& aItem ) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Sort
|
|
|
|
* is a helper function to be used by the C++ STL sort algorithm for sorting a STL
|
|
|
|
* container of EDA_ITEM pointers.
|
|
|
|
*
|
|
|
|
* @param aLeft The left hand item to compare.
|
|
|
|
* @param aRight The right hand item to compare.
|
|
|
|
* @return True if \a aLeft is less than \a aRight.
|
|
|
|
*/
|
|
|
|
static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; }
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2009-11-23 20:18:47 +00:00
|
|
|
#if defined(DEBUG)
|
2007-09-13 11:28:58 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2007-10-31 17:47:44 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2011-12-01 16:49:28 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
2007-08-06 02:02:39 +00:00
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
virtual void Show( int nestLevel, std::ostream& os ) const;
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-10-31 17:47:44 +00:00
|
|
|
/**
|
2007-08-06 02:02:39 +00:00
|
|
|
* Function NestedSpace
|
|
|
|
* outputs nested space for pretty indenting.
|
|
|
|
* @param nestLevel The nest count
|
|
|
|
* @param os The ostream&, where to output
|
|
|
|
* @return std::ostream& - for continuation.
|
|
|
|
**/
|
2009-11-23 20:18:47 +00:00
|
|
|
static std::ostream& NestedSpace( int nestLevel, std::ostream& os );
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
#endif
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function new_clone
|
2011-03-25 19:16:05 +00:00
|
|
|
* provides cloning capabilities for all Boost pointer containers of EDA_ITEM pointers.
|
2010-12-21 15:13:09 +00:00
|
|
|
*
|
|
|
|
* @param aItem EDA_ITEM to clone.
|
|
|
|
* @return Clone of \a aItem.
|
|
|
|
*/
|
|
|
|
inline EDA_ITEM* new_clone( const EDA_ITEM& aItem ) { return aItem.Clone(); }
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define list of drawing items for screens.
|
|
|
|
*
|
2011-12-01 16:49:28 +00:00
|
|
|
* The standard C++ container was chosen so the pointer can be removed from a list without
|
2011-03-25 19:16:05 +00:00
|
|
|
* it being destroyed.
|
2010-12-21 15:13:09 +00:00
|
|
|
*/
|
2011-03-25 19:16:05 +00:00
|
|
|
typedef std::vector< EDA_ITEM* > EDA_ITEMS;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
// Graphic Text justify:
|
2007-06-05 12:10:51 +00:00
|
|
|
// Values -1,0,1 are used in computations, do not change them
|
2008-12-16 19:44:57 +00:00
|
|
|
enum GRTextHorizJustifyType {
|
2007-08-04 04:42:49 +00:00
|
|
|
GR_TEXT_HJUSTIFY_LEFT = -1,
|
|
|
|
GR_TEXT_HJUSTIFY_CENTER = 0,
|
|
|
|
GR_TEXT_HJUSTIFY_RIGHT = 1
|
2008-12-16 19:44:57 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
enum GRTextVertJustifyType {
|
2009-11-23 20:18:47 +00:00
|
|
|
GR_TEXT_VJUSTIFY_TOP = -1,
|
2007-08-04 04:42:49 +00:00
|
|
|
GR_TEXT_VJUSTIFY_CENTER = 0,
|
|
|
|
GR_TEXT_VJUSTIFY_BOTTOM = 1
|
2008-12-16 19:44:57 +00:00
|
|
|
};
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
/* Options to show solid segments (segments, texts...) */
|
2009-06-28 16:50:42 +00:00
|
|
|
enum GRTraceMode {
|
2009-11-23 20:18:47 +00:00
|
|
|
FILAIRE = 0, // segments are drawn as lines
|
|
|
|
FILLED, // normal mode: segments have thickness
|
2011-12-01 16:49:28 +00:00
|
|
|
SKETCH // sketch mode: segments have thickness, but are not
|
2009-11-23 20:18:47 +00:00
|
|
|
// filled
|
2008-12-16 19:44:57 +00:00
|
|
|
};
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
/**
|
|
|
|
* Enum FILL_T
|
|
|
|
* is the set of fill types used in plotting or drawing enclosed areas.
|
|
|
|
*/
|
|
|
|
enum FILL_T {
|
|
|
|
NO_FILL, // Poly, Square, Circle, Arc = option No Fill
|
|
|
|
FILLED_SHAPE, /* Poly, Square, Circle, Arc = option Fill
|
|
|
|
* with current color ("Solid shape") */
|
2010-10-04 12:58:07 +00:00
|
|
|
FILLED_WITH_BG_BODYCOLOR /* Poly, Square, Circle, Arc = option Fill
|
2009-06-28 16:50:42 +00:00
|
|
|
* with background body color, translucent
|
|
|
|
* (texts inside this shape can be seen)
|
|
|
|
* not filled in B&W mode when plotting or
|
|
|
|
* printing */
|
|
|
|
};
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-05-21 17:42:42 +00:00
|
|
|
#define DEFAULT_SIZE_TEXT 60 /* default text height (in mils or 1/1000") */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
/**
|
2011-03-29 19:33:07 +00:00
|
|
|
* Class EDA_TEXT
|
2009-11-23 20:18:47 +00:00
|
|
|
* is a basic class to handle texts (labels, texts on components or footprints
|
2011-11-30 21:15:56 +00:00
|
|
|
* ..) not used directly. The "used" text classes are derived from EDA_ITEM and
|
|
|
|
* EDA_TEXT using multiple inheritance.
|
2007-10-31 17:47:44 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
class EDA_TEXT
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2011-11-29 17:25:30 +00:00
|
|
|
int m_Thickness; /* pen size used to draw this text */
|
|
|
|
int m_Orient; /* Orient in 0.1 degrees */
|
|
|
|
|
2007-08-04 04:42:49 +00:00
|
|
|
wxString m_Text; /* text! */
|
|
|
|
wxPoint m_Pos; /* XY position of anchor text. */
|
|
|
|
wxSize m_Size; /* XY size of text */
|
2011-12-01 22:50:41 +00:00
|
|
|
bool m_Mirror; ///< true iff mirrored
|
2007-10-31 17:47:44 +00:00
|
|
|
int m_Attributs; /* flags (visible...) */
|
2009-11-23 20:18:47 +00:00
|
|
|
bool m_Italic; /* true to simulate (or use if exists)
|
|
|
|
* an italic font... */
|
2009-05-30 16:06:01 +00:00
|
|
|
bool m_Bold; /* true to simulate a bold font ... */
|
|
|
|
GRTextHorizJustifyType m_HJustify; /* Horiz justification */
|
|
|
|
GRTextVertJustifyType m_VJustify; /* Vertical justification */
|
2009-11-23 20:18:47 +00:00
|
|
|
bool m_MultilineAllowed; /* true to use multiline option, false
|
|
|
|
* to use only single line text
|
|
|
|
* Single line is faster in
|
|
|
|
* calculations than multiline */
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
public:
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_TEXT( const wxString& text = wxEmptyString );
|
|
|
|
EDA_TEXT( const EDA_TEXT& aText );
|
|
|
|
virtual ~EDA_TEXT();
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2011-01-09 11:17:28 +00:00
|
|
|
/**
|
|
|
|
* Function SetThickness
|
|
|
|
* sets text thickness.
|
|
|
|
* @param aNewThickness is the new text thickness.
|
|
|
|
*/
|
|
|
|
void SetThickness( int aNewThickness ) { m_Thickness = aNewThickness; };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetThickness
|
|
|
|
* returns text thickness.
|
|
|
|
* @return int - text thickness.
|
|
|
|
*/
|
|
|
|
int GetThickness() const { return m_Thickness; };
|
|
|
|
|
2011-11-29 17:25:30 +00:00
|
|
|
void SetOrientation( int aOrientation ) { m_Orient = aOrientation; }
|
|
|
|
int GetOrientation() const { return m_Orient; }
|
|
|
|
|
2011-11-30 07:43:46 +00:00
|
|
|
void SetItalic( bool isItalic ) { m_Italic = isItalic; }
|
2011-11-30 21:15:56 +00:00
|
|
|
bool IsItalic() const { return m_Italic; }
|
2011-11-30 07:43:46 +00:00
|
|
|
|
2011-12-01 22:50:41 +00:00
|
|
|
void SetMirrored( bool doMirror ) { m_Mirror = doMirror; }
|
|
|
|
bool IsMirrored() const { return m_Mirror; }
|
|
|
|
|
2011-01-09 11:17:28 +00:00
|
|
|
/**
|
|
|
|
* Function SetSize
|
|
|
|
* sets text size.
|
|
|
|
* @param aNewSize is the new text size.
|
|
|
|
*/
|
2011-11-30 21:15:56 +00:00
|
|
|
void SetSize( const wxSize& aNewSize ) { m_Size = aNewSize; };
|
2011-01-09 11:17:28 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetSize
|
|
|
|
* returns text size.
|
|
|
|
* @return wxSize - text size.
|
|
|
|
*/
|
2011-11-30 21:15:56 +00:00
|
|
|
const wxSize GetSize() const { return m_Size; };
|
2011-01-09 11:17:28 +00:00
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
/// named differently than the ones using multiple inheritance and including this class
|
|
|
|
void SetPos( const wxPoint& aPoint ) { m_Pos = aPoint; }
|
|
|
|
const wxPoint GetPos() const { return m_Pos; }
|
2011-11-29 17:25:30 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
int GetLength() const { return m_Text.Length(); };
|
2007-10-31 17:47:44 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
2011-12-01 16:49:28 +00:00
|
|
|
* @param aPanel = the current DrawPanel
|
|
|
|
* @param aDC = the current Device Context
|
|
|
|
* @param aOffset = draw offset (usually (0,0))
|
|
|
|
* @param aColor = text color
|
|
|
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode.
|
|
|
|
* @param aDisplay_mode = FILAIRE, FILLED or SKETCH
|
|
|
|
* @param aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ).
|
2008-12-16 19:44:57 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
2009-11-23 20:18:47 +00:00
|
|
|
const wxPoint& aOffset, EDA_Colors aColor,
|
|
|
|
int aDrawMode, GRTraceMode aDisplay_mode = FILAIRE,
|
|
|
|
EDA_Colors aAnchor_color = UNSPECIFIED_COLOR );
|
2007-08-04 04:42:49 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
private:
|
2009-11-23 20:18:47 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function DrawOneLineOfText
|
2009-05-01 16:46:56 +00:00
|
|
|
* Draw a single text line.
|
2011-03-29 19:33:07 +00:00
|
|
|
* Used to draw each line of this EDA_TEXT, that can be multiline
|
2011-12-01 16:49:28 +00:00
|
|
|
* @param aPanel = the current DrawPanel
|
|
|
|
* @param aDC = the current Device Context
|
|
|
|
* @param aOffset = draw offset (usually (0,0))
|
|
|
|
* @param aColor = text color
|
|
|
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode.
|
|
|
|
* @param aFillMode = FILAIRE, FILLED or SKETCH
|
|
|
|
* @param aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ).
|
|
|
|
* @param aText = the single line of text to draw.
|
|
|
|
* @param aPos = the position of this line ).
|
2009-05-01 16:46:56 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
void DrawOneLineOfText( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
|
2009-11-23 20:18:47 +00:00
|
|
|
const wxPoint& aOffset, EDA_Colors aColor,
|
|
|
|
int aDrawMode, GRTraceMode aFillMode,
|
|
|
|
EDA_Colors aAnchor_color, wxString& aText,
|
|
|
|
wxPoint aPos );
|
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
public:
|
2009-11-23 20:18:47 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
/**
|
2009-06-11 14:26:17 +00:00
|
|
|
* Function TextHitTest
|
2010-12-10 19:47:44 +00:00
|
|
|
* Test if \a aPoint is within the bounds of this object.
|
|
|
|
* @param aPoint- A wxPoint to test
|
|
|
|
* @param aAccuracy - Amount to inflate the bounding box.
|
2007-08-04 20:05:54 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const;
|
2007-10-31 17:47:44 +00:00
|
|
|
|
|
|
|
/**
|
2009-11-23 20:18:47 +00:00
|
|
|
* Function TextHitTest (overloaded)
|
2010-12-10 19:47:44 +00:00
|
|
|
* Tests if object bounding box is contained within or intersects \a aRect.
|
|
|
|
*
|
|
|
|
* @param aRect - Rect to test against.
|
|
|
|
* @param aContains - Test for containment instead of intersection if true.
|
|
|
|
* @param aAccuracy - Amount to inflate the bounding box.
|
2008-01-06 12:43:57 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const;
|
2008-01-06 12:43:57 +00:00
|
|
|
|
2008-03-05 22:40:52 +00:00
|
|
|
/**
|
2009-05-07 17:10:53 +00:00
|
|
|
* Function LenSize
|
2009-11-23 20:18:47 +00:00
|
|
|
* @return the text length in internal units
|
2009-05-07 17:10:53 +00:00
|
|
|
* @param aLine : the line of text to consider.
|
|
|
|
* For single line text, this parameter is always m_Text
|
2007-10-31 17:47:44 +00:00
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
int LenSize( const wxString& aLine ) const;
|
2009-05-07 17:10:53 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetTextBox
|
2009-11-23 20:18:47 +00:00
|
|
|
* useful in multiline texts to calculate the full text or a line area (for
|
|
|
|
* zones filling, locate functions....)
|
|
|
|
* @return the rect containing the line of text (i.e. the position and the
|
2011-12-01 16:49:28 +00:00
|
|
|
* size of one line) this rectangle is calculated for 0 orient text.
|
|
|
|
* If orientation is not 0 the rect must be rotated to match the
|
|
|
|
* physical area
|
|
|
|
* @param aLine The line of text to consider.
|
2009-05-07 17:10:53 +00:00
|
|
|
* for single line text, aLine is unused
|
|
|
|
* If aLine == -1, the full area (considering all lines) is returned
|
2011-12-01 16:49:28 +00:00
|
|
|
* @param aThickness Overrides the current thickness when greater than 0.
|
|
|
|
* @param aInvertY Invert the Y axis when calculating bounding box.
|
2009-05-07 17:10:53 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false ) const;
|
2009-05-30 16:06:01 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetInterline
|
2009-05-07 17:10:53 +00:00
|
|
|
* return the distance between 2 text lines
|
|
|
|
* has meaning only for multiline texts
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
int GetInterline() const
|
2009-05-07 17:10:53 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
return (( m_Size.y * 14 ) / 10) + m_Thickness;
|
2009-05-07 17:10:53 +00:00
|
|
|
}
|
2010-11-17 18:41:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetTextStyleName
|
2011-10-21 18:17:51 +00:00
|
|
|
* @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic)
|
2010-11-17 18:41:20 +00:00
|
|
|
*/
|
|
|
|
wxString GetTextStyleName();
|
2010-12-31 19:47:39 +00:00
|
|
|
|
|
|
|
void SetText( const wxString& aText ) { m_Text = aText; }
|
|
|
|
|
2011-10-21 18:17:51 +00:00
|
|
|
/**
|
|
|
|
* Function GetText
|
|
|
|
* returns the string associated with the text object.
|
|
|
|
* <p>
|
|
|
|
* This function is virtual to allow derived classes to override getting the
|
|
|
|
* string to provide a way for modifying the base string by adding a suffix or
|
|
|
|
* prefix to the base string.
|
|
|
|
* </p>
|
2011-11-30 21:15:56 +00:00
|
|
|
* @return a const wxString object containing the string of the item.
|
2011-10-21 18:17:51 +00:00
|
|
|
*/
|
2011-11-30 21:15:56 +00:00
|
|
|
virtual const wxString GetText() const { return m_Text; }
|
2011-07-04 21:32:49 +00:00
|
|
|
|
|
|
|
GRTextHorizJustifyType GetHorizJustify() const { return m_HJustify; };
|
|
|
|
GRTextVertJustifyType GetVertJustify() const { return m_VJustify; };
|
|
|
|
void SetHorizJustify( GRTextHorizJustifyType aType ) { m_HJustify = aType; };
|
|
|
|
void SetVertJustify( GRTextVertJustifyType aType ) { m_VJustify = aType; };
|
2007-06-05 12:10:51 +00:00
|
|
|
};
|
|
|
|
|
2011-11-30 21:15:56 +00:00
|
|
|
#endif // BASE_STRUCT_H_
|