Beispiel #1
0
        def checktest(self, *args, **kwargs):
            # Run the test function.
            val = func(self, *args, **kwargs)
            # After running the function, delete the microstructures.
            from ooflib.common.IO.mainmenu import OOF
            for msname in _microstructures:
                OOF.Microstructure.Delete(microstructure=msname)
            # Exceptions can hold references to data.  Since this file
            # tests for exceptions as well as memory leaks, it's
            # important to clear the exception state before checking
            # for leaks.
            sys.exc_clear()
            gc.collect()

            from ooflib.common.worker import allWorkers, allWorkerCores
            from ooflib.common.IO import whoville
            from ooflib.SWIG.common import cmicrostructure
            from ooflib.SWIG.common import threadstate
            from ooflib.SWIG.engine import cskeleton
            from ooflib.SWIG.engine import csubproblem
            from ooflib.SWIG.engine import femesh
            from ooflib.SWIG.engine import linearizedsystem

            self.assertEqual(whoville.getClass("Microstructure").nActual(), 0)
            self.assertEqual(whoville.getClass("Image").nActual(), 0)
            self.assertEqual(whoville.getClass("Skeleton").nActual(), 0)
            self.assertEqual(whoville.getClass("Mesh").nActual(), 0)
            self.assertEqual(whoville.getClass("SubProblem").nActual(), 0)
            self.assertEqual(linearizedsystem.get_globalLinSysCount(),0)
            self.assertEqual(cmicrostructure.get_globalMicrostructureCount(), 0)
            self.assertEqual(femesh.get_globalFEMeshCount(), 0)
            self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0)
            self.assertEqual(cskeleton.get_globalNodeCount(), 0)
            self.assertEqual(cskeleton.get_globalElementCount(), 0)
            self.assertEqual(len(allWorkers), 0)
            ## TODO: For some reason, on some systems there is
            ## occasionally a leftover WorkerCore when this check is
            ## run.  It doesn't seem to have any references,
            ## though... Since there are no extra ThreadStates, we're
            ## ignoring the leftover WorkerCore for now.
#             if len(allWorkerCores) > 0:
#                 from ooflib.common import debug
#                 debug.set_debug_mode()
#                 print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\
#                     "id=", id(allWorkerCores.keys()[0])
#                 debug.dumpReferrers(allWorkerCores.keys()[0], 2)
#             self.assertEqual(len(allWorkerCores), 0)

            # The main thread still exists, but all subthreads should
            # have finished.
            self.assertEqual(threadstate.nThreadStates(), 1)
            print >> sys.stderr, "Memory leak check passed."
            return val
Beispiel #2
0
    def lockAndDelete(self):
        self.reserve()
        ms = self.getObject()
        try:
            # We have to remove Images, etc, from the Microstructure
            # *before* acquiring the write-lock on the Microstructure,
            # because we can't obtain the write locks on the Image and
            # the Microstructure at the same time.  (An Image can't be
            # locked unless it can obtain its Microstructure's read
            # lock.)
            for imagename in ms.imageNames():
                image = whoville.getClass('Image')[[self.name(), imagename]]
                image.begin_writing()
                try:
                    image.removeMicrostructure(ms)
                    ms.removeImage(image)
                finally:
                    image.end_writing()
            aa = activearea.activeareaWhoClass[self.name()]
            aa.begin_writing()
            try:
                activearea.activeareaWhoClass.remove(aa.name())
            finally:
                aa.end_writing()
            aa.setParent(None)
            pixsel = pixelselection.pixelselectionWhoClass[self.name()]
            pixsel.begin_writing()
            try:
                pixelselection.pixelselectionWhoClass.remove(pixsel.name())
            finally:
                pixsel.end_writing()
            pixsel.setParent(None)

            # Remove Skeletons
            skelclass = whoville.getClass('Skeleton')
            # TODO 3D: Remove this when engine is added to 3d
            if skelclass is not None:
                for skeletonname in skelclass.keys(base=self.name()):
                    skelcontext = skelclass[[self.name(), skeletonname[0]]]
                    skelcontext.lockAndDelete()
                    skelcontext.setParent(None)
            self.begin_writing()
            try:
                microStructures.remove(self.name())
                ms.destroy()
            finally:
                self.end_writing()
        finally:
            self.cancel_reservation()
Beispiel #3
0
def _new_group(menuitem, skeleton, name):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if groupset.isGroup(name):
        raise ooferror.ErrUserError("Group %s already exists." % group)
    else:
        groupset.addGroup(name)
Beispiel #4
0
 def Create_From_Image(self):
     from ooflib.common import primitives
     OOF.Microstructure.Create_From_ImageFile(
         filename=reference_file("ms_data","small.ppm"),
         microstructure_name=automatic,
         height=20.0, width=20.0)
     OOF.Microstructure.Create_From_Image(
         name="new", width=automatic, height=automatic,
         image="small.ppm:small.ppm")
     ms_0 = getMicrostructure("small.ppm")
     ms_1 = getMicrostructure("new")
     # Ensure images are separate objects.
     imageclass = whoville.getClass('Image')
     ms_1_image_id = id(ms_1.getImageContexts()[0])
     # Make sure the image wasn't copied in the source microstructure.
     self.assertEqual(len(ms_0.imageNames()), 1)
     # Make sure the newly constructed microstructure is the right size.
     self.assertEqual(ms_1.sizeInPixels(), primitives.iPoint(150,150))
     self.assertEqual(ms_1.size(), primitives.Point(20.0, 20.0))
     self.assertEqual(ms_1.sizeOfPixels(), (20.0/150, 20.0/150))
     OOF.Microstructure.Delete(microstructure="small.ppm")
     # Ensure that after the originating microstructure has been
     # deleted, the derived one still has the same image.
     self.assert_("small.ppm" in ms_1.imageNames())
     self.assertEqual(ms_1_image_id, id(ms_1.getImageContexts()[0]))
