def creatorcallback(self, menuitem, **kwargs): treepath = string.split(menuitem.path(),".")[3:] reg = self.data[treepath].object name = menuitem.params[0].value # Collision looks for the name under this tree, and if it # finds it, checks if the parameter values are all equal. If # a collision occurs and the parameters conflict, an exception # is raised. If collision returns "true", that means a # collision occurred but the parameters matched. If collision # returns "false", a collision did not occur. namecollision, parametercollision = reg.collision(name, menuitem.params[1:]) if namecollision: # name is a duplicate if parametercollision: # parameters disagree if name != "": raise ooferror.ErrSetupError("Named property in datafile conflicts with existing property '%s'" % name) # reparametrization of unnamed property if reg.materials: raise ooferror.ErrSetupError("Unnamed property in datafile conflicts with existing property '%s'" % name) # Unnamed property is being reparametrized, but it's # not used in any materials, so it's ok. reg.new_params(**kwargs) switchboard.notify("redraw") # A name collision with no parameter collision doesn't # require any action. The data file contained a property # identical to an existing property. else: # No collision, we must create a new NamedRegistration. # We know it's a NamedRegistration because unnamed # property registrations *always* produce a name conflict. fullname = string.join( treepath + [name], ":") newreg = reg.named_copy(fullname, menuitem.params[1:]) switchboard.notify("redraw")
def try_appendSegsToBdy(self, name, seg_set): try: bdy = self.edgeboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge boundary." % name) return bdy.try_appendSegs(seg_set)
def try_removeFacesFromBdy(self, name, faces): try: bdy = self.faceboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not a face boundary." % name) return bdy.try_removeFaces(faces)
def renameInterface(self, oldname, newname): if oldname == newname: return if newname in self.getCurrentReservedNames(): raise ooferror.ErrSetupError("Name %s already in use." % newname) try: obj = self.namedinterfaces[oldname] del self.namedinterfaces[oldname] self.namedinterfaces[newname] = obj interfacenames = self.getInterfaceNames() #Because of the possibility of compound interfaces (e.g. union), #we must search the other interfaces for the presence #of the interface corresponding to oldname. for interfacename in interfacenames: interfaceobj = self.namedinterfaces[interfacename] interfaceobj.renameInterface(oldname, newname) #interface must also be renamed in the list of #material assignments matname = self.getInterfaceMaterialName(oldname) self.removeMaterialFromInterfaces([oldname]) self.assignMaterialToInterfaces(matname, [newname]) #Rename the interface in the boundary conditions #and in the edgements. meshclass = ooflib.engine.mesh.meshes msname = self.microstructure.name() for meshkey in meshclass.keys(base=msname): meshctxt = meshclass[[msname] + meshkey] meshctxt.renameInterface(oldname, newname) self.selectInterface(newname) switchboard.notify("interface renamed", self.microstructure) except KeyError: pass
def removeFacesFromBdy(self, name, faces): try: bdy = self.faceboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not a face boundary." % name) bdy.removeFaces(faces) self.bdyPropagate(name, bdy)
def addNodesToBdy(self, name, node_list): try: bdy = self.pointboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not a point boundary." % name) bdy.appendNodes(node_list) self.bdyPropagate(name, bdy)
def try_removeSegsfromBdy(self, name, seg_set): try: bdy = self.edgeboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge Boundary." % name) return bdy.try_delete(seg_set)
def appendSegsToBdy(self, name, seg_set): try: bdy = self.edgeboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge boundary." % name) bdy.appendSegs(seg_set) self.bdyPropagate(name, bdy)
def __init__(self, question, *answers, **kwargs): debug.mainthreadTest() if len(answers) == 0: raise ooferror.ErrSetupError( "Questioner must have at least one possible answer.") self.answers = answers self.gtk = gtklogger.Dialog() self.gtk.set_keep_above(True) gtklogger.newTopLevelWidget(self.gtk, "Questioner") hbox = gtk.HBox() self.gtk.vbox.pack_start(hbox, padding=15) hbox.pack_start(gtk.Label(question), padding=15) self.defaultbutton = None try: self.default = kwargs['default'] except KeyError: self.default = None else: if not self.default in answers: self.answers = (self.default, ) + answers self.answerdict = {} count = 1 for answer in self.answers: #TODO:Replace the try except block with this #stock = answer["stock"] #choice = answer["choice"] #icon = gtk.stock_lookup(stock) #if icon is None: # debug.fmsg('no gtk stock icon for id: ', stock) # self.gtk.add_button(choice, count) #else: # button = self.gtk.add_button(icon, count) # label = gtkutils.findChild(gtk.Label, button) # label.set_text(choice) #if answer["stock"] == self.default["stock"]: # self.gtk.set_default_response(count) try: stock = _stock[answer] button = self.gtk.add_button(stock, count) # Replace the label on the stock button with the answer text. label = gtkutils.findChild(gtk.Label, button) label.set_text(answer) except KeyError: debug.fmsg('no stock icon for', answer) self.gtk.add_button(answer, count) self.answerdict[count] = answer if answer == self.default: self.gtk.set_default_response(count) count += 1 hbox.show_all()
def removeNodesfromBdy(self, name, node_list): try: bdy = self.pointboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not a point boundary." % name) bdy.delete(node_list) self.bdyPropagate(name, bdy) self.bdytimestamp.increment()
def removeSegsfromBdy(self, name, seg_set): try: bdy = self.edgeboundaries[name] except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge boundary." % name) bdy.delete(seg_set) self.bdyPropagate(name, bdy) self.bdytimestamp.increment()
def reverseBoundary(self, name): ## print "BEGIN skeletoncontext:reverseBoundary" ## print self.edgeboundaries["bottom"].current_boundary().edges try: bdy = self.edgeboundaries[name] # SkelContextEdgeBoundary except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge boundary." % name) bdy.reverse() self.bdyPropagate(name, bdy) self.bdytimestamp.increment()
def reverseBoundary(self, name): try: bdy = self.edgeboundaries[name] # SkelContextEdgeBoundary except KeyError: try: bdy = self.faceboundaries[name] # SkelContextFaceBoundary except KeyError: raise ooferror.ErrSetupError( "Boundary %s is not an edge or face boundary." % name) bdy.reverse() self.bdyPropagate(name, bdy)
def renameBoundary(self, oldname, newname): if oldname == newname: return if newname in self.allBoundaryNames(): raise ooferror.ErrSetupError("Name %s already in use." % newname) if config.dimension() == 2 and runtimeflags.surface_mode: if newname in self.allInterfaceNames(): raise ooferror.ErrSetupError( "Name %s is already in use as an interface name." % newname) ## TODO 3.1: Use virtual methods in the boundary classes instead ## of this ugly if/elif. There should be just one dict for ## the name lookup. if oldname in self.faceboundaries: bdydict = self.faceboundaries elif oldname in self.edgeboundaries: bdydict = self.edgeboundaries elif oldname in self.pointboundaries: bdydict = self.pointboundaries else: raise ooferror.ErrPyProgrammingError( "Boundary name %s not found." % oldname) bdydict[newname] = bdydict[oldname] del bdydict[oldname] # SkelContextBoundary.rename calls Skeleton.renameBoundary bdydict[newname].rename(newname) # Maintain consistency in Meshes for mesh in self.getMeshes(): mesh.renameBoundary(oldname, newname) switchboard.notify("boundary renamed", self) # self.bdytimestamp.increment() self.selectBoundary(newname) switchboard.notify("new boundary configuration", self)
def renameBoundary(self, oldname, newname): if oldname == newname: return if newname in self.allBoundaryNames(): raise ooferror.ErrSetupError("Name %s is already in use." % newname) #Interface branch if config.dimension() == 2 and runtimeflags.surface_mode: if newname in self.allInterfaceNames(): raise ooferror.ErrSetupError( "Name %s is already in use as an interface name." % newname) if oldname in self.edgeboundaries: dict = self.edgeboundaries elif oldname in self.pointboundaries: dict = self.pointboundaries else: raise ooferror.ErrPyProgrammingError( "Boundary name %s not found." % oldname) dict[newname] = dict[oldname] del dict[oldname] # SkelContextBoundary.rename calls Skeleton.renameBoundary dict[newname].rename(newname) # Maintain consistency in Meshes for mesh in self.getMeshes(): mesh.renameBoundary(oldname, newname) switchboard.notify("boundary renamed", self) self.bdytimestamp.increment() self.selectBoundary(newname)
def start_sockets_Front_End(): if parallel_enable.enabled(): try: from ooflib.SWIG.common import mpitools except ImportError: raise ooferror.ErrSetupError( "Parallel option requested, but parallel code not present.") from ooflib.common.IO import socket2me ## Tell back end what port to listen s_name = mpitools.Get_processor_name() s_address = socket2me.socketPort.getPort() mpitools.bcast_string("%i" % s_address, 0) mpitools.bcast_string(s_name, 0) ## Tell back end the number of processors on the back end socket2me.socketPort.connect(mpitools.Size() - 1)
def setSize(self, sighs): self._size = sighs if self._sizeInPixels != self._size: tempimage = vtk.vtkImageData() changer = vtk.vtkImageChangeInformation() x_spacing = self._size[0]/self._sizeInPixels[0] y_spacing = self._size[1]/self._sizeInPixels[1] z_spacing = self._size[2]/self._sizeInPixels[2] tempimage = self.image changer.SetInput(tempimage) if not (x_spacing and y_spacing and z_spacing): raise ooferror.ErrSetupError("Pixels have zero size!") changer.SetOutputSpacing(x_spacing, y_spacing, z_spacing) self.image = changer.GetOutput() self.image.Update()
def padImage(self, amount=1): # pad the image with extra voxels because of vtk off by 1 # annoyance in calculating image bounds self.image.Update() extent = list(self.image.GetExtent()) if extent[1]+amount<=1 or extent[3]+amount<=1 or extent[5]+amount<=1: raise ooferror.ErrSetupError("Image dimensions too small") for i in xrange(1,7,2): extent[i] += amount padder = vtk.vtkImageConstantPad() padder.SetInput(self.image) padder.SetOutputWholeExtent(extent) padder.SetConstant(255) temp = padder.GetOutput() self.image = temp self.image.Update()
def __init__(self, question, *answers, **kwargs): debug.mainthreadTest() if len(answers)==0: raise ooferror.ErrSetupError( "Questioner must have at least one possible answer.") self.answers = answers self.gtk = gtklogger.Dialog(parent=guitop.top().gtk) gtklogger.newTopLevelWidget(self.gtk, "Questioner") hbox = gtk.HBox() self.gtk.vbox.pack_start(hbox, padding=15) hbox.pack_start(gtk.Label(question), padding=15) self.defaultbutton = None try: self.default = kwargs['default'] except KeyError: self.default=None else: if not self.default in answers: self.answers = (self.default,)+answers self.answerdict = {} count = 1 for answer in self.answers: try: stock = _stock[answer] button = self.gtk.add_button(stock, count) # Replace the label on the stock button with the answer text. label = gtkutils.findChild(gtk.Label, button) label.set_text(answer) except KeyError: debug.fmsg('no stock icon for', answer) self.gtk.add_button(answer, count) self.answerdict[count] = answer if answer == self.default: self.gtk.set_default_response(count) count += 1 hbox.show_all()