summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/file.py8
-rw-r--r--src/phys.py11
-rw-r--r--src/ui.py51
-rw-r--r--src/ui_widgets.py9
4 files changed, 55 insertions, 24 deletions
diff --git a/src/file.py b/src/file.py
index 4285207..7c5f570 100644
--- a/src/file.py
+++ b/src/file.py
@@ -1,7 +1,7 @@
import re, sys, traceback, json
import phys
-file_format_version = 1
+file_format_version = 2
def save_system(path, system):
ser = dict()
@@ -14,7 +14,9 @@ def save_system(path, system):
"type": pol.type,
"angle": pol.angle,
"delta": pol.delta,
- "ref": pol.ref
+ "ref": pol.ref,
+ "t1": pol.t1,
+ "t2": pol.t2
}
ser["elements"].append(el)
@@ -39,6 +41,8 @@ def open_system(path):
pol.angle = float(el["angle"])
pol.delta = float(el["delta"])
pol.ref = el["ref"]
+ pol.t1 = float(el["t1"])
+ pol.t2 = float(el["t2"])
system.elements.append(pol)
return system \ No newline at end of file
diff --git a/src/phys.py b/src/phys.py
index 2109f28..96f3bad 100644
--- a/src/phys.py
+++ b/src/phys.py
@@ -57,6 +57,8 @@ class Polarizer:
self.angle = 0
self.delta = delta
self.ref = False # FIXME: move this to UI or System
+ self.t1 = 1
+ self.t2 = 0
self.set_type(type)
def set_type(self, type):
@@ -74,12 +76,17 @@ class Polarizer:
if state is None:
if self.type == "linear":
return np.dot(R(-self.angle - self.delta), \
- np.array([[1], [0]]))
+ np.array([[1], [0]])) * np.sqrt(self.t1)
else:
return None
+ if type == "linear":
+ A = np.sqrt(np.array([[self.t1, 0], [0, self.t2]]))
+ else:
+ A = np.sqrt(np.array([[self.t1, 0], [0, self.t1]]))
+
M = np.matmul(R(-self.angle - self.delta), \
- np.matmul(self.M, R(self.angle + self.delta)))
+ np.matmul(np.matmul(self.M, A), R(self.angle + self.delta)))
return np.dot(M, state)
class System:
diff --git a/src/ui.py b/src/ui.py
index 4f6b189..6fced54 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -39,14 +39,15 @@ class Pens:
from ui_widgets import *
-
-
class OptBox(QVBoxLayout):
def __init__(self, row, pol, rownum):
super().__init__()
+ self.rownum = rownum
# Name
self.name = MeinGroßLabel("Element %d" % rownum)
+ self.name.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.name.customContextMenuRequested.connect(lambda pos: OptBox.open_menu(self, pos))
self.addWidget(self.name)
# Type / Enable box
@@ -92,6 +93,18 @@ class OptBox(QVBoxLayout):
box.addWidget(self.delta)
box.addWidget(QLabel("°"))
+ # Transmittance layout
+ box = QHBoxLayout()
+ self.addLayout(box)
+
+ box.addWidget(QLabel("T"))
+ self.t1 = QLineEdit("1")
+ self.t1.textChanged.connect(lambda: TableRow.t_change(row))
+ box.addWidget(self.t1)
+ self.t2 = QLineEdit("0")
+ self.t2.textChanged.connect(lambda: TableRow.t_change(row))
+ box.addWidget(self.t2)
+
# Angle
self.angle = AngleSlider("Angle")
self.angle.setValue(pol.angle * 180 / np.pi)
@@ -99,20 +112,12 @@ class OptBox(QVBoxLayout):
self.addLayout(self.angle)
self.addItem(ExpandingSpacer())
- # Add
- self.add_above = QPushButton("Add above")
- self.add_above.clicked.connect(lambda: half_assed_element_creation(rownum - 1))
- self.add_below = QPushButton("Add below")
- self.add_below.clicked.connect(lambda: half_assed_element_creation(rownum))
- self.delete = QPushButton("Delete")
- self.delete.clicked.connect(lambda: half_assed_element_deletion(rownum - 1))
-
- box = QHBoxLayout()
- box.addWidget(self.add_above)
- box.addWidget(self.add_below)
- box.addWidget(self.delete)
- self.addLayout(box)
-
+ def open_menu(self, pos):
+ menu = QMenu()
+ menu.addAction("Insert before", lambda: half_assed_element_creation(self.rownum - 1))
+ menu.addAction("Insert after", lambda: half_assed_element_creation(self.rownum))
+ menu.addAction("Delete", lambda: half_assed_element_deletion(self.rownum - 1))
+ menu.exec_(self.name.mapToGlobal(pos))
class TableRow:
@@ -156,6 +161,15 @@ class TableRow:
row.pol.set_type(row.optbox.type.currentData())
update()
+ @staticmethod
+ def t_change(row):
+ try:
+ row.pol.t1 = float(row.optbox.t1.text())
+ row.pol.t2 = float(row.optbox.t2.text())
+ except ValueError:
+ pass
+ update()
+
def populate_table():
GUI.table = QGridLayout()
@@ -197,9 +211,8 @@ def update():
row.ellipse.is_used = not system.ignore[i]
row.ellipse.repaint()
- text = "%s (%f°)\nat %f°" \
- % (pol.type, pol.delta * 180 / np.pi,
- (pol.angle + pol.delta) * 180 / np.pi)
+ text = "%s at %f°" \
+ % (pol.type, (pol.angle + pol.delta) * 180 / np.pi)
row.info_angle.setText(text)
state = system.states[i]
diff --git a/src/ui_widgets.py b/src/ui_widgets.py
index 48282c4..636f2ed 100644
--- a/src/ui_widgets.py
+++ b/src/ui_widgets.py
@@ -29,8 +29,11 @@ class EllipseWidget(QWidget):
self.ellipse = None
self.is_used = True
+ self.setSizePolicy(QSizePolicy(QSizePolicy.MinimumExpanding, \
+ QSizePolicy.MinimumExpanding))
+
def minimumSizeHint(self):
- return QSize(150, 150)
+ return QSize(100, 100)
def paintEvent(self, event):
P = QPainter(self)
@@ -68,6 +71,10 @@ class EllipseWidget(QWidget):
if self.state is None:
return
+ if np.isnan(self.ellipse.a) or np.isnan(self.ellipse.b) \
+ or np.isnan(self.ellipse.alpha) or np.isnan(self.ellipse.theta):
+ return
+
P.resetTransform()
r *= 0.88
P.translate(cx, cy)