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