Example #1
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])
Example #2
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])
Example #3
0
def parallel_femesh(menuitem, name, skeleton, D_typename, T_typename,
                    Q_typename):
    # Build edict map. Access masterelement dictionary directly
    MEdict = masterelement.getMasterElementDict()
    edict = {
        MEdict[D_typename].nsides(): MEdict[D_typename],
        MEdict[T_typename].nsides(): MEdict[T_typename],
        MEdict[Q_typename].nsides(): MEdict[Q_typename]
    }
    skelpath = labeltree.makePath(skeleton)
    skel = skeletoncontext.skeletonContexts[skelpath].getObject()
    femesh = skel.femesh_shares(edict,
                                skeletonelement.SkeletonElement.realmaterial)
    if _rank == 0:
        femesh.all_meshskeletons = skel.all_skeletons
    #collect_pieces(femesh)
    if femesh is not None:
        meshctxt = ooflib.engine.mesh.meshes.add(
            skelpath + [name],
            femesh,
            parent=skeletoncontext.skeletonContexts[skelpath],
            skeleton=skel,
            elementdict=edict,
            materialfactory=skeletonelement.SkeletonElement.realmaterial)
        meshctxt.createDefaultSubProblem()
Example #4
0
 def set_state(self, subppath):
     debug.mainthreadTest()
     path = labeltree.makePath(subppath)
     self.subpwidget.set_value(path)
     # Retrieve the subproblem from the widget, just in case
     # subppath wasn't a complete subproblem path.
     subpctxt = self.currentSubProblemContext()
     if subpctxt:           # ie, path was complete
         subp = subpctxt.getObject() # CSubProblem object
         mesh = self.currentMesh()
         for fname,fld in allCompoundFields.items():
             fdef = subp.is_defined_field(fld)
             self.fieldbuttons[(fname, "defined")].set(fdef)
             self.fieldbuttons[(fname, "active")].set_sensitive(fdef)
             if config.dimension() == 2:
                 self.fieldbuttons[(fname, "inplane")].set_sensitive(fdef)
             if fdef:
                 self.fieldbuttons[(fname, "active")].set(
                     subp.is_active_field(fld))
                 if config.dimension() == 2:
                     self.fieldbuttons[(fname, "inplane")].set(
                         mesh.in_plane(fld))
             else:                   # field not defined
                 self.fieldbuttons[(fname, "active")].set(0)
                 if config.dimension() == 2:
                     self.fieldbuttons[(fname, "inplane")].set(0)
         for eqn in equation.allEquations:
             active = subp.is_active_equation(eqn)
             self.eqnbuttons[(eqn.name(),"active")].set(active)
     else:                           # no current subproblem
         for button in self.fieldbuttons.values():
             button.set(0)
         for button in self.eqnbuttons.values():
             button.set(0)
     self.sensitize()
Example #5
0
 def checker(self, x):
     # x must be the name of a Who instance of the correct
     # WhoClass.
     if not (type(x) == StringType
             and labeltree.makePath(x) in self.whoclass.keys()):
         raise TypeError("Expected the name of a %s instance." %
                         self.whoclass)
Example #6
0
 def add(self, name, obj, parent, **kwargs):
     assert (self.parentClass is None and parent is None) \
            or isinstance(parent, self.parentClass.instanceClass)
     path = labeltree.makePath(name)
     if len(path) != len(self.hierarchy()):
         raise ValueError(
             "%s is an invalid name for an object in WhoClass %s" %
             (name, self.name()))
     # Silently overwrite an old object with the same name.  It's
     # assumed that if we got this far we know what we're doing.
     try:
         oldwho = self[path]
     except KeyError:
         pass
     else:
         self.remove(path)
     whoobj = self.instanceClass(path[-1],
                                 self.name(),
                                 obj,
                                 parent=parent,
                                 **kwargs)
     self.members[path] = whoobj
     self.nmembers += 1
     switchboard.notify('new who', self.name(), path)  # generic version
     switchboard.notify(('new who', self.name()), path)  # specific version
     whoobj.parallelize()  # does useful work in parallel mode
     return whoobj
Example #7
0
 def remove(self, name):
     path = labeltree.makePath(name)
     try:  ## TODO: This outer try/except/else is meaningless
         obj = self[path]  # Who instance
     except KeyError:
         raise  #pass                        # is "pass" necessary?
     else:
         obj.pause_writing()
         try:
             switchboard.notify('preremove who', self.name(), path)
             switchboard.notify(('preremove who', self.name()), path)
         finally:
             obj.resume_writing()
         # Remove the leaf from the tree.  If it's the only leaf on
         # its branch, remove the branch.
         self.members.prune(path)
         obj.remove()
         self.nmembers -= 1
         # The order of these last two signals is important -- the
         # widgets catch the specific signal, and it's helpful to
         # the pages (which catch the generic signal) if the widget
         # is in the new state at page-update-time.
         obj.pause_writing()
         try:
             switchboard.notify(('remove who', self.name()),
                                path)  # specific
             switchboard.notify('remove who', self.name(), path)  # generic
         finally:
             obj.resume_writing()
