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
def printAll(): figures=objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName=None if filePath: fileName=os.path.basename(filePath) n=name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo(str.join("\n", [" "+s for s in description.split("\n")])) gf.echo("Content:") gf.echo(str.join("\n", [" "+counts(f) for f in figures]))
def info(): gf.echo("""--- SpaceNavigator --- device=""" + get_device() + """ sensitivity=""" + str(get_sens())) if active: gf.echo("The device is active") else: gf.echo("The device is inactive") gf.clearAfterCmd()
def commandIsConvex(): figures=objFigure.fromGfFigure(gf.figureGet()) for f in figures: if not isFigureConvex(f): gf.echo("The figure is not convex.") return cnt=len(figures) if len(figures)>1: gf.echo("All figures are convex.") else: gf.echo("The figure is convex.")
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")
gf.echo("""--- SpaceNavigator --- device=""" + get_device() + """ sensitivity=""" + str(get_sens())) if active: gf.echo("The device is active") else: gf.echo("The device is inactive") gf.clearAfterCmd() gf.removeCommands("spacenavigator") gf.addCommand("spacenavigator", "spaceNavigator.info()") gf.addCommand("spacenavigator on", "spaceNavigator.on()") gf.addCommand("spacenavigator off", "spaceNavigator.off()") gf.addCommand("spacenavigator device=", "spaceNavigator.set_device(%)", 1, "p") gf.addCommand("spacenavigator device", "' device=' + spaceNavigator.get_device()") gf.addCommand("spacenavigator sensitivity", "' sensitivity=' + str(spaceNavigator.get_sens())") gf.addCommand("spacenavigator sensitivity=", "spaceNavigator.set_sens(%)", 1, "-") if os.access(device, os.R_OK): on() try: # deactivate randomRot module, if exists import randomRot randomRot.set_auto(False) except ImportError: pass gf.echo("Space navigator module loaded, device found")
def printAll(): figures=objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName=None if filePath: fileName=os.path.basename(filePath) n=name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo(str.join("\n", [" "+s for s in description.split("\n")])) gf.echo("Content:") cntsD=dict() groupLines=False for f in figures: cnts=counts(f) if cnts in cntsD: cntsD[cnts]+=1 groupLines=True else: cntsD[cnts]=1 for cnts in cntsD: if not groupLines: gf.echo(" "+countsToStr(cnts)) elif cntsD[cnts]==1: gf.echo(" "+countsToStr(cnts)) else: gf.echo(("%4d" % cntsD[cnts])+"x "+countsToStr(cnts))
def printAll(): figures = objFigure.fromGfFigure(gf.figureGet()) if not figures: gf.echo("Nothing opened") else: if name: fileName = None if filePath: fileName = os.path.basename(filePath) n = name if fileName: n += ' (' + fileName + ')' if modified: n += ' (modified)' gf.echo(n) if description: gf.echo( str.join("\n", [" " + s for s in description.split("\n")])) gf.echo("Content:") cntsD = dict() groupLines = False for f in figures: cnts = counts(f) if cnts in cntsD: cntsD[cnts] += 1 groupLines = True else: cntsD[cnts] = 1 for cnts in cntsD: if not groupLines: gf.echo(" " + countsToStr(cnts)) elif cntsD[cnts] == 1: gf.echo(" " + countsToStr(cnts)) else: gf.echo(("%4d" % cntsD[cnts]) + "x " + countsToStr(cnts))
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 is_active(): return active def info(): gf.echo("""--- SpaceNavigator --- device=""" + get_device() + """ sensitivity=""" + str(get_sens())) if active: gf.echo("The device is active") else: gf.echo("The device is inactive") gf.clearAfterCmd() gf.removeCommands("spacenavigator") gf.addCommand("spacenavigator", "spaceNavigator.info()") gf.addCommand("spacenavigator on", "spaceNavigator.on()") gf.addCommand("spacenavigator off", "spaceNavigator.off()") gf.addCommand("spacenavigator device=", "spaceNavigator.set_device(%)", 1, "p") gf.addCommand("spacenavigator device", "' device=' + spaceNavigator.get_device()") gf.addCommand("spacenavigator sensitivity", "' sensitivity=' + str(spaceNavigator.get_sens())") gf.addCommand("spacenavigator sensitivity=", "spaceNavigator.set_sens(%)", 1, "-") if os.access(device, os.R_OK): on() try: # deactivate randomRot module, if exists import randomRot randomRot.set_auto(False) except ImportError: pass gf.echo("Space navigator module loaded, device found")
global help_pages, main_help_pages gf.addCommand("help " + name, "helpMod.printPage('" + name + "')") help_pages[name]=content.strip("\n") 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]) gf.map("?", "helpMod.configPrint()") gf.map("<F1>", "helpMod.configPrint()") gf.addCommand("help config", "helpMod.configPrint()") gf.echo("To see the configuration press F1") config_readme="" def configPrint(): text="" if config_readme: text += config_readme text += "\n\nFor further help see the configuration file," else: text += "There is no help on configuration (maybe there is no config.py file at all)," if main_help_pages: text += """ for help on imported modules type :help module <name>, <name> can be:"""; i=0 for s in sorted(main_help_pages):