feat: Enhance equipment components with pin functionality and constraint management
- Added pin support to MechanicalButton, enabling pin-click events and componentId handling. - Updated Pin component to manage constraint states and colors dynamically. - Integrated SMT_LED with pin functionality, allowing LED state to respond to constraints. - Enhanced Wire component to reflect constraint colors and manage wire states based on pin connections. - Introduced wireManager for managing wire states and constraints. - Implemented a constraints store for managing and notifying constraint state changes across components. - Updated component configuration to remove appearance options and clarify constraint descriptions. - Improved ProjectView to handle optional chaining for props and ensure robust data handling. - Initialized constraint communication in main application entry point.
This commit is contained in:
82
src/stores/constraints.ts
Normal file
82
src/stores/constraints.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { ref, reactive } from 'vue';
|
||||
|
||||
// 约束电平状态类型
|
||||
export type ConstraintLevel = 'high' | 'low' | 'undefined';
|
||||
|
||||
// 约束状态存储
|
||||
const constraintStates = reactive<Record<string, ConstraintLevel>>({});
|
||||
|
||||
// 约束颜色映射
|
||||
export const constraintColors = {
|
||||
high: '#ff3333', // 高电平为红色
|
||||
low: '#3333ff', // 低电平为蓝色
|
||||
undefined: '#999999' // 未定义为灰色
|
||||
};
|
||||
|
||||
// 获取约束状态
|
||||
export function getConstraintState(constraint: string): ConstraintLevel {
|
||||
if (!constraint) return 'undefined';
|
||||
return constraintStates[constraint] || 'undefined';
|
||||
}
|
||||
|
||||
// 设置约束状态
|
||||
export function setConstraintState(constraint: string, level: ConstraintLevel) {
|
||||
if (!constraint) return;
|
||||
constraintStates[constraint] = level;
|
||||
}
|
||||
|
||||
// 批量设置约束状态
|
||||
export function batchSetConstraintStates(states: Record<string, ConstraintLevel>) {
|
||||
// 收集发生变化的约束
|
||||
const changedConstraints: [string, ConstraintLevel][] = [];
|
||||
|
||||
// 更新状态并收集变化
|
||||
Object.entries(states).forEach(([constraint, level]) => {
|
||||
if (constraintStates[constraint] !== level) {
|
||||
constraintStates[constraint] = level;
|
||||
changedConstraints.push([constraint, level]);
|
||||
}
|
||||
});
|
||||
|
||||
// 通知所有变化
|
||||
changedConstraints.forEach(([constraint, level]) => {
|
||||
stateChangeCallbacks.forEach(callback => callback(constraint, level));
|
||||
});
|
||||
}
|
||||
|
||||
// 获取约束对应的颜色
|
||||
export function getConstraintColor(constraint: string): string {
|
||||
const state = getConstraintState(constraint);
|
||||
return constraintColors[state];
|
||||
}
|
||||
|
||||
// 清除所有约束状态
|
||||
export function clearAllConstraintStates() {
|
||||
Object.keys(constraintStates).forEach(key => {
|
||||
delete constraintStates[key];
|
||||
});
|
||||
}
|
||||
|
||||
// 获取所有约束状态
|
||||
export function getAllConstraintStates(): Record<string, ConstraintLevel> {
|
||||
return { ...constraintStates };
|
||||
}
|
||||
|
||||
// 注册约束状态变化回调
|
||||
const stateChangeCallbacks: ((constraint: string, level: ConstraintLevel) => void)[] = [];
|
||||
|
||||
export function onConstraintStateChange(callback: (constraint: string, level: ConstraintLevel) => void) {
|
||||
stateChangeCallbacks.push(callback);
|
||||
return () => {
|
||||
const index = stateChangeCallbacks.indexOf(callback);
|
||||
if (index > -1) {
|
||||
stateChangeCallbacks.splice(index, 1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 触发约束变化
|
||||
export function notifyConstraintChange(constraint: string, level: ConstraintLevel) {
|
||||
setConstraintState(constraint, level);
|
||||
stateChangeCallbacks.forEach(callback => callback(constraint, level));
|
||||
}
|
||||
Reference in New Issue
Block a user