Esempio n. 1
0
##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.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters

# First context / first parameterized box
p = Parameters()            # Create a parameters set
context1 = ParametricModelingContext(p)     # Create and initialize a parametric context
p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2 = 12,70,12,30,30,30
my_pnt1 = context1.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1", show=True)
my_pnt2 = context1.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2", show=True)
my_box1 = context1.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=True)

# Second context / second parameterized box
p2 = Parameters()
context2 = ParametricModelingContext(p2)
p2.X1, p2.Y1, p2.Z1, p2.X2, p2.Y2, p2.Z2 = 16,80,20,40,25,50
my_pnt3 = context2.basic_operations.MakePointXYZ(p2.X1,p2.Y1,p2.Z1, name="Pnt3", show=True)
my_pnt4 = context2.basic_operations.MakePointXYZ(p2.X2,p2.Y2,p2.Z2, name="Pnt4", show=True)
my_box2 = context2.prim_operations.MakeBoxTwoPnt(my_pnt3,my_pnt4,name="Box2", show=True)

# Display contexts
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()
context1.set_display(display)
context2.set_display(display)
start_display()
Esempio n. 2
0
# A sample that shows how to generate the gear geometry according
# to knowledge

from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters, Rule, Relation, symb
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

from math import pi
from sympy import *

# Initialization
p = Parameters()
my_context = ParametricModelingContext(p)
my_context.set_display(display)
my_context.register_operations(my_context.basic_operations)

# Define the first gear (actually modelized by a cylinder)
# location of the first gear
p.X1 = 0.0001  #sympy have sometimes problems with 0 value
p.Y1 = 0.0
p.Z1 = 0.0
my_pnt1 = my_context.basic_operations.MakePointXYZ(p.X1,
                                                   p.Y1,
                                                   p.Z1,
                                                   name="Pnt1")

# Direction of the gear
p.DX1 = 0.0
p.DY1 = 0.0
def main():
    p = Parameters()                          # Create a parameters set
    # Create and initialize a parametric context
    # not committing changes ( Undo stack ), nor registering all *_operations
    # this speeds things up considerably
    my_context = ParametricModelingContext(p, commit=False, register_all_operations=False)
    my_context.set_display(display)                 # start the graphic display


    # we need to register the operations that are used
    # for concerns of performance, _only_ operations that are registered
    # are associative
    my_context.register_operations(my_context.basic_operations,
                                   my_context.boolean_operations,
                                   my_context.local_operations
    )
    # Create parameters
    p.X1, p.Y1, p.Z1 = 0,0,0
    p.X2, p.Y2, p.Z2 = 30,30,30

    p.X3, p.Y3, p.Z3 = 10,10,-10
    p.X4, p.Y4, p.Z4 = 20,20,40

    p.RADIUS         = 1

    # points box 1
    my_pnt1 = my_context.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1")   # Create the first point box1
    my_pnt2 = my_context.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2")   # Create the second point box1

    # points box 2
    my_pnt3 = my_context.basic_operations.MakePointXYZ(p.X3,p.Y3,p.Z3, name="Pnt3")   # Create the first point box2
    my_pnt4 = my_context.basic_operations.MakePointXYZ(p.X4,p.Y4,p.Z4, name="Pnt4")   # Create the second point box2

    # create boxes
    box1 = my_context.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=False)            # Create the box
    box2 = my_context.prim_operations.MakeBoxTwoPnt(my_pnt3,my_pnt4,name="Box2", show=False)            # Create the box

    # boolean subtract box2 from box1
    booled_box = my_context.boolean_operations.MakeBoolean( box1, box2, 2, name='BooleanBox', show=False)

    # add fillets to the booleaned box
    fillet_box = my_context.local_operations.MakeFilletAll( booled_box, p.RADIUS, name='FilletBox', show=True)



    li1 = make_line(gp_Pnt(-10,0,0), gp_Pnt(10,0,0))
    li2 = make_line(gp_Pnt(0,-10,0), gp_Pnt(0,10,0))
    li1_geom = geomobject_from_topods(my_context, li1)
    li2_geom = geomobject_from_topods(my_context, li2)

    yy1 = TColStd_HSequenceOfTransient()
    yy2 = TColStd_HSequenceOfTransient()
    yy1.Append(li1_geom.GetHandle())
    yy2.Append(li2_geom.GetHandle())

    import ipdb; ipdb.set_trace()
    my_context.boolean_operations.MakeBoolean(li1_geom.GetHandle(),li2_geom.GetHandle(),3, show=True)

    #TColgp_HSequenceOfDir
