2
# -*- coding: utf-8 -*-
4
# LORZE erasandcad, a 2D CAD with an intuitive user interface, simple and easy.
5
# http://erasand.jimdo.com/python-programme/lorze/
6
# (C) 2012, Andreas Ulrich
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
from lrzoptions import LorzeOptions
25
#Lorze preview for the graphic panel
27
def __init__(self, parent, options):
28
# parent, GraphicPanel(), options
30
self.__options= options
33
self.__pen= wx.Pen(self.__options.GetPreviewColor(),
34
options.GetPreviewPenSize(), options.GetPreviewPenStyle())
44
self.__xa, self.__ya, self.__xb, self.__yb= 0, 0, 0, 0
47
def IncreaseClick(self, mousex, mousey):
48
# click in the GraphicPanel
51
self.__xa= float(mousex)
52
self.__ya= float(mousey)
53
elif self.__click== 2:
54
self.__xb= float(mousex)
55
self.__yb= float(mousey)
63
# return coord as a tuple
64
return((self.__xa, self.__ya, self.__xb, self.__yb))
67
def wxPaint(self, dc, userscale, mousex, mousey):
68
# paint preview in wxpython drawing client
69
# userscale: scale factor for zoom
70
# x, y: mouse coordinates
73
dc.SetBrush(wx.Brush('#000000', wx.TRANSPARENT))
76
action= self.__parent.GetAction()
78
# select & paint preview
79
if action== 'elementsel':
81
# 1st point of rect, rect coordinates
83
x= self.__xa* userscale
84
w= (mousex- self.__xa)* userscale
87
w= (self.__xa - mousex)* userscale
90
y= self.__ya* userscale
91
h= (mousey- self.__ya)* userscale
94
h= (self.__ya - mousey)* userscale
96
dc.DrawRectangle(x, y, w, h)
99
class TestFrame(wx.Frame):
102
wx.Frame.__init__(self, None, title= 'Testcode Selection',
104
self.__options= LorzeOptions()
105
self.__dps= self.__options.GetDezPlcs()
106
self.__panel= wx.Panel(self)
107
buttonA= wx.Button(self, label= 'Element Selection Preview')
109
vbox= wx.BoxSizer(wx.VERTICAL)
110
self.__panel.Bind(wx.EVT_MOTION, self.OnMouseMove)
111
vbox= wx.BoxSizer(wx.VERTICAL)
113
vbox.Add(self.__panel, 1, wx.EXPAND)
115
self.Bind(wx.EVT_PAINT, self.OnPaint)
116
buttonA.Bind(wx.EVT_BUTTON, self.OnButtonA)
118
self.__prev= LorzePreview(self, self.__options)
121
self.__userscale= 96/ 25.4
129
def OnButtonA(self, event):
130
self.__action= 'elementsel'
132
self.__prev.IncreaseClick(0, 0)
134
def OnPaint(self, event):
135
dc = wx.PaintDC(self.__panel)
139
dc.SetDeviceOrigin(self.__originx, self.__originy)
140
dc.SetAxisOrientation(True, True)
143
self.__prev.wxPaint(dc, self.__userscale, self.__mousex, self.__mousey)
147
# simulates the method of the GraphicPanel()
148
return(self.__action)
151
def OnMouseMove(self, event):
152
# mouse movement, mouse-position, pixel on the panel
153
xpanel, ypanel= event.GetPosition()
154
dc= wx.ClientDC(self)
155
dc.SetDeviceOrigin(self.__originx, self.__originy)
156
dc.SetAxisOrientation(True, True)
157
self.__mousex= dc.DeviceToLogicalX(xpanel)/ self.__userscale
158
self.__mousey= dc.DeviceToLogicalY(ypanel)/ self.__userscale
159
self.__mousex= round(self.__mousex, self.__dps)
160
self.__mousey= round(self.__mousey, self.__dps)
164
if __name__== '__main__':