Viewer.py
author 'Laurent Bessard <laurent.bessard@lolitech.fr>'
Fri, 02 Oct 2009 18:14:43 +0200
changeset 440 e183bffc05f0
parent 437 59e33406eea8
child 441 b7511a0b261c
permissions -rw-r--r--
Changes from bct merged
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
#
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
0
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: 3
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
58
39cd981ff242 Changing file headers
lbessard
parents: 56
diff changeset
    19
#General Public License for more details.
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    20
#
5
f8652b073e84 GPL->LGPL
etisserant
parents: 3
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
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
    25
import math
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
    26
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    27
import wx
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    28
if wx.VERSION >= (2, 8, 0):
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    29
    USE_AUI = True
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    30
else:
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
    31
    USE_AUI = False
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    32
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    33
from plcopen.structures import *
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
    34
from PLCControler import ITEM_POU
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    35
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
    36
from dialogs import *
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
    37
from graphics import *
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    38
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    39
from types import TupleType
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
    40
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    41
SCROLLBAR_UNIT = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    42
WINDOW_BORDER = 10
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
    43
SCROLL_ZONE = 10
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
    44
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    45
CURSORS = None
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    46
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    47
def ResetCursors():
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    48
    global CURSORS
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    49
    if CURSORS == None:
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    50
        CURSORS = [wx.NullCursor, 
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    51
                   wx.StockCursor(wx.CURSOR_HAND),
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    52
                   wx.StockCursor(wx.CURSOR_SIZENWSE),
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    53
                   wx.StockCursor(wx.CURSOR_SIZENESW),
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    54
                   wx.StockCursor(wx.CURSOR_SIZEWE),
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    55
                   wx.StockCursor(wx.CURSOR_SIZENS)]
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
    56
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    57
def AppendMenu(parent, help, id, kind, text):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    58
    if wx.VERSION >= (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    59
        parent.Append(help=help, id=id, kind=kind, text=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    60
    else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    61
        parent.Append(helpString=help, id=id, kind=kind, item=text)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
    62
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    63
if wx.Platform == '__WXMSW__':
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    64
    faces = { 'times': 'Times New Roman',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    65
              'mono' : 'Courier New',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    66
              'helv' : 'Arial',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    67
              'other': 'Comic Sans MS',
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
    68
              'size' : 20,
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    69
             }
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    70
else:
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    71
    faces = { 'times': 'Times',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    72
              'mono' : 'Courier',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    73
              'helv' : 'Helvetica',
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    74
              'other': 'new century schoolbook',
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
    75
              'size' : 20,
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    76
             }
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
    77
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
    78
ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, 7)]
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
    79
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    80
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    81
def GetVariableCreationFunction(variable_type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    82
    def variableCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    83
        return FBD_Variable(viewer, variable_type, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    84
                                    specific_values["name"], 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    85
                                    specific_values["value_type"], 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    86
                                    id,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    87
                                    specific_values["executionOrder"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    88
    return variableCreationFunction
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    89
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    90
def GetConnectorCreationFunction(connector_type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    91
    def connectorCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    92
        return FBD_Connector(viewer, connector_type, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    93
                                     specific_values["name"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    94
    return connectorCreationFunction
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    95
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    96
def commentCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    97
    return Comment(viewer, specific_values["content"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    98
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
    99
def GetPowerRailCreationFunction(powerrail_type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   100
    def powerRailCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   101
        return LD_PowerRail(viewer, powerrail_type, id, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   102
                                    specific_values["connectors"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   103
    return powerRailCreationFunction
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   104
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   105
CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   106
                 (False, "rising"): CONTACT_RISING,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   107
                 (False, "falling"): CONTACT_FALLING}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   108
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   109
def contactCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   110
    contact_type = CONTACT_TYPES.get((specific_values.get("negated", False), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   111
                                      specific_values.get("edge", "none")),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   112
                                     CONTACT_NORMAL)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   113
    return LD_Contact(viewer, contact_type, specific_values["name"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   114
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   115
COIL_TYPES = {(True, "none", "none"): COIL_REVERSE,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   116
              (False, "none", "set"): COIL_SET,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   117
              (False, "none", "reset"): COIL_RESET,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   118
              (False, "rising", "none"): COIL_RISING,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   119
              (False, "falling", "none"): COIL_FALLING}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   120
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   121
def coilCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   122
    coil_type = COIL_TYPES.get((specific_values.get("negated", False), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   123
                                specific_values.get("edge", "none"),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   124
                                specific_values.get("storage", "none")),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   125
                               COIL_NORMAL)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   126
    return LD_Coil(viewer, coil_type, specific_values["name"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   127
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   128
def stepCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   129
    step = SFC_Step(viewer, specific_values["name"], 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   130
                            specific_values.get("initial", False), id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   131
    if specific_values.get("action", None):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   132
        step.AddAction()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   133
        connector = step.GetActionConnector()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   134
        connector.SetPosition(wx.Point(*specific_values["action"]["position"]))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   135
    return step
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   136
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   137
def transitionCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   138
    transition = SFC_Transition(viewer, specific_values["condition_type"], 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   139
                                        specific_values.get("condition", None), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   140
                                        specific_values["priority"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   141
    return transition
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   142
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   143
def GetDivergenceCreationFunction(divergence_type):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   144
    def divergenceCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   145
        return SFC_Divergence(viewer, divergence_type, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   146
                                      specific_values["connectors"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   147
    return divergenceCreationFunction
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   148
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   149
def jumpCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   150
    return SFC_Jump(viewer, specific_values["target"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   151
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   152
def actionBlockCreationFunction(viewer, id, specific_values):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   153
    return SFC_ActionBlock(viewer, specific_values["actions"], id)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   154
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   155
ElementCreationFunctions = {
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   156
    "input": GetVariableCreationFunction(INPUT),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   157
    "output": GetVariableCreationFunction(OUTPUT),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   158
    "inout": GetVariableCreationFunction(INOUT),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   159
    "connector": GetConnectorCreationFunction(CONNECTOR),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   160
    "continuation": GetConnectorCreationFunction(CONTINUATION),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   161
    "comment": commentCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   162
    "leftPowerRail": GetPowerRailCreationFunction(LEFTRAIL),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   163
    "rightPowerRail": GetPowerRailCreationFunction(RIGHTRAIL),
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   164
    "contact": contactCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   165
    "coil": coilCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   166
    "step": stepCreationFunction, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   167
    "transition": transitionCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   168
    "selectionDivergence": GetDivergenceCreationFunction(SELECTION_DIVERGENCE), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   169
    "selectionConvergence": GetDivergenceCreationFunction(SELECTION_CONVERGENCE), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   170
    "simultaneousDivergence": GetDivergenceCreationFunction(SIMULTANEOUS_DIVERGENCE), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   171
    "simultaneousConvergence": GetDivergenceCreationFunction(SIMULTANEOUS_CONVERGENCE), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   172
    "jump": jumpCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   173
    "actionBlock": actionBlockCreationFunction,
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   174
}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   175
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   176
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   177
#                       Graphic elements Viewer base class
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   178
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   179
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   180
# ID Constants for alignment menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   181
[ID_VIEWERALIGNMENTMENUITEMS0, ID_VIEWERALIGNMENTMENUITEMS1,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   182
 ID_VIEWERALIGNMENTMENUITEMS2, ID_VIEWERALIGNMENTMENUITEMS4,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   183
 ID_VIEWERALIGNMENTMENUITEMS5, ID_VIEWERALIGNMENTMENUITEMS6,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   184
] = [wx.NewId() for _init_coll_AlignmentMenu_Items in range(6)]
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   185
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   186
# ID Constants for contextual menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   187
[ID_VIEWERCONTEXTUALMENUITEMS0, ID_VIEWERCONTEXTUALMENUITEMS1,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   188
 ID_VIEWERCONTEXTUALMENUITEMS2, ID_VIEWERCONTEXTUALMENUITEMS3,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   189
 ID_VIEWERCONTEXTUALMENUITEMS5, ID_VIEWERCONTEXTUALMENUITEMS6,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   190
 ID_VIEWERCONTEXTUALMENUITEMS8, ID_VIEWERCONTEXTUALMENUITEMS9,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   191
 ID_VIEWERCONTEXTUALMENUITEMS11, ID_VIEWERCONTEXTUALMENUITEMS12,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   192
 ID_VIEWERCONTEXTUALMENUITEMS14, ID_VIEWERCONTEXTUALMENUITEMS16,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   193
 ID_VIEWERCONTEXTUALMENUITEMS17,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   194
] = [wx.NewId() for _init_coll_ContextualMenu_Items in range(13)]
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   195
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   196
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   197
class ViewerDropTarget(wx.TextDropTarget):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   198
    
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   199
    def __init__(self, parent):
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   200
        wx.TextDropTarget.__init__(self)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   201
        self.ParentWindow = parent
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   202
    
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   203
    def OnDropText(self, x, y, data):
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   204
        tagname = self.ParentWindow.GetTagName()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   205
        pou_name, pou_type = self.ParentWindow.Controler.GetEditedElementType(tagname, self.ParentWindow.Debug)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
   206
        x, y = self.ParentWindow.CalcUnscrolledPosition(x, y)
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   207
        x = int(x / self.ParentWindow.ViewScale[0])
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   208
        y = int(y / self.ParentWindow.ViewScale[1])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   209
        scaling = self.ParentWindow.Scaling
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   210
        message = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   211
        try:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   212
            values = eval(data)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   213
        except:
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   214
            message = _("Invalid value \"%s\" for viewer block")%data
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   215
            values = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   216
        if not isinstance(values, TupleType):
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   217
            message = _("Invalid value \"%s\" for viewer block")%data
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   218
            values = None
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   219
        if values is not None:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   220
            if values[1] == "debug":
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   221
                pass
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   222
            elif values[1] == "program":
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   223
                message = _("Programs can't be used by other POUs!")
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   224
            elif values[1] in ["function", "functionBlock"]:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   225
                words = tagname.split("::")
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   226
                if pou_name == values[0]:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   227
                    message = _("\"%s\" can't use itself!")%pou_name
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   228
                elif pou_type == "function" and values[1] != "function":
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   229
                    message = _("Function Blocks can't be used in Functions!")
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   230
                elif words[0] == "T" and values[1] != "function":
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   231
                    message = _("Function Blocks can't be used in Transitions!")
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   232
                elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug):
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   233
                    message = _("\"%s\" is already used by \"%s\"!")%(pou_name, values[0])
195
d9084f6eecfd Adding Function Block name test in Viewer Drop Target
lbessard
parents: 178
diff changeset
   234
                else:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   235
                    blockname = values[2]
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   236
                    if len(values) > 3:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   237
                        blockinputs = values[3]
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   238
                    else:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   239
                        blockinputs = None
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   240
                    if values[1] != "function" and blockname == "":
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   241
                        dialog = wx.TextEntryDialog(self.ParentWindow.ParentWindow, "Block name", "Please enter a block name", "", wx.OK|wx.CANCEL|wx.CENTRE)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   242
                        if dialog.ShowModal() == wx.ID_OK:
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   243
                            blockname = dialog.GetValue()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   244
                        else:
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   245
                            return
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   246
                        dialog.Destroy()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   247
                    if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   248
                        message = _("\"%s\" pou already exists!")%blockname
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   249
                    elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   250
                        message = _("\"%s\" element for this pou already exists!")%blockname
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   251
                    else:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   252
                        id = self.ParentWindow.GetNewId()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
   253
                        block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   254
                        width, height = block.GetMinSize()
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   255
                        if scaling is not None:
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   256
                            x = round(float(x) / float(scaling[0])) * scaling[0]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   257
                            y = round(float(y) / float(scaling[1])) * scaling[1]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   258
                            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   259
                            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   260
                        block.SetPosition(x, y)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   261
                        block.SetSize(width, height)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   262
                        self.ParentWindow.AddBlock(block)
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   263
                        self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   264
                        self.ParentWindow.RefreshBlockModel(block)
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   265
                        self.ParentWindow.RefreshBuffer()
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   266
                        self.ParentWindow.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   267
                        self.ParentWindow.RefreshVisibleElements()
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   268
                        self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   269
                        self.ParentWindow.Refresh(False)
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   270
            elif values[1] == "location":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   271
                if len(values) > 2 and pou_type == "program":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   272
                    var_name = values[3]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   273
                    if var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   274
                        message = _("\"%s\" pou already exists!")%blockname
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   275
                    elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   276
                        message = _("\"%s\" element for this pou already exists!")%blockname
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   277
                    else:
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   278
                        if values[0][1] == "Q":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   279
                            var_class = OUTPUT
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   280
                        else:
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   281
                            var_class = INPUT
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   282
                        if values[2] is not None:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   283
                            var_type = values[2]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   284
                        else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   285
                            var_type = LOCATIONDATATYPES.get(values[0][2], ["BOOL"])[0]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   286
                        id = self.ParentWindow.GetNewId()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   287
                        variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   288
                        width, height = variable.GetMinSize()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   289
                        if scaling is not None:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   290
                            x = round(float(x) / float(scaling[0])) * scaling[0]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   291
                            y = round(float(y) / float(scaling[1])) * scaling[1]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   292
                            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   293
                            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   294
                        variable.SetPosition(x, y)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   295
                        variable.SetSize(width, height)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   296
                        self.ParentWindow.AddBlock(variable)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   297
                        self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, values[0], values[4])
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   298
                        self.ParentWindow.Controler.AddEditedElementVariable(tagname, id, var_class)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   299
                        self.ParentWindow.RefreshVariableModel(variable)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   300
                        self.ParentWindow.RefreshBuffer()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   301
                        self.ParentWindow.RefreshScrollBars()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   302
                        self.ParentWindow.RefreshVisibleElements()
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   303
                        self.ParentWindow.ParentWindow.RefreshVariablePanel(tagname)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   304
                        self.ParentWindow.Refresh(False)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   305
            elif values[3] == tagname:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   306
                if values[1] == "Output":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   307
                    var_class = OUTPUT
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   308
                elif values[1] == "InOut":
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   309
                    var_class = INPUT
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   310
                else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   311
                    var_class = INPUT
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   312
                tree = dict([(var["Name"], var["Tree"]) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, self.ParentWindow.Debug)]).get(values[0], None)
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   313
                if tree is not None:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   314
                    if len(tree[0]) > 0:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   315
                        menu = wx.Menu(title='')
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   316
                        self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   317
                        self.ParentWindow.PopupMenuXY(menu)
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   318
                    else:
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   319
                        self.AddParentVariableBlock(x, y, scaling, var_class, values[0], values[2])
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   320
                else:
437
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   321
                    message = _("Unknown variable \"%s\" for this POU!") % values[0]
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   322
            else:
59e33406eea8 Adding support for dropping Beremiz plugin variable locations into PLCOpenEditor viewers and adding corresponding variable into POU interface
laurent
parents: 433
diff changeset
   323
                message = _("Variable don't belong to this POU!")
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   324
        if message is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   325
            wx.CallAfter(self.ShowMessage, message)
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   326
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   327
    def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
299
15669fe26e56 Adding support for generating real array dimension in variable blocks
lbessard
parents: 297
diff changeset
   328
        for child_name, child_type, (child_tree, child_dimensions) in tree:
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   329
            if base_path:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   330
                child_path = "%s.%s" % (base_path, child_name)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   331
            else:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   332
                child_path = child_name
299
15669fe26e56 Adding support for generating real array dimension in variable blocks
lbessard
parents: 297
diff changeset
   333
            if len(child_dimensions) > 0:
15669fe26e56 Adding support for generating real array dimension in variable blocks
lbessard
parents: 297
diff changeset
   334
                child_path += "[%s]" % ",".join([str(dimension[0]) for dimension in child_dimensions])
297
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   335
                child_name += "[]"
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   336
            new_id = wx.NewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   337
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   338
            self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   339
            if len(child_tree) > 0:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   340
                new_id = wx.NewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   341
                child_menu = wx.Menu(title='')
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   342
                self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   343
                menu.AppendMenu(new_id, "%s." % child_name, child_menu)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   344
            
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   345
    def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   346
        def AddVariableFunction(event):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   347
            self.AddParentVariableBlock(x, y, scaling, var_class, var_name, var_type)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   348
        return AddVariableFunction
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   349
    
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   350
    def AddParentVariableBlock(self, x, y, scaling, var_class, var_name, var_type):
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   351
        id = self.ParentWindow.GetNewId()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   352
        variable = FBD_Variable(self.ParentWindow, var_class, var_name, var_type, id)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   353
        width, height = variable.GetMinSize()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   354
        if scaling is not None:
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   355
            x = round(float(x) / float(scaling[0])) * scaling[0]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   356
            y = round(float(y) / float(scaling[1])) * scaling[1]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   357
            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   358
            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   359
        variable.SetPosition(x, y)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   360
        variable.SetSize(width, height)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   361
        self.ParentWindow.AddBlock(variable)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   362
        self.ParentWindow.Controler.AddEditedElementVariable(self.ParentWindow.GetTagName(), id, var_class)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   363
        self.ParentWindow.RefreshVariableModel(variable)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   364
        self.ParentWindow.RefreshBuffer()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   365
        self.ParentWindow.RefreshScrollBars()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   366
        self.ParentWindow.RefreshVisibleElements()
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   367
        self.ParentWindow.Refresh(False)
e837b67cb184 Adding help menu for inserting complex variable in graphical viewer
lbessard
parents: 292
diff changeset
   368
    
218
1b8e9bb83f25 Bug with unformated drop text fixed
lbessard
parents: 216
diff changeset
   369
    def ShowMessage(self, message):
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   370
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   371
        message.ShowModal()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   372
        message.Destroy()
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
   373
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   374
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   375
"""
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   376
Class that implements a Viewer based on a wx.ScrolledWindow for drawing and 
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   377
manipulating graphic elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   378
"""
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   379
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   380
class Viewer(wx.ScrolledWindow, DebugViewer):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   381
    
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   382
    if wx.VERSION < (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   383
        def Bind(self, event, function, id = None):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   384
            if id is not None:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   385
                event(self, id, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   386
            else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   387
                event(self, function)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   388
    
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   389
    # Create Alignment Menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   390
    def _init_coll_AlignmentMenu_Items(self, parent):
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   391
        # Create menu items
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   392
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS0,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   393
              kind=wx.ITEM_NORMAL, text=_(u'Left'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   394
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   395
              kind=wx.ITEM_NORMAL, text=_(u'Center'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   396
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   397
              kind=wx.ITEM_NORMAL, text=_(u'Right'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   398
        parent.AppendSeparator()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   399
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS4,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   400
              kind=wx.ITEM_NORMAL, text=_(u'Top'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   401
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS5,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   402
              kind=wx.ITEM_NORMAL, text=_(u'Middle'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   403
        AppendMenu(parent, help='', id=ID_VIEWERALIGNMENTMENUITEMS6,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   404
              kind=wx.ITEM_NORMAL, text=_(u'Bottom'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   405
        # Link menu event to corresponding called functions
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   406
        self.Bind(wx.EVT_MENU, self.OnAlignLeftMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   407
              id=ID_VIEWERALIGNMENTMENUITEMS0)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   408
        self.Bind(wx.EVT_MENU, self.OnAlignCenterMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   409
              id=ID_VIEWERALIGNMENTMENUITEMS1)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   410
        self.Bind(wx.EVT_MENU, self.OnAlignRightMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   411
              id=ID_VIEWERALIGNMENTMENUITEMS2)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   412
        self.Bind(wx.EVT_MENU, self.OnAlignTopMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   413
              id=ID_VIEWERALIGNMENTMENUITEMS4)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   414
        self.Bind(wx.EVT_MENU, self.OnAlignMiddleMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   415
              id=ID_VIEWERALIGNMENTMENUITEMS5)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   416
        self.Bind(wx.EVT_MENU, self.OnAlignBottomMenu,
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   417
              id=ID_VIEWERALIGNMENTMENUITEMS6)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   418
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   419
    # Create Contextual Menu items
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   420
    def _init_coll_ContextualMenu_Items(self, parent):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   421
        # Create menu items
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   422
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS0,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   423
              kind=wx.ITEM_RADIO, text=_(u'No Modifier'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   424
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS1,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   425
              kind=wx.ITEM_RADIO, text=_(u'Negated'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   426
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS2,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   427
              kind=wx.ITEM_RADIO, text=_(u'Rising Edge'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   428
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS3,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   429
              kind=wx.ITEM_RADIO, text=_(u'Falling Edge'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   430
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   431
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS5,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   432
              kind=wx.ITEM_NORMAL, text=_(u'Add Wire Segment'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   433
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS6,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   434
              kind=wx.ITEM_NORMAL, text=_(u'Delete Wire Segment'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   435
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   436
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS8,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   437
              kind=wx.ITEM_NORMAL, text=_(u'Add Divergence Branch'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   438
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS9,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   439
              kind=wx.ITEM_NORMAL, text=_(u'Delete Divergence Branch'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   440
        parent.AppendSeparator()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   441
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS11,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   442
              kind=wx.ITEM_NORMAL, text=_(u'Clear Execution Order'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   443
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS12,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   444
              kind=wx.ITEM_NORMAL, text=_(u'Reset Execution Order'))
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   445
        parent.AppendSeparator()
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   446
        parent.AppendMenu(ID_VIEWERCONTEXTUALMENUITEMS14, _("Alignment"), self.AlignmentMenu)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   447
        parent.AppendSeparator()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   448
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS16,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   449
              kind=wx.ITEM_NORMAL, text=_(u'Edit Block'))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   450
        AppendMenu(parent, help='', id=ID_VIEWERCONTEXTUALMENUITEMS17,
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
   451
              kind=wx.ITEM_NORMAL, text=_(u'Delete'))
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   452
        # Link menu event to corresponding called functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   453
        self.Bind(wx.EVT_MENU, self.OnNoModifierMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   454
              id=ID_VIEWERCONTEXTUALMENUITEMS0)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   455
        self.Bind(wx.EVT_MENU, self.OnNegatedMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   456
              id=ID_VIEWERCONTEXTUALMENUITEMS1)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   457
        self.Bind(wx.EVT_MENU, self.OnRisingEdgeMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   458
              id=ID_VIEWERCONTEXTUALMENUITEMS2)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   459
        self.Bind(wx.EVT_MENU, self.OnFallingEdgeMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   460
              id=ID_VIEWERCONTEXTUALMENUITEMS3)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   461
        self.Bind(wx.EVT_MENU, self.OnAddSegmentMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   462
              id=ID_VIEWERCONTEXTUALMENUITEMS5)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   463
        self.Bind(wx.EVT_MENU, self.OnDeleteSegmentMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   464
              id=ID_VIEWERCONTEXTUALMENUITEMS6)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   465
        self.Bind(wx.EVT_MENU, self.OnAddBranchMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   466
              id=ID_VIEWERCONTEXTUALMENUITEMS8)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   467
        self.Bind(wx.EVT_MENU, self.OnDeleteBranchMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   468
              id=ID_VIEWERCONTEXTUALMENUITEMS9)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   469
        self.Bind(wx.EVT_MENU, self.OnClearExecutionOrderMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   470
              id=ID_VIEWERCONTEXTUALMENUITEMS11)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
   471
        self.Bind(wx.EVT_MENU, self.OnResetExecutionOrderMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   472
              id=ID_VIEWERCONTEXTUALMENUITEMS12)
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
   473
        self.Bind(wx.EVT_MENU, self.OnEditBlockMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   474
              id=ID_VIEWERCONTEXTUALMENUITEMS16)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   475
        self.Bind(wx.EVT_MENU, self.OnDeleteMenu,
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   476
              id=ID_VIEWERCONTEXTUALMENUITEMS17)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   477
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   478
    # Create and initialize Contextual Menu
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   479
    def _init_menus(self):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   480
        self.AlignmentMenu = wx.Menu(title='')
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   481
        self.ContextualMenu = wx.Menu(title='')
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   482
        
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   483
        self._init_coll_AlignmentMenu_Items(self.AlignmentMenu)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   484
        self._init_coll_ContextualMenu_Items(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   485
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   486
    # Create a new Viewer
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   487
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
   488
        wx.ScrolledWindow.__init__(self, parent, pos=wx.Point(0, 0), size=wx.Size(0, 0), 
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   489
            style=wx.HSCROLL | wx.VSCROLL | wx.ALWAYS_SHOW_SB)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   490
        DebugViewer.__init__(self, controler, debug)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   491
        self._init_menus()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   492
        # Adding a rubberband to Viewer
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   493
        self.rubberBand = RubberBand(drawingSurface=self)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   494
        self.SetBackgroundColour(wx.Colour(255,255,255))
224
e5bf78b847e1 Bug with AutoBufferedPaintDC and Background style fixed
lbessard
parents: 222
diff changeset
   495
        self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   496
        self.ResetView()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   497
        self.Scaling = None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   498
        self.DrawGrid = True
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   499
        self.GridBrush = wx.TRANSPARENT_BRUSH
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   500
        self.PageSize = None
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   501
        self.PagePen = wx.TRANSPARENT_PEN
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
   502
        self.DrawingWire = False
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   503
        self.current_id = 0
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   504
        self.TagName = tagname
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   505
        self.Errors = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   506
        self.InstancePath = instancepath
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   507
        self.StartMousePos = None
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   508
        self.StartScreenPos = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   509
        
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   510
        # Initialize Cursors
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   511
        ResetCursors()
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   512
        self.CurrentCursor = 0
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   513
        
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   514
        # Initialize Block, Wire and Comment numbers
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   515
        self.wire_id = 0
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   516
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   517
        # Initialize Viewer mode to Selection mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   518
        self.Mode = MODE_SELECTION
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   519
        self.SavedMode = False
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   520
        self.CurrentLanguage = "FBD"
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   521
        
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   522
        self.ParentWindow = window
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   523
        self.Controler = controler
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   524
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   525
        if not self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   526
            self.SetDropTarget(ViewerDropTarget(self))
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   527
        
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   528
        self.NewDataRefreshRect = None
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   529
        
156
2a2e974302fe Adding support for Viewer font
lbessard
parents: 155
diff changeset
   530
        dc = wx.ClientDC(self)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   531
        font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   532
        dc.SetFont(font)
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   533
        width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   534
        while width > 260:
157
e4e8bc2e3e1a Adding support for Viewer font
lbessard
parents: 156
diff changeset
   535
            faces["size"] -= 1
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   536
            font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   537
            dc.SetFont(font)
158
8a770e8d745a Adding support for Viewer font
lbessard
parents: 157
diff changeset
   538
            width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   539
        self.SetFont(font)
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   540
        self.MiniTextDC = wx.MemoryDC()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   541
        self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
156
2a2e974302fe Adding support for Viewer font
lbessard
parents: 155
diff changeset
   542
        
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   543
        self.SetScale(len(ZOOM_FACTORS) / 2)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   544
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   545
        self.ResetView()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   546
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   547
        # Link Viewer event to corresponding methods
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   548
        self.Bind(wx.EVT_PAINT, self.OnPaint)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   549
        self.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   550
        self.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   551
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnViewerLeftDClick)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   552
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   553
        self.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   554
        self.Bind(wx.EVT_MIDDLE_DOWN, self.OnViewerMiddleDown)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   555
        self.Bind(wx.EVT_MIDDLE_UP, self.OnViewerMiddleUp)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
   556
        self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   557
        self.Bind(wx.EVT_MOTION, self.OnViewerMotion)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
   558
        self.Bind(wx.EVT_CHAR, self.OnChar)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   559
        self.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   560
        self.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.OnScrollStop)
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   561
        self.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   562
        self.Bind(wx.EVT_SIZE, self.OnMoveWindow)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   563
    
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   564
    def SetCurrentCursor(self, cursor):
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   565
        global CURSORS
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   566
        if self.CurrentCursor != cursor:
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   567
            self.CurrentCursor = cursor
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   568
            self.SetCursor(CURSORS[cursor])
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
   569
    
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   570
    def GetScrolledRect(self, rect):
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   571
        rect.x, rect.y = self.CalcScrolledPosition(int(rect.x * self.ViewScale[0]), 
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   572
                                                   int(rect.y * self.ViewScale[1]))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   573
        rect.width = int(rect.width * self.ViewScale[0]) + 2
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   574
        rect.height = int(rect.height * self.ViewScale[1]) + 2
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   575
        return rect
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   576
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   577
    def GetScaling(self):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   578
        return self.Scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   579
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   580
    def SetTagName(self, tagname):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   581
        self.TagName = tagname
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   582
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   583
    def GetTagName(self):
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   584
        return self.TagName
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   585
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   586
    def GetInstancePath(self):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   587
        return self.InstancePath
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   588
    
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   589
    def IsViewing(self, tagname):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   590
        if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   591
            return self.InstancePath == tagname
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   592
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   593
            return self.TagName == tagname
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   594
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   595
    # Returns a new id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   596
    def GetNewId(self):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   597
        self.current_id += 1
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   598
        return self.current_id
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   599
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   600
    # Destructor
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   601
    def __del__(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   602
        DebugViewer.__del__(self)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   603
        self.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   604
        self.ResetView()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   605
    
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
   606
    def SetScale(self, scale_number, refresh=True):
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   607
        self.CurrentScale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1))
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   608
        self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale])
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
   609
        self.RefreshScaling(refresh)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   610
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   611
    def GetScale(self):
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   612
        return self.CurrentScale
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
   613
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   614
    def GetLogicalDC(self, buffered=False):
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   615
        if buffered:
352
5cd60f7e510c fixed some bugs:
greg
parents: 345
diff changeset
   616
            bitmap = wx.EmptyBitmap(*self.GetClientSize())
5cd60f7e510c fixed some bugs:
greg
parents: 345
diff changeset
   617
            dc = wx.MemoryDC(bitmap)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   618
        else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   619
            dc = wx.ClientDC(self)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
   620
        dc.SetFont(self.GetFont())
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   621
        if wx.VERSION >= (2, 6, 0):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   622
            self.DoPrepareDC(dc)
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   623
        else:
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
   624
            self.PrepareDC(dc)
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   625
        dc.SetUserScale(self.ViewScale[0], self.ViewScale[1])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   626
        return dc
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   627
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   628
    def GetMiniTextExtent(self, text):
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   629
        return self.MiniTextDC.GetTextExtent(text)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   630
    
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   631
    def GetMiniFont(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   632
        return self.MiniTextDC.GetFont()
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   633
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   634
#-------------------------------------------------------------------------------
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   635
#                         Element management functions
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   636
#-------------------------------------------------------------------------------
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   637
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   638
    def AddBlock(self, block):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   639
        self.Blocks[block.GetId()] = block
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   640
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   641
    def AddWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   642
        self.wire_id += 1
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   643
        self.Wires[wire] = self.wire_id
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   644
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   645
    def AddComment(self, comment):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   646
        self.Comments[comment.GetId()] = comment
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   647
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   648
    def IsBlock(self, block):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   649
        return self.Blocks.get(block.GetId(), False)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   650
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   651
    def IsWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   652
        return self.Wires.get(wire, False)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   653
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   654
    def IsComment(self, comment):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   655
        return self.Comments.get(comment.GetId(), False)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   656
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   657
    def RemoveBlock(self, block):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   658
        self.Blocks.pop(block.GetId())
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   659
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   660
    def RemoveWire(self, wire):
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   661
        self.Wires.pop(wire)
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   662
        
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   663
    def RemoveComment(self, comment):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   664
        self.Comments.pop(comment.GetId())
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   665
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   666
    def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   667
        blocks = self.Blocks.values()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   668
        wires = self.Wires.keys()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   669
        comments = self.Comments.values()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   670
        if sort_blocks:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   671
            blocks.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   672
        if sort_wires:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
   673
            wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   674
        if sort_comments:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   675
            comments.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   676
        return blocks + wires + comments
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   677
388
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   678
    def GetConnectorByName(self, name):
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   679
        for block in self.Blocks.itervalues():
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   680
            if isinstance(block, FBD_Connector) and\
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   681
               block.GetType() == CONNECTOR and\
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   682
               block.GetName() == name:
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   683
                return block
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   684
        return None
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   685
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   686
    def RefreshVisibleElements(self, xp = None, yp = None):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   687
        x, y = self.CalcUnscrolledPosition(0, 0)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   688
        if xp is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   689
            x = xp * self.GetScrollPixelsPerUnit()[0]
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   690
        if yp is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   691
            y = yp * self.GetScrollPixelsPerUnit()[1]
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   692
        width, height = self.GetClientSize()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   693
        screen = wx.Rect(int(x / self.ViewScale[0]), int(y / self.ViewScale[1]),
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   694
                         int(width / self.ViewScale[0]), int(height / self.ViewScale[1]))
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   695
        for comment in self.Comments.itervalues():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   696
            comment.TestVisible(screen)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   697
        for wire in self.Wires.iterkeys():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   698
            wire.TestVisible(screen)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   699
        for block in self.Blocks.itervalues():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   700
            block.TestVisible(screen)
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   701
    
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   702
    def GetElementIECPath(self, element):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   703
        iec_path = None
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   704
        if isinstance(element, Wire) and element.EndConnected is not None:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   705
            block = element.EndConnected.GetParentBlock()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   706
            if isinstance(block, FBD_Block):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   707
                blockname = block.GetName()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   708
                connectorname = element.EndConnected.GetName()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   709
                if blockname != "":
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   710
                    iec_path = "%s.%s.%s"%(self.InstancePath, blockname, connectorname)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   711
                else:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   712
                    if connectorname == "":
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   713
                        iec_path = "%s.%s%d"%(self.InstancePath, block.GetType(), block.GetId())
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   714
                    else:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   715
                        iec_path = "%s.%s%d_%s"%(self.InstancePath, block.GetType(), block.GetId(), connectorname)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   716
            elif isinstance(block, FBD_Variable):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   717
                iec_path = "%s.%s"%(self.InstancePath, block.GetName())
388
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   718
            elif isinstance(block, FBD_Connector):
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   719
                connection = self.GetConnectorByName(block.GetName())
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   720
                if connection is not None:
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   721
                    connector = connection.GetConnector()
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   722
                    if len(connector.Wires) == 1:
7ea1f5094df3 Adding support for testing type between element connected with connector/continuation
laurent
parents: 384
diff changeset
   723
                        iec_path = self.GetElementIECPath(connector.Wires[0][0])
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   724
        elif isinstance(element, LD_Contact):
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   725
            iec_path = "%s.%s"%(self.InstancePath, element.GetName())
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   726
        elif isinstance(element, SFC_Step):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   727
            iec_path = "%s.%s.X"%(self.InstancePath, element.GetName())
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   728
        elif isinstance(element, SFC_Transition):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   729
            connectors = element.GetConnectors()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   730
            previous_steps = self.GetPreviousSteps(connectors["input"])
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   731
            next_steps = self.GetNextSteps(connectors["output"])
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   732
            iec_path = "%s.%s->%s"%(self.InstancePath, ",".join(previous_steps), ",".join(next_steps))
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   733
        return iec_path
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   734
       
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   735
#-------------------------------------------------------------------------------
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   736
#                              Reset functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   737
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   738
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   739
    # Resets Viewer lists
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   740
    def ResetView(self):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   741
        self.Blocks = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   742
        self.Wires = {}
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   743
        self.Comments = {}
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   744
        self.Subscribed = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   745
        self.SelectedElement = None
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
   746
        self.HighlightedElement = None
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   747
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   748
    def Flush(self):
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   749
        self.DeleteDataConsumers()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   750
        for block in self.Blocks.itervalues():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   751
            block.Flush()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   752
    
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   753
    # Remove all elements
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   754
    def CleanView(self):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   755
        for block in self.Blocks.itervalues():
47
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   756
            block.Clean()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   757
        self.ResetView()
2b2f8d88e6d3 Interface changed to show pou interface at the bottom of the window
lbessard
parents: 45
diff changeset
   758
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   759
    # Changes Viewer mode
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   760
    def SetMode(self, mode):
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   761
        if self.Mode != mode or mode == MODE_SELECTION:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   762
            self.Mode = mode
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   763
            self.SavedMode = False
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   764
        else:
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   765
            self.SavedMode = True
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   766
        # Reset selection
3
86ccc89d7b0b FBD Blocks and Variables can now be modified and wires can't be unconnected on both sides
lbessard
parents: 2
diff changeset
   767
        if self.Mode != MODE_SELECTION and self.SelectedElement:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   768
            self.SelectedElement.SetSelected(False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   769
            self.SelectedElement = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   770
    
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   771
    # Return current drawing mode
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   772
    def GetDrawingMode(self):
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   773
        return self.ParentWindow.GetDrawingMode()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   774
    
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   775
    # Buffer the last model state
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   776
    def RefreshBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   777
        self.Controler.BufferProject()
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   778
        self.ParentWindow.RefreshTitle()
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   779
        self.ParentWindow.RefreshEditMenu()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   780
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   781
    # Refresh the current scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   782
    def RefreshScaling(self, refresh=True):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   783
        properties = self.Controler.GetProjectProperties(self.Debug)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   784
        scaling = properties["scaling"][self.CurrentLanguage]
380
9ca678ee827f Bug with scaling when one dimension not defined fixed
laurent
parents: 375
diff changeset
   785
        if scaling[0] != 0 and scaling[1] != 0:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   786
            self.Scaling = scaling
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   787
            if self.DrawGrid:
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   788
                width = max(2, int(scaling[0] * self.ViewScale[0]))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   789
                height = max(2, int(scaling[1] * self.ViewScale[1]))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   790
                bitmap = wx.EmptyBitmap(width, height)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   791
                dc = wx.MemoryDC(bitmap)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   792
                dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   793
                dc.Clear()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   794
                dc.SetPen(wx.Pen(wx.Colour(180, 180, 180)))
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   795
                dc.DrawPoint(0, 0)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   796
                self.GridBrush = wx.BrushFromBitmap(bitmap)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   797
            else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   798
                self.GridBrush = wx.TRANSPARENT_BRUSH
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   799
        else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   800
            self.Scaling = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   801
            self.GridBrush = wx.TRANSPARENT_BRUSH
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   802
        page_size = properties["pageSize"]
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   803
        if page_size != (0, 0):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   804
            self.PageSize = map(int, page_size)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   805
            self.PagePen = wx.Pen(wx.Colour(180, 180, 180))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   806
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   807
            self.PageSize = None
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   808
            self.PagePen = wx.TRANSPARENT_PEN
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   809
        if refresh:
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
   810
            self.RefreshVisibleElements()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
   811
            self.Refresh(False)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   812
        
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
   813
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   814
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   815
#                          Refresh functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   816
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   817
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   818
    def UpdateRefreshRect(self, refresh_rect):
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   819
        if self.NewDataRefreshRect is None:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   820
            self.NewDataRefreshRect = refresh_rect
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   821
        else:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   822
            self.NewDataRefreshRect.Union(refresh_rect)
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   823
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   824
    def RefreshNewData(self):
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   825
        if self.NewDataRefreshRect is not None:
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   826
            refresh_rect, self.NewDataRefreshRect = self.NewDataRefreshRect, None
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   827
            self.RefreshRect(self.GetScrolledRect(refresh_rect), False)
375
65ccc896b115 Bug with DebugViewer refresh fixed
greg
parents: 372
diff changeset
   828
        else:
65ccc896b115 Bug with DebugViewer refresh fixed
greg
parents: 372
diff changeset
   829
            DebugViewer.RefreshNewData(self)
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
   830
        
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   831
    def ResetBuffer(self):
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   832
        pass
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
   833
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   834
    # Refresh Viewer elements
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   835
    def RefreshView(self, selection=None):
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
   836
        self.Inhibit(True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   837
        self.current_id = 0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   838
        # Start by reseting Viewer
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   839
        self.Flush()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   840
        self.ResetView()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   841
        instance = {}
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   842
        # List of ids of already loaded blocks
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   843
        ids = []
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   844
        # Load Blocks until they are all loaded
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   845
        while instance is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   846
            instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, exclude = ids, debug = self.Debug)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   847
            if instance is not None:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   848
                self.loadInstance(instance, ids, selection)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   849
        self.RefreshScrollBars()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   850
        
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   851
        for wire in self.Wires:
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
   852
            if not wire.IsConnectedCompatible():
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   853
                wire.SetValid(False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   854
            if self.Debug:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   855
                iec_path = self.GetElementIECPath(wire)
432
f4c0e9c9b3b9 fix LD debug viewer (broken by 25ffba)
b.taylor@willowglen.ca
parents: 416
diff changeset
   856
                if iec_path is None:
f4c0e9c9b3b9 fix LD debug viewer (broken by 25ffba)
b.taylor@willowglen.ca
parents: 416
diff changeset
   857
                    block = wire.EndConnected.GetParentBlock()
f4c0e9c9b3b9 fix LD debug viewer (broken by 25ffba)
b.taylor@willowglen.ca
parents: 416
diff changeset
   858
                    if isinstance(block, LD_PowerRail):
f4c0e9c9b3b9 fix LD debug viewer (broken by 25ffba)
b.taylor@willowglen.ca
parents: 416
diff changeset
   859
                        wire.SetValue(True)
f4c0e9c9b3b9 fix LD debug viewer (broken by 25ffba)
b.taylor@willowglen.ca
parents: 416
diff changeset
   860
                elif self.AddDataConsumer(iec_path.upper(), wire) is None:
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   861
                    wire.SetValue("undefined")
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   862
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   863
        if self.Debug:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   864
            for block in self.Blocks.itervalues():
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   865
                block.SpreadCurrent()
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   866
                iec_path = self.GetElementIECPath(block)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
   867
                if iec_path is not None:
361
62570186dad4 Adding support for synchronize refreshing with tick and limit it to a defined period
greg
parents: 352
diff changeset
   868
                    self.AddDataConsumer(iec_path.upper(), block)
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
   869
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
   870
        self.Inhibit(False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
   871
        self.RefreshVisibleElements()
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
   872
        self.ShowErrors()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
   873
        self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   874
    
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   875
    def GetPreviousSteps(self, connector):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   876
        steps = []
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   877
        for wire, handle in connector.GetWires():
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   878
            previous = wire.GetOtherConnected(connector).GetParentBlock()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   879
            if isinstance(previous, SFC_Step):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   880
                steps.append(previous.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   881
            elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   882
                connectors = previous.GetConnectors()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   883
                for input in connectors["inputs"]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   884
                    steps.extend(self.GetPreviousSteps(input))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   885
        return steps
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   886
    
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   887
    def GetNextSteps(self, connector):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   888
        steps = []
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   889
        for wire, handle in connector.GetWires():
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   890
            next = wire.GetOtherConnected(connector).GetParentBlock()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   891
            if isinstance(next, SFC_Step):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   892
                steps.append(next.GetName())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   893
            elif isinstance(next, SFC_Jump):
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   894
                steps.append(next.GetTarget())
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   895
            elif isinstance(next, SFC_Divergence) and next.GetType() in [SIMULTANEOUS_DIVERGENCE, SELECTION_CONVERGENCE]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   896
                connectors = next.GetConnectors()
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   897
                for output in connectors["outputs"]:
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   898
                    steps.extend(self.GetNextSteps(output))
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   899
        return steps
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
   900
    
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   901
    def GetMaxSize(self):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   902
        maxx = maxy = 0
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
   903
        for element in self.GetElements():
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   904
            bbox = element.GetBoundingBox()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   905
            maxx = max(maxx, bbox.x + bbox.width)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
   906
            maxy = max(maxy, bbox.y + bbox.height)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   907
        return maxx, maxy
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   908
    
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   909
    def RefreshScrollBars(self, width_incr=0, height_incr=0):
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   910
        xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   911
        window_size = self.GetClientSize()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   912
        maxx, maxy = self.GetMaxSize()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   913
        maxx = max(maxx + WINDOW_BORDER, (xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0])
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   914
        maxy = max(maxy + WINDOW_BORDER, (ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   915
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   916
            extent = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   917
            maxx = max(maxx, extent.x + extent.width)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   918
            maxy = max(maxy, extent.y + extent.height)
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   919
        maxx = int(maxx * self.ViewScale[0])
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
   920
        maxy = int(maxy * self.ViewScale[1])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
   921
        self.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT, 
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
   922
            round(maxx / SCROLLBAR_UNIT) + width_incr, round(maxy / SCROLLBAR_UNIT) + height_incr, 
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
   923
            xstart, ystart, True)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   924
    
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   925
    def SelectInGroup(self, element):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   926
        element.SetSelected(True)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   927
        if self.SelectedElement is None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   928
            self.SelectedElement = element
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   929
        elif isinstance(self.SelectedElement, Graphic_Group):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   930
            self.SelectedElement.SelectElement(element)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   931
        else:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   932
            group = Graphic_Group(self)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   933
            group.SelectElement(self.SelectedElement)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   934
            group.SelectElement(element)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   935
            self.SelectedElement = group
95
ee66a9a1748b Corrections for wx version 2.8.4 and Windows
lbessard
parents: 94
diff changeset
   936
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   937
    # Load instance from given informations
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   938
    def loadInstance(self, instance, ids, selection):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   939
        ids.append(instance["id"])
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   940
        self.current_id = max(self.current_id, instance["id"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   941
        creation_function = ElementCreationFunctions.get(instance["type"], None)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   942
        connectors = {"inputs" : [], "outputs" : []}
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   943
        specific_values = instance["specific_values"]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   944
        if creation_function is not None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   945
            element = creation_function(self, instance["id"], specific_values)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   946
            if isinstance(element, SFC_Step):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   947
                if len(instance["inputs"]) > 0:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   948
                    element.AddInput()
400
12b55d82d363 Bug loading step with wrong input definition fixed
laurent
parents: 391
diff changeset
   949
                else:
12b55d82d363 Bug loading step with wrong input definition fixed
laurent
parents: 391
diff changeset
   950
                    element.RemoveInput()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   951
                if len(instance["outputs"]) > 0:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   952
                    element.AddOutput()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   953
            if isinstance(element, SFC_Transition) and specific_values["condition_type"] == "connection":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   954
                connector = element.GetConditionConnector()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   955
                self.CreateWires(connector, id, specific_values["connection"]["links"], ids, selection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
   956
        else:
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   957
            executionControl = False
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   958
            for input in instance["inputs"]:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   959
                if input["negated"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   960
                    connectors["inputs"].append((input["name"], None, "negated"))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   961
                elif input["edge"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   962
                    connectors["inputs"].append((input["name"], None, input["edge"]))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   963
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   964
                    connectors["inputs"].append((input["name"], None, "none"))
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   965
            for output in instance["outputs"]:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   966
                if output["negated"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   967
                    connectors["outputs"].append((output["name"], None, "negated"))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   968
                elif output["edge"]:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   969
                    connectors["outputs"].append((output["name"], None, output["edge"]))
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   970
                else:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
   971
                    connectors["outputs"].append((output["name"], None, "none"))
290
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   972
            if len(connectors["inputs"]) > 0 and connectors["inputs"][0][0] == "EN":
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   973
                connectors["inputs"].pop(0)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   974
                executionControl = True
290
56c4fe6b7012 Bug when searching for EN/ENO on block without interface fixed
greg
parents: 283
diff changeset
   975
            if len(connectors["outputs"]) > 0 and connectors["outputs"][0][0] == "ENO":
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   976
                connectors["outputs"].pop(0)
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
   977
                executionControl = True
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   978
            if specific_values["name"] is None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   979
                specific_values["name"] = ""
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   980
            element = FBD_Block(self, instance["type"], specific_values["name"], 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   981
                      instance["id"], len(connectors["inputs"]), 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   982
                      connectors=connectors, executionControl=executionControl, 
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   983
                      executionOrder=specific_values["executionOrder"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   984
        element.SetPosition(instance["x"], instance["y"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   985
        element.SetSize(instance["width"], instance["height"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   986
        if isinstance(element, Comment):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   987
            self.AddComment(element)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   988
        else:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   989
            self.AddBlock(element)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   990
            connectors = element.GetConnectors()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   991
        for i, input_connector in enumerate(instance["inputs"]):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   992
            if i < len(connectors["inputs"]):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   993
                connector = connectors["inputs"][i]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   994
                connector.SetPosition(wx.Point(*input_connector["position"]))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   995
                if input_connector.get("negated", False):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   996
                    connector.SetNegated(True)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   997
                if input_connector.get("edge", "none") != "none":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   998
                    connector.SetEdge(input_connector["edge"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
   999
                self.CreateWires(connector, instance["id"], input_connector["links"], ids, selection)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1000
        for i, output_connector in enumerate(instance["outputs"]):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1001
            if i < len(connectors["outputs"]):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1002
                connector = connectors["outputs"][i]
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1003
                if output_connector.get("negated", False):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1004
                    connector.SetNegated(True)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1005
                if output_connector.get("edge", "none") != "none":
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1006
                    connector.SetEdge(output_connector["edge"])
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1007
                connector.SetPosition(wx.Point(*output_connector["position"]))
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1008
        if selection is not None and selection[0].get(instance["id"], False):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1009
            self.SelectInGroup(element)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1010
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1011
    def CreateWires(self, start_connector, id, links, ids, selection=None):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1012
        for link in links:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1013
            refLocalId = link["refLocalId"]
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1014
            if refLocalId is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1015
                if refLocalId not in ids:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1016
                    new_instance = self.Controler.GetEditedElementInstanceInfos(self.TagName, refLocalId, debug = self.Debug)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1017
                    if new_instance is not None:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1018
                        self.loadInstance(new_instance, ids, selection)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1019
                connected = self.FindElementById(refLocalId)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1020
                if connected is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1021
                    points = link["points"]
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1022
                    end_connector = connected.GetConnector(wx.Point(points[-1][0], points[-1][1]), link["formalParameter"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1023
                    if end_connector is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1024
                        wire = Wire(self)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1025
                        wire.SetPoints(points)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1026
                        start_connector.Connect((wire, 0), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1027
                        end_connector.Connect((wire, -1), False)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1028
                        wire.ConnectStartPoint(None, start_connector)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1029
                        wire.ConnectEndPoint(None, end_connector)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1030
                        self.AddWire(wire)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1031
                        if selection is not None and (\
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1032
                           selection[1].get((id, refLocalId), False) or \
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1033
                           selection[1].get((refLocalId, id), False)):
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1034
                            self.SelectInGroup(wire)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1035
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1036
    def IsOfType(self, type, reference):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1037
        return self.Controler.IsOfType(type, reference, self.Debug)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1038
    
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1039
    def IsEndType(self, type):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1040
        return self.Controler.IsEndType(type)
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1041
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1042
    def GetBlockType(self, type, inputs = None):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1043
        return self.Controler.GetBlockType(type, inputs, self.Debug)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1044
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1045
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1046
#                          Search Element functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1047
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1048
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1049
    def FindBlock(self, pos):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1050
        for block in self.Blocks.itervalues():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1051
            if block.HitTest(pos) or block.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1052
                return block
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1053
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1054
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1055
    def FindWire(self, pos):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1056
        for wire in self.Wires:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1057
            if wire.HitTest(pos) or wire.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1058
                return wire
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1059
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1060
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1061
    def FindElement(self, pos, exclude_group = False):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1062
        if self.SelectedElement and not (exclude_group and isinstance(self.SelectedElement, Graphic_Group)):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1063
            if self.SelectedElement.HitTest(pos) or self.SelectedElement.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1064
                return self.SelectedElement
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1065
        for element in self.GetElements():
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1066
            if element.HitTest(pos) or element.TestHandle(pos) != (0, 0):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1067
                return element
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1068
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1069
    
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1070
    def FindBlockConnector(self, pos, direction = None, exclude = None):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1071
        for block in self.Blocks.itervalues():
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1072
            result = block.TestConnector(pos, direction, exclude)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1073
            if result:
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1074
                return result
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1075
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1076
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1077
    def FindElementById(self, id):
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1078
        block = self.Blocks.get(id, None)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1079
        if block is not None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1080
            return block
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1081
        comment = self.Comments.get(id, None)
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1082
        if comment is not None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1083
            return comment
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1084
        return None
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1085
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1086
    def SearchElements(self, bbox):
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1087
        elements = []
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1088
        for element in self.GetElements():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1089
            if element.IsInSelection(bbox):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1090
                elements.append(element)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1091
        return elements
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1092
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1093
    def SelectAll(self):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1094
        if self.SelectedElement is not None:
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1095
            self.SelectedElement.SetSelected(False)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1096
        self.SelectedElement = Graphic_Group(self)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1097
        for element in self.GetElements():
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1098
            self.SelectedElement.SelectElement(element)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1099
        self.SelectedElement.SetSelected(True)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1100
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1101
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1102
#                           Popup menu functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1103
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1104
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1105
    def PopupBlockMenu(self, connector = None):
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1106
        if connector is not None and connector.IsCompatible("BOOL"):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1107
            type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1108
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1109
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1110
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, type != "function")
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1111
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, type != "function")
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1112
        else:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1113
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1114
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1115
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1116
            self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1117
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1118
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1119
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1120
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1121
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1122
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug))
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1123
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1124
        if connector is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1125
            if connector.IsNegated():
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1126
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS1, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1127
            elif connector.GetEdge() == "rising":
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1128
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS2, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1129
            elif connector.GetEdge() == "falling":
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1130
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS3, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1131
            else:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1132
                self.ContextualMenu.Check(ID_VIEWERCONTEXTUALMENUITEMS0, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1133
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1134
    
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1135
    def PopupWireMenu(self, delete=True):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1136
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1137
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1138
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1139
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1140
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, True)
235
7b58a3b5b6ec Change in layout from AuiMDIParentFrame to AuiNotebook
lbessard
parents: 231
diff changeset
  1141
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, delete)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1142
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1143
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1144
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1145
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1146
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1147
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1148
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1149
    def PopupDivergenceMenu(self, connector):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1150
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1151
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1152
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1153
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1154
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1155
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1156
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1157
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, connector)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1158
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1159
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1160
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1161
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1162
    
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1163
    def PopupGroupMenu(self):
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1164
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1165
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1166
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1167
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1168
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1169
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1170
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1171
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1172
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1173
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1174
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1175
        self.PopupMenu(self.ContextualMenu)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1176
    
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1177
    def PopupDefaultMenu(self, block = True):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1178
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS0, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1179
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS1, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1180
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS2, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1181
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS3, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1182
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS5, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1183
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS6, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1184
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS8, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1185
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS9, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1186
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS14, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1187
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS16, False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1188
        self.ContextualMenu.Enable(ID_VIEWERCONTEXTUALMENUITEMS17, block)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1189
        self.PopupMenu(self.ContextualMenu)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1190
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1191
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1192
#                            Menu items functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1193
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1194
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1195
    def OnAlignLeftMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1196
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1197
            self.SelectedElement.AlignElements(ALIGN_LEFT, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1198
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1199
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1200
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1201
    def OnAlignCenterMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1202
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1203
            self.SelectedElement.AlignElements(ALIGN_CENTER, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1204
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1205
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1206
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1207
    def OnAlignRightMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1208
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1209
            self.SelectedElement.AlignElements(ALIGN_RIGHT, None)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1210
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1211
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1212
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1213
    def OnAlignTopMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1214
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1215
            self.SelectedElement.AlignElements(None, ALIGN_TOP)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1216
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1217
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1218
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1219
    def OnAlignMiddleMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1220
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1221
            self.SelectedElement.AlignElements(None, ALIGN_MIDDLE)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1222
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1223
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1224
    
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1225
    def OnAlignBottomMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1226
        if self.SelectedElement is not None and isinstance(self.SelectedElement, Graphic_Group):
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1227
            self.SelectedElement.AlignElements(None, ALIGN_BOTTOM)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1228
            self.RefreshBuffer()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1229
            self.Refresh(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1230
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1231
    def OnNoModifierMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1232
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1233
            self.SelectedElement.SetConnectorNegated(False)
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1234
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1235
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1236
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1237
    def OnNegatedMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1238
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1239
            self.SelectedElement.SetConnectorNegated(True)
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1240
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1241
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1242
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1243
    def OnRisingEdgeMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1244
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1245
            self.SelectedElement.SetConnectorEdge("rising")
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1246
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1247
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1248
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1249
    def OnFallingEdgeMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1250
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1251
            self.SelectedElement.SetConnectorEdge("falling")
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1252
            self.SelectedElement.Refresh()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1253
            self.RefreshBuffer()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1254
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1255
    def OnAddSegmentMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1256
        if self.SelectedElement is not None and self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1257
            self.SelectedElement.AddSegment()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1258
            self.SelectedElement.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1259
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1260
    def OnDeleteSegmentMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1261
        if self.SelectedElement is not None and self.IsWire(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1262
            self.SelectedElement.DeleteSegment()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1263
            self.SelectedElement.Refresh()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1264
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1265
    def OnAddBranchMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1266
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1267
            self.AddDivergenceBranch(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1268
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1269
    def OnDeleteBranchMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1270
        if self.SelectedElement is not None and self.IsBlock(self.SelectedElement):
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1271
            self.RemoveDivergenceBranch(self.SelectedElement)
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1272
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1273
    def OnEditBlockMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1274
        if self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1275
            self.ParentWindow.EditProjectElement(ITEM_POU, "P::%s"%self.SelectedElement.GetType())
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1276
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1277
    def OnDeleteMenu(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1278
        if self.SelectedElement is not None:
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1279
            self.SelectedElement.Delete()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1280
            self.SelectedElement = None
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1281
            self.RefreshBuffer()
206
f7c85a5939dc Bug with RightUp refresh element fixed
lbessard
parents: 202
diff changeset
  1282
            self.Refresh(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1283
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1284
    def OnClearExecutionOrderMenu(self, event):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1285
        self.Controler.ClearEditedElementExecutionOrder(self.TagName)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1286
        self.RefreshBuffer()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1287
        self.RefreshView()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1288
        
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1289
    def OnResetExecutionOrderMenu(self, event):
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1290
        self.Controler.ResetEditedElementExecutionOrder(self.TagName)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1291
        self.RefreshBuffer()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1292
        self.RefreshView()
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1293
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1294
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1295
#                          Mouse event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1296
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1297
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1298
    def OnViewerLeftDown(self, event):
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1299
        if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1300
            dc = self.GetLogicalDC()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1301
            pos = event.GetLogicalPosition(dc)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1302
            if event.ShiftDown() and not event.ControlDown() and self.SelectedElement is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1303
                element = self.FindElement(pos, True)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1304
                if element is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1305
                    if isinstance(self.SelectedElement, Graphic_Group):
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1306
                        self.SelectedElement.SetSelected(False)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1307
                        self.SelectedElement.SelectElement(element)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1308
                    elif self.SelectedElement is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1309
                        group = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1310
                        group.SelectElement(self.SelectedElement)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1311
                        group.SelectElement(element)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1312
                        self.SelectedElement = group
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1313
                    elements = self.SelectedElement.GetElements()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1314
                    if len(elements) == 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1315
                        self.SelectedElement = element
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1316
                    elif len(elements) == 1:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1317
                        self.SelectedElement = elements[0]
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1318
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1319
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1320
                element = self.FindElement(pos)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1321
                if not self.Debug and (element is None or element.TestHandle(pos) == (0, 0)):
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1322
                    connector = self.FindBlockConnector(pos)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1323
                else:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1324
                    connector = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1325
                if not self.Debug and self.DrawingWire:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1326
                    self.DrawingWire = False
174
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1327
                    if self.SelectedElement is not None:
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1328
                        if element is None or element.TestHandle(pos) == (0, 0):
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1329
                            connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1330
                        if connector is not None:
174
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1331
                            event.Dragging = lambda : True
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1332
                            self.SelectedElement.OnMotion(event, self.GetLogicalDC(), self.Scaling)
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1333
                        if self.SelectedElement.EndConnected is not None:
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1334
                            self.SelectedElement.ResetPoints()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1335
                            self.SelectedElement.GeneratePoints()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1336
                            self.SelectedElement.RefreshModel()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1337
                            self.SelectedElement.SetSelected(True)
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1338
                            element = self.SelectedElement
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1339
                            self.RefreshBuffer()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1340
                        else:
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1341
                            rect = self.SelectedElement.GetRedrawRect()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1342
                            self.SelectedElement.Delete()
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1343
                            self.SelectedElement = None
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1344
                            element = None
97bbbaa54964 Bug on wire Drawing fixed
lbessard
parents: 169
diff changeset
  1345
                            self.RefreshRect(self.GetScrolledRect(rect), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1346
                elif not self.Debug and connector is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1347
                    self.DrawingWire = True
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1348
                    scaled_pos = GetScaledEventPosition(event, self.GetLogicalDC(), self.Scaling)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1349
                    if (connector.GetDirection() == EAST):
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1350
                        wire = Wire(self, [wx.Point(pos.x, pos.y), EAST], [wx.Point(scaled_pos.x, scaled_pos.y), WEST])
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1351
                    else:
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1352
                        wire = Wire(self, [wx.Point(pos.x, pos.y), WEST], [wx.Point(scaled_pos.x, scaled_pos.y), EAST])
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1353
                    wire.oldPos = scaled_pos
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1354
                    wire.Handle = (HANDLE_POINT, 0)
327
7fd5233ce5ce Adding support for contraining move to only one direction when control down
lbessard
parents: 323
diff changeset
  1355
                    wire.ProcessDragging(0, 0, event, None)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1356
                    wire.Handle = (HANDLE_POINT, 1)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1357
                    self.AddWire(wire)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1358
                    if self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1359
                        self.SelectedElement.SetSelected(False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1360
                    self.SelectedElement = wire
259
fae941a87cff Bug with invisible created wires fixed
lbessard
parents: 253
diff changeset
  1361
                    self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1362
                    self.SelectedElement.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1363
                else:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1364
                    if self.SelectedElement is not None and self.SelectedElement != element:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1365
                        self.SelectedElement.SetSelected(False)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1366
                        self.SelectedElement = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1367
                    if element is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1368
                        self.SelectedElement = element
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1369
                        if self.Debug:
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1370
                            self.StartMousePos = event.GetPosition()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1371
                            Graphic_Element.OnLeftDown(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1372
                        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1373
                            self.SelectedElement.OnLeftDown(event, dc, self.Scaling)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1374
                        self.SelectedElement.Refresh()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1375
                    else:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1376
                        self.rubberBand.Reset()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1377
                        self.rubberBand.OnLeftDown(event, dc, self.Scaling)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1378
        elif self.Mode in [MODE_BLOCK, MODE_VARIABLE, MODE_CONNECTION, MODE_COMMENT, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1379
                           MODE_CONTACT, MODE_COIL, MODE_POWERRAIL, MODE_INITIALSTEP, 
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1380
                           MODE_STEP, MODE_TRANSITION, MODE_DIVERGENCE, MODE_JUMP, MODE_ACTION]:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1381
            self.rubberBand.Reset()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1382
            self.rubberBand.OnLeftDown(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1383
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1384
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1385
    def OnViewerLeftUp(self, event):
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1386
        self.StartMousePos = None
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1387
        if self.rubberBand.IsShown():
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1388
            if self.Mode == MODE_SELECTION:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1389
                elements = self.SearchElements(self.rubberBand.GetCurrentExtent())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1390
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1391
                if len(elements) == 1:
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1392
                    self.SelectedElement = elements[0]
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1393
                    self.SelectedElement.SetSelected(True)
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1394
                elif len(elements) > 1:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1395
                    self.SelectedElement = Graphic_Group(self)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1396
                    self.SelectedElement.SetElements(elements)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1397
                    self.SelectedElement.SetSelected(True)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1398
            else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1399
                bbox = self.rubberBand.GetCurrentExtent()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1400
                self.rubberBand.OnLeftUp(event, self.GetLogicalDC(), self.Scaling)                
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1401
                if self.Mode == MODE_BLOCK:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1402
                    wx.CallAfter(self.AddNewBlock, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1403
                elif self.Mode == MODE_VARIABLE:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1404
                    wx.CallAfter(self.AddNewVariable, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1405
                elif self.Mode == MODE_CONNECTION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1406
                    wx.CallAfter(self.AddNewConnection, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1407
                elif self.Mode == MODE_COMMENT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1408
                    wx.CallAfter(self.AddNewComment, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1409
                elif self.Mode == MODE_CONTACT:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1410
                    wx.CallAfter(self.AddNewContact, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1411
                elif self.Mode == MODE_COIL:
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1412
                    wx.CallAfter(self.AddNewCoil, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1413
                elif self.Mode == MODE_POWERRAIL:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1414
                    wx.CallAfter(self.AddNewPowerRail, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1415
                elif self.Mode == MODE_INITIALSTEP:
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1416
                    wx.CallAfter(self.AddNewStep, bbox, True)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1417
                elif self.Mode == MODE_STEP:
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1418
                    wx.CallAfter(self.AddNewStep, bbox, False)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1419
                elif self.Mode == MODE_TRANSITION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1420
                    wx.CallAfter(self.AddNewTransition, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1421
                elif self.Mode == MODE_DIVERGENCE:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1422
                    wx.CallAfter(self.AddNewDivergence, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1423
                elif self.Mode == MODE_JUMP:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1424
                    wx.CallAfter(self.AddNewJump, bbox)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1425
                elif self.Mode == MODE_ACTION:
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1426
                    wx.CallAfter(self.AddNewActionBlock, bbox)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1427
        elif self.Mode == MODE_SELECTION and self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1428
            dc = self.GetLogicalDC()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1429
            if not self.Debug and self.DrawingWire:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1430
                pos = event.GetLogicalPosition(dc)
243
c5da8b706cde Adding support for allowing connections only between an input and an output connector
lbessard
parents: 239
diff changeset
  1431
                connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection())
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1432
                if self.SelectedElement.EndConnected is not None:
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1433
                    self.DrawingWire = False
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1434
                    self.SelectedElement.StartConnected.HighlightParentBlock(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1435
                    self.SelectedElement.EndConnected.HighlightParentBlock(False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1436
                    self.SelectedElement.ResetPoints()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1437
                    self.SelectedElement.OnMotion(event, dc, self.Scaling)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1438
                    self.SelectedElement.GeneratePoints()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1439
                    self.SelectedElement.RefreshModel()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1440
                    if self.HighlightedElement is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1441
                        self.HighlightedElement.SetHighlighted(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1442
                        self.HighlightedElement = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1443
                    self.SelectedElement.SetHighlighted(True)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1444
                    self.HighlightedElement = self.SelectedElement
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1445
                    self.SelectedElement.SetSelected(True)
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1446
                    self.RefreshBuffer()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1447
                elif connector is None or self.SelectedElement.GetDragging():
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1448
                    self.DrawingWire = False
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1449
                    rect = self.SelectedElement.GetRedrawRect()
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1450
                    self.SelectedElement.Delete()
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1451
                    self.SelectedElement = None
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1452
                    self.RefreshRect(self.GetScrolledRect(rect), False)
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1453
            else:
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1454
                if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1455
                    Graphic_Element.OnLeftUp(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1456
                else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1457
                    self.SelectedElement.OnLeftUp(event, dc, self.Scaling)
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
  1458
                wx.CallAfter(self.SetCurrentCursor, 0)
106
3fc63036de16 Adding support for variable type compatibility check after drag and drop
lbessard
parents: 102
diff changeset
  1459
        if self.Mode != MODE_SELECTION and not self.SavedMode:
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  1460
            wx.CallAfter(self.ParentWindow.ResetCurrentMode)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1461
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1462
    
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1463
    def OnViewerMiddleDown(self, event):
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1464
        self.StartMousePos = event.GetPosition()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1465
        self.StartScreenPos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1466
        event.Skip()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1467
        
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1468
    def OnViewerMiddleUp(self, event):
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1469
        self.StartMousePos = None
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1470
        self.StartScreenPos = None
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1471
        event.Skip()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1472
    
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1473
    def OnViewerRightDown(self, event):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1474
        if self.Mode == MODE_SELECTION:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1475
            dc = self.GetLogicalDC()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1476
            pos = event.GetLogicalPosition(dc)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1477
            element = self.FindElement(pos)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1478
            if self.SelectedElement is not None and self.SelectedElement != element:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1479
                self.SelectedElement.SetSelected(False)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1480
                self.SelectedElement = None
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1481
            if element:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1482
                self.SelectedElement = element
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1483
                if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1484
                    Graphic_Element.OnRightDown(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1485
                else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1486
                    self.SelectedElement.OnRightDown(event, dc, self.Scaling)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1487
                self.SelectedElement.Refresh()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1488
        event.Skip()
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1489
    
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1490
    def OnViewerRightUp(self, event):
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1491
        dc = self.GetLogicalDC()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1492
        if self.SelectedElement is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1493
            if self.Debug:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1494
                Graphic_Element.OnRightUp(self.SelectedElement, event, dc, self.Scaling)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1495
            else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1496
                self.SelectedElement.OnRightUp(event, dc, self.Scaling)
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
  1497
            wx.CallAfter(self.SetCurrentCursor, 0)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1498
        elif not self.Debug:
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  1499
            self.PopupDefaultMenu(False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1500
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1501
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1502
    def OnViewerLeftDClick(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1503
        if self.Mode == MODE_SELECTION and self.SelectedElement is not None:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1504
            if self.Debug:
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1505
                iec_path = self.GetElementIECPath(self.SelectedElement)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1506
                if iec_path is not None:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1507
                    if isinstance(self.SelectedElement, Wire):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1508
                        if self.SelectedElement.EndConnected is not None:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1509
                            var_type = self.SelectedElement.EndConnected.GetType()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1510
                            if self.Controler.IsOfType(var_type, "ANY_NUM", self.Debug) or\
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1511
                               self.Controler.IsOfType(var_type, "ANY_BIT", self.Debug):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1512
                                self.ParentWindow.OpenGraphicViewer(iec_path)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1513
                    else:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1514
                        self.ParentWindow.OpenGraphicViewer(iec_path)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1515
            elif event.ControlDown() and not event.ShiftDown():
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1516
                if self.IsBlock(self.SelectedElement) and self.SelectedElement.GetType() in self.Controler.GetProjectPouNames(self.Debug):
345
d79f73a337d7 fix bug when ctrl + DoubleClick
greg
parents: 343
diff changeset
  1517
                    self.ParentWindow.EditProjectElement(ITEM_POU, self.Controler.ComputePouName(self.SelectedElement.GetType()))
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1518
                else:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1519
                    self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1520
            elif event.ControlDown() and event.ShiftDown():
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1521
                movex, movey = self.SelectedElement.AdjustToScaling(self.Scaling)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1522
                self.SelectedElement.RefreshModel()
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1523
                self.RefreshBuffer()
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1524
                if movex != 0 or movey != 0:
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1525
                    self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
102
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1526
            else:
85875dcb7754 Adding edit user's POU by double click on block instance
lbessard
parents: 98
diff changeset
  1527
                self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1528
        event.Skip()
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1529
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1530
    def OnViewerMotion(self, event):
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1531
        refresh = False
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1532
        dc = self.GetLogicalDC()
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1533
        pos = GetScaledEventPosition(event, dc, self.Scaling)
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1534
        if event.MiddleIsDown():
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1535
            if self.StartMousePos is not None and self.StartScreenPos is not None:
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1536
                new_pos = event.GetPosition()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1537
                xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1538
                ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1539
                scrollx = max(0, self.StartScreenPos[0] - (new_pos[0] - self.StartMousePos[0]) / SCROLLBAR_UNIT)
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  1540
                scrolly = max(0, self.StartScreenPos[1] - (new_pos[1] - self.StartMousePos[1]) / SCROLLBAR_UNIT)
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1541
                if scrollx > xmax or scrolly > ymax:
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1542
                    self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1543
                    self.Scroll(scrollx, scrolly)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1544
                else:
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1545
                    self.Scroll(scrollx, scrolly)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1546
                    self.RefreshScrollBars()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1547
                self.RefreshVisibleElements()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  1548
        else:
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1549
            if not event.Dragging():
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1550
                if self.Debug:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1551
                    tooltip_pos = self.ClientToScreen(event.GetPosition())
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1552
                    tooltip_pos.x += 10
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1553
                    tooltip_pos.y += 10
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1554
                highlighted = self.FindElement(pos) 
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1555
                if self.HighlightedElement is not None and self.HighlightedElement != highlighted:
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1556
                    if self.Debug and isinstance(self.HighlightedElement, Wire):
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 332
diff changeset
  1557
                        self.HighlightedElement.ClearToolTip()
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1558
                    self.HighlightedElement.SetHighlighted(False)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1559
                    self.HighlightedElement = None
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1560
                if highlighted is not None and self.HighlightedElement != highlighted:
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1561
                    if self.Debug and isinstance(highlighted, Wire):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1562
                        highlighted.CreateToolTip(tooltip_pos)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1563
                    highlighted.SetHighlighted(True)
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1564
                elif self.Debug and highlighted is not None and isinstance(highlighted, Wire):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1565
                    highlighted.MoveToolTip(tooltip_pos)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1566
                self.HighlightedElement = highlighted
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1567
            if self.rubberBand.IsShown():
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1568
                self.rubberBand.OnMotion(event, dc, self.Scaling)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1569
            elif not self.Debug and self.Mode == MODE_SELECTION and self.SelectedElement is not None:
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1570
                if self.DrawingWire:
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1571
                    connector = self.FindBlockConnector(pos, self.SelectedElement.GetConnectionDirection(), self.SelectedElement.EndConnected)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1572
                    if not connector or self.SelectedElement.EndConnected == None:
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1573
                        self.SelectedElement.ResetPoints()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1574
                        movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1575
                        self.SelectedElement.GeneratePoints()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1576
                        if movex != 0 or movey != 0:
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1577
                            self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1578
                else:
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1579
                    movex, movey = self.SelectedElement.OnMotion(event, dc, self.Scaling)
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1580
                    if movex != 0 or movey != 0:
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1581
                        self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(movex, movey)), False)
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1582
            elif self.Debug and self.StartMousePos is not None and event.Dragging():
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1583
                pos = event.GetPosition()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1584
                if abs(self.StartMousePos.x - pos.x) > 5 or abs(self.StartMousePos.y - pos.y) > 5:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1585
                    iec_path = self.GetElementIECPath(self.SelectedElement)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1586
                    if iec_path is not None:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1587
                        self.StartMousePos = None
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1588
                        if self.HighlightedElement is not None:
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1589
                            if isinstance(self.HighlightedElement, Wire):
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1590
                                self.HighlightedElement.ClearToolTip()
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1591
                            self.HighlightedElement.SetHighlighted(False)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1592
                            self.HighlightedElement = None
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1593
                        data = wx.TextDataObject(str((iec_path, "debug")))
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1594
                        dragSource = wx.DropSource(self)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1595
                        dragSource.SetData(data)
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1596
                        dragSource.DoDragDrop()
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1597
            self.UpdateScrollPos(event)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1598
        event.Skip()
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1599
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1600
    def OnLeaveViewer(self, event):
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  1601
        self.StartMousePos = None
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1602
        if self.SelectedElement is not None and self.SelectedElement.GetDragging():
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1603
            event.Skip()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1604
        elif self.HighlightedElement is not None:
338
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 332
diff changeset
  1605
            if isinstance(self.HighlightedElement, Wire):
87e5015330ae Adding support for ToolTip on wire when debugging
lbessard
parents: 332
diff changeset
  1606
                self.HighlightedElement.ClearToolTip()
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1607
            self.HighlightedElement.SetHighlighted(False)
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  1608
            self.HighlightedElement = None
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1609
        event.Skip()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1610
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1611
    def UpdateScrollPos(self, event):
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1612
        if (event.Dragging() and self.SelectedElement is not None) or self.rubberBand.IsShown():
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1613
            position = event.GetPosition()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1614
            move_window = wx.Point()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1615
            window_size = self.GetClientSize()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1616
            xstart, ystart = self.GetViewStart()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1617
            if position.x < SCROLL_ZONE and xstart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1618
                move_window.x = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1619
            elif position.x > window_size[0] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1620
                move_window.x = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1621
            if position.y < SCROLL_ZONE and ystart > 0:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1622
                move_window.y = -1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1623
            elif position.y > window_size[1] - SCROLL_ZONE:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1624
                move_window.y = 1
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1625
            if move_window.x != 0 or move_window.y != 0:
267
a95bfb76a1eb Bug on refresh in any Viewer fixed
lbessard
parents: 264
diff changeset
  1626
                self.RefreshVisibleElements(xp = xstart + move_window.x, yp = ystart + move_window.y)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1627
                self.Scroll(xstart + move_window.x, ystart + move_window.y)
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1628
            self.RefreshScrollBars()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1629
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1630
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1631
#                          Keyboard event functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1632
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1633
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1634
    def OnChar(self, event):
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1635
        xpos, ypos = self.GetScrollPos(wx.HORIZONTAL), self.GetScrollPos(wx.VERTICAL)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1636
        xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1637
        ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1638
        keycode = event.GetKeyCode()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1639
        if self.Scaling is not None:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1640
            scaling = self.Scaling
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1641
        else:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1642
            scaling = (8, 8)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1643
        if not self.Debug and keycode == wx.WXK_DELETE and self.SelectedElement is not None:
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1644
            rect = self.SelectedElement.GetRedrawRect(1, 1)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1645
            self.SelectedElement.Delete()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1646
            self.SelectedElement = None
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1647
            self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1648
            self.RefreshScrollBars()
381
98890d848701 Redefine cursor switching procedure in graphic viewers
laurent
parents: 380
diff changeset
  1649
            wx.CallAfter(self.SetCurrentCursor, 0)
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1650
            self.RefreshRect(self.GetScrolledRect(rect), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1651
        elif not self.Debug and keycode == wx.WXK_RETURN and self.SelectedElement is not None:
138
9c74d00ce93e Last bugs on block and wire moving, resizing with cursor fixed
lbessard
parents: 128
diff changeset
  1652
            self.SelectedElement.OnLeftDClick(event, self.GetLogicalDC(), self.Scaling)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1653
        elif keycode == wx.WXK_LEFT:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1654
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1655
                self.Scroll(0, ypos)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1656
                self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1657
            elif event.ControlDown():
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1658
                self.Scroll(xpos - 1, ypos)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1659
                self.RefreshScrollBars()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1660
                self.RefreshVisibleElements()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1661
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1662
                self.SelectedElement.Move(-scaling[0], 0)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1663
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1664
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1665
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1666
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(-scaling[0], 0)), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1667
        elif keycode == wx.WXK_RIGHT:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1668
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1669
                self.Scroll(xmax, ypos)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1670
                self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1671
            elif event.ControlDown():
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1672
                self.RefreshScrollBars(width_incr=max(0, xpos + 1 - xmax))
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1673
                self.Scroll(xpos + 1, ypos)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1674
                self.RefreshVisibleElements()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1675
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1676
                self.SelectedElement.Move(scaling[0], 0)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1677
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1678
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1679
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1680
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(scaling[0], 0)), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1681
        elif keycode == wx.WXK_UP:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1682
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1683
                self.Scroll(xpos, 0)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1684
                self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1685
            elif event.ControlDown():
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1686
                self.Scroll(xpos, ypos - 1)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1687
                self.RefreshScrollBars()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1688
                self.RefreshVisibleElements()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1689
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1690
                self.SelectedElement.Move(0, -scaling[1])
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1691
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1692
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1693
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1694
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, -scaling[1])), False)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1695
        elif keycode == wx.WXK_DOWN:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1696
            if event.ControlDown() and event.ShiftDown():
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1697
                self.Scroll(xpos, ymax)
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1698
                self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1699
            elif event.ControlDown():
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1700
                self.RefreshScrollBars(height_incr=max(0, ypos + 1 - ymax))
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1701
                self.Scroll(xpos, ypos + 1)
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  1702
                self.RefreshVisibleElements()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1703
            elif not self.Debug and self.SelectedElement is not None:
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1704
                self.SelectedElement.Move(0, scaling[1])
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1705
                self.SelectedElement.RefreshModel()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1706
                self.RefreshBuffer()
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1707
                self.RefreshScrollBars()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  1708
                self.RefreshRect(self.GetScrolledRect(self.SelectedElement.GetRedrawRect(0, scaling[1])), False)
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1709
        elif not self.Debug and keycode == wx.WXK_SPACE and self.SelectedElement is not None and self.SelectedElement.Dragging:
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1710
            if self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement):
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1711
                block = self.CopyBlock(self.SelectedElement, wx.Point(*self.SelectedElement.GetPosition()))
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1712
                event = wx.MouseEvent()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1713
                event.m_x, event.m_y = self.ScreenToClient(wx.GetMousePosition())
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1714
                dc = self.GetLogicalDC()
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1715
                self.SelectedElement.OnLeftUp(event, dc, self.Scaling)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1716
                self.SelectedElement.SetSelected(False)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1717
                block.OnLeftDown(event, dc, self.Scaling)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1718
                self.SelectedElement = block
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1719
                self.SelectedElement.SetSelected(True)
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1720
                self.ParentWindow.RefreshVariablePanel(self.TagName)
267
a95bfb76a1eb Bug on refresh in any Viewer fixed
lbessard
parents: 264
diff changeset
  1721
                self.RefreshVisibleElements()
216
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1722
            else:
93af9ac5aeaf Not connecting wire on scaled graphics bug and forbidding copy on the fly of groups fixed
lbessard
parents: 213
diff changeset
  1723
                event.Skip()
97
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1724
        else:
28337cd092fd Bugs on Variable and Viewer DropTarget fixed
lbessard
parents: 95
diff changeset
  1725
            event.Skip()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1726
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1727
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1728
#                          Model adding functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1729
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1730
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1731
    def GetScaledSize(self, width, height):
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1732
        if self.Scaling is not None:
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1733
            width = round(float(width) / float(self.Scaling[0]) + 0.4) * self.Scaling[0]
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1734
            height = round(float(height) / float(self.Scaling[1]) + 0.4) * self.Scaling[1]
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1735
        return width, height
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  1736
    
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1737
    def AddNewBlock(self, bbox):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1738
        dialog = FBDBlockDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1739
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1740
        dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1741
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1742
        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1743
        dialog.SetMinBlockSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1744
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1745
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1746
            values = dialog.GetValues()
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1747
            values.setdefault("name", "")
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1748
            block = FBD_Block(self, values["type"], values["name"], id, 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1749
                    values["extension"], values["inputs"], 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1750
                    executionControl = values["executionControl"],
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  1751
                    executionOrder = values["executionOrder"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1752
            block.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1753
            block.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1754
            self.AddBlock(block)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1755
            self.Controler.AddEditedElementBlock(self.TagName, id, values["type"], values.get("name", None))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1756
            self.RefreshBlockModel(block)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1757
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1758
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1759
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1760
            self.ParentWindow.RefreshVariablePanel(self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  1761
            self.ParentWindow.RefreshInstancesTree()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1762
            block.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1763
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1764
    
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1765
    def AddNewVariable(self, bbox):
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1766
        words = self.TagName.split("::")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1767
        if words[0] == "T":
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1768
            dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2])
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  1769
        else:
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1770
            dialog = FBDVariableDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1771
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1772
        dialog.SetMinVariableSize((bbox.width, bbox.height))
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1773
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1774
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1775
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1776
            for var in vars:
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1777
                if var["Edit"]:
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  1778
                    varlist.append((var["Name"], var["Class"], var["Type"]))
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1779
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1780
        if returntype:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1781
            varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1782
        dialog.SetVariables(varlist)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1783
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1784
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1785
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1786
            variable = FBD_Variable(self, values["type"], values["name"], values["value_type"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1787
            variable.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1788
            variable.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1789
            self.AddBlock(variable)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1790
            self.Controler.AddEditedElementVariable(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1791
            self.RefreshVariableModel(variable)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1792
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1793
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1794
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1795
            variable.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1796
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1797
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1798
    def AddNewConnection(self, bbox):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1799
        dialog = ConnectionDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1800
        dialog.SetPreviewFont(self.GetFont())
330
d803ba077da0 Adding Test when creating ConnectionBlock
lbessard
parents: 327
diff changeset
  1801
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d803ba077da0 Adding Test when creating ConnectionBlock
lbessard
parents: 327
diff changeset
  1802
        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1803
        dialog.SetMinConnectionSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1804
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1805
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1806
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1807
            connection = FBD_Connector(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1808
            connection.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1809
            connection.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1810
            self.AddBlock(connection)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1811
            self.Controler.AddEditedElementConnection(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1812
            self.RefreshConnectionModel(connection)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1813
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1814
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1815
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1816
            connection.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1817
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1818
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1819
    def AddNewComment(self, bbox):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1820
        if wx.VERSION >= (2, 5, 0):
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  1821
            dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL|wx.TE_MULTILINE)
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  1822
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  1823
            dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), "", wx.OK|wx.CANCEL)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1824
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1825
            value = dialog.GetValue()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1826
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1827
            comment = Comment(self, value, id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1828
            comment.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1829
            min_width, min_height = comment.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1830
            comment.SetSize(*self.GetScaledSize(max(min_width,bbox.width),max(min_height,bbox.height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1831
            self.AddComment(comment)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1832
            self.Controler.AddEditedElementComment(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1833
            self.RefreshCommentModel(comment)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1834
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1835
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1836
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1837
            comment.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1838
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1839
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1840
    def AddNewContact(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1841
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1842
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1843
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1844
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1845
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1846
            for var in vars:
277
5fc11b2d4fbb Bug in contact edition not allowing output referencing fixed
lbessard
parents: 275
diff changeset
  1847
                if var["Type"] == "BOOL":
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1848
                    varlist.append(var["Name"])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1849
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1850
        dialog.SetValues({"name":"","type":CONTACT_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1851
        dialog.SetElementSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1852
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1853
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1854
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1855
            contact = LD_Contact(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1856
            contact.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1857
            contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1858
            self.AddBlock(contact)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1859
            self.Controler.AddEditedElementContact(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1860
            self.RefreshContactModel(contact)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1861
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1862
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1863
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1864
            contact.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1865
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1866
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1867
    def AddNewCoil(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1868
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1869
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1870
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1871
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1872
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1873
            for var in vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1874
                if var["Class"] != "Input" and var["Type"] == "BOOL":
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1875
                    varlist.append(var["Name"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1876
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1877
        if returntype == "BOOL":
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1878
            varlist.append(self.Controler.GetEditedElementName(self.TagName))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1879
        dialog.SetVariables(varlist)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1880
        dialog.SetValues({"name":"","type":COIL_NORMAL})
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  1881
        dialog.SetElementSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1882
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1883
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1884
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1885
            coil = LD_Coil(self, values["type"], values["name"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1886
            coil.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1887
            coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1888
            self.AddBlock(coil)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1889
            self.Controler.AddEditedElementCoil(self.TagName, id)
67
3a1b0afdaf84 Adding support for automatically generate function blocks in interface when a block is added
lbessard
parents: 64
diff changeset
  1890
            self.RefreshCoilModel(coil)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1891
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1892
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1893
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1894
            coil.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1895
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1896
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1897
    def AddNewPowerRail(self, bbox):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  1898
        dialog = LDPowerRailDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1899
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1900
        dialog.SetMinSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1901
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1902
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1903
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1904
            powerrail = LD_PowerRail(self, values["type"], id, [True for i in xrange(values["number"])])
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1905
            powerrail.SetPosition(bbox.x, bbox.y)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1906
            powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"]))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1907
            self.AddBlock(powerrail)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1908
            self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1909
            self.RefreshPowerRailModel(powerrail)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1910
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1911
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1912
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1913
            powerrail.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1914
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1915
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1916
    def AddNewStep(self, bbox, initial = False):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1917
        dialog = SFCStepDialog(self.ParentWindow, self.Controler, initial)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1918
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1919
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1920
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1921
        dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step)])
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1922
        dialog.SetMinStepSize((bbox.width, bbox.height))
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1923
        if dialog.ShowModal() == wx.ID_OK:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1924
            id = self.GetNewId()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1925
            values = dialog.GetValues()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1926
            step = SFC_Step(self, values["name"], initial, id)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1927
            if values["input"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1928
                step.AddInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1929
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1930
                step.RemoveInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1931
            if values["output"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1932
                step.AddOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1933
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1934
                step.RemoveOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1935
            if values["action"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1936
                step.AddAction()    
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1937
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1938
                step.RemoveAction()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1939
            step.SetPosition(bbox.x, bbox.y)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1940
            min_width, min_height = step.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1941
            step.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1942
            self.AddBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1943
            self.Controler.AddEditedElementStep(self.TagName, id)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1944
            self.RefreshStepModel(step)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1945
            self.RefreshBuffer()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1946
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1947
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1948
            step.Refresh()
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1949
        dialog.Destroy()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  1950
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1951
    def AddNewTransition(self, bbox):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1952
        dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1953
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1954
        dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1955
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1956
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1957
            values = dialog.GetValues()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  1958
            transition = SFC_Transition(self, values["type"], values["value"], values["priority"], id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1959
            transition.SetPosition(bbox.x, bbox.y)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1960
            min_width, min_height = transition.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1961
            transition.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1962
            self.AddBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1963
            self.Controler.AddEditedElementTransition(self.TagName, id)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1964
            self.RefreshTransitionModel(transition)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1965
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1966
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1967
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1968
            transition.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1969
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1970
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1971
    def AddNewDivergence(self, bbox):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  1972
        dialog = SFCDivergenceDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  1973
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1974
        dialog.SetMinSize((bbox.width, bbox.height))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  1975
        if dialog.ShowModal() == wx.ID_OK:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1976
            id = self.GetNewId()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1977
            values = dialog.GetValues()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1978
            divergence = SFC_Divergence(self, values["type"], values["number"], id)
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1979
            divergence.SetPosition(bbox.x, bbox.y)
111
0ec40799ba11 Bug on divergence creation with null size fixed
lbessard
parents: 108
diff changeset
  1980
            min_width, min_height = divergence.GetMinSize(True)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  1981
            divergence.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1982
            self.AddBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  1983
            self.Controler.AddEditedElementDivergence(self.TagName, id, values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1984
            self.RefreshDivergenceModel(divergence)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  1985
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  1986
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  1987
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  1988
            divergence.Refresh()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  1989
        dialog.Destroy()
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  1990
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1991
    def AddNewJump(self, bbox):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1992
        choices = []
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  1993
        for block in self.Blocks.itervalues():
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1994
            if isinstance(block, SFC_Step):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1995
                choices.append(block.GetName())
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  1996
        dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Add a new jump"), _("Please choose a target"), choices, wx.OK|wx.CANCEL)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1997
        if dialog.ShowModal() == wx.ID_OK:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1998
            id = self.GetNewId()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  1999
            value = dialog.GetStringSelection()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2000
            jump = SFC_Jump(self, value, id)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2001
            jump.SetPosition(bbox.x, bbox.y)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2002
            min_width, min_height = jump.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2003
            jump.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2004
            self.AddBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2005
            self.Controler.AddEditedElementJump(self.TagName, id)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2006
            self.RefreshJumpModel(jump)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2007
            self.RefreshBuffer()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2008
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2009
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2010
            jump.Refresh()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2011
        dialog.Destroy()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2012
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2013
    def AddNewActionBlock(self, bbox):
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2014
        dialog = ActionBlockDialog(self.ParentWindow)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2015
        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2016
        dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2017
        dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2018
        if dialog.ShowModal() == wx.ID_OK:
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2019
            actions = dialog.GetValues()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2020
            id = self.GetNewId()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2021
            actionblock = SFC_ActionBlock(self, actions, id)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2022
            actionblock.SetPosition(bbox.x, bbox.y)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2023
            min_width, min_height = actionblock.GetMinSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2024
            actionblock.SetSize(*self.GetScaledSize(max(bbox.width, min_width), max(bbox.height, min_height)))
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2025
            self.AddBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2026
            self.Controler.AddEditedElementActionBlock(self.TagName, id)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2027
            self.RefreshActionBlockModel(actionblock)
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2028
            self.RefreshBuffer()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2029
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2030
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2031
            actionblock.Refresh()
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2032
        dialog.Destroy()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2033
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2034
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2035
#                          Edit element content functions
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2036
#-------------------------------------------------------------------------------
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2037
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2038
    def EditBlockContent(self, block):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2039
        dialog = FBDBlockDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2040
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2041
        dialog.SetBlockList(self.Controler.GetBlockTypes(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2042
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2043
        variable_names = self.Controler.GetEditedElementVariables(self.TagName, self.Debug)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2044
        if block.GetName() != "":
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2045
            variable_names.remove(block.GetName())
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2046
        dialog.SetPouElementNames(variable_names)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2047
        dialog.SetMinBlockSize(block.GetSize())
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2048
        old_values = {"name" : block.GetName(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2049
                      "type" : block.GetType(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2050
                      "extension" : block.GetExtension(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2051
                      "inputs" : block.GetInputTypes(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2052
                      "executionControl" : block.GetExecutionControl(), 
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2053
                      "executionOrder" : block.GetExecutionOrder()}
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2054
        dialog.SetValues(old_values)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2055
        if dialog.ShowModal() == wx.ID_OK:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2056
            new_values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2057
            rect = block.GetRedrawRect(1, 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2058
            if "name" in new_values:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2059
                block.SetName(new_values["name"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2060
            else:
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2061
                block.SetName("")
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2062
            block.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"]))
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2063
            block.SetType(new_values["type"], new_values["extension"], executionControl = new_values["executionControl"])
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2064
            block.SetExecutionOrder(new_values["executionOrder"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2065
            rect = rect.Union(block.GetRedrawRect())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2066
            self.RefreshBlockModel(block)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2067
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2068
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2069
            self.RefreshVisibleElements()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2070
            self.ParentWindow.RefreshVariablePanel(self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2071
            self.ParentWindow.RefreshInstancesTree()
269
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2072
            if old_values["executionOrder"] != new_values["executionOrder"]:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2073
                self.RefreshView()
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2074
            else:
34eff05909b0 Adding support for EN/ENO variables (temporarily disabled, waiting for matiec support)
lbessard
parents: 267
diff changeset
  2075
                block.Refresh(rect)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2076
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2077
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2078
    def EditVariableContent(self, variable):
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2079
        words = self.TagName.split("::")
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2080
        if words[0] == "T":
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2081
            dialog = FBDVariableDialog(self.ParentWindow, self.Controler, words[2])
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2082
        else:
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2083
            dialog = FBDVariableDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2084
        dialog.SetPreviewFont(self.GetFont())
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2085
        dialog.SetMinVariableSize(variable.GetSize())
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2086
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2087
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2088
        if vars:
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2089
            for var in vars:
70
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  2090
                if var["Edit"]:
0e48629c1e6d Adding support for avoiding name conflicts
lbessard
parents: 67
diff changeset
  2091
                    varlist.append((var["Name"], var["Class"], var["Type"]))
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2092
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2093
        if returntype:
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2094
            varlist.append((self.Controler.GetEditedElementName(self.TagName), "Output", returntype))
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2095
        dialog.SetVariables(varlist)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2096
        old_values = {"name" : variable.GetName(), "type" : variable.GetType(), 
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2097
            "executionOrder" : variable.GetExecutionOrder()}
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2098
        dialog.SetValues(old_values)
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2099
        if dialog.ShowModal() == wx.ID_OK:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2100
            new_values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2101
            rect = variable.GetRedrawRect(1, 1)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2102
            variable.SetName(new_values["name"])
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2103
            variable.SetType(new_values["type"], new_values["value_type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2104
            variable.SetSize(*self.GetScaledSize(new_values["width"], new_values["height"]))
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2105
            variable.SetExecutionOrder(new_values["executionOrder"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2106
            rect = rect.Union(variable.GetRedrawRect())
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2107
            if old_values["type"] != new_values["type"]:
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2108
                id = variable.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2109
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2110
                self.Controler.AddEditedElementVariable(self.TagName, id, new_values["type"])
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2111
            self.RefreshVariableModel(variable)
118
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2112
            if old_values["executionOrder"] != new_values["executionOrder"]:
0c53d6a36013 Add support for defining execution order in FBD networks (related ST code not generated yet)
lbessard
parents: 114
diff changeset
  2113
                self.RefreshView()
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2114
            self.RefreshBuffer()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2115
            self.RefreshVisibleElements()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2116
            self.RefreshScrollBars()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2117
            variable.Refresh(rect)
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2118
        dialog.Destroy()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2119
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2120
    def EditConnectionContent(self, connection):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2121
        dialog = ConnectionDialog(self.ParentWindow, self.Controler)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2122
        dialog.SetPreviewFont(self.GetFont())
330
d803ba077da0 Adding Test when creating ConnectionBlock
lbessard
parents: 327
diff changeset
  2123
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d803ba077da0 Adding Test when creating ConnectionBlock
lbessard
parents: 327
diff changeset
  2124
        dialog.SetPouElementNames(self.Controler.GetEditedElementVariables(self.TagName, self.Debug))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2125
        dialog.SetMinConnectionSize(connection.GetSize())
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2126
        values = {"name" : connection.GetName(), "type" : connection.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2127
        dialog.SetValues(values)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2128
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2129
            old_type = connection.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2130
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2131
            rect = connection.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2132
            connection.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2133
            connection.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2134
            connection.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2135
            rect = rect.Union(connection.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2136
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2137
                id = connection.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2138
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2139
                self.Controler.AddEditedElementConnection(self.TagName, id, values["type"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2140
            self.RefreshConnectionModel(connection)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2141
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2142
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2143
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2144
            connection.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2145
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2146
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2147
    def EditContactContent(self, contact):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2148
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "contact")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2149
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2150
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2151
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2152
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2153
            for var in vars:
277
5fc11b2d4fbb Bug in contact edition not allowing output referencing fixed
lbessard
parents: 275
diff changeset
  2154
                if var["Type"] == "BOOL":
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2155
                    varlist.append(var["Name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2156
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2157
        values = {"name" : contact.GetName(), "type" : contact.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2158
        dialog.SetValues(values)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2159
        dialog.SetElementSize(contact.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2160
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2161
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2162
            rect = contact.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2163
            contact.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2164
            contact.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2165
            contact.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2166
            rect = rect.Union(contact.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2167
            self.RefreshContactModel(contact)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2168
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2169
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2170
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2171
            contact.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2172
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2173
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2174
    def EditCoilContent(self, coil):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2175
        dialog = LDElementDialog(self.ParentWindow, self.Controler, "coil")
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2176
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2177
        varlist = []
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2178
        vars = self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2179
        if vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2180
            for var in vars:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2181
                if var["Class"] != "Input" and var["Type"] == "BOOL":
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2182
                    varlist.append(var["Name"])
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2183
        returntype = self.Controler.GetEditedElementInterfaceReturnType(self.TagName, self.Debug)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2184
        if returntype == "BOOL":
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2185
            varlist.append(self.Controler.GetEditedElementName(self.TagName))
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2186
        dialog.SetVariables(varlist)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2187
        values = {"name" : coil.GetName(), "type" : coil.GetType()}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2188
        dialog.SetValues(values)
61
dc7142ae9438 Adding possibility to change Type and Pin number of power rails
lbessard
parents: 58
diff changeset
  2189
        dialog.SetElementSize(coil.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2190
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2191
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2192
            rect = coil.GetRedrawRect(1, 1)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2193
            coil.SetName(values["name"])
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2194
            coil.SetType(values["type"])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2195
            coil.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2196
            rect = rect.Union(coil.GetRedrawRect())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2197
            self.RefreshCoilModel(coil)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2198
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2199
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2200
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2201
            coil.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2202
        dialog.Destroy()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2203
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2204
    def EditPowerRailContent(self, powerrail):
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2205
        dialog = LDPowerRailDialog(self.ParentWindow, self.Controler, powerrail.GetType(), len(powerrail.GetConnectors()))
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2206
        dialog.SetPreviewFont(self.GetFont())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2207
        dialog.SetMinSize(powerrail.GetSize())
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2208
        if dialog.ShowModal() == wx.ID_OK:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2209
            old_type = powerrail.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2210
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2211
            rect = powerrail.GetRedrawRect(1, 1)
61
dc7142ae9438 Adding possibility to change Type and Pin number of power rails
lbessard
parents: 58
diff changeset
  2212
            powerrail.SetType(values["type"], [True for i in xrange(values["number"])])
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2213
            powerrail.SetSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2214
            rect = rect.Union(powerrail.GetRedrawRect())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2215
            if old_type != values["type"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2216
                id = powerrail.GetId()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2217
                self.Controler.RemoveEditedElementInstance(self.TagName, id)
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2218
                self.Controler.AddEditedElementPowerRail(self.TagName, id, values["type"])
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2219
            self.RefreshPowerRailModel(powerrail)
56
7187e1c00975 Adding support for Undo/Redo and Unsaved File On Close detection
lbessard
parents: 54
diff changeset
  2220
            self.RefreshBuffer()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2221
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2222
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2223
            powerrail.Refresh(rect)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2224
        dialog.Destroy()
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2225
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2226
    def EditStepContent(self, step):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2227
        dialog = SFCStepDialog(self.ParentWindow, self.Controler, step.GetInitial())
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2228
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2229
        dialog.SetPouNames(self.Controler.GetProjectPouNames(self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2230
        dialog.SetVariables(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2231
        dialog.SetStepNames([block.GetName() for block in self.Blocks.itervalues() if isinstance(block, SFC_Step) and block.GetName() != step.GetName()])
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2232
        dialog.SetMinStepSize(step.GetSize())
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2233
        values = {"name" : step.GetName()}
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2234
        connectors = step.GetConnectors()
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2235
        values["input"] = len(connectors["inputs"]) > 0
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2236
        values["output"] = len(connectors["outputs"]) > 0
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2237
        values["action"] = step.GetActionConnector() != None
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2238
        dialog.SetValues(values)
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2239
        if dialog.ShowModal() == wx.ID_OK:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2240
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2241
            rect = step.GetRedrawRect(1, 1)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2242
            step.SetName(values["name"])
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2243
            if values["input"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2244
                step.AddInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2245
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2246
                step.RemoveInput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2247
            if values["output"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2248
                step.AddOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2249
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2250
                step.RemoveOutput()
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2251
            if values["action"]:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2252
                step.AddAction()    
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2253
            else:
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2254
                step.RemoveAction()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2255
            step.UpdateSize(*self.GetScaledSize(values["width"], values["height"]))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2256
            rect = rect.Union(step.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2257
            self.RefreshStepModel(step)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2258
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2259
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2260
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2261
            step.Refresh(rect)
71
0578bc212c20 Adding Dialog for Step in free drawing
lbessard
parents: 70
diff changeset
  2262
        
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2263
    def EditTransitionContent(self, transition):
409
34c9f624c2fe Reorganization of Dialog classes by splitting Dialogs.py into several files, one for each Dialog class
laurent
parents: 407
diff changeset
  2264
        dialog = SFCTransitionDialog(self.ParentWindow, self.Controler, self.GetDrawingMode() == FREEDRAWING_MODE)
165
e464a4e4e06d Adding Font support in Dialog
lbessard
parents: 162
diff changeset
  2265
        dialog.SetPreviewFont(self.GetFont())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2266
        dialog.SetTransitions(self.Controler.GetEditedElementTransitions(self.TagName, self.Debug))
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2267
        dialog.SetValues({"type":transition.GetType(),"value":transition.GetCondition(), "priority":transition.GetPriority()})
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2268
        dialog.SetElementSize(transition.GetSize())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2269
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2270
            values = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2271
            rect = transition.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2272
            transition.SetType(values["type"],values["value"])
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2273
            transition.SetPriority(values["priority"])
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2274
            rect = rect.Union(transition.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2275
            self.RefreshTransitionModel(transition)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2276
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2277
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2278
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2279
            transition.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2280
        dialog.Destroy()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2281
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2282
    def EditJumpContent(self, jump):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2283
        choices = []
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2284
        for block in self.Blocks.itervalues():
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2285
            if isinstance(block, SFC_Step):
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2286
                choices.append(block.GetName())
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2287
        dialog = wx.SingleChoiceDialog(self.ParentWindow, _("Edit jump target"), _("Please choose a target"), choices, wx.OK|wx.CANCEL)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2288
        dialog.SetSelection(choices.index(jump.GetTarget()))
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2289
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2290
            value = dialog.GetStringSelection()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2291
            rect = jump.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2292
            jump.SetTarget(value)
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2293
            rect = rect.Union(jump.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2294
            self.RefreshJumpModel(jump)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2295
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2296
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2297
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2298
            jump.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2299
        dialog.Destroy()
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2300
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2301
    def EditActionBlockContent(self, actionblock):
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2302
        dialog = ActionBlockDialog(self.ParentWindow)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2303
        dialog.SetQualifierList(self.Controler.GetQualifierTypes())
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2304
        dialog.SetActionList(self.Controler.GetEditedElementActions(self.TagName, self.Debug))
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2305
        dialog.SetVariableList(self.Controler.GetEditedElementInterfaceVars(self.TagName, self.Debug))
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2306
        dialog.SetValues(actionblock.GetActions())
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2307
        if dialog.ShowModal() == wx.ID_OK:
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2308
            actions = dialog.GetValues()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2309
            rect = actionblock.GetRedrawRect(1, 1)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2310
            actionblock.SetActions(actions)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2311
            actionblock.SetSize(*self.GetScaledSize(*actionblock.GetSize()))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2312
            rect = rect.Union(actionblock.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2313
            self.RefreshActionBlockModel(actionblock)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2314
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2315
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2316
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2317
            actionblock.Refresh(rect)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2318
        dialog.Destroy()
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2319
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2320
    def EditCommentContent(self, comment):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2321
        if wx.VERSION >= (2, 5, 0):
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2322
            dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL|wx.TE_MULTILINE)
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2323
        else:
391
07447ee3538e Adding support for internationalization
laurent
parents: 388
diff changeset
  2324
            dialog = wx.TextEntryDialog(self.ParentWindow, _("Edit comment"), _("Please enter comment text"), comment.GetContent(), wx.OK|wx.CANCEL)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2325
        if dialog.ShowModal() == wx.ID_OK:
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2326
            value = dialog.GetValue()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2327
            rect = comment.GetRedrawRect(1, 1)
90
2245e8776086 Adding support support for using PLCOpenEditor with Beremiz
lbessard
parents: 80
diff changeset
  2328
            comment.SetContent(value)
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2329
            comment.SetSize(*self.GetScaledSize(*comment.GetSize()))
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2330
            rect = rect.Union(comment.GetRedrawRect())
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2331
            self.RefreshCommentModel(comment)
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2332
            self.RefreshBuffer()
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2333
            self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2334
            self.RefreshVisibleElements()
154
203c4acdaf27 Redrawing bugs fixed
lbessard
parents: 145
diff changeset
  2335
            comment.Refresh(rect)
64
dd6f693e46a1 Cleaning code for using only wxPython 2.6 class naming
lbessard
parents: 61
diff changeset
  2336
        dialog.Destroy()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2337
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2338
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2339
#                          Model update functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2340
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2341
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2342
    def RefreshBlockModel(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2343
        blockid = block.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2344
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2345
        infos["type"] = block.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2346
        infos["name"] = block.GetName()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2347
        if self.CurrentLanguage == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2348
            infos["executionOrder"] = block.GetExecutionOrder()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2349
        infos["x"], infos["y"] = block.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2350
        infos["width"], infos["height"] = block.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2351
        infos["connectors"] = block.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2352
        self.Controler.SetEditedElementBlockInfos(self.TagName, blockid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2353
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2354
    def RefreshVariableModel(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2355
        variableid = variable.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2356
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2357
        infos["name"] = variable.GetName()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2358
        if self.CurrentLanguage == "FBD":
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2359
            infos["executionOrder"] = variable.GetExecutionOrder()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2360
        infos["x"], infos["y"] = variable.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2361
        infos["width"], infos["height"] = variable.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2362
        infos["connectors"] = variable.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2363
        self.Controler.SetEditedElementVariableInfos(self.TagName, variableid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2364
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2365
    def RefreshConnectionModel(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2366
        connectionid = connection.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2367
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2368
        infos["name"] = connection.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2369
        infos["x"], infos["y"] = connection.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2370
        infos["width"], infos["height"] = connection.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2371
        infos["connector"] = connection.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2372
        self.Controler.SetEditedElementConnectionInfos(self.TagName, connectionid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2373
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2374
    def RefreshCommentModel(self, comment):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2375
        commentid = comment.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2376
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2377
        infos["content"] = comment.GetContent()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2378
        infos["x"], infos["y"] = comment.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2379
        infos["width"], infos["height"] = comment.GetSize()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2380
        self.Controler.SetEditedElementCommentInfos(self.TagName, commentid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2381
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2382
    def RefreshPowerRailModel(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2383
        powerrailid = powerrail.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2384
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2385
        infos["x"], infos["y"] = powerrail.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2386
        infos["width"], infos["height"] = powerrail.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2387
        infos["connectors"] = powerrail.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2388
        self.Controler.SetEditedElementPowerRailInfos(self.TagName, powerrailid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2389
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2390
    def RefreshContactModel(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2391
        contactid = contact.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2392
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2393
        infos["name"] = contact.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2394
        infos["type"] = contact.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2395
        infos["x"], infos["y"] = contact.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2396
        infos["width"], infos["height"] = contact.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2397
        infos["connectors"] = contact.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2398
        self.Controler.SetEditedElementContactInfos(self.TagName, contactid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2399
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2400
    def RefreshCoilModel(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2401
        coilid = coil.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2402
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2403
        infos["name"] = coil.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2404
        infos["type"] = coil.GetType()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2405
        infos["x"], infos["y"] = coil.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2406
        infos["width"], infos["height"] = coil.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2407
        infos["connectors"] = coil.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2408
        self.Controler.SetEditedElementCoilInfos(self.TagName, coilid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2409
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2410
    def RefreshStepModel(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2411
        stepid = step.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2412
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2413
        infos["name"] = step.GetName()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2414
        infos["initial"] = step.GetInitial()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2415
        infos["x"], infos["y"] = step.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2416
        infos["width"], infos["height"] = step.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2417
        infos["connectors"] = step.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2418
        infos["action"] = step.GetActionConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2419
        self.Controler.SetEditedElementStepInfos(self.TagName, stepid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2420
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2421
    def RefreshTransitionModel(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2422
        transitionid = transition.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2423
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2424
        infos["type"] = transition.GetType()
80
c798a68c5560 Lots of bugs fixed
lbessard
parents: 71
diff changeset
  2425
        infos["priority"] = transition.GetPriority()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2426
        infos["condition"] = transition.GetCondition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2427
        infos["x"], infos["y"] = transition.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2428
        infos["width"], infos["height"] = transition.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2429
        infos["connectors"] = transition.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2430
        infos["connection"] = transition.GetConditionConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2431
        self.Controler.SetEditedElementTransitionInfos(self.TagName, transitionid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2432
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2433
    def RefreshDivergenceModel(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2434
        divergenceid = divergence.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2435
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2436
        infos["x"], infos["y"] = divergence.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2437
        infos["width"], infos["height"] = divergence.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2438
        infos["connectors"] = divergence.GetConnectors()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2439
        self.Controler.SetEditedElementDivergenceInfos(self.TagName, divergenceid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2440
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2441
    def RefreshJumpModel(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2442
        jumpid = jump.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2443
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2444
        infos["target"] = jump.GetTarget()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2445
        infos["x"], infos["y"] = jump.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2446
        infos["width"], infos["height"] = jump.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2447
        infos["connector"] = jump.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2448
        self.Controler.SetEditedElementJumpInfos(self.TagName, jumpid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2449
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2450
    def RefreshActionBlockModel(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2451
        actionblockid = actionblock.GetId()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2452
        infos = {}
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2453
        infos["actions"] = actionblock.GetActions()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2454
        infos["x"], infos["y"] = actionblock.GetPosition()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2455
        infos["width"], infos["height"] = actionblock.GetSize()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2456
        infos["connector"] = actionblock.GetConnector()
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2457
        self.Controler.SetEditedElementActionBlockInfos(self.TagName, actionblockid, infos)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2458
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2459
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2460
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2461
#                          Model delete functions
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2462
#-------------------------------------------------------------------------------
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2463
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2464
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2465
    def DeleteBlock(self, block):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2466
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2467
        for output in block.GetConnectors()["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2468
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2469
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2470
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2471
        block.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2472
        self.RemoveBlock(block)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2473
        self.Controler.RemoveEditedElementInstance(self.TagName, block.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2474
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2475
            element.RefreshModel()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2476
        wx.CallAfter(self.ParentWindow.RefreshVariablePanel, self.TagName)
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2477
        wx.CallAfter(self.ParentWindow.RefreshInstancesTree)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2478
        
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2479
    def DeleteVariable(self, variable):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2480
        connectors = variable.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2481
        if len(connectors["outputs"]) > 0:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2482
            elements = connectors["outputs"][0].GetConnectedBlocks()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2483
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2484
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2485
        variable.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2486
        self.RemoveBlock(variable)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2487
        self.Controler.RemoveEditedElementInstance(self.TagName, variable.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2488
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2489
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2490
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2491
    def DeleteConnection(self, connection):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2492
        if connection.GetType() == CONTINUATION:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2493
            elements = connection.GetConnector().GetConnectedBlocks()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2494
        else:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2495
            elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2496
        connection.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2497
        self.RemoveBlock(connection)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2498
        self.Controler.RemoveEditedElementInstance(self.TagName, connection.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2499
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2500
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2501
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2502
    def DeleteComment(self, comment):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2503
        self.RemoveComment(comment)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2504
        self.Controler.RemoveEditedElementInstance(self.TagName, comment.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2505
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2506
    def DeleteWire(self, wire):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2507
        if wire in self.Wires:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2508
            connected = wire.GetConnected()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2509
            wire.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2510
            self.RemoveWire(wire)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2511
            for connector in connected:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2512
                connector.RefreshParentBlock()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2513
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2514
    def DeleteContact(self, contact):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2515
        connectors = contact.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2516
        elements = connectors["outputs"][0].GetConnectedBlocks()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2517
        contact.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2518
        self.RemoveBlock(contact)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2519
        self.Controler.RemoveEditedElementInstance(self.TagName, contact.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2520
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2521
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2522
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2523
    def DeleteCoil(self, coil):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2524
        connectors = coil.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2525
        elements = connectors["outputs"][0].GetConnectedBlocks()
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2526
        coil.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2527
        self.RemoveBlock(coil)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2528
        self.Controler.RemoveEditedElementInstance(self.TagName, coil.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2529
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2530
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2531
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2532
    def DeletePowerRail(self, powerrail):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2533
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2534
        if powerrail.GetType() == LEFTRAIL:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2535
            connectors = powerrail.GetConnectors()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2536
            for connector in connectors["outputs"]:
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2537
                for element in connector.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2538
                    if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2539
                        elements.append(element)
108
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2540
        powerrail.Clean()
9aa1fdfb7cb2 A lots of bugs fixed
lbessard
parents: 106
diff changeset
  2541
        self.RemoveBlock(powerrail)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2542
        self.Controler.RemoveEditedElementInstance(self.TagName, powerrail.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2543
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2544
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2545
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2546
    def DeleteStep(self, step):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2547
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2548
        connectors = step.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2549
        action_connector = step.GetActionConnector()
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2550
        if len(connectors["outputs"]) > 0:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2551
            for element in connectors["outputs"][0].GetConnectedBlocks():
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2552
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2553
                    elements.append(element)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2554
        if action_connector is not None:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2555
            for element in action_connector.GetConnectedBlocks():
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2556
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2557
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2558
        step.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2559
        self.RemoveBlock(step)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2560
        self.Controler.RemoveEditedElementInstance(self.TagName, step.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2561
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2562
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2563
            
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2564
    def DeleteTransition(self, transition):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2565
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2566
        connectors = transition.GetConnectors()
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2567
        for element in connectors["outputs"][0].GetConnectedBlocks():
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2568
            if element not in elements:
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2569
                elements.append(element)
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2570
        transition.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2571
        self.RemoveBlock(transition)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2572
        self.Controler.RemoveEditedElementInstance(self.TagName, transition.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2573
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2574
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2575
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2576
    def DeleteDivergence(self, divergence):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2577
        elements = []
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2578
        connectors = divergence.GetConnectors()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2579
        for output in connectors["outputs"]:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2580
            for element in output.GetConnectedBlocks():
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2581
                if element not in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2582
                    elements.append(element)
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2583
        divergence.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2584
        self.RemoveBlock(divergence)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2585
        self.Controler.RemoveEditedElementInstance(self.TagName, divergence.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2586
        for element in elements:
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2587
            element.RefreshModel()
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2588
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2589
    def DeleteJump(self, jump):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2590
        jump.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2591
        self.RemoveBlock(jump)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2592
        self.Controler.RemoveEditedElementInstance(self.TagName, jump.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2593
    
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2594
    def DeleteActionBlock(self, actionblock):
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2595
        actionblock.Clean()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2596
        self.RemoveBlock(actionblock)
121
40b91ba978db Improving PLCOpenEditor for using wx2.8 AUI
lbessard
parents: 118
diff changeset
  2597
        self.Controler.RemoveEditedElementInstance(self.TagName, actionblock.GetId())
28
fc23e1f415d8 Adding support for concurrent overriden standard function
lbessard
parents: 27
diff changeset
  2598
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2599
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2600
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2601
#                            Editing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2602
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2603
    
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2604
    def Cut(self):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2605
        if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2606
            blocks, wires = self.SelectedElement.GetDefinition()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2607
            text = self.Controler.GetEditedElementInstancesCopy(self.TagName, blocks, wires, self.Debug)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2608
            self.ParentWindow.SetCopyBuffer(text)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2609
            rect = self.SelectedElement.GetRedrawRect(1, 1)
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2610
            self.SelectedElement.Delete()
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2611
            self.SelectedElement = None
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2612
            self.RefreshBuffer()
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2613
            self.RefreshScrollBars()
239
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2614
            self.ParentWindow.RefreshVariablePanel(self.TagName)
d12779e971bd Adding support for function and functionBlock (standard or user) library
lbessard
parents: 235
diff changeset
  2615
            self.ParentWindow.RefreshInstancesTree()
155
b695f7459ef6 Removing flickering on Windows
lbessard
parents: 154
diff changeset
  2616
            self.RefreshRect(self.GetScrolledRect(rect), False)
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2617
        
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2618
    def Copy(self):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2619
        if not self.Debug and (self.IsBlock(self.SelectedElement) or self.IsComment(self.SelectedElement) or isinstance(self.SelectedElement, Graphic_Group)):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2620
            blocks, wires = self.SelectedElement.GetDefinition()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2621
            text = self.Controler.GetEditedElementInstancesCopy(self.TagName, blocks, wires, self.Debug)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2622
            self.ParentWindow.SetCopyBuffer(text)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2623
            
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2624
    def Paste(self):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2625
        if not self.Debug:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2626
            element = self.ParentWindow.GetCopyBuffer()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2627
            mouse_pos = self.ScreenToClient(wx.GetMousePosition())
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2628
            middle = wx.Rect(0, 0, *self.GetClientSize()).InsideXY(mouse_pos.x, mouse_pos.y)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2629
            if middle:
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2630
                x, y = self.CalcUnscrolledPosition(mouse_pos.x, mouse_pos.y)
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2631
            else:
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2632
                x, y = self.CalcUnscrolledPosition(0, 0)
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2633
            new_pos = [int(x / self.ViewScale[0]), int(y / self.ViewScale[1])]
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2634
            result = self.Controler.PasteEditedElementInstances(self.TagName, element, new_pos, middle, self.Debug)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2635
            if not isinstance(result, (StringType, UnicodeType)):
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2636
                self.RefreshBuffer()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2637
                self.RefreshView(result)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2638
                self.ParentWindow.RefreshVariablePanel(self.TagName)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2639
                self.ParentWindow.RefreshInstancesTree()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2640
            else:
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2641
                message = wx.MessageDialog(self, result, "Error", wx.OK|wx.ICON_ERROR)
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2642
                message.ShowModal()
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2643
                message.Destroy()
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2644
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2645
    def CanAddElement(self, block):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2646
        if isinstance(block, Graphic_Group):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2647
            return block.CanAddBlocks(self)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2648
        elif self.CurrentLanguage == "SFC":
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2649
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2650
        elif self.CurrentLanguage == "LD" and not isinstance(block, (SFC_Step, SFC_Transition, SFC_Divergence, SFC_Jump, SFC_ActionBlock)):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2651
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2652
        elif self.CurrentLanguage == "FBD" and isinstance(block, (FBD_Block, FBD_Variable, FBD_Connector, Comment)):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2653
            return True
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2654
        return False
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2655
343
dc8ff76b39fd Adding support for drag and drop wire, step and transition in debug mode
lbessard
parents: 338
diff changeset
  2656
    def GenerateNewName(self, element, exclude={}):
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2657
        if isinstance(element, SFC_Step):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2658
            format = "Step%d"
384
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2659
        else:
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2660
            format = "Block%d"    
ed27a676d5c9 Changing Cut/Copy/Paste procedures for using wx.Clipboard with xml definition of copied elements
laurent
parents: 383
diff changeset
  2661
        return self.Controler.GenerateNewName(self.TagName, element.GetName(), format, exclude, self.Debug)
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2662
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2663
    def IsNamedElement(self, element):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2664
        return isinstance(element, FBD_Block) and element.GetName() != "" or isinstance(element, SFC_Step)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2665
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2666
    def CopyBlock(self, element, pos):
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2667
        id = self.GetNewId()
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2668
        if isinstance(element, Graphic_Group):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2669
            block = element.Clone(self, pos=pos)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2670
        else:
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2671
            if self.IsNamedElement(element):
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2672
                name = self.GenerateNewName(element)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2673
                block = element.Clone(self, id, name, pos)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2674
            else:
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2675
                name = None
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2676
                block = element.Clone(self, id, pos=pos)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2677
            self.AddBlockInModel(block)
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2678
        return block
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2679
    
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2680
    def AddBlockInModel(self, block):
114
06454545e5d0 Adding support for block copy and for wxpython 2.4
lbessard
parents: 111
diff changeset
  2681
        if isinstance(block, Comment):
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2682
            self.AddComment(block)
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2683
            self.Controler.AddEditedElementComment(self.TagName, block.GetId())
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2684
            self.RefreshCommentModel(block)
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2685
        else:
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2686
            self.AddBlock(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2687
            if isinstance(block, FBD_Block):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2688
                self.Controler.AddEditedElementBlock(self.TagName, block.GetId(), block.GetType(), block.GetName())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2689
                self.RefreshBlockModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2690
            elif isinstance(block, FBD_Variable):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2691
                self.Controler.AddEditedElementVariable(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2692
                self.RefreshVariableModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2693
            elif isinstance(block, FBD_Connector):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2694
                self.Controler.AddEditedElementConnection(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2695
                self.RefreshConnectionModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2696
            elif isinstance(block, LD_Contact):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2697
                self.Controler.AddEditedElementContact(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2698
                self.RefreshContactModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2699
            elif isinstance(block, LD_Coil):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2700
                self.Controler.AddEditedElementCoil(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2701
                self.RefreshCoilModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2702
            elif isinstance(block, LD_PowerRail):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2703
                self.Controler.AddEditedElementPowerRail(self.TagName, block.GetId(), block.GetType())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2704
                self.RefreshPowerRailModel(block)
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2705
            elif isinstance(block, SFC_Step):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2706
                self.Controler.AddEditedElementStep(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2707
                self.RefreshStepModel(block)    
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2708
            elif isinstance(block, SFC_Transition):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2709
                self.Controler.AddEditedElementTransition(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2710
                self.RefreshTransitionModel(block)       
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2711
            elif isinstance(block, SFC_Divergence):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2712
                self.Controler.AddEditedElementDivergence(self.TagName, block.GetId(), block.GetType())
202
e219803fdd11 Bug on SFC_Divergence copying fixed
lbessard
parents: 198
diff changeset
  2713
                self.RefreshDivergenceModel(block)
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2714
            elif isinstance(block, SFC_Jump):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2715
                self.Controler.AddEditedElementJump(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2716
                self.RefreshJumpModel(block)       
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2717
            elif isinstance(block, SFC_ActionBlock):
283
c4199b88cf60 Adding support for copying a group of elements
lbessard
parents: 279
diff changeset
  2718
                self.Controler.AddEditedElementActionBlock(self.TagName, block.GetId())
178
a9035374eb05 Bug on Copy/Cut/Paste comments fixed
lbessard
parents: 174
diff changeset
  2719
                self.RefreshActionBlockModel(block)
231
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2720
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2721
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2722
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2723
#                        Errors showing functions
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2724
#-------------------------------------------------------------------------------
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2725
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2726
    def ClearErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2727
        self.Errors = []
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2728
        self.RefreshView()
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2729
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2730
    def AddShownError(self, infos, start, end):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2731
        self.Errors.append((infos, start, end))
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2732
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2733
    def ShowErrors(self):
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2734
        for infos, start, end in self.Errors:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2735
            if infos[0] in ["io_variable", "block", "coil", "contact", "transition", "step", "action_block"]:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2736
                block = self.FindElementById(infos[1])
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2737
                if block is not None:
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2738
                    block.AddError(infos[2:], start, end)    
fc2d6cbb8b39 Adding support for highlighing compiling errors from matiec
lbessard
parents: 224
diff changeset
  2739
        
0
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2740
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2741
#                            Drawing functions
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2742
#-------------------------------------------------------------------------------
b622defdfd98 PLCOpenEditor initial commit. 31/01/07.
etisserant
parents:
diff changeset
  2743
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2744
    def OnScrollWindow(self, event):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2745
        if event.GetOrientation() == wx.HORIZONTAL:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2746
            self.RefreshVisibleElements(xp = event.GetPosition())
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2747
        else:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2748
            self.RefreshVisibleElements(yp = event.GetPosition())
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2749
        event.Skip()
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2750
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  2751
    def OnScrollStop(self, event):
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  2752
        self.RefreshScrollBars()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  2753
        event.Skip()
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  2754
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2755
    def OnMouseWheelWindow(self, event):
319
efe0671df286 Adding extension of Viewer
lbessard
parents: 302
diff changeset
  2756
        if self.StartMousePos is None or self.StartScreenPos is None:
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2757
            rotation = event.GetWheelRotation() / event.GetWheelDelta()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2758
            if event.ShiftDown():
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2759
                x, y = self.GetViewStart()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2760
                xp = max(0, min(x - rotation * 3, self.GetVirtualSize()[0] / self.GetScrollPixelsPerUnit()[0]))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2761
                self.RefreshVisibleElements(xp = xp)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2762
                self.Scroll(xp, y)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2763
            elif event.ControlDown():
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2764
                dc = self.GetLogicalDC()
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2765
                self.Freeze()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2766
                pos = event.GetLogicalPosition(dc)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2767
                mouse_pos = event.GetPosition()
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2768
                self.SetScale(self.CurrentScale + rotation, False)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2769
                xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2770
                ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2771
                scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2772
                scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2773
                if scrollx > xmax or scrolly > ymax:
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2774
                    self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2775
                    self.Scroll(scrollx, scrolly)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2776
                else:
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2777
                    self.Scroll(scrollx, scrolly)
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2778
                    self.RefreshScrollBars()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2779
                self.RefreshVisibleElements()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2780
                self.Refresh()
363
5eb9c5536334 Fix Bug with Zoom in Viewer
greg
parents: 361
diff changeset
  2781
                self.Thaw()
332
555124c752ec Adding Display menu with Zoom item
lbessard
parents: 331
diff changeset
  2782
                self.ParentWindow.RefreshDisplayMenu()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2783
            else:
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2784
                x, y = self.GetViewStart()
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2785
                yp = max(0, min(y - rotation * 3, self.GetVirtualSize()[1] / self.GetScrollPixelsPerUnit()[1]))
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2786
                self.RefreshVisibleElements(yp = yp)
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2787
                self.Scroll(x, yp)
253
d9391572655f Adding support for Debugging in PLCOpenEditor
lbessard
parents: 249
diff changeset
  2788
        
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2789
    def OnMoveWindow(self, event):
292
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
  2790
        if not USE_AUI:
800e100038ae Bug on Viewer ScrollBar with AUI fixed
lbessard
parents: 290
diff changeset
  2791
            self.GetBestSize()
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2792
        self.RefreshScrollBars()
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2793
        self.RefreshVisibleElements()
27
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2794
        event.Skip()
dae55dd9ee14 Current developping version
lbessard
parents: 13
diff changeset
  2795
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2796
    def DoDrawing(self, dc, printing = False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2797
        if printing:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2798
            if getattr(dc, "printing", False):
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2799
                font = wx.Font(self.GetFont().GetPointSize(), wx.MODERN, wx.NORMAL, wx.NORMAL)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2800
                dc.SetFont(font)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2801
            else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2802
                dc.SetFont(self.GetFont())
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2803
        else:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2804
            dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2805
            dc.Clear()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2806
            dc.BeginDrawing()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2807
        if self.Scaling is not None and self.DrawGrid and not printing:
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2808
            dc.SetPen(wx.TRANSPARENT_PEN)
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2809
            dc.SetBrush(self.GridBrush)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2810
            xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2811
            window_size = self.GetClientSize()
145
4fb225afddf4 Adding scaling
lbessard
parents: 144
diff changeset
  2812
            width, height = self.GetVirtualSize()
323
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2813
            width = int(max(width, xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0])
fd3a3a002bce Adding support for scaling
lbessard
parents: 319
diff changeset
  2814
            height = int(max(height, ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1])
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2815
            dc.DrawRectangle(1, 1, width, height)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2816
        if self.PageSize is not None and not printing:
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2817
            dc.SetPen(self.PagePen)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2818
            xstart, ystart = self.GetViewStart()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2819
            window_size = self.GetClientSize()
331
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2820
            for x in xrange(self.PageSize[0] - (xstart * SCROLLBAR_UNIT) % self.PageSize[0], int(window_size[0] / self.ViewScale[0]), self.PageSize[0]):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2821
                dc.DrawLine(xstart * SCROLLBAR_UNIT + x + 1, int(ystart * SCROLLBAR_UNIT / self.ViewScale[0]), 
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2822
                            xstart * SCROLLBAR_UNIT + x + 1, int((ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[0]))
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2823
            for y in xrange(self.PageSize[1] - (ystart * SCROLLBAR_UNIT) % self.PageSize[1], int(window_size[1] / self.ViewScale[1]), self.PageSize[1]):
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2824
                dc.DrawLine(int(xstart * SCROLLBAR_UNIT / self.ViewScale[0]), ystart * SCROLLBAR_UNIT + y + 1, 
9106d66bd204 Bug with Scaling, MiddleButton, Wire modifications fixed.
lbessard
parents: 330
diff changeset
  2825
                            int((xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[1]), ystart * SCROLLBAR_UNIT + y + 1)
140
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  2826
        
06d28f03f6f4 Adding highlighting on group or element when mouse is over
lbessard
parents: 138
diff changeset
  2827
        # Draw all elements
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2828
        for comment in self.Comments.itervalues():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2829
            if comment != self.SelectedElement and (comment.IsVisible() or printing):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2830
                comment.Draw(dc)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2831
        for wire in self.Wires.iterkeys():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2832
            if wire != self.SelectedElement and (wire.IsVisible() or printing):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2833
                 if not self.Debug or wire.GetValue() != True:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2834
                    wire.Draw(dc)
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2835
        if self.Debug:
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2836
            for wire in self.Wires.iterkeys():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2837
                if wire != self.SelectedElement and (wire.IsVisible() or printing) and wire.GetValue() == True:
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2838
                    wire.Draw(dc)
383
25ffba02b6a8 Improving viewer loading instances procedure to faster
laurent
parents: 381
diff changeset
  2839
        for block in self.Blocks.itervalues():
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2840
            if block != self.SelectedElement and (block.IsVisible() or printing):
42
4a8400732001 Adding optimization on redrawing
lbessard
parents: 28
diff changeset
  2841
                block.Draw(dc)
144
b67a5de5a24a Adding optimization on Viewer redrawing
lbessard
parents: 140
diff changeset
  2842
        
249
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2843
        if self.SelectedElement is not None and (self.SelectedElement.IsVisible() or printing):
d8425712acef Adding support for Debugging in PLCOpenEditor
lbessard
parents: 243
diff changeset
  2844
            self.SelectedElement.Draw(dc)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2845
        
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2846
        if not printing:
407
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 400
diff changeset
  2847
            if self.Debug:
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 400
diff changeset
  2848
                xstart, ystart = self.GetViewStart()
0a324a874981 Adding support for integrating PLCOpenEditor in Beremiz frame
laurent
parents: 400
diff changeset
  2849
                dc.DrawText(_("Debug: %s") % self.InstancePath, 2, 2)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2850
            if self.rubberBand.IsShown():
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2851
                self.rubberBand.Draw(dc)
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2852
            dc.EndDrawing()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2853
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2854
    def OnPaint(self, event):
352
5cd60f7e510c fixed some bugs:
greg
parents: 345
diff changeset
  2855
        dc = self.GetLogicalDC(True)
5cd60f7e510c fixed some bugs:
greg
parents: 345
diff changeset
  2856
        self.DoDrawing(dc)
5cd60f7e510c fixed some bugs:
greg
parents: 345
diff changeset
  2857
        wx.BufferedPaintDC(self, dc.GetAsBitmap())
372
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
  2858
        if self.Debug:
8cab11dd2325 Bug that fixed Windows in Debug mode fixed
greg
parents: 363
diff changeset
  2859
            DebugViewer.RefreshNewData(self)
213
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2860
        event.Skip()
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2861
4931959ea256 Adding support for printing graphical languages
lbessard
parents: 206
diff changeset
  2862