// SPDX-License-Identifier: GPL-3.0-or-later // Copyright (C) 2026 ZiroEDA and contributors. // Portions derived from KiCad, copyright The KiCad Developers. See NOTICE.md. /** * `DIALOG_CREATE_ARRAY_BASE` (pcbnew/dialogs/dialog_create_array_base.cpp): the sizer tree, Add() * for Add(). The members are props; the behaviour is DIALOG_CREATE_ARRAY's * (dialog_create_array.tsx). */ import type { JSX } from 'react'; import { DialogShim } from '@ziroeda/common/dialog_shim.js'; import { TextCtrlEval } from '@ziroeda/common/widgets/text_ctrl_eval.js'; import { Button, type CHECK, type CHOICE, CheckBox, Choice, RadioBox, RadioButton, StaticText, TextCtrl, } from '@ziroeda/wx/controls.js'; import { wxALIGN_CENTER_VERTICAL, wxALL, wxBOTTOM, wxEXPAND, wxHORIZONTAL, wxLEFT, wxRIGHT, wxTOP, wxVERTICAL, } from '@ziroeda/wx/defs.js'; import { Notebook } from '@ziroeda/wx/notebook_ui.js'; import { BoxSizer, FlexGridSizer, SizerItem, Spacer, StaticBoxSizer, StdDialogButtonSizer, } from '@ziroeda/wx/sizer.js'; /** A text control: its text, Enable() and wxEVT_TEXT. */ export interface ENTRY { value: string; enabled?: boolean; onChange: (aText: string) => void; onBlur?: () => void; } /** A wxRadioBox: its selection, Enable() and wxEVT_RADIOBOX. */ export interface RADIOBOX { selection: number; enabled?: boolean; onChange: (aIndex: number) => void; } /** A radio button pair or group member. */ export interface RADIO { value: boolean; onSelect: () => void; } export interface DIALOG_CREATE_ARRAY_BASE_PROPS { /** The window's Enable(): false while PCB_PICKER_TOOL picks a center for it. */ enabled: boolean; /** `m_gridTypeNotebook`'s selection. */ page: number; onPage: (aPage: number) => void; m_entryNx: ENTRY; m_entryNy: ENTRY; /** UNIT_BINDER texts, and the units each shows. */ m_entryDx: ENTRY; m_entryDy: ENTRY; m_entryOffsetX: ENTRY; m_entryOffsetY: ENTRY; units: string; m_entryStagger: ENTRY; m_staggerRows: RADIO; m_staggerCols: RADIO; m_rbItemsRemainInPlace: RADIO; m_rbCentreOnSource: RADIO; /** `m_gridPadNumberingPanel->Show()`: the footprint editor's pad numbering. */ gridPadNumberingShown: boolean; m_cbRenumberPads: CHECK; m_radioBoxGridNumberingAxis: RADIOBOX; m_checkBoxGridReverseNumbering: CHECK; m_rbGridStartNumberingOpt: RADIOBOX; m_radioBoxGridNumberingScheme: RADIOBOX; numberingChoices: readonly string[]; m_choicePriAxisNumbering: CHOICE; m_choiceSecAxisNumbering: CHOICE; m_entryGridPriNumberingOffset: ENTRY; m_entryGridSecNumberingOffset: ENTRY; m_entryGridPriNumberingStep: ENTRY; m_entryGridSecNumberingStep: ENTRY; /** The labels setControlEnablement greys with their controls. */ priAxisLabelEnabled: boolean; secAxisLabelEnabled: boolean; numberingOffsetLabelEnabled: boolean; numberingStepLabelEnabled: boolean; m_entryCentreX: ENTRY; m_entryCentreY: ENTRY; onSelectCenterPoint: () => void; onSelectCenterItem: () => void; m_checkBoxFullCircle: CHECK; m_rbCircDirection: RADIOBOX; m_entryCircAngle: ENTRY; m_entryCircCount: ENTRY; m_entryCircOffset: ENTRY; m_entryRotateItemsCb: CHECK; circPadNumberingShown: boolean; m_rbCircStartNumberingOpt: RADIOBOX; m_choiceCircNumbering: CHOICE; m_entryCircNumberingStart: ENTRY; m_entryCircNumberingStep: ENTRY; m_radioBtnDuplicateSelection: RADIO; m_radioBtnArrangeSelection: RADIO; /** `m_footprintReannotatePanel->Show()`. */ footprintReannotateShown: boolean; m_radioBtnKeepRefs: RADIO; m_radioBtnUniqueRefs: RADIO; onOK: () => void; onCancel: () => void; } const CV = wxALIGN_CENTER_VERTICAL; const REFS_TIP = 'This can conflict with reference designators in the schematic that have not yet been synchronized with the board.'; export function DIALOG_CREATE_ARRAY_BASE(p: DIALOG_CREATE_ARRAY_BASE_PROPS): JSX.Element { const text = (aLabel: string, e: ENTRY, aTitle?: string) => ( ); const evalText = (aLabel: string, e: ENTRY, aTitle?: string) => ( ); const radio = (aLabel: string, aGroup: string, r: RADIO, aTitle?: string) => ( ); // A UNIT_BINDER row of a wxFlexGridSizer( 0, 3, 5, 5 ): label, text, units. const unitRow = ( aLabel: string, e: ENTRY, aUnits: string, aTitle?: string, aCtrlFlag = CV | wxEXPAND, ) => ( <> {text(aLabel, e)} ); const gridPage = ( // bSizerGridArray {/* bSizerGridLeft */} {/* fgSizerGridSize = wxFlexGridSizer( 0, 2, 5, 5 ) */} {evalText('Horizontal count', p.m_entryNx)} {evalText('Vertical count', p.m_entryNy, 'Number of rows')} {/* fgSizerItemSpacing = wxFlexGridSizer( 0, 3, 5, 5 ) */} {unitRow('Horizontal spacing:', p.m_entryDx, p.units, 'Distance between columns')} {unitRow('Vertical spacing:', p.m_entryDy, p.units, 'Distance between rows')} {unitRow( 'Horizontal offset:', p.m_entryOffsetX, p.units, 'Offset added to the next row position.', )} {unitRow( 'Vertical offset:', p.m_entryOffsetY, p.units, 'Offset added to the next column position', )} {/* bSizerStaggerset */} {evalText('Stagger', p.m_entryStagger)} {radio('Rows', 'm_stagger', p.m_staggerRows)} {radio('Columns', 'm_stagger', p.m_staggerCols)} {radio('Source items remain in place', 'm_gridPosition', p.m_rbItemsRemainInPlace)} {radio('Centre on source items', 'm_gridPosition', p.m_rbCentreOnSource)} {/* m_gridPadNumberingPanel > bSizer15 */} {/* m_gridPadNumberingSizer */} {/* fgSizer1 = wxFlexGridSizer( 2, 3, 0, 0 ) */} {text('Primary numbering start', p.m_entryGridPriNumberingOffset)} {text('Secondary numbering start', p.m_entryGridSecNumberingOffset)} {text('Primary numbering increment', p.m_entryGridPriNumberingStep)} {text('Secondary numbering increment', p.m_entryGridSecNumberingStep)} ); const circularPage = ( // bSizer4 {/* bSizerCircLeft */} {/* fgSizerArrayPrms = wxFlexGridSizer( 0, 3, 5, 5 ) */} {text('Center pos X', p.m_entryCentreX)} {text('Center pos Y', p.m_entryCentreY)} {/* bSizer12 */}