Beispiel #5
0
def _copy_group(menuitem, skeleton, group, new_name):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if groupset.isGroup(new_name):
        raise ooferror.ErrUserError("Group %s already exists." % new_name)
    if groupset.isGroup(group):
        groupset.copyGroup(group, new_name)
Beispiel #6
0
def _auto_group(menuitem, skeleton):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    ms = skelc.getMicrostructure()      # ms object, not context
    mscontext = microstructure.microStructures[ms.name()]
    mscontext.begin_reading()
    # gdict is a dict of lists of objects to add to each group, keyed
    # by group name
    gdict = {}
    try:
        # Create groups
        groupnames = ms.groupNames()    # all pixel group names in ms
        newgrps = [name for name in groupnames if not groupset.isGroup(name)]
        groupset.addGroup(*newgrps)
        # Find objects to add to groups
        for obj in menuitem.iterator(skelc.getObject().sheriffSkeleton()):
            cat = obj.dominantPixel(ms) # dominant pxl category
            repPix = ms.getRepresentativePixel(cat) # representative pixel
            # grplist contains all pixel group names at the repr. pixel
            grplist = pixelgroup.pixelGroupNames(ms, repPix)
            for name in grplist:
                gdict.setdefault(name, []).append(obj)

        # Actually add objects to groups
        groupset.addToGroup(**gdict)
    finally:
        mscontext.end_reading()
Beispiel #7
0
def _remove_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    else:
        groupset.removeGroup(group)
Beispiel #8
0
def imageNameResolver(param, startname):
    if param.automatic():
        basename = param.group['image'].value
    else:
        basename = startname
    imagename = labeltree.makePath(basename)[-1]
    msname = labeltree.makePath(param.group['microstructure'].value)[0]
    return whoville.getClass('Image').uniqueName([msname, imagename])
Beispiel #9
0
def whoNameCheck(whoclass, names):
    from ooflib.common.IO import whoville
    classmembers = whoville.getClass(whoclass).actualMembers()
    if len(classmembers) != len(names):
        return False
    for whoobj in classmembers:
        if whoobj.name() not in names:
            return False
    return True
Beispiel #10
0
 def __init__(self, value=None, scope=None, name=None):
     whowidget.WhoParameterWidget.__init__(
         self,
         whoclass=whoville.getClass("Microstructure"),
         value=value,
         scope=scope,
         name=name,
         condition=_withoutOrientationMap,
     )
    def getSourceObject(self, params, gfxwindow):
        # We're expecting a MicroStructure or an Image.

        # params is a dictionary of parameter values that was passed
        # to the menu item that was automatically created from a
        # PixelSelectionRegistration by
        # GenericSelectToolbox.rebuildMenus().  rebuildMenus() used
        # the derived sourceParams function to add the 'source'
        # 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]
Beispiel #12
0
 def __call__(self, ms, selection):
     curselection = selection.getObject()
     # 'cause my teeth are perly...
     image = whoville.getClass('Image')[self.image]
     imageobj = image.getObject()
     ms = image.getMicrostructure()
     selection.start()
     selection.clearAndSelect(
         pixelselectioncourieri.ColorSelection(ms, imageobj,
                                               self.reference, self.range))
Beispiel #13
0
def _sensitize(path):
    msclass = whoville.getClass('Microstructure')
    # If this module was somehow loaded first, the Microstructure
    # class might not be defined.
    if msclass and msclass.nActual() > 0:
        orientmapmenu.enable()
        mainmenu.OOF.File.Load.OrientationMap.enable()
    else:
        orientmapmenu.disable()
        mainmenu.OOF.File.Load.OrientationMap.disable()
Beispiel #14
0
def skeletonElementSelectionCheck(skeleton, elemlist):
    from ooflib.common.IO import whoville
    sc = whoville.getClass('Skeleton')[skeleton]
    elems = sc.elementselection.retrieve()
    elemindices = [el.index for el in elems]
    elemindices.sort()
    elemlist.sort()
    ok = (elemindices == elemlist)
    if not ok:
        print >> sys.stderr, elemindices
    return ok
Beispiel #15
0
def skeletonSegmentSelectionCheck(skeleton, seglist):
    from ooflib.common.IO import whoville
    sc = whoville.getClass('Skeleton')[skeleton]
    segs = sc.segmentselection.retrieve()
    nodepairs = [[n.index for n in seg.nodes()] for seg in segs]
    nodepairs.sort()
    seglist.sort()
    ok = nodepairs == seglist
    if not ok:
        print >> sys.stderr, nodepairs
    return ok
Beispiel #16
0
def skeletonNodeSelectionCheck(skeleton, nodelist):
    from ooflib.common.IO import whoville
    sc = whoville.getClass('Skeleton')[skeleton]
    nodes = sc.nodeselection.retrieve()
    nodeindices = [node.index for node in nodes]
    nodeindices.sort()
    nodelist.sort()
    ok = (nodeindices == nodelist)
    if not ok:
        print >> sys.stderr, nodeindices
    return ok
Beispiel #17
0
def _imageNameResolver(param, startname):
    msname = labeltree.makePath(param.group['microstructure'].value)[0]
    if param.automatic():
        # The automatic name for an image created from orientation
        # data is the filename of the data, minus any directory path
        # or suffix that it might have.
        msobj = ooflib.common.microstructure.microStructures[msname].getObject()
        basename = os.path.splitext(os.path.split(
            orientmapdata.getOrientationMapFile(msobj))[1])[0]
    else:
        basename = startname
    return whoville.getClass('Image').uniqueName([msname, basename])
Beispiel #18
0
 def changeDisplayedObject(self, category, object):
     if not LayerEditor.recursionInhibitor:
         LayerEditor.recursionInhibitor = 1
         self.currentWhoClass = whoville.getClass(category)
         if self.currentWhoClass is not None:
             try:
                 who = self.currentWhoClass[object]
             except KeyError:
                 who = None
         else:
             who = None
         self.currentLayerSet.changeWho(who)
         self.updateEditee()
         LayerEditor.recursionInhibitor = 0