Example #8
0
 def rename_skeleton_CB(self,
                        gtkobj):  # gtk callback for "Rename..." button
     menuitem = skeletonmenu.Rename
     namearg = menuitem.get_arg('name')
     namearg.value = labeltree.makePath(self.skelwidget.get_value())[-1]
     if parameterwidgets.getParameters(namearg, title='Rename skeleton'):
         menuitem.callWithDefaults(skeleton=self.skelwidget.get_value())
Example #9
0
def select(menuitem, source, method):
    # source is the name of a Microstructure or Image.  Get the object.
    whopath = labeltree.makePath(source)
    if len(whopath) == 1:
        ms = whoville.getClass('Microstructure')[whopath]
        source = ms
    else:
        assert len(whopath) == 2
        ms = whoville.getClass('Microstructure')[whopath[0:1]]
        source = whoville.getClass('Image')[whopath]
    selection = ms.getSelectionContext()
    selection.reserve()
    selection.begin_writing()
    try:
        selection.start()
        method.select(source, selection)
    finally:
        selection.end_writing()
        selection.cancel_reservation()
    # "pixel selection changed" tells UI components that reflect the
    # pixel selection status to update themselves.
    switchboard.notify('pixel selection changed', selection)
    # The notify method for some selection methods sends a switchboard
    # message indicating that the method has been used, so that it can
    # be recorded in the voxel selection page's historian, for example.
    method.notify()
    switchboard.notify('redraw')
Example #10
0
 def checker(self, x):
     # x must be the name of a Who instance of the correct
     # WhoClass.
     if not (type(x) == StringType and 
             labeltree.makePath(x) in self.whoclass.keys()):
         raise TypeError("Expected the name of a %s instance."
                         % self.whoclass)
Example #11
0
 def set_state(self, subppath):
     debug.mainthreadTest()
     path = labeltree.makePath(subppath)
     self.subpwidget.set_value(path)
     # Retrieve the subproblem from the widget, just in case
     # subppath wasn't a complete subproblem path.
     subpctxt = self.currentSubProblemContext()
     if subpctxt:  # ie, path was complete
         subp = subpctxt.getObject()  # CSubProblem object
         mesh = self.currentMesh()
         for fname, fld in allCompoundFields.items():
             fdef = subp.is_defined_field(fld)
             self.fieldbuttons[(fname, "defined")].set(fdef)
             self.fieldbuttons[(fname, "active")].set_sensitive(fdef)
             if config.dimension() == 2:
                 self.fieldbuttons[(fname, "inplane")].set_sensitive(fdef)
             if fdef:
                 self.fieldbuttons[(fname, "active")].set(
                     subp.is_active_field(fld))
                 if config.dimension() == 2:
                     self.fieldbuttons[(fname,
                                        "inplane")].set(mesh.in_plane(fld))
             else:  # field not defined
                 self.fieldbuttons[(fname, "active")].set(0)
                 if config.dimension() == 2:
                     self.fieldbuttons[(fname, "inplane")].set(0)
         for eqn in equation.allEquations:
             active = subp.is_active_equation(eqn)
             self.eqnbuttons[(eqn.name(), "active")].set(active)
     else:  # no current subproblem
         for button in self.fieldbuttons.values():
             button.set(0)
         for button in self.eqnbuttons.values():
             button.set(0)
     self.sensitize()
Example #12
0
def _skeleton_copy(menuitem, skeleton, name):
    if parallel_enable.enabled():
        from ooflib.engine.IO import skeletonIPC
        skeletonIPC.smenu.Copy(skeleton=skeleton, name=name)
        return

    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    oldskelcontext = skeletoncontext.skeletonContexts[skeleton]
    if name is automatic.automatic:
        nm = skeletoncontext.skeletonContexts.uniqueName(skeleton)
    else:
        nm = name

    orig = oldskelcontext.getObject()
    newskel = oldskelcontext.resolveCSkeleton(orig.completeCopy())
    for e in oldskelcontext.edgeboundaries.values():
        newskel.mapBoundary(e, orig, local=None)
    for p in oldskelcontext.pointboundaries.values():
        newskel.mapBoundary(p, orig, local=None)
    for f in oldskelcontext.faceboundaries.values():
        newskel.mapBoundary(f, orig, local=None)

    msname = oldskelpath[0]
    # "add" calls the SkeletonContext constructor, which calls
    # "disconnect" on the skeleton, ensuring that the propagation
    # we just did doesn't mess up the old skeleton context.
    skeletoncontext.skeletonContexts.add(
        [msname, nm], newskel, parent=microstructure.microStructures[msname])

    newskelcontext = skeletoncontext.skeletonContexts[[msname, nm]]
    newskelcontext.groupCopy(oldskelcontext)
