def writeToPOV_INCFile(self, fileName, frontFaceColor, embeddedInPlant, rotateCount): outputFile = TextFile() i = 0 triangle = KfIndexTriangle() colorToDraw = TColorRef() nameString = "" AssignFile(outputFile, fileName) try: # v1.5 usupport.setDecimalSeparator() Rewrite(outputFile) nameString = usupport.replacePunctuationWithUnderscores( self.getName()) writeln(outputFile, "// POV-format INC file of PlantStudio v1.x 3D object") writeln(outputFile, "// \"" + self.getName() + "\"") if (not embeddedInPlant): writeln(outputFile, "// include this file in a POV file thus to use it:") writeln( outputFile, "// #include \"" + usupport.stringUpTo(ExtractFileName(fileName), ".") + ".inc\"") writeln(outputFile, "// object { " + nameString + " }") if rotateCount > 1: writeln(outputFile, "// or") writeln(outputFile, "// object { " + nameString + "_rotated }") writeln(outputFile) writeln(outputFile, "#declare " + nameString + "=mesh {") for i in range(0, self.triangles.Count): triangle = KfIndexTriangle(self.triangles.Items[i]) self.writeTriangleToPOV_INCFIle( outputFile, self.points[triangle.pointIndexes[0] - 1], self.points[triangle.pointIndexes[1] - 1], self.points[triangle.pointIndexes[2] - 1]) writeln( outputFile, chr(9) + "pigment { color rgb <" + usupport.digitValueString( UNRESOLVED.getRValue(frontFaceColor) / 256.0) + ", " + usupport.digitValueString( UNRESOLVED.getGValue(frontFaceColor) / 256.0) + ", " + usupport.digitValueString( UNRESOLVED.getBValue(frontFaceColor) / 256.0) + "> }") writeln(outputFile, "}") if rotateCount > 1: writeln(outputFile) writeln(outputFile, "#declare " + nameString + "_rotated=union {") writeln(outputFile, chr(9) + "object { " + nameString + " }") for i in range(1, rotateCount): writeln( outputFile, chr(9) + "object { " + nameString + " rotate " + IntToStr(i) + "*365/" + IntToStr(rotateCount) + "*y }") writeln(outputFile, "}") finally: CloseFile(outputFile)
def readFromTextFile(self, inputFile): inputLine = "" varName = "" varValue = "" while not UNRESOLVED.eof(inputFile): # plant reads start line; just continue from there UNRESOLVED.readln(inputFile, inputLine) if (trim(inputLine) == ""): continue varName = usupport.stringUpTo(inputLine, "=") varValue = usupport.stringBeyond(inputLine, "=") if not self.setField(varName, varValue): break if UNRESOLVED.pos(uppercase(kEndAmendmentString), uppercase(inputLine)) <= 0: raise GeneralException.create("Problem: Expected end of posing change.")
def readFromTextFile(self, inputFile): inputLine = "" varName = "" varValue = "" inputLine = inputFile.readln() while inputLine != None: # plant reads start line; just continue from there if inputLine.strip() == "": continue varName = usupport.stringUpTo(inputLine, "=") varValue = usupport.stringBeyond(inputLine, "=") if not self.setField(varName, varValue): break inputLine = inputFile.readln() if not string_match(kEndAmendmentString, inputLine): raise GeneralException.create("Problem: Expected end of posing change.")
def readFromMemo(self, aMemo, readingMemoLine): inputLine = "" varName = "" varValue = "" while readingMemoLine <= len(aMemo.Lines) - 1: # plant reads start line; just continue from there inputLine = aMemo.Lines.Strings[readingMemoLine] if inputLine.strip() == "": continue varName = usupport.stringUpTo(inputLine, "=") varValue = usupport.stringBeyond(inputLine, "=") if not self.setField(varName, varValue): break readingMemoLine += 1 if not string_match(kEndAmendmentString, inputLine): raise GeneralException.create("Problem: Expected end of posing change.") return readingMemoLine
def readFromMemo(self, aMemo, readingMemoLine): inputLine = "" varName = "" varValue = "" while readingMemoLine <= aMemo.Lines.Count - 1: # plant reads start line; just continue from there inputLine = aMemo.Lines.Strings[readingMemoLine] if (trim(inputLine) == ""): continue varName = usupport.stringUpTo(inputLine, "=") varValue = usupport.stringBeyond(inputLine, "=") if not self.setField(varName, varValue): break readingMemoLine += 1 if UNRESOLVED.pos(uppercase(kEndAmendmentString), uppercase(inputLine)) <= 0: raise GeneralException.create("Problem: Expected end of posing change.") return readingMemoLine
def readFromTextFile(self, inputFile): inputLine = "" varName = "" varValue = "" inputLine = readln(inputFile) while inputLine != None: # plant reads start line; just continue from there if (trim(inputLine) == ""): continue varName = usupport.stringUpTo(inputLine, "=") varValue = usupport.stringBeyond(inputLine, "=") if not self.setField(varName, varValue): break inputLine = readln(inputFile) if not string_match(kEndAmendmentString, inputLine): raise GeneralException.create( "Problem: Expected end of posing change.")
def writeToPOV_INCFile(self, fileName, frontFaceColor, embeddedInPlant, rotateCount): outputFile = TextFile() i = 0 triangle = KfIndexTriangle() colorToDraw = TColorRef() nameString = "" AssignFile(outputFile, fileName) try: # v1.5 usupport.setDecimalSeparator() Rewrite(outputFile) nameString = usupport.replacePunctuationWithUnderscores(self.getName()) writeln(outputFile, "// POV-format INC file of PlantStudio v1.x 3D object") writeln(outputFile, "// \"" + self.getName() + "\"") if (not embeddedInPlant): writeln(outputFile, "// include this file in a POV file thus to use it:") writeln(outputFile, "// #include \"" + usupport.stringUpTo(ExtractFileName(fileName), ".") + ".inc\"") writeln(outputFile, "// object { " + nameString + " }") if rotateCount > 1: writeln(outputFile, "// or") writeln(outputFile, "// object { " + nameString + "_rotated }") writeln(outputFile) writeln(outputFile, "#declare " + nameString + "=mesh {") for i in range(0, self.triangles.Count): triangle = KfIndexTriangle(self.triangles.Items[i]) self.writeTriangleToPOV_INCFIle(outputFile, self.points[triangle.pointIndexes[0] - 1], self.points[triangle.pointIndexes[1] - 1], self.points[triangle.pointIndexes[2] - 1]) writeln(outputFile, chr(9) + "pigment { color rgb <" + usupport.digitValueString(UNRESOLVED.getRValue(frontFaceColor) / 256.0) + ", " + usupport.digitValueString(UNRESOLVED.getGValue(frontFaceColor) / 256.0) + ", " + usupport.digitValueString(UNRESOLVED.getBValue(frontFaceColor) / 256.0) + "> }") writeln(outputFile, "}") if rotateCount > 1: writeln(outputFile) writeln(outputFile, "#declare " + nameString + "_rotated=union {") writeln(outputFile, chr(9) + "object { " + nameString + " }") for i in range(1, rotateCount): writeln(outputFile, chr(9) + "object { " + nameString + " rotate " + IntToStr(i) + "*365/" + IntToStr(rotateCount) + "*y }") writeln(outputFile, "}") finally: CloseFile(outputFile)
def loadPlantsFromFile(self, fileName, inPlantMover): inputFile = TextFile() plant = PdPlant() aLine = "" plantName = "" concentratedInFile = false concentratedLastTimeSaved = false lineCount = 0 AssignFile(inputFile, fileName) try: # v1.5 usupport.setDecimalSeparator() Reset(inputFile) self.plants.clear() # defaults in case things are missing from file self.plantDrawOffset_mm = usupport.setSinglePoint(0, 0) self.plantDrawScale_PixelsPerMm = 1.0 self.mainWindowViewMode = udomain.domain.options.mainWindowViewMode self.mainWindowOrientation = udomain.domain.options.mainWindowOrientation self.showBoundsRectangle = udomain.domain.options.showBoundsRectangle concentratedLastTimeSaved = false self.fitInVisibleAreaForConcentrationChange = false while not UNRESOLVED.eof(inputFile): # cfk testing aLine = usupport.tolerantReadln(inputFile, aLine) if (aLine == "") or (UNRESOLVED.pos(";", aLine) == 1): continue if UNRESOLVED.pos("offset=", aLine) == 1: self.plantDrawOffset_mm = usupport.stringToSinglePoint(usupport.stringBeyond(aLine, "=")) elif UNRESOLVED.pos("scale=", aLine) == 1: try: self.plantDrawScale_PixelsPerMm = intround(StrToFloat(usupport.stringBeyond(aLine, "=")) * 100.0) / 100.0 except: self.plantDrawScale_PixelsPerMm = 1.0 elif UNRESOLVED.pos("concentrated=", aLine) == 1: concentratedLastTimeSaved = udomain.domain.viewPlantsInMainWindowOnePlantAtATime() if udomain.domain.options.ignoreWindowSettingsInFile: # v2.1 if ignoring settings in file, use current settings, otherwise use what is in file concentratedInFile = (self.mainWindowViewMode == udomain.kViewPlantsInMainWindowOneAtATime) else: concentratedInFile = usupport.strToBool(usupport.stringBeyond(aLine, "=")) if concentratedInFile: self.mainWindowViewMode = udomain.kViewPlantsInMainWindowOneAtATime else: self.mainWindowViewMode = udomain.kViewPlantsInMainWindowFreeFloating if not inPlantMover: udomain.domain.options.mainWindowViewMode = self.mainWindowViewMode self.fitInVisibleAreaForConcentrationChange = concentratedInFile and not concentratedLastTimeSaved elif UNRESOLVED.pos("orientation (top/side)=", aLine) == 1: if not udomain.domain.options.ignoreWindowSettingsInFile: # v2.1 only read if not ignoring settings in file self.mainWindowOrientation = StrToInt(usupport.stringBeyond(aLine, "=")) elif UNRESOLVED.pos("boxes=", aLine) == 1: self.showBoundsRectangle = usupport.strToBool(usupport.stringBeyond(aLine, "=")) if not inPlantMover: udomain.domain.options.showBoundsRectangle = self.showBoundsRectangle if (umain.MainForm != None) and (not umain.MainForm.inFormCreation) and (not inPlantMover): umain.MainForm.updateForChangeToDomainOptions() umain.MainForm.copyDrawingBitmapToPaintBox() elif UNRESOLVED.pos("[", aLine) == 1: # plant start line checkVersionNumberInPlantNameLine(aLine) plant = uplant.PdPlant().create() plantName = usupport.stringBeyond(aLine, "[") plantName = usupport.stringUpTo(plantName, "]") plant.setName(plantName) udomain.domain.parameterManager.setAllReadFlagsToFalse() # cfk change v1.3 # changed reading end of plant to read "end PlantStudio plant" instead of empty line because # sometimes text wrapping puts empty lines in, not a good measure of completion. # now end of plant must be there to be read. could produce endless loop if no end # of plant, so stop at absolute cutoff of 300 non-empty, non-comment lines (there are now 215 parameters). # also stop reading if reach next plant square bracket or end of file. # v2.0 increased number of params to 350 so 300 is problem, changed to 3000 to avoid this in future, oops lineCount = 0 while (UNRESOLVED.pos(uplant.kPlantAsTextEndString, aLine) <= 0) and (lineCount <= 3000): # aLine <> '' do aLine = usupport.tolerantReadln(inputFile, aLine) if (UNRESOLVED.pos("[", aLine) == 1) or (UNRESOLVED.eof(inputFile)): # v1.60 reversed order of the next two lines -- fixes infinite loop when no end of plant # v1.3 added check for next plant or eof break if (trim(aLine) == "") or (UNRESOLVED.pos(";", aLine) == 1): # v1.3 added skip empty lines continue plant.readLineAndTdoFromPlantFile(aLine, inputFile) lineCount = lineCount + 1 plant.finishLoadingOrDefaulting(uplant.kCheckForUnreadParams) self.plants.Add(plant) finally: CloseFile(inputFile)