def selectTdoBasedOn(self, aTdo): indexToSelect = 0 i = 0 tdo = KfObject3D() # assumes initialize already called and tdos already in list indexToSelect = -1 if self.tdos.Items.Count > 0: for i in range(0, self.tdos.Items.Count): tdo = utdo.KfObject3D(self.tdos.Items.Objects[i]) if tdo.isSameAs(aTdo): indexToSelect = i break if indexToSelect < 0: if MessageDialog("This 3D object is not in the current library." + chr(13) + "Its name or shape is different from the 3D objects in the list." + chr(13) + chr(13) + "Do you want to add this 3D object to the library?", mtWarning, [mbYes, mbNo, ], 0) == delphi_compatability.IDNO: return tdo = utdo.KfObject3D().create() tdo.copyFrom(aTdo) self.tdos.Items.AddObject(tdo.name, tdo) self.grid.RowCount = self.tdos.Items.Count / self.grid.ColCount + 1 self.libraryGroupBox.Caption = "The current library has " + IntToStr(self.tdos.Items.Count) + " object(s)" self.setLibraryChanged(true) indexToSelect = self.tdos.Items.Count - 1 if indexToSelect >= 0: self.selectTdoAtIndex(indexToSelect)
def newTdoClick(self, Sender): tdoEditorForm = TTdoEditorForm() response = 0 newTdo = KfObject3D() newName = "" newName = "" newTdo = utdo.KfObject3D().create() newTdo.setName("New 3D object") tdoEditorForm = utdoedit.TTdoEditorForm().create(self) if tdoEditorForm == None: raise GeneralException.create("Problem: Could not create 3D object editor window.") try: tdoEditorForm.initializeWithTdo(newTdo) response = tdoEditorForm.ShowModal() if response == mrOK: if newTdo.getName() == "New 3D object": if InputQuery("Name 3D object", "Enter a name for the new 3D object", newName): newTdo.setName(newName) else: newTdo.setName("Unnamed 3D object") newTdo.copyFrom(tdoEditorForm.tdo) self.editedTdo = true self.tdos.Items.AddObject(newTdo.name, newTdo) self.grid.RowCount = self.tdos.Items.Count / self.grid.ColCount + 1 self.selectTdoAtIndex(self.tdos.Items.Count - 1) self.libraryGroupBox.Caption = "The current library has " + IntToStr(self.tdos.Items.Count) + " object(s)" self.setLibraryChanged(true) self.chooseTdoFromList(self.tdos.Items.IndexOfObject(self.selectedTdo())) finally: tdoEditorForm.free tdoEditorForm = None
def readTdosFromFile(self): result = false newTdo = KfObject3D() inputFile = TextFile() # returns false if file could not be found and user canceled finding another result = true self.tdos.Clear() if udomain.domain == None: return result if not udomain.domain.checkForExistingDefaultTdoLibrary(): result = false return result AssignFile(inputFile, udomain.domain.defaultTdoLibraryFileName) try: # v1.5 usupport.setDecimalSeparator() Reset(inputFile) while not UNRESOLVED.eof(inputFile): newTdo = utdo.KfObject3D().create() newTdo.readFromFileStream(inputFile, utdo.kInTdoLibrary) self.tdos.Items.AddObject(newTdo.name, newTdo) finally: CloseFile(inputFile) self.grid.RowCount = self.tdos.Items.Count / self.grid.ColCount + 1 self.libraryGroupBox.Caption = "The current library has " + IntToStr(self.tdos.Items.Count) + " object(s)" return result
def breedFromParents(self, aFirstParent, aSecondParent, fractionOfMaxAge): self.firstParent = aFirstParent if self.firstParent == None: return if udomain.domain == None: return self.secondParent = aSecondParent self.plants.Clear() self.selectedPlants.Clear() tdos = None if (udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary) and (not udomain.domain.checkForExistingDefaultTdoLibrary()): MessageDialog("Because you didn't choose a 3D object library, the breeder won't be able" + chr(13) + "to randomly choose 3D objects for your breeding offspring." + chr(13) + chr(13) + "You can choose a library later by choosing Custom from the Variation menu" + chr(13) + "and choosing a 3D object library there.", mtWarning, [mbOK, ], 0) if udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary: tdos = ucollect.TListCollection() fileNameWithPath = udomain.domain.defaultTdoLibraryFileName if not FileExists(fileNameWithPath): udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary = False else: # cfk note: is it really ok to read the whole tdo file each time? AssignFile(inputFile, fileNameWithPath) try: # v1.5 usupport.setDecimalSeparator() Reset(inputFile) while not UNRESOLVED.eof(inputFile): newTdo = utdo.KfObject3D() newTdo.readFromFileStream(inputFile, utdo.kInTdoLibrary) tdos.Add(newTdo) finally: CloseFile(inputFile) for i in range(0, udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration): newPlant = uplant.PdPlant() self.plants.Add(newPlant) newPlant.reset() if udomain.domain.breedingAndTimeSeriesOptions.variationType != udomain.kBreederVariationNoNumeric: newPlant.randomize() localOptions = uplant.BreedingAndTimeSeriesOptionsStructure() self.setLocalOptionsToDomainOptions(localOptions) newPlant.useBreedingOptionsAndPlantsToSetParameters(localOptions, self.firstParent, self.secondParent, tdos) newAge = intround(newPlant.pGeneral.ageAtMaturity * fractionOfMaxAge) newPlant.setAge(umath.intMin(newAge, newPlant.pGeneral.ageAtMaturity)) # v2.0 plants take rotation angles from first parent newPlant.xRotation = self.firstParent.xRotation newPlant.yRotation = self.firstParent.yRotation newPlant.zRotation = self.firstParent.zRotation
def copyTdoClick(self, Sender): newTdo = KfObject3D() newName = "" if self.selectedTdo() == None: return newName = "Copy of " + self.selectedTdo().getName() if not InputQuery("Enter name for copy", "Type a name for the copy of " + self.selectedTdo().getName(), newName): return newTdo = utdo.KfObject3D().create() self.selectedTdo().copyTo(newTdo) newTdo.setName(newName) self.tdos.Items.AddObject(newTdo.name, newTdo) self.grid.RowCount = self.tdos.Items.Count / self.grid.ColCount + 1 self.selectTdoAtIndex(self.tdos.Items.Count - 1) self.libraryGroupBox.Caption = "The current library has " + IntToStr(self.tdos.Items.Count) + " object(s)" self.setLibraryChanged(true) self.chooseTdoFromList(self.tdos.Items.IndexOfObject(self.selectedTdo()))
#import atk import pygtk pygtk.require('2.0') import gtk #import cairo from gtk_helpers import * import math import uturtle import gtkdrawingsurface import delphi_compatability import utdo example_tdo = utdo.KfObject3D() #example_tdo.readFromFile("./3dobject/l_carrot.tdo") example_tdo.readFromFile("./3dobject/l_squash.tdo") import uplant import ucursor import hotshot prof = None class PlantDrawingArea(gtk.DrawingArea): def __init__(self): gtk.DrawingArea.__init__(self) self.connect("expose_event", self.expose) self.xr = 0 self.yr = 0
def create(self, anOwner): PdParameterPanel.create(self, anOwner) self.tdo = utdo.KfObject3D().create() return self
def tdoForIndex(self, index): result = KfObject3D() result = None if (index >= 0) and (index <= self.tdos.Items.Count - 1): result = utdo.KfObject3D(self.tdos.Items.Objects[index]) return result
def reconcileFileWithTdoLibrary(self, plantFileName, tdoLibrary): result = 0 plantFileTdos = TListCollection() libraryFileTdos = TListCollection() plantFile = TextFile() tdoFile = TextFile() outputTdoFile = TextFile() i = 0 j = 0 tdo = KfObject3d() plantFileTdo = KfObject3d() libraryTdo = KfObject3d() matchInLibrary = false aLine = "" fileInfo = SaveFileNamesStructure() result = 0 if not FileExists(plantFileName): # check that files exist plantFileName = usupport.getFileOpenInfo(usupport.kFileTypePlant, plantFileName, "Choose a plant file") if plantFileName == "": return result if not FileExists(tdoLibrary): tdoLibrary = usupport.getFileOpenInfo(usupport.kFileTypeTdo, tdoLibrary, "Choose a 3D object library (tdo) file") if tdoLibrary == "": return result plantFileTdos = ucollect.TListCollection().Create() libraryFileTdos = ucollect.TListCollection().Create() try: ucursor.cursor_startWait() # read tdos from plants AssignFile(plantFile, plantFileName) try: # v1.5 usupport.setDecimalSeparator() Reset(plantFile) while not UNRESOLVED.eof(plantFile): UNRESOLVED.readln(plantFile, aLine) if UNRESOLVED.pos(utdo.kStartTdoString, aLine) > 0: tdo = utdo.KfObject3D().create() tdo.readFromFileStream(plantFile, utdo.kInTdoLibrary) plantFileTdos.Add(tdo) finally: CloseFile(plantFile) # read tdos from library AssignFile(tdoFile, tdoLibrary) try: # v1.5 usupport.setDecimalSeparator() Reset(tdoFile) while not UNRESOLVED.eof(tdoFile): tdo = utdo.KfObject3D().create() tdo.readFromFileStream(tdoFile, utdo.kInTdoLibrary) libraryFileTdos.Add(tdo) finally: CloseFile(tdoFile) if plantFileTdos.Count > 0: for i in range(0, plantFileTdos.Count): # add plant tdos not in library list to library list plantFileTdo = utdo.KfObject3D(plantFileTdos.Items[i]) matchInLibrary = false if libraryFileTdos.Count > 0: for j in range(0, libraryFileTdos.Count): libraryTdo = utdo.KfObject3D(libraryFileTdos.Items[j]) if plantFileTdo.isSameAs(libraryTdo): matchInLibrary = true break if not matchInLibrary: tdo = utdo.KfObject3D().create() tdo.copyFrom(plantFileTdo) libraryFileTdos.Add(tdo) result += 1 if result > 0: if usupport.getFileSaveInfo(usupport.kFileTypeTdo, usupport.kDontAskForFileName, tdoLibrary, fileInfo): # if any tdos in plant file but not in library, rewrite library AssignFile(outputTdoFile, fileInfo.tempFile) try: # v1.5 usupport.setDecimalSeparator() Rewrite(outputTdoFile) usupport.startFileSave(fileInfo) if libraryFileTdos.Count > 0: for i in range(0, libraryFileTdos.Count): tdo = UNRESOLVED.TObject(libraryFileTdos.Items[i]) as utdo.KfObject3D if tdo == None: continue tdo.writeToFileStream(outputTdoFile, utdo.kInTdoLibrary) fileInfo.writingWasSuccessful = true finally: CloseFile(outputTdoFile) usupport.cleanUpAfterFileSave(fileInfo) finally: plantFileTdos.free libraryFileTdos.free ucursor.cursor_stopWait() return result