Compare commits
5 Commits
fed72676bc
...
feat/runne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da2a360c56 | ||
|
|
3dd0da3964 | ||
|
|
4921095296 | ||
|
|
3a9fe6aed8 | ||
|
|
9e99b83091 |
463
freecad/dag.py
Normal file
463
freecad/dag.py
Normal file
@@ -0,0 +1,463 @@
|
||||
"""DAG extraction engine for FreeCAD documents.
|
||||
|
||||
Extracts the feature tree from a FreeCAD document as nodes and edges
|
||||
for syncing to the Silo server. No GUI dependencies -- usable in both
|
||||
desktop and headless (``--console``) mode.
|
||||
|
||||
Public API
|
||||
----------
|
||||
classify_type(type_id) -> Optional[str]
|
||||
compute_properties_hash(obj) -> str
|
||||
extract_dag(doc) -> (nodes, edges)
|
||||
"""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import math
|
||||
from typing import Any, Dict, List, Optional, Set, Tuple
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# TypeId -> DAG node type mapping
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_TYPE_MAP: Dict[str, str] = {
|
||||
# Sketch
|
||||
"Sketcher::SketchObject": "sketch",
|
||||
# Sketch-based additive
|
||||
"PartDesign::Pad": "pad",
|
||||
"PartDesign::Revolution": "pad",
|
||||
"PartDesign::AdditivePipe": "pad",
|
||||
"PartDesign::AdditiveLoft": "pad",
|
||||
"PartDesign::AdditiveHelix": "pad",
|
||||
# Sketch-based subtractive
|
||||
"PartDesign::Pocket": "pocket",
|
||||
"PartDesign::Groove": "pocket",
|
||||
"PartDesign::Hole": "pocket",
|
||||
"PartDesign::SubtractivePipe": "pocket",
|
||||
"PartDesign::SubtractiveLoft": "pocket",
|
||||
"PartDesign::SubtractiveHelix": "pocket",
|
||||
# Dress-up
|
||||
"PartDesign::Fillet": "fillet",
|
||||
"PartDesign::Chamfer": "chamfer",
|
||||
"PartDesign::Draft": "chamfer",
|
||||
"PartDesign::Thickness": "chamfer",
|
||||
# Transformations
|
||||
"PartDesign::Mirrored": "pad",
|
||||
"PartDesign::LinearPattern": "pad",
|
||||
"PartDesign::PolarPattern": "pad",
|
||||
"PartDesign::Scaled": "pad",
|
||||
"PartDesign::MultiTransform": "pad",
|
||||
# Boolean
|
||||
"PartDesign::Boolean": "pad",
|
||||
# Additive primitives
|
||||
"PartDesign::AdditiveBox": "pad",
|
||||
"PartDesign::AdditiveCylinder": "pad",
|
||||
"PartDesign::AdditiveSphere": "pad",
|
||||
"PartDesign::AdditiveCone": "pad",
|
||||
"PartDesign::AdditiveEllipsoid": "pad",
|
||||
"PartDesign::AdditiveTorus": "pad",
|
||||
"PartDesign::AdditivePrism": "pad",
|
||||
"PartDesign::AdditiveWedge": "pad",
|
||||
# Subtractive primitives
|
||||
"PartDesign::SubtractiveBox": "pocket",
|
||||
"PartDesign::SubtractiveCylinder": "pocket",
|
||||
"PartDesign::SubtractiveSphere": "pocket",
|
||||
"PartDesign::SubtractiveCone": "pocket",
|
||||
"PartDesign::SubtractiveEllipsoid": "pocket",
|
||||
"PartDesign::SubtractiveTorus": "pocket",
|
||||
"PartDesign::SubtractivePrism": "pocket",
|
||||
"PartDesign::SubtractiveWedge": "pocket",
|
||||
# Containers
|
||||
"PartDesign::Body": "body",
|
||||
"App::Part": "part",
|
||||
"Part::Feature": "part",
|
||||
# Datum / reference
|
||||
"PartDesign::Point": "datum",
|
||||
"PartDesign::Line": "datum",
|
||||
"PartDesign::Plane": "datum",
|
||||
"PartDesign::CoordinateSystem": "datum",
|
||||
"PartDesign::ShapeBinder": "datum",
|
||||
"PartDesign::SubShapeBinder": "datum",
|
||||
}
|
||||
|
||||
|
||||
def classify_type(type_id: str) -> Optional[str]:
|
||||
"""Map a FreeCAD TypeId string to a DAG node type.
|
||||
|
||||
Returns one of ``sketch``, ``pad``, ``pocket``, ``fillet``,
|
||||
``chamfer``, ``body``, ``part``, ``datum``, or ``None`` if the
|
||||
TypeId is not a recognized feature.
|
||||
"""
|
||||
return _TYPE_MAP.get(type_id)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Properties hash
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def _safe_float(val: Any) -> Any:
|
||||
"""Convert a float to a JSON-safe value, replacing NaN/Infinity with 0."""
|
||||
if isinstance(val, float) and (math.isnan(val) or math.isinf(val)):
|
||||
return 0.0
|
||||
return val
|
||||
|
||||
|
||||
def _prop_value(obj: Any, name: str) -> Any:
|
||||
"""Safely read ``obj.<name>.Value``, returning *None* on failure."""
|
||||
try:
|
||||
return _safe_float(getattr(obj, name).Value)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _prop_raw(obj: Any, name: str) -> Any:
|
||||
"""Safely read ``obj.<name>``, returning *None* on failure."""
|
||||
try:
|
||||
return getattr(obj, name)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _link_name(obj: Any, name: str) -> Optional[str]:
|
||||
"""Return the ``.Name`` of a linked object property, or *None*."""
|
||||
try:
|
||||
link = getattr(obj, name)
|
||||
if isinstance(link, (list, tuple)):
|
||||
link = link[0]
|
||||
return link.Name if link is not None else None
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
def _collect_inputs(obj: Any) -> Dict[str, Any]:
|
||||
"""Extract the parametric inputs that affect *obj*'s geometry.
|
||||
|
||||
The returned dict is JSON-serialized and hashed to produce the
|
||||
``properties_hash`` for the DAG node.
|
||||
"""
|
||||
tid = obj.TypeId
|
||||
inputs: Dict[str, Any] = {"_type": tid}
|
||||
|
||||
# --- Sketch ---
|
||||
if tid == "Sketcher::SketchObject":
|
||||
inputs["geometry_count"] = _prop_raw(obj, "GeometryCount")
|
||||
inputs["constraint_count"] = _prop_raw(obj, "ConstraintCount")
|
||||
try:
|
||||
inputs["geometry"] = obj.Shape.exportBrepToString()
|
||||
except Exception:
|
||||
pass
|
||||
return inputs
|
||||
|
||||
# --- Extrude (Pad / Pocket) ---
|
||||
if tid in ("PartDesign::Pad", "PartDesign::Pocket"):
|
||||
inputs["length"] = _prop_value(obj, "Length")
|
||||
inputs["type"] = str(_prop_raw(obj, "Type") or "")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
inputs["sketch"] = _link_name(obj, "Profile")
|
||||
return inputs
|
||||
|
||||
# --- Revolution / Groove ---
|
||||
if tid in ("PartDesign::Revolution", "PartDesign::Groove"):
|
||||
inputs["angle"] = _prop_value(obj, "Angle")
|
||||
inputs["type"] = str(_prop_raw(obj, "Type") or "")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
inputs["sketch"] = _link_name(obj, "Profile")
|
||||
return inputs
|
||||
|
||||
# --- Hole ---
|
||||
if tid == "PartDesign::Hole":
|
||||
inputs["diameter"] = _prop_value(obj, "Diameter")
|
||||
inputs["depth"] = _prop_value(obj, "Depth")
|
||||
inputs["threaded"] = _prop_raw(obj, "Threaded")
|
||||
inputs["thread_type"] = str(_prop_raw(obj, "ThreadType") or "")
|
||||
inputs["depth_type"] = str(_prop_raw(obj, "DepthType") or "")
|
||||
inputs["sketch"] = _link_name(obj, "Profile")
|
||||
return inputs
|
||||
|
||||
# --- Pipe / Loft / Helix (additive + subtractive) ---
|
||||
if tid in (
|
||||
"PartDesign::AdditivePipe",
|
||||
"PartDesign::SubtractivePipe",
|
||||
"PartDesign::AdditiveLoft",
|
||||
"PartDesign::SubtractiveLoft",
|
||||
"PartDesign::AdditiveHelix",
|
||||
"PartDesign::SubtractiveHelix",
|
||||
):
|
||||
inputs["sketch"] = _link_name(obj, "Profile")
|
||||
inputs["spine"] = _link_name(obj, "Spine")
|
||||
return inputs
|
||||
|
||||
# --- Fillet ---
|
||||
if tid == "PartDesign::Fillet":
|
||||
inputs["radius"] = _prop_value(obj, "Radius")
|
||||
return inputs
|
||||
|
||||
# --- Chamfer ---
|
||||
if tid == "PartDesign::Chamfer":
|
||||
inputs["chamfer_type"] = str(_prop_raw(obj, "ChamferType") or "")
|
||||
inputs["size"] = _prop_value(obj, "Size")
|
||||
inputs["size2"] = _prop_value(obj, "Size2")
|
||||
inputs["angle"] = _prop_value(obj, "Angle")
|
||||
return inputs
|
||||
|
||||
# --- Draft ---
|
||||
if tid == "PartDesign::Draft":
|
||||
inputs["angle"] = _prop_value(obj, "Angle")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
return inputs
|
||||
|
||||
# --- Thickness ---
|
||||
if tid == "PartDesign::Thickness":
|
||||
inputs["value"] = _prop_value(obj, "Value")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
inputs["mode"] = str(_prop_raw(obj, "Mode") or "")
|
||||
inputs["join"] = str(_prop_raw(obj, "Join") or "")
|
||||
return inputs
|
||||
|
||||
# --- Mirrored ---
|
||||
if tid == "PartDesign::Mirrored":
|
||||
inputs["mirror_plane"] = _link_name(obj, "MirrorPlane")
|
||||
return inputs
|
||||
|
||||
# --- LinearPattern ---
|
||||
if tid == "PartDesign::LinearPattern":
|
||||
inputs["direction"] = _link_name(obj, "Direction")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
inputs["length"] = _prop_value(obj, "Length")
|
||||
inputs["occurrences"] = _prop_value(obj, "Occurrences")
|
||||
return inputs
|
||||
|
||||
# --- PolarPattern ---
|
||||
if tid == "PartDesign::PolarPattern":
|
||||
inputs["axis"] = _link_name(obj, "Axis")
|
||||
inputs["reversed"] = _prop_raw(obj, "Reversed")
|
||||
inputs["angle"] = _prop_value(obj, "Angle")
|
||||
inputs["occurrences"] = _prop_value(obj, "Occurrences")
|
||||
return inputs
|
||||
|
||||
# --- Scaled ---
|
||||
if tid == "PartDesign::Scaled":
|
||||
inputs["factor"] = _prop_value(obj, "Factor")
|
||||
inputs["occurrences"] = _prop_value(obj, "Occurrences")
|
||||
return inputs
|
||||
|
||||
# --- MultiTransform ---
|
||||
if tid == "PartDesign::MultiTransform":
|
||||
try:
|
||||
inputs["transform_count"] = len(obj.Transformations)
|
||||
except Exception:
|
||||
pass
|
||||
return inputs
|
||||
|
||||
# --- Boolean ---
|
||||
if tid == "PartDesign::Boolean":
|
||||
inputs["type"] = str(_prop_raw(obj, "Type") or "")
|
||||
return inputs
|
||||
|
||||
# --- Primitives (additive) ---
|
||||
if tid in (
|
||||
"PartDesign::AdditiveBox",
|
||||
"PartDesign::SubtractiveBox",
|
||||
):
|
||||
inputs["length"] = _prop_value(obj, "Length")
|
||||
inputs["width"] = _prop_value(obj, "Width")
|
||||
inputs["height"] = _prop_value(obj, "Height")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveCylinder",
|
||||
"PartDesign::SubtractiveCylinder",
|
||||
):
|
||||
inputs["radius"] = _prop_value(obj, "Radius")
|
||||
inputs["height"] = _prop_value(obj, "Height")
|
||||
inputs["angle"] = _prop_value(obj, "Angle")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveSphere",
|
||||
"PartDesign::SubtractiveSphere",
|
||||
):
|
||||
inputs["radius"] = _prop_value(obj, "Radius")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveCone",
|
||||
"PartDesign::SubtractiveCone",
|
||||
):
|
||||
inputs["radius1"] = _prop_value(obj, "Radius1")
|
||||
inputs["radius2"] = _prop_value(obj, "Radius2")
|
||||
inputs["height"] = _prop_value(obj, "Height")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveEllipsoid",
|
||||
"PartDesign::SubtractiveEllipsoid",
|
||||
):
|
||||
inputs["radius1"] = _prop_value(obj, "Radius1")
|
||||
inputs["radius2"] = _prop_value(obj, "Radius2")
|
||||
inputs["radius3"] = _prop_value(obj, "Radius3")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveTorus",
|
||||
"PartDesign::SubtractiveTorus",
|
||||
):
|
||||
inputs["radius1"] = _prop_value(obj, "Radius1")
|
||||
inputs["radius2"] = _prop_value(obj, "Radius2")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditivePrism",
|
||||
"PartDesign::SubtractivePrism",
|
||||
):
|
||||
inputs["polygon"] = _prop_raw(obj, "Polygon")
|
||||
inputs["circumradius"] = _prop_value(obj, "Circumradius")
|
||||
inputs["height"] = _prop_value(obj, "Height")
|
||||
return inputs
|
||||
|
||||
if tid in (
|
||||
"PartDesign::AdditiveWedge",
|
||||
"PartDesign::SubtractiveWedge",
|
||||
):
|
||||
for dim in (
|
||||
"Xmin",
|
||||
"Ymin",
|
||||
"Zmin",
|
||||
"X2min",
|
||||
"Z2min",
|
||||
"Xmax",
|
||||
"Ymax",
|
||||
"Zmax",
|
||||
"X2max",
|
||||
"Z2max",
|
||||
):
|
||||
inputs[dim.lower()] = _prop_value(obj, dim)
|
||||
return inputs
|
||||
|
||||
# --- Datum / ShapeBinder ---
|
||||
if tid in (
|
||||
"PartDesign::Point",
|
||||
"PartDesign::Line",
|
||||
"PartDesign::Plane",
|
||||
"PartDesign::CoordinateSystem",
|
||||
"PartDesign::ShapeBinder",
|
||||
"PartDesign::SubShapeBinder",
|
||||
):
|
||||
try:
|
||||
p = obj.Placement
|
||||
inputs["position"] = {
|
||||
"x": _safe_float(p.Base.x),
|
||||
"y": _safe_float(p.Base.y),
|
||||
"z": _safe_float(p.Base.z),
|
||||
}
|
||||
inputs["rotation"] = {
|
||||
"axis_x": _safe_float(p.Rotation.Axis.x),
|
||||
"axis_y": _safe_float(p.Rotation.Axis.y),
|
||||
"axis_z": _safe_float(p.Rotation.Axis.z),
|
||||
"angle": _safe_float(p.Rotation.Angle),
|
||||
}
|
||||
except Exception:
|
||||
pass
|
||||
return inputs
|
||||
|
||||
# --- Body / Part (containers) ---
|
||||
if tid in ("PartDesign::Body", "App::Part", "Part::Feature"):
|
||||
try:
|
||||
inputs["child_count"] = len(obj.Group)
|
||||
except Exception:
|
||||
inputs["child_count"] = 0
|
||||
return inputs
|
||||
|
||||
# --- Fallback ---
|
||||
inputs["label"] = obj.Label
|
||||
return inputs
|
||||
|
||||
|
||||
def compute_properties_hash(obj: Any) -> str:
|
||||
"""Return a SHA-256 hex digest of *obj*'s parametric inputs.
|
||||
|
||||
The hash is used for memoization -- if a node's inputs haven't
|
||||
changed since the last validation run, re-validation can be skipped.
|
||||
"""
|
||||
inputs = _collect_inputs(obj)
|
||||
canonical = json.dumps(inputs, sort_keys=True, default=str)
|
||||
return hashlib.sha256(canonical.encode()).hexdigest()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# DAG extraction
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def extract_dag(
|
||||
doc: Any,
|
||||
) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]]:
|
||||
"""Walk a FreeCAD document and return ``(nodes, edges)``.
|
||||
|
||||
*nodes* is a list of dicts matching the Silo ``PUT /dag`` payload
|
||||
schema. *edges* connects dependencies (source) to dependents
|
||||
(target).
|
||||
|
||||
Only objects whose TypeId is recognized by :func:`classify_type`
|
||||
are included. Edges are limited to pairs where **both** endpoints
|
||||
are included, preventing dangling references to internal objects
|
||||
such as ``App::Origin``.
|
||||
"""
|
||||
# Pass 1 -- identify included objects
|
||||
included: Set[str] = set()
|
||||
classified: Dict[str, str] = {} # obj.Name -> node_type
|
||||
|
||||
for obj in doc.Objects:
|
||||
if not hasattr(obj, "TypeId"):
|
||||
continue
|
||||
node_type = classify_type(obj.TypeId)
|
||||
if node_type is not None:
|
||||
included.add(obj.Name)
|
||||
classified[obj.Name] = node_type
|
||||
|
||||
# Pass 2 -- build nodes and edges
|
||||
nodes: List[Dict[str, Any]] = []
|
||||
edges: List[Dict[str, Any]] = []
|
||||
seen_edges: Set[Tuple[str, str]] = set()
|
||||
|
||||
for obj in doc.Objects:
|
||||
if obj.Name not in included:
|
||||
continue
|
||||
|
||||
nodes.append(
|
||||
{
|
||||
"node_key": obj.Name,
|
||||
"node_type": classified[obj.Name],
|
||||
"properties_hash": compute_properties_hash(obj),
|
||||
"metadata": {
|
||||
"label": obj.Label,
|
||||
"type_id": obj.TypeId,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
# Walk dependencies: OutList contains objects this one depends on
|
||||
try:
|
||||
out_list = obj.OutList
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
for dep in out_list:
|
||||
if not hasattr(dep, "Name"):
|
||||
continue
|
||||
if dep.Name not in included:
|
||||
continue
|
||||
edge_key = (dep.Name, obj.Name)
|
||||
if edge_key in seen_edges:
|
||||
continue
|
||||
seen_edges.add(edge_key)
|
||||
edges.append(
|
||||
{
|
||||
"source_key": dep.Name,
|
||||
"target_key": obj.Name,
|
||||
"edge_type": "depends_on",
|
||||
}
|
||||
)
|
||||
|
||||
return nodes, edges
|
||||
156
freecad/runner.py
Normal file
156
freecad/runner.py
Normal file
@@ -0,0 +1,156 @@
|
||||
"""Headless runner entry points for silorunner compute jobs.
|
||||
|
||||
These functions are invoked via ``create --console -e`` by the
|
||||
silorunner binary. They must work without a display server.
|
||||
|
||||
Entry Points
|
||||
------------
|
||||
dag_extract(input_path, output_path)
|
||||
Extract feature DAG and write JSON.
|
||||
validate(input_path, output_path)
|
||||
Rebuild all features and report pass/fail per node.
|
||||
export(input_path, output_path, format='step')
|
||||
Export geometry to STEP, IGES, STL, or OBJ.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import FreeCAD
|
||||
|
||||
|
||||
def dag_extract(input_path, output_path):
|
||||
"""Extract the feature DAG from a Create file.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
input_path : str
|
||||
Path to the ``.kc`` or ``.FCStd`` file.
|
||||
output_path : str
|
||||
Path to write the JSON output.
|
||||
|
||||
Output JSON::
|
||||
|
||||
{"nodes": [...], "edges": [...]}
|
||||
"""
|
||||
from dag import extract_dag
|
||||
|
||||
doc = FreeCAD.openDocument(input_path)
|
||||
try:
|
||||
nodes, edges = extract_dag(doc)
|
||||
with open(output_path, "w") as f:
|
||||
json.dump({"nodes": nodes, "edges": edges}, f)
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"DAG extracted: {len(nodes)} nodes, {len(edges)} edges -> {output_path}\n"
|
||||
)
|
||||
finally:
|
||||
FreeCAD.closeDocument(doc.Name)
|
||||
|
||||
|
||||
def validate(input_path, output_path):
|
||||
"""Validate a Create file by rebuilding all features.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
input_path : str
|
||||
Path to the ``.kc`` or ``.FCStd`` file.
|
||||
output_path : str
|
||||
Path to write the JSON output.
|
||||
|
||||
Output JSON::
|
||||
|
||||
{
|
||||
"valid": true/false,
|
||||
"nodes": [
|
||||
{"node_key": "Pad001", "state": "clean", "message": null, "properties_hash": "..."},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
from dag import classify_type, compute_properties_hash
|
||||
|
||||
doc = FreeCAD.openDocument(input_path)
|
||||
try:
|
||||
doc.recompute()
|
||||
|
||||
results = []
|
||||
all_valid = True
|
||||
|
||||
for obj in doc.Objects:
|
||||
if not hasattr(obj, "TypeId"):
|
||||
continue
|
||||
node_type = classify_type(obj.TypeId)
|
||||
if node_type is None:
|
||||
continue
|
||||
|
||||
state = "clean"
|
||||
message = None
|
||||
if hasattr(obj, "isValid") and not obj.isValid():
|
||||
state = "failed"
|
||||
message = f"Feature {obj.Label} failed to recompute"
|
||||
all_valid = False
|
||||
|
||||
results.append(
|
||||
{
|
||||
"node_key": obj.Name,
|
||||
"state": state,
|
||||
"message": message,
|
||||
"properties_hash": compute_properties_hash(obj),
|
||||
}
|
||||
)
|
||||
|
||||
with open(output_path, "w") as f:
|
||||
json.dump({"valid": all_valid, "nodes": results}, f)
|
||||
|
||||
status = "PASS" if all_valid else "FAIL"
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Validation {status}: {len(results)} nodes -> {output_path}\n"
|
||||
)
|
||||
finally:
|
||||
FreeCAD.closeDocument(doc.Name)
|
||||
|
||||
|
||||
def export(input_path, output_path, format="step"):
|
||||
"""Export a Create file to an external geometry format.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
input_path : str
|
||||
Path to the ``.kc`` or ``.FCStd`` file.
|
||||
output_path : str
|
||||
Path to write the exported file.
|
||||
format : str
|
||||
One of ``step``, ``iges``, ``stl``, ``obj``.
|
||||
"""
|
||||
import Part
|
||||
|
||||
doc = FreeCAD.openDocument(input_path)
|
||||
try:
|
||||
shapes = [
|
||||
obj.Shape for obj in doc.Objects if hasattr(obj, "Shape") and obj.Shape
|
||||
]
|
||||
if not shapes:
|
||||
raise ValueError("No geometry found in document")
|
||||
|
||||
compound = Part.makeCompound(shapes)
|
||||
|
||||
format_lower = format.lower()
|
||||
if format_lower == "step":
|
||||
compound.exportStep(output_path)
|
||||
elif format_lower == "iges":
|
||||
compound.exportIges(output_path)
|
||||
elif format_lower == "stl":
|
||||
import Mesh
|
||||
|
||||
Mesh.export([compound], output_path)
|
||||
elif format_lower == "obj":
|
||||
import Mesh
|
||||
|
||||
Mesh.export([compound], output_path)
|
||||
else:
|
||||
raise ValueError(f"Unsupported format: {format}")
|
||||
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Exported {format_lower.upper()} -> {output_path}\n"
|
||||
)
|
||||
finally:
|
||||
FreeCAD.closeDocument(doc.Name)
|
||||
@@ -26,7 +26,9 @@ from silo_client import (
|
||||
_PREF_GROUP = "User parameter:BaseApp/Preferences/Mod/KindredSilo"
|
||||
|
||||
# Configuration - preferences take priority over env vars
|
||||
SILO_PROJECTS_DIR = os.environ.get("SILO_PROJECTS_DIR", os.path.expanduser("~/projects"))
|
||||
SILO_PROJECTS_DIR = os.environ.get(
|
||||
"SILO_PROJECTS_DIR", os.path.expanduser("~/projects")
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -64,7 +66,9 @@ class FreeCADSiloSettings(SiloSettings):
|
||||
param = FreeCAD.ParamGet(_PREF_GROUP)
|
||||
return param.GetString("SslCertPath", "")
|
||||
|
||||
def save_auth(self, username: str, role: str = "", source: str = "", token: str = ""):
|
||||
def save_auth(
|
||||
self, username: str, role: str = "", source: str = "", token: str = ""
|
||||
):
|
||||
param = FreeCAD.ParamGet(_PREF_GROUP)
|
||||
param.SetString("AuthUsername", username)
|
||||
param.SetString("AuthRole", role)
|
||||
@@ -122,7 +126,9 @@ def _get_ssl_verify() -> bool:
|
||||
def _get_ssl_context():
|
||||
from silo_client._ssl import build_ssl_context
|
||||
|
||||
return build_ssl_context(_fc_settings.get_ssl_verify(), _fc_settings.get_ssl_cert_path())
|
||||
return build_ssl_context(
|
||||
_fc_settings.get_ssl_verify(), _fc_settings.get_ssl_cert_path()
|
||||
)
|
||||
|
||||
|
||||
def _get_auth_headers() -> Dict[str, str]:
|
||||
@@ -179,7 +185,9 @@ def _fetch_server_mode() -> str:
|
||||
# Icon helper
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
_ICON_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "resources", "icons")
|
||||
_ICON_DIR = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)), "resources", "icons"
|
||||
)
|
||||
|
||||
|
||||
def _icon(name):
|
||||
@@ -580,7 +588,9 @@ def handle_kindred_url(url: str):
|
||||
parts = [parsed.netloc] + [p for p in parsed.path.split("/") if p]
|
||||
if len(parts) >= 2 and parts[0] == "item":
|
||||
part_number = parts[1]
|
||||
FreeCAD.Console.PrintMessage(f"Silo: Opening item {part_number} from kindred:// URL\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Silo: Opening item {part_number} from kindred:// URL\n"
|
||||
)
|
||||
_sync.open_item(part_number)
|
||||
|
||||
|
||||
@@ -600,9 +610,8 @@ class Silo_Open:
|
||||
}
|
||||
|
||||
def Activated(self):
|
||||
from PySide import QtGui, QtWidgets
|
||||
|
||||
from open_search import OpenItemWidget
|
||||
from PySide import QtGui, QtWidgets
|
||||
|
||||
mw = FreeCADGui.getMainWindow()
|
||||
mdi = mw.findChild(QtWidgets.QMdiArea)
|
||||
@@ -649,7 +658,6 @@ class Silo_New:
|
||||
|
||||
def Activated(self):
|
||||
from PySide import QtGui, QtWidgets
|
||||
|
||||
from schema_form import SchemaFormWidget
|
||||
|
||||
mw = FreeCADGui.getMainWindow()
|
||||
@@ -689,7 +697,9 @@ class Silo_New:
|
||||
},
|
||||
)
|
||||
obj.Label = part_number
|
||||
_sync.save_to_canonical_path(FreeCAD.ActiveDocument, force_rename=True)
|
||||
_sync.save_to_canonical_path(
|
||||
FreeCAD.ActiveDocument, force_rename=True
|
||||
)
|
||||
else:
|
||||
_sync.create_document_for_item(result, save=True)
|
||||
|
||||
@@ -707,6 +717,28 @@ class Silo_New:
|
||||
return _server_mode == "normal"
|
||||
|
||||
|
||||
def _push_dag_after_upload(doc, part_number, revision_number):
|
||||
"""Extract and push the feature DAG after a successful upload.
|
||||
|
||||
Failures are logged as warnings -- DAG sync must never block save.
|
||||
"""
|
||||
try:
|
||||
from dag import extract_dag
|
||||
|
||||
nodes, edges = extract_dag(doc)
|
||||
if not nodes:
|
||||
return
|
||||
|
||||
result = _client.push_dag(part_number, revision_number, nodes, edges)
|
||||
node_count = result.get("node_count", len(nodes))
|
||||
edge_count = result.get("edge_count", len(edges))
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"DAG synced: {node_count} nodes, {edge_count} edges\n"
|
||||
)
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintWarning(f"DAG sync failed: {e}\n")
|
||||
|
||||
|
||||
class Silo_Save:
|
||||
"""Save locally and upload to MinIO."""
|
||||
|
||||
@@ -770,11 +802,15 @@ class Silo_Save:
|
||||
|
||||
# Try to upload to MinIO
|
||||
try:
|
||||
result = _client._upload_file(part_number, str(file_path), properties, "Auto-save")
|
||||
result = _client._upload_file(
|
||||
part_number, str(file_path), properties, "Auto-save"
|
||||
)
|
||||
|
||||
new_rev = result["revision_number"]
|
||||
FreeCAD.Console.PrintMessage(f"Uploaded as revision {new_rev}\n")
|
||||
|
||||
_push_dag_after_upload(doc, part_number, new_rev)
|
||||
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintWarning(f"Upload failed: {e}\n")
|
||||
FreeCAD.Console.PrintMessage("File saved locally but not uploaded.\n")
|
||||
@@ -803,7 +839,9 @@ class Silo_Commit:
|
||||
|
||||
obj = get_tracked_object(doc)
|
||||
if not obj:
|
||||
FreeCAD.Console.PrintError("No tracked object. Use 'New' to register first.\n")
|
||||
FreeCAD.Console.PrintError(
|
||||
"No tracked object. Use 'New' to register first.\n"
|
||||
)
|
||||
return
|
||||
|
||||
part_number = obj.SiloPartNumber
|
||||
@@ -820,11 +858,15 @@ class Silo_Commit:
|
||||
if not file_path:
|
||||
return
|
||||
|
||||
result = _client._upload_file(part_number, str(file_path), properties, comment)
|
||||
result = _client._upload_file(
|
||||
part_number, str(file_path), properties, comment
|
||||
)
|
||||
|
||||
new_rev = result["revision_number"]
|
||||
FreeCAD.Console.PrintMessage(f"Committed revision {new_rev}: {comment}\n")
|
||||
|
||||
_push_dag_after_upload(doc, part_number, new_rev)
|
||||
|
||||
except Exception as e:
|
||||
FreeCAD.Console.PrintError(f"Commit failed: {e}\n")
|
||||
|
||||
@@ -869,7 +911,9 @@ def _check_pull_conflicts(part_number, local_path, doc=None):
|
||||
server_updated = item.get("updated_at", "")
|
||||
if server_updated:
|
||||
# Parse ISO format timestamp
|
||||
server_dt = datetime.datetime.fromisoformat(server_updated.replace("Z", "+00:00"))
|
||||
server_dt = datetime.datetime.fromisoformat(
|
||||
server_updated.replace("Z", "+00:00")
|
||||
)
|
||||
if server_dt > local_mtime:
|
||||
conflicts.append("Server version is newer than local file.")
|
||||
except Exception:
|
||||
@@ -899,7 +943,9 @@ class SiloPullDialog:
|
||||
# Revision table
|
||||
self._table = QtGui.QTableWidget()
|
||||
self._table.setColumnCount(5)
|
||||
self._table.setHorizontalHeaderLabels(["Rev", "Date", "Comment", "Status", "File"])
|
||||
self._table.setHorizontalHeaderLabels(
|
||||
["Rev", "Date", "Comment", "Status", "File"]
|
||||
)
|
||||
self._table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
||||
self._table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
||||
self._table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
@@ -992,7 +1038,9 @@ def _pull_dependencies(part_number, progress_callback=None):
|
||||
# Skip if already exists locally
|
||||
existing = find_file_by_part_number(child_pn)
|
||||
if existing and existing.exists():
|
||||
FreeCAD.Console.PrintMessage(f" {child_pn}: already exists at {existing}\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f" {child_pn}: already exists at {existing}\n"
|
||||
)
|
||||
# Still recurse — this child may itself be an assembly with missing deps
|
||||
_pull_dependencies(child_pn, progress_callback)
|
||||
continue
|
||||
@@ -1072,14 +1120,18 @@ class Silo_Pull:
|
||||
|
||||
if not has_any_file:
|
||||
if existing_local:
|
||||
FreeCAD.Console.PrintMessage(f"Opening existing local file: {existing_local}\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Opening existing local file: {existing_local}\n"
|
||||
)
|
||||
FreeCAD.openDocument(str(existing_local))
|
||||
else:
|
||||
try:
|
||||
item = _client.get_item(part_number)
|
||||
new_doc = _sync.create_document_for_item(item, save=True)
|
||||
if new_doc:
|
||||
FreeCAD.Console.PrintMessage(f"Created local file for {part_number}\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Created local file for {part_number}\n"
|
||||
)
|
||||
else:
|
||||
QtGui.QMessageBox.warning(
|
||||
None,
|
||||
@@ -1166,7 +1218,9 @@ class Silo_Pull:
|
||||
progress.setValue(100)
|
||||
progress.close()
|
||||
if dep_pulled:
|
||||
FreeCAD.Console.PrintMessage(f"Pulled {len(dep_pulled)} dependency file(s)\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Pulled {len(dep_pulled)} dependency file(s)\n"
|
||||
)
|
||||
|
||||
# Close existing document if open, then reopen
|
||||
if doc and doc.FileName == str(dest_path):
|
||||
@@ -1221,7 +1275,9 @@ class Silo_Push:
|
||||
server_dt = datetime.fromisoformat(
|
||||
server_time_str.replace("Z", "+00:00")
|
||||
)
|
||||
local_dt = datetime.fromtimestamp(local_mtime, tz=timezone.utc)
|
||||
local_dt = datetime.fromtimestamp(
|
||||
local_mtime, tz=timezone.utc
|
||||
)
|
||||
if local_dt > server_dt:
|
||||
unuploaded.append(lf)
|
||||
else:
|
||||
@@ -1234,7 +1290,9 @@ class Silo_Push:
|
||||
pass # Not in DB, skip
|
||||
|
||||
if not unuploaded:
|
||||
QtGui.QMessageBox.information(None, "Push", "All local files are already uploaded.")
|
||||
QtGui.QMessageBox.information(
|
||||
None, "Push", "All local files are already uploaded."
|
||||
)
|
||||
return
|
||||
|
||||
msg = f"Found {len(unuploaded)} files to upload:\n\n"
|
||||
@@ -1252,7 +1310,9 @@ class Silo_Push:
|
||||
|
||||
uploaded = 0
|
||||
for item in unuploaded:
|
||||
result = _sync.upload_file(item["part_number"], item["path"], "Synced from local")
|
||||
result = _sync.upload_file(
|
||||
item["part_number"], item["path"], "Synced from local"
|
||||
)
|
||||
if result:
|
||||
uploaded += 1
|
||||
|
||||
@@ -1301,9 +1361,7 @@ class Silo_Info:
|
||||
msg = f"<h3>{part_number}</h3>"
|
||||
msg += f"<p><b>Type:</b> {item.get('item_type', '-')}</p>"
|
||||
msg += f"<p><b>Description:</b> {item.get('description', '-')}</p>"
|
||||
msg += (
|
||||
f"<p><b>Projects:</b> {', '.join(project_codes) if project_codes else 'None'}</p>"
|
||||
)
|
||||
msg += f"<p><b>Projects:</b> {', '.join(project_codes) if project_codes else 'None'}</p>"
|
||||
msg += f"<p><b>Current Revision:</b> {item.get('current_revision', 1)}</p>"
|
||||
msg += f"<p><b>Local Revision:</b> {getattr(obj, 'SiloRevision', '-')}</p>"
|
||||
|
||||
@@ -1369,7 +1427,9 @@ class Silo_TagProjects:
|
||||
try:
|
||||
# Get current projects for item
|
||||
current_projects = _client.get_item_projects(part_number)
|
||||
current_codes = {p.get("code", "") for p in current_projects if p.get("code")}
|
||||
current_codes = {
|
||||
p.get("code", "") for p in current_projects if p.get("code")
|
||||
}
|
||||
|
||||
# Get all available projects
|
||||
all_projects = _client.get_projects()
|
||||
@@ -1480,7 +1540,9 @@ class Silo_Rollback:
|
||||
dialog.setMinimumHeight(300)
|
||||
layout = QtGui.QVBoxLayout(dialog)
|
||||
|
||||
label = QtGui.QLabel(f"Select a revision to rollback to (current: Rev {current_rev}):")
|
||||
label = QtGui.QLabel(
|
||||
f"Select a revision to rollback to (current: Rev {current_rev}):"
|
||||
)
|
||||
layout.addWidget(label)
|
||||
|
||||
# Revision table
|
||||
@@ -1495,8 +1557,12 @@ class Silo_Rollback:
|
||||
for i, rev in enumerate(prev_revisions):
|
||||
table.setItem(i, 0, QtGui.QTableWidgetItem(str(rev["revision_number"])))
|
||||
table.setItem(i, 1, QtGui.QTableWidgetItem(rev.get("status", "draft")))
|
||||
table.setItem(i, 2, QtGui.QTableWidgetItem(rev.get("created_at", "")[:10]))
|
||||
table.setItem(i, 3, QtGui.QTableWidgetItem(rev.get("comment", "") or ""))
|
||||
table.setItem(
|
||||
i, 2, QtGui.QTableWidgetItem(rev.get("created_at", "")[:10])
|
||||
)
|
||||
table.setItem(
|
||||
i, 3, QtGui.QTableWidgetItem(rev.get("comment", "") or "")
|
||||
)
|
||||
|
||||
table.resizeColumnsToContents()
|
||||
layout.addWidget(table)
|
||||
@@ -1522,7 +1588,9 @@ class Silo_Rollback:
|
||||
def on_rollback():
|
||||
selected = table.selectedItems()
|
||||
if not selected:
|
||||
QtGui.QMessageBox.warning(dialog, "Rollback", "Please select a revision")
|
||||
QtGui.QMessageBox.warning(
|
||||
dialog, "Rollback", "Please select a revision"
|
||||
)
|
||||
return
|
||||
selected_rev[0] = int(table.item(selected[0].row(), 0).text())
|
||||
dialog.accept()
|
||||
@@ -1620,7 +1688,9 @@ class Silo_SetStatus:
|
||||
# Update status
|
||||
_client.update_revision(part_number, rev_num, status=status)
|
||||
|
||||
FreeCAD.Console.PrintMessage(f"Updated Rev {rev_num} status to '{status}'\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Updated Rev {rev_num} status to '{status}'\n"
|
||||
)
|
||||
QtGui.QMessageBox.information(
|
||||
None, "Status Updated", f"Revision {rev_num} status set to '{status}'"
|
||||
)
|
||||
@@ -1684,7 +1754,9 @@ class Silo_Settings:
|
||||
ssl_checkbox.setChecked(param.GetBool("SslVerify", True))
|
||||
layout.addWidget(ssl_checkbox)
|
||||
|
||||
ssl_hint = QtGui.QLabel("Disable only for internal servers with self-signed certificates.")
|
||||
ssl_hint = QtGui.QLabel(
|
||||
"Disable only for internal servers with self-signed certificates."
|
||||
)
|
||||
ssl_hint.setWordWrap(True)
|
||||
ssl_hint.setStyleSheet("color: #888; font-size: 11px;")
|
||||
layout.addWidget(ssl_hint)
|
||||
@@ -1717,7 +1789,7 @@ class Silo_Settings:
|
||||
path, _ = QtGui.QFileDialog.getOpenFileName(
|
||||
dialog,
|
||||
"Select CA Certificate",
|
||||
os.path.dirname(cert_input.text()) or "/etc/ssl/certs",
|
||||
os.path.dirname(cert_input.text()) or os.path.expanduser("~"),
|
||||
"Certificates (*.pem *.crt *.cer);;All Files (*)",
|
||||
)
|
||||
if path:
|
||||
@@ -1961,7 +2033,9 @@ class Silo_BOM:
|
||||
|
||||
wu_table = QtGui.QTableWidget()
|
||||
wu_table.setColumnCount(5)
|
||||
wu_table.setHorizontalHeaderLabels(["Parent Part Number", "Type", "Qty", "Unit", "Ref Des"])
|
||||
wu_table.setHorizontalHeaderLabels(
|
||||
["Parent Part Number", "Type", "Qty", "Unit", "Ref Des"]
|
||||
)
|
||||
wu_table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
|
||||
wu_table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
|
||||
wu_table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
|
||||
@@ -1990,12 +2064,16 @@ class Silo_BOM:
|
||||
bom_table.setItem(
|
||||
row, 1, QtGui.QTableWidgetItem(entry.get("child_description", ""))
|
||||
)
|
||||
bom_table.setItem(row, 2, QtGui.QTableWidgetItem(entry.get("rel_type", "")))
|
||||
bom_table.setItem(
|
||||
row, 2, QtGui.QTableWidgetItem(entry.get("rel_type", ""))
|
||||
)
|
||||
qty = entry.get("quantity")
|
||||
bom_table.setItem(
|
||||
row, 3, QtGui.QTableWidgetItem(str(qty) if qty is not None else "")
|
||||
)
|
||||
bom_table.setItem(row, 4, QtGui.QTableWidgetItem(entry.get("unit") or ""))
|
||||
bom_table.setItem(
|
||||
row, 4, QtGui.QTableWidgetItem(entry.get("unit") or "")
|
||||
)
|
||||
ref_des = entry.get("reference_designators") or []
|
||||
bom_table.setItem(row, 5, QtGui.QTableWidgetItem(", ".join(ref_des)))
|
||||
bom_table.setItem(
|
||||
@@ -2017,12 +2095,16 @@ class Silo_BOM:
|
||||
wu_table.setItem(
|
||||
row, 0, QtGui.QTableWidgetItem(entry.get("parent_part_number", ""))
|
||||
)
|
||||
wu_table.setItem(row, 1, QtGui.QTableWidgetItem(entry.get("rel_type", "")))
|
||||
wu_table.setItem(
|
||||
row, 1, QtGui.QTableWidgetItem(entry.get("rel_type", ""))
|
||||
)
|
||||
qty = entry.get("quantity")
|
||||
wu_table.setItem(
|
||||
row, 2, QtGui.QTableWidgetItem(str(qty) if qty is not None else "")
|
||||
)
|
||||
wu_table.setItem(row, 3, QtGui.QTableWidgetItem(entry.get("unit") or ""))
|
||||
wu_table.setItem(
|
||||
row, 3, QtGui.QTableWidgetItem(entry.get("unit") or "")
|
||||
)
|
||||
ref_des = entry.get("reference_designators") or []
|
||||
wu_table.setItem(row, 4, QtGui.QTableWidgetItem(", ".join(ref_des)))
|
||||
wu_table.resizeColumnsToContents()
|
||||
@@ -2075,7 +2157,9 @@ class Silo_BOM:
|
||||
try:
|
||||
qty = float(qty_text)
|
||||
except ValueError:
|
||||
QtGui.QMessageBox.warning(dialog, "BOM", "Quantity must be a number.")
|
||||
QtGui.QMessageBox.warning(
|
||||
dialog, "BOM", "Quantity must be a number."
|
||||
)
|
||||
return
|
||||
|
||||
unit = unit_input.text().strip() or None
|
||||
@@ -2154,7 +2238,9 @@ class Silo_BOM:
|
||||
try:
|
||||
new_qty = float(qty_text)
|
||||
except ValueError:
|
||||
QtGui.QMessageBox.warning(dialog, "BOM", "Quantity must be a number.")
|
||||
QtGui.QMessageBox.warning(
|
||||
dialog, "BOM", "Quantity must be a number."
|
||||
)
|
||||
return
|
||||
|
||||
new_unit = unit_input.text().strip() or None
|
||||
@@ -2178,7 +2264,9 @@ class Silo_BOM:
|
||||
)
|
||||
load_bom()
|
||||
except Exception as exc:
|
||||
QtGui.QMessageBox.warning(dialog, "BOM", f"Failed to update entry:\n{exc}")
|
||||
QtGui.QMessageBox.warning(
|
||||
dialog, "BOM", f"Failed to update entry:\n{exc}"
|
||||
)
|
||||
|
||||
def on_remove():
|
||||
selected = bom_table.selectedItems()
|
||||
@@ -2204,7 +2292,9 @@ class Silo_BOM:
|
||||
_client.delete_bom_entry(part_number, child_pn)
|
||||
load_bom()
|
||||
except Exception as exc:
|
||||
QtGui.QMessageBox.warning(dialog, "BOM", f"Failed to remove entry:\n{exc}")
|
||||
QtGui.QMessageBox.warning(
|
||||
dialog, "BOM", f"Failed to remove entry:\n{exc}"
|
||||
)
|
||||
|
||||
add_btn.clicked.connect(on_add)
|
||||
edit_btn.clicked.connect(on_edit)
|
||||
@@ -2243,7 +2333,9 @@ class SiloEventListener(QtCore.QThread):
|
||||
|
||||
item_updated = QtCore.Signal(str) # part_number
|
||||
revision_created = QtCore.Signal(str, int) # part_number, revision
|
||||
connection_status = QtCore.Signal(str, int, str) # (status, retry_count, error_message)
|
||||
connection_status = QtCore.Signal(
|
||||
str, int, str
|
||||
) # (status, retry_count, error_message)
|
||||
server_mode_changed = QtCore.Signal(str) # "normal" / "read-only" / "degraded"
|
||||
|
||||
_MAX_RETRIES = 10
|
||||
@@ -2317,7 +2409,9 @@ class SiloEventListener(QtCore.QThread):
|
||||
req = urllib.request.Request(url, headers=headers, method="GET")
|
||||
|
||||
try:
|
||||
self._response = urllib.request.urlopen(req, context=_get_ssl_context(), timeout=90)
|
||||
self._response = urllib.request.urlopen(
|
||||
req, context=_get_ssl_context(), timeout=90
|
||||
)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code in (404, 501):
|
||||
raise _SSEUnsupported()
|
||||
@@ -2598,7 +2692,9 @@ class SiloAuthDockWidget:
|
||||
self._sse_label.setToolTip("")
|
||||
FreeCAD.Console.PrintMessage("Silo: SSE connected\n")
|
||||
elif status == "disconnected":
|
||||
self._sse_label.setText(f"Reconnecting ({retry}/{SiloEventListener._MAX_RETRIES})...")
|
||||
self._sse_label.setText(
|
||||
f"Reconnecting ({retry}/{SiloEventListener._MAX_RETRIES})..."
|
||||
)
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #FF9800;")
|
||||
self._sse_label.setToolTip(error or "Connection lost")
|
||||
FreeCAD.Console.PrintWarning(
|
||||
@@ -2608,7 +2704,9 @@ class SiloAuthDockWidget:
|
||||
self._sse_label.setText("Disconnected")
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #F44336;")
|
||||
self._sse_label.setToolTip(error or "Max retries reached")
|
||||
FreeCAD.Console.PrintError(f"Silo: SSE gave up after {retry} retries: {error}\n")
|
||||
FreeCAD.Console.PrintError(
|
||||
f"Silo: SSE gave up after {retry} retries: {error}\n"
|
||||
)
|
||||
elif status == "unsupported":
|
||||
self._sse_label.setText("Not available")
|
||||
self._sse_label.setStyleSheet("font-size: 11px; color: #888;")
|
||||
@@ -2650,10 +2748,14 @@ class SiloAuthDockWidget:
|
||||
self._refresh_activity_panel()
|
||||
|
||||
def _on_remote_revision(self, part_number, revision):
|
||||
FreeCAD.Console.PrintMessage(f"Silo: New revision {revision} for {part_number}\n")
|
||||
FreeCAD.Console.PrintMessage(
|
||||
f"Silo: New revision {revision} for {part_number}\n"
|
||||
)
|
||||
mw = FreeCADGui.getMainWindow()
|
||||
if mw is not None:
|
||||
mw.statusBar().showMessage(f"Silo: {part_number} rev {revision} available", 5000)
|
||||
mw.statusBar().showMessage(
|
||||
f"Silo: {part_number} rev {revision} available", 5000
|
||||
)
|
||||
self._refresh_activity_panel()
|
||||
|
||||
def _refresh_activity_panel(self):
|
||||
@@ -2719,7 +2821,9 @@ class SiloAuthDockWidget:
|
||||
rev_part = f" \u2013 Rev {rev_num}" if rev_num else ""
|
||||
date_part = f" \u2013 {updated}" if updated else ""
|
||||
local_badge = " \u25cf local" if pn in local_pns else ""
|
||||
line1 = f"{pn} \u2013 {desc_display}{rev_part}{date_part}{local_badge}"
|
||||
line1 = (
|
||||
f"{pn} \u2013 {desc_display}{rev_part}{date_part}{local_badge}"
|
||||
)
|
||||
|
||||
if comment:
|
||||
line1 += f'\n "{comment}"'
|
||||
@@ -3175,7 +3279,9 @@ class Silo_StartPanel:
|
||||
dock = QtGui.QDockWidget("Silo", mw)
|
||||
dock.setObjectName("SiloStartPanel")
|
||||
dock.setWidget(content.widget)
|
||||
dock.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea)
|
||||
dock.setAllowedAreas(
|
||||
QtCore.Qt.LeftDockWidgetArea | QtCore.Qt.RightDockWidgetArea
|
||||
)
|
||||
mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)
|
||||
|
||||
def IsActive(self):
|
||||
@@ -3209,7 +3315,9 @@ class _DiagWorker(QtCore.QThread):
|
||||
self.result.emit("DNS", False, "no hostname in URL")
|
||||
return
|
||||
try:
|
||||
addrs = socket.getaddrinfo(hostname, None, socket.AF_UNSPEC, socket.SOCK_STREAM)
|
||||
addrs = socket.getaddrinfo(
|
||||
hostname, None, socket.AF_UNSPEC, socket.SOCK_STREAM
|
||||
)
|
||||
first_ip = addrs[0][4][0] if addrs else "?"
|
||||
self.result.emit("DNS", True, f"{hostname} -> {first_ip}")
|
||||
except socket.gaierror as e:
|
||||
|
||||
Submodule silo-client updated: 68a4139251...fb658c5a24
Reference in New Issue
Block a user