You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

434 lines
15 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef PANEL_ASSIGN_COMPONENT_CLASSES_H
  24. #define PANEL_ASSIGN_COMPONENT_CLASSES_H
  25. #include <panel_assign_component_classes_base.h>
  26. #include <unordered_set>
  27. #include <vector>
  28. #include <dialog_shim.h>
  29. #include <pcb_edit_frame.h>
  30. #include <project/component_class_settings.h>
  31. /**************************************************************************************************
  32. *
  33. * PANEL_ASSIGN_COMPONENT_CLASSES
  34. *
  35. *************************************************************************************************/
  36. /**
  37. * Top-level panel for dynamic component class assignment configuration. Nests a
  38. * PANEL_COMPONENT_CLASS_ASSIGNMENT panel for each set of component class assignment conditions
  39. */
  40. class PANEL_COMPONENT_CLASS_ASSIGNMENT;
  41. class PANEL_ASSIGN_COMPONENT_CLASSES : public PANEL_ASSIGN_COMPONENT_CLASSES_BASE
  42. {
  43. public:
  44. PANEL_ASSIGN_COMPONENT_CLASSES( wxWindow* aParentWindow, PCB_EDIT_FRAME* aFrame,
  45. std::shared_ptr<COMPONENT_CLASS_SETTINGS> aSettings,
  46. DIALOG_SHIM* aDlg );
  47. ~PANEL_ASSIGN_COMPONENT_CLASSES() override;
  48. /// Loads current component class assignments from the board settings
  49. bool TransferDataToWindow() override;
  50. /// Saves the component class assignments to the board settings
  51. bool TransferDataFromWindow() override;
  52. /// Loads component class assignments from the given settings object
  53. void ImportSettingsFrom( const std::shared_ptr<COMPONENT_CLASS_SETTINGS>& aOtherSettings );
  54. /// Adds a new component class assignment rule
  55. void OnAddAssignmentClick( wxCommandEvent& event ) override;
  56. /// Removes a given component class assignment rule
  57. void RemoveAssignment( PANEL_COMPONENT_CLASS_ASSIGNMENT* aPanel );
  58. /// Returns references for all currently selected footprints
  59. const std::vector<wxString>& GetSelectionRefs() const { return m_selectionRefs; }
  60. /// Returns names of all fields present in footprints
  61. const std::vector<wxString>& GetFieldNames() const { return m_fieldNames; }
  62. /// Returns names of all sheets present in footprints
  63. const std::vector<wxString>& GetSheetNames() const { return m_sheetNames; }
  64. /// Gets the active edit frame
  65. PCB_EDIT_FRAME* GetFrame() const { return m_frame; }
  66. /// Validates that all assignment rules can compile successfully
  67. bool Validate() override;
  68. private:
  69. /// Adds a new component class assignment rule
  70. PANEL_COMPONENT_CLASS_ASSIGNMENT* addAssignment();
  71. /// Scrolls the panel to specified assignment rule
  72. void scrollToAssignment( const PANEL_COMPONENT_CLASS_ASSIGNMENT* aAssignment ) const;
  73. /// The parent dialog
  74. DIALOG_SHIM* m_dlg;
  75. /// The active edit frame
  76. PCB_EDIT_FRAME* m_frame;
  77. /// Vector of all currently displayed assignment rules
  78. std::vector<PANEL_COMPONENT_CLASS_ASSIGNMENT*> m_assignments;
  79. /// The active settings object
  80. std::shared_ptr<COMPONENT_CLASS_SETTINGS> m_componentClassSettings;
  81. /// All currently selected footprint references
  82. std::vector<wxString> m_selectionRefs;
  83. /// All footprint fields names present on the board
  84. std::vector<wxString> m_fieldNames;
  85. /// All sheet names present on the board
  86. std::vector<wxString> m_sheetNames;
  87. /// The list of all currently present component class assignments
  88. wxBoxSizer* m_assignmentsList;
  89. };
  90. /**************************************************************************************************
  91. *
  92. * CONDITION_DATA
  93. *
  94. *************************************************************************************************/
  95. /**
  96. * Class used to provide a unified interface from condition panels
  97. * Handles determining the type of condition in use, and getting and settings the field data
  98. */
  99. class CONDITION_DATA
  100. {
  101. public:
  102. CONDITION_DATA( const COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITION_TYPE aCondition,
  103. wxTextEntry* aPrimary, wxTextEntry* aSecondary = nullptr ) :
  104. m_conditionType( aCondition ), m_primaryCtrl( aPrimary ), m_secondaryCtrl( aSecondary )
  105. {
  106. }
  107. virtual ~CONDITION_DATA() {};
  108. /// Gets the type of condition (e.g. Reference, Side) this data represents
  109. virtual COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITION_TYPE GetConditionType() const
  110. {
  111. return m_conditionType;
  112. }
  113. /// Gets the primary data member for the condition (e.g. Reference, Side)
  114. virtual wxString GetPrimaryField() const;
  115. /// Sets the primary data member for the condition (e.g. Reference, Side)
  116. virtual void SetPrimaryField( const wxString& aVal );
  117. /// Gets the primary data member for the condition (e.g. FOOTPRITNT field value)
  118. virtual wxString GetSecondaryField() const;
  119. /// Sets the primary data member for the condition (e.g. FOOTPRITNT field
  120. /// value)
  121. virtual void SetSecondaryField( const wxString& aVal );
  122. private:
  123. /// The type of condition being referenced
  124. COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITION_TYPE m_conditionType;
  125. /// The primary data field in the condition panel
  126. wxTextEntry* m_primaryCtrl;
  127. /// The Secondary data field in the condition panel
  128. wxTextEntry* m_secondaryCtrl;
  129. };
  130. /**************************************************************************************************
  131. *
  132. * PANEL_COMPONENT_CLASS_ASSIGNMENT
  133. *
  134. *************************************************************************************************/
  135. /**
  136. * Panel which configures a set of conditions for a component class assignment rule
  137. */
  138. class PANEL_COMPONENT_CLASS_ASSIGNMENT : public PANEL_COMPONENT_CLASS_ASSIGNMENT_BASE
  139. {
  140. public:
  141. /// IDs for match type popup menu
  142. enum ADD_MATCH_POPUP
  143. {
  144. ID_REFERENCE = wxID_HIGHEST + 1,
  145. ID_FOOTPRINT,
  146. ID_SIDE,
  147. ID_ROTATION,
  148. ID_FOOTPRINT_FIELD,
  149. ID_SHEET_NAME,
  150. ID_CUSTOM
  151. };
  152. PANEL_COMPONENT_CLASS_ASSIGNMENT( wxWindow* aParent,
  153. PANEL_ASSIGN_COMPONENT_CLASSES* aPanelParent,
  154. DIALOG_SHIM* aDlg );
  155. ~PANEL_COMPONENT_CLASS_ASSIGNMENT();
  156. /// Deletes this component class assignment rule
  157. void OnDeleteAssignmentClick( wxCommandEvent& event ) override;
  158. /// Adds a match condition to this component class assignment rule
  159. void OnAddConditionClick( wxCommandEvent& event ) override;
  160. /// Highlights footprints matching this set of conditions
  161. void OnHighlightItemsClick( wxCommandEvent& event ) override;
  162. /// Adds a condition to this component class assignment rule
  163. CONDITION_DATA* AddCondition( COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITION_TYPE aCondition );
  164. /// Removes a given condition from this component class assignment rule (note: called from the child
  165. /// condition panel)
  166. void RemoveCondition( wxPanel* aMatch );
  167. const std::vector<CONDITION_DATA*>& GetConditions() const { return m_matches; }
  168. /// Sets the resulting component class for this assignment
  169. void SetComponentClass( const wxString& aComponentClass ) const;
  170. /// Gets the resulting component class for this assignment
  171. const wxString GetComponentClass() const;
  172. /// Sets the boolean operator applied to all assignment conditions
  173. void
  174. SetConditionsOperator( COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITIONS_OPERATOR aCondition ) const;
  175. /// Gets the boolean operator applied to all assignment conditions
  176. COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITIONS_OPERATOR GetConditionsOperator() const;
  177. /// Converts the UI representation in to the internal assignment data representation
  178. COMPONENT_CLASS_ASSIGNMENT_DATA GenerateAssignmentData() const;
  179. protected:
  180. /// Handles add match condition popup menu selections
  181. void onMenu( wxCommandEvent& aEvent );
  182. /// The top-level configuration panel which owns this assignment rule
  183. PANEL_ASSIGN_COMPONENT_CLASSES* m_parentPanel;
  184. /// The sizer containing match condition panels
  185. wxStaticBoxSizer* m_matchesList;
  186. /// Set containing all currently configured match condition types
  187. std::unordered_set<COMPONENT_CLASS_ASSIGNMENT_DATA::CONDITION_TYPE> m_conditionTypes;
  188. /// The parent configuration dialog
  189. DIALOG_SHIM* m_dlg;
  190. /// All match conditions for this component class assignment rule
  191. std::vector<CONDITION_DATA*> m_matches;
  192. };
  193. /**************************************************************************************************
  194. *
  195. * PANEL_COMPONENT_CLASS_CONDITION_REFERENCE
  196. *
  197. *************************************************************************************************/
  198. /**
  199. * Configures matching based on footprint reference
  200. */
  201. class PANEL_COMPONENT_CLASS_CONDITION_REFERENCE
  202. : public PANEL_COMPONENT_CLASS_CONDITION_REFERENCE_BASE,
  203. public CONDITION_DATA
  204. {
  205. public:
  206. /// IDs for match type popup menu
  207. enum IMPORT_POPUP_IDS
  208. {
  209. ID_IMPORT_REFS = wxID_HIGHEST + 1
  210. };
  211. explicit PANEL_COMPONENT_CLASS_CONDITION_REFERENCE( wxWindow* aParent );
  212. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  213. void OnImportRefsClick( wxCommandEvent& event ) override;
  214. void SetSelectionRefs( const std::vector<wxString>& aRefs ) { m_selectionRefs = aRefs; }
  215. protected:
  216. /// Handles import references popup menu selections
  217. void onMenu( wxCommandEvent& aEvent );
  218. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  219. std::vector<wxString> m_selectionRefs;
  220. };
  221. /**************************************************************************************************
  222. *
  223. * PANEL_COMPONENT_CLASS_CONDITION_FOOTPRINT
  224. *
  225. *************************************************************************************************/
  226. /**
  227. * Configures matching based on footprint library identifier
  228. */
  229. class PANEL_COMPONENT_CLASS_CONDITION_FOOTPRINT
  230. : public PANEL_COMPONENT_CLASS_CONDITION_FOOTPRINT_BASE,
  231. public CONDITION_DATA
  232. {
  233. public:
  234. explicit PANEL_COMPONENT_CLASS_CONDITION_FOOTPRINT( wxWindow* aParent, DIALOG_SHIM* aDlg );
  235. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  236. void OnShowLibraryClick( wxCommandEvent& event ) override;
  237. protected:
  238. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  239. DIALOG_SHIM* m_dlg;
  240. };
  241. /**************************************************************************************************
  242. *
  243. * PANEL_COMPONENT_CLASS_CONDITION_SIDE
  244. *
  245. *************************************************************************************************/
  246. /**
  247. * Configures matching based on which side of the board a footprint is on
  248. */
  249. class PANEL_COMPONENT_CLASS_CONDITION_SIDE : public PANEL_COMPONENT_CLASS_CONDITION_SIDE_BASE,
  250. public CONDITION_DATA
  251. {
  252. public:
  253. explicit PANEL_COMPONENT_CLASS_CONDITION_SIDE( wxWindow* aParent );
  254. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  255. protected:
  256. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  257. };
  258. /**************************************************************************************************
  259. *
  260. * PANEL_COMPONENT_CLASS_CONDITION_ROTATION
  261. *
  262. *************************************************************************************************/
  263. /**
  264. * Configures matching based on footprint rotation
  265. */
  266. class PANEL_COMPONENT_CLASS_CONDITION_ROTATION
  267. : public PANEL_COMPONENT_CLASS_CONDITION_ROTATION_BASE,
  268. public CONDITION_DATA
  269. {
  270. public:
  271. explicit PANEL_COMPONENT_CLASS_CONDITION_ROTATION( wxWindow* aParent );
  272. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  273. protected:
  274. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  275. };
  276. /**************************************************************************************************
  277. *
  278. * PANEL_COMPONENT_CLASS_CONDITION_FIELD
  279. *
  280. *************************************************************************************************/
  281. /**
  282. * Configures matching based on footprint field contents
  283. */
  284. class PANEL_COMPONENT_CLASS_CONDITION_FIELD : public PANEL_COMPONENT_CLASS_CONDITION_FIELD_BASE,
  285. public CONDITION_DATA
  286. {
  287. public:
  288. explicit PANEL_COMPONENT_CLASS_CONDITION_FIELD( wxWindow* aParent );
  289. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  290. void SetFieldsList( const std::vector<wxString>& aFields );
  291. protected:
  292. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  293. };
  294. /**************************************************************************************************
  295. *
  296. * PANEL_COMPONENT_CLASS_CONDITION_CUSTOM
  297. *
  298. *************************************************************************************************/
  299. /**
  300. * Configures matching based on a custom DRC expression
  301. */
  302. class PANEL_COMPONENT_CLASS_CONDITION_CUSTOM : public PANEL_COMPONENT_CLASS_CONDITION_CUSTOM_BASE,
  303. public CONDITION_DATA
  304. {
  305. public:
  306. explicit PANEL_COMPONENT_CLASS_CONDITION_CUSTOM( wxWindow* aParent );
  307. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  308. protected:
  309. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  310. };
  311. /**************************************************************************************************
  312. *
  313. * PANEL_COMPONENT_CLASS_SHEET
  314. *
  315. *************************************************************************************************/
  316. /**
  317. * Configures matching based on a custom DRC expression
  318. */
  319. class PANEL_COMPONENT_CLASS_CONDITION_SHEET : public PANEL_COMPONENT_CLASS_CONDITION_SHEET_BASE,
  320. public CONDITION_DATA
  321. {
  322. public:
  323. explicit PANEL_COMPONENT_CLASS_CONDITION_SHEET( wxWindow* aParent );
  324. void OnDeleteConditionClick( wxCommandEvent& event ) override;
  325. void SetSheetsList( const std::vector<wxString>& aSheets );
  326. protected:
  327. PANEL_COMPONENT_CLASS_ASSIGNMENT* m_panelParent;
  328. };
  329. #endif //PANEL_ASSIGN_COMPONENT_CLASSES_H