Commit 5842d780 authored by fenghen777's avatar fenghen777

chore: 提交所有待定修改

parent 22002153
...@@ -458,7 +458,7 @@ export default function ComponentEditor() { ...@@ -458,7 +458,7 @@ export default function ComponentEditor() {
onChange={(e) => { onChange={(e) => {
const params = [...editingTemplate.params]; const params = [...editingTemplate.params];
const newType = e.target.value; const newType = e.target.value;
const autoDefault = newType === 'bool' ? true : newType === 'int' ? 0 : newType === 'real' ? 0 : ''; const autoDefault = newType === 'bool' ? true : newType === 'int' ? 0 : newType === 'real' ? 0 : newType === 'select' ? '' : '';
params[i] = { ...params[i], type: newType, defaultValue: autoDefault }; params[i] = { ...params[i], type: newType, defaultValue: autoDefault };
updateEditing({ params }); updateEditing({ params });
}} }}
...@@ -467,6 +467,7 @@ export default function ComponentEditor() { ...@@ -467,6 +467,7 @@ export default function ComponentEditor() {
<option value="int">int</option> <option value="int">int</option>
<option value="real">real</option> <option value="real">real</option>
<option value="string">string</option> <option value="string">string</option>
<option value="select">select</option>
</select> </select>
</div> </div>
<div> <div>
...@@ -498,6 +499,21 @@ export default function ComponentEditor() { ...@@ -498,6 +499,21 @@ export default function ComponentEditor() {
<option value="true">true</option> <option value="true">true</option>
<option value="false">false</option> <option value="false">false</option>
</select> </select>
) : (p.type === 'select' && p.options?.length > 0) ? (
<select
className={styles.propInput}
value={String(p.defaultValue ?? '')}
style={{ fontSize: 10 }}
onChange={(e) => {
const params = [...editingTemplate.params];
params[i] = { ...params[i], defaultValue: e.target.value };
updateEditing({ params });
}}
>
{p.options.map(opt => (
<option key={opt.value} value={opt.value}>{opt.label}</option>
))}
</select>
) : ( ) : (
<input <input
className={styles.propInput} className={styles.propInput}
...@@ -521,6 +537,63 @@ export default function ComponentEditor() { ...@@ -521,6 +537,63 @@ export default function ComponentEditor() {
>&#10005;</button> >&#10005;</button>
</div> </div>
{/* select 类型选项编辑 */}
{p.type === 'select' && (
<div style={{ marginTop: 4, padding: '6px 8px', background: 'rgba(99,102,241,0.06)', borderRadius: 4, border: '1px solid #2a2a3a' }}>
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 4 }}>
<span style={{ fontSize: 9, color: '#888' }}>选项 ({(p.options || []).length})</span>
<button
style={{ background: 'none', border: '1px solid #333', borderRadius: 3, color: '#6366f1', fontSize: 9, cursor: 'pointer', padding: '0 4px' }}
onClick={() => {
const params = [...editingTemplate.params];
const opts = [...(params[i].options || [])];
opts.push({ value: `opt${opts.length + 1}`, label: `选项${opts.length + 1}` });
params[i] = { ...params[i], options: opts, defaultValue: params[i].defaultValue || opts[0]?.value || '' };
updateEditing({ params });
}}
>+ 添加</button>
</div>
{(p.options || []).map((opt, oi) => (
<div key={oi} style={{ display: 'grid', gridTemplateColumns: '1fr 1fr auto', gap: 4, marginBottom: 2 }}>
<input
className={styles.propInput}
value={opt.value}
placeholder="值"
style={{ fontSize: 9 }}
onChange={(e) => {
const params = [...editingTemplate.params];
const opts = [...(params[i].options || [])];
opts[oi] = { ...opts[oi], value: e.target.value };
params[i] = { ...params[i], options: opts };
updateEditing({ params });
}}
/>
<input
className={styles.propInput}
value={opt.label}
placeholder="显示名"
style={{ fontSize: 9 }}
onChange={(e) => {
const params = [...editingTemplate.params];
const opts = [...(params[i].options || [])];
opts[oi] = { ...opts[oi], label: e.target.value };
params[i] = { ...params[i], options: opts };
updateEditing({ params });
}}
/>
<button
style={{ background: 'none', border: 'none', color: '#666', cursor: 'pointer', fontSize: 10, padding: 0 }}
onClick={() => {
const params = [...editingTemplate.params];
const opts = (params[i].options || []).filter((_, j) => j !== oi);
params[i] = { ...params[i], options: opts };
updateEditing({ params });
}}
></button>
</div>
))}
</div>
)}
</div> </div>
))} ))}
</div> </div>
......
...@@ -403,6 +403,8 @@ ...@@ -403,6 +403,8 @@
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-all; word-break: break-all;
line-height: 1.5; line-height: 1.5;
user-select: text;
cursor: text;
} }
.logError { .logError {
......
...@@ -182,6 +182,16 @@ export default function PropertiesPanel() { ...@@ -182,6 +182,16 @@ export default function PropertiesPanel() {
<option value="true">true</option> <option value="true">true</option>
<option value="false">false</option> <option value="false">false</option>
</select> </select>
) : pType === 'select' && p.options ? (
<select
className={styles.input}
value={val ?? ''}
onChange={(e) => updateNodeParam(selectedNode.id, p.key, e.target.value)}
>
{p.options.map(opt => (
<option key={opt.value} value={opt.value}>{opt.label}</option>
))}
</select>
) : ( ) : (
<input <input
className={styles.input} className={styles.input}
......
...@@ -97,7 +97,7 @@ export default function SimResultsModal({ csvData, modelName, onClose }) { ...@@ -97,7 +97,7 @@ export default function SimResultsModal({ csvData, modelName, onClose }) {
}, [headers]); }, [headers]);
const xKey = headers[xIdx] || 'time'; const xKey = headers[xIdx] || 'time';
const variables = useMemo(() => const variables = useMemo(() =>
headers.map((h, i) => ({ name: h, index: i })).filter((_, i) => i !== xIdx), headers.map((h, i) => ({ name: h, index: i })).filter((v, i) => i !== xIdx && !/\.\b[pn]\b\./.test(v.name)),
[headers, xIdx]); [headers, xIdx]);
useEffect(() => { useEffect(() => {
......
...@@ -196,6 +196,25 @@ export const DEVICE_CATEGORIES = [ ...@@ -196,6 +196,25 @@ export const DEVICE_CATEGORIES = [
{ key: 'closed', label: '初始状态', type: 'bool', unit: '', defaultValue: false }, { key: 'closed', label: '初始状态', type: 'bool', unit: '', defaultValue: false },
], ],
}, },
{
code: 1008, type: 'signal_generator', label: '信号发生器', color: '#E040FB', icon: '∿',
width: 140, height: 100,
ports: [
{ id: 'p-pos', name: 'V+', side: 'left', position: 0.5, type: 'power', connector: 'p' },
{ id: 'p-neg', name: 'V-', side: 'right', position: 0.5, type: 'power', connector: 'n' },
],
params: [
{ key: 'waveform', label: '波形', type: 'select', unit: '', defaultValue: 'sine',
options: [
{ value: 'sine', label: '正弦波' },
{ value: 'square', label: '方波' },
],
},
{ key: 'amplitude', label: '幅值', type: 'real', unit: 'V', defaultValue: 5 },
{ key: 'frequency', label: '频率', type: 'real', unit: 'Hz', defaultValue: 50 },
{ key: 'offset', label: '直流偏置', type: 'real', unit: 'V', defaultValue: 0 },
],
},
], ],
}, },
{ {
......
...@@ -46,6 +46,10 @@ const MODEL_MAP = { ...@@ -46,6 +46,10 @@ const MODEL_MAP = {
portMap: { 'p-in': 'p', 'p-out': 'n' }, portMap: { 'p-in': 'p', 'p-out': 'n' },
controlVar: 'closed', // IdealSwitch.mo: parameter Boolean closed controlVar: 'closed', // IdealSwitch.mo: parameter Boolean closed
}, },
signal_generator: {
modelName: 'SignalGenerator',
portMap: { 'p-pos': 'p', 'p-neg': 'n' },
},
// ===== 电气控制 ===== // ===== 电气控制 =====
terminal: { terminal: {
......
...@@ -155,17 +155,22 @@ export function exportToModelica(data, modelName = 'Circuit') { ...@@ -155,17 +155,22 @@ export function exportToModelica(data, modelName = 'Circuit') {
(td?.params || []).forEach(p => { (td?.params || []).forEach(p => {
const rawVal = pv[p.key]; const rawVal = pv[p.key];
if (rawVal != null && rawVal !== '') { if (rawVal != null && rawVal !== '') {
// 下拉选择参数:加 Modelica 双引号
if (p.type === 'select') {
paramParts.push(`${p.key}="${rawVal}"`);
// 布尔值直接透传 (Modelica 支持 true/false) // 布尔值直接透传 (Modelica 支持 true/false)
const lower = String(rawVal).toLowerCase();
if (lower === 'true' || lower === 'false') {
paramParts.push(`${p.key}=${lower}`);
} else { } else {
const numVal = parseEngValue(rawVal); const lower = String(rawVal).toLowerCase();
if (numVal != null) { if (lower === 'true' || lower === 'false') {
paramParts.push(`${p.key}=${formatMoValue(numVal)}`); paramParts.push(`${p.key}=${lower}`);
} else { } else {
paramParts.push(`${p.key}=${rawVal}`); const numVal = parseEngValue(rawVal);
warnings.push(`"${label}".${p.key} = "${rawVal}" 无法解析为数值`); if (numVal != null) {
paramParts.push(`${p.key}=${formatMoValue(numVal)}`);
} else {
paramParts.push(`${p.key}=${rawVal}`);
warnings.push(`"${label}".${p.key} = "${rawVal}" 无法解析为数值`);
}
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment