Пример #1
0
def onOpen():
    global name
    global description
    global filePath
    if snapshots and not snapshots.restoringInProgress():
        updateSnapshotState()
    gf.clear()
    printAll()
Пример #2
0
def onOpen(path):
	global name
	global description
	global filePath
	if snapshots and not snapshots.restoringInProgress():
		updateSnapshotState()
	gf.clear()
	printAll()
def onModify():
	if snapshots and snapshots.restoringInProgress():
		gf.clear()
		printAll()
		return
	global modified
	global name
	modified=True
	if snapshots:
		updateSnapshotState()
Пример #4
0
def onModify():
    if snapshots and snapshots.restoringInProgress():
        gf.clear()
        printAll()
        return
    global modified
    global name
    modified = True
    if snapshots:
        updateSnapshotState()
Пример #5
0
def open(newGfFigure, byName):
	global gfFigure
	global figsByName
	global instructions
	gfFigure=newGfFigure
	figsByName=byName
	gf.figureOpen(gfFigure)
	gf.clear()
	sleep()
	instructions=deque()
	gf.map("<enter>", "debugPlayback.play()")
Пример #6
0
def setNameDescPath(newName, newDescription, path=None):
	global name
	global description
	global modified
	global filePath
	name=newName
	if name:
		name=name.strip()
	description=newDescription
	if description:
		description=description.strip()
	filePath=path
	modified=False
	if snapshots:
		updateSnapshotState()
	gf.clear()
	printAll()
Пример #7
0
def setNameDescPath(newName, newDescription, path=None):
    global name
    global description
    global modified
    global filePath
    name = newName
    if name:
        name = name.strip()
    description = newDescription
    if description:
        description = description.strip()
    filePath = path
    modified = False
    if snapshots:
        updateSnapshotState()
    gf.clear()
    printAll()
Пример #8
0
def cutOff(figure, hyperplanes, showProgress=False):
	figures=[figure]
	i=0
	for h in hyperplanes:
		i+=1
		figures2=[]
		for f in figures:
			figures2.extend(cutFigure(f, h)[0])
		figures=figures2
		if showProgress:
			gf.clear()
			gf.echo("Cutting figure, hyperplane " + str(i) + "/" + str(len(hyperplanes)) + ", press any key to abort...")
			if not gf.sleep(0):
				return [figure]
	if showProgress:
		gf.clear()
		gf.echo("Figure has been cut")
	return figures
Пример #9
0
	def onSnapshotRestore(oldIndex):
		global name
		global description
		global filePath
		global modified
		state=snapshots.getState("figureInfo")
		if state:
			#(name, description, filePath, modified) = state
			name=state[0]
			description=state[1]
			filePath=state[2]
			modified=state[3]
		else:
			name=None
			description=None
			filePath=None
			modified=False
		gf.clear()
		printAll()
Пример #10
0
 def onSnapshotRestore(oldIndex):
     global name
     global description
     global filePath
     global modified
     state = snapshots.getState("figureInfo")
     if state:
         #(name, description, filePath, modified) = state
         name = state[0]
         description = state[1]
         filePath = state[2]
         modified = state[3]
     else:
         name = None
         description = None
         filePath = None
         modified = False
     gf.clear()
     printAll()
Пример #11
0
def commandCutFaces(dim=2, ratio=0.1):
	if ratio>=1 or ratio<=0:
		raise RuntimeError("Wrong ratio")
	figures=objFigure.fromGfFigure(gf.figureGet())
	for f in figures:
		if not check.isFigureConvex(f):
			raise RuntimeError("The figure is not convex")
	if figureInfo:
		name, desc = figureInfo.getNameDesc()
	figures2=[]
	for f in figures:
		figures2.extend(cutOffFacesDim(f, ratio, dim))
	gf.figureOpen(objFigure.toGfFigure(figures2), True)
	gf.clear()
	if dim==0:
		name = name + " with vertices cut off"
	elif dim==1:
		name = name + " with edges cut off"
	else:
		name = name + " with " + str(dim) + "-faces cut off"

	if figureInfo:
		figureInfo.setNameDescPath(name, None)
