2012-01-14 19:50:32 +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) 2011 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.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-23 13:57:12 +00:00
|
|
|
/**
|
|
|
|
* @file class_drawsegment.h
|
|
|
|
* @brief Class to handle a graphic segment.
|
|
|
|
*/
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
#ifndef CLASS_DRAWSEGMENT_H_
|
|
|
|
#define CLASS_DRAWSEGMENT_H_
|
2011-08-01 15:29:27 +00:00
|
|
|
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board_item.h>
|
|
|
|
#include <PolyLine.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LINE_READER;
|
|
|
|
class EDA_DRAW_FRAME;
|
|
|
|
class MODULE;
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-08-01 15:29:27 +00:00
|
|
|
|
2008-01-16 18:48:04 +00:00
|
|
|
class DRAWSEGMENT : public BOARD_ITEM
|
|
|
|
{
|
2011-12-14 04:29:25 +00:00
|
|
|
protected:
|
|
|
|
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
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
int m_Shape; ///< Shape: line, Circle, Arc
|
|
|
|
int m_Type; ///< Used in complex associations ( Dimensions.. )
|
|
|
|
double 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
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
std::vector<wxPoint> m_BezierPoints;
|
|
|
|
std::vector<wxPoint> m_PolyPoints;
|
2011-08-08 23:50:55 +00:00
|
|
|
|
2008-01-16 18:48:04 +00:00
|
|
|
public:
|
2011-12-14 04:29:25 +00:00
|
|
|
DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
// Do not create a copy constructor. The one generated by the compiler is adequate.
|
|
|
|
|
2008-01-16 18:48:04 +00:00
|
|
|
~DRAWSEGMENT();
|
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
/// skip the linked list stuff, and parent
|
|
|
|
const DRAWSEGMENT& operator = ( const DRAWSEGMENT& rhs );
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
|
|
|
|
DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetWidth( int aWidth ) { m_Width = aWidth; }
|
|
|
|
int GetWidth() const { return m_Width; }
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2011-12-02 21:56:47 +00:00
|
|
|
/**
|
|
|
|
* Function SetAngle
|
|
|
|
* sets the angle for arcs, and normalizes it within the range 0 - 360 degrees.
|
|
|
|
* @param aAngle is tenths of degrees, but will soon be degrees.
|
|
|
|
*/
|
|
|
|
void SetAngle( double aAngle ); // encapsulates the transition to degrees
|
2011-12-12 08:37:05 +00:00
|
|
|
double GetAngle() const { return m_Angle; }
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetType( int aType ) { m_Type = aType; }
|
|
|
|
int GetType() const { return m_Type; }
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetShape( int aShape ) { m_Shape = aShape; }
|
|
|
|
int GetShape() const { return m_Shape; }
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetBezControl1( const wxPoint& aPoint ) { m_BezierC1 = aPoint; }
|
|
|
|
const wxPoint& GetBezControl1() const { return m_BezierC1; }
|
2011-11-29 03:08:14 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetBezControl2( const wxPoint& aPoint ) { m_BezierC2 = aPoint; }
|
|
|
|
const wxPoint& GetBezControl2() const { return m_BezierC2; }
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-12-14 04:29:25 +00:00
|
|
|
void SetPosition( const wxPoint& aPos ) { m_Start = aPos; } // override
|
2012-02-20 04:33:54 +00:00
|
|
|
const wxPoint& GetPosition() const { return m_Start; } // override
|
2011-11-29 17:25:30 +00:00
|
|
|
|
2008-05-05 19:46:54 +00:00
|
|
|
/**
|
|
|
|
* Function GetStart
|
|
|
|
* returns the starting point of the graphic
|
|
|
|
*/
|
2011-12-14 04:29:25 +00:00
|
|
|
const wxPoint& GetStart() const { return m_Start; }
|
|
|
|
void SetStart( const wxPoint& aStart ) { m_Start = aStart; }
|
|
|
|
void SetStartY( int y ) { m_Start.y = y; }
|
|
|
|
void SetStartX( int x ) { m_Start.x = x; }
|
2008-05-05 19:46:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function GetEnd
|
|
|
|
* returns the ending point of the graphic
|
|
|
|
*/
|
2011-12-14 04:29:25 +00:00
|
|
|
const wxPoint& GetEnd() const { return m_End; }
|
|
|
|
void SetEnd( const wxPoint& aEnd ) { m_End = aEnd; }
|
|
|
|
void SetEndY( int y ) { m_End.y = y; }
|
|
|
|
void SetEndX( int x ) { m_End.x = x; }
|
|
|
|
|
|
|
|
// Arc attributes are read only, since they are "calculated" from
|
|
|
|
// m_Start, m_End, and m_Angle. No Set...() functions.
|
|
|
|
|
|
|
|
const wxPoint& GetCenter() const { return m_Start; }
|
|
|
|
const wxPoint& GetArcStart() const { return m_End; }
|
|
|
|
const wxPoint GetArcEnd() const;
|
2008-05-05 19:46:54 +00:00
|
|
|
|
2011-02-27 19:54:01 +00:00
|
|
|
/**
|
|
|
|
* Function GetRadius
|
|
|
|
* returns the radius of this item
|
|
|
|
* Has meaning only for arc and circle
|
|
|
|
*/
|
2011-12-14 04:29:25 +00:00
|
|
|
int GetRadius() const
|
2011-02-27 19:54:01 +00:00
|
|
|
{
|
|
|
|
double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) );
|
2011-08-01 15:29:27 +00:00
|
|
|
return wxRound( radius );
|
2011-02-27 19:54:01 +00:00
|
|
|
}
|
|
|
|
|
2011-08-08 23:50:55 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
|
2011-12-12 08:37:05 +00:00
|
|
|
const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; };
|
|
|
|
const std::vector<wxPoint>& GetPolyPoints() const { return m_PolyPoints; };
|
2011-11-29 03:08:14 +00:00
|
|
|
|
|
|
|
void SetBezierPoints( std::vector<wxPoint>& aPoints )
|
|
|
|
{
|
|
|
|
m_BezierPoints = aPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetPolyPoints( std::vector<wxPoint>& aPoints )
|
|
|
|
{
|
|
|
|
m_PolyPoints = aPoints;
|
|
|
|
}
|
2011-08-08 23:50:55 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2009-11-16 08:13:40 +00:00
|
|
|
bool Save( FILE* aFile ) const;
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-01-14 17:43:30 +00:00
|
|
|
bool ReadDrawSegmentDescr( LINE_READER* aReader );
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2009-11-16 08:13:40 +00:00
|
|
|
void Copy( DRAWSEGMENT* source );
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
|
2010-11-11 21:46:55 +00:00
|
|
|
int aDrawMode, const wxPoint& aOffset = ZeroOffset );
|
2008-04-01 06:07:00 +00:00
|
|
|
|
2008-01-16 18:48:04 +00:00
|
|
|
/**
|
2009-04-17 08:51:02 +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.
|
2010-12-08 20:12:46 +00:00
|
|
|
* Is virtual from EDA_ITEM.
|
2011-03-01 19:26:17 +00:00
|
|
|
* @param frame A PCB_BASE_FRAME in which to print status information.
|
2008-01-16 18:48:04 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
|
2008-01-16 18:48:04 +00:00
|
|
|
|
2011-08-08 23:50:55 +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)
|
2011-03-29 19:33:07 +00:00
|
|
|
* 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.
|
2011-03-29 19:33:07 +00:00
|
|
|
* @param refArea the given EDA_RECT to test
|
2008-01-16 18:48:04 +00:00
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
2011-03-29 19:33:07 +00:00
|
|
|
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-05-05 19:46:54 +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();
|
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
return hypot( double( delta.x ), double( delta.y ) );
|
2008-05-05 19:46:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2009-11-16 08:13:40 +00:00
|
|
|
virtual void Move( const wxPoint& aMoveVector )
|
2009-08-01 19:26:05 +00:00
|
|
|
{
|
|
|
|
m_Start += aMoveVector;
|
2009-11-16 08:13:40 +00:00
|
|
|
m_End += aMoveVector;
|
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.
|
|
|
|
*/
|
2011-12-14 04:29:25 +00:00
|
|
|
virtual void Rotate( const wxPoint& aRotCentre, double 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
|
|
|
*/
|
2009-11-16 08:13:40 +00:00
|
|
|
virtual void Flip( const wxPoint& aCentre );
|
|
|
|
|
2010-11-12 15:17:10 +00:00
|
|
|
/**
|
|
|
|
* Function TransformShapeWithClearanceToPolygon
|
2009-11-16 08:13:40 +00:00
|
|
|
* 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
|
2011-08-01 15:29:27 +00:00
|
|
|
* clearance when the circle is approximated by segment bigger or equal
|
2009-11-16 08:13:40 +00:00
|
|
|
* to the real clearance value (usually near from 1.0)
|
|
|
|
*/
|
2011-07-14 15:42:44 +00:00
|
|
|
void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
|
|
|
|
int aClearanceValue,
|
|
|
|
int aCircleToSegmentsCount,
|
|
|
|
double aCorrectionFactor );
|
|
|
|
|
|
|
|
virtual wxString GetSelectMenuText() const;
|
2008-05-05 19:46:54 +00:00
|
|
|
|
2011-08-29 03:04:59 +00:00
|
|
|
virtual BITMAP_DEF GetMenuImage() const { return add_dashed_line_xpm; }
|
2011-08-01 15:29:27 +00:00
|
|
|
|
2008-04-01 06:07:00 +00:00
|
|
|
#if defined(DEBUG)
|
2011-12-14 17:25:42 +00:00
|
|
|
void Show( int nestLevel, std::ostream& os ) const; // overload
|
2009-11-16 08:13:40 +00:00
|
|
|
#endif
|
2012-01-14 19:50:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
virtual EDA_ITEM* doClone() const;
|
2008-01-16 18:48:04 +00:00
|
|
|
};
|
|
|
|
|
2011-11-29 03:08:14 +00:00
|
|
|
#endif // CLASS_DRAWSEGMENT_H_
|