editors/Viewer.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Mon, 28 Nov 2016 16:47:01 +0300
changeset 1581 2295fdc5c271
parent 1578 f8e2a04c4445
child 1584 431f4ef34bde
permissions -rw-r--r--
fix translation strings with multiple parameters


this fixes a lot of warnings given by msgmerge:

../PLCOpenEditor.py:196: warning: 'msgid' format string with unnamed arguments cannot be properly localized:
The translator cannot reorder the arguments.
Please consider using a format string with named arguments,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
     7
# Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
     9
# See COPYING file for copyrights details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    11
# This program is free software; you can redistribute it and/or
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    12
# modify it under the terms of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    13
# as published by the Free Software Foundation; either version 2
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    14
# of the License, or (at your option) any later version.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    16
# This program is distributed in the hope that it will be useful,
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    19
# GNU General Public License for more details.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
1571
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    21
# You should have received a copy of the GNU General Public License
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    22
# along with this program; if not, write to the Free Software
486f94a8032c fix license notices in source files and license files under GPLv2+
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1567
diff changeset
    23
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    25
import re
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    26
import math
1224
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
    27
from time import time as gettime
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
from types import TupleType
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    29
from threading import Lock
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    30
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    31
import wx
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
from plcopen.structures import *
885
fc91d3718b74 Fix bug multiple graph viewer tab displaying values of the same variable can be opened
Laurent Bessard
parents: 882
diff changeset
    34
from PLCControler import ITEM_VAR_LOCAL, ITEM_POU, ITEM_PROGRAM, ITEM_FUNCTIONBLOCK
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
from dialogs import *
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    37
from graphics import *
1224
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
    38
