The Object Modules¶
core.opsim_objectbase
¶
This is the base class of all DOSSS objects.
In order to extend DOSSS by adding new objects, create a new class derived from DOSSSObject
and overwrite the following four interface functions:
GetDisplayPoints()
:Returns a list of points for drawing the object into the ClientDC.
Intersection()
:Returns some information about the intersection with a light ray: intersection point, distance of travel, emerging rays.
ShowPropertyDialog()
:Show the property dialog box for the object.
GetLight()
:Returns a list of light rays if the object is a light source.
In addition, you have to provide a unique name / identifier for the object in the name
class attribute, which will then be used in the objects menu.
-
class
core.opsim_objectbase.
DOSSSObject
(xpos=0, ypos=0)¶ DOSSS object base class. All objects have to be derived from this class.
Parameters: - xpos (float) – x-coordinate of object center in laboratory frame.
- ypos (float) – y-coordinate of object center in laboratory frame.
-
CalculateBoundingBox
(points)¶ Calculates the bounding box around a set of points.
Parameters: points (list) – List of object points like corners, etc. Returns: Bounding box [minx, miny, maxx, maxy] containing all points.
-
Draw
(dc, zoom, x0, y0)¶ Draw the object to the client DC.
Parameters: - dc (wx.DC) – Paint DC.
- zoom (float) – Zoom level (1 is no zoom).
- x0 (float) – x-coordinate of origin of current view in laboratory frame.
- y0 (float) – y-coordinate of origin of current view in laboratory frame.
-
GetDisplayPoints
()¶ Returns a list of wx.Points which contain the coordinates of the object’s points/corners in the object’s coordinate system for displaying on screen as polyline. These are subsequently mirrored, rotated and translated according to the object properties and finally projected onto the screen. These points are only for drawing the object and should be chosen such that the function of the object becomes evident.
Important
This function needs to be overwritten by your object class.
-
GetLight
()¶ Returns a list of DOSSS_LightRay - objects emitted from the object. This function applies only for light sources and for an object to be a light source, the lightsource flag has to be set.
Important
This function needs to be overwritten by your object class if it is a light source.
-
Intersection
(line)¶ Test for intersection between a line and the current object. If there are several intersections, return the one closest to the light rays origin, i.e., with the smallest lambda value.
Important
This function needs to be overwritten by your object class.
Parameters: line (DOSSSLine) – The light ray. Returns: - point of intersection, if any (DOSSSVector or None)
- distance from base to intersection (float)
- list of emerging rays, e.g., transmitted and/or reflected (list of DOSSSLine)
-
ProjectDisplayPoints
(points, ox, oy, zoom)¶ Apply rotation, mirror and translation operations to set of points and return coordinates in client system.
Parameters: - points (list) – List of points.
- ox (float) – x-coordinate of origin of current view in laboratory frame.
- oy (float) – y-coordinate of origin of current view in laboratory frame.
- zoom (float) – Zoom level (1 is no zoom).
Returns: List of points in client system.
-
ProjectIntoObjectCosy
(line, back=0)¶ Project a line or vector into the object’s coordinate system. This is done by applying the transformations from
ProjectDisplayPoints()
in reverse order and without the projection into the screen system. This is a convenience wrapper aroundproject()
.Parameters: - or DOSSSVector) line ((DOSSSLine) – Line or vector object to project.
- back (bool) – Forward (False, default) or backward (True) projection.
Returns: Line or vector projected into object’s coordinate system.
-
ShowPropertyDialog
()¶ Show the property dialog box for the object, which allows the user to change the objects parameters.
Important
This function needs to be overwritten by your object class.
-
color
= None¶ default color for drawing the object to the screen
-
get_bbox
()¶ Returns the bounding box.
-
get_name
()¶ Returns the name / category of the object. This string is used to build the object menu items.
-
get_position
()¶ Returns current position (x,y).
-
lightsource
= None¶ set this to one/True if you want to create a light source
-
name
= None¶ overwrite this string for each new object and give it a unique identifier
-
project
(ve, isunit=False, back=False)¶ Apply transformations to a vector.
Parameters: - ve (DOSSSVector) – Vector to be projected.
- isunit (bool) – If True, treat as direction vector, otherwise as coordinate vector (default).
- back (bool) – Direction of projection: True for screen-to-lab, False for lab-to-screen (default).
Returns: Transformed version of the vector.
-
set_position
(x, y)¶ Set new position (x, y) in laboratory frame.
-
svgstr
()¶ Returns a string in SVG format for exporting to vector format.