108 if values[1] != "function" and blockname == "": |
108 if values[1] != "function" and blockname == "": |
109 dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) |
109 dialog = wx.TextEntryDialog(self.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE) |
110 if dialog.ShowModal(): |
110 if dialog.ShowModal(): |
111 blockname = dialog.GetValue() |
111 blockname = dialog.GetValue() |
112 dialog.Destroy() |
112 dialog.Destroy() |
113 id = self.ParentWindow.GetNewId() |
113 if blockname.upper() not in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames()]: |
114 block = FBD_Block(self.ParentWindow, values[0], blockname, id) |
114 message = wx.MessageDialog(self.ParentWindow, "\"%s\" pou already exists!"%blockname, "Error", wx.OK|wx.ICON_ERROR) |
115 width, height = block.GetMinSize() |
115 message.ShowModal() |
116 if scaling is not None: |
116 message.Destroy() |
117 x = round(float(x) / float(scaling[0])) * scaling[0] |
117 elif blockname.upper() not in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(self.ParentWindow.GetTagName())]: |
118 y = round(float(y) / float(scaling[1])) * scaling[1] |
118 message = wx.MessageDialog(self.ParentWindow, "\"%s\" element for this pou already exists!"%blockname, "Error", wx.OK|wx.ICON_ERROR) |
119 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
119 message.ShowModal() |
120 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
120 message.Destroy() |
121 block.SetPosition(x, y) |
121 else: |
122 block.SetSize(width, height) |
122 id = self.ParentWindow.GetNewId() |
123 self.ParentWindow.AddBlock(block) |
123 block = FBD_Block(self.ParentWindow, values[0], blockname, id) |
124 self.ParentWindow.Controler.AddEditedElementBlock(self.ParentWindow.GetTagName(), id, values[0], blockname) |
124 width, height = block.GetMinSize() |
125 self.ParentWindow.RefreshBlockModel(block) |
125 if scaling is not None: |
126 self.ParentWindow.RefreshBuffer() |
126 x = round(float(x) / float(scaling[0])) * scaling[0] |
127 self.ParentWindow.RefreshScrollBars() |
127 y = round(float(y) / float(scaling[1])) * scaling[1] |
128 self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName()) |
128 width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0] |
129 self.ParentWindow.Refresh(False) |
129 height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1] |
|
130 block.SetPosition(x, y) |
|
131 block.SetSize(width, height) |
|
132 self.ParentWindow.AddBlock(block) |
|
133 self.ParentWindow.Controler.AddEditedElementBlock(self.ParentWindow.GetTagName(), id, values[0], blockname) |
|
134 self.ParentWindow.RefreshBlockModel(block) |
|
135 self.ParentWindow.RefreshBuffer() |
|
136 self.ParentWindow.RefreshScrollBars() |
|
137 self.ParentWindow.ParentWindow.RefreshVariablePanel(self.ParentWindow.GetTagName()) |
|
138 self.ParentWindow.Refresh(False) |
130 elif values[1] != "location": |
139 elif values[1] != "location": |
131 if values[3] == self.ParentWindow.GetTagName(): |
140 if values[3] == self.ParentWindow.GetTagName(): |
132 id = self.ParentWindow.GetNewId() |
141 id = self.ParentWindow.GetNewId() |
133 if values[1] == "Output": |
142 if values[1] == "Output": |
134 var_type = OUTPUT |
143 var_type = OUTPUT |
286 self._init_coll_ContextualMenu_Items(self.ContextualMenu) |
295 self._init_coll_ContextualMenu_Items(self.ContextualMenu) |
287 |
296 |
288 # Create a new Viewer |
297 # Create a new Viewer |
289 def __init__(self, parent, tagname, window, controler): |
298 def __init__(self, parent, tagname, window, controler): |
290 wx.ScrolledWindow.__init__(self, parent, pos=wx.Point(0, 0), size=wx.Size(0, 0), |
299 wx.ScrolledWindow.__init__(self, parent, pos=wx.Point(0, 0), size=wx.Size(0, 0), |
291 style=wx.SUNKEN_BORDER | wx.HSCROLL | wx.VSCROLL) |
300 style=wx.HSCROLL | wx.VSCROLL) |
292 self._init_menus() |
301 self._init_menus() |
293 # Adding a rubberband to Viewer |
302 # Adding a rubberband to Viewer |
294 self.rubberBand = RubberBand(drawingSurface=self) |
303 self.rubberBand = RubberBand(drawingSurface=self) |
295 self.SetBackgroundColour(wx.Colour(255,255,255)) |
304 self.SetBackgroundColour(wx.Colour(255,255,255)) |
296 self.ResetView() |
305 self.ResetView() |
758 block.SetPosition(instance["x"], instance["y"]) |
767 block.SetPosition(instance["x"], instance["y"]) |
759 block.SetSize(instance["width"], instance["height"]) |
768 block.SetSize(instance["width"], instance["height"]) |
760 self.AddBlock(block) |
769 self.AddBlock(block) |
761 connectors = block.GetConnectors() |
770 connectors = block.GetConnectors() |
762 for i, input_connector in enumerate(instance["connectors"]["inputs"]): |
771 for i, input_connector in enumerate(instance["connectors"]["inputs"]): |
763 connector = connectors["inputs"][i] |
772 if i < len(connectors["inputs"]): |
764 connector.SetPosition(wx.Point(*input_connector["position"])) |
773 connector = connectors["inputs"][i] |
765 if input_connector["negated"]: |
774 connector.SetPosition(wx.Point(*input_connector["position"])) |
766 connector.SetNegated(True) |
775 if input_connector["negated"]: |
767 if input_connector["edge"] != "none": |
776 connector.SetNegated(True) |
768 connector.SetEdge(input_connector["edge"]) |
777 if input_connector["edge"] != "none": |
769 self.CreateWires(connector, input_connector["links"], ids) |
778 connector.SetEdge(input_connector["edge"]) |
|
779 self.CreateWires(connector, input_connector["links"], ids) |
770 for i, output_connector in enumerate(instance["connectors"]["outputs"]): |
780 for i, output_connector in enumerate(instance["connectors"]["outputs"]): |
771 connector = connectors["outputs"][i] |
781 if i < len(connectors["outputs"]): |
772 if output_connector["negated"]: |
782 connector = connectors["outputs"][i] |
773 connector.SetNegated(True) |
783 if output_connector["negated"]: |
774 if output_connector["edge"] != "none": |
784 connector.SetNegated(True) |
775 connector.SetEdge(output_connector["edge"]) |
785 if output_connector["edge"] != "none": |
776 connector.SetPosition(wx.Point(*output_connector["position"])) |
786 connector.SetEdge(output_connector["edge"]) |
|
787 connector.SetPosition(wx.Point(*output_connector["position"])) |
777 |
788 |
778 def CreateWires(self, start_connector, links, ids): |
789 def CreateWires(self, start_connector, links, ids): |
779 for link in links: |
790 for link in links: |
780 refLocalId = link["refLocalId"] |
791 refLocalId = link["refLocalId"] |
781 if refLocalId != None: |
792 if refLocalId != None: |