Example #13
0
def createMSFromImage(menuitem, name, width, height, image):
    if parallel_enable.enabled():
        # For the back-end processes
        from ooflib.image.IO import oofimageIPC
        oofimageIPC.imenu.Create_From_Image_Parallel(msname=name, image=image)

    # For serial mode #0 in parallel mode
    imagepath = labeltree.makePath(image)
    immidgecontext = imagecontext.imageContexts[image]
    immidge = immidgecontext.getObject().clone(imagepath[-1])

    size = immidge.size()  # Point object.
    if width != automatic.automatic:
        size[0] = width
    if height != automatic.automatic:
        size[1] = height

    ms = ooflib.common.microstructure.Microstructure(name,
                                                     immidge.sizeInPixels(),
                                                     size)
    newimagecontext = imagecontext.imageContexts.add(
        [name, immidge.name()],
        immidge,
        parent=ooflib.common.microstructure.microStructures[name])
    switchboard.notify("redraw")
Example #14
0
def _skeleton_copy(menuitem, skeleton, name):
    if parallel_enable.enabled():
        from ooflib.engine.IO import skeletonIPC

        skeletonIPC.smenu.Copy(skeleton=skeleton, name=name)
        return

    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    oldskelcontext = skeletoncontext.skeletonContexts[skeleton]
    if name is automatic.automatic:
        nm = skeletoncontext.skeletonContexts.uniqueName(skeleton)
    else:
        nm = name

    orig = oldskelcontext.getObject()
    newskel = orig.properCopy(fresh=True)
    for e in oldskelcontext.edgeboundaries.values():
        newskel.mapBoundary(e, orig, local=None)
    for p in oldskelcontext.pointboundaries.values():
        newskel.mapBoundary(p, orig, local=None)

    msname = oldskelpath[0]
    # "add" calls the SkeletonContext constructor, which calls
    # "disconnect" on the skeleton, ensuring that the propagation
    # we just did doesn't mess up the old skeleton context.
    skeletoncontext.skeletonContexts.add([msname, nm], newskel, parent=microstructure.microStructures[msname])

    newskelcontext = skeletoncontext.skeletonContexts[[msname, nm]]
    newskelcontext.groupCopy(oldskelcontext)
Example #15
0
 def getCurrentSkeleton(self):
     name = self.getCurrentSkeletonName()
     path = labeltree.makePath(name)
     try:
         return skeletoncontext.skeletonContexts[name]
     except KeyError:
         return None
Example #16
0
def _skeleton_copy_parallel(menuitem, skeleton, name):
    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    oldskelcontext = skeletoncontext.skeletonContexts[skeleton]
    if name is automatic.automatic:
        nm = skeletoncontext.skeletonContexts.uniqueName(skeleton)
    else:
        nm = name
        
    orig = oldskelcontext.getObject()
    newskel = orig.properCopy(fresh=True) 
    for e in oldskelcontext.edgeboundaries.values():
        newskel.mapBoundary(e, orig, local=None)
    for p in oldskelcontext.pointboundaries.values():
        newskel.mapBoundary(p, orig, local=None)

    msname = oldskelpath[0]
    # "add" calls the SkeletonContext constructor, which calls
    # "disconnect" on the skeleton, ensuring that the propagation
    # we just did doesn't mess up the old skeleton context.
    skeletoncontext.skeletonContexts.add(
        [msname, nm], newskel,
        parent=microstructure.microStructures[msname])

    newskelcontext = skeletoncontext.skeletonContexts[ [msname, nm] ]
    newskelcontext.groupCopy(oldskelcontext)
Example #17
0
def createMSFromImage(menuitem, name, width, height, image):
    if parallel_enable.enabled():
        # For the back-end processes
        from ooflib.image.IO import oofimageIPC
        oofimageIPC.imenu.Create_From_Image_Parallel(
            msname=name, image=image)

    # For serial mode #0 in parallel mode
    imagepath = labeltree.makePath(image)
    immidgecontext = imagecontext.imageContexts[image]
    immidge = immidgecontext.getObject().clone(imagepath[-1])

    size = immidge.size() # Point object.
    if width!=automatic.automatic:
        size[0]=width
    if height!=automatic.automatic:
        size[1]=height
        
    ms = ooflib.common.microstructure.Microstructure(name,
                                                   immidge.sizeInPixels(),
                                                   size)
    newimagecontext = imagecontext.imageContexts.add(
        [name, immidge.name()],
        immidge,
        parent=ooflib.common.microstructure.microStructures[name])
    switchboard.notify("redraw")
Example #18
0
 def remove(self, name):
     path = labeltree.makePath(name)
     try:
         obj = self[path]            # Who instance
     except KeyError:
         raise #pass                        # is "pass" necessary?
     else:
         obj.pause_writing()
         try:
             switchboard.notify('preremove who', self.name(), path)
             switchboard.notify(('preremove who', self.name()), path)
         finally:
             obj.resume_writing()
         # Remove the leaf from the tree.  If it's the only leaf on
         # its branch, remove the branch.
         self.members.prune(path)
         obj.remove()
         self.nmembers -= 1
         # The order of these last two signals is important -- the
         # widgets catch the specific signal, and it's helpful to
         # the pages (which catch the generic signal) if the widget
         # is in the new state at page-update-time.
         obj.pause_writing()
         try:
             switchboard.notify(('remove who', self.name()), path) # specific
             switchboard.notify('remove who', self.name(), path) # generic
         finally:
             obj.resume_writing()
Example #19
0
 def subprobRenameCB(self, gtkobj):
     menuitem = mainmenu.OOF.Subproblem.Rename
     namearg = menuitem.get_arg('name')
     cursubprob = self.currentFullSubProblemName()
     namearg.value = labeltree.makePath(cursubprob)[-1]
     if parameterwidgets.getParameters(
         namearg, title="Rename subproblem " + namearg.value):
         menuitem.callWithDefaults(subproblem=cursubprob)
Example #20
0
 def renameCB(self, *args):          # gtk button callback
     menuitem = meshmenu.Rename
     namearg = menuitem.get_arg('name')
     curmeshpath = self.currentFullMeshName()
     namearg.value = labeltree.makePath(curmeshpath)[-1]
     if parameterwidgets.getParameters(namearg,
                                       title='Rename mesh '+namearg.value):
         menuitem.callWithDefaults(mesh=curmeshpath)
Example #21
0
 def set_state(self, meshpath):  # widget update & information update
     debug.mainthreadTest()
     path = labeltree.makePath(meshpath)
     self.meshwidget.set_value(path)
     self.update_info()
     self.set_subproblem_state()
     self.sensitize()
     self.sensitizeHistory()
Example #22
0
def msImageNameResolver(param, name):
    if param.automatic():
        imagename = param.group['image'].value
        imagepath = labeltree.makePath(imagename)
        basename = imagepath[-1]
    else:
        basename = name
    return ooflib.common.microstructure.microStructures.uniqueName(basename)
Example #23
0
 def subprobRenameCB(self, gtkobj):
     menuitem = mainmenu.OOF.Subproblem.Rename
     namearg = menuitem.get_arg('name')
     cursubprob = self.currentFullSubProblemName()
     namearg.value = labeltree.makePath(cursubprob)[-1]
     if parameterwidgets.getParameters(
         namearg, title="Rename subproblem " + namearg.value):
         menuitem.callWithDefaults(subproblem=cursubprob)
Example #24
0
 def renameCB(self, *args):          # gtk button callback
     menuitem = meshmenu.Rename
     namearg = menuitem.get_arg('name')
     curmeshpath = self.currentFullMeshName()
     namearg.value = labeltree.makePath(curmeshpath)[-1]
     if parameterwidgets.getParameters(namearg,
                                       title='Rename mesh '+namearg.value):
         menuitem.callWithDefaults(mesh=curmeshpath)
Example #25
0
def msImageNameResolver(param, name):
    if param.automatic():
        imagename = param.group['image'].value
        imagepath = labeltree.makePath(imagename)
        basename = imagepath[-1]
    else:
        basename = name
    return ooflib.common.microstructure.microStructures.uniqueName(basename)
Example #26
0
 def set_state(self, meshpath):  # widget update & information update
     debug.mainthreadTest()
     path = labeltree.makePath(meshpath)
     self.meshwidget.set_value(path)
     self.update_info()
     self.set_subproblem_state()
     self.sensitize()
     self.sensitizeHistory()
Example #27
0
def subproblemNameResolver(param, startname):
    if param.automatic():
        basename = 'subproblem'
    else:
        basename = startname
    meshname = param.group['mesh'].value
    if meshname is not None:
        meshpath = labeltree.makePath(meshname)
        return ooflib.engine.subproblemcontext.subproblems.uniqueName(
            meshpath + [basename])
Example #28
0
def renameMesh_parallel(menuitem, mesh, name):
    oldmeshpath = labeltree.makePath(mesh)
    themesh = ooflib.engine.mesh.meshes[oldmeshpath]
    themesh.reserve()
    themesh.begin_writing()
    try:
        themesh.rename(name, exclude=oldmeshpath[-1])
    finally:
        themesh.end_writing()
        themesh.cancel_reservation()
