Exemple #1
0
def intf_ENTMOVE(E):
    """Supply an entity ID number (or a list of IDs) followed by a coordinate
    list (e.g. [3.5 -2 0]) on the stack and this function will remove them from
    the stack and move each point in the entity by the ammounts in the
    coordinate list vector."""
    input1ok= False
    if E.The.StackSize() >= 2: 
        # CHECK INPUT #1
        # Check that next ready stack item is a LST of 3 VALs.
        check= E.The.StackCopyItemLast() # Input verification. Next item on stack now.
        # Probably should use inc.point_formatted_LST here. See ENTPGRAM.
        if check.whatami == "LST":
            if len(check.val)==3:
                #if not filter(lambda x:x.whatami!="VAL",check.val):
                if all([x.whatami=="VAL" for x in check.val]):
                    input1ok= True
    if not input1ok or not inc.entid_or_LST_of_entids(E.The,2):
        print("Input Error: move")
        print(intf_ENTMOVE.__doc__)
        return # Without doing much of anything.
    myoffset= [ xyz.val for xyz in E.The.StackPop().val ] # A list [3.5 -2 0].
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            myent= MMEL.El[myeid]
            myent.translate(myoffset)
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    OUT.default(MMEL,E) # AUTODUMP 
Exemple #2
0
def intf_ENTPTS(E):
    """Supply a number on the stack and this function will return
    the geometry of that entity. If a list of entity IDs is supplied,
    return geometry data for each."""
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: pts")
        print(intf_ENTPTS.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        # NEEDS TO CHECK IF EID EXISTS!
        if myeid in MMEL.El: # Check if eid exists.
            pids= MMEL.El[myeid].epts # List of point IDs for this entity.
            for pid in pids:
                x= mm.Entity.allplist.PLdict[pid].x
                y= mm.Entity.allplist.PLdict[pid].y
                z= mm.Entity.allplist.PLdict[pid].z
                z= objectifier.StackOB_VAL(z) # Can't be just regular Python ints.
                y= objectifier.StackOB_VAL(y)
                x= objectifier.StackOB_VAL(x)
                p= objectifier.StackOB_LST([x, y, z])
                p.names= ['x','y','z']
                E.The.StackPush(p)
        else:
            print("Warning: No entity #%d. Skipping." % myeid)
Exemple #3
0
def intf_ENTDUP(E):
    """Supply an entity ID or list of entity IDs  on the stack and this
    function will create a new entity of the same type and using the same
    points. The new entity id or list of ids will be returned to the stack."""
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: entdup")
        print(intf_ENTDUP.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
        listify= True
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
        listify= False
    new_eid= list()
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            src_ent= MMEL.El[myeid]
            new_ent= src_ent.duplicate()
            MMEL.add_ent(new_ent)
            if listify:
                new_eid.append( objectifier.StackOB_VAL(new_ent.eid) )
            else:
                new_eid= objectifier.StackOB_VAL(new_ent.eid)
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    if new_eid:
        if listify:
            new_eid= objectifier.StackOB_LST(new_eid)
        E.The.StackPush(new_eid)
Exemple #4
0
def intf_ENTDUPS(E):
    """Returns a list of every entity ID in the memory model which has
    an earlier (lower EID) corresponding entity which shares all of the
    exact same points. This is handy for managing duplicate entities.
    To completely clean up a model of duplicated entities, 
        all edup? ~ -> """
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: doubles")
        print(intf_ENTERASE.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    some_doubles= list()
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            if not myeid in some_doubles:
                new_doubles= MMEL.find_doubles_of(MMEL.El[myeid])
                some_doubles+= new_doubles
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    if some_doubles:
        some_doubles_so= [objectifier.StackOB_VAL(eid) for eid in some_doubles]
        some_doubles_so= objectifier.StackOB_LST(some_doubles_so)
        E.The.StackPush(some_doubles_so)
    else:
        E.The.StackPush( objectifier.StackOB_LST( list() ))
Exemple #5
0
def intf_ENTCHTAG(E):
    """ From level three either an entity ID value or a list of entity ID values
    off the stack. From level two, a TXT object of an existing tag is
    taken off the stack. Finally from level one, the TXT object of the new
    replacement tag is taken.
    Any specified entities which are tagged with the specified tags will have
    those tags removed and replaced with the new one.
        <entID> ''roof'' ''wall'' chtag ->  
        [<entID> <entID> <entID>] ''roof'' ''wall'' chtag -> 
    """
    if ( not inc.entid_or_LST_of_entids(E.The,3) or
         not inc.TXT(E,2) or not inc.TXT(E,1) ):
        print("Input Error: chtag")
        print(intf_ENTCHTAG.__doc__)
        return # Without doing much of anything.
    refreshview= False # No need unless view attributes (@) have been affected.
    newtag= E.The.StackPop().val
    oldtag= E.The.StackPop().val
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of VALs.
        myeids= [x.val for x in  myeids] # Should now be a list of VALs.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            if MMEL.El[myeid].has_tag(oldtag):
                print("Untagging entity #%d with tag ''%s''" % (myeid,oldtag))
                MMEL.El[myeid].del_tag(oldtag)
                MMEL.El[myeid].add_tag(newtag)
                if '@' in oldtag or '@' in newtag: refreshview= True
        else:
            print("Warning: No entity #%d. Skipping." % myeid)
    if refreshview: OUT.default(MMEL,E) # AUTODUMP 
Exemple #6
0
def intf_ENTPGRAM(E):
    """Takes an entity or list of entities from v3 and two point formatted
    lists from v2 and v1 (which could come from a line entity number supplied
    to the `pts` function) and creates a parallelogram. This parallelogram
    consists of the original supplied line entity, a new parallel line entity,
    two new line entites connecting the endpoints of the other lines, and two
    trifaces which cover the entire area of the parallelogram."""
    # !! Need to check for some eids being TRIs. Filter that out.
    if ( not inc.entid_or_LST_of_entids(E.The,3) or 
         not inc.point_formatted_LST(E.The,2) or
         not inc.point_formatted_LST(E.The,1) ):
        print("Input Error: pgram")
        print(intf_ENTPGRAM.__doc__)
        return # Without doing much of anything.
    oB= [ xyz.val for xyz in E.The.StackPop().val ] # A list [3.5 -2 0].
    oA= [ xyz.val for xyz in E.The.StackPop().val ] # A list [3.5 -2 0].
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    neweidlist= []
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            src_ent= MMEL.El[myeid]
            new_ent= src_ent.duplicate()
            new_ent.translate([ oB[0]-oA[0], oB[1]-oA[1], oB[2]-oA[2] ])
            As= mm.Entity.allplist.PLdict[ src_ent.epts[0] ]
            Ae= mm.Entity.allplist.PLdict[ src_ent.epts[1] ]
            Bs= mm.Entity.allplist.PLdict[ new_ent.epts[0] ]
            Be= mm.Entity.allplist.PLdict[ new_ent.epts[1] ]
            neweidlist.append(new_ent.eid)
            MMEL.add_ent(new_ent)
            line_entS= mm.Line_Entity( [As,Bs] )
            neweidlist.append(line_entS.eid)
            MMEL.add_ent(line_entS)
            line_entE= mm.Line_Entity( [Ae,Be] )
            neweidlist.append(line_entE.eid)
            MMEL.add_ent(line_entE)
            tri_entA= mm.Tri_Entity( [As, Ae, Bs] )
            neweidlist.append(tri_entA.eid)
            MMEL.add_ent(tri_entA)
            tri_entB= mm.Tri_Entity( [Bs, Be, Ae] )
            neweidlist.append(tri_entB.eid)
            MMEL.add_ent(tri_entB)
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    if neweidlist:
        neweids= objectifier.StackOB_LST( [objectifier.StackOB_VAL(x) for x in neweidlist] )
        E.The.StackPush(neweids)
    OUT.default(MMEL,E) # AUTODUMP 
Exemple #7
0
def intf_MMITEM(E):
    """Dump the memory model of only the supplied entity ID or list of entity
    IDs to interpreter in a way that's helpful to the user.
        <entID> mmitem ->  
        [<entID> <entID> <entID>] mmitem -> 
    """
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: mmitem\n" + intf_MMITEM.__doc__)
        return # Without doing much of anything.
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: mmitem")
        print(intf_MMITEM.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El:
            print(MMEL.El[myeid].mmlist_repr())
Exemple #8
0
def intf_ENTTAG(E):
    """From level two either an entity ID value or a list of entity ID values
    is taken off the stack. From level one, a TXT object or a list of TXT
    objects is taken off the stack. The specified entities are tagged with the
    text items.
        <entID> ''roof'' tag ->  
        [<entID> <entID> <entID>] ''roof'' tag -> 
        [<entID> <entID>] [''roof'' ''house''] tag -> 
        last ''door'' tag -> 
    """
    if not inc.entid_or_LST_of_entids(E.The,2) or not inc.TXT_or_LST_of_TXTs(E.The,1):
        print("Input Error: tag")
        print(intf_ENTTAG.__doc__)
        return # Without doing much of anything.
    refreshview= False # No need unless view attributes (@) have been set.
    mytags= E.The.StackPop().val
    if type(mytags)==type(list()):
        #mytags= map(lambda x:x.val, mytags) # Should now be a list of TXTs.
        mytags= [x.val for x in  mytags] # Should now be a list of TXTs.
    else:
        mytags= [ mytags ] # Also a (1 item) list of ints.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of VALs.
        myeids= [x.val for x in  myeids] # Should now be a list of VALs.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            for mytag in mytags:
                if len(mytag) > 1 and '@' == mytag[1]:
                    refreshview= True
                    existing_att_tags= MMEL.El[myeid].has_tag_starting_with(mytag[0:2])
                    if existing_att_tags:
                        for et in  existing_att_tags:
                            MMEL.El[myeid].del_tag(et)
                print("Tagging entity #%d with tag ''%s''" % (myeid,mytag))
                if not MMEL.El[myeid].has_tag(mytag):
                    MMEL.El[myeid].add_tag(mytag)
        else:
            print("Warning: No entity #%d. Skipping." % myeid)
    if refreshview: OUT.default(MMEL,E) # AUTODUMP 
Exemple #9
0
def intf_ENTERASE(E):
    """Supply an entity ID or a list of entity IDs on the stack and this
    function will delete it. Points used in the specified entity will be
    removed if not used elsewhere."""
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: erase")
        print(intf_ENTERASE.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            MMEL.del_ent(myeid)
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    OUT.default(MMEL,E) # AUTODUMP 
Exemple #10
0
def intf_ENTDETAG(E):
    """Supply an entity ID or list of entity IDs  on the stack and this
    function will remove all tags from the supplied entities. To remove all
    tags from all entities, use `all detag`. Entity IDs are consumed."""
    if not inc.entid_or_LST_of_entids(E.The,1):
        print("Input Error: detag")
        print(intf_ENTDETAG.__doc__)
        return # Without doing much of anything.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of ints.
        myeids= [x.val for x in  myeids] # Should now be a list of ints.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            MMEL.El[myeid].tags= list()
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    OUT.default(MMEL,E) # AUTODUMP 
Exemple #11
0
def intf_ENTUNTAG(E):
    """ From level two either an entity ID value or a list of entity ID values
    off the stack. From level one, a TXT object or a list of TXT objects is
    taken off the stack. Any specified entities which are tagged with any of
    the specified tags will have those tags removed.
        <entID> ''roof'' untag ->  
        [<entID> <entID> <entID>] ''roof'' untag -> 
        [<entID> <entID>] [''roof'' ''house''] untag -> 
        last ''door'' untag -> 
    """
    if not inc.entid_or_LST_of_entids(E.The,2) or not inc.TXT_or_LST_of_TXTs(E.The,1):
        print("Input Error: untag")
        print(intf_ENTUNTAG.__doc__)
        return # Without doing much of anything.
    refreshview= False # No need unless view attributes (@) have been set.
    mytags= E.The.StackPop().val
    if type(mytags)==type(list()):
        #mytags= map(lambda x:x.val, mytags) # Should now be a list of TXTs.
        mytags= [x.val for x in  mytags] # Should now be a list of TXTs.
    else:
        mytags= [ mytags ] # Also a (1 item) list of ints.
    myeids= E.The.StackPop().val
    if type(myeids)==type(list()):
        #myeids= map(lambda x:x.val, myeids) # Should now be a list of VALs.
        myeids= [x.val for x in myeids] # Should now be a list of VALs.
    else:
        myeids= [ myeids ] # Also a (1 item) list of ints.
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            for mytag in mytags:
                if MMEL.El[myeid].has_tag(mytag):
                    print("Untagging entity #%d with tag ''%s''" % (myeid,mytag))
                    MMEL.El[myeid].del_tag(mytag)
                    if '@' in mytag: refreshview= True
        else:
            print("Warning: No entity #%d. Skipping." % myeid)
    if refreshview: OUT.default(MMEL,E) # AUTODUMP 
Exemple #12
0
def intf_ENTROTATE(E):
    """Rotate one or more entities around a provided axis by a provided angle.
       This function takes 3 items off the stack. In order of entry, the third
       item is either an entity ID value or a list of one or more entity IDs.
       These are the entities which will be modified by the rotation.
       The second item is the axis of rotation. It can be an entity ID value
       of a line entity (tri entities are not supported) or it can be a list
       containing precisely two lists which each contain three values. This
       list contains two coordinate lists for points on (defining) a line. This
       line is the axis of rotation. If you point your right thumb from the
       first point on this line to the second point, your fingers will curve in
       a postive rotation. Finally, the first item popped off the stack (last
       entered) is the angle in degrees of the rotation. An example is `[2 4
       13] [[0 0 0][0 0 1]] 45 rotate ->`, which would rotate entities 2, 4,
       and 13 by 45 degrees counter clockwise when seen looking from the second
       reference axis point ([0 0 1]) to the first ([0 0 0])."""
    # Input must be in one of the following forms:
    # A.  V V V ->
    # B.  V [[V V V][V V V]] V ->
    # C.  [V...V] V V ->
    # D.  [V...V] [[V V V][V V V]] V ->
    # == Check Input ==
    input1ok,input2ok= False,False
    if E.The.StackSize() >= 3: 
        # === Check Item #1 ===
        # Check that next ready stack item is a VAL (degrees to rotate).
        check= E.The.StackCopyItemLast() # Input verification. Next item on stack now.
        if check.whatami == "VAL":
            input1ok= True
            # === Check Item #2 === 
            # Check that stack item 2 (penultimate) is a LST of 2 LST, OR a VAL.
            check= E.The.StackCopyItemN(2)
            if check.whatami == "LST":
                if len(check.val) == 2:
                    #if not filter(lambda x:x.whatami!="LST",check.val):
                    if all([x.whatami=="LST" for x in check.val]):
                        #if (not filter(lambda x:x.whatami!="VAL",check.val[0].val) and
                        #    not filter(lambda x:x.whatami!="VAL",check.val[1].val) ):
                        if ( all([x.whatami=="VAL" for x in check.val[0].val]) and 
                             all([x.whatami=="VAL" for x in check.val[1].val]) ):
                            input2ok= True
            elif check.whatami == "VAL":
                input2ok= True # Might want to check here if entityID exists.
    if not input1ok or not input2ok or not inc.entid_or_LST_of_entids(E.The,3):
        print("Input Error: rotate")
        print(intf_ENTROTATE.__doc__)
        return # Without doing much of anything.
    # == Parse Input ==
    # === Parse Item #1 ===
    myangle= E.The.StackPop().val # degrees
    # === Parse Item #2 ===
    axisP0,axisP1= [0,0,0],[0,0,1] # Defaults if there are problems.
    axis_object= E.The.StackPop() # either 1 line eid VAL OR LST:[LST LST]]
    if axis_object.whatami == "LST":
        P0object= axis_object.val[0] # A LST of 3 VALs.
        if len(P0object.val) == 3:
            #axisP0= map(lambda x:x.val, P0object.val) # Should now be a list of floats.
            axisP0= [x.val for x in P0object.val] # Should now be a list of floats.
        else:
            print("Error: First axis point defined badly. Assuming: [0 0 0]")
        P1object= axis_object.val[1]
        if len(P1object.val) == 3:
            #axisP1= map(lambda x:x.val, P1object.val) # Should now be a list of floats.
            axisP1= [x.val for x in P1object.val] # Should now be a list of floats.
        else:
            print("Error: Second axis point defined badly. Assuming: [0 0 1]")
        # LST:[ LST:[ VAL VAL VAL ] LST:[ VAL VAL VAL ] ]
    elif axis_object.whatami == "VAL":
        axis_eid= int(axis_object.val)
        if axis_eid in MMEL.El: # Check if axis_eid exists.
            axis_ent= MMEL.El[axis_eid]
            if axis_ent.etype is "Line":
                x= mm.Entity.allplist.PLdict[ axis_ent.epts[0] ].x
                y= mm.Entity.allplist.PLdict[ axis_ent.epts[0] ].y
                z= mm.Entity.allplist.PLdict[ axis_ent.epts[0] ].z
                axisP0=[x,y,z]
                x= mm.Entity.allplist.PLdict[ axis_ent.epts[1] ].x
                y= mm.Entity.allplist.PLdict[ axis_ent.epts[1] ].y
                z= mm.Entity.allplist.PLdict[ axis_ent.epts[1] ].z
                axisP1=[x,y,z]
            else:
                print("Warning: Specified axis entity was not a line. Assuming: [[0 0 0][0 0 1]]")
        else:
            print("Warning: Specified axis entity did not exist. Assuming: [[0 0 0][0 0 1]]")
    else:
        print("Error: This should never happen. Input check in rotation function failed.")
        return
    # === Parse Item #3 ===
    myents_object= E.The.StackPop() # either 1 eid or a LST of eid VALs
    if myents_object.whatami=="LST":
        #myeids= map(lambda x:x.val, myents_object.val) # Should now be a list of ints.
        myeids= [x.val for x in myents_object.val] # Should now be a list of ints.
    else:
        myeids= [ myents_object.val ] # Also a (1 item) list of ints.
    # == Iterate Over Target Entities  ==
    for myeid in myeids:
        if myeid in MMEL.El: # Check if eid exists.
            myent= MMEL.El[myeid]
            #print('myent.rotate(%s,%s,%s)' % (myangle.__repr__(),axisP0.__repr__(),axisP1.__repr__()))
            # Looks like this: myent.rotate(22.5,[-1.0, -2.0, -3.0],[4.4, 5.5, 6.6])
            #DO THE ROTATION HERE!!!!!!!!!!!
            myent.rotate(myangle,axisP0,axisP1)
        else:
            print("WARNING: Entity ID# %d does not exist." % myeid)
    OUT.default(MMEL,E) # AUTODUMP