LDViewer.py
author lbessard
Thu, 19 Jul 2007 15:04:41 +0200
changeset 46 4379e98a30aa
parent 45 42637f721b5b
child 50 4610aafc884e
permissions -rw-r--r--
Bug on SFC generation fixed
Adding Action and Transition remove functions
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     3
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     5
#based on the plcopen standard.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     6
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     7
#Copyright (C): Edouard TISSERANT and Laurent BESSARD
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     8
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
     9
#See COPYING file for copyrights details.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    10
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5
f8652b073e84 GPL->LGPL
etisserant
parents: 2
diff changeset
    12
#modify it under the terms of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    15
#
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    19
#Lesser General Public License for more details.
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#
5
f8652b073e84 GPL->LGPL
etisserant
parents: 2
diff changeset
    21
#You should have received a copy of the GNU General Public
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    24
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    25
from wxPython.wx import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    26
import wx
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
from types import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    28
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    29
from Viewer import *
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    30
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    31
def ExtractNextBlocks(block, block_list):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
    current_list = [block]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
    while len(current_list) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    34
        next_list = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    35
        for current in current_list:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    36
            connectors = current.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    37
            input_connectors = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    38
            if isinstance(current, LD_PowerRail) and current.GetType() == RIGHTRAIL:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    39
                input_connectors = connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    40
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    41
                if "inputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    42
                    input_connectors = connectors["inputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    43
                if "input" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
                    input_connectors = [connectors["input"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    45
            for connector in input_connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    46
                for wire, handle in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    47
                    next = wire.EndConnected.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    48
                    if not isinstance(next, LD_PowerRail) and next not in block_list:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    49
                        block_list.append(next)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    50
                        next_list.append(next)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    51
        current_list = next_list
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    52
    
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    53
def CalcBranchSize(elements, stops):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    54
    branch_size = 0
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    55
    stop_list = stops
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    56
    for stop in stops:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    57
        ExtractNextBlocks(stop, stop_list)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    58
    element_tree = {}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    59
    for element in elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    60
        if element not in element_tree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    61
            element_tree[element] = {"parents":["start"], "children":[], "weight":None}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    62
            GenerateTree(element, element_tree, stop_list)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    63
        elif element_tree[element]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    64
            element_tree[element]["parents"].append("start")
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    65
    remove_stops = {"start":[], "stop":[]}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    66
    for element, values in element_tree.items():
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    67
        if "stop" in values["children"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    68
            removed = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    69
            for child in values["children"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    70
                if child != "stop":
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    71
##                    if child in elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    72
##                        RemoveElement(child, element_tree)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    73
##                        removed.append(child)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    74
                    if "start" in element_tree[child]["parents"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    75
                        if element not in remove_stops["stop"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    76
                            remove_stops["stop"].append(element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    77
                        if child not in remove_stops["start"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    78
                            remove_stops["start"].append(child)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    79
            for child in removed:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    80
                values["children"].remove(child)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    81
    for element in remove_stops["start"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    82
        element_tree[element]["parents"].remove("start")
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    83
    for element in remove_stops["stop"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    84
        element_tree[element]["children"].remove("stop")
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    85
    for element, values in element_tree.items():
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    86
        if values and "stop" in values["children"]:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    87
            CalcWeight(element, element_tree)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    88
            if values["weight"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    89
                branch_size += values["weight"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    90
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    91
                return 1
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
    92
    #print branch_size
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    93
    return branch_size
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    94
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    95
def RemoveElement(remove, element_tree):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    96
    if remove in element_tree and element_tree[remove]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    97
        for child in element_tree[remove]["children"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    98
            if child != "stop":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    99
                RemoveElement(child, element_tree)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   100
        element_tree.pop(remove)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   101
##        element_tree[remove] = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   102
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   103
def GenerateTree(element, element_tree, stop_list):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   104
    if element in element_tree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   105
        connectors = element.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   106
        input_connectors = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   107
        if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   108
            input_connectors = connectors
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   109
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   110
            if "inputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   111
                input_connectors = connectors["inputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   112
            if "input" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   113
                input_connectors = [connectors["input"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   114
        for connector in input_connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   115
            for wire, handle in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   116
                next = wire.EndConnected.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   117
                if isinstance(next, LD_PowerRail) and next.GetType() == LEFTRAIL or next in stop_list:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   118
##                    for remove in element_tree[element]["children"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   119
##                        RemoveElement(remove, element_tree)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   120
##                    element_tree[element]["children"] = ["stop"]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   121
                    element_tree[element]["children"].append("stop")
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   122
##                elif element_tree[element]["children"] == ["stop"]:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   123
##                    element_tree[next] = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   124
                elif next not in element_tree or element_tree[next]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   125
                    element_tree[element]["children"].append(next)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   126
                    if next in element_tree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   127
                        element_tree[next]["parents"].append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   128
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   129
                        element_tree[next] = {"parents":[element], "children":[], "weight":None}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   130
                        GenerateTree(next, element_tree, stop_list)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   131
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   132
def CalcWeight(element, element_tree):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   133
    weight = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   134
    parts = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   135
    if element in element_tree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   136
        for parent in element_tree[element]["parents"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   137
            if parent == "start":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   138
                weight += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   139
            elif parent in element_tree:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   140
                if not parts:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   141
                    parts = len(element_tree[parent]["children"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   142
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   143
                    parts = min(parts, len(element_tree[parent]["children"]))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   144
                if not element_tree[parent]["weight"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   145
                    CalcWeight(parent, element_tree)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   146
                if element_tree[parent]["weight"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   147
                    weight += element_tree[parent]["weight"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   148
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   149
                    element_tree[element]["weight"] = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   150
                    return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   151
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   152
                element_tree[element]["weight"] = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   153
                return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   154
        if not parts:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   155
            parts = 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   156
        element_tree[element]["weight"] = max(1, weight / parts)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   157
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   158
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   159
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   160
#                     Ladder Diagram Graphic elements Viewer class
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   161
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   162
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   163
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   164
Class derived from Viewer class that implements a Viewer of Ladder Diagram
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   165
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   166
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   167
class LD_Viewer(Viewer):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   168
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   169
    def __init__(self, parent, window, controler):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   170
        Viewer.__init__(self, parent, window, controler)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   171
        self.Rungs = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   172
        self.RungComments = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   173
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   174
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   175
#                          Refresh functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   178
    def RefreshView(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
        Viewer.RefreshView(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   180
        for i, rung in enumerate(self.Rungs):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   181
            bbox = rung.GetBoundingBox()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   182
            if i < len(self.RungComments):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   183
                pos = self.RungComments[i].GetPosition()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   184
                if pos[1] > bbox.y:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   185
                    self.RungComments.insert(i, None)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   186
            else:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   187
                self.RungComments.insert(i, None)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   188
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   189
    def loadInstance(self, instance, ids):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   190
        Viewer.loadInstance(self, instance, ids)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   191
        if instance["type"] == "leftPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   192
            element = self.FindElementById(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   193
            rung = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   194
            rung.SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   195
            self.Rungs.append(rung)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   196
        elif instance["type"] == "rightPowerRail":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   197
            rungs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   198
            for connector in instance["connectors"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   199
                for link in connector["links"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   200
                    connected = self.FindElementById(link["refLocalId"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   201
                    rung = self.FindRung(connected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   202
                    if rung not in rungs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   203
                        rungs.append(rung)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   204
            if len(rungs) > 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   205
                raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   206
            element = self.FindElementById(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   207
            self.Rungs[rungs[0]].SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   208
            for connector in element.GetConnectors():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   209
                for wire, num in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   210
                    self.Rungs[rungs[0]].SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   211
            self.RefreshPosition(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   212
        elif instance["type"] in ["contact", "coil"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   213
            rungs = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   214
            for link in instance["connectors"]["input"]["links"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   215
                connected = self.FindElementById(link["refLocalId"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   216
                rung = self.FindRung(connected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   217
                if rung not in rungs:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   218
                    rungs.append(rung)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   219
            if len(rungs) > 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   220
                raise "ValueError", "Ladder element with id %d is on more than one rung."%instance["id"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   221
            element = self.FindElementById(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   222
            self.Rungs[rungs[0]].SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   223
            for wire, num in element.GetConnectors()["input"].GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   224
                self.Rungs[rungs[0]].SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   225
            self.RefreshPosition(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   226
        elif instance["type"] == "comment":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   227
            element = self.FindElementById(instance["id"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   228
            pos = element.GetPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   229
            i = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   230
            inserted = False
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   231
            while i < len(self.RungComments) and not inserted: 
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   232
                ipos = self.RungComments[i].GetPosition()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   233
                if pos[1] < ipos[1]:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   234
                    self.RungComments.insert(i, element)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   235
                    inserted = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   236
                i += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   237
            if not inserted:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   238
                self.RungComments.append(element)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   239
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   240
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   241
#                          Search Element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   242
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   243
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   244
    def FindRung(self, element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   245
        for i, rung in enumerate(self.Rungs):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   246
            if rung.IsElementIn(element):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   247
                return i
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   248
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   249
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   250
    def FindElement(self, pos):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   251
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   252
            return Viewer.FindElement(self, pos)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   253
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   254
        elements = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   255
        for element in self.GetElements(sort_wires=True):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   256
            if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   257
                elements.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   258
        if len(elements) == 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   259
            return elements[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   260
        elif len(elements) > 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   261
            group = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   262
            for element in elements:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   263
                if self.IsBlock(element):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   264
                    return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   265
                group.SelectElement(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   266
            return group
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   267
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   268
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   269
    def SearchElements(self, bbox):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   270
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   271
            return Viewer.SearchElements(self, bbox)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   272
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   273
        elements = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   274
        for element in self.Blocks:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   275
            if element.IsInSelection(bbox):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   276
                elements.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   277
        return elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   278
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   279
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   280
#                          Mouse event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   281
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   282
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   283
    def OnViewerLeftDown(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   284
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   285
            Viewer.OnViewerLeftDown(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   286
        elif self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   287
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   288
            pos = event.GetLogicalPosition(dc)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   289
            element = self.FindElement(pos)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   290
            if self.SelectedElement:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   291
                if not isinstance(self.SelectedElement, Graphic_Group):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   292
                    if self.SelectedElement != element:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   293
                        if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   294
                            self.SelectedElement.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   295
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   296
                            self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   297
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   298
                        self.SelectedElement = None
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   299
                elif element and isinstance(element, Graphic_Group):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   300
                    if self.SelectedElement.GetElements() != element.GetElements():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   301
                        for elt in self.SelectedElement.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   302
                            if self.IsWire(elt):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   303
                                elt.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   304
                        self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   305
                        self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   306
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   307
                    for elt in self.SelectedElement.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   308
                        if self.IsWire(elt):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   309
                            elt.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   310
                    self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   311
                    self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   312
                self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   313
            if element:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   314
                self.SelectedElement = element
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   315
                self.SelectedElement.OnLeftDown(event, dc, self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   316
                self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   317
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   318
                self.rubberBand.Reset()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   319
                self.rubberBand.OnLeftDown(event, dc, self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   320
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   321
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   322
    def OnViewerLeftUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   323
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   324
            Viewer.OnViewerLeftUp(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   325
        elif self.rubberBand.IsShown():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   326
            if self.Mode == MODE_SELECTION:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   327
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   328
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   329
                if len(elements) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   330
                    self.SelectedElement = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   331
                    self.SelectedElement.SetElements(elements)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   332
                    self.SelectedElement.SetSelected(True)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   333
                    self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   334
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   335
            dc = self.GetLogicalDC() 
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   336
            if not isinstance(self.SelectedElement, Graphic_Group):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   337
                if self.IsWire(self.SelectedElement):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   338
                    result = self.SelectedElement.TestSegment(event.GetLogicalPosition(dc), True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   339
                    if result and result[1] in [EAST, WEST]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   340
                        self.SelectedElement.SetSelectedSegment(result[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   341
                else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   342
                    self.SelectedElement.OnLeftUp(event, dc, self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   343
            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   344
                for element in self.SelectedElement.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   345
                    if self.IsWire(element):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   346
                        result = element.TestSegment(event.GetLogicalPosition(dc), True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   347
                        if result and result[1] in [EAST, WEST]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   348
                            element.SetSelectedSegment(result[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   349
                    else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   350
                        element.OnLeftUp(event, dc, self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   351
            wxCallAfter(self.SetCursor, wxNullCursor)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   352
            self.ReleaseMouse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   353
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   354
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   355
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   356
    def OnViewerRightUp(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   357
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   358
            Viewer.OnViewerRightUp(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   359
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   360
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   361
            pos = event.GetLogicalPosition(dc)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   362
            element = self.FindElement(pos)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   363
            if element:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   364
                if self.SelectedElement and self.SelectedElement != element:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   365
                    self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   366
                self.SelectedElement = element
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   367
                if self.IsWire(self.SelectedElement):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   368
                    self.SelectedElement.SetSelectedSegment(0)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   369
                else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   370
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   371
                    self.SelectedElement.OnRightUp(event, dc, self.Scaling)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   372
                wxCallAfter(self.SetCursor, wxNullCursor)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   373
                self.ReleaseMouse()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   374
                self.Refresh()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   375
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   376
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   377
    def OnViewerLeftDClick(self, event):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   378
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   379
            Viewer.OnViewerLeftDClick(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   380
        elif self.Mode == MODE_SELECTION and self.SelectedElement:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   381
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   382
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   383
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   384
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   385
    def OnViewerMotion(self, event):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   386
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   387
            Viewer.OnViewerMotion(self, event)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   388
        elif self.rubberBand.IsShown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   389
            self.rubberBand.OnMotion(event, self.GetLogicalDC(), self.Scaling)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   390
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   391
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   392
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   393
#                          Keyboard event functions
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   394
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   395
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   396
    def OnChar(self, event):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   397
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   398
            Viewer.OnChar(self, event)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   399
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   400
            keycode = event.GetKeyCode()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   401
            if keycode == WXK_DELETE and self.SelectedElement:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   402
                if self.IsBlock(self.SelectedElement):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   403
                    self.SelectedElement.Delete()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   404
                elif self.IsWire(self.SelectedElement):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   405
                    self.DeleteWire(self.SelectedElement)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   406
                elif isinstance(self.SelectedElement, Graphic_Group):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   407
                    all_wires = True
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   408
                    for element in self.SelectedElement.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   409
                        all_wires &= self.IsWire(element)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   410
                    if all_wires:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   411
                        self.DeleteWire(self.SelectedElement)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   412
                    else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   413
                        self.SelectedElement.Delete()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   414
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   415
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   416
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   417
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   418
#                          Adding element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   421
    def AddLadderRung(self):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   422
        dialog = LDElementDialog(self.Parent, "coil")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   423
        varlist = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   424
        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   425
        if vars:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   426
            for var in vars:
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   427
                if var["Class"] != "Input" and var["Type"] == "BOOL":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   428
                    varlist.append(var["Name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   429
        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   430
        if returntype == "BOOL":
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   431
            varlist.append(self.Controler.GetCurrentElementEditingName())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   432
        dialog.SetVariables(varlist)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   433
        dialog.SetValues({"name":"","type":COIL_NORMAL})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   434
        if dialog.ShowModal() == wxID_OK:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   435
            values = dialog.GetValues()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   436
            startx, starty = LD_OFFSET[0], 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   437
            if len(self.Rungs) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   438
                bbox = self.Rungs[-1].GetBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   439
                starty = bbox.y + bbox.height
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   440
            starty += LD_OFFSET[1]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   441
            rung = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   442
            # Create comment
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   443
            id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   444
            comment = Comment(self, "Commentaire", id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   445
            comment.SetPosition(startx, starty)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   446
            comment.SetSize(LD_COMMENT_DEFAULTSIZE[0], LD_COMMENT_DEFAULTSIZE[1])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   447
            self.AddComment(comment)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   448
            self.RungComments.append(comment)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   449
            self.Controler.AddCurrentElementEditingComment(id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   450
            self.RefreshCommentModel(comment)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   451
            starty += LD_COMMENT_DEFAULTSIZE[1] + LD_OFFSET[1]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   452
            # Create LeftPowerRail
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   453
            id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   454
            leftpowerrail = LD_PowerRail(self, LEFTRAIL, id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   455
            leftpowerrail.SetPosition(startx, starty)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   456
            self.AddBlock(leftpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   457
            rung.SelectElement(leftpowerrail)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   458
            self.Controler.AddCurrentElementEditingPowerRail(id, LEFTRAIL)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   459
            self.RefreshPowerRailModel(leftpowerrail)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   460
            # Create Coil
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   461
            id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   462
            coil = LD_Coil(self, values["type"], values["name"], id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   463
            coil.SetPosition(startx, starty + (LD_LINE_SIZE - LD_ELEMENT_SIZE[1]) / 2)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   464
            self.AddBlock(coil)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   465
            rung.SelectElement(coil)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   466
            self.Controler.AddCurrentElementEditingCoil(id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
            # Create Wire between LeftPowerRail and Coil
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   468
            wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   469
            start_connector = coil.GetConnectors()["input"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   470
            end_connector = leftpowerrail.GetConnectors()[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   471
            start_connector.Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   472
            end_connector.Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   473
            wire.ConnectStartPoint(None, start_connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   474
            wire.ConnectEndPoint(None, end_connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   475
            self.AddWires(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   476
            rung.SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   477
            # Create RightPowerRail
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
            id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   479
            rightpowerrail = LD_PowerRail(self, RIGHTRAIL, id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   480
            rightpowerrail.SetPosition(startx, starty)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   481
            self.AddBlock(rightpowerrail)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   482
            rung.SelectElement(rightpowerrail)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   483
            self.Controler.AddCurrentElementEditingPowerRail(id, RIGHTRAIL)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
            # Create Wire between LeftPowerRail and Coil
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   485
            wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   486
            start_connector = rightpowerrail.GetConnectors()[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   487
            end_connector = coil.GetConnectors()["output"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   488
            start_connector.Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   489
            end_connector.Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   490
            wire.ConnectStartPoint(None, start_connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
            wire.ConnectEndPoint(None, end_connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   492
            self.AddWires(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
            rung.SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   494
            self.RefreshPosition(coil)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   495
            self.Rungs.append(rung)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
            self.Refresh()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   497
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   498
    def AddLadderContact(self):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   499
        wires = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   500
        if self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   501
            left_element = self.SelectedElement.EndConnected
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   502
            if not isinstance(left_element.GetParentBlock(), LD_Coil):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   503
                wires.append(self.SelectedElement)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   504
        elif self.SelectedElement and isinstance(self.SelectedElement,Graphic_Group):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   505
            if False not in [self.IsWire(element) for element in self.SelectedElement.GetElements()]:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   506
                for element in self.SelectedElement.GetElements():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   507
                    wires.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   508
        if len(wires) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
            dialog = LDElementDialog(self.Parent, "contact")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   510
            varlist = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   511
            vars = self.Controler.GetCurrentElementEditingInterfaceVars()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   512
            if vars:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   513
                for var in vars:
6
c8cf918ee7ea Bug corrected and improvements
lbessard
parents: 5
diff changeset
   514
                    if var["Class"] != "Output" and var["Type"] == "BOOL":
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   515
                        varlist.append(var["Name"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   516
            dialog.SetVariables(varlist)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
            dialog.SetValues({"name":"","type":CONTACT_NORMAL})
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   518
            if dialog.ShowModal() == wxID_OK:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   519
                values = dialog.GetValues()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   520
                points = wires[0].GetSelectedSegmentPoints()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
                id = self.GetNewId()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   522
                contact = LD_Contact(self, values["type"], values["name"], id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
                contact.SetPosition(0, points[0].y - (LD_ELEMENT_SIZE[1] + 1) / 2)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   524
                self.AddBlock(contact)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   525
                self.Controler.AddCurrentElementEditingContact(id)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   526
                rungindex = self.FindRung(wires[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   527
                rung = self.Rungs[rungindex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   528
                old_bbox = rung.GetBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   529
                rung.SelectElement(contact)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   530
                connectors = contact.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   531
                left_elements = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   532
                right_elements = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   533
                left_index = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   534
                right_index = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   535
                for wire in wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   536
                    if wire.EndConnected not in left_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   537
                        left_elements.append(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   538
                        left_index.append(wire.EndConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   539
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   540
                        idx = left_elements.index(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   541
                        left_index[idx] = min(left_index[idx], wire.EndConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   542
                    if wire.StartConnected not in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   543
                        right_elements.append(wire.StartConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   544
                        right_index.append(wire.StartConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   545
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   546
                        idx = right_elements.index(wire.StartConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
                        right_index[idx] = min(right_index[idx], wire.StartConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   548
                    wire.SetSelectedSegment(None)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   549
                    wire.Clean()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   550
                    rung.SelectElement(wire)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   551
                    self.RemoveWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   552
                wires = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   553
                right_wires = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   554
                for i, left_element in enumerate(left_elements):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   555
                    wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   556
                    wires.append(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   557
                    connectors["input"].Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   558
                    left_element.InsertConnect(left_index[i], (wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   559
                    wire.ConnectStartPoint(None, connectors["input"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   560
                    wire.ConnectEndPoint(None, left_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   561
                for i, right_element in enumerate(right_elements):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   562
                    wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   563
                    wires.append(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   564
                    right_wires.append(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   565
                    right_element.InsertConnect(right_index[i], (wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   566
                    connectors["output"].Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   567
                    wire.ConnectStartPoint(None, right_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   568
                    wire.ConnectEndPoint(None, connectors["output"])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   569
                right_wires.reverse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   570
                for wire in wires:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   571
                    self.AddWire(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   572
                    rung.SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   573
                self.RefreshPosition(contact)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   574
                if len(right_wires) > 1:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   575
                    group = Graphic_Group(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
                    group.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   577
                    for wire in right_wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   578
                        wire.SetSelectedSegment(-1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   579
                        group.SelectElement(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   580
                    self.SelectedElement = group
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   581
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   582
                    right_wires[0].SetSelectedSegment(-1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   583
                    self.SelectedElement = right_wires[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   584
                rung.RefreshBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   585
                new_bbox = rung.GetBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   586
                self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   587
                self.Refresh()
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   588
        else:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   589
            message = wxMessageDialog(self, "You must select the wire where a contact should be added!", "Error", wxOK|wxICON_ERROR)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   590
            message.ShowModal()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   591
            message.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   592
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   593
    def AddLadderBranch(self):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   594
        blocks = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   595
        if self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
            blocks = [self.SelectedElement]
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   597
        elif isinstance(self.SelectedElement, Graphic_Group):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   598
            elements = self.SelectedElement.GetElements()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
            for element in elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   600
                blocks.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
        if len(blocks) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   602
            blocks_infos = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   603
            left_elements = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
            left_index = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   605
            right_elements = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   606
            right_index = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   607
            for block in blocks:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   608
                connectors = block.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   609
                block_infos = {"inputs":[],"outputs":[],"lefts":[],"rights":[]}
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
                if "inputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   611
                    block_infos["inputs"] = connectors["inputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   612
                if "outputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   613
                    block_infos["outputs"] = connectors["outputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   614
                if "input" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   615
                    block_infos["inputs"] = [connectors["input"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   616
                if "output" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   617
                    block_infos["outputs"] = [connectors["output"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   618
                for connector in block_infos["inputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   619
                    for wire, handle in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   620
                        found = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   621
                        for infos in blocks_infos:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   622
                            if wire.EndConnected in infos["outputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   623
                                for left_element in infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   624
                                    if left_element not in block_infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   625
                                        block_infos["lefts"].append(left_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   626
                                found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   627
                        if not found and wire.EndConnected not in block_infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   628
                            block_infos["lefts"].append(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   629
                            if wire.EndConnected not in left_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   630
                                left_elements.append(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   631
                                left_index.append(wire.EndConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   632
                            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   633
                                index = left_elements.index(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   634
                                left_index[index] = max(left_index[index], wire.EndConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   635
                for connector in block_infos["outputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   636
                    for wire, handle in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   637
                        found = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   638
                        for infos in blocks_infos:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   639
                            if wire.StartConnected in infos["inputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   640
                                for right_element in infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   641
                                    if right_element not in block_infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   642
                                        block_infos["rights"].append(right_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   643
                                found = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   644
                        if not found and wire.StartConnected not in block_infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   645
                            block_infos["rights"].append(wire.StartConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   646
                            if wire.StartConnected not in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   647
                                right_elements.append(wire.StartConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   648
                                right_index.append(wire.StartConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   649
                            else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   650
                                index = right_elements.index(wire.StartConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   651
                                right_index[index] = max(right_index[index], wire.StartConnected.GetWireIndex(wire))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   652
                for connector in block_infos["inputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   653
                    for infos in blocks_infos:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   654
                        if connector in infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   655
                            infos["rights"].remove(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   656
                            if connector in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   657
                                index = right_elements.index(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   658
                                right_elements.pop(index)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   659
                                right_index.pop(index)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   660
                            for right_element in block_infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   661
                                if right_element not in infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   662
                                    infos["rights"].append(right_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   663
                for connector in block_infos["outputs"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   664
                    for infos in blocks_infos:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   665
                        if connector in infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   666
                            infos["lefts"].remove(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   667
                            if connector in left_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   668
                                index = left_elements.index(connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   669
                                left_elements.pop(index)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   670
                                left_index.pop(index)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   671
                            for left_element in block_infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   672
                                if left_element not in infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   673
                                    infos["lefts"].append(left_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   674
                blocks_infos.append(block_infos)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   675
            for infos in blocks_infos:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   676
                left_elements = [element for element in infos["lefts"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   677
                for left_element in left_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   678
                    if isinstance(left_element.GetParentBlock(), LD_PowerRail):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   679
                        infos["lefts"].remove(left_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   680
                        if "LD_PowerRail" not in infos["lefts"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   681
                            infos["lefts"].append("LD_PowerRail")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   682
                right_elements = [element for element in infos["rights"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   683
                for right_element in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   684
                    if isinstance(right_element.GetParentBlock(), LD_PowerRail):
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   685
                        infos["rights"].remove(right_element)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   686
                        if "LD_PowerRail" not in infos["rights"]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   687
                            infos["rights"].append("LD_PowerRail")
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   688
                infos["lefts"].sort()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   689
                infos["rights"].sort()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   690
            lefts = blocks_infos[0]["lefts"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   691
            rights = blocks_infos[0]["rights"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   692
            good = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   693
            for infos in blocks_infos[1:]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   694
                good &= infos["lefts"] == lefts
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   695
                good &= infos["rights"] == rights
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   696
            if good:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   697
                rungindex = self.FindRung(blocks[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   698
                rung = self.Rungs[rungindex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   699
                old_bbox = rung.GetBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   700
                left_powerrail = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   701
                right_powerrail = True
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   702
                for element in left_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   703
                    left_powerrail &= isinstance(element.GetParentBlock(), LD_PowerRail)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   704
                for element in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   705
                    right_powerrail &= isinstance(element.GetParentBlock(), LD_PowerRail)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   706
                if not left_powerrail or not right_powerrail:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   707
                    wires = []
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   708
                    if left_powerrail:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   709
                        powerrail = left_elements[0].GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   710
                        index = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   711
                        for left_element in left_elements: 
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   712
                            index = max(index, powerrail.GetConnectorIndex(left_element))
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   713
                        if powerrail.IsNullConnector(index + 1):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   714
                            powerrail.DeleteConnector(index + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   715
                        powerrail.InsertConnector(index + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   716
                        powerrail.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   717
                        connectors = powerrail.GetConnectors()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   718
                        right_elements.reverse()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   719
                        for i, right_element in enumerate(right_elements):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   720
                            new_wire = Wire(self)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   721
                            wires.append(new_wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   722
                            right_element.InsertConnect(right_index[i] + 1, (new_wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   723
                            connectors[index + 1].Connect((new_wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   724
                            new_wire.ConnectStartPoint(None, right_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   725
                            new_wire.ConnectEndPoint(None, connectors[index + 1])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   726
                        right_elements.reverse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   727
                    elif right_powerrail:
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   728
                        dialog = LDElementDialog(self.Parent, "coil")
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   729
                        varlist = []
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   730
                        vars = self.Controler.GetCurrentElementEditingInterfaceVars()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   731
                        if vars:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   732
                            for var in vars:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   733
                                if var["Class"] != "Input" and var["Type"] == "BOOL":
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   734
                                    varlist.append(var["Name"])
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   735
                        returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   736
                        if returntype == "BOOL":
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   737
                            varlist.append(self.Controler.GetCurrentElementEditingName())
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   738
                        dialog.SetVariables(varlist)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   739
                        dialog.SetValues({"name":"","type":COIL_NORMAL})
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   740
                        if dialog.ShowModal() == wxID_OK:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   741
                            values = dialog.GetValues()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   742
                            powerrail = right_elements[0].GetParentBlock()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   743
                            index = 0
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   744
                            for right_element in right_elements: 
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   745
                                index = max(index, powerrail.GetConnectorIndex(right_element))
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   746
                            if powerrail.IsNullConnector(index + 1):
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   747
                                powerrail.DeleteConnector(index + 1)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   748
                            powerrail.InsertConnector(index + 1)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   749
                            powerrail.RefreshModel()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   750
                            connectors = powerrail.GetConnectors()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   751
                            # Create Coil
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   752
                            id = self.GetNewId()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   753
                            coil = LD_Coil(self, values["type"], values["name"], id)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   754
                            pos = blocks[0].GetPosition()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   755
                            coil.SetPosition(pos[0], pos[1] + LD_LINE_SIZE)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   756
                            self.AddBlock(coil)
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   757
                            rung.SelectElement(coil)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   758
                            self.Controler.AddCurrentElementEditingCoil(id)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   759
                            coil_connectors = coil.GetConnectors()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   760
                            # Create Wire between LeftPowerRail and Coil
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   761
                            wire = Wire(self)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   762
                            connectors[index + 1].Connect((wire, 0), False)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   763
                            coil_connectors["output"].Connect((wire, -1), False)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   764
                            wire.ConnectStartPoint(None, connectors[index + 1])
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   765
                            wire.ConnectEndPoint(None, coil_connectors["output"])
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   766
                            self.AddWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   767
                            rung.SelectElement(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   768
                            left_elements.reverse()
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   769
                            for i, left_element in enumerate(left_elements):
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   770
                                # Create Wire between LeftPowerRail and Coil
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   771
                                new_wire = Wire(self)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   772
                                wires.append(new_wire)
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   773
                                coil_connectors["input"].Connect((new_wire, 0), False)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   774
                                left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   775
                                new_wire.ConnectStartPoint(None, coil_connectors["input"])
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   776
                                new_wire.ConnectEndPoint(None, left_element)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   777
                            self.RefreshPosition(coil)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   778
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   779
                        left_elements.reverse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   780
                        right_elements.reverse()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   781
                        for i, left_element in enumerate(left_elements):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   782
                            for j, right_element in enumerate(right_elements):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   783
                                exist = False
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   784
                                for wire, handle in right_element.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   785
                                    exist |= wire.EndConnected == left_element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   786
                                if not exist:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   787
                                    new_wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   788
                                    wires.append(new_wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   789
                                    right_element.InsertConnect(right_index[j] + 1, (new_wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   790
                                    left_element.InsertConnect(left_index[i] + 1, (new_wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   791
                                    new_wire.ConnectStartPoint(None, right_element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   792
                                    new_wire.ConnectEndPoint(None, left_element)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   793
                    wires.reverse()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   794
                    for wire in wires:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   795
                        self.AddWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   796
                        rung.SelectElement(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   797
                    right_elements.reverse()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   798
                for block in blocks:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   799
                    self.RefreshPosition(block)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   800
                for right_element in right_elements:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   801
                    self.RefreshPosition(right_element.GetParentBlock())
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   802
                self.SelectedElement.RefreshBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   803
                rung.RefreshBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   804
                new_bbox = rung.GetBoundingBox()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   805
                self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   806
                self.Refresh()
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   807
            else:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   808
                message = wxMessageDialog(self, "The group of block must be coherent!", "Error", wxOK|wxICON_ERROR)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   809
                message.ShowModal()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   810
                message.Destroy()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   811
        else:
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   812
            message = wxMessageDialog(self, "You must select the block or group of blocks around which a branch should be added!", "Error", wxOK|wxICON_ERROR)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   813
            message.ShowModal()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   814
            message.Destroy()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   815
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   816
    def AddLadderBlock(self):
7
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   817
        message = wxMessageDialog(self, "This option isn't available yet!", "Warning", wxOK|wxICON_EXCLAMATION)
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   818
        message.ShowModal()
f1691e685c49 Adding error messages on LD editor
lbessard
parents: 6
diff changeset
   819
        message.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   820
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   821
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   822
#                          Delete element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   823
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   824
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   825
    def DeleteContact(self, contact):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   826
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   827
            Viewer.DeleteContact(self, contact)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   828
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   829
            rungindex = self.FindRung(contact)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   830
            rung = self.Rungs[rungindex]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   831
            old_bbox = rung.GetBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   832
            connectors = contact.GetConnectors()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   833
            input_wires = [wire for wire, handle in connectors["input"].GetWires()]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   834
            output_wires = [wire for wire, handle in connectors["output"].GetWires()]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   835
            left_elements = [(wire.EndConnected, wire.EndConnected.GetWireIndex(wire)) for wire in input_wires]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   836
            right_elements = [(wire.StartConnected, wire.StartConnected.GetWireIndex(wire)) for wire in output_wires]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   837
            for wire in input_wires:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   838
                wire.Clean()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   839
                rung.SelectElement(wire)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   840
                self.RemoveWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   841
            for wire in output_wires:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   842
                wire.Clean()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   843
                rung.SelectElement(wire)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   844
                self.RemoveWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   845
            rung.SelectElement(contact)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   846
            contact.Clean()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   847
            left_elements.reverse()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   848
            right_elements.reverse()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   849
            powerrail = len(left_elements) == 1 and isinstance(left_elements[0][0].GetParentBlock(), LD_PowerRail)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   850
            for left_element, left_index in left_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   851
                for right_element, right_index in right_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   852
                    wire_removed = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   853
                    for wire, handle in right_element.GetWires():
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   854
                        if wire.EndConnected == left_element:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   855
                            wire_removed.append(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   856
                        elif isinstance(wire.EndConnected.GetParentBlock(), LD_PowerRail) and powerrail:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   857
                            left_powerrail = wire.EndConnected.GetParentBlock()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   858
                            index = left_powerrail.GetConnectorIndex(wire.EndConnected)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   859
                            left_powerrail.DeleteConnector(index)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   860
                            wire_removed.append(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   861
                    for wire in wire_removed:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   862
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   863
                        self.RemoveWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   864
                        rung.SelectElement(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   865
            wires = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   866
            for left_element, left_index in left_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   867
                for right_element, right_index in right_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   868
                    wire = Wire(self)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   869
                    wires.append(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   870
                    right_element.InsertConnect(right_index, (wire, 0), False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   871
                    left_element.InsertConnect(left_index, (wire, -1), False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   872
                    wire.ConnectStartPoint(None, right_element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   873
                    wire.ConnectEndPoint(None, left_element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   874
            wires.reverse()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   875
            for wire in wires:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   876
                self.RemoveWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   877
                rung.SelectElement(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   878
            right_elements.reverse()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   879
            for right_element, right_index in right_elements:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   880
                self.RefreshPosition(right_element.GetParentBlock())
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   881
            self.RemoveBlock(contact)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   882
            self.Controler.RemoveCurrentElementEditingInstance(contact.GetId())
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   883
            rung.RefreshBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   884
            new_bbox = rung.GetBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   885
            self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   886
            self.SelectedElement = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   887
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   888
    def RecursiveDeletion(self, element, rung):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   889
        connectors = element.GetConnectors()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   890
        input_wires = [wire for wire, handle in connectors["input"].GetWires()]
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   891
        left_elements = [wire.EndConnected for wire in input_wires]
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   892
        rung.SelectElement(element)
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   893
        element.Clean()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   894
        for wire in input_wires:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   895
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   896
            self.RemoveWire(wire)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   897
            rung.SelectElement(wire)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   898
        self.RemoveBlock(element)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   899
        self.Controler.RemoveCurrentElementEditingInstance(element.GetId())
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   900
        for left_element in left_elements:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   901
            block = left_element.GetParentBlock()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   902
            if len(left_element.GetWires()) == 0:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   903
                self.RecursiveDeletion(block, rung)
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   904
            else:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   905
                self.RefreshPosition(block)
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   906
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   907
    def DeleteCoil(self, coil):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   908
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   909
            Viewer.DeleteContact(self, coil)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
   910
        else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   911
            rungindex = self.FindRung(coil)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   912
            rung = self.Rungs[rungindex]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   913
            old_bbox = rung.GetBoundingBox()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   914
            nbcoils = 0
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   915
            for element in rung.GetElements():
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   916
                if isinstance(element, LD_Coil):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   917
                    nbcoils += 1
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   918
            if nbcoils > 1:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   919
                connectors = coil.GetConnectors()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   920
                output_wires = [wire for wire, handle in connectors["output"].GetWires()]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   921
                right_elements = [wire.StartConnected for wire in output_wires]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   922
                for wire in output_wires:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   923
                    wire.Clean()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   924
                    self.Wires.remove(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   925
                    self.Elements.remove(wire)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   926
                    rung.SelectElement(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   927
                for right_element in right_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   928
                    right_block = right_element.GetParentBlock()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   929
                    if isinstance(right_block, LD_PowerRail):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   930
                        if len(right_element.GetWires()) == 0:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   931
                            index = right_block.GetConnectorIndex(right_element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   932
                            right_block.DeleteConnector(index)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   933
                            powerrail_connectors = right_block.GetConnectors()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   934
                            for connector in powerrail_connectors:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   935
                                for wire, handle in connector.GetWires():
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   936
                                    block = wire.EndConnected.GetParentBlock()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   937
                                    endpoint = wire.EndConnected.GetPosition(False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   938
                                    startpoint = connector.GetPosition(False)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   939
                                    block.Move(0, startpoint.y - endpoint.y)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   940
                                    self.RefreshPosition(block)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   941
                self.RecursiveDeletion(coil, rung)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   942
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   943
                for element in rung.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   944
                    if self.IsWire(element):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   945
                        element.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   946
                        self.RemoveWire(element)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   947
                for element in rung.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   948
                    if self.IsBlock(element):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   949
                        self.Controler.RemoveCurrentElementEditingInstance(element.GetId())
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   950
                        self.RemoveBlock(element)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   951
                self.Controler.RemoveCurrentElementEditingInstance(self.Comments[rungindex].GetId())
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   952
                self.RemoveComment(self.RungComments[rungindex])
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   953
                self.RungComments.pop(rungindex)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   954
                self.Rungs.pop(rungindex)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   955
                if rungindex < len(self.Rungs):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   956
                    next_bbox = self.Rungs[rungindex].GetBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   957
                    self.RefreshRungs(old_bbox.y - next_bbox.y, rungindex)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   958
            self.SelectedElement = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   959
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   960
    def DeleteWire(self, wire):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   961
        if self.GetDrawingMode() == FREEDRAWING_MODE:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   962
            Viewer.DeleteWire(self, wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   963
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   964
            wires = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   965
            left_elements = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   966
            right_elements = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   967
            if self.IsWire(wire):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   968
                wires = [wire]
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   969
            elif isinstance(wire, Graphic_Group):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   970
                for element in wire.GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   971
                    if self.IsWire(element):
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   972
                        wires.append(element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   973
                    else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   974
                        wires = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   975
                        break
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   976
            if len(wires) > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   977
                rungindex = self.FindRung(wires[0])
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   978
                rung = self.Rungs[rungindex]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   979
                old_bbox = rung.GetBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   980
                for wire in wires:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   981
                    connections = wire.GetSelectedSegmentConnections()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   982
                    left_block = wire.EndConnected.GetParentBlock()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   983
                    if wire.EndConnected not in left_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   984
                        left_elements.append(wire.EndConnected)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   985
                    if wire.StartConnected not in right_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   986
                        right_elements.append(wire.StartConnected)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   987
                    if connections == (False, False) or connections == (False, True) and isinstance(left_block, LD_PowerRail):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   988
                        wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   989
                        self.RemoveWire(wire)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   990
                        rung.SelectElement(wire)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   991
                for left_element in left_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   992
                    left_block = left_element.GetParentBlock()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   993
                    if isinstance(left_block, LD_PowerRail):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   994
                        if len(left_element.GetWires()) == 0:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   995
                            index = left_block.GetConnectorIndex(left_element)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   996
                            left_block.DeleteConnector(index)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   997
                    else:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   998
                        connectors = left_block.GetConnectors()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
   999
                        output_connectors = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1000
                        if "outputs" in connectors:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1001
                            output_connectors = connectors["outputs"]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1002
                        if "output" in connectors:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1003
                            output_connectors = [connectors["output"]]
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1004
                        for connector in output_connectors:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1005
                            for wire, handle in connector.GetWires():
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1006
                                self.RefreshPosition(wire.StartConnected.GetParentBlock())
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1007
                for right_element in right_elements:
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1008
                    self.RefreshPosition(right_element.GetParentBlock())
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1009
                rung.RefreshBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1010
                new_bbox = rung.GetBoundingBox()
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1011
                self.RefreshRungs(new_bbox.height - old_bbox.height, rungindex + 1)
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1012
                self.SelectedElement = None
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1013
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1014
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1015
#                        Refresh element position functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1016
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1017
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1018
    def RefreshPosition(self, element, recursive=True):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1019
        if isinstance(element, LD_PowerRail) and element.GetType() == LEFTRAIL:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1020
            element.RefreshModel()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1021
            return
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1022
        connectors = element.GetConnectors()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1023
        input_connectors = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1024
        output_connectors = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1025
        if isinstance(element, LD_PowerRail) and element.GetType() == RIGHTRAIL:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1026
            input_connectors = connectors
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1027
            for i, connector in enumerate(input_connectors):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1028
                for j, (wire, handle) in enumerate(connector.GetWires()):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1029
                    block = wire.EndConnected.GetParentBlock()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1030
                    self.RefreshPosition(block, False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1031
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1032
            if "inputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1033
                input_connectors = connectors["inputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1034
            if "outputs" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1035
                output_connectors = connectors["outputs"]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1036
            if "input" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1037
                input_connectors = [connectors["input"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1038
            if "output" in connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1039
                output_connectors = [connectors["output"]]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1040
        position = element.GetPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1041
        minx = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1042
        onlyone = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1043
        for connector in input_connectors:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1044
            onlyone.append(len(connector.GetWires()) == 1)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1045
            for wire, handle in connector.GetWires():
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1046
                onlyone[-1] &= len(wire.EndConnected.GetWires()) == 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1047
                leftblock = wire.EndConnected.GetParentBlock()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1048
                pos = leftblock.GetPosition()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1049
                size = leftblock.GetSize()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1050
                minx = max(minx, pos[0] + size[0])
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1051
        if isinstance(element, LD_Coil):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1052
            interval = LD_WIRECOIL_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1053
        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1054
            interval = LD_WIRE_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1055
        if False in onlyone:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1056
            interval += LD_WIRE_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1057
        movex = minx + interval - position[0]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1058
        element.Move(movex, 0)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1059
        position = element.GetPosition()
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1060
        blocks = []
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1061
        for i, connector in enumerate(input_connectors):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1062
            for j, (wire, handle) in enumerate(connector.GetWires()):
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1063
                blocks.append(wire.EndConnected.GetParentBlock())
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1064
        for i, connector in enumerate(input_connectors):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1065
            startpoint = connector.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1066
            previous_blocks = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1067
            block_list = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1068
            start_offset = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1069
            if not onlyone[i]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1070
                middlepoint = minx + LD_WIRE_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1071
            for j, (wire, handle) in enumerate(connector.GetWires()):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1072
                block = wire.EndConnected.GetParentBlock()
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1073
                if isinstance(element, LD_PowerRail):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1074
                    pos = block.GetPosition()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1075
                    size = leftblock.GetSize()
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1076
                    movex = position[0] - LD_WIRE_SIZE - size[0] - pos[0]
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1077
                    block.Move(movex, 0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1078
                endpoint = wire.EndConnected.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1079
                if j == 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1080
                    if not onlyone[i] and wire.EndConnected.GetWireIndex(wire) > 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1081
                        start_offset = endpoint.y - startpoint.y
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1082
                    offset = start_offset
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1083
                else:
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1084
                    offset = start_offset + LD_LINE_SIZE * CalcBranchSize(previous_blocks, blocks)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1085
                if block in block_list:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1086
                    wires = wire.EndConnected.GetWires()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1087
                    endmiddlepoint = wires[0][0].StartConnected.GetPosition(False)[0] - LD_WIRE_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1088
                    points = [startpoint, wxPoint(middlepoint, startpoint.y),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1089
                              wxPoint(middlepoint, startpoint.y + offset),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1090
                              wxPoint(endmiddlepoint, startpoint.y + offset),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1091
                              wxPoint(endmiddlepoint, endpoint.y), endpoint]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1092
                else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1093
                    if startpoint.y + offset != endpoint.y:
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1094
                        if isinstance(element, LD_PowerRail):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1095
                            diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1096
                            for k in xrange(abs(diff)):
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1097
                                if diff < 0:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1098
                                    element.DeleteConnector(i - 1 - k)
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1099
                                else:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1100
                                    element.InsertConnector(i + k, False)
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1101
                        elif isinstance(block, LD_PowerRail):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1102
                            index = block.GetConnectorIndex(wire.EndConnected)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1103
                            if index:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1104
                                diff = (startpoint.y - endpoint.y) / LD_LINE_SIZE
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1105
                                for k in xrange(abs(diff)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1106
                                    if diff < 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1107
                                        block.DeleteConnector(index - 1 - k)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1108
                                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1109
                                        block.InsertConnector(index + k, False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1110
                        else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1111
                            block.Move(0, startpoint.y + offset - endpoint.y)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1112
                            self.RefreshPosition(block, False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1113
                        endpoint = wire.EndConnected.GetPosition(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1114
                    if not onlyone[i]:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1115
                        points = [startpoint, wxPoint(middlepoint, startpoint.y),
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1116
                                  wxPoint(middlepoint, endpoint.y), endpoint]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1117
                    else:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1118
                        points = [startpoint, endpoint]
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1119
                wire.SetPoints(points)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1120
                previous_blocks.append(block)
27
dae55dd9ee14 Current developping version
lbessard
parents: 9
diff changeset
  1121
                blocks.remove(block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1122
                ExtractNextBlocks(block, block_list)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1123
        element.RefreshModel(False)
8
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1124
        if recursive:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1125
            for connector in output_connectors:
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1126
                for wire, handle in connector.GetWires():
7ceec5c40d77 Adding auto-completion into ST and IL Editors
lbessard
parents: 7
diff changeset
  1127
                    self.RefreshPosition(wire.StartConnected.GetParentBlock())
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1128
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1129
    def RefreshRungs(self, movey, fromidx):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1130
        if movey != 0:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1131
            for i in xrange(fromidx, len(self.Rungs)):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1132
                self.RungComments[i].Move(0, movey)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1133
                self.RungComments[i].RefreshModel()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1134
                self.Rungs[i].Move(0, movey)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1135
                for element in self.Rungs[i].GetElements():
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1136
                    if self.IsBlock(element):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1137
                        self.RefreshPosition(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1138
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1139
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1140
#                          Edit element content functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1141
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1142
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1143
    def EditContactContent(self, contact):
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1144
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1145
            Viewer.EditContactContent(self, contact)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1146
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1147
            dialog = LDElementDialog(self.Parent, "contact")
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1148
            varlist = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1149
            vars = self.Controler.GetCurrentElementEditingInterfaceVars()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1150
            if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1151
                for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1152
                    if var["Class"] != "Output" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1153
                        varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1154
            dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1155
            dialog.SetValues({"name":contact.GetName(),"type":contact.GetType()})
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1156
            if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1157
                values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1158
                contact.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1159
                contact.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1160
                contact.RefreshModel(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1161
                self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1162
            dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1163
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1164
    def EditCoilContent(self, coil):
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1165
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1166
            Viewer.EditCoilContent(self, coil)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1167
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1168
            dialog = LDElementDialog(self.Parent, "coil")
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1169
            varlist = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1170
            vars = self.Controler.GetCurrentElementEditingInterfaceVars()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1171
            if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1172
                for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1173
                    if var["Class"] != "Input" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1174
                        varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1175
            returntype = self.Controler.GetCurrentElementEditingInterfaceReturnType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1176
            if returntype == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1177
                varlist.append(self.Controler.GetCurrentElementEditingName())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1178
            dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1179
            dialog.SetValues({"name":coil.GetName(),"type":coil.GetType()})
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1180
            if dialog.ShowModal() == wxID_OK:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1181
                values = dialog.GetValues()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1182
                coil.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1183
                coil.SetType(values["type"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1184
                coil.RefreshModel(False)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1185
                self.Refresh()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1186
            dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1187
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1188
    def EditPowerRailContent(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1189
        if self.GetDrawingMode() == FREEDRAWING_MODE:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1190
            Viewer.EditPowerRailContent(self, powerrail)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1191