File: array_options.h

package info (click to toggle)
kicad 9.0.7%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 771,448 kB
  • sloc: cpp: 969,355; ansic: 121,001; xml: 66,428; python: 18,387; sh: 1,010; awk: 301; asm: 292; makefile: 228; javascript: 167; perl: 10
file content (207 lines) | stat: -rw-r--r-- 6,059 bytes parent folder | download | duplicates (4)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright The 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
 */

#ifndef PCBNEW_ARRAY_OPTIONS__H
#define PCBNEW_ARRAY_OPTIONS__H

#include <kicommon.h>
#include <math/vector2d.h>
#include <array_axis.h>
#include <geometry/eda_angle.h>

/**
 * Options that govern the setup of an "array" of multiple item.
 *
 * The base #ARRAY_OPTIONS do not encode a specific geometry or numbering
 * method, this is done by derived classes.
 */
class KICOMMON_API ARRAY_OPTIONS
{
public:
    enum ARRAY_TYPE_T
    {
        ARRAY_GRID,     ///< A grid (x*y) array
        ARRAY_CIRCULAR, ///< A circular array
    };

    ARRAY_OPTIONS( ARRAY_TYPE_T aType ) :
        m_type( aType ),
        m_shouldNumber( false ),
        m_reannotateFootprints( false ),
        m_numberingStartIsSpecified( false )
    {
    }

    virtual ~ARRAY_OPTIONS(){};

    /**
     * Transform applied to an object by this array.
     */
    struct TRANSFORM
    {
        VECTOR2I  m_offset;
        EDA_ANGLE m_rotation;
    };

    /**
     * Get the transform of the n-th point in the array.
     *
     * @param  aN the index of the array point (0 is the original point).
     * @param  aPos the existing item position.
     * @return a transform (an offset and a rotation)/
     */
    virtual TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const = 0;

    /**
     * The number of points in this array.
     */
    virtual int GetArraySize() const = 0;

    /**
     * Get the position number (name) for the n'th array point.
     *
     * @param  n array point index, from 0 to GetArraySize() - 1.
     * @return the point's name.
     */
    virtual wxString GetItemNumber( int n ) const = 0;

    /**
     * @return are the items in this array numbered, or are all the items numbered the same?
     */
    bool ShouldNumberItems() const
    {
        return m_shouldNumber;
    }

    void SetShouldNumber( bool aShouldNumber )
    {
        m_shouldNumber = aShouldNumber;
    }

    /**
     * @return are the footprints in this array reannotated to be unique (true), or do they
     * keep the original annotation (false)?
     */
    bool ShouldReannotateFootprints() const
    {
        return m_reannotateFootprints;
    }

    void SetSShouldReannotateFootprints( bool aShouldReannotate )
    {
        m_reannotateFootprints = aShouldReannotate;
    }

    /**
     * @return is the numbering is enabled and should start at a point
     * specified in these options or is it implicit according to the calling
     * code?
     */
    bool GetNumberingStartIsSpecified() const
    {
        return m_shouldNumber && m_numberingStartIsSpecified;
    }

    void SetNumberingStartIsSpecified( bool aIsSpecified )
    {
        m_numberingStartIsSpecified = aIsSpecified;
    }

protected:

    ARRAY_TYPE_T m_type;

    /// True if this array numbers the new items
    bool m_shouldNumber;

    /// True if this array will rename any footprints to be unique
    bool m_reannotateFootprints;

    /// True if this array's number starts from the preset point
    /// False if the array numbering starts from some externally provided point
    bool m_numberingStartIsSpecified;
};


struct KICOMMON_API ARRAY_GRID_OPTIONS : public ARRAY_OPTIONS
{
    ARRAY_GRID_OPTIONS()
            : ARRAY_OPTIONS( ARRAY_GRID ),
              m_centred( false ),
              m_nx( 0 ),
              m_ny( 0 ),
              m_horizontalThenVertical( true ),
              m_reverseNumberingAlternate( false ),
              m_stagger( 0 ),
              m_stagger_rows( true ),
              m_2dArrayNumbering( false )
    {
    }

    // Are the grid positions relative to item (0, 0), or the grid center?
    bool             m_centred;
    long             m_nx, m_ny;
    bool             m_horizontalThenVertical, m_reverseNumberingAlternate;
    VECTOR2I         m_delta;
    VECTOR2I         m_offset;
    long             m_stagger;
    bool             m_stagger_rows;
    bool             m_2dArrayNumbering;
    ARRAY_AXIS       m_pri_axis, m_sec_axis;

    TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const override;
    int       GetArraySize() const override;
    wxString  GetItemNumber( int n ) const override;

private:
    VECTOR2I gtItemPosRelativeToItem0( int n ) const;
    VECTOR2I getGridCoords( int n ) const;
};


struct KICOMMON_API ARRAY_CIRCULAR_OPTIONS : public ARRAY_OPTIONS
{
    ARRAY_CIRCULAR_OPTIONS()
            : ARRAY_OPTIONS( ARRAY_CIRCULAR ),
              m_nPts( 0 ),
              m_angle( ANGLE_0 ),
              m_rotateItems( false )
    {
    }

    /// number of point in the array
    long             m_nPts;

    /// angle between points, or 0 for each point separated by this value (decideg)
    EDA_ANGLE        m_angle;
    VECTOR2I         m_centre;
    bool             m_rotateItems;
    ARRAY_AXIS       m_axis;

    TRANSFORM GetTransform( int aN, const VECTOR2I& aPos ) const override;
    int       GetArraySize() const override;
    wxString  GetItemNumber( int n ) const override;
};


#endif // PCBNEW_ARRAY_OPTIONS__H