Example #29
0
def bcnameResolver(param, name):
    if param.automatic():
        basename = 'bc'
    else:
        basename = name
    meshname = param.group['mesh'].value
    if meshname is not None:
        meshpath = labeltree.makePath(meshname)
        meshcontext = ooflib.engine.mesh.meshes[meshpath]
        return meshcontext.uniqueBCName(basename)
Example #30
0
def subproblemNameResolver(param, startname):
    if param.automatic():
        basename = 'subproblem'
    else:
        basename = startname
    meshname = param.group['mesh'].value
    if meshname is not None:
        meshpath = labeltree.makePath(meshname)
        return ooflib.engine.subproblemcontext.subproblems.uniqueName(meshpath +
                                                                    [basename])
Example #31
0
def renameMesh_parallel(menuitem, mesh, name):
    oldmeshpath = labeltree.makePath(mesh)
    themesh = ooflib.engine.mesh.meshes[oldmeshpath]
    themesh.reserve()
    themesh.begin_writing()
    try:
        themesh.rename(name, exclude=oldmeshpath[-1])
    finally:
        themesh.end_writing()
        themesh.cancel_reservation()
Example #32
0
def bcnameResolver(param, name):
    if param.automatic():
        basename = 'bc'
    else:
        basename = name
    meshname = param.group['mesh'].value
    if meshname is not None:
        meshpath = labeltree.makePath(meshname)
        meshcontext = ooflib.engine.mesh.meshes[meshpath]
        return meshcontext.uniqueBCName(basename)
Example #33
0
def _new_subproblem(menuitem, name, mesh, subproblem):
    ##    if parallel_enable.enabled():
    ##        ## TODO MER: very out of date!
    ##        ipcsubpmenu.New(name=name, mesh=mesh, subproblem=subproblem)
    ##        return
    meshcontext = ooflib.engine.mesh.meshes[mesh]
    # 'subproblem' is a SubProblemType instance
    subpobj = subproblem.create()
    meshcontext.newSubProblem(subpobj, subproblem,
                              labeltree.makePath(mesh) + [name])
Example #34
0
 def getMeshes(self):
     from ooflib.engine import mesh # avoid import loop
     path = labeltree.makePath(self.path())
     if not path:
         # path can be None if we're still in the process o
         # building a new SkeletonContext.  In that case, there are
         # no Meshes.
         return []
     meshnames = mesh.meshes.keys(
         path, condition=lambda x: not isinstance(x, whoville.WhoProxy))
     return [mesh.meshes[path + name] for name in meshnames]
Example #35
0
def _new_subproblem(menuitem, name, mesh, subproblem):
##    if parallel_enable.enabled():
##        ## TODO: very out of date!
##        ipcsubpmenu.New(name=name, mesh=mesh, subproblem=subproblem)
##        return
    meshcontext = ooflib.engine.mesh.meshes[mesh]
    # 'subproblem' is a SubProblemType instance
    subpobj = subproblem.create()
    meshcontext.newSubProblem(subpobj,
                              subproblem,
                              labeltree.makePath(mesh)+[name])
Example #36
0
def _skeleton_rename_parallel(menuitem, skeleton, name):
    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    skel = skeletoncontext.skeletonContexts[oldskelpath]
    skel.reserve()
    skel.begin_writing()
    try:
        skel.rename(name, exclude=oldskelpath[-1])
    finally:
        skel.end_writing()
        skel.cancel_reservation()
Example #37
0
def _skeleton_rename_parallel(menuitem, skeleton, name):
    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    skel = skeletoncontext.skeletonContexts[oldskelpath]
    skel.reserve()
    skel.begin_writing()
    try:
        skel.rename(name, exclude=oldskelpath[-1])
    finally:
        skel.end_writing()
        skel.cancel_reservation()
Example #38
0
def _newSubProblem(menuitem, mesh, name, subproblem):
    meshcontext = ooflib.engine.mesh.meshes[mesh]
    meshcontext.reserve()
    meshcontext.begin_writing()
    try:
        subpobj = subproblem.create()
        meshcontext.newSubProblem(subpobj, subproblem,
                                  labeltree.makePath(mesh)+[name])
    finally:
        meshcontext.end_writing()
        meshcontext.cancel_reservation()
Example #39
0
def _newSubProblem(menuitem, mesh, name, subproblem):
    meshcontext = ooflib.engine.mesh.meshes[mesh]
    meshcontext.reserve()
    meshcontext.begin_writing()
    try:
        subpobj = subproblem.create()
        meshcontext.newSubProblem(subpobj, subproblem,
                                  labeltree.makePath(mesh) + [name])
    finally:
        meshcontext.end_writing()
        meshcontext.cancel_reservation()