Beispiel #19
0
 def buildWidget(self):
     debug.mainthreadTest()
     if self.whopwidget:
         self.whopwidget.destroy()
     self.whoclassname = self.classwidget.get_value()
     whoclass = whoville.getClass(self.whoclassname)
     # Create a WhoWidget that doesn't exclude proxy who
     # objects. If it's necessary to create an
     # AnyWhoParameterWidget with a different exclusion policy,
     # then the AnyWhoParameter will need to have a 'condition'
     # attribute that can be passed in to the widget.
     self.whopwidget = WhoParameterWidget(whoclass, scope=self,
                                          sort=whoville.proxiesLast,
                                          condition=lambda x:1)
     self.gtk.pack_start(self.whopwidget.gtk)
     self.gtk.show_all()
Beispiel #20
0
def buildImageModMenu():
    imagemodmenu.clearMenu()
    for registration in imagemodifier.ImageModifier.registry:
        try:
            help = registration.tip
        except AttributeError:
            help = None
        params = [whoville.WhoParameter('image', whoville.getClass('Image'),
                                        tip=parameter.emptyTipString)] \
                 + registration.params
        menuitem = imagemodmenu.addItem(
            oofmenu.OOFMenuItem(registration.name(),
                                callback=imagemodifier.doImageMod,
                                params=params,
                                help=help,
                                discussion=registration.discussion))
        menuitem.data = registration
Beispiel #21
0
def _query_elem_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    members = skelc.elementgroups.get_group(group)
    area = 0.0
    homog = 0.0
    for element in members:
        area += element.area()
        homog += element.homogeneity(skelc.getObject().MS)
    if len(members):
        homog /= len(members)
    plural="s"*(len(members)!=1)
    strings = ["Group '%s'" % group,
               "%d element%s" % (len(members), "s"*(len(members)!=1)),
               "area=%s" % area,
               "average homogeneity=%g" % homog]

    matl = skelc.elementgroups.getMaterial(group)
    if matl is not None:
        strings.append("material=%s" % matl.name())
    reporter.report(", ".join(strings))
Beispiel #22
0
    def sensitize_thread(self, skelselected, undoable, redoable, not_illegal):
        debug.mainthreadTest()
        self.okbutton.set_sensitive(skelselected and self.skelmod.isValid()
                                    and not_illegal)
        self.undobutton.set_sensitive(undoable)
        self.redobutton.set_sensitive(redoable)
        
        msclass = whoville.getClass('Microstructure')
        havems = msclass is not None and msclass.nActual() > 0
        self.newbutton.set_sensitive(havems)
        self.simplebutton.set_sensitive(havems)
        self.autobutton.set_sensitive(havems)
        self.deletebutton.set_sensitive(skelselected)
        self.renamebutton.set_sensitive(skelselected)
        self.copybutton.set_sensitive(skelselected)
        self.savebutton.set_sensitive(skelselected)

        if not self.getSkeletonAvailability():
            self.okbutton.set_sensitive(0)
            self.undobutton.set_sensitive(0)
            self.redobutton.set_sensitive(0)
        self.sensitizeHistory_thread()
        gtklogger.checkpoint("skeleton page sensitized")
Beispiel #23
0
def loadImageIntoMS(image, microstructure):
    # 'image' is an OOFImage object.
    # 'microstructure' is a Microstructure name.
    
    # See if the Microstructure already exists
    msclass = whoville.getClass('Microstructure')
    try:                            # look for existing microstructure
        ms = msclass[microstructure] # Who object
    except KeyError:
        msobj = ooflib.common.microstructure.Microstructure(microstructure,
                                                     image.sizeInPixels(),
                                                     image.size())
        ms = msclass.add(microstructure, msobj, parent=None)

    # Check size of microstructure
    if ms.getObject().sizeInPixels() != image.sizeInPixels():
        raise ooferror.ErrUserError("Cannot load an image into an existing Microstructure of a different size.")

    # See if the image name is unique in the Microstructure
    newname = imagecontext.imageContexts.uniqueName([ms.name(), image.name()])
    image.rename(newname)
    # Create ImageContext object
    immidgecontext = imagecontext.imageContexts.add([ms.name(),newname], image,
                                              parent=ms)
Beispiel #24
0
def activeVolumeOverrideCheck(o):
    from ooflib.common.IO import whoville
    ms = whoville.getClass('Microstructure')['5color'].getObject()
    return ms.activearea.getOverride() == o
Beispiel #25
0
def _query_sgmt_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    members = skelc.segmentgroups.get_group(group)
    plural = "s" * (len(members) != 1)
    reporter.report(">>> ", len(members), " segment" + plural)
