Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosimulation feature 1 #233

Open
wants to merge 23 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c33f866
Revert "cleaned up the code from comments and unused code"
PandoraQS Jun 22, 2024
3b05bde
Merge branch 'development' of https://github.com/PandoraQS/into-cps-a…
PandoraQS Nov 25, 2024
fa826a3
fixed serve port
PandoraQS Nov 25, 2024
b3788c3
feature 1 - cosimulation page and coe server
PandoraQS Nov 27, 2024
474ba9a
removed coments
PandoraQS Nov 27, 2024
41b4ab2
cosimulation work in progress
PandoraQS Nov 29, 2024
357d2f7
removed coe, mm and fmus from codebase, used .env for coe configurati…
PandoraQS Dec 1, 2024
c81ef80
Fixed sidebar collapse and resopnsiveness
PandoraQS Dec 5, 2024
df13d65
new project structure path and renamed json files in main
PandoraQS Dec 6, 2024
66660e0
removed coe for maestro and fixed start and build configurations
PandoraQS Dec 15, 2024
25c1fab
new error for missing java, including env path for windows
SimoneMicalizzi Dec 15, 2024
ecc8b28
Merge branch 'development' into cosimulation-feature-1
PandoraQS Dec 15, 2024
37bbcf9
integrated maestro with existing logic for cosimulation
PandoraQS Dec 15, 2024
8569e1f
constants redefinition, any statements removal, separation of cosimul…
PandoraQS Dec 23, 2024
c2987fd
defined a constants management structure
PandoraQS Dec 23, 2024
386e85a
Review work in progress
PandoraQS Dec 29, 2024
6f5cb84
PR #223 work in progress
PandoraQS Dec 30, 2024
e43cbe6
Documentation for the application modules interactions, first version…
PandoraQS Jan 9, 2025
94db5d1
fixed markdown lint
PandoraQS Jan 10, 2025
4e00d19
Maestro model and Maestro Model with IPC and UI
PandoraQS Jan 10, 2025
88f4f31
React App diagrams
PandoraQS Jan 13, 2025
050bd9b
Package diagram + react ipc communication + constant fix in app
PandoraQS Jan 16, 2025
2b1ef92
fixed mardkown + wip maestro single channel configuration
PandoraQS Jan 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ pkg/
/playwright-report/
/blob-report/
/playwright/.cache/
/src/resources/coe
743 changes: 420 additions & 323 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"build": "rimraf release/ && node esbuild.config.mjs && electron-builder --x64",
"build:win": "npm run build && .\\convert-to-msix.bat",
"start": "node esbuild.config.mjs --dev && concurrently \"npm run serve\" \"npm run electron-start\"",
"serve": "serve dist -l 8080 --cors",
"electron-start": "wait-on http://localhost:8080 && npx electron dist/main.js",
"serve": "serve dist -l 3000 --cors",
"electron-start": "wait-on http://localhost:3000 && npx electron dist/main.js",
"syntax": "npx eslint . --fix",
"clean": "npx rimraf dist monocart-report release pkg test-results test/coverage-reports && npm ci"
},
Expand All @@ -42,7 +42,11 @@
},
"win": {
"icon": "src/resources/into-cps/appicon/into-cps-logo.png.ico",
"target": ["nsis", "msi", "portable"],
"target": [
"nsis",
"msi",
"portable"
],
"signAndEditExecutable": false,
"forceCodeSigning": false
},
Expand All @@ -69,7 +73,9 @@
"monocart-coverage-reports": "^2.11.1",
"playwright": "^1.48.2",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-router-dom": "^7.0.1",
"tree-kill": "^1.2.2"
},
"devDependencies": {
"@eslint/js": "^9.14.0",
Expand Down Expand Up @@ -97,4 +103,4 @@
"typescript-eslint": "^8.12.2",
"wait-on": "^8.0.1"
}
}
}
7 changes: 6 additions & 1 deletion preload.js
PandoraQS marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
},
removeToggleDarkModeListener: () => {
ipcRenderer.removeAllListeners('toggle-dark-mode');
}
},
readJsonFile: (relativePath) => {
return ipcRenderer.invoke('read-json-file', relativePath)
},
startCoe: () => ipcRenderer.invoke('start-coe'),
stopCoe: () => ipcRenderer.invoke('stop-coe'),
});
31 changes: 17 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, { useState, useEffect } from 'react';
import { HashRouter as Router, Routes, Route } from 'react-router-dom';
import { ThemeProvider, CssBaseline, Box } from '@mui/material';
import { lightTheme, darkTheme } from './themes';
import Sidebar from './components/Sidebar';
import Main from './components/Main';
import Bottom from './components/Bottom';
import Main from './components/Main';
import Cosimulation from './components/Cosimulation/Cosimulation';

