Beispiel #1
0
 def execute(self):
     ax = gp.gp_Ax2(gp.gp_Pnt(*self.position),
                     gp.gp_Dir(*self.z_axis),
                     gp.gp_Dir(*self.x_axis))
     m_box = BRepPrimAPI.BRepPrimAPI_MakeBox(ax, *self.dims)
     self.update_naming(m_box)
     return m_box.Shape()
Beispiel #2
0
def make_box(position, direction, x_axis, dx, dy, dz):
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(gp.gp_Pnt(-dx/2., -dy/2., 0.0),
                                          dx, dy, -dz)
    ax = gp.gp_Ax2(gp.gp_Pnt(*position), 
                   gp.gp_Dir(*direction),
                   gp.gp_Dir(*x_axis))
    ax3 = gp.gp_Ax3()
    trans = gp.gp_Trsf()
    trans.SetTransformation(gp.gp_Ax3(ax), ax3)
    t_box = BRepBuilderAPI.BRepBuilderAPI_Transform(box.Shape(), trans)
    return toshape(t_box)
Beispiel #3
0
def doc_demo_():
    from doc import doc_ctrl
    from OCC import BRepPrimAPI
    quader = BRepPrimAPI.BRepPrimAPI_MakeBox(3, 4, 5).Solid()
    kugel = BRepPrimAPI.BRepPrimAPI_MakeSphere(2).Solid()
    with doc_ctrl.open_command():
        doc_ctrl.add(quader)
        doc_ctrl.set_color(quader, [0, 1, 0])
    with doc_ctrl.open_command():
        doc_ctrl.add(kugel)
        doc_ctrl.set_color(kugel, [1, 0, 0])
Beispiel #4
0
def export_step():
    """
    Exports a TopoDS_Shape to a STEP file.
    """
    test_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(100., 100., 100.).Shape()
    # export to AP203 schema
    ap203_exporter = StepExporter('./models_out/box_203.stp', schema='AP203')
    ap203_exporter.add_shape(test_shape)
    ap203_exporter.write_file()
    # export AP214 schema
    ap214cd_exporter = StepExporter('./models_out/box_214CD.stp',
                                    schema='AP214CD')
    ap214cd_exporter.add_shape(test_shape)
    ap214cd_exporter.write_file()
Beispiel #5
0
def demo_():
    from math import pi, sin, cos
    from gui import viewer_3d
    from OCC import BRepPrimAPI

    quader = BRepPrimAPI.BRepPrimAPI_MakeBox(3, 4, 5).Solid()
    viewer_3d.display_shape(quader)
    viewer_3d.view_mode = 'shaded'
    viewer_3d.zoom = 1
    N = 40
    for i in range(N):
        phi = i / N * pi + pi / 6
        viewer_3d.eye = [sin(phi), cos(phi), phi / 5]
        viewer_3d.zoom *= 1.05
Beispiel #6
0
    def InitDoc(self):
        h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())
        l_Colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())

        shape_tool = h_shape_tool.GetObject()
        colors = l_Colors.GetObject()

        self.shape_tool = shape_tool

        top_label = shape_tool.NewShape(
        )  #this is the "root" label for the assembly
        self.top_label = top_label

        #Add some shapes
        box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
        box_label = shape_tool.AddShape(box, False)

        cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
        cyl_label = shape_tool.AddShape(cyl, False)

        #Add components as references to our shape
        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(100, 100, 100))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(-100, -100, -100))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(10, 10, 10))
        loc = TopLoc.TopLoc_Location(tr)
        cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

        #Add some colors
        red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
        green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
        blue = Quantity.Quantity_Color(Quantity.Quantity_NOC_BLUE1)
        colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
        colors.SetColor(box_label, blue, XCAFDoc.XCAFDoc_ColorGen)
        colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

        self.box_label = box_label
        self.cyl_label = cyl_label
        self.box_comp1 = box_comp1
        self.box_comp2 = box_comp2
        self.cyl_comp = cyl_comp
Beispiel #7
0
def make_ellipsoid_mirror(f1, f2, major_axis, 
                          x_bounds, y_bounds, z_bounds,
                          centre, direction, x_axis):
    ellipsoid = make_ellipsoid(f1, f2, major_axis)
    P1 = gp.gp_Pnt(x_bounds[0], y_bounds[0], z_bounds[0])
    P2 = gp.gp_Pnt(x_bounds[1], y_bounds[1], z_bounds[1])
    block = BRepPrimAPI.BRepPrimAPI_MakeBox(P1, P2)
    
    ##comment these out to reinstate the cut
    #t_block = position_shape(toshape(block), centre, direction, x_axis)
    #t_ellipse = position_shape(ellipsoid, centre, direction, x_axis)
    #return make_compound([toshape(block), ellipsoid])
    
    #cut = toshape(BRepAlgoAPI.BRepAlgoAPI_Cut(toshape(block), ellipsoid))
    cut = make_compound([toshape(block), ellipsoid])
    return position_shape(cut, centre, direction, x_axis)
