acdmmeplotproperties.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. // AcDMMEPlotProperties.h
  13. // the proxy EPlotProperties object
  14. //
  15. #ifndef AcDMMEPlotProperties_h
  16. #define AcDMMEPlotProperties_h
  17. #include "AcDMMEPlotProperty.h"
  18. #include "AcDMMUtils.h"
  19. /////////////////////////////////////////////////////////////////////
  20. // class AcDMMEPlotProperties
  21. /////////////////////////////////////////////////////////////////////
  22. /// <summary>
  23. /// This class is a lighweight proxy for the DWF EPlotProperties class which is
  24. /// used by the DMM (DWF Metadata Manager) API to allow clients to
  25. /// associate entity properties with DWF geometry without linking to
  26. /// the DWF toolkit. This class contains the data but not the behavior
  27. /// of the corresponding DWF toolkit object.
  28. /// </summary>
  29. ///
  30. /// <remarks>
  31. /// Note that all strings are Unicode. XML encoding will be done by the
  32. /// DMM when the proxy object is converted to the corresponding DWF
  33. /// toolkit object.
  34. /// </remarks>
  35. ///
  36. class AcDMMEPlotProperties
  37. {
  38. public:
  39. /// <summary>
  40. /// Default constructor
  41. /// </summary>
  42. ///
  43. /// <remarks>
  44. /// Constructs an empty AcDMMEPlotProperties object.
  45. /// </remarks>
  46. ///
  47. AcDMMEPlotProperties()
  48. : m_id(NULL)
  49. {
  50. }
  51. /// <summary>
  52. /// Copy constructor
  53. /// </summary>
  54. ///
  55. /// <param name="src">
  56. /// the object to be copied
  57. /// </param>
  58. ///
  59. AcDMMEPlotProperties(const AcDMMEPlotProperties &src)
  60. : m_id(NULL)
  61. {
  62. *this = src;
  63. }
  64. /// <summary>
  65. /// Destructor
  66. /// </summary>
  67. ///
  68. ~AcDMMEPlotProperties()
  69. {
  70. m_properties.removeAll();
  71. m_refs.removeAll();
  72. if (NULL != m_id)
  73. delete m_id;
  74. }
  75. /// <summary>
  76. /// Adds a new AcDMMEPlotProperty object to the internal vector of
  77. /// properties
  78. /// </summary>
  79. ///
  80. /// <param name="property">
  81. /// the property to be added to this Properties list
  82. /// </param>
  83. ///
  84. void AddProperty(const AcDMMEPlotProperty * property)
  85. {
  86. if (NULL == property)
  87. return;
  88. m_properties.append(*property);
  89. }
  90. /// <summary>
  91. /// Creates and adds a new AcDMMEPlotProperty object to the internal
  92. /// vector of properties.
  93. /// </summary>
  94. ///
  95. /// <param name="name">
  96. /// the new property's name
  97. /// </param>
  98. ///
  99. /// <param name="value">
  100. /// the new property's value
  101. /// </param>
  102. ///
  103. void AddProperty(wchar_t * name, wchar_t *value)
  104. {
  105. AcDMMEPlotProperty newProp(name, value);
  106. m_properties.append(newProp);
  107. }
  108. /// <summary>
  109. /// accessor for the internal vector of AcDMMEPlotProperty objects
  110. /// contained by this object
  111. /// </summary>
  112. ///
  113. /// <returns>
  114. /// Returns a const reference to the internal Vector of
  115. /// AcDMMEPlotProperty objects contained by this object
  116. /// </returns>
  117. const AcDMMEPlotPropertyVec& GetProperties() const
  118. {
  119. return m_properties;
  120. }
  121. /// <summary>
  122. /// accessor for individual properties in the internal vector of
  123. /// AcDMMEPlotProperties contained in this object
  124. /// </summary>
  125. ///
  126. /// <param name="index">
  127. /// the zero based index of the desired property
  128. /// </param>
  129. ///
  130. /// <returns>
  131. /// Returns a const pointer to the EPlotProperty object at the given
  132. /// 0-based index.
  133. /// </returns>
  134. ///
  135. /// <remarks>
  136. /// warning - May overflow the internal Vector array. Clients should
  137. /// check GetProperties().size() before calling this method.
  138. /// </remarks>
  139. ///
  140. const AcDMMEPlotProperty * GetProperty(unsigned long index) const
  141. {
  142. if (m_properties.length() <= (int)index)
  143. return NULL;
  144. return &m_properties[index];
  145. }
  146. /// <summary>
  147. /// mutator for the Id attribute of this object
  148. /// </summary>
  149. ///
  150. /// <param name="id">
  151. /// the Unicode unique identifier the client assigns to this object.
  152. /// </param>
  153. ///
  154. /// <remarks>
  155. /// The unique identifier for this EPlotProperties element (can be
  156. /// a name, a GUID, etc.). It is preferred for this string to be
  157. /// prefixed with the client application name to distinguish its
  158. /// properties from those of other clients
  159. /// The EPlotProperties element, when used in an ObjectDefinition resource,
  160. /// can be referenced by other "child" EPlotProperties elements, thereby
  161. /// creating an efficient hierarchy of properties.
  162. /// WARNING - these Ids are processed in a space delimited list. Your
  163. /// properties will not behave as expected if the Id contains spaces.
  164. /// </remarks>
  165. void SetId(const wchar_t * id)
  166. {
  167. if (NULL != m_id)
  168. delete m_id;
  169. if (NULL != id) {
  170. size_t nSize = ::wcslen(id) + 1;
  171. m_id = new wchar_t[nSize];
  172. errno_t err =::wcscpy_s(m_id, nSize, id);
  173. assert(err == 0);
  174. } else
  175. m_id = NULL;
  176. }
  177. /// <summary>
  178. /// accessor for the Id attribute.
  179. /// </summary>
  180. ///
  181. /// <returns>
  182. /// returns a const pointer to the Unicode string which is the unique
  183. /// identifier assigned by the client to this object.
  184. /// </returns>
  185. ///
  186. /// <remarks>
  187. /// Returns the unique identifier for this AcDMMEPlotProperties element.
  188. /// </remarks>
  189. const wchar_t * GetId() const
  190. {
  191. return m_id;
  192. }
  193. /// <summary>
  194. /// Sets the vector of the unique identifiers of the EPlotProperties
  195. /// objects referenced (inherited) by this object.
  196. /// </summary>
  197. ///
  198. /// <param name="refs">
  199. /// a const reference to a vector of Unicode string identifications
  200. /// of additional AcDMMEPlotProperties objects
  201. /// </param>
  202. ///
  203. /// <remarks>
  204. /// The properties in the referenced EPlotProperties objects should be
  205. /// considered part of this EPlotProperties instance as if they were
  206. /// contained directly by this instance.
  207. /// </remarks>
  208. void SetRefs(const AcDMMStringVec& refs)
  209. {
  210. m_refs.removeAll();
  211. for (int i = 0; i < refs.length(); i++)
  212. m_refs.append(refs.at(i));
  213. }
  214. /// <summary>
  215. /// accessor for the vector of Unicode string identifications of
  216. /// referenced AcDMMEPlotProperties objects
  217. /// </summary>
  218. ///
  219. /// <returns>
  220. /// a const pointer to the vector of Unicode string identifications of
  221. /// referenced AcDMMEPlotProperties objects
  222. /// </returns>
  223. const AcDMMStringVec * GetRefs() const
  224. {
  225. return &m_refs;
  226. }
  227. /// <summary>
  228. /// operator= also used by copy constructor
  229. /// </summary>
  230. ///
  231. /// <param name="src">
  232. /// the object whose values will be copied to this object
  233. /// </param>
  234. ///
  235. /// <returns>
  236. /// returns this object
  237. /// </returns>
  238. AcDMMEPlotProperties& operator= (const AcDMMEPlotProperties &src)
  239. {
  240. if (this == &src)
  241. return *this;
  242. m_properties.removeAll();
  243. for (int i = 0; i < src.m_properties.length(); i++)
  244. m_properties.append(src.m_properties.at(i));
  245. SetId(src.m_id);
  246. SetRefs(src.m_refs);
  247. return *this;
  248. }
  249. private:
  250. AcDMMEPlotPropertyVec m_properties;
  251. wchar_t * m_id; /**< Unique identifier for this object. */
  252. AcDMMStringVec m_refs; /**< Contains a list of EPlotProperties ID's.*/
  253. };
  254. #endif // AcDMMEPlotProperties_h