コード例 #1
0
class SCLDifference(SCLPart3):
    def __init__(self, parent):
        super().__init__(parent)

    def difference(self):
        children = self.get_children()
        shapes = []
        debug("children: %s" % (children, ))
        for c in children:
            if c.shape != None:
                shapes.append(c.shape)
        u = None
        f = None
        if len(shapes) > 1:
            f = shapes[0].get_shape()
            for s in shapes[1:]:
                f = BRepAlgoAPI_Cut(f, s.get_shape()).Shape()
        self.shape = SCLShape(f)
        self.shape.set_shape_color(shapes[0].get_shape_color())
        self.children = []

    def display(self, writer=None):
        debug("Display SCLUnion")
        if self.shape != None:
            self.shape.display(writer)
コード例 #2
0
 def intersection(self):
     children = self.get_children()
     shapes = []
     debug("children: %s" % (children, ))
     for c in children:
         if c.shape != None:
             shapes.append(c.shape)
     u = None
     if len(shapes) > 0:
         u = shapes[0].get_shape()
         for s in shapes[1:]:
             u = BRepAlgoAPI_Common(u, s.get_shape()).Shape()
     self.shape = SCLShape(u)
     self.children = []
コード例 #3
0
 def difference(self):
     children = self.get_children()
     shapes = []
     debug("children: %s" % (children, ))
     for c in children:
         if c.shape != None:
             shapes.append(c.shape)
     u = None
     f = None
     if len(shapes) > 1:
         f = shapes[0].get_shape()
         for s in shapes[1:]:
             f = BRepAlgoAPI_Cut(f, s.get_shape()).Shape()
     self.shape = SCLShape(f)
     self.shape.set_shape_color(shapes[0].get_shape_color())
     self.children = []
コード例 #4
0
 def import_step(self, filename):
     shapes_labels_colors = read_step_file_with_names_colors(filename)
     for shpt_lbl_color in shapes_labels_colors:
         label, c = shapes_labels_colors[shpt_lbl_color]
         debug("shpt_lbl_color: %s" % (str(shpt_lbl_color), ))
         if (type(shpt_lbl_color) != TopoDS_Solid):
             debug("skip")
             continue
         scls = SCLShape(shpt_lbl_color)
         scls.color([c.Red(), c.Green(), c.Blue()])
         sclp = SCLPart3(self)
         sclp.set_shape(scls)
         name = get_inc_name("step")
         sclp.set_name(name)
         debug("Creating step %s" % (name, ))
         self.add_child_context(sclp)
コード例 #5
0
    def cube(self, xyz, center=False):
        cube_shape = BRepPrimAPI_MakeBox(xyz.x(), xyz.y(), xyz.z()).Shape()

        scls = SCLShape(cube_shape)
        if (center):
            debug("center cube")
            trsf = gp_Trsf()
            trsf.SetTranslation(
                gp_Vec(-xyz.x() / 2.0, -xyz.y() / 2.0, -xyz.z() / 2.0))
            scls.transform(trsf)
        sclp = SCLPart3(self)
        sclp.set_shape(scls)
        name = get_inc_name("cube")
        sclp.set_name(name)
        debug("Creating cube %s" % (name, ))
        self.add_child_context(sclp)
コード例 #6
0
    def cylinder(self, r, r1, r2, d, d1, d2, h, center=False):
        nr1 = None
        nr2 = None
        nh = None
        if (not is_var_set(d)) and is_var_set(r):
            nr1 = r
            nr2 = r
        elif is_var_set(d) and (not is_var_set(r)):
            nr1 = d / 2.0
            nr2 = d / 2.0
        elif is_var_set(d) and is_var_set(r):
            nr1 = d / 2.0
            nr2 = d / 2.0
        elif (not is_var_set(d)) and (not is_var_set(r)) and (
                is_var_set(r1) and is_var_set(r2)):
            nr1 = r1
            nr2 = r2
        elif (not is_var_set(d)) and (not is_var_set(r)) and (
                is_var_set(d1) and is_var_set(d2)):
            nr1 = d1 / 2.0
            nr2 = d2 / 2.0
        else:
            nr1 = 0.5
            nr2 = 0.5

        nh = 1.0
        if is_var_set(h):
            nh = h

        ax = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
        s = None
        if nr1 == nr2:
            s = BRepPrimAPI_MakeCylinder(ax, nr1, nh).Shape()
        else:
            s = BRepPrimAPI_MakeCone(ax, nr1, nr2, nh).Shape()
        scls = SCLShape(s)
        if (center):
            debug("center cylinder")
            trsf = gp_Trsf()
            trsf.SetTranslation(gp_Vec(0, 0, -h / 2.0))
            scls.transform(trsf)
        sclp = SCLPart3(self)
        sclp.set_shape(scls)
        name = get_inc_name("cylinder")
        sclp.set_name(name)
        debug("Creating cylinder %s" % (name, ))
        self.add_child_context(sclp)
コード例 #7
0
 def import_stl(self, filename):
     stl_shp = read_stl_file(filename)
     scls = SCLShape(stl_shp)
     sclp = SCLPart3(self)
     sclp.set_shape(scls)
     name = get_inc_name("stl")
     sclp.set_name(name)
     debug("Creating stl %s" % (name, ))
     self.add_child_context(sclp)
