Skip to content
Snippets Groups Projects
Commit 64810bc8 authored by Daniel Brown's avatar Daniel Brown
Browse files

more gui fixes

parent 486eb5c5
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ import numpy as np ...@@ -6,7 +6,7 @@ import numpy as np
code = """ code = """
l l1 1 0 0 n1 l l1 1 0 0 n1
s s1 10 1 n1 n2 s s1 10 1 n1 n2
m m1 1 0 0 n2 dump m m1 1 0 0 n2 n3
gauss g1 m1 n2 1e-3 0 gauss g1 m1 n2 1e-3 0
......
...@@ -10,52 +10,12 @@ from pykat.structs import * ...@@ -10,52 +10,12 @@ from pykat.structs import *
import numpy as np import numpy as np
import pylab as pl import pylab as pl
kat = finesse.kat() code = """
l l1 1 0 0 n1
"""
laser(kat,'l1','n1',1) kat = finesse.kat(kat_code = code)
space(kat,'s1','n1','n2',1)
mirror(kat,'m1','n2','n3',R=0.8,T=0.2)
space(kat,'s2','n3','n4',L=1)
mirror(kat,'m2','n4','n5',R=0.7,T=0.3)
cavity(kat, 'cav1','m1','n3','m2','n4')
space(kat,'s3','n5','n6',L=1)
photodiode(kat,'pd_cav','n4')
photodiode(kat,'pd_ref','n2')
photodiode(kat,'pd_trs','n5')
kat.m1.Rcx = -1000.0
kat.m1.Rcy = -1000.0
kat.m2.Rcx = 1000.0
kat.m2.Rcy = 1000.0
xaxis(kat, Scale.linear, [0,360], kat.m2, kat.m2.phi, 1000)
kat.maxtem = 0
run = kat.run(printout=0,printerr=0)
#pl.figure()
#pl.ion()
#pl.plot(run.x,run.y)
#pl.xlabel(run.xlabel)
#pl.ylabel("Intensity [W]")
#pl.legend(run.ylabels)
#pl.show()
kat.m1.R = 0.5
kat.m1.T = 0.5
kat.pd_cav.enabled = False
run = kat.run(printout=0,printerr=0)
#pl.figure()
#pl.plot(run.x,run.y)
#pl.xlabel(run.xlabel)
#pl.ylabel("Intensity [W]")
#pl.legend(run.ylabels)
#pl.show()
kat.openGUI() kat.openGUI()
......
...@@ -17,7 +17,7 @@ class Component(object) : ...@@ -17,7 +17,7 @@ class Component(object) :
def __init__(self, name): def __init__(self, name):
self.__name = name self.__name = name
self._svgItem = None self._svgItem = None
self.__nodes = [] self._nodes = []
self._requested_node_names = [] self._requested_node_names = []
self._kat = None self._kat = None
...@@ -52,13 +52,13 @@ class Component(object) : ...@@ -52,13 +52,13 @@ class Component(object) :
else: else:
n.connect(self) n.connect(self)
self.__nodes.append(n) self._nodes.append(n)
return n return n
def getNodes(self): def getNodes(self):
""" Returns a copy of the nodes the component has """ """ Returns a copy of the nodes the component has """
return self.__nodes[:] return self._nodes[:]
def __getname(self): def __getname(self):
return self.__name return self.__name
...@@ -235,11 +235,11 @@ class space(Component): ...@@ -235,11 +235,11 @@ class space(Component):
node_new.connect(self) node_new.connect(self)
node_old.disconnect(self) node_old.disconnect(self)
if self.node1 == node_old: if self._nodes[0] == node_old:
self.node1 = node_new self._nodes[0] = node_new
if self.node2 == node_old: if self._nodes[1] == node_old:
self.node2 = node_new self._nodes[1] = node_new
class laser(Component): class laser(Component):
......
...@@ -60,11 +60,16 @@ class SpaceQGraphicsItem(QGraphicsLineItem): ...@@ -60,11 +60,16 @@ class SpaceQGraphicsItem(QGraphicsLineItem):
conn = nodes[0].amIConnected(self.__space) conn = nodes[0].amIConnected(self.__space)
x1 = 0
y1 = 0
x2 = 0
y2 = 0
if conn[0]: if conn[0]:
if conn[1] != None: if conn[1] != None:
if self.__n1 is not None: if self.__n1 is not None:
# i.e. we have a node graphic item but now it is connected to something # i.e. we have a node graphic item but now it is connected to something
self.__n1.scene().removeItem(self.__n2) self.__n1.scene().removeItem(self.__n1)
self.__n1 = None self.__n1 = None
# now check if a connected component was returned too # now check if a connected component was returned too
...@@ -170,7 +175,7 @@ class ComponentQGraphicsItem(QGraphicsSvgItem): ...@@ -170,7 +175,7 @@ class ComponentQGraphicsItem(QGraphicsSvgItem):
n.refresh() n.refresh()
def itemChange(self, change, value): def itemChange(self, change, value):
# if the item move then update any spaces # if the item is moved then update any spaces attached to it
if change == QGraphicsItem.ItemPositionHasChanged: if change == QGraphicsItem.ItemPositionHasChanged:
nodes = self.__component.getNodes() nodes = self.__component.getNodes()
......
...@@ -99,10 +99,27 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow): ...@@ -99,10 +99,27 @@ class pyKatGUI(QtGui.QMainWindow, qt_gui.Ui_MainWindow):
def addMirror(self, x,y): def addMirror(self, x,y):
name = self.kat.getNewComponentName('m') name = self.kat.getNewComponentName('m')
n = self.kat.getNewNodeNames('n',2) n = self.kat.getNewNodeNames('n',2)
m = pykat.components.mirror(self.kat,name,n[0],n[1]) m = pykat.components.mirror(name,n[0],n[1])
self.kat.add(m)
self.addComponentToScene(m,x,y) self.addComponentToScene(m,x,y)
def addSpace(self, x,y):
name = self.kat.getNewComponentName('s')
n = self.kat.getNewNodeNames('n',2)
s = pykat.components.space(name, n[0], n[1])
self.kat.add(s)
self.addComponentToScene(s,x,y)
def addLaser(self, x,y):
name = self.kat.getNewComponentName('l')
n = self.kat.getNewNodeNames('n',1)
l = pykat.components.laser(name, n[0])
self.kat.add(l)
self.addComponentToScene(l,x,y)
class pyKatGraphicsScene(QGraphicsScene): class pyKatGraphicsScene(QGraphicsScene):
def drawBackground(self, painter, rect): def drawBackground(self, painter, rect):
size = 10 size = 10
...@@ -148,10 +165,15 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -148,10 +165,15 @@ class pyKatGraphicsView(QGraphicsView):
menu = QMenu(self) menu = QMenu(self)
addmenu = menu.addMenu("Add...") addmenu = menu.addMenu("Add...")
action = addmenu.addAction("Space")
action.triggered.connect(functools.partial(gui.addSpace, pt.x(), pt.y()))
action = addmenu.addAction("Mirror") action = addmenu.addAction("Mirror")
action.triggered.connect(functools.partial(gui.addMirror, pt.x(), pt.y())) action.triggered.connect(functools.partial(gui.addMirror, pt.x(), pt.y()))
addmenu.addAction("Laser") action = addmenu.addAction("Laser")
action.triggered.connect(functools.partial(gui.addLaser, pt.x(), pt.y()))
addmenu.addAction("Beamsplitter") addmenu.addAction("Beamsplitter")
addmenu.addAction("Photodiode") addmenu.addAction("Photodiode")
...@@ -204,6 +226,7 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -204,6 +226,7 @@ class pyKatGraphicsView(QGraphicsView):
def mouseReleaseEvent(self, ev): def mouseReleaseEvent(self, ev):
# if we have dragged a node and marked another to connect it too # if we have dragged a node and marked another to connect it too
if self.__selected_item is not None and isinstance(self.__selected_item, NodeQGraphicItem) and self.__marked is not None: if self.__selected_item is not None and isinstance(self.__selected_item, NodeQGraphicItem) and self.__marked is not None:
# node attached to space which needs to be removed # node attached to space which needs to be removed
node_s = self.__selected_item.node node_s = self.__selected_item.node
...@@ -217,13 +240,16 @@ class pyKatGraphicsView(QGraphicsView): ...@@ -217,13 +240,16 @@ class pyKatGraphicsView(QGraphicsView):
qcomp = self.__marked.parentItem() qcomp = self.__marked.parentItem()
# connect space of node dragged to the component node # connect space of node dragged to the component node
# the space node that has been dragged gets deleted and we
# replace it with the components
space.changeNode(node_s, node_c) space.changeNode(node_s, node_c)
node_s.remove() node_s.remove() # now remove from node network completly
# then refresh the graphical items # then refresh the graphical items
qspace.refresh() qspace.refresh()
qcomp.refresh() qcomp.refresh()
if self.__marked is not None: if self.__marked is not None:
self.__marked.marked = False self.__marked.marked = False
self.__marked.refresh() self.__marked.refresh()
......
...@@ -30,7 +30,7 @@ class NodeNetwork(object): ...@@ -30,7 +30,7 @@ class NodeNetwork(object):
if not isinstance(node,Node): if not isinstance(node,Node):
raise exceptions.ValueError("node argument is not of type Node") raise exceptions.ValueError("node argument is not of type Node")
if node not in self._nodes: if node.name not in self._nodes:
raise exceptions.RuntimeError("Trying to remove node {0} when it has not been added".format(node.name)) raise exceptions.RuntimeError("Trying to remove node {0} when it has not been added".format(node.name))
C = node.getComponents() C = node.getComponents()
...@@ -87,7 +87,7 @@ class Node(object): ...@@ -87,7 +87,7 @@ class Node(object):
self._detectors = [] self._detectors = []
self.__name = name self.__name = name
self._item = None self._item = None
self._network = None self._network = network
@property @property
def network(self): return self._network def network(self): return self._network
...@@ -100,8 +100,33 @@ class Node(object): ...@@ -100,8 +100,33 @@ class Node(object):
def remove(self): def remove(self):
self._network.removeNode(self) self._network.removeNode(self)
if self._item != None:
self._item.scene().removeItem(self._item) self._item.scene().removeItem(self._item)
def disconnect(self, obj):
if not (isinstance(obj,Component) or isinstance(obj,Detector)):
raise exceptions.ValueError("Object is not a component or detector")
if isinstance(obj, Component):
if self._comp1 == obj:
self._comp1 = None
elif self._comp2 == obj:
self._comp2 = None
else:
raise exceptions.RuntimeError("Cannot dettach {0} from node {1}".format(
obj.name, self.__name))
else:
# we must have a detector as we check above
self._detectors.remove(obj)
if self._item is not None:
self._item.refresh()
def connect(self, obj): def connect(self, obj):
if not (isinstance(obj,Component) or isinstance(obj,Detector)): if not (isinstance(obj,Component) or isinstance(obj,Detector)):
...@@ -143,7 +168,7 @@ class Node(object): ...@@ -143,7 +168,7 @@ class Node(object):
def amIConnected(self, obj): def amIConnected(self, obj):
""" """
Checks if obj is connected oto the node. Returns true or false in tuple Checks if obj is connected to the node. Returns true or false in tuple
with None or the other object and the node index which it is attached to with None or the other object and the node index which it is attached to
""" """
if obj == self._comp1: if obj == self._comp1:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment