Skip to main content

philips_isyntax_rs/
facade.rs

1//! This module contains all functions related to Philips ISyntaxFacade
2//!
3
4use crate::{ContainerName, Facade, Image, ImageType, Result};
5use cxx::let_cxx_string;
6use std::path::Path;
7
8impl Drop for Facade<'_> {
9    fn drop(&mut self) {
10        if let Err(_err) = self.close() {
11            // todo! log?
12        };
13    }
14}
15
16/// A facade is a reference to a Philips Engine internal object
17/// The facade allow file manipulation & file information retrieval
18/// NOTE: Philips Engine and all internal objects are not thread safe
19impl Facade<'_> {
20    /// Open an ISyntax file through a facade and specify a cache file
21    /// if the container allows it
22    pub(crate) fn open_with_cache_file<P: AsRef<Path>, R: AsRef<Path>>(
23        &self,
24        filename: P,
25        container: &ContainerName,
26        cache_filename: R,
27    ) -> Result<()> {
28        let filename = filename.as_ref().display().to_string();
29        let cache_filename = cache_filename.as_ref().display().to_string();
30        Ok(self
31            .inner
32            .open(&filename, container.as_str(), &cache_filename)?)
33    }
34
35    // close close hold by the facade
36    // WARNING: Do not call this function if the facade was not "opened" or already closed
37    // this will cause a SIGSEGV
38    fn close(&self) -> Result<()> {
39        Ok(self.inner.close()?)
40    }
41
42    /// Returns numbers of images in ISyntax file
43    /// Should always return 3 images eg WSI, Macro, Label/ILE
44    pub fn num_images(&self) -> Result<usize> {
45        Ok(self.inner.numImages()?)
46    }
47
48    /// Returns the version of isyntax file
49    pub fn isyntax_file_version(&self) -> Result<&str> {
50        Ok(self.inner.iSyntaxFileVersion()?.to_str()?)
51    }
52
53    /// Return the id of the facade
54    /// See also PhilipsEngine::facade
55    pub fn id(&self) -> Result<&str> {
56        Ok(self.inner.id()?.to_str()?)
57    }
58
59    /// Returns the barcode in the Label/ILE image
60    pub fn barcode(&self) -> Result<&str> {
61        Ok(self.inner.barcode()?.to_str()?)
62    }
63
64    /// Returns the calibration status of the scanner used to create the image file
65    pub fn scanner_calibration_status(&self) -> Result<&str> {
66        Ok(self.inner.scannerCalibrationStatus()?.to_str()?)
67    }
68
69    /// Returns the software versions used to create the image file
70    pub fn software_versions(&self) -> Result<impl Iterator<Item = &str>> {
71        Ok(self
72            .inner
73            .softwareVersions()?
74            .iter()
75            .filter_map(|cxx_str| cxx_str.to_str().ok()))
76    }
77
78    /// Returns the derivation description
79    /// Example: "PHILIPS UFS V1.6.6063 | Quality=1 | DWT=1 | Compressor=16"
80    pub fn derivation_description(&self) -> Result<&str> {
81        Ok(self.inner.derivationDescription()?.to_str()?)
82    }
83
84    /// Returns the acquisition DateTime of the image file
85    pub fn acquisition_date_time(&self) -> Result<&str> {
86        Ok(self.inner.acquisitionDateTime()?.to_str()?)
87    }
88
89    /// Returns the scanner manufacturer used to create the image file
90    pub fn manufacturer(&self) -> Result<&str> {
91        Ok(self.inner.manufacturer()?.to_str()?)
92    }
93
94    /// Returns the scanner model used to create the image file
95    pub fn model_name(&self) -> Result<&str> {
96        Ok(self.inner.modelName()?.to_str()?)
97    }
98
99    /// Returns the scanner serial number used to create the image file
100    pub fn device_serial_number(&self) -> Result<&str> {
101        Ok(self.inner.deviceSerialNumber()?.to_str()?)
102    }
103
104    /// Returns the scanner rack number used to create the image file
105    pub fn scanner_rack_number(&self) -> Result<u16> {
106        Ok(self.inner.scannerRackNumber()?)
107    }
108
109    /// Returns the scanner slot number used to create the image file
110    pub fn scanner_slot_number(&self) -> Result<u16> {
111        Ok(self.inner.scannerSlotNumber()?)
112    }
113
114    /// Returns the scanner operator id used to create the image file
115    pub fn scanner_operator_id(&self) -> Result<&str> {
116        Ok(self.inner.scannerOperatorId()?.to_str()?)
117    }
118
119    pub fn scanner_rack_priority(&self) -> Result<u16> {
120        Ok(self.inner.scannerRackPriority()?)
121    }
122
123    /// Returns the last calibration date of the scanner used to create the image file
124    pub fn date_of_last_calibration(&self) -> Result<impl Iterator<Item = &str>> {
125        Ok(self
126            .inner
127            .dateOfLastCalibration()?
128            .iter()
129            .filter_map(|cxx_str| cxx_str.to_str().ok()))
130    }
131
132    /// Returns the last calibration time of the scanner used to create the image file
133    pub fn time_of_last_calibration(&self) -> Result<impl Iterator<Item = &str>> {
134        Ok(self
135            .inner
136            .timeOfLastCalibration()?
137            .iter()
138            .filter_map(|cxx_str| cxx_str.to_str().ok()))
139    }
140
141    /// Returns true if the distributor of the image file is Philips
142    pub fn is_philips(&self) -> Result<bool> {
143        Ok(self.inner.isPhilips()?)
144    }
145
146    /// Returns true if the distributor of the image file is Hamamatsu
147    pub fn is_hamamatsu(&self) -> Result<bool> {
148        Ok(self.inner.isHamamatsu()?)
149    }
150
151    /// Returns true if the file was created by Philips Ultra Fast Scanner
152    pub fn is_ufs(&self) -> Result<bool> {
153        Ok(self.inner.isUFS()?)
154    }
155
156    pub fn is_ufsb(&self) -> Result<bool> {
157        Ok(self.inner.isUFSb()?)
158    }
159
160    pub fn is_uvs(&self) -> Result<bool> {
161        Ok(self.inner.isUVS()?)
162    }
163
164    /// Create a new instance of Image
165    /// An Image is a reference to a Philips Engine internal object
166    /// You can create multiple Image handler for every possible ImageType
167    /// WARNING: multiple Image handler created with the same image_type will points
168    /// to the same reference in Philips Engine internal.
169    pub fn image(&self, image_type: &ImageType) -> Result<Image<'_>> {
170        let_cxx_string!(image_type = image_type);
171        Ok(Image {
172            inner: self.inner.image(&image_type)?,
173            _lifetime: Default::default(),
174        })
175    }
176}
177
178impl ContainerName {
179    pub fn as_str(&self) -> &str {
180        match &self {
181            Self::Default => "",
182            Self::Ficom => "ficom",
183            Self::Dicom => "dicom",
184            Self::CachingFicom => "caching-ficom",
185            Self::S3 => "s3",
186            Self::Legacy => "legacy",
187        }
188    }
189}