From c5afcefd8da9668914f0692cfc55c48aadcfbd60 Mon Sep 17 00:00:00 2001 From: Roman Kuzmenko Date: Thu, 3 Oct 2024 21:37:17 -0700 Subject: [PATCH] Improved rendering of part and assembly aliases --- examples/feature_interface/README.md | 54 +++++++++++++++---- examples/produce_assembly_assy/README.md | 24 +++++++-- examples/produce_part_3mf/README.md | 4 +- examples/produce_part_ai_build123d/README.md | 6 +-- examples/produce_part_ai_cadquery/README.md | 6 +-- examples/produce_part_ai_openscad/README.md | 6 +-- .../README.md | 4 +- examples/produce_part_cadquery_logo/README.md | 14 ++--- .../produce_part_cadquery_primitive/README.md | 37 ++++++++++--- examples/produce_part_extrude/README.md | 16 +++--- examples/produce_part_openscad/README.md | 4 +- examples/produce_part_step/README.md | 25 ++++++++- examples/produce_part_stl/README.md | 4 +- examples/produce_sketch_basic/README.md | 20 +++---- examples/produce_sketch_build123d/README.md | 4 +- examples/produce_sketch_dxf/README.md | 4 +- examples/produce_sketch_svg/README.md | 4 +- partcad/src/partcad/assembly_factory_alias.py | 1 + partcad/src/partcad/part_factory_alias.py | 1 + partcad/src/partcad/project.py | 38 +++++++++---- 20 files changed, 204 insertions(+), 72 deletions(-) diff --git a/examples/feature_interface/README.md b/examples/feature_interface/README.md index a0b6f629..b26f8d6a 100644 --- a/examples/feature_interface/README.md +++ b/examples/feature_interface/README.md @@ -20,27 +20,59 @@ pc inspect -a -p placement=inner connect-mates ## Assemblies -### connect-ports - - - - -
Demonstrates how to connect parts by specifying ports.Parameters:
  • placement:
    • inner
    • outer
  • motor_tr_connect_to:
    • TR
    • TL
    • BR
    • BL
- ### connect-interfaces - + - +
Demonstrates how to connect parts by specifying interfaces.Parameters:
  • placement:
    • inner
    • outer
  • motor_tr_connect_to:
    • TR
    • TL
    • BR
    • BL
Parameters:
    +
  • placement:
      +
    • inner
    • outer
    • +
    +
  • +
  • motor_tr_connect_to:
      +
    • TR
    • +
    • TL
    • BR
    • BL
    +
  • +
+
### connect-mates - + - +
Demonstrates how to provide the minimum information while letting PartCAD determine the rest using the interfaces' mating metadata. Parameters:
  • placement:
    • inner
    • outer
  • motor_tr_connect_to:
    • TR
    • TL
    • BR
    • BL
Parameters:
    +
  • placement:
      +
    • inner
    • outer
    • +
    +
  • +
  • motor_tr_connect_to:
      +
    • TR
    • +
    • TL
    • BR
    • BL
    +
  • +
+
+### connect-ports + + + + +
Demonstrates how to connect parts by specifying ports.Parameters:
    +
  • placement:
      +
    • inner
    • outer
    • +
    +
  • +
  • motor_tr_connect_to:
      +
    • TR
    • +
    • TL
    • BR
    • BL
    +
  • +
