IntegerParameter.h 20 KB

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