Beispiel #8
0
    def FillTestDoc(doc):
        h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().shapetool(doc.Main())
        h_Colors = XCAFDoc.XCAFDoc_DocumentTool().colortool(doc.Main())

        shape_tool = h_shape_tool.GetObject()
        colors = h_Colors.GetObject()

        top_label = shape_tool.NewShape(
        )  #this is the "root" label for the assembly

        print "top entry", Label(TDF_Label=top_label).entry

        box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
        box_label = shape_tool.AddShape(box, False)

        cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
        cyl_label = shape_tool.AddShape(cyl, False)
        #
        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(100, 100, 100))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(200, 200, 200))
        loc = TopLoc.TopLoc_Location(tr)
        box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

        tr = gp.gp_Trsf()
        tr.SetTranslation(gp.gp_Vec(150, 200, 100))
        loc = TopLoc.TopLoc_Location(tr)
        cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

        red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
        green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
        colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
        colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)
def box_shape():
    r"""Box shape for testing"""
    return BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
Beispiel #10
0
def get_shape():
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30)
    shape = box.Shape()
    return shape
Beispiel #11
0
from OCC import BRepPrimAPI
from OCC.gp import gp_Pnt, gp_Ax2, gp_Vec, gp_Trsf, gp_Ax3, gp_Dir
from OCC import TopoDS, BRep, STEPControl, BRepBuilderAPI

app = wx.App()

frame = wx.Frame(None, -1, "OCC frame", size=(600, 700))
canvas = GraphicsCanva3D(frame)
frame.Show()
wx.SafeYield()

canvas.Init3dViewer()
viewer = canvas._3dDisplay
print viewer

box = BRepPrimAPI.BRepPrimAPI_MakeBox(20, 30, 40)

ax = gp_Ax2()
ax.Translate(gp_Vec(50, 50, 50))

cyl_len = 40
radius = 10
angle = pi * 1.5

cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(radius, cyl_len)

ax = gp_Ax3()
ax.SetLocation(gp_Pnt(50, 60, 70))
ax.SetDirection(gp_Dir(gp_Vec(1, 1, 1)))
trans = gp_Trsf()
trans.SetTransformation(ax)
Beispiel #12
0
from OCC.Display.SimpleGui import *
from OCC import BRepPrimAPI
from OCC import Voxel

display, start_display, add_menu, add_function_to_menu = init_display()
box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 10, 20)
box_voxel = Voxel.Voxel_ColorDS()
v = Voxel.Voxel_FastConverter(box.Shape(), box_voxel, 0.1, 20, 20, 20)
progress = 1
v.Convert(progress)
v.FillInVolume(1)
visu = Voxel.Voxel_Prs()
visu.SetBoolVoxels(box_voxel)
visu.SetDisplayMode(0)
visu.SetColor(2)
visu.SetPointSize(1)
visu.SetQuadrangleSize(100)
visu.SetTransparency(0)
#display.DisplayShape(box.Shape())
display.Context.Display(visu.GetHandle(), True)
start_display()
Beispiel #13
0
#
doc = h_doc.GetObject()
h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())
l_Colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())

shape_tool = h_shape_tool.GetObject()
colors = l_Colors.GetObject()

top_label = shape_tool.NewShape() #this is the "root" label for the assembly

print "Is Assembly", shape_tool.IsAssembly(top_label) #not yet, 'cos it's empty

#
#Add some shapes
#
box = BRepPrimAPI.BRepPrimAPI_MakeBox(10,20,30).Shape()
box_label = shape_tool.AddShape(box, False)

cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25,50).Shape()
cyl_label = shape_tool.AddShape(cyl, False)

#
#Add components as references to our shape
#
tr = gp.gp_Trsf()
tr.SetTranslation(gp.gp_Vec(100,100,100))
loc = TopLoc.TopLoc_Location(tr)
box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

