import { useState } from "react"; import { Card, CardHeader, CardContent, CardTitle, CardDescription, Button, Input } from "../ui/components"; import { PencilIcon, PlusIcon, TrashIcon, ArrowDownTrayIcon as DownloadIcon } from '@heroicons/react/24/outline'; import axios from "axios"; export default function Manual() { const [points, setPoints] = useState([{ id: 0, len: 0, height: 0 }]); const [args, setArgs] = useState({ scale: 200 }); const [isLoading, setIsLoading] = useState(false); const reIndex = () => { let newId = 0; let newPoints = []; for (let point of points) { point.id = newId; newPoints.push(point); newId += 1; } setPoints([...newPoints]); }; const addPoint = () => { setPoints([ ...points, { id: points.length, len: Number(points[points.length - 1].len) + 1, height: 0, }, ]); }; const removePoint = (index) => { let newPoints = points; newPoints.splice(index, 1); setPoints([...newPoints]); reIndex(); }; const updatePoint = (index, field, value) => { let newPoints = points; newPoints[index][field] = value; setPoints([...newPoints]); }; const generation = (e) => { setIsLoading(true); let pointString = "Próbkowanie: 1\nSegment 0: w dół\nX: Y, Z"; for (let point of points) { pointString += "\n"; pointString += Number(point.len) * 1.0; pointString += ", 1.0, "; pointString += point.height; } py(e, pointString, args); }; const py = (e, profil, args) => { e.preventDefault(); axios .post("/api/spawn", { profil: profil, arguments: args, }) .then(function (response) { setIsLoading(false); console.log(response); if (response.data.toString().startsWith("Py Error")) { alert("Błąd: " + response.data); return; } document.getElementById("down").download = response.data.filename.toString() + ".dxf"; document.getElementById("down").click(); }) .catch(function (error) { setIsLoading(false); console.log(error); }); }; return (
{/* Input Section */}
Punkty profilu Wprowadź punkty profilu ręcznie - długość i wysokość nad poziomem morza {/* Scale Input */} setArgs({ ...args, scale: e.target.value })} /> {/* Points List */}
{points.map((point, index) => (
updatePoint(index, 'len', e.target.value)} />
updatePoint(index, 'height', e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { addPoint(); // Focus next input after render setTimeout(() => { const nextInput = e.target.parentNode.parentNode.parentNode.nextSibling?.querySelector('input'); if (nextInput) nextInput.focus(); }, 100); } }} /> {points.length > 1 && ( )}
))}
{/* Action Buttons */}
{/* Preview/Instructions Section */}
Podgląd punktów Lista wprowadzonych punktów profilu {points.length > 0 ? (
{points.map((point, index) => (
Punkt {index + 1}
Długość: {point.len}m Wysokość: {point.height}m
))}
) : (

Brak punktów do wyświetlenia

)}
Instrukcje
1

Wprowadź kolejne punkty profilu z długością i wysokością

2

Użyj klawisza Enter aby szybko dodać następny punkt

3

Ustaw skalę i kliknij "Generuj profil"

); }