summaryrefslogtreecommitdiff
path: root/pcbnew/dialogs/dialog_design_rules.h
blob: 9544f92c9a1b20c8ca712b072b1559fc67b32e40 (plain)
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
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
 * Copyright (C) 2004-2009 Jean-Pierre Charras, jean-pierre.charras@gpisa-lab.inpg.fr
 * Copyright (C) 2009 Dick Hollenbeck, dick@softplc.com
 * Copyright (C) 2009-2015 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 dialog_design_rules.h
 */

#ifndef __dialog_design_rules_h_
#define __dialog_design_rules_h_

#include <../class_board.h>

#include <dialog_design_rules_base.h>


class PCB_EDIT_FRAME;
class BOARD_DESIGN_SETTINGS;


// helper struct to handle a net and its netclass in dialog design rule editor
struct NETCUP
{
    NETCUP( const wxString& aNet, const wxString& aClass )
    {
        net = aNet;
        clazz = aClass;
    }

    wxString    net;            ///< a net name
    wxString    clazz;          ///< a class name
};


typedef std::vector<NETCUP>     NETCUPS;
typedef std::vector<NETCUP*>    PNETCUPS;

class DIALOG_DESIGN_RULES : public DIALOG_DESIGN_RULES_BASE
{

private:

    static const wxString wildCard;     ///< the name of a fictitious netclass which includes all NETs

    PCB_EDIT_FRAME*         m_Parent;
    BOARD*                  m_Pcb;
    BOARD_DESIGN_SETTINGS*  m_BrdSettings;

    static int              s_LastTabSelection;     ///< which tab user had open last

    /**
     * A two column table which gets filled once and never loses any elements, so it is
     * basically constant, except that the NETCUP::clazz member can change for any
     * given row a NET is moved in and out of a class.  class reflects the respective
     * NET's current net class.
     */
    NETCUPS                 m_AllNets;

    // List of values to "customize" some tracks and vias
    std::vector <VIA_DIMENSION> m_ViasDimensionsList;
    std::vector <int> m_TracksWidthList;

private:
    void OnNetClassesNameLeftClick( wxGridEvent& event ){ event.Skip(); }
    void OnNetClassesNameRightClick( wxGridEvent& event ){ event.Skip(); }
    void OnAddNetclassClick( wxCommandEvent& event );
    void OnRemoveNetclassClick( wxCommandEvent& event );

    /*
     * Called on "Move Up" button click
     * the selected(s) rules are moved up
     * The default netclass is always the first rule
     */
    void OnMoveUpSelectedNetClass( wxCommandEvent& event );

    /*
     * Called on the left Choice Box selection
     */
    void OnLeftCBSelection( wxCommandEvent& event );

    /*
     * Called on the Right Choice Box selection
     */
    void OnRightCBSelection( wxCommandEvent& event );

    void OnRightToLeftCopyButton( wxCommandEvent& event );
    void OnLeftToRightCopyButton( wxCommandEvent& event );

    void OnNotebookPageChanged( wxNotebookEvent& event );

    /*
     * Called on clicking the left "select all" button:
     * select all items of the left netname list list box
     */
    void OnLeftSelectAllButton( wxCommandEvent& event );

    /*
     * Called on clicking the right "select all" button:
     * select all items of the right netname list list box
     */
    void OnRightSelectAllButton( wxCommandEvent& event );

    /*
     * Function TestDataValidity
     *
     * Performs a check of design rule data validity and displays an error message if errors
     * are found.
     * @param aErrorMsg is a pointer to a wxString to copy the error message into.  Can be NULL.
     * @return true if Ok, false if error
     */
    bool TestDataValidity( wxString* aErrorMsg = NULL );

    void InitDialogRules();
    void InitGlobalRules();

    /**
     * Function InitRulesList
     * Fill the grid showing current rules with values
     */
    void InitRulesList();

    /* Populates the lists of sizes (Tracks width list and Vias diameters & drill list) */
    void InitDimensionsLists();

    void InitializeRulesSelectionBoxes();

    /* Copy the rules list from grid to board
     */
    void CopyRulesListToBoard();

    void CopyGlobalRulesToBoard();
    void CopyDimensionsListsToBoard( );
    void SetRoutableLayerStatus();

    /**
     * Function FillListBoxWithNetNames
     * populates aListCtrl with net names and class names from m_AllNets in a two column display.
     */
    void FillListBoxWithNetNames( NETS_LIST_CTRL* aListCtrl, const wxString& aNetClass );

    /**
     * Function swapNetClass
     * replaces one net class name with another in the master list, m_AllNets.
     */
    void swapNetClass( const wxString& oldClass, const wxString& newClass )
    {
        for( NETCUPS::iterator i = m_AllNets.begin(); i!=m_AllNets.end();  ++i )
        {
            if( i->clazz == oldClass )
                i->clazz = newClass;
        }
    }

    void makePointers( PNETCUPS* aList, const wxString& aNetClassName );

    void setNetClass( const wxString& aNetName, const wxString& aClassName );

    void moveSelectedItems( NETS_LIST_CTRL* src, const wxString& newClassName );


public:
    DIALOG_DESIGN_RULES( PCB_EDIT_FRAME* parent );
    ~DIALOG_DESIGN_RULES( ) { }

    virtual bool TransferDataFromWindow();
};

#endif //__dialog_design_rules_h_