#    tt= my_context.boolean_operations.MakePartition(yy1.GetHandle(), yy2.GetHandle(),
#                                                    yy1.GetHandle(), yy2.GetHandle(),
#                                                    TopoDS_Shape().ShapeType(),
#                                                    None,None,None,None,None)






#    fb = fillet_box.GetObject()
#
#    labels = []
#
#    _iter = TDF_ChildIterator(fb.GetEntry())
#
#    while _iter.More():
#        labels.append(_iter.Value())
#        _iter.Next()
#
#
#
#    import ipdb; ipdb.set_trace()

    # configuring presentations
    #===========================================================================
    # MISSING "get_presentation" !!!!
    #===========================================================================
    pres1, pres2, pres_fillet = my_context.get_presentation(box1), my_context.get_presentation(box2), my_context.get_presentation(fillet_box)
    pres1.SetTransparency(.8); pres1.SetColor(12)
    pres2.SetTransparency(.8); pres1.SetColor(12)
    pres_fillet.SetColor(1)

    #    for i in range(14,40,5):
    #        print 'changed parameter p.Z2 from %s to %s' % ( i-1, i )
    #        tA = time.time()
    #        p.Z2 = i
    #        print 'updating geometry took:', time.time() - tA

    #    for i in range(10,40,5):
    #        tA = time.time()
    #        p.RADIUS = i/10.
    #        print 'updating geometry took:', time.time() - tA

    start_display()