コード例 #8
0
class SCLIntersection(SCLPart3):
    def __init__(self, parent):
        super().__init__(parent)

    def intersection(self):
        children = self.get_children()
        shapes = []
        debug("children: %s" % (children, ))
        for c in children:
            if c.shape != None:
                shapes.append(c.shape)
        u = None
        if len(shapes) > 0:
            u = shapes[0].get_shape()
            for s in shapes[1:]:
                u = BRepAlgoAPI_Common(u, s.get_shape()).Shape()
        self.shape = SCLShape(u)
        self.children = []

    def display(self, writer=None):
        debug("Display SCLIntersection")
        if self.shape != None:
            self.shape.display(writer)
コード例 #9
0
    def linear_extrude(self, height=1.0):
        faces = []
        for c in self.children:
            debug("Adding face")
            f = c.get_face()
            faces.append(f)

        self.children = []

        for f in faces:
            prism_vec = gp_Vec(0, 0, height)
            shape = BRepPrimAPI_MakePrism(f.Face(), prism_vec).Shape()
            scls = SCLShape(shape)
            sclp = SCLPart3(self)
            sclp.set_shape(scls)
            name = get_inc_name("extrusion")
            sclp.set_name(name)
            debug("Creating extrusion %s" % (name, ))
            self.add_child_context(sclp)
コード例 #10
0
    def loft(self, solid=True, ruled=True, precision=0.000001):
        wires = collect_wires(self)

        self.children = []

        generator = BRepOffsetAPI_ThruSections(solid, ruled, precision)

        for w in wires:
            debug("wire: %s" % (str(w), ))
            generator.AddWire(w)
        generator.Build()

        shape = generator.Shape()
        scls = SCLShape(shape)
        sclp = SCLPart3(self)
        sclp.set_shape(scls)
        name = get_inc_name("loft")
        sclp.set_name(name)
        debug("Creating loft %s" % (name, ))
        self.add_child_context(sclp)
コード例 #11
0
 def hlr_project(self, shapes):
     hlralgo = HLRBRep_Algo()
     if len(shapes) > 0:
         for s in shapes:
             hlralgo.Add(s)
         self.children = []
         trsf = gp_Trsf()
         p = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(0, 0, 1)))
         hlralgo.Projector(p)
         hlralgo.Update()
         hlralgo.Hide()
         hlrtoshape = HLRBRep_HLRToShape(hlralgo)
         vcompound = hlrtoshape.VCompound()
         voutline = hlrtoshape.OutLineVCompound()
         rg1linevcompound = hlrtoshape.Rg1LineVCompound()
         rgnlinevcompound = hlrtoshape.RgNLineVCompound()
         isolinevcompound = hlrtoshape.IsoLineVCompound()
         hcompound = hlrtoshape.HCompound()
         houtline = hlrtoshape.OutLineHCompound()
         rg1linehcompound = hlrtoshape.Rg1LineHCompound()
         rgnlinehcompound = hlrtoshape.RgNLineHCompound()
         isolinehcompound = hlrtoshape.IsoLineHCompound()
         debug("vcompound: %s" % (str(vcompound), ))
         debug("voutline: %s" % (str(voutline), ))
         debug("rg1linevcompound: %s" % (str(rg1linevcompound), ))
         debug("rgnlinevcompound: %s" % (str(rgnlinevcompound), ))
         debug("isolinevcompound: %s" % (str(isolinevcompound), ))
         debug("hcompound: %s" % (str(hcompound), ))
         debug("houtline: %s" % (str(houtline), ))
         debug("rg1linehcompound: %s" % (str(rg1linehcompound), ))
         debug("rgnlinehcompound: %s" % (str(rgnlinehcompound), ))
         debug("isolinehcompound: %s" % (str(isolinehcompound), ))
         name = get_inc_name("projection")
         if (vcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(vcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'vcompound')
             self.add_child_context(sclp)
         if (voutline != None):
             sclp = SCLPart3(self)
             scls = SCLShape(voutline)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'voutline')
             self.add_child_context(sclp)
         if (rg1linevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rg1linevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'rg1linevcompound')
             self.add_child_context(sclp)
         if (rgnlinevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rgnlinevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'rgnlinecompound')
             self.add_child_context(sclp)
         if (isolinevcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(isolinevcompound)
             scls.set_linestyle("main_projection")
             sclp.set_shape(scls)
             sclp.set_name(name + 'isolinevcompound')
             self.add_child_context(sclp)
         if (hcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(hcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'hcompound')
             self.add_child_context(sclp)
         if (houtline != None):
             sclp = SCLPart3(self)
             scls = SCLShape(houtline)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'houtline')
             self.add_child_context(sclp)
         if (rg1linehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rg1linehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'rg1linehcompound')
             self.add_child_context(sclp)
         if (rgnlinehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(rgnlinehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'rgnlinehcompound')
             self.add_child_context(sclp)
         if (isolinehcompound != None):
             sclp = SCLPart3(self)
             scls = SCLShape(isolinehcompound)
             scls.set_linestyle("hidden")
             scls.set_hidden(True)
             sclp.set_shape(scls)
             sclp.set_name(name + 'isolinehcompound')
             self.add_child_context(sclp)