예제 #1
0
    def __init__(self, name, gfxmgr, clone=0):
        debug.subthreadTest()
        # self.name is also assigned by GhostGfxWindow, but it's
        # helpful for debugging for it to be assigned as soon as
        # possible in all execution paths.
        self.name = name
        self.gfxlock = lock.Lock()
        self.acquireGfxLock()

        # This whole initialization sequence is complicated.  The
        # reason is that the order of operations is important -- the
        # ghostgfxwindow makes function calls which need to be
        # redefined in the GUI before they occur -- and there is a
        # requirement that the main thread never be locked.
        # Furthermore, the ghostgfxwindow has to create the menu
        # before the SubWindow init gets called.  It could probably be
        # rationalized, but it's not urgent.

        # preinitialize and postinitialize are defined in gfxwindow.py
        # for 2D and gfxwindow3d.py for 3D.
        mainthread.runBlock(self.preinitialize, (name, gfxmgr, clone))
        # GhostGfxWindow.__init__ creates the canvas, among other things.
        ghostgfxwindow.GhostGfxWindow.__init__(self, name, gfxmgr, clone=clone)
        mainthread.runBlock(self.postinitialize, (name, gfxmgr, clone))
        self.releaseGfxLock()

        self.switchboardCallbacks.append(
            switchboard.requestCallback("shutdown", self.shutdownCB))
예제 #2
0
 def move_thread(self, skeleton, x, y, shift, ctrl):
     debug.subthreadTest()
     self.mouselock.acquire()
     try:
         if self.movingnode is not None:
             self.moving = 1
             homogeneity = 0.0
             shapeenergy = 0.0
             point = self.getPoint(x, y)
             # It's generally forbidden to call node.moveTo instead of
             # skeleton.moveNodeTo, but since we're going to move the
             # node back (see up(), below), it's ok.
             if point is not None:
                 self.movingnode.moveTo(point)
             if self.movingnode.illegal():
                 homogtext = "---"
                 shapetext = "---"
                 labeltext = "Illegal node position!"
             else:
                 for element in self.nbrelements:
                     # Evaluating homogeneity and shape energy is
                     # safe, because the Skeleton's read lock was
                     # acquired when the mouse went down.
                     homogeneity += element.homogeneity(skeleton.MS)
                     shapeenergy += element.energyShape()
                 homogtext = "%-11.4g" % (homogeneity - self.homogeneity0)
                 shapetext = "%-11.4g" % (shapeenergy - self.shapeenergy0)
                 labeltext = ""
             mainthread.runBlock(self.move_info,
                                 (point, homogtext, shapetext, labeltext))
             gtklogger.checkpoint("Move Node toolbox move event")
     finally:
         self.mouselock.release()
예제 #3
0
 def updateAAInfo(self):             # must be called on subthread
     debug.subthreadTest()
     ms = self.getCurrentMS()
     if ms is not None:
         activearea = ms.getObject().activearea
         activearea.begin_reading()
         try:
             aasize = activearea.size()
             mssize = ms.getObject().sizeInPixels()
             if config.dimension()==2:
                 mpxls = mssize[0] * mssize[1]
                 pixstring="pixels"
             elif config.dimension()==3:
                 mpxls = mssize[0] * mssize[1] * mssize[2]
                 pixstring="voxels"
             apxls = mpxls - aasize
             if ms.getObject().activearea.getOverride():
                 msg = "OVERRIDE: all %d %s are active" % (mpxls, pixstring)
             else:
                 msg = "%d of %d %s are active" % (apxls, mpxls, pixstring)
         finally:
             activearea.end_reading()
     else:
         msg = "No Microstructure selected"
     mainthread.runBlock(self.aainfo.set_text, (msg,))
     gtklogger.checkpoint("active area status updated")
예제 #4
0
 def updateSegmentList(self, chsr, objlist):
     # called only when Skeleton readlock has been obtained.        
     namelist = ["Segment %d, nodes (%d, %d) (length: %s)" %
                 (obj.index, obj.nodes()[0].index, obj.nodes()[1].index,
                  obj.length())
                 for obj in objlist]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #5
0
 def __init__(self, name, gfxmgr, clone=0):
     debug.subthreadTest()
     self.gfxlock = lock.Lock()
     mainthread.runBlock(self.preinitialize, (name, gfxmgr, clone))
     self.newCanvas()
     ghostgfxwindow.GhostGfxWindow.__init__(self, name, gfxmgr, clone=clone)
     mainthread.runBlock(self.postinitialize, (name, gfxmgr, clone))
예제 #6
0
 def initialize(self, gfxwindow, layerNumber=None):
     layereditor.LayerEditor.initialize(self, gfxwindow, layerNumber)
     gtklogger.checkpoint("layereditor layerset changed")
     self.setData("gfxwindow", gfxwindow)
     if gfxwindow is not None:
         mainthread.runBlock(self.destinationMenu.set_state,
                             (gfxwindow.name, ))
예제 #7
0
    def updateSomething(self, container):
        debug.subthreadTest()
        segment = container.object
        skeleton = container.skeleton
        container.context.begin_reading()
        try:
            sindex = `segment.getIndex()`
            self.updateNodeList(self.nodes, list(segment.get_nodes()))
            self.syncPeeker(self.nodes, "Node")
            self.updateElementList(self.elem, segment.getElements())
            self.syncPeeker(self.elem, "Element")
            length = `segment.length()`
            homogval = segment.homogeneity(skeleton.MS)
            if 0.9999 < homogval < 1.0:
                homog = "1 - (%e)" % (1.0-homogval)
            else:
                homog = `homogval`
            self.updateGroup(segment)

            bdynames = ','.join(
                segment.boundaryNames(container.context.getObject()))
#             mat = segment.material(container.context)
#             if mat:
#                 matname = mat.name()
#             else:
#                 matname = "<No material>"
        finally:
            container.context.end_reading()
        mainthread.runBlock(self.updateSomething_thread,
                            (sindex, length, homog, bdynames,
                             #matname
                             ))
예제 #8
0
    def sensitize_subthread(self):
        def set_button_sensitivity(u, r, c):
            self.undobutton.set_sensitive(u)
            self.redobutton.set_sensitive(r)
            self.clearbutton.set_sensitive(c)

        def set_ok_sensitivity(selection):
            ok =  selection is not None and \
                 self.selectionModFactory.isValid()
            self.okbutton.set_sensitive(ok)

        (ms, selection) = mainthread.runBlock(self.getSelectionContext)
        if selection is not None:
            selection.begin_reading()
            try:
                u = selection.undoable()
                r = selection.redoable()
                c = selection.clearable()
            finally:
                selection.end_reading()
        else:
            (u, r, c) = (0, 0, 0)
        mainthread.runBlock(set_button_sensitivity, (u, r, c))
        mainthread.runBlock(set_ok_sensitivity, (selection, ))
        gtklogger.checkpoint("pixel page sensitized")
예제 #9
0
    def setInfo_subthread(self):
        debug.subthreadTest()

        source = self.getSelectionSource()
        if source is not None:
            source.begin_reading()
            try:
                selection = source.getSelectionContext(
                    **self.toolbox.extrakwargs)
                ## Selection can be None because an Image must be created
                ## before a Microstructure, but the selection source for
                ## an Image is its Microstructure.
                if selection is not None:
                    selection.begin_reading()
                    try:
                        sizetextdata = ` selection.size() `
                    finally:
                        selection.end_reading()
                else:
                    sizetextdata = '0'
            finally:
                source.end_reading()
        else:
            sizetextdata = self.toolbox.emptyMessage()

        mainthread.runBlock(self._write_text, (sizetextdata, ))
예제 #10
0
 def updateAAInfo(self):             # must be called on subthread
     debug.subthreadTest()
     ms = self.getCurrentMS()
     if ms is not None:
         activearea = ms.getObject().activearea
         activearea.begin_reading()
         try:
             aasize = activearea.size()
             mssize = ms.getObject().sizeInPixels()
             if config.dimension()==2:
                 mpxls = mssize[0] * mssize[1]
                 pixstring="pixels"
             elif config.dimension()==3:
                 mpxls = mssize[0] * mssize[1] * mssize[2]
                 pixstring="voxels"
             apxls = mpxls - aasize
             if ms.getObject().activearea.getOverride():
                 msg = "OVERRIDE: all %d %s are active" % (mpxls, pixstring)
             else:
                 msg = "%d of %d %s are active" % (apxls, mpxls, pixstring)
         finally:
             activearea.end_reading()
     else:
         msg = "No Microstructure selected"
     mainthread.runBlock(self.aainfo.set_text, (msg,))
     gtklogger.checkpoint("active area status updated")
예제 #11
0
 def sensitize(self):
     debug.subthreadTest()
     ms_available = False
     grp_selected = False
     nonemptygrp = False
     pixelsselected = False
     ngrps = 0
     msctxt = self.currentMScontext()
     if msctxt:
         # TODO: This is incorrect.  Don't call begin_reading here.
         # The ms may be doing some long calculation, and the
         # buttons should be desensitized because of it.  Calling
         # begin_reading will lock and prevent densensitization
         # until after the calculation is done!
         msctxt.begin_reading()
         try:
             ms = msctxt.getObject()
             if ms is not None:
                 ms_available = True
                 grp = self.currentGroup()
                 grp_selected = (grp is not None) and ms_available
                 nonemptygrp = grp_selected and len(grp) > 0
                 pixelsselected = ms.pixelselection.size() > 0
                 ngrps = ms.nGroups()
         finally:
             msctxt.end_reading()
     mainthread.runBlock(
         self.sensitize_thread,
         (ms_available, grp_selected, pixelsselected, nonemptygrp, ngrps))
예제 #12
0
파일: pixelPage.py 프로젝트: santiama/OOF3D
    def sensitize_subthread(self):

        def set_button_sensitivity(u, r, c):
            self.undobutton.set_sensitive(u)
            self.redobutton.set_sensitive(r)
            self.clearbutton.set_sensitive(c)

        def set_ok_sensitivity(selection):
            ok =  (selection is not None
                   and not selection.query_reservation()
                   and self.selectionModFactory.isValid())
            self.okbutton.set_sensitive(ok)

        (ms, selection) = mainthread.runBlock(self.getSelectionContext)
        if selection is not None:
            available = not selection.query_reservation()
            selection.begin_reading()
            try:
                u = available and selection.undoable()
                r = available and selection.redoable()
                c = available and selection.clearable()
            finally:
                selection.end_reading()
        else:
            (u,r,c) = (0,0,0)
        mainthread.runBlock(set_button_sensitivity, (u,r,c))
        mainthread.runBlock(set_ok_sensitivity, (selection,) )
