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