Commit 6aea82f2 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Network: Split graph model file.

Showing with 102 additions and 86 deletions
+102 -86
# -*- coding: utf-8 -*-
from model.network.Node import Node
class Edge(object):
def __init__(self, id:str, name:str, node1:Node = None, node2:Node = None):
super(Edge, self).__init__()
self.id = id
self.name = name
self.node1 = node1
self.node2 = node2
self.enable = True
def __repr__(self):
return f"Edge {{id: {self.id}, enable: {self.enable}, name: {self.name}, self.node1: {self.node1}, self.node2: {self.node2},}}"
def __getitem__(self, name):
ret = None
if name == "name":
ret = self.name
elif name == "id":
ret = self.id
elif name == "node1":
ret = self.node1.name
elif name == "node2":
ret = self.node2.name
elif name == "enable":
ret = self.enable
return ret
def __setitem__(self, name, value):
if name == "name":
self.name = value
elif name == "id":
self.id = value
elif name == "node1":
self.node1 = value
elif name == "node2":
self.node2 = value
elif name == "enable":
self.enable = value
def enable(self):
self.enable = True
def disable(self):
self.enable = False
......@@ -2,81 +2,8 @@
from functools import reduce
class Node(object):
def __init__(self, id:str, name:str):
super(Node, self).__init__()
self.id = id
self.name = name
def __repr__(self):
return f"Node {{id: {self.id}, name: {self.name}}}"
def __getitem__(self, name):
ret = None
if name == "name":
ret = self.name
elif name == "id":
ret = self.id
return ret
def __setitem__(self, name, value):
if name == "name":
self.name = value
elif name == "id":
self.id = value
class Edge(object):
def __init__(self, id:str, name:str, node1:Node = None, node2:Node = None):
super(Edge, self).__init__()
self.id = id
self.name = name
self.node1 = node1
self.node2 = node2
self.enable = True
def __repr__(self):
return f"Edge {{id: {self.id}, enable: {self.enable}, name: {self.name}, self.node1: {self.node1}, self.node2: {self.node2},}}"
def __getitem__(self, name):
ret = None
if name == "name":
ret = self.name
elif name == "id":
ret = self.id
elif name == "node1":
ret = self.node1.name
elif name == "node2":
ret = self.node2.name
elif name == "enable":
ret = self.enable
return ret
def __setitem__(self, name, value):
if name == "name":
self.name = value
elif name == "id":
self.id = value
elif name == "node1":
self.node1 = value
elif name == "node2":
self.node2 = value
elif name == "enable":
self.enable = value
def enable(self):
self.enable = True
def disable(self):
self.enable = False
from model.network.Node import Node
from model.network.Edge import Edge
class Graph(object):
def __init__(self):
......
# -*- coding: utf-8 -*-
from model.network.Point import Point
class Node(object):
def __init__(self, id:str, name:str):
super(Node, self).__init__()
self.id = id
self.name = name
self.pos = Point(0, 0)
def __repr__(self):
return f"Node {{id: {self.id}, name: {self.name}}}"
def __getitem__(self, name):
ret = None
if name == "name":
ret = self.name
elif name == "id":
ret = self.id
return ret
def __setitem__(self, name, value):
if name == "name":
self.name = value
elif name == "id":
self.id = value
# -*- coding: utf-8 -*-
def Point(object):
def __init__(self, x:float, y:float):
super(Point, self).__init__()
self.x = x
self.y = y
def __repr__(self):
return f"({self.x}, {self.y})"
def set_pos(self, x, y):
self.x = x
self.y = y
# -*- coding: utf-8 -*-
from view.ASubWindow import ASubWindow
from model.network.Graph import (Node, Edge, Graph)
from model.network.Node import Node
from model.network.Edge import Edge
from model.network.Graph import Graph
from PyQt5.QtCore import (
Qt, QRect, QVariant, QAbstractTableModel, pyqtSlot, pyqtSignal,
......@@ -120,13 +122,6 @@ class NetworkWindow(ASubWindow):
self.graph = Graph()
n1 = self.graph.add_node() # TODO: Delete me
n2 = self.graph.add_node() # TODO: Delete me
n3 = self.graph.add_node() # TODO: Delete me
for i in range(0,100):
self.graph.add_node() # TODO: Delete me
# Nodes table
self.nodes_model = TableModel(
......@@ -140,9 +135,6 @@ class NetworkWindow(ASubWindow):
table.setItemDelegate(self.delegate_line)
#table.resizeColumnsToContents()
self.graph.add_edge(n1, n2) # TODO: Delete me
self.graph.add_edge(n2, n3) # TODO: Delete me
# Edges table
self.reachs_model = TableModel(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment