Exemplo n.º 1
0
    def TransformShape(self, X: float, Y: float, Z: float, RX: float,
                       RY: float, RZ: float,
                       Shape: TopoDS_Compound) -> TopoDS_Compound:
        trsf = self.__GetTransform(X, Y, Z, RX, RY, RZ)

        transform = BRepBuilderAPI_Transform(Shape, trsf, False)
        transform.Build()

        return transform.Shape()
Exemplo n.º 2
0
def mirror_axe2(brep, axe2, copy=False):
    '''
    @param brep:
    @param line:
    '''
    trns = gp_Trsf()
    trns.SetMirror(axe2)
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    with assert_isdone(brep_trns, 'could not produce mirror'):
        brep_trns.Build()
        return brep_trns.Shape()
Exemplo n.º 3
0
def mirror_pnt_dir(brep, pnt, direction, copy=False):
    '''
    @param brep:
    @param line:
    '''
    trns = gp_Trsf()
    trns.SetMirror(gp_Ax1(pnt, direction))
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    with assert_isdone(brep_trns, 'could not produce mirror'):
        brep_trns.Build()
        return brep_trns.Shape()
Exemplo n.º 4
0
def translate_topods_from_vector(brep_or_iterable, vec, copy=False):
    '''
    translate a brep over a vector
    @param brep:    the Topo_DS to translate
    @param vec:     the vector defining the translation
    @param copy:    copies to brep if True
    '''
    trns = gp_Trsf()
    trns.SetTranslation(vec)
    brep_trns = BRepBuilderAPI_Transform(brep_or_iterable, trns, copy)
    brep_trns.Build()
    return brep_trns.Shape()
Exemplo n.º 5
0
def rotate(brep, axe, degree, copy=False):
    '''
    @param brep:
    @param axe:
    @param degree:
    '''
    from math import radians
    trns = gp_Trsf()
    trns.SetRotation(axe, radians(degree))
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    with assert_isdone(brep_trns, 'could not produce rotation'):
        brep_trns.Build()
        return ST(brep_trns.Shape())
Exemplo n.º 6
0
def scale_uniformal(brep, pnt, factor, copy=False):
    '''
    translate a brep over a vector
    @param brep:    the Topo_DS to translate
    @param pnt:     a gp_Pnt
    @param triple:  scaling factor
    @param copy:    copies to brep if True
    '''
    trns = gp_Trsf()
    trns.SetScale(pnt, factor)
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    brep_trns.Build()
    return brep_trns.Shape()
Exemplo n.º 7
0
def translate_topods_from_vector(brep, vec, copy=False):
    """Translate a brep over a vector.

    Args:
        brep (BRep): the Topo_DS to translate
        vec (gp_Vec): the vector defining the translation
        copy (bool): copies to brep if True
    """
    trns = gp_Trsf()
    trns.SetTranslation(vec)
    brep_trns = BRepBuilderAPI_Transform(brep, trns, copy)
    brep_trns.Build()
    return brep_trns.Shape()
Exemplo n.º 8
0
def translate_topods_from_vector(brep_or_iterable, vec, copy=False):
    '''
    translate a brep over a vector
    @param brep:    the Topo_DS to translate
    @param vec:     the vector defining the translation
    @param copy:    copies to brep if True
    '''
    st = ShapeToTopology()
    trns = gp_Trsf()
    trns.SetTranslation(vec)
    if issubclass(brep_or_iterable.__class__, TopoDS_Shape):
        brep_trns = BRepBuilderAPI_Transform(brep_or_iterable, trns, copy)
        brep_trns.Build()
        return st(brep_trns.Shape())
    else:
        return [translate_topods_from_vector(brep_or_iterable, vec, copy) for i in brep_or_iterable]
Exemplo n.º 9
0
    def create_model(self, rotate_angle=None):
        edges = makeEdgesFromPoints(self.points)
        wire = makeWireFromEdges(edges)
        aFace = makeFaceFromWire(wire)
        extrudeDir = self.T * self.wDir  # extrudeDir is a numpy array
        if rotate_angle == None:
            prism1 = makePrismFromFace(aFace, extrudeDir)
        else:
            prism = makePrismFromFace(aFace, extrudeDir)
            trns = gp_Trsf()
            # axis = numpy.array([1.0, 0.0, 0.0])
            angle = radians(rotate_angle)
            trns.SetRotation(gp_OX(), angle)
            brep_trns = BRepBuilderAPI_Transform(prism, trns, False)
            brep_trns.Build()
            prism1 = brep_trns.Shape()

        return prism1
