class_track.h 15.5 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
/*
 * 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) 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
 */

25 26 27 28
/**
 * @file class_track.h
 * @brief Definitions for tracks, vias and zones.
 */
29 30 31 32

#ifndef CLASS_TRACK_H
#define CLASS_TRACK_H

33

34 35 36
#include <class_board_item.h>
#include <class_board_connected_item.h>
#include <PolyLine.h>
37
#include <trigo.h>
38 39


40
class TRACK;
41
class D_PAD;
42 43
class MSG_PANEL_ITEM;

44

45
// Via attributes (m_Shape parameter)
46 47 48 49 50 51 52
#define VIA_THROUGH                3       /* Always a through hole via */
#define VIA_BLIND_BURIED           2       /* this via can be on internal layers */
#define VIA_MICROVIA               1       /* this via which connect from an external layer
                                            * to the near neighbor internal layer */
#define VIA_NOT_DEFINED            0       /* not yet used */

#define UNDEFINED_DRILL_DIAMETER  -1       //< Undefined via drill diameter.
53

54
#define MIN_VIA_DRAW_SIZE          4       /// Minimum size in pixel for full drawing
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

/**
 * Function GetTrace
 * is a helper function to locate a trace segment having an end point at \a aPosition
 * on \a aLayerMask starting at \a aStartTrace and end at \a aEndTrace.
 * <p>
 * The segments of track that are flagged as deleted or busy are ignored.  Layer
 * visibility is also ignored.
 * </p>
 * @param aStartTrace A pointer to the TRACK object to begin searching.
 * @param aEndTrace A pointer to the TRACK object to stop the search.  A NULL value
 *                  searches to the end of the list.
 * @param aPosition A wxPoint object containing the position to test.
 * @param aLayerMask A layer or layers to mask the hit test.  Use -1 to ignore
 *                   layer mask.
 * @return A TRACK object pointer if found otherwise NULL.
 */
extern TRACK* GetTrace( TRACK* aStartTrace, TRACK* aEndTrace, const wxPoint& aPosition,
73
                        LAYER_MSK aLayerMask );
74

75

