class_drawsegment.h 9.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * 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
 */

26 27 28 29
/**
 * @file class_drawsegment.h
 * @brief Class to handle a graphic segment.
 */
30

31 32
#ifndef CLASS_DRAWSEGMENT_H_
#define CLASS_DRAWSEGMENT_H_
33

34

35 36
#include <class_board_item.h>
#include <PolyLine.h>
37 38 39 40 41


class LINE_READER;
class EDA_DRAW_FRAME;
class MODULE;
42

43

44 45
class DRAWSEGMENT : public BOARD_ITEM
{
Dick Hollenbeck's avatar
Dick Hollenbeck committed
46 47 48 49
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
50

Dick Hollenbeck's avatar
Dick Hollenbeck committed
51 52 53 54 55
    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
56

57 58
    std::vector<wxPoint>    m_BezierPoints;
    std::vector<wxPoint>    m_PolyPoints;
59

60
public:
Dick Hollenbeck's avatar
Dick Hollenbeck committed
61
    DRAWSEGMENT( BOARD_ITEM* aParent = NULL, KICAD_T idtype = PCB_LINE_T );
62 63 64

    // Do not create a copy constructor.  The one generated by the compiler is adequate.

65 66
    ~DRAWSEGMENT();

Dick Hollenbeck's avatar
Dick Hollenbeck committed
67 68 69
    /// skip the linked list stuff, and parent
    const DRAWSEGMENT& operator = ( const DRAWSEGMENT& rhs );

70 71
    DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
    DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
72

Dick Hollenbeck's avatar
Dick Hollenbeck committed
73 74
    void SetWidth( int aWidth )             { m_Width = aWidth; }
    int GetWidth() const                    { return m_Width; }
75

76 77 78 79 80 81
    /**
     * 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
Dick Hollenbeck's avatar
Dick Hollenbeck committed
82
    double GetAngle() const { return m_Angle; }
83

Dick Hollenbeck's avatar
Dick Hollenbeck committed
84 85
    void SetType( int aType )               { m_Type = aType; }
    int GetType() const                     { return m_Type; }
86

Dick Hollenbeck's avatar
Dick Hollenbeck committed
87 88
    void SetShape( int aShape )             { m_Shape = aShape; }
    int GetShape() const                    { return m_Shape; }
89

Dick Hollenbeck's avatar
Dick Hollenbeck committed
90 91
    void SetBezControl1( const wxPoint& aPoint )    { m_BezierC1 = aPoint; }
    const wxPoint& GetBezControl1() const           { return m_BezierC1; }
92

Dick Hollenbeck's avatar
Dick Hollenbeck committed
93 94
    void SetBezControl2( const wxPoint& aPoint )    { m_BezierC2 = aPoint; }
    const wxPoint& GetBezControl2() const           { return m_BezierC2; }
95

Dick Hollenbeck's avatar
Dick Hollenbeck committed
96
    void SetPosition( const wxPoint& aPos ) { m_Start = aPos; }     // override
Dick Hollenbeck's avatar
Dick Hollenbeck committed
97
    const wxPoint& GetPosition() const      { return m_Start; }     // override
98

99 100 101 102
    /**
     * Function GetStart
     * returns the starting point of the graphic
     */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
103 104 105 106
    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; }
107 108 109 110 111

    /**
     * Function GetEnd
     * returns the ending point of the graphic
     */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
112 113 114 115 116 117 118 119 120 121 122
    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;
123

jean-pierre charras's avatar
jean-pierre charras committed
124 125 126 127 128
    /**
     * Function GetRadius
     * returns the radius of this item
     * Has meaning only for arc and circle
     */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
129
    int GetRadius() const
jean-pierre charras's avatar
jean-pierre charras committed
130 131
    {
        double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) );
132
        return wxRound( radius );
jean-pierre charras's avatar
jean-pierre charras committed
133 134
    }