Пример #12
0
def randomRot(allowCameraMoving=False, printInfo=True):
    global mappedTo
    maxspeed = gf.get_speed()
    dim = gf.get_dimen()

    # Create two dimensional list of angular velocities (one for every pair of axes)
    velocities = [0]
    for i in range(1, dim + 1):
        velocities = velocities + [[0] * i]

    if allowCameraMoving:
        # Create list of camera distances (in different levels of persp. proj.) and list of their current speeds
        camPosL = [0] * (dim + 1)
        for i in range(3, dim + 1):
            camPosL[i] = gf.get_camposl(i)
        camPosLAcc = [0] * (dim + 1)

    lastTime = gf.time()
    minDelay = 1000 / gf.get_maxfps()
    while gf.sleep(
            minDelay
    ):  # Repeat till user abort; repaint and wait at least 1ms before every course
        t = gf.time()  # Time measuring to deal with different sleeping time
        if printInfo:
            gf.clear()
            # echo prints every line below the previous one, clearing is necessary
            gf.echo("--- Random rotation ---")

        # Rotate figure and write velocities to console
        for i in range(1, dim + 1):
            for j in range(1, i):
                velocities[i][j] = velocities[i][j] + (random.random() -
                                                       0.5) * maxspeed / 20
                if velocities[i][j] > maxspeed / 2:
                    velocities[i][j] = maxspeed / 2
                if velocities[i][j] < -maxspeed / 2:
                    velocities[i][j] = -maxspeed / 2
                if printInfo:
                    gf.echo("  {}{}: {:6.2f} deg/sec".format(
                        j, i, -velocities[i][j]))
                gf.rotate(i, j, velocities[i][j] * (t - lastTime) / 1000)

        if allowCameraMoving:
            # Change camera distances and write new values to console
            for i in range(3, dim + 1):
                camPosLAcc[i] = camPosLAcc[i] + (random.random() - 0.5) / 64
                if camPosLAcc[i] < 0:
                    if camPosLAcc[i] < -0.01:
                        camPosLAcc[i] = -0.01
                    camPosL[i] = camPosL[i] + (camPosL[i] -
                                               0.2) * camPosLAcc[i]
                if camPosLAcc[i] > 0:
                    if camPosLAcc[i] > 0.01:
                        camPosLAcc[i] = 0.01
                    camPosL[i] = camPosL[i] + (10 - camPosL[i]) * camPosLAcc[i]
                if printInfo:
                    gf.echo("  camposl{}={:6.2f}".format(i, camPosL[i]))
                gf.set_camposl(i, camPosL[i])

        lastTime = t
        if printInfo:
            if auto:
                gf.echo("Automatic rotation enabled")
            else:
                gf.echo("Automatic rotation disabled")
        if mappedTo:
            if printInfo:
                gf.clearAfterCmd(
                    "Press " + mappedTo +
                    " to toggle camera moving or any other key to stop moving"
                )  # Remove only this line when user types command
            if allowCameraMoving:
                gf.map(mappedTo, "randomRot.randomRot(False)"
                       )  # Tab always rotates without camera moving (default)
            else:
                gf.map(
                    mappedTo, "randomRot.randomRot(gf.time()<" +
                    str(gf.time() + 100) + ")"
                )  # Pressing tab in 100ms will rotate with camera moving
                # If tab was used to abort rotation, the same press will resume it
        else:
            if printInfo:
                gf.clearAfterCmd("Press any key to stop moving")
