예제 #1
0
	createCallbacks.remove(func)


def set_maxcount(newCnt):
	global maxCnt
	if newCnt<0:
		newCnt=0
	maxCnt=newCnt
	checkCnt()

def get_maxcount():
	global maxCnt
	return maxCnt
	

gf.addCommand("undo", "snapshots.undo(%)", -1)
gf.addCommand("redo", "snapshots.redo(%)", -1)
gf.addCommand("snapshots maxcount", "'  maxcount=' + str(snapshots.get_maxcount())")
gf.addCommand("snapshots maxcount=", "snapshots.set_maxcount(%)", 1, "-")


# Private methods

def checkCnt():
	global maxCnt
	global snapshots
	global currentIndex
	diff=len(snapshots)-maxCnt
	if diff>0:
		currentIndex=currentIndex-diff
		del snapshots[:diff]
    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)
예제 #3
0
    global auto
    if value ^ auto:
        if value:
            gf.registerCallback("open", schedule)
        else:
            gf.unregisterCallback("open", schedule)
        auto = value


def get_auto():
    return auto


set_auto(True)

gf.addCommand("randomrot auto", "randomRot.set_auto(True)")
gf.addCommand("randomrot noauto", "randomRot.set_auto(False)")
gf.addCommand("randomrot map", "randomRot.map(None)")
gf.addCommand("randomrot map ", "randomRot.map(%)", 1, "s")
gf.addCommand("randomrot", "randomRot.randomRot()")


# Randomly rotates opened figure in all existing axes, optionally moves with camera (resp. modifies perspective projections)
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):
예제 #4
0
		text+= str(cnts[3]) + " cells, "
	if figure.dim>2:
		text+= str(cnts[2]) + " faces, "
	if figure.dim>1:
		text+= str(cnts[1]) + " edges, "
	text+= str(cnts[0]) + " vertices)"
	return text;

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]))

gf.addCommand("info", "figureInfo.printAll()")

예제 #5
0

def set_maxcount(newCnt):
    global maxCnt
    if newCnt < 0:
        newCnt = 0
    maxCnt = newCnt
    checkCnt()


def get_maxcount():
    global maxCnt
    return maxCnt


gf.addCommand("undo", "snapshots.undo(%)", -1)
gf.addCommand("redo", "snapshots.redo(%)", -1)
gf.addCommand("snapshots maxcount",
              "'  maxcount=' + str(snapshots.get_maxcount())")
gf.addCommand("snapshots maxcount=", "snapshots.set_maxcount(%)", 1, "-")

# Private methods


def checkCnt():
    global maxCnt
    global snapshots
    global currentIndex
    diff = len(snapshots) - maxCnt
    if diff > 0:
        currentIndex = currentIndex - diff
예제 #6
0
		queue=[apexFigure]
		apexFigure.mark=True
		while queue:
			apexFace=queue.pop(0)
			if not apexFace.mark: continue
			apexFace.mark=None
			for apexFace2 in list(apexFace.boundary):
				if apexFace2.origFace:
					apexFace.boundary.remove(apexFace2)
					apexFace.boundary.add(apexFace2.origFace)
				else:
					apexFace2.mark=True
					queue.append(apexFace2)
		newFacets.extend(apexFigure.boundary)

	return objFigure.Figure(newFacets)

def commandStellate():
	figures=objFigure.fromGfFigure(gf.figureGet())
	if figureInfo:
		name,desc=figureInfo.getNameDesc()
	figures=[stellateFigure(f) for f in figures]
	if name:
		name="Stellated " + name
	desc=None
	gf.figureOpen(objFigure.toGfFigure(figures), True)
	if figureInfo:
		figureInfo.setNameDescPath(name, desc)

gf.addCommand("stellate", "stellation.commandStellate()")
예제 #7
0
	dim=figures[0].spaceDim
	if dim<=0:
		raise RuntimeError("The figure cannot be cut")
	hyperplane=algebra.Hyperplane((0,)*(dim-1)+(1,), lastCoordinate)
	newFigures=[]
	for f in figures:
		newFigures.extend(cutFigure(f, hyperplane)[1])
	gfFigure=objFigure.toGfFigure(newFigures)
	if gfFigure:
		gfFigure[0]=[p[:-1] for p in gfFigure[0]]
		del gfFigure[dim]
	if figureInfo:
		name, desc=figureInfo.getNameDesc()
	gf.figureOpen(gfFigure)
	if figureInfo:
		figureInfo.setNameDescPath("Cross-section of "+name, None)



gf.addCommand("cut vertices", "cuts.commandCutFaces(0)")
gf.addCommand("cut edges", "cuts.commandCutFaces(1)")
gf.addCommand("cut faces", "cuts.commandCutFaces()")
gf.addCommand("cut off", "cuts.commandCutOff()")
gf.addCommand("cut figure", "cuts.commandCutFigure()")

