Example #1
0
    def writeToDXFFile(self, fileName, frontFaceColor, backFaceColor):
        outputFile = TextFile()
        i = 0
        triangle = KfIndexTriangle()
        colorToDraw = TColorRef()

        AssignFile(outputFile, fileName)
        try:
            # v1.5
            usupport.setDecimalSeparator()
            Rewrite(outputFile)
            writeln(outputFile, "0")
            writeln(outputFile, "SECTION")
            writeln(outputFile, "2")
            writeln(outputFile, "ENTITIES")
            for i in range(0, self.triangles.Count):
                triangle = KfIndexTriangle(self.triangles.Items[i])
                if self.triangleIsBackFacing(triangle):
                    colorToDraw = backFaceColor
                else:
                    colorToDraw = frontFaceColor
                self.writeTriangleToDXFFIle(
                    outputFile, self.points[triangle.pointIndexes[0] - 1],
                    self.points[triangle.pointIndexes[1] - 1],
                    self.points[triangle.pointIndexes[2] - 1], colorToDraw)
            writeln(outputFile, "0")
            writeln(outputFile, "ENDSEC")
            writeln(outputFile, "0")
            writeln(outputFile, "EOF")
        finally:
            CloseFile(outputFile)
Example #2
0
 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 writeToDXFFile(self, fileName, frontFaceColor, backFaceColor):
     outputFile = TextFile()
     i = 0
     triangle = KfIndexTriangle()
     colorToDraw = TColorRef()
     
     AssignFile(outputFile, fileName)
     try:
         # v1.5
         usupport.setDecimalSeparator()
         Rewrite(outputFile)
         writeln(outputFile, "0")
         writeln(outputFile, "SECTION")
         writeln(outputFile, "2")
         writeln(outputFile, "ENTITIES")
         for i in range(0, self.triangles.Count):
             triangle = KfIndexTriangle(self.triangles.Items[i])
             if self.triangleIsBackFacing(triangle):
                 colorToDraw = backFaceColor
             else:
                 colorToDraw = frontFaceColor
             self.writeTriangleToDXFFIle(outputFile, self.points[triangle.pointIndexes[0] - 1], self.points[triangle.pointIndexes[1] - 1], self.points[triangle.pointIndexes[2] - 1], colorToDraw)
         writeln(outputFile, "0")
         writeln(outputFile, "ENDSEC")
         writeln(outputFile, "0")
         writeln(outputFile, "EOF")
     finally:
         CloseFile(outputFile)
Example #4
0
    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)
Example #5
0
 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 breedFromParents(self, aFirstParent, aSecondParent, fractionOfMaxAge):
     newPlant = PdPlant()
     i = 0
     newAge = 0
     fileNameWithPath = ""
     newTdo = KfObject3D()
     inputFile = TextFile()
     tdos = TListCollection()
     localOptions = BreedingAndTimeSeriesOptionsStructure()
     
     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)
     try:
         if udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary:
             tdos = ucollect.TListCollection().Create()
             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().create()
                         newTdo.readFromFileStream(inputFile, utdo.kInTdoLibrary)
                         tdos.Add(newTdo)
                 finally:
                     CloseFile(inputFile)
         for i in range(0, udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration):
             newPlant = uplant.PdPlant().create()
             self.plants.Add(newPlant)
             newPlant.reset()
             if udomain.domain.breedingAndTimeSeriesOptions.variationType != udomain.kBreederVariationNoNumeric:
                 newPlant.randomize()
             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
     finally:
         tdos.free
 def writeToFile(self, fileName):
     outputFile = TextFile()
     
     AssignFile(outputFile, fileName)
     try:
         # v1.5
         usupport.setDecimalSeparator()
         Rewrite(outputFile)
         self.writeToFileStream(outputFile, kStandAloneFile)
     finally:
         CloseFile(outputFile)
Example #8
0
    def writeToFile(self, fileName):
        outputFile = TextFile()

        AssignFile(outputFile, fileName)
        try:
            # v1.5
            usupport.setDecimalSeparator()
            Rewrite(outputFile)
            self.writeToFileStream(outputFile, kStandAloneFile)
        finally:
            CloseFile(outputFile)
Example #9
0
    def readFromFile(self, fileName):
        inputFile = TextFile()

        AssignFile(inputFile, fileName)
        try:
            # v1.5
            usupport.setDecimalSeparator()
            Reset(inputFile)
            self.readFromFileStream(inputFile, kStandAloneFile)
        finally:
            CloseFile(inputFile)
Example #10
0
 def readFromFile(self, fileName):
     inputFile = TextFile()
     
     AssignFile(inputFile, fileName)
     try:
         # v1.5
         usupport.setDecimalSeparator()
         Reset(inputFile)
         self.readFromFileStream(inputFile, kStandAloneFile)
     finally:
         CloseFile(inputFile)
