2 # Copyright 2017 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
21 logging
.basicConfig(level
=logging
.DEBUG
)
22 log
= logging
.getLogger('RdclGraph')
25 class RdclGraph(object):
26 """ Operates on the graph representation used for the GUI graph views """
41 def add_link(self
, source
, target
, view
, group
, graph_object
, optional
={}):
42 if (source
is None) or (target
is None):
52 edge_obj
.update(optional
)
53 if edge_obj
not in graph_object
['edges']:
54 graph_object
['edges'].append(edge_obj
)
56 def add_node(self
, id, type, group
, positions
, graph_object
, optional
={}):
59 node
= next((x
for x
in graph_object
['vertices'] if x
['id'] == id), None)
61 node
['info']['group'].append(group
)
63 node
= copy
.deepcopy(self
.node_t3d_base
)
65 node
['info']['type'] = type
67 node
['info']['group'].append(group
)
68 if positions
and id in positions
['vertices'] and 'x' in positions
['vertices'][id] and 'y' in positions
['vertices'][id]:
69 node
['fx'] = positions
['vertices'][id]['x']
70 node
['fy'] = positions
['vertices'][id]['y']
71 node
['info'].update(optional
)
72 graph_object
['vertices'].append(node
)
74 def is_directed_edge(self
, source_type
=None, target_type
=None, layer
=None, model
={}):
75 if source_type
is None or target_type
is None or layer
is None:
77 if layer
in model
['layer'] and 'allowed_edges' in model
['layer'][layer
]:
78 if source_type
in model
['layer'][layer
]['allowed_edges'] and target_type
in model
['layer'][layer
]['allowed_edges'][source_type
]['destination']:
79 edge_pro
= model
['layer'][layer
]['allowed_edges'][source_type
]['destination'][target_type
]
80 return edge_pro
['direct_edge'] if 'direct_edge' in edge_pro
else False