예제 #13
0
    def sensitize_subthread(self):

        def set_button_sensitivity(u, r, c):
            self.undobutton.set_sensitive(u)
            self.redobutton.set_sensitive(r)
            self.clearbutton.set_sensitive(c)

        def set_ok_sensitivity(selection):
            ok =  selection is not None and \
                 self.selectionModFactory.isValid()
            self.okbutton.set_sensitive(ok)

        (ms, selection) = mainthread.runBlock(self.getSelectionContext)
        if selection is not None:
            selection.begin_reading()
            try:
                u = selection.undoable()
                r = selection.redoable()
                c = selection.clearable()
            finally:
                selection.end_reading()
        else:
            (u,r,c) = (0,0,0)
        mainthread.runBlock(set_button_sensitivity, (u,r,c))
        mainthread.runBlock(set_ok_sensitivity, (selection,) )
        gtklogger.checkpoint("pixel page sensitized")
예제 #14
0
 def displayMSInfo(self, *args):
     # *args is given because this is used as a switchboard
     # callback for ('rename who', 'Image') as well as being called
     # directly.  This indicates either slovenliness or efficiency
     # on the part of the programmer.
     debug.subthreadTest()
     mscontext = self.currentMScontext()
     text = ""
     if mscontext is not None:
         mscontext.begin_reading()
         try:
             ms = mscontext.getObject()
             size = ms.sizeInPixels()
             if config.dimension() == 2:
                 text += 'Pixel size: %dx%d\n' % (size.x, size.y)
                 size = ms.size()
                 text += 'Physical size: %gx%g\n' % (size.x, size.y)
             elif config.dimension() == 3:
                 text += 'Voxel size: %dx%dx%d\n' % (size.x, size.y, size.z)
                 size = ms.size()
                 text += 'Physical size: %gx%gx%g\n' % (size.x, size.y,
                                                        size.z)
             imagenames = ms.imageNames()
             if imagenames:
                 text += 'Images:\n'
                 for name in imagenames:
                     text += '  ' + name + '\n'
             for infoplugin in self.infoplugins:
                 plugintext = infoplugin(mscontext)
                 if plugintext:
                     text += plugintext + '\n'
         finally:
             mscontext.end_reading()
     mainthread.runBlock(self.infoarea.get_buffer().set_text, (text, ))
예제 #15
0
 def updateNodeList(self, chsr, objlist, element=None):
     namelist = [
         "Node %d at %s" %
         (obj.uiIdentifier(), genericinfoGUI.posString(obj.position()))
         for obj in objlist
     ]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #16
0
 def update(self, indx):
     debug.subthreadTest()
     if indx is not None:
         meshctxt = self.gfxtoolbox.getMeshContext()
         meshctxt.begin_reading()
         try:
             element = meshctxt.getObject().getElement(indx)
             # element probably can't be None, but it doesn't hurt
             # to check.
             if element is not None:
                 self.updateNodeList(element.nodes())
                 mat = element.material()
                 if mat:
                     matname = mat.name()
                 else:
                     matname = "<No material>"
                 mainthread.runBlock(self.update_thread,
                                     (element.masterelement().name(), `
                                      element.uiIdentifier() `, matname))
                 return
         finally:
             meshctxt.end_reading()
     # Nothing to display
     mainthread.runBlock(self.update_thread, ("", "", ""))
     self.updateNodeList([])
예제 #17
0
 def rebuild_grouplist(self):
     debug.subthreadTest()
     mscontext = self.currentMScontext()
     msg = None
     if mscontext is not None:
         mscontext.begin_reading()
         ms = mscontext.getObject()
         try:
             if ms.nGroups() > 0:
                 grpnames = ms.groupNames()
                 dispnames = grpnames[:]
                 for i in range(len(grpnames)):
                     grpname = grpnames[i]
                     grp = ms.findGroup(grpname)
                     dispnames[i] += " (%d %s%s" % (len(grp), pixstring,
                                                    "s" * (len(grp) != 1))
                     if grp.is_meshable():
                         dispnames[i] += ", meshable)"
                     else:
                         dispnames[i] += ")"
             else:
                 msg = 'No %s groups defined!' % pixstring
         finally:
             mscontext.end_reading()
     else:  # ms is None
         msg = 'No Microstructure defined!'
     if msg:
         mainthread.runBlock(self.set_group_message, (msg, ))
     else:
         mainthread.runBlock(self.set_group_list, (grpnames, dispnames))
     self.setMeshableButton()
예제 #18
0
 def updateNodeList(self, nodes):
     namelist = [
         "%s %d at %s" % (node.classname(), node.uiIdentifier(),
                          genericinfoGUI.posString(node.position()))
         for node in nodes
     ]
     mainthread.runBlock(self.nodes.update, (nodes, namelist))
예제 #19
0
 def _clipPlanesChanged(self, viewobj, viewname=None):
     # The "true" arg tells set_view to set the clip planes.
     mainthread.runBlock(self.gfxwindow().oofcanvas.set_view,
                         (viewobj, True))
     self.gfxwindow().updateview()
     switchboard.notify("view changed", self.gfxwindow())
     switchboard.notify("clip planes changed", self.gfxwindow())
