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 <drc/drc_rule_parser.h>
26#include <thread_pool.h>
27#include <drc/drc_item.h>
28#include "tools/drc_tool.h"
29#include <tool/tool_manager.h>
30#include <drc/drc_rtree.h>
31
33
38
39
40class PCB_EDIT_FRAME;
42class TOOL_MANAGER;
43class DRC_RTREE;
44
46{
47public:
48 DIALOG_DRC_RULE_EDITOR( PCB_EDIT_FRAME* aEditorFrame, wxWindow* aParent );
49
51
52 bool TransferDataToWindow() override;
53
54 bool TransferDataFromWindow() override;
55
56 std::vector<RULE_TREE_NODE> GetDefaultRuleTreeItems() override;
57
64 void AddNewRule( RULE_TREE_ITEM_DATA* aRuleTreeItemData ) override;
65
71 void DuplicateRule( RULE_TREE_ITEM_DATA* aRuleTreeItemData ) override;
72
78 void RuleTreeItemSelectionChanged( RULE_TREE_ITEM_DATA* aCurrentRuleTreeItemData ) override;
79
85 void UpdateRuleTypeTreeItemData( RULE_TREE_ITEM_DATA* aCurrentRuleTreeItemData ) override;
86
95 bool isEnabled( RULE_TREE_ITEM_DATA* aRuleTreeItemData,
96 RULE_EDITOR_TREE_CONTEXT_OPT aOption ) override;
97
103 void RemoveRule( int aNodeId ) override;
104
105 void UpdateData();
106
107 void OnSave( wxCommandEvent& aEvent ) override;
108
109 void OnCancel( wxCommandEvent& aEvent ) override;
110
111private:
112 std::vector<RULE_TREE_NODE> buildElectricalRuleTreeNodes( int& aParentId );
113
114 std::vector<RULE_TREE_NODE> buildManufacturabilityRuleTreeNodes( int& aParentId );
115
116 std::vector<RULE_TREE_NODE> buildHighspeedDesignRuleTreeNodes( int& aParentId );
117
118 std::vector<RULE_TREE_NODE> buildFootprintsRuleTreeNodes( int& aParentId );
119
120 void LoadExistingRules();
121
122 void SaveRulesToFile();
123
132
146 buildRuleTreeNodeData( const std::string& aName, const DRC_RULE_EDITOR_ITEM_TYPE& aNodeType,
147 const std::optional<int>& aParentId = std::nullopt,
148 const std::optional<DRC_RULE_EDITOR_CONSTRAINT_NAME>& aConstraintType = std::nullopt,
149 const std::vector<RULE_TREE_NODE>& aChildNodes = {},
150 const std::optional<int>& aId = std::nullopt );
151
156 RULE_TREE_NODE buildRuleNodeFromKicadDrc( const wxString& aName, const wxString& aCode,
157 const std::optional<int>& aParentId = std::nullopt );
158
167 RULE_TREE_NODE* getRuleTreeNodeInfo( const int& aNodeId );
168
175 void saveRule( int aNodeId );
176
182 void closeRuleEntryView( int aNodeId );
183
190 int highlightMatchingItems( int aNodeId );
191
200 bool validateRuleName( int aNodeId, wxString aRuleName );
201
209 bool deleteTreeNodeData( const int& aNodeId );
210
217 void collectChildRuleNodes( int aParentId, std::vector<RULE_TREE_NODE*>& aResult );
218
219 // PROGRESS_REPORTER calls
220 bool updateUI() override;
221
222 void AdvancePhase( const wxString& aMessage ) override;
223
224
225protected:
226 BOARD_DESIGN_SETTINGS& bds() { return m_currentBoard->GetDesignSettings(); }
227
228 BOARD* m_currentBoard; // the board currently on test
232 wxDataViewCtrl* m_markerDataView;
233
234private:
236 std::vector<RULE_TREE_NODE> m_ruleTreeNodeDatas;
239
240 std::shared_ptr<RC_ITEMS_PROVIDER> m_markersProvider;
243};
244
245#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
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.
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...
RULE_TREE_NODE buildRuleTreeNodeData(const std::string &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 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.
PANEL_DRC_RULE_EDITOR * m_ruleEditorPanel
RULE_TREE_NODE buildRuleTreeNode(RULE_TREE_ITEM_DATA *aRuleTreeItemData)
Creates a new rule tree node with a unique name and assigns the appropriate constraint data.
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.