Example #40
0
 def getMeshes(self):
     from ooflib.engine import mesh  # avoid import loop
     path = labeltree.makePath(self.path())
     if not path:
         # path can be None if we're still in the process o
         # building a new SkeletonContext.  In that case, there are
         # no Meshes.
         return []
     meshnames = mesh.meshes.keys(
         path, condition=lambda x: not isinstance(x, whoville.WhoProxy))
     return [mesh.meshes[path + name] for name in meshnames]
Example #41
0
 def update(self, skelname, locked):
     debug.subthreadTest()
     # Most pages are updated when their info changes even if
     # they're not currently visible.  Because the Skeleton Page
     # displays the homogeneity which may be slow to compute, it's
     # not updated unless it's currently visible.
     if not self.is_current():       # not displayed in the GUI
         self.postponed_update = True
         return
     self.postponed_update = False
     skelpath = labeltree.makePath(skelname)
     if skelpath:
         skelctxt = skeletoncontext.skeletonContexts[skelpath]
         skel = skelctxt.getObject()
         ## Updating the state info is done in two stages, because
         ## the homogeneity index can take a while to compute.  In
         ## the first stage, the quick stuff is computed, and the
         ## homogeneity index is displayed as '????'. 
         if not locked:
             skelctxt.begin_reading()
         try:
             ms_name = skel.MS.name()
             nNodes = len(skel.nodes)
             nElements = len(skel.elements)
             illegalcount = skel.getIllegalCount()
             shapecounts = skel.countShapes()
             lr_periodicity = skel.left_right_periodicity
             tb_periodicity = skel.top_bottom_periodicity
             if config.dimension() == 3:
                 fb_periodicity = skel.front_back_periodicity
             else:
                 fb_periodicity = False
         finally:
             if not locked:
                 skelctxt.end_reading()
         mainthread.runBlock(self.writeInfoBuffer,
                             (nNodes, nElements, illegalcount, shapecounts,
                              None, lr_periodicity, tb_periodicity,
                              fb_periodicity))
         # Homogeneity Index stuff.  
         if not locked:
             skelctxt.begin_writing()
         try:
             homogIndex = skel.getHomogeneityIndex()
         finally:
             if not locked:
                 skelctxt.end_writing()
         mainthread.runBlock(self.writeInfoBuffer,
                             (nNodes, nElements, illegalcount, shapecounts,
                              homogIndex, lr_periodicity, tb_periodicity,
                              fb_periodicity))
     else:
         mainthread.runBlock(self.deleteInfoBuffer)
     self.sensitize()
Example #42
0
 def update(self, skelname, locked):
     debug.subthreadTest()
     # Most pages are updated when their info changes even if
     # they're not currently visible.  Because the Skeleton Page
     # displays the homogeneity which may be slow to compute, it's
     # not updated unless it's currently visible.
     if not self.is_current():       # not displayed in the GUI
         self.postponed_update = True
         return
     self.postponed_update = False
     skelpath = labeltree.makePath(skelname)
     if skelpath:
         skelctxt = skeletoncontext.skeletonContexts[skelpath]
         skel = skelctxt.getObject()
         ## Updating the state info is done in two stages, because
         ## the homogeneity index can take a while to compute.  In
         ## the first stage, the quick stuff is computed, and the
         ## homogeneity index is displayed as '????'. 
         if not locked:
             skelctxt.begin_reading()
         try:
             ms_name = skel.MS.name()
             nNodes = len(skel.nodes)
             nElements = len(skel.elements)
             illegalcount = skel.getIllegalCount()
             shapecounts = skel.countShapes()
             lr_periodicity = skel.left_right_periodicity
             tb_periodicity = skel.top_bottom_periodicity
             if config.dimension() == 3:
                 fb_periodicity = skel.front_back_periodicity
             else:
                 fb_periodicity = False
         finally:
             if not locked:
                 skelctxt.end_reading()
         mainthread.runBlock(self.writeInfoBuffer,
                             (nNodes, nElements, illegalcount, shapecounts,
                              None, lr_periodicity, tb_periodicity,
                              fb_periodicity))
         # Homogeneity Index stuff.  
         if not locked:
             skelctxt.begin_writing()
         try:
             homogIndex = skel.getHomogeneityIndex()
         finally:
             if not locked:
                 skelctxt.end_writing()
         mainthread.runBlock(self.writeInfoBuffer,
                             (nNodes, nElements, illegalcount, shapecounts,
                              homogIndex, lr_periodicity, tb_periodicity,
                              fb_periodicity))
     else:
         mainthread.runBlock(self.deleteInfoBuffer)
     self.sensitize()
