DbField.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. // Name: DbField.h
  13. //
  14. // Description: AcDbObject derived API classes for fields.
  15. // Contains the following classes:
  16. // AcDbField
  17. //////////////////////////////////////////////////////////////////////////////
  18. #pragma once
  19. #include "AdAChar.h"
  20. #include "AcField.h"
  21. #include "acstring.h"
  22. class AcDbField;
  23. typedef AcArray<AcDbField*> AcDbFieldArray;
  24. //*************************************************************************
  25. // AcFd
  26. //*************************************************************************
  27. typedef struct AcFd
  28. {
  29. // Enum for acdbEvaluateFields
  30. enum EvalFields
  31. {
  32. kEvalRecursive = (0x1 << 0), // Recursively evaluate complex objects
  33. };
  34. // Options for function acdbConvertFieldsToText()
  35. enum ConvertFieldToText
  36. {
  37. kConvertFieldToTextNone = 0,
  38. kEvaluateBeforeConversion = (0x1 << 0),
  39. kExcludeEvaluatorsInList = (0x1 << 1),
  40. kIgnoreEvaluatorVersion = (0x1 << 2),
  41. };
  42. } AcFd;
  43. //*************************************************************************
  44. // AcHyperlink
  45. //*************************************************************************
  46. typedef struct AcHyperlink
  47. {
  48. AcString msUrl;
  49. AcString msSubLocation;
  50. AcString msDescription;
  51. Adesk::Int32 mlFlag;
  52. } AcHyperlink;
  53. //*************************************************************************
  54. // AcDbField
  55. //*************************************************************************
  56. class AcDbField : public AcDbObject
  57. {
  58. public:
  59. enum State
  60. {
  61. kInitialized = (0x1 << 0), // Field has been initialized by the evaluator
  62. kCompiled = (0x1 << 1), // Field has beene compiled
  63. kModified = (0x1 << 2), // Field code has been modified, but not yet evaluated
  64. kEvaluated = (0x1 << 3), // Field has been evaluated
  65. kHasCache = (0x1 << 4), // Field has evaluated cache
  66. kHasFormattedString = (0x1 << 5), // For internal use only. Field has cached formatted string.
  67. };
  68. enum EvalOption
  69. {
  70. kDisable = 0, // Disable evaluation of field
  71. kOnOpen = (0x1 << 0), // Evaluate on drawing open
  72. kOnSave = (0x1 << 1), // Evaluate on drawing save
  73. kOnPlot = (0x1 << 2), // Evaluate on drawing plot
  74. kOnEtransmit = (0x1 << 3), // Evaluate on drawing etransmit
  75. kOnRegen = (0x1 << 4), // Evaluate on drawing regen
  76. kOnDemand = (0x1 << 5), // Evaluate on demand
  77. kAutomatic = (kOnOpen | kOnSave | kOnPlot |
  78. kOnEtransmit | kOnRegen | kOnDemand), // No restriction
  79. };
  80. enum EvalContext
  81. {
  82. kOpen = (0x1 << 0), // Field is being evaluated during open
  83. kSave = (0x1 << 1), // Field is being evaluated during save
  84. kPlot = (0x1 << 2), // Field is being evaluated during plot
  85. kEtransmit = (0x1 << 3), // Field is being evaluated during etransmit
  86. kRegen = (0x1 << 4), // Field is being evaluated during regen
  87. kDemand = (0x1 << 5), // Field is being evaluated on demand
  88. kPreview = (0x1 << 6), // Field is being evaluated for preview of field result
  89. kPlotPreview = (0x1 << 7), // Field is being evaluated during plot preview
  90. };
  91. enum EvalStatus
  92. {
  93. kNotYetEvaluated = (0x1 << 0), // Not yet evaluated
  94. kSuccess = (0x1 << 1), // Evaluated successfully
  95. kEvaluatorNotFound = (0x1 << 2), // Evaluator not found
  96. kSyntaxError = (0x1 << 3), // Field code syntax error
  97. kInvalidCode = (0x1 << 4), // Invalid field code
  98. kInvalidContext = (0x1 << 5), // Invalid context to evaluate field
  99. kOtherError = (0x1 << 6), // Evaluation error
  100. };
  101. enum FieldCodeFlag
  102. {
  103. kFieldCode = (0x1 << 0), // Get raw field code. Used only in getFieldCode().
  104. kEvaluatedText = (0x1 << 1), // Get evaluated text. Used only in getFieldCode().
  105. kEvaluatedChildren = (0x1 << 2), // Get field code with evaluated text for child fields. Used only in getFieldCode().
  106. kObjectReference = (0x1 << 3), // Get child fields as object references if this is text field or
  107. // this field as object reference if this is not text field. Used only in getFieldCode().
  108. kAddMarkers = (0x1 << 4), // Include markers around field codes. Used only in getFieldCode().
  109. kEscapeBackslash = (0x1 << 5), // Convert single backslashes to double backslashes. Used only in getFieldCode().
  110. kStripOptions = (0x1 << 6), // Strip the standard options from field code. Used only in getFieldCode().
  111. kPreserveFields = (0x1 << 7), // Try to preserve existing fields. Used only in setFieldCode().
  112. kTextField = (0x1 << 8), // Treat the field as text with embedded fields. Used only in setFieldCode().
  113. kPreserveOptions = (0x1 << 9), // Preserve the current standard options. Used only in setFieldCode(). For internal use.
  114. kDetachChildren = (0x1 << 10), // For internal use. Detach the child fields without erasing/deleting them.
  115. // Used only in setFieldCode().
  116. kChildObjectReference = (0x1 << 11), // For internal use. Get child fields as object references.
  117. // Used only in getFieldCode().
  118. kForExpression = (0x1 << 12), // For internal use. Used with kEvaluatedText/kEvaluatedChildren.
  119. // Get the value in a format which can be used in arithmatic expressions. Used only in getFieldCode().
  120. };
  121. enum FilingOption
  122. {
  123. kSkipFilingResult = (0x1 << 0), // Don't file field value
  124. };
  125. public:
  126. ACDB_DECLARE_MEMBERS(AcDbField);
  127. ACDB_PORT AcDbField(void);
  128. ACDB_PORT AcDbField(const ACHAR * pszFieldCode, bool bTextField = false);
  129. ACDB_PORT ~AcDbField(void);
  130. ACDB_PORT Acad::ErrorStatus setInObject (AcDbObject* pObj,
  131. const ACHAR * pszPropName);
  132. ACDB_PORT Acad::ErrorStatus postInDatabase(AcDbDatabase* pDb);
  133. ACDB_PORT AcDbField::State state (void) const;
  134. ACDB_PORT AcDbField::EvalStatus evaluationStatus(int* pnErrCode = NULL,
  135. ACHAR ** pszErrMsg = NULL) const;
  136. ACDB_PORT AcDbField::EvalOption evaluationOption(void) const;
  137. ACDB_PORT Acad::ErrorStatus setEvaluationOption(AcDbField::EvalOption nEvalOption);
  138. ACDB_PORT AcDbField::FilingOption filingOption(void) const;
  139. ACDB_PORT Acad::ErrorStatus setFilingOption(AcDbField::FilingOption nOption);
  140. ACDB_PORT const ACHAR * evaluatorId (void) const;
  141. ACDB_PORT Acad::ErrorStatus setEvaluatorId(const ACHAR * pszEvaluatorId);
  142. bool isTextField (void) const;
  143. Acad::ErrorStatus convertToTextField (void);
  144. ACDB_PORT const ACHAR * getFieldCode (AcDbField::FieldCodeFlag nFlag,
  145. AcArray<AcDbField*>* pChildFields = NULL,
  146. AcDb::OpenMode mode = AcDb::kForRead) const;
  147. ACDB_PORT Acad::ErrorStatus getFieldCode(ACHAR*& pszFieldCode,
  148. AcDbField::FieldCodeFlag nFlag,
  149. AcArray<AcDbField*>* pChildFields = NULL,
  150. AcDb::OpenMode mode = AcDb::kForRead) const;
  151. ACDB_PORT Acad::ErrorStatus setFieldCode(const ACHAR* pszFieldCode,
  152. AcDbField::FieldCodeFlag nFlag = (AcDbField::FieldCodeFlag) 0,
  153. AcDbFieldArray* pChildFields = NULL);
  154. ACDB_PORT int childCount (void) const;
  155. ACDB_PORT Acad::ErrorStatus getChild (int iIndex,
  156. AcDbField*& pField,
  157. AcDb::OpenMode mode);
  158. ACDB_PORT const ACHAR * getFormat (void) const;
  159. ACDB_PORT Acad::ErrorStatus getFormat (ACHAR*& pszFormat) const;
  160. ACDB_PORT Acad::ErrorStatus setFormat (const ACHAR* pszFormat);
  161. ACDB_PORT Acad::ErrorStatus evaluate (int nContext,
  162. AcDbDatabase* pDb,
  163. int* pNumFound = NULL,
  164. int* pNumEvaluated = NULL);
  165. ACDB_PORT AcValue::DataType dataType (void) const;
  166. ACDB_PORT const ACHAR * getValue (void) const;
  167. ACDB_PORT Acad::ErrorStatus getValue (ACHAR*& pszValue) const;
  168. ACDB_PORT Acad::ErrorStatus getValue (AcValue& value) const;
  169. ACDB_PORT Acad::ErrorStatus getValue (AcFdFieldValue& value) const;
  170. ACDB_PORT bool hasHyperlink (void) const;
  171. ACDB_PORT Acad::ErrorStatus getHyperlink(AcHyperlink& hlink) const;
  172. ACDB_PORT Acad::ErrorStatus getHyperlink(ACHAR** pszName,
  173. ACHAR** pszDescription,
  174. ACHAR** pszSubLocation,
  175. ACHAR** pszDisplayString,
  176. Adesk::Int32* pFlag) const;
  177. ACDB_PORT Acad::ErrorStatus setHyperlink(const AcHyperlink& hlink);
  178. ACDB_PORT Acad::ErrorStatus setHyperlink(const ACHAR* pszName,
  179. const ACHAR* pszDescription,
  180. const ACHAR* pszSubLocation = NULL);
  181. ACDB_PORT Acad::ErrorStatus setHyperlink(const ACHAR* pszName,
  182. const ACHAR* pszDescription,
  183. const ACHAR* pszSubLocation,
  184. Adesk::Int32 lFlag);
  185. ACDB_PORT Acad::ErrorStatus removeHyperlink(void);
  186. ACDB_PORT Acad::ErrorStatus getData (const ACHAR* pszKey,
  187. AcValue* pData) const;
  188. ACDB_PORT Acad::ErrorStatus setData (const ACHAR* pszKey,
  189. const AcValue* pData);
  190. ACDB_PORT Acad::ErrorStatus setData (const ACHAR* pszKey,
  191. const AcValue* pData,
  192. bool bRecursive);
  193. public:
  194. // Base class overrides
  195. ACDB_PORT virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler* pFiler);
  196. ACDB_PORT virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
  197. ACDB_PORT virtual Acad::ErrorStatus dxfInFields (AcDbDxfFiler* pFiler);
  198. ACDB_PORT virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler) const;
  199. ACDB_PORT virtual Acad::ErrorStatus subClose();
  200. };
  201. //*************************************************************************
  202. // Global exported functions
  203. //*************************************************************************
  204. ACDB_PORT AcFdFieldEngine* acdbGetFieldEngine(void);
  205. ACDB_PORT bool acdbGetFieldMarkers (const ACHAR*& pszPrefix,
  206. const ACHAR*& pszSuffix);
  207. ACDB_PORT bool acdbHasFields (const ACHAR * pszText);
  208. ACDB_PORT bool acdbFindField (const ACHAR * pszText,
  209. int iSearchFrom,
  210. int& nStartPos,
  211. int& nEndPos);
  212. ACDB_PORT Acad::ErrorStatus acdbEvaluateFields(const AcDbObjectId& objId,
  213. int nContext,
  214. const ACHAR* pszPropName = NULL,
  215. AcDbDatabase* pDb = NULL,
  216. AcFd::EvalFields nEvalFlag = AcFd::kEvalRecursive,
  217. int* pNumFound = NULL,
  218. int* pNumEvaluated = NULL);
  219. ACDB_PORT Acad::ErrorStatus acdbEvaluateFields(const AcDbObjectId& objId,
  220. int nContext,
  221. const AcDbObjectIdArray* pFieldsToEvaluate,
  222. const ACHAR* pszEvaluatorId,
  223. AcDbDatabase* pDb,
  224. AcFd::EvalFields nEvalFlag,
  225. int* pNumFound,
  226. int* pNumEvaluated);
  227. ACDB_PORT Acad::ErrorStatus acdbEvaluateFields(const AcDbObjectIdArray& objIds,
  228. int nContext,
  229. const ACHAR* pszPropName = NULL,
  230. AcDbDatabase* pDb = NULL,
  231. AcFd::EvalFields nEvalFlag = AcFd::kEvalRecursive,
  232. int* pNumFound = NULL,
  233. int* pNumEvaluated = NULL);
  234. ACDB_PORT Acad::ErrorStatus acdbEvaluateFields(const AcDbObjectIdArray& objIds,
  235. int nContext,
  236. const AcDbObjectIdArray* pFieldsToEvaluate,
  237. const ACHAR* pszEvaluatorId,
  238. AcDbDatabase* pDb,
  239. AcFd::EvalFields nEvalFlag,
  240. int* pNumFound,
  241. int* pNumEvaluated);
  242. ACDB_PORT Acad::ErrorStatus acdbConvertFieldsToText(AcDbDatabase* pDb,
  243. const AcStringArray* pEvalIds,
  244. AcFd::ConvertFieldToText nOption);
  245. ACDB_PORT Acad::ErrorStatus acdbConvertFieldsToText(const AcDbObjectIdArray& objIds,
  246. const AcStringArray* pEvalIds,
  247. AcFd::ConvertFieldToText nOption);
  248. ACDB_PORT Acad::ErrorStatus acdbMakeFieldCode(const ACHAR * pszFieldExpr,
  249. ACHAR*& pszFieldCode);
  250. ACDB_PORT Acad::ErrorStatus acdbMakeFieldCode(const ACHAR * pszFieldExpr,
  251. ACHAR*& pszFieldCode,
  252. const ACHAR * pszEvalId,
  253. const ACHAR * pszFormat,
  254. const AcHyperlink* pHyperlink);