Exemplo n.º 1
0
    def __init__(self):

        BE_Object.__init__(self)
        self._type = self.CANVASOBJECT_CITYEVOLUTION
        self.timeRange = [0, 0]
        self.baseSegment = Geometry.Segment2D()
        self.arrow = Geometry.Segment2D()
        self.housesPerYear = 1
        self.groupID = 0
        self.__colorDB = wx.ColourDatabase()
Exemplo n.º 2
0
    def Draw(self, dc):

        if (self._status == self.STATUS_FINISHED):
            return
        if (self._status == self.STATUS_NOTSTARTED):
            return

        canvas = self.GetCanvas()
        lastpen = dc.GetPen()

        if (self._status == self.STATUS_STARTED):

            if (self._prevMousePos and self._curMousePos):

                dc.SetPen(wx.Pen(wx.Colour(0, 0, 0, wx.ALPHA_OPAQUE), 2))

                dc.SetLogicalFunction(wx.INVERT)

                start = canvas.UserToScreenCoord(self.__startPos.x,
                                                 self.__startPos.y)
                prev = canvas.UserToScreenCoord(self._prevMousePos.x,
                                                self._prevMousePos.y)
                curr = canvas.UserToScreenCoord(self._curMousePos.x,
                                                self._curMousePos.y)

                dc.DrawLine(start.x, start.y, prev.x, prev.y)

                if (self.__XORflag):
                    seg = Geometry.Segment2D(self.__startPos,
                                             self._prevMousePos)
                    arrow = seg.GetArrow(atEnd=True, size=30, arrowangle=20)
                    plist = []
                    for p in arrow:
                        parrow = canvas.UserToScreenCoord(p.x, p.y)
                        plist.append([parrow.x, parrow.y])
                    dc.DrawPolygon(plist)

                self.__XORflag = True

                dc.DrawLine(start.x, start.y, curr.x, curr.y)

                seg = Geometry.Segment2D(self.__startPos, self._curMousePos)
                arrow = seg.GetArrow(atEnd=True, size=30, arrowangle=20)
                plist = []
                for p in arrow:
                    parrow = canvas.UserToScreenCoord(p.x, p.y)
                    plist.append([parrow.x, parrow.y])
                dc.DrawPolygon(plist)

        dc.SetPen(lastpen)
Exemplo n.º 3
0
    def __init__(self, mainwindow):

        BE_HandlerCanvas.__init__(self, mainwindow)

        self.__extraStatus = self.STATUS_EXT_NONE

        self.__baseSegment = Geometry.Segment2D()
        self.__arrowEndPoint = Geometry.Point2D()

        self.__XORflag = False  # internal flag to control the draw xor issues for the first arrow drawing time
Exemplo n.º 4
0
    def Draw(self, dc, document, canvas):

        battle = document.GetGameData().battles.GetBattle(self.year)
        if (not battle):
            return
        if (not battle.color):
            return

        lastpen = dc.GetPen()
        lastbrush = dc.GetBrush()
        dc.SetPen(wx.Pen(battle.color, 1))
        dc.SetBrush(wx.Brush(battle.color, wx.BDIAGONAL_HATCH))

        plist = []
        axis = Geometry.Segment2D(self.origin, self.target)
        length = axis.GetLength()
        direction = axis.GetDirection()
        normal = axis.GetNormal()

        arrowwidth = 20
        arrowcapheight = 50
        arrowcapwidth = 50

        p = self.origin.Copy()
        p.Move(normal, arrowwidth / 2.0)
        plist.append([p.x, p.y])
        p.Move(direction, length - arrowcapheight)
        plist.append([p.x, p.y])
        p.Move(normal, (arrowcapwidth / 2.0) - (arrowwidth / 2.0))
        plist.append([p.x, p.y])
        plist.append([self.target.x, self.target.y])
        p.Move(normal, -arrowcapwidth)
        plist.append([p.x, p.y])
        p.Move(normal, (arrowcapwidth / 2.0) - (arrowwidth / 2.0))
        plist.append([p.x, p.y])
        p = self.origin.Copy()
        p.Move(normal, -arrowwidth / 2.0)
        plist.append([p.x, p.y])

        plistcanvas = []
        for pl in plist:
            pc = canvas.UserToScreenCoord(pl[0], pl[1])
            plistcanvas.append([pc.x, pc.y])

        dc.DrawPolygon(plistcanvas)

        dc.SetBrush(lastbrush)
        dc.SetPen(lastpen)
