FloatParameter.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. //------------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2018-2021 Basler AG
  4. // http://www.baslerweb.com
  5. //------------------------------------------------------------------------------
  6. /*!
  7. \file
  8. \brief Contains the class CFloatParameter used to simplify access to %GenApi parameters.
  9. */
  10. #ifndef INCLUDED_BASLER_PYLON_CFLOATPARAMETER_H
  11. #define INCLUDED_BASLER_PYLON_CFLOATPARAMETER_H
  12. #pragma once
  13. #include <pylon/PylonBase.h>
  14. #include <GenApi/IFloat.h>
  15. #include <pylon/Parameter.h>
  16. #ifdef _MSC_VER
  17. # pragma pack(push, PYLON_PACKING)
  18. #endif /* _MSC_VER */
  19. #ifdef _MSC_VER
  20. # pragma warning( push )
  21. # pragma warning( disable : 4275 ) // Class needs to have a dll interface to be used by clients of the class.
  22. # pragma warning( disable : 4250 ) // warning C4250: 'Pylon::CXYZParameter': inherits 'Pylon::CParameter::Pylon::CParameter::ZYX' via dominance
  23. #endif
  24. namespace Pylon
  25. {
  26. /// Lists possible float value correction strategies.
  27. enum EFloatValueCorrection
  28. {
  29. /// No correction is applied. If the value isn't valid for the parameter, an exception is thrown.
  30. FloatValueCorrection_None = 0,
  31. /// If the value is not in the valid range, the value is corrected to the valid range.
  32. FloatValueCorrection_ClipToRange = 3
  33. };
  34. class CIntegerParameter;
  35. /*!
  36. \brief Extends the GenApi::IFloat interface with convenience methods.
  37. */
  38. interface IFloatEx : virtual public GenApi::IFloat, virtual public IValueEx
  39. {
  40. using GenApi::IFloat::operator=;
  41. using GenApi::IFloat::SetValue;
  42. /*!
  43. \brief Sets the value of the parameter if the parameter is writable.
  44. \brief The value must be in the valid range and the increment must be correct.
  45. \return Returns false if the parameter is not writable.
  46. \param[in] value The value to set.
  47. <para>If the float parameter has an increment, the increment is automatically corrected.
  48. \pre
  49. <ul>
  50. <li>The passed value must be &gt;= GenApi::IFloat::GetMin().
  51. <li>The passed value must be &lt;= GenApi::IFloat::GetMax().
  52. </ul>
  53. \threading
  54. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  55. \error
  56. Can throw exceptions if the preconditions are not met or if writing the value fails.
  57. */
  58. virtual bool TrySetValue( double value ) = 0;
  59. /*!
  60. \brief Gets the value of the parameter if the parameter is readable.
  61. \brief Otherwise returns the default value.
  62. \return Returns the parameter value if the parameter is readable. Otherwise returns the default value.
  63. \param[in] defaultValue The default value returned if the parameter is not readable.
  64. \threading
  65. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  66. \error
  67. Can throw exception if reading the value fails.
  68. */
  69. virtual double GetValueOrDefault( double defaultValue ) = 0;
  70. /*!
  71. \brief Sets the value of the parameter if the parameter is writable and readable.
  72. \brief The value is automatically corrected if needed.
  73. \return Returns false if the parameter is not readable or not writable.
  74. \param[in] value The value to set.
  75. \param[in] correction The correction method.
  76. \note Calls TrySetValue(GenApi::IFloatParameter, double) if \c correction equals FloatValueCorrection_None.
  77. \threading
  78. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  79. \error
  80. Can throw exceptions if writing the value fails.
  81. */
  82. virtual bool TrySetValue( double value, EFloatValueCorrection correction ) = 0;
  83. /*!
  84. \brief Sets the value of the parameter. The value is automatically corrected if needed.
  85. \param[in] value The value to set.
  86. \param[in] correction The correction method.
  87. \pre
  88. <ul>
  89. <li>The parameter must be writable.
  90. <li>The parameter must be readable.
  91. </ul>
  92. \note Calls GenApi::IFloatParameter::SetValue(double) if \c correction equals FloatValueCorrection_None.
  93. \threading
  94. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  95. \error
  96. Can throw exceptions if the preconditions are not met or if writing the value fails.
  97. */
  98. virtual void SetValue( double value, EFloatValueCorrection correction ) = 0;
  99. /*!
  100. \brief Gets the value of the parameter in percent of its value range (from minimum to maximum).
  101. \return Returns the parameter value in percent of its value range. Returns 100 if minimum equals maximum.
  102. \pre The parameter must be readable.
  103. \threading
  104. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  105. \error
  106. Can throw exceptions if writing the value fails.
  107. */
  108. virtual double GetValuePercentOfRange() = 0;
  109. /*!
  110. \brief Sets the value of the parameter to a value within its range, using this formula (simplified): ((max - min) * (percentOfRange / 100.0)) + min.
  111. \param[in] percentOfRange The percentage of the range to be used in the calculation.
  112. \pre
  113. <ul>
  114. <li>The parameter must be writable.
  115. <li>The parameter must be readable.
  116. </ul>
  117. \threading
  118. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  119. \error
  120. Can throw exceptions if writing the value fails.
  121. */
  122. virtual void SetValuePercentOfRange( double percentOfRange ) = 0;
  123. /*!
  124. \brief If the parameter is writable and readable, sets the value of the parameter to a value within its range, using this formula (simplified): ((max - min) * (percentOfRange / 100.0)) + min.
  125. \return Returns true if the value has been set.
  126. \param[in] percentOfRange The percentage of the range used in the calculation. Valid values are in the range of 0 to 100.
  127. \threading
  128. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  129. \error
  130. Can throw exceptions if writing the value fails.
  131. */
  132. virtual bool TrySetValuePercentOfRange( double percentOfRange ) = 0;
  133. /*!
  134. \brief Sets the parameter value to the maximum possible value.
  135. \pre
  136. <ul>
  137. <li>The parameter must be writable.
  138. <li>The parameter must be readable.
  139. </ul>
  140. \threading
  141. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  142. \error
  143. Can throw exceptions if the parameter is not writable, not readable, or if reading or writing fails.
  144. */
  145. virtual void SetToMaximum() = 0;
  146. /*!
  147. \brief Sets the parameter value to the minimum possible value.
  148. \pre
  149. <ul>
  150. <li>The parameter must be writable.
  151. <li>The parameter must be readable.
  152. </ul>
  153. \threading
  154. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  155. \error
  156. Can throw exceptions if the parameter is not writable, not readable, or if reading or writing fails.
  157. */
  158. virtual void SetToMinimum() = 0;
  159. /*!
  160. \brief Sets the parameter value to the maximum possible value if the parameter is readable and writable.
  161. \return Returns true if the maximum value has been set.
  162. \threading
  163. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  164. \error
  165. Can throw exceptions if reading or writing fails.
  166. */
  167. virtual bool TrySetToMaximum() = 0;
  168. /*!
  169. \brief Sets the parameter value to the minimum possible value if the parameter is readable and writable.
  170. \return Returns true if the minimum value has been set.
  171. \threading
  172. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  173. \error
  174. Can throw exceptions if reading or writing fails.
  175. */
  176. virtual bool TrySetToMinimum() = 0;
  177. /*!
  178. \brief Gets the alternative integer representation of the float parameter, if available.
  179. The alternative integer representation is typically used if a parameter is represented as a
  180. float value in the node map, but as an integer register in the camera device.
  181. \param[out] parameter The integer representation returned. The returned value will be empty if no alternative representation is available.
  182. \threading
  183. The method accesses the parameter multiple times. These accesses are not synchronized by a lock.
  184. \error
  185. Can throw exceptions.
  186. */
  187. virtual void GetAlternativeIntegerRepresentation( CIntegerParameter& parameter ) = 0;
  188. };
  189. /*!
  190. \brief CFloatParameter class used to simplify access to %GenApi parameters.
  191. */
  192. class PYLONBASE_API CFloatParameter : public IFloatEx, public CParameter
  193. {
  194. public:
  195. /*!
  196. \brief Creates an empty CFloatParameter object.
  197. \error
  198. Does not throw C++ exceptions.
  199. */
  200. CFloatParameter();
  201. /*!
  202. \brief Creates a CFloatParameter object and attaches it to a node, typically retrieved for a nodemap calling GetNode().
  203. \param[in] pNode The node to attach.
  204. \post
  205. <ul>
  206. <li>If the passed node does not match the parameter type, the parameter will be empty, see IsValid().
  207. <li>If the passed node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  208. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  209. </ul>
  210. \error
  211. Does not throw C++ exceptions.
  212. */
  213. explicit CFloatParameter( GenApi::INode* pNode );
  214. /*!
  215. \brief Creates a CFloatParameter object and attaches it to a node of a matching type.
  216. \param[in] pFloat The node to attach.
  217. \post
  218. The parameter object must not be used to access the node's functionality if the source of the attached \c pFloat has been destroyed. In this case, call Release() or attach a new node.
  219. \error
  220. Does not throw C++ exceptions.
  221. */
  222. explicit CFloatParameter( GenApi::IFloat* pFloat );
  223. /*!
  224. \brief Creates a CFloatParameter object and attaches it to a node retrieved from the provided node map.
  225. \param[in] pNodeMap The node map. The source of the parameter.
  226. \param[in] pName The name of the parameter to attach.
  227. \post
  228. <ul>
  229. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  230. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  231. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  232. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  233. </ul>
  234. \error
  235. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  236. */
  237. CFloatParameter( GenApi::INodeMap* pNodeMap, const char* pName );
  238. /*!
  239. \brief Creates a CFloatParameter object and attaches it to a node retrieved from the provided node map.
  240. \param[in] nodeMap The node map. The source of the parameter.
  241. \param[in] pName The name of the parameter to attach.
  242. \post
  243. <ul>
  244. <li>If \c name is NULL, the parameter will be empty, see IsValid().
  245. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  246. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  247. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  248. </ul>
  249. \error
  250. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  251. */
  252. CFloatParameter( GenApi::INodeMap& nodeMap, const char* pName );
  253. /*!
  254. \brief Copies a CFloatParameter object.
  255. \param[in] rhs The object to copy.
  256. \error
  257. Does not throw C++ exceptions.
  258. */
  259. CFloatParameter( const CFloatParameter& rhs );
  260. /*!
  261. \brief Destroys the CFloatParameter object.
  262. Does not access the attached node.
  263. \error
  264. Does not throw C++ exceptions.
  265. */
  266. virtual ~CFloatParameter();
  267. /*!
  268. \brief Attaches a node retrieved from the provided node map.
  269. \param[in] pNodeMap The node map. The source of the parameter.
  270. \param[in] pName The name of the parameter to attach.
  271. \return Returns true if the node has been attached.
  272. \post
  273. <ul>
  274. <li>If \c pNodeMap or \c name is NULL, the parameter will be empty, see IsValid().
  275. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  276. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  277. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  278. </ul>
  279. \error
  280. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  281. */
  282. virtual bool Attach( GenApi::INodeMap* pNodeMap, const char* pName );
  283. /*!
  284. \brief Attaches a node retrieved from the provided node map.
  285. \param[in] nodeMap The node map. The source of the parameter.
  286. \param[in] pName The name of the parameter to attach.
  287. \return Returns true if the node has been attached.
  288. \post
  289. <ul>
  290. <li>If \c name is NULL the parameter will be empty, see IsValid().
  291. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  292. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  293. <li>The parameter object must not be used to access the node's functionality if the provided node map has been destroyed. In this case, call Release() or attach a new node.
  294. </ul>
  295. \error
  296. The call to GenApi::INodeMap::GetNode can throw C++ exceptions.
  297. */
  298. virtual bool Attach( GenApi::INodeMap& nodeMap, const char* pName );
  299. /*!
  300. \brief Attaches a node, typically retrieved for a nodemap calling GetNode().
  301. \param[in] pNode The node to assign.
  302. \return Returns true if the node has been attached.
  303. \post
  304. <ul>
  305. <li>If the node does not match the parameter type, the parameter will be empty, see IsValid().
  306. <li>If the node does match the parameter type, it is attached and the parameter object can be used to access the node's functionality.
  307. <li>The parameter object must not be used to access the node's functionality if the source of the attached \c pNode has been destroyed. In this case, call Release() or attach a new node.
  308. </ul>
  309. \error
  310. Does not throw C++ exceptions.
  311. */
  312. virtual bool Attach( GenApi::INode* pNode );
  313. /*!
  314. \brief Assigns a node of the same type to the parameter object.
  315. \param[in] pFloat The node to assign.
  316. \return Returns true if the node has been attached.
  317. \error
  318. Does not throw C++ exceptions.
  319. */
  320. virtual bool Attach( GenApi::IFloat* pFloat );
  321. /*!
  322. \brief Assigns a CFloatParameter object.
  323. \param[in] rhs The object to assign.
  324. \error
  325. Does not throw C++ exceptions.
  326. */
  327. CFloatParameter& operator=( const CFloatParameter& rhs );
  328. /*!
  329. \brief Returns true if the same nodes are attached or both parameters are empty.
  330. \param[in] rhs The object to compare to.
  331. \return Returns true if the same nodes are attached or both parameters are empty.
  332. \error
  333. Does not throw C++ exceptions.
  334. */
  335. virtual bool Equals( const CFloatParameter& rhs ) const;
  336. /*!
  337. \brief Returns true if the attached node pointer is equal.
  338. \param[in] pNode The node to compare to.
  339. \return Returns true if the attached node pointer is equal.
  340. \error
  341. Does not throw C++ exceptions.
  342. */
  343. virtual bool Equals( const GenApi::INode* pNode ) const;
  344. /*!
  345. \brief Returns true if the attached node pointer is equal.
  346. \param[in] pFloat The node to compare to.
  347. \return Returns true if the attached node pointer is equal.
  348. \error
  349. Does not throw C++ exceptions.
  350. */
  351. virtual bool Equals( const GenApi::IFloat* pFloat ) const;
  352. /*!
  353. \brief Releases the attached node.
  354. \error
  355. Does not throw C++ exceptions.
  356. */
  357. virtual void Release();
  358. // Implements IValueEx
  359. virtual bool IsValid() const;
  360. // Implements GenApi::IFloat
  361. virtual void SetValue( double value, bool verify = true );
  362. // Implements GenApi::IFloat
  363. virtual GenApi::IFloat& operator=( double value );
  364. // Implements GenApi::IFloat
  365. virtual double GetValue( bool verify = false, bool ignoreCache = false );
  366. // Implements GenApi::IFloat
  367. virtual double operator()();
  368. // Implements GenApi::IFloat
  369. virtual double operator*();
  370. // Implements GenApi::IFloat
  371. virtual double GetMin();
  372. // Implements GenApi::IFloat
  373. virtual double GetMax();
  374. // Implements GenApi::IFloat
  375. virtual bool HasInc();
  376. // Implements GenApi::IFloat
  377. virtual GenApi::EIncMode GetIncMode();
  378. // Implements GenApi::IFloat
  379. virtual double GetInc();
  380. // Implements GenApi::IFloat
  381. virtual GenApi::double_autovector_t GetListOfValidValues( bool bounded = true );
  382. // Implements GenApi::IFloat
  383. virtual GenApi::ERepresentation GetRepresentation();
  384. // Implements GenApi::IFloat
  385. virtual GenICam::gcstring GetUnit() const;
  386. // Implements GenApi::IFloat
  387. virtual GenApi::EDisplayNotation GetDisplayNotation() const;
  388. // Implements GenApi::IFloat
  389. virtual int64_t GetDisplayPrecision() const;
  390. // Implements GenApi::IFloat
  391. virtual void ImposeMin( double value );
  392. // Implements GenApi::IFloat
  393. virtual void ImposeMax( double value );
  394. // Implements IFloatEx
  395. virtual bool TrySetValue( double value );
  396. // Implements IFloatEx
  397. virtual double GetValueOrDefault( double defaultValue );
  398. // Implements IFloatEx
  399. virtual bool TrySetValue( double value, EFloatValueCorrection correction );
  400. // Implements IFloatEx
  401. virtual void SetValue( double value, EFloatValueCorrection correction );
  402. // Implements IFloatEx
  403. virtual double GetValuePercentOfRange();
  404. // Implements IFloatEx
  405. virtual void SetValuePercentOfRange( double percentOfRange );
  406. // Implements IFloatEx
  407. virtual bool TrySetValuePercentOfRange( double percentOfRange );
  408. // Implements IFloatEx
  409. virtual void SetToMaximum();
  410. // Implements IFloatEx
  411. virtual void SetToMinimum();
  412. // Implements IFloatEx
  413. virtual bool TrySetToMaximum();
  414. // Implements IFloatEx
  415. virtual bool TrySetToMinimum();
  416. // Implements IFloatEx
  417. virtual void GetAlternativeIntegerRepresentation( CIntegerParameter& parameter );
  418. protected:
  419. GenApi::IFloat* m_pFeature;
  420. };
  421. }
  422. #ifdef _MSC_VER
  423. # pragma warning( pop )
  424. #endif
  425. #ifdef _MSC_VER
  426. # pragma pack(pop)
  427. #endif /* _MSC_VER */
  428. #endif /* INCLUDED_BASLER_PYLON_CFLOATPARAMETER_H */