Exemple #1
0
    def testTrackViewer_IsSelectionPossible(self):
        t1 = Track(p1=Vec3("0", "0", "0"), p2=Vec3("0", "20", "0"))
        bounds = EditorBounds()
        bounds.scale = Scale(1.0)
        bounds.minX = -1000.0
        bounds.maxX = 1000.0
        bounds.minY = -1000.0
        bounds.maxY = 1000.0

        tv = TrackViewer(t1)
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1100, 1100)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1100, 1090)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1100, 1080)))

        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1100, 1075)))
        self.assertFalse(tv.IsSelectionPossible(bounds, wx.Point(1100, 1074)))

        self.assertFalse(tv.IsSelectionPossible(bounds, wx.Point(1100, 1005)))

        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1096, 1080)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1104, 1080)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1096, 1100)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1104, 1100)))

        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1096, 1090)))
        self.assertTrue(tv.IsSelectionPossible(bounds, wx.Point(1104, 1090)))
Exemple #2
0
    def __init__(self, p1=Vec3(), v1=Vec3(), v2=Vec3(), p2=Vec3()):
        """
        Constructor
        """
        self.p1 = p1
        self.v1 = v1
        self.v2 = v2
        self.p2 = p2
        
        self.n1 = None
        self.n2 = None

        self.name = None
Exemple #3
0
def exportScenery(path, tracks, switches, callback):
    sectors = dict()

    __sortTrackings(sectors, tracks, 'tracks')
    __sortTrackings(sectors, switches, 'switches')

    progress = 0
    percent = 0
    callback(percent)

    for sector in sectors.itervalues():
        sector_name = "%+05d%+05d.sct" % sector.position
        with file(os.path.abspath(os.path.join(path, sector_name)),
                  "wb") as fout:
            position = Vec3(
                Decimal(sector.position[0]) * DEC_SECTOR_SIZE,
                Decimal(sector.position[1]) * DEC_SECTOR_SIZE, Decimal("0.0"))
            writeSector(fout, position, sector.tracks, sector.switches)

        progress += 1
        newPercent = (progress * 100) / len(sectors)
        if (newPercent > percent):
            percent = newPercent
            callback(percent)

    with file(os.path.join(path, "default.scv"), "wb") as fout:
        writeVariant(fout, 0, sectors.values())
Exemple #4
0
    def __init__(self, parent, main_window, id=wx.ID_ANY):
        wx.Panel.__init__(self, parent, id, style=wx.BORDER_SUNKEN)

        sizer = wx.FlexGridSizer(2, 2, 1, 1)

        corner = wx.Panel(self, name="Corner")
        corner.SetBackgroundColour('WHITE')
        self.leftRuler = Ruler(self,
                               orientation=wx.VERTICAL,
                               name="Left ruler")
        self.topRuler = Ruler(self,
                              orientation=wx.HORIZONTAL,
                              name="Top ruler")
        self.parts = [PlanePart(self, main_window)]

        self.scenery = None
        self.sceneryListener = SceneryListener(self)
        self.selection = None

        sizer.Add(corner)
        sizer.Add(self.topRuler, 0, flag=wx.EXPAND)
        sizer.Add(self.leftRuler, 0, flag=wx.EXPAND)
        sizer.Add(self.parts[0], 1, wx.EXPAND)
        sizer.AddGrowableCol(1, 1)
        sizer.AddGrowableRow(1, 1)

        self.SetSizer(sizer)

        self.SetBasePoint(BasePoint(Vec3(), 0.0, 0.0))
Exemple #5
0
    def CreateCurve(self, length, radius, isLeft):
        """
        Creates curve track
        """
        angle = length / radius
        half = 0.5 * angle
        sin_a = sin(half)
        cos_a = cos(half)

        p1 = Vec3()
        p2 = Vec3()
        v1 = Vec3()
        v2 = Vec3()

        p1.x = Decimal(-radius * cos_a)
        p1.y = Decimal(radius * sin_a)
        p2.x = Decimal(-radius * cos_a)
        p2.y = Decimal(-radius * sin_a)

        ctrlX = -radius * (4.0 - cos_a) / 3.0
        ctrlY = -radius * (1.0 - cos_a) * (cos_a - 3.0) / (3.0 * sin_a)

        v1.x = Decimal(ctrlX) - p1.x
        v1.y = Decimal(ctrlY) - p1.y
        v2.x = Decimal(ctrlX) - p2.x
        v2.y = Decimal(-ctrlY) - p2.y

        # Left or right
        tr = LeftTrackTransform(length, radius) if isLeft \
            else RightTrackTransform(length, radius)
        tr.Transform([p1, p2], [v1, v2])

        basePoint = self.editor.basePoint

        tr = BasePointTransform(basePoint)
        tr.Transform([p1, p2], [v1, v2])

        basePoint.point = Vec3(p2.x, p2.y, p2.z)
        if isLeft:
            basePoint.alpha -= degrees(angle)
        else:
            basePoint.alpha += degrees(angle)

        # Refresh editor
        self.editor.SetBasePoint(basePoint, True)

        return Track(p1, v1, v2, p2)
