refactor api-simulation for create and fetch
This commit is contained in:
@@ -59,7 +59,8 @@ export const saveSimulationData = async (data: any) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
export const getSimulationData = async (data: any) => {
|
||||
export const updateSimulateData = async (data: any) => {
|
||||
console.log("data: update", data);
|
||||
try {
|
||||
const response = await fetch(`${url_Backend_dwinzo}/api/V1/ValidateSimulated`, {
|
||||
method: "POST",
|
||||
@@ -76,7 +77,7 @@ export const getSimulationData = async (data: any) => {
|
||||
localStorage.setItem("token", newAccessToken);
|
||||
}
|
||||
if (!response.ok) {
|
||||
console.error("Failed to add project");
|
||||
console.error("Failed to update ");
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
@@ -90,4 +91,35 @@ export const getSimulationData = async (data: any) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
export const clearSimulationData = ({ key, data }: SimulationData) => {};
|
||||
export const getSimulationData = async (projectId: string, versionId: string, productUuid: string) => {
|
||||
console.log("called");
|
||||
try {
|
||||
const response = await fetch(`${url_Backend_dwinzo}/api/V1/SimulatedDatas/${projectId}/${versionId}?productUuid=${productUuid}`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: "Bearer <access_token>",
|
||||
"Content-Type": "application/json",
|
||||
token: localStorage.getItem("token") || "",
|
||||
refresh_token: localStorage.getItem("refreshToken") || "",
|
||||
},
|
||||
});
|
||||
|
||||
console.log("response: ", response);
|
||||
|
||||
const newAccessToken = response.headers.get("x-access-token");
|
||||
if (newAccessToken) {
|
||||
localStorage.setItem("token", newAccessToken);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error("Failed to fetch simulateData");
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error: any) {
|
||||
console.error("Failed to get simulation data");
|
||||
console.log(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
// export const clearSimulationData = ({ key, data }: SimulationData) => {};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon, } from "../../../icons/ExportCommonIcons";
|
||||
import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon } from "../../../icons/ExportCommonIcons";
|
||||
import RenameInput from "../../../ui/inputs/RenameInput";
|
||||
import { handleResize } from "../../../../functions/handleResizePannel";
|
||||
import { useMainProduct, useSelectedAsset } from "../../../../store/simulation/useSimulationStore";
|
||||
@@ -13,13 +13,13 @@ import { deleteProductApi } from "../../../../services/simulation/products/delet
|
||||
import { renameProductApi } from "../../../../services/simulation/products/renameProductApi";
|
||||
import { determineExecutionMachineSequences } from "../../../../modules/simulation/simulator/functions/determineExecutionMachineSequences";
|
||||
import ComparePopUp from "../../../ui/compareVersion/Compare";
|
||||
import { useCompareStore, useSaveVersion, } from "../../../../store/builder/store";
|
||||
import { useCompareStore, useSaveVersion, useSimulateId } from "../../../../store/builder/store";
|
||||
import { useToggleStore } from "../../../../store/useUIToggleStore";
|
||||
import { useProductContext } from "../../../../modules/simulation/products/productContext";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useVersionContext } from "../../../../modules/builder/version/versionContext";
|
||||
import { useSceneContext } from "../../../../modules/scene/sceneContext";
|
||||
import { getSimulationData } from "../../scenes/functions/simulationStorage";
|
||||
import { getSimulationData, updateSimulateData } from "../../scenes/functions/simulationStorage";
|
||||
|
||||
interface Event {
|
||||
modelName: string;
|
||||
@@ -41,7 +41,7 @@ const List: React.FC<ListProps> = ({ val }) => {
|
||||
const Simulations: React.FC = () => {
|
||||
const productsContainerRef = useRef<HTMLDivElement>(null);
|
||||
const { eventStore, productStore } = useSceneContext();
|
||||
const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById, } = productStore();
|
||||
const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById } = productStore();
|
||||
const { selectedProductStore } = useProductContext();
|
||||
const { selectedProduct, setSelectedProduct } = selectedProductStore();
|
||||
const { getEventByModelUuid } = eventStore();
|
||||
@@ -55,6 +55,7 @@ const Simulations: React.FC = () => {
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
const { comparePopUp, setComparePopUp } = useCompareStore();
|
||||
const { setIsVersionSaved } = useSaveVersion();
|
||||
const { simulateId } = useSimulateId();
|
||||
|
||||
const handleSaveVersion = () => {
|
||||
setIsVersionSaved(true);
|
||||
@@ -70,7 +71,7 @@ const Simulations: React.FC = () => {
|
||||
productName: name,
|
||||
productUuid: id,
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
versionId: selectedVersion?.versionId || "",
|
||||
});
|
||||
};
|
||||
|
||||
@@ -86,14 +87,8 @@ const Simulations: React.FC = () => {
|
||||
if (currentIndex >= updatedProducts.length) {
|
||||
newSelectedIndex = updatedProducts.length - 1;
|
||||
}
|
||||
setSelectedProduct(
|
||||
updatedProducts[newSelectedIndex].productUuid,
|
||||
updatedProducts[newSelectedIndex].productName
|
||||
);
|
||||
setMainProduct(
|
||||
updatedProducts[newSelectedIndex].productUuid,
|
||||
updatedProducts[newSelectedIndex].productName
|
||||
);
|
||||
setSelectedProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName);
|
||||
setMainProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName);
|
||||
} else {
|
||||
setSelectedProduct("", "");
|
||||
setMainProduct("", "");
|
||||
@@ -103,14 +98,14 @@ const Simulations: React.FC = () => {
|
||||
removeProduct(productUuid);
|
||||
deleteProductApi({
|
||||
productUuid,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
projectId
|
||||
versionId: selectedVersion?.versionId || "",
|
||||
projectId,
|
||||
});
|
||||
};
|
||||
|
||||
const handleRenameProduct = (productUuid: string, newName: string) => {
|
||||
renameProduct(productUuid, newName);
|
||||
renameProductApi({ productName: newName, productUuid, projectId: projectId || '', versionId: selectedVersion?.versionId || '' });
|
||||
renameProductApi({ productName: newName, productUuid, projectId: projectId || "", versionId: selectedVersion?.versionId || "" });
|
||||
if (selectedProduct.productUuid === productUuid) {
|
||||
setSelectedProduct(productUuid, newName);
|
||||
setMainProduct(productUuid, newName);
|
||||
@@ -119,11 +114,10 @@ const Simulations: React.FC = () => {
|
||||
|
||||
const handleRemoveEventFromProduct = () => {
|
||||
if (selectedAsset) {
|
||||
|
||||
deleteEventDataApi({
|
||||
productUuid: selectedProduct.productUuid,
|
||||
modelUuid: selectedAsset.modelUuid,
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
versionId: selectedVersion?.versionId || "",
|
||||
projectId: projectId,
|
||||
});
|
||||
removeEvent(selectedProduct.productUuid, selectedAsset.modelUuid);
|
||||
@@ -136,29 +130,37 @@ const Simulations: React.FC = () => {
|
||||
const selectedProductData = getProductById(selectedProduct.productUuid);
|
||||
|
||||
if (selectedProductData) {
|
||||
determineExecutionMachineSequences([selectedProductData]).then(
|
||||
(sequences) => {
|
||||
console.log('selectedProductData: ', selectedProductData);
|
||||
sequences.forEach((sequence) => {
|
||||
const events: Event[] =
|
||||
sequence.map((event) => ({
|
||||
modelName: event.modelName,
|
||||
modelId: event.modelUuid,
|
||||
})) || [];
|
||||
processes.push(events);
|
||||
});
|
||||
setProcesses(processes);
|
||||
}
|
||||
);
|
||||
determineExecutionMachineSequences([selectedProductData]).then((sequences) => {
|
||||
console.log("selectedProductData: ", selectedProductData);
|
||||
sequences.forEach((sequence) => {
|
||||
const events: Event[] =
|
||||
sequence.map((event) => ({
|
||||
modelName: event.modelName,
|
||||
modelId: event.modelUuid,
|
||||
})) || [];
|
||||
processes.push(events);
|
||||
});
|
||||
setProcesses(processes);
|
||||
});
|
||||
}
|
||||
|
||||
}, [selectedProduct.productUuid, products]);
|
||||
//call when comparePopup is true
|
||||
useEffect(() => {
|
||||
if (comparePopUp || selectedProduct.productUuid) {
|
||||
getSimulationData({ key: selectedProduct.productUuid });
|
||||
}
|
||||
}, [comparePopUp])
|
||||
}, [comparePopUp]);
|
||||
|
||||
const getSimulate = async () => {
|
||||
// const singleData = {
|
||||
// projectId: projectId,
|
||||
// versionId: selectedVersion?.versionId || "",
|
||||
// productUuid: selectedProduct?.productUuid || "",
|
||||
// };
|
||||
// console.log("singleData: ", singleData);
|
||||
// const getData = await getSimulationData(singleData);
|
||||
// console.log("getData: ", getData);
|
||||
setComparePopUp(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="simulations-container">
|
||||
@@ -167,77 +169,41 @@ const Simulations: React.FC = () => {
|
||||
<div className="actions section">
|
||||
<div className="header">
|
||||
<div className="header-value">Products</div>
|
||||
<button
|
||||
id="add-simulation"
|
||||
className="add-button"
|
||||
onClick={handleAddProduct}
|
||||
>
|
||||
<button id="add-simulation" className="add-button" onClick={handleAddProduct}>
|
||||
<AddIcon /> Add
|
||||
</button>
|
||||
</div>
|
||||
<div
|
||||
className="lists-main-container"
|
||||
ref={productsContainerRef}
|
||||
style={{ height: "120px" }}
|
||||
>
|
||||
<div className="lists-main-container" ref={productsContainerRef} style={{ height: "120px" }}>
|
||||
<div className="list-container">
|
||||
{products.map((product, index) => (
|
||||
<div
|
||||
key={product.productUuid}
|
||||
className={`list-item ${selectedProduct.productUuid === product.productUuid
|
||||
? "active"
|
||||
: ""
|
||||
}`}
|
||||
>
|
||||
<div key={product.productUuid} className={`list-item ${selectedProduct.productUuid === product.productUuid ? "active" : ""}`}>
|
||||
{/* eslint-disable-next-line */}
|
||||
<div
|
||||
className="value"
|
||||
onClick={() => {
|
||||
setSelectedProduct(product.productUuid, product.productName)
|
||||
setMainProduct(product.productUuid, product.productName)
|
||||
setSelectedProduct(product.productUuid, product.productName);
|
||||
setMainProduct(product.productUuid, product.productName);
|
||||
}}
|
||||
>
|
||||
<input
|
||||
type="radio"
|
||||
name="products"
|
||||
checked={selectedProduct.productUuid === product.productUuid}
|
||||
readOnly
|
||||
/>
|
||||
<RenameInput
|
||||
value={product.productName}
|
||||
onRename={(newName) =>
|
||||
handleRenameProduct(product.productUuid, newName)
|
||||
}
|
||||
/>
|
||||
<input type="radio" name="products" checked={selectedProduct.productUuid === product.productUuid} readOnly />
|
||||
<RenameInput value={product.productName} onRename={(newName) => handleRenameProduct(product.productUuid, newName)} />
|
||||
</div>
|
||||
{products.length > 1 && (
|
||||
<button
|
||||
id="remove-product-button"
|
||||
className="remove-button"
|
||||
onClick={() => handleRemoveProduct(product.productUuid)}
|
||||
>
|
||||
<button id="remove-product-button" className="remove-button" onClick={() => handleRemoveProduct(product.productUuid)}>
|
||||
<RemoveIcon />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<button
|
||||
className="resize-icon"
|
||||
id="action-resize"
|
||||
onMouseDown={(e: any) => handleResize(e, productsContainerRef)}
|
||||
>
|
||||
<button className="resize-icon" id="action-resize" onMouseDown={(e: any) => handleResize(e, productsContainerRef)}>
|
||||
<ResizeHeightIcon />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="simulation-process section">
|
||||
<button
|
||||
id="collapse-header"
|
||||
className="collapse-header-container"
|
||||
onClick={() => setOpenObjects(!openObjects)}
|
||||
>
|
||||
<button id="collapse-header" className="collapse-header-container" onClick={() => setOpenObjects(!openObjects)}>
|
||||
<div className="header">Process Flow</div>
|
||||
<div className="arrow-container">
|
||||
<ArrowIcon />
|
||||
@@ -254,14 +220,17 @@ const Simulations: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<div className="compare-simulations-container">
|
||||
<div className="compare-simulations-header">
|
||||
Need to Compare Layout?
|
||||
</div>
|
||||
<div className="compare-simulations-header">Need to Compare Layout?</div>
|
||||
<div className="content">
|
||||
Click '<span>Compare</span>' to review and analyze the layout
|
||||
differences between them.
|
||||
Click '<span>Compare</span>' to review and analyze the layout differences between them.
|
||||
</div>
|
||||
<button className="input" onClick={() => setComparePopUp(true)}>
|
||||
<button
|
||||
className="input"
|
||||
onClick={() => {
|
||||
// setComparePopUp(true);
|
||||
getSimulate();
|
||||
}}
|
||||
>
|
||||
<input type="button" value={"Compare"} className="submit" />
|
||||
</button>
|
||||
</div>
|
||||
@@ -278,8 +247,8 @@ const Simulations: React.FC = () => {
|
||||
addEvent,
|
||||
selectedProduct,
|
||||
clearSelectedAsset,
|
||||
projectId: projectId || '',
|
||||
versionId: selectedVersion?.versionId || '',
|
||||
projectId: projectId || "",
|
||||
versionId: selectedVersion?.versionId || "",
|
||||
});
|
||||
} else {
|
||||
handleRemoveEventFromProduct();
|
||||
|
||||
@@ -6,9 +6,10 @@ import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useVersionContext } from "../../builder/version/versionContext";
|
||||
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import { updateSimulateData, saveSimulationData, getSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import { get } from "http";
|
||||
import { set } from "immer/dist/internal";
|
||||
import { useSimulateId } from "../../../store/builder/store";
|
||||
interface SimulationUsageRecord {
|
||||
activeTime: number;
|
||||
isActive: boolean;
|
||||
@@ -53,6 +54,7 @@ const SimulationHandler = () => {
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
const [simulationEntry, setSimulationEntry] = useState<any>();
|
||||
const { setSimulateId } = useSimulateId();
|
||||
const COST_RATES: Record<SimulationUsageRecord["type"], number> = {
|
||||
roboticArm: 5,
|
||||
vehicle: 2,
|
||||
@@ -121,36 +123,55 @@ const SimulationHandler = () => {
|
||||
return { ...m, efficiencyScore };
|
||||
});
|
||||
}
|
||||
useEffect(() => {
|
||||
const runSimulation = async () => {
|
||||
console.log("simulationRecords: ", simulationRecords);
|
||||
if (!projectId || !selectedVersion || !selectedProduct.productUuid || simulationRecords.length === 0) return;
|
||||
|
||||
const project = simulationRecords[0];
|
||||
// useEffect(() => {
|
||||
// const runSimulation = async () => {
|
||||
// console.log("simulationRecords: ", simulationRecords);
|
||||
// if (!projectId || !selectedVersion || !selectedProduct.productUuid || simulationRecords.length === 0) return;
|
||||
|
||||
if (project) {
|
||||
// const scores = calculateEfficiencyScores(project.versions);
|
||||
// console.log("Version Comparisons:", scores);
|
||||
}
|
||||
console.log("simulationEntry: ", simulationEntry);
|
||||
console.log("simulationEntrysaddasd: ", useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData);
|
||||
// const project = simulationRecords[0];
|
||||
|
||||
const data = {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion.versionId,
|
||||
productUuid: selectedProduct.productUuid,
|
||||
simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
};
|
||||
// if (project) {
|
||||
// // const scores = calculateEfficiencyScores(project.versions);
|
||||
// // console.log("Version Comparisons:", scores);
|
||||
// }
|
||||
// console.log("simulationEntry: ", simulationEntry);
|
||||
// console.log("simulationEntrysaddasd: ", useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData);
|
||||
|
||||
const simulations = await saveSimulationData(data);
|
||||
if (simulations.message === "SimulatedData created Successfully") {
|
||||
setSimulationEntry(simulations.data);
|
||||
}
|
||||
console.log("Saved simulations:", simulations);
|
||||
};
|
||||
// const data = {
|
||||
// projectId: projectId,
|
||||
// versionId: selectedVersion.versionId,
|
||||
// productUuid: selectedProduct.productUuid,
|
||||
// simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
// };
|
||||
|
||||
runSimulation();
|
||||
}, [simulationRecords, projectId, selectedVersion, selectedProduct, simulationEntry]);
|
||||
// const simulations = await saveSimulationData(data);
|
||||
// console.log("simulations: ", simulations);
|
||||
// const simulateId = localStorage.getItem("simulateId");
|
||||
// console.log("simulateId: ", simulateId);
|
||||
// if (simulations.message === "SimulatedData created Successfully") {
|
||||
// console.log("simulations.data: ", simulations.data);
|
||||
// setSimulationEntry(simulations.data);
|
||||
// localStorage.setItem("simulateId", simulations.data);
|
||||
// setSimulateId(simulations.data);
|
||||
// }
|
||||
|
||||
// // else {
|
||||
// // console.log("djh");
|
||||
// // const data = {
|
||||
// // projectId: projectId,
|
||||
// // versionId: selectedVersion.versionId,
|
||||
// // productUuid: selectedProduct.productUuid,
|
||||
// // simulateId: simulateId,
|
||||
// // simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
// // };
|
||||
// // const update = await updateSimulateData(data);
|
||||
// // console.log("update: ", update);
|
||||
// // }
|
||||
// };
|
||||
|
||||
// runSimulation();
|
||||
// }, [simulationRecords, projectId, selectedVersion, selectedProduct]);
|
||||
|
||||
// useEffect(() => {
|
||||
// console.log('simulationRecords: ', simulationRecords);
|
||||
@@ -173,21 +194,6 @@ const SimulationHandler = () => {
|
||||
// // });
|
||||
// }, [simulationRecords]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchSimulationData = async () => {
|
||||
if (!projectId || !selectedVersion || !selectedProduct.productUuid) return;
|
||||
const data = {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion.versionId,
|
||||
productUuid: selectedProduct.productUuid,
|
||||
simulatedId: simulationEntry,
|
||||
};
|
||||
const datas = await getSimulationData(data);
|
||||
console.log("datas: ", datas);
|
||||
};
|
||||
fetchSimulationData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
let checkTimer: ReturnType<typeof setTimeout>;
|
||||
if (!projectId) return;
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useActionHandler } from '../actions/useActionHandler';
|
||||
import { usePlayButtonStore, useResetButtonStore } from '../../../store/usePlayButtonStore';
|
||||
import { determineExecutionOrder } from './functions/determineExecutionOrder';
|
||||
import { useProductContext } from '../products/productContext';
|
||||
import { useSceneContext } from '../../scene/sceneContext';
|
||||
import SimulationHandler from './SimulationHandler';
|
||||
import { useEffect } from "react";
|
||||
import { useActionHandler } from "../actions/useActionHandler";
|
||||
import { usePlayButtonStore, useResetButtonStore } from "../../../store/usePlayButtonStore";
|
||||
import { determineExecutionOrder } from "./functions/determineExecutionOrder";
|
||||
import { useProductContext } from "../products/productContext";
|
||||
import { useSceneContext } from "../../scene/sceneContext";
|
||||
import SimulationHandler from "./SimulationHandler";
|
||||
import { getSimulationData, saveSimulationData } from "../../../components/layout/scenes/functions/simulationStorage";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useVersionContext } from "../../builder/version/versionContext";
|
||||
import { version } from "os";
|
||||
import { get } from "http";
|
||||
import { useSimulationManager } from "../../../store/rough/useSimulationManagerStore";
|
||||
|
||||
function Simulator() {
|
||||
const { selectedProductStore } = useProductContext();
|
||||
@@ -14,6 +20,9 @@ function Simulator() {
|
||||
const { selectedProduct } = selectedProductStore();
|
||||
const { isPlaying } = usePlayButtonStore();
|
||||
const { isReset } = useResetButtonStore();
|
||||
const { projectId } = useParams();
|
||||
const { selectedVersionStore } = useVersionContext();
|
||||
const { selectedVersion } = selectedVersionStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPlaying || isReset || !selectedProduct.productUuid) return;
|
||||
@@ -23,21 +32,40 @@ function Simulator() {
|
||||
|
||||
const executionOrder = determineExecutionOrder([product]);
|
||||
|
||||
executionOrder.forEach(action => {
|
||||
executionOrder.forEach((action) => {
|
||||
handleAction(action);
|
||||
});
|
||||
}, [products, isPlaying, isReset, selectedProduct]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!projectId || !selectedVersion || !selectedProduct?.productUuid) return;
|
||||
const fetchSimulateData = async () => {
|
||||
const getData = await getSimulationData(projectId, selectedVersion.versionId, selectedProduct?.productUuid);
|
||||
const product = getProductById(selectedProduct.productUuid);
|
||||
if (!product) return;
|
||||
const products: productsSchema = [product];
|
||||
const getSimulate = getData?.data;
|
||||
if (getData && getSimulate && getSimulate.productTimestamp === products[0]?.timestamp) {
|
||||
return;
|
||||
} else {
|
||||
//call create API
|
||||
const data = {
|
||||
projectId: projectId,
|
||||
versionId: selectedVersion.versionId,
|
||||
productUuid: selectedProduct.productUuid,
|
||||
simulateData: useSimulationManager.getState().getProductById(projectId, selectedVersion?.versionId, selectedProduct.productUuid)?.simulateData,
|
||||
};
|
||||
const simulations = await saveSimulationData(data);
|
||||
console.log("simulations: ", simulations);
|
||||
echo.log("Simulation data saved successfully");
|
||||
}
|
||||
};
|
||||
fetchSimulateData();
|
||||
}, []);
|
||||
return (
|
||||
|
||||
<>
|
||||
|
||||
{/* <simulationHandler/> */}
|
||||
<SimulationHandler />
|
||||
|
||||
</>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -542,3 +542,7 @@ export const comparsionMaterialData = create<any>((set: any) => ({
|
||||
materialData: [],
|
||||
setMaterialData: (x: any) => set({ materialData: x }),
|
||||
}));
|
||||
export const useSimulateId = create<any>((set: any) => ({
|
||||
simulateId: "",
|
||||
setSimulateId: (x: any) => set({ simulateId: x }),
|
||||
}));
|
||||
|
||||
75
app/src/types/simulationTypes.d.ts
vendored
75
app/src/types/simulationTypes.d.ts
vendored
@@ -14,13 +14,12 @@ interface TriggerSchema {
|
||||
triggerType: "onComplete" | "onStart" | "onStop" | "delay" | "onError";
|
||||
delay: number;
|
||||
triggeredAsset: {
|
||||
triggeredModel: { modelName: string, modelUuid: string };
|
||||
triggeredPoint: { pointName: string, pointUuid: string } | null;
|
||||
triggeredAction: { actionName: string, actionUuid: string } | null;
|
||||
triggeredModel: { modelName: string; modelUuid: string };
|
||||
triggeredPoint: { pointName: string; pointUuid: string } | null;
|
||||
triggeredAction: { actionName: string; actionUuid: string } | null;
|
||||
} | null;
|
||||
}
|
||||
|
||||
|
||||
// Actions
|
||||
|
||||
interface ConveyorAction {
|
||||
@@ -41,8 +40,8 @@ interface VehicleAction {
|
||||
unLoadDuration: number;
|
||||
loadCapacity: number;
|
||||
steeringAngle: number;
|
||||
pickUpPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
|
||||
unLoadPoint: { position: { x: number; y: number, z: number }, rotation: { x: number; y: number, z: number } } | null;
|
||||
pickUpPoint: { position: { x: number; y: number; z: number }; rotation: { x: number; y: number; z: number } } | null;
|
||||
unLoadPoint: { position: { x: number; y: number; z: number }; rotation: { x: number; y: number; z: number } } | null;
|
||||
paths: {
|
||||
initPickup: {
|
||||
pointId: string;
|
||||
@@ -50,22 +49,22 @@ interface VehicleAction {
|
||||
isCurved: boolean;
|
||||
handleA: [number, number, number] | null;
|
||||
handleB: [number, number, number] | null;
|
||||
}[],
|
||||
}[];
|
||||
pickupDrop: {
|
||||
pointId: string;
|
||||
position: [number, number, number];
|
||||
isCurved: boolean;
|
||||
handleA: [number, number, number] | null;
|
||||
handleB: [number, number, number] | null;
|
||||
}[],
|
||||
}[];
|
||||
dropPickup: {
|
||||
pointId: string;
|
||||
position: [number, number, number];
|
||||
isCurved: boolean;
|
||||
handleA: [number, number, number] | null;
|
||||
handleB: [number, number, number] | null;
|
||||
}[],
|
||||
}
|
||||
}[];
|
||||
};
|
||||
triggers: TriggerSchema[];
|
||||
}
|
||||
|
||||
@@ -73,7 +72,7 @@ interface RoboticArmAction {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
actionType: "pickAndPlace";
|
||||
process: { startPoint: [number, number, number] | null; endPoint: [number, number, number] | null; };
|
||||
process: { startPoint: [number, number, number] | null; endPoint: [number, number, number] | null };
|
||||
triggers: TriggerSchema[];
|
||||
}
|
||||
|
||||
@@ -99,10 +98,10 @@ interface HumanAction {
|
||||
actionType: "worker" | "manufacturer" | "operator" | "assembler";
|
||||
processTime: number;
|
||||
swapMaterial?: string;
|
||||
manufacturePoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||
assemblyPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||
pickUpPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||
dropPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null; }
|
||||
manufacturePoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null };
|
||||
assemblyPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null };
|
||||
pickUpPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null };
|
||||
dropPoint?: { position: [number, number, number] | null; rotation: [number, number, number] | null };
|
||||
assemblyCount: number;
|
||||
assemblyCondition: {
|
||||
conditionType: "material";
|
||||
@@ -111,7 +110,7 @@ interface HumanAction {
|
||||
sourceUuid: string;
|
||||
sourceActionUuid: string;
|
||||
}[];
|
||||
}
|
||||
};
|
||||
loadCount: number;
|
||||
manufactureCount: number;
|
||||
loadCapacity: number;
|
||||
@@ -128,7 +127,6 @@ interface CraneAction {
|
||||
|
||||
type Action = ConveyorAction | VehicleAction | RoboticArmAction | MachineAction | StorageAction | HumanAction | CraneAction;
|
||||
|
||||
|
||||
// Points
|
||||
|
||||
interface ConveyorPointSchema {
|
||||
@@ -180,8 +178,7 @@ interface CranePointSchema {
|
||||
actions: CraneAction[];
|
||||
}
|
||||
|
||||
type PointsScheme = | ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | HumanPointSchema | CranePointSchema;
|
||||
|
||||
type PointsScheme = ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | HumanPointSchema | CranePointSchema;
|
||||
|
||||
// Events
|
||||
|
||||
@@ -194,7 +191,7 @@ interface ConveyorEventSchema extends AssetEventSchema {
|
||||
|
||||
interface VehicleEventSchema extends AssetEventSchema {
|
||||
type: "vehicle";
|
||||
subType: "manual" | "automatic" | "semiAutomatic" | '';
|
||||
subType: "manual" | "automatic" | "semiAutomatic" | "";
|
||||
speed: number;
|
||||
point: VehiclePointSchema;
|
||||
}
|
||||
@@ -230,12 +227,11 @@ interface HumanEventSchema extends AssetEventSchema {
|
||||
|
||||
interface CraneEventSchema extends AssetEventSchema {
|
||||
type: "crane";
|
||||
subType: "pillarJib" | '';
|
||||
subType: "pillarJib" | "";
|
||||
point: CranePointSchema;
|
||||
}
|
||||
|
||||
type EventsSchema = | ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema | HumanEventSchema | CraneEventSchema;
|
||||
|
||||
type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema | HumanEventSchema | CraneEventSchema;
|
||||
|
||||
// Statuses
|
||||
|
||||
@@ -281,7 +277,7 @@ interface VehicleStatus extends VehicleEventSchema {
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentLoad: number;
|
||||
currentMaterials: { materialType: string; materialId: string; }[];
|
||||
currentMaterials: { materialType: string; materialId: string }[];
|
||||
distanceTraveled: number;
|
||||
}
|
||||
|
||||
@@ -291,7 +287,7 @@ interface StorageUnitStatus extends StorageEventSchema {
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentLoad: number;
|
||||
currentMaterials: { materialType: string; materialId: string; }[];
|
||||
currentMaterials: { materialType: string; materialId: string }[];
|
||||
}
|
||||
|
||||
interface HumanStatus extends HumanEventSchema {
|
||||
@@ -302,7 +298,7 @@ interface HumanStatus extends HumanEventSchema {
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentLoad: number;
|
||||
currentMaterials: { materialType: string; materialId: string; }[];
|
||||
currentMaterials: { materialType: string; materialId: string }[];
|
||||
distanceTraveled: number;
|
||||
currentAction?: {
|
||||
actionUuid: string;
|
||||
@@ -319,7 +315,7 @@ interface CraneStatus extends CraneEventSchema {
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentLoad: number;
|
||||
currentMaterials: { materialType: string; materialId: string; }[];
|
||||
currentMaterials: { materialType: string; materialId: string }[];
|
||||
currentAction?: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
@@ -328,13 +324,12 @@ interface CraneStatus extends CraneEventSchema {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// Event Manager
|
||||
|
||||
type HumanEventState = {
|
||||
humanId: string;
|
||||
actionQueue: {
|
||||
actionType: 'worker' | 'manufacturer' | 'operator';
|
||||
actionType: "worker" | "manufacturer" | "operator";
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
maxLoadCount: number;
|
||||
@@ -368,7 +363,6 @@ type CraneEventManagerState = {
|
||||
craneStates: CraneEventState[];
|
||||
};
|
||||
|
||||
|
||||
// Materials
|
||||
|
||||
interface MaterialSchema {
|
||||
@@ -404,16 +398,15 @@ interface MaterialSchema {
|
||||
|
||||
type MaterialsSchema = MaterialSchema[];
|
||||
|
||||
|
||||
// Products
|
||||
|
||||
type productsSchema = {
|
||||
productName: string;
|
||||
productUuid: string;
|
||||
eventDatas: EventsSchema[];
|
||||
timestamp?: string;
|
||||
}[];
|
||||
|
||||
|
||||
// Material History
|
||||
|
||||
interface MaterialHistoryEntry {
|
||||
@@ -423,7 +416,6 @@ interface MaterialHistoryEntry {
|
||||
|
||||
type MaterialHistorySchema = MaterialHistoryEntry[];
|
||||
|
||||
|
||||
// IK Constraints
|
||||
|
||||
type Link = {
|
||||
@@ -447,33 +439,32 @@ type IK = {
|
||||
// Conveyor Spline Points
|
||||
|
||||
type NormalConveyor = {
|
||||
type: 'normal';
|
||||
type: "normal";
|
||||
points: [number, number, number][][];
|
||||
}
|
||||
};
|
||||
|
||||
type YJunctionConveyor = {
|
||||
type: 'y-junction';
|
||||
type: "y-junction";
|
||||
points: [number, number, number][][];
|
||||
}
|
||||
};
|
||||
|
||||
type CurvedConveyor = {
|
||||
type: 'curved';
|
||||
type: "curved";
|
||||
points: [number, number, number][][];
|
||||
}
|
||||
};
|
||||
|
||||
type ConveyorPoints = NormalConveyor | YJunctionConveyor | CurvedConveyor;
|
||||
|
||||
|
||||
// Crane Constraints
|
||||
|
||||
type PillarJibCrane = {
|
||||
trolleySpeed: number;
|
||||
hookSpeed: number;
|
||||
rotationSpeed: number;
|
||||
trolleyMinOffset: number
|
||||
trolleyMinOffset: number;
|
||||
trolleyMaxOffset: number;
|
||||
hookMinOffset: number;
|
||||
hookMaxOffset: number;
|
||||
}
|
||||
};
|
||||
|
||||
type CraneConstraints = PillarJibCrane;
|
||||
Reference in New Issue
Block a user