def main():
    p = Parameters()  # Create a parameters set
    my_context = ParametricModelingContext(
        p, commit=False)  # Create and initialize a parametric context
    my_context.set_display(display)  # start the graphic display

    # we need to register the operations that are used
    # for concerns of performance, _only_ operations that are registered
    # are associative

    my_context.register_operations(
        my_context.basic_operations,
        my_context.boolean_operations,
        my_context.local_operations,
        my_context.curve_operations,
    )

    for ops in dir(my_context):
        try:
            if ops.split('_')[1] == 'operations':
                print '\n\n****** %s ******\n\n' % (ops)
                print 'has the following methods:'
                for i in dir(getattr(my_context, ops)):
                    if not i.islower():
                        print i
        except IndexError:
            pass
    '''
    
    Could be really interesting to make examples here of functions in the GEOM module
    that do not have counter parts in the OCC API
    
    '''

    #===============================================================================
    # SKETCHER INFOS
    # Init Sketcher
    # Create a string beginning by :"Sketcher:"
    # Each command must be separated by ":"
    # "F x y" : Create first point at X & Y
    #
    # To Make Segment
    # "R angle" : Set the direction by angle
    # "D dx dy" : Set the direction by DX & DY
    #
    # "TT x y" : Create by point at X & Y
    # "T dx dy" : Create by point with DX & DY
    # "L length" : Create by direction & Length
    # "IX x" : Create by direction & Intersect. X
    # "IY y" : Create by direction & Intersect. Y
    #
    # To Make Arc
    # "C radius length" : Create by direction, radius and length(in degree)
    #
    # To finish
    # "WW" : Close Wire
    #
    # Create Sketcher
    #===============================================================================
    Cmd = "Sketch:F 0 0:TT 0 100:C 100 180:WW"

    ## Return list of variables value from salome notebook
    ## @ingroup l1_geompy_auxiliary
    def ParseSketcherCommand(command):
        Result = ""
        StringResult = ""
        sections = command.split(":")
        for section in sections:
            parameters = section.split(" ")
            paramIndex = 1
            for parameter in parameters:
                if paramIndex > 1 and parameter.find("'") != -1:
                    parameter = parameter.replace("'", "")
                    if notebook.isVariable(parameter):
                        Result = Result + str(notebook.get(parameter)) + " "
                        pass
                    else:
                        raise RuntimeError, "Variable with name '" + parameter + "' doesn't exist!!!"
                        pass
                    pass
                else:
                    Result = Result + str(parameter) + " "
                    pass
                if paramIndex > 1:
                    StringResult = StringResult + parameter
                    StringResult = StringResult + ":"
                    pass
                paramIndex = paramIndex + 1
                pass
            Result = Result[:len(Result) - 1] + ":"
            pass
        Result = Result[:len(Result) - 1]
        return Result, StringResult

    cmd, params = ParseSketcherCommand(Cmd)
    theWorkingPlane = [0, 0, 0, 0, 0, 1, 1, 0, 0]

    cmd = TCollection_AsciiString(cmd)

    # theWorkingPlane should be a GEOM_Parameter nested in a std::list
    # ---BUG--- NO CONVERTER FOR STD::LIST

    # NOT YET IMPLEMENTED
    #sketcher = my_context.curve_operations.MakeSketcher(cmd, theWorkingPlane) #(string)->GEOM_Shape_ptr

    #    Out[0]: <OCC.TCollection.TCollection_AsciiString; proxy of <Swig Object of type 'TCollection_AsciiString *' at 0x210b2860> >
    #    ipdb> crv.MakeSketcher(_cmd, theWorkingPlane)
    #    *** TypeError: in method 'GEOMImpl_ICurvesOperations_MakeSketcher', argument 3 of type 'std::list< GEOM_Parameter,std::allocator< GEOM_Parameter > >'

    start_display()

    # Create parameters
    p.X1, p.Y1, p.Z1 = 0, 0, 0
    p.X2, p.Y2, p.Z2 = 30, 30, 30

    p.X3, p.Y3, p.Z3 = 10, 10, -10
    p.X4, p.Y4, p.Z4 = 20, 20, 40

    p.RADIUS = 1

    # points box 1
    my_pnt1 = my_context.basic_operations.MakePointXYZ(
        p.X1, p.Y1, p.Z1, name="Pnt1")  # Create the first point box1
    my_pnt2 = my_context.basic_operations.MakePointXYZ(
        p.X2, p.Y2, p.Z2, name="Pnt2")  # Create the second point box1

    # points box 2
    my_pnt3 = my_context.basic_operations.MakePointXYZ(
        p.X3, p.Y3, p.Z3, name="Pnt3")  # Create the first point box2
    my_pnt4 = my_context.basic_operations.MakePointXYZ(
        p.X4, p.Y4, p.Z4, name="Pnt4")  # Create the second point box2

    # create boxes
    box1 = my_context.prim_operations.MakeBoxTwoPnt(
        my_pnt1, my_pnt2, name="Box1", show=True)  # Create the box
    box2 = my_context.prim_operations.MakeBoxTwoPnt(
        my_pnt3, my_pnt4, name="Box2", show=True)  # Create the box

    # boolean subtract box2 from box1
    booled_box = my_context.boolean_operations.MakeBoolean(box1,
                                                           box2,
                                                           2,
                                                           name='BooleanBox',
                                                           show=False)

    # add fillets to the booleaned box
    fillet_box = my_context.local_operations.MakeFilletAll(booled_box,
                                                           p.RADIUS,
                                                           name='FilletBox',
                                                           show=True)

    # configuring presentations
    #===========================================================================
    # MISSING THE "get_presentation" METHOD Nooooooooooooooooooooooo!
    #===========================================================================
    #    pres1, pres2, pres_fillet = my_context.get_presentation(box1), my_context.get_presentation(box2), my_context.get_presentation(fillet_box)
    #    pres1.SetTransparency(.8); pres1.SetColor(12)
    #    pres2.SetTransparency(.8); pres1.SetColor(12)
    #    pres_fillet.SetColor(1)

    for i in range(14, 40, 5):
        print 'changed parameter p.Z2 from %s to %s' % (i - 1, i)
        tA = time.time()
        p.Z2 = i
        print 'updating geometry took:', time.time() - tA

    for i in range(10, 40, 5):
        tA = time.time()
        p.RADIUS = i / 10.
        print 'updating geometry took:', time.time() - tA

    start_display()
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters
from OCC.PAF.TopologyParameterizer import geomobject_from_topods
from OCC.Display.SimpleGui import init_display
from OCC.Utils.Construct import *
from OCC.Utils.Common import *

