Пример #1
0
 def pastePlantsFromPrivatePlantClipboardToList(self, aList):
     i = 0
     plant = PdPlant()
     newPlant = PdPlant()
     
     if self.privatePlantClipboard.Count > 0:
         for i in range(0, self.privatePlantClipboard.Count):
             # caller takes responsibility of freeing plants 
             plant = uplant.PdPlant(self.privatePlantClipboard.Items[i])
             newPlant = uplant.PdPlant().create()
             plant.copyTo(newPlant)
             newPlant.moveBy(Point(updcom.kPasteMoveDistance, 0))
             aList.Add(newPlant)
Пример #2
0
 def copyPlantsInListToPrivatePlantClipboard(self, aList):
     i = 0
     plant = PdPlant()
     newPlant = PdPlant()
     
     self.privatePlantClipboard.clear()
     if aList.Count > 0:
         for i in range(0, aList.Count):
             plant = uplant.PdPlant(aList.Items[i])
             newPlant = uplant.PdPlant().create()
             plant.copyTo(newPlant)
             newPlant.setName("Copy of " + newPlant.getName())
             self.privatePlantClipboard.Add(newPlant)
Пример #3
0
 def plantsDrawGridMouseDown(self, Sender, Button, Shift, X, Y):
     plant = PdPlant()
     col = 0
     row = 0
     oldSelectedRow = 0
     generation = PdGeneration()
     
     col, row = self.plantsDrawGrid.MouseToCell(X, Y, col, row)
     if (row >= 0) and (row <= self.generations.Count - 1):
         generation = ugener.PdGeneration(self.generations.Items[row])
         if generation != None:
             self.selectGeneration(generation)
             if (col >= 1) and (col - 1 <= generation.plants.Count - 1):
                 plant = uplant.PdPlant(generation.plants.Items[col - 1])
                 if plant != None:
                     generation.selectPlant(plant, (delphi_compatability.TShiftStateEnum.ssShift in Shift))
                 else:
                     generation.deselectAllPlants()
                 # in first column or past them on right 
             else:
                 generation.deselectAllPlants()
         else:
             self.deselectAllGenerations()
     else:
         self.deselectAllGenerations()
     self.updateForChangeToGenerations()
     if (Button == delphi_compatability.TMouseButton.mbRight) or (delphi_compatability.TShiftStateEnum.ssShift in Shift):
         # start drag of plant
         return
     plant = self.plantAtMouse(X, Y)
     if plant == None:
         return
     self.dragPlantStartPoint = Point(X, Y)
     self.plantsDrawGrid.BeginDrag(false)
Пример #4
0
 def totalPlantPartCountInInvalidRect(self, selectedPlants, invalidRect, excludeInvisiblePlants, excludeNonSelectedPlants):
     result = 0L
     plantIndex = 0
     plant = PdPlant()
     intersection = TRect()
     plantRect = TRect()
     intersectResult = longbool()
     includePlant = false
     
     result = 0
     if delphi_compatability.Application.terminated:
         return result
     if self.plants.Count > 0:
         for plantIndex in range(self.plants.Count - 1, 0 + 1):
             plant = uplant.PdPlant(self.plants.Items[plantIndex])
             includePlant = false
             plantRect = plant.boundsRect_pixels()
             if (plantRect.Left == 0) and (plantRect.Right == 0) and (plantRect.Top == 0) and (plantRect.Bottom == 0):
                 # if plant has just been read in, recalculate bounds rect by drawing it 
                 includePlant = true
             intersectResult = delphi_compatability.IntersectRect(intersection, plantRect, invalidRect)
             includePlant = includePlant or intersectResult
             if excludeInvisiblePlants:
                 includePlant = includePlant and not plant.hidden
             if excludeNonSelectedPlants:
                 includePlant = includePlant and (selectedPlants.IndexOf(plant) >= 0)
             if includePlant:
                 plant.countPlantParts()
                 result = result + plant.totalPlantParts
     return result
