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