Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
import { useSimulatorStore, ARDUINO_POSITION } from '../../store/useSimulatorStore';
|
|
|
|
|
import React, { useEffect, useState, useRef } from 'react';
|
2026-03-03 10:20:49 +07:00
|
|
|
import { ArduinoUno } from '../components-wokwi/ArduinoUno';
|
|
|
|
|
import { LED } from '../components-wokwi/LED';
|
|
|
|
|
import { Resistor } from '../components-wokwi/Resistor';
|
|
|
|
|
import { Pushbutton } from '../components-wokwi/Pushbutton';
|
|
|
|
|
import { Potentiometer } from '../components-wokwi/Potentiometer';
|
|
|
|
|
import { ComponentPalette } from './ComponentPalette';
|
|
|
|
|
import { PinSelector } from './PinSelector';
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
import { WireLayer } from './WireLayer';
|
|
|
|
|
import { PinOverlay } from './PinOverlay';
|
2026-03-03 10:20:49 +07:00
|
|
|
import type { ComponentTemplate } from '../../types/components';
|
|
|
|
|
import './SimulatorCanvas.css';
|
|
|
|
|
|
|
|
|
|
export const SimulatorCanvas = () => {
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
const {
|
|
|
|
|
components,
|
|
|
|
|
running,
|
|
|
|
|
pinManager,
|
|
|
|
|
initSimulator,
|
|
|
|
|
updateComponentState,
|
|
|
|
|
addComponent,
|
|
|
|
|
removeComponent,
|
|
|
|
|
updateComponent,
|
|
|
|
|
} = useSimulatorStore();
|
|
|
|
|
|
|
|
|
|
// Wire management from store
|
|
|
|
|
const startWireCreation = useSimulatorStore((s) => s.startWireCreation);
|
|
|
|
|
const updateWireInProgress = useSimulatorStore((s) => s.updateWireInProgress);
|
|
|
|
|
const finishWireCreation = useSimulatorStore((s) => s.finishWireCreation);
|
|
|
|
|
const cancelWireCreation = useSimulatorStore((s) => s.cancelWireCreation);
|
|
|
|
|
const wireInProgress = useSimulatorStore((s) => s.wireInProgress);
|
|
|
|
|
const recalculateAllWirePositions = useSimulatorStore((s) => s.recalculateAllWirePositions);
|
|
|
|
|
|
|
|
|
|
// Component palette drag
|
2026-03-03 10:20:49 +07:00
|
|
|
const [draggedTemplate, setDraggedTemplate] = useState<ComponentTemplate | null>(null);
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
|
|
|
|
|
// Component selection
|
2026-03-03 10:20:49 +07:00
|
|
|
const [selectedComponentId, setSelectedComponentId] = useState<string | null>(null);
|
|
|
|
|
const [showPinSelector, setShowPinSelector] = useState(false);
|
|
|
|
|
const [pinSelectorPos, setPinSelectorPos] = useState({ x: 0, y: 0 });
|
|
|
|
|
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
// Component dragging state
|
|
|
|
|
const [draggedComponentId, setDraggedComponentId] = useState<string | null>(null);
|
|
|
|
|
const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });
|
|
|
|
|
|
|
|
|
|
// Pin visualization
|
|
|
|
|
const [hoveredComponentId, setHoveredComponentId] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
// Canvas ref for coordinate calculations
|
|
|
|
|
const canvasRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
// Initialize simulator on mount
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
initSimulator();
|
|
|
|
|
}, [initSimulator]);
|
|
|
|
|
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
// Recalculate wire positions after web components initialize their pinInfo
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
|
recalculateAllWirePositions();
|
|
|
|
|
}, 500);
|
|
|
|
|
return () => clearTimeout(timer);
|
|
|
|
|
}, [recalculateAllWirePositions]);
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
// Connect components to pin manager
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const unsubscribers: (() => void)[] = [];
|
|
|
|
|
|
|
|
|
|
components.forEach((component) => {
|
|
|
|
|
if (component.properties.pin !== undefined) {
|
|
|
|
|
const unsubscribe = pinManager.onPinChange(
|
|
|
|
|
component.properties.pin,
|
|
|
|
|
(pin, state) => {
|
|
|
|
|
// Update component state when pin changes
|
|
|
|
|
updateComponentState(component.id, state);
|
|
|
|
|
console.log(`Component ${component.id} on pin ${pin}: ${state ? 'HIGH' : 'LOW'}`);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
unsubscribers.push(unsubscribe);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
unsubscribers.forEach(unsub => unsub());
|
|
|
|
|
};
|
|
|
|
|
}, [components, pinManager, updateComponentState]);
|
|
|
|
|
|
|
|
|
|
// Handle keyboard delete
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
|
|
|
if ((e.key === 'Delete' || e.key === 'Backspace') && selectedComponentId) {
|
|
|
|
|
removeComponent(selectedComponentId);
|
|
|
|
|
setSelectedComponentId(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('keydown', handleKeyDown);
|
|
|
|
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
|
|
|
}, [selectedComponentId, removeComponent]);
|
|
|
|
|
|
|
|
|
|
// Drag & drop handlers
|
|
|
|
|
const handleDragOver = (e: React.DragEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.dataTransfer.dropEffect = 'copy';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleDrop = (e: React.DragEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!draggedTemplate) return;
|
|
|
|
|
|
|
|
|
|
const canvasRect = e.currentTarget.getBoundingClientRect();
|
|
|
|
|
const x = e.clientX - canvasRect.left;
|
|
|
|
|
const y = e.clientY - canvasRect.top;
|
|
|
|
|
|
|
|
|
|
const newComponent = {
|
|
|
|
|
id: `${draggedTemplate.type}-${Date.now()}`,
|
|
|
|
|
type: draggedTemplate.type,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
properties: {
|
|
|
|
|
...draggedTemplate.defaultProperties,
|
|
|
|
|
state: false,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addComponent(newComponent as any);
|
|
|
|
|
setDraggedTemplate(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Component selection
|
|
|
|
|
const handleComponentClick = (componentId: string, event: React.MouseEvent) => {
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
setSelectedComponentId(componentId);
|
|
|
|
|
setPinSelectorPos({ x: event.clientX, y: event.clientY });
|
|
|
|
|
setShowPinSelector(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Pin assignment
|
|
|
|
|
const handlePinSelect = (componentId: string, pin: number) => {
|
|
|
|
|
updateComponent(componentId, {
|
|
|
|
|
properties: {
|
|
|
|
|
...components.find((c) => c.id === componentId)?.properties,
|
|
|
|
|
pin,
|
|
|
|
|
},
|
|
|
|
|
} as any);
|
|
|
|
|
};
|
|
|
|
|
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
// Component dragging handlers
|
|
|
|
|
const handleComponentMouseDown = (componentId: string, e: React.MouseEvent) => {
|
|
|
|
|
// Don't start dragging if we're clicking on the pin selector
|
|
|
|
|
if (showPinSelector) return;
|
|
|
|
|
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
const component = components.find((c) => c.id === componentId);
|
|
|
|
|
if (!component || !canvasRef.current) return;
|
|
|
|
|
|
|
|
|
|
// Get canvas position to convert viewport coords to canvas coords
|
|
|
|
|
const canvasRect = canvasRef.current.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
// Calculate offset in canvas coordinate system
|
|
|
|
|
setDraggedComponentId(componentId);
|
|
|
|
|
setDragOffset({
|
|
|
|
|
x: (e.clientX - canvasRect.left) - component.x,
|
|
|
|
|
y: (e.clientY - canvasRect.top) - component.y,
|
|
|
|
|
});
|
|
|
|
|
setSelectedComponentId(componentId);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCanvasMouseMove = (e: React.MouseEvent) => {
|
|
|
|
|
if (!canvasRef.current) return;
|
|
|
|
|
|
|
|
|
|
// Handle component dragging
|
|
|
|
|
if (draggedComponentId) {
|
|
|
|
|
const canvasRect = canvasRef.current.getBoundingClientRect();
|
|
|
|
|
const newX = e.clientX - canvasRect.left - dragOffset.x;
|
|
|
|
|
const newY = e.clientY - canvasRect.top - dragOffset.y;
|
|
|
|
|
|
|
|
|
|
updateComponent(draggedComponentId, {
|
|
|
|
|
x: Math.max(0, newX),
|
|
|
|
|
y: Math.max(0, newY),
|
|
|
|
|
} as any);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle wire creation preview
|
|
|
|
|
if (wireInProgress && canvasRef.current) {
|
|
|
|
|
const canvasRect = canvasRef.current.getBoundingClientRect();
|
|
|
|
|
const currentX = e.clientX - canvasRect.left;
|
|
|
|
|
const currentY = e.clientY - canvasRect.top;
|
|
|
|
|
updateWireInProgress(currentX, currentY);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleCanvasMouseUp = () => {
|
|
|
|
|
if (draggedComponentId) {
|
|
|
|
|
// Recalculate wire positions after moving component
|
|
|
|
|
recalculateAllWirePositions();
|
|
|
|
|
setDraggedComponentId(null);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Wire creation via pin clicks
|
|
|
|
|
const handlePinClick = (componentId: string, pinName: string, x: number, y: number) => {
|
|
|
|
|
if (wireInProgress) {
|
|
|
|
|
// Finish wire creation
|
|
|
|
|
finishWireCreation({
|
|
|
|
|
componentId,
|
|
|
|
|
pinName,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
// Start wire creation
|
|
|
|
|
startWireCreation({
|
|
|
|
|
componentId,
|
|
|
|
|
pinName,
|
|
|
|
|
x,
|
|
|
|
|
y,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Keyboard handlers for wires
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const handleKeyDown = (e: KeyboardEvent) => {
|
|
|
|
|
if (e.key === 'Escape' && wireInProgress) {
|
|
|
|
|
cancelWireCreation();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('keydown', handleKeyDown);
|
|
|
|
|
return () => window.removeEventListener('keydown', handleKeyDown);
|
|
|
|
|
}, [wireInProgress, cancelWireCreation]);
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
// Render component
|
|
|
|
|
const renderComponent = (component: any) => {
|
|
|
|
|
const isSelected = selectedComponentId === component.id;
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
const isHovered = hoveredComponentId === component.id;
|
|
|
|
|
const showPinsForComponent = isHovered || wireInProgress !== null;
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
const commonProps = {
|
|
|
|
|
id: component.id,
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
x: 0, // Position handled by wrapper div - don't double-position
|
|
|
|
|
y: 0,
|
2026-03-03 10:20:49 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const wrapperStyle = {
|
|
|
|
|
position: 'absolute' as const,
|
|
|
|
|
left: `${component.x}px`,
|
|
|
|
|
top: `${component.y}px`,
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
cursor: draggedComponentId === component.id ? 'grabbing' : 'grab',
|
2026-03-03 10:20:49 +07:00
|
|
|
border: isSelected ? '2px dashed #007acc' : '2px solid transparent',
|
|
|
|
|
borderRadius: '4px',
|
|
|
|
|
padding: '4px',
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
userSelect: 'none' as const,
|
2026-03-03 10:20:49 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
<React.Fragment key={component.id}>
|
|
|
|
|
<div
|
|
|
|
|
style={wrapperStyle}
|
|
|
|
|
onClick={(e) => handleComponentClick(component.id, e)}
|
|
|
|
|
onMouseDown={(e) => handleComponentMouseDown(component.id, e)}
|
|
|
|
|
onMouseEnter={() => setHoveredComponentId(component.id)}
|
|
|
|
|
onMouseLeave={() => setHoveredComponentId(null)}
|
|
|
|
|
>
|
2026-03-03 10:20:49 +07:00
|
|
|
{component.type === 'led' && (
|
|
|
|
|
<>
|
|
|
|
|
<LED
|
|
|
|
|
{...commonProps}
|
|
|
|
|
color={component.properties.color as any}
|
|
|
|
|
value={component.properties.state || false}
|
|
|
|
|
/>
|
|
|
|
|
<div className="component-label">
|
|
|
|
|
{component.properties.pin !== undefined
|
|
|
|
|
? `Pin ${component.properties.pin}`
|
|
|
|
|
: 'No pin'}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{component.type === 'resistor' && (
|
|
|
|
|
<>
|
|
|
|
|
<Resistor {...commonProps} value={component.properties.value || 220} />
|
|
|
|
|
<div className="component-label">
|
|
|
|
|
{component.properties.value || 220}Ω
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{component.type === 'pushbutton' && (
|
|
|
|
|
<>
|
|
|
|
|
<Pushbutton
|
|
|
|
|
{...commonProps}
|
|
|
|
|
color={component.properties.color as any}
|
|
|
|
|
pressed={component.properties.state || false}
|
|
|
|
|
/>
|
|
|
|
|
<div className="component-label">
|
|
|
|
|
{component.properties.pin !== undefined
|
|
|
|
|
? `Pin ${component.properties.pin}`
|
|
|
|
|
: 'No pin'}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
{component.type === 'potentiometer' && (
|
|
|
|
|
<>
|
|
|
|
|
<Potentiometer {...commonProps} value={component.properties.value || 50} />
|
|
|
|
|
<div className="component-label">
|
|
|
|
|
{component.properties.pin !== undefined
|
|
|
|
|
? `Pin A${component.properties.pin - 14}`
|
|
|
|
|
: 'No pin'}
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Pin overlay for wire creation */}
|
|
|
|
|
<PinOverlay
|
|
|
|
|
componentId={component.id}
|
|
|
|
|
componentX={component.x}
|
|
|
|
|
componentY={component.y}
|
|
|
|
|
onPinClick={handlePinClick}
|
|
|
|
|
showPins={showPinsForComponent}
|
|
|
|
|
/>
|
|
|
|
|
</React.Fragment>
|
2026-03-03 10:20:49 +07:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="simulator-canvas-container">
|
|
|
|
|
{/* Component Palette */}
|
|
|
|
|
<ComponentPalette onDragStart={setDraggedTemplate} />
|
|
|
|
|
|
|
|
|
|
{/* Main Canvas */}
|
|
|
|
|
<div className="simulator-canvas">
|
|
|
|
|
<div className="canvas-header">
|
|
|
|
|
<h3>Arduino Simulator</h3>
|
|
|
|
|
<div className="canvas-header-info">
|
|
|
|
|
<span className={`status-indicator ${running ? 'running' : 'stopped'}`}>
|
|
|
|
|
{running ? 'Running' : 'Stopped'}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="component-count">{components.length} components</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
ref={canvasRef}
|
2026-03-03 10:20:49 +07:00
|
|
|
className="canvas-content"
|
|
|
|
|
onDragOver={handleDragOver}
|
|
|
|
|
onDrop={handleDrop}
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
onMouseMove={handleCanvasMouseMove}
|
|
|
|
|
onMouseUp={handleCanvasMouseUp}
|
2026-03-03 10:20:49 +07:00
|
|
|
onClick={() => setSelectedComponentId(null)}
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
style={{ cursor: wireInProgress ? 'crosshair' : 'default' }}
|
2026-03-03 10:20:49 +07:00
|
|
|
>
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
{/* Wire Layer - Renders below all components */}
|
|
|
|
|
<WireLayer />
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
{/* Arduino Uno Board using wokwi-elements */}
|
|
|
|
|
<ArduinoUno
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
x={ARDUINO_POSITION.x}
|
|
|
|
|
y={ARDUINO_POSITION.y}
|
2026-03-03 10:20:49 +07:00
|
|
|
led13={components.find((c) => c.id === 'led-builtin')?.properties.state || false}
|
|
|
|
|
/>
|
|
|
|
|
|
Add backend and frontend test suites for Arduino compilation and simulation
- Implemented a comprehensive backend test suite in `test_compilation.py` to validate the Arduino CLI installation, AVR core presence, compilation service, and API endpoint functionality.
- Created a frontend test suite in `simulation.test.ts` to test the `PinManager` and `AVRSimulator` components, ensuring proper functionality and integration.
- Introduced new components for wire management in the simulator, including `PinOverlay`, `WireInProgressRenderer`, `WireLayer`, and `WireRenderer`, enhancing the visual wiring system.
- Developed utility functions for pin position calculations and wire color management, ensuring accurate connections and visual representation.
- Added types for wire management in `wire.ts`, defining structures for wire endpoints, control points, and signal types.
2026-03-04 02:44:07 +07:00
|
|
|
{/* Arduino pin overlay */}
|
|
|
|
|
<PinOverlay
|
|
|
|
|
componentId="arduino-uno"
|
|
|
|
|
componentX={ARDUINO_POSITION.x}
|
|
|
|
|
componentY={ARDUINO_POSITION.y}
|
|
|
|
|
onPinClick={handlePinClick}
|
|
|
|
|
showPins={wireInProgress !== null}
|
|
|
|
|
/>
|
|
|
|
|
|
2026-03-03 10:20:49 +07:00
|
|
|
{/* Components using wokwi-elements */}
|
|
|
|
|
<div className="components-area">{components.map(renderComponent)}</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Pin Selector Modal */}
|
|
|
|
|
{showPinSelector && selectedComponentId && (
|
|
|
|
|
<PinSelector
|
|
|
|
|
componentId={selectedComponentId}
|
|
|
|
|
componentType={
|
|
|
|
|
components.find((c) => c.id === selectedComponentId)?.type || 'unknown'
|
|
|
|
|
}
|
|
|
|
|
currentPin={
|
|
|
|
|
components.find((c) => c.id === selectedComponentId)?.properties.pin
|
|
|
|
|
}
|
|
|
|
|
onPinSelect={handlePinSelect}
|
|
|
|
|
onClose={() => setShowPinSelector(false)}
|
|
|
|
|
position={pinSelectorPos}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|