def idle():
    global axes
    global buttons
    global lock
    global idleTime
    if not axes:
        if not os.access(device, os.R_OK):
            off()
            raise IOError("Device " + device + " cannot be opened")
        axes = [0] * 6

        def handler():
            global axes
            global device
            global buttons
            global lock
            eventFormat = "llHHi"
            eventSize = struct.calcsize(eventFormat)
            openTime = time.time()
            skipping = True
            try:
                dev = open(device, "rb")
                event = dev.read(eventSize)
            except IOError as ex:
                with lock:
                    axes = None
                    raise ex
            while event:
                if skipping:  # events that happened before opening the device
                    if time.time() - openTime > 0.1:
                        skipping = False
                    event = dev.read(eventSize)
                    continue
                (tv_sec, tv_usec, type, code,
                 value) = struct.unpack(eventFormat, event)
                if type == 2:
                    with lock:
                        axes[code] += value
                elif type == 1 and value == 1:
                    buttons.append(code)
                try:
                    event = dev.read(eventSize)
                except IOError as ex:
                    with lock:
                        axes = None
                        raise ex

        t = threading.Thread(target=handler, args=())
        t.daemon = True
        t.start()

    currTime = gf.time()
    if currTime - idleTime > 100:
        with lock:
            axes = [0] * 6
        del buttons[:]
    else:
        dim = gf.get_dimen()
        with lock:
            if not axes:
                return
            (right, near, down, tiltNear, tiltLeft, rotRight) = axes
            axes = [0] * 6
        if dim >= 2:
            if tiltLeft:  # ifs needed not to force repainting
                gf.rotate(1, 2, sensitivity * tiltLeft)
        if dim >= 3:
            if tiltNear:
                gf.rotate(2, 3, sensitivity * tiltNear)
            if rotRight:
                gf.rotate(1, 3, sensitivity * rotRight)
        if dim >= 4:
            if right:
                gf.rotate(4, 1, sensitivity * right)
            if near:
                gf.rotate(4, 3, sensitivity * near)
            if down:
                gf.rotate(2, 4, sensitivity * down)

        while len(buttons):
            gf.clear()
            if buttons.pop() == 256:
                if leftBtnFunc:
                    leftBtnFunc()
            else:
                if rightBtnFunc:
                    rightBtnFunc()
    idleTime = currTime
Пример #14
0
def randomRot(allowCameraMoving=False, printInfo=True):
    global mappedTo
    maxspeed = gf.get_speed()
    dim = gf.get_dimen()

    # Create two dimensional list of angular velocities (one for every pair of axes)
    velocities = [0]
    for i in range(1, dim + 1):
        velocities = velocities + [[0] * i]

    if allowCameraMoving:
        # Create list of camera distances (in different levels of persp. proj.) and list of their current speeds
        camPosL = [0] * (dim + 1)
        for i in range(3, dim + 1):
            camPosL[i] = gf.get_camposl(i)
        camPosLAcc = [0] * (dim + 1)

    lastTime = gf.time()
    minDelay = 1000 / gf.get_maxfps()
    while gf.sleep(minDelay):  # Repeat till user abort; repaint and wait at least 1ms before every course
        t = gf.time()  # Time measuring to deal with different sleeping time
        if printInfo:
            gf.clear()
            # echo prints every line below the previous one, clearing is necessary
            gf.echo("--- Random rotation ---")

            # Rotate figure and write velocities to console
        for i in range(1, dim + 1):
            for j in range(1, i):
                velocities[i][j] = velocities[i][j] + (random.random() - 0.5) * maxspeed / 20
                if velocities[i][j] > maxspeed / 2:
                    velocities[i][j] = maxspeed / 2
                if velocities[i][j] < -maxspeed / 2:
                    velocities[i][j] = -maxspeed / 2
                if printInfo:
                    gf.echo("  {}{}: {:6.2f} deg/sec".format(j, i, -velocities[i][j]))
                gf.rotate(i, j, velocities[i][j] * (t - lastTime) / 1000)

        if allowCameraMoving:
            # Change camera distances and write new values to console
            for i in range(3, dim + 1):
                camPosLAcc[i] = camPosLAcc[i] + (random.random() - 0.5) / 64
                if camPosLAcc[i] < 0:
                    if camPosLAcc[i] < -0.01:
                        camPosLAcc[i] = -0.01
                    camPosL[i] = camPosL[i] + (camPosL[i] - 0.2) * camPosLAcc[i]
                if camPosLAcc[i] > 0:
                    if camPosLAcc[i] > 0.01:
                        camPosLAcc[i] = 0.01
                    camPosL[i] = camPosL[i] + (10 - camPosL[i]) * camPosLAcc[i]
                if printInfo:
                    gf.echo("  camposl{}={:6.2f}".format(i, camPosL[i]))
                gf.set_camposl(i, camPosL[i])

        lastTime = t
        if printInfo:
            if auto:
                gf.echo("Automatic rotation enabled")
            else:
                gf.echo("Automatic rotation disabled")
        if mappedTo:
            if printInfo:
                gf.clearAfterCmd(
                    "Press " + mappedTo + " to toggle camera moving or any other key to stop moving"
                )  # Remove only this line when user types command
            if allowCameraMoving:
                gf.map(mappedTo, "randomRot.randomRot(False)")  # Tab always rotates without camera moving (default)
            else:
                gf.map(
                    mappedTo, "randomRot.randomRot(gf.time()<" + str(gf.time() + 100) + ")"
                )  # Pressing tab in 100ms will rotate with camera moving
                # If tab was used to abort rotation, the same press will resume it
        else:
            if printInfo:
                gf.clearAfterCmd("Press any key to stop moving")
