From cc34f456770901520776068db181157c65310b43 Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 30 Jun 2017 14:31:25 +0200 Subject: [PATCH 1/2] Additional drawing options for Project --- gns3server/controller/project.py | 73 +++++++++++++++++++++++++++++-- gns3server/controller/topology.py | 4 ++ gns3server/schemas/project.py | 48 ++++++++++++++++++++ 3 files changed, 122 insertions(+), 3 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 8d25f024..e51e6f54 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -68,7 +68,7 @@ class Project: def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened", filename=None, auto_start=False, auto_open=False, auto_close=True, - scene_height=1000, scene_width=2000): + scene_height=1000, scene_width=2000, zoom=100, show_layers=False, snap_to_grid=False, show_grid=False): self._controller = controller assert name is not None @@ -79,6 +79,10 @@ class Project: self._status = status self._scene_height = scene_height self._scene_width = scene_width + self._zoom = zoom + self._show_layers = show_layers + self._snap_to_grid = snap_to_grid + self._show_grid = show_grid self._loading = False # Disallow overwrite of existing project @@ -170,6 +174,66 @@ class Project: """ self._scene_width = val + @property + def zoom(self): + """ + Zoom level in percentage + :return: integer > 0 + """ + return self._zoom + + @zoom.setter + def zoom(self, zoom): + """ + Setter for zoom level in percentage + """ + self._zoom = zoom + + @property + def show_layers(self): + """ + Show layers mode + :return: bool + """ + return self._show_layers + + @show_layers.setter + def show_layers(self, show_layers): + """ + Setter for show layers mode + """ + self._show_layers = show_layers + + @property + def snap_to_grid(self): + """ + Snap to grid mode + :return: bool + """ + return self._snap_to_grid + + @snap_to_grid.setter + def snap_to_grid(self, snap_to_grid): + """ + Setter for snap to grid mode + """ + self._snap_to_grid = snap_to_grid + + @property + def show_grid(self): + """ + Show grid mode + :return: bool + """ + return self._show_grid + + @show_grid.setter + def show_grid(self, show_grid): + """ + Setter for snam to grid mode + """ + self._show_grid = show_grid + @property def auto_start(self): """ @@ -798,7 +862,6 @@ class Project: yield from pool.join() def __json__(self): - return { "name": self._name, "project_id": self._id, @@ -809,7 +872,11 @@ class Project: "auto_close": self._auto_close, "auto_open": self._auto_open, "scene_height": self._scene_height, - "scene_width": self._scene_width + "scene_width": self._scene_width, + "zoom": self._zoom, + "show_layers": self._show_layers, + "snap_to_grid": self._snap_to_grid, + "show_grid": self._show_grid } def __repr__(self): diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index fc75795a..05d41ad3 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -79,6 +79,10 @@ def project_to_topology(project): "auto_close": project.auto_close, "scene_width": project.scene_width, "scene_height": project.scene_height, + "zoom": project.zoom, + "show_layers": project.show_layers, + "snap_to_grid": project.snap_to_grid, + "show_grid": project.show_grid, "topology": { "nodes": [], "links": [], diff --git a/gns3server/schemas/project.py b/gns3server/schemas/project.py index 71118ee7..48171897 100644 --- a/gns3server/schemas/project.py +++ b/gns3server/schemas/project.py @@ -49,6 +49,22 @@ PROJECT_CREATE_SCHEMA = { "scene_width": { "type": "integer", "description": "Width of the drawing area" + }, + "zoom": { + "type": "integer", + "description": "Zoom of the drawing area" + }, + "show_layers": { + "type": "boolean", + "description": "Show layers on the drawing area" + }, + "snap_to_grid": { + "type": "boolean", + "description": "Snap to grid on the drawing area" + }, + "show_grid": { + "type": "boolean", + "description": "Show the grid on the drawing area" } }, "additionalProperties": False, @@ -88,6 +104,22 @@ PROJECT_UPDATE_SCHEMA = { "scene_width": { "type": "integer", "description": "Width of the drawing area" + }, + "zoom": { + "type": "integer", + "description": "Zoom of the drawing area" + }, + "show_layers": { + "type": "boolean", + "description": "Show layers on the drawing area" + }, + "snap_to_grid": { + "type": "boolean", + "description": "Snap to grid on the drawing area" + }, + "show_grid": { + "type": "boolean", + "description": "Show the grid on the drawing area" } }, "additionalProperties": False, @@ -143,6 +175,22 @@ PROJECT_OBJECT_SCHEMA = { "scene_width": { "type": "integer", "description": "Width of the drawing area" + }, + "zoom": { + "type": "integer", + "description": "Zoom of the drawing area" + }, + "show_layers": { + "type": "boolean", + "description": "Show layers on the drawing area" + }, + "snap_to_grid": { + "type": "boolean", + "description": "Snap to grid on the drawing area" + }, + "show_grid": { + "type": "boolean", + "description": "Show the grid on the drawing area" } }, "additionalProperties": False, From dadbb0ab0909a099d9c5436d1a2aa8d59060803f Mon Sep 17 00:00:00 2001 From: ziajka Date: Mon, 3 Jul 2017 10:01:22 +0200 Subject: [PATCH 2/2] More options for drawing area --- gns3server/controller/project.py | 24 +++++++++++++++++++++--- gns3server/controller/topology.py | 1 + gns3server/schemas/project.py | 12 ++++++++++++ gns3server/schemas/topology.py | 20 ++++++++++++++++++++ tests/controller/test_project.py | 7 ++++++- tests/controller/test_topology.py | 5 +++++ 6 files changed, 65 insertions(+), 4 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index e51e6f54..cb60d8df 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -68,7 +68,8 @@ class Project: def __init__(self, name=None, project_id=None, path=None, controller=None, status="opened", filename=None, auto_start=False, auto_open=False, auto_close=True, - scene_height=1000, scene_width=2000, zoom=100, show_layers=False, snap_to_grid=False, show_grid=False): + scene_height=1000, scene_width=2000, zoom=100, show_layers=False, snap_to_grid=False, show_grid=False, + show_interface_labels=False): self._controller = controller assert name is not None @@ -83,6 +84,7 @@ class Project: self._show_layers = show_layers self._snap_to_grid = snap_to_grid self._show_grid = show_grid + self._show_interface_labels = show_interface_labels self._loading = False # Disallow overwrite of existing project @@ -230,10 +232,25 @@ class Project: @show_grid.setter def show_grid(self, show_grid): """ - Setter for snam to grid mode + Setter for showing the grid mode """ self._show_grid = show_grid + @property + def show_interface_labels(self): + """ + Show interface labels mode + :return: bool + """ + return self._show_interface_labels + + @show_interface_labels.setter + def show_interface_labels(self, show_interface_labels): + """ + Setter for show interface labels + """ + self._show_interface_labels = show_interface_labels + @property def auto_start(self): """ @@ -876,7 +893,8 @@ class Project: "zoom": self._zoom, "show_layers": self._show_layers, "snap_to_grid": self._snap_to_grid, - "show_grid": self._show_grid + "show_grid": self._show_grid, + "show_interface_labels": self._show_interface_labels } def __repr__(self): diff --git a/gns3server/controller/topology.py b/gns3server/controller/topology.py index 05d41ad3..948f49d2 100644 --- a/gns3server/controller/topology.py +++ b/gns3server/controller/topology.py @@ -83,6 +83,7 @@ def project_to_topology(project): "show_layers": project.show_layers, "snap_to_grid": project.snap_to_grid, "show_grid": project.show_grid, + "show_interface_labels": project.show_interface_labels, "topology": { "nodes": [], "links": [], diff --git a/gns3server/schemas/project.py b/gns3server/schemas/project.py index 48171897..eb008389 100644 --- a/gns3server/schemas/project.py +++ b/gns3server/schemas/project.py @@ -65,6 +65,10 @@ PROJECT_CREATE_SCHEMA = { "show_grid": { "type": "boolean", "description": "Show the grid on the drawing area" + }, + "show_interface_labels": { + "type": "boolean", + "description": "Show interface labels on the drawing area" } }, "additionalProperties": False, @@ -120,6 +124,10 @@ PROJECT_UPDATE_SCHEMA = { "show_grid": { "type": "boolean", "description": "Show the grid on the drawing area" + }, + "show_interface_labels": { + "type": "boolean", + "description": "Show interface labels on the drawing area" } }, "additionalProperties": False, @@ -191,6 +199,10 @@ PROJECT_OBJECT_SCHEMA = { "show_grid": { "type": "boolean", "description": "Show the grid on the drawing area" + }, + "show_interface_labels": { + "type": "boolean", + "description": "Show interface labels on the drawing area" } }, "additionalProperties": False, diff --git a/gns3server/schemas/topology.py b/gns3server/schemas/topology.py index ad383c5d..bf9fc1cf 100644 --- a/gns3server/schemas/topology.py +++ b/gns3server/schemas/topology.py @@ -73,6 +73,26 @@ TOPOLOGY_SCHEMA = { "type": "integer", "description": "Width of the drawing area" }, + "zoom": { + "type": "integer", + "description": "Zoom of the drawing area" + }, + "show_layers": { + "type": "boolean", + "description": "Show layers on the drawing area" + }, + "snap_to_grid": { + "type": "boolean", + "description": "Snap to grid on the drawing area" + }, + "show_grid": { + "type": "boolean", + "description": "Show the grid on the drawing area" + }, + "show_interface_labels": { + "type": "boolean", + "description": "Show interface labels on the drawing area" + }, "topology": { "description": "The topology content", "type": "object", diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index cbafaa51..d56325f2 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -70,7 +70,12 @@ def test_json(tmpdir): "auto_close": True, "auto_open": False, "scene_width": 2000, - "scene_height": 1000 + "scene_height": 1000, + "zoom": 100, + "show_grid": False, + "show_interface_labels": False, + "show_layers": False, + "snap_to_grid": False } diff --git a/tests/controller/test_topology.py b/tests/controller/test_topology.py index 4431d722..01dbf245 100644 --- a/tests/controller/test_topology.py +++ b/tests/controller/test_topology.py @@ -40,6 +40,11 @@ def test_project_to_topology_empty(tmpdir): "scene_width": 2000, "scene_height": 1000, "revision": GNS3_FILE_FORMAT_REVISION, + "zoom": 100, + "show_grid": False, + "show_interface_labels": False, + "show_layers": False, + "snap_to_grid": False, "topology": { "nodes": [], "links": [],