Пример #5
0
 def BreederMenuRandomizeClick(self, Sender):
     newCommand = PdCommand()
     randomizeList = TList()
     aGeneration = PdGeneration()
     i = 0
     plant = PdPlant()
     
     aGeneration = self.selectedGeneration()
     if aGeneration == None:
         return
     if aGeneration.selectedPlants.Count <= 0:
         return
     randomizeList = delphi_compatability.TList().Create()
     try:
         for i in range(0, aGeneration.selectedPlants.Count):
             plant = uplant.PdPlant(aGeneration.selectedPlants.Items[i])
             randomizeList.Add(plant)
         newCommand = updcom.PdRandomizeCommand().createWithListOfPlants(randomizeList)
         (newCommand as updcom.PdRandomizeCommand).isInBreeder = true
         ucursor.cursor_startWait()
         umain.MainForm.doCommand(newCommand)
     finally:
         #command has another list, so we must free this one
         randomizeList.free
         ucursor.cursor_stopWait()
Пример #6
0
 def BreederMenuRandomizeAllClick(self, Sender):
     generation = PdGeneration()
     i = 0
     j = 0
     newCommand = PdCommand()
     randomizeList = TList()
     
     if self.generations.Count <= 0:
         return
     randomizeList = None
     try:
         ucursor.cursor_startWait()
         randomizeList = delphi_compatability.TList().Create()
         if self.generations.Count > 0:
             for i in range(0, self.generations.Count):
                 generation = ugener.PdGeneration(self.generations.Items[i])
                 if generation.plants.Count > 0:
                     for j in range(0, generation.plants.Count):
                         randomizeList.Add(uplant.PdPlant(generation.plants.Items[j]))
         newCommand = updcom.PdRandomizeCommand().createWithListOfPlants(randomizeList)
         (newCommand as updcom.PdRandomizeCommand).isInBreeder = true
         (newCommand as updcom.PdRandomizeCommand).isRandomizeAllInBreeder = true
         umain.MainForm.doCommand(newCommand)
     finally:
         randomizeList.free
         ucursor.cursor_stopWait()
Пример #7
0
 def recalculateCommonDrawingScaleAndPosition(self):
     plant = PdPlant()
     i = 0
     minScale = 0.0
     plantPartsToDraw = 0L
     partsDrawn = 0L
     bestPosition = TPoint()
     widestWidth = 0L
     tallestHeight = 0L
     
     if self.plants == None:
         return
     if self.plants.Count <= 0:
         return
     # find smallest scale
     minScale = 0.0
     for i in range(0, self.plants.Count):
         plant = uplant.PdPlant(self.plants.Items[i])
         plant.fixedPreviewScale = false
         plant.fixedDrawPosition = false
         plant.drawPreviewIntoCache(Point(self.grid.DefaultColWidth, self.grid.DefaultRowHeight), uplant.kDontConsiderDomainScale, uplant.kDontDrawNow)
         if (i == 0) or (plant.drawingScale_PixelsPerMm < minScale):
             minScale = plant.drawingScale_PixelsPerMm
     # find common draw position
     widestWidth = 0
     tallestHeight = 0
     for i in range(0, self.plants.Count):
         plant = uplant.PdPlant(self.plants.Items[i])
         plant.fixedPreviewScale = true
         plant.drawingScale_PixelsPerMm = minScale
         plant.fixedDrawPosition = false
         plant.drawPreviewIntoCache(Point(self.grid.DefaultColWidth, self.grid.DefaultRowHeight), uplant.kDontConsiderDomainScale, uplant.kDontDrawNow)
         if (i == 0) or (usupport.rWidth(plant.boundsRect_pixels()) > widestWidth):
             widestWidth = usupport.rWidth(plant.boundsRect_pixels())
             bestPosition.X = plant.drawPositionIfFixed.X
         if (i == 0) or (usupport.rHeight(plant.boundsRect_pixels()) > tallestHeight):
             tallestHeight = usupport.rHeight(plant.boundsRect_pixels())
             bestPosition.Y = plant.drawPositionIfFixed.Y
     for i in range(0, self.plants.Count):
         # set draw position to use when repaint - don't draw now
         plant = uplant.PdPlant(self.plants.Items[i])
         plant.fixedPreviewScale = true
         plant.drawingScale_PixelsPerMm = minScale
         plant.fixedDrawPosition = true
         plant.drawPositionIfFixed = bestPosition
         plant.previewCacheUpToDate = false
Пример #8
0
 def zeroAllBoundsRectsToForceRedraw(self):
     i = 0
     plant = PdPlant()
     
     if self.plants.Count > 0:
         for i in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[i])
             plant.setBoundsRect_pixels(Rect(0, 0, 0, 0))
