def saveTdosToLibrary(self): fileInfo = SaveFileNamesStructure() suggestedName = "" outputFile = TextFile() i = 0 tdo = KfObject3D() suggestedName = udomain.domain.defaultTdoLibraryFileName if not usupport.getFileSaveInfo(usupport.kFileTypeTdo, usupport.kDontAskForFileName, suggestedName, fileInfo): return AssignFile(outputFile, fileInfo.tempFile) try: # v1.5 usupport.setDecimalSeparator() Rewrite(outputFile) usupport.startFileSave(fileInfo) if self.tdos.Items.Count > 0: for i in range(0, self.tdos.Items.Count): tdo = UNRESOLVED.TObject(self.tdos.Items.Objects[i]) as utdo.KfObject3D if tdo == None: continue tdo.writeToFileStream(outputFile, utdo.kInTdoLibrary) fileInfo.writingWasSuccessful = true finally: CloseFile(outputFile) usupport.cleanUpAfterFileSave(fileInfo) self.setLibraryChanged(false)
def saveListAsClick(self, Sender): fileInfo = SaveFileNamesStructure() if self.DebugList.Items.Count <= 0: return if not usupport.getFileSaveInfo(usupport.kFileTypeExceptionList, usupport.kAskForFileName, "pstudio.nex", fileInfo): return try: self.saveExceptionListToFile(fileInfo.tempFile) fileInfo.writingWasSuccessful = true finally: usupport.cleanUpAfterFileSave(fileInfo)
def saveListAsClick(self, Sender): fileInfo = SaveFileNamesStructure() if self.infoList.Lines.Count <= 0: return if not usupport.getFileSaveInfo(usupport.kFileTypeProgramInfo, usupport.kAskForFileName, "PStudio.txt", fileInfo): return try: self.saveInfoListToFile(fileInfo.tempFile) fileInfo.writingWasSuccessful = true finally: usupport.cleanUpAfterFileSave(fileInfo)
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