Exemple #1
0
def Mapping(fwork, keystates, keystates_prev):
    global mouse_prev, sections, warpd

    PL = gstt.Laser
    dots = []

    #switch to edit mode Key E ?
    if keystates[pygame.K_e] and not keystates_prev[
            pygame.K_e] and gstt.EditStep == 0:
        print "Switching to Edit Mode"
        gstt.EditStep = 1
        gstt.CurrentWindow = 0
        gstt.CurrentCorner = 0

    # Back to WARP mode if ENTER key is pressed ?
    if keystates[pygame.K_RETURN] and gstt.EditStep == 1:

        print "Switching to Warp Mode"
        gstt.EditStep = 0
        gstt.CurrentCorner = 0

    # EDIT MODE : cycle windows if press e key to adjust corner position
    # Escape edit mode with enter key
    if gstt.EditStep > 0:

        dots = []
        CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow]

        # Draw all windows points or "corners"
        for corner in xrange(len(CurrentWindowPoints)):
            dots.append(
                proj(int(CurrentWindowPoints[corner][0]),
                     int(CurrentWindowPoints[corner][1]), 0))
        fwork.PolyLineOneColor(dots,
                               c=colorify.rgb2hex(gstt.color),
                               PL=PL,
                               closed=False)

        # Left mouse is clicked, modify current Corner coordinate
        if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:
            deltax = gstt.mouse[0][0] - mouse_prev[0][0]
            deltay = gstt.mouse[0][1] - mouse_prev[0][1]
            CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2)
            CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2)

        # Change corner if Z key is pressed.
        if keystates[pygame.K_z] and not keystates_prev[pygame.K_z]:
            if gstt.CurrentCorner < settings.Mapping(
                    sections[gstt.CurrentSection]) - 1:
                gstt.CurrentCorner += 1
                print "Corner : ", gstt.CurrentCorner

        # Press E inside Edit mode : Next window
        if keystates[pygame.K_e] and not keystates_prev[pygame.K_e]:

            # Save current Window and switch to the next one.
            if gstt.CurrentWindow < settings.Mapping(
                    sections[gstt.CurrentSection]) - 1:
                print "saving "
                settings.MappingWrite(sections, str(gstt.CurrentWindow),
                                      CurrentWindowPoints)
                gstt.CurrentWindow += 1
                gstt.CurrentCorner = -1
                if gstt.CurrentWindow == settings.Mapping(
                        sections[gstt.CurrentSection]) - 1:
                    gstt.EditStep == 0
                    gstt.CurrentWindow = 0
                print "Now Editing window ", gstt.CurrentWindow

        mouse_prev = gstt.mouse
        gstt.PL[PL] = fwork.LinesPL(PL)

    # Press A : Next section ?
    if keystates[pygame.K_a] and not keystates_prev[pygame.K_a]:

        print "current section : ", gstt.CurrentSection
        if gstt.CurrentSection < len(sections) - 1:
            gstt.CurrentSection += 1
            print "Next section name is ", sections[gstt.CurrentSection]
            if "screen" in sections[gstt.CurrentSection]:
                print ""
                print "switching to section ", gstt.CurrentSection, " ", sections[
                    gstt.CurrentSection]
                MappingConf(gstt.CurrentSection)
        else:
            gstt.CurrentSection = -1

    # WARP Mode
    if gstt.EditStep == 0:

        #print "Warp mode"
        # Left mouse is clicked, modify current Corner coordinate
        #print gstt.mouse
        if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:
            deltax = gstt.mouse[0][0] - mouse_prev[0][0]
            deltay = gstt.mouse[0][1] - mouse_prev[0][1]

            print "Laser ", gstt.Laser, " Corner ", gstt.CurrentCorner, "deltax ", deltax, "deltay", deltay
            #int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][0]) += (deltax *20)
            #int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][1]) += (deltay * 2)

            print warpd

            #print int(gstt.warpdest[gstt.Laser][gstt.CurrentCorner][0]) + (deltax * 20)
        # Change corner if Z key is pressed.
        if keystates[pygame.K_z] and not keystates_prev[pygame.K_z]:
            if gstt.CurrentCorner < 4:
                gstt.CurrentCorner += 1
                print "Corner : ", gstt.CurrentCorner

        # Display all windows to current PL for display
        for Window in gstt.Windows:

            dots = []
            for corner in xrange(len(Window)):
                #print "Editing : ", WindowPoints[corner]
                #print Window[corner][0]
                dots.append(
                    proj(int(Window[corner][0]), int(Window[corner][1]), 0))

            fwork.PolyLineOneColor(dots,
                                   c=colorify.rgb2hex(gstt.color),
                                   PL=PL,
                                   closed=False)

        gstt.PL[PL] = fwork.LinesPL(PL)

        mouse_prev = gstt.mouse