예제 #20
0
 def updateNodeListAngle(self, chsr, element):
     # called only when Skeleton readlock has been obtained.
     namelist = ["Node %d at (%s, %s) (angle: %s)" % \
                (node.index, node.position().x, node.position().y,
                 element.getRealAngle(element.nodes.index(node)))
                 for node in element.nodes]
     mainthread.runBlock(chsr.update, (element.nodes, namelist))
예제 #21
0
 def updateNodeListAngle(self, chsr, element):
     # called only when Skeleton readlock has been obtained.
     namelist = ["Node %d at (%s, %s) (angle: %s)" % \
                (node.index, node.position().x, node.position().y,
                 element.getRealAngle(element.nodes.index(node)))
                 for node in element.nodes]
     mainthread.runBlock(chsr.update, (element.nodes, namelist))
예제 #22
0
    def setInfo_subthread(self):
        debug.subthreadTest()
            
        source = self.getSource()
        if source is not None:
            source.begin_reading()
            try:
                selection = source.getSelectionContext(
                    **self.toolbox.extrakwargs)
                ## Selection can be None because an Image must be created
                ## before a Microstructure, but the selection source for
                ## an Image is its Microstructure.
                if selection is not None:
                    selection.begin_reading()
                    try:
                        sizetextdata = `selection.size()`
                    finally:
                        selection.end_reading()
                else:
                    sizetextdata = '0'
            finally:
                source.end_reading()
        else:
            sizetextdata = self.toolbox.emptyMessage()

        mainthread.runBlock(self._write_text, (sizetextdata,))
        gtklogger.checkpoint("selection info updated")
예제 #23
0
 def rebuild_grouplist(self):
     debug.subthreadTest()
     mscontext = self.currentMScontext()
     msg = None
     if mscontext is not None:
         mscontext.begin_reading()
         ms = mscontext.getObject()
         try:
             if ms.nGroups() > 0:
                 grpnames = ms.groupNames()
                 dispnames = grpnames[:]
                 for i in range(len(grpnames)):
                     grpname = grpnames[i]
                     grp = ms.findGroup(grpname)
                     dispnames[i] += " (%d %s%s" % (len(grp), pixstring,
                                                       "s"*(len(grp)!=1))
                     if grp.is_meshable():
                         dispnames[i] += ", meshable)"
                     else:
                         dispnames[i] += ")"
             else:
                 msg = 'No %s groups defined!'%pixstring
         finally:
             mscontext.end_reading()
     else:                           # ms is None
         msg = 'No Microstructure defined!'
     if msg:
         mainthread.runBlock(self.set_group_message, (msg,))
     else:
         mainthread.runBlock(self.set_group_list, (grpnames, dispnames))
     self.setMeshableButton()
예제 #24
0
 def move_thread(self, skeleton, x, y, shift, ctrl):
     debug.subthreadTest()
     self.mouselock.acquire()
     try:
         if self.movingnode is not None:
             self.moving = 1
             homogeneity = 0.0
             shapeenergy = 0.0
             point = self.getPoint(x,y)
             # It's generally forbidden to call node.moveTo instead of
             # skeleton.moveNodeTo, but since we're going to move the
             # node back (see up(), below), it's ok.
             if point is not None:
                 self.movingnode.moveTo(point)
             if self.movingnode.illegal():
                 homogtext = "---"
                 shapetext = "---"
                 labeltext = "Illegal node position!"
             else:
                 for element in self.nbrelements:
                     # Evaluating homogeneity and shape energy is
                     # safe, because the Skeleton's read lock was
                     # acquired when the mouse went down.
                     homogeneity += element.homogeneity(skeleton.MS)
                     shapeenergy += element.energyShape()
                 homogtext = "%-11.4g" % (homogeneity-self.homogeneity0)
                 shapetext = "%-11.4g" % (shapeenergy-self.shapeenergy0)
                 labeltext = ""
             mainthread.runBlock(self.move_info,
                                 (point, homogtext, shapetext, labeltext))
             gtklogger.checkpoint("Move Node toolbox move event")
     finally:
         self.mouselock.release()
예제 #25
0
 def initialize(self, gfxwindow, layerNumber=None):
     layereditor.LayerEditor.initialize(self, gfxwindow, layerNumber)
     gtklogger.checkpoint("layereditor layerset changed")
     self.setData("gfxwindow", gfxwindow)
     if gfxwindow is not None:
         mainthread.runBlock(self.destinationMenu.set_state,
                             (gfxwindow.name,))
예제 #26
0
 def displayImageInfo(self):
     debug.subthreadTest()
     imagecontext = self.getCurrentImage()
     text = ""
     if imagecontext:
         imagecontext.begin_reading()
         try:
             if config.dimension() == 2:
                 image = imagecontext.getObject()
                 size = image.sizeInPixels()
                 text += 'Pixel size: %dx%d\n' % (size.x, size.y)
                 size = image.size()
                 text += 'Physical size: %gx%g\n' % (size.x, size.y)
                 if image.comment():
                     text += '\nComments:\n%s\n' % image.comment()
             elif config.dimension() == 3:
                 image = imagecontext.getObject()
                 size = image.sizeInPixels()
                 text += 'Voxel size: %dx%dx%d\n' % (size.x, size.y, size.z)
                 size = image.size()
                 text += 'Physical size: %gx%gx%g\n' % (size.x, size.y,
                                                        size.z)
         finally:
             imagecontext.end_reading()
     mainthread.runBlock(self.displayImageInfo_thread, (text, ))