tr = gp.gp_Trsf()
tr.SetTranslation(gp.gp_Vec(200,200,200))
def step_export_layers_and_colors(event=None):
    r"""
    demo showing how to export step files with layers & colors.
    adapted from Bryan's names_shape_demo
    """

    # Create the TDocStd document
    h_doc = TDocStd.Handle_TDocStd_Document()
    print("Empty Doc?", h_doc.IsNull())

    # Create the application
    app = XCAFApp.GetApplication().GetObject()
    app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"), h_doc)

    # Get root assembly
    doc = h_doc.GetObject()
    h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())
    l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())
    l_layers = XCAFDoc.XCAFDoc_DocumentTool().LayerTool(doc.Main())

    shape_tool = h_shape_tool.GetObject()
    colors = l_colors.GetObject()
    layers = l_layers.GetObject()

    top_label = shape_tool.NewShape(
    )  # this is the "root" label for the assembly

    print("Is Assembly",
          shape_tool.IsAssembly(top_label))  # not yet, 'cos it's empty)

    # Add some shapes
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
    box_label = shape_tool.AddShape(box, False)

    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
    cyl_label = shape_tool.AddShape(cyl, False)

    # Add components as references to our shape
    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(100, 100, 100))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(200, 200, 200))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(150, 200, 100))
    loc = TopLoc.TopLoc_Location(tr)
    cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

    print("Is Assembly", shape_tool.IsAssembly(top_label))  # it is now...

    # Add some colors
    red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
    green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
    colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
    colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

    # Set the box on the 'box' layer, the cylinder on the 'cylinder' layer
    layers.SetLayer(box_comp1, TCollection_ExtendedString('BOX'))
    layers.SetLayer(cyl_comp, TCollection_ExtendedString('CYLINDER'))

    # Set up AIS Presentation stuff (I don't understand this, but it kinda works)
    aisView = TPrsStd.TPrsStd_AISViewer().New(top_label,
                                              display.Context.GetHandle())
    aisPres = TPrsStd.TPrsStd_AISPresentation().Set(
        top_label,
        XCAFPrs.XCAFPrs_Driver().GetID())
    aisPres.GetObject().Display(True)
    display.FitAll()

    # write the stuff to STEP, with layers & colors
    work_session = XSControl_WorkSession()
    writer = STEPCAFControl_Writer(work_session.GetHandle(), False)
    writer.Transfer(h_doc, STEPControl_AsIs)
    pth = '.'
    print('writing STEP file')
    status = writer.Write(os.path.join(pth, 'step_layers_colors.step'))
    print('status:', status)
Beispiel #15
0
from OCC import TopExp, BRepPrimAPI, TopAbs, TopoDS

box = BRepPrimAPI.BRepPrimAPI_MakeBox(10., 20., 30.)
ex = TopExp.TopExp_Explorer(box.Shape(), TopAbs.TopAbs_EDGE)

results = []

while ex.More():
    shape = TopoDS.TopoDS().Edge(ex.Current())
    print "is null?", bool(shape.IsNull())
    results.append(shape)
    ex.Next()
ex.ReInit()

for edge in results:
    print "null now?", bool(edge.IsNull())
Beispiel #16
0
from OCC import BRepAlgoAPI, BRepPrimAPI, gp
from OCC import TopoDS
from lib.subshapes import subshapes

cube = BRepPrimAPI.BRepPrimAPI_MakeBox(gp.gp_Pnt(-10000, -10000, -10000),
                                       20000, 20000, 20000).Solid()


def copy(shape):
    """Return a copy of the shape that does not reference the original shape"""
    new = BRepAlgoAPI.BRepAlgoAPI_Common(shape, cube).Shape()
    comp = TopoDS.TopoDS_Compound(new)
    return subshapes(comp, shape.ShapeType())[0]
Beispiel #17
0
#!/usr/bin/env python
# coding: utf-8
r"""Exporting a single shape to BREP"""

import logging

from OCC import BRepPrimAPI

from OCCDataExchange.brep import BrepExporter
from OCCDataExchange.utils import path_from_file

logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s :: %(levelname)6s :: %(module)20s :: %(lineno)3d :: %(message)s'
)

# First create a simple shape to export
box_shape = BRepPrimAPI.BRepPrimAPI_MakeBox(50, 50, 50).Shape()

# Export to BREP
filename = path_from_file(__file__, "./models_out/box.brep")
step_exporter = BrepExporter(filename)
step_exporter.set_shape(box_shape)
step_exporter.write_file()
Beispiel #18
0
 def SetBoxSize(self, size):
     box = BRepPrimAPI.BRepPrimAPI_MakeBox(1. * size, 2. * size,
                                           3. * size).Shape()
     self.shape_tool.SetShape(self.box_label, box)
     self.shape_tool.UpdateAssembly(self.top_label)
Beispiel #19
0
 def CreateShape(self):
     p1 = gp_Pnt(-self.rbox[0], -self.rbox[1], -self.rbox[2])
     p2 = gp_Pnt(self.rbox[0], self.rbox[1], self.rbox[2])
     self.occ_shape = occprim.BRepPrimAPI_MakeBox(p1, p2).Shape()
     self.OrientShape()
