Пример #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
##Copyright 2016 Thomas Paviot ([email protected])
##
##This file is part of pythonOCC.
##
##pythonOCC is free software: you can redistribute it and/or modify
##it under the terms of the GNU Lesser General Public License as published by
##the Free Software Foundation, either version 3 of the License, or
##(at your option) any later version.
##
##pythonOCC is distributed in the hope that it will be useful,
##but WITHOUT ANY WARRANTY; without even the implied warranty of
##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##GNU Lesser General Public License for more details.
##
##You should have received a copy of the GNU Lesser General Public License
##along with pythonOCC.  If not, see <http://www.gnu.org/licenses/>.

from OCC.Display.SimpleGui import init_display
from OCC.Core.Addons import text_to_brep, Font_FontAspect_Bold

display, start_display, add_menu, add_function_to_menu = init_display()

## create a basic string
arialbold_brep_string = text_to_brep("pythonocc rocks !", "Arial",
                                     Font_FontAspect_Bold, 12., True)

## Then display the string
display.DisplayShape(arialbold_brep_string, update=True)

start_display()
Пример #3
0
# register the Respective font
register_font(os.path.join('..', 'assets', 'fonts', 'Respective.ttf'))

# Poetry from Paul Verlaine, Chanson d'Automne
text = """Les sanglots longs
Des violons
De l'automne
Blessent mon cœur
D'une langueur monotone

Tout suffocant
Et blême, quand
Sonne l'heure,
Je me souviens
Des jours anciens
Et je pleure

Et je m'en vais
Au vent mauvais
Qui m'emporte
Deçà, delà,
Pareil à la
Feuille morte."""
## create a basic string
arialbold_brep_string = text_to_brep(text, "Respective", Font_FA_Regular, 12., True)

## Then display the string
display.DisplayColoredShape(arialbold_brep_string, update=True)

start_display()
Пример #4
0
## hello in various languages
hello = {"你好世界": "Microsoft Yahei",  # Chinese
         "Hallo wereld": "Arial",  # Dutch
         "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)
Пример #5
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
from OCC.Core.gp import gp_Trsf
from OCC.Core.TopLoc import TopLoc_Location
from OCC.Core.Addons import text_to_brep, register_font, Font_FA_Regular, Font_FA_Undefined

display, start_display, add_menu, add_function_to_menu = init_display()

# resgister font
register_font("./fonts/Respective.ttf")
register_font("./fonts/METROLOX.ttf")

text = """
Japan
"""

# create a basic string
arialbold_brep_string1 = text_to_brep(text, "Respective", Font_FA_Regular, 10.,
                                      True)

arialbold_brep_string2 = text_to_brep(text, "METOLOX", Font_FA_Regular, 10.,
                                      True)

trf = gp_Trsf()
trf.SetDisplacement(gp_Ax3(), gp_Ax3(gp_Pnt(0, 20, 0), gp_Dir(0, 0, 1)))
arialbold_brep_string2.Move(TopLoc_Location(trf))

# Then display the string
display.DisplayShape(arialbold_brep_string1)
display.DisplayShape(arialbold_brep_string2)
display.FitAll()

start_display()