예제 #27
0
    def update(self, indx):
        debug.subthreadTest()
        if indx is not None:
            meshctxt = self.gfxtoolbox.getMeshContext()
            meshctxt.begin_reading()
            try:
                femesh = meshctxt.getObject()
                node = femesh.getNode(indx)
                # node probably can't be None, but it doesn't hurt to
                # check.
                if node is not None:
                    # Find out which fields are defined at the node
                    fieldnames = node.fieldNames()  # compound field names
                    nfieldrows = 0
                    listedfields = []
                    for fieldname in fieldnames:
                        fld = field.getField(fieldname)
                        nfieldrows += fld.ndof()
                        listedfields.append(fld)
                        if config.dimension() == 2:
                            zfld = fld.out_of_plane()
                            if node.hasField(zfld):
                                listedfields.append(zfld)
                                nfieldrows += zfld.ndof()
                        tfld = fld.time_derivative()
                        if node.hasField(tfld):
                            listedfields.append(tfld)
                            nfieldrows += tfld.ndof()
                    # Rebuild the table of field values, but only if the
                    # fields have changed.
                    if self.fieldslisted != listedfields:
                        mainthread.runBlock(self.rebuildFieldTable, (
                            nfieldrows,
                            listedfields,
                        ))

                    # Get the field values for the table.
                    fieldvals = []
                    # The structure of this loop must match the loop
                    # in update_thread, below.
                    for fld in self.fieldslisted:
                        fcomp = fld.iterator(planarity.ALL_INDICES)
                        while not fcomp.end():
                            fieldvals.append(
                                fld.value(femesh, node, fcomp.integer()))
                            fcomp.next()
                    # end loop over field values
                    mainthread.runBlock(self.update_thread,
                                        ( ` node.index() `, node.classname(),
                                          genericinfoGUI.posString(
                                              node.position()), fieldvals))
                    return
                # end if node is not None
            finally:
                meshctxt.end_reading()
        # end if indx is not None

        # No node
        mainthread.runBlock(self.update_thread, ("", "", "", []))
예제 #28
0
 def nextCB(self, *args):            # go to the next history item
     self.historyBuffer.next()
     self.inhibit = 1
     self.setCB(self.historyBuffer.current(), **self.setCBkwargs)
     self.inhibit = 0 
     self.editingHistory = 1
     if self.sensitizeCB:
         mainthread.runBlock(self.sensitizeCB)
예제 #29
0
 def updateFaceList(self, chsr, objlist):
     namelist = [
         "Face %d, nodes %s (area: %g)" %
         (obj.uiIdentifier(), tuple(o.uiIdentifier()
                                    for o in obj.getNodes()), obj.area())
         for obj in objlist
     ]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #30
0
 def updateSegmentList(self, chsr, objlist):
     # called only when Skeleton readlock has been obtained.
     namelist = [
         "Segment %d, nodes (%d, %d) (length: %s)" %
         (obj.index, obj.nodes()[0].index, obj.nodes()[1].index,
          obj.length()) for obj in objlist
     ]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #31
0
 def contourmapTextColor(self, menuitem, color):
     self.acquireGfxLock()
     try:
         ghostgfxwindow.GhostGfxWindow.contourmapTextColor(self, menuitem, color)
         mainthread.runBlock(self.oofcanvas.set_contourmap_textcolor, (color,))
         self.oofcanvas.render()
     finally:
         self.releaseGfxLock()
예제 #32
0
 def __init__(self, name, gfxmgr, clone=0):
     debug.subthreadTest()
     self.gfxlock = lock.Lock()
     mainthread.runBlock(self.preinitialize, (name, gfxmgr, clone))
     self.newCanvas()
     ghostgfxwindow.GhostGfxWindow.__init__(self, name, gfxmgr,
                                            clone=clone)
     mainthread.runBlock(self.postinitialize, (name, gfxmgr, clone))
예제 #33
0
 def updateSegmentList(self, chsr, objlist):
     namelist = [
         "Segment %d, nodes %s (length: %g)" %
         (obj.uiIdentifier(), tuple(o.uiIdentifier()
                                    for o in obj.getNodes()), obj.length())
         for obj in objlist
     ]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #34
0
 def destroy(self, destroy_canvaslayer=True):
     self.gfxwindow = None  # TODO OPT: Is this necessary?
     if self.whoChangedSignal:
         switchboard.removeCallback(self.whoChangedSignal)
         switchboard.removeCallback(self.whoRenamedSignal)
     if destroy_canvaslayer and self.canvaslayer is not None:
         mainthread.runBlock(self.canvaslayer.destroy)
         self.canvaslayer = None
예제 #35
0
 def nextCB(self, *args):  # go to the next history item
     self.historyBuffer.next()
     self.inhibit = 1
     self.setCB(self.historyBuffer.current(), **self.setCBkwargs)
     self.inhibit = 0
     self.editingHistory = 1
     if self.sensitizeCB:
         mainthread.runBlock(self.sensitizeCB)