const App: React.FC = () => {
const [darkMode, setDarkMode] = useState(false);
Expand All @@ -16,34 +18,35 @@ const App: React.FC = () => {
const handleToggleDarkMode = () => {
toggleDarkMode();
};

if (window.electronAPI) {
window.electronAPI.addToggleDarkModeListener(handleToggleDarkMode);
} else {
console.warn('window.electronAPI not found');
}

return () => {
if (window.electronAPI) {
window.electronAPI.removeToggleDarkModeListener();
}
};
}, []);



return (
<ThemeProvider theme={darkMode ? darkTheme : lightTheme}>
<ThemeProvider theme={darkMode ? lightTheme : darkTheme}>
<CssBaseline />
<Box sx={{ display: 'flex', minHeight: '100vh' }}>
<Sidebar />

<Box component="main" sx={{ flexGrow: 1, p: 3, position: 'relative' }}>
<Main />
<Router>
<Box sx={{ display: 'flex', minHeight: '100vh' }}>
<Sidebar />
<Box component="main" sx={{ flexGrow: 1, p: 3, position: 'relative' }}>
<Routes>
<Route path="/" element={<Main />} />
<Route path="/cosimulation" element={<Cosimulation />} />
</Routes>
</Box>
<Bottom />
</Box>

<Bottom />
</Box>
</Router>
</ThemeProvider>
);
};
Expand Down
23 changes: 20 additions & 3 deletions src/components/Bottom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import StopCircleIcon from '@mui/icons-material/StopCircle';
const Bottom: React.FC = () => {
const [coeRunning, setCoeRunning] = useState(false);

const toggleCoeState = () => setCoeRunning((prev) => !prev);
const toggleCoeState = async () => {
try {
if (coeRunning) {
await window?.electronAPI?.stopCoe();
} else {
await window?.electronAPI?.startCoe();
}
setCoeRunning(!coeRunning);
} catch (error) {
console.error('Error toggling COE:', error);
}
};

return (
<Box
Expand All @@ -18,12 +29,18 @@ const Bottom: React.FC = () => {
bgcolor: 'background.paper',
boxShadow: 3,
}}
>
>
<BottomNavigation showLabels sx={{ justifyContent: 'flex-start' }}>
<BottomNavigationAction
id="coe-btn-launch-bottom"
label={<Typography>{coeRunning ? 'Stop COE' : 'Start COE'}</Typography>}
icon={coeRunning ? <StopCircleIcon id="coeIconColor" color="error" /> : <PlayCircleOutlineIcon id="coeIconColor" color="primary" />}
icon={
coeRunning ? (
<StopCircleIcon id="coeIconColor" color="error" />
) : (
<PlayCircleOutlineIcon id="coeIconColor" color="primary" />
)
}
onClick={toggleCoeState}
/>
</BottomNavigation>
Expand Down
51 changes: 51 additions & 0 deletions src/components/Cosimulation/Cosimulation.tsx
PandoraQS marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import React, { useEffect, useState } from 'react';
import { Typography, Skeleton, Box } from '@mui/material';
import { renderJson } from '../../utils/renderJson';

const Cosimulation: React.FC = () => {
const filePath = 'cosimulation/2018may7/coe.json';
const [jsonData, setJsonData] = useState<any>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchJson = async () => {
try {
console.log('window.electronAPI:', window?.electronAPI);
console.log('readJsonFile exists:', typeof window?.electronAPI?.readJsonFile === 'function');

console.log('Fetching JSON from:', filePath);
const data = await window?.electronAPI?.readJsonFile(filePath); // Dovrebbe ora ricevere i dati
PandoraQS marked this conversation as resolved.
Show resolved Hide resolved
console.log('Data fetched:', data); // Dovrebbe loggare il JSON correttamente
setJsonData(data);
} catch (err) {
console.error('Error fetching JSON:', err);
setError('Failed to load JSON file.');
}
};

fetchJson();
}, []);


return (
<Box>
<Typography variant="h4" component="h1" gutterBottom>
Cosimulation
</Typography>
<Typography variant="h6" component="h6" gutterBottom>
{filePath}
</Typography>
{error ? (
<Typography variant="body2" color="error">
{error}
</Typography>
) : jsonData ? (
renderJson(jsonData)
) : (
<Skeleton animation="wave" />
)}
</Box>
);
};

export default Cosimulation;
14 changes: 12 additions & 2 deletions src/components/Sidebar.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application needs to be responsive. For example, please see this code

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Drawer, List, Divider, Toolbar } from '@mui/material';
import { Drawer, List, ListItem, ListItemText, ListItemButton, Toolbar } from '@mui/material';
import { NavLink } from 'react-router-dom';

const Sidebar: React.FC = () => (
<Drawer
Expand All @@ -11,8 +12,17 @@ const Sidebar: React.FC = () => (
}}
>
<Toolbar />
<Divider />
<List>
<ListItem disablePadding>
<ListItemButton component={NavLink} to="/">
<ListItemText primary="Home" />
</ListItemButton>
</ListItem>
<ListItem disablePadding>
<ListItemButton component={NavLink} to="/cosimulation">
<ListItemText primary="Cosimulation" />
</ListItemButton>
</ListItem>
</List>
</Drawer>
);
Expand Down
Loading