Пример #9
0
 def loadPlantObjectsIntoTStrings(self, stringList):
     i = 0
     plant = PdPlant()
     
     if self.plants.Count > 0:
         for i in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[i])
             stringList.AddObject(plant.getName(), plant)
Пример #10
0
 def updateForNewNumberOfStages(self):
     i = 0
     firstPlant = PdPlant()
     keepPlant = PdPlant()
     
     keepPlant = None
     try:
         if self.plants.Count > 0:
             firstPlant = uplant.PdPlant(self.plants.Items[0])
             if firstPlant != None:
                 keepPlant = uplant.PdPlant().create()
                 firstPlant.copyTo(keepPlant)
                 self.plants.clear()
         if keepPlant != None:
             self.initializeWithPlant(keepPlant, umain.kDontDrawYet)
     finally:
         keepPlant.free
     self.redrawPlants()
Пример #11
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
Пример #12
0
 def visiblePlantCount(self):
     result = 0
     i = 0
     
     result = 0
     if self.plants.Count > 0:
         for i in range(0, self.plants.Count):
             if not uplant.PdPlant(self.plants.Items[i]).hidden:
                 result += 1
     return result
Пример #13
0
 def copyFromPlant(self, plant):
     result = PdPlant()
     newPlant = PdPlant()
     
     if plant == None:
         raise GeneralException.create("Problem: Nil plant in method PdPlantManager.copyFromPlant.")
     newPlant = uplant.PdPlant().create()
     plant.copyTo(newPlant)
     self.plants.Add(newPlant)
     result = newPlant
     return result
Пример #14
0
 def pasteFirstPlantFromPrivatePlantClipboardToPlant(self, newPlant):
     plant = PdPlant()
     
     if newPlant == None:
         # this is used by the breeder and grower windows 
         # caller creates newPlant first 
         return
     if self.privatePlantClipboard.Count > 0:
         # caller takes responsibility of freeing plants 
         plant = uplant.PdPlant(self.privatePlantClipboard.Items[0])
         plant.copyTo(newPlant)
Пример #15
0
 def plantForIndex(self, index):
     result = PdPlant()
     result = None
     if index < 0:
         return result
     if index > self.plants.Count - 1:
         return result
     if self.plants.Items[index] == None:
         return result
     result = uplant.PdPlant(self.plants.Items[index])
     return result
Пример #16
0
 def TimeSeriesMenuPasteClick(self, Sender):
     newPlant = PdPlant()
     newCommand = PdCommand()
     
     if udomain.domain.plantManager.privatePlantClipboard.Count <= 0:
         return
     newPlant = uplant.PdPlant().create()
     try:
         udomain.domain.plantManager.pasteFirstPlantFromPrivatePlantClipboardToPlant(newPlant)
         newCommand = updcom.PdMakeTimeSeriesCommand().createWithNewPlant(newPlant)
         (newCommand as updcom.PdMakeTimeSeriesCommand).isPaste = true
         umain.MainForm.doCommand(newCommand)
     finally:
         #command makes copies from plant, but we must free it
         newPlant.free
Пример #17
0
 def redrawPlants(self, considerIfPreviewCacheIsUpToDate):
     generation = PdGeneration()
     plant = PdPlant()
     genCount = 0
     plCount = 0
     
     if not considerIfPreviewCacheIsUpToDate:
         for genCount in range(0, self.generations.Count):
             generation = ugener.PdGeneration(self.generations.Items[genCount])
             if generation.plants.Count > 0:
                 for plCount in range(0, generation.plants.Count):
                     plant = uplant.PdPlant(generation.plants.Items[plCount])
                     plant.previewCacheUpToDate = false
     self.plantsDrawGrid.Invalidate()
     self.plantsDrawGrid.Update()
Пример #18
0
 def findPlantAtPoint(self, aPoint):
     result = PdPlant()
     plant = PdPlant()
     i = 0
     
     result = None
     if self.plants.Count > 0:
         for i in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[i])
             if plant.hidden:
                 continue
             if plant.includesPoint(aPoint):
                 result = plant
                 return result
     return result