Exemplo n.º 10
0
def rotate_shape(shape, axis, angle, unite="deg"):
    """Rotate a shape around an axis, with a given angle.

    @param shape : the shape to rotate
    @point : the origin of the axis
    @vector : the axis direction
    @angle : the value of the rotation

    @return: the rotated shape.
    """
    assert_shape_not_null(shape)
    if unite == "deg":  # convert angle to radians
        angle = radians(angle)
    trns = gp_Trsf()
    trns.SetRotation(axis, angle)
    brep_trns = BRepBuilderAPI_Transform(shape, trns, False)
    brep_trns.Build()
    shp = brep_trns.Shape()
    return shp
Exemplo n.º 11
0
    def _place(self):
        """
        put the part where it belongs. This should be called
        after the shape has been initialized, so that the
        shape can be transformed
        """
        assert (self._shape is not None)

        if self._parent is not None:
            trans = self._parent.shape.Location().Transformation()
        else:
            trans = gp_Trsf()

        translation = gp_Trsf()
        translation.SetTranslation(gp_Vec(*self._position))
        trans = trans * translation

        rot = euler_to_gp_trsf(self._orientation)
        trans = trans * rot

        brep_trns = BRepBuilderAPI_Transform(self._shape, trans, False)
        brep_trns.Build()
        self._shape = brep_trns.Shape()
Exemplo n.º 12
0
 def translate_shp(shp, vec, copy=False):
     trns = gp_Trsf()
     trns.SetTranslation(vec)
     brep_trns = BRepBuilderAPI_Transform(shp, trns, copy)
     brep_trns.Build()
     return brep_trns.Shape()
Exemplo n.º 13
0
def get_boundingbox_shape(bb):
    """
    Given the dict returned by `get_boundingbox`, this
    function creates a TopoDS_Compound to visualize
    the bounding box, including annotations

    :param bb: dict returned by `get_boundingbox`

    :return: a TopoDS_Compound to visualize the bounding box
    """
    compound = TopoDS_Compound()
    builder = BRep_Builder()
    builder.MakeCompound(compound)

    bb_box = BRepPrimAPI_MakeBox(bb['dx'], bb['dy'], bb['dz']).Shape()
    translation = gp_Trsf()
    translation.SetTranslation(gp_Vec(bb['xmin'], bb['ymin'], bb['zmin']))
    brep_trns = BRepBuilderAPI_Transform(bb_box, translation, False)
    brep_trns.Build()
    bb_box = brep_trns.Shape()
    anEdgeExplorer = TopExp_Explorer(bb_box, TopAbs_EDGE)
    while anEdgeExplorer.More():
        anEdge = topods.Edge(anEdgeExplorer.Current())
        builder.Add(compound, anEdge)
        anEdgeExplorer.Next()

    dx_string = text_to_brep(str(round(bb['dx'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True)
    transformation = gp_Trsf()
    transformation.SetTranslation(gp_Vec(bb['xmin'] + 120, bb['ymin'] - 120, 0))
    brep_trns = BRepBuilderAPI_Transform(dx_string, transformation, False)
    brep_trns.Build()
    dx_string = brep_trns.Shape()
    builder.Add(compound, dx_string)

    dy_string = text_to_brep(str(round(bb['dy'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True)
    t1 = gp_Trsf()
    z = gp_Ax1(gp_Pnt(), gp_Dir(0, 0, 1))
    t1.SetRotation(z, radians(90))
    t2 = gp_Trsf()
    t2.SetTranslation(gp_Vec(bb['xmin'] - 25, bb['ymin'] + 120, 0))
    brep_trns = BRepBuilderAPI_Transform(dy_string, t2 * t1, False)
    brep_trns.Build()
    dy_string = brep_trns.Shape()
    builder.Add(compound, dy_string)

    dz_string = text_to_brep(str(round(bb['dz'])) + " mm", "Arial", Font_FontAspect_Bold, 120., True)
    x = gp_Ax1(gp_Pnt(), gp_Dir(1, 0, 0))
    y = gp_Ax1(gp_Pnt(), gp_Dir(0, 1, 0))
    z = gp_Ax1(gp_Pnt(), gp_Dir(0, 0, 1))
    t1 = gp_Trsf()
    t1.SetRotation(z, radians(90))
    t2 = gp_Trsf()
    t2.SetRotation(y, radians(90))
    t3 = gp_Trsf()
    t3.SetRotation(x, radians(90))
    t4 = gp_Trsf()
    t4.SetTranslation(gp_Vec(bb['xmin'], bb['ymin'] - 25, 120))
    brep_trns = BRepBuilderAPI_Transform(dz_string, t4 * t3 * t2 * t1, False)
    brep_trns.Build()
    dz_string = brep_trns.Shape()
    builder.Add(compound, dz_string)

    return compound