def _newSelectionMode(mode): class SkelSelectToolbox(SkeletonSelectionToolbox): def __init__(self, gfxwindow): SkeletonSelectionToolbox.__init__(self, mode=mode, gfxwindow=gfxwindow) global tbordering tbordering += 0.01 tip="Select " + mode.name + "s in a Skeleton." discussion="""<para> Commands for selecting %ss in a &skel;, based on mouse input. </para>""" % mode.name ## The mode keeps a reference to the associated class so that GUI ## extensions can be applied to the class. If the mode didn't ## keep a reference, then the only way to find the class would be ## to look through the registry in toolbox.py. mode.tbclass = SkelSelectToolbox toolbox.registerToolboxClass(SkelSelectToolbox, ordering=tbordering)
name=toolboxName(), method=pixelselection.VoxelSelectionMethod, menu=pixelselectionmenu.selectmenu, gfxwindow=gfxwindow) def getSelectionSource(self): # Return the Microstructure of the top Microstructure or Image # layer. who = self.gfxwindow().topwho('Microstructure', 'Image') if who is not None: if who.getClassName() == 'Microstructure': return who return who.getParent() # Microstructure is the parent of Image # The following two functions are used when generating xml output. def objName(self): return 'Pixel' def sourceName(self): return 'µ or ℑ' tip = "Select pixels in a Microstructure." discussion = """<para> Commands for <link linkend='Section:Concepts:Microstructure:PixelSelection'>selecting</link> pixels in a µ, based on mouse input. </para>""" toolbox.registerToolboxClass(PixelSelectToolbox, ordering=1.5)
self.querier.set(context=context, object=object, targetname=targetname, position=position) self.records.push(self.querier.clone()) if self.peeker is None: self.peeker = SkeletonPeekContainer(self, context) self.peeker.reset() self.timestamp.increment() self.querysignal() switchboard.notify("redraw") def querysignal(self): switchboard.notify((self.gfxwindow(), "query skeleton")) def clearQuerier(self): self.querier = None self.peeker = None self.timestamp.increment() def prev_able(self): return not self.records.atBottom() def next_able(self): return not self.records.atTop() tip = "Get information about Skeleton components." discussion = """<para> Get information about &skel; components, based on mouse input. </para>""" toolbox.registerToolboxClass(SkeletonInfoToolbox, ordering=2.0)
finally: skelcontext.end_writing() skelcontext.cancel_reservation() skeleton.needsHash() switchboard.notify('redraw') def selectNode(self, menuitem, position): context = apply(self.gfxwindow().topwho, self.whoset) if context: skeleton = context.getObject() self.selectednode.set(skeleton.nearestNode(position)) switchboard.notify('redraw') switchboard.notify(("node selected", self)) def allowIllegal(self, menuitem, allowed): self.allow_illegal=allowed switchboard.notify(("illegal-move status changed", self), allowed) def layersChangedCB(self): # sb (gfxwindow, "layers changed") skelctxt = self.getSkeletonContext() if skelctxt is not self.skeleton: self.skeleton = skelctxt self.selectednode.set() # clears selection switchboard.notify(("skeleton changed", self)) tip="Move Skeleton nodes interactively." discussion="""<para> Menu commands for moving &skel; nodes, based on mouse input. </para>""" toolbox.registerToolboxClass(MoveNodeToolbox, ordering=2.6)
from ooflib.common.IO import parameter from ooflib.common.IO import pointparameter from ooflib.common.IO import whoville from ooflib.common.IO import xmlmenudump from ooflib.engine import skeletoncontext from ooflib.engine import pinnodesmodifier # Toolbox for pinning nodes. Pinned nodes don't move during mesh # modification operations. They *can* move during equilibration -- # they're not boundary conditions. Pinned nodes are treated much like # Skeleton Selectables, and share a lot of code with them. # The PinnedNodes toolbox is *not* derived from GenericSelectToolbox # because it doesn't require different kinds of mousehandlers for # different selection methods. class PinnedNodesToolbox(toolbox.Toolbox): def __init__(self, gfxwindow): toolbox.Toolbox.__init__(self, 'Pin Nodes', gfxwindow) tip = "Pin nodes." discussion = """<para> Pinned nodes are immobile during &skel; modifications. This menu contains tools for pinning and unpinning nodes with mouse input. </para>""" toolbox.registerToolboxClass(PinnedNodesToolbox, ordering=2.7)
# parameter to the parameter list. # gfxwindow is the GfxWindow or GhostGfxWindow that the # selection was initiated in. It might not be needed here # anymore. whopath = labeltree.makePath(params['source']) if len(whopath) == 1: return whoville.getClass('Microstructure')[whopath] if len(whopath) == 2: return whoville.getClass('Image')[whopath] # The following two functions are used when generating xml output. def objName(self): return 'Pixel' def sourceName(self): return 'µ or ℑ' def sourceParamName(self): return 'source' tip = "Select pixels in a Microstructure." discussion = """<para> Commands for <link linkend='Section-Concepts-Microstructure-PixelSelection'>selecting</link> pixels in a µ, based on mouse input. </para>""" toolbox.registerToolboxClass(PixelSelectToolbox, ordering = 1.5)
self.timestamp.increment() self.point = None switchboard.notify(self) switchboard.notify('redraw') def currentPixel(self): return self.point def findMicrostructure(self): ## This used to check for Skeletons and Meshes, too, and use ## their getMicrostructure function. That led to some ## confusing situations, when a Skeleton was displayed over an ## Image from a different Microstructure, for example. So now ## it doesn't return anything when no Microstructure or Image ## is displayed. who = self.gfxwindow().topwho('Microstructure', 'Image') if who is not None: return who.getMicrostructure() return None def getTimeStamp(self): return self.timestamp tip = "Get information about a pixel." discussion = """<para> Get information about a pixel, based on mouse input. </para>""" toolbox.registerToolboxClass(PixelInfoToolbox, ordering=1.0)
# This is not a menu callback, and doesn't acquire the # gfxlock, which should have already been acquired by the # calling function. newView = retrieveView(view, self.gfxwindow()).clone() oldView = mainthread.runBlock(self.gfxwindow().oofcanvas.get_view) nclip = oldView.nClipPlanes() for i in range(nclip): newView.addClipPlane(oldView.getClipPlane(i).clone()) mainthread.runBlock(self.gfxwindow().oofcanvas.set_view, (newView, False)) self._updateView() switchboard.notify("completed view change", self.gfxwindow()) def setView(self, viewname): # This is called by the GUI toolbox and the GUI toolbar to # invoke the menu command that restores the view. menuitem = self.menu.Restore_Named_View menuitem.callWithDefaults(view=viewname) def deleteView(self, menuitem, view): v = namedViews[view] if v.deletable: del namedViews[view] switchboard.notify("view deleted", view) else: raise ooferror.ErrUserError( "Please don't delete the predefined Views.") toolbox.registerToolboxClass(ViewerToolbox, ordering=0.0)
self.last_position = None if self.querier: self.querier.set() self.peeker.reset() self.redraw() switchboard.notify((self, "clear")) def currentPoint(self): try: currentquerier = self.records.current() except IndexError: return if currentquerier: return currentquerier.mesh_position def redraw(self): switchboard.notify("redraw") def prev_able(self): return not self.records.atBottom() def next_able(self): return not self.records.atTop() tip = "Get information about a Mesh." discussion="""<para> Get information about a &mesh;, including &field; values, based on mouse input. </para>""" toolbox.registerToolboxClass(MeshInfoToolbox, ordering=3.0)
position=position) self.records.push(self.querier.clone()) if self.peeker is None: self.peeker = SkeletonPeekContainer(self, context) self.peeker.reset() self.timestamp.increment() self.querysignal() switchboard.notify("redraw") def querysignal(self): switchboard.notify((self.gfxwindow(), "query skeleton")) def clearQuerier(self): self.querier = None self.peeker = None self.timestamp.increment() def prev_able(self): return not self.records.atBottom() def next_able(self): return not self.records.atTop() tip = "Get information about Skeleton components." discussion = """<para> Get information about &skel; components, based on mouse input. </para>""" toolbox.registerToolboxClass(SkeletonInfoToolbox, ordering=2.0)
def emptyMessage(self): return "No Skeleton!" # you spineless bastard discussion = "Methods for selecting &skel; components in a graphics window." ordering = 2.5 skeletonselectionmodes.initialize() for mode in skeletonselmodebase.SkeletonSelectionMode.modes: class SkeletonSelectionToolbox(SkeletonSelectionToolboxBase): def __init__(self, gfxwindow, selmode=mode): SkeletonSelectionToolboxBase.__init__( self, name=selmode.toolboxName(), method=selmode.methodclass, menu=selmode.getSelectionMenu(), mode=selmode, gfxwindow=gfxwindow) SkeletonSelectionToolbox.tip = "Select " + mode.name + "s in a Skeleton" mode.toolboxclass = SkeletonSelectionToolbox toolbox.registerToolboxClass(SkeletonSelectionToolbox, ordering=ordering) ordering += 0.01 # TODO? Earlier versions allowed new toolbox modes to be added after # initialization time via a switchboard signal sent from # SkeletonSelectionMode.__init__. Is that at all useful?
# Given the indicated start and end point, make a CS and add it # to the mesh. Eventually there will be more of these. Call # is triggered by the MouseUp in the graphical toolbox. def makeCS(self, start, end): cs = meshcrosssection.StraightCrossSection(start=start, end=end) namepar = meshmenu.csnameparam meshpar = meshmenu.csmeshparam if self.current_mesh: meshpar.set(mesh.meshes.getPath(self.current_mesh)) namepar.set(automatic.automatic) meshmenu.csmenu.New.callWithDefaults(cross_section=cs) def newLayers(self): self.activate() def stop_callbacks(self): for s in self.sb_callbacks: switchboard.removeCallback(s) self.sb_callbacks = [] tip = "You couldn't hit the side of barn." discussion = """<para> This toolbox doesn't have any of its own menu items, so this text that you're reading right now shouldn't appear in the documentation. If it does, please file a bug report. </para>""" toolbox.registerToolboxClass(CrossSectionToolbox, 3.0)
# $RCSfile: viewertoolbox.py,v $ # $Revision: 1.5 $ # $Author: langer $ # $Date: 2014/09/27 21:40:33 $ # This software was produced by NIST, an agency of the U.S. government, # and by statute is not subject to copyright in the United States. # Recipients of this software assume all responsibilities associated # with its operation, modification and maintenance. However, to # facilitate maintenance we ask that before distributing modified # versions of this software, you first contact the authors at # [email protected]. from ooflib.common import toolbox # Toolbox for viewing. # Major functionality: zooming, panning class ViewerToolbox(toolbox.Toolbox): def __init__(self, gfxwindow): toolbox.Toolbox.__init__(self, 'Viewer', gfxwindow) tip="Seeing is believing." discussion="""<para> This toolbox doesn't have any of its own menu items, so this text that you're reading right now shouldn't appear in the documentation. If it does, please file a bug report. </para>""" toolbox.registerToolboxClass(ViewerToolbox, ordering=0.0)
# to the mesh. Eventually there will be more of these. Call # is triggered by the MouseUp in the graphical toolbox. def makeCS(self, start, end): cs = meshcrosssection.StraightCrossSection( start=start, end=end) namepar = meshmenu.csnameparam meshpar = meshmenu.csmeshparam if self.current_mesh: meshpar.set(mesh.meshes.getPath(self.current_mesh) ) namepar.set(automatic.automatic) meshmenu.csmenu.New.callWithDefaults( cross_section=cs) def newLayers(self): self.activate() def stop_callbacks(self): for s in self.sb_callbacks: switchboard.removeCallback(s) self.sb_callbacks = [] tip="You couldn't hit the side of barn." discussion="""<para> This toolbox doesn't have any of its own menu items, so this text that you're reading right now shouldn't appear in the documentation. If it does, please file a bug report. </para>""" toolbox.registerToolboxClass(CrossSectionToolbox, 3.0)
newpinned = skelcontext.getObject().notPinnedNodes() skelcontext.pinnednodes.start() skelcontext.pinnednodes.clear() skelcontext.pinnednodes.pin(newpinned) skelcontext.pinnednodes.signal() def unpinall(self, menuitem, skeleton): skelcontext = skeletoncontext.skeletonContexts[skeleton] skelcontext.pinnednodes.start() skelcontext.pinnednodes.clear() skelcontext.pinnednodes.signal() def undoPin(self, menuitem, skeleton): skelcontext = skeletoncontext.skeletonContexts[skeleton] skelcontext.pinnednodes.undo() skelcontext.pinnednodes.signal() def redoPin(self, menuitem, skeleton): skelcontext = skeletoncontext.skeletonContexts[skeleton] skelcontext.pinnednodes.redo() skelcontext.pinnednodes.signal() tip="Pin nodes." discussion="""<para> Pinned nodes are immobile during &skel; modifications. This menu contains tools for pinning and unpinning nodes with mouse input. </para>""" toolbox.registerToolboxClass(PinnedNodesToolbox, ordering=2.7)