Exemplo n.º 5
0
    def Select(self, point):
        # Since river is a nonclosed polyline, we need to check the selection over each polyline segment

        i = 1
        while (i < len(self.__polyline)):
            seg = Geometry.Segment2D(self.__polyline[i - 1],
                                     self.__polyline[i])
            poly = seg.GetBounding(self.__width / 2.0)
            bbox = Geometry.BoundingQuad()
            for p in poly.shape:
                bbox.InsertPoint(p.p1)
            if (len(poly.shape) > 0):
                bbox.InsertPoint(poly.shape[-1].p2)
            if (bbox.IsInside(point)):
                return True

            i += 1

        return False
Exemplo n.º 6
0
    def ExportXML(self, root, document):

        main = ET.SubElement(root, "BattleEvents")

        for k, v in self.__battles.items():

            battlexml = ET.SubElement(main, "Battle")

            ET.SubElement(battlexml, "Year").text = str(v.year)
            ET.SubElement(battlexml, "Simulations").text = str(v.nSimulations)
            ET.SubElement(battlexml,
                          "RepeatUntilDefendersWin").text = str(v.repeatUntil)

            defendersxml = ET.SubElement(battlexml, "Defenders")
            if (v.defenders['Archers'] > 0):
                ET.SubElement(defendersxml,
                              "Archers").text = str(v.defenders['Archers'])
            if (v.defenders['Cannons'] > 0):
                ET.SubElement(defendersxml,
                              "Cannons").text = str(v.defenders['Cannons'])

            flanks = self.GetBattleFlanks(v.year, document)
            if (len(flanks) > 0):
                attackersxml = ET.SubElement(battlexml, "Attackers")

                for f in flanks:
                    flankxml = ET.SubElement(attackersxml, "Flank")

                    if (f.standDistance):
                        ET.SubElement(flankxml, "StandDistance").text = str(
                            f.standDistance)
                    ET.SubElement(flankxml, "Origin").text = "[" + str(
                        f.origin.x) + "," + str(f.origin.y) + "]"

                    seg = Geometry.Segment2D(f.origin, f.target)
                    dir = seg.GetDirection()
                    ET.SubElement(flankxml, "Direction").text = "[" + str(
                        dir.val[0]) + "," + str(dir.val[1]) + "]"

                    # This is an extra field that only will be used by the Editor. It justs stores the user arrow length defined to reconstruct it on ImportXML function
                    # It does not change anything in the simulation, and is used only for visual purposes
                    arrowlength = ET.SubElement(flankxml,
                                                "BE_Editor_ArrowLength")
                    arrowlength.text = str(seg.GetLength())

                    battalionsxml = ET.SubElement(flankxml, "Battalions")
                    for bk, bv in f.battalions.items():
                        if (bv['Number'] and (bv['Number'] > 0)):
                            bxml = ET.SubElement(battalionsxml, "Battalion")
                            ET.SubElement(bxml, "Type").text = str(bk)
                            ET.SubElement(bxml,
                                          "Number").text = str(bv['Number'])
                            if (bv['BattalionSize']):
                                ET.SubElement(bxml,
                                              "BattalionSize").text = str(
                                                  bv['BattalionSize'])
                            if (bv['GroupSize']):
                                ET.SubElement(bxml, "GroupSize").text = str(
                                    bv['GroupSize'])
                            if (bv['GroupDistance']):
                                ET.SubElement(bxml,
                                              "GroupDistance").text = str(
                                                  bv['GroupDistance'])
