1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
2# Copyright (C) 2016-2019 German Aerospace Center (DLR) and others.
3# SUMOPy module
4# Copyright (C) 2012-2017 University of Bologna - DICAM
5# This program and the accompanying materials
6# are made available under the terms of the Eclipse Public License v2.0
7# which accompanies this distribution, and is available at
8# http://www.eclipse.org/legal/epl-v20.html
9# SPDX-License-Identifier: EPL-2.0
10
11# @file    test_app.py
12# @author  Joerg Schweizer
13# @date
14# @version $Id$
15
16import os
17import sys
18
19import wx
20from wx.lib.wordwrap import wordwrap
21
22
23if __name__ == '__main__':
24    try:
25        APPDIR = os.path.dirname(os.path.abspath(__file__))
26    except:
27        APPDIR = os.path.dirname(os.path.abspath(sys.argv[0]))
28    AGILEDIR = os.path.join(APPDIR, '..')
29    print 'APPDIR,AGILEDIR', APPDIR, AGILEDIR
30    sys.path.append(AGILEDIR)
31    libpaths = [AGILEDIR, os.path.join(AGILEDIR, "lib_base"), os.path.join(AGILEDIR, "lib_wx"), ]
32    for libpath in libpaths:
33        print '  libpath=', libpath
34        lp = os.path.abspath(libpath)
35        if not lp in sys.path:
36            # print ' append',lp
37            sys.path.append(lp)
38
39from mainframe import *
40
41# import corepackages
42#from test_glcanvas import *
43from ogleditor import *
44##
45##import wx
46##
47
48# try:
49##    dirName = os.path.dirname(os.path.abspath(__file__))
50# except:
51##    dirName = os.path.dirname(os.path.abspath(sys.argv[0]))
52##
53# sys.path.append(os.path.split(dirName)[0])
54
55
56IMAGEDIR = os.path.join(os.path.dirname(__file__), "images")
57ICONPATH = os.path.join(IMAGEDIR, 'icon_color_small.png')  # None
58
59
60class MyApp(wx.App):
61    def __init__(self, redirect=False, filename=None):
62        wx.App.__init__(self, redirect, filename)
63        #self.frame = wx.Frame(None, wx.ID_ANY, title='My Title')
64        self.mainframe = AgileMainframe(title='MyApp', size_toolbaricons=(32, 32))
65        if ICONPATH is not None:
66            icon = wx.Icon(ICONPATH, wx.BITMAP_TYPE_PNG, 16, 16)
67            self.mainframe.SetIcon(icon)
68
69        self.gleditor = self.mainframe.add_view("OGleditor", OGleditor)
70
71        self.mainframe.Show()
72        self.on_test()
73        self.make_menu()
74        self.make_toolbar()
75        #canvas = gleditor.get_canvas()
76        # canvas.add_element(lines)
77        # canvas.add_element(triangles)
78        # canvas.add_element(rectangles)
79
80    def make_toolbar(self):
81        tsize = self.mainframe.get_size_toolbaricons()
82        new_bmp = wx.ArtProvider.GetBitmap(wx.ART_NEW, wx.ART_TOOLBAR, tsize)
83        open_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_TOOLBAR, tsize)
84        save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE, wx.ART_TOOLBAR, tsize)
85        #cut_bmp = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR, tsize)
86        #copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize)
87        #paste_bmp= wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR, tsize)
88
89        self.mainframe.add_tool('new', self.on_open, new_bmp, 'create new doc')
90        self.mainframe.add_tool('open', self.on_open, open_bmp, 'Open doc')
91        self.mainframe.add_tool('save', self.on_save, save_bmp, 'Save doc')
92        # self.toolbar.AddSeparator()
93        # self.add_tool('cut',self.on_open,cut_bmp,'Cut')
94        # self.add_tool('copy',self.on_open,copy_bmp,'Copy')
95        # self.add_tool('paste',self.on_open,paste_bmp,'Paste')
96
97    def make_menu(self):
98        self.mainframe.menubar.append_menu('file')
99        self.mainframe.menubar.append_menu('file/doc')
100
101        self.mainframe.menubar.append_item('file/doc/open', self.on_open,
102                                           shortkey='Ctrl+o', info='open it out')
103
104        self.mainframe.menubar.append_item('file/doc/save', self.on_save,
105                                           shortkey='Ctrl+s', info='save it out')
106
107    def on_save(self, event):
108        print 'save it!!'
109
110    def on_open(self, event):
111        """Open a document"""
112        #wildcards = CreateWildCards() + "All files (*.*)|*.*"
113        print 'open it!!'
114
115    def on_test(self, event=None):
116        print '\non_test'
117        vertices = np.array([
118            [[0.0, 0.0, 0.0], [0.2, 0.0, 0.0]],  # 0 green
119            [[0.0, 0.0, 0.0], [0.0, 0.9, 0.0]],  # 1 red
120        ])
121
122        colors = np.array([
123            [0.0, 0.9, 0.0, 0.9],    # 0
124            [0.9, 0.0, 0.0, 0.9],    # 1
125        ])
126
127        colors2 = np.array([
128            [0.5, 0.9, 0.5, 0.5],    # 0
129            [0.9, 0.5, 0.9, 0.5],    # 1
130        ])
131        colors2o = np.array([
132            [0.8, 0.9, 0.8, 0.9],    # 0
133            [0.9, 0.8, 0.9, 0.9],    # 1
134        ])
135
136        drawing = OGLdrawing()
137# -------------------------------------------------------------------------------
138
139        if 0:
140            lines = Lines('lines', drawing)
141            lines.add_drawobjs(vertices, colors)
142            drawing.add_drawobj(lines)
143# -------------------------------------------------------------------------------
144        if 0:
145            fancylines = Fancylines('fancylines', drawing)
146            vertices_fancy = np.array([
147                [[0.0, -1.0, 0.0], [2, -1.0, 0.0]],  # 0 green
148                [[0.0, -1.0, 0.0], [0.0, -5.0, 0.0]],  # 1 red
149            ])
150
151            widths = [0.5,
152                      0.3,
153                      ]
154            # print '  vertices_fancy\n',vertices_fancy
155            # FLATHEAD = 0
156            #BEVELHEAD = 1
157            #TRIANGLEHEAD = 2
158            #ARROWHEAD = 3
159            fancylines.add_drawobjs(vertices_fancy,
160                                    widths,  # width
161                                    colors,
162                                    beginstyles=[TRIANGLEHEAD, TRIANGLEHEAD],
163                                    endstyles=[ARROWHEAD, ARROWHEAD])
164            drawing.add_drawobj(fancylines)
165# -------------------------------------------------------------------------------
166        if 0:
167            polylines = Polylines('polylines', drawing, joinstyle=BEVELHEAD)
168            colors_poly = np.array([
169                [0.0, 0.8, 0.5, 0.9],    # 0
170                [0.8, 0.0, 0.5, 0.9],    # 1
171            ])
172
173            vertices_poly = np.array([
174                [[0.0, 2.0, 0.0], [5.0, 2.0, 0.0], [5.0, 7.0, 0.0], [0.0, 7.0, 0.0]],  # 0 green
175                [[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0]],  # 1 red
176            ], np.object)
177
178            widths = [0.5,
179                      0.3,
180                      ]
181            # print '  vertices_poly\n',vertices_poly
182            polylines.add_drawobjs(vertices_poly,
183                                   widths,  # width
184                                   colors_poly,
185                                   beginstyles=[ARROWHEAD, ARROWHEAD],
186                                   endstyles=[ARROWHEAD, ARROWHEAD])
187            drawing.add_drawobj(polylines)
188
189# -------------------------------------------------------------------------------
190        if 1:
191            polygons = Polygons('polygons', drawing, linewidth=5)
192            colors_poly = np.array([
193                [0.0, 0.9, 0.9, 0.9],    # 0
194                [0.8, 0.2, 0.2, 0.9],    # 1
195            ])
196
197            vertices_poly = np.array([
198                [[0.0, 2.0, 0.0], [5.0, 2.0, 0.0], [5.0, 7.0, 0.0], [0.0, 7.0, 0.0]],  # 0 green
199                [[0.0, -2.0, 0.0], [-2.0, -2.0, 0.0], [-2.0, 0.0, 0.0]],  # 1 red
200            ], np.object)
201
202            print '  vertices_polygon\n', vertices_poly
203            polygons.add_drawobjs(vertices_poly,
204                                  colors_poly)
205            drawing.add_drawobj(polygons)
206
207        canvas = self.gleditor.get_canvas()
208        canvas.set_drawing(drawing)
209
210        #lines.add_drawobj([[0.0,0.0,0.0],[-0.2,-0.8,0.0]], [0.0,0.9,0.9,0.9])
211        #circles.add_drawobj([1.5,0.0,0.0],0.6,colors2o[0], colors2[0])
212
213        # canvas.zoom_tofit()
214        wx.CallAfter(canvas.zoom_tofit)
215
216
217if __name__ == '__main__':
218    # if len(sys.argv)==3:
219    #    ident = sys.argv[1]
220    #    dirpath = sys.argv[2]
221    # else:
222    #    ident =  None
223    #    dirpath = None
224    myapp = MyApp(0)
225
226    myapp.MainLoop()
227