display, start_display, add_menu, add_function_to_menu = init_display()

p = Parameters()                          # Create a parameters set
# Create and initialize a parametric context
# not committing changes ( Undo stack ), nor registering all *_operations
# this speeds things up considerably
my_context = ParametricModelingContext(p, commit=False, register_all_operations=False)
my_context.set_display(display)                 # start the graphic display


# we need to register the operations that are used
# for concerns of performance, _only_ operations that are registered
# are associative
my_context.register_operations(my_context.basic_operations,
                               my_context.boolean_operations,
                               my_context.local_operations
)
# Create parameters
p.X1, p.Y1, p.Z1 = 0,0,0
p.X2, p.Y2, p.Z2 = 30,30,30

p.X3, p.Y3, p.Z3 = 10,10,-10
p.X4, p.Y4, p.Z4 = 20,20,40
    anImport = my_context.myEngine.AddObject(my_context.docId, GEOM_IMPORT).GetObject()
    _import_driver = GEOMImpl_ImportDriver()
    aFunc = anImport.AddFunction(_import_driver.GetID(), IMPORT_SHAPE).GetObject()
    aFunc.SetValue(topods_shape)
    return anImport

 
if __name__=='__main__':
    from OCC.PAF.Context import ParametricModelingContext
    from OCC.PAF.Parametric import Parameters
    p = Parameters()            # Create a parameters set
    my_context = ParametricModelingContext(p)     # Create and initialize a parametric context
    # Create a box
    from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox
    shape = BRepPrimAPI_MakeBox(10,20,30).Shape()
    # Move each vertex to the PAF
    t = Topo(shape)
    for vertex in t.vertices():
        vertex_to_paf(p,vertex)
    # Move each edge to the PAF. Uncomment the 2 lines below and you will see a parameterized box (only vertices
    # and edges)
    for edge in t.edges():
        edge_to_paf(p,edge)
    
    # Display
    from OCC.Display.SimpleGui import init_display
    display, start_display, add_menu, add_function_to_menu = init_display()
    my_context.set_display(display)
    start_display()
    
Esempio n. 7
0
from OCC.PAF.Parametric import Parameters
# import SMESH
from OCC.SMESH import *
from OCC.StdMeshers import *
from OCC.MeshVS import *
# import display
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

#
# Init PAF
#
p = Parameters()  # Create a parameters set
my_context = ParametricModelingContext(
    p)  # Create and initialize a parametric context
my_context.set_display(display)  # start display#
my_context.register_operations(my_context.basic_operations,
                               my_context.prim_operations,
                               my_context.local_operations)
#
# Set Wireframe mode
#
#my_context.display.SetModeWireFrame()

#
# Create parameters and geometry
#

