814
|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
|
|
3 |
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
|
|
4 |
#based on the plcopen standard.
|
|
5 |
#
|
|
6 |
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
|
|
7 |
#
|
|
8 |
#See COPYING file for copyrights details.
|
|
9 |
#
|
|
10 |
#This library is free software; you can redistribute it and/or
|
|
11 |
#modify it under the terms of the GNU General Public
|
|
12 |
#License as published by the Free Software Foundation; either
|
|
13 |
#version 2.1 of the License, or (at your option) any later version.
|
|
14 |
#
|
|
15 |
#This library is distributed in the hope that it will be useful,
|
|
16 |
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 |
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
18 |
#General Public License for more details.
|
|
19 |
#
|
|
20 |
#You should have received a copy of the GNU General Public
|
|
21 |
#License along with this library; if not, write to the Free Software
|
|
22 |
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
23 |
|
|
24 |
import wx
|
|
25 |
|
|
26 |
from graphics import *
|
|
27 |
|
|
28 |
#-------------------------------------------------------------------------------
|
|
29 |
# Edit Ladder Power Rail Properties Dialog
|
|
30 |
#-------------------------------------------------------------------------------
|
|
31 |
|
|
32 |
class LDPowerRailDialog(wx.Dialog):
|
|
33 |
|
|
34 |
def __init__(self, parent, controller, type = LEFTRAIL, number = 1):
|
|
35 |
wx.Dialog.__init__(self, parent, size=wx.Size(350, 260),
|
|
36 |
title=_('Power Rail Properties'))
|
|
37 |
|
|
38 |
main_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=10)
|
|
39 |
main_sizer.AddGrowableCol(0)
|
|
40 |
main_sizer.AddGrowableRow(0)
|
|
41 |
|
|
42 |
column_sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
43 |
main_sizer.AddSizer(column_sizer, border=20,
|
|
44 |
flag=wx.GROW|wx.TOP|wx.LEFT|wx.RIGHT)
|
|
45 |
|
|
46 |
left_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=5, vgap=5)
|
|
47 |
left_gridsizer.AddGrowableCol(0)
|
|
48 |
column_sizer.AddSizer(left_gridsizer, 1, border=5,
|
|
49 |
flag=wx.GROW|wx.RIGHT)
|
|
50 |
|
|
51 |
type_label = wx.StaticText(self, label=_('Type:'))
|
|
52 |
left_gridsizer.AddWindow(type_label, flag=wx.GROW)
|
|
53 |
|
|
54 |
self.LeftPowerRail = wx.RadioButton(self,
|
|
55 |
label=_('Left PowerRail'), style=wx.RB_GROUP)
|
|
56 |
self.LeftPowerRail.SetValue(True)
|
|
57 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.LeftPowerRail)
|
|
58 |
left_gridsizer.AddWindow(self.LeftPowerRail, flag=wx.GROW)
|
|
59 |
|
|
60 |
self.RightPowerRail = wx.RadioButton(self, label=_('Right PowerRail'))
|
|
61 |
self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, self.RightPowerRail)
|
|
62 |
left_gridsizer.AddWindow(self.RightPowerRail, flag=wx.GROW)
|
|
63 |
|
|
64 |
pin_number_label = wx.StaticText(self, label=_('Pin number:'))
|
|
65 |
left_gridsizer.AddWindow(pin_number_label, flag=wx.GROW)
|
|
66 |
|
|
67 |
self.PinNumber = wx.SpinCtrl(self, min=1, max=50,
|
|
68 |
style=wx.SP_ARROW_KEYS)
|
|
69 |
self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber)
|
|
70 |
left_gridsizer.AddWindow(self.PinNumber, flag=wx.GROW)
|
|
71 |
|
|
72 |
right_gridsizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=5)
|
|
73 |
right_gridsizer.AddGrowableCol(0)
|
|
74 |
right_gridsizer.AddGrowableRow(1)
|
|
75 |
column_sizer.AddSizer(right_gridsizer, 1, border=5,
|
|
76 |
flag=wx.GROW|wx.LEFT)
|
|
77 |
|
|
78 |
preview_label = wx.StaticText(self, label=_('Preview:'))
|
|
79 |
right_gridsizer.AddWindow(preview_label, flag=wx.GROW)
|
|
80 |
|
|
81 |
self.Preview = wx.Panel(self,
|
|
82 |
style=wx.TAB_TRAVERSAL|wx.SIMPLE_BORDER)
|
|
83 |
self.Preview.SetBackgroundColour(wx.Colour(255,255,255))
|
|
84 |
setattr(self.Preview, "GetDrawingMode", lambda:FREEDRAWING_MODE)
|
|
85 |
setattr(self.Preview, "GetScaling", lambda:None)
|
|
86 |
setattr(self.Preview, "IsOfType", controller.IsOfType)
|
|
87 |
self.Preview.Bind(wx.EVT_PAINT, self.OnPaint)
|
|
88 |
right_gridsizer.AddWindow(self.Preview, flag=wx.GROW)
|
|
89 |
|
|
90 |
button_sizer = self.CreateButtonSizer(wx.OK|wx.CANCEL|wx.CENTRE)
|
|
91 |
main_sizer.AddSizer(button_sizer, border=20,
|
|
92 |
flag=wx.ALIGN_RIGHT|wx.BOTTOM|wx.LEFT|wx.RIGHT)
|
|
93 |
|
|
94 |
self.SetSizer(main_sizer)
|
|
95 |
|
|
96 |
self.Type = type
|
|
97 |
if type == LEFTRAIL:
|
|
98 |
self.LeftPowerRail.SetValue(True)
|
|
99 |
elif type == RIGHTRAIL:
|
|
100 |
self.RightPowerRail.SetValue(True)
|
|
101 |
self.PinNumber.SetValue(number)
|
|
102 |
|
|
103 |
self.PowerRailMinSize = (0, 0)
|
|
104 |
self.PowerRail = None
|
|
105 |
|
|
106 |
self.LeftPowerRail.SetFocus()
|
|
107 |
|
|
108 |
def SetPreviewFont(self, font):
|
|
109 |
self.Preview.SetFont(font)
|
|
110 |
|
|
111 |
def SetMinSize(self, size):
|
|
112 |
self.PowerRailMinSize = size
|
|
113 |
self.RefreshPreview()
|
|
114 |
|
|
115 |
def GetValues(self):
|
|
116 |
values = {}
|
|
117 |
values["type"] = self.Type
|
|
118 |
values["number"] = self.PinNumber.GetValue()
|
|
119 |
values["width"], values["height"] = self.PowerRail.GetSize()
|
|
120 |
return values
|
|
121 |
|
|
122 |
def OnTypeChanged(self, event):
|
|
123 |
if self.LeftPowerRail.GetValue():
|
|
124 |
self.Type = LEFTRAIL
|
|
125 |
elif self.RightPowerRail.GetValue():
|
|
126 |
self.Type = RIGHTRAIL
|
|
127 |
self.RefreshPreview()
|
|
128 |
event.Skip()
|
|
129 |
|
|
130 |
def OnPinNumberChanged(self, event):
|
|
131 |
self.RefreshPreview()
|
|
132 |
event.Skip()
|
|
133 |
|
|
134 |
def RefreshPreview(self):
|
|
135 |
dc = wx.ClientDC(self.Preview)
|
|
136 |
dc.SetFont(self.Preview.GetFont())
|
|
137 |
dc.Clear()
|
|
138 |
self.PowerRail = LD_PowerRail(self.Preview, self.Type, connectors = self.PinNumber.GetValue())
|
|
139 |
min_width, min_height = 2, LD_LINE_SIZE * self.PinNumber.GetValue()
|
|
140 |
width, height = max(min_width, self.PowerRailMinSize[0]), max(min_height, self.PowerRailMinSize[1])
|
|
141 |
self.PowerRail.SetSize(width, height)
|
|
142 |
clientsize = self.Preview.GetClientSize()
|
|
143 |
self.PowerRail.SetPosition((clientsize.width - width) / 2, (clientsize.height - height) / 2)
|
|
144 |
self.PowerRail.Draw(dc)
|
|
145 |
|
|
146 |
def OnPaint(self, event):
|
|
147 |
self.RefreshPreview()
|
|
148 |
event.Skip()
|