def idle():
	global axes
	global buttons
	global lock
	global idleTime
	if not axes:
		if not os.access(device, os.R_OK):
			off()
			raise IOError("Device " + device + " cannot be opened")
		axes=[0]*6
		def handler():
			global axes
			global device
			global buttons
			global lock
			eventFormat="llHHi"
			eventSize=struct.calcsize(eventFormat)
			openTime=time.time()
			skipping=True
			try:
				dev=open(device, "rb")
				event=dev.read(eventSize)
			except IOError as ex:
				with lock:
					axes=None
					raise ex
			while event:
				if skipping: # events that happened before opening the device
					if time.time()-openTime > 0.1:
						skipping=False
					event=dev.read(eventSize)
					continue
				(tv_sec, tv_usec, type, code, value)=struct.unpack(eventFormat, event)
				if type==2:
					with lock:
						axes[code]+=value
				elif type==1 and value==1:
					buttons.append(code)
				try:
					event=dev.read(eventSize)
				except IOError as ex:
					with lock:
						axes=None
						raise ex
		t=threading.Thread(target=handler, args=())
		t.daemon=True
		t.start()

	currTime=gf.time()
	if currTime-idleTime>100:
		with lock:
			axes=[0]*6
		del buttons[:]
	else:
		dim=gf.get_dimen()
		with lock:
			if not axes:
				return;
			(right, near, down, tiltNear, tiltLeft, rotRight)=axes
			axes=[0]*6
		if dim>=2:
			if tiltLeft: # ifs needed not to force repainting
				gf.rotate(1, 2, sensitivity*tiltLeft)
		if dim>=3:
			if tiltNear:
				gf.rotate(2, 3, sensitivity*tiltNear)
			if rotRight:
				gf.rotate(1, 3, sensitivity*rotRight)
		if dim>=4:
			if right:
				gf.rotate(4, 1, sensitivity*right)
			if near:
				gf.rotate(4, 3, sensitivity*near)
			if down:
				gf.rotate(2, 4, sensitivity*down)

		while len(buttons):
			gf.clear()
			if buttons.pop()==256:
				if leftBtnFunc:
					leftBtnFunc()
			else:
				if rightBtnFunc:
					rightBtnFunc()
	idleTime=currTime
Пример #16
0
def printPage(name):
	help_page=help_pages[name]
	if not help_page:
		raise RuntimeException("help " + name + " not found")
	gf.clear()
	gf.printCentered(help_pages[name])