Exemple #6
0
    def CreateStraight(self, length):
        p2 = Vec3("0", str(length), "0")
        p1 = Vec3()

        basePoint = self.editor.basePoint

        tr = BasePointTransform(basePoint)
        tr.Transform([p1, p2], [])

        v1 = Vec3()
        v2 = Vec3()

        basePoint.point = Vec3(p2.x, p2.y, p2.z)

        # Refresh editor
        self.editor.SetBasePoint(basePoint, True)

        return Track(p1, v1, v2, p2)
Exemple #7
0
 def getNormalVector(self, point):
     """
     Gets a normal vector for given point
     """
     if point == self.p1:
         if not self.v1.x and not self.v1.y and not self.v1.z:
             return Vec3(self.p1.x - self.p2.x, \
                     self.p1.y - self.p2.y, \
                     self.p1.z - self.p2.z)
         else:
             return Vec3(-self.v1.x, -self.v1.y, -self.v1.z)
     elif point == self.p2:
         if not self.v2.x and not self.v2.y and not self.v2.z:
             return Vec3(self.p2.x - self.p1.x, \
                     self.p2.y - self.p1.y, \
                     self.p2.z - self.p1.z)
         else:
             return Vec3(-self.v2.x, -self.v2.y, -self.v2.z)
     else:
         return None
Exemple #8
0
    def testSingle(self):
        railSwitch = Switch( \
            pc = Vec3("0.0", "0.0", "0.0"), \
            p1 = Vec3("0.0", "33.23", "0.0"), \
            p2 = Vec3("-1.837", "33.162", "0.0"), \
            vc1 = Vec3("0.0", "0.0", "0.0"), \
            v1 = Vec3("0.0", "0.0", "0.0"), \
            vc2 = Vec3("0.0", "11.079", "0.0"), \
            v2 = Vec3("-0.776", "-6.974", "0.0"))

        group = RailGroup()

        group.insert(railSwitch)

        self.assertEquals(1, group.size())

        endpoints = group.connections.keys()
        self.assertTrue(Vec3("0", "0", "0") in endpoints)
        self.assertTrue(Vec3("0.0", "33.23", "0") in endpoints)
        self.assertTrue(Vec3("-1.837", "33.162", "0") in endpoints)
        self.assertEquals(3, len(endpoints))
Exemple #9
0
    def testGetSnapData(self):
        t1 = Track(Vec3("-10.293", "106.952", "0"),
                   Vec3("-0.565", "4.968", "0"), Vec3("0.316", "-4.99", "0"),
                   Vec3("-11.715", "121.891", "0"))
        t2 = Track(Vec3("-1.924", "33.427", "-1.000"), Vec3(), Vec3(),
                   Vec3("-10.293", "106.952", "0"))
        t1.n1 = t2
        t2.n2 = t1

        bounds = EditorBounds()
        bounds.scale = Scale(10.0)
        bounds.minX = -55000.0
        bounds.maxX = 1000.0
        bounds.minY = -5000.0
        bounds.maxY = 60000.0

        print bounds.ModelToView(Vec3("-10.293", "106.952", "0"))

        tv = TrackViewer(t1)
        sd = tv.GetSnapData(bounds, wx.Point(9, 9))

        self.assertIsNone(sd)
Exemple #10
0
    def OnButton(self, event):
        """
        Sets the scroll to the editor part.
        """
        try:
            px = Decimal(str(self.x.GetValue()))
            py = Decimal(str(self.y.GetValue()))
            pz = Decimal(str(self.z.GetValue()))
            pScale = float(self.zoom.GetValue())

            editor = self.GetParent().editor
            editor.parts[0].SetScale(ui.editor.Scale(pScale))
            (vx, vy) = editor.parts[0].ModelToView(Vec3(px, py, pz))
            editor.parts[0].CenterViewAt((vx, vy))

            self.Destroy()
        except ValueError:
            # Swallow number parsing error
            pass
