updated with github
This commit is contained in:
+45
-105
@@ -1,103 +1,3 @@
|
||||
# import os
|
||||
# import yaml
|
||||
# from collections import OrderedDict
|
||||
# from flask import Flask, jsonify, send_from_directory, request, redirect, url_for, session, render_template
|
||||
# from werkzeug.security import check_password_hash
|
||||
# import database # Imports the database.py you created earlier
|
||||
|
||||
# # --- Path Configurations ---
|
||||
# BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
# FRONTEND_DIR = os.path.join(BASE_DIR, '..', 'frontend')
|
||||
|
||||
# # Use os.path.join exclusively for cross-platform safety
|
||||
# YML_PATH = os.path.join(BASE_DIR, '..', 'mxpic', 'PDKs', 'Silterra', 'directories.yaml')
|
||||
# COMPS_ROOT = os.path.join(BASE_DIR, '..', 'mxpic', 'PDKs', 'Silterra')
|
||||
|
||||
# # Initialize Flask, pointing to the frontend folder for HTML/CSS/JS
|
||||
# app = Flask(__name__, template_folder=FRONTEND_DIR, static_folder=FRONTEND_DIR)
|
||||
# app.secret_key = 'super_secret_mxpic_key' # Required for session management
|
||||
# app.json.sort_keys = False # Keep dictionary order
|
||||
|
||||
# # Ensure database tables exist when the server boots
|
||||
# database.init_db()
|
||||
|
||||
# # --- YAML & PDK Parsing Helper Functions (Unchanged) ---
|
||||
# def countSpaces(line):
|
||||
# """Count leading spaces (tab=4)."""
|
||||
# expanded = line.expandtabs(4)
|
||||
# return len(expanded) - len(expanded.lstrip(' '))
|
||||
|
||||
# def buildTree(filepath):
|
||||
# """Build nested tree from indented yaml."""
|
||||
# if not os.path.exists(filepath):
|
||||
# return OrderedDict()
|
||||
|
||||
# with open(filepath, 'r', encoding='utf-8') as f:
|
||||
# lines = f.readlines()
|
||||
|
||||
# rootIdx = None
|
||||
# for i, line in enumerate(lines):
|
||||
# if line.strip().startswith('root') and ':' in line.strip():
|
||||
# rootIdx = i
|
||||
# break
|
||||
# if rootIdx is None:
|
||||
# return OrderedDict()
|
||||
|
||||
# entries = []
|
||||
# for line in lines[rootIdx + 1:]:
|
||||
# stripped = line.strip()
|
||||
# if not stripped or stripped.startswith('#'):
|
||||
# continue
|
||||
# if stripped.startswith('- '):
|
||||
# spaceNum = countSpaces(line)
|
||||
# # FIX 1: Strip trailing colons off the string so 'composites:' becomes 'composites'
|
||||
# name = stripped[2:].strip().rstrip(':')
|
||||
# if name:
|
||||
# entries.append((spaceNum, name))
|
||||
|
||||
# if not entries:
|
||||
# return OrderedDict()
|
||||
|
||||
# minIndent = min(indent for indent, _ in entries)
|
||||
# nest = OrderedDict()
|
||||
# levelStack = [(minIndent - 1, nest)]
|
||||
|
||||
# for spaceNum, name in entries:
|
||||
# while levelStack and levelStack[-1][0] >= spaceNum:
|
||||
# levelStack.pop()
|
||||
# parent = levelStack[-1][1]
|
||||
# child = OrderedDict()
|
||||
# parent[name] = child
|
||||
# levelStack.append((spaceNum, child))
|
||||
|
||||
# return nest
|
||||
|
||||
# def addCompsToTree(compMap):
|
||||
# """
|
||||
# Build a completely fresh tree from scratch and insert component nodes.
|
||||
# No previous tree object or inspection required.
|
||||
# """
|
||||
# # Initialize a clean, empty root tree
|
||||
# fresh_tree = OrderedDict()
|
||||
|
||||
# for pathSeg, compItem in compMap.items():
|
||||
# compName = compItem['folder']
|
||||
# curNode = fresh_tree
|
||||
|
||||
# # Sequentially build the nested path segments dynamically
|
||||
# for seg in pathSeg:
|
||||
# if seg not in curNode:
|
||||
# curNode[seg] = OrderedDict()
|
||||
# curNode = curNode[seg]
|
||||
|
||||
# # Place the component metadata dictionary into its leaf node
|
||||
# curNode[compName] = OrderedDict({
|
||||
# "__type__": "component",
|
||||
# "__name__": compName,
|
||||
# "__yml__": compItem['yml']
|
||||
# })
|
||||
|
||||
# return fresh_tree
|
||||
|
||||
import os
|
||||
import yaml
|
||||
@@ -105,6 +5,7 @@ from collections import OrderedDict
|
||||
from flask import Flask, jsonify, send_from_directory, request, redirect, url_for, session, render_template
|
||||
from werkzeug.security import check_password_hash
|
||||
import database
|
||||
from flask import Response
|
||||
|
||||
# --- Path Configurations ---
|
||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
@@ -115,6 +16,10 @@ COMPS_ROOT = os.path.join(BASE_DIR, '..', 'mxpic', 'PDKs', 'Silterra')
|
||||
# Define where your new icons folder is located (adjust if it's placed elsewhere)
|
||||
ICONS_DIR = os.path.join(BASE_DIR, 'icons')
|
||||
|
||||
#build layout save path
|
||||
SAVE_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'generated_layouts')
|
||||
|
||||
|
||||
app = Flask(__name__, template_folder=FRONTEND_DIR, static_folder=FRONTEND_DIR)
|
||||
app.secret_key = 'super_secret_mxpic_key'
|
||||
app.json.sort_keys = False
|
||||
@@ -175,18 +80,22 @@ def addCompsToTree(compMap):
|
||||
@app.route('/api/icon/<category>')
|
||||
def getIcon(category):
|
||||
"""Serve the icon corresponding to the component category."""
|
||||
# Look for an image matching the category name (e.g., edge_coupler.png)
|
||||
for ext in ('.png', '.svg', '.jpg'):
|
||||
icon_path = os.path.join(ICONS_DIR, f"{category}{ext}")
|
||||
if os.path.exists(icon_path):
|
||||
return send_from_directory(ICONS_DIR, f"{category}{ext}")
|
||||
|
||||
# Optional: Return a default fallback icon if the specific one is missing
|
||||
fallback = os.path.join(ICONS_DIR, "default.png")
|
||||
if os.path.exists(fallback):
|
||||
return send_from_directory(ICONS_DIR, "default.png")
|
||||
|
||||
return jsonify({"error": "Icon not found"}), 404
|
||||
|
||||
# return png if not found
|
||||
transparent_png = (
|
||||
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01'
|
||||
b'\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01'
|
||||
b'\x00\x00\x05\x00\x01\r\n\xf4\xc0\x00\x00\x00\x00IEND\xaeB`\x82'
|
||||
)
|
||||
return Response(transparent_png, mimetype='image/png')
|
||||
|
||||
# ... [Keep existing API routes below] ...
|
||||
|
||||
@@ -249,6 +158,33 @@ def logout():
|
||||
session.clear()
|
||||
return redirect(url_for('home'))
|
||||
|
||||
|
||||
|
||||
|
||||
@app.route('/api/save-layout', methods=['POST'])
|
||||
def save_layout():
|
||||
try:
|
||||
data = request.get_json()
|
||||
filename = data.get('filename', 'layout.yaml')
|
||||
content = data.get('content', '')
|
||||
|
||||
os.makedirs(SAVE_DIR, exist_ok=True)
|
||||
|
||||
save_path = os.path.join(SAVE_DIR, filename)
|
||||
|
||||
with open(save_path, 'w', encoding='utf-8') as f:
|
||||
f.write(content)
|
||||
|
||||
return jsonify({
|
||||
"message": "successfully saved",
|
||||
"path": save_path
|
||||
}), 200
|
||||
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
|
||||
# --- API ROUTES (Library & Components) ---
|
||||
@app.route('/api/library')
|
||||
def getLib():
|
||||
@@ -284,4 +220,8 @@ def getCompImg(component_name):
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Starting mxpic EDA Server on http://127.0.0.1:3000")
|
||||
app.run(host='127.0.0.1', port=3000, debug=True)
|
||||
app.run(host='127.0.0.1', port=3000, debug=True)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user