This commit is contained in:
2026-09-09 18:06:21 +08:00
parent 161af68fe3
commit 45b9f9ed5d
79 changed files with 1167 additions and 1532 deletions
@@ -88,11 +88,11 @@
<h1 id="widgets">Widgets</h1>
<p>The reusable controls that pages embed rather than own. Each page here documents one control — most
of them under the SPA's <code>components/widgets/</code> directory — together with its WPF counterpart where one
exists, so a reader who meets the same control on four screens reads about it once.</p>
of them under the SPA's <code>components/widgets/</code> directory — so a reader who meets the same control on
four screens reads about it once.</p>
<p>A control earns a page here when more than one screen embeds it. A control that only ever appears
on one screen is documented on that screen's page instead.</p>
<p>Ordered by how widely each control is embedded across the two clients, most-embedded first.</p>
<p>Ordered by how widely each control is embedded, most-embedded first.</p>
<h2 id="pages">Pages</h2>
<ul>
<li><a href="numeric-input.html">Numeric Input</a> — The single-value numeric field every editor embeds: blur-and-Enter commit, inclusive bounds, and the Infinity and NaN spellings; the most widely embedded control in the app</li>
@@ -87,32 +87,8 @@
<article data-uid="Anatomy-PolarResolution2dPanel">
<h1 id="polar-resolution-2d-panel">Polar Resolution 2D Panel</h1>
<p>The model is <a class="xref" href="../../api/Hi.Geom.Resolution.PolarResolution2d.html">PolarResolution2d</a>: a linear step in millimetres plus an angular step, carried in radians and edited in degrees, that together tessellate a revolved shape into an STL mesh. Both clients edit it on a tool holder and nowhere else — the WPF client through this widget, the web client through the Cylindroid holder's Resolution section.</p>
<p>The model is <a class="xref" href="../../api/Hi.Geom.Resolution.PolarResolution2d.html">PolarResolution2d</a>: a linear step in millimetres plus an angular step, carried in radians and edited in degrees, that together tessellate a revolved shape into an STL mesh. It is edited on a tool holder and nowhere else, through the Cylindroid holder's Resolution section.</p>
<h2 id="layout">Layout</h2>
<h3 id="wpf-layout">WPF Layout</h3>
<ul>
<li>Polar Resolution 2D Panel
<ul>
<li>Enable Custom Resolution CheckBox
<ul>
<li>checked if the host model is not null; the checkbox itself is always clickable.</li>
<li>unchecking sets the host model to null; checking a null model publishes a fresh <a class="xref" href="../../api/Hi.Geom.Resolution.PolarResolution2d.html">PolarResolution2d</a> of 0.5 mm / 5 deg through the setter.</li>
</ul>
</li>
<li>Linear Resolution Input Field, with an <code>mm</code> suffix label
<ul>
<li>enabled if model not null</li>
</ul>
</li>
<li>Angle Resolution Input Field, with a degree-sign suffix label
<ul>
<li>enabled if model not null</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="web-layout">Web Layout</h3>
<ul>
<li>Holder Resolution Section
<ul>
@@ -122,14 +98,13 @@
</ul>
</li>
</ul>
<p>There is no enable checkbox and no null state on the web: both fields are always editable, and each commits on blur or Enter, and only when both values are greater than zero.</p>
<p>There is no enable checkbox and no null state: both fields are always editable, and each commits on blur or Enter, and only when both values are greater than zero.</p>
<h2 id="feature">Feature</h2>
<p>The Enable CheckBox is always shown. The host drives the WPF widget only through <code>GetterFunc</code> / <code>SetterFunc</code>; it calls <code>UpdateUI()</code> after its own model changes and subscribes to <code>OnModelChanged</code> to react to an edit.</p>
<p>An edit republishes a whole new carrier through the setter instead of mutating the current one, in either client. A holder's <a class="xref" href="../../api/Hi.NcMech.Holders.CylindroidHolder.html#Hi_NcMech_Holders_CylindroidHolder_PolarResolution2d">PolarResolution2d</a> setter swaps the holder's solid for one born with the new value and disposes the old one, and skips a value-equal reassignment — which is what makes the WPF widget's per-keystroke setting affordable. The web client performs the same swap server-side inside <code>SetPolarResolution</code>, then clears the holder's cache.</p>
<p>If the host model is null, it may mean the resolution applied the default value: <a class="xref" href="../../api/Hi.NcMech.Solids.Solid.html#Hi_NcMech_Solids_Solid_PolarResolution2d">PolarResolution2d</a> is a snapshot of the solid's identity, and a null carrier lets a parametric geometry apply its own default. Only the WPF client can reach that state. The service reports a null resolution as 0 mm / 0 deg, the two web fields display those zeros, and the commit guard then blocks any write until real numbers are typed.</p>
<p>An edit republishes a whole new carrier instead of mutating the current one. A holder's <a class="xref" href="../../api/Hi.NcMech.Holders.CylindroidHolder.html#Hi_NcMech_Holders_CylindroidHolder_PolarResolution2d">PolarResolution2d</a> setter swaps the holder's solid for one born with the new value and disposes the old one, and skips a value-equal reassignment; the same swap happens server-side inside <code>SetPolarResolution</code>, which then clears the holder's cache.</p>
<p>A null host model means the resolution applied the default value: <a class="xref" href="../../api/Hi.NcMech.Solids.Solid.html#Hi_NcMech_Solids_Solid_PolarResolution2d">PolarResolution2d</a> is a snapshot of the solid's identity, and a null carrier lets a parametric geometry apply its own default. Nothing on this surface can produce that state. The service reports a null resolution as 0 mm / 0 deg, the two fields display those zeros, and the commit guard then blocks any write until real numbers are typed.</p>
<h2 id="source-code-path">Source Code Path</h2>
<p>See <a class="xref" href="../index.html">HiNC App Anatomy</a> for git repository links.</p>
<p>HiNC-2025-webservice (Quasar CLI SPA): no standalone widget. The resolution is edited on the Cylindroid holder's Resolution section, at the Control-Tree id <code>toolhouse/tool-{id}/holder/resolution</code> and the route <code>/tool-house/:toolId/holder/resolution</code>. A Freeform holder grows no sections in the web client; its Holder panel shows a hint pointing at the WPF client instead.</p>
<p>HiNC-2025-webservice (Quasar CLI SPA): no standalone widget. The resolution is edited on the Cylindroid holder's Resolution section, at the Control-Tree id <code>toolhouse/tool-{id}/holder/resolution</code> and the route <code>/tool-house/:toolId/holder/resolution</code>. A Freeform holder grows no sections here; its Holder panel shows a hint saying the geometry is edited elsewhere.</p>
<ul>
<li><code>wwwroot-src/src/components/controlTree/toolhouse/HolderSectionPanel.vue</code> — the <code>section === 'resolution'</code> branch: the two number fields, seeded from <code>Get</code> and committed on blur / Enter.</li>
<li><code>wwwroot-src/src/components/controlTree/toolHouseItemTypes.ts</code> — registers that panel as the <code>HolderSection</code> item type and grows the Resolution node only for a <code>CylindroidHolder</code>.</li>
@@ -87,7 +87,7 @@
<article data-uid="Anatomy-RenderingCanvasToolBar">
<h1 id="renderingcanvas-tool-bar">RenderingCanvas Tool Bar</h1>
<p>The RenderingCanvas Tool Bar is the camera-preset menu that every 3D canvas in the app carries. In the WPF client the control holds a <a class="xref" href="../../api/Hi.Disp.DispEngine.html">DispEngine</a> and drives it directly from each menu click. On the web it holds no engine: it takes a <code>canvas</code> prop and calls that component's exposed <code>setView(name)</code>, which invokes the <code>SetView</code> hub method, and the hub is what drives the per-connection <a class="xref" href="../../api/Hi.Disp.DispEngine.html">DispEngine</a>.</p>
<p>The RenderingCanvas Tool Bar is the camera-preset menu that every 3D canvas in the app carries. It holds no engine of its own: it takes a <code>canvas</code> prop and calls that component's exposed <code>setView(name)</code>, which invokes the <code>SetView</code> hub method, and the hub is what drives the per-connection <a class="xref" href="../../api/Hi.Disp.DispEngine.html">DispEngine</a>.</p>
<h2 id="view-menu">View Menu</h2>
<p>The bar is a single <code>View ▾</code> menu. Its seven entries, in shipped order, are Isometric, Front, Back, Right, Left, Top and Bottom. The engine also understands a <code>home</code> view and <code>RenderingCanvas.vue</code> exposes <code>setViewToHomeView</code>, but this menu does not offer it.</p>
<table>
@@ -129,9 +129,9 @@
</tbody>
</table>
<h3 id="back-view-implementation">Back View Implementation</h3>
<p>Back / Left / Bottom views are composed by first calling the corresponding forward-view method (<code>SetViewToFrontView</code> / <code>SetViewToRightView</code> / <code>SetViewToTopView</code>) and then invoking <a class="xref" href="../../api/Hi.Disp.DispEngine.html#Hi_Disp_DispEngine_TurnBackView">TurnBackView()</a> to flip the camera about the view plane. Both clients compose them the same way — the web in the hub's <code>SetView</code> switch, WPF in the tool bar's click handlers.</p>
<p>Back / Left / Bottom views are composed by first calling the corresponding forward-view method (<code>SetViewToFrontView</code> / <code>SetViewToRightView</code> / <code>SetViewToTopView</code>) and then invoking <a class="xref" href="../../api/Hi.Disp.DispEngine.html#Hi_Disp_DispEngine_TurnBackView">TurnBackView()</a> to flip the camera about the view plane, composed in the hub's <code>SetView</code> switch.</p>
<h3 id="canvas-binding">Canvas Binding</h3>
<p>On the web the tool bar declares exactly one prop, a nullable <code>canvas</code>, typed structurally as an object exposing <code>setView(v: string): Promise&lt;void&gt;</code> rather than as the <code>RenderingCanvas</code> component type. Every entry calls it optionally, so a tool bar with no canvas bound still opens and each entry is a no-op. The preset names travel to the hub untranslated; only the row labels are localized, from the <code>widgets.canvas.*</code> keys.</p>
<p>The tool bar declares exactly one prop, a nullable <code>canvas</code>, typed structurally as an object exposing <code>setView(v: string): Promise&lt;void&gt;</code> rather than as the <code>RenderingCanvas</code> component type. Every entry calls it optionally, so a tool bar with no canvas bound still opens and each entry is a no-op. The preset names travel to the hub untranslated; only the row labels are localized, from the <code>widgets.canvas.*</code> keys.</p>
<h2 id="scene-menu">Scene Menu</h2>
<p>Pages that sit next to a <code>RenderingCanvas</code> surface a per-page <code>Scene ▾</code> menu button — the <code>DisplayOptionsMenu</code> component, labelled from <code>widgets.canvas.scene</code> because no caller overrides the label. It chooses what the 3D scene draws (solids, coordinates, display aids), as distinct from the camera-oriented <code>View ▾</code> menu beside it. The layout (header + checkboxes + radio rows) is shared across four callers — the Execution page's extended tool bar, the General Setup equipment panel, the Tool House setup panel and the STL preview pane — so it is implemented once as a generic, schema-driven component.</p>
<h3 id="schema">Schema</h3>
@@ -154,10 +154,6 @@
</li>
<li>Backends — one per caller, each a different surface: <code>ExecutionExtendedToolBar.vue</code> reaches <code>/api/rendering-flags</code> (<code>Common/RenderingFlagsController.cs</code>), which flips bits in <code>ExecutionDisplayee.RenderingFlagBitArray</code>; <code>EquipmentSetupPanel.vue</code> reaches <code>/api/mech/equipment-setup-display/*</code> (<code>Mech/EquipmentSetupDisplayController.cs</code>); <code>ToolHouseSetupPanel.vue</code> reaches <code>/api/mech/tool-house-display/*</code> (<code>Mech/ToolHouseDisplayController.cs</code>); <code>StlPreviewPane.vue</code> reaches <code>/api/stl-preview/set-coordinate/*</code> (<code>Disp/StlPreviewController.cs</code>). Those last three route each POST by the caller's <code>renderingConnectionId</code>, so the toggle lands on that canvas's own engine; the rendering-flags surface carries no connection id and acts on the project-wide <code>ExecutionDisplayee</code> instead. <code>DisplayOptionsMenu.vue</code> is UI-only; it does no REST work itself — the caller owns the <code>onUpdate</code> handlers, so optimistic update and error reversion stay page-local.</li>
</ul>
<h3 id="wpf">WPF</h3>
<ul>
<li><code>Play/RenderingFlagSubmenu.xaml</code> — the shared flag submenu, wrapped per surface by <code>Numerical/Controller/ControllerExtendedRenderingCanvasToolBar.xaml</code> and <code>Play/PlayerExtendedRenderingCanvasToolBar.xaml</code>. Behaviour parity with the web <code>Scene ▾</code> menu; no schema-driven composition.</li>
</ul>
<h2 id="source-code-path">Source Code Path</h2>
<p>See <a class="xref" href="../index.html">HiNC App Anatomy</a> for git repository links.</p>
<p>HiNC-2025-webservice (Quasar CLI SPA):</p>
@@ -91,21 +91,17 @@
and no Control-Tree node of its own, reached only through the editors that host it.</p>
<h2 id="key-model">Key Model</h2>
<p>The persisted model is <a class="xref" href="../../api/Hi.Geom.Vec3d.html">Vec3d</a>, exposed over <code>/api/Vec3d</code> by <code>Widget/Vec3dController.cs</code>.</p>
<p>In the web application the widget's own model is the plain <code>{ x, y, z }</code> number triple exported as
<p>The widget's own model is the plain <code>{ x, y, z }</code> number triple exported as
<code>interface Vec3</code> from <code>wwwroot-src/src/components/widgets/Vec3Input.vue</code>. The widget carries no key
and calls no endpoint: the host binds it with <code>v-model</code> plus an <code>@update:model-value</code> handler, and
that handler does the persisting, each host on its own terms. The four transformer editors call
<code>updateVec3d</code> from <code>wwwroot-src/src/api/geometry.ts</code>, which posts all three axes together to
<code>/api/Vec3d/Update</code>, while <code>wwwroot-src/src/components/geom/Box3dEditor.vue</code> folds the edited triple
back into a min and max pair and posts that to <code>/api/Box3d/Update</code>.</p>
<p>The WPF control likewise holds no value of its own. <code>GetterFunc</code> returns the live
<a class="xref" href="../../api/Hi.Geom.Vec3d.html">Vec3d</a> instance, the text handlers write the parsed numbers straight onto it, and
<code>UpdateByContentFunc</code> is awaited afterwards so the host can push the change on.</p>
<p>The web props are <code>modelValue</code>, <code>disable</code>, <code>readonly</code>, <code>normalize</code>, <code>labels</code> and <code>textMode</code>, and the
<p>The props are <code>modelValue</code>, <code>disable</code>, <code>readonly</code>, <code>normalize</code>, <code>labels</code> and <code>textMode</code>, and the
emits are <code>update:modelValue</code> and <code>normalize</code>. <code>labels</code> is a three-tuple defaulting to
<code>['X', 'Y', 'Z']</code>, and carries units where the host has them, as in <code>['X (mm)', 'Y (mm)', 'Z (mm)']</code>.
<code>textMode</code> sets the initial mode only and defaults to false. The corresponding WPF properties are
<code>ShowNormalizeButton</code>, <code>IsTextMode</code> and <code>IsReadOnly</code>.</p>
<code>textMode</code> sets the initial mode only and defaults to false.</p>
<h2 id="layout">Layout</h2>
<ul>
<li>Vec3dControl
@@ -119,496 +115,28 @@ control is disabled or readonly</li>
</ul>
</li>
</ul>
<p>In the WPF client the two forms are two panels, <code>StandardModePanel</code> and <code>TextModePanel</code>, of which
exactly one is visible; each panel carries its own mode-toggle and normalize buttons.</p>
<h2 id="feature">Feature</h2>
<h3 id="per-axis-form">Per-axis form</h3>
<p>X, Y and Z in three separate fields. The web widget renders every finite value at full precision;
the WPF control renders each axis with a fixed three decimal places.</p>
<p>X, Y and Z in three separate fields, each rendering every finite value at full precision.</p>
<h3 id="single-field-text-form">Single-field text form</h3>
<p>The web form is <code>(x, y, z)</code>. Its parser strips surrounding brackets and splits on comma, semicolon
<p>The form is <code>(x, y, z)</code>. Its parser strips surrounding brackets and splits on comma, semicolon
or whitespace, requiring at least three parts, and entering the text form re-syncs the field from
the current value so a stale in-progress edit is discarded. The WPF text box holds comma-separated
<code>x,y,z</code> without brackets and accepts two further shapes: a pasted 4x4 matrix, from which it takes
the translation column, and loose text, from which it takes the first three numbers it can read.</p>
the current value so a stale in-progress edit is discarded.</p>
<h3 id="vector-normalization">Vector normalization</h3>
<p>The normalize button is opt-in and off by default in both clients: the <code>normalize</code> prop in the web
widget, the <code>ShowNormalizeButton</code> property in the WPF control.</p>
<p>In the web widget the button only raises a <code>normalize</code> event, and the embedding editor performs the
<p>The normalize button is opt-in and off by default, through the <code>normalize</code> prop.</p>
<p>The button only raises a <code>normalize</code> event, and the embedding editor performs the
normalization on its own owning object. <code>wwwroot-src/src/components/topo/StaticRotationEditor.vue</code>
posts to <code>/api/StaticRotation/NormalizeAxis</code>, while
<code>wwwroot-src/src/components/topo/DynamicRotationEditor.vue</code> and
<code>wwwroot-src/src/components/topo/DynamicTranslationEditor.vue</code> call <code>normalizeDynamicRotationAxis</code>
and <code>normalizeDynamicTranslationAxis</code> from <code>wwwroot-src/src/api/transformer.ts</code>. The WPF control
normalizes the vector in place and writes the result back at three decimal places.</p>
and <code>normalizeDynamicTranslationAxis</code> from <code>wwwroot-src/src/api/transformer.ts</code>.</p>
<h3 id="commit-and-special-values">Commit and special values</h3>
<p>Web edits commit on blur or Enter, never per keystroke, and a value is emitted only when it differs
<p>Edits commit on blur or Enter, never per keystroke, and a value is emitted only when it differs
from the current model. An empty field parses to 0; any other unparseable text reverts the field to
the last valid value. Formatting and parsing are local to the component: NaN renders as <code>NaN</code> and
the infinities as <code>Infinity</code> and <code>-Infinity</code>, and the parser accepts those spellings
case-insensitively as well as the <code>∞</code> and <code>-∞</code> glyphs. The WPF control commits on every keystroke
instead, leaving the model untouched while the text is unparseable so that a half-typed number is
not treated as an error.</p>
<h2 id="refer-sample-code">Refer Sample Code</h2>
<pre><code class="lang-csharp" name="SampleCode-xaml">&lt;UserControl x:Class=&quot;HiNC_2025_win_desktop.Geom.Vec3dControl&quot;
xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
mc:Ignorable=&quot;d&quot;
d:DesignHeight=&quot;30&quot; d:DesignWidth=&quot;200&quot;&gt;
&lt;Grid&gt;
&lt;Grid.ColumnDefinitions&gt;
&lt;ColumnDefinition Width=&quot;*&quot;/&gt;
&lt;ColumnDefinition Width=&quot;*&quot;/&gt;
&lt;ColumnDefinition Width=&quot;*&quot;/&gt;
&lt;ColumnDefinition Width=&quot;Auto&quot;/&gt;
&lt;ColumnDefinition Width=&quot;Auto&quot;/&gt;
&lt;/Grid.ColumnDefinitions&gt;
&lt;!-- Standard Mode Panel --&gt;
&lt;StackPanel x:Name=&quot;StandardModePanel&quot; Orientation=&quot;Horizontal&quot; Grid.ColumnSpan=&quot;5&quot;&gt;
&lt;TextBox x:Name=&quot;XTextBox&quot; Width=&quot;60&quot; Margin=&quot;0,0,2,0&quot; TextChanged=&quot;XTextBox_TextChanged&quot; IsReadOnly=&quot;{Binding IsReadOnly}&quot;/&gt;
&lt;TextBox x:Name=&quot;YTextBox&quot; Width=&quot;60&quot; Margin=&quot;0,0,2,0&quot; TextChanged=&quot;YTextBox_TextChanged&quot; IsReadOnly=&quot;{Binding IsReadOnly}&quot;/&gt;
&lt;TextBox x:Name=&quot;ZTextBox&quot; Width=&quot;60&quot; Margin=&quot;0,0,2,0&quot; TextChanged=&quot;ZTextBox_TextChanged&quot; IsReadOnly=&quot;{Binding IsReadOnly}&quot;/&gt;
&lt;Button Content=&quot;{DynamicResource Vec3d_TextMode_Toggle}&quot; Width=&quot;20&quot; Click=&quot;TextModeToggle_Click&quot; Margin=&quot;0,0,2,0&quot; ToolTip=&quot;{DynamicResource Vec3d_TextMode_Tooltip}&quot;/&gt;
&lt;Button Content=&quot;{DynamicResource Vec3d_Normalize}&quot; Width=&quot;20&quot; Click=&quot;NormalizeButton_Click&quot; Visibility=&quot;{Binding ShowNormalizeButton, Converter={StaticResource BooleanToVisibilityConverter}}&quot; ToolTip=&quot;{DynamicResource Vec3d_Normalize_Tooltip}&quot;/&gt;
&lt;/StackPanel&gt;
&lt;!-- Text Mode Panel --&gt;
&lt;StackPanel x:Name=&quot;TextModePanel&quot; Orientation=&quot;Horizontal&quot; Grid.ColumnSpan=&quot;5&quot; Visibility=&quot;Collapsed&quot;&gt;
&lt;TextBox x:Name=&quot;VectorTextBox&quot; Width=&quot;180&quot; Margin=&quot;0,0,2,0&quot; TextChanged=&quot;VectorTextBox_TextChanged&quot; IsReadOnly=&quot;{Binding IsReadOnly}&quot;
ToolTip=&quot;{DynamicResource Vec3d_TextMode_Format_Tooltip}&quot;/&gt;
&lt;Button Content=&quot;{DynamicResource Vec3d_StandardMode_Toggle}&quot; Width=&quot;20&quot; Click=&quot;StandardModeToggle_Click&quot; Margin=&quot;0,0,2,0&quot; ToolTip=&quot;{DynamicResource Vec3d_StandardMode_Tooltip}&quot;/&gt;
&lt;Button Content=&quot;{DynamicResource Vec3d_Normalize}&quot; Width=&quot;20&quot; Click=&quot;NormalizeButton_Click&quot; Visibility=&quot;{Binding ShowNormalizeButton, Converter={StaticResource BooleanToVisibilityConverter}}&quot; ToolTip=&quot;{DynamicResource Vec3d_Normalize_Tooltip}&quot;/&gt;
&lt;/StackPanel&gt;
&lt;/Grid&gt;
&lt;/UserControl&gt;
</code></pre><pre><code class="lang-csharp" name="SampleCode-xaml.cs">using System;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using Hi.Geom;
using System.Text.RegularExpressions;
using System.ComponentModel;
using Hi.Common;
using Hi.Common.Messages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
namespace HiNC_2025_win_desktop.Geom
{
/// &lt;summary&gt;
/// Vec3dControl.xaml 的交互逻辑
/// &lt;/summary&gt;
public partial class Vec3dControl : UserControl, INotifyPropertyChanged
{
private bool _isUpdating = false;
private Func&lt;Vec3d&gt; _getterFunc;
private Func&lt;Task&gt; _updateByContentFunc;
private bool _showNormalizeButton = false;
private bool _isTextMode = false;
private bool _isReadOnly = false;
private readonly ILogger&lt;Vec3dControl&gt; _logger = App.ServiceProvider.GetRequiredService&lt;ILogger&lt;Vec3dControl&gt;&gt;();
private static readonly Regex VectorRegex = new Regex(@&quot;^\s*[\(\[\{]?\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*[\)\]\}]?\s*$&quot;, RegexOptions.Compiled);
private static readonly Regex MatrixRegex = new Regex(@&quot;\{(?:\s*\{?\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*\}?\s*,){3}\s*\{?\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*,\s*(-?\d*\.?\d+)\s*\}?\s*\}&quot;, RegexOptions.Compiled);
public event PropertyChangedEventHandler PropertyChanged;
public string ControlId { get; set; } = Guid.NewGuid().ToString();
public Func&lt;Vec3d&gt; GetterFunc
{
get =&gt; _getterFunc;
set
{
_getterFunc = value;
UpdateUI();
}
}
public Func&lt;Task&gt; UpdateByContentFunc
{
get =&gt; _updateByContentFunc;
set =&gt; _updateByContentFunc = value;
}
public bool ShowNormalizeButton
{
get =&gt; _showNormalizeButton;
set
{
if (_showNormalizeButton != value)
{
_showNormalizeButton = value;
OnPropertyChanged(nameof(ShowNormalizeButton));
}
}
}
public bool IsTextMode
{
get =&gt; _isTextMode;
set
{
if (_isTextMode != value)
{
_isTextMode = value;
UpdateModeVisibility();
OnPropertyChanged(nameof(IsTextMode));
}
}
}
public bool IsReadOnly
{
get =&gt; _isReadOnly;
set
{
if (_isReadOnly != value)
{
_isReadOnly = value;
OnPropertyChanged(nameof(IsReadOnly));
}
}
}
protected void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public Vec3dControl()
{
InitializeComponent();
DataContext = this;
}
private void UpdateModeVisibility()
{
if (IsTextMode)
{
StandardModePanel.Visibility = Visibility.Collapsed;
TextModePanel.Visibility = Visibility.Visible;
UpdateVectorTextFromXYZ();
}
else
{
StandardModePanel.Visibility = Visibility.Visible;
TextModePanel.Visibility = Visibility.Collapsed;
}
}
private void UpdateVectorTextFromXYZ()
{
if (_isUpdating) return;
if (double.TryParse(XTextBox.Text, out double x) &amp;&amp;
double.TryParse(YTextBox.Text, out double y) &amp;&amp;
double.TryParse(ZTextBox.Text, out double z))
{
VectorTextBox.Text = $&quot;{x},{y},{z}&quot;;
}
}
private void TextModeToggle_Click(object sender, RoutedEventArgs e)
{
IsTextMode = true;
}
private void StandardModeToggle_Click(object sender, RoutedEventArgs e)
{
IsTextMode = false;
}
private async void NormalizeButton_Click(object sender, RoutedEventArgs e)
{
if (_isUpdating || _getterFunc == null || IsReadOnly)
return;
try
{
_isUpdating = true;
var vec = _getterFunc();
if (vec != null)
{
vec.Normalize();
XTextBox.Text = vec.X.ToString(&quot;F3&quot;);
YTextBox.Text = vec.Y.ToString(&quot;F3&quot;);
ZTextBox.Text = vec.Z.ToString(&quot;F3&quot;);
if (IsTextMode)
{
VectorTextBox.Text = $&quot;{vec.X:F3},{vec.Y:F3},{vec.Z:F3}&quot;;
}
if(_updateByContentFunc != null)
await _updateByContentFunc();
}
}
catch (Exception ex)
{
_logger.LogWarning(string.Format(Application.Current.FindResource(&quot;Vec3d_Update_Error&quot;).ToString(), ex.Message));
_logger.LogError(ex, &quot;{Message}&quot;, ex.Message);
}
finally
{
_isUpdating = false;
}
}
public void UpdateUI()
{
if (_isUpdating || _getterFunc == null)
return;
try
{
_isUpdating = true;
var vec = _getterFunc();
if (vec != null)
{
XTextBox.Text = vec.X.ToString(&quot;F3&quot;);
YTextBox.Text = vec.Y.ToString(&quot;F3&quot;);
ZTextBox.Text = vec.Z.ToString(&quot;F3&quot;);
if (IsTextMode)
{
VectorTextBox.Text = $&quot;{vec.X},{vec.Y},{vec.Z}&quot;;
}
}
else
{
XTextBox.Text = &quot;&quot;;
YTextBox.Text = &quot;&quot;;
ZTextBox.Text = &quot;&quot;;
VectorTextBox.Text = &quot;&quot;;
}
}
finally
{
_isUpdating = false;
}
}
private async void XTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
await HandleTextChanged();
}
private async void YTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
await HandleTextChanged();
}
private async void ZTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
await HandleTextChanged();
}
private async void VectorTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (_isUpdating || _getterFunc == null || IsReadOnly)
return;
try
{
string text = VectorTextBox.Text.Trim();
// 如果文本为空或太短,不做处理
if (string.IsNullOrWhiteSpace(text) || text.Length &lt; 3)
return;
_isUpdating = true;
// 尝试解析为向量格式
if (TryParseVector(text, out double x, out double y, out double z))
{
await UpdateVectorValues(x, y, z);
}
// 尝试解析为变换矩阵格式(仅提取位移分量)
else if (TryParseTransformMatrix(text, out double tx, out double ty, out double tz))
{
await UpdateVectorValues(tx, ty, tz);
}
// 尝试作为单值解析每个字段(宽松模式)
else if (TryParseLooseVector(text, out double lx, out double ly, out double lz))
{
await UpdateVectorValues(lx, ly, lz);
}
}
catch (Exception ex)
{
_logger.LogWarning(string.Format(Application.Current.FindResource(&quot;Vec3d_Update_Error&quot;).ToString(), ex.Message));
_logger.LogError(ex, &quot;{Message}&quot;, ex.Message);
}
finally
{
_isUpdating = false;
}
}
private bool TryParseVector(string text, out double x, out double y, out double z)
{
x = y = z = 0;
// 使用正则表达式匹配向量格式
Match match = VectorRegex.Match(text);
if (match.Success &amp;&amp; match.Groups.Count &gt;= 4)
{
if (double.TryParse(match.Groups[1].Value, out x) &amp;&amp;
double.TryParse(match.Groups[2].Value, out y) &amp;&amp;
double.TryParse(match.Groups[3].Value, out z))
{
return true;
}
}
return false;
}
private bool TryParseTransformMatrix(string text, out double tx, out double ty, out double tz)
{
tx = ty = tz = 0;
// 移除所有换行和多余空格,便于匹配
text = Regex.Replace(text, @&quot;\s+&quot;, &quot; &quot;);
// 尝试匹配变换矩阵格式
Match match = MatrixRegex.Match(text);
if (match.Success &amp;&amp; match.Groups.Count &gt;= 8)
{
// 变换矩阵的第4列通常是位移分量
if (double.TryParse(match.Groups[4].Value, out tx) &amp;&amp;
double.TryParse(match.Groups[8].Value, out ty) &amp;&amp;
double.TryParse(match.Groups[12].Value, out tz))
{
return true;
}
}
// 尝试匹配更宽松的变换矩阵表示(例如从界面复制的数据)
var numbers = Regex.Matches(text, @&quot;(-?\d*\.?\d+)&quot;);
if (numbers.Count &gt;= 16)
{
// 假设这是一个4x4矩阵,提取位移分量(第4、8、12个数字)
if (double.TryParse(numbers[3].Value, out tx) &amp;&amp;
double.TryParse(numbers[7].Value, out ty) &amp;&amp;
double.TryParse(numbers[11].Value, out tz))
{
return true;
}
}
return false;
}
private bool TryParseLooseVector(string text, out double x, out double y, out double z)
{
x = y = z = 0;
// 移除所有非数字和小数点以外的字符,然后按空白分割
string cleanText = Regex.Replace(text, @&quot;[^\d\.\-\s,;]+&quot;, &quot; &quot;);
string[] parts = Regex.Split(cleanText, @&quot;[\s,;]+&quot;);
// 尝试从分割后的部分获取三个数字
var numbers = new System.Collections.Generic.List&lt;double&gt;();
foreach (var part in parts)
{
if (!string.IsNullOrWhiteSpace(part) &amp;&amp; double.TryParse(part, out double value))
{
numbers.Add(value);
if (numbers.Count &gt;= 3) break; // 最多取3个数字
}
}
// 如果获取到了三个数字,就认为解析成功
if (numbers.Count &gt;= 3)
{
x = numbers[0];
y = numbers[1];
z = numbers[2];
return true;
}
return false;
}
private async Task UpdateVectorValues(double x, double y, double z)
{
XTextBox.Text = x.ToString(&quot;F3&quot;);
YTextBox.Text = y.ToString(&quot;F3&quot;);
ZTextBox.Text = z.ToString(&quot;F3&quot;);
var vec = _getterFunc?.Invoke();
if (vec != null)
{
vec.X = x;
vec.Y = y;
vec.Z = z;
if (_updateByContentFunc != null)
{
await _updateByContentFunc();
}
}
}
private async Task HandleTextChanged()
{
if (_isUpdating || _getterFunc == null || IsReadOnly)
return;
try
{
_isUpdating = true;
// 尝试解析每个文本框的值
bool allValid = true;
allValid &amp;= double.TryParse(XTextBox.Text, out double x);
allValid &amp;= double.TryParse(YTextBox.Text, out double y);
allValid &amp;= double.TryParse(ZTextBox.Text, out double z);
if (allValid)
{
if (IsTextMode)
{
VectorTextBox.Text = $&quot;{x},{y},{z}&quot;;
}
var vec = _getterFunc();
if (vec != null)
{
vec.X = x;
vec.Y = y;
vec.Z = z;
if(_updateByContentFunc != null)
await _updateByContentFunc();
}
}
else
{
// 如果有无效输入,不进行更新但也不显示错误
// 这允许用户在输入过程中有不完整的状态
}
}
catch (Exception ex)
{
// 记录异常但不中断用户操作
_logger.LogWarning(string.Format(Application.Current.FindResource(&quot;Vec3d_Update_Error&quot;).ToString(), ex.Message));
_logger.LogError(ex, &quot;{Message}&quot;, ex.Message);
}
finally
{
_isUpdating = false;
}
}
}
}
</code></pre><h2 id="source-code-path">Source Code Path</h2>
case-insensitively as well as the <code>∞</code> and <code>-∞</code> glyphs.</p>
<h2 id="source-code-path">Source Code Path</h2>
<p>See <a class="xref" href="../index.html">HiNC App Anatomy</a> for git repository links.</p>
<ul>
<li><code>wwwroot-src/src/components/widgets/Vec3Input.vue</code> — the widget itself: mode toggle, per-axis and