AcDbAssocArrayActionBody.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2015 Autodesk, Inc. All rights reserved.
  4. //
  5. // Use of this software is subject to the terms of the Autodesk license
  6. // agreement provided at the time of installation or download, or which
  7. // otherwise accompanies this software in either electronic or hard copy form.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // CREATED BY: Sharad Jaiswal March 2010
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #pragma once
  15. #include "AcDbAssocParamBasedActionBody.h"
  16. #include "AcDbAssocArrayItem.h"
  17. class AcDbAssocArrayParameters;
  18. /// <summary><para>
  19. /// AcDbAssocArrayActionBody class is an associative action which evaluates
  20. /// to manage or position array items. This class in general manages assoc
  21. /// dependencies on various objects related to associative array entity.
  22. /// </para><para>
  23. /// Array enity is generally represented as block reference enity, which
  24. /// references array block table record (array BTR). Array BTR contains a list
  25. /// of entities to represent items in the array. By default this class
  26. /// represents an array item as an instance of AcDbBlocReference referencing a
  27. /// the source block table record (source BTR) positioned at item transform.
  28. /// </para><para>
  29. /// Derived classes may override array items and may choose to represent them
  30. /// differently.
  31. /// </para></summary>
  32. /// <remarks> Deriving from this class is not supported. </remarks>
  33. ///
  34. class ACDB_PORT AcDbAssocArrayActionBody : public AcDbAssocParamBasedActionBody
  35. {
  36. public:
  37. ACRX_DECLARE_MEMBERS(AcDbAssocArrayActionBody);
  38. /// <summary> Default constructor. </summary>
  39. /// <param name="createImpObject"> See AcDbAssocCreateImpObject. </param>
  40. ///
  41. explicit AcDbAssocArrayActionBody(AcDbAssocCreateImpObject createImpObject = kAcDbAssocCreateImpObject);
  42. /// <summary> Destructor. </summary>
  43. ///
  44. virtual ~AcDbAssocArrayActionBody(void);
  45. /// <summary> Obtains parameters for read. This object must be opened
  46. /// at least for read. This method will get invoked only if it is called
  47. /// on const AcDbAssocArrayActionBody object. </summary>
  48. /// <returns> Pointer to AcDbAssocArrayParameters. </returns>
  49. ///
  50. const AcDbAssocArrayParameters* parameters() const;
  51. /// <summary> Obtains parameters for write. This object must be opened
  52. /// at least for write. </summary>
  53. /// <returns> Pointer to AcDbAssocArrayParameters. </returns>
  54. ///
  55. AcDbAssocArrayParameters* parameters();
  56. /// <summary> Marks the item at given index for erase/unerase. The item at
  57. /// given index goes to hidden state, when marked erased. </summary>
  58. /// <param name="index"> The input spatial index. </param>
  59. /// <param name="bErase"> The input flag, whether erase or unerase.</param>
  60. /// <returns> Acad::ErrorStatus </returns>
  61. ///
  62. Acad::ErrorStatus deleteItem(const AcDbItemLocator& index, bool bErase = true);
  63. /// <summary> Applies a relative transform to an item at given index and
  64. /// this transform is remembered by the action body. So when this action
  65. /// reconfigures all its items, the effect of this additional transform
  66. /// will be still be present to the item at given index.
  67. /// </summary>
  68. /// <param name="index"> The input spatial index. </param>
  69. /// <param name="xform"> The input transformation. </param>
  70. /// <returns> Acad::ErrorStatus </returns>
  71. ///
  72. Acad::ErrorStatus transformItemBy(const AcDbItemLocator& index,
  73. const AcGeMatrix3d& xform);
  74. /// <summary> Gets indices of all the items owned by this array.</summary>
  75. /// <param name="indices"> The output list of spatial indices. </param>
  76. /// <param name="skipErased"> The input flag, whether to skip erased items.
  77. /// </param>
  78. void getItems(AcArray<AcDbItemLocator>& indices, bool skipErased = true) const;
  79. /// <summary> Obtains array item at given index as well as subent path of
  80. /// the item. </summary>
  81. /// <param name="index"> The input spatial index. </param>
  82. /// <param name="path"> Returned subent path of item at given index. </param>
  83. /// <returns> Pointer to AcDbAssocArrayItem at given index, NULL if item is
  84. /// not available at given index. </returns>
  85. /// <remarks> Subent type for the returned path is AcDb::kClassSubentType,
  86. /// to represent array item. </remarks>
  87. ///
  88. const AcDbAssocArrayItem* getItemAt(const AcDbItemLocator& index,
  89. AcDbFullSubentPath& path) const;
  90. inline const AcDbAssocArrayItem* getItemAt(const AcDbItemLocator& index) const
  91. {
  92. AcDbFullSubentPath path = AcDbFullSubentPath();
  93. return getItemAt(index, path);
  94. }
  95. /// <summary> Obtains array item at given subent path of the array.
  96. /// </summary>
  97. /// <param name="path"> The input subent path of the array. </param>
  98. /// <returns> Pointer to AcDbAssocArrayItem at given path, NULL if item is
  99. /// not available at given path. </returns>
  100. /// <remarks> The input subent path must point to an entity to locate the
  101. /// array item properly. </remarks>
  102. ///
  103. const AcDbAssocArrayItem* getItemAt(const AcDbFullSubentPath& path) const;
  104. /// <summary> Implements evaluation logic for this action. This method is
  105. /// called by Associative Framework when the owning network is getting
  106. /// evaluated and this action needs to be evaluated. </summary>
  107. ///
  108. virtual void evaluateOverride() ADESK_OVERRIDE;
  109. /// <summary> Obtains object id of the associative array controlled by this
  110. /// action. </summary>
  111. /// <returns> AcDbObjectId of the array entity. </returns>
  112. ///
  113. virtual AcDbObjectId getArrayEntity() const;
  114. /// <summary> <para> An item in an associative array can be controlled
  115. /// either by the action which has created it or by another action which
  116. /// modifies this item. </para><para>
  117. /// This method checks whether the given item is controlled by this
  118. /// action. This method returns false in two condition if the index is out
  119. /// of range or this action is a modification action and doesn't modify
  120. /// the given item. </para></summary>
  121. /// <param name="index"> The input spatial index. </param>
  122. /// <returns> true, if the item is controlled by this action. </returns>
  123. ///
  124. virtual bool controlsItem(const AcDbAssocArrayItem& index) const;
  125. /// <summary> Transforms the array group/entity by given transform.
  126. /// </summary>
  127. /// <param name="xform"> The input transform. </param>
  128. /// <returns> Acad::ErrorStatus </returns>
  129. ///
  130. virtual Acad::ErrorStatus transformBy(const AcGeMatrix3d& xform);
  131. /// <summary> Returns transformation matrix applied to the array group
  132. /// or entity. </summary>
  133. /// <returns> AcGeMatrix3d. </returns>
  134. ///
  135. virtual AcGeMatrix3d getTransform() const;
  136. //Methods related to source entities.
  137. /// <summary> Obtains list of source entities for this action. </summary>
  138. /// <returns> List of source entities used by the action. </returns>
  139. ///
  140. AcDbObjectIdArray getSourceEntities() const;
  141. /// <summary> Adds the given entity to the list of source items and updates
  142. /// each item in the array controlled by this action. The added source entity
  143. /// will be sent to hidden locked layer and will be managed by this action.
  144. /// </summary>
  145. /// <param name="entity"> The input entity to add. </param>
  146. /// <param name="basePoint"> The input reference point in WCS. This point
  147. /// will be used as reference to reposition the newly added source entity.
  148. /// </param>
  149. /// <returns> Acad::ErrorStatus. </returns>
  150. ///
  151. Acad::ErrorStatus addSourceEntity(AcDbObjectId entity,
  152. const AcGePoint3d& basePoint);
  153. /// <summary> Removes the given entity from the list of source items and
  154. /// updates each item in the array controlled by this action. </summary>
  155. /// <param name="entity"> The input entity to remove. </param>
  156. /// <returns> Acad::ErrorStatus. </returns>
  157. ///
  158. Acad::ErrorStatus removeSourceEntity(AcDbObjectId entity);
  159. /// <summary> <para>Sets base point for the source objects.
  160. /// Base point is a relative point with respect to source entities using
  161. /// which source entities are transformed in the array pattern.
  162. /// </para><para>
  163. /// Base point can be defined as constant point or a reference point. This
  164. /// point defines grip position on first item (i.e at 0,0,0) in array.
  165. /// This method may change array parameters in order to minimize changes
  166. /// in array object representation.
  167. /// </para><para>
  168. /// </para></summary>
  169. /// <param name="basePoint"> The input base point. </param>
  170. /// <returns> Acad::ErrorStatus. </returns>
  171. ///
  172. Acad::ErrorStatus setSourceBasePoint(const AcDbVertexRef& basePoint);
  173. /// <summary> Gets base point definition for the source objects.</summary>
  174. /// <param name="vertexRef"> The output vertex reference point. The point
  175. /// evaluated on vertexRef may not match with the output position of base
  176. /// point, as it is evaluated in the space of source BTR.</param>
  177. /// <param name="position"> The output position for base point. </param>
  178. /// <returns> Acad::ErrorStatus. </returns>
  179. ///
  180. Acad::ErrorStatus getSourceBasePoint(AcDbVertexRef& vertexRef,
  181. AcGePoint3d& position) const;
  182. //utility methods.
  183. /// <summary> Checks if the given entity is an associative array.
  184. /// </summary>
  185. /// <param name="pEntity"> The input entity. </param>
  186. /// <returns> true, if the input entity is an array. </returns>
  187. ///
  188. static bool isAssociativeArray(const AcDbEntity* pEntity);
  189. /// <summary> Obtains creation or modification array action body id
  190. /// controlling the given array item. Passing NULL pItemIndex will return
  191. /// array creation action body. If the given entity is not an associative
  192. /// array, this method will return null object id.
  193. /// </summary>
  194. /// <param name="pEntity"> The input entity. </param>
  195. /// <param name="pItemIndex"> Pointer of array item index. </param>
  196. /// <returns> AcDbObjectId of array action body controlling given array
  197. /// item. </returns>
  198. ///
  199. static AcDbObjectId getControllingActionBody(const AcDbEntity* pEntity,
  200. const AcDbItemLocator* pItemIndex = NULL);
  201. /// <summary> Extracts array items from the array group as individual items
  202. /// and removes associativity from the arrayed items controlled by
  203. /// array action. It also erases the action. Normally erasing array action
  204. /// will erase all the arrayed items controlled by the action.
  205. /// </summary>
  206. /// <param name="pEntity"> The input entity. </param>
  207. /// <param name="newIds"> The output exploded entity ids. </param>
  208. /// <returns> Acad::ErrorStatus </returns>
  209. ///
  210. static Acad::ErrorStatus explode(AcDbEntity* pEntity,
  211. AcDbObjectIdArray& newIds);
  212. /// <summary> Removes item override such as position, orientation or
  213. /// object replacement, from the list of given items or all items of an
  214. /// associative array.
  215. /// </summary>
  216. /// <param name="arrayEntityId"> The input object id for array entity.
  217. /// </param>
  218. /// <param name="indices"> The input list of item indices which needs to
  219. /// be reset. This parameter will be ignored if resetAll is true.</param>
  220. /// <param name="resetAll"> The input flag to indicate, whether all items
  221. /// of array needs to be reset.</param>
  222. /// <returns> Acad::ErrorStatus </returns>
  223. ///
  224. static Acad::ErrorStatus resetArrayItems(AcDbObjectId arrayEntityId,
  225. const AcArray<AcDbItemLocator>& indices, bool resetAll = false);
  226. /// <summary> Obtains list of AcDbItemLocator for given set of subents of
  227. /// an associative array. The subents provided should be subentity of array
  228. /// item.
  229. /// </summary>
  230. /// <param name="subents"> The input list of item subent path. </param>
  231. /// <param name="indices"> The output list of AcDbItemLocator for given
  232. /// list of subents. </param>
  233. /// <returns> Acad::ErrorStatus </returns>
  234. /// <remarks> The input subent path must point to an entity to locate the
  235. /// array item properly. </remarks>
  236. ///
  237. static Acad::ErrorStatus getArrayItemLocators(
  238. const AcDbFullSubentPathArray& subents, AcArray<AcDbItemLocator>& indices);
  239. /// <summary> <para> Creates associative array action body as well as array
  240. /// entity with given parameters and source entities This method is
  241. /// responsible creating action and attaching appropriate dependencies.
  242. /// </para><para> Caller must evaluate top level network after calling this
  243. /// method. Non-associative array can be created by calling explode method
  244. /// after this action is properly evaluated. </para></summary>
  245. /// <param name="sourceEntites"> The input list of source entities. </param>
  246. /// <param name="basePoint"> The input vertex ref to define base point.
  247. /// Base point is a relative point with respect to source entities using
  248. /// which source entities are transformed in the array pattern.
  249. /// </param>
  250. /// <param name="pParameters"> The input parameters for array. </param>
  251. /// <param name="arrayId"> The returned array object id. </param>
  252. /// <param name="actionBodyId"> The returned array action body id. </param>
  253. /// <returns> Acad::ErrorStatus </returns>
  254. ///
  255. static Acad::ErrorStatus createInstance(const AcDbObjectIdArray& sourceEntites,
  256. AcDbVertexRef& basePoint, const AcDbAssocArrayParameters* pParameters,
  257. AcDbObjectId& arrayId, AcDbObjectId& actionBodyId);
  258. /// <summary> Returns owning block table record for the source items.
  259. /// </summary>
  260. /// <returns> AcDbObjectId of source BTR. </returns>
  261. ///
  262. AcDbObjectId getArraySourceBTR() const;
  263. /// <summary>
  264. /// This method is called by associative framework when any of the dependent
  265. /// entity is being cloned. This is override of base class method. See the
  266. /// description of AcDbAssocAction::addMoreObjectsToDeepClone for more info.
  267. /// </summary>
  268. /// <param name="idMap"> The input AcDbIdMapping object.</param>
  269. /// <param name="additionalObjectsToClone"> The input list of AcDbObjectIds
  270. /// to be cloned. </param>
  271. /// <returns> Acad::ErrorStatus </returns>
  272. ///
  273. virtual Acad::ErrorStatus addMoreObjectsToDeepCloneOverride(AcDbIdMapping& idMap,
  274. AcDbObjectIdArray& additionalObjectsToClone) const ADESK_OVERRIDE;
  275. /// <summary>
  276. /// This method is called by associative framework when any of the dependent
  277. /// entity is being cloned. This is override of base class method. See the
  278. /// description of AcDbAssocAction::postProcessAfterDeepClone for more info.
  279. /// </summary>
  280. /// <param name="idMap"> The input AcDbIdMapping object. </param>
  281. /// <returns> Acad::ErrorStatus </returns>
  282. ///
  283. virtual Acad::ErrorStatus postProcessAfterDeepCloneOverride(
  284. AcDbIdMapping& idMap) ADESK_OVERRIDE;
  285. /// <summary>
  286. /// This function is called to notify the action when a there is a drag
  287. /// operation in progress and some objects the action depends on, either
  288. /// directly or indirectly, are being dragged. This is override of base
  289. /// class method.
  290. /// </summary>
  291. /// <param name="status"> See the AcDb::DragStat enum. </param>
  292. /// <returns> Acad::ErrorStatus </returns>
  293. ///
  294. virtual Acad::ErrorStatus dragStatusOverride(const AcDb::DragStat status) ADESK_OVERRIDE;
  295. };