コード例 #1
0
ファイル: uamendmt.py プロジェクト: Neon22/PlantStudio
 def setField(self, varName, varValue):
     result = False
     result = True
     if string_match("part number", varName):
         # how deal with problem?
         self.partID = StrToIntDef(varValue, 0)
     elif string_match("part type", varName):
         self.typeOfPart = varValue
     elif string_match("hide", varName):
         self.hide = usupport.strToBool(varValue)
     elif string_match("change colors", varName):
         # read these for possible backward compatibility later, but don't do anything with them
         # self.changeColors := strToBool(varValue)
         result = True
     elif string_match("propagate colors up stem", varName):
         # self.propagateColors := strToBool(varValue)
         result = True
     elif string_match("front face color", varName):
         # self.faceColor := strToIntDef(varValue, 0)
         result = True
     elif string_match("back face color", varName):
         # self.backfaceColor := strToIntDef(varValue, 0)
         result = True
     elif string_match("line color", varName):
         # self.lineColor := strToIntDef(varValue, 0)
         result = True
     elif string_match("rotate", varName):
         self.addRotations = usupport.strToBool(varValue)
     elif string_match("x rotation", varName):
         self.xRotation = float(varValue)
     elif string_match("y rotation", varName):
         self.yRotation = float(varValue)
     elif string_match("z rotation", varName):
         self.zRotation = float(varValue)
     elif string_match("change scale", varName):
         self.multiplyScale = usupport.strToBool(varValue)
     elif string_match("propagate scale change up stem", varName):
         self.propagateScale = usupport.strToBool(varValue)
     elif string_match("3d object scale multiplier", varName):
         self.scaleMultiplier_pct = StrToIntDef(varValue, 100)
     elif string_match("line length multiplier", varName):
         self.lengthMultiplier_pct = StrToIntDef(varValue, 100)
     elif string_match("line width multiplier", varName):
         self.widthMultiplier_pct = StrToIntDef(varValue, 100)
     elif string_match("apply at age", varName):
         # read these for possible backward compatibility later, but don't do anything with them
         # self.applyAtAge := strToIntDef(varValue, 0)
         result = True
     else:
         result = False
     return result
コード例 #2
0
ファイル: uamendmt.pas.py プロジェクト: overdhose/PlantStudio
 def setField(self, varName, varValue):
     result = false
     result = true
     if UNRESOLVED.pos("part number", varName) > 0:
         # how deal with problem?
         self.partID = StrToIntDef(varValue, 0)
     elif UNRESOLVED.pos("part type", varName) > 0:
         self.typeOfPart = varValue
     elif UNRESOLVED.pos("hide", varName) > 0:
         self.hide = usupport.strToBool(varValue)
     elif UNRESOLVED.pos("change colors", varName) > 0:
         # read these for possible backward compatibility later, but don't do anything with them
         # self.changeColors := strToBool(varValue)
         result = true
     elif UNRESOLVED.pos("propagate colors up stem", varName) > 0:
         # self.propagateColors := strToBool(varValue)
         result = true
     elif UNRESOLVED.pos("front face color", varName) > 0:
         # self.faceColor := strToIntDef(varValue, 0)
         result = true
     elif UNRESOLVED.pos("back face color", varName) > 0:
         # self.backfaceColor := strToIntDef(varValue, 0)
         result = true
     elif UNRESOLVED.pos("line color", varName) > 0:
         # self.lineColor := strToIntDef(varValue, 0)
         result = true
     elif UNRESOLVED.pos("rotate", varName) > 0:
         self.addRotations = usupport.strToBool(varValue)
     elif UNRESOLVED.pos("x rotation", varName) > 0:
         self.xRotation = StrToInt(varValue) * 1.0
     elif UNRESOLVED.pos("y rotation", varName) > 0:
         self.yRotation = StrToInt(varValue) * 1.0
     elif UNRESOLVED.pos("z rotation", varName) > 0:
         self.zRotation = StrToInt(varValue) * 1.0
     elif UNRESOLVED.pos("change scale", varName) > 0:
         self.multiplyScale = usupport.strToBool(varValue)
     elif UNRESOLVED.pos("propagate scale change up stem", varName) > 0:
         self.propagateScale = usupport.strToBool(varValue)
     elif UNRESOLVED.pos("3d object scale multiplier", varName) > 0:
         self.scaleMultiplier_pct = StrToIntDef(varValue, 100)
     elif UNRESOLVED.pos("line length multiplier", varName) > 0:
         self.lengthMultiplier_pct = StrToIntDef(varValue, 100)
     elif UNRESOLVED.pos("line width multiplier", varName) > 0:
         self.widthMultiplier_pct = StrToIntDef(varValue, 100)
     elif UNRESOLVED.pos("apply at age", varName) > 0:
         # read these for possible backward compatibility later, but don't do anything with them
         # self.applyAtAge := strToIntDef(varValue, 0)
         result = true
     else:
         result = false
     return result
コード例 #3
0
    def readFromFile(self, aFileName):
        inputFile = TextFile()
        inputLine = ""
        lineType = ""
        stream = KfStringStream()
        i = 0

        AssignFile(inputFile, aFileName)
        stream = None
        try:
            Reset(inputFile)
            stream = usstream.KfStringStream.create
            UNRESOLVED.readln(inputFile, inputLine)
            if UNRESOLVED.pos("STRATEGY", uppercase(inputLine)) <= 0:
                raise GeneralException.create(
                    "Improper format for breeding strategy file")
            while not UNRESOLVED.eof(inputFile):
                UNRESOLVED.readln(inputFile, inputLine)
                stream.onStringSeparator(inputLine, "=")
                lineType = stream.nextToken()
                stream.spaceSeparator()
                if UNRESOLVED.pos("NUMERIC", uppercase(lineType)) > 0:
                    self.getNonNumericalParametersFrom = StrToIntDef(
                        stream.nextToken(),
                        kFromPlantWithGreaterWeightForSectionIfEqualChooseRandomly
                    )
                elif UNRESOLVED.pos("MUTATION", uppercase(lineType)) > 0:
                    for i in range(0, kMaxBreedingSections):
                        self.mutationStrengths[i] = StrToIntDef(
                            stream.nextToken(), 0)
                elif UNRESOLVED.pos("WEIGHT", uppercase(lineType)) > 0:
                    for i in range(0, kMaxBreedingSections):
                        self.firstPlantWeights[i] = StrToIntDef(
                            stream.nextToken(), 50)
                elif UNRESOLVED.pos("COLORS", uppercase(lineType)) > 0:
                    self.mutateAndBlendColorValues = usupport.strToBool(
                        stream.nextToken())
                elif UNRESOLVED.pos("3D OBJECTS", uppercase(lineType)) > 0:
                    self.chooseTdosRandomlyFromCurrentLibrary = usupport.strToBool(
                        stream.nextToken())
                else:
                    break
        finally:
            stream.free
            CloseFile(inputFile)
コード例 #4
0
 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)