예제 #36
0
 def bgColor(self, menuitem, color):
     self.acquireGfxLock()
     try:
         ghostgfxwindow.GhostGfxWindow.bgColor(self, menuitem, color)
         mainthread.runBlock(self.oofcanvas.set_bgColor, (color,))
         self.oofcanvas.render()
     finally:
         self.releaseGfxLock()
예제 #37
0
 def bgColor(self, menuitem, color):
     self.acquireGfxLock()
     try:
         ghostgfxwindow.GhostGfxWindow.bgColor(self, menuitem, color)
         mainthread.runBlock(self.oofcanvas.set_bgColor, (color, ))
         self.oofcanvas.render()
     finally:
         self.releaseGfxLock()
예제 #38
0
    def update(self, indx):
        debug.subthreadTest()
        skelctxt = self.getContext()
        if not skelctxt:
            return
        skeleton = skelctxt.getObject()
        if indx is not None and 0 <= indx < skeleton.nelements():
            skelctxt.begin_reading()
            try:
                microstructure = skeleton.getMicrostructure()
                # If the user typed the index, instead of clicking on
                # an element, it could be invalid.
                if indx < 0 or indx >= skeleton.nelements():
                    return

                element = skeleton.getElement(indx)
                assert element is not None

                if config.dimension() == 3:
                    self.updateFaceList(self.faces,
                                        skeleton.getElementFaces(element))
                self.updateSegmentList(self.segs,
                                       skeleton.getElementSegments(element))
                self.updateNodeList(self.nodes, element.getNodes(), element)

                eid = ` indx `
                etype = skeleton.getElementType(element.getIndex())
                if config.dimension() == 3:
                    earea = "%g" % element.volume()
                elif config.dimension() == 2:
                    earea = "%g" % element.area()
                if not element.illegal():
                    domCat = element.dominantPixel(skeleton)
                    hom = "%f" % element.homogeneity(skeleton)
                    eshape = "%f" % element.energyShape()
                    mat = element.material(skeleton)
                    egrps = ", ".join(element.groupNames())
                    if mat:
                        matname = mat.name()
                    else:
                        matname = "<No material>"
                else:  # illegal element
                    domCat = "Not Computed"
                    egrps = "???"
                    hom = "???"
                    eshape = "???"
                    matname = "???"
                mainthread.runBlock(self.update_thread,
                                    (etype, eid, earea, ` domCat
                                     `, egrps, hom, eshape, matname))
                return
            finally:
                skelctxt.end_reading()
        # end if indx is not None
        # Nothing to display -- no element or no indx.
        mainthread.runBlock(self.update_thread,
                            ("", "", "", "", "", "", "", ""))
        mainthread.runBlock(self.clearObjLists)
예제 #39
0
    def updateSomething(self, container):
        debug.subthreadTest()
        node = container.object
        skeleton = container.skeleton
        container.context.begin_reading()
        try:
            nindex = `node.getIndex()`
            if config.dimension() == 2:
                npos = "(%s, %s)" % (node.position().x, node.position().y)
            elif config.dimension() == 3:
                npos = "(%s, %s, %s)" % (node.position().x, 
                                         node.position().y, node.position().z)
            
            if config.dimension() == 2:
                if node.movable_x() and node.movable_y():
                    nmob = "free"
                elif node.movable_x() and not node.movable_y():
                    nmob = "x only"
                elif not node.movable_x() and node.movable_y():
                    nmob = "y only"
                elif node.pinned():
                    nmob = "pinned"
                else:
                    nmob = "fixed"
            elif config.dimension() == 3:
                if node.movable_x() and node.movable_y() and node.movable_z():
                    nmob = "free"
                elif node.movable_x() and node.movable_y() and not node.movable_z():
                    nmob = "x and y only"
                elif node.movable_x() and not node.movable_y() and node.movable_z():
                    nmob = "x and z only"
                elif not node.movable_x() and node.movable_y() and node.movable_z():
                    nmob = "y and z only"
                elif node.movable_x() and not node.movable_y() and not node.movable_z():
                    nmob = "x only"
                elif not node.movable_x() and node.movable_y() and not node.movable_z():
                    nmob = "y only"
                elif not node.movable_x() and not node.movable_y() and node.movable_z():
                    nmob = "z only"
                elif node.pinned():
                    nmob = "pinned"
                else:
                    nmob = "fixed"

            self.updateElementList(self.elem, node.neighborElements())
            self.syncPeeker(self.elem, "Element")

            self.updateGroup(node)

            bdys = []
            for key, bdy in skeleton.pointboundaries.items():
                if node in bdy.nodes:
                    bdys.append(key)
            bdynames = string.join(bdys, ", ")
        finally:
            container.context.end_reading()
        mainthread.runBlock(self.updateSomething_thread,
                            (nindex, npos, nmob, bdynames))
예제 #40
0
 def close(self, *args):
     # The subwindow menu-removal can't depend on the existence of
     # .gtk, and it's done in the non-GUI parent, so call it
     # if this is the first time through.
     if not self.closed:
         ghostgfxwindow.GhostGfxWindow.close(self, *args)
         self.closed = 1
     if self.gtk:
         mainthread.runBlock(self.gtk.destroy)  # calls destroyCB via gtk