135 136 137 138 139 140 141 142
    /**
     * 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;

Dick Hollenbeck's avatar
Dick Hollenbeck committed
143 144
    const std::vector<wxPoint>& GetBezierPoints() const { return m_BezierPoints; };
    const std::vector<wxPoint>& GetPolyPoints() const { return m_PolyPoints; };
145 146 147 148 149 150 151 152 153 154

    void SetBezierPoints( std::vector<wxPoint>& aPoints )
    {
        m_BezierPoints = aPoints;
    }

    void SetPolyPoints( std::vector<wxPoint>& aPoints )
    {
        m_PolyPoints = aPoints;
    }
155

156 157 158 159 160 161
    /**
     * 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.
     */
162
    bool         Save( FILE* aFile ) const;
163

164
    bool         ReadDrawSegmentDescr( LINE_READER* aReader );
165

166
    void         Copy( DRAWSEGMENT* source );
167

168
    void         Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
169
                       int aDrawMode, const wxPoint& aOffset = ZeroOffset );
dickelbeck's avatar
dickelbeck committed
170

171
    /**
172
     * Function DisplayInfo
173 174
     * has knowledge about the frame and how and where to put status information
     * about this object into the frame's message panel.
175
     * Is virtual from EDA_ITEM.
176
     * @param frame A PCB_BASE_FRAME in which to print status information.
177
     */
178
    virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
179

180 181 182 183 184 185 186 187 188
    /**
     * 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;

189 190 191
    /**
     * Function HitTest
     * tests if the given wxPoint is within the bounds of this object.
192
     * @param aRefPos A wxPoint to test
193 194
     * @return bool - true if a hit, else false
     */
195
    bool         HitTest( const wxPoint& aRefPos );
196 197 198

    /**
     * Function HitTest (overlayed)
199
     * tests if the given EDA_RECT intersect this object.
200
     * For now, an ending point must be inside this rect.
201
     * @param refArea the given EDA_RECT to test
202 203
     * @return bool - true if a hit, else false
     */
204
    bool         HitTest( EDA_RECT& refArea );
205 206 207 208 209 210 211 212 213 214

    /**
     * Function GetClass
     * returns the class name.
     * @return wxString
     */
    wxString GetClass() const
    {
        return wxT( "DRAWSEGMENT" );
    }
dickelbeck's avatar
dickelbeck committed
215

216 217 218 219 220 221 222 223 224
    /**
     * 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();

225
        return hypot( double( delta.x ), double( delta.y ) );
226 227
    }

228 229 230
    /**
     * Function Move
     * move this object.
231
     * @param aMoveVector - the move vector for this object.
232
     */
233
    virtual void Move( const wxPoint& aMoveVector )
234 235
    {
        m_Start += aMoveVector;
236
        m_End   += aMoveVector;
237 238 239 240 241
    }

    /**
     * Function Rotate
     * Rotate this object.
242
     * @param aRotCentre - the rotation point.
243 244
     * @param aAngle - the rotation angle in 0.1 degree.
     */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
245
    virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
246 247 248 249

    /**
     * Function Flip
     * Flip this object, i.e. change the board side for this object
250
     * @param aCentre - the rotation point.
251
     */
252 253
    virtual void Flip( const wxPoint& aCentre );

254 255
    /**
     * Function TransformShapeWithClearanceToPolygon
256 257 258 259 260 261 262
     * 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
263
     * clearance when the circle is approximated by segment bigger or equal
264 265
     * to the real clearance value (usually near from 1.0)
     */
266 267 268 269 270 271
    void TransformShapeWithClearanceToPolygon( std::vector <CPolyPt>& aCornerBuffer,
                                               int                    aClearanceValue,
                                               int                    aCircleToSegmentsCount,
                                               double                 aCorrectionFactor );

    virtual wxString GetSelectMenuText() const;
272

273
    virtual BITMAP_DEF GetMenuImage() const { return  add_dashed_line_xpm; }
274

dickelbeck's avatar
dickelbeck committed
275
#if defined(DEBUG)
276
    void Show( int nestLevel, std::ostream& os ) const;     // overload
277
#endif
278 279 280

private:
    virtual EDA_ITEM* doClone() const;
281 282
};

283
#endif  // CLASS_DRAWSEGMENT_H_