gf.addCommand("cut vertices ", "cuts.commandCutFaces(0,%)", -1, '-')
gf.addCommand("cut edges ", "cuts.commandCutFaces(1,%)", -1, '-')
gf.addCommand("cut faces ", "cuts.commandCutFaces(%)", -2, '-')
gf.addCommand("cut off ", "cuts.commandCutOff(%)", -1, '-')
gf.addCommand("cut figure ", "cuts.commandCutFigure(%)", -1, '-')
예제 #8
0
                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))


gf.addCommand("info", "figureInfo.printAll()")
예제 #9
0
	edgesParents=dict()
	for facet in figure.boundary:
		facetsInnerPoints[facet]=algebra.vectAvg(*(v.position for v in facet if v.dim==0))
		for edge in facet.boundary:
			if not edge in edgesParents:
				edgesParents[edge]=set()
			edgesParents[edge].add(facet)
	hyperplanes=spaceCuts.hyperplanesOfFigure(figure);
	for facet in figure.boundary:
		hyperplane=spaceCuts.hyperplaneOfFacet(facet, innerPoint)
		for edge in facet.boundary:
			facet2=[f for f in edgesParents[edge] if f!=facet][0]
			point=facetsInnerPoints[facet2]
			if hyperplane.orientedDistance(point)<0.0001:
				return False
	return True

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.")

gf.addCommand("is convex", "check.commandIsConvex()")
	active=False
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")
예제 #11
0
    global auto
    if value ^ auto:
        if value:
            gf.registerCallback("open", schedule)
        else:
            gf.unregisterCallback("open", schedule)
        auto = value


def get_auto():
    return auto


set_auto(True)

gf.addCommand("randomrot auto", "randomRot.set_auto(True)")
gf.addCommand("randomrot noauto", "randomRot.set_auto(False)")
gf.addCommand("randomrot map", "randomRot.map(None)")
gf.addCommand("randomrot map ", "randomRot.map(%)", 1, "s")
gf.addCommand("randomrot", "randomRot.randomRot()")


# Randomly rotates opened figure in all existing axes, optionally moves with camera (resp. modifies perspective projections)
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):
예제 #12
0
		for f in figureElem:
			if not f.dualCache: # create vertex of the dual figure using polar reciprocation
				vertsPos=[v.position for v in f if v.dim==0]
				hyperplane=algebra.hyperplaneFromPoints(vertsPos)
				f.dualCache=Vertex(dualPointFromHyperplane(hyperplane, centerPoint))
			for child in f.boundary:
				if not child.dualCache:
					child.dualCache=Figure()
				child.dualCache.addToBoundary(f.dualCache)
				if child.dim == 0:
					dualFigure.addToBoundary(child.dualCache)
	finally:
		for f in figureElem:
			del f.dualCache
	return dualFigure


def commandCreateDual():
	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()
	figures=[createDual(f) for f in figures]
	gf.figureOpen(objFigure.toGfFigure(figures), True)
	if figureInfo:
		figureInfo.setNameDescPath("Dual of " + name, None)

gf.addCommand("create dual", "duals.commandCreateDual()")
예제 #13
0
def addPage(name, content):
	global help_pages, main_help_pages
	gf.addCommand("help " + name, "helpMod.printPage('" + name + "')")
	help_pages[name]=content.strip("\n")
예제 #14
0
def addPage(name, content):
	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
예제 #15
0
		g=find(f)
		if g.componentIndex == None:
			g.componentIndex=len(components)
			components.append([])
		components[g.componentIndex].append(f)
	for f in figures:
		del f.component
		del f.componentIndex
		del f.componentRank
		for f2 in f.boundary:
			f2.component=None
			del f2.component
			f2.componentRank=None
			del f2.componentRank
	return components


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.")

gf.addCommand("is convex", "check.commandIsConvex()")
예제 #16
0
				f.dualCache=Vertex(dualPointFromHyperplane(hyperplane, centerPoint))
			else:
				f.dualCache=Figure()
				f.dualCache.setDim(d,figure.spaceDim)
			f.dualCache.origDualFace=f
		for f in figure:
			if f.dim<figure.dim:
				for child in f.boundary:
					child.dualCache.addToBoundary(f.dualCache)
				if f.dim == 0:
					dualFigure.addToBoundary(f.dualCache)
	finally:
		for f in figure:
			del f.dualCache
	return dualFigure


def commandCreateDual():
	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()
	figures=[createDual(f) for f in figures]
	gf.figureOpen(objFigure.toGfFigure(figures), True)
	if figureInfo:
		figureInfo.setNameDescPath("Dual of " + name, None)

gf.addCommand("create dual", "duals.commandCreateDual()")