from OCC.Display.SimpleGui import *
display, start_display, add_menu, add_function_to_menu = init_display()

app = AppStd.AppStd_Application()

h_doc = TDocStd.Handle_TDocStd_Document()
schema = TCollection.TCollection_ExtendedString("MyFormat")
app.NewDocument(schema, h_doc)

doc = h_doc.GetObject()

root = doc.Main()

ts = TDF.TDF_TagSource()

box = BRepPrimAPI.BRepPrimAPI_MakeBox(20.0, 20.0, 20.0).Shape()

box_label = ts.NewChild(root)
ns_builder = TNaming.TNaming_Builder(box_label)
ns_builder.Generated(box)

topo = Topo(box)

##
##Name all the subshape we *might* want to refer to later
##
for edge in topo.edges():
    sub_label = ts.NewChild(box_label)
    ns_builder = TNaming.TNaming_Builder(sub_label)
    ns_builder.Generated(edge)
def assembly(event=None):
    # Create the TDocStd document
    h_doc = TDocStd.Handle_TDocStd_Document()
    print("Empty Doc?", h_doc.IsNull())

    # Create the application
    app = XCAFApp.GetApplication().GetObject()
    app.NewDocument(TCollection.TCollection_ExtendedString("MDTV-CAF"), h_doc)

    # Get root assembly
    doc = h_doc.GetObject()
    h_shape_tool = XCAFDoc.XCAFDoc_DocumentTool().ShapeTool(doc.Main())
    l_colors = XCAFDoc.XCAFDoc_DocumentTool().ColorTool(doc.Main())

    shape_tool = h_shape_tool.GetObject()
    colors = l_colors.GetObject()

    top_label = shape_tool.NewShape(
    )  #this is the "root" label for the assembly

    print("Is Assembly",
          shape_tool.IsAssembly(top_label))  # not yet, 'cos it's empty

    # Add some shapes
    box = BRepPrimAPI.BRepPrimAPI_MakeBox(10, 20, 30).Shape()
    box_label = shape_tool.AddShape(box, False)

    cyl = BRepPrimAPI.BRepPrimAPI_MakeCylinder(25, 50).Shape()
    cyl_label = shape_tool.AddShape(cyl, False)

    # Add components as references to our shape
    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(100, 100, 100))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp1 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(200, 200, 200))
    loc = TopLoc.TopLoc_Location(tr)
    box_comp2 = shape_tool.AddComponent(top_label, box_label, loc)

    tr = gp.gp_Trsf()
    tr.SetTranslation(gp.gp_Vec(150, 200, 100))
    loc = TopLoc.TopLoc_Location(tr)
    cyl_comp = shape_tool.AddComponent(top_label, cyl_label, loc)

    print("Is Assembly", shape_tool.IsAssembly(top_label))  # it is now...

    # Add some colors
    red = Quantity.Quantity_Color(Quantity.Quantity_NOC_RED)
    green = Quantity.Quantity_Color(Quantity.Quantity_NOC_GREEN)
    colors.SetColor(cyl_comp, red, XCAFDoc.XCAFDoc_ColorGen)
    colors.SetColor(box_comp2, green, XCAFDoc.XCAFDoc_ColorGen)

    # Set up AIS Presentation stuff (I don't understand this, but it kinda works)
    ais_view = TPrsStd.TPrsStd_AISViewer().New(top_label,
                                               display.Context.GetHandle())
    ais_pres = TPrsStd.TPrsStd_AISPresentation().Set(
        top_label,
        XCAFPrs.XCAFPrs_Driver().GetID())
    ais_pres.GetObject().Display(True)
    display.FitAll()
    print "end iteration"


app = AppStd.AppStd_Application()

h_doc = TDocStd.Handle_TDocStd_Document()
schema = TCollection.TCollection_ExtendedString("MyFormat")
app.NewDocument(schema, h_doc)

doc = h_doc.GetObject()

root = doc.Main()

ts = TDF.TDF_TagSource()

box = BRepPrimAPI.BRepPrimAPI_MakeBox(20.0, 20.0, 20.0).Shape()

box_label = ts.NewChild(root)
ns_builder = TNaming.TNaming_Builder(box_label)
ns_builder.Generated(box)

topo = Topo(box)

##
##Name all the subshape we *might* want to refer to later
##
for edge in topo.edges():
    sub_label = ts.NewChild(box_label)
    ns_builder = TNaming.TNaming_Builder(sub_label)
    ns_builder.Generated(edge)