예제 #41
0
 def handleMode(self, targetname):
     for mode in modes:
         if mode.targetname == targetname:
             if self.modeclass is not mode:
                 self.clearPosition()
                 # Call changeModeCB on main thread
                 mainthread.runBlock(
                     self.modebuttondict[targetname].set_active, (1, ))
             break
예제 #42
0
 def close(self, *args): 
     # The subwindow menu-removal can't depend on the existence of
     # .gtk, and it's done in the non-GUI parent, so call it
     # if this is the first time through.
     if not self.closed:
         ghostgfxwindow.GhostGfxWindow.close(self, *args)
         self.closed = 1
     if self.gtk:
         mainthread.runBlock(self.gtk.destroy) # calls destroyCB via gtk
예제 #43
0
 def destroyCB(self, *args, **kwargs):
     if self.gtk is not None:        # recursion suppression
         selfgtk = self.gtk
         self.gtk = None
         map(switchboard.removeCallback, self.sbcallbacks)
         if self.whowidgetsignal:
             switchboard.removeCallback(self.whowidgetsignal)
         mainthread.runBlock(selfgtk.destroy)
         layereditor.LayerEditor.destroy(self)
예제 #44
0
 def handleMode(self, targetname):
     for mode in modes:
         if mode.targetname == targetname:
             if self.modeclass is not mode:
                 self.clearPosition()
                 # Call changeModeCB on main thread
                 mainthread.runBlock(
                     self.modebuttondict[targetname].set_active, (1,))
             break
예제 #45
0
 def prevCB(self, *args):            # go to the previous history item
     if self.editingHistory:
         self.historyBuffer.prev()
     self.inhibit = 1
     self.setCB(self.historyBuffer.current(), **self.setCBkwargs)
     self.inhibit = 0
     self.editingHistory = 1
     if self.sensitizeCB:
         mainthread.runBlock(self.sensitizeCB)
예제 #46
0
 def _updateQuerySubthread(self):
     self.meshcontext.restoreCachedData(self.gfxwindow().displayTime)
     try:
         mainthread.runBlock(self.modeobj.updateSomething,
                             (self.toolbox.querier,))
     finally:
         self.meshcontext.releaseCachedData()
     gtklogger.checkpoint(self.gfxwindow().name + " " +
                          self._name + " updated")
예제 #47
0
 def _updateQuerySubthread(self):
     self.meshcontext.restoreCachedData(self.gfxwindow().displayTime)
     try:
         mainthread.runBlock(self.modeobj.updateSomething,
                             (self.toolbox.querier,))
     finally:
         self.meshcontext.releaseCachedData()
     gtklogger.checkpoint(self.gfxwindow().name + " " +
                          self._name + " updated")
예제 #48
0
 def destroyCB(self, *args, **kwargs):
     if self.gtk is not None:  # recursion suppression
         selfgtk = self.gtk
         self.gtk = None
         map(switchboard.removeCallback, self.sbcallbacks)
         if self.whowidgetsignal:
             switchboard.removeCallback(self.whowidgetsignal)
         mainthread.runBlock(selfgtk.destroy)
         layereditor.LayerEditor.destroy(self)
예제 #49
0
 def prevCB(self, *args):  # go to the previous history item
     if self.editingHistory:
         self.historyBuffer.prev()
     self.inhibit = 1
     self.setCB(self.historyBuffer.current(), **self.setCBkwargs)
     self.inhibit = 0
     self.editingHistory = 1
     if self.sensitizeCB:
         mainthread.runBlock(self.sensitizeCB)
예제 #50
0
 def newwhoMS(self, whoname): # switchboard ('new who', 'Microstructure')
     # whoname is a list of strings
     self.grouplock.acquire()
     try:
         mainthread.runBlock(self.mswidget.set_value, (whoname,))
         self.rebuild_grouplist()
         self.displayMSInfo()
         self.sensitize()
     finally:
         self.grouplock.release()
예제 #51
0
 def stateChangeCB(self, *args):     # call this when the selector changes
     if self.inhibit:
         return
     self.editingHistory = 0
     try:
         self.historyBuffer.last()
     except IndexError:
         pass
     if self.sensitizeCB:
         mainthread.runBlock(self.sensitizeCB)
예제 #52
0
 def newCanvas(self):
     # Recreate the canvas object.
     # It's important to acquire and release the lock in the
     # subthread, before calling mainthread.runBlock, to avoid
     # deadlocks.
     debug.subthreadTest()
     self.acquireGfxLock()
     try:
         mainthread.runBlock(self.newCanvas_thread)
     finally:
         self.releaseGfxLock()
