示例#1
0
    def export(self):
        """ Export a DeclaraCAD model from an enaml file to VRML based on the
        given options.

        Parameters
        ----------
        options: declaracad.occ.plugin.ExportOptions

        """
        # Set all params
        exporter = VrmlAPI_Writer()
        exporter.SetDeflection(self.deflection)

        rep_name = self.representation.title().replace('-', '')
        exporter.SetRepresentation(
            getattr(VrmlAPI_RepresentationOfShape,
                    f'VrmlAPI_{rep_name}Representation'))
        v = self.version
        output_path = self.path

        # Load the enaml model file
        parts = load_model(self.filename)

        # Remove old file
        if os.path.exists(output_path):
            os.remove(output_path)

        for part in parts:
            # Render the part from the declaration
            s = part.render()

            # Transfer all shapes
            if not exporter.Write(s, output_path, v):
                raise RuntimeError("Failed to write shape")
        print(f"Written to {output_path}")
示例#2
0
    def export(self):
        """ Export a DeclaraCAD model from an enaml file to an STL based on the
        given options.
        
        Parameters
        ----------
        options: declaracad.occ.plugin.ExportOptions
        
        """
        from OCC.BRep import BRep_Builder
        from OCC.BRepMesh import BRepMesh_IncrementalMesh
        from OCC.StlAPI import StlAPI_Writer
        from OCC.TopoDS import TopoDS_Compound
        
        # Make a compound of compounds (if needed)
        compound = TopoDS_Compound()
        builder = BRep_Builder()
        builder.MakeCompound(compound)
        
        # Load the enaml model file
        parts = load_model(self.filename)
        
        for part in parts:
            # Render the part from the declaration
            shape = part.render()
            
            # Must mesh the shape firsts
            if hasattr(shape, 'Shape'):
                builder.Add(compound, shape.Shape())
            else:
                builder.Add(compound, shape)

        #: Build the mesh
        exporter = StlAPI_Writer()
        exporter.SetASCIIMode(not self.binary)
        mesh = BRepMesh_IncrementalMesh(
            compound,
            self.linear_deflection,
            self.relative,
            self.angular_deflection
        )
        mesh.Perform()
        if not mesh.IsDone():
            raise RuntimeError("Failed to create the mesh")
        
        exporter.Write(compound, self.path)
            
        if not os.path.exists(self.path):
            raise RuntimeError("Failed to write shape")
示例#3
0
    def export(self):
        """ Export a DeclaraCAD model from an enaml file to an STL based on the
        given options.
        
        Parameters
        ----------
        options: declaracad.occ.plugin.ExportOptions
        
        """
        from OCC.STEPControl import STEPControl_Writer, STEPControl_AsIs
        from OCC.Interface import Interface_Static_SetCVal as SetCVal
        from OCC.Interface import Interface_Static_SetIVal as SetIVal
        from OCC.Interface import Interface_Static_SetRVal as SetRVal
        from OCC.IFSelect import IFSelect_RetDone
        
        # Set all params
        exporter = STEPControl_Writer()
        SetIVal("write.precision.mode", PRECISION_MODES[self.precision_mode])
        if self.precision_mode == 'greatest':
            SetRVal("write.precision.val", self.precision_val)
        SetIVal("write.step.assembly", ASSEMBLY_MODES[self.assembly_mode])
        SetCVal("write.step.schema", self.schema)
        if self.product_name:
            SetCVal("write.step.product.name", self.product_name)
        SetIVal("write.surfacecurve.mode", 
                SURFACECURVE_MODES[self.surfacecurve_mode])
        SetCVal("write.step.unit", self.units.upper())
        SetIVal("write.step.vertex.mode", VERTEX_MODES[self.vertex_mode])

        # Load the enaml model file
        parts = load_model(self.filename)
        
        for part in parts:
            # Render the part from the declaration
            shape = part.render()
            
            # Transfer all shapes
            if hasattr(shape, 'Shape'):
                exporter.Transfer(shape.Shape(), STEPControl_AsIs)
            else:
                exporter.Transfer(shape, STEPControl_AsIs)

        # Send it
        status = exporter.Write(self.path)
        if status != IFSelect_RetDone or not os.path.exists(self.path):
            raise RuntimeError("Failed to write shape")
示例#4
0
def test_shapes_render(qt_app, name):
    assembly = load_model("test", TEMPLATE % TESTS[name])[0]
    assert isinstance(assembly.render(), TopoDS_Shape)
示例#5
0
def main(**kwargs):
    app = Application()
    view = Main(model=load_model(kwargs['file']))
    view.show()
    app.start()
示例#6
0
def test_example(qt_app, name):
    path = 'examples/%s.enaml' % name
    assembly = load_model(path)
    for shape in assembly:
        assert isinstance(shape.render(), TopoDS_Shape)