Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, matrix, x=0.0, fixedWidth=False):
self.matrix = matrix
super(MatrixGraphic, self).__init__(x=x, fixedWidth=fixedWidth, label=self.matrix.label)
if self.matrix.L != 0:
self.points.extend(self.verticesPoints)
self.points.extend(self.pointsOfInterest)
self.addPrincipalPlanes()
from .figure import MplFigure
from .imagingpath import ImagingPath
path = ImagingPath(elements=[self.matrix])
figure = MplFigure(path)
figure.graphics = [self]
figure.create(title="Element properties")
figure.display2D()
class LensGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0, fixedWidth=False, minSize=0):
if matrix.apertureDiameter == float('+Inf') and minSize > matrix._physicalHalfHeight:
matrix._physicalHalfHeight = minSize
super(LensGraphic, self).__init__(matrix, x=x, fixedWidth=fixedWidth)
@property
def mainComponents(self):
return [DoubleThinArrow(self.matrix.displayHalfHeight()*2)]
class ApertureGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0):
super().__init__(matrix, x=x)
@property
self.corners = [components[0].corners[0], components[-1].corners[1]]
return components
@property
def apertureComponents(self):
halfHeight = self.matrix.displayHalfHeight()
if len(self.surfaces) == 1:
return []
outerWidth = self.corners[1] - self.corners[0]
return [ApertureBars(y=halfHeight, x=self.corners[0], width=outerWidth)]
class MatrixGroupGraphic(MatrixGraphic):
def __init__(self, matrixGroup, x=0.0):
self.matrixGroup = matrixGroup
super().__init__(matrixGroup, x=x)
@property
def L(self):
L = 0
for element in self.matrixGroup.elements:
L += element.L
return L
@property
def components(self):
if self._components is None:
self._components = self.mainComponents
return self._components
def __new__(cls, element, x=0.0, minSize=0) -> Union[MatrixGraphic, None, list]:
instance = type(element).__name__
if type(element) is Objective or issubclass(type(element), Objective):
return ObjectiveGraphic(element, x=x)
if instance is 'Lens':
return LensGraphic(element, x=x, minSize=minSize)
if instance is 'Space':
return None
if instance is 'Aperture':
return ApertureGraphic(element, x=x)
if element.surfaces:
return SurfacesGraphic(element, x=x)
if issubclass(type(element), MatrixGroup):
return MatrixGroupGraphic(element, x=x).standAloneGraphics
else:
return MatrixGraphic(element, x=x)
@property
def mainComponents(self):
return [DoubleThinArrow(self.matrix.displayHalfHeight()*2)]
class ApertureGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0):
super().__init__(matrix, x=x)
@property
def mainComponents(self):
return []
class SurfacesGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0):
self.surfaces = matrix.surfaces
self.corners = None
super(SurfacesGraphic, self).__init__(matrix, x=x, fixedWidth=True)
@property
def mainComponents(self):
halfHeight = self.matrix.displayHalfHeight()
if len(self.surfaces) == 1:
return [Surface(self.surfaces[0], halfHeight)]
z = 0
components = []
for i, surfaceA in enumerate(self.surfaces[:-1]):
figure.display2D()
class LensGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0, fixedWidth=False, minSize=0):
if matrix.apertureDiameter == float('+Inf') and minSize > matrix._physicalHalfHeight:
matrix._physicalHalfHeight = minSize
super(LensGraphic, self).__init__(matrix, x=x, fixedWidth=fixedWidth)
@property
def mainComponents(self):
return [DoubleThinArrow(self.matrix.displayHalfHeight()*2)]
class ApertureGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0):
super().__init__(matrix, x=x)
@property
def mainComponents(self):
return []
class SurfacesGraphic(MatrixGraphic):
def __init__(self, matrix, x=0.0):
self.surfaces = matrix.surfaces
self.corners = None
super(SurfacesGraphic, self).__init__(matrix, x=x, fixedWidth=True)
@property