editors/LDViewer.py
changeset 2437 105c20fdeb19
parent 2432 dbc065a2f7a5
child 2450 5024c19ca8f0
equal deleted inserted replaced
2436:82bfc75bcd9d 2437:105c20fdeb19
    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 __future__ import division
    27 from types import *
    28 from types import *
    28 
    29 
    29 import wx
    30 import wx
    30 from six.moves import xrange
    31 from six.moves import xrange
    31 
    32 
   158             else:
   159             else:
   159                 element_tree[element]["weight"] = None
   160                 element_tree[element]["weight"] = None
   160                 return
   161                 return
   161         if not parts:
   162         if not parts:
   162             parts = 1
   163             parts = 1
   163         element_tree[element]["weight"] = max(1, weight / parts)
   164         element_tree[element]["weight"] = max(1, weight // parts)
   164 
   165 
   165 
   166 
   166 # -------------------------------------------------------------------------------
   167 # -------------------------------------------------------------------------------
   167 #                     Ladder Diagram Graphic elements Viewer class
   168 #                     Ladder Diagram Graphic elements Viewer class
   168 # -------------------------------------------------------------------------------
   169 # -------------------------------------------------------------------------------
   455             id = self.GetNewId()
   456             id = self.GetNewId()
   456             if var_class == INPUT:
   457             if var_class == INPUT:
   457                 contact = LD_Contact(self, CONTACT_NORMAL, var_name, id)
   458                 contact = LD_Contact(self, CONTACT_NORMAL, var_name, id)
   458                 width, height = contact.GetMinSize()
   459                 width, height = contact.GetMinSize()
   459                 if scaling is not None:
   460                 if scaling is not None:
   460                     x = round(float(x) / float(scaling[0])) * scaling[0]
   461                     x = round(x / scaling[0]) * scaling[0]
   461                     y = round(float(y) / float(scaling[1])) * scaling[1]
   462                     y = round(y / scaling[1]) * scaling[1]
   462                     width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
   463                     width = round(width / scaling[0] + 0.5) * scaling[0]
   463                     height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
   464                     height = round(height / scaling[1] + 0.5) * scaling[1]
   464                 contact.SetPosition(x, y)
   465                 contact.SetPosition(x, y)
   465                 contact.SetSize(width, height)
   466                 contact.SetSize(width, height)
   466                 self.AddBlock(contact)
   467                 self.AddBlock(contact)
   467                 self.Controler.AddEditedElementContact(self.GetTagName(), id)
   468                 self.Controler.AddEditedElementContact(self.GetTagName(), id)
   468                 self.RefreshContactModel(contact)
   469                 self.RefreshContactModel(contact)
   469             else:
   470             else:
   470                 coil = LD_Coil(self, COIL_NORMAL, var_name, id)
   471                 coil = LD_Coil(self, COIL_NORMAL, var_name, id)
   471                 width, height = coil.GetMinSize()
   472                 width, height = coil.GetMinSize()
   472                 if scaling is not None:
   473                 if scaling is not None:
   473                     x = round(float(x) / float(scaling[0])) * scaling[0]
   474                     x = round(x / scaling[0]) * scaling[0]
   474                     y = round(float(y) / float(scaling[1])) * scaling[1]
   475                     y = round(y / scaling[1]) * scaling[1]
   475                     width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
   476                     width = round(width / scaling[0] + 0.5) * scaling[0]
   476                     height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
   477                     height = round(height / scaling[1] + 0.5) * scaling[1]
   477                 coil.SetPosition(x, y)
   478                 coil.SetPosition(x, y)
   478                 coil.SetSize(width, height)
   479                 coil.SetSize(width, height)
   479                 self.AddBlock(coil)
   480                 self.AddBlock(coil)
   480                 self.Controler.AddEditedElementCoil(self.GetTagName(), id)
   481                 self.Controler.AddEditedElementCoil(self.GetTagName(), id)
   481                 self.RefreshCoilModel(coil)
   482                 self.RefreshCoilModel(coil)
   535             self.RefreshPowerRailModel(leftpowerrail)
   536             self.RefreshPowerRailModel(leftpowerrail)
   536 
   537 
   537             # Create Coil
   538             # Create Coil
   538             id = self.GetNewId()
   539             id = self.GetNewId()
   539             coil = LD_Coil(self, values["type"], values["name"], id)
   540             coil = LD_Coil(self, values["type"], values["name"], id)
   540             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)
   541             coil_connectors = coil.GetConnectors()
   542             coil_connectors = coil.GetConnectors()
   542             self.AddBlock(coil)
   543             self.AddBlock(coil)
   543             rung.SelectElement(coil)
   544             rung.SelectElement(coil)
   544             self.Controler.AddEditedElementCoil(self.TagName, id)
   545             self.Controler.AddEditedElementCoil(self.TagName, id)
   545 
   546 
   604             if dialog.ShowModal() == wx.ID_OK:
   605             if dialog.ShowModal() == wx.ID_OK:
   605                 values = dialog.GetValues()
   606                 values = dialog.GetValues()
   606                 points = wires[0].GetSelectedSegmentPoints()
   607                 points = wires[0].GetSelectedSegmentPoints()
   607                 id = self.GetNewId()
   608                 id = self.GetNewId()
   608                 contact = LD_Contact(self, values["type"], values["name"], id)
   609                 contact = LD_Contact(self, values["type"], values["name"], id)
   609                 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)
   610                 self.AddBlock(contact)
   611                 self.AddBlock(contact)
   611                 self.Controler.AddEditedElementContact(self.TagName, id)
   612                 self.Controler.AddEditedElementContact(self.TagName, id)
   612                 rungindex = self.FindRung(wires[0])
   613                 rungindex = self.FindRung(wires[0])
   613                 rung = self.Rungs[rungindex]
   614                 rung = self.Rungs[rungindex]
   614                 old_bbox = rung.GetBoundingBox()
   615                 old_bbox = rung.GetBoundingBox()