Skip to content

Commit db6af51

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 70c140a commit db6af51

File tree

5 files changed

+43
-31
lines changed

5 files changed

+43
-31
lines changed

jupytercad_freecad/freecad/jcad_converter.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ def export_jcad_to_fcstd(jcad_dict: dict) -> "fc.Document":
8686

8787
prop_handlers = build_prop_handlers()
8888
coordinate_names = {
89-
"Origin", "X_Axis", "Y_Axis", "Z_Axis", "XY_Plane", "XZ_Plane", "YZ_Plane"
89+
"Origin",
90+
"X_Axis",
91+
"Y_Axis",
92+
"Z_Axis",
93+
"XY_Plane",
94+
"XZ_Plane",
95+
"YZ_Plane",
9096
}
9197

9298
# 1) Sanitize JCAD names in place and build a mapping
@@ -104,20 +110,19 @@ def export_jcad_to_fcstd(jcad_dict: dict) -> "fc.Document":
104110

105111
# 2) Separate PartDesign::Body entries from others
106112
body_objs = [
107-
o for o in jcad_dict.get("objects", [])
108-
if o["shape"] == "PartDesign::Body"
113+
o for o in jcad_dict.get("objects", []) if o["shape"] == "PartDesign::Body"
109114
]
110115
other_objs = [
111-
o for o in jcad_dict.get("objects", [])
116+
o
117+
for o in jcad_dict.get("objects", [])
112118
if o not in body_objs and o["name"] not in coordinate_names
113119
]
114120

115121
# Helper: determine RGB tuple and visibility flag
116122
def _color_and_visibility(jcad_obj):
117123
opts = jcad_dict.get("options", {}).get(jcad_obj["name"], {})
118-
hexcol = (
119-
jcad_obj.get("parameters", {}).get("Color")
120-
or opts.get("color", "#808080")
124+
hexcol = jcad_obj.get("parameters", {}).get("Color") or opts.get(
125+
"color", "#808080"
121126
)
122127
rgb = _hex_to_rgb(hexcol)
123128
visible = opts.get("visible")
@@ -152,16 +157,17 @@ def _color_and_visibility(jcad_obj):
152157

153158
rgb, visible = _color_and_visibility(obj)
154159
default_camera = (
155-
"OrthographicCamera {\n"
156-
" viewportMapping ADJUST_CAMERA\n"
157-
" position 5.0 0.0 10.0\n"
158-
" orientation 0.7 0.2 0.4 1.0\n"
159-
" nearDistance 0.2\n"
160-
" farDistance 20.0\n"
161-
" aspectRatio 1.0\n"
162-
" focalDistance 8.0\n"
163-
" height 16.0\n"
164-
"}")
160+
"OrthographicCamera {\n"
161+
" viewportMapping ADJUST_CAMERA\n"
162+
" position 5.0 0.0 10.0\n"
163+
" orientation 0.7 0.2 0.4 1.0\n"
164+
" nearDistance 0.2\n"
165+
" farDistance 20.0\n"
166+
" aspectRatio 1.0\n"
167+
" focalDistance 8.0\n"
168+
" height 16.0\n"
169+
"}"
170+
)
165171
guidata[obj["name"]] = {
166172
"ShapeColor": {"type": "App::PropertyColor", "value": rgb},
167173
"Visibility": {"type": "App::PropertyBool", "value": visible},
@@ -176,4 +182,4 @@ def _color_and_visibility(jcad_obj):
176182
path = tmp.name
177183
OfflineRenderingUtils.save(doc, filename=path, guidata=guidata)
178184

179-
return fc.app.openDocument(path)
185+
return fc.app.openDocument(path)

jupytercad_freecad/freecad/loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def save(self, objects: List, options: Dict, metadata: Dict) -> None:
192192
# Skip Color property as it's handled separately through guidata
193193
if prop == "Color":
194194
continue
195-
195+
196196
if hasattr(fc_obj, prop):
197197
try:
198198
prop_type = fc_obj.getTypeIdOfProperty(prop)

jupytercad_freecad/freecad/props/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
from .property_link_list import * # noqa
88
from .property_map import * # noqa
99
from .property_partshape import * # noqa
10-
from .property_placement import * # noqa
10+
from .property_placement import * # noqa

jupytercad_freecad/freecad/props/property_partshape.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ def jcad_to_fc(prop_value: str, **kwargs) -> Any:
3030

3131
try:
3232
shape = Part.Shape()
33-
shape.importBrepFromString(prop_value)
34-
33+
shape.importBrepFromString(prop_value)
34+
3535
if shape.isNull():
36-
print(f"Warning: Reconstructed shape is Null after importBrepFromString. Input (first 100 chars): {prop_value[:100]}...")
37-
return None
36+
print(
37+
f"Warning: Reconstructed shape is Null after importBrepFromString. Input (first 100 chars): {prop_value[:100]}..."
38+
)
39+
return None
3840

3941
return shape
4042
except Exception as e:
41-
print(f"Failed to rebuild BRep shape with importBrepFromString: {e}. Input (first 100 chars): {prop_value[:100]}...")
43+
print(
44+
f"Failed to rebuild BRep shape with importBrepFromString: {e}. Input (first 100 chars): {prop_value[:100]}..."
45+
)
4246
return None

jupytercad_freecad/handlers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from jupytercad_freecad.freecad.loader import FCStd
1212
from jupytercad_freecad.freecad.jcad_converter import export_jcad_to_fcstd
1313

14+
1415
class BackendCheckHandler(APIHandler):
1516
@tornado.web.authenticated
1617
def post(self):
@@ -36,7 +37,7 @@ def post(self):
3637

3738
# Works with both prefixed and unprefixed paths
3839
path = body.get("path", "")
39-
parts = path.split(":", 1)
40+
parts = path.split(":", 1)
4041

4142
if len(parts) == 2:
4243
file_name = parts[1]
@@ -113,21 +114,22 @@ def post(self):
113114
# convert to FreeCAD document
114115
try:
115116
doc = export_jcad_to_fcstd(jcad_dict)
116-
117-
temp_fcstd_path = doc.FileName
117+
118+
temp_fcstd_path = doc.FileName
118119
shutil.copy2(temp_fcstd_path, str(out_path))
119-
120+
120121
# Clean up the temporary file
121122
if os.path.exists(temp_fcstd_path):
122123
os.unlink(temp_fcstd_path)
123-
124+
124125
except Exception as e:
125126
self.log.error(f"Error converting to FCStd: {e}")
126127
self.set_status(500)
127128
return self.finish(json.dumps({"error": str(e)}))
128129

129130
self.finish(json.dumps({"done": True, "exportedPath": str(out_path)}))
130131

132+
131133
def setup_handlers(web_app):
132134
host_pattern = ".*$"
133135

@@ -142,7 +144,7 @@ def setup_handlers(web_app):
142144
url_path_join(base_url, "jupytercad_freecad", "export-jcad"),
143145
JCadExportHandler,
144146
),
145-
(
147+
(
146148
url_path_join(base_url, "jupytercad_freecad", "export-fcstd"),
147149
FCStdExportHandler,
148150
),

0 commit comments

Comments
 (0)