Exemple #2
0
def Shapes(fwork):
    global mouse_prev, sections, warpd

    PL = gstt.Laser
    dots = []
    CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow]

    #switch to SHAPE mode Key E ?
    if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[
            pygame.K_e] and gstt.EditStep == 1:

        print "SHAPE Mode."
        gstt.EditStep = 0
        gstt.CurrentWindow = 0
        gstt.CurrentCorner = 0

    # ENTER : Display all shapes
    if gstt.keystates[pygame.K_RETURN] and gstt.EditStep == 0:

        print "Display all Mode."
        gstt.EditStep = 1
        gstt.CurrentCorner = 0

    # Draw all windows points or "corners"
    for corner in xrange(len(CurrentWindowPoints)):
        dots.append(
            proj(int(CurrentWindowPoints[corner][0]),
                 int(CurrentWindowPoints[corner][1]), 0))

    fwork.PolyLineOneColor(dots,
                           c=colorify.rgb2hex(gstt.color),
                           PL=PL,
                           closed=False)

    # Left mouse is clicked, modify current Corner coordinate
    if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:

        deltax = gstt.mouse[0][0] - mouse_prev[0][0]
        deltay = gstt.mouse[0][1] - mouse_prev[0][1]
        CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2)
        CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2)

    # Change corner if Z key is pressed.
    if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]:

        if gstt.CurrentCorner < settings.Mapping(
                sections[gstt.CurrentSection]) - 1:
            gstt.CurrentCorner += 1
            print "Corner : ", gstt.CurrentCorner

    # Press E inside shape mode : Next window
    if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[pygame.K_e]:

        # Save current Window and switch to the next one.
        if gstt.CurrentWindow < settings.Mapping(
                sections[gstt.CurrentSection]) - 1:

            print "saving "
            settings.MappingWrite(sections, str(gstt.CurrentWindow),
                                  CurrentWindowPoints)
            gstt.CurrentWindow += 1
            gstt.CurrentCorner = -1

            if gstt.CurrentWindow == settings.Mapping(
                    sections[gstt.CurrentSection]) - 1:
                gstt.EditStep == 0
                gstt.CurrentWindow = 0
            print "Now Editing window ", gstt.CurrentWindow

    mouse_prev = gstt.mouse
    gstt.PL[PL] = fwork.LinesPL(PL)

    # Press A : Next screen. Press until current section is a screen section with shapes.
    if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]:

        if gstt.CurrentSection < len(sections) - 1:
            gstt.CurrentSection += 1
        else:
            gstt.CurrentSection = 0
        print "Section ", sections[gstt.CurrentSection]

        if sections[gstt.CurrentSection].find("screen") == 0:
            print "switching to section ", sections[gstt.CurrentSection]
            print gstt.CurrentSection
            print sections[gstt.CurrentSection]
            MappingConf(gstt.CurrentSection)

    if gstt.EditStep == 1:

        # Add all windows to PL for display
        for Window in gstt.Windows:
            #print Window
            dots = []
            for corner in xrange(len(Window)):
                #print "Editing : ", WindowPoints[corner]
                #print Window[corner][0]
                dots.append(
                    proj(int(Window[corner][0]), int(Window[corner][1]), 0))

            fwork.PolyLineOneColor(dots,
                                   c=colorify.rgb2hex(gstt.color),
                                   PL=PL,
                                   closed=False)
            #print dots

        gstt.PL[PL] = fwork.LinesPL(PL)