# First create the box
p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12, 70, 12, 30, 30, 30, 4  # Create 7 parameters
my_pnt1 = my_context.basic_operations.MakePointXYZ(
def main():
    p = Parameters()                          # Create a parameters set
    my_context = ParametricModelingContext(p, commit=False)     # Create and initialize a parametric context
    my_context.set_display(display)                 # start the graphic display
    
    
    # we need to register the operations that are used
    # for concerns of performance, _only_ operations that are registered
    # are associative 

    my_context.register_operations(my_context.basic_operations,
                                   my_context.boolean_operations,
                                   my_context.local_operations,
                                   my_context.curve_operations,
                                   )

    for ops in dir(my_context):
        try:
            if ops.split('_')[1] == 'operations':
                print '\n\n****** %s ******\n\n' % ( ops )
                print 'has the following methods:'
                for i in dir(getattr(my_context, ops)):
                    if not i.islower():
                        print i
        except IndexError:
            pass 

    '''
    
    Could be really interesting to make examples here of functions in the GEOM module
    that do not have counter parts in the OCC API
    
    '''

    
    #===============================================================================
    # SKETCHER INFOS
    # Init Sketcher
    # Create a string beginning by :"Sketcher:"
    # Each command must be separated by ":"
    # "F x y" : Create first point at X & Y
    # 
    # To Make Segment
    # "R angle" : Set the direction by angle
    # "D dx dy" : Set the direction by DX & DY
    # 
    # "TT x y" : Create by point at X & Y
    # "T dx dy" : Create by point with DX & DY
    # "L length" : Create by direction & Length
    # "IX x" : Create by direction & Intersect. X
    # "IY y" : Create by direction & Intersect. Y
    # 
    # To Make Arc
    # "C radius length" : Create by direction, radius and length(in degree)
    # 
    # To finish
    # "WW" : Close Wire
    # 
    # Create Sketcher
    #===============================================================================
    Cmd = "Sketch:F 0 0:TT 0 100:C 100 180:WW"
    #import ipdb; ipdb.set_trace()
    
    
    ## Return list of variables value from salome notebook
    ## @ingroup l1_geompy_auxiliary    
    def ParseSketcherCommand(command):
        Result = ""
        StringResult = ""
        sections = command.split(":")
        for section in sections:
            parameters = section.split(" ")
            paramIndex = 1
            for parameter in parameters:
                if paramIndex > 1 and parameter.find("'") != -1:
                    parameter = parameter.replace("'","")
                    if notebook.isVariable(parameter):
                        Result = Result + str(notebook.get(parameter)) + " "
                        pass
                    else:
                        raise RuntimeError, "Variable with name '" + parameter + "' doesn't exist!!!"
                        pass
                    pass
                else:
                    Result = Result + str(parameter) + " "
                    pass
                if paramIndex > 1:
                    StringResult = StringResult + parameter
                    StringResult = StringResult + ":"
                    pass
                paramIndex = paramIndex + 1
                pass
            Result = Result[:len(Result)-1] + ":"
            pass
        Result = Result[:len(Result)-1]
        return Result, StringResult
    
    
    cmd, params = ParseSketcherCommand(Cmd)
    theWorkingPlane = [0,0,0, 0,0,1, 1,0,0]
    

    cmd = TCollection_AsciiString(cmd)
    
    # theWorkingPlane should be a GEOM_Parameter nested in a std::list
    # ---BUG--- NO CONVERTER FOR STD::LIST

    # NOT YET IMPLEMENTED
    #sketcher = my_context.curve_operations.MakeSketcher(cmd, theWorkingPlane) #(string)->GEOM_Shape_ptr
    
    
    
#    Out[0]: <OCC.TCollection.TCollection_AsciiString; proxy of <Swig Object of type 'TCollection_AsciiString *' at 0x210b2860> >
#    ipdb> crv.MakeSketcher(_cmd, theWorkingPlane)
#    *** TypeError: in method 'GEOMImpl_ICurvesOperations_MakeSketcher', argument 3 of type 'std::list< GEOM_Parameter,std::allocator< GEOM_Parameter > >'
    


    start_display()

# Create parameters
    p.X1, p.Y1, p.Z1 = 0,0,0
    p.X2, p.Y2, p.Z2 = 30,30,30
    
    p.X3, p.Y3, p.Z3 = 10,10,-10
    p.X4, p.Y4, p.Z4 = 20,20,40
    
    p.RADIUS         = 1
        
    # points box 1                              
    my_pnt1 = my_context.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1")   # Create the first point box1
    my_pnt2 = my_context.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2")   # Create the second point box1
    
    # points box 2
    my_pnt3 = my_context.basic_operations.MakePointXYZ(p.X3,p.Y3,p.Z3, name="Pnt3")   # Create the first point box2
    my_pnt4 = my_context.basic_operations.MakePointXYZ(p.X4,p.Y4,p.Z4, name="Pnt4")   # Create the second point box2
    
    # create boxes
    box1 = my_context.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=True)            # Create the box
    box2 = my_context.prim_operations.MakeBoxTwoPnt(my_pnt3,my_pnt4,name="Box2", show=True)            # Create the box
    
    # boolean subtract box2 from box1 
    booled_box = my_context.boolean_operations.MakeBoolean( box1, box2, 2, name='BooleanBox', show=False)
    
    # add fillets to the booleaned box
    fillet_box = my_context.local_operations.MakeFilletAll( booled_box, p.RADIUS, name='FilletBox', show=True)
    
    # configuring presentations
    #===========================================================================
    # MISSING THE "get_presentation" METHOD Nooooooooooooooooooooooo!
    #===========================================================================