+
+ +

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_assembly_assy/README.md b/examples/produce_assembly_assy/README.md index 40ba73d5..a0ac1c08 100644 --- a/examples/produce_assembly_assy/README.md +++ b/examples/produce_assembly_assy/README.md @@ -12,19 +12,33 @@ pc inspect logo_embedded ## Assemblies -### primitive - - ### logo - +
PartCAD logo
### logo_embedded - +
PartCAD logo using embedded assemblies
+### partcad_logo (alias to logo) + + + +
PartCAD logo
+ +### partcad_logo_short (alias to logo) + + + +
PartCAD logo
+ +### primitive + + +

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_3mf/README.md b/examples/produce_part_3mf/README.md index 5934ead7..167b69ea 100644 --- a/examples/produce_part_3mf/README.md +++ b/examples/produce_part_3mf/README.md @@ -12,8 +12,10 @@ pc inspect cube ### cube - +
A cube defined in 3MF
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_ai_build123d/README.md b/examples/produce_part_ai_build123d/README.md index de4a2ca5..7e6ce54e 100644 --- a/examples/produce_part_ai_build123d/README.md +++ b/examples/produce_part_ai_build123d/README.md @@ -14,19 +14,19 @@ pc inspect tetrahedron ### cube - +
A cube
### prism - +
A hexagonal prism
### tetrahedron - +
A tetrahedron
diff --git a/examples/produce_part_ai_cadquery/README.md b/examples/produce_part_ai_cadquery/README.md index f29b2334..e4625c48 100644 --- a/examples/produce_part_ai_cadquery/README.md +++ b/examples/produce_part_ai_cadquery/README.md @@ -14,19 +14,19 @@ pc inspect tetrahedron ### cube - +
A cube
### prism - +
A hexagonal prism
### tetrahedron - +
A tetrahedron
diff --git a/examples/produce_part_ai_openscad/README.md b/examples/produce_part_ai_openscad/README.md index 69edcafd..c485f30e 100644 --- a/examples/produce_part_ai_openscad/README.md +++ b/examples/produce_part_ai_openscad/README.md @@ -14,19 +14,19 @@ pc inspect tetrahedron ### cube - +
A cube
### prism - +
A hexagonal prism
### tetrahedron - +
A tetrahedron
diff --git a/examples/produce_part_build123d_primitive/README.md b/examples/produce_part_build123d_primitive/README.md index e7a2afc0..7829bcfe 100644 --- a/examples/produce_part_build123d_primitive/README.md +++ b/examples/produce_part_build123d_primitive/README.md @@ -12,8 +12,10 @@ pc inspect cube ### cube - +
Sample part defined using build123d
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_cadquery_logo/README.md b/examples/produce_part_cadquery_logo/README.md index d45bd1cd..b12d0e92 100644 --- a/examples/produce_part_cadquery_logo/README.md +++ b/examples/produce_part_cadquery_logo/README.md @@ -11,16 +11,18 @@ pc inspect bone ## Parts -### head_half +### bone - - + +
Bracket used as one side of the head on PartCAD logoPlate used as one of the bones on PartCAD logo
-### bone +### head_half - - + +
Plate used as one of the bones on PartCAD logoBracket used as one side of the head on PartCAD logo
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_cadquery_primitive/README.md b/examples/produce_part_cadquery_primitive/README.md index c065a059..2c4ce970 100644 --- a/examples/produce_part_cadquery_primitive/README.md +++ b/examples/produce_part_cadquery_primitive/README.md @@ -12,25 +12,50 @@ pc inspect cylinder ## Parts -### cube +### box (alias to cube) - + - +
This is a cube from examplesParameters:
  • width: 10.0
  • length: 10.0
  • height: 10.0
Parameters:
    +
  • width: 10.0
  • +
  • length: 10.0
  • +
  • height: 10.0
  • +
+
Aliases:
  • box
### brick - + + + +
This is a cube from examplesParameters:
    +
  • width: 20.0
  • +
  • length: 10.0
  • +
  • height: 7.5
  • +
+
+ +### cube + + - + +
This is a cube from examplesParameters:
  • width: 20.0
  • length: 10.0
  • height: 7.5
Parameters:
    +
  • width: 10.0
  • +
  • length: 10.0
  • +
  • height: 10.0
  • +
+
Aliases:
  • box
### cylinder - +
This is a cylinder from examples
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_extrude/README.md b/examples/produce_part_extrude/README.md index 193a08ba..cc27b183 100644 --- a/examples/produce_part_extrude/README.md +++ b/examples/produce_part_extrude/README.md @@ -12,22 +12,24 @@ pc inspect clock ## Parts +### clock + + + +
Extrude a clock sketch to create a 3D clock.
+ ### cylinder - +
Extrude a circle sketch to create a cylinder.
### dxf - +
Extrude a DXF sketch to create a 3D part.
-### clock - - - -
Extrude a clock sketch to create a 3D clock.
+

*Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_openscad/README.md b/examples/produce_part_openscad/README.md index f2888656..d8236fb5 100644 --- a/examples/produce_part_openscad/README.md +++ b/examples/produce_part_openscad/README.md @@ -12,8 +12,10 @@ pc inspect cube ### cube - +
A cube defined in SCAD
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_step/README.md b/examples/produce_part_step/README.md index eb186d1e..785fc118 100644 --- a/examples/produce_part_step/README.md +++ b/examples/produce_part_step/README.md @@ -12,9 +12,32 @@ pc inspect bolt ### bolt - +
M8x30-screw Aliases:
  • hexhead
+### fastener (alias to bolt) + + + + +
M8x30-screwAliases:
  • hexhead
+ +### hexhead (alias to bolt) + + + + +
M8x30-screwAliases:
  • hexhead
+ +### screw (alias to bolt) + + + + +
M8x30-screwAliases:
  • hexhead
+ +

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_part_stl/README.md b/examples/produce_part_stl/README.md index 6d85cc8d..f48543e2 100644 --- a/examples/produce_part_stl/README.md +++ b/examples/produce_part_stl/README.md @@ -12,8 +12,10 @@ pc inspect cube ### cube - +
A cube defined in STL
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_sketch_basic/README.md b/examples/produce_sketch_basic/README.md index 80e127d5..84d18857 100644 --- a/examples/produce_sketch_basic/README.md +++ b/examples/produce_sketch_basic/README.md @@ -16,32 +16,34 @@ pc inspect -s rect_01 ### circle_01 - +
The shortest way to create a basic circle in PartCAD
### circle_02 - +
A longer way to create a basic circle in PartCAD
### circle_03 - +
The longest way to create a basic circle in PartCAD
-### square_01 +### rect_01 - - + +
The shortest way to create a basic square in PartCADThe longest way to create a basic square in PartCAD
-### rect_01 +### square_01 - - + +
The longest way to create a basic square in PartCADThe shortest way to create a basic square in PartCAD
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_sketch_build123d/README.md b/examples/produce_sketch_build123d/README.md index d33b9540..13270e62 100644 --- a/examples/produce_sketch_build123d/README.md +++ b/examples/produce_sketch_build123d/README.md @@ -12,8 +12,10 @@ pc inspect -s clock ### clock - +
A clock face taken from the build123d examples
+

+ *Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_sketch_dxf/README.md b/examples/produce_sketch_dxf/README.md index 42b13ce7..628d3b98 100644 --- a/examples/produce_sketch_dxf/README.md +++ b/examples/produce_sketch_dxf/README.md @@ -11,6 +11,8 @@ pc inspect -s dxf_01 ## Sketches ### dxf_01 - + + +

