Beispiel #1
0
 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 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
Beispiel #4
0
 def calculateResolutionFromInchesAndPixels(self):
     xRes = 0.0
     yRes = 0.0
     
     xRes = umath.safedivExcept(self.pictureWidth_px, self.pictureWidth_in, delphi_compatability.Screen.PixelsPerInch)
     yRes = umath.safedivExcept(self.pictureHeight_px, self.pictureHeight_in, delphi_compatability.Screen.PixelsPerInch)
     self.setValue(self.resolutionEdit, intround(umath.min(xRes, yRes)))
     self.calculatePixelsFromResolutionAndInches()
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")
Beispiel #6
0
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")
Beispiel #7
0
    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 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
Beispiel #9
0
    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
Beispiel #10
0
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 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")
Beispiel #12
0
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
Beispiel #13
0
 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
Beispiel #14
0
 def updatePrintPreview(self):
     scaleX_pxPin = 0.0
     scaleY_pxPin = 0.0
     scale_pxPin = 0.0
     borderThickness_in = 0.0
     availableWidth_px = 0
     availableHeight_px = 0
     marginRect = TRect()
     
     availableWidth_px = self.sizeLabel.Left - self.wholePageImage.Left - 10
     availableHeight_px = self.printBox.Height - self.wholePageImage.Top - 10
     scaleX_pxPin = umath.safedivExcept(1.0 * availableWidth_px, self.wholePageWidth_in, 5)
     scaleY_pxPin = umath.safedivExcept(1.0 * availableHeight_px, self.wholePageHeight_in, 5)
     scale_pxPin = umath.min(scaleX_pxPin, scaleY_pxPin)
     self.wholePageImage.Width = intround(self.wholePageWidth_in * scale_pxPin)
     self.wholePageImage.Height = intround(self.wholePageHeight_in * scale_pxPin)
     if (self.wholePageImage.Picture.Bitmap.Width != self.wholePageImage.Width) or (self.wholePageImage.Picture.Bitmap.Height != self.wholePageImage.Height):
         try:
             self.wholePageImage.Picture.Bitmap.Width = self.wholePageImage.Width
             self.wholePageImage.Picture.Bitmap.Height = self.wholePageImage.Height
         except:
             self.wholePageImage.Picture.Bitmap.Width = 1
             self.wholePageImage.Picture.Bitmap.Height = 1
     marginRect.Left = intround(self.printMinMarginLeft_in * scale_pxPin)
     marginRect.Top = intround(self.printMinMarginTop_in * scale_pxPin)
     # subtract 1 from right and bottom because last pixel is not drawn
     marginRect.Right = self.wholePageImage.Width - intround(self.printMinMarginRight_in * scale_pxPin) - 1
     marginRect.Bottom = self.wholePageImage.Height - intround(self.printMinMarginBottom_in * scale_pxPin) - 1
     self.wholePageImage.Picture.Bitmap.Canvas.Brush.Color = delphi_compatability.clWindow
     self.wholePageImage.Picture.Bitmap.Canvas.FillRect(Rect(0, 0, self.wholePageImage.Width, self.wholePageImage.Height))
     self.wholePageImage.Picture.Bitmap.Canvas.Brush.Style = delphi_compatability.TFPBrushStyle.bsClear
     self.wholePageImage.Picture.Bitmap.Canvas.Pen.Color = UNRESOLVED.clBtnShadow
     self.wholePageImage.Picture.Bitmap.Canvas.MoveTo(0, marginRect.Top)
     self.wholePageImage.Picture.Bitmap.Canvas.LineTo(self.wholePageImage.Width, marginRect.Top)
     self.wholePageImage.Picture.Bitmap.Canvas.MoveTo(marginRect.Left, 0)
     self.wholePageImage.Picture.Bitmap.Canvas.LineTo(marginRect.Left, self.wholePageImage.Height)
     self.wholePageImage.Picture.Bitmap.Canvas.MoveTo(marginRect.Right, 0)
     self.wholePageImage.Picture.Bitmap.Canvas.LineTo(marginRect.Right, self.wholePageImage.Height)
     self.wholePageImage.Picture.Bitmap.Canvas.MoveTo(0, marginRect.Bottom)
     self.wholePageImage.Picture.Bitmap.Canvas.LineTo(self.wholePageImage.Width, marginRect.Bottom)
     self.wholePageImage.Picture.Bitmap.Canvas.Pen.Style = delphi_compatability.TFPPenStyle.psSolid
     self.wholePageImage.Picture.Bitmap.Canvas.Rectangle(0, 0, self.wholePageImage.Width, self.wholePageImage.Height)
     borderThickness_in = umath.safedivExcept(self.options.borderThickness, self.smallestPrintResolution_pxPin, 0)
     self.printImagePanel.SetBounds(intround(self.wholePageImage.Left + (self.printLeftMargin_in - borderThickness_in) * scale_pxPin), intround(self.wholePageImage.Top + (self.printTopMargin_in - borderThickness_in) * scale_pxPin), intround((self.printWidth_in + borderThickness_in * 2) * scale_pxPin), intround((self.printHeight_in + borderThickness_in * 2) * scale_pxPin))
Beispiel #15
0
 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 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
Beispiel #17
0
 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
Beispiel #19
0
 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
Beispiel #20
0
 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