kicad/pcbnew/class_drawsegment.h

214 lines
6.5 KiB
C
Raw Normal View History

2008-01-16 18:48:04 +00:00
/*************************************/
/* class to handle a graphic segment */
/**************************************/
#ifndef CLASS_DRAWSEGMENT_H
#define CLASS_DRAWSEGMENT_H
#include "PolyLine.h"
#include "richio.h"
2008-01-16 18:48:04 +00:00
2008-01-16 18:48:04 +00:00
class DRAWSEGMENT : public BOARD_ITEM
{
public:
2008-12-23 13:14:01 +00:00
int m_Width; // thickness of lines ...
wxPoint m_Start; // Line start point or Circle and Arc center
wxPoint m_End; // Line end point or circle and arc start point
2008-01-16 18:48:04 +00:00
int m_Shape; // Shape: line, Circle, Arc
int m_Type; // Used in complex associations ( Dimensions.. )
int m_Angle; // Used only for Arcs: Arc angle in 1/10 deg
wxPoint m_BezierC1; // Bezier Control Point 1
wxPoint m_BezierC2; // Bezier Control Point 1
2008-01-16 18:48:04 +00:00
protected:
2009-06-25 20:45:27 +00:00
std::vector<wxPoint> m_BezierPoints;
std::vector<wxPoint> m_PolyPoints;
2008-01-16 18:48:04 +00:00
public:
DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype = TYPE_DRAWSEGMENT );
2008-01-16 18:48:04 +00:00
~DRAWSEGMENT();
DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
2008-01-16 18:48:04 +00:00
/**
* Function GetPosition
* returns the position of this object.
* Required by pure virtual BOARD_ITEM::GetPosition()
* @return const wxPoint& - The position of this object.
*/
wxPoint& GetPosition()
{
return m_Start;
}
/**
* Function GetStart
* returns the starting point of the graphic
*/
wxPoint GetStart() const;
/**
* Function GetEnd
* returns the ending point of the graphic
*/
wxPoint GetEnd() const;
/**
* Function GetRadius
* returns the radius of this item
* Has meaning only for arc and circle
*/
int GetRadius() const
{
double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) );
return wxRound( radius );
}
/**
* Function GetParentModule
* returns a pointer to the parent module, or NULL if DRAWSEGMENT does not
* belong to a module.
* @return MODULE* - pointer to the parent module or NULL.
*/
MODULE* GetParentModule() const;
std::vector<wxPoint>& GetBezierPoints() { return m_BezierPoints; };
std::vector<wxPoint>& GetPolyPoints() { return m_PolyPoints; };
2008-01-16 18:48:04 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
2008-01-16 18:48:04 +00:00
bool ReadDrawSegmentDescr( LINE_READER* aReader );
2008-01-16 18:48:04 +00:00
void Copy( DRAWSEGMENT* source );
2008-01-16 18:48:04 +00:00
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
int aDrawMode, const wxPoint& aOffset = ZeroOffset );
2008-04-01 06:07:00 +00:00
2008-01-16 18:48:04 +00:00
/**
* Function DisplayInfo
2008-01-16 18:48:04 +00:00
* has knowledge about the frame and how and where to put status information
* about this object into the frame's message panel.
* Is virtual from EDA_ITEM.
* @param frame A PCB_BASE_FRAME in which to print status information.
2008-01-16 18:48:04 +00:00
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
2008-01-16 18:48:04 +00:00
/**
* Function GetBoundingBox
* returns the orthogonal, bounding box of this object for display purposes.
* This box should be an enclosing perimeter for visible components of this
* object, and the units should be in the pcb or schematic coordinate system.
* It is OK to overestimate the size by a few counts.
*/
virtual EDA_RECT GetBoundingBox() const;
2008-01-16 18:48:04 +00:00
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
2010-12-29 17:47:32 +00:00
* @param aRefPos A wxPoint to test
2008-01-16 18:48:04 +00:00
* @return bool - true if a hit, else false
*/
2010-12-29 17:47:32 +00:00
bool HitTest( const wxPoint& aRefPos );
2008-01-16 18:48:04 +00:00
/**
* Function HitTest (overlayed)
* tests if the given EDA_RECT intersect this object.
2008-01-16 18:48:04 +00:00
* For now, an ending point must be inside this rect.
* @param refArea the given EDA_RECT to test
2008-01-16 18:48:04 +00:00
* @return bool - true if a hit, else false
*/
bool HitTest( EDA_RECT& refArea );
2008-01-16 18:48:04 +00:00
/**
* Function GetClass
* returns the class name.
* @return wxString
*/
wxString GetClass() const
{
return wxT( "DRAWSEGMENT" );
}
2008-01-22 20:36:46 +00:00
2008-04-01 06:07:00 +00:00
/**
* Function GetLength
* returns the length of the track using the hypotenuse calculation.
* @return double - the length of the track
*/
double GetLength() const
{
wxPoint delta = GetEnd() - GetStart();
return hypot( delta.x, delta.y );
}
2009-08-01 19:26:05 +00:00
/**
* Function Move
* move this object.
2010-12-29 17:47:32 +00:00
* @param aMoveVector - the move vector for this object.
2009-08-01 19:26:05 +00:00
*/
virtual void Move( const wxPoint& aMoveVector )
2009-08-01 19:26:05 +00:00
{
m_Start += aMoveVector;
m_End += aMoveVector;
2009-08-01 19:26:05 +00:00
}
2009-08-01 19:26:05 +00:00
/**
* Function Rotate
* Rotate this object.
2010-12-29 17:47:32 +00:00
* @param aRotCentre - the rotation point.
2009-08-01 19:26:05 +00:00
* @param aAngle - the rotation angle in 0.1 degree.
*/
virtual void Rotate( const wxPoint& aRotCentre, int aAngle );
2009-08-01 19:26:05 +00:00
/**
* Function Flip
* Flip this object, i.e. change the board side for this object
2010-12-29 17:47:32 +00:00
* @param aCentre - the rotation point.
2009-08-01 19:26:05 +00:00
*/
virtual void Flip( const wxPoint& aCentre );
2010-11-12 15:17:10 +00:00
/**
* Function TransformShapeWithClearanceToPolygon
* Convert the track shape to a closed polygon
* Used in filling zones calculations
* Circles and arcs are approximated by segments
* @param aCornerBuffer = a buffer to store the polygon
* @param aClearanceValue = the clearance around the pad
* @param aCircleToSegmentsCount = the number of segments to approximate a circle
* @param aCorrectionFactor = the correction to apply to circles radius to keep
* clearance when the circle is approximated by segment bigger or equal
* to the real clearance value (usually near from 1.0)
*/
void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
int aClearanceValue,
int aCircleToSegmentsCount,
double aCorrectionFactor );
virtual wxString GetSelectMenuText() const;
virtual const char** GetMenuImage() const { return (const char**) add_dashed_line_xpm; }
2008-04-01 06:07:00 +00:00
#if defined(DEBUG)
2008-01-22 20:36:46 +00:00
void Show( int nestLevel, std::ostream& os );
2008-04-01 06:07:00 +00:00
#endif
2008-01-16 18:48:04 +00:00
};
#endif // #ifndef CLASS_DRAWSEGMENT_H