Exemple #3
0
def Mapping(fwork):
    global mouse_prev, sections

    PL = gstt.Laser
    dots = []

    # switch to windows/shapes edit mode Key E ?
    if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[
            pygame.K_e] and gstt.EditStep == 0:
        print "Switching to Edit Mode"
        gstt.EditStep = 1
        gstt.CurrentWindow = 0
        gstt.CurrentCorner = 0

    # Back to Warp edit Mode if ENTER key is pressed ?
    if gstt.keystates[pygame.K_RETURN] and gstt.EditStep == 1:

        print "Switching to Warp Mode"
        gstt.EditStep = 0
        gstt.CurrentCorner = 0

    # Warp Display and Warp edit Mode
    # Change current corner position with mouse pointer
    # Change corner with Z key

    if gstt.EditStep == 0:

        # print "Warp mode"
        # Left mouse is clicked, modify current Corner coordinate
        # print gstt.mouse

        if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:
            deltax = gstt.mouse[0][0] - mouse_prev[0][0]
            deltay = gstt.mouse[0][1] - mouse_prev[0][1]

            gstt.warpdest[gstt.Laser][gstt.CurrentCorner, 0] -= (deltax * 5)
            gstt.warpdest[gstt.Laser][gstt.CurrentCorner, 1] += (deltay * 5)

            #print "Laser ", gstt.Laser, " Corner ", gstt.CurrentCorner, "deltax ", deltax, "deltay", deltay
            #print gstt.warpdest[gstt.Laser]

            homography.newEDH(gstt.Laser)
            settings.Write()

        # Change corner if Z key is pressed.
        if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]:
            if gstt.CurrentCorner < 3:
                gstt.CurrentCorner += 1
            else:
                gstt.CurrentCorner = 0
            print "Corner : ", gstt.CurrentCorner

        # Display all windows to current PL for display
        for Window in gstt.Windows:

            dots = []
            for corner in xrange(len(Window)):
                #print "Editing : ", WindowPoints[corner]
                #print Window[corner][0]
                dots.append(
                    proj(int(Window[corner][0]), int(Window[corner][1]), 0))

            fwork.PolyLineOneColor(dots,
                                   c=colorify.rgb2hex(gstt.color),
                                   PL=PL,
                                   closed=False)

        gstt.PL[PL] = fwork.LinesPL(PL)

        mouse_prev = gstt.mouse

    # EDIT WINDOWS MODE : cycle windows for current laser if press e key to adjust corner position
    # ENTER key to warp/display mode
    # Mouse to change current corner postion
    # Z key : next corner
    # E Key : Next window
    # A key : Next section

    if gstt.EditStep > 0:

        dots = []
        CurrentWindowPoints = gstt.Windows[gstt.CurrentWindow]

        # Draw all windows points or "corners"
        for corner in xrange(len(CurrentWindowPoints)):
            dots.append(
                proj(int(CurrentWindowPoints[corner][0]),
                     int(CurrentWindowPoints[corner][1]), 0))
        fwork.PolyLineOneColor(dots,
                               c=colorify.rgb2hex(gstt.color),
                               PL=PL,
                               closed=False)

        # Left mouse is clicked, modify current Corner coordinate
        if gstt.mouse[1][0] == mouse_prev[1][0] and mouse_prev[1][0] == 1:
            deltax = gstt.mouse[0][0] - mouse_prev[0][0]
            deltay = gstt.mouse[0][1] - mouse_prev[0][1]
            CurrentWindowPoints[gstt.CurrentCorner][0] += (deltax * 2)
            CurrentWindowPoints[gstt.CurrentCorner][1] -= (deltay * 2)

        # Change corner if Z key is pressed.
        if gstt.keystates[pygame.K_z] and not gstt.keystates_prev[pygame.K_z]:
            if gstt.CurrentCorner < settings.Mapping(
                    sections[gstt.CurrentSection]) - 1:
                gstt.CurrentCorner += 1
                print "Corner : ", gstt.CurrentCorner

        # E Key : Next window
        if gstt.keystates[pygame.K_e] and not gstt.keystates_prev[pygame.K_e]:

            # Save current Window and switch to the next one.
            if gstt.CurrentWindow < settings.Mapping(
                    sections[gstt.CurrentSection]) - 1:
                print "saving "
                settings.MappingWrite(sections, str(gstt.CurrentWindow),
                                      CurrentWindowPoints)
                gstt.CurrentWindow += 1
                gstt.CurrentCorner = -1
                if gstt.CurrentWindow == settings.Mapping(
                        sections[gstt.CurrentSection]) - 1:
                    gstt.EditStep == 0
                    gstt.CurrentWindow = 0
                print "Now Editing window ", gstt.CurrentWindow

        mouse_prev = gstt.mouse
        gstt.PL[PL] = fwork.LinesPL(PL)

    # A key : Next section ?
    if gstt.keystates[pygame.K_a] and not gstt.keystates_prev[pygame.K_a]:

        print "current section : ", gstt.CurrentSection
        if gstt.CurrentSection < len(sections) - 1:
            gstt.CurrentSection += 1
            print "Next section name is ", sections[gstt.CurrentSection]
            if "screen" in sections[gstt.CurrentSection]:
                print ""
                print "switching to section ", gstt.CurrentSection, " ", sections[
                    gstt.CurrentSection]
                MappingConf(gstt.CurrentSection)
        else:
            gstt.CurrentSection = -1