copy node and links
This commit is contained in:
parent
395f8134dc
commit
c1755afb2f
4 changed files with 69 additions and 6 deletions
|
@ -760,9 +760,10 @@ class CoreClient:
|
||||||
if edge in edges:
|
if edge in edges:
|
||||||
continue
|
continue
|
||||||
edges.add(edge)
|
edges.add(edge)
|
||||||
if edge.token not in self.links:
|
#
|
||||||
logging.error("unknown edge: %s", edge.token)
|
# if edge.token not in self.links:
|
||||||
del self.links[edge.token]
|
# logging.error("unknown edge: %s", edge.token)
|
||||||
|
self.links.pop(edge.token, None)
|
||||||
|
|
||||||
def create_interface(self, canvas_node):
|
def create_interface(self, canvas_node):
|
||||||
node = canvas_node.core_node
|
node = canvas_node.core_node
|
||||||
|
|
|
@ -46,6 +46,7 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.offset = (0, 0)
|
self.offset = (0, 0)
|
||||||
self.cursor = (0, 0)
|
self.cursor = (0, 0)
|
||||||
self.marker_tool = None
|
self.marker_tool = None
|
||||||
|
self.to_copy = []
|
||||||
|
|
||||||
# background related
|
# background related
|
||||||
self.wallpaper_id = None
|
self.wallpaper_id = None
|
||||||
|
@ -441,7 +442,8 @@ class CanvasGraph(tk.Canvas):
|
||||||
continue
|
continue
|
||||||
edges.add(edge)
|
edges.add(edge)
|
||||||
self.throughput_draw.delete(edge)
|
self.throughput_draw.delete(edge)
|
||||||
del self.edges[edge.token]
|
self.edges.pop(edge.token, None)
|
||||||
|
# del self.edges[edge.token]
|
||||||
edge.delete()
|
edge.delete()
|
||||||
|
|
||||||
# update node connected to edge being deleted
|
# update node connected to edge being deleted
|
||||||
|
@ -838,3 +840,47 @@ class CanvasGraph(tk.Canvas):
|
||||||
self.nodes[source.id].edges.add(edge)
|
self.nodes[source.id].edges.add(edge)
|
||||||
self.nodes[dest.id].edges.add(edge)
|
self.nodes[dest.id].edges.add(edge)
|
||||||
self.core.create_link(edge, source, dest)
|
self.core.create_link(edge, source, dest)
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
if self.selection:
|
||||||
|
logging.debug(
|
||||||
|
"store current selection to to_copy, number of nodes: %s",
|
||||||
|
len(self.selection),
|
||||||
|
)
|
||||||
|
self.to_copy = self.selection.keys()
|
||||||
|
|
||||||
|
def paste(self):
|
||||||
|
logging.debug("copy")
|
||||||
|
# maps original node canvas id to copy node canvas id
|
||||||
|
copy_map = {}
|
||||||
|
# the edges that will be copy over
|
||||||
|
to_copy_edges = []
|
||||||
|
for canvas_nid in self.to_copy:
|
||||||
|
core_node = self.nodes[canvas_nid].core_node
|
||||||
|
actual_x = core_node.position.x + 50
|
||||||
|
actual_y = core_node.position.y + 50
|
||||||
|
scaled_x, scaled_y = self.get_scaled_coords(actual_x, actual_y)
|
||||||
|
|
||||||
|
copy = self.core.create_node(
|
||||||
|
actual_x, actual_y, core_node.type, core_node.model
|
||||||
|
)
|
||||||
|
node = CanvasNode(
|
||||||
|
self.master, scaled_x, scaled_y, copy, self.nodes[canvas_nid].image
|
||||||
|
)
|
||||||
|
copy_map[canvas_nid] = node.id
|
||||||
|
self.core.canvas_nodes[copy.id] = node
|
||||||
|
self.nodes[node.id] = node
|
||||||
|
|
||||||
|
edges = self.nodes[canvas_nid].edges
|
||||||
|
for edge in edges:
|
||||||
|
if edge.src not in self.to_copy or edge.dst not in self.to_copy:
|
||||||
|
if canvas_nid == edge.src:
|
||||||
|
self.create_edge(node, self.nodes[edge.dst])
|
||||||
|
elif canvas_nid == edge.dst:
|
||||||
|
self.create_edge(self.nodes[edge.src], node)
|
||||||
|
else:
|
||||||
|
to_copy_edges.append(tuple([edge.src, edge.dst]))
|
||||||
|
for e in to_copy_edges:
|
||||||
|
source_node_copy = self.nodes[copy_map[e[0]]]
|
||||||
|
dest_node_copy = self.nodes[copy_map[e[1]]]
|
||||||
|
self.create_edge(source_node_copy, dest_node_copy)
|
||||||
|
|
|
@ -30,6 +30,7 @@ class MenuAction:
|
||||||
def __init__(self, app, master):
|
def __init__(self, app, master):
|
||||||
self.master = master
|
self.master = master
|
||||||
self.app = app
|
self.app = app
|
||||||
|
self.canvas = app.canvas
|
||||||
|
|
||||||
def cleanup_old_session(self, quitapp=False):
|
def cleanup_old_session(self, quitapp=False):
|
||||||
logging.info("cleaning up old session")
|
logging.info("cleaning up old session")
|
||||||
|
@ -155,3 +156,11 @@ class MenuAction:
|
||||||
self.app.core.enable_throughputs()
|
self.app.core.enable_throughputs()
|
||||||
else:
|
else:
|
||||||
self.app.core.cancel_throughputs()
|
self.app.core.cancel_throughputs()
|
||||||
|
|
||||||
|
def copy(self, event=None):
|
||||||
|
logging.debug("copy")
|
||||||
|
self.app.canvas.copy()
|
||||||
|
|
||||||
|
def paste(self, event=None):
|
||||||
|
logging.debug("paste")
|
||||||
|
self.app.canvas.paste()
|
||||||
|
|
|
@ -90,8 +90,12 @@ class Menubar(tk.Menu):
|
||||||
menu.add_command(label="Redo", accelerator="Ctrl+Y", state=tk.DISABLED)
|
menu.add_command(label="Redo", accelerator="Ctrl+Y", state=tk.DISABLED)
|
||||||
menu.add_separator()
|
menu.add_separator()
|
||||||
menu.add_command(label="Cut", accelerator="Ctrl+X", state=tk.DISABLED)
|
menu.add_command(label="Cut", accelerator="Ctrl+X", state=tk.DISABLED)
|
||||||
menu.add_command(label="Copy", accelerator="Ctrl+C", state=tk.DISABLED)
|
menu.add_command(
|
||||||
menu.add_command(label="Paste", accelerator="Ctrl+V", state=tk.DISABLED)
|
label="Copy", accelerator="Ctrl+C", command=self.menuaction.copy
|
||||||
|
)
|
||||||
|
menu.add_command(
|
||||||
|
label="Paste", accelerator="Ctrl+V", command=self.menuaction.paste
|
||||||
|
)
|
||||||
menu.add_separator()
|
menu.add_separator()
|
||||||
menu.add_command(label="Select all", accelerator="Ctrl+A", state=tk.DISABLED)
|
menu.add_command(label="Select all", accelerator="Ctrl+A", state=tk.DISABLED)
|
||||||
menu.add_command(
|
menu.add_command(
|
||||||
|
@ -102,6 +106,9 @@ class Menubar(tk.Menu):
|
||||||
menu.add_command(label="Clear marker", state=tk.DISABLED)
|
menu.add_command(label="Clear marker", state=tk.DISABLED)
|
||||||
self.add_cascade(label="Edit", menu=menu)
|
self.add_cascade(label="Edit", menu=menu)
|
||||||
|
|
||||||
|
self.app.master.bind_all("<Control-c>", self.menuaction.copy)
|
||||||
|
self.app.master.bind_all("<Control-v>", self.menuaction.paste)
|
||||||
|
|
||||||
def draw_canvas_menu(self):
|
def draw_canvas_menu(self):
|
||||||
"""
|
"""
|
||||||
Create canvas menu
|
Create canvas menu
|
||||||
|
|
Loading…
Reference in a new issue