57 |
57 |
58 if __name__ == '__main__': |
58 if __name__ == '__main__': |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
59 __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation |
60 |
60 |
61 from Beremiz import * |
61 from Beremiz import * |
62 from plugger import PluginsRoot, PlugTemplate, opjimg, connectors |
62 from ConfigTree import ConfigTreeRoot, ConfigTreeNode, opjimg, connectors |
63 from plcopen.structures import LOCATIONDATATYPES |
63 from plcopen.structures import LOCATIONDATATYPES |
64 from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\ |
64 from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\ |
65 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
65 LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY |
66 from PLCOpenEditor import IDEFrame, ProjectDialog |
66 from PLCOpenEditor import IDEFrame, ProjectDialog |
67 |
67 |
68 havecanfestival = False |
68 havecanfestival = False |
69 try: |
69 try: |
70 from plugins.canfestival import RootClass as CanOpenRootClass |
70 from confnodes.canfestival import RootClass as CanOpenRootClass |
71 from plugins.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager |
71 from confnodes.canfestival.canfestival import _SlavePlug, _NodeListPlug, NodeManager |
72 havecanfestival = True |
72 havecanfestival = True |
73 except: |
73 except: |
74 havecanfestival = False |
74 havecanfestival = False |
75 |
75 |
76 |
76 |
77 #------------------------------------------------------------------------------- |
77 #------------------------------------------------------------------------------- |
78 # CANFESTIVAL PLUGIN HACK |
78 # CANFESTIVAL CONFNODE HACK |
79 #------------------------------------------------------------------------------- |
79 #------------------------------------------------------------------------------- |
80 # from plugins.canfestival import canfestival |
80 # from confnodes.canfestival import canfestival |
81 # class LPC_canfestival_config: |
81 # class LPC_canfestival_config: |
82 # def getCFLAGS(self, *args): |
82 # def getCFLAGS(self, *args): |
83 # return "" |
83 # return "" |
84 # |
84 # |
85 # def getLDFLAGS(self, *args): |
85 # def getLDFLAGS(self, *args): |
526 |
526 |
527 self.SimulationBuildPath = None |
527 self.SimulationBuildPath = None |
528 |
528 |
529 self.AbortTransferTimer = None |
529 self.AbortTransferTimer = None |
530 |
530 |
531 def PluginLibraryFilePath(self): |
531 def ConfNodeLibraryFilePath(self): |
532 if self.OrigBuildPath is not None: |
532 if self.OrigBuildPath is not None: |
533 return os.path.join(self.OrigBuildPath, "pous.xml") |
533 return os.path.join(self.OrigBuildPath, "pous.xml") |
534 else: |
534 else: |
535 return PluginsRoot.PluginLibraryFilePath(self) |
535 return ConfigTreeRoot.ConfNodeLibraryFilePath(self) |
536 |
536 |
537 def GetProjectName(self): |
537 def GetProjectName(self): |
538 return self.Project.getname() |
538 return self.Project.getname() |
539 |
539 |
540 def GetDefaultTargetName(self): |
540 def GetDefaultTargetName(self): |
541 if self.CurrentMode == SIMULATION_MODE: |
541 if self.CurrentMode == SIMULATION_MODE: |
542 return PluginsRoot.GetDefaultTargetName(self) |
542 return ConfigTreeRoot.GetDefaultTargetName(self) |
543 else: |
543 else: |
544 return "LPC" |
544 return "LPC" |
545 |
545 |
546 def GetTarget(self): |
546 def GetTarget(self): |
547 target = PluginsRoot.GetTarget(self) |
547 target = ConfigTreeRoot.GetTarget(self) |
548 if self.CurrentMode != SIMULATION_MODE: |
548 if self.CurrentMode != SIMULATION_MODE: |
549 target.getcontent()["value"].setBuildPath(self.BuildPath) |
549 target.getcontent()["value"].setBuildPath(self.BuildPath) |
550 return target |
550 return target |
551 |
551 |
552 def _getBuildPath(self): |
552 def _getBuildPath(self): |
553 if self.CurrentMode == SIMULATION_MODE: |
553 if self.CurrentMode == SIMULATION_MODE: |
554 if self.SimulationBuildPath is None: |
554 if self.SimulationBuildPath is None: |
555 self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build") |
555 self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build") |
556 return self.SimulationBuildPath |
556 return self.SimulationBuildPath |
557 else: |
557 else: |
558 return PluginsRoot._getBuildPath(self) |
558 return ConfigTreeRoot._getBuildPath(self) |
559 |
559 |
560 def _Build(self): |
560 def _Build(self): |
561 save = self.ProjectTestModified() |
561 save = self.ProjectTestModified() |
562 if save: |
562 if save: |
563 self.SaveProject() |
563 self.SaveProject() |
564 self.AppFrame._Refresh(TITLE, FILEMENU) |
564 self.AppFrame._Refresh(TITLE, FILEMENU) |
565 if self.BuildPath is not None: |
565 if self.BuildPath is not None: |
566 mycopytree(self.OrigBuildPath, self.BuildPath) |
566 mycopytree(self.OrigBuildPath, self.BuildPath) |
567 PluginsRoot._Build(self) |
567 ConfigTreeRoot._Build(self) |
568 if save: |
568 if save: |
569 wx.CallAfter(self.AppFrame.RefreshAll) |
569 wx.CallAfter(self.AppFrame.RefreshAll) |
570 |
570 |
571 def SetProjectName(self, name): |
571 def SetProjectName(self, name): |
572 return self.Project.setname(name) |
572 return self.Project.setname(name) |
1179 |
1179 |
1180 def RefreshPLCParams(self): |
1180 def RefreshPLCParams(self): |
1181 self.Freeze() |
1181 self.Freeze() |
1182 self.ClearSizer(self.PLCParamsSizer) |
1182 self.ClearSizer(self.PLCParamsSizer) |
1183 |
1183 |
1184 if self.PluginRoot is not None: |
1184 if self.CTR is not None: |
1185 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1185 plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1186 if self.PluginRoot.PlugTestModified(): |
1186 if self.CTR.PlugTestModified(): |
1187 bkgdclr = CHANGED_TITLE_COLOUR |
1187 bkgdclr = CHANGED_TITLE_COLOUR |
1188 else: |
1188 else: |
1189 bkgdclr = TITLE_COLOUR |
1189 bkgdclr = TITLE_COLOUR |
1190 |
1190 |
1191 if self.PluginRoot not in self.PluginInfos: |
1191 if self.CTR not in self.ConfNodeInfos: |
1192 self.PluginInfos[self.PluginRoot] = {"right_visible" : False} |
1192 self.ConfNodeInfos[self.CTR] = {"right_visible" : False} |
1193 |
1193 |
1194 plcwindow.SetBackgroundColour(TITLE_COLOUR) |
1194 plcwindow.SetBackgroundColour(TITLE_COLOUR) |
1195 plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
1195 plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown) |
1196 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
1196 self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW) |
1197 |
1197 |
1198 plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1198 plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1199 plcwindow.SetSizer(plcwindowsizer) |
1199 plcwindow.SetSizer(plcwindowsizer) |
1200 |
1200 |
1201 st = wx.StaticText(plcwindow, -1) |
1201 st = wx.StaticText(plcwindow, -1) |
1202 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1202 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1203 st.SetLabel(self.PluginRoot.GetProjectName()) |
1203 st.SetLabel(self.CTR.GetProjectName()) |
1204 plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
1204 plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER) |
1205 |
1205 |
1206 plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
1206 plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL) |
1207 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
1207 plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL) |
1208 |
1208 |
1209 plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
1209 plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL) |
1210 plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
1210 plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER) |
1211 |
1211 |
1212 msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"]) |
1212 msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow, not self.ConfNodeInfos[self.CTR]["right_visible"]) |
1213 plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
1213 plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW) |
1214 |
1214 |
1215 self.PLCConfigMainSizer.Layout() |
1215 self.PLCConfigMainSizer.Layout() |
1216 self.RefreshScrollBars() |
1216 self.RefreshScrollBars() |
1217 self.Thaw() |
1217 self.Thaw() |
1218 |
1218 |
1219 def GenerateTreeBranch(self, plugin): |
1219 def GenerateTreeBranch(self, confnode): |
1220 leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1220 leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1221 if plugin.PlugTestModified(): |
1221 if confnode.PlugTestModified(): |
1222 bkgdclr=CHANGED_WINDOW_COLOUR |
1222 bkgdclr=CHANGED_WINDOW_COLOUR |
1223 else: |
1223 else: |
1224 bkgdclr=WINDOW_COLOUR |
1224 bkgdclr=WINDOW_COLOUR |
1225 |
1225 |
1226 leftwindow.SetBackgroundColour(bkgdclr) |
1226 leftwindow.SetBackgroundColour(bkgdclr) |
1227 |
1227 |
1228 if plugin not in self.PluginInfos: |
1228 if confnode not in self.ConfNodeInfos: |
1229 self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "right_visible" : False} |
1229 self.ConfNodeInfos[confnode] = {"expanded" : False, "left_visible" : False, "right_visible" : False} |
1230 |
1230 |
1231 self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds() |
1231 self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChilds() |
1232 plugin_infos = plugin.GetVariableLocationTree() |
1232 confnode_infos = confnode.GetVariableLocationTree() |
1233 plugin_locations = [] |
1233 confnode_locations = [] |
1234 if len(self.PluginInfos[plugin]["children"]) == 0: |
1234 if len(self.ConfNodeInfos[confnode]["children"]) == 0: |
1235 plugin_locations = plugin_infos["children"] |
1235 confnode_locations = confnode_infos["children"] |
1236 if not self.PluginInfos[plugin].has_key("locations_infos"): |
1236 if not self.ConfNodeInfos[confnode].has_key("locations_infos"): |
1237 self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}} |
1237 self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded" : False}} |
1238 |
1238 |
1239 self.PluginInfos[plugin]["locations_infos"]["root"]["left"] = None |
1239 self.ConfNodeInfos[confnode]["locations_infos"]["root"]["left"] = None |
1240 self.PluginInfos[plugin]["locations_infos"]["root"]["right"] = None |
1240 self.ConfNodeInfos[confnode]["locations_infos"]["root"]["right"] = None |
1241 self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = [] |
1241 self.ConfNodeInfos[confnode]["locations_infos"]["root"]["children"] = [] |
1242 |
1242 |
1243 self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1243 self.ConfNodeTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW) |
1244 |
1244 |
1245 leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) |
1245 leftwindowvsizer = wx.BoxSizer(wx.VERTICAL) |
1246 leftwindow.SetSizer(leftwindowvsizer) |
1246 leftwindow.SetSizer(leftwindowvsizer) |
1247 |
1247 |
1248 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1248 leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL) |
1249 leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) |
1249 leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0) |
1250 |
1250 |
1251 self.GenerateEnableButton(leftwindow, leftwindowsizer, plugin) |
1251 self.GenerateEnableButton(leftwindow, leftwindowsizer, confnode) |
1252 |
1252 |
1253 st = wx.StaticText(leftwindow, -1) |
1253 st = wx.StaticText(leftwindow, -1) |
1254 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1254 st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1255 st.SetLabel(plugin.GetFullIEC_Channel()) |
1255 st.SetLabel(confnode.GetFullIEC_Channel()) |
1256 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1256 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT) |
1257 |
1257 |
1258 expandbutton_id = wx.NewId() |
1258 expandbutton_id = wx.NewId() |
1259 expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), |
1259 expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')), |
1260 name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
1260 name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0), |
1262 expandbutton.labelDelta = 0 |
1262 expandbutton.labelDelta = 0 |
1263 expandbutton.SetBezelWidth(0) |
1263 expandbutton.SetBezelWidth(0) |
1264 expandbutton.SetUseFocusIndicator(False) |
1264 expandbutton.SetUseFocusIndicator(False) |
1265 expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png'))) |
1265 expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png'))) |
1266 |
1266 |
1267 if len(self.PluginInfos[plugin]["children"]) > 0: |
1267 if len(self.ConfNodeInfos[confnode]["children"]) > 0: |
1268 expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"]) |
1268 expandbutton.SetToggle(self.ConfNodeInfos[confnode]["expanded"]) |
1269 def togglebutton(event): |
1269 def togglebutton(event): |
1270 if expandbutton.GetToggle(): |
1270 if expandbutton.GetToggle(): |
1271 self.ExpandPlugin(plugin) |
1271 self.ExpandConfNode(confnode) |
1272 else: |
1272 else: |
1273 self.CollapsePlugin(plugin) |
1273 self.CollapseConfNode(confnode) |
1274 self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() |
1274 self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle() |
1275 self.PLCConfigMainSizer.Layout() |
1275 self.PLCConfigMainSizer.Layout() |
1276 self.RefreshScrollBars() |
1276 self.RefreshScrollBars() |
1277 event.Skip() |
1277 event.Skip() |
1278 expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
1278 expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
1279 elif len(plugin_locations) > 0: |
1279 elif len(confnode_locations) > 0: |
1280 locations_infos = self.PluginInfos[plugin]["locations_infos"] |
1280 locations_infos = self.ConfNodeInfos[confnode]["locations_infos"] |
1281 expandbutton.SetToggle(locations_infos["root"]["expanded"]) |
1281 expandbutton.SetToggle(locations_infos["root"]["expanded"]) |
1282 def togglebutton(event): |
1282 def togglebutton(event): |
1283 if expandbutton.GetToggle(): |
1283 if expandbutton.GetToggle(): |
1284 self.ExpandLocation(locations_infos, "root") |
1284 self.ExpandLocation(locations_infos, "root") |
1285 else: |
1285 else: |
1286 self.CollapseLocation(locations_infos, "root") |
1286 self.CollapseLocation(locations_infos, "root") |
1287 self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle() |
1287 self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle() |
1288 locations_infos["root"]["expanded"] = expandbutton.GetToggle() |
1288 locations_infos["root"]["expanded"] = expandbutton.GetToggle() |
1289 self.PLCConfigMainSizer.Layout() |
1289 self.PLCConfigMainSizer.Layout() |
1290 self.RefreshScrollBars() |
1290 self.RefreshScrollBars() |
1291 event.Skip() |
1291 event.Skip() |
1292 expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
1292 expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id) |
1293 else: |
1293 else: |
1294 expandbutton.Enable(False) |
1294 expandbutton.Enable(False) |
1295 leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1295 leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1296 |
1296 |
1297 sb = wx.StaticBitmap(leftwindow, -1) |
1297 sb = wx.StaticBitmap(leftwindow, -1) |
1298 icon = plugin_infos.get("icon", None) |
1298 icon = confnode_infos.get("icon", None) |
1299 if icon is None: |
1299 if icon is None: |
1300 icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[plugin_infos["type"]]) |
1300 icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[confnode_infos["type"]]) |
1301 else: |
1301 else: |
1302 icon_bitmap = wx.Bitmap(icon) |
1302 icon_bitmap = wx.Bitmap(icon) |
1303 sb.SetBitmap(icon_bitmap) |
1303 sb.SetBitmap(icon_bitmap) |
1304 leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1304 leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1305 |
1305 |
1306 st_id = wx.NewId() |
1306 st_id = wx.NewId() |
1307 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1307 st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER) |
1308 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1308 st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"])) |
1309 st.SetLabel(plugin.MandatoryParams[1].getName()) |
1309 st.SetLabel(confnode.MandatoryParams[1].getName()) |
1310 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1310 leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL) |
1311 |
1311 |
1312 rightwindow = self.GenerateParamsPanel(plugin, bkgdclr) |
1312 rightwindow = self.GenerateParamsPanel(confnode, bkgdclr) |
1313 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1313 self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1314 |
1314 |
1315 self.PluginInfos[plugin]["left"] = leftwindow |
1315 self.ConfNodeInfos[confnode]["left"] = leftwindow |
1316 self.PluginInfos[plugin]["right"] = rightwindow |
1316 self.ConfNodeInfos[confnode]["right"] = rightwindow |
1317 for child in self.PluginInfos[plugin]["children"]: |
1317 for child in self.ConfNodeInfos[confnode]["children"]: |
1318 self.GenerateTreeBranch(child) |
1318 self.GenerateTreeBranch(child) |
1319 if not self.PluginInfos[child]["expanded"]: |
1319 if not self.ConfNodeInfos[child]["expanded"]: |
1320 self.CollapsePlugin(child) |
1320 self.CollapseConfNode(child) |
1321 |
1321 |
1322 if len(plugin_locations) > 0: |
1322 if len(confnode_locations) > 0: |
1323 locations_infos = self.PluginInfos[plugin]["locations_infos"] |
1323 locations_infos = self.ConfNodeInfos[confnode]["locations_infos"] |
1324 treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, |
1324 treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, |
1325 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) |
1325 style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT) |
1326 treectrl.SetImageList(self.LocationImageList) |
1326 treectrl.SetImageList(self.LocationImageList) |
1327 treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos)) |
1327 treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos)) |
1328 treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True)) |
1328 treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True)) |
1329 treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) |
1329 treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False)) |
1330 |
1330 |
1331 treectrl.AddRoot("") |
1331 treectrl.AddRoot("") |
1332 self.PluginTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) |
1332 self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0) |
1333 |
1333 |
1334 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1334 rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1)) |
1335 rightwindow.SetBackgroundColour(wx.WHITE) |
1335 rightwindow.SetBackgroundColour(wx.WHITE) |
1336 self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1336 self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW) |
1337 |
1337 |
1338 locations_infos["root"]["left"] = treectrl |
1338 locations_infos["root"]["left"] = treectrl |
1339 locations_infos["root"]["right"] = rightwindow |
1339 locations_infos["root"]["right"] = rightwindow |
1340 for location in plugin_locations: |
1340 for location in confnode_locations: |
1341 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1341 locations_infos["root"]["children"].append("root.%s" % location["name"]) |
1342 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) |
1342 self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location) |
1343 if locations_infos["root"]["expanded"]: |
1343 if locations_infos["root"]["expanded"]: |
1344 self.ExpandLocation(locations_infos, "root") |
1344 self.ExpandLocation(locations_infos, "root") |
1345 |
1345 |
1452 frame.RefreshAll() |
1452 frame.RefreshAll() |
1453 |
1453 |
1454 def Close(self): |
1454 def Close(self): |
1455 global frame |
1455 global frame |
1456 |
1456 |
1457 self.PluginRoot.ResetAppFrame(self.Log) |
1457 self.CTR.ResetAppFrame(self.Log) |
1458 if frame is not None: |
1458 if frame is not None: |
1459 frame.Hide() |
1459 frame.Hide() |
1460 |
1460 |
1461 def Compile(self): |
1461 def Compile(self): |
1462 self.PluginRoot._Build() |
1462 self.CTR._Build() |
1463 |
1463 |
1464 def SetProjectProperties(self, projectname, productname, productversion, companyname): |
1464 def SetProjectProperties(self, projectname, productname, productversion, companyname): |
1465 properties = self.PluginRoot.GetProjectProperties() |
1465 properties = self.CTR.GetProjectProperties() |
1466 new_properties = properties.copy() |
1466 new_properties = properties.copy() |
1467 new_properties["projectName"] = projectname |
1467 new_properties["projectName"] = projectname |
1468 new_properties["productName"] = productname |
1468 new_properties["productName"] = productname |
1469 new_properties["productVersion"] = productversion |
1469 new_properties["productVersion"] = productversion |
1470 new_properties["companyName"] = companyname |
1470 new_properties["companyName"] = companyname |
1471 if new_properties != properties: |
1471 if new_properties != properties: |
1472 self.PluginRoot.SetProjectProperties(properties=new_properties, buffer=False) |
1472 self.CTR.SetProjectProperties(properties=new_properties, buffer=False) |
1473 self.RestartTimer() |
1473 self.RestartTimer() |
1474 |
1474 |
1475 def SetOnlineMode(self, mode, path=None): |
1475 def SetOnlineMode(self, mode, path=None): |
1476 self.PluginRoot.SetOnlineMode(mode, path) |
1476 self.CTR.SetOnlineMode(mode, path) |
1477 self.RestartTimer() |
1477 self.RestartTimer() |
1478 |
1478 |
1479 def AddBus(self, iec_channel, name, icon=None): |
1479 def AddBus(self, iec_channel, name, icon=None): |
1480 for child in self.PluginRoot.IterChilds(): |
1480 for child in self.CTR.IterChilds(): |
1481 if child.BaseParams.getName() == name: |
1481 if child.BaseParams.getName() == name: |
1482 return "Error: A bus named %s already exists\n" % name |
1482 return "Error: A bus named %s already exists\n" % name |
1483 elif child.BaseParams.getIEC_Channel() == iec_channel: |
1483 elif child.BaseParams.getIEC_Channel() == iec_channel: |
1484 return "Error: A bus with IEC_channel %d already exists\n" % iec_channel |
1484 return "Error: A bus with IEC_channel %d already exists\n" % iec_channel |
1485 bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel) |
1485 bus = self.CTR.PlugAddChild(name, "LPCBus", iec_channel) |
1486 if bus is None: |
1486 if bus is None: |
1487 return "Error: Unable to create bus\n" |
1487 return "Error: Unable to create bus\n" |
1488 bus.SetIcon(icon) |
1488 bus.SetIcon(icon) |
1489 self.RestartTimer() |
1489 self.RestartTimer() |
1490 |
1490 |
1491 def RenameBus(self, iec_channel, name): |
1491 def RenameBus(self, iec_channel, name): |
1492 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1492 bus = self.CTR.GetChildByIECLocation((iec_channel,)) |
1493 if bus is None: |
1493 if bus is None: |
1494 return "Error: No bus found\n" |
1494 return "Error: No bus found\n" |
1495 for child in self.PluginRoot.IterChilds(): |
1495 for child in self.CTR.IterChilds(): |
1496 if child != bus and child.BaseParams.getName() == name: |
1496 if child != bus and child.BaseParams.getName() == name: |
1497 return "Error: A bus named %s already exists\n" % name |
1497 return "Error: A bus named %s already exists\n" % name |
1498 bus.BaseParams.setName(name) |
1498 bus.BaseParams.setName(name) |
1499 self.RestartTimer() |
1499 self.RestartTimer() |
1500 |
1500 |
1501 def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel): |
1501 def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel): |
1502 bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,)) |
1502 bus = self.CTR.GetChildByIECLocation((old_iec_channel,)) |
1503 if bus is None: |
1503 if bus is None: |
1504 return "Error: No bus found\n" |
1504 return "Error: No bus found\n" |
1505 for child in self.PluginRoot.IterChilds(): |
1505 for child in self.CTR.IterChilds(): |
1506 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: |
1506 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel: |
1507 return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel |
1507 return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel |
1508 if wx.GetApp() is None: |
1508 if wx.GetApp() is None: |
1509 self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), |
1509 self.CTR.UpdateProjectVariableLocation(str(old_iec_channel), |
1510 str(new_iec_channel)) |
1510 str(new_iec_channel)) |
1511 else: |
1511 else: |
1512 self.PluginRoot.UpdateProjectVariableLocation( |
1512 self.CTR.UpdateProjectVariableLocation( |
1513 str(old_iec_channel), |
1513 str(old_iec_channel), |
1514 str(new_iec_channel)) |
1514 str(new_iec_channel)) |
1515 bus.BaseParams.setIEC_Channel(new_iec_channel) |
1515 bus.BaseParams.setIEC_Channel(new_iec_channel) |
1516 self.RestartTimer() |
1516 self.RestartTimer() |
1517 |
1517 |
1518 def RemoveBus(self, iec_channel): |
1518 def RemoveBus(self, iec_channel): |
1519 bus = self.PluginRoot.GetChildByIECLocation((iec_channel,)) |
1519 bus = self.CTR.GetChildByIECLocation((iec_channel,)) |
1520 if bus is None: |
1520 if bus is None: |
1521 return "Error: No bus found\n" |
1521 return "Error: No bus found\n" |
1522 self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel)) |
1522 self.CTR.RemoveProjectVariableByFilter(str(iec_channel)) |
1523 self.PluginRoot.PluggedChilds["LPCBus"].remove(bus) |
1523 self.CTR.PluggedChilds["LPCBus"].remove(bus) |
1524 self.RestartTimer() |
1524 self.RestartTimer() |
1525 |
1525 |
1526 def AddModule(self, parent, iec_channel, name, icode, icon=None): |
1526 def AddModule(self, parent, iec_channel, name, icode, icon=None): |
1527 module = self.PluginRoot.GetChildByIECLocation(parent) |
1527 module = self.CTR.GetChildByIECLocation(parent) |
1528 if module is None: |
1528 if module is None: |
1529 return "Error: No parent found\n" |
1529 return "Error: No parent found\n" |
1530 for child in _GetModuleChildren(module): |
1530 for child in _GetModuleChildren(module): |
1531 if child["name"] == name: |
1531 if child["name"] == name: |
1532 return "Error: A module named %s already exists\n" % name |
1532 return "Error: A module named %s already exists\n" % name |
1539 "init": icode, |
1539 "init": icode, |
1540 "children": []}) |
1540 "children": []}) |
1541 self.RestartTimer() |
1541 self.RestartTimer() |
1542 |
1542 |
1543 def RenameModule(self, iec_location, name): |
1543 def RenameModule(self, iec_location, name): |
1544 module = self.PluginRoot.GetChildByIECLocation(iec_location) |
1544 module = self.CTR.GetChildByIECLocation(iec_location) |
1545 if module is None: |
1545 if module is None: |
1546 return "Error: No module found\n" |
1546 return "Error: No module found\n" |
1547 parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1]) |
1547 parent = self.CTR.GetChildByIECLocation(iec_location[:-1]) |
1548 if parent is self.PluginRoot: |
1548 if parent is self.CTR: |
1549 return "Error: No module found\n" |
1549 return "Error: No module found\n" |
1550 if module["name"] != name: |
1550 if module["name"] != name: |
1551 for child in _GetModuleChildren(parent): |
1551 for child in _GetModuleChildren(parent): |
1552 if child["name"] == name: |
1552 if child["name"] == name: |
1553 return "Error: A module named %s already exists\n" % name |
1553 return "Error: A module named %s already exists\n" % name |
1554 module["name"] = name |
1554 module["name"] = name |
1555 self.RestartTimer() |
1555 self.RestartTimer() |
1556 |
1556 |
1557 def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel): |
1557 def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel): |
1558 module = self.PluginRoot.GetChildByIECLocation(old_iec_location) |
1558 module = self.CTR.GetChildByIECLocation(old_iec_location) |
1559 if module is None: |
1559 if module is None: |
1560 return "Error: No module found\n" |
1560 return "Error: No module found\n" |
1561 parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1]) |
1561 parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1]) |
1562 if parent is self.PluginRoot: |
1562 if parent is self.CTR: |
1563 return "Error: No module found\n" |
1563 return "Error: No module found\n" |
1564 if module["IEC_Channel"] != new_iec_channel: |
1564 if module["IEC_Channel"] != new_iec_channel: |
1565 for child in _GetModuleChildren(parent): |
1565 for child in _GetModuleChildren(parent): |
1566 if child["IEC_Channel"] == new_iec_channel: |
1566 if child["IEC_Channel"] == new_iec_channel: |
1567 return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel |
1567 return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel |
1568 self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) |
1568 self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,)))) |
1569 module["IEC_Channel"] = new_iec_channel |
1569 module["IEC_Channel"] = new_iec_channel |
1570 self.RestartTimer() |
1570 self.RestartTimer() |
1571 |
1571 |
1572 def ChangeModuleInitCode(self, iec_location, icode): |
1572 def ChangeModuleInitCode(self, iec_location, icode): |
1573 module = self.PluginRoot.GetChildByIECLocation(iec_location) |
1573 module = self.CTR.GetChildByIECLocation(iec_location) |
1574 if module is None: |
1574 if module is None: |
1575 return "Error: No module found\n" |
1575 return "Error: No module found\n" |
1576 module["init"] = icode |
1576 module["init"] = icode |
1577 |
1577 |
1578 def RemoveModule(self, parent, iec_channel): |
1578 def RemoveModule(self, parent, iec_channel): |
1579 module = self.PluginRoot.GetChildByIECLocation(parent) |
1579 module = self.CTR.GetChildByIECLocation(parent) |
1580 if module is None: |
1580 if module is None: |
1581 return "Error: No parent found\n" |
1581 return "Error: No parent found\n" |
1582 child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,)) |
1582 child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,)) |
1583 if child is None: |
1583 if child is None: |
1584 return "Error: No module found\n" |
1584 return "Error: No module found\n" |
1585 self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,)))) |
1585 self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,)))) |
1586 _RemoveModuleChild(module, child) |
1586 _RemoveModuleChild(module, child) |
1587 self.RestartTimer() |
1587 self.RestartTimer() |
1588 |
1588 |
1589 def StartGroup(self, parent, name, icon=None): |
1589 def StartGroup(self, parent, name, icon=None): |
1590 module = self.PluginRoot.GetChildByIECLocation(parent) |
1590 module = self.CTR.GetChildByIECLocation(parent) |
1591 if module is None: |
1591 if module is None: |
1592 return "Error: No parent found\n" |
1592 return "Error: No parent found\n" |
1593 for child in module["children"]: |
1593 for child in module["children"]: |
1594 if child["type"] == LOCATION_GROUP and child["name"] == name: |
1594 if child["type"] == LOCATION_GROUP and child["name"] == name: |
1595 return "Error: A group named %s already exists\n" % name |
1595 return "Error: A group named %s already exists\n" % name |
1628 elif child["name"] == new_name: |
1628 elif child["name"] == new_name: |
1629 return "Error: A variable named %s already exists\n" % new_name |
1629 return "Error: A variable named %s already exists\n" % new_name |
1630 if variable is None: |
1630 if variable is None: |
1631 return "Error: No variable found\n" |
1631 return "Error: No variable found\n" |
1632 if variable["name"] != new_name: |
1632 if variable["name"] != new_name: |
1633 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name) |
1633 self.CTR.UpdateProjectVariableName(variable["name"], new_name) |
1634 variable["name"] = new_name |
1634 variable["name"] = new_name |
1635 variable["type"] = LOCATION_TYPES[new_direction] |
1635 variable["type"] = LOCATION_TYPES[new_direction] |
1636 variable["IEC_type"] = new_type |
1636 variable["IEC_type"] = new_type |
1637 variable["retrieve"] = new_rcode |
1637 variable["retrieve"] = new_rcode |
1638 variable["publish"] = new_pcode |
1638 variable["publish"] = new_pcode |
1639 if new_description is not None: |
1639 if new_description is not None: |
1640 variable["description"] = new_description |
1640 variable["description"] = new_description |
1641 self.RestartTimer() |
1641 self.RestartTimer() |
1642 |
1642 |
1643 def RemoveVariable(self, parent, location, direction): |
1643 def RemoveVariable(self, parent, location, direction): |
1644 module = self.PluginRoot.GetChildByIECLocation(parent) |
1644 module = self.CTR.GetChildByIECLocation(parent) |
1645 if module is None: |
1645 if module is None: |
1646 return "Error: No parent found\n" |
1646 return "Error: No parent found\n" |
1647 child = _GetModuleVariable(module, location, direction) |
1647 child = _GetModuleVariable(module, location, direction) |
1648 if child is None: |
1648 if child is None: |
1649 return "Error: No variable found\n" |
1649 return "Error: No variable found\n" |
1650 size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])] |
1650 size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])] |
1651 address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location)) |
1651 address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location)) |
1652 self.PluginRoot.RemoveProjectVariableByAddress(address) |
1652 self.CTR.RemoveProjectVariableByAddress(address) |
1653 _RemoveModuleChild(module, child) |
1653 _RemoveModuleChild(module, child) |
1654 self.RestartTimer() |
1654 self.RestartTimer() |
1655 |
1655 |
1656 def location(loc): |
1656 def location(loc): |
1657 return tuple(map(int, loc.split("."))) |
1657 return tuple(map(int, loc.split("."))) |
1736 "AddVariable": ([location, location, str, str, str, str, str, str], 1), |
1736 "AddVariable": ([location, location, str, str, str, str, str, str], 1), |
1737 "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1), |
1737 "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1), |
1738 "RemoveVariable": ([location, location], 0)}.iteritems(): |
1738 "RemoveVariable": ([location, location], 0)}.iteritems(): |
1739 |
1739 |
1740 setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt)) |
1740 setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt)) |
1741 lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log) |
1741 lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log) |
1742 lpcberemiz_cmd.cmdloop() |
1742 lpcberemiz_cmd.cmdloop() |
1743 |
1743 |
1744 Log = StdoutPseudoFile(port) |
1744 Log = StdoutPseudoFile(port) |
1745 |
1745 |
1746 PluginRoot = LPCPluginsRoot(None, Log, buildpath) |
1746 CTR = LPCConfigTreeRoot(None, Log, buildpath) |
1747 if projectOpen is not None and os.path.isdir(projectOpen): |
1747 if projectOpen is not None and os.path.isdir(projectOpen): |
1748 result = PluginRoot.LoadProject(projectOpen) |
1748 result = CTR.LoadProject(projectOpen) |
1749 if result: |
1749 if result: |
1750 Log.write("Error: Invalid project directory", result) |
1750 Log.write("Error: Invalid project directory", result) |
1751 else: |
1751 else: |
1752 Log.write("Error: No such file or directory") |
1752 Log.write("Error: No such file or directory") |
1753 |
1753 |
1754 cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log]) |
1754 cmd_thread=Thread(target=CmdThreadProc, args=[CTR, Log]) |
1755 cmd_thread.start() |
1755 cmd_thread.start() |
1756 |
1756 |
1757 # Install a exception handle for bug reports |
1757 # Install a exception handle for bug reports |
1758 AddExceptHook(os.getcwd(),__version__) |
1758 AddExceptHook(os.getcwd(),__version__) |
1759 |
1759 |
1760 frame = LPCBeremiz(None, plugin_root=PluginRoot, debug=True) |
1760 frame = LPCBeremiz(None, ctr=CTR, debug=True) |
1761 |
1761 |
1762 app.MainLoop() |
1762 app.MainLoop() |
1763 |
1763 |