Пример #19
0
    def createWithParents(self, parentOne, parentTwo, fractionOfMaxAge):
        newPlant = PdPlant()

        # note: this is only used right now in the PdBreedFromParentsCommand command, so some things might not
        #    fit other situations. if you need to use it somewhere else, check that you want to do everything that
        #    is done here.
        self.create()
        if parentOne != None:
            newPlant = uplant.PdPlant().create()
            if newPlant == None:
                return self
            parentOne.copyTo(newPlant)
            # v2.0
            newPlant.removeAllAmendments()
            newPlant.setAge(
                intround(newPlant.pGeneral.ageAtMaturity * fractionOfMaxAge))
            self.plants.Add(newPlant)
            self.firstParent = newPlant
            if self.plants.IndexOf(parentOne) >= 0:
                # only select parent if this is being done from the breeder and you have the parents already
                self.selectedPlants.Add(self.firstParent)
        if parentTwo != None:
            newPlant = uplant.PdPlant().create()
            if newPlant == None:
                return self
            parentTwo.copyTo(newPlant)
            # v2.0
            newPlant.removeAllAmendments()
            newPlant.setAge(
                intround(newPlant.pGeneral.ageAtMaturity * fractionOfMaxAge))
            self.plants.Add(newPlant)
            self.secondParent = newPlant
            if self.plants.IndexOf(parentTwo) >= 0:
                # only select parent if this is being done from the breeder and you have the parents already
                self.selectedPlants.Add(self.secondParent)
        return self
Пример #20
0
 def updateForChangeToDomainOptions(self):
     generation = PdGeneration()
     plant = PdPlant()
     genCount = 0
     plCount = 0
     newAge = 0
     atLeastOnePlantHasChangedAge = false
     
     if self.plantsDrawGrid.ColCount != udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration + 1:
         self.plantsDrawGrid.ColCount = udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration + 1
     if ((self.plantsDrawGrid.DefaultColWidth != udomain.domain.breedingAndTimeSeriesOptions.thumbnailWidth) or (self.plantsDrawGrid.DefaultRowHeight != udomain.domain.breedingAndTimeSeriesOptions.thumbnailHeight)):
         self.plantsDrawGrid.DefaultColWidth = udomain.domain.breedingAndTimeSeriesOptions.thumbnailWidth
         self.plantsDrawGrid.ColWidths[0] = kFirstColumnWidth
         self.plantsDrawGrid.DefaultRowHeight = udomain.domain.breedingAndTimeSeriesOptions.thumbnailHeight
         self.redrawPlants(kDontConsiderIfPreviewCacheIsUpToDate)
     if udomain.domain.breedingAndTimeSeriesOptions.variationType == udomain.kBreederVariationLow:
         self.BreederMenuVariationLow.checked = true
         self.variationLow.Down = true
     elif udomain.domain.breedingAndTimeSeriesOptions.variationType == udomain.kBreederVariationMedium:
         self.BreederMenuVariationMedium.checked = true
         self.variationMedium.Down = true
     elif udomain.domain.breedingAndTimeSeriesOptions.variationType == udomain.kBreederVariationHigh:
         self.BreederMenuVariationHigh.checked = true
         self.variationHigh.Down = true
     elif udomain.domain.breedingAndTimeSeriesOptions.variationType == udomain.kBreederVariationCustom:
         self.BreederMenuVariationCustom.checked = true
         self.variationCustom.Down = true
     elif udomain.domain.breedingAndTimeSeriesOptions.variationType == udomain.kBreederVariationNoNumeric:
         self.BreederMenuVariationNone.checked = true
         self.variationNoneNumeric.Down = true
     self.BreederMenuVaryColors.checked = udomain.domain.breedingAndTimeSeriesOptions.mutateAndBlendColorValues
     self.varyColors.Down = udomain.domain.breedingAndTimeSeriesOptions.mutateAndBlendColorValues
     self.BreederMenuVary3DObjects.checked = udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary
     self.vary3DObjects.Down = udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary
     self.redoCaption()
     atLeastOnePlantHasChangedAge = false
     if self.generations.Count > 0:
         for genCount in range(0, self.generations.Count):
             generation = ugener.PdGeneration(self.generations.Items[genCount])
             if generation.plants.Count > 0:
                 for plCount in range(0, generation.plants.Count):
                     plant = uplant.PdPlant(generation.plants.Items[plCount])
                     newAge = intround(udomain.domain.breedingAndTimeSeriesOptions.percentMaxAge / 100.0 * plant.pGeneral.ageAtMaturity)
                     if plant.age != newAge:
                         plant.setAge(newAge)
                         atLeastOnePlantHasChangedAge = true
     if atLeastOnePlantHasChangedAge:
         self.redrawPlants(kDontConsiderIfPreviewCacheIsUpToDate)
