Example #1
0
    def test_without_viewer():
        # create parameters
        p = Parameters()
        # create parametric modeling context
        c = ParametricModelingContext(p)

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

        box_shape = c.get_shape(my_box)
        print box_shape
Example #2
0
    def test_without_viewer():
        # create parameters
        p = Parameters()
        # create parametric modeling context
        c = ParametricModelingContext(p)
   
        p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12,70,12,30,30,30,4  
        my_pnt1 = c.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1", show=True)
        my_pnt2 = c.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2", show=True)   # Create the second point
        my_box = c.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2, name="Box1", show=True)            # Create the box

        box_shape = c.get_shape(my_box)
        print box_shape
Example #3
0
 def test_with_viewer_after():
     # create parameters
     p = Parameters()
     c = ParametricModelingContext(p)
     # create simple box
     p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12,70,12,30,30,30,4  
     my_pnt1 = c.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1", show=True)
     my_pnt2 = c.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2", show=True)   # Create the second point
     my_box = c.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=True)
     #Init display after geometry is created
     from OCC.Display.SimpleGui import init_display
     display, start_display, add_menu, add_function_to_menu = init_display()
     c.set_display(display)
     start_display()
Example #4
0
 def test_with_viewer_after():
     # create parameters
     p = Parameters()
     c = ParametricModelingContext(p)
     # create simple box
     p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12,70,12,30,30,30,4  
     my_pnt1 = c.basic_operations.MakePointXYZ(p.X1,p.Y1,p.Z1, name="Pnt1", show=True)
     my_pnt2 = c.basic_operations.MakePointXYZ(p.X2,p.Y2,p.Z2, name="Pnt2", show=True)   # Create the second point
     my_box = c.prim_operations.MakeBoxTwoPnt(my_pnt1,my_pnt2,name="Box1", show=True)
     #Init display after geometry is created
     from OCC.Display.SimpleGui import init_display
     display, start_display, add_menu, add_function_to_menu = init_display()
     c.set_display(display)
     start_display()
Example #5
0
 def test_with_viewer():
      # init viewer
     from OCC.Display.SimpleGui import init_display
     display, start_display, add_menu, add_function_to_menu = init_display()
     # create parameters
     p = Parameters()
     # create parametric modeling context
     c = ParametricModelingContext(p)
     # set graphics
     c.set_display(display)
     # create simple box
     p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12, 70, 12, 30, 30, 30, 4  
     my_pnt1 = c.basic_operations.MakePointXYZ(p.X1, p.Y1, p.Z1, name="Pnt1", show=True)
     my_pnt2 = c.basic_operations.MakePointXYZ(p.X2, p.Y2, p.Z2, name="Pnt2", show=True)
     my_box = c.prim_operations.MakeBoxTwoPnt(my_pnt1, my_pnt2, name="Box1", show=True)
    def test_associative_methods(self):
        p = Parameters()  # Create a parameters set
        my_context = ParametricModelingContext(
            p, commit=False)  # Create and initialize a parametric context

        # 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
        Cmd = "Sketch:F 0 0:TT 0 100:C 100 180:WW"
        cmd, params = ParseSketcherCommand(Cmd)
        theWorkingPlane = [0, 0, 0, 0, 0, 1, 1, 0, 0]
        cmd = TCollection_AsciiString(cmd)
Example #7
0
    parameters = Instance(Parameters)
    update = Button
    r = Float(1.0)
    a = Float(100.0)

    view = View(
        Item("parameters", editor=PAFContextEditorFactory(context="context")), Item("update"), Item("a"), Item("r")
    )

    def _update_changed(self):
        self.parameters.a = self.a
        self.parameters.r = self.r


# Initialization
p = Parameters()
my_context = ParametricModelingContext(p)

# create trait viewer
paftest = PAFTest(context=my_context, parameters=p)
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
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters

p = Parameters()
tutorial_context = ParametricModelingContext(p,commit = True)
tutorial_context.init_display()

p.height = 43.3
p.radius = 12.9

tutorial_context.register_operations(tutorial_context.prim_operations)
my_cylinder = tutorial_context.prim_operations.MakeCylinderRH(p.radius,p.height,name="cylinder1", show=True)


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()
# HONESTLY STOLEN FROM geomDC.py
#===============================================================================
ShapeType = {
    "COMPOUND": 0,
    "COMPSOLID": 1,
    "SOLID": 2,
    "SHELL": 3,
    "FACE": 4,
    "WIRE": 5,
    "EDGE": 6,
    "VERTEX": 7,
    "SHAPE": 8
}

from OCC.PAF.Context import Parameters, ParametricModelingContext
p = Parameters()
my_context = ParametricModelingContext(p)

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=False)  # Create the first point
my_pnt2 = my_context.basic_operations.MakePointXYZ(
    p.X2, p.Y2, p.Z2, name="Pnt2", show=False)  # Create the second point
my_box = my_context.prim_operations.MakeBoxTwoPnt(my_pnt1,
                                                  my_pnt2,
                                                  name="Box1",
                                                  show=False)  # Create the box

#===============================================================================
# FROM geomDC.py: SubShapeAllSorted
#===============================================================================
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()
Example #12
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()
Example #13
0
##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.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,
Example #14
0
##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.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
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()
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()
Example #17
0
# import PAF
from OCC.PAF.Context import ParametricModelingContext
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
#
Example #18
0
    :return:                GEOM_Object
    """
    GEOM_IMPORT, IMPORT_SHAPE = 1, 1
    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
Example #19
0
from OCC.PAF.Context import ParametricModelingContext
from OCC.PAF.Parametric import Parameters
from OCC.PAF.Parametric import Relation
from OCC.PAF.Parametric import Rule

p = Parameters()
tutorial_context = ParametricModelingContext(p)
tutorial_context.init_display()

p.height = 43.3
p.radius = 12.9

tutorial_context.register_operations(tutorial_context.prim_operations)
my_cylinder = tutorial_context.prim_operations.MakeCylinderRH(p.radius,
                                                              p.height,
                                                              name="cylinder1",
                                                              show=True)

radius = p.radius.symbol
height = p.height.symbol

Rel = 2 * radius
Relation(p, "height", Rel)


def IsPositive(x):
    return x > 0


Rule(p, "radius", IsPositive)
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
    parameters = Instance(Parameters)
    update = Button
    r = Float(1.)
    a = Float(100.)

    view = View(
        Item("parameters", editor=PAFContextEditorFactory(context='context')),
        Item("update"), Item("a"), Item("r"))

    def _update_changed(self):
        self.parameters.a = self.a
        self.parameters.r = self.r


# Initialization
p = Parameters()
my_context = ParametricModelingContext(p)

#create trait viewer
paftest = PAFTest(context=my_context, parameters=p)
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")
Example #22
0
# import PAF
from OCC.PAF.Context import ParametricModelingContext
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