100 pass |
100 pass |
101 elif values[1] == "program": |
101 elif values[1] == "program": |
102 message = "Programs can't be used by other POUs!" |
102 message = "Programs can't be used by other POUs!" |
103 elif values[1] in ["function", "functionBlock", "program"]: |
103 elif values[1] in ["function", "functionBlock", "program"]: |
104 name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug) |
104 name, type = self.ParentWindow.Controler.GetEditedElementType(self.ParentWindow.GetTagName(), self.ParentWindow.Debug) |
|
105 words = self.ParentWindow.TagName.split("::") |
105 if name == values[0]: |
106 if name == values[0]: |
106 message = "\"%s\" can't use itself!"%name |
107 message = "\"%s\" can't use itself!"%name |
107 elif type == "function" and values[1] != "function": |
108 elif type == "function" and values[1] != "function": |
108 message = "Function Blocks can't be used by Functions!" |
109 message = "Function Blocks can't be used in Functions!" |
|
110 elif words[0] == "T" and values[1] != "function": |
|
111 message = "Function Blocks can't be used in Transitions!" |
109 elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug): |
112 elif self.ParentWindow.Controler.PouIsUsedBy(name, values[0], self.ParentWindow.Debug): |
110 message = "\"%s\" is already used by \"%s\"!"%(name, values[0]) |
113 message = "\"%s\" is already used by \"%s\"!"%(name, values[0]) |
111 else: |
114 else: |
112 blockname = values[2] |
115 blockname = values[2] |
113 if len(values) > 3: |
116 if len(values) > 3: |
349 self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp) |
352 self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp) |
350 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer) |
353 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer) |
351 self.Bind(wx.EVT_MOTION, self.OnViewerMotion) |
354 self.Bind(wx.EVT_MOTION, self.OnViewerMotion) |
352 self.Bind(wx.EVT_CHAR, self.OnChar) |
355 self.Bind(wx.EVT_CHAR, self.OnChar) |
353 self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow) |
356 self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow) |
|
357 self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow) |
354 self.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
358 self.Bind(wx.EVT_SIZE, self.OnMoveWindow) |
355 |
359 |
356 def GetScrolledRect(self, rect): |
360 def GetScrolledRect(self, rect): |
357 rect.x, rect.y = self.CalcScrolledPosition(rect.x, rect.y) |
361 rect.x, rect.y = self.CalcScrolledPosition(rect.x, rect.y) |
358 return rect |
362 return rect |
572 iec_path = "%s.%s.%s"%(self.InstancePath, block.GetName(), connectorname) |
580 iec_path = "%s.%s.%s"%(self.InstancePath, block.GetName(), connectorname) |
573 else: |
581 else: |
574 if connectorname == "": |
582 if connectorname == "": |
575 connectorname = "OUT" |
583 connectorname = "OUT" |
576 iec_path = "%s.%s%d_%s"%(self.InstancePath, block.GetType(), block.GetId(), connectorname) |
584 iec_path = "%s.%s%d_%s"%(self.InstancePath, block.GetType(), block.GetId(), connectorname) |
577 self.Subscribed[wire] = iec_path.upper() |
585 if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), wire) is not None: |
578 self.Controler.SubscribeDebugIECVariable(iec_path.upper(), wire) |
586 self.Subscribed[wire] = iec_path.upper() |
|
587 else: |
|
588 wire.SetValue("undefined") |
|
589 elif isinstance(block, FBD_Variable): |
|
590 iec_path = "%s.%s"%(self.InstancePath, block.GetName()) |
|
591 if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), wire) is not None: |
|
592 self.Subscribed[wire] = iec_path.upper() |
|
593 else: |
|
594 wire.SetValue("undefined") |
|
595 elif isinstance(block, FBD_Connector): |
|
596 wire.SetValue("undefined") |
579 |
597 |
580 if self.Debug: |
598 if self.Debug: |
581 for block in self.Blocks.keys(): |
599 for block in self.Blocks.keys(): |
582 if isinstance(block, (LD_Contact, LD_Coil)): |
600 block.SpreadCurrent() |
583 block.SetValue(False) |
|
584 block.SpreadCurrent() |
|
585 if isinstance(block, LD_Contact): |
601 if isinstance(block, LD_Contact): |
586 iec_path = "%s.%s"%(self.InstancePath, block.GetName()) |
602 iec_path = "%s.%s"%(self.InstancePath, block.GetName()) |
587 self.Subscribed[block] = iec_path.upper() |
603 if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None: |
588 self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) |
604 self.Subscribed[block] = iec_path.upper() |
589 |
605 elif isinstance(block, SFC_Step): |
|
606 iec_path = "%s.%s.X"%(self.InstancePath, block.GetName()) |
|
607 if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None: |
|
608 self.Subscribed[block] = iec_path.upper() |
|
609 elif isinstance(block, SFC_Transition): |
|
610 connectors = block.GetConnectors() |
|
611 previous_steps = self.GetPreviousSteps(connectors["input"]) |
|
612 next_steps = self.GetNextSteps(connectors["output"]) |
|
613 iec_path = "%s.%s->%s"%(self.InstancePath, ",".join(previous_steps), ",".join(next_steps)) |
|
614 if self.Controler.SubscribeDebugIECVariable(iec_path.upper(), block) is not None: |
|
615 self.Subscribed[block] = iec_path.upper() |
|
616 else: |
|
617 print "Unknown IEC_Path", iec_path |
|
618 |
590 self.RefreshVisibleElements() |
619 self.RefreshVisibleElements() |
591 self.ShowErrors() |
620 self.ShowErrors() |
592 self.Refresh(False) |
621 self.Refresh(False) |
|
622 |
|
623 def GetPreviousSteps(self, connector): |
|
624 steps = [] |
|
625 for wire, handle in connector.GetWires(): |
|
626 previous = wire.GetOtherConnected(connector).GetParentBlock() |
|
627 if isinstance(previous, SFC_Step): |
|
628 steps.append(previous.GetName()) |
|
629 elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]: |
|
630 connectors = previous.GetConnectors() |
|
631 for input in connectors["inputs"]: |
|
632 steps.extend(self.GetPreviousSteps(input)) |
|
633 return steps |
|
634 |
|
635 def GetNextSteps(self, connector): |
|
636 steps = [] |
|
637 for wire, handle in connector.GetWires(): |
|
638 next = wire.GetOtherConnected(connector).GetParentBlock() |
|
639 if isinstance(next, SFC_Step): |
|
640 steps.append(next.GetName()) |
|
641 elif isinstance(next, SFC_Jump): |
|
642 steps.append(next.GetTarget()) |
|
643 elif isinstance(next, SFC_Divergence) and next.GetType() in [SIMULTANEOUS_DIVERGENCE, SELECTION_CONVERGENCE]: |
|
644 connectors = next.GetConnectors() |
|
645 for output in connectors["outputs"]: |
|
646 steps.extend(self.GetNextSteps(output)) |
|
647 return steps |
593 |
648 |
594 def GetMaxSize(self): |
649 def GetMaxSize(self): |
595 maxx = maxy = 0 |
650 maxx = maxy = 0 |
596 for element in self.GetElements(): |
651 for element in self.GetElements(): |
597 bbox = element.GetBoundingBox() |
652 bbox = element.GetBoundingBox() |