#    pres1, pres2, pres_fillet = my_context.get_presentation(box1), my_context.get_presentation(box2), my_context.get_presentation(fillet_box)
#    pres1.SetTransparency(.8); pres1.SetColor(12) 
#    pres2.SetTransparency(.8); pres1.SetColor(12)
#    pres_fillet.SetColor(1)
    
    for i in range(14,40,5):
        print 'changed parameter p.Z2 from %s to %s' % ( i-1, i )
        tA = time.time() 
        p.Z2 = i
        print 'updating geometry took:', time.time() - tA
    
    for i in range(10,40,5):
        tA = time.time() 
        p.RADIUS = i/10.
        print 'updating geometry took:', time.time() - tA
    
    start_display()
Esempio n. 9
0
                                                 my_pnt2,
                                                 name="Box1",
                                                 show=True)

# Second context / second parameterized box
p2 = Parameters()
context2 = ParametricModelingContext(p2)
p2.X1, p2.Y1, p2.Z1, p2.X2, p2.Y2, p2.Z2 = 16, 80, 20, 40, 25, 50
my_pnt3 = context2.basic_operations.MakePointXYZ(p2.X1,
                                                 p2.Y1,
                                                 p2.Z1,
                                                 name="Pnt3",
                                                 show=True)
my_pnt4 = context2.basic_operations.MakePointXYZ(p2.X2,
                                                 p2.Y2,
                                                 p2.Z2,
                                                 name="Pnt4",
                                                 show=True)
my_box2 = context2.prim_operations.MakeBoxTwoPnt(my_pnt3,
                                                 my_pnt4,
                                                 name="Box2",
                                                 show=True)

# Display contexts
from OCC.Display.SimpleGui import init_display

