editors/LDViewer.py
changeset 2459 21164625b393
parent 2457 9deec258ab1a
child 3750 f62625418bff
equal deleted inserted replaced
2458:2a70d5240300 2459:21164625b393
    22 # along with this program; if not, write to the Free Software
    22 # along with this program; if not, write to the Free Software
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    24 
    24 
    25 
    25 
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
    27 from types import *
    27 from __future__ import division
       
    28 from future.builtins import round
    28 
    29 
    29 import wx
    30 import wx
       
    31 from six.moves import xrange
    30 
    32 
    31 from editors.Viewer import *
    33 from editors.Viewer import *
    32 
    34 
    33 
    35 
    34 def ExtractNextBlocks(block, block_list):
    36 def ExtractNextBlocks(block, block_list):
   157             else:
   159             else:
   158                 element_tree[element]["weight"] = None
   160                 element_tree[element]["weight"] = None
   159                 return
   161                 return
   160         if not parts:
   162         if not parts:
   161             parts = 1
   163             parts = 1
   162         element_tree[element]["weight"] = max(1, weight / parts)
   164         element_tree[element]["weight"] = max(1, weight // parts)
   163 
   165 
   164 
   166 
   165 # -------------------------------------------------------------------------------
   167 # -------------------------------------------------------------------------------
   166 #                     Ladder Diagram Graphic elements Viewer class
   168 #                     Ladder Diagram Graphic elements Viewer class
   167 # -------------------------------------------------------------------------------
   169 # -------------------------------------------------------------------------------
   454             id = self.GetNewId()
   456             id = self.GetNewId()
   455             if var_class == INPUT:
   457             if var_class == INPUT:
   456                 contact = LD_Contact(self, CONTACT_NORMAL, var_name, id)
   458                 contact = LD_Contact(self, CONTACT_NORMAL, var_name, id)
   457                 width, height = contact.GetMinSize()
   459                 width, height = contact.GetMinSize()
   458                 if scaling is not None:
   460                 if scaling is not None:
   459                     x = round(float(x) / float(scaling[0])) * scaling[0]
   461                     x = round(x / scaling[0]) * scaling[0]
   460                     y = round(float(y) / float(scaling[1])) * scaling[1]
   462                     y = round(y / scaling[1]) * scaling[1]
   461                     width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
   463                     width = round(width / scaling[0] + 0.5) * scaling[0]
   462                     height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
   464                     height = round(height / scaling[1] + 0.5) * scaling[1]
   463                 contact.SetPosition(x, y)
   465                 contact.SetPosition(x, y)
   464                 contact.SetSize(width, height)
   466                 contact.SetSize(width, height)
   465                 self.AddBlock(contact)
   467                 self.AddBlock(contact)
   466                 self.Controler.AddEditedElementContact(self.GetTagName(), id)
   468                 self.Controler.AddEditedElementContact(self.GetTagName(), id)
   467                 self.RefreshContactModel(contact)
   469                 self.RefreshContactModel(contact)
   468             else:
   470             else:
   469                 coil = LD_Coil(self, COIL_NORMAL, var_name, id)
   471                 coil = LD_Coil(self, COIL_NORMAL, var_name, id)
   470                 width, height = coil.GetMinSize()
   472                 width, height = coil.GetMinSize()
   471                 if scaling is not None:
   473                 if scaling is not None:
   472                     x = round(float(x) / float(scaling[0])) * scaling[0]
   474                     x = round(x / scaling[0]) * scaling[0]
   473                     y = round(float(y) / float(scaling[1])) * scaling[1]
   475                     y = round(y / scaling[1]) * scaling[1]
   474                     width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
   476                     width = round(width / scaling[0] + 0.5) * scaling[0]
   475                     height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
   477                     height = round(height / scaling[1] + 0.5) * scaling[1]
   476                 coil.SetPosition(x, y)
   478                 coil.SetPosition(x, y)
   477                 coil.SetSize(width, height)
   479                 coil.SetSize(width, height)
   478                 self.AddBlock(coil)
   480                 self.AddBlock(coil)
   479                 self.Controler.AddEditedElementCoil(self.GetTagName(), id)
   481                 self.Controler.AddEditedElementCoil(self.GetTagName(), id)
   480                 self.RefreshCoilModel(coil)
   482                 self.RefreshCoilModel(coil)
   534             self.RefreshPowerRailModel(leftpowerrail)
   536             self.RefreshPowerRailModel(leftpowerrail)
   535 
   537 
   536             # Create Coil
   538             # Create Coil
   537             id = self.GetNewId()
   539             id = self.GetNewId()
   538             coil = LD_Coil(self, values["type"], values["name"], id)
   540             coil = LD_Coil(self, values["type"], values["name"], id)
   539             coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2)
   541             coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) // 2)
   540             coil_connectors = coil.GetConnectors()
   542             coil_connectors = coil.GetConnectors()
   541             self.AddBlock(coil)
   543             self.AddBlock(coil)
   542             rung.SelectElement(coil)
   544             rung.SelectElement(coil)
   543             self.Controler.AddEditedElementCoil(self.TagName, id)
   545             self.Controler.AddEditedElementCoil(self.TagName, id)
   544 
   546 
   603             if dialog.ShowModal() == wx.ID_OK:
   605             if dialog.ShowModal() == wx.ID_OK:
   604                 values = dialog.GetValues()
   606                 values = dialog.GetValues()
   605                 points = wires[0].GetSelectedSegmentPoints()
   607                 points = wires[0].GetSelectedSegmentPoints()
   606                 id = self.GetNewId()
   608                 id = self.GetNewId()
   607                 contact = LD_Contact(self, values["type"], values["name"], id)
   609                 contact = LD_Contact(self, values["type"], values["name"], id)
   608                 contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) / 2)
   610                 contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) // 2)
   609                 self.AddBlock(contact)
   611                 self.AddBlock(contact)
   610                 self.Controler.AddEditedElementContact(self.TagName, id)
   612                 self.Controler.AddEditedElementContact(self.TagName, id)
   611                 rungindex = self.FindRung(wires[0])
   613                 rungindex = self.FindRung(wires[0])
   612                 rung = self.Rungs[rungindex]
   614                 rung = self.Rungs[rungindex]
   613                 old_bbox = rung.GetBoundingBox()
   615                 old_bbox = rung.GetBoundingBox()