76
class TRACK : public BOARD_CONNECTED_ITEM
77
{
78 79 80
    // make SetNext() and SetBack() private so that they may not be called from anywhere.
    // list management is done on TRACKs using DLIST<TRACK> only.
private:
81 82
    void SetNext( EDA_ITEM* aNext )       { Pnext = aNext; }
    void SetBack( EDA_ITEM* aBack )       { Pback = aBack; }
83

84
protected:
85
    int         m_Width;            // Thickness of track, or via diameter
86 87 88 89
    wxPoint     m_Start;            // Line start point
    wxPoint     m_End;              // Line end point
    int         m_Shape;            // vias: shape and type, Track = shape..

dickelbeck's avatar
dickelbeck committed
90
    int         m_Drill;            // for vias: via drill (- 1 for default value)
91 92

public:
93 94
    BOARD_CONNECTED_ITEM* start;    // pointers to a connected item (pad or track)
    BOARD_CONNECTED_ITEM* end;
95

Dick Hollenbeck's avatar
Dick Hollenbeck committed
96
    double      m_Param;            // Auxiliary variable ( used in some computations )
97

98
    TRACK( BOARD_ITEM* aParent, KICAD_T idtype = PCB_TRACE_T );
99

100
    // Do not create a copy constructor.  The one generated by the compiler is adequate.
dickelbeck's avatar
dickelbeck committed
101

102 103
    TRACK* Next() const { return (TRACK*) Pnext; }
    TRACK* Back() const { return (TRACK*) Pback; }
dickelbeck's avatar
dickelbeck committed
104

105
    virtual void Move( const wxPoint& aMoveVector )
106 107
    {
        m_Start += aMoveVector;
Dick Hollenbeck's avatar
Dick Hollenbeck committed
108
        m_End   += aMoveVector;
109 110
    }

Dick Hollenbeck's avatar
Dick Hollenbeck committed
111
    virtual void Rotate( const wxPoint& aRotCentre, double aAngle );
112

113
    virtual void Flip( const wxPoint& aCentre );
114

Dick Hollenbeck's avatar
Dick Hollenbeck committed
115 116
    void SetPosition( const wxPoint& aPos )     { m_Start = aPos; }     // was overload
    const wxPoint& GetPosition() const          { return m_Start; }     // was overload
117

Dick Hollenbeck's avatar
Dick Hollenbeck committed
118 119
    void SetWidth( int aWidth )                 { m_Width = aWidth; }
    int GetWidth() const                        { return m_Width; }
120

Dick Hollenbeck's avatar
Dick Hollenbeck committed
121 122
    void SetEnd( const wxPoint& aEnd )          { m_End = aEnd; }
    const wxPoint& GetEnd() const               { return m_End; }
123

Dick Hollenbeck's avatar
Dick Hollenbeck committed
124 125
    void SetStart( const wxPoint& aStart )      { m_Start = aStart; }
    const wxPoint& GetStart() const             { return m_Start; }
126

127 128 129
    int GetShape() const                        { return m_Shape; }
    void SetShape( int aShape )                 { m_Shape = aShape; }

130 131
    // Virtual function
    const EDA_RECT GetBoundingBox() const;
dickelbeck's avatar
dickelbeck committed
132

dickelbeck's avatar
dickelbeck committed
133 134 135
    /**
     * Function GetBestInsertPoint
     * searches the "best" insertion point within the track linked list.
dickelbeck's avatar
dickelbeck committed
136 137
     * The best point is the begging of the corresponding net code section.
     * (The BOARD::m_Track and BOARD::m_Zone lists are sorted by netcode.)
138
     * @param aPcb The BOARD to search for the insertion point.
dickelbeck's avatar
dickelbeck committed
139 140
     * @return TRACK* - the item found in the linked list (or NULL if no track)
     */
141
    TRACK* GetBestInsertPoint( BOARD* aPcb );
dickelbeck's avatar
dickelbeck committed
142

CHARRAS's avatar
CHARRAS committed
143 144
    /* Search (within the track linked list) the first segment matching the netcode
     * ( the linked list is always sorted by net codes )
145
     */
146
    TRACK* GetStartNetCode( int NetCode );
dickelbeck's avatar
dickelbeck committed
147

CHARRAS's avatar
CHARRAS committed
148 149 150
    /* Search (within the track linked list) the last segment matching the netcode
     * ( the linked list is always sorted by net codes )
     */
151
    TRACK* GetEndNetCode( int NetCode );
dickelbeck's avatar
dickelbeck committed
152

153 154 155 156 157
    /**
     * Function GetLength
     * returns the length of the track using the hypotenuse calculation.
     * @return double - the length of the track
     */
158
    double GetLength() const
159
    {
160
        return GetLineLength( m_Start, m_End );
161
    }
162

dickelbeck's avatar
dickelbeck committed
163
    /* Display on screen: */
164 165
    void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
               GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
dickelbeck's avatar
dickelbeck committed
166

167 168
    /**
     * Function TransformShapeWithClearanceToPolygon
169 170 171 172 173 174 175
     * Convert the track shape to a closed polygon
     * Used in filling zones calculations
     * Circles (vias) and arcs (ends of tracks) 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
176
     * clearance when the circle is approximated by segment bigger or equal
177 178
     * to the real clearance value (usually near from 1.0)
     */
179 180 181 182
    void TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer,
                                               int             aClearanceValue,
                                               int             aCircleToSegmentsCount,
                                               double          aCorrectionFactor ) const;
dickelbeck's avatar
dickelbeck committed
183
    /**
184
     * Function SetDrill
185
     * sets the drill value for vias.
186
     * @param aDrill is the new drill diameter
dickelbeck's avatar
dickelbeck committed
187
    */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
    void SetDrill( int aDrill )             { m_Drill = aDrill; }

    /**
     * Function GetDrill
     * returns the local drill setting for this VIA.  If you want the calculated value,
     * use GetDrillValue() instead.
     */
    int GetDrill() const                    { return m_Drill; }

    /**
     * Function GetDrillValue
     * "calculates" the drill value for vias (m-Drill if > 0, or default
     * drill value for the board.
     * @return real drill_value
    */
    int GetDrillValue() const;
204

dickelbeck's avatar
dickelbeck committed
205
    /**
206
     * Function SetDrillDefault
207
     * sets the drill value for vias to the default value #UNDEFINED_DRILL_DIAMETER.
dickelbeck's avatar
dickelbeck committed
208
    */
209
    void SetDrillDefault()      { m_Drill = UNDEFINED_DRILL_DIAMETER; }
dickelbeck's avatar
dickelbeck committed
210 211

    /**
212
     * Function IsDrillDefault
dickelbeck's avatar
dickelbeck committed
213 214
     * @return true if the drill value is default value (-1)
    */
Dick Hollenbeck's avatar
Dick Hollenbeck committed
215
    bool IsDrillDefault()       { return m_Drill <= 0; }
