def streamSinglePoint(self, aPoint): raise "method streamSinglePoint had assigned to var parameter aPoint not added to return; fixup manually" x = 0.0 y = 0.0 if self.isReading(): x = self.streamSingle(x) y = self.streamSingle(y) aPoint = usupport.setSinglePoint(x, y) else: x = aPoint.x y = aPoint.y x = self.streamSingle(x) y = self.streamSingle(y)
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)