class_drawsegment.h 5.09 KB
Newer Older
1 2 3 4 5 6
/*************************************/
/* class to handle a graphic segment */
/**************************************/

#ifndef CLASS_DRAWSEGMENT_H
#define CLASS_DRAWSEGMENT_H
7
#include "PolyLine.h"
8 9 10 11

class DRAWSEGMENT : public BOARD_ITEM
{
public:
12
    int     m_Width;            // thickness of lines ...
13 14 15 16 17 18
    wxPoint m_Start;            // Line start point
    wxPoint m_End;              // Line end point

    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
19 20
    wxPoint m_BezierC1;         // Bezier Control Point 1
    wxPoint m_BezierC2;         // Bezier Control Point 1
21

charras's avatar
charras committed
22
    std::vector<wxPoint> m_BezierPoints;
23
public:
24
    DRAWSEGMENT( BOARD_ITEM* aParent, KICAD_T idtype = TYPE_DRAWSEGMENT );
25 26
    ~DRAWSEGMENT();

27 28
    DRAWSEGMENT* Next() const { return (DRAWSEGMENT*) Pnext; }
    DRAWSEGMENT* Back() const { return (DRAWSEGMENT*) Pback; }
29 30 31 32 33 34 35 36 37 38 39 40 41

    /**
     * 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;
    }


42 43 44 45
    /**
     * Function GetStart
     * returns the starting point of the graphic
     */
46
    wxPoint      GetStart() const;
47 48 49 50 51

    /**
     * Function GetEnd
     * returns the ending point of the graphic
     */
52
    wxPoint      GetEnd() const;
53

54 55 56 57 58 59
    /**
     * 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.
     */
60
    bool         Save( FILE* aFile ) const;
61

62
    bool         ReadDrawSegmentDescr( FILE* File, int* LineNum );
63

64
    void         Copy( DRAWSEGMENT* source );
65 66


67 68
    void         Draw( WinEDA_DrawPanel* panel, wxDC* DC,
                       int aDrawMode, const wxPoint& offset = ZeroOffset );
dickelbeck's avatar
dickelbeck committed
69

70
    /**
71
     * Function DisplayInfo
72 73 74 75 76
     * 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_BaseStruct.
     * @param frame A WinEDA_BasePcbFrame in which to print status information.
     */
77
    virtual void DisplayInfo( WinEDA_DrawFrame* frame );
78 79 80 81 82 83 84 85


    /**
     * Function HitTest
     * tests if the given wxPoint is within the bounds of this object.
     * @param ref_pos A wxPoint to test
     * @return bool - true if a hit, else false
     */
86
    bool         HitTest( const wxPoint& ref_pos );
87 88 89 90 91 92 93 94

    /**
     * Function HitTest (overlayed)
     * tests if the given EDA_Rect intersect this object.
     * For now, an ending point must be inside this rect.
     * @param refPos the given EDA_Rect to test
     * @return bool - true if a hit, else false
     */
95
    bool         HitTest( EDA_Rect& refArea );
96 97 98 99 100 101 102 103 104 105

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

dickelbeck's avatar
dickelbeck committed
107

108 109 110 111 112 113 114 115 116 117 118 119
    /**
     * 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 );
    }

120

121 122 123 124 125
    /**
     * Function Move
     * move this object.
     * @param const wxPoint& aMoveVector - the move vector for this object.
     */
126
    virtual void Move( const wxPoint& aMoveVector )
127 128
    {
        m_Start += aMoveVector;
129
        m_End   += aMoveVector;
130 131
    }

132

133 134 135 136 137 138
    /**
     * Function Rotate
     * Rotate this object.
     * @param const wxPoint& aRotCentre - the rotation point.
     * @param aAngle - the rotation angle in 0.1 degree.
     */
139
    virtual void Rotate( const wxPoint& aRotCentre, int aAngle );
140 141 142 143 144 145

    /**
     * Function Flip
     * Flip this object, i.e. change the board side for this object
     * @param const wxPoint& aCentre - the rotation point.
     */
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    virtual void Flip( const wxPoint& aCentre );

    /** 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 approxiamted 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 );
165

dickelbeck's avatar
dickelbeck committed
166
#if defined(DEBUG)
dickelbeck's avatar
dickelbeck committed
167
    void Show( int nestLevel, std::ostream& os );
dickelbeck's avatar
dickelbeck committed
168

169
#endif
170 171 172 173
};


#endif      // #ifndef CLASS_DRAWSEGMENT_H