Example #43
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])
Example #44
0
def skeletonNameResolver(param, startname):
    if param.automatic():
        basename = "skeleton"
    else:
        basename = startname
    msname = param.group["microstructure"].value
    mspath = labeltree.makePath(msname)
    # In the command-line case, msname may not be set yet -- return
    # "None" so the menu system will prompt the user.
    if not mspath:
        return None
    return skeletoncontext.skeletonContexts.uniqueName(mspath + [basename])
Example #45
0
def skeletonNameResolver(param, startname):
    if param.automatic():
        basename = 'skeleton'
    else:
        basename = startname
    msname = param.group['microstructure'].value
    mspath = labeltree.makePath(msname)
    # In the command-line case, msname may not be set yet -- return
    # "None" so the menu system will prompt the user.
    if not mspath:
        return None
    return skeletoncontext.skeletonContexts.uniqueName(mspath + [basename])
Example #46
0
 def renameWhoCB(self, oldpath, newname): # sb ("rename who", classname)
     # The object being renamed might be an internal node, in which
     # case the path being passed in will be shorter than required
     # for setting the state of this widget.
     opath = labeltree.makePath(oldpath) # old path to renamed object
     npath = opath[:-1] + [newname]  # new path to renamed object
     cpath = self.currentPath        # current path
     if opath == cpath[:len(opath)]: # path to current object is changing
         npath += cpath[len(opath):] # new path to current object
         self.buildWidgets(npath)
     else:                           # change does not affect current object
         self.buildWidgets()
Example #47
0
 def renameWhoCB(self, oldpath, newname):  # sb ("rename who", classname)
     # The object being renamed might be an internal node, in which
     # case the path being passed in will be shorter than required
     # for setting the state of this widget.
     opath = labeltree.makePath(oldpath)  # old path to renamed object
     npath = opath[:-1] + [newname]  # new path to renamed object
     cpath = self.currentPath  # current path
     if opath == cpath[:len(opath)]:  # path to current object is changing
         npath += cpath[len(opath):]  # new path to current object
         self.buildWidgets(npath)
     else:  # change does not affect current object
         self.buildWidgets()
Example #48
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])
Example #49
0
def _rename_subproblem(menuitem, subproblem, name):
    if parallel_enable.enabled():
        ipcsubpmenu.Rename(name=name, subproblem=subproblem)
        return
    oldpath = labeltree.makePath(subproblem)
    newpath = labeltree.makePath(subproblem)[:-1] + [name]
    subprob = ooflib.engine.subproblemcontext.subproblems[oldpath]
    old_dependents = subprob.subptype.get_dependents()
    if subprob.name() == ooflib.engine.mesh.defaultSubProblemName:
        raise ooferror.ErrUserError("You can't rename the default Subproblem!")
    for dependent in old_dependents:
        dependentsubp = ooflib.engine.subproblemcontext.subproblems[dependent]
        dependentsubp.subptype.sync_dependency(":".join(oldpath),
                                               ":".join(newpath))
    subprob.reserve()
    subprob.begin_writing()
    try:
        subprob.rename(name, exclude=oldpath[-1])
    finally:
        subprob.end_writing()
        subprob.cancel_reservation()
Example #50
0
def parallel_rename_subproblem(menuitem, subproblem, name):
    debug.fmsg()
    oldpath = labeltree.makePath(subproblem)
    subprob = ooflib.engine.subproblemcontext.subproblems[oldpath]
    if subprob.name() == ooflib.engine.mesh.defaultSubProblemName:
        raise ooferror.ErrUserError("You can't rename the default Subproblem!")
    subprob.reserve()
    subprob.begin_writing()
    try:
        subprob.rename(name, exclude=oldpath[-1])
    finally:
        subprob.end_writing()
        subprob.cancel_reservation()
Example #51
0
def _newMesh(menuitem, name, masterelems, skeleton):
    skel = skeletoncontext.skeletonContexts[skeleton].getObject()
    edict = getMyMasterElementDict(masterelems)
    # This hard-codes the realmaterial material factory
    # function. There's not much chance of ever wanting to store
    # Meshes that use other factory functions.
    femesh = skel.femesh(edict)
    meshctxt = ooflib.engine.mesh.meshes.add(
        labeltree.makePath(skeleton)+[name], femesh,
        parent=skeletoncontext.skeletonContexts[skeleton],
        skeleton=skel, elementdict=edict,
        materialfactory=None) #skeletonelement.SkeletonElement.realmaterial)
    meshctxt.createDefaultSubProblem()