from editors.DebugViewer import DebugViewer, REFRESH_PERIOD
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    39
from EditorPanel import EditorPanel
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    40
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
SCROLLBAR_UNIT = 10
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
WINDOW_BORDER = 10
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
SCROLL_ZONE = 10
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    44
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    45
CURSORS = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    46
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    47
def ResetCursors():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    48
    global CURSORS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    49
    if CURSORS == None:
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
    50
        CURSORS = [wx.NullCursor,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    51
                   wx.StockCursor(wx.CURSOR_HAND),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    52
                   wx.StockCursor(wx.CURSOR_SIZENWSE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    53
                   wx.StockCursor(wx.CURSOR_SIZENESW),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    54
                   wx.StockCursor(wx.CURSOR_SIZEWE),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    55
                   wx.StockCursor(wx.CURSOR_SIZENS)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    56
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    57
def AppendMenu(parent, help, id, kind, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    58
    if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    59
        parent.Append(help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    60
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    61
        parent.Append(helpString=help, id=id, kind=kind, item=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    62
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    63
if wx.Platform == '__WXMSW__':
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    64
    faces = { 'times': 'Times New Roman',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    65
              'mono' : 'Courier New',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    66
              'helv' : 'Arial',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    67
              'other': 'Comic Sans MS',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    68
              'size' : 10,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    69
             }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    70
else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    71
    faces = { 'times': 'Times',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    72
              'mono' : 'Courier',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    73
              'helv' : 'Helvetica',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    74
              'other': 'new century schoolbook',
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    75
              'size' : 12,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    76
             }
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    77
1123
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
    78
if wx.Platform == '__WXMSW__':
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
    79
    MAX_ZOOMIN = 4
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
    80
else:
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
    81
    MAX_ZOOMIN = 7
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
    82
ZOOM_FACTORS = [math.sqrt(2) ** x for x in xrange(-6, MAX_ZOOMIN)]
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    83
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    84
def GetVariableCreationFunction(variable_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    85
    def variableCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
    86
        return FBD_Variable(viewer, variable_type,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
    87
                                    specific_values.name,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
    88
                                    specific_values.value_type,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    89
                                    id,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
    90
                                    specific_values.execution_order)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    91
    return variableCreationFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    92
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    93
def GetConnectorCreationFunction(connector_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    94
    def connectorCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
    95
        return FBD_Connector(viewer, connector_type,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
    96
                                     specific_values.name, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    return connectorCreationFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    99
def commentCreationFunction(viewer, id, specific_values):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   100
    return Comment(viewer, specific_values.content, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   101
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   102
def GetPowerRailCreationFunction(powerrail_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   103
    def powerRailCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   104
        return LD_PowerRail(viewer, powerrail_type, id,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   105
                                    specific_values.connectors)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   106
    return powerRailCreationFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   107
1381
8b0a7eceb76d Fixed bug with edge and storage parameters in contact and coil not loaded in file saved with older version
Laurent Bessard
parents: 1377
diff changeset
   108
NEGATED_VALUE = lambda x: x if x is not None else False
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   109
MODIFIER_VALUE = lambda x: x if x is not None else 'none'
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   110
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   111
CONTACT_TYPES = {(True, "none"): CONTACT_REVERSE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   112
                 (False, "rising"): CONTACT_RISING,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   113
                 (False, "falling"): CONTACT_FALLING}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   114
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   115
def contactCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   116
    contact_type = CONTACT_TYPES.get((NEGATED_VALUE(specific_values.negated),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   117
                                      MODIFIER_VALUE(specific_values.edge)),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
                                     CONTACT_NORMAL)
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   119
    return LD_Contact(viewer, contact_type, specific_values.name, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   120
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   121
COIL_TYPES = {(True, "none", "none"): COIL_REVERSE,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   122
              (False, "none", "set"): COIL_SET,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
              (False, "none", "reset"): COIL_RESET,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
              (False, "rising", "none"): COIL_RISING,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
              (False, "falling", "none"): COIL_FALLING}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   126
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   127
def coilCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   128
    coil_type = COIL_TYPES.get((NEGATED_VALUE(specific_values.negated),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   129
                                MODIFIER_VALUE(specific_values.edge),
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   130
                                MODIFIER_VALUE(specific_values.storage)),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
                               COIL_NORMAL)
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   132
    return LD_Coil(viewer, coil_type, specific_values.name, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   133
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   134
def stepCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   135
    step = SFC_Step(viewer, specific_values.name,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   136
                            specific_values.initial, id)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   137
    if specific_values.action is not None:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   138
        step.AddAction()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   139
        connector = step.GetActionConnector()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   140
        connector.SetPosition(wx.Point(*specific_values.action.position))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   141
    return step
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   142
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   143
def transitionCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   144
    transition = SFC_Transition(viewer, specific_values.condition_type,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   145
                                        specific_values.condition,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   146
                                        specific_values.priority, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
    return transition
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   148
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   149
def GetDivergenceCreationFunction(divergence_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   150
    def divergenceCreationFunction(viewer, id, specific_values):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   151
        return SFC_Divergence(viewer, divergence_type,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   152
                                      specific_values.connectors, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   153
    return divergenceCreationFunction
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   154
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   155
def jumpCreationFunction(viewer, id, specific_values):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   156
    return SFC_Jump(viewer, specific_values.target, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   158
def actionBlockCreationFunction(viewer, id, specific_values):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
   159
    return SFC_ActionBlock(viewer, specific_values.actions, id)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
ElementCreationFunctions = {
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   162
    "input": GetVariableCreationFunction(INPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   163
    "output": GetVariableCreationFunction(OUTPUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   164
    "inout": GetVariableCreationFunction(INOUT),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   165
    "connector": GetConnectorCreationFunction(CONNECTOR),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   166
    "continuation": GetConnectorCreationFunction(CONTINUATION),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
    "comment": commentCreationFunction,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   168
    "leftPowerRail": GetPowerRailCreationFunction(LEFTRAIL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   169
    "rightPowerRail": GetPowerRailCreationFunction(RIGHTRAIL),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
    "contact": contactCreationFunction,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   171
    "coil": coilCreationFunction,
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   172
    "step": stepCreationFunction,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   173
    "transition": transitionCreationFunction,
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   174
    "selectionDivergence": GetDivergenceCreationFunction(SELECTION_DIVERGENCE),
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   175
    "selectionConvergence": GetDivergenceCreationFunction(SELECTION_CONVERGENCE),
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   176
    "simultaneousDivergence": GetDivergenceCreationFunction(SIMULTANEOUS_DIVERGENCE),
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   177
    "simultaneousConvergence": GetDivergenceCreationFunction(SIMULTANEOUS_CONVERGENCE),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   178
    "jump": jumpCreationFunction,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   179
    "actionBlock": actionBlockCreationFunction,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   180
}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   181
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   182
def sort_blocks(block_infos1, block_infos2):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   183
    x1, y1 = block_infos1[0].GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   184
    x2, y2 = block_infos2[0].GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   185
    if y1 == y2:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   186
        return cmp(x1, x2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   187
    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   188
        return cmp(y1, y2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   189
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   190
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   191
#                       Graphic elements Viewer base class
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   192
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   193
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   194
# ID Constants for alignment menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   195
[ID_VIEWERALIGNMENTMENUITEMS0, ID_VIEWERALIGNMENTMENUITEMS1,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   196
 ID_VIEWERALIGNMENTMENUITEMS2, ID_VIEWERALIGNMENTMENUITEMS4,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   197
 ID_VIEWERALIGNMENTMENUITEMS5, ID_VIEWERALIGNMENTMENUITEMS6,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   198
] = [wx.NewId() for _init_coll_AlignmentMenu_Items in range(6)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   199
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
# ID Constants for contextual menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   201
[ID_VIEWERCONTEXTUALMENUITEMS0, ID_VIEWERCONTEXTUALMENUITEMS1,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   202
 ID_VIEWERCONTEXTUALMENUITEMS2, ID_VIEWERCONTEXTUALMENUITEMS3,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   203
 ID_VIEWERCONTEXTUALMENUITEMS5, ID_VIEWERCONTEXTUALMENUITEMS6,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   204
 ID_VIEWERCONTEXTUALMENUITEMS8, ID_VIEWERCONTEXTUALMENUITEMS9,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   205
 ID_VIEWERCONTEXTUALMENUITEMS11, ID_VIEWERCONTEXTUALMENUITEMS12,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   206
 ID_VIEWERCONTEXTUALMENUITEMS14, ID_VIEWERCONTEXTUALMENUITEMS16,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   207
 ID_VIEWERCONTEXTUALMENUITEMS17,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   208
] = [wx.NewId() for _init_coll_ContextualMenu_Items in range(13)]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   209
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   210
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   211
class ViewerDropTarget(wx.TextDropTarget):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   212
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   213
    def __init__(self, parent):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   214
        wx.TextDropTarget.__init__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   215
        self.ParentWindow = parent
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   216
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   217
    def OnDropText(self, x, y, data):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   218
        self.ParentWindow.Select()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        tagname = self.ParentWindow.GetTagName()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
        pou_name, pou_type = self.ParentWindow.Controler.GetEditedElementType(tagname, self.ParentWindow.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   221
        x, y = self.ParentWindow.CalcUnscrolledPosition(x, y)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   222
        x = int(x / self.ParentWindow.ViewScale[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   223
        y = int(y / self.ParentWindow.ViewScale[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   224
        scaling = self.ParentWindow.Scaling
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   225
        message = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   226
        try:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   227
            values = eval(data)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   228
        except:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   229
            message = _("Invalid value \"%s\" for viewer block")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   230
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   231
        if not isinstance(values, TupleType):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
            message = _("Invalid value \"%s\" for viewer block")%data
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   233
            values = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   234
        if values is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   235
            if values[1] == "debug":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   236
                pass
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   237
            elif values[1] == "program":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
                message = _("Programs can't be used by other POUs!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
            elif values[1] in ["function", "functionBlock"]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
                words = tagname.split("::")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
                if pou_name == values[0]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   242
                    message = _("\"%s\" can't use itself!")%pou_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   243
                elif pou_type == "function" and values[1] != "function":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   244
                    message = _("Function Blocks can't be used in Functions!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   245
                elif self.ParentWindow.Controler.PouIsUsedBy(pou_name, values[0], self.ParentWindow.Debug):
1581
2295fdc5c271 fix translation strings with multiple parameters
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1578
diff changeset
   246
                    message = _("\"{a1}\" is already used by \"{a2}\"!").format(a1 = pou_name, a2 = values[0])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
                    blockname = values[2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   249
                    if len(values) > 3:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   250
                        blockinputs = values[3]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   251
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   252
                        blockinputs = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   253
                    if values[1] != "function" and blockname == "":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   254
                        blockname = self.ParentWindow.GenerateNewName(blocktype=values[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   255
                    if blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   256
                        message = _("\"%s\" pou already exists!")%blockname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   257
                    elif blockname.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   258
                        message = _("\"%s\" element for this pou already exists!")%blockname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   259
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   260
                        id = self.ParentWindow.GetNewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   261
                        block = FBD_Block(self.ParentWindow, values[0], blockname, id, inputs = blockinputs)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   262
                        width, height = block.GetMinSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   263
                        if scaling is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   264
                            x = round(float(x) / float(scaling[0])) * scaling[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   265
                            y = round(float(y) / float(scaling[1])) * scaling[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   266
                            width = round(float(width) / float(scaling[0]) + 0.5) * scaling[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   267
                            height = round(float(height) / float(scaling[1]) + 0.5) * scaling[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   268
                        block.SetPosition(x, y)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   269
                        block.SetSize(width, height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   270
                        self.ParentWindow.AddBlock(block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   271
                        self.ParentWindow.Controler.AddEditedElementBlock(tagname, id, values[0], blockname)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   272
                        self.ParentWindow.RefreshBlockModel(block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   273
                        self.ParentWindow.RefreshBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   274
                        self.ParentWindow.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   275
                        self.ParentWindow.RefreshVisibleElements()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   276
                        self.ParentWindow.RefreshVariablePanel()
1233
5e6d0969bb5d Fixed bugs in refresh of PouInstanceVariablesPanel
Laurent Bessard
parents: 1229
diff changeset
   277
                        self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   278
                        self.ParentWindow.Refresh(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   279
            elif values[1] == "location":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   280
                if pou_type == "program":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   281
                    location = values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   282
                    if not location.startswith("%"):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   283
                        dialog = wx.SingleChoiceDialog(self.ParentWindow.ParentWindow,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   284
                              _("Select a variable class:"), _("Variable class"),
1578
f8e2a04c4445 add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   285
                              [_("Input"), _("Output"), _("Memory")],
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   286
                              wx.DEFAULT_DIALOG_STYLE|wx.OK|wx.CANCEL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   287
                        if dialog.ShowModal() == wx.ID_OK:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   288
                            selected = dialog.GetSelection()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   289
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   290
                            selected = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   291
                        dialog.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   292
                        if selected is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   293
                            return
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   294
                        if selected == 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   295
                            location = "%I" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   296
                        elif selected == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   297
                            location = "%Q" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   298
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   299
                            location = "%M" + location
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   300
                    var_name = values[3]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   301
                    dlg = wx.TextEntryDialog(
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   302
                        self.ParentWindow.ParentWindow,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   303
                        _("Confirm or change variable name"),
1578
f8e2a04c4445 add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   304
                        _('Variable Drop'), var_name)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   305
                    dlg.SetValue(var_name)
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   306
                    var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   307
                    dlg.Destroy()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   308
                    if var_name is None:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   309
                        return
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   310
                    elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   311
                        message = _("\"%s\" pou already exists!")%var_name
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   312
                    elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   313
                        if location[1] == "Q":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   314
                            var_class = OUTPUT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   315
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   316
                            var_class = INPUT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   317
                        if values[2] is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   318
                            var_type = values[2]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   319
                        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   320
                            var_type = LOCATIONDATATYPES.get(location[2], ["BOOL"])[0]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   321
                        self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, location=location, description=values[4])
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   322
                        self.ParentWindow.RefreshVariablePanel()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   323
                        self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
1406
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   324
                        self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   325
                    else:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   326
                        message = _("\"%s\" element for this pou already exists!")%var_name
1406
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   327
            elif values[1] == "NamedConstant":
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   328
                if pou_type == "program":
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   329
                    initval = values[0]
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   330
                    var_name = values[3]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   331
                    dlg = wx.TextEntryDialog(
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   332
                        self.ParentWindow.ParentWindow,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   333
                        _("Confirm or change variable name"),
1578
f8e2a04c4445 add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   334
                        _('Variable Drop'), var_name)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   335
                    dlg.SetValue(var_name)
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   336
                    var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   337
                    dlg.Destroy()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   338
                    if var_name is None:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   339
                        return
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   340
                    elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
1406
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   341
                        message = _("\"%s\" pou already exists!")%var_name
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   342
                    elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
1406
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   343
                        var_class = INPUT
82db84fe88ea Added 'NamedConstant' drag'n'drop in programs. It does create a simple variable with initial value and is usefull for drag'n'drop constants from extensions while keeping a name associated with constant
Edouard Tisserant
parents: 1381
diff changeset
   344
                        var_type = values[2]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   345
                        self.ParentWindow.Controler.AddEditedElementPouVar(tagname, var_type, var_name, description=values[4], initval=initval)
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   346
                        self.ParentWindow.RefreshVariablePanel()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   347
                        self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   348
                        self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   349
                    else:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   350
                        message = _("\"%s\" element for this pou already exists!")%var_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   351
            elif values[1] == "Global":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   352
                var_name = values[0]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   353
                dlg = wx.TextEntryDialog(
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   354
                    self.ParentWindow.ParentWindow,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   355
                    _("Confirm or change variable name"),
1578
f8e2a04c4445 add localization to time strings in DebugVariablePanel and to dialog shown after variable drag'n'drop
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1571
diff changeset
   356
                    _('Variable Drop'), var_name)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   357
                dlg.SetValue(var_name)
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   358
                var_name = dlg.GetValue() if dlg.ShowModal() == wx.ID_OK else None
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   359
                dlg.Destroy()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   360
                if var_name is None:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   361
                    return
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   362
                elif var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetProjectPouNames(self.ParentWindow.Debug)]:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   363
                    message = _("\"%s\" pou already exists!")%var_name
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   364
                elif not var_name.upper() in [name.upper() for name in self.ParentWindow.Controler.GetEditedElementVariables(tagname, self.ParentWindow.Debug)]:
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   365
                    self.ParentWindow.Controler.AddEditedElementPouExternalVar(tagname, values[2], var_name)
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   366
                    self.ParentWindow.RefreshVariablePanel()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   367
                    self.ParentWindow.ParentWindow.RefreshPouInstanceVariablesPanel()
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   368
                    self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, var_name, values[2])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   369
                else:
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   370
                    message = _("\"%s\" element for this pou already exists!")%var_name
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   371
            elif values[1] == "Constant":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   372
                self.ParentWindow.AddVariableBlock(x, y, scaling, INPUT, values[0], None)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   373
            elif values[3] == tagname:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   374
                if values[1] == "Output":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   375
                    var_class = OUTPUT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   376
                elif values[1] == "InOut":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   377
                    var_class = INPUT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   378
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   379
                    var_class = INPUT
1347
533741e5075c Fixed pou variables information loading stylesheet
Laurent Bessard
parents: 1342
diff changeset
   380
                tree = dict([(var.Name, var.Tree) for var in self.ParentWindow.Controler.GetEditedElementInterfaceVars(tagname, True, self.ParentWindow.Debug)]).get(values[0], None)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   381
                if tree is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   382
                    if len(tree[0]) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   383
                        menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   384
                        self.GenerateTreeMenu(x, y, scaling, menu, "", var_class, [(values[0], values[2], tree)])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   385
                        self.ParentWindow.PopupMenuXY(menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   386
                    else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   387
                        self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, values[0], values[2])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   388
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   389
                    message = _("Unknown variable \"%s\" for this POU!") % values[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   390
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   391
                message = _("Variable don't belong to this POU!")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   392
        if message is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   393
            wx.CallAfter(self.ShowMessage, message)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   394
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   395
    def GenerateTreeMenu(self, x, y, scaling, menu, base_path, var_class, tree):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   396
        for child_name, child_type, (child_tree, child_dimensions) in tree:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   397
            if base_path:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   398
                child_path = "%s.%s" % (base_path, child_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   399
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   400
                child_path = child_name
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   401
            if len(child_dimensions) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   402
                child_path += "[%s]" % ",".join([str(dimension[0]) for dimension in child_dimensions])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   403
                child_name += "[]"
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   404
            new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   405
            AppendMenu(menu, help='', id=new_id, kind=wx.ITEM_NORMAL, text=child_name)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   406
            self.ParentWindow.Bind(wx.EVT_MENU, self.GetAddVariableBlockFunction(x, y, scaling, var_class, child_path, child_type), id=new_id)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   407
            if len(child_tree) > 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   408
                new_id = wx.NewId()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   409
                child_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   410
                self.GenerateTreeMenu(x, y, scaling, child_menu, child_path, var_class, child_tree)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   411
                menu.AppendMenu(new_id, "%s." % child_name, child_menu)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   412
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   413
    def GetAddVariableBlockFunction(self, x, y, scaling, var_class, var_name, var_type):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   414
        def AddVariableFunction(event):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   415
            self.ParentWindow.AddVariableBlock(x, y, scaling, var_class, var_name, var_type)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   416
        return AddVariableFunction
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   417
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   418
    def ShowMessage(self, message):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   419
        message = wx.MessageDialog(self.ParentWindow, message, _("Error"), wx.OK|wx.ICON_ERROR)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   420
        message.ShowModal()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   421
        message.Destroy()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   422
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   423
"""
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   424
Class that implements a Viewer based on a wx.ScrolledWindow for drawing and
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   425
manipulating graphic elements
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   426
"""
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   427
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1170
diff changeset
   428
class Viewer(EditorPanel, DebugViewer):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   429
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   430
    if wx.VERSION < (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   431
        def Bind(self, event, function, id = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   432
            if id is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   433
                event(self, id, function)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   434
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   435
                event(self, function)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   436
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   437
    # Add list of menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   438
    def AddMenuItems(self, menu, items):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   439
        for item in items:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   440
            if item is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   441
                menu.AppendSeparator()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   442
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   443
                id, kind, text, help, callback = item
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   444
                AppendMenu(menu, help=help, id=id, kind=kind, text=text)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   445
                # Link menu event to corresponding called functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   446
                self.Bind(wx.EVT_MENU, callback, id=id)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   447
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   448
    # Add Block Pin Menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   449
    def AddBlockPinMenuItems(self, menu, connector):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   450
        [ID_NO_MODIFIER, ID_NEGATED, ID_RISING_EDGE,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   451
         ID_FALLING_EDGE] = [wx.NewId() for i in xrange(4)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   452
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   453
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   454
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   455
            (ID_NO_MODIFIER, wx.ITEM_RADIO, _(u'No Modifier'), '', self.OnNoModifierMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   456
            (ID_NEGATED, wx.ITEM_RADIO, _(u'Negated'), '', self.OnNegatedMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   457
            (ID_RISING_EDGE, wx.ITEM_RADIO, _(u'Rising Edge'), '', self.OnRisingEdgeMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   458
            (ID_FALLING_EDGE, wx.ITEM_RADIO, _(u'Falling Edge'), '', self.OnFallingEdgeMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   459
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   460
        type = self.Controler.GetEditedElementType(self.TagName, self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   461
        menu.Enable(ID_RISING_EDGE, type != "function")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   462
        menu.Enable(ID_FALLING_EDGE, type != "function")
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   463
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   464
        if connector.IsNegated():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   465
            menu.Check(ID_NEGATED, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   466
        elif connector.GetEdge() == "rising":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   467
            menu.Check(ID_RISING_EDGE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   468
        elif connector.GetEdge() == "falling":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   469
            menu.Check(ID_FALLING_EDGE, True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   470
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   471
            menu.Check(ID_NO_MODIFIER, True)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   472
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   473
    # Add Alignment Menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   474
    def AddAlignmentMenuItems(self, menu):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   475
        [ID_ALIGN_LEFT, ID_ALIGN_CENTER, ID_ALIGN_RIGHT,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   476
         ID_ALIGN_TOP, ID_ALIGN_MIDDLE, ID_ALIGN_BOTTOM,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   477
        ] = [wx.NewId() for i in xrange(6)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   478
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   479
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   480
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   481
            (ID_ALIGN_LEFT, wx.ITEM_NORMAL, _(u'Left'), '', self.OnAlignLeftMenu),
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   482
            (ID_ALIGN_CENTER, wx.ITEM_NORMAL, _(u'Center'), '', self.OnAlignCenterMenu),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   483
            (ID_ALIGN_RIGHT, wx.ITEM_NORMAL, _(u'Right'), '', self.OnAlignRightMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   484
            None,
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   485
            (ID_ALIGN_TOP, wx.ITEM_NORMAL, _(u'Top'), '', self.OnAlignTopMenu),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   486
            (ID_ALIGN_MIDDLE, wx.ITEM_NORMAL, _(u'Middle'), '', self.OnAlignMiddleMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   487
            (ID_ALIGN_BOTTOM, wx.ITEM_NORMAL, _(u'Bottom'), '', self.OnAlignBottomMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   488
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   489
    # Add Wire Menu items to the given menu
1263
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   490
    def AddWireMenuItems(self, menu, delete=False, replace=False):
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   491
        [ID_ADD_SEGMENT, ID_DELETE_SEGMENT, ID_REPLACE_WIRE,
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   492
         ] = [wx.NewId() for i in xrange(3)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   493
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   494
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   495
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   496
            (ID_ADD_SEGMENT, wx.ITEM_NORMAL, _(u'Add Wire Segment'), '', self.OnAddSegmentMenu),
1263
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   497
            (ID_DELETE_SEGMENT, wx.ITEM_NORMAL, _(u'Delete Wire Segment'), '', self.OnDeleteSegmentMenu),
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   498
            (ID_REPLACE_WIRE, wx.ITEM_NORMAL, _(u'Replace Wire by connections'), '', self.OnReplaceWireMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   499
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   500
        menu.Enable(ID_DELETE_SEGMENT, delete)
1263
895605ccac70 Added support for replacing a wire by two connections
Laurent Bessard
parents: 1260
diff changeset
   501
        menu.Enable(ID_REPLACE_WIRE, replace)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   502
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   503
    # Add Divergence Menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   504
    def AddDivergenceMenuItems(self, menu, delete=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   505
        [ID_ADD_BRANCH, ID_DELETE_BRANCH] = [wx.NewId() for i in xrange(2)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   506
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   507
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   508
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   509
            (ID_ADD_BRANCH, wx.ITEM_NORMAL, _(u'Add Divergence Branch'), '', self.OnAddBranchMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   510
            (ID_DELETE_BRANCH, wx.ITEM_NORMAL, _(u'Delete Divergence Branch'), '', self.OnDeleteBranchMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   511
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   512
        menu.Enable(ID_DELETE_BRANCH, delete)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   513
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   514
    # Add Add Menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   515
    def AddAddMenuItems(self, menu):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   516
        [ID_ADD_BLOCK, ID_ADD_VARIABLE, ID_ADD_CONNECTION,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   517
         ID_ADD_COMMENT] = [wx.NewId() for i in xrange(4)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   518
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   519
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   520
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   521
            (ID_ADD_BLOCK, wx.ITEM_NORMAL, _(u'Block'), '', self.GetAddMenuCallBack(self.AddNewBlock)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   522
            (ID_ADD_VARIABLE, wx.ITEM_NORMAL, _(u'Variable'), '', self.GetAddMenuCallBack(self.AddNewVariable)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   523
            (ID_ADD_CONNECTION, wx.ITEM_NORMAL, _(u'Connection'), '', self.GetAddMenuCallBack(self.AddNewConnection)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   524
            None])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   525
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   526
        if self.CurrentLanguage != "FBD":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   527
            [ID_ADD_POWER_RAIL, ID_ADD_CONTACT, ID_ADD_COIL,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   528
            ] = [wx.NewId() for i in xrange(3)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   529
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   530
            # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   531
            self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   532
                (ID_ADD_POWER_RAIL, wx.ITEM_NORMAL, _(u'Power Rail'), '', self.GetAddMenuCallBack(self.AddNewPowerRail)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   533
                (ID_ADD_CONTACT, wx.ITEM_NORMAL, _(u'Contact'), '', self.GetAddMenuCallBack(self.AddNewContact))])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   534
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   535
            if self.CurrentLanguage != "SFC":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   536
                self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   537
                     (ID_ADD_COIL, wx.ITEM_NORMAL, _(u'Coil'), '', self.GetAddMenuCallBack(self.AddNewCoil))])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   538
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   539
            menu.AppendSeparator()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   540
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   541
        if self.CurrentLanguage == "SFC":
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   542
            [ID_ADD_INITIAL_STEP, ID_ADD_STEP, ID_ADD_TRANSITION,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   543
             ID_ADD_ACTION_BLOCK, ID_ADD_DIVERGENCE, ID_ADD_JUMP,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   544
            ] = [wx.NewId() for i in xrange(6)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   545
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   546
            # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   547
            self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   548
                (ID_ADD_INITIAL_STEP, wx.ITEM_NORMAL, _(u'Initial Step'), '', self.GetAddMenuCallBack(self.AddNewStep, True)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   549
                (ID_ADD_STEP, wx.ITEM_NORMAL, _(u'Step'), '', self.GetAddMenuCallBack(self.AddNewStep)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   550
                (ID_ADD_TRANSITION, wx.ITEM_NORMAL, _(u'Transition'), '', self.GetAddMenuCallBack(self.AddNewTransition)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   551
                (ID_ADD_ACTION_BLOCK, wx.ITEM_NORMAL, _(u'Action Block'), '', self.GetAddMenuCallBack(self.AddNewActionBlock)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   552
                (ID_ADD_DIVERGENCE, wx.ITEM_NORMAL, _(u'Divergence'), '', self.GetAddMenuCallBack(self.AddNewDivergence)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   553
                (ID_ADD_JUMP, wx.ITEM_NORMAL, _(u'Jump'), '', self.GetAddMenuCallBack(self.AddNewJump)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   554
                None])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   555
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   556
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   557
             (ID_ADD_COMMENT, wx.ITEM_NORMAL, _(u'Comment'), '', self.GetAddMenuCallBack(self.AddNewComment))])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   558
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   559
    # Add Default Menu items to the given menu
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   560
    def AddDefaultMenuItems(self, menu, edit=False, block=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   561
        if block:
852
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   562
            [ID_EDIT_BLOCK, ID_DELETE, ID_ADJUST_BLOCK_SIZE] = [wx.NewId() for i in xrange(3)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   563
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   564
            # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   565
            self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   566
                 (ID_EDIT_BLOCK, wx.ITEM_NORMAL, _(u'Edit Block'), '', self.OnEditBlockMenu),
852
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   567
                 (ID_ADJUST_BLOCK_SIZE, wx.ITEM_NORMAL, _(u'Adjust Block Size'), '', self.OnAdjustBlockSizeMenu),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   568
                 (ID_DELETE, wx.ITEM_NORMAL, _(u'Delete'), '', self.OnDeleteMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   569
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   570
            menu.Enable(ID_EDIT_BLOCK, edit)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   571
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   572
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   573
            [ID_CLEAR_EXEC_ORDER, ID_RESET_EXEC_ORDER] = [wx.NewId() for i in xrange(2)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   574
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   575
            # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   576
            self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   577
                 (ID_CLEAR_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Clear Execution Order'), '', self.OnClearExecutionOrderMenu),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   578
                 (ID_RESET_EXEC_ORDER, wx.ITEM_NORMAL, _(u'Reset Execution Order'), '', self.OnResetExecutionOrderMenu)])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   579
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   580
            menu.AppendSeparator()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   581
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   582
            add_menu = wx.Menu(title='')
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   583
            self.AddAddMenuItems(add_menu)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   584
            menu.AppendMenu(-1, _(u'Add'), add_menu)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   585
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   586
        menu.AppendSeparator()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   587
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   588
        [ID_CUT, ID_COPY, ID_PASTE] = [wx.NewId() for i in xrange(3)]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   589
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   590
        # Create menu items
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   591
        self.AddMenuItems(menu, [
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   592
             (ID_CUT, wx.ITEM_NORMAL, _(u'Cut'), '', self.GetClipboardCallBack(self.Cut)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   593
             (ID_COPY, wx.ITEM_NORMAL, _(u'Copy'), '', self.GetClipboardCallBack(self.Copy)),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   594
             (ID_PASTE, wx.ITEM_NORMAL, _(u'Paste'), '', self.GetAddMenuCallBack(self.Paste))])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   595
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   596
        menu.Enable(ID_CUT, block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   597
        menu.Enable(ID_COPY, block)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   598
        menu.Enable(ID_PASTE, self.ParentWindow.GetCopyBuffer() is not None)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   599
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   600
    def _init_Editor(self, prnt):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   601
        self.Editor = wx.ScrolledWindow(prnt, name="Viewer",
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   602
            pos=wx.Point(0, 0), size=wx.Size(0, 0),
1481
5b294dcaae18 fix issue, then it wasn't possible to view FBD programs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1431
diff changeset
   603
            style=wx.HSCROLL | wx.VSCROLL)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   604
        self.Editor.ParentWindow = self
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   605
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   606
    # Create a new Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   607
    def __init__(self, parent, tagname, window, controler, debug = False, instancepath = ""):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   608
        self.VARIABLE_PANEL_TYPE = controler.GetPouType(tagname.split("::")[1])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   609
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   610
        EditorPanel.__init__(self, parent, tagname, window, controler, debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   611
        DebugViewer.__init__(self, controler, debug)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   612
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   613
        # Adding a rubberband to Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   614
        self.rubberBand = RubberBand(viewer=self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   615
        self.Editor.SetBackgroundColour(wx.Colour(255,255,255))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   616
        self.Editor.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   617
        self.ResetView()
1342
c17507a10807 Fixed various latency issues removing unnecessary calls
Laurent Bessard
parents: 1338
diff changeset
   618
        self.LastClientSize = None
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   619
        self.Scaling = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   620
        self.DrawGrid = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   621
        self.GridBrush = wx.TRANSPARENT_BRUSH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   622
        self.PageSize = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   623
        self.PagePen = wx.TRANSPARENT_PEN
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   624
        self.DrawingWire = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   625
        self.current_id = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   626
        self.TagName = tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   627
        self.Highlights = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   628
        self.SearchParams = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   629
        self.SearchResults = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   630
        self.CurrentFindHighlight = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   631
        self.InstancePath = instancepath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   632
        self.StartMousePos = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   633
        self.StartScreenPos = None
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   634
1224
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
   635
        # Prevent search for highlighted element to be called too often
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
   636
        self.LastHighlightCheckTime = gettime()
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
   637
        # Prevent search for element producing tooltip to be called too often
30e72bc7d21b Fixed lag when moving mouse over Viewer
Laurent Bessard
parents: 1208
diff changeset
   638
        self.LastToolTipCheckTime = gettime()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   639
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   640
        self.Buffering = False
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   641
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   642
        # Initialize Cursors
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   643
        ResetCursors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   644
        self.CurrentCursor = 0
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   645
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   646
        # Initialize Block, Wire and Comment numbers
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   647
        self.wire_id = 0
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   648
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   649
        # Initialize Viewer mode to Selection mode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   650
        self.Mode = MODE_SELECTION
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   651
        self.SavedMode = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   652
        self.CurrentLanguage = "FBD"
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   653
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   654
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   655
            self.Editor.SetDropTarget(ViewerDropTarget(self))
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   656
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   657
        self.ElementRefreshList = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   658
        self.ElementRefreshList_lock = Lock()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   659
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   660
        dc = wx.ClientDC(self.Editor)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   661
        font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   662
        dc.SetFont(font)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   663
        width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   664
        while width > 260:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   665
            faces["size"] -= 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   666
            font = wx.Font(faces["size"], wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["mono"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   667
            dc.SetFont(font)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   668
            width, height = dc.GetTextExtent("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   669
        self.SetFont(font)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   670
        self.MiniTextDC = wx.MemoryDC()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   671
        self.MiniTextDC.SetFont(wx.Font(faces["size"] * 0.75, wx.SWISS, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   672
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   673
        self.CurrentScale = None
1123
55ed55ef7aea Fixed bug on biggest Viewer zoom factor preventing them to be used on Windows
Laurent Bessard
parents: 1122
diff changeset
   674
        self.SetScale(ZOOM_FACTORS.index(1.0), False)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   675
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   676
        self.RefreshHighlightsTimer = wx.Timer(self, -1)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   677
        self.Bind(wx.EVT_TIMER, self.OnRefreshHighlightsTimer, self.RefreshHighlightsTimer)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   678
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   679
        self.ResetView()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   680
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   681
        # Link Viewer event to corresponding methods
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   682
        self.Editor.Bind(wx.EVT_PAINT, self.OnPaint)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   683
        self.Editor.Bind(wx.EVT_LEFT_DOWN, self.OnViewerLeftDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   684
        self.Editor.Bind(wx.EVT_LEFT_UP, self.OnViewerLeftUp)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   685
        self.Editor.Bind(wx.EVT_LEFT_DCLICK, self.OnViewerLeftDClick)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   686
        self.Editor.Bind(wx.EVT_RIGHT_DOWN, self.OnViewerRightDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   687
        self.Editor.Bind(wx.EVT_RIGHT_UP, self.OnViewerRightUp)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   688
        self.Editor.Bind(wx.EVT_MIDDLE_DOWN, self.OnViewerMiddleDown)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   689
        self.Editor.Bind(wx.EVT_MIDDLE_UP, self.OnViewerMiddleUp)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   690
        self.Editor.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveViewer)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   691
        self.Editor.Bind(wx.EVT_MOTION, self.OnViewerMotion)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   692
        self.Editor.Bind(wx.EVT_CHAR, self.OnChar)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   693
        self.Editor.Bind(wx.EVT_SCROLLWIN, self.OnScrollWindow)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   694
        self.Editor.Bind(wx.EVT_SCROLLWIN_THUMBRELEASE, self.OnScrollStop)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   695
        self.Editor.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheelWindow)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   696
        self.Editor.Bind(wx.EVT_SIZE, self.OnMoveWindow)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   697
        self.Editor.Bind(wx.EVT_MOUSE_EVENTS, self.OnViewerMouseEvent)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   698
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   699
    # Destructor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   700
    def __del__(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   701
        DebugViewer.__del__(self)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   702
        self.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   703
        self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   704
        self.RefreshHighlightsTimer.Stop()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   705
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   706
    def SetCurrentCursor(self, cursor):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   707
        if self.Mode != MODE_MOTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   708
            global CURSORS
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   709
            if self.CurrentCursor != cursor:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   710
                self.CurrentCursor = cursor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   711
                self.Editor.SetCursor(CURSORS[cursor])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   712
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   713
    def GetScrolledRect(self, rect):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   714
        rect.x, rect.y = self.Editor.CalcScrolledPosition(int(rect.x * self.ViewScale[0]),
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   715
                                                   int(rect.y * self.ViewScale[1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   716
        rect.width = int(rect.width * self.ViewScale[0]) + 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   717
        rect.height = int(rect.height * self.ViewScale[1]) + 2
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   718
        return rect
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   719
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   720
    def GetTitle(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   721
        if self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   722
            if len(self.InstancePath) > 15:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   723
                return "..." + self.InstancePath[-12:]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   724
            return self.InstancePath
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   725
        return EditorPanel.GetTitle(self)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   726
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   727
    def GetScaling(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   728
        return self.Scaling
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   729
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   730
    def GetInstancePath(self, variable_base=False):
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   731
        if variable_base:
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   732
            words = self.TagName.split("::")
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   733
            if words[0] in ["A", "T"]:
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   734
                return ".".join(self.InstancePath.split(".")[:-1])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   735
        return self.InstancePath
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   736
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   737
    def IsViewing(self, tagname):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   738
        if self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   739
            return self.InstancePath == tagname
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   740
        return EditorPanel.IsViewing(self, tagname)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   741
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   742
    # Returns a new id
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   743
    def GetNewId(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   744
        self.current_id += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   745
        return self.current_id
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   746
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   747
    def SetScale(self, scale_number, refresh=True, mouse_event=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   748
        new_scale = max(0, min(scale_number, len(ZOOM_FACTORS) - 1))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   749
        if self.CurrentScale != new_scale:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   750
            if refresh:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   751
                dc = self.GetLogicalDC()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   752
            self.CurrentScale = new_scale
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   753
            self.ViewScale = (ZOOM_FACTORS[self.CurrentScale], ZOOM_FACTORS[self.CurrentScale])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   754
            if refresh:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   755
                self.Editor.Freeze()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   756
                if mouse_event is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   757
                    client_size = self.Editor.GetClientSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   758
                    mouse_pos = wx.Point(client_size[0] / 2, client_size[1] / 2)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   759
                    mouse_event = wx.MouseEvent(wx.EVT_MOUSEWHEEL.typeId)
1498
b11045a2f17c fix deprecation warnings about accessing properties m_x, m_y of wxKeyEvent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1481
diff changeset
   760
                    mouse_event.x = mouse_pos.x
b11045a2f17c fix deprecation warnings about accessing properties m_x, m_y of wxKeyEvent
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 1481
diff changeset
   761
                    mouse_event.y = mouse_pos.y
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   762
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   763
                    mouse_pos = mouse_event.GetPosition()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   764
                pos = mouse_event.GetLogicalPosition(dc)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   765
                xmax = self.GetScrollRange(wx.HORIZONTAL) - self.GetScrollThumb(wx.HORIZONTAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   766
                ymax = self.GetScrollRange(wx.VERTICAL) - self.GetScrollThumb(wx.VERTICAL)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   767
                scrollx = max(0, round(pos.x * self.ViewScale[0] - mouse_pos.x) / SCROLLBAR_UNIT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   768
                scrolly = max(0, round(pos.y * self.ViewScale[1] - mouse_pos.y) / SCROLLBAR_UNIT)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   769
                if scrollx > xmax or scrolly > ymax:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   770
                    self.RefreshScrollBars(max(0, scrollx - xmax), max(0, scrolly - ymax))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   771
                    self.Scroll(scrollx, scrolly)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   772
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   773
                    self.Scroll(scrollx, scrolly)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   774
                    self.RefreshScrollBars()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   775
                self.RefreshScaling(refresh)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   776
                self.Editor.Thaw()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   777
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   778
    def GetScale(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   779
        return self.CurrentScale
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   780
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   781
    def GetViewScale(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   782
        return self.ViewScale
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   783
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   784
    def GetLogicalDC(self, buffered=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   785
        if buffered:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   786
            bitmap = wx.EmptyBitmap(*self.Editor.GetClientSize())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   787
            dc = wx.MemoryDC(bitmap)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   788
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   789
            dc = wx.ClientDC(self.Editor)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   790
        dc.SetFont(self.GetFont())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   791
        if wx.VERSION >= (2, 6, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   792
            self.Editor.DoPrepareDC(dc)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   793
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   794
            self.Editor.PrepareDC(dc)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   795
        dc.SetUserScale(self.ViewScale[0], self.ViewScale[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   796
        return dc
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   797
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   798
    def RefreshRect(self, rect, eraseBackground=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   799
        self.Editor.RefreshRect(rect, eraseBackground)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   800
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   801
    def Scroll(self, x, y):
1204
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   802
        if self.Debug and wx.Platform == '__WXMSW__':
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   803
            self.Editor.Freeze()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   804
        self.Editor.Scroll(x, y)
1204
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   805
        if self.Debug:
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   806
            if wx.Platform == '__WXMSW__':
1208
d22fcdfae8d0 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1205
diff changeset
   807
                self.Editor.Thaw()
1204
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   808
            else:
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
   809
                self.Editor.Refresh()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   810
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   811
    def GetScrollPos(self, orientation):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   812
        return self.Editor.GetScrollPos(orientation)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   813
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   814
    def GetScrollRange(self, orientation):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   815
        return self.Editor.GetScrollRange(orientation)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   816
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   817
    def GetScrollThumb(self, orientation):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   818
        return self.Editor.GetScrollThumb(orientation)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   819
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   820
    def CalcUnscrolledPosition(self, x, y):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   821
        return self.Editor.CalcUnscrolledPosition(x, y)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   822
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   823
    def GetViewStart(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   824
        return self.Editor.GetViewStart()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   825
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   826
    def GetTextExtent(self, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   827
        return self.Editor.GetTextExtent(text)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   828
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   829
    def GetFont(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   830
        return self.Editor.GetFont()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   831
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   832
    def GetMiniTextExtent(self, text):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   833
        return self.MiniTextDC.GetTextExtent(text)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   834
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   835
    def GetMiniFont(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   836
        return self.MiniTextDC.GetFont()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   837
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   838
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   839
#                         Element management functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   840
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   841
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   842
    def AddBlock(self, block):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   843
        self.Blocks[block.GetId()] = block
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   844
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   845
    def AddWire(self, wire):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   846
        self.wire_id += 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   847
        self.Wires[wire] = self.wire_id
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   848
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   849
    def AddComment(self, comment):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   850
        self.Comments[comment.GetId()] = comment
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   851
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   852
    def IsBlock(self, block):
852
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   853
        if block is not None:
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   854
            return self.Blocks.get(block.GetId(), False)
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   855
        return False
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   856
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   857
    def IsWire(self, wire):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   858
        return self.Wires.get(wire, False)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   859
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   860
    def IsComment(self, comment):
852
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   861
        if comment is not None:
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   862
            return self.Comments.get(comment.GetId(), False)
1009f956d2ee Fix support for adjusting block size to block minimum size and to Viewer scaling
Laurent Bessard
parents: 832
diff changeset
   863
        return False
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   864
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   865
    def RemoveBlock(self, block):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   866
        self.Blocks.pop(block.GetId())
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   867
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   868
    def RemoveWire(self, wire):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   869
        self.Wires.pop(wire)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   870
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   871
    def RemoveComment(self, comment):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   872
        self.Comments.pop(comment.GetId())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   873
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   874
    def GetElements(self, sort_blocks=False, sort_wires=False, sort_comments=False):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   875
        blocks = self.Blocks.values()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   876
        wires = self.Wires.keys()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   877
        comments = self.Comments.values()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   878
        if sort_blocks:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   879
            blocks.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   880
        if sort_wires:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   881
            wires.sort(lambda x, y: cmp(self.Wires[x], self.Wires[y]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   882
        if sort_comments:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   883
            comments.sort(lambda x, y: cmp(x.GetId(), y.GetId()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   884
        return blocks + wires + comments
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   885
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   886
    def GetConnectorByName(self, name):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   887
        for block in self.Blocks.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   888
            if isinstance(block, FBD_Connector) and\
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   889
               block.GetType() == CONNECTOR and\
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   890
               block.GetName() == name:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   891
                return block
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   892
        return None
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   893
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   894
    def RefreshVisibleElements(self, xp = None, yp = None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   895
        x, y = self.Editor.CalcUnscrolledPosition(0, 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   896
        if xp is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   897
            x = xp * self.Editor.GetScrollPixelsPerUnit()[0]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   898
        if yp is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   899
            y = yp * self.Editor.GetScrollPixelsPerUnit()[1]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   900
        width, height = self.Editor.GetClientSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   901
        screen = wx.Rect(int(x / self.ViewScale[0]), int(y / self.ViewScale[1]),
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   902
                         int(width / self.ViewScale[0]), int(height / self.ViewScale[1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   903
        for comment in self.Comments.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   904
            comment.TestVisible(screen)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   905
        for wire in self.Wires.iterkeys():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   906
            wire.TestVisible(screen)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   907
        for block in self.Blocks.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   908
            block.TestVisible(screen)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   909
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   910
    def GetElementIECPath(self, element):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   911
        iec_path = None
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   912
        instance_path = self.GetInstancePath(True)
1166
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
   913
        if isinstance(element, (Wire, Connector)):
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
   914
            if isinstance(element, Wire):
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
   915
                element = element.EndConnected
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
   916
            block = element.GetParentBlock()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   917
            if isinstance(block, FBD_Block):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   918
                blockname = block.GetName()
1166
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
   919
                connectorname = element.GetName()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   920
                if blockname != "":
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   921
                    iec_path = "%s.%s.%s"%(instance_path, blockname, connectorname)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   922
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   923
                    if connectorname == "":
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   924
                        iec_path = "%s.%s%d"%(instance_path, block.GetType(), block.GetId())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   925
                    else:
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   926
                        iec_path = "%s.%s%d_%s"%(instance_path, block.GetType(), block.GetId(), connectorname)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   927
            elif isinstance(block, FBD_Variable):
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   928
                iec_path = "%s.%s"%(instance_path, block.GetName())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   929
            elif isinstance(block, FBD_Connector):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   930
                connection = self.GetConnectorByName(block.GetName())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   931
                if connection is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   932
                    connector = connection.GetConnector()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   933
                    if len(connector.Wires) == 1:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   934
                        iec_path = self.GetElementIECPath(connector.Wires[0][0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   935
        elif isinstance(element, LD_Contact):
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   936
            iec_path = "%s.%s"%(instance_path, element.GetName())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   937
        elif isinstance(element, SFC_Step):
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   938
            iec_path = "%s.%s.X"%(instance_path, element.GetName())
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   939
        elif isinstance(element, SFC_Transition):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   940
            connectors = element.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   941
            previous_steps = self.GetPreviousSteps(connectors["inputs"])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   942
            next_steps = self.GetNextSteps(connectors["outputs"])
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
   943
            iec_path = "%s.%s->%s"%(instance_path, ",".join(previous_steps), ",".join(next_steps))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   944
        return iec_path
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   945
1377
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   946
    def GetWireModifier(self, wire):
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   947
        connector = wire.EndConnected
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   948
        block = connector.GetParentBlock()
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   949
        if isinstance(block, FBD_Connector):
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   950
            connection = self.GetConnectorByName(block.GetName())
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   951
            if connection is not None:
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   952
                connector = connection.GetConnector()
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   953
                if len(connector.Wires) == 1:
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   954
                    return self.GetWireModifier(connector.Wires[0][0])
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   955
        else:
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   956
            if connector.IsNegated():
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   957
                return "negated"
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   958
            else:
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   959
                return connector.GetEdge()
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
   960
        return "none"
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   961
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   962
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   963
#                              Reset functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   964
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   965
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   966
    # Resets Viewer lists
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   967
    def ResetView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   968
        self.Blocks = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   969
        self.Wires = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   970
        self.Comments = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   971
        self.Subscribed = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   972
        self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   973
        self.HighlightedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   974
        self.ToolTipElement = None
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   975
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   976
    def Flush(self):
1205
638d1d430d24 Fixed bug Viewer not refreshed when debugging
Laurent Bessard
parents: 1204
diff changeset
   977
        self.UnsubscribeAllDataConsumers(tick=False)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   978
        for block in self.Blocks.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   979
            block.Flush()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   980
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   981
    # Remove all elements
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   982
    def CleanView(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   983
        for block in self.Blocks.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   984
            block.Clean()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   985
        self.ResetView()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   986
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   987
    # Changes Viewer mode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   988
    def SetMode(self, mode):
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
   989
        if self.Mode != mode or mode == MODE_SELECTION:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   990
            if self.Mode == MODE_MOTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   991
                wx.CallAfter(self.Editor.SetCursor, wx.NullCursor)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   992
            self.Mode = mode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   993
            self.SavedMode = False
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   994
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   995
            self.SavedMode = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   996
        # Reset selection
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   997
        if self.Mode != MODE_SELECTION and self.SelectedElement:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   998
            self.SelectedElement.SetSelected(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   999
            self.SelectedElement = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1000
        if self.Mode == MODE_MOTION:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1001
            wx.CallAfter(self.Editor.SetCursor, wx.StockCursor(wx.CURSOR_HAND))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1002
            self.SavedMode = True
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1003
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1004
    # Return current drawing mode
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1005
    def GetDrawingMode(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1006
        return self.ParentWindow.GetDrawingMode()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1007
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1008
    # Buffer the last model state
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1009
    def RefreshBuffer(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1010
        self.Controler.BufferProject()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1011
        if self.ParentWindow:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1012
            self.ParentWindow.RefreshTitle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1013
            self.ParentWindow.RefreshFileMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1014
            self.ParentWindow.RefreshEditMenu()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1015
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1016
    def StartBuffering(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1017
        if not self.Buffering:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1018
            self.Buffering = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1019
            self.Controler.StartBuffering()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1020
            if self.ParentWindow:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1021
                self.ParentWindow.RefreshTitle()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1022
                self.ParentWindow.RefreshFileMenu()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1023
                self.ParentWindow.RefreshEditMenu()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1024
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1025
    def ResetBuffer(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1026
        if self.Buffering:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1027
            self.Controler.EndBuffering()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1028
            self.Buffering = False
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1029
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1030
    def GetBufferState(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1031
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1032
            return self.Controler.GetBufferState()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1033
        return False, False
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1034
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1035
    def Undo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1036
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1037
            self.Controler.LoadPrevious()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1038
            self.ParentWindow.CloseTabsWithoutModel()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1039
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1040
    def Redo(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1041
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1042
            self.Controler.LoadNext()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1043
            self.ParentWindow.CloseTabsWithoutModel()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1044
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1045
    def HasNoModel(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1046
        if not self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1047
            return self.Controler.GetEditedElement(self.TagName) is None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1048
        return False
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1049
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1050
    # Refresh the current scaling
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1051
    def RefreshScaling(self, refresh=True):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1052
        properties = self.Controler.GetProjectProperties(self.Debug)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1053
        scaling = properties["scaling"][self.CurrentLanguage]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1054
        if scaling[0] != 0 and scaling[1] != 0:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1055
            self.Scaling = scaling
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1056
            if self.DrawGrid:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1057
                width = max(2, int(scaling[0] * self.ViewScale[0]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1058
                height = max(2, int(scaling[1] * self.ViewScale[1]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1059
                bitmap = wx.EmptyBitmap(width, height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1060
                dc = wx.MemoryDC(bitmap)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1061
                dc.SetBackground(wx.Brush(self.Editor.GetBackgroundColour()))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1062
                dc.Clear()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1063
                dc.SetPen(MiterPen(wx.Colour(180, 180, 180)))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1064
                dc.DrawPoint(0, 0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1065
                self.GridBrush = wx.BrushFromBitmap(bitmap)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1066
            else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1067
                self.GridBrush = wx.TRANSPARENT_BRUSH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1068
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1069
            self.Scaling = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1070
            self.GridBrush = wx.TRANSPARENT_BRUSH
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1071
        page_size = properties["pageSize"]
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1072
        if page_size != (0, 0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1073
            self.PageSize = map(int, page_size)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1074
            self.PagePen = MiterPen(wx.Colour(180, 180, 180))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1075
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1076
            self.PageSize = None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1077
            self.PagePen = wx.TRANSPARENT_PEN
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1078
        if refresh:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1079
            self.RefreshVisibleElements()
1204
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
  1080
            self.Editor.Refresh(False)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1081
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1082
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1083
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1084
#                          Refresh functions
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1085
#-------------------------------------------------------------------------------
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1086
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1087
    VALUE_TRANSLATION = {True: _("Active"), False: _("Inactive")}
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1088
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1089
    def SetValue(self, value):
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1090
        if self.Value != value:
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1091
            self.Value = value
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1092
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1093
            xstart, ystart = self.GetViewStart()
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1094
            window_size = self.Editor.GetClientSize()
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1095
            refresh_rect = self.GetRedrawRect()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1096
            if (xstart * SCROLLBAR_UNIT <= refresh_rect.x + refresh_rect.width and
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1097
                xstart * SCROLLBAR_UNIT + window_size[0] >= refresh_rect.x and
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1098
                ystart * SCROLLBAR_UNIT <= refresh_rect.y + refresh_rect.height and
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1099
                ystart * SCROLLBAR_UNIT + window_size[1] >= refresh_rect.y):
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1100
                self.ElementNeedRefresh(self)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1101
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1102
    def GetRedrawRect(self):
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1103
        dc = self.GetLogicalDC()
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1104
        ipw, iph = dc.GetTextExtent(_("Debug: %s") % self.InstancePath)
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1105
        vw, vh = 0, 0
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1106
        for value in self.VALUE_TRANSLATION.itervalues():
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1107
            w, h = dc.GetTextExtent("(%s)" % value)
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1108
            vw = max(vw, w)
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1109
            vh = max(vh, h)
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1110
        return wx.Rect(ipw + 4, 2, vw, vh)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1111
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1112
    def ElementNeedRefresh(self, element):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1113
        self.ElementRefreshList_lock.acquire()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1114
        self.ElementRefreshList.append(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1115
        self.ElementRefreshList_lock.release()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1116
1431
df59be5afb08 more minor cleanup
Edouard Tisserant
parents: 1417
diff changeset
  1117
    def NewDataAvailable(self, ticks):
1366
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1118
        if self.IsShown():
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1119
            refresh_rect = None
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1120
            self.ElementRefreshList_lock.acquire()
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1121
            for element in self.ElementRefreshList:
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1122
                if refresh_rect is None:
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1123
                    refresh_rect = element.GetRedrawRect()
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1124
                else:
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1125
                    refresh_rect.Union(element.GetRedrawRect())
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1126
            self.ElementRefreshList = []
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1127
            self.ElementRefreshList_lock.release()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1128
1366
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1129
            if refresh_rect is not None:
3756ae754713 Fixed refresh speed so that interface is not blocked when debugging
Laurent Bessard
parents: 1363
diff changeset
  1130
                self.RefreshRect(self.GetScrolledRect(refresh_rect), False)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1131
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1170
diff changeset
  1132
    def SubscribeAllDataConsumers(self):
1201
3907f10efcf4 Fixed bug Viewer not refreshed when debugging
Laurent Bessard
parents: 1176
diff changeset
  1133
        self.RefreshView()
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1170
diff changeset
  1134
        DebugViewer.SubscribeAllDataConsumers(self)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1135
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1136
    # Refresh Viewer elements
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1137
    def RefreshView(self, variablepanel=True, selection=None):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1138
        EditorPanel.RefreshView(self, variablepanel)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1139
1293
40117d02601b Fixed diagram editing in xmlclass refactoring
Laurent Bessard
parents: 1287
diff changeset
  1140
        if self.TagName.split("::")[0] == "A" and self.Debug:
828
319dac4c4fd3 Fix debug of Action and Transition defined in FBD and LD using Viewer
laurent
parents: 823
diff changeset
  1141
            self.AddDataConsumer("%s.Q" % self.InstancePath.upper(), self)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1142
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1143
        if self.ToolTipElement is not None:
1170
074e46cdedbc Added support for displaying ToolTip, starting drag'n drop and Double click on Block connectors when debugging
Laurent Bessard
parents: 1166
diff changeset
  1144
            self.ToolTipElement.DestroyToolTip()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1145
            self.ToolTipElement = None
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1146
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1147
        self.Inhibit(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1148
        self.current_id = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1149
        # Start by reseting Viewer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1150
        self.Flush()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1151
        self.ResetView()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1152
        self.ResetBuffer()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1153
        instance = {}
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1154
        # List of ids of already loaded blocks
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1155
        instances = self.Controler.GetEditedElementInstancesInfos(self.TagName, debug = self.Debug)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1156
        # Load Blocks until they are all loaded
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1157
        while len(instances) > 0:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1158
            self.loadInstance(instances.popitem(0)[1], instances, selection)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1159
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1160
        if (selection is not None and
1229
137fd7e7b102 Fixed typo in Viewer
Laurent Bessard
parents: 1228
diff changeset
  1161
            isinstance(self.SelectedElement, Graphic_Group)):
1226
93e7a8abce5e Fixed lag when selecting all elements using CTRL+A or after paste a lot of blocks
Laurent Bessard
parents: 1225
diff changeset
  1162
            self.SelectedElement.RefreshWireExclusion()
93e7a8abce5e Fixed lag when selecting all elements using CTRL+A or after paste a lot of blocks
Laurent Bessard
parents: 1225
diff changeset
  1163
            self.SelectedElement.RefreshBoundingBox()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1164
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1165
        self.RefreshScrollBars()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1166
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1167
        for wire in self.Wires:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1168
            if not wire.IsConnectedCompatible():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1169
                wire.SetValid(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1170
            if self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1171
                iec_path = self.GetElementIECPath(wire)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1172
                if iec_path is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1173
                    block = wire.EndConnected.GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1174
                    if isinstance(block, LD_PowerRail):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1175
                        wire.SetValue(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1176
                elif self.AddDataConsumer(iec_path.upper(), wire) is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1177
                    wire.SetValue("undefined")
1377
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
  1178
                else:
cc8f9177d41c Fixed bug when debugging wire connected to output connector with modifiers even if connector/continuation is used to replace long wires
Laurent Bessard
parents: 1366
diff changeset
  1179
                    wire.SetModifier(self.GetWireModifier(wire))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1180
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1181
        if self.Debug:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1182
            for block in self.Blocks.itervalues():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1183
                block.SpreadCurrent()
1166
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1184
                if isinstance(block, FBD_Block):
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1185
                    for output_connector in block.GetConnectors()["outputs"]:
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1186
                        if len(output_connector.GetWires()) == 0:
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1187
                            iec_path = self.GetElementIECPath(output_connector)
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1188
                            if iec_path is not None:
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1189
                                self.AddDataConsumer(iec_path.upper(), output_connector)
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1190
                else:
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1191
                    iec_path = self.GetElementIECPath(block)
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1192
                    if iec_path is not None:
2ed9675be08d Added support for displaying value of unconnected block connectors in debug
Laurent Bessard
parents: 1141
diff changeset
  1193
                        self.AddDataConsumer(iec_path.upper(), block)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1194
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1195
        self.Inhibit(False)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1196
        self.RefreshVisibleElements()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1197
        self.ShowHighlights()
1204
8a620b460b49 Fixed support for drawing instance path at a fixed position in Viewer debug mode on Windows
Laurent Bessard
parents: 1203
diff changeset
  1198
        self.Editor.Refresh(False)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1199
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1200
    def GetPreviousSteps(self, connectors):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1201
        steps = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1202
        for connector in connectors:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1203
            for wire, handle in connector.GetWires():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1204
                previous = wire.GetOtherConnected(connector).GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1205
                if isinstance(previous, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1206
                    steps.append(previous.GetName())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1207
                elif isinstance(previous, SFC_Divergence) and previous.GetType() in [SIMULTANEOUS_CONVERGENCE, SELECTION_DIVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1208
                    connectors = previous.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1209
                    steps.extend(self.GetPreviousSteps(connectors["inputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1210
        return steps
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1211
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1212
    def GetNextSteps(self, connectors):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1213
        steps = []
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1214
        for connector in connectors:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1215
            for wire, handle in connector.GetWires():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1216
                next = wire.GetOtherConnected(connector).GetParentBlock()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1217
                if isinstance(next, SFC_Step):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1218
                    steps.append(next.GetName())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1219
                elif isinstance(next, SFC_Jump):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1220
                    steps.append(next.GetTarget())
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1221
                elif isinstance(next, SFC_Divergence) and next.GetType() in [SIMULTANEOUS_DIVERGENCE, SELECTION_CONVERGENCE]:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1222
                    connectors = next.GetConnectors()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1223
                    steps.extend(self.GetNextSteps(connectors["outputs"]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1224
        return steps
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1225
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1226
    def GetMaxSize(self):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1227
        maxx = maxy = 0
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1228
        for element in self.GetElements():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1229
            bbox = element.GetBoundingBox()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1230
            maxx = max(maxx, bbox.x + bbox.width)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1231
            maxy = max(maxy, bbox.y + bbox.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1232
        return maxx, maxy
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1233
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1234
    def RefreshScrollBars(self, width_incr=0, height_incr=0):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1235
        xstart, ystart = self.GetViewStart()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1236
        window_size = self.Editor.GetClientSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1237
        maxx, maxy = self.GetMaxSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1238
        maxx = max(maxx + WINDOW_BORDER, (xstart * SCROLLBAR_UNIT + window_size[0]) / self.ViewScale[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1239
        maxy = max(maxy + WINDOW_BORDER, (ystart * SCROLLBAR_UNIT + window_size[1]) / self.ViewScale[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1240
        if self.rubberBand.IsShown():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1241
            extent = self.rubberBand.GetCurrentExtent()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1242
            maxx = max(maxx, extent.x + extent.width)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1243
            maxy = max(maxy, extent.y + extent.height)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1244
        maxx = int(maxx * self.ViewScale[0])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1245
        maxy = int(maxy * self.ViewScale[1])
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1246
        self.Editor.SetScrollbars(SCROLLBAR_UNIT, SCROLLBAR_UNIT,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1247
            round(maxx / SCROLLBAR_UNIT) + width_incr, round(maxy / SCROLLBAR_UNIT) + height_incr,
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1248
            xstart, ystart, True)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1249
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1250
    def EnsureVisible(self, block):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1251
        xstart, ystart = self.GetViewStart()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1252
        window_size = self.Editor.GetClientSize()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1253
        block_bbx = block.GetBoundingBox()
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1254
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1255
        screen_minx, screen_miny = xstart * SCROLLBAR_UNIT, ystart * SCROLLBAR_UNIT
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1256
        screen_maxx, screen_maxy = screen_minx + window_size[0], screen_miny + window_size[1]
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1257
        block_minx = int(block_bbx.x * self.ViewScale[0])
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1258
        block_miny = int(block_bbx.y * self.ViewScale[1])
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1259
        block_maxx = int(round((block_bbx.x + block_bbx.width) * self.ViewScale[0]))
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1260
        block_maxy = int(round((block_bbx.y + block_bbx.height) * self.ViewScale[1]))
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1261
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1262
        xpos, ypos = xstart, ystart
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1263
        if block_minx < screen_minx and block_maxx < screen_maxx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1264
            xpos -= (screen_minx - block_minx) / SCROLLBAR_UNIT + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1265
        elif block_maxx > screen_maxx and block_minx > screen_minx:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1266
            xpos += (block_maxx - screen_maxx) / SCROLLBAR_UNIT + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1267
        if block_miny < screen_miny and block_maxy < screen_maxy:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1268
            ypos -= (screen_miny - block_miny) / SCROLLBAR_UNIT + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1269
        elif block_maxy > screen_maxy and block_miny > screen_miny:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1270
            ypos += (block_maxy - screen_maxy) / SCROLLBAR_UNIT + 1
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1271
        self.Scroll(xpos, ypos)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1272
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1273
    def SelectInGroup(self, element):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1274
        element.SetSelected(True)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1275
        if self.SelectedElement is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1276
            self.SelectedElement = element
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1277
        elif isinstance(self.SelectedElement, Graphic_Group):
1226
93e7a8abce5e Fixed lag when selecting all elements using CTRL+A or after paste a lot of blocks
Laurent Bessard
parents: 1225
diff changeset
  1278
            self.SelectedElement.AddElement(element)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1279
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1280
            group = Graphic_Group(self)
1226
93e7a8abce5e Fixed lag when selecting all elements using CTRL+A or after paste a lot of blocks
Laurent Bessard
parents: 1225
diff changeset
  1281
            group.AddElement(self.SelectedElement)
93e7a8abce5e Fixed lag when selecting all elements using CTRL+A or after paste a lot of blocks
Laurent Bessard
parents: 1225
diff changeset
  1282
            group.AddElement(element)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1283
            self.SelectedElement = group
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1284
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1285
    # Load instance from given informations
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1286
    def loadInstance(self, instance, remaining_instances, selection):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1287
        self.current_id = max(self.current_id, instance.id)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1288
        creation_function = ElementCreationFunctions.get(instance.type, None)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1289
        connectors = {"inputs" : [], "outputs" : []}
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1290
        specific_values = instance.specific_values
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1291
        if creation_function is not None:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1292
            element = creation_function(self, instance.id, specific_values)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1293
            if isinstance(element, SFC_Step):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1294
                if len(instance.inputs) > 0:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1295
                    element.AddInput()
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1296
                else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1297
                    element.RemoveInput()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1298
                if len(instance.outputs) > 0:
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1299
                    element.AddOutput()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1300
            if isinstance(element, SFC_Transition) and specific_values.condition_type == "connection":
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1301
                connector = element.GetConditionConnector()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1302
                self.CreateWires(connector, instance.id, specific_values.connection.links, remaining_instances, selection)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1303
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1304
            executionControl = False
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1305
            for input in instance.inputs:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1306
                input_edge = MODIFIER_VALUE(input.edge)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1307
                if input.negated:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1308
                    connectors["inputs"].append((input.name, None, "negated"))
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1309
                elif input_edge:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1310
                    connectors["inputs"].append((input.name, None, input_edge))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1311
                else:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1312
                    connectors["inputs"].append((input.name, None, "none"))
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1313
            for output in instance.outputs:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1314
                output_edge = MODIFIER_VALUE(output.edge)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1315
                if output.negated:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1316
                    connectors["outputs"].append((output.name, None, "negated"))
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1317
                elif output_edge:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1318
                    connectors["outputs"].append((output.name, None, output_edge))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1319
                else:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1320
                    connectors["outputs"].append((output.name, None, "none"))
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1321
            if len(connectors["inputs"]) > 0 and connectors["inputs"][0][0] == "EN":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1322
                connectors["inputs"].pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1323
                executionControl = True
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1324
            if len(connectors["outputs"]) > 0 and connectors["outputs"][0][0] == "ENO":
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1325
                connectors["outputs"].pop(0)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1326
                executionControl = True
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1327
            block_name = specific_values.name if specific_values.name is not None else ""
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1328
            element = FBD_Block(self, instance.type, block_name,
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1329
                      instance.id, len(connectors["inputs"]),
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1330
                      connectors=connectors, executionControl=executionControl,
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1331
                      executionOrder=specific_values.execution_order)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1332
        if isinstance(element, Comment):
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1333
            self.AddComment(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1334
        else:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1335
            self.AddBlock(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1336
            connectors = element.GetConnectors()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1337
        element.SetPosition(instance.x, instance.y)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1338
        element.SetSize(instance.width, instance.height)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1339
        for i, output_connector in enumerate(instance.outputs):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1340
            connector_pos = wx.Point(*output_connector.position)
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1341
            if isinstance(element, FBD_Block):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1342
                connector = element.GetConnector(connector_pos,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1343
                    output_name = output_connector.name)
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1344
            elif i < len(connectors["outputs"]):
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1345
                connector = connectors["outputs"][i]
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1346
            else:
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1347
                connector = None
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1348
            if connector is not None:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1349
                if output_connector.negated:
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1350
                    connector.SetNegated(True)
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1351
                if output_connector.edge is not None:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1352
                    connector.SetEdge(output_connector.edge)
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1353
                if connectors["outputs"].index(connector) == i:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1354
                    connector.SetPosition(connector_pos)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1355
        for i, input_connector in enumerate(instance.inputs):
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1356
            connector_pos = wx.Point(*input_connector.position)
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1357
            if isinstance(element, FBD_Block):
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1358
                connector = element.GetConnector(connector_pos,
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1359
                    input_name = input_connector.name)
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1360
            elif i < len(connectors["inputs"]):
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1361
                connector = connectors["inputs"][i]
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1362
            else:
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1363
                connector = None
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1364
            if connector is not None:
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1365
                if connectors["inputs"].index(connector) == i:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1366
                    connector.SetPosition(connector_pos)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1367
                if input_connector.negated:
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1368
                    connector.SetNegated(True)
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1369
                if input_connector.edge is not None:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1370
                    connector.SetEdge(input_connector.edge)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1371
                if not self.CreateWires(connector, instance.id, input_connector.links, remaining_instances, selection):
1141
5069a28486b9 Fixed bug connection disappear when removing variable from interface of an already used POU
Laurent Bessard
parents: 1135
diff changeset
  1372
                    element.RefreshModel()
1130
f96e0254f0ce Fixed loading of Blocks in Viewer when block interface have changed
Laurent Bessard
parents: 1123
diff changeset
  1373
        element.RefreshConnectors()
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1374
        if selection is not None and selection[0].get(instance.id, False):
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1375
            self.SelectInGroup(element)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1376
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1377
    def CreateWires(self, start_connector, id, links, remaining_instances, selection=None):
1135
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1378
        links_connected = True
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
  1379
        for link in links:
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1380
            refLocalId = link.refLocalId
1135
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1381
            if refLocalId is None:
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1382
                links_connected = False
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1383
                continue
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1384
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1385
            new_instance = remaining_instances.pop(refLocalId, None)
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1386
            if new_instance is not None:
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1387
                self.loadInstance(new_instance, remaining_instances, selection)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1388
1135
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1389
            connected = self.FindElementById(refLocalId)
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1390
            if connected is None:
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1391
                links_connected = False
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1392
                continue
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1393
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1394
            points = link.points
1335
1b9610fc1e6b Fixed bug when loading graphic pou connection between blocks and no points for drawing wire are defined
Laurent Bessard
parents: 1331
diff changeset
  1395
            end_connector = connected.GetConnector(
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1396
                wx.Point(points[-1].x, points[-1].y)
1417
374238039643 Added a variable name text entry dialog to allow name change on drag'n'drops
Edouard Tisserant
parents: 1406
diff changeset
  1397
                if len(points) > 0 else wx.Point(0, 0),
1338
c1e6c712cc35 Replaced old graphic viewer blocks loading process by xslt stylesheet
Laurent Bessard
parents: 1335
diff changeset
  1398
                link.formalParameter)
1135
519a21ddbc40 Added support for updating model when broken connection is detected in Viewer
Laurent Bessard
parents: 1133
diff changeset
  1399
            if end_connector is not None:
1335
1b9610fc1e6b Fixed bug when loading graphic pou connection between blocks and no points for drawing wire are defined
Laurent Bessard
parents: 1331
diff changeset
  1400
                if len(points) > 0:
1b9610fc1e6b Fixed bug when loading graphic pou connection between blocks and no points for drawing wire are defined
Laurent Bessard
parents: 1331
diff changeset