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)
    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")
Esempio n. 3
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)
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()
Esempio n. 5
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)


Esempio n. 6
0
    gf = tt.GetLastFunction().GetObject()  # GEOM_Function
    gf.IsNull()  # yep...
    gf.SetValue(
        shape)  # segfault; this is the shape that tt.GetValue() will return!

    tt.GetValue().IsNull()

    if geomobject.GetValue().IsNull():
        raise ValueError('TopoDS_Shape was not set...')

    return tt.GetHandle()


p = Parameters()
pmc = ParametricModelingContext(p)
pmc.register_operations(pmc.boolean_operations)

v, lA, lB = map(lambda x: geomobject_from_topods(x, pmc),
                (vertex, lineA, lineB))

try:
    qq = pmc.boolean_operations.MakeBoolean(lA, lB, 3)
    qqq = qq.GetObject().GetValue()
except Exception, e:
    print e

Display()(qqq)

#   pmc.boolean_operations.MakePartition()
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
Esempio n. 8
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
p.X1, p.Y1, p.Z1, p.X2, p.Y2, p.Z2, p.RADIUS = 12, 70, 12, 30, 30, 30, 4  # Create 7 parameters
Esempio n. 9
0
##(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)
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()