display, start_display, add_menu, add_function_to_menu = init_display()
context1.set_display(display)
context2.set_display(display)
start_display()
def main():
    p = Parameters()  # Create a parameters set
    # Create and initialize a parametric context
    # not committing changes ( Undo stack ), nor registering all *_operations
    # this speeds things up considerably
    my_context = ParametricModelingContext(p,
                                           commit=False,
                                           register_all_operations=False)
    my_context.set_display(display)  # start the graphic display

    # we need to register the operations that are used
    # for concerns of performance, _only_ operations that are registered
    # are associative
    my_context.register_operations(my_context.basic_operations,
                                   my_context.boolean_operations,
                                   my_context.local_operations)
    # Create parameters
    p.X1, p.Y1, p.Z1 = 0, 0, 0
    p.X2, p.Y2, p.Z2 = 30, 30, 30

    p.X3, p.Y3, p.Z3 = 10, 10, -10
    p.X4, p.Y4, p.Z4 = 20, 20, 40

    p.RADIUS = 1

    # points box 1
    my_pnt1 = my_context.basic_operations.MakePointXYZ(
        p.X1, p.Y1, p.Z1, name="Pnt1")  # Create the first point box1
    my_pnt2 = my_context.basic_operations.MakePointXYZ(
        p.X2, p.Y2, p.Z2, name="Pnt2")  # Create the second point box1

    # points box 2
    my_pnt3 = my_context.basic_operations.MakePointXYZ(
        p.X3, p.Y3, p.Z3, name="Pnt3")  # Create the first point box2
    my_pnt4 = my_context.basic_operations.MakePointXYZ(
        p.X4, p.Y4, p.Z4, name="Pnt4")  # Create the second point box2

    # create boxes
    box1 = my_context.prim_operations.MakeBoxTwoPnt(
        my_pnt1, my_pnt2, name="Box1", show=False)  # Create the box
    box2 = my_context.prim_operations.MakeBoxTwoPnt(
        my_pnt3, my_pnt4, name="Box2", show=False)  # Create the box

    # boolean subtract box2 from box1
    booled_box = my_context.boolean_operations.MakeBoolean(box1,
                                                           box2,
                                                           2,
                                                           name='BooleanBox',
                                                           show=False)

    # add fillets to the booleaned box
    fillet_box = my_context.local_operations.MakeFilletAll(booled_box,
                                                           p.RADIUS,
                                                           name='FilletBox',
                                                           show=True)

    li1 = make_line(gp_Pnt(-10, 0, 0), gp_Pnt(10, 0, 0))
    li2 = make_line(gp_Pnt(0, -10, 0), gp_Pnt(0, 10, 0))
    li1_geom = geomobject_from_topods(my_context, li1)
    li2_geom = geomobject_from_topods(my_context, li2)

    yy1 = TColStd_HSequenceOfTransient()
    yy2 = TColStd_HSequenceOfTransient()
    yy1.Append(li1_geom.GetHandle())
    yy2.Append(li2_geom.GetHandle())

    import ipdb
    ipdb.set_trace()
    my_context.boolean_operations.MakeBoolean(li1_geom.GetHandle(),
                                              li2_geom.GetHandle(),
                                              3,
                                              show=True)

    #TColgp_HSequenceOfDir
    #    tt= my_context.boolean_operations.MakePartition(yy1.GetHandle(), yy2.GetHandle(),
    #                                                    yy1.GetHandle(), yy2.GetHandle(),
    #                                                    TopoDS_Shape().ShapeType(),
    #                                                    None,None,None,None,None)

    #    fb = fillet_box.GetObject()
    #
    #    labels = []
    #
    #    _iter = TDF_ChildIterator(fb.GetEntry())
    #
    #    while _iter.More():
    #        labels.append(_iter.Value())
    #        _iter.Next()
    #
    #
    #
    #    import ipdb; ipdb.set_trace()

    # configuring presentations
    #===========================================================================
    # MISSING "get_presentation" !!!!
    #===========================================================================
    pres1, pres2, pres_fillet = my_context.get_presentation(
        box1), my_context.get_presentation(box2), my_context.get_presentation(
            fillet_box)
    pres1.SetTransparency(.8)
    pres1.SetColor(12)
    pres2.SetTransparency(.8)
    pres1.SetColor(12)
    pres_fillet.SetColor(1)

    #    for i in range(14,40,5):
    #        print 'changed parameter p.Z2 from %s to %s' % ( i-1, i )
    #        tA = time.time()
    #        p.Z2 = i
    #        print 'updating geometry took:', time.time() - tA

    #    for i in range(10,40,5):
    #        tA = time.time()
    #        p.RADIUS = i/10.
    #        print 'updating geometry took:', time.time() - tA

    start_display()
Esempio n. 11
0
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

p = Parameters()            # Create a parameters set
my_context = ParametricModelingContext(p)     # Create and initialize a parametric context
my_context.set_display(display)   # start display#
my_context.register_operations(my_context.prim_operations)

p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12,70,12,30,30,30,4                                   # Create 7 parameters

my_pnt1 = my_context.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1", show=True)   # Create the first point
my_pnt2 = my_context.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2", show=True)   # Create the second point
my_box = my_context.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=True)            # Create the box

for i in range(14,100):
    print 'changed parameter p.Z2 from %s to %s' % ( i-1, i ) 
    p.Z2 = i

start_display()