diff -r b22f661cbcfb -r c798a68c5560 LDViewer.py --- a/LDViewer.py Thu Aug 23 09:50:35 2007 +0200 +++ b/LDViewer.py Mon Aug 27 17:37:50 2007 +0200 @@ -188,56 +188,55 @@ def loadInstance(self, instance, ids): Viewer.loadInstance(self, instance, ids) - if instance["type"] == "leftPowerRail": - element = self.FindElementById(instance["id"]) - rung = Graphic_Group(self) - rung.SelectElement(element) - self.Rungs.append(rung) - elif instance["type"] == "rightPowerRail": - rungs = [] - for connector in instance["connectors"]: - for link in connector["links"]: + if self.GetDrawingMode() != FREEDRAWING_MODE: + if instance["type"] == "leftPowerRail": + element = self.FindElementById(instance["id"]) + rung = Graphic_Group(self) + rung.SelectElement(element) + self.Rungs.append(rung) + elif instance["type"] == "rightPowerRail": + rungs = [] + for connector in instance["connectors"]: + for link in connector["links"]: + connected = self.FindElementById(link["refLocalId"]) + rung = self.FindRung(connected) + if rung not in rungs: + rungs.append(rung) + if len(rungs) > 1: + raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"] + element = self.FindElementById(instance["id"]) + self.Rungs[rungs[0]].SelectElement(element) + for connector in element.GetConnectors(): + for wire, num in connector.GetWires(): + self.Rungs[rungs[0]].SelectElement(wire) + self.RefreshPosition(element) + elif instance["type"] in ["contact", "coil"]: + rungs = [] + for link in instance["connectors"]["input"]["links"]: connected = self.FindElementById(link["refLocalId"]) rung = self.FindRung(connected) if rung not in rungs: rungs.append(rung) - if len(rungs) > 1: - raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"] - element = self.FindElementById(instance["id"]) - self.Rungs[rungs[0]].SelectElement(element) - for connector in element.GetConnectors(): - for wire, num in connector.GetWires(): + if len(rungs) > 1: + raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"] + element = self.FindElementById(instance["id"]) + self.Rungs[rungs[0]].SelectElement(element) + for wire, num in element.GetConnectors()["input"].GetWires(): self.Rungs[rungs[0]].SelectElement(wire) - if self.GetDrawingMode() != FREEDRAWING_MODE: self.RefreshPosition(element) - elif instance["type"] in ["contact", "coil"]: - rungs = [] - for link in instance["connectors"]["input"]["links"]: - connected = self.FindElementById(link["refLocalId"]) - rung = self.FindRung(connected) - if rung not in rungs: - rungs.append(rung) - if len(rungs) > 1: - raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"] - element = self.FindElementById(instance["id"]) - self.Rungs[rungs[0]].SelectElement(element) - for wire, num in element.GetConnectors()["input"].GetWires(): - self.Rungs[rungs[0]].SelectElement(wire) - if self.GetDrawingMode() != FREEDRAWING_MODE: - self.RefreshPosition(element) - elif instance["type"] == "comment": - element = self.FindElementById(instance["id"]) - pos = element.GetPosition() - i = 0 - inserted = False - while i < len(self.RungComments) and not inserted: - ipos = self.RungComments[i].GetPosition() - if pos[1] < ipos[1]: - self.RungComments.insert(i, element) - inserted = True - i += 1 - if not inserted: - self.RungComments.append(element) + elif instance["type"] == "comment": + element = self.FindElementById(instance["id"]) + pos = element.GetPosition() + i = 0 + inserted = False + while i < len(self.RungComments) and not inserted: + ipos = self.RungComments[i].GetPosition() + if pos[1] < ipos[1]: + self.RungComments.insert(i, element) + inserted = True + i += 1 + if not inserted: + self.RungComments.append(element) #------------------------------------------------------------------------------- # Search Element functions @@ -249,10 +248,13 @@ return i return None - def FindElement(self, pos): - if self.GetDrawingMode() == FREEDRAWING_MODE: - return Viewer.FindElement(self, pos) + def FindElement(self, pos, exclude_group = False): + if self.GetDrawingMode() == FREEDRAWING_MODE: + return Viewer.FindElement(self, pos, exclude_group) + if self.SelectedElement and not (exclude_group and isinstance(self.SelectedElement, Graphic_Group)): + if self.SelectedElement.HitTest(pos) or self.SelectedElement.TestHandle(pos) != (0, 0): + return self.SelectedElement elements = [] for element in self.GetElements(sort_wires=True): if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):