Adding support for opening block debug view directly from parent debug view by double clicking on block
authorLaurent Bessard
Wed, 23 May 2012 10:36:18 +0200
changeset 694 b7c1914034f9
parent 693 4ecfbcc09bef
child 695 8848ffb7ae2a
Adding support for opening block debug view directly from parent debug view by double clicking on block
Viewer.py
--- a/Viewer.py	Tue May 22 10:14:24 2012 +0200
+++ b/Viewer.py	Wed May 23 10:36:18 2012 +0200
@@ -30,7 +30,7 @@
 import wx
 
 from plcopen.structures import *
-from PLCControler import ITEM_POU
+from PLCControler import ITEM_POU, ITEM_PROGRAM, ITEM_FUNCTIONBLOCK
 
 from dialogs import *
 from graphics import *
@@ -833,7 +833,7 @@
                     connector = connection.GetConnector()
                     if len(connector.Wires) == 1:
                         iec_path = self.GetElementIECPath(connector.Wires[0][0])
-        elif isinstance(element, LD_Contact):
+        elif isinstance(element, (LD_Contact, FBD_Block)):
             iec_path = "%s.%s"%(self.InstancePath, element.GetName())
         elif isinstance(element, SFC_Step):
             iec_path = "%s.%s.X"%(self.InstancePath, element.GetName())
@@ -1714,19 +1714,32 @@
     def OnViewerLeftDClick(self, event):
         if self.Mode == MODE_SELECTION and self.SelectedElement is not None:
             if self.Debug:
-                iec_path = self.GetElementIECPath(self.SelectedElement)
-                if iec_path is not None:
-                    if isinstance(self.SelectedElement, Wire):
-                        if self.SelectedElement.EndConnected is not None:
-                            var_type = self.SelectedElement.EndConnected.GetType()
-                            if self.Controler.IsOfType(var_type, "ANY_NUM", self.Debug) or\
-                               self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug):
-                                self.ParentWindow.OpenGraphicViewer(iec_path)
-                    else:
-                        self.ParentWindow.OpenGraphicViewer(iec_path)
+                if self.IsBlock(self.SelectedElement):
+                    instance_type = self.SelectedElement.GetType()
+                    pou_type = {
+                        "program": ITEM_PROGRAM,
+                        "functionBlock": ITEM_FUNCTIONBLOCK,
+                    }.get(self.Controler.GetPouType(instance_type))
+                    if pou_type is not None and instance_type in self.Controler.GetProjectPouNames(self.Debug):
+                        self.ParentWindow.OpenDebugViewer(pou_type, 
+                            self.GetElementIECPath(self.SelectedElement),
+                            self.Controler.ComputePouName(instance_type))
+                else:
+                    iec_path = self.GetElementIECPath(self.SelectedElement)
+                    if iec_path is not None:
+                        if isinstance(self.SelectedElement, Wire):
+                            if self.SelectedElement.EndConnected is not None:
+                                var_type = self.SelectedElement.EndConnected.GetType()
+                                if self.Controler.IsOfType(var_type, "ANY_NUM", self.Debug) or\
+                                   self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug):
+                                    self.ParentWindow.OpenGraphicViewer(iec_path)
+                        else:
+                            self.ParentWindow.OpenGraphicViewer(iec_path)
             elif event.ControlDown() and not event.ShiftDown():
-                if self.IsBlock(self.SelectedElement) and self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug):
-                    self.ParentWindow.EditProjectElement(ITEM_POU, self.Controler.ComputePouName(self.SelectedElement.GetType()))
+                instance_type = self.SelectedElement.GetType()
+                if self.IsBlock(self.SelectedElement) and instance_type in self.Controler.GetProjectPouNames(self.Debug):
+                    self.ParentWindow.EditProjectElement(ITEM_POU, 
+                        self.Controler.ComputePouName(instance_type))
                 else:
                     self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
             elif event.ControlDown() and event.ShiftDown():