427 |
427 |
428 |
428 |
429 |
429 |
430 class DebugInstanceName(DebugDataConsumer): |
430 class DebugInstanceName(DebugDataConsumer): |
431 VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")} |
431 VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")} |
432 |
432 |
433 def __init__(self, parent): |
433 def __init__(self, parent): |
434 DebugDataConsumer.__init__(self) |
434 DebugDataConsumer.__init__(self) |
435 self.Parent = parent |
435 self.Parent = parent |
436 self.ActionLastState = None |
436 self.ActionLastState = None |
437 self.ActionState = None |
437 self.ActionState = None |
438 self.x_offset = 2 |
438 self.x_offset = 2 |
439 self.y_offset = 2 |
439 self.y_offset = 2 |
440 |
440 |
441 def SetValue(self, value): |
441 def SetValue(self, value): |
442 self.ActionState = value |
442 self.ActionState = value |
443 if self.ActionState != self.ActionLastState: |
443 if self.ActionState != self.ActionLastState: |
444 self.ActionLastState = self.ActionState |
444 self.ActionLastState = self.ActionState |
445 wx.CallAfter(self.Parent.ElementNeedRefresh, self) |
445 wx.CallAfter(self.Parent.ElementNeedRefresh, self) |
446 |
446 |
447 def GetInstanceName(self): |
447 def GetInstanceName(self): |
448 return _("Debug: %s") % self.Parent.InstancePath |
448 return _("Debug: %s") % self.Parent.InstancePath |
449 |
449 |
450 def GetRedrawRect(self): |
450 def GetRedrawRect(self): |
451 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
451 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
452 dc = self.Parent.GetLogicalDC() |
452 dc = self.Parent.GetLogicalDC() |
453 ipw, iph = dc.GetTextExtent(self.GetInstanceName()) |
453 ipw, iph = dc.GetTextExtent(self.GetInstanceName()) |
454 vw, vh = 0, 0 |
454 vw, vh = 0, 0 |
455 for value in self.VALUE_TRANSLATION.itervalues(): |
455 for value in self.VALUE_TRANSLATION.itervalues(): |
456 w, h = dc.GetTextExtent(" (%s)" % value) |
456 w, h = dc.GetTextExtent(" (%s)" % value) |
460 |
460 |
461 def Draw(self, dc): |
461 def Draw(self, dc): |
462 scalex, scaley = dc.GetUserScale() |
462 scalex, scaley = dc.GetUserScale() |
463 dc.SetUserScale(1, 1) |
463 dc.SetUserScale(1, 1) |
464 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
464 x, y = self.Parent.CalcUnscrolledPosition(self.x_offset, self.y_offset) |
465 |
465 |
466 text = self.GetInstanceName() |
466 text = self.GetInstanceName() |
467 if self.ActionState is not None: |
467 if self.ActionState is not None: |
468 text += " (" |
468 text += " (" |
469 |
469 |
470 dc.DrawText(text, x, y) |
470 dc.DrawText(text, x, y) |
471 tw, th = dc.GetTextExtent(text) |
471 tw, th = dc.GetTextExtent(text) |
472 if self.ActionState is not None: |
472 if self.ActionState is not None: |
473 |
473 |
474 text = self.VALUE_TRANSLATION[self.ActionState] |
474 text = self.VALUE_TRANSLATION[self.ActionState] |
475 if self.ActionState: |
475 if self.ActionState: |
476 dc.SetTextForeground(wx.GREEN) |
476 dc.SetTextForeground(wx.GREEN) |
477 dc.DrawText(text, x + tw, y) |
477 dc.DrawText(text, x + tw, y) |
478 if self.ActionState: |
478 if self.ActionState: |
479 dc.SetTextForeground(wx.BLACK) |
479 dc.SetTextForeground(wx.BLACK) |
480 tw = tw + dc.GetTextExtent(text)[0] |
480 tw = tw + dc.GetTextExtent(text)[0] |
481 |
481 |
482 text = ")" |
482 text = ")" |
483 dc.DrawText(text, x + tw, y) |
483 dc.DrawText(text, x + tw, y) |
484 dc.SetUserScale(scalex, scaley) |
484 dc.SetUserScale(scalex, scaley) |
485 |
485 |
486 """ |
486 """ |
487 Class that implements a Viewer based on a wx.ScrolledWindow for drawing and |
487 Class that implements a Viewer based on a wx.ScrolledWindow for drawing and |
953 if isinstance(block, FBD_Connector) and\ |
953 if isinstance(block, FBD_Connector) and\ |
954 block.GetType() == CONTINUATION and\ |
954 block.GetType() == CONTINUATION and\ |
955 block.GetName() == name: |
955 block.GetName() == name: |
956 blocks.append(block) |
956 blocks.append(block) |
957 return blocks |
957 return blocks |
958 |
958 |
959 def GetConnectorByName(self, name): |
959 def GetConnectorByName(self, name): |
960 for block in self.Blocks.itervalues(): |
960 for block in self.Blocks.itervalues(): |
961 if isinstance(block, FBD_Connector) and\ |
961 if isinstance(block, FBD_Connector) and\ |
962 block.GetType() == CONNECTOR and\ |
962 block.GetType() == CONNECTOR and\ |
963 block.GetName() == name: |
963 block.GetName() == name: |
1220 |
1220 |
1221 self.RefreshScrollBars() |
1221 self.RefreshScrollBars() |
1222 |
1222 |
1223 if self.TagName.split("::")[0] == "A" and self.Debug: |
1223 if self.TagName.split("::")[0] == "A" and self.Debug: |
1224 self.AddDataConsumer("%s.Q" % self.InstancePath.upper(), self.InstanceName) |
1224 self.AddDataConsumer("%s.Q" % self.InstancePath.upper(), self.InstanceName) |
1225 |
1225 |
1226 for wire in self.Wires: |
1226 for wire in self.Wires: |
1227 if not wire.IsConnectedCompatible(): |
1227 if not wire.IsConnectedCompatible(): |
1228 wire.SetValid(False) |
1228 wire.SetValid(False) |
1229 if self.Debug: |
1229 if self.Debug: |
1230 iec_path = self.GetElementIECPath(wire) |
1230 iec_path = self.GetElementIECPath(wire) |
1524 def FindBlockConnector(self, pos, direction = None, exclude = None): |
1524 def FindBlockConnector(self, pos, direction = None, exclude = None): |
1525 result, error = self.FindBlockConnectorWithError(pos, direction, exclude) |
1525 result, error = self.FindBlockConnectorWithError(pos, direction, exclude) |
1526 return result |
1526 return result |
1527 |
1527 |
1528 def FindBlockConnectorWithError(self, pos, direction = None, exclude = None): |
1528 def FindBlockConnectorWithError(self, pos, direction = None, exclude = None): |
1529 error = False |
1529 error = False |
1530 startblock = None |
1530 startblock = None |
1531 for block in self.Blocks.itervalues(): |
1531 for block in self.Blocks.itervalues(): |
1532 connector = block.TestConnector(pos, direction, exclude) |
1532 connector = block.TestConnector(pos, direction, exclude) |
1533 if connector: |
1533 if connector: |
1534 if self.IsWire(self.SelectedElement): |
1534 if self.IsWire(self.SelectedElement): |
1537 if not avail or not self.BlockCompatibility(startblock, block, direction): |
1537 if not avail or not self.BlockCompatibility(startblock, block, direction): |
1538 connector = None |
1538 connector = None |
1539 error = True |
1539 error = True |
1540 return connector, error |
1540 return connector, error |
1541 return None, error |
1541 return None, error |
1542 |
1542 |
1543 def FindElementById(self, id): |
1543 def FindElementById(self, id): |
1544 block = self.Blocks.get(id, None) |
1544 block = self.Blocks.get(id, None) |
1545 if block is not None: |
1545 if block is not None: |
1546 return block |
1546 return block |
1547 comment = self.Comments.get(id, None) |
1547 comment = self.Comments.get(id, None) |
2583 wire.GetStartConnectedType()): |
2583 wire.GetStartConnectedType()): |
2584 connector = input_connector |
2584 connector = input_connector |
2585 break |
2585 break |
2586 self.AddNewElement(block, bbox, wire, connector) |
2586 self.AddNewElement(block, bbox, wire, connector) |
2587 self.RefreshVariablePanel() |
2587 self.RefreshVariablePanel() |
2588 self.ParentWindow.RefreshPouInstanceVariablesPanel() |
2588 self.ParentWindow.RefreshPouInstanceVariablesPanel() |
2589 dialog.Destroy() |
2589 dialog.Destroy() |
2590 |
2590 |
2591 def AddNewVariable(self, bbox, exclude_input=False, wire=None): |
2591 def AddNewVariable(self, bbox, exclude_input=False, wire=None): |
2592 dialog = FBDVariableDialog(self.ParentWindow, self.Controler, self.TagName, exclude_input) |
2592 dialog = FBDVariableDialog(self.ParentWindow, self.Controler, self.TagName, exclude_input) |
2593 dialog.SetPreviewFont(self.GetFont()) |
2593 dialog.SetPreviewFont(self.GetFont()) |