Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
65365327
Commit
65365327
authored
Nov 02, 2019
by
Maxime Perrotin
Browse files
Start working with pyside2
parent
93394b60
Changes
22
Expand all
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
65365327
...
...
@@ -32,31 +32,23 @@ flake8:
Statechart.py TextInteraction.py
>
flake8_report
compile-all
:
@
pyside-rcc opengeode.qrc
-o
opengeode/icons.py
@
if
[
!
-f
antlr-3.1.3.tar.bz2
]
;
\
then
wget http://download.tuxfamily.org/taste/misc/antlr-3.1.3.tar.bz2
;
\
tar
jxvf antlr-3.1.3.tar.bz2
;
\
fi
@
CLASSPATH
=
$$
PWD/antlr-3.1.3/lib/antlr-3.1.3.jar java org.antlr.Tool sdl92.g
@
mv
sdl92
*
.py opengeode
@
pyside2-rcc opengeode.qrc
-o
opengeode/icons.py
# use antlr3 from Debian's python3-antlr3 package
antlr3
-o
opengeode sdl92.g
update
:
git pull
#@git submodule update --remote
dependencies
:
@
pip2
install
--user
--upgrade
./antlr3-python
@
pip2
install
--user
--upgrade
singledispatch
@
pip2
install
--user
--upgrade
enum34
@
pip2
install
--user
--upgrade
./speedometer
#@pip2 install --user --upgrade ./properties
@
pip3
install
--user
--upgrade
./dmt
@
pip2
install
--user
--upgrade
./pymsc
#@pip2 install --user --upgrade ./asn1-value-editor
@
pip2
install
--user
--upgrade
./pygraphviz
apt
install
pyside2
*
apt
install
python3-antlr3
apt
install
pyside2-tools
pip3
install
--user
--upgrade
pygraphviz
pip3
install
--user
--upgrade
stringtemplate3
# optional dependencies from taste: spedometer, properties, dmt, pymsc, asn1-value-editor
install
:
@
pip
2
install
--user
--upgrade
.
@
pip
3
install
--user
--upgrade
.
full-install
:
update dependencies install
...
...
opengeode/AdaGenerator.py
View file @
65365327
#!/usr/bin/env python
#!/usr/bin/env python
3
# -*- coding: utf-8 -*-
"""
...
...
@@ -74,15 +74,9 @@ import traceback
import
os
import
stat
from
itertools
import
chain
,
product
try
:
# python2
from
singledispatch
import
singledispatch
except
ModuleNotFoundError
:
# python3
from
functools
import
singledispatch
from
functools
import
singledispatch
import
ogAST
import
Helper
from
.
import
ogAST
,
Helper
LOG
=
logging
.
getLogger
(
__name__
)
...
...
@@ -330,7 +324,7 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
process_level_decl
=
[]
# Establish the list of states (excluding START states) XXX update C backend
full_statelist
=
set
(
chain
(
aggregates
.
view
keys
(),
full_statelist
=
set
(
chain
(
aggregates
.
keys
(),
(
name
for
name
in
process
.
mapping
.
iterkeys
()
if
not
name
.
endswith
(
u
'START'
))))
reduced_statelist
=
{
s
for
s
in
full_statelist
if
s
not
in
parallel_states
}
...
...
@@ -350,9 +344,9 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
types_with_proper_case
=
[]
# The ASN.1 module must import the types from other asn1 modules
for
_
,
sortdef
in
process
.
user_defined_types
.
view
items
():
for
_
,
sortdef
in
process
.
user_defined_types
.
items
():
sort
=
sortdef
.
type
.
type
.
ReferencedTypeName
for
moduleName
,
sorts
in
process
.
DV
.
exportedTypes
.
view
items
():
for
moduleName
,
sorts
in
process
.
DV
.
exportedTypes
.
items
():
for
each
in
sorts
:
if
sort
.
lower
().
replace
(
'-'
,
'_'
)
==
\
each
.
lower
().
replace
(
'-'
,
'_'
):
...
...
@@ -360,7 +354,7 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
.
format
(
t
=
each
,
m
=
moduleName
))
types_with_proper_case
.
append
(
each
)
for
sortname
,
sortdef
in
process
.
user_defined_types
.
view
items
():
for
sortname
,
sortdef
in
process
.
user_defined_types
.
items
():
rangeMin
=
sortdef
.
type
.
Min
rangeMax
=
sortdef
.
type
.
Max
refType
=
sortdef
.
type
.
type
.
ReferencedTypeName
...
...
@@ -388,12 +382,12 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
context_decl
.
append
(
'initDone : Boolean := False;'
)
# State aggregation: add list of substates (XXX to be added in C generator)
for
substates
in
aggregates
.
view
values
():
for
substates
in
aggregates
.
values
():
for
each
in
substates
:
context_decl
.
append
(
u
'{}{}state: States;'
.
format
(
each
.
statename
,
UNICODE_SEP
))
for
var_name
,
(
var_type
,
def_value
)
in
process
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
def_value
)
in
process
.
variables
.
items
():
if
def_value
:
# Expression must be a ground expression, i.e. must not
# require temporary variable to store computed result
...
...
@@ -436,7 +430,7 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
process_level_decl
.
append
(
'CS_Only : constant Integer := {};'
.
format
(
len
(
process
.
transitions
)))
for
name
,
val
in
process
.
mapping
.
view
items
():
for
name
,
val
in
process
.
mapping
.
items
():
# Test val, in principle there is a value but if the code targets
# generation of properties, the model may have been cleant up and
# in that case no value would be set..
...
...
@@ -446,7 +440,7 @@ LD_LIBRARY_PATH=./lib:. opengeode-simulator
# Declare start procedure for aggregate states XXX add in C generator
# should create one START per "via" clause, TODO later
for
name
,
substates
in
aggregates
.
view
items
():
for
name
,
substates
in
aggregates
.
items
():
proc_name
=
u
'procedure {}{}START'
.
format
(
name
,
UNICODE_SEP
)
process_level_decl
.
append
(
u
'{};'
.
format
(
proc_name
))
aggreg_start_proc
.
extend
([
u
'{} is'
.
format
(
proc_name
),
...
...
@@ -594,7 +588,7 @@ package {process_name} is'''.format(generic=generic_spec,
.
format
(
process_name
))
# interface to get/set state aggregations XXX add to C generator
for
substates
in
aggregates
.
view
values
():
for
substates
in
aggregates
.
values
():
for
each
in
substates
:
process_level_decl
.
append
(
u
"function get_{name}_state return chars_ptr "
...
...
@@ -605,7 +599,7 @@ package {process_name} is'''.format(generic=generic_spec,
proc
=
process_name
,
sep
=
UNICODE_SEP
))
# Functions to get gobal variables (length and value)
for
var_name
,
(
var_type
,
_
)
in
process
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
_
)
in
process
.
variables
.
items
():
# Getters for external applications to view local variables via dll
process_level_decl
.
append
(
u
"function l_{name}_value"
u
" return access {sort} "
...
...
@@ -745,20 +739,20 @@ package {process_name} is'''.format(generic=generic_spec,
return
taste_template
.
append
(
u
'when {state} =>'
.
format
(
state
=
state
))
input_def
=
mapping
[
signame
].
get
(
state
)
if
state
in
aggregates
.
view
keys
():
if
state
in
aggregates
.
keys
():
# State aggregation:
# - find which substate manages this input
# - add a swich case on the corresponding substate
taste_template
.
append
(
u
'-- this is a state aggregation'
)
for
sub
in
aggregates
[
state
]:
if
[
a
for
a
in
sub
.
mapping
.
view
keys
()
if
a
in
mapping
[
signame
].
view
keys
()]:
if
[
a
for
a
in
sub
.
mapping
.
keys
()
if
a
in
mapping
[
signame
].
keys
()]:
taste_template
.
append
(
u
'case '
u
'{ctxt}.{sub}{sep}state is'
.
format
(
ctxt
=
LPREFIX
,
sub
=
sub
.
statename
,
sep
=
UNICODE_SEP
))
for
par
in
sub
.
mapping
.
view
keys
():
for
par
in
sub
.
mapping
.
keys
():
case_state
(
par
)
taste_template
.
append
(
'when others =>'
)
taste_template
.
append
(
'null;'
)
...
...
@@ -1092,11 +1086,11 @@ package {process_name} is'''.format(generic=generic_spec,
last
=
''
# flag indicating there are CS in nested states but not at root
need_final_endif
=
False
for
cs
,
agg
in
product
(
process
.
cs_mapping
.
view
items
(),
aggregates
.
view
items
()):
for
cs
,
agg
in
product
(
process
.
cs_mapping
.
items
(),
aggregates
.
items
()):
(
statename
,
cs_item
),
(
agg_name
,
substates
)
=
cs
,
agg
for
each
in
substates
:
if
statename
in
each
.
mapping
.
view
keys
():
if
statename
in
each
.
mapping
.
keys
():
need_final_endif
=
True
taste_template
.
append
(
u
'{first}if not msgPending and '
u
'trId = -1 and '
...
...
@@ -1125,7 +1119,7 @@ package {process_name} is'''.format(generic=generic_spec,
taste_template
.
append
(
u
'end if;'
)
# inner if
sep
=
'if '
break
for
statename
in
process
.
cs_mapping
.
view
keys
()
-
done
:
for
statename
in
process
.
cs_mapping
.
keys
()
-
done
:
need_final_endif
=
False
cs_item
=
process
.
cs_mapping
[
statename
]
taste_template
.
append
(
u
'{first}if not msgPending and '
...
...
@@ -1700,7 +1694,7 @@ def _prim_call(prim, **kwargs):
# signed element (with the risk of cutting very big values)
has_unsigned
=
False
has_signed
=
False
for
each
in
sort
.
Children
.
view
values
():
for
each
in
sort
.
Children
.
values
():
child_sort
=
find_basic_type
(
each
.
type
)
if
child_sort
.
kind
.
startswith
(
'Integer'
):
if
float
(
child_sort
.
Min
)
<
0.0
:
...
...
@@ -1708,7 +1702,7 @@ def _prim_call(prim, **kwargs):
else
:
has_unsigned
=
True
need_cast
=
has_signed
and
has_unsigned
for
child_name
,
descr
in
sort
.
Children
.
view
items
():
for
child_name
,
descr
in
sort
.
Children
.
items
():
child_name_ada
=
child_name
.
replace
(
'-'
,
'_'
)
child_id
=
descr
.
EnumID
child_sort
=
find_basic_type
(
descr
.
type
)
...
...
@@ -2562,11 +2556,11 @@ def _sequence(seq, **kwargs):
type_children
=
find_basic_type
(
seq
.
exprType
).
Children
optional_fields
=
{
field
.
lower
().
replace
(
'-'
,
'_'
):
{
'present'
:
False
,
'ref'
:
(
field
,
val
)}
for
field
,
val
in
type_children
.
view
items
()
for
field
,
val
in
type_children
.
items
()
if
val
.
Optional
==
'True'
}
present_fields
=
[]
absent_fields
=
[]
for
elem
,
value
in
seq
.
value
.
view
items
():
for
elem
,
value
in
seq
.
value
.
items
():
# Set the type of the field - easy thanks to ASN.1 flattened AST
delem
=
elem
.
replace
(
'_'
,
'-'
)
for
each
in
type_children
:
...
...
@@ -2588,7 +2582,7 @@ def _sequence(seq, **kwargs):
# Process optional fields
if
optional_fields
:
absent_fields
=
((
fd_name
,
fd_data
[
'ref'
])
for
fd_name
,
fd_data
in
optional_fields
.
view
items
()
for
fd_name
,
fd_data
in
optional_fields
.
items
()
if
not
fd_data
[
'present'
])
for
fd_name
,
fd_data
in
absent_fields
:
fd_type
=
fd_data
[
1
].
type
...
...
@@ -2602,7 +2596,7 @@ def _sequence(seq, **kwargs):
sep
=
u
', '
ada_string
+=
u
', Exist => ('
sep
=
''
for
fd_name
,
fd_data
in
optional_fields
.
view
items
():
for
fd_name
,
fd_data
in
optional_fields
.
items
():
ada_string
+=
u
'{}{} => {}'
.
format
(
sep
,
fd_name
,
'1'
if
fd_data
[
'present'
]
else
'0'
)
sep
=
u
', '
...
...
@@ -2864,10 +2858,10 @@ def _transition(tr, **kwargs):
# "nextstate -": switch case to re-run the entry transition
# in case of a composite state or state aggregation
if
any
(
next_id
for
next_id
in
tr
.
terminator
.
candidate_id
.
view
keys
()
for
next_id
in
tr
.
terminator
.
candidate_id
.
keys
()
if
next_id
!=
-
1
):
code
.
append
(
'case {}.state is'
.
format
(
LPREFIX
))
for
nid
,
sta
in
tr
.
terminator
.
candidate_id
.
view
items
():
for
nid
,
sta
in
tr
.
terminator
.
candidate_id
.
items
():
if
nid
!=
-
1
:
if
tr
.
terminator
.
next_is_aggregation
:
statement
=
u
'{};'
.
format
(
nid
)
...
...
@@ -3021,7 +3015,7 @@ def _inner_procedure(proc, **kwargs):
local_decl
.
extend
(
inner_local
)
code
.
extend
(
inner_code
)
code
.
append
(
pi_header
+
u
' is'
)
for
var_name
,
(
var_type
,
def_value
)
in
proc
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
def_value
)
in
proc
.
variables
.
items
():
typename
=
type_name
(
var_type
)
if
def_value
:
# Expression must be a ground expression, i.e. must not
...
...
@@ -3146,7 +3140,7 @@ def find_basic_type(a_type):
basic_type
=
a_type
while
basic_type
.
kind
==
'ReferenceType'
:
# Find type with proper case in the data view
for
typename
in
TYPES
.
view
keys
():
for
typename
in
TYPES
.
keys
():
if
typename
.
lower
()
==
basic_type
.
ReferencedTypeName
.
lower
():
basic_type
=
TYPES
[
typename
].
type
break
...
...
@@ -3191,7 +3185,7 @@ def child_spelling(name, bty):
def
find_var
(
var
):
''' Return a variable from the scope, with proper case '''
for
visible_var
in
VARIABLES
.
view
keys
():
for
visible_var
in
VARIABLES
.
keys
():
if
var
.
lower
()
==
visible_var
.
lower
():
return
visible_var
return
None
...
...
@@ -3200,7 +3194,7 @@ def find_var(var):
def
is_local
(
var
):
''' Check if a variable is in the global context or in a local scope
Typically needed to select the right prefix to use '''
return
var
.
lower
()
in
(
loc
.
lower
()
for
loc
in
LOCAL_VAR
.
view
keys
())
return
var
.
lower
()
in
(
loc
.
lower
()
for
loc
in
LOCAL_VAR
.
keys
())
def
path_type
(
path
):
...
...
opengeode/Asn1scc.py
View file @
65365327
...
...
@@ -23,9 +23,9 @@ import importlib
import
logging
import
traceback
import
hashlib
from
PySide.QtCore
import
QProcess
,
QFile
from
PySide
2
.QtCore
import
QProcess
,
QFile
import
icons
from
.
import
icons
LOG
=
logging
.
getLogger
(
__name__
)
terminal_formatter
=
logging
.
Formatter
(
fmt
=
"[%(levelname)s] %(message)s"
)
...
...
opengeode/CGenerator.py
View file @
65365327
#!/usr/bin/env python
#!/usr/bin/env python
3
# -*- coding: utf-8 -*-
"""
...
...
@@ -15,15 +15,9 @@
import
logging
import
os
try
:
# python2
from
singledispatch
import
singledispatch
except
ModuleNotFoundError
:
# python3
from
functools
import
singledispatch
from
functools
import
singledispatch
import
Helper
import
ogAST
from
.
import
Helper
,
ogAST
LOG
=
logging
.
getLogger
(
__name__
)
...
...
@@ -371,7 +365,7 @@ def _inner_procedure(proc, **kwargs):
code
.
extend
(
inner_code
)
code
.
append
(
pi_header
)
code
.
append
(
u
'{'
)
for
var_name
,
(
var_type
,
def_value
)
in
proc
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
def_value
)
in
proc
.
variables
.
items
():
typename
=
type_name
(
var_type
)
if
def_value
:
# Expression must be a ground expression, i.e. must not
...
...
@@ -541,7 +535,7 @@ LD_LIBRARY_PATH=. taste-gui -l
if
state_list
:
context_type
.
append
(
u
'states_t state;'
)
for
var_name
,
(
var_type
,
init
)
in
process
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
init
)
in
process
.
variables
.
items
():
init_stmt
=
[]
init_string
=
''
init_decl
=
[]
...
...
@@ -570,7 +564,7 @@ LD_LIBRARY_PATH=. taste-gui -l
global_decls
.
append
(
u
'context_t {ct};'
.
format
(
ct
=
LPREFIX
))
global_decls
.
extend
(
context_init_code
)
for
name
,
val
in
process
.
mapping
.
view
items
():
for
name
,
val
in
process
.
mapping
.
items
():
if
name
.
endswith
(
u
'START'
)
and
name
!=
u
'START'
:
global_decls
.
append
(
u
'#define {name} {val}'
.
format
(
name
=
name
,
val
=
str
(
val
)))
...
...
@@ -606,7 +600,7 @@ LD_LIBRARY_PATH=. taste-gui -l
dll_code
.
append
(
u
''
)
# Functions to get gobal variables (length and value)
for
var_name
,
(
var_type
,
_
)
in
process
.
variables
.
view
items
():
for
var_name
,
(
var_type
,
_
)
in
process
.
variables
.
items
():
# Getters for local variables
global_decls
.
append
(
u
'int {name}_size()'
.
format
(
name
=
var_name
))
global_decls
.
append
(
u
'{'
)
...
...
@@ -658,7 +652,7 @@ LD_LIBRARY_PATH=. taste-gui -l
input_signals_code
.
append
(
u
'{'
)
input_signals_code
.
append
(
u
'switch({ct}.state)'
.
format
(
ct
=
LPREFIX
))
input_signals_code
.
append
(
u
'{'
)
for
state
in
process
.
mapping
.
view
keys
():
for
state
in
process
.
mapping
.
keys
():
if
state
.
endswith
(
u
'START'
):
continue
input_signals_code
.
append
(
u
'case {st}:'
.
format
(
st
=
state
))
...
...
@@ -988,10 +982,10 @@ def _transition(tr, **kwargs):
if
tr
.
terminator
.
next_id
==
-
1
:
stmts
.
append
(
u
'{ctxt}.state = {nextState};'
.
format
(
ctxt
=
LPREFIX
,
nextState
=
tr
.
terminator
.
inputString
.
lower
()))
else
:
if
any
(
next_id
for
next_id
in
tr
.
terminator
.
candidate_id
.
view
keys
()
if
next_id
!=
-
1
):
if
any
(
next_id
for
next_id
in
tr
.
terminator
.
candidate_id
.
keys
()
if
next_id
!=
-
1
):
stmts
.
append
(
'switch ({}.state)'
.
format
(
LPREFIX
))
stmts
.
append
(
'{'
)
for
nid
,
sta
in
tr
.
terminator
.
candidate_id
.
view
items
():
for
nid
,
sta
in
tr
.
terminator
.
candidate_id
.
items
():
if
nid
!=
-
1
:
for
each
in
sta
:
stmts
.
append
(
u
'case {} :'
.
format
(
each
))
...
...
@@ -1932,10 +1926,10 @@ def _sequence(seq):
string
=
u
"({}) {{"
.
format
(
type_name
(
seq
.
exprType
))
sep
=
''
type_children
=
find_basic_type
(
seq
.
exprType
).
Children
optional_fields
=
{
field
.
lower
().
replace
(
'-'
,
'_'
):
{
'present'
:
False
,
'ref'
:
(
field
,
val
)}
for
field
,
val
in
type_children
.
view
items
()
if
val
.
Optional
==
'True'
}
optional_fields
=
{
field
.
lower
().
replace
(
'-'
,
'_'
):
{
'present'
:
False
,
'ref'
:
(
field
,
val
)}
for
field
,
val
in
type_children
.
items
()
if
val
.
Optional
==
'True'
}
present_fields
=
[]
absent_fields
=
[]
for
elem
,
value
in
seq
.
value
.
view
items
():
for
elem
,
value
in
seq
.
value
.
items
():
# Set the type of the field - easy thanks to ASN.1 flattened AST
delem
=
elem
.
replace
(
'_'
,
'-'
)
for
each
in
type_children
:
...
...
@@ -1957,7 +1951,7 @@ def _sequence(seq):
local_decl
.
extend
(
local_var
)
# Process optional fields
if
optional_fields
:
absent_fields
=
((
fd_name
,
fd_data
[
'ref'
])
for
fd_name
,
fd_data
in
optional_fields
.
view
items
()
if
not
fd_data
[
'present'
])
absent_fields
=
((
fd_name
,
fd_data
[
'ref'
])
for
fd_name
,
fd_data
in
optional_fields
.
items
()
if
not
fd_data
[
'present'
])
for
fd_name
,
fd_data
in
absent_fields
:
fd_type
=
fd_data
[
1
].
type
if
fd_type
.
kind
==
'ReferenceType'
:
...
...
@@ -1970,7 +1964,7 @@ def _sequence(seq):
sep
=
u
', '
string
+=
u
', .exist = {'
sep
=
''
for
fd_name
,
fd_data
in
optional_fields
.
view
items
():
for
fd_name
,
fd_data
in
optional_fields
.
items
():
string
+=
u
'{} {}'
.
format
(
sep
,
'1'
if
fd_data
[
'present'
]
else
'0'
)
sep
=
u
', '
string
+=
u
'}'
...
...
@@ -2107,7 +2101,7 @@ def find_basic_type(a_type):
basic_type
=
a_type
while
basic_type
.
kind
==
'ReferenceType'
:
# Find type with proper case in the data view
for
typename
in
TYPES
.
view
keys
():
for
typename
in
TYPES
.
keys
():
if
typename
.
lower
()
==
basic_type
.
ReferencedTypeName
.
lower
():
basic_type
=
TYPES
[
typename
].
type
break
...
...
@@ -2115,7 +2109,7 @@ def find_basic_type(a_type):
def
find_var
(
var
):
''' Return a variable from the scope, with proper case '''
for
visible_var
in
VARIABLES
.
view
keys
():
for
visible_var
in
VARIABLES
.
keys
():
if
var
.
lower
()
==
visible_var
.
lower
():
return
visible_var
return
None
...
...
@@ -2137,7 +2131,7 @@ def indent_c_code(lines):
def
is_local
(
var
):
''' Check if a variable is in the global context or in a local scope
Typically needed to select the right prefix to use '''
return
var
in
LOCAL_VAR
.
view
keys
()
return
var
in
LOCAL_VAR
.
keys
()
def
string_payload
(
prim
,
string
):
...
...
opengeode/Clipboard.py
View file @
65365327
#!/usr/bin/env python
#!/usr/bin/env python
3
# -*- coding: utf-8 -*-
"""
...
...
@@ -19,14 +19,11 @@ import os
import
traceback
import
logging
from
itertools
import
chain
import
PySide
from
PySide2.QtCore
import
*
from
PySide2.QtGui
import
*
from
PySide2.QtWidgets
import
*
import
ogAST
import
ogParser
import
sdlSymbols
import
genericSymbols
import
Renderer
import
Pr
from
.
import
ogAST
,
ogParser
,
sdlSymbols
,
genericSymbols
,
Renderer
,
Pr
__all__
=
[
'copy'
,
'paste'
]
...
...
@@ -98,7 +95,7 @@ def copy_branch(top_level_item):
res_terminators
=
terminators
for
term
in
terminators
:
# Get symbol at terminator coordinates
symbols
=
top_level_item
.
scene
().
items
(
PySide
.
QtCore
.
QRectF
symbols
=
top_level_item
.
scene
().
items
(
QRectF
(
term
.
pos_x
,
term
.
pos_y
,
term
.
width
,
term
.
height
).
center
())
for
symbol
in
symbols
:
if
(
isinstance
(
symbol
,
sdlSymbols
.
State
)
and
[
c
for
c
in
...
...
opengeode/Connectors.py
View file @
65365327
...
...
@@ -18,20 +18,17 @@
import
math
import
logging
from
PySide.QtCore
import
Qt
,
QPointF
,
QLineF
,
Slot
from
PySide.QtGui
import
(
QGraphicsPathItem
,
QPainterPath
,
QGraphicsItem
,
QPen
,
QPainter
,
QFont
,
QGraphicsTextItem
,
QColor
,
QFontMetrics
,
QTextBlockFormat
,
QTextCursor
)
import
ogParser
from
TextInteraction
import
EditableText
from
PySide2.QtCore
import
*
from
PySide2.QtGui
import
*
from
PySide2.QtWidgets
import
*
from
.
import
ogParser
from
.TextInteraction
import
EditableText
LOG
=
logging
.
getLogger
(
__name__
)
# pylint: disable=R0904
class
Connection
(
QGraphicsPathItem
,
object
):
class
Connection
(
QGraphicsPathItem
):
''' Connection between two symbols (top-level class) '''
# Default connections are not selectable
default_cursor
=
Qt
.
ArrowCursor
...
...
@@ -471,7 +468,7 @@ class Channel(Signalroute):
class
Controlpoint
(
QGraphicsPathItem
,
object
):
class
Controlpoint
(
QGraphicsPathItem
):
''' Class handling one edge control point (to change bezier curves) '''
user_can_connect
=
False
# not used but will avoid exceptions
def
__init__
(
self
,
pos
,
edge
):
...
...
opengeode/Helper.py
View file @
65365327
#!/usr/bin/env python
#!/usr/bin/env python
3
# -*- coding: utf-8 -*-
"""
...
...
@@ -31,14 +31,9 @@ import logging
from
itertools
import
chain
from
collections
import
defaultdict
try
:
# python2
from
singledispatch
import
singledispatch
except
ModuleNotFoundError
:
# python3
from
functools
import
singledispatch
from
functools
import
singledispatch
import
ogAST
from
.
import
ogAST
LOG
=
logging
.
getLogger
(
__name__
)
...
...
@@ -51,7 +46,7 @@ def statenames(context, sep=u'\u00dc'):
''' Return the list of states (just the names) of a given context
Format the output by replacing unicode separator symbol with a dot '''
# note: if model has been flattened, all contexts are already merged
return
(
s
.
replace
(
sep
,
u
'.'
)
for
s
in
context
.
mapping
.
view
keys
()
return
(
s
.
replace
(
sep
,
u
'.'
)
for
s
in
context
.
mapping
.
keys
()
if
not
s
.
endswith
(
u
'START'
))
...
...
@@ -103,7 +98,7 @@ def state_aggregations(process):
for
each
in
process
.
terminators
:
if
each
.
inputString
.
lower
()
in
aggregates
:
each
.
next_is_aggregation
=
True
for
name
,
comp
in
aggregates
.
view
items
():
for
name
,
comp
in
aggregates
.
items
():
# for each state aggregation. update the terminators
# of each parallel state with the name of all sibling states
# useful for backends to handle parallel state termination (return)
...
...
@@ -118,9 +113,9 @@ def parallel_states(aggregates):
''' Given a mapping obtained with state_aggregation(process), extract
all parallel states and return a list of state names '''
parallel_states
=
[]
for
name
,
comp
in
aggregates
.
view
items
():
for
name
,
comp
in
aggregates
.
items
():
for
each
in
comp
:
parallel_states
.
extend
(
name
for
name
in
each
.
mapping
.
view
keys
()
parallel_states
.
extend
(
name
for
name
in
each
.
mapping
.
keys
()
if
not
name
.
endswith
(
u
'START'
))
return
parallel_states
...
...
@@ -132,7 +127,7 @@ def map_input_state(process):
# Add timers to the mapping
input_signals
.
extend
(
process
.
timers
)
for
input_signal
in
input_signals
:
for
state_name
,
input_symbols
in
process
.
mapping
.
view
items
():
for
state_name
,
input_symbols
in
process
.
mapping
.
items
():
if
isinstance
(
input_symbols
,
list
):
# Start symbols have no list of inputs
for
i
in
input_symbols
:
...
...
@@ -187,7 +182,7 @@ def flatten(process, sep=u'_'):
term
.
candidate_id
[
each
+
sep
+
u
'START'
]
=
[
each
]
else
:
term
.
candidate_id
[
each
+
sep
+
u
'START'
]
=
\
[
st
for
st
in
process
.
mapping
.
view
keys
()
[
st
for
st
in
process
.
mapping
.
keys
()
if
st
.
startswith
(
each
)
and
not
st
.
endswith
(
u
'START'
)]
continue
...
...
@@ -209,7 +204,7 @@ def flatten(process, sep=u'_'):
process
.
transitions
.
extend
(
state
.
transitions
)
# Add prefix to local variable names and push them at process level
for
dcl
in
state
.
variables
.
view
keys
():
for
dcl
in
state
.
variables
.
keys
():
rename_everything
(
state
.
content
,
dcl
,
prefix
+
dcl
)
state
.
variables
=
{
prefix
+
key
:
state
.
variables
.
pop
(
key
)
for
key
in
state
.
variables
.
keys
()}
...
...
@@ -224,7 +219,7 @@ def flatten(process, sep=u'_'):
break
values
=
[]
for
key
,
value
in
state
.
mapping
.
view
items
():
for
key
,
value
in
state
.
mapping
.
items
():
# Update transition indices
if
isinstance
(
value
,
int
):
# START transitions
...
...
@@ -232,7 +227,7 @@ def flatten(process, sep=u'_'):
else
:
values
.
extend
(
value
)
for
each
in
state
.
cs_mapping
.
view
values
():
for
each
in
state
.
cs_mapping
.
values
():
# Update transition indices of continuous signals
# XXX shouldn't we do it also for CONNECT parts?
values
.
extend
(
each
)
...
...
@@ -248,7 +243,7 @@ def flatten(process, sep=u'_'):
# If composite state has entry procedures, add the call
if
state
.
entry_procedure
:
for
each
in
(
trans
for
trans
in
state
.
mapping
.
view
values
()
for
each
in
(
trans
for
trans
in
state
.
mapping
.
values
()
if
isinstance
(
trans
,
int
)):
call_entry
=
ogAST
.
ProcedureCall
()
call_entry
.
inputString
=
'entry'
...
...
@@ -310,7 +305,7 @@ def flatten(process, sep=u'_'):
processed by each of the substates.
'''
if
not
isinstance
(
nested_state
,
ogAST
.
StateAggregation
):
for
_
,
val
in
nested_state
.
mapping
.
view
items
():
for
_
,
val
in
nested_state
.
mapping
.
items
():
try
:
inputlist
=
context
.
mapping
[
nested_state
.
statename
]
val
.
extend
(
inputlist
)
...
...
@@ -397,7 +392,7 @@ def _rename_automaton(ast, from_name, to_name):
rename_everything
(
each
.
composite
.
content
,
from_name
,
to_name
)
for
each
in
ast
.
inner_procedures
:
# Check that from_name is not a redefined variable in the procedure
for
varname
in
each
.
variables
.
view
keys
():