summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSuchita Lad2025-04-09 12:48:51 +0530
committerSuchita Lad2025-04-09 12:48:51 +0530
commit677377ec1ea15a1fbfc831b5b9fcd1fdd6760ea9 (patch)
treeaaf83dbff7a1856e8e96e45bd956a06a6d14da47
parent27ea203ca1c6b38665d310f607387dadd5c24b31 (diff)
downloadCommon-Interface-Project-677377ec1ea15a1fbfc831b5b9fcd1fdd6760ea9.tar.gz
Common-Interface-Project-677377ec1ea15a1fbfc831b5b9fcd1fdd6760ea9.tar.bz2
Common-Interface-Project-677377ec1ea15a1fbfc831b5b9fcd1fdd6760ea9.zip
Added auto execute script feature on loading diagram
-rwxr-xr-xblocks/Xcos/MxGraphParser.py9
-rwxr-xr-xblocks/Xcos/XmlToXcos.sh10
-rw-r--r--blocks/Xcos/common/AAAAAA.py10
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js2
-rw-r--r--blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js14
-rw-r--r--blocks/eda-frontend/src/redux/saveSchematicSlice.js2
-rw-r--r--blocks/simulationAPI/helpers/ngspice_helper.py10
-rw-r--r--blocks/simulationAPI/views.py13
8 files changed, 53 insertions, 17 deletions
diff --git a/blocks/Xcos/MxGraphParser.py b/blocks/Xcos/MxGraphParser.py
index c4204bd2..cf12a400 100755
--- a/blocks/Xcos/MxGraphParser.py
+++ b/blocks/Xcos/MxGraphParser.py
@@ -9,11 +9,12 @@ import defusedxml.ElementTree as goodET
from xcosblocks import process_xcos_model, remove_hyphen_number
-if len(sys.argv) != 2:
- print("Usage: %s filename.xml" % sys.argv[0])
+if len(sys.argv) != 3:
+ print("Usage: %s filename.xml workspace.dat" % sys.argv[0])
sys.exit(1)
filename = sys.argv[1]
+workspace_file = sys.argv[2]
(basename, ext) = os.path.splitext(filename)
if ext != '.xml':
@@ -24,12 +25,12 @@ title = re.sub(r'^.*/', r'', filename)
title = re.sub(base, r'', title)
tree = goodET.parse(filename)
-
model = tree.getroot()
rootattribid = '0:1:0'
parentattribid = '0:2:0'
-outdiagram = process_xcos_model(model, title, rootattribid, parentattribid)
+
+outdiagram = process_xcos_model(model, title, rootattribid, parentattribid, workspace_file)
outtree = ET.ElementTree(outdiagram)
diff --git a/blocks/Xcos/XmlToXcos.sh b/blocks/Xcos/XmlToXcos.sh
index b6f539e2..05cde250 100755
--- a/blocks/Xcos/XmlToXcos.sh
+++ b/blocks/Xcos/XmlToXcos.sh
@@ -2,11 +2,11 @@
usage() {
echo "Usage:" >&2
- echo " $0 input-file.xml" >&2
+ echo " $0 input-file.xml workspace.dat" >&2
exit 101
}
-if test $# -ne 1; then
+if test $# -ne 2; then
usage
fi
@@ -23,6 +23,8 @@ else
usage
fi
+WORKSPACE="$2"
+
set -e
TMPFILE2="$(mktemp -t XXXXXX.xml)"
@@ -59,8 +61,8 @@ INPUT1="$BASE-$rv.xml"
xmllint --format "$INPUT1" >"$TMPFILE2"
cp -f "$TMPFILE2" "$INPUT1"
-echo "Running Xcos/MxGraphParser.py $INPUT1" >&2
-Xcos/MxGraphParser.py "$INPUT1" >&2
+echo "Running Xcos/MxGraphParser.py $INPUT1 $WORKSPACE" >&2
+Xcos/MxGraphParser.py "$INPUT1" "$WORKSPACE" >&2
INPUT1="$BASE.xcos"
echo "Created $INPUT1" >&2
diff --git a/blocks/Xcos/common/AAAAAA.py b/blocks/Xcos/common/AAAAAA.py
index cf691199..87856e5e 100644
--- a/blocks/Xcos/common/AAAAAA.py
+++ b/blocks/Xcos/common/AAAAAA.py
@@ -718,12 +718,18 @@ def get_number_power(value):
value)
-def format_real_number(parameter):
+def format_real_number(parameter, workspace_file):
if not parameter.strip(): # Handle empty strings
return '0'
elif re.search(r'[dDeE\^]', parameter): # Check for scientific notation
real_number = float(parameter.replace('*10^', 'e').replace('10^', '1e').replace('d', 'e').replace('D', 'e'))
- return "{:.10g}".format(real_number)
+ return "{:.10g}".format(real_number)
+ elif re.search(r'[a-zA-Z]', parameter): # Check if parameter contains alphabetic characters
+ print('send to Scilab', workspace_file)
+ with open("params.txt", "a") as f:
+ f.write(parameter + "\n")
+ # uploadscript("params.txt")
+ # return parameter # Or return some status
try:
return "{:.10g}".format(float(parameter)) # Convert numeric strings safely
except ValueError:
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
index 259803b4..f1cc65b1 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/SchematicToolbar.js
@@ -101,6 +101,7 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) {
const description = useSelector(state => state.saveSchematic.description)
const xmlData = useSelector(state => state.saveSchematic.xmlData)
const title2 = useSelector(state => state.saveSchematic.title)
+ const scriptTaskId = useSelector(state => state.simulation.scriptTaskId)
const scriptDump = useSelector(state => state.saveSchematic.scriptDump)
const showDot = useSelector(state => state.saveSchematic.showDot)
@@ -333,6 +334,7 @@ export default function SchematicToolbar ({ mobileClose, gridRef }) {
const formData = new FormData()
formData.append('file', xmlBlob, xmlFileName)
+ formData.append('scriptTaskId', scriptTaskId)
const config = {
headers: {
diff --git a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
index 84686ce2..381e40de 100644
--- a/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
+++ b/blocks/eda-frontend/src/components/SchematicEditor/ToolbarExtension.js
@@ -341,6 +341,8 @@ HelpScreen.propTypes = {
export function ScriptScreen ({ isOpen, onClose }) {
const scriptDump = useSelector(state => state.saveSchematic.scriptDump)
const title = useSelector(state => state.saveSchematic.title)
+ const showDot = useSelector(state => state.saveSchematic.showDot)
+ const fetchComplete = useSelector((state) => state.saveSchematic.fetchComplete)
const dispatch = useDispatch()
const [result, setResult] = useState('No output yet...')
const [variables, setVariables] = useState([])
@@ -349,6 +351,16 @@ export function ScriptScreen ({ isOpen, onClose }) {
dispatch(setShowDot(true))
}
+ useEffect(() => {
+ if (fetchComplete) {
+ const timer = setTimeout(() => {
+ executeScript()
+ }, 1000)
+
+ return () => clearTimeout(timer)
+ }
+ }, [fetchComplete])
+
const prepareScriptNetlist = (scriptDump) => {
const titleA = sanitizeTitle(title)
const myblob = new Blob([scriptDump], {
@@ -581,7 +593,7 @@ export function ScriptScreen ({ isOpen, onClose }) {
{/* Action Buttons */}
<Box sx={{ mt: 4, display: 'flex', gap: 4 }}>
- <Button onClick={executeScript} color='primary' variant='contained'>
+ <Button onClick={executeScript} color='primary' variant='contained' disabled={!showDot}>
Execute
</Button>
<Button onClick={resetCode} color='secondary' variant='contained'>
diff --git a/blocks/eda-frontend/src/redux/saveSchematicSlice.js b/blocks/eda-frontend/src/redux/saveSchematicSlice.js
index 7cfdcf3c..a36b9468 100644
--- a/blocks/eda-frontend/src/redux/saveSchematicSlice.js
+++ b/blocks/eda-frontend/src/redux/saveSchematicSlice.js
@@ -236,6 +236,8 @@ const saveSchematicSlice = createSlice({
state.xmlData = action.payload.data_dump
state.scriptDump = action.payload.script_dump
state.showDot = action.payload.script_dump !== ''
+ state.fetchComplete = action.payload.script_dump !== ''
+ // state.showDot = true
})
.addCase(fetchDiagram.rejected, (state) => {
state.isLoading = false
diff --git a/blocks/simulationAPI/helpers/ngspice_helper.py b/blocks/simulationAPI/helpers/ngspice_helper.py
index a7d86262..66df93d2 100644
--- a/blocks/simulationAPI/helpers/ngspice_helper.py
+++ b/blocks/simulationAPI/helpers/ngspice_helper.py
@@ -73,7 +73,7 @@ def update_task_status(task_id, status, meta=None):
)
-def CreateXml(file_path, parameters, task_id):
+def CreateXml(file_path, parameters, task_id, workspace_file):
parameters = json.loads(parameters)
current_dir = settings.MEDIA_ROOT + '/' + str(task_id)
# Make Unique Directory for simulation to run
@@ -82,7 +82,7 @@ def CreateXml(file_path, parameters, task_id):
(xcosfilebase, __) = splitext(file_path)
xcosfile = xcosfilebase + '.xcos'
logger.info('will run %s %s', 'XmlToXcos', file_path)
- proc = subprocess.Popen([XmlToXcos, file_path],
+ proc = subprocess.Popen([XmlToXcos, file_path, workspace_file],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = proc.communicate()
@@ -111,8 +111,8 @@ def CreateXml(file_path, parameters, task_id):
raise e
-def CreateXcos(file_path, parameters, task_id):
- xcosfile = CreateXml(file_path, parameters, task_id)
+def CreateXcos(file_path, parameters, task_id, workspace_file):
+ xcosfile = CreateXml(file_path, parameters, task_id, workspace_file)
return xcosfile
@@ -123,7 +123,7 @@ def ExecXml(task, task_name, workspace_file):
current_dir = settings.MEDIA_ROOT + '/' + str(task_id)
try:
# Create xcos file
- xcosfile = CreateXml(file_path, task.parameters, task_id)
+ xcosfile = CreateXml(file_path, task.parameters, task_id, workspace_file)
upload(task.session, task, xcosfile)
result = start_scilab(task.session, task, xcosfile)
diff --git a/blocks/simulationAPI/views.py b/blocks/simulationAPI/views.py
index 55093377..4d74e4e0 100644
--- a/blocks/simulationAPI/views.py
+++ b/blocks/simulationAPI/views.py
@@ -110,6 +110,7 @@ class XmlSave(APIView):
def post(self, request, *args, **kwargs):
logger.info('Got POST for Xml save: data=%s', request.data)
file = request.FILES.get('file', None)
+ script_task_id = request.POST.get('scriptTaskId', None)
if not file:
return Response({"error": "No file provided"}, status=status.HTTP_400_BAD_REQUEST)
file_name = file.name
@@ -122,11 +123,21 @@ class XmlSave(APIView):
for chunk in file.chunks():
destination.write(chunk)
+ if script_task_id:
+ try:
+ script_task = Task.objects.get(task_id=script_task_id)
+ workspace_file = script_task.workspace_file
+ except Task.DoesNotExist:
+ print("Task not found")
+ else:
+ print("No scriptTaskId provided")
+
+ logger.info('workspace_file: %s', workspace_file)
try:
# Update the request data to include the file path
data = request.data.copy()
data['file_path'] = file_path
- filename = CreateXcos(data['file_path'], '{}', 'saves')
+ filename = CreateXcos(data['file_path'], '{}', 'saves', workspace_file)
with open(filename, 'r') as file:
filecontent = file.read()