Example #52
0
def parallel_rename_subproblem(menuitem, subproblem, name):
    debug.fmsg()
    oldpath = labeltree.makePath(subproblem)
    subprob = ooflib.engine.subproblemcontext.subproblems[oldpath]
    if subprob.name() == ooflib.engine.mesh.defaultSubProblemName:
        raise ooferror.ErrUserError("You can't rename the default Subproblem!")
    subprob.reserve()
    subprob.begin_writing()
    try:
        subprob.rename(name, exclude=oldpath[-1])
    finally:
        subprob.end_writing()
        subprob.cancel_reservation()
Example #53
0
def createMSFromImage_Parallel(menuitem, msname, image):
    if _rank==0:
        return
    #Already done in imagemenu for process 0
    imagepath = labeltree.makePath(image)
    imagecontext = oofimage.imageContexts[image]
    immidge = imagecontext.getObject().clone(imagepath[-1])
    ms = ooflib.common.microstructure.Microstructure(msname,
                                                   immidge.sizeInPixels(),
                                                   immidge.size())
    newimagecontext = oofimage.imageContexts.add([msname, immidge.name()],
                                                 immidge,
                                                 parent=ooflib.common.microstructure.microStructures[msname])
    ms.addImage(newimagecontext)
Example #54
0
def _newMesh(menuitem, name, masterelems, skeleton):
    skel = skeletoncontext.skeletonContexts[skeleton].getObject()
    edict = getMyMasterElementDict(masterelems)
    # This hard-codes the realmaterial material factory
    # function. There's not much chance of ever wanting to store
    # Meshes that use other factory functions.
    femesh = skel.femesh(edict, skeletonelement.SkeletonElement.realmaterial,
                         skeleton) #Interface branch, pass skeleton path to femesh
    meshctxt = ooflib.engine.mesh.meshes.add(
        labeltree.makePath(skeleton)+[name], femesh,
        parent=skeletoncontext.skeletonContexts[skeleton],
        skeleton=skel, elementdict=edict,
        materialfactory=skeletonelement.SkeletonElement.realmaterial)
    meshctxt.createDefaultSubProblem()
Example #55
0
 def rename(self, name, exclude=None):
     ## TODO LATER: PARALLELIZE THIS FUNCTION
     oldpath = self.path()           # local copy! path will change
     # Make sure the new name is unique.  Changing the name
     # silently here is probably a bad idea.
     newname = self.getClass().uniqueName(
         labeltree.makePath(oldpath)[:-1]+[name], exclude=exclude)
     self._name = newname
     if hasattr(self._obj, "rename"):
         self._obj.rename(newname)
     self.pause_writing()
     switchboard.notify('rename who', self.classname, oldpath, self.name())
     switchboard.notify(('rename who', self.classname), oldpath, self.name())
     self.resume_writing()
Example #56
0
 def uniqueName(self, name, exclude=None):
     # Given a LabelTree path (list of strings, or colon separated
     # substrings), returns a single string that doesn't already
     # name a leaf in the same tree.  For example, if the WhoClass
     # contains a Who called "Hey:Bee:Sea", and you call uniqueName
     # with the argument "Hey:Bee:Sea" or ["Hey", "Bee", "Sea"], it
     # will return "Sea<2>".  If you pass in "Hay:Bea:Sea" it will
     # return "Sea".
     path = labeltree.makePath(name)
     try:
         basenode = self.members[path[:-1]]
     except KeyError:
         return path[-1]             # subtree doesn't exist yet
     return utils.uniqueName(path[-1], basenode.children(), exclude=exclude)
Example #57
0
def _skeleton_rename(menuitem, skeleton, name):
    if parallel_enable.enabled():
        from ooflib.engine.IO import skeletonIPC

        skeletonIPC.smenu.Rename(skeleton=skeleton, name=name)
        return

    # skeleton is a colon separated string
    oldskelpath = labeltree.makePath(skeleton)
    skel = skeletoncontext.skeletonContexts[oldskelpath]
    skel.reserve()
    skel.begin_writing()
    try:
        skel.rename(name, exclude=oldskelpath[-1])
    finally:
        skel.end_writing()
        skel.cancel_reservation()
Example #58
0
    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]
Example #59
0
 def set_value(self, object):
     debug.mainthreadTest()
     path = labeltree.makePath(self.tree.objpath(object))
     depth = len(path)
     for widget in self.widgets:
         widget.destroy()
     self.widgets = []
     tree = self.tree
     depth = 0
     for name in path:
         names = [node.name for node in tree.nodes]
         widget = chooser.ChooserWidget(names, callback=self.chooserCB,
                                        callbackargs=(depth,),
                                        name="%s_%d"%(self.name,depth))
         depth += 1
         widget.set_state(name)
         self.widgets.append(widget)
         self.gtk.pack_start(widget.gtk, expand=0, fill=0)
         tree = tree[name]
     self.gtk.show_all()