Beispiel #26
0
def _remove_matl(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.removeMaterial(group)
Beispiel #27
0
def _clear_all_groups(menuitem, skeleton):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.clearGroup(*groupset.allGroups())
Beispiel #28
0
def _rename_group(menuitem, skeleton, group, new_name):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.renameGroup(group, new_name)
Beispiel #29
0
def _query_sgmt_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    members = skelc.segmentgroups.get_group(group)
    plural="s"*(len(members)!=1)
    reporter.report(">>> ", len(members), " segment"+plural )
Beispiel #30
0
def _rename_group(menuitem, skeleton, group, new_name):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.renameGroup(group, new_name)
    switchboard.notify("redraw")        
Beispiel #31
0
    # Gets the default name from the object being copied (or renamed).
    def getBasename(self, param, startname):
        if param.automatic():
            return param.group['group'].value
        return startname
    
#######################################    

# Node-specific menu items:

new = oofmenu.OOFMenuItem(
    "New_Group",
    cli_only=1,
    callback=_new_group,
    params=parameter.ParameterGroup(
    whoville.WhoParameter("skeleton", whoville.getClass('Skeleton'),
                          tip=parameter.emptyTipString),
    AutomaticNameParameter("name", value=automatic.automatic,
                           resolver=NewGroupNameResolver("nodegroup",
                                                         "nodegroups"),
                           tip="Name of the group to be created.")),
    help="Create a new node group.",
    discussion=xmlmenudump.loadFile('DISCUSSIONS/engine/menu/newnodegroup.xml')
    )
new.data = "nodegroups"
nodegroupmenu.addItem(new)

auto = oofmenu.OOFMenuItem(
    "Auto_Group",
    cli_only=1,
    callback=_auto_group,
Beispiel #32
0
    def __init__(self):
        oofGUI.MainPage.__init__(self,
                                 name="Pin Nodes",
                                 ordering=120.1,
                                 tip='Pin and unpin nodes')

        mainbox = gtk.VBox(spacing=2)
        self.gtk.add(mainbox)

        align = gtk.Alignment(xalign=0.5)
        mainbox.pack_start(align, expand=0, fill=0)
        centerbox = gtk.HBox(spacing=3)
        align.add(centerbox)
        self.skelwidget = whowidget.WhoWidget(whoville.getClass('Skeleton'),
                                              callback=self.select_skeletonCB)
        label = gtk.Label('Microstructure=')
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.skelwidget.gtk[0], expand=0, fill=0)
        label = gtk.Label('Skeleton=')
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.skelwidget.gtk[1], expand=0, fill=0)

        mainpane = gtk.HPaned()
        gtklogger.setWidgetName(mainpane, 'Pane')
        mainbox.pack_start(mainpane, expand=1, fill=1)
        gtklogger.connect_passive(mainpane, 'notify::position')

        # Pinned nodes status in the left half of the main pane
        pnsframe = gtk.Frame("Pinned Nodes Status")
        pnsframe.set_shadow_type(gtk.SHADOW_IN)
        self.datascroll = gtk.ScrolledWindow()
        gtklogger.logScrollBars(self.datascroll, "StatusScroll")
        pnsframe.add(self.datascroll)
        self.datascroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.psdata = fixedwidthtext.FixedWidthTextView()
        self.psdata.set_editable(False)
        self.psdata.set_wrap_mode(gtk.WRAP_WORD)
        self.psdata.set_cursor_visible(False)
        self.datascroll.add_with_viewport(self.psdata)
        mainpane.pack1(pnsframe, resize=1, shrink=0)

        # Pin nodes method
        modframe = gtk.Frame("Pin Nodes Methods")
        gtklogger.setWidgetName(modframe, 'Modify')
        modframe.set_shadow_type(gtk.SHADOW_IN)
        modbox = gtk.VBox()  # will have "methods" and "buttons"
        modframe.add(modbox)
        self.pinModFactory = regclassfactory.RegisteredClassFactory(
            pinnodesmodifier.PinNodesModifier.registry,
            title="Method:",
            scope=self,
            name="Method")
        modbox.pack_start(self.pinModFactory.gtk, expand=1, fill=1, padding=2)

        # buttons
        hbox1 = gtk.HBox()
        modbox.pack_start(hbox1, expand=0, fill=0, padding=2)
        self.okbutton = gtk.Button(stock=gtk.STOCK_OK)
        gtklogger.setWidgetName(self.okbutton, 'OK')
        gtklogger.connect(self.okbutton, "clicked", self.okCB)
        tooltips.set_tooltip_text(self.okbutton,
                                  "Pin nodes with the selected method.")
        self.undobutton = gtk.Button(stock=gtk.STOCK_UNDO)
        gtklogger.setWidgetName(self.undobutton, 'Undo')
        gtklogger.connect(self.undobutton, "clicked", self.undoCB)
        tooltips.set_tooltip_text(self.undobutton, "Undo the latest action.")
        self.redobutton = gtk.Button(stock=gtk.STOCK_REDO)
        gtklogger.setWidgetName(self.redobutton, 'Redo')
        gtklogger.connect(self.redobutton, "clicked", self.redoCB)
        tooltips.set_tooltip_text(self.redobutton,
                                  "Redo the latest undone action.")
        hbox1.pack_start(self.undobutton, expand=0, fill=1, padding=2)
        hbox1.pack_start(self.okbutton, expand=1, fill=1, padding=2)
        hbox1.pack_end(self.redobutton, expand=0, fill=1, padding=2)

        hbox2 = gtk.HBox(homogeneous=1)
        modbox.pack_start(hbox2, expand=0, fill=0, padding=2)
        self.unpinallbutton = gtk.Button("Unpin All")
        gtklogger.setWidgetName(self.unpinallbutton, 'Unpin All')
        gtklogger.connect(self.unpinallbutton, "clicked", self.unpinallCB)
        tooltips.set_tooltip_text(self.unpinallbutton,
                                  "Unpin all the pinned nodes.")
        self.invertbutton = gtk.Button("Invert")
        gtklogger.setWidgetName(self.invertbutton, 'Invert')
        gtklogger.connect(self.invertbutton, "clicked", self.invertCB)
        tooltips.set_tooltip_text(
            self.invertbutton,
            "Invert - pin the unpinned and unpin the pinned.")
        hbox2.pack_start(self.unpinallbutton, expand=1, fill=1, padding=2)
        hbox2.pack_start(self.invertbutton, expand=1, fill=1, padding=2)

        mainpane.pack2(modframe, resize=0, shrink=0)

        # Switchboard callbacks
        switchboard.requestCallbackMain(('who changed', 'Skeleton'),
                                        self.changeSkeleton)
        switchboard.requestCallbackMain(('new who', 'Microstructure'),
                                        self.newMS)
        switchboard.requestCallbackMain("new pinned nodes",
                                        self.newNodesPinned)
        switchboard.requestCallbackMain(self.skelwidget, self.skel_update)
        switchboard.requestCallbackMain("made reservation",
                                        self.reservationChanged)
        switchboard.requestCallbackMain("cancelled reservation",
                                        self.reservationChanged)
