working on shape
This commit is contained in:
parent
1a05571e50
commit
5c04225cc4
3 changed files with 80 additions and 22 deletions
|
@ -13,7 +13,7 @@ from coretk.dialogs.mobilityconfig import MobilityConfigDialog
|
|||
from coretk.dialogs.nodeconfig import NodeConfigDialog
|
||||
from coretk.dialogs.wlanconfig import WlanConfigDialog
|
||||
from coretk.graph_helper import GraphHelper, WlanAntennaManager
|
||||
from coretk.images import Images
|
||||
from coretk.images import ImageEnum, Images
|
||||
from coretk.linkinfo import LinkInfo, Throughput
|
||||
from coretk.nodedelete import CanvasComponentManagement
|
||||
from coretk.nodeutils import NodeUtils
|
||||
|
@ -53,11 +53,13 @@ class CanvasGraph(tk.Canvas):
|
|||
super().__init__(master, cnf, **kwargs)
|
||||
self.app = master
|
||||
self.mode = GraphMode.SELECT
|
||||
self.annotation_type = None
|
||||
self.selected = None
|
||||
self.node_draw = None
|
||||
self.context = None
|
||||
self.nodes = {}
|
||||
self.edges = {}
|
||||
self.shapes = {}
|
||||
self.drawing_edge = None
|
||||
self.grid = None
|
||||
self.canvas_management = CanvasComponentManagement(self, core)
|
||||
|
@ -271,10 +273,17 @@ class CanvasGraph(tk.Canvas):
|
|||
if self.context:
|
||||
self.context.unpost()
|
||||
self.context = None
|
||||
else:
|
||||
if self.mode == GraphMode.ANNOTATION:
|
||||
if self.annotation_type in [ImageEnum.OVAL, ImageEnum.RECTANGLE]:
|
||||
x, y = self.canvas_xy(event)
|
||||
self.shapes[self.selected].shape_complete(x, y)
|
||||
else:
|
||||
self.focus_set()
|
||||
self.selected = self.get_selected(event)
|
||||
logging.debug(f"click release selected({self.selected}) mode({self.mode})")
|
||||
logging.debug(
|
||||
f"click release selected({self.selected}) mode({self.mode})"
|
||||
)
|
||||
if self.mode == GraphMode.EDGE:
|
||||
self.handle_edge_release(event)
|
||||
elif self.mode == GraphMode.NODE:
|
||||
|
@ -333,8 +342,11 @@ class CanvasGraph(tk.Canvas):
|
|||
x, y = self.coords(selected)
|
||||
self.drawing_edge = CanvasEdge(x, y, x, y, selected, self)
|
||||
if self.mode == GraphMode.ANNOTATION:
|
||||
shape = Shape(self.app, self, event.x, event.y)
|
||||
print(shape)
|
||||
if self.annotation_type in [ImageEnum.OVAL, ImageEnum.RECTANGLE]:
|
||||
x, y = self.canvas_xy(event)
|
||||
shape = Shape(self.app, self, x, y)
|
||||
self.selected = shape.id
|
||||
self.shapes[shape.id] = shape
|
||||
|
||||
def click_motion(self, event):
|
||||
"""
|
||||
|
@ -347,6 +359,10 @@ class CanvasGraph(tk.Canvas):
|
|||
x2, y2 = self.canvas_xy(event)
|
||||
x1, y1, _, _ = self.coords(self.drawing_edge.id)
|
||||
self.coords(self.drawing_edge.id, x1, y1, x2, y2)
|
||||
if self.mode == GraphMode.ANNOTATION:
|
||||
if self.annotation_type in [ImageEnum.OVAL, ImageEnum.RECTANGLE]:
|
||||
x, y = self.canvas_xy(event)
|
||||
self.shapes[self.selected].shape_motion(x, y)
|
||||
|
||||
def click_context(self, event):
|
||||
logging.info("context event: %s", self.context)
|
||||
|
|
|
@ -1,16 +1,57 @@
|
|||
"""
|
||||
class for shapes
|
||||
"""
|
||||
# from coretk.images import ImageEnum, Images
|
||||
import logging
|
||||
|
||||
from coretk.images import ImageEnum
|
||||
|
||||
ABOVE_COMPONENT = ["gridline", "edge", "linkinfo", "antenna", "node", "nodename"]
|
||||
|
||||
|
||||
class Shape:
|
||||
def __init__(self, app, canvas, topleft_x, topleft_y):
|
||||
def __init__(self, app, canvas, top_x, top_y):
|
||||
self.app = app
|
||||
self.canvas = canvas
|
||||
self.x0 = topleft_x
|
||||
self.y0 = topleft_y
|
||||
# imageenum = self.app.toolbar
|
||||
self.id = self.canvas.create_oval(
|
||||
topleft_x, topleft_y, topleft_x + 30, topleft_y + 30
|
||||
self.x0 = top_x
|
||||
self.y0 = top_y
|
||||
self.cursor_x = None
|
||||
self.cursor_y = None
|
||||
annotation_type = self.canvas.annotation_type
|
||||
if annotation_type == ImageEnum.OVAL:
|
||||
self.id = canvas.create_oval(
|
||||
top_x, top_y, top_x, top_y, tags="shape", dash="-"
|
||||
)
|
||||
elif annotation_type == ImageEnum.RECTANGLE:
|
||||
self.id = canvas.create_rectangle(
|
||||
top_x, top_y, top_x, top_y, tags="shape", dash="-"
|
||||
)
|
||||
self.canvas.tag_bind(self.id, "<ButtonPress-1>", self.click_press)
|
||||
self.canvas.tag_bind(self.id, "<ButtonRelease-1>", self.click_release)
|
||||
self.canvas.tag_bind(self.id, "<B1-Motion>", self.motion)
|
||||
|
||||
def shape_motion(self, x1, y1):
|
||||
self.canvas.coords(self.id, self.x0, self.y0, x1, y1)
|
||||
|
||||
def shape_complete(self, x, y):
|
||||
self.canvas.itemconfig(self.id, width=0, fill="#ccccff")
|
||||
for component in ABOVE_COMPONENT:
|
||||
self.canvas.tag_raise(component)
|
||||
|
||||
def click_press(self, event):
|
||||
logging.debug("Click on shape %s", self.id)
|
||||
self.cursor_x = event.x
|
||||
self.cursor_y = event.y
|
||||
|
||||
def click_release(self, event):
|
||||
logging.debug("Click release on shape %s", self.id)
|
||||
|
||||
def motion(self, event):
|
||||
logging.debug("motion on shape %s", self.id)
|
||||
delta_x = event.x - self.cursor_x
|
||||
delta_y = event.y - self.cursor_y
|
||||
x0, y0, x1, y1 = self.canvas.bbox(self.id)
|
||||
self.canvas.coords(
|
||||
self.id, x0 + delta_x, y0 + delta_y, x1 + delta_x, y1 + delta_y
|
||||
)
|
||||
self.cursor_x = event.x
|
||||
self.cursor_y = event.y
|
||||
|
|
|
@ -300,7 +300,7 @@ class Toolbar(ttk.Frame):
|
|||
image = icon(image_enum)
|
||||
self.create_picker_button(
|
||||
image,
|
||||
partial(self.update_annotation, image),
|
||||
partial(self.update_annotation, image, image_enum),
|
||||
self.annotation_picker,
|
||||
tooltip,
|
||||
)
|
||||
|
@ -362,12 +362,13 @@ class Toolbar(ttk.Frame):
|
|||
|
||||
self.design_frame.tkraise()
|
||||
|
||||
def update_annotation(self, image):
|
||||
def update_annotation(self, image, image_enum):
|
||||
logging.info("clicked annotation: ")
|
||||
self.hide_pickers()
|
||||
self.annotation_button.configure(image=image)
|
||||
self.annotation_button.image = image
|
||||
self.app.canvas.mode = GraphMode.ANNOTATION
|
||||
self.app.canvas.annotation_type = image_enum
|
||||
|
||||
def click_run_button(self):
|
||||
logging.debug("Click on RUN button")
|
||||
|
|
Loading…
Add table
Reference in a new issue