def _newactivearea(menuitem, microstructure, name): ms_obj = ms_module.getMicrostructure(microstructure) new_aa = activearea.ActiveArea(ms_obj.sizeInPixels(), ms_obj.size(), ms_obj) new_aa.rename(name) ms_obj.namedActiveAreas.append(new_aa) switchboard.notify('stored active areas changed', name)
def __init__(self, name, isize, size): cmicrostructure.CMicrostructure.__init__(self, name, isize, size) self._isize = isize # iPoint(width, height) in pixels # Make sure that the physical size isn't stored as ints, which # could cause problems later (specifically when computing the # aspect ratio of the microstructure, as in # Skeleton.hashNodes). This *isn't* done in the Point # constructor, since it might be slow. if config.dimension() == 2: self._size = primitives.Point(float(size.x), float(size.y)) elif config.dimension() == 3: self._size = primitives.Point(float(size.x), float(size.y), float(size.z)) # Also store increments. if config.dimension() == 2: self._delta = (self._size[0] / self._isize[0], self._size[1] / self._isize[1]) elif config.dimension() == 3: self._delta = (self._size[0] / self._isize[0], self._size[1] / self._isize[1], self._size[2] / self._isize[2]) # The 'parent' arg to pixelselectionWhoClass.add and # activeareaWhoClass.add should be set to the Who object for # this MS, which hasn't been created yet. So it's set to None # here, and fixed later. pixsel = pixelselection.PixelSelection(isize, size, self) pixelselection.pixelselectionWhoClass.add(name, pixsel, parent=None) self.pixelselection = pixelselection.pixelselectionWhoClass[name] self.activearea = activearea.activeareaWhoClass.add( name, activearea.ActiveArea(isize, size, self), parent=None) self.namedActiveAreas = [] self.setCurrentActiveArea(self.activearea.getObject()) # Plug-ins have to be created before the Microstructure # context Who object is created, because Who object creation # might trigger switchboard calls that use the plug-ins. self.plugins = {} for pluginname, pluginclass in plugInClasses.items(): self.plugins[pluginname] = pluginclass(self) # Create the Who object for this Microstructure, and add it to # list of all Microstructures. Do this last, because it calls # switchboard callbacks that may assume that the MS is fully # constructed. mswho = microStructures.add(name, self, parent=None) # Fix the 'parent' for the pixelselection and activearea. See # comment above. self.pixelselection.setParent(mswho) self.activearea.setParent(mswho) self.sbcallbacks = [ switchboard.requestCallback(('who changed', 'Active Area'), self.aaChangedCB) ]