dickelbeck's avatar
dickelbeck committed
216

217
    /**
218
     * Function GetLayerMask
219
     * returns a "layer mask", which is a bitmap of all layers on which the
220
     * TRACK segment or SEGVIA physically resides.
221
     * @return int - a layer mask, see pcbstruct.h's LAYER_BACK, etc.
222
     */
223
    LAYER_MSK GetLayerMask() const;
224

225 226 227 228 229 230 231
    /**
     * Function IsPointOnEnds
     * returns STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if
     * point if near (dist = min_dist) end point,STARTPOINT|ENDPOINT if point if near
     * (dist = min_dist) both ends, or 0 if none of the above.
     * if min_dist < 0: min_dist = track_width/2
     */
232
    STATUS_FLAGS IsPointOnEnds( const wxPoint& point, int min_dist = 0 );
233

234 235 236 237
    /**
     * Function IsNull
     * returns true if segment length is zero.
     */
238
    bool IsNull();
dickelbeck's avatar
dickelbeck committed
239

240
    void GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList );
241

242
    /**
243
     * Function GetMsgPanelInfoBase
244
     * Display info about the track segment only, and does not calculate the full track length
245
     * @param aList A list of #MSG_PANEL_ITEM objects to add status information.
246
     */
247
    void GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList );
248

249 250 251 252
    /**
     * Function ShowWidth
     * returns the width of the track in displayable user units.
     */
253
    wxString ShowWidth() const;
254

255 256
    SEARCH_RESULT Visit( INSPECTOR* inspector, const void* testData,
                         const KICAD_T scanTypes[] );
257 258


259
    virtual bool HitTest( const wxPoint& aPosition );
dickelbeck's avatar
dickelbeck committed
260

261 262 263 264
    /** @copydoc BOARD_ITEM::HitTest(const EDA_RECT& aRect,
     *                               bool aContained = true, int aAccuracy ) const
     */
    bool HitTest( const EDA_RECT& aRect, bool aContained = true, int aAccuracy = 0 ) const;
265 266 267 268 269 270

    /**
     * Function GetVia
     * finds the first SEGVIA object at \a aPosition on \a aLayer starting at the trace.
     *
     * @param aPosition The wxPoint to HitTest() against.
271
     * @param aLayer The layer to match, pass -1 for a don't care.
272 273
     * @return A pointer to a SEGVIA object if found, else NULL.
     */
274
    TRACK* GetVia( const wxPoint& aPosition, LAYER_NUM aLayer = UNDEFINED_LAYER );
275 276 277 278 279 280 281 282 283 284 285

    /**
     * Function GetVia
     * finds the first SEGVIA object at \a aPosition on \a aLayer starting at the trace
     * and ending at \a aEndTrace.
     *
     * @param aEndTrace Pointer to the last TRACK object to end search.
     * @param aPosition The wxPoint to HitTest() against.
     * @param aLayerMask The layers to match, pass -1 for a don't care.
     * @return A pointer to a SEGVIA object if found, else NULL.
     */
286
    TRACK* GetVia( TRACK* aEndTrace, const wxPoint& aPosition, LAYER_MSK aLayerMask );
287

288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312
    /**
     * Function GetTrace
     * return the trace segment connected to the segment at \a aEndPoint from \a
     * aStartTrace to \a aEndTrace.
     *
     * @param aStartTrace A pointer to the TRACK object to begin searching.
     * @param aEndTrace A pointer to the TRACK object to stop the search.  A NULL value
     *                  searches to the end of the list.
     * @param aEndPoint The start or end point of the segment to test against.
     * @return A TRACK object pointer if found otherwise NULL.
     */
    TRACK* GetTrace( TRACK* aStartTrace, TRACK* aEndTrace, int aEndPoint );

    /**
     * Function GetEndSegments
     * get the segments connected to the end point of the track.
     *  return 1 if OK, 0 when a track is a closed loop
     *  and the beginning and the end of the track in *StartTrack and *EndTrack
     *  Modify *StartTrack en *EndTrack  :
     *  (*StartTrack)->m_Start coordinate is the beginning of the track
     *  (*EndTrack)->m_End coordinate is the end of the track
     *  Segments connected must be consecutive in list
     */
    int GetEndSegments( int NbSegm, TRACK** StartTrack, TRACK** EndTrack );

dickelbeck's avatar
dickelbeck committed
313 314
    wxString GetClass() const
    {
315
        return wxT( "TRACK" );
dickelbeck's avatar
dickelbeck committed
316
    }
317

318 319 320 321 322 323 324 325 326 327 328
     /**
     * Function GetClearance
     * returns the clearance in internal units.  If \a aItem is not NULL then the
     * returned clearance is the greater of this object's clearance and
     * aItem's clearance.  If \a aItem is NULL, then this objects clearance
     * is returned.
     * @param aItem is another BOARD_CONNECTED_ITEM or NULL
     * @return int - the clearance in internal units.
     */
    virtual int GetClearance( BOARD_CONNECTED_ITEM* aItem = NULL ) const;

329
    virtual wxString GetSelectMenuText() const;
330

331
    virtual BITMAP_DEF GetMenuImage() const { return  showtrack_xpm; }
332

333 334
    virtual EDA_ITEM* Clone() const;

335 336 337 338 339 340
    /// @copydoc VIEW_ITEM::ViewGetLayers()
    virtual void ViewGetLayers( int aLayers[], int& aCount ) const;

    /// @copydoc VIEW_ITEM::ViewGetLOD()
    virtual unsigned int ViewGetLOD( int aLayer ) const;

341
#if defined (DEBUG)
342
    virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); }    // override
343 344 345 346 347 348 349 350

    /**
     * Function ShowState
     * converts a set of state bits to a wxString
     * @param stateBits Is an OR-ed together set of bits like BUSY, EDIT, etc.
     */
    static wxString ShowState( int stateBits );

351
#endif
352 353
};

354

dickelbeck's avatar
dickelbeck committed
355
class SEGZONE : public TRACK
356 357
{
public:
358
    SEGZONE( BOARD_ITEM* aParent );
359

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

dickelbeck's avatar
dickelbeck committed
362 363
    wxString GetClass() const
    {
364
        return wxT( "ZONE" );
dickelbeck's avatar
dickelbeck committed
365
    }
366

367 368

    SEGZONE* Next() const { return (SEGZONE*) Pnext; }
369

370
    wxString GetSelectMenuText() const;
371

372
    BITMAP_DEF GetMenuImage() const { return  add_zone_xpm; }
373

374
    EDA_ITEM* Clone() const;
375 376
};

377

dickelbeck's avatar
dickelbeck committed
378
class SEGVIA : public TRACK
379 380
{
public:
381
    SEGVIA( BOARD_ITEM* aParent );
382

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

385 386
    void Draw( EDA_DRAW_PANEL* panel, wxDC* DC,
               GR_DRAWMODE aDrawMode, const wxPoint& aOffset = ZeroOffset );
387

388
    bool IsOnLayer( LAYER_NUM aLayer ) const;
389

390 391 392 393 394 395
    /**
     * Function SetLayerPair
     * set the .m_Layer member param:
     *  For a via m_Layer contains the 2 layers :
     * top layer and bottom layer used by the via.
     * The via connect all layers from top layer to bottom layer
396
     * 4 bits for the first layer and 4 next bits for the second layer
397 398 399
     * @param top_layer = first layer connected by the via
     * @param bottom_layer = last layer connected by the via
     */
400
    void SetLayerPair( LAYER_NUM top_layer, LAYER_NUM bottom_layer );
401 402 403 404 405 406 407 408

    /**
     * Function ReturnLayerPair
     * Return the 2 layers used by  the via (the via actually uses
     * all layers between these 2 layers)
     *  @param top_layer = pointer to the first layer (can be null)
     *  @param bottom_layer = pointer to the last layer (can be null)
     */
409
    void ReturnLayerPair( LAYER_NUM* top_layer, LAYER_NUM* bottom_layer ) const;
410

Dick Hollenbeck's avatar
Dick Hollenbeck committed
411 412
    const wxPoint& GetPosition() const  {  return m_Start; }       // was overload
    void SetPosition( const wxPoint& aPoint ) { m_Start = aPoint;  m_End = aPoint; }    // was overload
413

dickelbeck's avatar
dickelbeck committed
414 415
    wxString GetClass() const
    {
416
        return wxT( "VIA" );
dickelbeck's avatar
dickelbeck committed
417
    }
418

419
    wxString GetSelectMenuText() const;
420

421
    BITMAP_DEF GetMenuImage() const { return  via_sketch_xpm; }
422

423
    EDA_ITEM* Clone() const;
424

425 426 427
    /// @copydoc VIEW_ITEM::ViewGetLayers()
    virtual void ViewGetLayers( int aLayers[], int& aCount ) const;

428
#if defined (DEBUG)
429
    virtual void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); }    // override
430
#endif
431 432 433 434
};


#endif /* CLASS_TRACK_H */