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