Beispiel #33
0
def skeletonSizeCheck(skeleton, nel, nnode):
    from ooflib.common.IO import whoville
    skel = whoville.getClass('Skeleton')[skeleton].getObject()
    return skel.nelements() == nel and skel.nnodes() == nnode
Beispiel #34
0
def skeletonElementSelectionSizeCheck(skeleton, n):
    from ooflib.common.IO import whoville
    sc = whoville.getClass('Skeleton')[skeleton]
    return sc.elementselection.size() == n
Beispiel #35
0
        def checktest(self, *args, **kwargs):
            # Run the test function.
            try:
                val = func(self, *args, **kwargs)
            finally:
                # After running the function, delete the microstructures.
                from ooflib.common.IO.mainmenu import OOF
                for msname in _microstructures:
                    OOF.Microstructure.Delete(microstructure=msname)
                # Exceptions can hold references to data.  Since this file
                # tests for exceptions as well as memory leaks, it's
                # important to clear the exception state before checking
                # for leaks.
                sys.exc_clear()
                gc.collect()

            from ooflib.common.worker import allWorkers, allWorkerCores
            from ooflib.common.IO import whoville
            from ooflib.SWIG.common import config
            from ooflib.SWIG.common import cmicrostructure
            from ooflib.SWIG.common import threadstate
            if config.dimension() == 2:
                from ooflib.SWIG.engine.cskeleton import get_globalNodeCount
                from ooflib.SWIG.engine.cskeleton import get_globalElementCount
            else:
                from ooflib.SWIG.engine.cskeletonnode2 import get_globalNodeCount
                from ooflib.SWIG.engine.cskeletonface import get_globalFaceCount, get_globalOrientedFaceCount
                from ooflib.SWIG.engine.cskeletonelement import get_globalElementCount
                from ooflib.SWIG.engine.cskeletonselectable import getTrackerCount
            from ooflib.SWIG.engine import csubproblem
            from ooflib.SWIG.engine import femesh
            from ooflib.SWIG.engine import linearizedsystem
            from ooflib.SWIG.engine import sparsemat

            self.assertEqual(whoville.getClass("Microstructure").nActual(), 0)
            self.assertEqual(whoville.getClass("Image").nActual(), 0)
            self.assertEqual(whoville.getClass("Skeleton").nActual(), 0)
            self.assertEqual(whoville.getClass("Mesh").nActual(), 0)
            self.assertEqual(whoville.getClass("SubProblem").nActual(), 0)
            self.assertEqual(linearizedsystem.get_globalLinSysCount(), 0)
            self.assertEqual(cmicrostructure.get_globalMicrostructureCount(),
                             0)
            self.assertEqual(get_globalNodeCount(), 0)  # skeleton nodes
            self.assertEqual(get_globalFaceCount(), 0)  # skeleton faces
            self.assertEqual(get_globalOrientedFaceCount(), 0)
            self.assertEqual(get_globalElementCount(), 0)  # skeleton elements
            self.assertEqual(femesh.get_globalFEMeshCount(), 0)
            self.assertEqual(csubproblem.get_globalCSubProblemCount(), 0)
            self.assertEqual(getTrackerCount(), 0)
            self.assertEqual(sparsemat.nSparseMatCores(), 0)
            self.assertEqual(len(allWorkers), 0)
            ## TODO 3.1: For some reason, on some systems there is
            ## occasionally a leftover WorkerCore when this check is
            ## run.  It doesn't seem to have any references,
            ## though... Since there are no extra ThreadStates, we're
            ## ignoring the leftover WorkerCore for now.
            #             if len(allWorkerCores) > 0:
            #                 from ooflib.common import debug
            #                 debug.set_debug_mode()
            #                 print >> sys.stderr, "Referrers for", allWorkerCores.keys()[0],\
            #                     "id=", id(allWorkerCores.keys()[0])
            #                 debug.dumpReferrers(allWorkerCores.keys()[0], 2)
            #             self.assertEqual(len(allWorkerCores), 0)

            # The main thread still exists, but all subthreads should
            # have finished.
            self.assertEqual(threadstate.nThreadStates(), 1)
            print >> sys.stderr, "Memory leak check passed."
            return val
Beispiel #36
0
def _rename_group(menuitem, skeleton, group, new_name):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.renameGroup(group, new_name)
Beispiel #37
0
def _assign_matl(menuitem, skeleton, group, material):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
Beispiel #38
0
 def __init__(self, gfxwindow):
     toolbox.Toolbox.__init__(self, 'Pin_Nodes', gfxwindow)
     self.skeleton_param = whoville.WhoParameter(
         'skeleton',
         whoville.getClass('Skeleton'),
         tip=parameter.emptyTipString)
Beispiel #39
0
    def __init__(self):
        oofGUI.MainPage.__init__(self,
                                 name="Equations",
                                 ordering=220,
                                 tip="Define equations for the mesh to solve.")
        mainbox = gtk.VBox()
        self.gtk.add(mainbox)

        align = gtk.Alignment(xalign=0.5)
        mainbox.pack_start(align, expand=0, fill=0)
        centerbox = gtk.HBox(spacing=3)
        align.add(centerbox)
        self.subpwidget = whowidget.WhoWidget(whoville.getClass('SubProblem'),
                                              scope=self)
        switchboard.requestCallbackMain(self.subpwidget, self.subpwidgetCB)
        label = gtk.Label("Microstructure=")
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.subpwidget.gtk[0], expand=0, fill=0)
        label = gtk.Label("Skeleton=")
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.subpwidget.gtk[1], expand=0, fill=0)
        label = gtk.Label("Mesh=")
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.subpwidget.gtk[2], expand=0, fill=0)
        label = gtk.Label("SubProblem=")
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.subpwidget.gtk[3], expand=0, fill=0)

        eqnframe = gtk.Frame("Equations")
        eqnframe.set_shadow_type(gtk.SHADOW_IN)
        scroll = gtk.ScrolledWindow()
        gtklogger.logScrollBars(scroll, "Equations")
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        eqnframe.add(scroll)
        bbox = gtk.VBox(
        )  # extra layer keeps table from expanding inside scroll
        scroll.add_with_viewport(bbox)
        self.eqntable = gtk.Table()
        bbox.pack_start(self.eqntable, expand=0, fill=0)
        self.eqnbuttons = {}
        self.build_eqnTable()
        switchboard.requestCallbackMain("new equation", self.newEquationCB)
        switchboard.requestCallbackMain("equation activated",
                                        self.activateEqnCB)
        #         switchboard.requestCallbackMain("kinetics activated",
        #                                         self.activateKinCB)
        #         switchboard.requestCallbackMain("dynamics activated",
        #                                         self.activateDynCB)
        mainbox.pack_start(eqnframe, expand=1, fill=1)

        copybox = gtk.HBox(spacing=3)
        self.copybutton = gtk.Button("Copy Equation State")
        gtklogger.setWidgetName(self.copybutton, "Copy")
        gtklogger.connect(self.copybutton, "clicked", self.copyeqstateCB)
        copybox.pack_start(self.copybutton, expand=1, fill=0)
        mainbox.pack_start(copybox, expand=0, fill=0)
        tooltips.set_tooltip_text(
            self.copybutton,
            "Copy the status of all equations from the current mesh to another mesh."
        )

        switchboard.requestCallbackMain(("new who", "Microstructure"),
                                        self.newSkeletonOrMesh)
        switchboard.requestCallbackMain(("new who", "Skeleton"),
                                        self.newSkeletonOrMesh)
        switchboard.requestCallbackMain(("new who", "Mesh"),
                                        self.newSkeletonOrMesh)
        ##        switchboard.requestCallbackMain(("new who", "SubProblem"),
        ##                                        self.newSubProblem)
        ##        switchboard.requestCallbackMain(("remove who", "SubProblem"),
        ##                                        self.removeSubProblem)
        switchboard.requestCallbackMain("made reservation",
                                        self.reservationChanged)
        switchboard.requestCallbackMain("cancelled reservation",
                                        self.reservationChanged)
Beispiel #40
0
def pixelGroupSizeCheck(msname, grpname, n):
    from ooflib.common.IO import whoville
    ms = whoville.getClass('Microstructure')[msname].getObject()
    grp = ms.findGroup(grpname)
    return len(grp) == n
Beispiel #41
0
def _clear_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.clearGroup(group)
Beispiel #42
0
def makeMenu(menu, modifier, selection_name):
    menu.clearMenu()

    objname = selection_name[:-9]  # 'node', 'segment', or 'element'

    undo_item = menu.addItem(
        oofmenu.OOFMenuItem(
            "Undo",
            callback=_undo,
            params=[
                whoville.WhoParameter("skeleton",
                                      whoville.getClass('Skeleton'),
                                      tip=parameter.emptyTipString)
            ],
            help="Undo the latest Skeleton %s selection operation." % objname,
            discussion=xmlmenudump.loadFile(
                'DISCUSSIONS/engine/menu/%s_undo.xml' % objname)))
    undo_item.data = selection_name

    redo_item = menu.addItem(oofmenu.OOFMenuItem(
        "Redo", callback=_redo,
              params = [
        whoville.WhoParameter("skeleton",
                              whoville.getClass('Skeleton'),
                              tip=parameter.emptyTipString)],
        help="Redo the latest undone Skeleton %s selection operation."\
        % objname,
        discussion=xmlmenudump.loadFile('DISCUSSIONS/engine/menu/%s_redo.xml'
                                        % objname)
        ))
    redo_item.data = selection_name

    clear_item = menu.addItem(
        oofmenu.OOFMenuItem(
            "Clear",
            callback=_clear,
            params=[
                whoville.WhoParameter("skeleton",
                                      whoville.getClass('Skeleton'),
                                      tip=parameter.emptyTipString)
            ],
            help="Clear the current Skeleton %s selection." % objname,
            discussion="<para>Unselect all %ss in the &skel;.</para>" %
            objname))
    clear_item.data = selection_name

    invert_item = menu.addItem(
        oofmenu.OOFMenuItem(
            "Invert",
            callback=_invert,
            params=[
                whoville.WhoParameter("skeleton",
                                      whoville.getClass('Skeleton'),
                                      tip=parameter.emptyTipString)
            ],
            help="Invert the current Skeleton %s selection." % objname,
            discussion="""<para>
        Select the unselected %ss, and unselect the selected %ss in the &skel;.
        </para>""" % (objname, objname)))
    invert_item.data = selection_name

    for r in modifier.registry:
        # For help
        try:
            help = r.tip
        except AttributeError:
            help = None
        # For discussion
        try:
            discussion = r.discussion
        except AttributeError:
            discussion = None
        menuitem = menu.addItem(
            oofmenu.OOFMenuItem(
                utils.space2underscore(r.name()),
                callback=skeletonselectionmod.modify,
                params=[
                    whoville.WhoParameter("skeleton",
                                          whoville.getClass('Skeleton'),
                                          tip=parameter.emptyTipString)
                ] + r.params,
                help=help,
                discussion=discussion))
        menuitem.data = r
Beispiel #43
0
def _assign_matl(menuitem, skeleton, group, material):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        raise ooferror.ErrUserError("Group %s does not exist." % group)
    groupset.assignMaterial(group, materialmanager.getMaterial(material))
Beispiel #44
0
    def __init__(self):
        self.built = False

        oofGUI.MainPage.__init__(
            self,
            name="Interfaces",
            ordering=105,
            tip="Create named one-dimensional interfaces.")

        mainbox = gtk.VBox(spacing=2)
        self.gtk.add(mainbox)

        align = gtk.Alignment(xalign=0.5)
        mainbox.pack_start(align, expand=0, fill=0)
        centerbox = gtk.HBox(spacing=3)
        align.add(centerbox)

        #skelwidget is really an mswidget
        self.skelwidget = whowidget.WhoWidget(
            whoville.getClass('Microstructure'), scope=self)
        switchboard.requestCallbackMain(self.skelwidget, self.widgetChanged)
        label = gtk.Label('Microstructure=')
        label.set_alignment(1.0, 0.5)
        centerbox.pack_start(label, expand=0, fill=0)
        centerbox.pack_start(self.skelwidget.gtk[0], expand=0, fill=0)
        #We might want to include a skeleton in the widget, if an interface
        #is defined in terms of skeleton segments. For now the interface is
        #only associated with a microstructure
        ##        label = gtk.Label('Skeleton=')
        ##        label.set_alignment(1.0, 0.5)
        ##        centerbox.pack_start(label, expand=0, fill=0)
        ##        centerbox.pack_start(self.skelwidget.gtk[1], expand=0, fill=0)

        mainpane = gtk.HPaned()
        gtklogger.setWidgetName(mainpane, 'Pane')
        mainbox.pack_start(mainpane, expand=1, fill=1)

        interfacelistframe = gtk.Frame("Interfaces")
        gtklogger.setWidgetName(interfacelistframe, 'Interfaces')
        gtklogger.connect_passive(interfacelistframe, 'size-allocate')
        interfacelistframe.set_shadow_type(gtk.SHADOW_IN)
        mainpane.pack1(interfacelistframe, resize=0, shrink=0)

        interfacelistbox = gtk.VBox()
        interfacelistframe.add(interfacelistbox)

        # List of all the named interfaces
        self.interfacelist = chooser.ScrolledChooserListWidget(
            callback=self.interfacelistCB,
            ##            dbcallback=self.modifyBoundaryCB,
            autoselect=0,
            name="InterfaceList")
        interfacelistbox.pack_start(self.interfacelist.gtk, expand=1, fill=1)

        interfacebuttonbox = gtk.HBox(homogeneous=1, spacing=2)
        interfacelistbox.pack_start(interfacebuttonbox, expand=0, fill=0)

        # Buttons that actually do stuff.
        self.newbutton = gtk.Button("New...")
        gtklogger.setWidgetName(self.newbutton, 'New')
        gtklogger.connect(self.newbutton, "clicked", self.newInterfaceCB)
        tooltips.set_tooltip_text(
            self.newbutton,
            "Construct a new interface in the microstructure and associated meshes."
        )
        interfacebuttonbox.pack_start(self.newbutton, expand=1, fill=1)

        self.renamebutton = gtk.Button("Rename...")
        gtklogger.setWidgetName(self.renamebutton, 'Rename')
        gtklogger.connect(self.renamebutton, "clicked", self.renameInterfaceCB)
        tooltips.set_tooltip_text(self.renamebutton,
                                  "Rename the selected interface.")
        interfacebuttonbox.pack_start(self.renamebutton, expand=1, fill=1)

        self.deletebutton = gtk.Button("Delete")
        gtklogger.setWidgetName(self.deletebutton, 'Delete')
        gtklogger.connect(self.deletebutton, "clicked", self.deleteInterfaceCB)
        tooltips.set_tooltip_text(
            self.deletebutton,
            "Delete the selected interface from the microstructure and associated meshes."
        )
        interfacebuttonbox.pack_start(self.deletebutton, expand=1, fill=1)

        ########## Adding and removing interface materials
        materialbuttonbox = gtk.HBox(homogeneous=1, spacing=2)
        interfacelistbox.pack_start(materialbuttonbox, expand=0, fill=0)
        self.assignmatbutton = gtk.Button("Assign interface material...")
        gtklogger.setWidgetName(self.assignmatbutton, 'Assign material')
        gtklogger.connect(self.assignmatbutton, "clicked", self.assignmatCB)
        tooltips.set_tooltip_text(self.assignmatbutton,
                                  "Assign material to interface.")
        materialbuttonbox.pack_start(self.assignmatbutton, expand=1, fill=1)

        self.removematbutton = gtk.Button("Remove material")
        gtklogger.setWidgetName(self.removematbutton, 'Remove material')
        gtklogger.connect(self.removematbutton, "clicked", self.removematCB)
        tooltips.set_tooltip_text(self.removematbutton,
                                  "Remove material from interface.")
        materialbuttonbox.pack_start(self.removematbutton, expand=1, fill=1)
        ####################################

        infoframe = gtk.Frame("Interface details")
        infoframe.set_shadow_type(gtk.SHADOW_IN)
        mainpane.pack2(infoframe, resize=1, shrink=1)

        infowindow = gtk.ScrolledWindow()
        gtklogger.logScrollBars(infowindow, "InfoScroll")
        infowindow.set_shadow_type(gtk.SHADOW_IN)
        infoframe.add(infowindow)
        infowindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

        self.infotext = fixedwidthtext.FixedWidthTextView()
        self.infotext.set_wrap_mode(gtk.WRAP_WORD)
        gtklogger.setWidgetName(self.infotext, 'status')
        self.infotext.set_editable(False)
        infowindow.add(self.infotext)

        self.built = True

        switchboard.requestCallbackMain("new interface created",
                                        self.newInterfaceUpdatePageCB)
        switchboard.requestCallbackMain("interface removed",
                                        self.newInterfaceUpdatePageCB)
        switchboard.requestCallbackMain("interface renamed",
                                        self.newInterfaceUpdatePageCB),
        ##        switchboard.requestCallbackMain("remove_material",self.del_mat)
        #TODO: Enable something like this later?
        ##        switchboard.requestCallbackMain(("new who", "Microstructure"),
        ##                                        self.newMicrostructureCB)

        self.selectsignals = [
            switchboard.requestCallbackMain("interface selected",
                                            self.interfaceSelectedCB),
            switchboard.requestCallbackMain("interface unselected",
                                            self.interfaceUnselectedCB)
        ]
Beispiel #45
0
 def __call__(self, param, startname):
     skelname = param.group['skeleton'].value
     skelcontext = whoville.getClass('Skeleton')[skelname]
     groupset = getattr(skelcontext, self.attrname)
     return utils.uniqueName(self.getBasename(param, startname),
                             list(groupset.allGroups()))
Beispiel #46
0
 def __init__(self, name, value=None, default=None, tip=None):
     whoville.WhoParameter.__init__(self, name,
                                    whoville.getClass('Microstructure'),
                                    value=value, default=default, tip=tip)
Beispiel #47
0
def pixelSelectionSizeCheck(msname, n):
    from ooflib.common.IO import whoville
    ms = whoville.getClass('Microstructure')[msname].getObject()
    return ms.pixelselection.size() == n
Beispiel #48
0
if config.dimension() == 2:

    def loadImage(menuitem, filename, microstructure, height, width):
        if filename:
            # Read file and create an OOFImage object
            image = autoReadImage(filename, height, width, depth=0)
            loadImageIntoMS(image, microstructure)
            switchboard.notify("redraw")

    imageparams = parameter.ParameterGroup(
        filenameparam.ReadFileNameParameter('filename',
                                            'image',
                                            tip="Name of the image file."),
        whoville.WhoParameter('microstructure',
                              whoville.getClass('Microstructure'),
                              tip=parameter.emptyTipString))

elif config.dimension() == 3:

    def loadImage(menuitem, filenames, microstructure, height, width, depth):
        if filenames:
            # Read file and create an OOFImage3D object
            image = autoReadImage(filenames, height, width, depth)
            loadImageIntoMS(image, microstructure)
            switchboard.notify("redraw")

    imageparams = parameter.ParameterGroup(
        parameter.RegisteredParameter("filenames",
                                      oofimage.ThreeDImageSpecification),
        whoville.WhoParameter('microstructure',
Beispiel #49
0
def pinnedNodesSkelCheck(skelname, n):
    from ooflib.common.IO import whoville
    skelctxt = whoville.getClass('Skeleton')[skelname]
    return skelctxt.pinnednodes.npinned() == n
Beispiel #50
0
        if param.automatic():
            return param.group['group'].value
        return startname


#######################################

# Node-specific menu items:

new = oofmenu.OOFMenuItem(
    "New_Group",
    cli_only=1,
    callback=_new_group,
    params=parameter.ParameterGroup(
        whoville.WhoParameter("skeleton",
                              whoville.getClass('Skeleton'),
                              tip=parameter.emptyTipString),
        AutomaticNameParameter("name",
                               value=automatic.automatic,
                               resolver=NewGroupNameResolver(
                                   "nodegroup", "nodegroups"),
                               tip="Name of the group to be created.")),
    help="Create a new node group.",
    discussion=xmlmenudump.loadFile(
        'DISCUSSIONS/engine/menu/newnodegroup.xml'))
new.data = "nodegroups"
nodegroupmenu.addItem(new)

auto = oofmenu.OOFMenuItem(
    "Auto_Group",
    cli_only=1,
Beispiel #51
0
def _remove_selection_from_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.removeSelectionFromGroup(group)
Beispiel #52
0
def _remove_all_groups(menuitem, skeleton):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.removeGroup(*groupset.allGroups().copy())
Beispiel #53
0
def _clear_all_groups(menuitem, skeleton):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.clearGroup(*groupset.allGroups())
Beispiel #54
0
def _add_selection_to_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    if not groupset.isGroup(group):
        groupset.addGroup(group)
    groupset.addSelectionToGroup(group)
Beispiel #55
0
 def __call__(self, param, startname):
     skelname = param.group['skeleton'].value
     skelcontext = whoville.getClass('Skeleton')[skelname]
     groupset = getattr(skelcontext, self.attrname)
     return utils.uniqueName(self.getBasename(param, startname),
                             list(groupset.allGroups()))
Beispiel #56
0
def _remove_selection_from_group(menuitem, skeleton, group):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.removeSelectionFromGroup(group)
Beispiel #57
0
def _clear_all_groups(menuitem, skeleton):
    skelc = whoville.getClass('Skeleton')[skeleton]
    groupset = getattr(skelc, menuitem.data)
    groupset.clearGroup(*groupset.allGroups())
    switchboard.notify("redraw")
Beispiel #58
0
def countMSGroups(msname):
    from ooflib.common.IO import whoville
    ms = whoville.getClass('Microstructure')[msname].getObject()
    return len(ms.groupNames())
Beispiel #59
0
def nIllegalElements():
    from ooflib.common.IO import whoville
    sc = whoville.getClass('Skeleton')['triangle.png:skeleton']
    return sc.getObject().getIllegalCount()
Beispiel #60
0
        image = whoville.getClass('Image')[self.image]
        imageobj = image.getObject()
        ms = image.getMicrostructure()
        self.operator.operate(
            selection,
            pixelselectioncourieri.ColorSelection(ms, imageobj, self.reference,
                                                  self.range))


pixelselection.VoxelSelectionModRegistration(
    'Color Range',
    ColorRange,
    ordering=3.14,
    params=[
        whoville.WhoParameter('image',
                              whoville.getClass('Image'),
                              tip=parameter.emptyTipString),
        color.NewColorParameter('reference', tip='Reference color.'),
        colordiffparameter.ColorDifferenceParameter(
            'range', tip='Deviation from the reference color.'),
        selectionoperators.SelectionOperatorParam('operator')
    ],
    tip="Select all pixels similar to a reference color.",
    discussion="""<para>

    Select all pixels in an &image; within a given
    <varname>range</varname> of a given <varname>refererence</varname>
    color.  This command basically does the same thing that <xref
    linkend='MenuItem:OOF.Graphics_n.Toolbox.Pixel_Select.Color'/>
    does except the latter takes its <varname>reference</varname>
    input from a mouse click in the Graphics window.