Exemplo n.º 1
0
def bounding_box(objs, loc=None, optimal=False):
    if isinstance(objs, (list, tuple)):
        compound = Compound._makeCompound(objs)
    else:
        compound = objs

    return BoundingBox(compound if loc is None else compound.Moved(loc.wrapped), optimal=optimal)
Exemplo n.º 2
0
def bounding_box(objs, loc=None, optimal=False):
    if isinstance(objs, (list, tuple)):
        compound = Compound._makeCompound(objs)  # pylint: disable=protected-access
    else:
        compound = objs

    return BoundingBox(compound if loc is None else compound.Moved(loc),
                       optimal=optimal)
 def __init__(self, edges, name="edges", color=None):
     super().__init__()
     self.edges = edges
     self.name = name
     self._compound = Compound.makeCompound(edges.objects)
     self.id = self.next_id()
     if color is not None:
         self.color = color
Exemplo n.º 4
0
def exportSTL(cadObj, filename, precision=0.001):
    compound = None
    if isinstance(cadObj, cadquery.Shape):
        compound = Compound.makeCompound(cadObj.objects)
    elif isinstance(cadObj, cadquery.Workplane):
        compound = Compound.makeCompound(cadObj.objects)
    elif isinstance(cadObj, cq_jupyter.Assembly):
        compound = cadObj.compound()
    elif isinstance(cadObj, cq_jupyter.Part):
        compound = cadObj.compound()
    elif has_cqparts and isinstance(cadObj, cqparts.Assembly):
        assembly = convertCqparts(cadObj)
        exportSTL(assembly, filename, precision)
    elif has_cqparts and isinstance(cadObj, cqparts.Part):
        part = cq_jupyter.Part(cadObj.local_obj, "part")
        exportSTL(part, filename)
    else:
        print("Unknown CAD object", type(cadObj))

    if compound is not None:
        compound.exportStl(filename, precision=precision)   
 def __init__(self,
              shape,
              name="part",
              color=None,
              show_faces=True,
              show_edges=True):
     super().__init__()
     self.name = name
     self.id = self.next_id()
     if color is not None:
         self.color = color
     self.shape = shape
     self._compound = Compound.makeCompound(shape.objects)
     self.show_faces = show_faces
     self.show_edges = show_edges
Exemplo n.º 6
0
 def compound(self):
     return Compound._makeCompound(self.compounds())
Exemplo n.º 7
0
 def compound(self):
     return Compound._makeCompound(self.compounds())  # pylint: disable=protected-access
Exemplo n.º 8
0
 def compound(self):
     return Compound._makeCompound(self.shape)
Exemplo n.º 9
0
    def run(self):

        options = self.options
        content = self.content
        state_machine = self.state_machine
        env = self.state.document.settings.env
        build_path = Path(env.app.builder.outdir)
        out_path = build_path / "_static"

        # only consider inline snippets
        plot_code = "\n".join(content)

        # collect the result
        try:
            result = cqgi.parse(plot_code).build()

            if result.success:
                if result.first_result:
                    shape = result.first_result.shape
                else:
                    shape = result.env[options.get("select", "result")]

                if isinstance(shape, Assembly):
                    assy = shape
                else:
                    assy = Assembly(shape, color=Color(*DEFAULT_COLOR))
            else:
                raise result.exception

        except Exception:
            traceback.print_exc()
            assy = Assembly(Compound.makeText("CQGI error", 10, 5))

        # save vtkjs to static
        fname = Path(str(uuid()))
        exporters.assembly.exportVTKJS(assy, out_path / fname)
        fname = str(fname) + ".zip"

        # add the output
        lines = []

        data = dumps(toJSON(assy))

        lines.extend(
            template_vtk.format(
                code=indent(TEMPLATE_RENDER.format(), "    "),
                data=data,
                ratio="null",
                element="document.currentScript.parentNode",
                txt_align=options.get("align", "left"),
                width=options.get("width", "100%"),
                height=options.get("height", "500px"),
            ).splitlines())

        lines.extend(["::", ""])
        lines.extend(
            ["    %s" % row.rstrip() for row in plot_code.split("\n")])
        lines.append("")

        if len(lines):
            state_machine.insert_input(lines,
                                       state_machine.input_lines.source(0))

        return []