lib_polyline.h 3.88 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 26 27
/*
 * 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) 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
 */

/**
 * @file lib_polyline.h
 */
28 29 30 31

#ifndef _LIB_POLYLINE_H_
#define _LIB_POLYLINE_H_

32
#include <lib_draw_item.h>
33 34


35
class LIB_POLYLINE : public LIB_ITEM
36
{
37 38 39 40
    int m_Width;                              // Line width
    std::vector<wxPoint> m_PolyPoints;        // list of points (>= 2)

    int m_ModifyIndex;                        // Index of the polyline point to modify
41

42
    void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
43
                      EDA_COLOR_T aColor, GR_DRAWMODE aDrawMode, void* aData,
44
                      const TRANSFORM& aTransform );
45 46 47

    void calcEdit( const wxPoint& aPosition );

48
public:
49
    LIB_POLYLINE( LIB_COMPONENT * aParent );
50 51 52

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

53 54
    ~LIB_POLYLINE() { }

55
    wxString GetClass() const
56 57 58 59 60
    {
        return wxT( "LIB_POLYLINE" );
    }


61
    bool Save( OUTPUTFORMATTER& aFormatter );
62

63
    bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
64 65 66

    void AddPoint( const wxPoint& aPoint );

67 68 69 70 71
    /**
     * Delete the segment at \a aPosition.
     */
    void DeleteSegment( const wxPoint aPosition );

72 73 74 75 76
    /**
     * @return the number of corners
     */
    unsigned GetCornerCount() const { return m_PolyPoints.size(); }

77
    bool HitTest( const wxPoint& aPosition );
78

79
    bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform );
80

81
    EDA_RECT GetBoundingBox() const;
82

83
    int GetPenSize( ) const;
84

85
    void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
86

87
    void BeginEdit( STATUS_FLAGS aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) );
88 89 90 91 92

    bool ContinueEdit( const wxPoint aNextPoint );

    void EndEdit( const wxPoint& aPosition, bool aAbort = false );

93
    void SetOffset( const wxPoint& aOffset );
94

95
    bool Inside( EDA_RECT& aRect ) const;
96

97
    void Move( const wxPoint& aPosition );
98

99
    wxPoint GetPosition() const { return m_PolyPoints[0]; }
100

101
    void MirrorHorizontal( const wxPoint& aCenter );
102

103
    void MirrorVertical( const wxPoint& aCenter );
104

105
    void Rotate( const wxPoint& aCenter, bool aRotateCCW = true );
106

107 108
    void Plot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
               const TRANSFORM& aTransform );
109

110
    int GetWidth() const { return m_Width; }
111

112
    void SetWidth( int aWidth ) { m_Width = aWidth; }
113

114
    wxString GetSelectMenuText() const;
115

116
    BITMAP_DEF GetMenuImage() const { return  add_polygon_xpm; }
117

118
    EDA_ITEM* Clone() const;
119

120
private:
121 122

    /**
123
     * @copydoc LIB_ITEM::compare()
124
     *
125
     * The sort order for specific to each polyline segment point is as follows:
126 127 128
     *      - Line segment point horizontal (X) position.
     *      - Line segment point vertical (Y) position.
     */
129
    int compare( const LIB_ITEM& aOther ) const;
130 131 132
};


133
#endif   // _LIB_POLYLINE_H_