Skip to content

Commit

Permalink
utilize all callbacks, improve setter properties resiliency
Browse files Browse the repository at this point in the history
  • Loading branch information
bbean23 committed Mar 29, 2024
1 parent 5b74ff5 commit c2d1de5
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions opencsp/app/sofast/SofastService.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,48 +74,66 @@ def system(self) -> SystemSofastFringe:

return self._system

@system.setter
def system(self, val: SystemSofastFringe):
if val is None:
old = self._system
self._system = None
self.callback.on_system_unset(old)
else:
self._system = val
self.callback.on_system_set(val)

@property
def image_projection(self):
def image_projection(self) -> ImageProjection:
return self._image_projection

@image_projection.setter
def image_projection(self, val: ImageProjection):
if val is None:
if self._image_projection is not None:
old_ip = self._image_projection
self._image_projection.close()
self._image_projection = None
self.callback.on_image_projection_unset(old_ip)
if self._system is not None:
old_sys = self._system
self._system = None
self.callback.on_system_unset(old_sys)
old_ip.close()
self.system = None
else:
self._image_projection = val
self.callback.on_image_projection_set(val)
self._load_system_elements()

@property
def image_acquisition(self):
def image_acquisition(self) -> ImageAcquisitionAbstract:
return self._image_acquisition

@image_acquisition.setter
def image_acquisition(self, val: ImageAcquisitionAbstract):
if val is None:
if self._image_acquisition is not None:
old_ia = self._image_acquisition
self._image_acquisition.close()
self._image_acquisition = None
self.callback.on_image_acquisition_unset(old_ia)
if self._system is not None:
old_sys = self._system
self._system = None
self.callback.on_system_unset(old_sys)
old_ia.close()
self.system = None
else:
self._image_acquisition = val
self.callback.on_image_acquisition_set(val)
self._load_system_elements()

@property
def calibration(self) -> ImageCalibrationAbstract:
return self._calibration

@calibration.setter
def calibration(self, val: ImageCalibrationAbstract):
if val is None:
old = self._calibration
self._calibration = None
self.callback.on_calibration_unset(old)
else:
self._calibration = val
self.callback.on_calibration_set(val)

def get_frame(self) -> np.ndarray:
"""
Captures frame from camera
Expand Down Expand Up @@ -143,8 +161,7 @@ def _load_system_elements(self) -> bool:
ImageAcquisition and ImageProjection classes are loaded)
"""
if self.image_acquisition is not None and self.image_projection is not None:
self._system = SystemSofastFringe(self.image_projection, self.image_acquisition)
self.callback.on_system_set(self._system)
self.system = SystemSofastFringe(self.image_projection, self.image_acquisition)
return True
return False

Expand Down

0 comments on commit c2d1de5

Please sign in to comment.