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 adjustValue(self): newString = ansistring() oldValueInCurrentUnit = 0.0 newValue = 0.0 newValueInPlantUnit = 0.0 oldString = "" prompt = "" nameString = "" unitString = "" minString = "" maxString = "" outOfRange = false oldValueInCurrentUnit = self.toCurrentUnit(self.currentValue) newString = usupport.digitValueString(oldValueInCurrentUnit) oldString = newString nameString = UNRESOLVED.copy(self.Caption, 1, 30) if len(nameString) == 30: nameString = nameString + "..." unitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) minString = usupport.digitValueString(self.toCurrentUnit(self.minValue)) maxString = usupport.digitValueString(self.toCurrentUnit(self.maxValue)) prompt = "Type a new value." if InputQuery("Enter value", prompt, newString): if (newString != oldString) and (usupport.boundForString(newString, self.param.fieldType, newValue)): newValueInPlantUnit = self.toPlantUnit(newValue) outOfRange = self.checkValueAgainstBounds(newValueInPlantUnit) if not outOfRange: self.currentValue = newValueInPlantUnit umain.MainForm.doCommand(updcom.PdChangeRealValueCommand().createCommandWithListOfPlants(umain.MainForm.selectedPlants, self.currentValue, self.param.fieldNumber, self.arrayIndex, self.param.regrow)) self.updateDisplay() self.Invalidate()
def stringForMemoryInK(self, kilobytes): result = "" if kilobytes <= 1024: result = usupport.digitValueString(kilobytes) + " K" else: result = usupport.digitValueString(kilobytes / 1024.0) + " MB" return result
def minScaleWidthWithBounds(self, unitSet, unitPlant, softMin, softMax): result = 0 i = 0 numeralChars = 0 letterChars = 0 maxLengthSoftMin = 0 maxLengthSoftMax = 0 minValue = 0.0 maxValue = 0.0 # value number of chars (always use max) #+ kMaxDisplayDigitsToRightOfDecimal + 1 numeralChars = kMaxDisplayDigitsToLeftOfDecimal # unit string number of chars (get max for set) letterChars = uunits.maxUnitStringLengthForSet(unitSet) # bounds number of chars (use actual bounds, but calculate max for set) maxLengthSoftMin = 0 maxLengthSoftMax = 0 for i in range(1, uunits.GetLastUnitEnumInUnitSet(unitSet)): minValue = uunits.Convert(unitSet, unitPlant, i, softMin) maxValue = uunits.Convert(unitSet, unitPlant, i, softMax) maxLengthSoftMin = umath.intMax(maxLengthSoftMin, len(usupport.digitValueString(minValue))) maxLengthSoftMax = umath.intMax(maxLengthSoftMax, len(usupport.digitValueString(maxValue))) numeralChars = numeralChars + maxLengthSoftMin + maxLengthSoftMax # calc min scale width from number of chars result = self.formTextWidth("i") * letterChars + self.formTextWidth("1") * numeralChars + kBetweenGap * 3 + kLeftRightGap * 2 return result
def paint(self): Rect = TRect() minString = "" valueString = "" maxString = "" unitString = "" if delphi_compatability.Application.terminated: return if (self.selectedItemIndex == kItemSlider): # ask slider to update itself based on whether it is selected self.slider.hasUnofficialFocus = true else: self.slider.hasUnofficialFocus = false PdParameterPanel.paint(self) self.slider.Visible = not self.param.collapsed if (self.param.collapsed): self.drawExtraValueCaptionWithString( usupport.digitValueString(self.toCurrentUnit( self.currentValue)), uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex)) return Rect = self.GetClientRect() minString = usupport.digitValueString(self.toCurrentUnit( self.minValue)) maxString = usupport.digitValueString(self.toCurrentUnit( self.maxValue)) if self.slider.dragging: valueString = usupport.digitValueString( self.toCurrentUnit(self.currentValueWhileSliding)) else: valueString = usupport.digitValueString( self.toCurrentUnit(self.currentValue)) unitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) self.valueTextRect.Left = uppanel.kLeftRightGap self.valueTextRect.Right = self.valueTextRect.Left + self.Canvas.TextWidth( valueString) self.valueTextRect.Top = self.collapsedHeight() + 1 self.valueTextRect.Bottom = self.valueTextRect.Top + self.textHeight self.unitTextRect = self.valueTextRect self.unitTextRect.Left = self.valueTextRect.Right + 5 self.unitTextRect.Right = self.unitTextRect.Left + self.Canvas.TextWidth( unitString) self.minTextRect = self.valueTextRect self.minTextRect.Left = self.unitTextRect.Right + 5 self.minTextRect.Right = self.minTextRect.Left + self.Canvas.TextWidth( minString) self.maxTextRect = self.valueTextRect self.maxTextRect.Right = Rect.right - uppanel.kLeftRightGap self.maxTextRect.Left = self.maxTextRect.Right - self.Canvas.TextWidth( maxString) self.drawText(minString, self.minTextRect, false, false, true) self.drawText(valueString, self.valueTextRect, not self.readOnly, (self.selectedItemIndex == kItemValueText), false) self.drawText(unitString, self.unitTextRect, true, (self.selectedItemIndex == kItemUnitText), false) self.drawText(maxString, self.maxTextRect, false, false, true)
def CloseClick(self, Sender): insertString = "" if (self.colorType.ItemIndex == 0) and ((self.copySavePrintType == kSavingDrawingToBmp) or (self.copySavePrintType == kSavingDrawingToJpeg)): # don't let them save the file as a device-dependent bitmap. MessageDialog("You cannot save a picture with the \"From screen\" color depth." + chr(13) + "Please change the color depth to another choice in the list.", delphi_compatability.TMsgDlgType.mtError, [mbOK, ], 0) return if (self.useSelectedPlants.Checked) and (umain.MainForm.selectedPlants.Count <= 0): # don't let them finish with no plants MessageDialog("You chose \"selected\" for \"Draw which plants\", but no plants are selected." + chr(13) + "You should make another choice, or click Cancel and select some plants.", delphi_compatability.TMsgDlgType.mtError, [mbOK, ], 0) return if self.copySavePrintType != kSavingDrawingToJpeg: if self.megabytesOfMemoryNeeded > kTooManyMegabytesOfMemory: if self.copySavePrintType == kCopyingDrawing: # warn about a really big operation insertString = "copy to the clipboard" elif self.copySavePrintType == kPrintingDrawing: insertString = "print" elif self.copySavePrintType == kSavingDrawingToBmp: insertString = "save" if MessageDialog("You are about to " + insertString + " a " + usupport.digitValueString(self.megabytesOfMemoryNeeded) + " MB bitmap." + chr(13) + "This could place stress on your system." + chr(13) + "We recommend closing any non-essential programs." + chr(13) + "Also, choosing fewer colors or a smaller picture will use less memory." + chr(13) + chr(13) + "To proceed, click OK. To go back and make changes, click Cancel.", mtWarning, [mbOK, mbCancel, ], 0) == delphi_compatability.IDCANCEL: return self.transferDirection = kTransferSave self.transferFields() self.ModalResult = mrOK
def reportOnMemoryNeeded(self): if self.copySavePrintType == kSavingDrawingToJpeg: # report memory needed -- do after calculating resolution-affected size # make no size estimation for JPG self.memoryUseInfoLabel.Visible = false return self.calculatePixelsFromResolutionAndInches() self.calculateMegabytesOfMemoryNeededConsideringColorBitsAndResolution() if self.megabytesOfMemoryNeeded < 1.0: self.memoryUseInfoLabel.Caption = "Estimated memory needed: " + usupport.digitValueString(self.megabytesOfMemoryNeeded * 1024) + " K" else: self.memoryUseInfoLabel.Caption = "Estimated memory needed: " + usupport.digitValueString(self.megabytesOfMemoryNeeded) + " MB" if self.megabytesOfMemoryNeeded > kTooManyMegabytesOfMemory: self.memoryUseInfoLabel.Font.Style = [UNRESOLVED.fsBold, ] else: self.memoryUseInfoLabel.Font.Style = []
def describePlant(self, describeString, plantProxy): plant = PdPlant() theRect = TRect() totalMemUse = 0.0 baseMemUse = 0.0 hangingMemUse = 0.0 tdoMemUse = 0.0 cacheMemUse = 0.0 partsMemUse = 0.0 if plantProxy == None: return plant = plantProxy as uplant.PdPlant plant.countPlantParts() self.infoList.Lines.Add(describeString + " plant: " + plant.name) # memory totalMemUse = plant.calculateTotalMemorySize() baseMemUse = plant.instanceSize / 1024.0 hangingMemUse = plant.hangingObjectsMemoryUse_K() tdoMemUse = plant.tdoMemoryUse_K() if plant.previewCache != None: cacheMemUse = ubitmap.BitmapMemorySize(plant.previewCache) / 1024.0 else: cacheMemUse = 0 partsMemUse = totalMemUse - baseMemUse - hangingMemUse - tdoMemUse - cacheMemUse self.infoList.Lines.Add(" total memory use " + self.stringForMemoryInK(totalMemUse)) self.infoList.Lines.Add(" base memory with parameters " + self.stringForMemoryInK(baseMemUse)) self.infoList.Lines.Add(" posing and random number generators " + self.stringForMemoryInK(hangingMemUse)) self.infoList.Lines.Add(" memory for 3D objects " + self.stringForMemoryInK(tdoMemUse)) self.infoList.Lines.Add(" memory for drawing cache " + self.stringForMemoryInK(cacheMemUse)) self.infoList.Lines.Add(" memory for plant parts " + self.stringForMemoryInK(partsMemUse)) # status self.infoList.Lines.Add(" age " + IntToStr(plant.age)) self.infoList.Lines.Add(" maturity " + IntToStr(plant.pGeneral.ageAtMaturity)) self.infoList.Lines.Add(" scale " + usupport.digitValueString(plant.drawingScale_PixelsPerMm)) if plant.previewCache != None: self.infoList.Lines.Add(" cache " + IntToStr(plant.previewCache.Width) + "x" + IntToStr(plant.previewCache.Height)) else: self.infoList.Lines.Add(" no cache") self.infoList.Lines.Add(" base " + usupport.digitValueString(plant.basePoint_mm.x) + "x" + usupport.digitValueString(plant.basePoint_mm.y)) self.infoList.Lines.Add(" hidden " + usupport.boolToStr(plant.hidden)) self.infoList.Lines.Add(" random number seed " + IntToStr(plant.pGeneral.startingSeedForRandomNumberGenerator)) theRect = plant.boundsRect_pixels() self.infoList.Lines.Add(" bounds " + IntToStr(theRect.Left) + "x" + IntToStr(theRect.Top) + "x" + IntToStr(theRect.Right) + "x" + IntToStr(theRect.Bottom) + " (" + IntToStr(usupport.rWidth(theRect)) + "x" + IntToStr(usupport.rHeight(theRect)) + ")") self.infoList.Lines.Add(" parts " + IntToStr(plant.totalPlantParts)) self.infoList.Lines.Add("")
def adjustValue(self): newString = ansistring() oldString = "" nameString = "" prompt = "" currentUnitString = "" newValue = 0.0 oldValue = 0.0 valueInCurrentUnit = 0.0 index = 0 failed = false points = [0] * (range(0, 1 + 1) + 1) if self.selectedItemIndex < kItemX1: return index = self.selectedItemIndex - kItemX1 oldValue = self.currentValues[index] nameString = UNRESOLVED.copy(self.Caption, 1, 30) currentUnitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) if len(nameString) == 30: nameString = nameString + "..." if not odd(index): # x valueInCurrentUnit = self.toCurrentUnit(self.currentValues[index]) newString = usupport.digitValueString(valueInCurrentUnit) # y # don't convert y value - is always 0-1 else: valueInCurrentUnit = self.currentValues[index] newString = FloatToStrF(valueInCurrentUnit, UNRESOLVED.ffFixed, 7, 2) oldString = newString prompt = "Type a new value." if InputQuery("Enter value", prompt, newString): if (newString != oldString) and (usupport.boundForString(newString, self.param.fieldType, newValue)): if not odd(index): self.currentValues[index] = self.toPlantUnit(newValue) else: self.currentValues[index] = newValue points[0] = self.pointFromXY(self.currentValues[0], self.currentValues[1]) points[1] = self.pointFromXY(self.currentValues[2], self.currentValues[3]) self.keepPointInGraphRect(points[(index - 1) / 2]) self.keepPointsFromCrossing(points[0], points[1], (index - 1) / 2) failed = self.drawSCurve(false, failed) if failed: self.currentValues[index] = oldValue ShowMessage("Invalid value.") else: # don't create change point command here, because only one float is changed umain.MainForm.doCommand( updcom.PdChangeRealValueCommand().createCommandWithListOfPlants( umain.MainForm.selectedPlants, self.currentValues[index], self.param.fieldNumber, index, self.param.regrow, ) ) self.Invalidate()
def paint(self): Rect = TRect() minString = "" valueString = "" maxString = "" unitString = "" if delphi_compatability.Application.terminated: return if (self.selectedItemIndex == kItemSlider): # ask slider to update itself based on whether it is selected self.slider.hasUnofficialFocus = true else: self.slider.hasUnofficialFocus = false PdParameterPanel.paint(self) self.slider.Visible = not self.param.collapsed if (self.param.collapsed): self.drawExtraValueCaptionWithString(usupport.digitValueString(self.toCurrentUnit(self.currentValue)), uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex)) return Rect = self.GetClientRect() minString = usupport.digitValueString(self.toCurrentUnit(self.minValue)) maxString = usupport.digitValueString(self.toCurrentUnit(self.maxValue)) if self.slider.dragging: valueString = usupport.digitValueString(self.toCurrentUnit(self.currentValueWhileSliding)) else: valueString = usupport.digitValueString(self.toCurrentUnit(self.currentValue)) unitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) self.valueTextRect.Left = uppanel.kLeftRightGap self.valueTextRect.Right = self.valueTextRect.Left + self.Canvas.TextWidth(valueString) self.valueTextRect.Top = self.collapsedHeight() + 1 self.valueTextRect.Bottom = self.valueTextRect.Top + self.textHeight self.unitTextRect = self.valueTextRect self.unitTextRect.Left = self.valueTextRect.Right + 5 self.unitTextRect.Right = self.unitTextRect.Left + self.Canvas.TextWidth(unitString) self.minTextRect = self.valueTextRect self.minTextRect.Left = self.unitTextRect.Right + 5 self.minTextRect.Right = self.minTextRect.Left + self.Canvas.TextWidth(minString) self.maxTextRect = self.valueTextRect self.maxTextRect.Right = Rect.right - uppanel.kLeftRightGap self.maxTextRect.Left = self.maxTextRect.Right - self.Canvas.TextWidth(maxString) self.drawText(minString, self.minTextRect, false, false, true) self.drawText(valueString, self.valueTextRect, not self.readOnly, (self.selectedItemIndex == kItemValueText), false) self.drawText(unitString, self.unitTextRect, true, (self.selectedItemIndex == kItemUnitText), false) self.drawText(maxString, self.maxTextRect, false, false, true)
def adjustValue(self): newString = ansistring() oldValueInCurrentUnit = 0.0 newValue = 0.0 newValueInPlantUnit = 0.0 oldString = "" prompt = "" nameString = "" unitString = "" minString = "" maxString = "" outOfRange = false oldValueInCurrentUnit = self.toCurrentUnit(self.currentValue) newString = usupport.digitValueString(oldValueInCurrentUnit) oldString = newString nameString = UNRESOLVED.copy(self.Caption, 1, 30) if len(nameString) == 30: nameString = nameString + "..." unitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) minString = usupport.digitValueString(self.toCurrentUnit( self.minValue)) maxString = usupport.digitValueString(self.toCurrentUnit( self.maxValue)) prompt = "Type a new value." if InputQuery("Enter value", prompt, newString): if (newString != oldString) and (usupport.boundForString( newString, self.param.fieldType, newValue)): newValueInPlantUnit = self.toPlantUnit(newValue) outOfRange = self.checkValueAgainstBounds(newValueInPlantUnit) if not outOfRange: self.currentValue = newValueInPlantUnit umain.MainForm.doCommand(updcom.PdChangeRealValueCommand( ).createCommandWithListOfPlants( umain.MainForm.selectedPlants, self.currentValue, self.param.fieldNumber, self.arrayIndex, self.param.regrow)) self.updateDisplay() self.Invalidate()
def labelStringForPartType(self, index): result = "" partType = 0 hasStuff = false result = "" partType = self.partTypeForIndex(index) hasStuff = (self.statistics.liveBiomass_pctMPB[partType] + self.statistics.deadBiomass_pctMPB[partType] > 0) or (self.statistics.count[partType] > 0) if not hasStuff: return result if self.statistics.count[partType] > 0: result = IntToStr(self.statistics.count[partType]) + " " result = result + self.nameForPartType(partType, self.statistics.count[partType] == 1) result = result + ": " + usupport.digitValueString(self.displayPercentForPartType(partType, kBothLiveAndDead)) + "%" return result
def transferFloatEditBox(self, editBox, value): oldValue = 0.0 newValue = 0.0 if self.transferDirection == kTransferLoad: editBox.Text = usupport.digitValueString(value) elif self.transferDirection == kTransferSave: oldValue = value try: newValue = StrToFloat(editBox.Text) except: newValue = oldValue if value != newValue: self.optionsChanged = true value = newValue return value
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)
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 toString(self): return usupport.digitValueString(self.x1) + " " + usupport.digitValueString(self.y1) + " " + usupport.digitValueString(self.x2) + " " + usupport.digitValueString(self.y2)
def FormCreate(self, Sender): numParams = 0 numSections = 0 numHints = 0 numPlants = 0 numPlantsInPrivateClipboard = 0 scale = 0.0 offsetX = 0.0 offsetY = 0.0 memoryStatus = TMemoryStatus() diskSpace = 0L screenColorBits = 0 screenColors = 0L screenDC = HDC() i = 0 genCount = 0 plCount = 0 plant = PdPlant() generation = PdGeneration() totalMemory_K = 0.0 self.infoList.Lines.Clear() self.infoList.Lines.Add("") self.infoList.Lines.Add("PlantStudio Program Information") self.infoList.Lines.Add(usupport.gVersionName) self.infoList.Lines.Add("-------------------------------------------") # OS info self.infoList.Lines.Add("") self.infoList.Lines.Add("Operating system") self.infoList.Lines.Add("-------------------------------------------") self.GetOSInfo() memoryStatus.dwLength = FIX_sizeof(memoryStatus) UNRESOLVED.GlobalMemoryStatus(memoryStatus) self.infoList.Lines.Add("Percent memory in use: " + IntToStr(memoryStatus.dwMemoryLoad)) self.infoList.Lines.Add("Total physical memory: " + IntToStr(memoryStatus.dwTotalPhys / 1024) + " K") self.infoList.Lines.Add("Available physical memory: " + IntToStr(memoryStatus.dwAvailPhys / 1024) + " K") self.infoList.Lines.Add("Total paging file: " + IntToStr(memoryStatus.dwTotalPageFile / 1024) + " K") self.infoList.Lines.Add("Available paging file: " + IntToStr(memoryStatus.dwAvailPageFile / 1024) + " K") self.infoList.Lines.Add("Total user memory: " + IntToStr(memoryStatus.dwTotalVirtual / 1024) + " K") self.infoList.Lines.Add("Available user memory: " + IntToStr(memoryStatus.dwAvailVirtual / 1024) + " K") # disk info self.infoList.Lines.Add("") self.infoList.Lines.Add("Hard disk") self.infoList.Lines.Add("-------------------------------------------") diskSpace = UNRESOLVED.DiskFree(0) self.infoList.Lines.Add("Disk space on current drive: " + IntToStr(diskSpace / (1024 * 1024)) + " MB") # screen info self.infoList.Lines.Add("") self.infoList.Lines.Add("Screen") self.infoList.Lines.Add("-------------------------------------------") screenDC = UNRESOLVED.GetDC(0) try: screenColorBits = (UNRESOLVED.GetDeviceCaps(screenDC, delphi_compatability.BITSPIXEL) * UNRESOLVED.GetDeviceCaps(screenDC, delphi_compatability.PLANES)) finally: UNRESOLVED.ReleaseDC(0, screenDC) if screenColorBits != 32: screenColors = 1 << screenColorBits self.infoList.Lines.Add("Colors: " + IntToStr(screenColors) + " (" + IntToStr(screenColorBits) + " bits)") else: self.infoList.Lines.Add("Colors: true color (" + IntToStr(screenColorBits) + " bits)") self.infoList.Lines.Add("Size: " + IntToStr(delphi_compatability.Screen.Width) + " x " + IntToStr(delphi_compatability.Screen.Height)) self.infoList.Lines.Add("Resolution: " + IntToStr(delphi_compatability.Screen.PixelsPerInch) + " pixels/inch") # domain info self.infoList.Lines.Add("") self.infoList.Lines.Add("Global settings") self.infoList.Lines.Add("-------------------------------------------") self.infoList.Lines.Add("Sections: " + IntToStr(udomain.domain.sectionManager.sections.Count)) self.infoList.Lines.Add("Parameters: " + IntToStr(udomain.domain.parameterManager.parameters.Count)) self.infoList.Lines.Add("Hints: " + IntToStr(udomain.domain.hintManager.hints.Count)) self.infoList.Lines.Add("Drawing scale: " + usupport.digitValueString(udomain.domain.plantManager.plantDrawScale_PixelsPerMm)) self.infoList.Lines.Add("Drawing offset: " + usupport.digitValueString(udomain.domain.plantManager.plantDrawOffset_mm.x) + " x " + usupport.digitValueString(udomain.domain.plantManager.plantDrawOffset_mm.y)) self.infoList.Lines.Add("") self.infoList.Lines.Add("Plants in file") self.infoList.Lines.Add("-------------------------------------------") # plant info self.infoList.Lines.Add("Plants in file: " + IntToStr(udomain.domain.plantManager.plants.Count)) self.infoList.Lines.Add("Plants in private clipboard: " + IntToStr(udomain.domain.plantManager.privatePlantClipboard.Count)) if udomain.domain.plantManager.plants.Count > 0: totalMemory_K = 0 self.infoList.Lines.Add("") for i in range(0, udomain.domain.plantManager.plants.Count): plant = uplant.PdPlant(udomain.domain.plantManager.plants.Items[i]) if plant == None: continue self.describePlant("Main window", plant) totalMemory_K = totalMemory_K + plant.totalMemoryUsed_K if totalMemory_K > 0: self.infoList.Lines.Add("Total memory used by plants in main window: " + self.stringForMemoryInK(totalMemory_K)) if (ubreedr.BreederForm != None) and (ubreedr.BreederForm.generations.Count > 0): # breeder info self.infoList.Lines.Add("") self.infoList.Lines.Add("Breeder plants") self.infoList.Lines.Add("-------------------------------------------") totalMemory_K = 0 for genCount in range(0, ubreedr.BreederForm.generations.Count): generation = ugener.PdGeneration(ubreedr.BreederForm.generations.Items[genCount]) if generation.plants.Count > 0: for plCount in range(0, generation.plants.Count): plant = uplant.PdPlant(generation.plants.Items[plCount]) if plant == None: continue self.describePlant("Breeder", plant) totalMemory_K = totalMemory_K + plant.totalMemoryUsed_K if totalMemory_K > 0: self.infoList.Lines.Add("Total memory used by plants in breeder: " + self.stringForMemoryInK(totalMemory_K)) if (utimeser.TimeSeriesForm != None) and (utimeser.TimeSeriesForm.plants.Count > 0): # time series info self.infoList.Lines.Add("") self.infoList.Lines.Add("Time series plants") self.infoList.Lines.Add("-------------------------------------------") totalMemory_K = 0 for i in range(0, utimeser.TimeSeriesForm.plants.Count): plant = uplant.PdPlant(utimeser.TimeSeriesForm.plants.Items[i]) if plant == None: continue self.describePlant("Time Series", plant) totalMemory_K = totalMemory_K + plant.totalMemoryUsed_K if totalMemory_K > 0: self.infoList.Lines.Add("Total memory used by plants in time series window: " + self.stringForMemoryInK(totalMemory_K))
def adjustAllValuesAtOnce(self): newString = ansistring() oldString = "" prompt = "" i = 0 failed = false points = [0] * (range(0, 1 + 1) + 1) oldValues = SCurveStructure() valuesInCurrentUnit = SCurveStructure() newValues = SCurveStructure() if self.selectedItemIndex < kItemX1: return oldValues.x1 = self.currentValues[0] oldValues.y1 = self.currentValues[1] oldValues.x2 = self.currentValues[2] oldValues.y2 = self.currentValues[3] valuesInCurrentUnit = oldValues valuesInCurrentUnit.x1 = self.toCurrentUnit(oldValues.x1) valuesInCurrentUnit.x2 = self.toCurrentUnit(oldValues.x2) newString = ( usupport.digitValueString(valuesInCurrentUnit.x1) + " " + usupport.digitValueString(valuesInCurrentUnit.y1) + " " + usupport.digitValueString(valuesInCurrentUnit.x2) + " " + usupport.digitValueString(valuesInCurrentUnit.y2) ) oldString = newString prompt = "Edit these four s curve values." if InputQuery("Enter value", prompt, newString): if newString != oldString: try: newValues = umath.stringToSCurve(newString) self.currentValues[0] = newValues.x1 self.currentValues[1] = newValues.y1 self.currentValues[2] = newValues.x2 self.currentValues[3] = newValues.y2 except: failed = true if not failed: points[0] = self.pointFromXY(self.currentValues[0], self.currentValues[1]) points[1] = self.pointFromXY(self.currentValues[2], self.currentValues[3]) for i in range(0, 1 + 1): self.keepPointInGraphRect(points[i]) self.keepPointsFromCrossing(points[0], points[1], 1) failed = self.drawSCurve(false, failed) if failed: self.currentValues[0] = oldValues.x1 self.currentValues[1] = oldValues.y1 self.currentValues[2] = oldValues.x2 self.currentValues[3] = oldValues.y2 ShowMessage("Invalid value.") else: # don't create change point command here, because only one float is changed umain.MainForm.doCommand( updcom.PdChangeSCurvePointValueCommand().createCommandWithListOfPlants( umain.MainForm.selectedPlants, self.currentValues[0], self.currentValues[1], self.param.fieldNumber, 0, self.param.regrow, ) ) umain.MainForm.doCommand( updcom.PdChangeSCurvePointValueCommand().createCommandWithListOfPlants( umain.MainForm.selectedPlants, self.currentValues[2], self.currentValues[3], self.param.fieldNumber, 1, self.param.regrow, ) ) self.Invalidate()
def paint(self): minYTextRect = TRect() maxYTextRect = TRect() minXTextRect = TRect() maxXTextRect = TRect() pointTextRect = TRect() maxXValueInCurrentUnit = 0.0 minXValueInCurrentUnit = 0.0 minXString = "" maxXString = "" minYString = "" maxYString = "" currentUnitString = "" currentValuesInCurrentUnit = [0] * (range(0, 3 + 1) + 1) valueStrings = [0] * (range(0, 3 + 1) + 1) i = 0 xPos = 0 totalWidth = 0 thePoint = TPoint() failed = false try: if delphi_compatability.Application.terminated: return PdParameterPanel.paint(self) if self.param.collapsed: return if gRecursing: # errorMessage('PdSCurveParameterPanel.Paint: recursion in paint method'); gRecursing = false return gRecursing = true # convert bounds and values from plant to current unit ( don't convert Y value) # this is only for writing strings; use plant unit for drawing points minXValueInCurrentUnit = self.toCurrentUnit(self.minXValue) if not self.belowZero: maxXValueInCurrentUnit = self.toCurrentUnit(self.maxXValue) currentValuesInCurrentUnit[0] = self.toCurrentUnit(self.currentValues[0]) currentValuesInCurrentUnit[2] = self.toCurrentUnit(self.currentValues[2]) else: maxXValueInCurrentUnit = self.toCurrentUnit(-self.maxXValue) currentValuesInCurrentUnit[0] = self.toCurrentUnit(-self.currentValues[0]) currentValuesInCurrentUnit[2] = self.toCurrentUnit(-self.currentValues[2]) currentValuesInCurrentUnit[1] = self.currentValues[1] currentValuesInCurrentUnit[3] = self.currentValues[3] # strings to write for number minXString = usupport.digitValueString(minXValueInCurrentUnit) maxXString = usupport.digitValueString(maxXValueInCurrentUnit) minYString = "0.0" maxYString = "1.0" currentUnitString = uunits.UnitStringForEnum(self.param.unitSet, self.currentUnitIndex) for i in range(0, 3 + 1): if (i == 0) or (i == 2): valueStrings[i] = ( self.stringForIndex(i) + " " + usupport.digitValueString(currentValuesInCurrentUnit[i]) ) else: valueStrings[i] = ( self.stringForIndex(i) + " " + FloatToStrF(currentValuesInCurrentUnit[i], UNRESOLVED.ffFixed, 7, 2) ) # calculate all rectangles to draw text, points self.graphRect.Left = uppanel.kLeftRightGap + self.Canvas.TextWidth(minYString) + udebug.kBetweenGap self.graphRect.Right = self.ClientWidth - uppanel.kLeftRightGap * 2 self.graphRect.Top = self.collapsedHeight() self.graphRect.Bottom = self.Height - self.textHeight * 2 - udebug.kBetweenGap - uppanel.kTopBottomGap * 2 minXTextRect.Left = self.graphRect.Left minXTextRect.Right = minXTextRect.Left + self.Canvas.TextWidth(minXString) minXTextRect.Top = self.graphRect.Bottom + 1 minXTextRect.Bottom = minXTextRect.Top + self.textHeight maxXTextRect.Right = self.graphRect.Right maxXTextRect.Left = maxXTextRect.Right - self.Canvas.TextWidth(maxXString) maxXTextRect.Top = minXTextRect.Top maxXTextRect.Bottom = maxXTextRect.Top + self.textHeight minYTextRect.Left = self.graphRect.Left - self.Canvas.TextWidth(maxYString) - udebug.kBetweenGap minYTextRect.Right = self.graphRect.Left - 1 minYTextRect.Top = self.graphRect.Bottom - self.textHeight minYTextRect.Bottom = self.graphRect.Bottom maxYTextRect.Left = self.graphRect.Left - self.Canvas.TextWidth(maxYString) - udebug.kBetweenGap maxYTextRect.Right = self.graphRect.Left - 1 maxYTextRect.Top = self.graphRect.Top maxYTextRect.Bottom = maxYTextRect.Top + self.textHeight for i in range(0, 1 + 1): thePoint = self.pointFromXY(self.currentValues[i * 2], self.currentValues[i * 2 + 1]) self.pointRects[i].Left = thePoint.X - usliders.kSliderDraggerHeight / 2 self.pointRects[i].Right = self.pointRects[i].Left + usliders.kSliderDraggerHeight self.pointRects[i].Top = thePoint.Y - usliders.kSliderDraggerHeight / 2 self.pointRects[i].Bottom = self.pointRects[i].Top + usliders.kSliderDraggerHeight # center point value texts totalWidth = 0 # for i := 0 to 3 do totalWidth := totalWidth + canvas.textWidth(valueStrings[i]); # totalWidth := totalWidth + kBetweenGap * 3; # xPos := self.left + self.width div 2 - totalWidth div 2; xPos = self.graphRect.Left for i in range(0, 3 + 1): self.valueRects[i].Left = xPos self.valueRects[i].Right = self.valueRects[i].Left + self.Canvas.TextWidth(valueStrings[i]) self.valueRects[i].Top = minXTextRect.Bottom + uppanel.kLeftRightGap / 2 self.valueRects[i].Bottom = self.valueRects[i].Top + self.textHeight xPos = xPos + (self.valueRects[i].Right - self.valueRects[i].Left) + uppanel.kLeftRightGap # center unit text self.unitTextRect.Left = ( self.graphRect.Left + (self.graphRect.Right - self.graphRect.Left) / 2 - self.Canvas.TextWidth(currentUnitString) / 2 ) self.unitTextRect.Right = self.unitTextRect.Left + self.Canvas.TextWidth(currentUnitString) self.unitTextRect.Top = minXTextRect.Top self.unitTextRect.Bottom = self.unitTextRect.Top + self.textHeight if self.editEnabled: # finally, draw all text # draw lines black if enabled, else gray self.Canvas.Pen.Color = UNRESOLVED.clBtnText else: self.Canvas.Pen.Color = UNRESOLVED.clBtnShadow # draw axes self.Canvas.MoveTo(self.graphRect.Left, self.graphRect.Top) self.Canvas.LineTo(self.graphRect.Left, self.graphRect.Bottom) self.Canvas.LineTo(self.graphRect.Right, self.graphRect.Bottom) # draw axis labels self.drawText(minYString, minYTextRect, false, false, true) self.drawText(maxYString, maxYTextRect, false, false, true) self.drawText(minXString, minXTextRect, false, false, true) self.drawText(maxXString, maxXTextRect, false, false, true) for i in range(0, 3 + 1): # draw value texts self.drawText( valueStrings[i], self.valueRects[i], true, (self.editEnabled) and (i == self.selectedItemIndex - kItemX1), false, ) # draw unit string self.drawText( currentUnitString, self.unitTextRect, true, (self.editEnabled) and (self.selectedItemIndex == kItemSCurveUnitText), false, ) for i in range(0, 1 + 1): # draw point rectangles and labels (labels first because brush color will affect them # first put text at lower right of point pointTextRect = Rect( self.pointRects[i].Right + 5, self.pointRects[i].Top, self.pointRects[i].Right + 5 + self.Canvas.TextWidth(IntToStr(i + 1)), self.pointRects[i].Top + self.textHeight, ) if pointTextRect.Right >= self.graphRect.Right: # adjust point text rectangle if could not be seen delphi_compatability.OffsetRect(pointTextRect, -20, 0) if pointTextRect.Bottom >= self.graphRect.Bottom: delphi_compatability.OffsetRect(pointTextRect, 0, -10) self.drawText(IntToStr(i + 1), pointTextRect, false, false, false) # draw curve failed = self.drawSCurve(true, failed) if not failed: for i in range(0, 1 + 1): # draw points usliders.KfDrawButton( self.Canvas, self.pointRects[i], (self.selectedItemIndex == kItemPoint1 + i), self.editEnabled ) finally: gRecursing = false
def sCurveToString(sCurve): result = usupport.digitValueString( sCurve.x1) + " " + usupport.digitValueString( sCurve.y1) + " " + usupport.digitValueString( sCurve.x2) + " " + usupport.digitValueString(sCurve.y2) return result
def writeTriangleToDXFFIle(self, outputFile, p1, p2, p3, color): writeln(outputFile, "0") writeln(outputFile, "3DFACE") writeln(outputFile, "8") writeln(outputFile, "3dObject") writeln(outputFile, "62") writeln(outputFile, IntToStr(color)) # v1.60final changed intToStr(round(p|.|)) to digitValueString(p|.|) # can't see that there was ever any reason to round these; it's probably left over from # when I didn't understand DXF very well writeln(outputFile, "10") writeln(outputFile, usupport.digitValueString(p1.x)) writeln(outputFile, "20") writeln(outputFile, usupport.digitValueString(-p1.y)) writeln(outputFile, "30") writeln(outputFile, usupport.digitValueString(p1.z)) writeln(outputFile, "11") writeln(outputFile, usupport.digitValueString(p2.x)) writeln(outputFile, "21") writeln(outputFile, usupport.digitValueString(-p2.y)) writeln(outputFile, "31") writeln(outputFile, usupport.digitValueString(p2.z)) writeln(outputFile, "12") writeln(outputFile, usupport.digitValueString(p3.x)) writeln(outputFile, "22") writeln(outputFile, usupport.digitValueString(-p3.y)) writeln(outputFile, "32") writeln(outputFile, usupport.digitValueString(p3.z)) writeln(outputFile, "13") writeln(outputFile, usupport.digitValueString(p3.x)) writeln(outputFile, "23") writeln(outputFile, usupport.digitValueString(-p3.y)) writeln(outputFile, "33") writeln(outputFile, usupport.digitValueString(p3.z))
def sCurveToString(sCurve): result = usupport.digitValueString(sCurve.x1) + " " + usupport.digitValueString(sCurve.y1) + " " + usupport.digitValueString(sCurve.x2) + " " + usupport.digitValueString(sCurve.y2) return result