Пример #1
0
def display_str_at_pos(stri, col, line):
    brepstr = text_to_brep(stri, "Arial", Font_FA_Bold, 12., True)
    # translate the letter to the right
    brepstr_translated = translate_shp(brepstr, gp_Vec(col * 8, -line * 10, 0))
    brepstr_extruded = make_extrusion(brepstr_translated, 2.5)
    display.DisplayColoredShape(brepstr_extruded, 'WHITE')
    display.Repaint()
Пример #2
0
def extrude_closed_wire(wire: TopoDS_Wire, origin, normal,
                        height) -> TopoDS_Shape:
    """Extrude a closed wire into a solid"""
    p1 = origin + normal * height
    starting_point = gp_Pnt(origin[0], origin[1], origin[2])
    end_point = gp_Pnt(*p1.tolist())
    vec = gp_Vec(starting_point, end_point)

    solid = make_extrusion(make_face(wire), height, vec)

    return solid
Пример #3
0
def combine_faces(face1, face2, height_mm):
    assert isinstance(face1, TopoDS_Face)
    assert isinstance(face2, TopoDS_Face)

    face1_ = copy.deepcopy(face1)
    face2_ = copy.deepcopy(face2)

    # assuming both faces start in the XZ plane
    tf = gp_Trsf()
    # rotate from the XZ plane to the YZ plane
    tf.SetRotation(gp_Ax1(ORIGIN, DIR_Z), math.pi / 2)
    face2_ = BRepBuilderAPI_Transform(face2_, tf).Shape()

    # We assume characters are no wider than they are tall, but just in case
    # we extrude by twice the height to make sure to capture all features
    face1_extruded = make_extrusion(face1_, 2 * height_mm, gp_Vec(0, 1, 0))
    face2_extruded = make_extrusion(face2_, 2 * height_mm, gp_Vec(1, 0, 0))
    common = BRepAlgoAPI_Common(face1_extruded, face2_extruded)

    result = common.Shape()
    assert isinstance(result, TopoDS_Compound)
    return copy.deepcopy(result)
Пример #4
0
    def MakeHexagonPattern(self, Length: float, Diameter: float,
                           Radius: float) -> TopoDS_Compound:
        section = self.__face.MakeHexagonFace(Diameter, Radius)

        return make_extrusion(section, Length, gp_Vec(0., 0., 1.))
Пример #5
0
    def MakeSquarePattern(self, Length: float, Width: float, High: float,
                          Radius: float) -> TopoDS_Compound:
        section = self.__face.MakeSquareFace(Width, High, Radius)

        return make_extrusion(section, Length, gp_Vec(0., 0., 1.))
Пример #6
0
    def MakeEliplePattern(self, Length: float, Major: float,
                          Minor: float) -> TopoDS_Compound:
        section = self.__face.MakeEllipsFace(Major, Minor)

        return make_extrusion(section, Length, gp_Vec(0., 0., 1.))
Пример #7
0
    def MakeCirclePatern(self, Length: float,
                         Diameter: float) -> TopoDS_Compound:
        section = self.__face.MakeCircleFace(Diameter / 2.0)

        return make_extrusion(section, Length, gp_Vec(0., 0., 1.))
Пример #8
0
         "Hello world": "Arial",  # English
         "Bonjour monde": "Arial",  # French
         "Hallo Welt": "Arial",  # German
         "γειά σου κόσμος": "Calibri",  # Greek
         "Ciao mondo": "Arial",  # Italian
         "こんにちは世界": "Microsoft Yahei",  # Japanese
         "여보세요 세계": "Malgun Gothic",  # Korean
         "Olá mundo": "Arial",  # Portuguese
         "Здравствулте мир": "Microsoft Yahei",  # Russian
         "Hola mundo": "Arial"  # Spanish
        }

arialbold_brep_string = text_to_brep("hello from pythonocc !", "Arial", Font_FA_Regular, 12., True)

## Then display the string
display.DisplayShape(arialbold_brep_string)
for hello_str in hello:
    rndm_size = random.uniform(10., 16.)
    font = hello[hello_str]
    brep_string = text_to_brep(hello_str, font, Font_FA_Regular, rndm_size, True)
    rndm_extrusion_depth = random.uniform(8., 16.)
    rndm_extrusion_direction = gp_Vec(random.random(), random.random(), random.random())
    extruded_string = make_extrusion(brep_string, rndm_extrusion_depth, rndm_extrusion_direction)
    rndm_pos = gp_Vec(random.random()*100-50, random.random()*100-50, random.random()*100-50)
    rndm_color = Quantity_Color(random.random(), random.random(), random.random(), Quantity_TOC_RGB)
    trs_shp = translate_shp(extruded_string, rndm_pos)
    display.DisplayColoredShape(trs_shp, rndm_color)

display.FitAll()
start_display()