Пример #21
0
    def fillPlantPartColors(self):
        i = 0
        firstPlant = PdPlant()

        self.colorsByPlantPart.Clear()
        if (udomain.domain
                == None) or (udomain.domain.plantManager == None) or (
                    udomain.domain.plantManager.plants.Count < 0):
            # use first plant to get DXF part type names - there must be at least one plant to bring up this form
            return
        firstPlant = uplant.PdPlant(udomain.domain.plantManager.plants[0])
        if firstPlant == None:
            return
        for i in range(0, u3dexport.kExportPartLast + 1):
            self.colorsByPlantPart.Items.Add(
                u3dexport.longNameForDXFPartType(i))
Пример #22
0
 def updateForChangeToPlant(self, aPlant):
     genCount = 0
     plCount = 0
     generation = PdGeneration()
     plant = PdPlant()
     cellRectOver = TRect()
     
     for genCount in range(0, self.generations.Count):
         generation = ugener.PdGeneration(self.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 == aPlant:
                     cellRectOver = self.plantsDrawGrid.CellRect(plCount + 1, genCount)
                     self.plantsDrawGridDrawCell(self, plCount + 1, genCount, cellRectOver, [UNRESOLVED.gdFocused, UNRESOLVED.gdSelected, ])
                     return
Пример #23
0
 def findFirstPlantWithBoundsRectAtPoint(self, aPoint):
     result = PdPlant()
     plant = PdPlant()
     plantIndex = 0
     
     result = None
     if self.plants.Count > 0:
         for plantIndex in range(self.plants.Count - 1, 0 + 1):
             # go through list backwards because list order is drawing order is from front to back
             plant = uplant.PdPlant(self.plants.Items[plantIndex])
             if plant.hidden:
                 continue
             if plant.pointInBoundsRect(aPoint):
                 result = plant
                 return result
     return result
Пример #24
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
Пример #25
0
 def combinedPlantBoundsRects(self, selectedPlants, excludeInvisiblePlants, excludeNonSelectedPlants):
     result = TRect()
     plant = PdPlant()
     plantIndex = 0
     includePlant = false
     
     result = delphi_compatability.Bounds(0, 0, 0, 0)
     if self.plants.Count > 0:
         for plantIndex in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[plantIndex])
             includePlant = true
             if excludeInvisiblePlants:
                 includePlant = includePlant and not plant.hidden
             if excludeNonSelectedPlants:
                 includePlant = includePlant and (selectedPlants.IndexOf(plant) >= 0)
             if includePlant:
                 delphi_compatability.UnionRect(result, result, plant.boundsRect_pixels())
     return result
Пример #26
0
 def gridEndDrag(self, Sender, Target, X, Y):
     plant = PdPlant()
     newCommand = PdCommand()
     newPlants = TList()
     newPlant = PdPlant()
     
     if delphi_compatability.Application.terminated:
         return
     if Target == None:
         return
     # get plant being dragged 
     plant = self.plantAtMouse(self.dragPlantStartPoint.X, self.dragPlantStartPoint.Y)
     if plant == None:
         return
     if Target == ubreedr.BreederForm.plantsDrawGrid:
         ubreedr.BreederForm.copyPlantToPoint(plant, X, Y)
     elif (Target == umain.MainForm.drawingPaintBox) or (Target == umain.MainForm.plantListDrawGrid):
         # make paste command - wants list of plants 
         newPlant = uplant.PdPlant().create()
         plant.copyTo(newPlant)
         self.numTimeSeriesPlantsCopiedThisSession += 1
         newPlant.setName("Time series plant " + IntToStr(self.numTimeSeriesPlantsCopiedThisSession))
         if Target == umain.MainForm.drawingPaintBox:
             newPlant.moveTo(Point(X, Y))
         else:
             newPlant.moveTo(umain.MainForm.standardPastePosition())
         if not udomain.domain.viewPlantsInMainWindowOnePlantAtATime():
             # v2.1
             newPlant.calculateDrawingScaleToLookTheSameWithDomainScale()
         #to save memory - don't need it in main window
         newPlant.shrinkPreviewCache()
         newPlants = delphi_compatability.TList().Create()
         newPlants.Add(newPlant)
         newCommand = updcom.PdPasteCommand().createWithListOfPlantsAndOldSelectedList(newPlants, umain.MainForm.selectedPlants)
         updcom.PdPasteCommand(newCommand).useSpecialPastePosition = true
         try:
             #command will free plant if paste is undone
             ucursor.cursor_startWait()
             umain.MainForm.doCommand(newCommand)
         finally:
             #command has another list, so we must free this one
             newPlants.free
             ucursor.cursor_stopWait()
