KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_drc_rule_editor.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#ifndef DIALOG_DRC_RULE_EDITOR_H
22#define DIALOG_DRC_RULE_EDITOR_H
23
24
25#include <map>
26
27#include <drc/drc_rule_parser.h>
28#include <thread_pool.h>
29#include <drc/drc_item.h>
30#include "tools/drc_tool.h"
31#include <tool/tool_manager.h>
32#include <drc/drc_rtree.h>
33
35
40
41#define DIALOG_DRC_RULE_EDITOR_WINDOW_NAME wxT( "DialogDrcRuleEditorWindowName" )
42
43class PCB_EDIT_FRAME;
45class TOOL_MANAGER;
46class DRC_RTREE;
47
49{
50public:
51 DIALOG_DRC_RULE_EDITOR( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent );
52
54
55 bool TransferDataToWindow() override;
56
57 bool TransferDataFromWindow() override;
58
59 std::vector<RULE_TREE_NODE> GetDefaultRuleTreeItems() override;
60
67 void AddNewRule( RULE_TREE_ITEM_DATA* aRuleTreeItemData ) override;
68
74 void DuplicateRule( RULE_TREE_ITEM_DATA* aRuleTreeItemData ) override;
75
81 void RuleTreeItemSelectionChanged( RULE_TREE_ITEM_DATA* aCurrentRuleTreeItemData ) override;
82
88 void UpdateRuleTypeTreeItemData( RULE_TREE_ITEM_DATA* aCurrentRuleTreeItemData ) override;
89
98 bool isEnabled( RULE_TREE_ITEM_DATA* aRuleTreeItemData,
99 RULE_EDITOR_TREE_CONTEXT_OPT aOption ) override;
100
106 void RemoveRule( int aNodeId ) override;
107
108 void UpdateData();
109
110 void OnSave( wxCommandEvent& aEvent ) override;
111
112 void OnCancel( wxCommandEvent& aEvent ) override;
113
114private:
115 std::vector<RULE_TREE_NODE> buildElectricalRuleTreeNodes( int& aParentId );
116
117 std::vector<RULE_TREE_NODE> buildManufacturabilityRuleTreeNodes( int& aParentId );
118
119 std::vector<RULE_TREE_NODE> buildHighspeedDesignRuleTreeNodes( int& aParentId );
120
121 std::vector<RULE_TREE_NODE> buildFootprintsRuleTreeNodes( int& aParentId );
122
123 void LoadExistingRules();
124
125 void SaveRulesToFile();
126
137 const wxString& aBaseName = wxEmptyString );
138
152 buildRuleTreeNodeData( const wxString& aName, const DRC_RULE_EDITOR_ITEM_TYPE& aNodeType,
153 const std::optional<int>& aParentId = std::nullopt,
154 const std::optional<DRC_RULE_EDITOR_CONSTRAINT_NAME>& aConstraintType = std::nullopt,
155 const std::vector<RULE_TREE_NODE>& aChildNodes = {},
156 const std::optional<int>& aId = std::nullopt );
157
162 RULE_TREE_NODE buildRuleNodeFromKicadDrc( const wxString& aName, const wxString& aCode,
163 const std::optional<int>& aParentId = std::nullopt );
164
173 RULE_TREE_NODE* getRuleTreeNodeInfo( const int& aNodeId );
174
181 void saveRule( int aNodeId );
182
188 void closeRuleEntryView( int aNodeId );
189
196 int highlightMatchingItems( int aNodeId );
197
206 bool validateRuleName( int aNodeId, wxString aRuleName );
207
215 bool deleteTreeNodeData( const int& aNodeId );
216
223 void collectChildRuleNodes( int aParentId, std::vector<RULE_TREE_NODE*>& aResult );
224
230 void collectModifiedRules( std::vector<RULE_TREE_NODE*>& aResult );
231
238 bool validateAllRules( std::map<wxString, wxString>& aErrors );
239
246
252 void selectRuleNode( int aNodeId );
253
254 // PROGRESS_REPORTER calls
255 bool updateUI() override;
256
257 void AdvancePhase( const wxString& aMessage ) override;
258
259
260protected:
261 BOARD_DESIGN_SETTINGS& bds() { return m_currentBoard->GetDesignSettings(); }
262
263 BOARD* m_currentBoard; // the board currently on test
267 wxDataViewCtrl* m_markerDataView;
268
269private:
271 std::vector<RULE_TREE_NODE> m_ruleTreeNodeDatas;
274
275 std::shared_ptr<RC_ITEMS_PROVIDER> m_markersProvider;
278};
279
280#endif //DIALOG_DRC_RULE_EDITOR_H
Container for design settings for a BOARD object.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:322
std::vector< RULE_TREE_NODE > m_ruleTreeNodeDatas
PANEL_DRC_GROUP_HEADER * m_groupHeaderPanel
bool validateAllRules(std::map< wxString, wxString > &aErrors)
Validates all rules and returns any that have validation errors.
std::vector< RULE_TREE_NODE > buildElectricalRuleTreeNodes(int &aParentId)
std::vector< RULE_TREE_NODE > buildHighspeedDesignRuleTreeNodes(int &aParentId)
void UpdateRuleTypeTreeItemData(RULE_TREE_ITEM_DATA *aCurrentRuleTreeItemData) override
Updates the rule tree item data by transferring data from the rule editor panel and updating the item...
void collectChildRuleNodes(int aParentId, std::vector< RULE_TREE_NODE * > &aResult)
Collects all child rule nodes for a given parent node ID.
int highlightMatchingItems(int aNodeId)
Highlights board items matching the current rule condition.
RULE_TREE_NODE buildRuleTreeNodeData(const wxString &aName, const DRC_RULE_EDITOR_ITEM_TYPE &aNodeType, const std::optional< int > &aParentId=std::nullopt, const std::optional< DRC_RULE_EDITOR_CONSTRAINT_NAME > &aConstraintType=std::nullopt, const std::vector< RULE_TREE_NODE > &aChildNodes={}, const std::optional< int > &aId=std::nullopt)
Creates a new rule tree node with the specified parameters, generating a new ID if not provided.
RULE_TREE_NODE buildRuleTreeNode(RULE_TREE_ITEM_DATA *aRuleTreeItemData, const wxString &aBaseName=wxEmptyString)
Creates a new rule tree node with a unique name and assigns the appropriate constraint data.
void saveRule(int aNodeId)
Saves the rule after validating the rule editor panel.
void AddNewRule(RULE_TREE_ITEM_DATA *aRuleTreeItemData) override
Adds a new rule to the rule tree, either as a child or under the parent, based on the node type (CONS...
void RuleTreeItemSelectionChanged(RULE_TREE_ITEM_DATA *aCurrentRuleTreeItemData) override
Handles rule tree item selection changes, updating the content panel with appropriate editor or heade...
int promptUnsavedChanges()
Shows a prompt for unsaved changes when closing with modifications.
RULE_TREE_NODE buildRuleNodeFromKicadDrc(const wxString &aName, const wxString &aCode, const std::optional< int > &aParentId=std::nullopt)
Build a rule tree node from a constraint keyword loaded from a .kicad_drc file.
std::vector< RULE_TREE_NODE > GetDefaultRuleTreeItems() override
Pure virtual method to get the default rule tree items.
std::shared_ptr< RC_ITEMS_PROVIDER > m_markersProvider
std::vector< RULE_TREE_NODE > buildManufacturabilityRuleTreeNodes(int &aParentId)
void RemoveRule(int aNodeId) override
Removes a rule from the rule tree after confirmation, deleting the item and associated data.
void OnCancel(wxCommandEvent &aEvent) override
BOARD_DESIGN_SETTINGS & bds()
std::vector< RULE_TREE_NODE > buildFootprintsRuleTreeNodes(int &aParentId)
RULE_TREE_NODE * getRuleTreeNodeInfo(const int &aNodeId)
Retrieves the rule tree node for a given ID.
void selectRuleNode(int aNodeId)
Selects a rule node in the tree by its ID.
PANEL_DRC_RULE_EDITOR * m_ruleEditorPanel
void collectModifiedRules(std::vector< RULE_TREE_NODE * > &aResult)
Collects all rule nodes that have unsaved changes (new or edited).
DIALOG_DRC_RULE_EDITOR(PCB_EDIT_FRAME *aEditorFrame, wxWindow *aParent)
bool deleteTreeNodeData(const int &aNodeId)
Deletes a rule tree node by its ID.
bool isEnabled(RULE_TREE_ITEM_DATA *aRuleTreeItemData, RULE_EDITOR_TREE_CONTEXT_OPT aOption) override
Verifies if a context menu option should be enabled based on the rule tree item type.
void closeRuleEntryView(int aNodeId)
Closes the rule entry view and re-enables controls.
void OnSave(wxCommandEvent &aEvent) override
void DuplicateRule(RULE_TREE_ITEM_DATA *aRuleTreeItemData) override
Duplicates a rule from the source tree node and appends it as a new item under the same parent.
bool validateRuleName(int aNodeId, wxString aRuleName)
Validates if the rule name is unique for the given node ID.
Implement an R-tree for fast spatial and layer indexing of connectable items.
Definition drc_rtree.h:50
The main frame for Pcbnew.
virtual void AdvancePhase() override
Use the next available virtual zone of the dialog progress bar.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
RULE_EDITOR_DIALOG_BASE(wxWindow *aParent, const wxString &aTitle, const wxSize &aInitialSize=wxDefaultSize)
A class representing additional data associated with a wxTree item.
Master controller class:
DRC_RULE_EDITOR_ITEM_TYPE
RULE_EDITOR_TREE_CONTEXT_OPT
Enumeration representing the available context menu options for the rule editor tree.
Structure representing a node in a rule tree, collection of this used for building the rule tree.