*Generated by [PartCAD](https://partcad.org/)* diff --git a/examples/produce_sketch_svg/README.md b/examples/produce_sketch_svg/README.md index 9d335e8a..923e55d0 100644 --- a/examples/produce_sketch_svg/README.md +++ b/examples/produce_sketch_svg/README.md @@ -11,6 +11,8 @@ pc inspect -s svg_01 ## Sketches ### svg_01 - + + +

*Generated by [PartCAD](https://partcad.org/)* diff --git a/partcad/src/partcad/assembly_factory_alias.py b/partcad/src/partcad/assembly_factory_alias.py index cd7f3e34..f483d3a5 100644 --- a/partcad/src/partcad/assembly_factory_alias.py +++ b/partcad/src/partcad/assembly_factory_alias.py @@ -56,6 +56,7 @@ def __init__(self, ctx, source_project, target_project, config): self.source = ( self.source_project_name + ":" + self.source_assembly_name ) + config["source_resolved"] = self.source if self.source_project_name == self.project.name: self.assembly.desc = "Alias to %s" % self.source_assembly_name diff --git a/partcad/src/partcad/part_factory_alias.py b/partcad/src/partcad/part_factory_alias.py index d33e94f9..4e91cb65 100644 --- a/partcad/src/partcad/part_factory_alias.py +++ b/partcad/src/partcad/part_factory_alias.py @@ -54,6 +54,7 @@ def __init__(self, ctx, source_project, target_project, config): else: self.source_project_name = source_project.name self.source = self.source_project_name + ":" + self.source_part_name + config["source_resolved"] = self.source if self.source_project_name == target_project.name: self.part.desc = "Alias to %s" % self.source_part_name diff --git a/partcad/src/partcad/project.py b/partcad/src/partcad/project.py index 5d176d67..abdf6d19 100644 --- a/partcad/src/partcad/project.py +++ b/partcad/src/partcad/project.py @@ -47,7 +47,7 @@ from . import provider from . import provider_config from .render import render_cfg_merge -from .utils import resolve_resource_path +from .utils import resolve_resource_path, normalize_resource_path class Project(project_config.Configuration): @@ -1761,7 +1761,7 @@ def render_readme_async(self, render_cfg, output_dir): lines += columns lines += [""] - def add_section(name, shape, render_cfg): + def add_section(name, display_name, shape, render_cfg): config = shape.config if ( @@ -1803,11 +1803,11 @@ def add_section(name, shape, render_cfg): image_path = os.path.join( return_path, svg_cfg.get("prefix", "."), - name + ".svg", + shape.name + ".svg", ) test_image_path = os.path.join( svg_cfg.get("prefix", "."), - name + ".svg", + shape.name + ".svg", ) img_text = ( '' @@ -1822,11 +1822,11 @@ def add_section(name, shape, render_cfg): image_path = os.path.join( return_path, png_cfg.get("prefix", "."), - name + ".png", + shape.name + ".png", ) test_image_path = os.path.join( png_cfg.get("prefix", "."), - name + ".png", + shape.name + ".png", ) img_text = ( '' @@ -1893,7 +1893,7 @@ def add_section(name, shape, render_cfg): interfaces += "- %s
" % interface.name columns += [interfaces] - lines = ["### %s" % name] + lines = ["### %s" % display_name] if len(columns) > 1: lines += [""] lines += map(lambda c: "", columns) @@ -1909,7 +1909,15 @@ def add_section(name, shape, render_cfg): shape_names = sorted(self.assemblies.keys()) for name in shape_names: shape = self.assemblies[name] - lines += add_section(name, shape, render_cfg) + if shape.config["type"] == "alias": + source_path = normalize_resource_path( + self.name, shape.config["source_resolved"] + ) + shape = self.ctx.get_assembly(source_path) + display_name = name + " (alias to " + shape.name + ")" + else: + display_name = name + lines += add_section(name, display_name, shape, render_cfg) if self.parts and not "parts" in exclude: lines += ["## Parts"] @@ -1917,7 +1925,15 @@ def add_section(name, shape, render_cfg): shape_names = sorted(self.parts.keys()) for name in shape_names: shape = self.parts[name] - lines += add_section(name, shape, render_cfg) + if shape.config["type"] == "alias": + source_path = normalize_resource_path( + self.name, shape.config["source_resolved"] + ) + shape = self.ctx.get_part(source_path) + display_name = name + " (alias to " + shape.name + ")" + else: + display_name = name + lines += add_section(name, display_name, shape, render_cfg) if self.interfaces and not "interfaces" in exclude: lines += ["## Interfaces"] @@ -1925,7 +1941,7 @@ def add_section(name, shape, render_cfg): shape_names = sorted(self.interfaces.keys()) for name in shape_names: shape = self.interfaces[name] - lines += add_section(name, shape, render_cfg) + lines += add_section(name, name, shape, render_cfg) if self.sketches and not "sketches" in exclude: lines += ["## Sketches"] @@ -1933,7 +1949,7 @@ def add_section(name, shape, render_cfg): shape_names = sorted(self.sketches.keys()) for name in shape_names: shape = self.sketches[name] - lines += add_section(name, shape, render_cfg) + lines += add_section(name, name, shape, render_cfg) lines += [ "

",
" + c + "