Exemplo n.º 7
0
    def Draw(self, dc):

        if (self._status == self.STATUS_FINISHED):
            return
        if (self._status == self.STATUS_NOTSTARTED):
            return

        canvas = self.GetCanvas()
        lastpen = dc.GetPen()

        if ((self._status == self.STATUS_STARTED)
                and (self.__extraStatus == self.STATUS_EXT_BASESEGMENT)):

            dc.SetPen(wx.Pen(wx.Colour(0, 0, 0, wx.ALPHA_OPAQUE), 2))
            dc.SetLogicalFunction(wx.INVERT)

            base1 = canvas.UserToScreenCoord(self.__baseSegment.p1.x,
                                             self.__baseSegment.p1.y)
            prev = canvas.UserToScreenCoord(self._prevMousePos.x,
                                            self._prevMousePos.y)
            curr = canvas.UserToScreenCoord(self._curMousePos.x,
                                            self._curMousePos.y)
            dc.DrawLine(base1.x, base1.y, prev.x, prev.y)
            dc.DrawLine(base1.x, base1.y, curr.x, curr.y)

        elif ((self._status == self.STATUS_STARTED)
              and (self.__extraStatus == self.STATUS_EXT_ARROW)):

            if (self._prevMousePos and self._curMousePos):
                dc.SetPen(wx.Pen(wx.Colour(0, 0, 0, wx.ALPHA_OPAQUE), 2))

                base1 = canvas.UserToScreenCoord(self.__baseSegment.p1.x,
                                                 self.__baseSegment.p1.y)
                base2 = canvas.UserToScreenCoord(self.__baseSegment.p2.x,
                                                 self.__baseSegment.p2.y)
                dc.DrawLine(base1.x, base1.y, base2.x, base2.y)

                mid = self.__baseSegment.GetMidPoint()

                dc.SetPen(wx.Pen(wx.Colour(0, 0, 0, wx.ALPHA_OPAQUE), 2))
                dc.SetLogicalFunction(wx.INVERT)

                pmid = canvas.UserToScreenCoord(mid.x, mid.y)
                prev = canvas.UserToScreenCoord(self._prevMousePos.x,
                                                self._prevMousePos.y)
                dc.DrawLine(pmid.x, pmid.y, prev.x, prev.y)

                # Draw the arrow

                if (self.__XORflag):
                    seg = Geometry.Segment2D(mid, self._prevMousePos)
                    arrow = seg.GetArrow(atEnd=True, size=30, arrowangle=20)
                    plist = []
                    for p in arrow:
                        parrow = canvas.UserToScreenCoord(p.x, p.y)
                        plist.append([parrow.x, parrow.y])
                    dc.DrawPolygon(plist)

                self.__XORflag = True

                curr = canvas.UserToScreenCoord(self._curMousePos.x,
                                                self._curMousePos.y)
                dc.DrawLine(pmid.x, pmid.y, curr.x, curr.y)

                seg = Geometry.Segment2D(mid, self._curMousePos)
                arrow = seg.GetArrow(atEnd=True, size=30, arrowangle=20)
                plist = []
                for p in arrow:
                    parrow = canvas.UserToScreenCoord(p.x, p.y)
                    plist.append([parrow.x, parrow.y])
                dc.DrawPolygon(plist)

        dc.SetPen(lastpen)
Exemplo n.º 8
0
    def Click(self, x, y):

        if (self._status == self.STATUS_NOTSTARTED):

            self.__baseSegment.p1 = self.GetCanvas().ScreenToUserCoord(x, y)

            self._status = self.STATUS_STARTED
            self.__extraStatus = self.STATUS_EXT_BASESEGMENT
            self._mainWindow.Refresh()
            self._mainWindow.SetCanvasCursor(wx.StockCursor(wx.CURSOR_CROSS))

        elif ((self._status == self.STATUS_STARTED)
              and (self.__extraStatus == self.STATUS_EXT_BASESEGMENT)):

            self.__baseSegment.p2 = self.GetCanvas().ScreenToUserCoord(x, y)

            self.__extraStatus = self.STATUS_EXT_ARROW
            self._mainWindow.Refresh()
            self._mainWindow.SetCanvasCursor(wx.StockCursor(wx.CURSOR_CROSS))

        elif ((self._status == self.STATUS_STARTED)
              and (self.__extraStatus == self.STATUS_EXT_ARROW)):

            self.__arrowEndPoint = self.GetCanvas().ScreenToUserCoord(x, y)

            dlg = BE_Dialogs.BE_CityEvolutionDlg.BE_CityEvolutionDlg(
                self._mainWindow)

            defdata = self._mainWindow.GetDocument().GetDefaultSettings()
            gamedata = self._mainWindow.GetDocument().GetGameData()
            dlg.textHousesYear.SetValue(str(
                defdata.city.housesCreationPerYear))
            dlg.textTimeRangeStart.SetValue(
                str((gamedata.timeRange[0] - 1) * 100))
            dlg.textTimeRangeEnd.SetValue(
                str((gamedata.timeRange[1] - 1) * 100))
            dlg.textGroupID.SetValue("0")

            if (dlg.ShowModal() == wx.ID_OK):

                self._receiver = BE_Objects.BE_CityEvolution()
                self._receiver.baseSegment = self.__baseSegment.Copy()
                self._receiver.arrow = Geometry.Segment2D(
                    self.__baseSegment.GetMidPoint(), self.__arrowEndPoint)

                try:
                    self._receiver.timeRange[0] = int(
                        dlg.textTimeRangeStart.GetValue())
                    self._receiver.timeRange[1] = int(
                        dlg.textTimeRangeEnd.GetValue())
                except:
                    pass

                try:
                    self._receiver.housesPerYear = float(
                        dlg.textHousesYear.GetValue())
                except:
                    pass

                try:
                    self._receiver.groupID = int(dlg.textGroupID.GetValue())
                except:
                    pass

                self.Finish()

            else:
                self.Cancel()

            dlg.Destroy()

            self.__extraStatus = self.STATUS_EXT_NONE