2011-10-19 20:32:21 +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-10-11 13:38:13 +00:00
|
|
|
/**
|
|
|
|
* @file sch_item_struct.h
|
|
|
|
* @brief Base schematic object class definition.
|
|
|
|
*/
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
#ifndef SCH_ITEM_STRUCT_H
|
|
|
|
#define SCH_ITEM_STRUCT_H
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <class_base_screen.h>
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
class SCH_ITEM;
|
2011-10-11 13:38:13 +00:00
|
|
|
class SCH_SHEET_PATH;
|
2010-11-10 15:30:12 +00:00
|
|
|
class LINE_READER;
|
2010-12-08 20:12:46 +00:00
|
|
|
class SCH_EDIT_FRAME;
|
2010-03-16 18:22:59 +00:00
|
|
|
class wxFindReplaceData;
|
2011-06-17 13:24:22 +00:00
|
|
|
class PLOTTER;
|
2011-10-11 13:38:13 +00:00
|
|
|
class NETLIST_OBJECT;
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-01-11 20:34:29 +00:00
|
|
|
typedef boost::ptr_vector< SCH_ITEM > SCH_ITEMS;
|
2011-01-20 16:34:57 +00:00
|
|
|
typedef SCH_ITEMS::iterator SCH_ITEMS_ITR;
|
|
|
|
typedef vector< SCH_ITEMS_ITR > SCH_ITEMS_ITRS;
|
2011-01-11 20:34:29 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/* used to calculate the pen size from default value
|
|
|
|
* the actual pen size is default value * BUS_WIDTH_EXPAND
|
|
|
|
*/
|
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
#define BUS_WIDTH_EXPAND 3.6
|
|
|
|
#else
|
|
|
|
#define BUS_WIDTH_EXPAND 1.4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
enum DANGLING_END_T {
|
|
|
|
UNKNOWN = 0,
|
|
|
|
WIRE_START_END,
|
|
|
|
WIRE_END_END,
|
|
|
|
BUS_START_END,
|
|
|
|
BUS_END_END,
|
|
|
|
JUNCTION_END,
|
|
|
|
PIN_END,
|
|
|
|
LABEL_END,
|
|
|
|
ENTRY_END,
|
|
|
|
SHEET_LABEL_END
|
|
|
|
};
|
|
|
|
|
|
|
|
// A helper class to store a list of items that can be connected to something:
|
|
|
|
class DANGLING_END_ITEM
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const void* m_Item; // a pointer to the parent
|
|
|
|
wxPoint m_Pos; // the position of the connecting point
|
|
|
|
DANGLING_END_T m_Type; // type of parent
|
|
|
|
|
|
|
|
DANGLING_END_ITEM( DANGLING_END_T type, const void* aItem )
|
|
|
|
{
|
|
|
|
m_Item = aItem;
|
|
|
|
m_Type = type;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Class SCH_ITEM
|
|
|
|
* is a base class for any item which can be embedded within the SCHEMATIC
|
|
|
|
* container class, and therefore instances of derived classes should only be
|
|
|
|
* found in EESCHEMA or other programs that use class SCHEMATIC and its contents.
|
2011-09-30 18:15:37 +00:00
|
|
|
* The corresponding class in Pcbnew is BOARD_ITEM.
|
2008-04-14 19:22:48 +00:00
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
class SCH_ITEM : public EDA_ITEM
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
int m_Layer;
|
2010-11-03 14:13:15 +00:00
|
|
|
EDA_ITEMS m_connections; ///< List of items connected to this item.
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
public:
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_ITEM( EDA_ITEM* aParent, KICAD_T aType );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_ITEM( const SCH_ITEM& aItem );
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
~SCH_ITEM();
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
virtual wxString GetClass() const
|
|
|
|
{
|
|
|
|
return wxT( "SCH_ITEM" );
|
|
|
|
}
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_ITEM* Clone() const { return ( SCH_ITEM* ) EDA_ITEM::Clone(); }
|
|
|
|
|
2011-04-05 14:46:51 +00:00
|
|
|
/**
|
|
|
|
* Function SwapDate
|
|
|
|
* swap the internal data structures \a aItem with the schematic item.
|
2011-06-09 13:30:46 +00:00
|
|
|
* Obviously, aItem must have the same type than me
|
2011-04-05 14:46:51 +00:00
|
|
|
* @param aItem The item to swap the data structures with.
|
|
|
|
*/
|
|
|
|
virtual void SwapData( SCH_ITEM* aItem );
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM* Next() { return (SCH_ITEM*) Pnext; }
|
2010-03-16 18:22:59 +00:00
|
|
|
SCH_ITEM* Back() { return (SCH_ITEM*) Pback; }
|
2008-04-14 19:22:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetLayer
|
|
|
|
* returns the layer this item is on.
|
|
|
|
*/
|
|
|
|
int GetLayer() const { return m_Layer; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetLayer
|
|
|
|
* sets the layer this item is on.
|
|
|
|
* @param aLayer The layer number.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
void SetLayer( int aLayer ) { m_Layer = aLayer; }
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function GetPenSize virtual pure
|
2009-06-30 19:21:41 +00:00
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
virtual int GetPenSize() const { return 0; }
|
2009-06-30 19:21:41 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
virtual void Draw( EDA_DRAW_PANEL* aPanel,
|
|
|
|
wxDC* aDC,
|
|
|
|
const wxPoint& aOffset,
|
|
|
|
int aDrawMode,
|
|
|
|
int aColor = -1 ) = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
/**
|
|
|
|
* Function Place
|
|
|
|
* place the schematic item into the draw list.
|
|
|
|
* <p>
|
|
|
|
* If the schematic item is a new item or is modified, it is added to undo list.
|
|
|
|
* </p>
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
virtual void Place( SCH_EDIT_FRAME* aFrame, wxDC* aDC );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function Move
|
|
|
|
* moves the item by \a aMoveVector to a new position.
|
2011-03-25 19:16:05 +00:00
|
|
|
* @param aMoveVector = the displacement vector
|
2009-07-27 14:32:40 +00:00
|
|
|
*/
|
2010-11-03 14:13:15 +00:00
|
|
|
virtual void Move( const wxPoint& aMoveVector ) = 0;
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
/**
|
|
|
|
* Function Mirror_Y
|
|
|
|
* mirrors item relative to an Y axis about \a aYaxis_position.
|
|
|
|
* @param aYaxis_position The Y axis position to mirror around.
|
2009-07-27 14:32:40 +00:00
|
|
|
*/
|
2010-11-03 14:13:15 +00:00
|
|
|
virtual void Mirror_Y( int aYaxis_position ) = 0;
|
2010-12-21 15:13:09 +00:00
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
virtual void Mirror_X( int aXaxis_position ) = 0;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
virtual void Rotate( wxPoint rotationPoint ) = 0;
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
2010-12-21 15:13:09 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
virtual bool Save( FILE* aFile ) const = 0;
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function Load
|
|
|
|
* reads a schematic item from \a aLine in a .sch file.
|
2010-11-10 15:30:12 +00:00
|
|
|
*
|
|
|
|
* @param aLine - Essentially this is file to read the object from.
|
|
|
|
* @param aErrorMsg - Description of the error if an error occurs while loading the object.
|
|
|
|
* @return True if the object loaded successfully.
|
|
|
|
*/
|
|
|
|
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) { return false; }
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function GetEndPoints
|
|
|
|
* adds the schematic item end points to \a aItemList if the item has end points.
|
2010-11-03 14:13:15 +00:00
|
|
|
*
|
|
|
|
* The default version doesn't do anything since many of the schematic object cannot
|
|
|
|
* be tested for dangling ends. If you add a new schematic item that can have a
|
|
|
|
* dangling end ( no connect ), override this method to provide the correct end
|
|
|
|
* points.
|
|
|
|
*
|
|
|
|
* @param aItemList - List of DANGLING_END_ITEMS to add to.
|
|
|
|
*/
|
|
|
|
virtual void GetEndPoints( vector< DANGLING_END_ITEM >& aItemList ) {}
|
|
|
|
|
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function IsDanglingStateChanged
|
|
|
|
* tests the schematic item to \a aItemList to check if it's dangling state has changed.
|
2010-11-03 14:13:15 +00:00
|
|
|
*
|
|
|
|
* Note that the return value only true when the state of the test has changed. Use
|
|
|
|
* the IsDangling() method to get the current dangling state of the item. Some of
|
|
|
|
* the schematic objects cannot be tested for a dangling state, the default method
|
|
|
|
* always returns false. Only override the method if the item can be tested for a
|
|
|
|
* dangling state.
|
|
|
|
*
|
|
|
|
* @param aItemList - List of items to test item against.
|
|
|
|
* @return True if the dangling state has changed from it's current setting.
|
|
|
|
*/
|
|
|
|
virtual bool IsDanglingStateChanged( vector< DANGLING_END_ITEM >& aItemList ) { return false; }
|
|
|
|
|
|
|
|
virtual bool IsDangling() const { return false; }
|
|
|
|
|
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function IsSelectStateChanged
|
|
|
|
* checks if the selection state of an item inside \a aRect has changed.
|
2010-11-03 14:13:15 +00:00
|
|
|
*
|
2010-12-21 15:13:09 +00:00
|
|
|
* This is used by the block selection code to verify if an item is selected or not.
|
2010-11-03 14:13:15 +00:00
|
|
|
* True is be return anytime the select state changes. If you need to know the
|
|
|
|
* the current selection state, use the IsSelected() method.
|
|
|
|
*
|
2011-03-25 19:16:05 +00:00
|
|
|
* @param aRect - Rectangle to test against.
|
2010-11-03 14:13:15 +00:00
|
|
|
*/
|
|
|
|
virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
/**
|
|
|
|
* Function IsConnectable
|
|
|
|
* returns true if the schematic item can connect to another schematic item.
|
|
|
|
*/
|
|
|
|
virtual bool IsConnectable() const { return false; }
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function GetConnectionPoints
|
|
|
|
* add all the connection points for this item to \a aPoints.
|
2010-11-03 14:13:15 +00:00
|
|
|
*
|
|
|
|
* Not all schematic items have connection points so the default method does nothing.
|
|
|
|
*
|
2010-12-21 15:13:09 +00:00
|
|
|
* @param aPoints List of connection points to add to.
|
2010-11-03 14:13:15 +00:00
|
|
|
*/
|
|
|
|
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const { }
|
|
|
|
|
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function ClearConnections
|
|
|
|
* clears all of the connection items from the list.
|
2010-11-03 14:13:15 +00:00
|
|
|
*
|
|
|
|
* The vector release method is used to prevent the item pointers from being deleted.
|
|
|
|
* Do not use the vector erase method on the connection list.
|
|
|
|
*/
|
2011-03-25 19:16:05 +00:00
|
|
|
void ClearConnections() { m_connections.clear(); }
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2010-12-13 15:59:00 +00:00
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function IsConnected
|
|
|
|
* tests the item to see if it is connected to \a aPoint.
|
2010-12-13 15:59:00 +00:00
|
|
|
*
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aPoint - Position to test for connection.
|
|
|
|
* @return True if connection to \a aPoint exists.
|
2010-12-13 15:59:00 +00:00
|
|
|
*/
|
|
|
|
bool IsConnected( const wxPoint& aPoint ) const;
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
virtual bool HitTest( const wxPoint& aPosition ) { return HitTest( aPosition, 0 ); }
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function HitTest
|
|
|
|
* tests if \a aPoint is contained within or on the bounding box of an item.
|
2010-12-10 19:47:44 +00:00
|
|
|
*
|
|
|
|
* @param aPoint - Point to test.
|
|
|
|
* @param aAccuracy - Increase the item bounding box by this amount.
|
2011-03-25 19:16:05 +00:00
|
|
|
* @return True if \a aPoint is within the item bounding box.
|
2010-12-10 19:47:44 +00:00
|
|
|
*/
|
2011-03-25 19:16:05 +00:00
|
|
|
bool HitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
return doHitTest( aPoint, aAccuracy );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-12-21 15:13:09 +00:00
|
|
|
* Function HitTest
|
|
|
|
* tests if \a aRect intersects or is contained within the bounding box of an item.
|
2010-12-10 19:47:44 +00:00
|
|
|
*
|
|
|
|
* @param aRect - Rectangle to test.
|
|
|
|
* @param aContained - Set to true to test for containment instead of an intersection.
|
2010-12-20 17:44:25 +00:00
|
|
|
* @param aAccuracy - Increase aRect by this amount.
|
2010-12-14 15:56:30 +00:00
|
|
|
* @return True if \a aRect contains or intersects the item bounding box.
|
2010-12-10 19:47:44 +00:00
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
bool HitTest( const EDA_RECT& aRect, bool aContained = false, int aAccuracy = 0 ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2010-12-21 15:13:09 +00:00
|
|
|
return doHitTest( aRect, aContained, aAccuracy );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 02:21:11 +00:00
|
|
|
virtual bool CanIncrementLabel() const { return false; }
|
|
|
|
|
2011-06-17 13:24:22 +00:00
|
|
|
void Plot( PLOTTER* aPlotter ) { doPlot( aPlotter ); }
|
|
|
|
|
2011-10-11 13:38:13 +00:00
|
|
|
/**
|
|
|
|
* Function GetNetListItem
|
|
|
|
* creates a new #NETLIST_OBJECT for the schematic object and adds it to
|
|
|
|
* \a aNetListItems.
|
|
|
|
* <p>
|
|
|
|
* Not all schematic objects have net list items associated with them. This
|
|
|
|
* method only needs to be overridden for those schematic objects that have
|
|
|
|
* net list objects associated with them.
|
|
|
|
*/
|
|
|
|
virtual void GetNetListItem( vector<NETLIST_OBJECT*>& aNetListItems,
|
|
|
|
SCH_SHEET_PATH* aSheetPath ) { }
|
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
/**
|
|
|
|
* Function GetPosition
|
|
|
|
* @return the schematic item position.
|
|
|
|
*/
|
|
|
|
wxPoint GetPosition() const { return doGetPosition(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function SetPosition
|
|
|
|
* set the schematic item position to \a aPosition.
|
|
|
|
*
|
|
|
|
* @param aPosition A reference to a wxPoint object containing the new position.
|
|
|
|
*/
|
|
|
|
void SetPosition( const wxPoint& aPosition ) { doSetPosition( aPosition ); }
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
virtual bool operator <( const SCH_ITEM& aItem ) const;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
/**
|
|
|
|
* @note - The DoXXX() functions below are used to enforce the interface while retaining
|
|
|
|
* the ability of change the implementation behavior of derived classes. See
|
|
|
|
* Herb Sutters explanation of virtuality as to why you might want to do this at:
|
|
|
|
* http://www.gotw.ca/publications/mill18.htm.
|
|
|
|
*/
|
|
|
|
private:
|
2011-03-25 19:16:05 +00:00
|
|
|
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-29 19:33:07 +00:00
|
|
|
virtual bool doHitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-12-13 15:59:00 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
virtual bool doIsConnected( const wxPoint& aPosition ) const { return false; }
|
2011-06-17 13:24:22 +00:00
|
|
|
|
|
|
|
virtual void doPlot( PLOTTER* aPlotter );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
|
|
|
virtual wxPoint doGetPosition() const = 0;
|
|
|
|
|
|
|
|
virtual void doSetPosition( const wxPoint& aPosition ) = 0;
|
2008-04-14 19:22:48 +00:00
|
|
|
};
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
|
|
|
|
extern bool sort_schematic_items( const SCH_ITEM* aItem1, const SCH_ITEM* aItem2 );
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
#endif /* SCH_ITEM_STRUCT_H */
|