예제 #53
0
    def updateSomething(self, container):
        debug.subthreadTest()
        element = container.object
        skeleton = container.skeleton

        container.context.begin_reading()
        try:
            etype = `element.type()`[1:-1] # strip quotes
            eindex = `element.getIndex()`

            if config.dimension() == 2:
                self.updateNodeListAngle(self.nodes, element)
            elif config.dimension() == 3:
                self.updateNodeList(self.nodes, element.nodes)
            # Clear the selection in the list of nodes if there's
            # nothing in the peeker.
            self.syncPeeker(self.nodes, "Node")

            esegs = element.getSegments(skeleton)
            self.updateSegmentList(self.segs, esegs)
            # Clear the selection in the list of segments if there's
            # nothing in the peeker.
            self.syncPeeker(self.segs, "Segment")

            if config.dimension() == 2:
                earea = "%s" % element.area()
            elif config.dimension() == 3:
                earea = "%s" % element.volume()

            if not element.illegal():
                domCat = element.dominantPixel(skeleton.MS)
                repPix = skeleton.MS.getRepresentativePixel(domCat)
                pixGrp = pixelgroup.pixelGroupNames(skeleton.MS, repPix)
                pixgrps = string.join(pixGrp, ", ")
                ehom = "%f" % element.homogeneity(skeleton.MS)
                eshape = "%f" % element.energyShape()

                mat = element.material(container.context)
                if mat:
                    matname = mat.name()
                else:
                    matname = "<No material>"
            else:                           # illegal element
                pixgrps = "???"
                ehom = "???"
                eshape = "???"
                matname = "???"
            self.updateGroup(element)
        finally:
            container.context.end_reading()
        mainthread.runBlock(self.updateSomething_thread,
                            (etype, eindex, earea, pixgrps, ehom, eshape,
                             matname))
예제 #54
0
    def update_subthread(self, skelcontext):
        # Get the selection from the skeleton context
        if skelcontext:
            n = self.selectionSize()    # requires subthread
            status_text = " %d %s%s selected." % (n,
                                                  self.activemode.name(),
                                                  's'*(n!=1))
        else:
            status_text = "No Skeleton selected."

        mainthread.runBlock(self.status.set_text, (status_text,))
        gtklogger.checkpoint("skeleton selection page updated")
예제 #55
0
파일: gfxmenu.py 프로젝트: anilkunwar/OOF2
def _CheckOOFMenuItem___call__(self, active):
    _old_CheckOOFMenuItem___call__(self, active)
    # Before calling set_active(), it's necessary to disable the gtk
    # callback mechanism for the button, so that set_active() won't
    # call the callback, which calls this function, which calls
    # set_active(), ad infinitum.
    try:
        gtkitem = self.gtkitem
    except AttributeError:
        pass
    else:
        mainthread.runBlock(_setactive, (gtkitem, self.handlerid, active))
예제 #56
0
 def updateNodeList(self, chsr, objlist):
     # called only when Skeleton readlock has been obtained.
     if config.dimension() == 2:
         namelist = ["Node %d at (%s, %s)" % (obj.index, obj.position().x,
                                              obj.position().y)
                     for obj in objlist]
     elif config.dimension() == 3:
         namelist = ["Node %d at (%s, %s, %s)" % (obj.index,
                                                  obj.position().x,
                                                  obj.position().y,
                                                  obj.position().z)
                     for obj in objlist]
     mainthread.runBlock(chsr.update, (objlist, namelist))
예제 #57
0
 def setMeshableButton(self):
     debug.subthreadTest()
     mscontext = self.currentMScontext()
     if mscontext:
         mscontext.begin_reading()
         try:
             grp = self.currentGroup()
             meshable = grp is not None and grp.is_meshable()
         finally:
             mscontext.end_reading()
     else:
         meshable = False
     mainthread.runBlock(self.setMeshableButton_thread, (meshable,))
예제 #58
0
 def updateQuery(self):
     if not self.toolbox.querier:
         return
     # See if there's anything to update ...
     if self.toolbox.querier.object:
         # Change mode if needed.
         self.handleMode(self.toolbox.querier.targetname)
         querier = self.toolbox.querier
         self.modeobj.updateSomething(querier)
         mainthread.runBlock(self.showPosition,(querier.position,))
     else:
         mainthread.runBlock(self.modeobj.updateNothing)
     switchboard.notify("redraw")
     self.sensitize()
예제 #59
0
 def zoomFillWindow(self, *args, **kwargs):
     # This has args because it's used as a menuitem callback.  The
     # 'lock' argument is not a menu argument, though.  It's only
     # used when zoomFillWindow is called explicitly from within
     # another drawing routine, to indicate that the gfxLock has
     # already been acquired.
     lock = kwargs.get('lock', True) # default is to acquire the lock
     if lock:
         self.acquireGfxLock()
     try:
         mainthread.runBlock(self.zoomFillWindow_thread)
     finally:
         if lock:
             self.releaseGfxLock()    
예제 #60
0
파일: worker.py 프로젝트: anilkunwar/OOF2
 def start(self):
     if self.menuitem.callback is not None:
         try:
             self.initialize()
             try:
                 mainthread.runBlock(self.menuitem.precall)
                 mainthread.runBlock(self.menuitem.callback,
                                     (self,)+self.args,
                                     self.kwargs)
                 # remove_excepthook is called here only if no
                 # exception occured.  If an exception occured,
                 # remove_excepthook can't be called until after
                 # the exception is handled.
                 excepthook.remove_excepthook(self.excepthook)
             except SystemExit:
                 raise
             # TODO SWIG1.3: After conversion to SWIG 1.3, OOF
             # exceptions will probably be subclasses of Exception.
             except (Exception, ooferror.ErrErrorPtr), exception:
                 mainthread.runBlock(self.menuitem.postcall, (False,))
                 if propagate_exceptions or not self.toplevel:
                     excepthook.remove_excepthook(self.excepthook)
                     raise
                 else:
                     reporter.error(exception)
                     sys.excepthook(*sys.exc_info())
             else:           # no exception
                 mainthread.runBlock(self.menuitem.postcall, (True,))