Exemple #11
0
    def testEquality(self):
        t1 = Track( \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "10.423", "0"))
        t2 =  Track( \
            Vec3("0", "10.423", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-1.141", "0.082", "0"))

        group1 = RailGroup()
        group2 = RailGroup()

        group1.insert(t1)
        group1.insert(t2)
        group2.insert(t2)
        group2.insert(t1)

        self.assertTrue(group1 == group2)
Exemple #12
0
    def OnButton(self, event):
        '''
        Sets the scroll to the editor part.
        '''
        try:
            px = Decimal(self.x.GetValue())
            py = Decimal(self.y.GetValue())
            pz = Decimal(self.z.GetValue())
            alpha = float(self.alpha.GetValue())
            gradient = float(self.gradient.GetValue())

            editor = self.GetParent().editor
            editor.SetBasePoint(
                ui.editor.BasePoint(Vec3(px, py, pz), alpha, gradient), True)

            self.Destroy()
        except ValueError:
            # Swallow number parsing error
            pass
Exemple #13
0
    def PaintAuxiliaryGrid(self, dc, clip):
        """
        Paints a grid.
        """
        center2D = self.ModelToView(Vec3())

        xoffset = clip.x + clip.width
        yoffset = clip.y + clip.height

        oldPen = dc.GetPen()
        dc.SetPen(wx.Pen('#666666'))
        try:
            x = center2D[0]
            while x > clip.x:
                x = x - 100
                if (x <= xoffset):
                    dc.DrawLine(x, clip.y, x, yoffset)
            x = center2D[0]
            while x < xoffset:
                if (x >= clip.x):
                    dc.DrawLine(x, clip.y, x, yoffset)
                x = x + 100

            y = center2D[1]
            while y > clip.y:
                y = y - 100
                if (y <= yoffset):
                    dc.DrawLine(clip.x, y, xoffset, y)
            y = center2D[1]
            while y < yoffset:
                if (y >= clip.y):
                    dc.DrawLine(clip.x, y, xoffset, y)
                y = y + 100
        finally:
            dc.SetPen(oldPen)

        oldPen = dc.GetPen()
        dc.SetPen(wx.Pen('#ff0000'))
        try:
            dc.DrawPoint(center2D[0], center2D[1])
        finally:
            dc.SetPen(oldPen)
Exemple #14
0
 def ModelToView(self, point=Vec3()):
     """
     Converts 3D point of scenery coordinate into 2D point of
     UI editor coordinates.
     
     Examples:
     >>> layout = EditorBounds()
     >>> layout.ModelToView()
     (1100, 1100)
     >>> layout.scale = Scale(0.5)
     >>> layout.ModelToView()
     (600, 600)
     >>> layout.scale = Scale(2.0)
     >>> layout.ModelToView()
     (2100, 2100)
     >>> layout.ModelToView(Vec3('-4.000', '540.000', '3.000'))
     (2092, 1020)
     """
     p2d = (int((float(point.x) - float(self.minX)) * self.scale.get() +
                self.extentX),
            int((-float(point.y) + float(self.maxY)) * self.scale.get() +
                self.extentY))
     return p2d
Exemple #15
0
 def ViewToModel(self, point):
     """
     Converts 2D point of UI editor coordinates into 3D point
     of scenery coordinates.
     
     Examples:
     >>> layout = EditorBounds()
     >>> layout.ViewToModel((1100, 1100))
     (0.000,0.000,0.000)
     >>> layout.scale = Scale(SCALE_MIN)
     >>> layout.ViewToModel((1100, 1100))
     (249000.000,-249000.000,0.000)
     >>> layout.scale = Scale(SCALE_MAX)
     >>> layout.ViewToModel((1100, 1100))
     (-999.500,999.500,0.000)
     """
     p3d = Vec3(
         Decimal(
             str((point[0] - self.extentX) / self.scale.get() +
                 float(self.minX))),
         Decimal(
             str(-((point[1] - self.extentY) / self.scale.get() -
                   float(self.maxY)))), Decimal("0"))
     return p3d
Exemple #16
0
    def __init__(self, pc=Vec3(),
                       p1=Vec3(),
                       p2=Vec3(),
                       vc1=Vec3(),
                       vc2=Vec3(),
                       v1=Vec3(),
                       v2=Vec3()):
        """
        Creates a switch.
        """

        self.pc = pc
        self.p1 = p1
        self.p2 = p2
        self.vc1 = vc1
        self.vc2 = vc2
        self.v1 = v1
        self.v2 = v2

        self.nc = None
        self.n1 = None
        self.n2 = None

        self.name = None
Exemple #17
0
 def getNormalVector(self, point):
     if point == self.pc:
         if self.vc1 == VEC3_ZERO:
             return Vec3(self.pc.x - self.p1.x, \
                     self.pc.y - self.p1.y, \
                     self.pc.z - self.p1.z)
         else:
             return Vec3(-self.vc1.x, -self.vc1.y, -self.vc1.z)
     elif point == self.p1:
         if self.v1 == VEC3_ZERO:
             return Vec3(self.p1.x - self.pc.x, \
                     self.p1.y - self.pc.y, \
                     self.p2.z - self.pc.z)
         else:
             return Vec3(-self.v1.x, -self.v1.y, -self.v1.z)
     elif point == self.p2:
         if self.v2 == VEC3_ZERO:
             return Vec3(self.p2.x - self.pc.x, \
                     self.p2.y - self.pc.y, \
                     self.p2.z - self.p2.z)
         else:
             return Vec3(-self.v2.x, -self.v2.y, -self.v2.z)
     else:
         return None
Exemple #18
0
    def testInsertRemove(self):
        #track { -2.501 39.124 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -1.838 33.162 0.0 }
        t1 = Track(Vec3("-2.501", "39.124", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-1.838", "33.162", "0"))
        #track { -3.673 62.125 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -3.673 60.126 0.0 }
        t2 = Track( \
            Vec3("-3.673", "62.125", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-3.673", "60.126", "0"))
        #track { -7.976 -16.881 0.0  -0.187 16.665 0.0  0.881 -16.644 0.0  -9.58 33.09 0.0 }
        t3 = Track( \
            Vec3("-7.976", "-16.881", "0"), \
            Vec3("-0.187", "16.665", "0"), \
            Vec3("0.881", "-16.644", "0"), \
            Vec3("-9.58", "33.09", "0"))

        # switch { 0.0 0.0 0.0  0.0 0.0 0.0  0.0 0.0 0.0  0.0 33.23 0.0  0.0 0.0 0.0  0.0 11.079 0.0  1.225 -11.012 0.0  -1.838 33.162 0.0 }
        r1 = Switch( \
            pc = Vec3("0", "0", "0"), \
            p1 = Vec3("0.0", "33.23", "0"), \
            p2 = Vec3("-1.838", "33.162", "0"), \
            vc1 = Vec3("0", "0", "0"), \
            v1 = Vec3("0", "0", "0"), \
            vc2 = Vec3("0.0", "11.079", "0"), \
            v2 = Vec3("1.225", "-11.012", "0"))
        #switch { -3.673 60.126 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -3.662 32.989 0.0  -3.673 60.126 0.0  0.0020 -7.016 0.0  -0.777 6.973 0.0  -2.501 39.124 0.0 }
        r2 = Switch( \
            pc = Vec3("-3.673", "60.126", "0"), \
            p1 = Vec3("-3.662", "32.989", "0"), \
            p2 = Vec3("-2.501", "39.124", "0"), \
            vc1 = Vec3("0", "0", "0"), \
            v1 = Vec3("0", "0", "0"), \
            vc2 = Vec3("0.002", "-7.016", "0"), \
            v2 = Vec3("-0.777", "6.973", "0"))
        #switch { -7.602 -50.108 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -7.976 -16.881 0.0  -7.602 -50.108 0.0  -0.124 11.078 0.0  -1.1 -11.024 0.0  -6.138 -16.929 0.0 }
        r3 = Switch( \
            pc = Vec3("-7.602", "-50.108", "0"), \
            p1 = Vec3("-7.976", "-16.881", "0"), \
            p2 = Vec3("-6.138", "-16.929", "0"), \
            vc1 = Vec3("0", "0", "0"), \
            v1 = Vec3("0", "0", "0"), \
            vc2 = Vec3("-0.124", "11.078", "0"), \
            v2 = Vec3("-1.1", "-11.024", "0"))

        group = RailGroup()

        group.insert(t1)
        outline = group.connections.keys()
        self.assertEquals(2, len(outline))
        self.assertTrue(Vec3("-2.501", "39.124", "0") in outline)
        self.assertTrue(Vec3("-1.838", "33.162", "0") in outline)

        group.insert(r1)
        outline = group.connections.keys()
        self.assertEquals(3, len(outline))
        self.assertTrue(Vec3("-2.501", "39.124", "0") in outline)
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)

        group.insert(r2)
        outline = group.connections.keys()
        self.assertEquals(4, len(outline))
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)
        self.assertTrue(Vec3("-3.673", "60.126", "0") in outline)
        self.assertTrue(Vec3("-3.662", "32.989", "0") in outline)

        group.insert(t2)
        outline = group.connections.keys()
        self.assertEquals(4, len(outline))
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)
        self.assertTrue(Vec3("-3.662", "32.989", "0") in outline)
        self.assertTrue(Vec3("-3.673", "62.125", "0") in outline)

        group.insert(r3)
        outline = group.connections.keys()
        self.assertEquals(7, len(outline))
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)
        self.assertTrue(Vec3("-3.662", "32.989", "0") in outline)
        self.assertTrue(Vec3("-3.673", "62.125", "0") in outline)
        self.assertTrue(Vec3("-7.602", "-50.108", "0") in outline)
        self.assertTrue(Vec3("-7.976", "-16.881", "0") in outline)
        self.assertTrue(Vec3("-6.138", "-16.929", "0") in outline)

        group.insert(t3)
        outline = group.connections.keys()
        self.assertEquals(7, len(outline))
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)
        self.assertTrue(Vec3("-3.662", "32.989", "0") in outline)
        self.assertTrue(Vec3("-3.673", "62.125", "0") in outline)
        self.assertTrue(Vec3("-7.602", "-50.108", "0") in outline)
        self.assertTrue(Vec3("-6.138", "-16.929", "0") in outline)
        self.assertTrue(Vec3("-9.58", "33.09", "0") in outline)

        group.remove(t2)
        outline = group.connections.keys()
        self.assertEquals(7, len(outline))
        self.assertTrue(Vec3("0", "0", "0") in outline)
        self.assertTrue(Vec3("0", "33.23", "0") in outline)
        self.assertTrue(Vec3("-3.662", "32.989", "0") in outline)
        self.assertTrue(Vec3("-3.673", "60.126", "0") in outline)
        self.assertTrue(Vec3("-7.602", "-50.108", "0") in outline)
        self.assertTrue(Vec3("-6.138", "-16.929", "0") in outline)
        self.assertTrue(Vec3("-9.58", "33.09", "0") in outline)
Exemple #19
0
 def max(self):
     return Vec3(self.maxX, self.maxY, self.maxZ)
Exemple #20
0
    def testTrackingConnections(self):
        underTest = Switch( \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("-1.924"), Decimal("33.927"), Decimal("0.0")), \
            Vec3(Decimal("1.924"), Decimal("33.927"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("11.336"), Decimal("0.0")), \
            Vec3(Decimal("1.282"), Decimal("-11.263"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("11.336"), Decimal("0.0")), \
            Vec3(Decimal("-1.282"), Decimal("-11.263"), Decimal("0.0")))
        t1 = Track( \
            Vec3(Decimal("-1.924"), Decimal("33.427"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("-10.292"), Decimal("106.952"), Decimal("0.0")))
        t2 = Track( \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
            Vec3(Decimal("0.0"), Decimal("-74.0"), Decimal("0.0")))

        underTest.n1 = t1
        underTest.nc = t2

        self.assertEquals(Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")),
                          underTest.tracking2point(t2))
        self.assertEquals(Vec3(Decimal("1.924"), Decimal("33.927"), Decimal("0.0")), \
            underTest.tracking2point(None))
        self.assertEquals(Vec3(Decimal("-1.924"), Decimal("33.927"), Decimal("0.0")), \
            underTest.tracking2point(t1))

        self.assertEquals(None, \
            underTest.point2tracking(Vec3(Decimal("1.924"), Decimal("33.927"), Decimal("0.0"))))
        self.assertEquals(t1, \
            underTest.point2tracking(Vec3(Decimal("-1.924"), Decimal("33.927"), Decimal("0.0"))))
        self.assertEquals(t2, \
            underTest.point2tracking(Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0"))))
Exemple #21
0
    def testSingleSlip(self):
        t1 = Track( \
            Vec3("0", "20.846", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "10.423", "0"))
        t2 =  Track( \
            Vec3("0", "10.424", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-1.141", "0.082", "0"))
        a = Switch( \
            pc = Vec3("0.0", "0.0", "0.0"), \
            p1 = Vec3("0.0", "10.423", "0.0"), \
            p2 = Vec3("0.285", "10.418", "0.0"), \
            vc1 = Vec3("0.0", "0.0", "0.0"), \
            v1 = Vec3("0.0", "0.0", "0.0"), \
            vc2 = Vec3("0.0", "3.476", "0.0"), \
            v2 = Vec3("-0.19", "-3.469", "0.0"))
        b = Switch( \
            pc = Vec3("1.141", "20.803", "0"), \
            p1 = Vec3("0.0", "10.424", "0"), \
            p2 = Vec3("0.285", "10.418", "0"), \
            vc1 = Vec3("0.0", "0.0", "0.0"), \
            v1 = Vec3("0.0", "0.0", "0.0"), \
            vc2 = Vec3("0.0", "-3.476", "0"), \
            v2 = Vec3("0.19", "3.469", "0"))

        group = RailGroup()

        group.insert(t1)
        group.insert(t2)
        group.insert(a)
        group.insert(b)

        self.assertEquals(4, group.size())

        endpoints = group.connections.keys()
        self.assertTrue(Vec3("0", "0", "0") in endpoints)
        self.assertTrue(Vec3("0.0", "20.846", "0") in endpoints)
        self.assertTrue(Vec3("-1.141", "0.082", "0") in endpoints)
        self.assertTrue(Vec3("1.141", "20.803", "0") in endpoints)
        self.assertEquals(4, len(endpoints))
Exemple #22
0
    def testCrossing(self):
        v1 = Track( \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-10", "-10", "0"))
        v2 = Track( \
            Vec3("10", "10", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"))
        h1 = Track( \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("-10", "10", "0"))
        h2 =  Track( \
            Vec3("10", "-10", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"), \
            Vec3("0", "0", "0"))

        group = RailGroup()

        group.insert(v1)
        group.insert(v2)
        group.insert(h1)
        group.insert(h2)

        self.assertEquals(4, group.size())

        endpoints = group.connections.keys()
        self.assertTrue(Vec3("10", "10", "0") in endpoints)
        self.assertTrue(Vec3("10", "-10", "0") in endpoints)
        self.assertTrue(Vec3("-10", "10", "0") in endpoints)
        self.assertTrue(Vec3("-10", "-10", "0") in endpoints)
        self.assertEquals(4, len(endpoints))
Exemple #23
0
    def CopyRailTracking(self, template, startPoint):
        """
        Copies template rail tracking (single one or a group)
        into scenery.

        template = rail tracking to copy
        startPoint = Vec3 point within that template which is the insertation point.
        """

        basePoint = self.editor.basePoint

        # 1. Make a copy of template
        tCopy = copy.deepcopy(template)

        # 2. Find the startPoint within copy
        if not tCopy.containsPoint(startPoint):
            raise ValueError, "Cannot find startPoint"

        # 3. Move to specified startPoint
        nVector = tCopy.getNormalVector(startPoint)

        nextPoint = tCopy.nextPoint(startPoint)

        tPoints = tCopy.getEndPoints()
        tGeo = tCopy.getGeometry()
        tVecs = [e for e in tGeo if e not in tPoints]

        for p in tPoints:
            p.moveBy(-startPoint)

        # 4. Rotate to specified startPoint
        angle = nVector.angleToJUnit()

        cos_a = cos(-angle - pi)
        sin_a = sin(-angle - pi)

        rMatrix = [ \
             [cos_a, sin_a, 0.0],
             [-sin_a, cos_a, 0.0],
             [0.0, 0.0, 1.0]]

        for g in tGeo:
            transformVec3(rMatrix, g)

        # 5-6. Rotate then to base point vector
        bpt = BasePointTransform(basePoint)
        bpt.Transform(tPoints, tVecs)

        # 7. Set the new position and vector of base point
        basePoint.point = Vec3(nextPoint.x, nextPoint.y, nextPoint.z)

        # Rail container, if yes rebuild
        if isinstance(tCopy, model.groups.RailContainer):
            tCopy.rebuild()

        nVector = tCopy.getNormalVector(nextPoint)
        angle = nVector.angleToJUnit()

        basePoint.alpha = degrees(angle)

        self.editor.SetBasePoint(basePoint, True)

        # Return copy
        return tCopy
Exemple #24
0
    def testDoubleSlip(self):
        a = Switch( \
            pc = Vec3("0.0", "0.0", "0.0"), \
            p1 = Vec3("0.0", "10.423", "0.0"), \
            p2 = Vec3("0.285", "10.418", "0.0"), \
            vc1 = Vec3("0.0", "0.0", "0.0"), \
            v1 = Vec3("0.0", "0.0", "0.0"), \
            vc2 = Vec3("0.0", "3.476", "0.0"), \
            v2 = Vec3("-0.19", "-3.469", "0.0"))
        b = Switch( \
            pc = Vec3("0.0", "20.846", "0.0"), \
            p1 = Vec3("0.0", "10.423", "0.0"), \
            p2 = Vec3("-0.286", "10.428", "0.0"), \
            vc1 = Vec3("0.0", "0.0", "0.0"), \
            v1 = Vec3("0.0", "0.0", "0.0"), \
            vc2 = Vec3("0.0", "-3.476", "0.0"), \
            v2 = Vec3("0.19", "3.469", "0.0"))
        c = Switch( \
            pc = Vec3("-1.142", "0.042", "0.0"), \
            p1 = Vec3("-0.001", "10.442", "0.0"), \
            p2 = Vec3("-0.286", "10.428", "0.0"), \
            vc1 = Vec3("0", "0", "0"), \
            v1 = Vec3("0", "0", "0"), \
            vc2 = Vec3("0.38", "3.454", "0.0"), \
            v2 = Vec3("-0.189", "-3.468", "0.0"))
        d = Switch( \
            pc = Vec3("1.141", "20.803", "0.0"), \
            p1 = Vec3("-0.001", "10.442", "0.0"), \
            p2 = Vec3("0.285", "10.418", "0.0"),  \
            vc1 = Vec3("0", "0", "0"), \
            v1 = Vec3("0", "0", "0"), \
            vc2 = Vec3("-0.38", "-3.454", "0"), \
            v2 = Vec3("0.189", "3.468", "0.0"))

        group = RailGroup()

        group.insert(a)
        group.insert(b)
        group.insert(c)
        group.insert(d)

        self.assertEquals(4, group.size())

        endpoints = group.connections.keys()
        self.assertTrue(Vec3("0", "0", "0") in endpoints)
        self.assertTrue(Vec3("0.0", "20.846", "0.0") in endpoints)
        self.assertTrue(Vec3("-1.142", "0.042", "0.0") in endpoints)
        self.assertTrue(Vec3("1.141", "20.803", "0.0") in endpoints)
        self.assertEquals(4, len(endpoints))
Exemple #25
0
    def testContains(self):
        #track { -2.501 39.124 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -1.838 33.162 0.0 }
        t1 = Track(Vec3("-2.501", "39.124", "0.0"), Vec3("0", "0", "0"), Vec3("0", "0", "0"), \
            Vec3("-1.838", "33.162", "0"))
        #track { -3.673 62.125 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -3.673 60.126 0.0 }
        t2 = Track(Vec3("-3.673", "62.125", "0"), Vec3("0", "0", "0"), Vec3("0", "0", "0"), \
            Vec3("-3.673", "60.126", "0"))
        #track { -7.976 -16.881 0.0  -0.187 16.665 0.0  0.881 -16.644 0.0  -9.58 33.09 0.0 }
        t3 = Track(Vec3("-7.976", "-16.881", "0"), Vec3("-0.187", "16.665", "0"), \
            Vec3("0.881", "-16.644", "0"), Vec3("-9.58", "33.09", "0"))

        # switch { 0.0 0.0 0.0  0.0 0.0 0.0  0.0 0.0 0.0  0.0 33.23 0.0  0.0 0.0 0.0  0.0 11.079 0.0  1.225 -11.012 0.0  -1.838 33.162 0.0 }
        r1 = Switch(Vec3("0", "0", "0"), Vec3("0.0", "33.23", "0"), Vec3("-1.838", "33.162", "0"), \
            Vec3("0", "0", "0"), Vec3("0", "0", "0"), Vec3("0.0", "11.079", "0"), Vec3("1.225", "-11.012", "0"))
        #switch { -3.673 60.126 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -3.662 32.989 0.0  -3.673 60.126 0.0  0.0020 -7.016 0.0  -0.777 6.973 0.0  -2.501 39.124 0.0 }
        r2 = Switch(Vec3("-3.673", "60.126", "0"), Vec3("-3.662", "32.989", "0"), Vec3("-2.501", "39.124", "0"), \
            Vec3("0", "0", "0"), Vec3("0", "0", "0"), Vec3("0.0020", "-7.016", "0"), Vec3("-0.777", "6.973", "0"))
        #switch { -7.602 -50.108 0.0  0.0 0.0 0.0  0.0 0.0 0.0  -7.976 -16.881 0.0  -7.602 -50.108 0.0  -0.124 11.078 0.0  -1.1 -11.024 0.0  -6.138 -16.929 0.0 }
        r3 = Switch(Vec3("-7.602", "-50.108", "0"), Vec3("-7.976", "-16.881", "0"), \
            Vec3("-6.138", "-16.929", "0"), \
            Vec3("0", "0", "0"), Vec3("0", "0", "0"), Vec3("-0.124", "11.078", "0"), Vec3("-1.1", "-11.024", "0"))

        group = RailGroup()

        group.insert(t1)
        self.assertTrue(group.containsPoint(Vec3("-2.501", "39.124", "0")))
        self.assertTrue(group.containsPoint(Vec3("-1.838", "33.162", "0")))

        group.insert(r1)
        self.assertTrue(group.containsPoint(Vec3("-2.501", "39.124", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))

        group.insert(r2)
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.673", "60.126", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.662", "32.989", "0")))

        group.insert(t2)
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.662", "32.989", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.673", "62.125", "0")))

        group.insert(r3)
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.662", "32.989", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.673", "62.125", "0")))
        self.assertTrue(group.containsPoint(Vec3("-7.602", "-50.108", "0")))
        self.assertTrue(group.containsPoint(Vec3("-7.976", "-16.881", "0")))
        self.assertTrue(group.containsPoint(Vec3("-6.138", "-16.929", "0")))

        group.insert(t3)
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.662", "32.989", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.673", "62.125", "0")))
        self.assertTrue(group.containsPoint(Vec3("-7.602", "-50.108", "0")))
        self.assertTrue(group.containsPoint(Vec3("-6.138", "-16.929", "0")))
        self.assertTrue(group.containsPoint(Vec3("-9.58", "33.09", "0")))

        group.remove(t2)
        self.assertTrue(group.containsPoint(Vec3("0", "0", "0")))
        self.assertTrue(group.containsPoint(Vec3("0", "33.23", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.662", "32.989", "0")))
        self.assertTrue(group.containsPoint(Vec3("-3.673", "60.126", "0")))
        self.assertTrue(group.containsPoint(Vec3("-7.602", "-50.108", "0")))
        self.assertTrue(group.containsPoint(Vec3("-6.138", "-16.929", "0")))
        self.assertTrue(group.containsPoint(Vec3("-9.58", "33.09", "0")))
Exemple #26
0
                     v2,
                     p3,
                     v3,
                     position="STRAIGHT",
                     name=None):
            self.p1 = p1
            self.v1 = v1
            self.p2 = p2
            self.v2 = v2
            self.p3 = p3
            self.v3 = v3

            self.n1 = None
            self.n2 = None
            self.n3 = None

            self.position = position
            self.name = name

    zero = Vec3("0.0", "0.0", "0.0")

    tracks = [Track(zero, zero, Vec3("100.0", "1.0", "0.0"), zero)]
    #        Track(Vec3(100, 100, 0), Vec3(0, 100, 0), Vec3(200, 200, 0), Vec3(0, -100, 0), "start"),
    #        Track(zero, Vec3(0, 100, 0), Vec3(100, 100, 0), Vec3(-100, 0, 0))]

    switches = []

    start = time.time()
    writeSector(file("test.sct", "w+"), Vec3(), tracks, switches)
    print "Time: %f ms" % ((time.time() - start) * 1000.0)
Exemple #27
0
    def testUnconnected(self):
        t1 = Track( \
            Vec3("0.0", "0.0", "0.0"), \
            Vec3("0.0", "0.0", "0.0"), \
            Vec3("0.0", "0.0", "0.0"), \
            Vec3("0.0", "100.0", "0.0"))
        t2 = Track( \
            Vec3("5.0", "0.0", "0.0"), \
            Vec3("0.0", "0.0", "0.0"), \
            Vec3("0.0", "0.0", "0.0"), \
            Vec3("5.0", "100.0", "0.0"))

        group = RailGroup()

        group.insert(t1)
        group.insert(t2)

        self.assertEquals(2, group.size())

        endpoints = group.connections.keys()
        self.assertTrue(Vec3("0.0", "0.0", "0.0") in endpoints)
        self.assertTrue(Vec3("5.0", "0.0", "0.0") in endpoints)
        self.assertTrue(Vec3("5.0", "100.0", "0.0") in endpoints)
        self.assertTrue(Vec3("0.0", "100.0", "0.0") in endpoints)
        self.assertEquals(4, len(endpoints))
Exemple #28
0
 def __init__(self, p = Vec3('-50000.0', '50000.0', '0'), \
              a = -math.pi/4):
     self.basePoint = BasePoint(p)
Exemple #29
0
    def testReadWrite(self):
        sceneryToWrite = model.scenery.Scenery()

        group1 = model.groups.RailContainer()
        group1.insert(model.tracks.Track(p1 = Vec3('26.250', '-51.250', '0.000'), \
            p2 = Vec3('28.880', '-45.857', '0.000') ))
        group1.insert(model.tracks.Switch(pc = Vec3('28.880', '-45.857', '0.000'), \
            p1 = Vec3('43.446', '-15.989', '0.000'), \
            p2 = Vec3('45.068', '-16.856', '0.000'), \
            vc2 = Vec3('4.856', '9.958', '0.000'), \
            v2 = Vec3('-5.928', '-9.361', '0.000')))

        group2 = model.groups.RailContainer()
        group2.insert(model.tracks.Track(p1 = Vec3('43.446', '-15.989', '0.000'), \
            v1 = Vec3('4.856', '9.958', '0.000'), \
            v2 = Vec3('-3.726', '-10.435', '0.000'), \
            p2 = Vec3('56.330', '14.623', '0.000')))
        group2.insert(model.tracks.Switch(pc = Vec3('69.214', '45.235', '0.000'), \
            p1 = Vec3('54.649', '15.368', '0.000'), \
            p2 = Vec3('56.330', '14.623', '0.000'), \
            vc2 = Vec3('-4.856', '-9.958', '0.000'), \
            v2 = Vec3('3.726', '10.435', '0.000')))

        track3 = model.tracks.Track(p1 = Vec3('44.395', '-3.000', '0.000'), \
            v1 = Vec3('3.755', '5.929', '0.000'), \
            v2 = Vec3('-3.076', '-6.307', '0.000'), \
            p2 = Vec3('54.649', '15.368', '0.000'))

        sceneryToWrite.AddRailTracking(group1)
        sceneryToWrite.AddRailTracking(group2)
        sceneryToWrite.AddRailTracking(track3)

        self.assertEquals(len(sceneryToWrite.tracks.children), 3)

        text = yaml.dump(sceneryToWrite)

        sceneryAfterRead = yaml.load(text, sptyaml.SptLoader)

        self.assertEquals(len(sceneryAfterRead.tracks.children), 3)

        l = list(
            sceneryAfterRead.tracks.children.query(
                sptial.Cuboid((26, -52, 0), (46, -15, 0))))
        ll = list(l[0].children)
        self.assertTrue( \
            model.tracks.Track( \
                p1 = Vec3('26.250', '-51.250', '0.000'), \
                p2 = Vec3('28.880', '-45.857', '0.000') ) in ll)
        self.assertTrue( \
            model.tracks.Switch( \
                pc = Vec3('28.880', '-45.857', '0.000'), \
                p1 = Vec3('43.446', '-15.989', '0.000'), \
                p2 = Vec3('45.068', '-16.856', '0.000'), \
                vc2 = Vec3('4.856', '9.958', '0.000'), \
                v2 = Vec3('-5.928', '-9.361', '0.000')) in ll)

        l = list(
            sceneryAfterRead.tracks.children.query(
                sptial.Cuboid((43, -16, 0), (70, 46, 0))))
        ll = list(l[1].children)
        self.assertTrue( \
            model.tracks.Track( \
                p1 = Vec3('43.446', '-15.989', '0.000'), \
                v1 = Vec3('4.856', '9.958', '0.000'), \
                v2 = Vec3('-3.726', '-10.435', '0.000'), \
                p2 = Vec3('56.330', '14.623', '0.000')) in ll)
        self.assertTrue( \
            model.tracks.Switch( \
                pc = Vec3('69.214', '45.235', '0.000'), \
                p1 = Vec3('54.649', '15.368', '0.000'), \
                p2 = Vec3('56.330', '14.623', '0.000'), \
                vc2 = Vec3('-4.856', '-9.958', '0.000'), \
                v2 = Vec3('3.726', '10.435', '0.000')) in ll)

        l = list(
            sceneryAfterRead.tracks.children.query(
                sptial.Cuboid((44, -4, 0), (55, 16, 0))))
        self.assertTrue( \
            model.tracks.Track( \
                p1 = Vec3('44.395', '-3.000', '0.000'), \
                v1 = Vec3('3.755', '5.929', '0.000'), \
                v2 = Vec3('-3.076', '-6.307', '0.000'), \
                p2 = Vec3('54.649', '15.368', '0.000')) in l)
Exemple #30
0
def generateSimpleScenery():
    scenery = Scenery()

    t1 = Track(p1 = Vec3(Decimal("1.164"), Decimal("21.003"), Decimal("0.0")), \
               p2 = Vec3(Decimal("1.825"), Decimal("26.966"), Decimal("0.0")))
    t2 = Track(Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
               Vec3(Decimal("0.0"), Decimal("-7.018"), Decimal("0.0")), \
               Vec3(Decimal("-0.776"), Decimal("6.974"), Decimal("0.0")), \
               Vec3(Decimal("1.164"), Decimal("-21.004"), Decimal("0.0")))
    t3 = Track(p1 = Vec3(Decimal("0.0"), Decimal("27.138"), Decimal("0.0")), \
               p2 = Vec3(Decimal("0.0"), Decimal("77.138"), Decimal("0.0")))
    t4 = Track(p1 = Vec3(Decimal("1.825"), Decimal("26.966"), Decimal("0.0")), \
               p2 = Vec3(Decimal("7.333"), Decimal("76.661"), Decimal("0.0")))

    r1 = Switch(pc = Vec3(Decimal("0.0"), Decimal("0.0"), Decimal("0.0")), \
                p1 = Vec3(Decimal("0.0"), Decimal("27.138"), Decimal("0.0")), \
                p2 = Vec3(Decimal("1.164"), Decimal("21.003"), Decimal("0.0")), \
                vc2 = Vec3(Decimal("0.0"), Decimal("7.017"), Decimal("0.0")), \
                v2 = Vec3(Decimal("-0.776"), Decimal("-6.974"), Decimal("0.0")))

    scenery.AddRailTracking(t1)
    scenery.AddRailTracking(t2)
    scenery.AddRailTracking(t3)
    scenery.AddRailTracking(t4)
    scenery.AddRailTracking(r1)

    # Configure yaml
    sptyaml.configureYaml()

    print yaml.dump(scenery)