--- a/graphics/LD_Objects.py Tue Jul 17 12:25:50 2007 +0200
+++ b/graphics/LD_Objects.py Wed Jul 18 11:51:30 2007 +0200
@@ -59,16 +59,22 @@
# Forbids to change the power rail size
def SetSize(self, width, height):
- if isinstance(self.Parent, wxPanel) or self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+ if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
Graphic_Element.SetSize(self, width, height)
self.RefreshConnectors()
# Forbids to select a power rail
def HitTest(self, pt):
- if isinstance(self.Parent, wxPanel) or self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+ if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
return Graphic_Element.HitTest(self, pt) or self.TestConnector(pt, False) != None
return False
+ # Forbids to select a power rail
+ def IsInSelection(self, rect):
+ if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+ return Graphic_Element.IsInSelection(rect)
+ return False
+
# Deletes this power rail by calling the appropriate method
def Delete(self):
self.Parent.DeletePowerRail(self)
@@ -301,6 +307,8 @@
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wxPoint(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wxPoint(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.RefreshNameSize()
+ self.RefreshTypeSize()
# Destructor
def __del__(self):
@@ -309,7 +317,7 @@
# Forbids to change the contact size
def SetSize(self, width, height):
- if isinstance(self.Parent, wxPanel) or self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+ if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
Graphic_Element.SetSize(self, width, height)
self.RefreshConnectors()
@@ -322,6 +330,29 @@
self.Input.UnConnect()
self.Output.UnConnect()
+ # Refresh the size of text for name
+ def RefreshNameSize(self):
+ dc = wxClientDC(self.Parent)
+ if self.Name != "":
+ self.NameSize = dc.GetTextExtent(self.Name)
+ else:
+ self.NameSize = 0, 0
+
+ # Refresh the size of text for type
+ def RefreshTypeSize(self):
+ dc = wxClientDC(self.Parent)
+ typetext = ""
+ if self.Type == CONTACT_REVERSE:
+ typetext = "/"
+ elif self.Type == CONTACT_RISING:
+ typetext = "P"
+ elif self.Type == CONTACT_FALLING:
+ typetext = "N"
+ if typetext != "":
+ self.TypeSize = dc.GetTextExtent(typetext)
+ else:
+ self.TypeSize = 0, 0
+
# Refresh the contact bounding box
def RefreshBoundingBox(self):
dc = wxClientDC(self.Parent)
@@ -391,6 +422,7 @@
# Changes the contact name
def SetName(self, name):
self.Name = name
+ self.RefreshNameSize()
# Returns the contact name
def GetName(self):
@@ -424,9 +456,8 @@
dc.DrawRectangle(self.Pos.x, self.Pos.y, 2, self.Size[1] + 1)
dc.DrawRectangle(self.Pos.x + self.Size[0] - 1, self.Pos.y, 2, self.Size[1] + 1)
# Draw contact name
- namewidth, nameheight = dc.GetTextExtent(self.Name)
- dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2,
- self.Pos.y - (nameheight + 2))
+ dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2,
+ self.Pos.y - (self.NameSize[1] + 2))
# Draw the modifier symbol in the middle of contact
typetext = ""
if self.Type == CONTACT_REVERSE:
@@ -436,9 +467,8 @@
elif self.Type == CONTACT_FALLING:
typetext = "N"
if typetext != "":
- typewidth, typeheight = dc.GetTextExtent(typetext)
- dc.DrawText(typetext, self.Pos.x + (self.Size[0] - typewidth) / 2 + 1,
- self.Pos.y + (self.Size[1] - typeheight) / 2)
+ dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1,
+ self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2)
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)
@@ -465,6 +495,8 @@
# Create an input and output connector
self.Input = Connector(self, "", "BOOL", wxPoint(0, self.Size[1] / 2 + 1), WEST)
self.Output = Connector(self, "", "BOOL", wxPoint(self.Size[0], self.Size[1] / 2 + 1), EAST)
+ self.RefreshNameSize()
+ self.RefreshTypeSize()
# Destructor
def __del__(self):
@@ -473,7 +505,7 @@
# Forbids to change the contact size
def SetSize(self, width, height):
- if isinstance(self.Parent, wxPanel) or self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
+ if self.Parent.GetDrawingMode() == FREEDRAWING_MODE:
Graphic_Element.SetSize(self, width, height)
self.RefreshConnectors()
@@ -486,6 +518,29 @@
self.Input.UnConnect()
self.Output.UnConnect()
+ # Refresh the size of text for name
+ def RefreshNameSize(self):
+ dc = wxClientDC(self.Parent)
+ if self.Name != "":
+ self.NameSize = dc.GetTextExtent(self.Name)
+ else:
+ self.NameSize = 0, 0
+
+ # Refresh the size of text for type
+ def RefreshTypeSize(self):
+ dc = wxClientDC(self.Parent)
+ typetext = ""
+ if self.Type == COIL_REVERSE:
+ typetext = "/"
+ elif self.Type == COIL_SET:
+ typetext = "S"
+ elif self.Type == COIL_RESET:
+ typetext = "R"
+ if typetext != "":
+ self.TypeSize = dc.GetTextExtent(typetext)
+ else:
+ self.TypeSize = 0, 0
+
# Refresh the coil bounding box
def RefreshBoundingBox(self):
dc = wxClientDC(self.Parent)
@@ -555,6 +610,7 @@
# Changes the coil name
def SetName(self, name):
self.Name = name
+ self.RefreshNameSize()
# Returns the coil name
def GetName(self):
@@ -563,6 +619,7 @@
# Changes the coil type
def SetType(self, type):
self.Type = type
+ self.RefreshTypeSize()
# Returns the coil type
def GetType(self):
@@ -590,9 +647,8 @@
dc.SetPen(wxBLACK_PEN)
dc.DrawPoint(self.Pos.x + 1, self.Pos.y + self.Size[1] / 2 + 1)
# Draw coil name
- namewidth, nameheight = dc.GetTextExtent(self.Name)
- dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - namewidth) / 2,
- self.Pos.y - (nameheight + 2))
+ dc.DrawText(self.Name, self.Pos.x + (self.Size[0] - self.NameSize[0]) / 2,
+ self.Pos.y - (self.NameSize[1] + 2))
# Draw the modifier symbol in the middle of coil
typetext = ""
if self.Type == COIL_REVERSE:
@@ -602,9 +658,8 @@
elif self.Type == COIL_RESET:
typetext = "R"
if typetext != "":
- typewidth, typeheight = dc.GetTextExtent(typetext)
- dc.DrawText(typetext, self.Pos.x + (self.Size[0] - typewidth) / 2 + 1,
- self.Pos.y + (self.Size[1] - typeheight) / 2)
+ dc.DrawText(typetext, self.Pos.x + (self.Size[0] - self.TypeSize[0]) / 2 + 1,
+ self.Pos.y + (self.Size[1] - self.TypeSize[1]) / 2)
# Draw input and output connectors
self.Input.Draw(dc)
self.Output.Draw(dc)