def _createStructure(self): """ Creates and returns the structure (in this case a L{NanotubeSegment} object. @return : Nanotube segment that include the nanotube chunk. @rtype: L{NanotubeSegment} """ # self.name needed for done message if self.create_name_from_prefix: # create a new name name = self.name = gensym(self.prefix, self.win.assy) # (in _build_struct) self._gensym_data_for_reusing_name = (self.prefix, name) else: # use externally created name self._gensym_data_for_reusing_name = None # (can't reuse name in this case -- not sure what prefix it was # made with) name = self.name # Create the model tree group node. # Make sure that the 'topnode' of this part is a Group (under which the # DNa group will be placed), if the topnode is not a group, make it a # a 'Group' (applicable to Clipboard parts).See part.py # --Part.ensure_toplevel_group method. This is an important line # and it fixes bug 2585 self.win.assy.part.ensure_toplevel_group() ntSegment = NanotubeSegment(self.name, self.win.assy, self.win.assy.part.topnode, editCommand = self ) try: # Make the NanotubeSegment. n, m, type, endings, endPoint1, endPoint2 = self._gatherParameters() from cnt.model.Nanotube import Nanotube self.nanotube = Nanotube() nanotube = self.nanotube nanotube.setChirality(n, m) nanotube.setType(type) nanotube.setEndings(endings) nanotube.setEndPoints(endPoint1, endPoint2) position = V(0.0, 0.0, 0.0) ntChunk = nanotube.build(self.name, self.win.assy, position) nanotube.computeEndPointsFromChunk(ntChunk) ntSegment.addchild(ntChunk) #set some properties such as nanotubeRise #This information will be stored on the NanotubeSegment object so that #it can be retrieved while editing this object. #Should these props be assigned to the NanotubeSegment in #Nanotube.build() itself? This needs to be answered while modifying #build() method to fit in the dna data model. --Ninad 2008-03-05 #WARNING 2008-03-05: Since self._modifyStructure calls #self._createStructure() #If in the near future, we actually permit modifying a #structure (such as dna) without actually recreating the whole #structure, then the following properties must be set in #self._modifyStructure as well. Needs more thought. props =(nanotube.getChirality(), nanotube.getType(), nanotube.getEndings(), nanotube.getEndPoints()) ntSegment.setProps(props) return ntSegment except (PluginBug, UserError): # Why do we need UserError here? Mark 2007-08-28 ntSegment.kill() raise PluginBug("Internal error while trying to create a NanotubeSegment.") return