Пример #27
0
 def BreederMenuPasteClick(self, Sender):
     generation = PdGeneration()
     plant = PdPlant()
     newPlant = PdPlant()
     newCommand = PdCommand()
     column = 0
     
     if udomain.domain.plantManager.privatePlantClipboard.Count <= 0:
         return
     generation = self.selectedGeneration()
     if generation == None:
         return
     plant = generation.firstSelectedPlant()
     if plant == None:
         return
     column = generation.plants.IndexOf(plant) + 1
     newPlant = uplant.PdPlant().create()
     udomain.domain.plantManager.pasteFirstPlantFromPrivatePlantClipboardToPlant(newPlant)
     newCommand = updcom.PdReplaceBreederPlant().createWithPlantRowAndColumn(newPlant, self.selectedRow, column)
     umain.MainForm.doCommand(newCommand)
Пример #28
0
 def fillListWithPlantsInRectangle(self, aRect, aList):
     plantIndex = 0
     plant = PdPlant()
     intersection = TRect()
     intersectResult = longbool()
     includePlant = false
     
     if aList == None:
         raise GeneralException.create("Problem: Nil list in method PdPlantManager.fillListWithPlantsInRectangle.")
     if delphi_compatability.Application.terminated:
         return
     if self.plants.Count > 0:
         for plantIndex in range(0, self.plants.Count):
             plant = uplant.PdPlant(self.plants.Items[plantIndex])
             includePlant = false
             intersectResult = delphi_compatability.IntersectRect(intersection, plant.boundsRect_pixels(), aRect)
             includePlant = includePlant or intersectResult
             includePlant = includePlant and not plant.hidden
             if includePlant:
                 aList.Add(plant)
Пример #29
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)
Пример #30
0
 def drawOnInvalidRect(self, destCanvas, selectedPlants, invalidRect, excludeInvisiblePlants, excludeNonSelectedPlants):
     plantIndex = 0
     plant = PdPlant()
     intersection = TRect()
     plantRect = TRect()
     intersectResult = longbool()
     includePlant = false
     partsDrawn = 0L
     
     if delphi_compatability.Application.terminated:
         return
     partsDrawn = 0
     if self.plants.Count > 0:
         for plantIndex in range(self.plants.Count - 1, 0 + 1):
             # go through list backwards because list order is drawing order is from front to back
             plant = uplant.PdPlant(self.plants.Items[plantIndex])
             includePlant = false
             plantRect = plant.boundsRect_pixels()
             if (plantRect.Left == 0) and (plantRect.Right == 0) and (plantRect.Top == 0) and (plantRect.Bottom == 0):
                 # if plant has just been read in, recalculate bounds rect by drawing it 
                 includePlant = true
             intersectResult = delphi_compatability.IntersectRect(intersection, plantRect, invalidRect)
             includePlant = includePlant or intersectResult
             if excludeInvisiblePlants:
                 includePlant = includePlant and not plant.hidden
             if excludeNonSelectedPlants:
                 includePlant = includePlant and (selectedPlants.IndexOf(plant) >= 0)
             if includePlant:
                 plant.plantPartsDrawnAtStart = partsDrawn
                 try:
                     plant.computeBounds = true
                     if (udomain.domain.options.cachePlantBitmaps) and (not udomain.domain.drawingToMakeCopyBitmap):
                         destCanvas.Draw(plantRect.Left, plantRect.Top, plant.previewCache)
                     else:
                         plant.drawOn(destCanvas)
                 finally:
                     plant.computeBounds = false
                 partsDrawn = partsDrawn + plant.totalPlantParts