def suggestPrintSizeClick(self, Sender): bestMargin_in = 0.0 bestWidth_in = 0.0 bestHeight_in = 0.0 newWidth_in = 0.0 newHeight_in = 0.0 maxMinMargin_in = 0.0 # calculate best margin: for 10 inches, 1.0 inches, for 5 inches, 0.5 inches; # keep to multiples of 0.25 inches maxMinMargin_in = umath.max(self.printMinMarginLeft_in, umath.max(self.printMinMarginTop_in, umath.max(self.printMinMarginRight_in, self.printMinMarginBottom_in))) bestMargin_in = umath.max(maxMinMargin_in, intround(4.0 * umath.min(self.wholePageWidth_in, self.wholePageHeight_in) / 10.0) / 4.0) bestWidth_in = self.wholePageWidth_in - bestMargin_in * 2 bestHeight_in = self.wholePageHeight_in - bestMargin_in * 2 # preserve aspect ratio - reduce the larger dimension so it still fits on the page self.updateSelectionRectFromMainWindow() newHeight_in = bestHeight_in newWidth_in = bestHeight_in * self.aspectRatio if newWidth_in > bestWidth_in: newWidth_in = bestWidth_in newHeight_in = umath.safedivExcept(bestWidth_in, self.aspectRatio, bestHeight_in) # set original picture size to fit on page using printer resolution self.setValue(self.inchWidthEdit, newWidth_in) self.setValue(self.inchHeightEdit, newHeight_in) self.setValue(self.resolutionEdit, self.smallestPrintResolution_pxPin) self.calculatePixelsFromResolutionAndInches() # set print size same as picture size self.setValue(self.printWidthEdit, newWidth_in) self.setValue(self.printHeightEdit, newHeight_in) # center picture self.printCenterClick(self)
def changePrintMarginsToFitPrintSize(self): self.setValue(self.printRightMarginEdit, umath.max(0, self.wholePageWidth_in - self.printLeftMargin_in - self.printWidth_in)) self.setValue(self.printBottomMarginEdit, umath.max(0, self.wholePageHeight_in - self.printTopMargin_in - self.printHeight_in)) if self.printPreserveAspectRatio.Checked: self.resizePrintBasedOnAspectRatio(kHeightAndWidthWereChanged) else: self.updatePrintPreview()
def printCenterClick(self, Sender): self.setValue(self.printLeftMarginEdit, umath.max(self.printMinMarginLeft_in, self.wholePageWidth_in / 2.0 - self.printWidth_in / 2.0)) self.setValue(self.printRightMarginEdit, umath.max(self.printMinMarginRight_in, self.wholePageWidth_in / 2.0 - self.printWidth_in / 2.0)) self.setValue(self.printTopMarginEdit, umath.max(self.printMinMarginTop_in, self.wholePageHeight_in / 2.0 - self.printHeight_in / 2.0)) self.setValue(self.printBottomMarginEdit, umath.max(self.printMinMarginBottom_in, self.wholePageHeight_in / 2.0 - self.printHeight_in / 2.0)) if self.printPreserveAspectRatio.Checked: self.resizePrintBasedOnAspectRatio(kHeightAndWidthWereChanged) else: self.updatePrintPreview()
def zeroToOne(self): k = intround(self.seed / 127773) self.seed = intround((16807 * (self.seed - (k * 127773))) - (k * 2846)) if (self.seed < 0.0): self.seed = self.seed + 2147483647 result = (umath.max(0.0, (umath.min(1.0, (self.seed * 0.0000000004656612875))))) * 1.0 return result
def randomPercent(self): k = intround(self.seed / 127773) self.seed = intround((16807 * (self.seed - (k * 127773))) - (k * 2846)) if (self.seed < 0.0): self.seed = self.seed + 2147483647 result = intround(umath.max(0, (umath.min(100, (self.seed * 0.0000000004656612875 * 100.0))))) return result
def FormActivate(self, Sender): timeBetween = TDateTime() hours = 0 minutes = 0 seconds = 0 milliseconds = 0 smallHours = 0 randomNumber = 0 i = 0 self.versionLabel.Caption = usupport.gVersionName self.exportRestrictionLabel.Caption = "- restricting the number of exports to " + IntToStr( udomain.kMaxUnregExportsAllowed) + " at first, then " + IntToStr( udomain.kMaxUnregExportsPerSessionAfterMaxReached ) + " per session" self.ActiveControl = self.registerIt UNRESOLVED.randomize for i in range(0, 100 + 1): UNRESOLVED.random randomNumber = UNRESOLVED.random(2) if randomNumber == 0: self.close.Top = 4 self.registerIt.Top = self.close.Top + self.close.Height + 3 elif randomNumber == 1: self.registerIt.Top = 4 self.close.Top = self.registerIt.Top + self.registerIt.Height + 3 self.hoursLabel.Caption = "You have been evaluating PlantStudio for " timeBetween = umath.max( (UNRESOLVED.Now - udomain.domain.startTimeThisSession), 0) + udomain.domain.accumulatedUnregisteredTime UNRESOLVED.DecodeTime(timeBetween, smallHours, minutes, seconds, milliseconds) hours = smallHours if timeBetween >= 1.0: hours = hours + trunc(timeBetween) * 24 if (minutes < 1) and (hours < 1): self.hoursLabel.Caption = self.hoursLabel.Caption + "less than one minute." elif (minutes == 1) and (hours < 1): self.hoursLabel.Caption = self.hoursLabel.Caption + "one minute." elif hours < 1: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr( minutes) + " minutes." elif hours == 1: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr( hours) + " hour and " + IntToStr(minutes) + " minutes." else: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr( hours) + " hours and " + IntToStr(minutes) + " minutes." self.timeWarningLabel.Caption = "If you have been using PlantStudio for " + IntToStr( usupport.kMaxEvaluationTime_hours ) + " hours or more (in total), you are legally required to register it." if hours >= usupport.kMaxEvaluationTime_hours: self.timeWarningLabel.Font.Color = delphi_compatability.clGreen self.timeWarningLabel.Font.Style = [ UNRESOLVED.fsBold, ]
def zeroToOne(self): result = 0.0 k = 0.0 k = intround(self.seed / 127773) self.seed = intround((16807 * (self.seed - (k * 127773))) - (k * 2846)) if (self.seed < 0.0): self.seed = self.seed + 2147483647 result = (umath.max( 0.0, (umath.min(1.0, (self.seed * 0.0000000004656612875))))) * 1.0 return result
def linearGrowthWithFactor(current, optimal, minDays, growthFactor): amountNeeded = 0.0 maxPossible = 0.0 try: amountNeeded = optimal - current maxPossible = umath.safedivExcept(optimal, minDays, optimal) amountNeeded = umath.max(0.0, umath.min(amountNeeded, maxPossible)) current = current + amountNeeded * growthFactor except Exception, e: usupport.messageForExceptionType(e, "linearGrowthWithFactor")
def blendColors(firstColor, secondColor, aStrength): #blend first color with second color, # weighting the second color by aStrength (0-1) and first color by (1 - aStrength). aStrength = umath.max(0.0, umath.min(1.0, aStrength)) r1 = umath.intMax(0, umath.intMin(255, GetRValue(firstColor))) g1 = umath.intMax(0, umath.intMin(255, GetGValue(firstColor))) b1 = umath.intMax(0, umath.intMin(255, GetBValue(firstColor))) r2 = umath.intMax(0, umath.intMin(255, GetRValue(secondColor))) g2 = umath.intMax(0, umath.intMin(255, GetGValue(secondColor))) b2 = umath.intMax(0, umath.intMin(255, GetBValue(secondColor))) result = support_rgb(intround(r1 * (1.0 - aStrength) + r2 * aStrength), intround(g1 * (1.0 - aStrength) + g2 * aStrength), intround(b1 * (1.0 - aStrength) + b2 * aStrength)) return result
def randomPercent(self): result = 0.0 k = 0.0 k = intround(self.seed / 127773) self.seed = intround((16807 * (self.seed - (k * 127773))) - (k * 2846)) if (self.seed < 0.0): self.seed = self.seed + 2147483647 result = intround( umath.max( 0, (umath.min(100, (self.seed * 0.0000000004656612875 * 100.0))))) return result
def linearGrowthResult(current, optimal, minDays): result = 0.0 amountNeeded = 0.0 maxPossible = 0.0 result = 0.0 try: amountNeeded = optimal - current maxPossible = umath.safedivExcept(optimal, minDays, optimal) amountNeeded = umath.max(0.0, umath.min(amountNeeded, maxPossible)) result = amountNeeded except Exception, e: usupport.messageForExceptionType(e, "linearGrowthResult")
def resizePrintBasedOnAspectRatio(self, whatWasChanged): newWidth_in = 0.0 newHeight_in = 0.0 newRight_in = 0.0 newBottom_in = 0.0 maxWidth_in = 0.0 maxHeight_in = 0.0 newWidth_in = self.printWidth_in newHeight_in = self.printHeight_in self.updateSelectionRectFromMainWindow() if whatWasChanged == kHeightWasChanged: newWidth_in = newHeight_in * self.aspectRatio elif whatWasChanged == kWidthWasChanged: newHeight_in = umath.safedivExcept(newWidth_in, self.aspectRatio, newHeight_in) elif whatWasChanged == kHeightAndWidthWereChanged: if newWidth_in > newHeight_in: newWidth_in = newHeight_in * self.aspectRatio else: newHeight_in = umath.safedivExcept(newWidth_in, self.aspectRatio, newHeight_in) # bound size at page, using left/top margins already set maxWidth_in = self.wholePageWidth_in - self.printLeftMargin_in - self.printMinMarginRight_in maxHeight_in = self.wholePageHeight_in - self.printTopMargin_in - self.printMinMarginBottom_in if newWidth_in > maxWidth_in: newWidth_in = maxWidth_in newHeight_in = umath.safedivExcept(newWidth_in, self.aspectRatio, newHeight_in) if newHeight_in > maxHeight_in: newHeight_in = maxHeight_in newWidth_in = newHeight_in * self.aspectRatio newRight_in = umath.max(self.printMinMarginRight_in, self.wholePageWidth_in - self.printLeftMargin_in - newWidth_in) newBottom_in = umath.max(self.printMinMarginBottom_in, self.wholePageHeight_in - self.printTopMargin_in - newHeight_in) # set values in edits self.setValue(self.printWidthEdit, newWidth_in) self.setValue(self.printHeightEdit, newHeight_in) self.setValue(self.printRightMarginEdit, newRight_in) self.setValue(self.printBottomMarginEdit, newBottom_in) self.updatePrintPreview()
def displayPercentForPartType(self, partType, livingDeadOrBoth): result = 0.0 total_pctMPB = 0.0 result = 0.0 total_pctMPB = self.statistics.liveBiomass_pctMPB[utravers.kStatisticsPartTypeAllVegetative] + self.statistics.deadBiomass_pctMPB[utravers.kStatisticsPartTypeAllVegetative] + self.statistics.liveBiomass_pctMPB[utravers.kStatisticsPartTypeAllReproductive] + self.statistics.deadBiomass_pctMPB[utravers.kStatisticsPartTypeAllReproductive] if total_pctMPB == 0.0: return result if livingDeadOrBoth == kLive: result = self.statistics.liveBiomass_pctMPB[partType] elif livingDeadOrBoth == kDead: result = self.statistics.deadBiomass_pctMPB[partType] elif livingDeadOrBoth == kBothLiveAndDead: result = self.statistics.liveBiomass_pctMPB[partType] + self.statistics.deadBiomass_pctMPB[partType] result = umath.min(100.0, umath.max(0.0, 100.0 * result / total_pctMPB)) return result
def FormActivate(self, Sender): timeBetween = TDateTime() hours = 0 minutes = 0 seconds = 0 milliseconds = 0 smallHours = 0 randomNumber = 0 i = 0 self.versionLabel.Caption = usupport.gVersionName self.exportRestrictionLabel.Caption = "- restricting the number of exports to " + IntToStr(udomain.kMaxUnregExportsAllowed) + " at first, then " + IntToStr(udomain.kMaxUnregExportsPerSessionAfterMaxReached) + " per session" self.ActiveControl = self.registerIt UNRESOLVED.randomize for i in range(0, 100 + 1): UNRESOLVED.random randomNumber = UNRESOLVED.random(2) if randomNumber == 0: self.close.Top = 4 self.registerIt.Top = self.close.Top + self.close.Height + 3 elif randomNumber == 1: self.registerIt.Top = 4 self.close.Top = self.registerIt.Top + self.registerIt.Height + 3 self.hoursLabel.Caption = "You have been evaluating PlantStudio for " timeBetween = umath.max((UNRESOLVED.Now - udomain.domain.startTimeThisSession), 0) + udomain.domain.accumulatedUnregisteredTime UNRESOLVED.DecodeTime(timeBetween, smallHours, minutes, seconds, milliseconds) hours = smallHours if timeBetween >= 1.0: hours = hours + trunc(timeBetween) * 24 if (minutes < 1) and (hours < 1): self.hoursLabel.Caption = self.hoursLabel.Caption + "less than one minute." elif (minutes == 1) and (hours < 1): self.hoursLabel.Caption = self.hoursLabel.Caption + "one minute." elif hours < 1: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr(minutes) + " minutes." elif hours == 1: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr(hours) + " hour and " + IntToStr(minutes) + " minutes." else: self.hoursLabel.Caption = self.hoursLabel.Caption + IntToStr(hours) + " hours and " + IntToStr(minutes) + " minutes." self.timeWarningLabel.Caption = "If you have been using PlantStudio for " + IntToStr(usupport.kMaxEvaluationTime_hours) + " hours or more (in total), you are legally required to register it." if hours >= usupport.kMaxEvaluationTime_hours: self.timeWarningLabel.Font.Color = delphi_compatability.clGreen self.timeWarningLabel.Font.Style = [UNRESOLVED.fsBold, ]
def initializeWithPlant(self, aPlant, drawNow): newPlant = PdPlant() i = 0 if aPlant == None: return if not self.Visible: self.Show() self.BringToFront() self.plants.clear() self.parentPlant = aPlant ucursor.cursor_startWait() try: for i in range(0, self.numStages): newPlant = uplant.PdPlant().create() self.parentPlant.copyTo(newPlant) self.ages[i] = intround(umath.max(0.0, umath.min(1.0, self.percentsOfMaxAge[i] / 100.0)) * newPlant.pGeneral.ageAtMaturity) newPlant.setAge(self.ages[i]) self.plants.Add(newPlant) finally: ucursor.cursor_stopWait() if drawNow: self.redrawPlants()
def changePrintSizeToFitPrintMargins(self, editBox): if editBox == self.printLeftMarginEdit: # keep print size same to start, just offset other margin self.setValue(self.printRightMarginEdit, umath.max(0, self.wholePageWidth_in - self.printLeftMargin_in - self.printWidth_in)) elif editBox == self.printRightMarginEdit: self.setValue(self.printLeftMarginEdit, umath.max(0, self.wholePageWidth_in - self.printRightMargin_in - self.printWidth_in)) elif editBox == self.printTopMarginEdit: self.setValue(self.printBottomMarginEdit, umath.max(0, self.wholePageHeight_in - self.printTopMargin_in - self.printHeight_in)) elif editBox == self.printBottomMarginEdit: self.setValue(self.printTopMarginEdit, umath.max(0, self.wholePageHeight_in - self.printBottomMargin_in - self.printHeight_in)) # now set print size self.setValue(self.printWidthEdit, umath.max(0, self.wholePageWidth_in - self.printRightMargin_in - self.printLeftMargin_in)) self.setValue(self.printHeightEdit, umath.max(0, self.wholePageHeight_in - self.printBottomMargin_in - self.printTopMargin_in)) if self.printPreserveAspectRatio.Checked: # now check aspect ratio self.resizePrintBasedOnAspectRatio(kHeightAndWidthWereChanged) else: self.updatePrintPreview()
def randomNormalPercent(self, mean): result = 0.0 #return normal random number based on mean (and std dev of half mean) bounded at 0 and 100 result = umath.max(0, (umath.min(100, intround(self.randomNormal(mean / 100.0) * 100.0)))) return result
def setValue(self, editBox, newValue): maxWidth_in = 0.0 maxHeight_in = 0.0 self.sideEffect = true maxWidth_in = self.wholePageWidth_in - self.printMinMarginLeft_in - self.printMinMarginRight_in maxHeight_in = self.wholePageHeight_in - self.printMinMarginTop_in - self.printMinMarginBottom_in if editBox == self.pixelWidthEdit: newValue = umath.max(udomain.kMinPixels, umath.min(udomain.kMaxPixels, newValue)) self.pictureWidth_px = newValue elif editBox == self.pixelHeightEdit: newValue = umath.max(udomain.kMinPixels, umath.min(udomain.kMaxPixels, newValue)) self.pictureHeight_px = newValue elif editBox == self.inchWidthEdit: newValue = umath.max(udomain.kMinInches, umath.min(udomain.kMaxInches, newValue)) self.pictureWidth_in = newValue elif editBox == self.inchHeightEdit: newValue = umath.max(udomain.kMinInches, umath.min(udomain.kMaxInches, newValue)) self.pictureHeight_in = newValue elif editBox == self.resolutionEdit: newValue = umath.max(udomain.kMinResolution, umath.min(udomain.kMaxResolution, newValue)) self.pictureResolution_pxPin = newValue elif editBox == self.printWidthEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxWidth_in)) self.printWidth_in = newValue elif editBox == self.printHeightEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxHeight_in)) self.printHeight_in = newValue elif editBox == self.printLeftMarginEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxWidth_in)) self.printLeftMargin_in = newValue elif editBox == self.printTopMarginEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxHeight_in)) self.printTopMargin_in = newValue elif editBox == self.printRightMarginEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxWidth_in)) self.printRightMargin_in = newValue elif editBox == self.printBottomMarginEdit: newValue = umath.max(udomain.kMinInches, umath.min(newValue, maxHeight_in)) self.printBottomMargin_in = newValue elif editBox == self.jpgCompressionEdit: newValue = umath.max(1, umath.min(100, newValue)) self.jpegCompression = newValue if editBox.Tag == kEditBoxHasInteger: editBox.Text = IntToStr(intround(newValue)) elif editBox.Tag == kEditBoxHasFloat: editBox.Text = floatStr(newValue) self.sideEffect = false
def randomNormalBoundedZeroToOne(self, mean): result = 0.0 #return normal random number based on mean (and std dev of half mean) result = umath.max(0.0, (umath.min(1.0, (self.randomNormal(mean))))) return result
def randomNormalPercent(self, mean): result = 0.0 #return normal random number based on mean (and std dev of half mean) bounded at 0 and 100 result = umath.max(0, (umath.min( 100, intround(self.randomNormal(mean / 100.0) * 100.0)))) return result