Example #11
0
 def saveExceptionListToFile(self, fileName):
     i = 0L
     
     AssignFile(self.outputFile, fileName)
     # v1.5
     usupport.setDecimalSeparator()
     Rewrite(self.outputFile)
     try:
         if self.DebugList.Items.Count > 0:
             for i in range(0, self.DebugList.Items.Count):
                 writeln(self.outputFile, self.DebugList.Items[i])
     finally:
         CloseFile(self.outputFile)
Example #12
0
 def saveInfoListToFile(self, fileName):
     i = 0L
     outputFile = TextFile()
     
     AssignFile(outputFile, fileName)
     # v1.5
     usupport.setDecimalSeparator()
     Rewrite(outputFile)
     try:
         if self.infoList.Lines.Count > 0:
             for i in range(0, self.infoList.Lines.Count):
                 writeln(outputFile, self.infoList.Lines[i])
     finally:
         CloseFile(outputFile)
Example #13
0
 def startLogging(self, fileName):
     dateString = ""
     
     if self.logging:
         return
     AssignFile(self.outputFile, fileName)
     if not FileExists(fileName):
         # v1.5
         usupport.setDecimalSeparator()
         Rewrite(self.outputFile)
     else:
         # v1.5
         usupport.setDecimalSeparator()
         UNRESOLVED.append(self.outputFile)
         dateString = UNRESOLVED.formatDateTime("m/d/yyyy, h:m am/pm", UNRESOLVED.now)
         writeln(self.outputFile, "---- log start (" + dateString + ") ----")
     self.logging = true
Example #14
0
    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
Example #15
0
 def write3DOutputFileToFileName(self, selectedPlants, excludeInvisiblePlants, excludeNonSelectedPlants, fileName, outputType):
     plant = PdPlant()
     i = 0
     includePlant = false
     includeRect = TRect()
     includedPlants = TList()
     translatePlants = false
     turtle = KfTurtle()
     
     usupport.setDecimalSeparator()
     includedPlants = None
     includeRect = self.combinedPlantBoundsRects(selectedPlants, excludeInvisiblePlants, excludeNonSelectedPlants)
     if (usupport.rWidth(includeRect) <= 0) or (usupport.rHeight(includeRect) <= 0):
         return
     includedPlants = delphi_compatability.TList().Create()
     turtle = uturtle.KfTurtle().createFor3DOutput(outputType, fileName)
     try:
         turtle.start3DExportFile()
         if self.plants.Count > 0:
             for i in range(0, self.plants.Count):
                 # count the plants to be drawn so we know if there is more than one
                 plant = uplant.PdPlant(self.plants.Items[i])
                 includePlant = true
                 if excludeInvisiblePlants:
                     includePlant = includePlant and not plant.hidden
                 if excludeNonSelectedPlants:
                     includePlant = includePlant and (selectedPlants.IndexOf(plant) >= 0)
                 if includePlant:
                     includedPlants.Add(plant)
         if includedPlants.Count <= 1:
             # if only one plant, don't translate or scale
             translatePlants = false
         else:
             translatePlants = udomain.domain.exportOptionsFor3D[outputType].translatePlantsToWindowPositions
         if includedPlants.Count > 0:
             for i in range(0, includedPlants.Count):
                 # iterate over included plants
                 uplant.PdPlant(includedPlants.Items[i]).saveToGlobal3DOutputFile(i, translatePlants, includeRect, outputType, turtle)
     finally:
         turtle.end3DExportFile()
         turtle.free
         turtle = None
         includedPlants.free
         includedPlants = None
Example #16
0
 def savePlantsToFile(self, fileName, inPlantMover):
     outputFile = TextFile()
     i = 0
     plant = PdPlant()
     
     if self.plants.Count <= 0:
         return
     AssignFile(outputFile, fileName)
     try:
         # v1.5
         usupport.setDecimalSeparator()
         if not inPlantMover:
             # update before writing out (keep as read in if in mover)
             # plantDrawOffset_mm is used from here
             # plantDrawScale_PixelsPerMm is used from here
             self.mainWindowViewMode = udomain.domain.options.mainWindowViewMode
             self.mainWindowOrientation = udomain.domain.options.mainWindowOrientation
             self.showBoundsRectangle = udomain.domain.options.showBoundsRectangle
         Rewrite(outputFile)
         # v2.0
         writeln(outputFile, "; PlantStudio version 2.0 plant file")
         writeln(outputFile, "offset=" + usupport.singlePointToString(self.plantDrawOffset_mm))
         writeln(outputFile, "scale=" + usupport.digitValueString(self.plantDrawScale_PixelsPerMm))
         if self.mainWindowViewMode == udomain.kViewPlantsInMainWindowOneAtATime:
             writeln(outputFile, "concentrated=true")
         else:
             writeln(outputFile, "concentrated=false")
         # v2.0
         writeln(outputFile, "orientation (top/side)=" + IntToStr(self.mainWindowOrientation))
         # v2.0
         writeln(outputFile, "boxes=" + usupport.boolToStr(self.showBoundsRectangle))
         writeln(outputFile)
         for i in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[i])
             if plant == None:
                 continue
             plant.writeToPlantFile(outputFile)
     finally:
         CloseFile(outputFile)
Example #17
0
 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)
Example #18
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)
Example #19
0
 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