dbeval.h 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  1. //
  2. //
  3. //////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Copyright 2015 Autodesk, Inc. All rights reserved.
  6. //
  7. // Use of this software is subject to the terms of the Autodesk license
  8. // agreement provided at the time of installation or download, or which
  9. // otherwise accompanies this software in either electronic or hard copy form.
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // dbeval.h
  14. //
  15. // AcRxObject
  16. // AcDbObject
  17. // AcDbEvalGraph
  18. // AcDbEvalExpr
  19. // AcDbEvalConnectable
  20. //
  21. // AcDbEvalContext
  22. // AcDbEvalContextPair
  23. // AcDbEvalContextIterator
  24. // AcDbEvalVariant
  25. //
  26. //
  27. // DESCRIPTION:
  28. //
  29. // The classes in this file provide a framework for managing and evaluating a
  30. // collection of operations in a specfic order. The framework consists of a
  31. // collection of nodes, organized in a graph. By establishing edges between
  32. // nodes in the graph and directions on each edge, the graph can sort the
  33. // nodes topologically and traverse the nodes in a specific order.
  34. //
  35. // The nodes themselves (AcDbEvalExpr) implement an evaluate() method that is
  36. // called by the graph (AcDbEvalGraph) in the order that the nodes are
  37. // traversed.
  38. //
  39. // Applications typically make use of this framework by implementing custom
  40. // objects derived from AcDbEvalExpr and implementing the
  41. // AcDbEvalExpr::evaluate() method. Applications instantiate custom nodes, add
  42. // them to a graph, add edges between the nodes, and call
  43. // AcDbEvalGraph::evaluate() to perform a traversal of the nodes.
  44. //
  45. #pragma once
  46. #include "dbmain.h"
  47. #include "dbents.h"
  48. #include "acstring.h"
  49. #include "adscodes.h"
  50. #include "adsdef.h"
  51. #pragma pack(push, 8)
  52. // Forward class declarations
  53. class AcDbEvalGraph;
  54. class AcDbEvalEdgeInfo;
  55. class AcDbEvalExpr;
  56. class AcDbEvalConnectable;
  57. class AcDbEvalContext;
  58. class AcDbEvalContextPair;
  59. class AcDbEvalContextIterator;
  60. class AcDbEvalVariant;
  61. class AcDbImpEvalContext;
  62. class AcDbImpEvalContextIterator;
  63. class AcRxValue;
  64. class AcRxValueType;
  65. // Type declarations
  66. // Unique (within an AcDbEvalGraph) identifier assigned to
  67. // a node (AcDbEvalExpr) in the graph.
  68. typedef Adesk::UInt32 AcDbEvalNodeId;
  69. typedef AcArray<AcDbEvalNodeId> AcDbEvalNodeIdArray;
  70. typedef AcArray<AcDbEvalEdgeInfo*> AcDbEvalEdgeInfoArray;
  71. typedef AcArray<AcDbEvalExpr*> AcDbEvalExprPtrArray;
  72. typedef AcArray<AcDbEvalVariant,
  73. AcArrayObjectCopyReallocator<AcDbEvalVariant> > AcDbEvalVariantArray;
  74. ////////////////////////////////////////////////////////////////////////
  75. // class AcDbEvalVariant
  76. ////////////////////////////////////////////////////////////////////////
  77. /// <summary>
  78. /// This class provides a lightweight wrapper for a resbuf structure. It
  79. /// provides typed constructors and overloaded assignment operators to
  80. /// facilitiate assignig values to the underlying data. AcDbEvalExpr objects
  81. /// return instances of this class for the "result" of the expressions.
  82. /// </summary>
  83. ///
  84. /// <remarks>
  85. /// The class manages the copying of strings by calling acutNewString() to copy
  86. /// strings. Linked lists of resbufs are not directly supported, but if an
  87. /// AcDbEvalVariant contains a linked resbuf chain the destructor will free the
  88. /// entire chain using acutRelRb().
  89. /// </remarks>
  90. ///
  91. class AcDbEvalVariant : public resbuf, public AcRxObject
  92. {
  93. public:
  94. ACRX_DECLARE_MEMBERS(AcDbEvalVariant);
  95. /// <summary>
  96. /// Default constructor.
  97. /// </summary>
  98. ///
  99. /// <remarks> Allocates the resbuf and initializes the variant type to
  100. /// AcDbEvalVariant::kNone.
  101. /// </remarks>
  102. ///
  103. AcDbEvalVariant ();
  104. /// <summary>
  105. /// Copy contstructor.
  106. /// </summary>
  107. ///
  108. /// <param name="other">
  109. /// The object to copy from.
  110. /// </param>
  111. ///
  112. AcDbEvalVariant(const AcDbEvalVariant& other);
  113. /// <summary>
  114. /// Copy contstructor.
  115. /// </summary>
  116. ///
  117. /// <param name="pOther">
  118. /// A pointer to the object to copy from.
  119. /// </param>
  120. ///
  121. AcDbEvalVariant (const AcDbEvalVariant* pOther);
  122. /// <summary>
  123. /// Destructor.
  124. /// </summary>
  125. ///
  126. /// <remarks>
  127. /// The data in the underlying resbuf is freed by this destructor. Strings
  128. /// are freed using acutDelString(), and linked resbuf chains are freed
  129. /// using acutRelRb().
  130. /// </remarks>
  131. ///
  132. ~AcDbEvalVariant();
  133. /// <summary>
  134. /// Constructs an AcDbEvalVariant wrapping a double value.
  135. /// </summary>
  136. ///
  137. /// <param name="dVal">
  138. /// The value to assign to the object.
  139. /// </param>
  140. ///
  141. /// <remarks>
  142. /// The variant type is set to AcDbEvalVariant::kDouble.
  143. /// </remarks>
  144. ///
  145. AcDbEvalVariant (double dVal);
  146. /// <summary>
  147. /// Constructs an AcDbEvalVariant wrapping a short integer value.
  148. /// </summary>
  149. ///
  150. /// <param name="iVal">
  151. /// The value to assign to the object.
  152. /// </param>
  153. ///
  154. /// <remarks>
  155. /// The variant type is set to AcDbEvalVariant::kShort.
  156. /// </remarks>
  157. ///
  158. AcDbEvalVariant (short iVal);
  159. /// <summary>
  160. /// Constructs an AcDbEvalVariant wrapping a string value.
  161. /// </summary>
  162. ///
  163. /// <param name="szVal">
  164. /// The value to assign to the object.
  165. /// </param>
  166. ///
  167. /// <remarks>
  168. /// The variant type is set to AcDbEvalVariant::kString.
  169. /// </remarks>
  170. ///
  171. AcDbEvalVariant (const ACHAR* szVal);
  172. /// <summary>
  173. /// Constructs an AcDbEvalVariant wrapping a long value.
  174. /// </summary>
  175. ///
  176. /// <param name="lVal">
  177. /// The value to assign to the object.
  178. /// </param>
  179. ///
  180. /// <remarks>
  181. /// The variant type is set to AcDbEvalVariant::kLong.
  182. /// </remarks>
  183. ///
  184. AcDbEvalVariant (Adesk::Int32 lVal);
  185. /// <summary>
  186. /// Constructs an AcDbEvalVariant wrapping an AcDbObjectId.
  187. /// </summary>
  188. ///
  189. /// <param name="id">
  190. /// The value to assign to the object.
  191. /// </param>
  192. ///
  193. /// <remarks>
  194. /// The variant type is set to AcDbEvalVariant::kOldId.
  195. /// </remarks>
  196. ///
  197. AcDbEvalVariant (const AcDbObjectId& id);
  198. /// <summary>
  199. /// Constructs an AcDbEvalVariant wrapping a 2D point.
  200. /// </summary>
  201. ///
  202. /// <param name="pt">
  203. /// The value to assign to the object.
  204. /// </param>
  205. ///
  206. /// <remarks>
  207. /// The variant type is set to AcDbEvalVariant::kPoint2d
  208. /// </remarks>
  209. ///
  210. AcDbEvalVariant (const AcGePoint2d& pt);
  211. /// <summary>
  212. /// Constructs an AcDbEvalVariant wrapping a 3D point.
  213. /// </summary>
  214. ///
  215. /// <param name="pt">
  216. /// The value to assign to the object.
  217. /// </param>
  218. ///
  219. /// <remarks>
  220. /// The variant type is set to AcDbEvalVariant::kPoint3d.
  221. /// </remarks>
  222. ///
  223. AcDbEvalVariant (const AcGePoint3d& pt);
  224. /// <summary>
  225. /// Constructs an AcDbEvalVariant from a resbuf.
  226. /// </summary>
  227. ///
  228. /// <param name="pt">
  229. /// The value to assign to the object.
  230. /// </param>
  231. ///
  232. /// <remarks>
  233. /// The variant type is set to rb.restype.
  234. /// </remarks>
  235. AcDbEvalVariant(const resbuf& rb);
  236. /// <summary>
  237. /// Assigns an AcDbEvalVariant to a resbuf.
  238. /// </summary>
  239. ///
  240. /// <param name="dVal">
  241. /// The value to assign to the object.
  242. /// </param>
  243. ///
  244. /// <returns>
  245. /// A reference to the updated variant.
  246. /// </returns>
  247. ///
  248. /// <remarks>
  249. /// The variant type is set to rb.restype.
  250. /// </remarks>
  251. ///
  252. AcDbEvalVariant& operator=(const resbuf& rb);
  253. /// <summary>
  254. /// Assigns an AcDbEvalVariant to a double value.
  255. /// </summary>
  256. ///
  257. /// <param name="dVal">
  258. /// The value to assign to the object.
  259. /// </param>
  260. ///
  261. /// <returns>
  262. /// A reference to the updated variant.
  263. /// </returns>
  264. ///
  265. /// <remarks>
  266. /// The variant type is set to AcDbEvalVariant::kDouble.
  267. /// </remarks>
  268. ///
  269. AcDbEvalVariant& operator=(double dVal);
  270. /// <summary>
  271. /// Assigns an AcDbEvalVariant to a short value.
  272. /// </summary>
  273. ///
  274. /// <param name="iVal">
  275. /// The value to assign to the object.
  276. /// </param>
  277. ///
  278. /// <returns>
  279. /// A reference to the updated variant.
  280. /// </returns>
  281. ///
  282. /// <remarks>
  283. /// The variant type is set to AcDbEvalVariant::kShort.
  284. /// </remarks>
  285. ///
  286. AcDbEvalVariant& operator=(short iVal);
  287. /// <summary>
  288. /// Assigns an AcDbEvalVariant to a long value.
  289. /// </summary>
  290. ///
  291. /// <param name="lVal">
  292. /// The value to assign to the object.
  293. /// </param>
  294. ///
  295. /// <returns>
  296. /// A reference to the updated variant.
  297. /// </returns>
  298. ///
  299. /// <remarks>
  300. /// The variant type is set to AcDbEvalVariant::kLong.
  301. /// </remarks>
  302. ///
  303. AcDbEvalVariant& operator=(Adesk::Int32 lVal);
  304. /// <summary>
  305. /// Assigns an AcDbEvalVariant to a character string.
  306. /// </summary>
  307. ///
  308. /// <param name="szVal">
  309. /// The value to assign to the object.
  310. /// </param>
  311. ///
  312. /// <returns>
  313. /// A reference to the updated variant.
  314. /// </returns>
  315. ///
  316. /// <remarks>
  317. /// The variant type is set to AcDbEvalVariant::kString.
  318. /// </remarks>
  319. ///
  320. AcDbEvalVariant& operator=(const ACHAR* szVal);
  321. /// <summary>
  322. /// Assigns an AcDbEvalVariant to the value stored in another
  323. /// AcDbEvalVariant.
  324. /// </summary>
  325. ///
  326. /// <param name="other">
  327. /// The value to assign to the object.
  328. /// </param>
  329. ///
  330. /// <returns>
  331. /// A reference to the updated variant.
  332. /// </returns>
  333. ///
  334. AcDbEvalVariant& operator=(const AcDbEvalVariant& other);
  335. /// <summary>
  336. /// Assigns an AcDbEvalVariant to the value of an AcDbObjectId.
  337. /// </summary>
  338. ///
  339. /// <param name="id">
  340. /// The value to assign to the object.
  341. /// </param>
  342. ///
  343. /// <returns>
  344. /// A reference to the updated variant.
  345. /// </returns>
  346. ///
  347. /// <remarks>
  348. /// The variant type is set to AcDbEvalVariant::kOldId.
  349. /// </remarks>
  350. ///
  351. AcDbEvalVariant& operator=(const AcDbObjectId& id);
  352. /// <summary>
  353. /// Assigns an AcDbEvalVariant to a 2D point value.
  354. /// </summary>
  355. ///
  356. /// <param name="pt">
  357. /// The value to assign to the object.
  358. /// </param>
  359. ///
  360. /// <returns>
  361. /// A reference to the updated variant.
  362. /// </returns>
  363. ///
  364. /// <remarks>
  365. /// The variant type is set to AcDbEvalVariant::kPoint2d.
  366. /// </remarks>
  367. ///
  368. AcDbEvalVariant& operator=(const AcGePoint2d& pt);
  369. /// <summary>
  370. /// Assigns an AcDbEvalVariant to a 3D point value.
  371. /// </summary>
  372. ///
  373. /// <param name="pt">
  374. /// The value to assign to the object.
  375. /// </param>
  376. ///
  377. /// <returns>
  378. /// A reference to the updated variant.
  379. /// </returns>
  380. ///
  381. /// <remarks>
  382. /// The variant type is set to AcDbEvalVariant::kPoint3d.
  383. /// </remarks>
  384. ///
  385. AcDbEvalVariant& operator=(const AcGePoint3d& pt);
  386. /// <summary>
  387. /// Clears the contents of the AcDbEvalVariant and frees any allocated
  388. /// memory, including resbuf chains descending from this AcDbEvalVariant.
  389. /// Changed the <c>AcDbEvalVariant::restype</c> to AcDbEvalVariant::kNone.
  390. /// </summary>
  391. void clear();
  392. /// <summary>
  393. /// Copies the value and data from a source AcDbEvalVariant object into this object.
  394. /// </summary>
  395. ///
  396. /// <param name="pOther">
  397. /// A pointer to the AcDbEvalVariant to copy from.
  398. /// </param>
  399. ///
  400. /// <returns>
  401. /// Returns Acad::eOk if successful. Returns Acad::eWrongObjectType if
  402. /// <c>pObject</c> is not an AcDbEvalVariant.
  403. /// </returns>
  404. virtual Acad::ErrorStatus copyFrom(const AcRxObject* pOther);
  405. /// <summary>
  406. /// Tests whether this AcDbEvalVariant is less than another.
  407. /// This operator may only be used if both AcDbEvalVariants are of
  408. /// type kDouble, kShort, kLong, or kString.
  409. /// </summary>
  410. /// <param name="val">
  411. /// AcDbEvalVariant to compare to.
  412. /// </param>
  413. /// <returns>
  414. /// True if this AcDbEvalVariant is less than val, false otherwise.
  415. /// If the two AcDbEvalVariants are of different types or if the
  416. /// data type is not kDouble, kShort, kLong, or kString then
  417. /// a value of false will be returned.
  418. /// </returns>
  419. bool operator < ( const AcDbEvalVariant& val ) const;
  420. /// <summary>
  421. /// Tests whether this AcDbEvalVariant is greater than another.
  422. /// This operator may only be used if both AcDbEvalVariants are of
  423. /// type kDouble, kShort, kLong, or kString.
  424. /// </summary>
  425. /// <param name="val">
  426. /// AcDbEvalVariant to compare to.
  427. /// </param>
  428. /// <returns>
  429. /// True if this AcDbEvalVariant is greater than val, false otherwise.
  430. /// If the two AcDbEvalVariants are of different types or if the
  431. /// data type is not kDouble, kShort, kLong, or kString then
  432. /// a value of false will be returned.
  433. /// </returns>
  434. bool operator > ( const AcDbEvalVariant& val ) const;
  435. /// <summary>
  436. /// Tests whether this AcDbEvalVariant is less than or equal to another.
  437. /// This operator may only be used if both AcDbEvalVariants are of
  438. /// type kDouble, kShort, kLong, or kString.
  439. /// </summary>
  440. /// <param name="val">
  441. /// AcDbEvalVariant to compare to.
  442. /// </param>
  443. /// <returns>
  444. /// True if this AcDbEvalVariant is less than or equal to val,
  445. /// false otherwise. If the two AcDbEvalVariants are of different types
  446. /// or if the data type is not kDouble, kShort, kLong, or kString then
  447. /// a value of false will be returned.
  448. /// </returns>
  449. bool operator <= ( const AcDbEvalVariant& val ) const;
  450. /// <summary>
  451. /// Tests whether this AcDbEvalVariant is greater than or equal to another.
  452. /// This operator may only be used if both AcDbEvalVariants are of
  453. /// type kDouble, kShort, kLong, or kString.
  454. /// </summary>
  455. /// <param name="val">
  456. /// AcDbEvalVariant to compare to.
  457. /// </param>
  458. /// <returns>
  459. /// True if this AcDbEvalVariant is greater than or equal to val,
  460. /// false otherwise. If the two AcDbEvalVariants are of different types
  461. /// or if the data type is not kDouble, kShort, kLong, or kString then
  462. /// a value of false will be returned.
  463. /// </returns>
  464. bool operator >= ( const AcDbEvalVariant& val ) const;
  465. /// <summary>
  466. /// Tests whether this AcDbEvalVariant is equal to another.
  467. /// </summary>
  468. /// <param name="val">
  469. /// AcDbEvalVariant to compare to.
  470. /// </param>
  471. /// <returns>
  472. /// True if this AcDbEvalVariant is equal to val, false otherwise.
  473. /// If the two AcDbEvalVariants are of different types then
  474. /// a value of false will be returned.
  475. /// </returns>
  476. bool operator == ( const AcDbEvalVariant& val ) const;
  477. /// <summary>
  478. /// Tests whether this AcDbEvalVariant is unequal to another.
  479. /// </summary>
  480. /// <param name="val">
  481. /// AcDbEvalVariant to compare to.
  482. /// </param>
  483. /// <returns>
  484. /// True if this AcDbEvalVariant is unequal to val, false otherwise.
  485. /// If the two AcDbEvalVariants are of different types then
  486. /// a value of true will be returned.
  487. /// </returns>
  488. bool operator != ( const AcDbEvalVariant& val ) const;
  489. Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
  490. Acad::ErrorStatus dwgInFields(AcDbDwgFiler* pFiler);
  491. Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* pFiler) const;
  492. Acad::ErrorStatus dxfInFields(AcDbDxfFiler* pFiler);
  493. AcDb::DwgDataType getType() const;
  494. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const double value);
  495. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const short value);
  496. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const Adesk::Int32 value);
  497. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const AcString& value);
  498. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const AcDbObjectId value);
  499. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const AcGePoint3d& value);
  500. Acad::ErrorStatus setValue(AcDb::DxfCode groupcode, const AcGePoint2d& value);
  501. Acad::ErrorStatus getValue(double& value) const;
  502. Acad::ErrorStatus getValue(short& value) const;
  503. Acad::ErrorStatus getValue(Adesk::Int32& value) const;
  504. ACDB_PORT Acad::ErrorStatus getValue(AcString& value) const;
  505. Acad::ErrorStatus getValue(AcDbObjectId& value, AcDbDatabase *pDb = NULL) const;
  506. Acad::ErrorStatus getValue(AcGePoint3d& value) const;
  507. Acad::ErrorStatus getValue(AcGePoint2d& value) const;
  508. /// <summary>
  509. /// Converts an AcDbEvalVariant to an AcRxValue.
  510. /// </summary>
  511. /// <param name="type">
  512. /// The expected type of the returned AcRxValue.
  513. /// </param>
  514. /// <param name="value">
  515. /// The returned AcRxValue.
  516. /// </param>
  517. /// <returns>
  518. /// Returns Acad::eOk if successful, returns eInvalidInput if the
  519. /// conversion could not be performed.
  520. /// </returns>
  521. Acad::ErrorStatus toAcRxValue(const AcRxValueType& type,
  522. AcRxValue& value) const;
  523. /// <summary>
  524. /// Converts an AcRxValue to an AcDbEvalVariant.
  525. /// </summary>
  526. /// <param name="value">
  527. /// The AcRxValue to convert.
  528. /// </param>
  529. /// <returns>
  530. /// Returns Acad::eOk if successful, returns eInvalidInput if the
  531. /// conversion could not be performed and leaves the variant unmodified.
  532. /// </returns>
  533. Acad::ErrorStatus fromAcRxValue(const AcRxValue& value);
  534. protected:
  535. /// <summary>
  536. /// Initializes the contents of the AcDbEvalVariant.
  537. /// </summary>
  538. ///
  539. /// <remarks>
  540. /// Called by constructor overloads to initialize the base resbuf memory.
  541. /// </remarks>
  542. void init();
  543. };
  544. class AcDbEvalEdgeInfo;
  545. class AcDbEvalIdMap
  546. {
  547. public:
  548. virtual AcDbEvalNodeId find(const AcDbEvalNodeId& key) = 0;
  549. virtual void kill() = 0;
  550. };
  551. ////////////////////////////////////////////////////////////////////////
  552. // class AcDbEvalGraph
  553. ////////////////////////////////////////////////////////////////////////
  554. /// <summary>
  555. /// This class holds the network of inter-related 'elements' that implement the
  556. /// smart behavior. Each individual 'element' (or AcDbEvalExpr) can depend on
  557. /// zero or more other AcDbEvalExprs. So - it is the role of AcDbEvalGraph to
  558. /// invoke the AcDbEvalExpr::evaluate() method for each of the elements it
  559. /// contains when it is the right time to do so. Right, in the sense, all the
  560. /// AcDbEvalExprs that are depended on have had their evaluate() invoked. In
  561. /// order to reprsent the inter-AcDbEvalExpr dependency - the AcDbEvalGraph
  562. /// represents a Directed Graph. If an AcDbEvalExpr E1 depends on (requires
  563. /// input from) an AcDbEvalExpr E2 - there is an edge from E2 to E1 represented
  564. /// in the graph.
  565. ///
  566. /// During evaluation, based on what AcDbEvalExpr's are 'active' (i.e. are
  567. /// directly modified, for example, through the property palette, or grip
  568. /// editing), is driven activation of a subset of AcDbEvalExprs reachable from
  569. /// the activated set. The resulting subgraph is expected to be a DAG. It is
  570. /// then topologically sorted to determine node evaluation order.
  571. ///
  572. /// The current internal use of this graph class is for 'Enhanced Blocks' where
  573. /// a graph of the expressions is maintained on the Block Table Record. This
  574. /// graph is queried at graph editing time, and evaluated in order to trigger
  575. /// the networked nodes (AcDbEvalExprs) that, through their evaluate() methods
  576. /// being invoked, end up implementing the 'enhanced' behavior.
  577. /// </summary>
  578. ///
  579. /// <seealso cref="AcDbEvalExpr"/>
  580. ///
  581. class AcDbEvalGraph : public AcDbObject
  582. {
  583. public:
  584. /// <summary>
  585. /// Special AcDbEvalNodeId values.
  586. /// </summary>
  587. ///
  588. enum NodeId {
  589. /// <summary>
  590. /// Null node Id.
  591. /// </summary>
  592. kNullNodeId = 0
  593. };
  594. ACDB_DECLARE_MEMBERS(AcDbEvalGraph);
  595. /// <summary>
  596. /// Default constructor, constructs an empty graph.
  597. /// </summary>
  598. ///
  599. AcDbEvalGraph();
  600. /// <summary>
  601. /// Destructor.
  602. /// </summary>
  603. virtual ~AcDbEvalGraph();
  604. /* Management */
  605. // This set of static methods deal with managing the
  606. // association of an AcDbEvalGraph with an AcDbObject.
  607. /// <summary>
  608. /// Determines if a graph exists on the supplied object. The object must
  609. /// be database resident.
  610. /// </summary>
  611. ///
  612. /// <param name="pObj">
  613. /// The object from which to retrieve the graph.
  614. /// </param>
  615. /// <param name="pKey">
  616. /// The key at which the graph is associated. This means multiple graphs
  617. /// can be associated with one object.
  618. /// </param>
  619. ///
  620. /// <returns>
  621. /// Returns true if the graph exists.
  622. /// </returns>
  623. static bool hasGraph(const AcDbObject* pObj,
  624. const ACHAR* pKey);
  625. /// <summary>
  626. /// Retrieves a graph, if one exists, from the supplied object with the
  627. /// requested open mode. The object must be database resident.
  628. /// </summary>
  629. ///
  630. /// <param name="pObj">
  631. /// The object from which to retrieve the graph.
  632. /// </param>
  633. /// <param name="pKey">
  634. /// The key at which the graph is associated. This means multiple graphs
  635. /// can be associated with one object.
  636. /// </param>
  637. /// <param name="pGraph">
  638. /// Result graph. *pGraph is set to NULL if not found.
  639. /// </param>
  640. /// <param name="mode">
  641. /// The mode in which to open the graph.
  642. /// </param>
  643. ///
  644. /// <returns>
  645. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if the
  646. /// graph with the specified key name does not exist.
  647. /// </returns>
  648. ///
  649. /// <remarks>
  650. /// The calling application is responsible for calling close() on the
  651. /// returned graph when it is no longer needed.
  652. /// </remarks>
  653. ///
  654. static Acad::ErrorStatus getGraph(const AcDbObject* pObj,
  655. const ACHAR* pKey,
  656. AcDbEvalGraph** pGraph,
  657. const AcDb::OpenMode mode);
  658. /// <summary>
  659. /// Creates a graph on the object at the supplied key. The object must be
  660. /// database resident.
  661. /// </summary>
  662. ///
  663. /// <param name="pObj">
  664. /// Object on which to create a graph.
  665. /// </param>
  666. /// <param name="pKey">
  667. /// Key at which to associate the new graph.
  668. /// </param>
  669. ///
  670. /// <returns>
  671. /// Returns Acad::eOk if successful. Returns eAlreadyInDb if the graph
  672. /// already exists on the object.
  673. /// </returns>
  674. ///
  675. static Acad::ErrorStatus createGraph(AcDbObject* pObj,
  676. const ACHAR* pKey);
  677. /// <summary>
  678. /// Removes the graph, if one exists, at the supplied key. The object must
  679. /// be database resident.
  680. /// </summary>
  681. ///
  682. /// <param name="pObj">
  683. /// Object from which to remove the graph.
  684. /// </param>
  685. /// <param name="pKey">
  686. /// Key at which the graph is associated on the object.
  687. /// </param>
  688. ///
  689. /// <returns>
  690. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if the
  691. /// graph does not exist.
  692. /// </returns>
  693. ///
  694. static Acad::ErrorStatus removeGraph(AcDbObject* pObj,
  695. const ACHAR* pKey);
  696. /// <summary>
  697. /// Determines if a graph exists at the supplied key in the databae.
  698. /// </summary>
  699. ///
  700. /// <param name="pDb">
  701. /// The database from which to retrieve the graph.
  702. /// </param>
  703. /// <param name="pKey">
  704. /// The key at which the graph is registered in the database.
  705. /// </param>
  706. ///
  707. /// <returns>
  708. /// Returns true if the graph exists.
  709. /// </returns>
  710. ///
  711. static bool hasGraph(AcDbDatabase* pDb,
  712. const ACHAR* pKey);
  713. /// <summary>
  714. /// Retrieves the graph from the database. This method
  715. /// provides the ability to associate a graph with a database
  716. /// (instead of a specific object in the database).
  717. /// </summary>
  718. ///
  719. /// <param name="pDb">
  720. /// Database from which to retrieve the graph.
  721. /// </param>
  722. /// <param name="pKey">
  723. /// Key at which the graph is associated.
  724. /// </param>
  725. /// <param name="pGraph">
  726. /// The graph at the specified key, or NULL if the graph does not exist.
  727. /// </param>
  728. /// <param name="mode">
  729. /// The mode (read/write) in which to return the graph.
  730. /// </param>
  731. ///
  732. /// <returns>
  733. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if the
  734. /// specified key could not be found.
  735. /// </returns>
  736. ///
  737. /// <remarks>
  738. /// The calling application is responsible for calling close() on the
  739. /// returned graph when it is no longer needed.
  740. /// </remarks>
  741. ///
  742. static Acad::ErrorStatus getGraph(AcDbDatabase* pDb,
  743. const ACHAR* pKey,
  744. AcDbEvalGraph** pGraph,
  745. const AcDb::OpenMode mode);
  746. /// <summary>
  747. /// Creates a graph at the specified key for the database. This method
  748. /// provides the ability to associate a graph witha database (instead of a
  749. /// specific object in the database).
  750. /// </summary>
  751. ///
  752. /// <param name="pDb">
  753. /// Database from which to create the graph.
  754. /// </param>
  755. /// <param name="pKey">
  756. /// Key at which the graph is associated.
  757. /// </param>
  758. ///
  759. /// <returns>
  760. /// Returns Acad::eOk if successful.
  761. /// </returns>
  762. ///
  763. static Acad::ErrorStatus createGraph(AcDbDatabase* pDb,
  764. const ACHAR* pKey);
  765. /// <summary>
  766. /// Removes a graph at the specified key for the database.
  767. /// </summary>
  768. ///
  769. /// <param name="pDb">
  770. /// Database from which to remove the graph.
  771. /// </param>
  772. /// <param name="pKey">
  773. /// Key at which the graph is associated.
  774. /// </param>
  775. ///
  776. /// <returns>
  777. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if there is
  778. /// no graph with that key associated to the database
  779. /// </returns>
  780. static Acad::ErrorStatus removeGraph(AcDbDatabase* pDb,
  781. const ACHAR* pKey);
  782. /// <summary>
  783. /// Replaces the graph on the object.
  784. /// </summary>
  785. ///
  786. /// <param name="pObj">
  787. /// Object on which to create a graph.
  788. /// </param>
  789. ///
  790. /// </param>
  791. /// <param name="pKey">
  792. /// Key at which the graph is associated.
  793. /// </param>
  794. ///
  795. /// <param name="graphId">
  796. /// AcDbObjectId of the graph that will be the replacement
  797. /// </param>
  798. ///
  799. /// <returns>
  800. /// Returns Acad::eOk if successful. Returns eWrongObjectType if wrong type
  801. /// of object (i.e. not an AcDbEvalGraph).
  802. /// </returns>
  803. ///
  804. static Acad::ErrorStatus replaceGraph(AcDbObject* pObj,
  805. const ACHAR* pKey,
  806. AcDbObjectId grphId);
  807. /* Graph Query/Edit */
  808. // This set of methods are to do with editing the graph - i.e. adding,
  809. // removing, querying for nodes and edges. The api is geared towards being
  810. // able to work with a non database resident version of the graph, i.e. it
  811. // deals with object pointers.
  812. //
  813. // For an AcDbGraph which is database resident, the caller must close the
  814. // returned nodes after they are done. This also includes add() methods,
  815. // e.g. addNode(AcDbEvalExpr* pNode). The caller is expected to close the
  816. // supplied pNode argument
  817. /// <summary>
  818. /// Adds a node to the graph and returns the AcDbEvalNodeId of the newly
  819. /// added node.
  820. /// </summary>
  821. ///
  822. /// <param name="pNode">
  823. /// A pointer to the node to add to the graph.
  824. /// </param>
  825. /// <param name="id">
  826. /// The id of newly added node.
  827. /// </param>
  828. ///
  829. /// <returns>
  830. /// Acad::eOk if successful.
  831. /// </returns>
  832. ///
  833. /// <remarks>
  834. /// If the graph is database-resident the caller must call close() on
  835. /// <c>pNode</c> when it is no longer needed.
  836. /// </remarks>
  837. ///
  838. virtual Acad::ErrorStatus addNode (AcDbEvalExpr* pNode,
  839. AcDbEvalNodeId& id);
  840. /// <summary>
  841. /// Removes a node from the graph.
  842. /// </summary>
  843. ///
  844. /// <param name="id">
  845. /// The id of the node to remove from the graph.
  846. /// </param>
  847. ///
  848. /// <returns>
  849. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if no
  850. /// node with the specified id exists in the graph.
  851. /// </returns>
  852. ///
  853. virtual Acad::ErrorStatus removeNode (const AcDbEvalNodeId& id);
  854. /// <summary>
  855. /// Removes a node from the graph. Assumes the object is already opened
  856. /// for read or write.
  857. /// </summary>
  858. ///
  859. /// <param name="pNode">
  860. /// The node to remove from the graph.
  861. /// </param>
  862. ///
  863. /// <returns>
  864. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound
  865. /// if the node does not exist in the graph.
  866. /// </returns>
  867. ///
  868. virtual Acad::ErrorStatus removeNode (AcDbEvalExpr* pNode);
  869. /// <summary>
  870. /// Returns an array of all node ids contained in the graph.
  871. /// </summary>
  872. ///
  873. /// <param name="nodes">
  874. /// An array of AcDbEvalNodeId objects for all of the nodes in the graph.
  875. /// </param>
  876. ///
  877. /// <returns>
  878. /// Returns Acad::eOk if successful.
  879. /// </returns>
  880. ///
  881. virtual Acad::ErrorStatus getAllNodes (AcDbEvalNodeIdArray& nodes) const;
  882. /// <summary>
  883. /// Opens a node in the graph given its node id.
  884. /// </summary>
  885. ///
  886. /// <param name="nodeId">
  887. /// The AcDbEvalNodeId of the node to open.
  888. /// </param>
  889. /// <param name="mode">
  890. /// The AcDb::OpenMode to open the node with.
  891. /// </param>
  892. /// <param name="ppNode">
  893. /// A pointer to the opened node.
  894. /// </param>
  895. ///
  896. /// <returns>
  897. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if no
  898. /// node with the specified id exists in the graph.
  899. /// </returns>
  900. ///
  901. /// <remarks>
  902. /// Callers must call close() on the returned node pointer when it is no
  903. /// longer needed.
  904. /// </remarks>
  905. virtual Acad::ErrorStatus getNode (const AcDbEvalNodeId& nodeId,
  906. AcDb::OpenMode mode,
  907. AcDbObject** ppNode) const;
  908. /// <summary>
  909. /// Adds a non-invertable edge between two nodes in the graph.
  910. /// </summary>
  911. ///
  912. /// <param name="idFrom">
  913. /// The AcDbEvalNodeId of the node from which the edge originates.
  914. /// </param>
  915. /// <param name="idTo">
  916. /// The AcDbEvalNodeId of the node at which the edge terminates.
  917. /// </param>
  918. ///
  919. /// <returns>
  920. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if
  921. /// either of the nodes are not resident in the graph.
  922. /// </returns>
  923. ///
  924. virtual Acad::ErrorStatus addEdge(const AcDbEvalNodeId& idFrom,
  925. const AcDbEvalNodeId& idTo);
  926. /// <summary>
  927. /// Adds an edge between two nodes in the graph.
  928. /// </summary>
  929. ///
  930. /// <param name="idFrom">
  931. /// The AcDbEvalNodeId of the node from which the edge originates.
  932. /// </param>
  933. /// <param name="idTo">
  934. /// The AcDbEvalNodeId of the node at which the edge terminates.
  935. /// </param>
  936. /// <param name="bInvertible">
  937. /// True if the edge can be inverted depending on which of the nodes
  938. /// has been activated.
  939. /// </param>
  940. ///
  941. /// <returns>
  942. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if
  943. /// either of the nodes are not resident in the graph.
  944. /// </returns>
  945. ///
  946. virtual Acad::ErrorStatus addEdge(const AcDbEvalNodeId& idFrom,
  947. const AcDbEvalNodeId& idTo,
  948. bool bInvertible);
  949. /// <summary>
  950. /// Removes an edge between to nodes in the graph.
  951. /// </summary>
  952. ///
  953. /// <param name="idFrom">
  954. /// The AcDbEvalNodeId of the node from which the edge originates.
  955. /// </param>
  956. /// <param name="idTo">
  957. /// The AcDbEvalNodeId of the node at which the edge terminates.
  958. /// </param>
  959. ///
  960. /// <returns>
  961. /// Returns Acad::eOk if successful. Returns Acad::eGraphEdgeNotFound if
  962. /// an edge between the nodes does not exist.
  963. /// </returns>
  964. ///
  965. virtual Acad::ErrorStatus removeEdge(const AcDbEvalNodeId& idFrom,
  966. const AcDbEvalNodeId& idTo);
  967. /// <summary>
  968. /// Returns a list of incoming edges to a node in the graph.
  969. /// </summary>
  970. ///
  971. /// <param name="nodeId">
  972. /// The AcDbEvalNodeId of the node to retrieve incoming edges for.
  973. /// </param>
  974. /// <param name="edges">
  975. /// An array of AcDbEvalEdgeInfo objects describing incoming edges for the
  976. /// node.
  977. /// </param>
  978. ///
  979. /// <returns>
  980. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if
  981. /// the node with the specified id does not exist in the graph.
  982. /// </returns>
  983. ///
  984. virtual Acad::ErrorStatus getIncomingEdges(const AcDbEvalNodeId& nodeId,
  985. AcDbEvalEdgeInfoArray& edges) const;
  986. /// <summary>
  987. /// Returns a list of outgoing edges from a node in the graph.
  988. /// </summary>
  989. ///
  990. /// <param name="nodeId">
  991. /// The AcDbEvalNodeId of the node to retrieve outgoing edges for.
  992. /// </param>
  993. /// <param name="edges">
  994. /// An array of AcDbEvalEdgeInfo objects describing outgoing edges for the
  995. /// node.
  996. /// </param>
  997. ///
  998. /// <returns>
  999. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if
  1000. /// the node with the specified id does not exist in the graph.
  1001. /// </returns>
  1002. ///
  1003. virtual Acad::ErrorStatus getOutgoingEdges(const AcDbEvalNodeId& nodeId,
  1004. AcDbEvalEdgeInfoArray& edges) const;
  1005. /// <summary>
  1006. /// Returns information about an edge between two nodes in a graph.
  1007. /// </summary>
  1008. ///
  1009. /// <param name="nodeFrom">
  1010. /// The AcDbEvalNodeId of the orginating node for the edge.
  1011. /// </param>
  1012. /// <param name="nodeTo">
  1013. /// The AcDbEvalNodeId of the destination node for the edge.
  1014. /// </param>
  1015. /// <param name="einfo">
  1016. /// An AcDbEvalEdgeInfo object describing the edge.
  1017. /// </param>
  1018. ///
  1019. /// <returns>
  1020. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound if
  1021. /// either of the nodes with the specified id does not exist in the graph.
  1022. /// Returns Acad::eGraphEdgeNotFound if edge exists between the nodes.
  1023. /// </returns>
  1024. virtual Acad::ErrorStatus getEdgeInfo(const AcDbEvalNodeId& nodeFrom,
  1025. const AcDbEvalNodeId& nodeTo, AcDbEvalEdgeInfo& einfo) const;
  1026. /// <summary>
  1027. /// Adds the nodes from one graph to another graph by moving the nodes and
  1028. /// edges from the source graph to this graph.
  1029. /// </summary>
  1030. ///
  1031. /// <param name="pGraphToAdd">
  1032. /// The graph containing the nodes and edges to add to this graph.
  1033. /// </param>
  1034. ///
  1035. /// <param name="idMap">
  1036. /// Pointer to output map from old node ids within 'pGraphToAdd' to their
  1037. /// new ids within this graph.
  1038. /// </param>
  1039. ///
  1040. /// <returns>
  1041. /// Returns Acad::eOk if successful.
  1042. /// </returns>
  1043. ///
  1044. /// <remarks>
  1045. /// All nodes and edges in <paramref name="pGraphToAdd"/> are moved to the
  1046. /// destination graph. The argument graph is emptied as as result
  1047. /// of the operation.
  1048. /// </remarks>
  1049. ///
  1050. virtual Acad::ErrorStatus addGraph(AcDbEvalGraph* pGraphToAdd,
  1051. AcDbEvalIdMap*& idMap);
  1052. /* Evaluation */
  1053. /// <summary>
  1054. /// Evaluates the class by traversing the graph and invoking
  1055. /// <c>AcDbEvalExpr::evaluate()</c> on all of the visited nodes.
  1056. /// </summary>
  1057. ///
  1058. /// <returns>
  1059. /// Returns Acad::eOk if succssful. If any of the calls to
  1060. /// <c>AcDbEvalExpr::evaluate()</c> fails the error returned by
  1061. /// <c>AcDbEvalExpr::evaluate()</c> is returned by this method.
  1062. /// </returns>
  1063. ///
  1064. /// <remarks>
  1065. /// Applications must first activate one or more nodes in the graph by
  1066. /// calling <c>AcDbEvalGraph::activatedNodes()</c> before calling this
  1067. /// method.
  1068. /// </remarks>
  1069. ///
  1070. virtual Acad::ErrorStatus evaluate() const;
  1071. /// <summary>
  1072. /// Evaluates the class by traversing the graph and invoking
  1073. /// <c>AcDbEvalExpr::evaluate()</c> on all of the visited nodes.
  1074. /// </summary>
  1075. ///
  1076. /// <param name="pContext">
  1077. /// A pointer to an AcDbEvalContext object that will be passed to each node
  1078. /// as it is visited when calling its <c>AcDbEvalExpr::evaluate()</c>
  1079. /// method.
  1080. /// </param>
  1081. ///
  1082. /// <returns>
  1083. /// Returns Acad::eOk if succssful. If any of the calls to
  1084. /// <c>AcDbEvalExpr::evaluate()</c> fails the error returned by
  1085. /// <c>AcDbEvalExpr::evaluate()</c> is returned by this method.
  1086. /// </returns>
  1087. ///
  1088. /// <remarks>
  1089. /// Applications must first activate one or more nodes in the graph by
  1090. /// calling <c>AcDbEvalGraph::activatedNodes()</c> before calling this
  1091. /// method.
  1092. /// </remarks>
  1093. ///
  1094. virtual Acad::ErrorStatus evaluate(
  1095. const AcDbEvalContext* pContext) const;
  1096. /// <summary>
  1097. /// Evaluates the class by traversing the graph and invoking
  1098. /// <c>AcDbEvalExpr::evaluate()</c> on all of the visited nodes.
  1099. /// </summary>
  1100. ///
  1101. /// <param name="pContext">
  1102. /// A pointer to an AcDbEvalContext object that will be passed to each node
  1103. /// as it is visited when calling its <c>AcDbEvalExpr::evaluate()</c>
  1104. /// method.
  1105. /// </param>
  1106. /// <param name="activatedNodes">
  1107. /// An array of AcDbEvalNodeIds to activate when performing the evaluation.
  1108. /// </param>
  1109. ///
  1110. /// <returns>
  1111. /// Returns Acad::eOk if succssful. If any of the calls to
  1112. /// <c>AcDbEvalExpr::evaluate()</c> fails the error returned by
  1113. /// <c>AcDbEvalExpr::evaluate()</c> is returned by this method.
  1114. /// </returns>
  1115. ///
  1116. /// <remarks>
  1117. /// Applications may activate and evaulate nodes in one step by providing a
  1118. /// non-null <paramref name="activatedNodes"/> array pointer. Otherwise
  1119. /// applications must first activate one or more nodes in the graph by
  1120. /// calling <c>AcDbEvalGraph::activatedNodes()</c> before calling this
  1121. /// method.
  1122. /// </remarks>
  1123. ///
  1124. virtual Acad::ErrorStatus evaluate(
  1125. const AcDbEvalContext* pContext,
  1126. const AcDbEvalNodeIdArray* activatedNodes) const;
  1127. /// <summary>
  1128. /// Activates a collection of nodes in a graph.
  1129. /// </summary>
  1130. ///
  1131. /// <param name="activatedNodes">
  1132. /// An array of AcDbEvalNodeIds of the nodes in the graph to activate.
  1133. /// </param>
  1134. ///
  1135. /// <returns>
  1136. /// Returns Acad::eOk if successful. Returns Acad::eGraphCyclesFound if the
  1137. /// node activation resulted in a cyclic graph.
  1138. /// </returns>
  1139. ///
  1140. /// <remarks>
  1141. /// Applications must activate nodes in a graph before calling
  1142. /// <c>AcDbEvalGraph::evaluate()</c>. Active nodes are used as the starting
  1143. /// point for the directed traversal of the graph during graph evaluation.
  1144. ///
  1145. /// If activatedNodes is empty, all the nodes in the graph are deactivated.
  1146. /// </remarks>
  1147. ///
  1148. virtual Acad::ErrorStatus activate(
  1149. const AcDbEvalNodeIdArray& activatedNodes) const;
  1150. /// <summary>
  1151. /// Activates a collection of nodes in a graph.
  1152. /// </summary>
  1153. ///
  1154. /// <param name="activatedNodes">
  1155. /// An array of AcDbEvalNodeIds of the nodes in the graph to activate.
  1156. /// </param>
  1157. /// <param name="pActiveSubgraph">
  1158. /// An array of the nodes that would be visited given the activated nodes.
  1159. /// </param>
  1160. ///
  1161. /// <returns>
  1162. /// Returns Acad::eOk if successful. Returns Acad::eGraphCyclesFound if the
  1163. /// node activation resulted in a cyclic graph.
  1164. /// </returns>
  1165. ///
  1166. /// <remarks>
  1167. /// Applications must activate nodes in a graph before calling
  1168. /// <c>AcDbEvalGraph::evaluate()</c>. Active nodes are used as the starting
  1169. /// point for the directed traversal of the graph during graph evaluation.
  1170. ///
  1171. /// If activatedNodes is empty, all the nodes in the graph are deactivated.
  1172. /// </remarks>
  1173. ///
  1174. virtual Acad::ErrorStatus activate(
  1175. const AcDbEvalNodeIdArray& activatedNodes,
  1176. AcDbEvalNodeIdArray* pActiveSubgraph) const;
  1177. /// <summary>
  1178. /// Activates a collection of nodes in a graph.
  1179. /// </summary>
  1180. ///
  1181. /// <param name="activatedNodes">
  1182. /// An array of AcDbEvalNodeIds of the nodes in the graph to activate.
  1183. /// </param>
  1184. /// <param name="pActiveSubgraph">
  1185. /// An array of the nodes that would be visited given the activated nodes.
  1186. /// </param>
  1187. /// <param name="pCycleNodes">
  1188. /// An array of the nodes that are cyclic given the activated nodes.
  1189. /// </param>
  1190. ///
  1191. /// <returns>
  1192. /// Returns Acad::eOk if successful. Returns Acad::eGraphCyclesFound if the
  1193. /// node activation resulted in a cyclic graph.
  1194. /// </returns>
  1195. ///
  1196. /// <remarks>
  1197. /// Applications must activate nodes in a graph before calling
  1198. /// <c>AcDbEvalGraph::evaluate()</c>. Active nodes are used as the starting
  1199. /// point for the directed traversal of the graph during graph evaluation.
  1200. ///
  1201. /// If activatedNodes is empty, all the nodes in the graph are deactivated.
  1202. /// </remarks>
  1203. ///
  1204. virtual Acad::ErrorStatus activate(
  1205. const AcDbEvalNodeIdArray& activatedNodes,
  1206. AcDbEvalNodeIdArray* pActiveSubgraph,
  1207. AcDbEvalNodeIdArray* pCycleNodes) const;
  1208. /// <summary>
  1209. /// Determines whether the specified node is activated in the graph.
  1210. /// </summary>
  1211. ///
  1212. /// <param name="id">
  1213. /// The AcDbEvalNodeId of a node in the graph.
  1214. /// </param>
  1215. /// <param name="bIsActive">
  1216. /// True if the specified node exists in the graph and is active, false
  1217. /// otherwise.
  1218. /// </param>
  1219. ///
  1220. /// <returns>
  1221. /// Returns Acad::eOk if successful. Returns Acad::eGraphNodeNotFound no
  1222. /// node with the specified id exists in the graph.
  1223. /// </returns>
  1224. ///
  1225. virtual Acad::ErrorStatus getIsActive(const AcDbEvalNodeId& id,
  1226. bool& bIsActive) const;
  1227. /// <summary>
  1228. /// Determines whether two graphs are 'equal' with equality defined
  1229. /// as Graph A equals Graph B if A is a subgraph of B and B is a subgraph
  1230. /// of A - where 'is a subgraph' is defined by the isSubgraphOf() method
  1231. /// below.
  1232. /// </summary>
  1233. ///
  1234. /// <param name="pOther">
  1235. /// The graph to be tested for equality with
  1236. /// </param>
  1237. ///
  1238. /// <returns>
  1239. /// true if the graphs are equal.
  1240. /// </returns>
  1241. ///
  1242. virtual bool equals(const AcDbEvalGraph* pOther) const;
  1243. /// <summary>
  1244. /// Determines whether the 'this' graph is a subgraph of the graph
  1245. /// passed in as an argument. 'A is a subgraph of B' is defined by
  1246. /// considering of mapping of nodes from A to B map(node) where the
  1247. /// nodeId of node in A is the same as the nodeId of the node
  1248. /// map(node) in B. If no such mapping exists, A is not a subgraph of
  1249. /// B.
  1250. /// If such a mapping exists - the order and types of both the
  1251. /// incoming and outgoing edges from nodes in A have to be a subset of
  1252. /// the incoming and outgoing edges for each of the mapped nodes in B.
  1253. /// If this is true, A is a subgraph of B. If not, A is not a subgraph
  1254. /// of B.
  1255. ///
  1256. /// </summary>
  1257. ///
  1258. /// <param name="pOther">
  1259. /// The graph to be tested against being a subgraph of.
  1260. /// </param>
  1261. ///
  1262. /// <returns>
  1263. /// true if 'this' is a subgraph of 'pOther'
  1264. /// </returns>
  1265. ///
  1266. virtual bool isSubgraphOf(const AcDbEvalGraph* pOther) const;
  1267. /// <summary>
  1268. /// Adds this graph to the database, giving it a
  1269. /// handle and an object ID.
  1270. /// The new object ID is returned in the objId argument.
  1271. /// All of this graph's nodes are added to the database and
  1272. /// this graph is made their owner.
  1273. /// This function does not establish ownership of this graph.
  1274. /// </summary>
  1275. ///
  1276. /// <param name="objId">
  1277. /// Output new object ID obtained by this function.
  1278. /// </param>
  1279. ///
  1280. /// <param name="pDb">
  1281. /// The destination database.
  1282. /// </param>
  1283. ///
  1284. /// <returns>
  1285. /// Returns Acad::eOk if successful.
  1286. /// </returns>
  1287. ///
  1288. virtual Acad::ErrorStatus postInDatabase(AcDbObjectId& objId, AcDbDatabase* pDb);
  1289. };
  1290. ////////////////////////////////////////////////////////////////////////
  1291. // class AcDbEvalEdgeInfo
  1292. ////////////////////////////////////////////////////////////////////////
  1293. /// <summary>
  1294. /// Utility class that holds directed edge information between two nodes in an
  1295. /// AcDbEvalGraph. Instances of this class are returned by calls to edge methods
  1296. /// on AcDbEvalGraph.
  1297. /// </summary>
  1298. ///
  1299. /// <seealso cref="AcDbEvalGraph.getIncomingEdges"/>
  1300. /// <seealso cref="AcDbEvalGraph.getOutgoingEdges"/>
  1301. /// <seealso cref="AcDbEvalGraph.getEdgeInfo"/>
  1302. ///
  1303. class AcDbEvalEdgeInfo
  1304. {
  1305. public:
  1306. /// <summary>
  1307. /// Constructor.
  1308. ///Adesk::UInt32 </summary>
  1309. AcDbEvalEdgeInfo()
  1310. : mFlags(0), mRefCount(0)
  1311. {
  1312. mIdFrom = AcDbEvalGraph::kNullNodeId;
  1313. mIdTo = AcDbEvalGraph::kNullNodeId;
  1314. }
  1315. /// <summary>
  1316. /// Constructor.
  1317. /// </summary>
  1318. ///
  1319. /// <param name="from">
  1320. /// The graph node id of the node from which this edge originates.
  1321. /// </param>
  1322. /// <param name="to">
  1323. /// The graph node id of the node at which this edge terminates.
  1324. /// </param>
  1325. /// <param name="flags">
  1326. /// Description to come.
  1327. /// </param>
  1328. /// <param name="count">
  1329. /// Description to come.
  1330. /// </param>
  1331. AcDbEvalEdgeInfo(AcDbEvalNodeId from,
  1332. AcDbEvalNodeId to,
  1333. Adesk::Int32 flags,
  1334. Adesk::UInt32 count)
  1335. : mIdFrom(from), mIdTo(to), mFlags(flags), mRefCount(count)
  1336. {}
  1337. /// <summary>
  1338. /// The originating node of the edge.
  1339. /// </summary>
  1340. ///
  1341. /// <returns>
  1342. /// The edge's originating node id.
  1343. /// </returns>
  1344. AcDbEvalNodeId from () const;
  1345. /// <summary>
  1346. /// The terminal node of the edge.
  1347. /// </summary>
  1348. ///
  1349. /// <returns>
  1350. /// The edge's terminating node id.
  1351. /// </returns>
  1352. AcDbEvalNodeId to () const;
  1353. /// <summary>
  1354. /// Description to come.
  1355. /// </summary>
  1356. ///
  1357. /// <returns>
  1358. /// Description to come.
  1359. /// </returns>
  1360. ///
  1361. Adesk::UInt32 refCount() const;
  1362. /// <summary>
  1363. /// Indicates whether the edge is invertable, i.e. whether the originating
  1364. /// and terminating nodes can be swapped depending on which of the nodes is
  1365. /// activated.
  1366. /// </summary>
  1367. ///
  1368. /// <returns>
  1369. /// Returns true if the edge is invertable.
  1370. /// </returns>
  1371. bool isInvertible () const;
  1372. /// <summary>
  1373. /// Tests whether an edge is suppressed, i.e. temporarily considered
  1374. /// 'removed' from the graph during activation and/or evaluation.
  1375. /// This flag applies only to an invertible pair of edges, where
  1376. /// during activation one of the directions are 'active' and the
  1377. /// complementary one 'suppressed'
  1378. /// </summary>
  1379. ///
  1380. /// <returns>
  1381. /// true if the edge is active.
  1382. /// </returns>
  1383. ///
  1384. bool isSuppressed () const;
  1385. /// <summary>
  1386. /// Member wise equality
  1387. /// </summary>
  1388. ///
  1389. /// <param name="other">
  1390. /// Item to be tested against for equality.
  1391. /// </param>
  1392. ///
  1393. /// <returns>
  1394. /// true if the two items are equal
  1395. /// </returns>
  1396. ///
  1397. bool operator == (const AcDbEvalEdgeInfo& other) const;
  1398. private:
  1399. AcDbEvalNodeId mIdFrom;
  1400. AcDbEvalNodeId mIdTo;
  1401. Adesk::Int32 mFlags;
  1402. Adesk::UInt32 mRefCount;
  1403. };
  1404. ////////////////////////////////////////////////////////////////////////
  1405. // class AcDbEvalExpr
  1406. ////////////////////////////////////////////////////////////////////////
  1407. //
  1408. /// <summary>
  1409. /// This class represents a single node in an AcDbEvalGraph. The node
  1410. /// represents an action (or "expression"). The owning graph calls the node's
  1411. /// evaluate() method when visiting the node during a traversal of the graph
  1412. /// from within the graph's evaluate().
  1413. /// </summary>
  1414. class AcDbEvalExpr : public AcDbObject
  1415. {
  1416. public:
  1417. ACDB_DECLARE_MEMBERS(AcDbEvalExpr);
  1418. /// <summary>
  1419. /// Default constructor.
  1420. /// </summary>
  1421. ///
  1422. AcDbEvalExpr();
  1423. /// <summary>
  1424. /// Destructor.
  1425. /// </summary>
  1426. ///
  1427. virtual ~AcDbEvalExpr();
  1428. /* Graph methods */
  1429. /// <summary>
  1430. /// Returns a pointer to the graph owning the node.
  1431. /// </summary>
  1432. ///
  1433. /// <param name="pGraph">
  1434. /// Pointer to the graph owning the node.
  1435. /// </param>
  1436. /// <param name="mode">
  1437. /// The AcDb::OpenMode to open the owning graph with.
  1438. /// </param>
  1439. ///
  1440. /// <returns>
  1441. /// Returns Acad::eOk if successful. Returns Acad::eNulNodeId if the node
  1442. /// is not graph-resident.
  1443. /// </returns>
  1444. ///
  1445. /// <remarks>
  1446. /// The caller is responsible for calling <c>close</c> on the returned
  1447. /// graph pointer.
  1448. /// </remarks>
  1449. ///
  1450. Acad::ErrorStatus getGraph(AcDbEvalGraph** pGraph,
  1451. AcDb::OpenMode mode) const;
  1452. /// <summary>
  1453. /// Returns the id of the node.
  1454. /// </summary>
  1455. ///
  1456. /// <returns>
  1457. /// The ID of the node if it is graph-resident. Returns AcDbGraph::kNullId
  1458. /// if the node is not graph-resident.
  1459. /// </returns>
  1460. ///
  1461. /// <remarks>
  1462. /// When a node is added to a graph it is assigned an ID that is unique
  1463. /// among all nodes in the graph. If the node is not graph-resident the id
  1464. /// will be AcDbEvalGraph::kNullNodeId;
  1465. /// </remarks>
  1466. ///
  1467. AcDbEvalNodeId nodeId() const;
  1468. /* Graph notification methods */
  1469. /// <summary>
  1470. /// Called when a node is added to a graph.
  1471. /// </summary>
  1472. ///
  1473. /// <param name="pGraph">
  1474. /// A pointer to the graph the node is added to.
  1475. /// </param>
  1476. ///
  1477. /// <remarks>
  1478. /// AcDbEvalGraph::addNode() calls this method on the node after it has
  1479. /// been added to the graph.
  1480. /// </remarks>
  1481. ///
  1482. virtual void addedToGraph (AcDbEvalGraph* pGraph);
  1483. /// <summary>
  1484. /// Called when a node is removed from a graph.
  1485. /// </summary>
  1486. ///
  1487. /// <param name="pGraph">
  1488. /// A pointer to the graph the node is removed from.
  1489. /// </param>
  1490. ///
  1491. /// <remarks>
  1492. /// AcDbEvalGraph::removeNode() calls this method on the node after it has
  1493. /// been removed from the graph.
  1494. /// </remarks>
  1495. ///
  1496. virtual void removedFromGraph (AcDbEvalGraph* pGraph);
  1497. /// <summary>
  1498. /// Called when a node with a shared edge to this node is removed from the
  1499. /// graph.
  1500. /// </summary>
  1501. ///
  1502. /// <param name="adjNodeId">
  1503. /// The AcDbEvalNodeId of the removed node.
  1504. /// </param>
  1505. ///
  1506. /// <remarks>
  1507. /// AcDbEvalGraph::removeNode() calls this method on nodes with shared
  1508. /// edges to the node being removed.
  1509. /// </remarks>
  1510. ///
  1511. virtual void adjacentNodeRemoved (const AcDbEvalNodeId& adjNodeId);
  1512. /// <summary>
  1513. /// Called when an edge on the node is removed.
  1514. /// </summary>
  1515. ///
  1516. /// <param name="adjEdgeNodeId">
  1517. /// The AcDbEvalNodeId of the node whose shared edge is being removed.
  1518. /// </param>
  1519. ///
  1520. /// <remarks>
  1521. /// AcDbEvalGraph::removeEdge() calls this method on node at either end of
  1522. /// the edge being removed.
  1523. /// </remarks>
  1524. virtual void adjacentEdgeRemoved (const AcDbEvalNodeId& adjEdgeNodeId);
  1525. /// <summary>
  1526. /// Called when an edge is added.
  1527. /// </summary>
  1528. ///
  1529. /// <param name="fromId">
  1530. /// The from AcDbEvalNodeId of the node whose shared edge is being
  1531. /// removed.
  1532. /// </param>
  1533. ///
  1534. /// <param name="toId">
  1535. /// The to AcDbEvalNodeId of the node whose shared edge is being
  1536. /// removed.
  1537. /// </param>
  1538. ///
  1539. /// <param name="bIsInvertible">
  1540. /// Whether the edge is invertible or not.
  1541. /// </param>
  1542. ///
  1543. /// <remarks>
  1544. /// Both the AcDbEvalGraph::addEdge() methods calls this method on each
  1545. /// of the nodes at either end of the edge being added. So, when adding an
  1546. /// invertible edge, for example, Four notifications will occur.
  1547. /// </remarks>
  1548. ///
  1549. virtual void adjacentEdgeAdded (const AcDbEvalNodeId& fromId,
  1550. const AcDbEvalNodeId& toId,
  1551. bool bIsInvertible);
  1552. /// <summary>
  1553. /// Called when a node is about to be moved from pFromGraph to another
  1554. /// graph.
  1555. /// </summary>
  1556. ///
  1557. /// <param name="pFromGraph">
  1558. /// The the graph from which the node is being transplanted from.
  1559. /// </param>
  1560. ///
  1561. /// <remarks>
  1562. /// AcDbEvalGraph::addGraph() calls this method on the node
  1563. /// just before it is added to the destination graph.
  1564. /// </remarks>
  1565. ///
  1566. virtual void movedFromGraph (AcDbEvalGraph* pFromGraph);
  1567. /// <summary>
  1568. /// Called when a node is done being moved from pFromGraph to another
  1569. /// graph.
  1570. /// </summary>
  1571. ///
  1572. /// <param name="pIntoGraph">
  1573. /// The the graph into which the node is being transplanted to.
  1574. /// </param>
  1575. ///
  1576. /// <remarks>
  1577. /// AcDbEvalGraph::addGraph() calls this method on the node
  1578. /// just after it is added to the destination graph.
  1579. /// Since addGraph() copies a disjoint subgraph into the destination
  1580. /// graph, the newly added subgraph is isomorphic to the source
  1581. /// graph in the addGraph operation.
  1582. /// </remarks>
  1583. ///
  1584. virtual void movedIntoGraph (AcDbEvalGraph* pIntoGraph);
  1585. /// <summary>
  1586. /// Called exactly once for each node in a graph after all nodes
  1587. /// in a graph had their ids changed.
  1588. /// </summary>
  1589. ///
  1590. /// <param name="idMap">
  1591. /// Map from old node ids within 'pGraphToAdd' to their new ids within
  1592. /// this graph. Should be empty initially and be the size of the number
  1593. /// of nodes on successful return.
  1594. /// </param>
  1595. ///
  1596. /// <remarks>
  1597. /// AcDbEvalGraph::addGraph() calls this method on each node in the
  1598. /// to-be-added graph just after after all nodes have been added to the
  1599. /// destination graph.
  1600. /// The default behavior is to do nothing. Some subclasses of
  1601. /// AcDbEvalExpr should override this function to update
  1602. /// their references to other nodes.
  1603. /// Nodes should not alter the map.
  1604. /// </remarks>
  1605. ///
  1606. virtual void remappedNodeIds (AcDbEvalIdMap& idMap);
  1607. /// <summary>
  1608. /// Called when a node is done being inserted due to a copy
  1609. /// operation from one graph to another.
  1610. /// </summary>
  1611. ///
  1612. /// <param name="pIntoGraph">
  1613. /// The the graph into which the node is being added to.
  1614. /// </param>
  1615. ///
  1616. /// <remarks>
  1617. /// AcDbEvalGraph::copyFrom() calls this method on the nodes
  1618. /// that are copies from the argument graph nodes. Since all the
  1619. /// nodes from the argument graph, as well as their edges are copied,
  1620. /// the graph structure in 'this' becomes isomorphic to the
  1621. /// graph structure in the source graph.
  1622. /// </remarks>
  1623. ///
  1624. virtual void copiedIntoGraph(AcDbEvalGraph* pIntoGraph);
  1625. /// <summary>
  1626. /// Returns whether this node should be actived
  1627. /// </summary>
  1628. ///
  1629. /// <remarks>
  1630. /// This method allows a node to indicate that its active() method should
  1631. /// not be called directly. The default implementation is to return true,
  1632. /// nodes are by default activatable.
  1633. /// </remarks>
  1634. ///
  1635. virtual bool isActivatable ();
  1636. /// <summary>
  1637. /// Called on graph resident nodes that become active.
  1638. /// </summary>
  1639. ///
  1640. /// <param name="argumentActiveList">
  1641. /// An array of AcDbEvalNodeIds of the nodes being activated in the graph.
  1642. /// </param>
  1643. ///
  1644. /// <remarks>
  1645. /// This method is called by AcDbEvalGraph::activate(), or by
  1646. /// AcDbEvalGraph::evaluate() when it is called with a non-null node
  1647. /// activation arrray, on every node being activated by the call.
  1648. /// </remarks>
  1649. ///
  1650. virtual void activated (AcDbEvalNodeIdArray& argumentActiveList);
  1651. /// <summary>
  1652. /// Called on graph resident nodes before traversing the graph in a call to
  1653. /// AcDbEvalGraph::evaluate().
  1654. /// </summary>
  1655. ///
  1656. /// <param name="bNodeIsActive">
  1657. /// True if the node has been activated for the traversal.
  1658. /// </param>
  1659. ///
  1660. /// <remarks>
  1661. /// This method is called by AcDbEvalGraph::evaluate() for nodes that will
  1662. /// be traversed during the graph evaluation.
  1663. /// </remarks>
  1664. ///
  1665. virtual void graphEvalStart (bool bNodeIsActive);
  1666. /// <summary>
  1667. /// Called on graph resident nodes after traversing the graph in a call to
  1668. /// AcDbEvalGraph::evaluate().
  1669. /// </summary>
  1670. ///
  1671. /// <param name="bNodeIsActive">
  1672. /// True if the node has been activated for the traversal.
  1673. /// </param>
  1674. ///
  1675. /// <remarks>
  1676. /// This method is called by AcDbEvalGraph::evaluate() for nodes that were
  1677. /// visited during the taversal of the graph.
  1678. /// </remarks>
  1679. ///
  1680. virtual void graphEvalEnd (bool bNodeIsActive);
  1681. /// <summary>
  1682. /// Called on graph resident nodes after aborting the traversal of the
  1683. /// graph in a call to AcDbEvalGraph::evaluate().
  1684. /// </summary>
  1685. ///
  1686. /// <param name="bNodeIsActive">
  1687. /// True if the node has been activated for the traversal.
  1688. /// </param>
  1689. ///
  1690. /// <remarks>
  1691. /// This method is called by AcDbEvalGraph::evaluate() for nodes that were
  1692. /// in the traversal list of an aborted graph evaluation.
  1693. /// </remarks>
  1694. ///
  1695. virtual void graphEvalAbort (bool bNodeIsActive);
  1696. /* Evaluation methods */
  1697. /// <summary>
  1698. /// Causes the expression represented by the node to be evaluated. Called
  1699. /// by for a graph-resident node when the node is visited during a call to
  1700. /// <c>AcDbEvalGraph::evaluate()</c>
  1701. /// </summary>
  1702. ///
  1703. /// <param name="ctxt">
  1704. /// A pointer to the AcDbEvalContext object used for the graph evaluation.
  1705. /// May be NULL.
  1706. /// </param>
  1707. ///
  1708. /// <returns>
  1709. /// Returns Acad::eOk if successful. Any non successful result terminates
  1710. /// the graph traversal.
  1711. /// </returns>
  1712. ///
  1713. /// <remarks>
  1714. /// The default implementation does nothing and returns Acad::eOk.
  1715. /// </remarks>
  1716. ///
  1717. virtual Acad::ErrorStatus evaluate(const AcDbEvalContext* ctxt);
  1718. /// <summary>
  1719. /// Determines if two AcDbEvalExprs are equal. The default
  1720. /// implementation is to check that the concrete class types
  1721. /// are the same, i.e. this->isA() == pOther->isA().
  1722. /// </summary>
  1723. ///
  1724. /// <param name="pOther">
  1725. /// Argument to be tested for equality against.
  1726. /// </param>
  1727. ///
  1728. /// <returns>
  1729. /// true if the objects are equal.
  1730. /// </returns>
  1731. ///
  1732. virtual bool equals(const AcDbEvalExpr* pOther) const;
  1733. /* Expression value methods */
  1734. /// <summary>
  1735. /// The value of the variant node.
  1736. /// </summary>
  1737. ///
  1738. /// <returns>
  1739. /// An AcDbEvalVariant representing the value of the evaluated expression.
  1740. /// </returns>
  1741. ///
  1742. /// <remarks>
  1743. /// The value is usually updated during the <c>AcDbEvalExpr::evaluate()</c>
  1744. /// call. The default value is uninitialized
  1745. /// (<c>AcDbEvalVariant::Type::kNone</c>).
  1746. /// </remarks>
  1747. ///
  1748. AcDbEvalVariant value() const;
  1749. /// <summary>
  1750. /// Adds this object to the database, giving it a
  1751. /// handle and an object ID.
  1752. /// The new object ID is returned in the objId argument.
  1753. /// This function does not establish ownership of this object.
  1754. /// Subclasses with child objects should override this
  1755. /// function to add them to the database at this time and
  1756. /// establish ownership.
  1757. /// </summary>
  1758. ///
  1759. /// <param name="objId">
  1760. /// Output new object ID obtained by this function.
  1761. /// </param>
  1762. ///
  1763. /// <param name="pDb">
  1764. /// The destination database.
  1765. /// </param>
  1766. ///
  1767. /// <returns>
  1768. /// Returns Acad::eOk if successful.
  1769. /// </returns>
  1770. ///
  1771. virtual Acad::ErrorStatus postInDatabase(AcDbObjectId& objId, AcDbDatabase* pDb);
  1772. protected:
  1773. /// <summary>
  1774. /// The value of the expression. <seealso cref="value"/>.
  1775. /// </summary>
  1776. ///
  1777. /// <remarks>
  1778. /// The default implementation does not persist this value, nor does it
  1779. /// ever update it from its initialized value
  1780. /// (<c>AcDbEvalVaraint::Type::kNone</c>).
  1781. /// </remarks>
  1782. ///
  1783. AcDbEvalVariant m_lastValue;
  1784. friend class AcDbImpEvalExpr;
  1785. };
  1786. ////////////////////////////////////////////////////////////////////////
  1787. // class AcDbEvalConnectable
  1788. ////////////////////////////////////////////////////////////////////////
  1789. /// <summary>
  1790. /// This class implements a runtime inspection interface for named properties
  1791. /// on AcDbEvalExpr objects. Objects implementing this class expose a
  1792. /// collection of named, typed properties and semantics for "connecting"
  1793. /// properties between AcDbEvalGraph resident connectable instances.
  1794. /// </summary>
  1795. ///
  1796. class AcDbEvalConnectable : public AcDbEvalExpr
  1797. {
  1798. public:
  1799. ACDB_DECLARE_MEMBERS(AcDbEvalConnectable);
  1800. /// <summary>
  1801. /// Destructor.
  1802. /// </summary>
  1803. ///
  1804. virtual ~AcDbEvalConnectable();
  1805. /* Connection Inspection */
  1806. /// <summary>
  1807. /// Returns an array of named connections.
  1808. /// </summary>
  1809. ///
  1810. /// <param name="names">
  1811. /// Returned array of named connections.
  1812. /// </param>
  1813. ///
  1814. /// <returns>
  1815. /// Acad::eOk if successful.
  1816. /// </returns>
  1817. ///
  1818. virtual Acad::ErrorStatus getConnectionNames (AcStringArray& names) const;
  1819. /// <summary>
  1820. /// Tests whether an object exposes a connection.
  1821. /// </summary>
  1822. ///
  1823. /// <param name="name">
  1824. /// The name of the connection to test for.
  1825. /// </param>
  1826. ///
  1827. /// <returns>
  1828. /// True if a connection with the specified name exists.
  1829. /// </returns>
  1830. ///
  1831. virtual bool hasConnectionNamed (const AcString& name) const;
  1832. /// <summary>
  1833. /// Returns the <c>AcDbEvalVariant::Type</c> of a named connection.
  1834. /// </summary>
  1835. ///
  1836. /// <param name="name">
  1837. /// The name of the connection to return the type of.
  1838. /// </param>
  1839. /// <param name="type">
  1840. /// The type of the named connection.
  1841. /// </param>
  1842. ///
  1843. /// <returns>
  1844. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if no
  1845. /// connection with the specified name exists.
  1846. /// </returns>
  1847. ///
  1848. virtual Acad::ErrorStatus getConnectionType (
  1849. const AcString& name,
  1850. AcDb::DwgDataType& type) const;
  1851. /* Connection Operations */
  1852. /// <summary>
  1853. /// Returns the value of a named connection.
  1854. /// </summary>
  1855. ///
  1856. /// <param name="name">
  1857. /// The name of the connection to return the value of.
  1858. /// </param>
  1859. /// <param name="value">
  1860. /// The value of the named connection.
  1861. /// </param>
  1862. ///
  1863. /// <returns>
  1864. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if no
  1865. /// connection with the specified name exists.
  1866. /// </returns>
  1867. ///
  1868. virtual Acad::ErrorStatus getConnectionValue (
  1869. const AcString& name,
  1870. AcDbEvalVariant& value) const;
  1871. /// <summary>
  1872. /// Sets the value of a named connection.
  1873. /// </summary>
  1874. ///
  1875. /// <param name="name">
  1876. /// The name of the connection to set the value of.
  1877. /// </param>
  1878. /// <param name="value">
  1879. /// The new value of the named connection.
  1880. /// </param>
  1881. ///
  1882. /// <returns>
  1883. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if no
  1884. /// connection with the specified name exists.
  1885. /// </returns>
  1886. virtual Acad::ErrorStatus setConnectionValue (
  1887. const AcString& name,
  1888. const AcDbEvalVariant& value);
  1889. /// <summary>
  1890. /// Connects a named connection on this object to a connection on
  1891. /// another AcDbEvalConnectable. Both objects must be graph-resident.
  1892. /// </summary>
  1893. ///
  1894. /// <param name="thisConnection">
  1895. /// The name of the connection on this object.
  1896. /// </param>
  1897. /// <param name="sourceConnectableId">
  1898. /// The AcDbEvalNodeId of the other connectable.
  1899. /// </param>
  1900. /// <param name="sourceConnectionName">
  1901. /// The name of the connection on the other connectable.
  1902. /// </param>
  1903. ///
  1904. /// <returns>
  1905. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if either
  1906. /// object does not expose its respective named connection.
  1907. /// </returns>
  1908. ///
  1909. virtual Acad::ErrorStatus connectTo (
  1910. const AcString& thisConnection,
  1911. const AcDbEvalNodeId sourceConnectableId,
  1912. const AcString& sourceConnectionName);
  1913. /// <summary>
  1914. /// Disconnects a named connection on this object from a connection on
  1915. /// another AcDbEvalConnectable. Both objects must be graph-resident.
  1916. /// </summary>
  1917. ///
  1918. /// <param name="thisConnection">
  1919. /// The name of the connection on this object.
  1920. /// </param>
  1921. /// <param name="sourceConnectableId">
  1922. /// The AcDbEvalNodeId of the other connectable.
  1923. /// </param>
  1924. /// <param name="sourceConnectionName">
  1925. /// The name of the connection on the other connectable.
  1926. /// </param>
  1927. ///
  1928. /// <returns>
  1929. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if either
  1930. /// object does not expose its respective named connection.
  1931. /// </returns>
  1932. ///
  1933. virtual Acad::ErrorStatus disconnectFrom (
  1934. const AcString& thisConnection,
  1935. const AcDbEvalNodeId sourceConnectableId,
  1936. const AcString& sourceConnectionName);
  1937. /// <summary>
  1938. /// Determines whether a connection is allowed between to objects.
  1939. /// </summary>
  1940. ///
  1941. /// <param name="thisConnection">
  1942. /// The name of the connection on this object.
  1943. /// </param>
  1944. /// <param name="sourceConnectableId">
  1945. /// The AcDbEvalNodeId of the other connectable.
  1946. /// </param>
  1947. /// <param name="sourceConnectionName">
  1948. /// The name of the connection on the other connectable.
  1949. /// </param>
  1950. ///
  1951. /// <returns>
  1952. /// Returns Acad::eOk if the connection is allowed. Returns
  1953. /// Acad::eKeyNotFound if either object does not expose its respective
  1954. /// named connection.
  1955. /// </returns>
  1956. ///
  1957. virtual bool connectionAllowed (
  1958. const AcString& thisConnection,
  1959. const AcDbEvalNodeId sourceConnectableId,
  1960. const AcString& sourceConnectionName) const;
  1961. /*---- Connection Information ---*/
  1962. /// <summary>
  1963. /// Returns a list objects connected to an exposed connection.
  1964. /// </summary>
  1965. ///
  1966. /// <param name="thisConnection">
  1967. /// The name of the connection on this object.
  1968. /// </param>
  1969. /// <param name="connectedObjects">
  1970. /// An array of AcDbEvalNodeIds of objects connected to the exposed
  1971. /// connection.
  1972. /// </param>
  1973. ///
  1974. /// <returns>
  1975. /// Returns Acad::eOk if the connection is allowed. Returns
  1976. /// Acad::eKeyNotFound if the object does not expose the named connection.
  1977. /// </returns>
  1978. ///
  1979. virtual Acad::ErrorStatus getConnectedObjects (
  1980. const AcString& thisConnection,
  1981. AcDbEvalNodeIdArray& connectedObjects) const;
  1982. /// <summary>
  1983. /// Returns a list connection names shared between a named connection on this
  1984. /// object and another connected object.
  1985. /// </summary>
  1986. ///
  1987. /// <param name="thisConnection">
  1988. /// The name of the connection on this object.
  1989. /// </param>
  1990. /// <param name="sourceConnectableId">
  1991. /// The AcDbEvalNodeId of the other connected object.
  1992. /// </param>
  1993. /// <param name="sourceConnectionNames">
  1994. /// An array of AcStrings identifying the connections on <paramref
  1995. /// name="sourceConnectableId"/> connected to <paramref
  1996. /// name="thisConnection"/>.
  1997. /// </param>
  1998. ///
  1999. /// <returns>
  2000. /// Returns Acad::eOk if the connection is allowed. Returns
  2001. /// Acad::eKeyNotFound if the object does not expose the named connection.
  2002. /// </returns>
  2003. ///
  2004. virtual Acad::ErrorStatus getConnectedNames (
  2005. const AcString& thisConnection,
  2006. const AcDbEvalNodeId sourceConnectableId,
  2007. AcStringArray& sourceConnectionNames) const;
  2008. protected:
  2009. /// <summary>
  2010. /// Default constructor.
  2011. /// </summary>
  2012. ///
  2013. AcDbEvalConnectable();
  2014. };
  2015. ////////////////////////////////////////////////////////////////////////
  2016. // class AcDbEvalContext
  2017. ////////////////////////////////////////////////////////////////////////
  2018. /// <summary>
  2019. /// This class implements a simple container for application data that can be
  2020. /// used during the evaluation of an AcDbEvalGraph. The graph passes any
  2021. /// AcDbEvalContext object supplied in a call to
  2022. /// <c>AcDbEvalGraph::evaluate()</c> to each node in the graph when calling
  2023. /// <c>AcDbEvalExpr::evaluate()</c> during the ensuing traversal. Graph client
  2024. /// applications typically use the context to store application-specific data
  2025. /// used by custom nodes during their evaluation.
  2026. /// </summary>
  2027. ///
  2028. ///
  2029. class AcDbEvalContext : public AcRxObject, public AcHeapOperators
  2030. {
  2031. public:
  2032. /// <summary>
  2033. /// Default constructor.
  2034. /// </summary>
  2035. ///
  2036. AcDbEvalContext();
  2037. /// <summary>
  2038. /// Destructor.
  2039. /// </summary>
  2040. ///
  2041. virtual ~AcDbEvalContext();
  2042. ACRX_DECLARE_MEMBERS(AcDbEvalContext);
  2043. /* Collection access methods */
  2044. /// <summary>
  2045. /// Inserts an AcDbEvalContextPair into the context.
  2046. /// </summary>
  2047. ///
  2048. /// <param name="pair">
  2049. /// The AcDbEvalContextPair to insert into the context.
  2050. /// </param>
  2051. ///
  2052. /// <remarks>
  2053. /// If an AcDbEvalContextPair with the specified key already exists it is
  2054. /// replaced with the new pair.
  2055. /// </remarks>
  2056. virtual void insertAt (const AcDbEvalContextPair& pair);
  2057. /// <summary>
  2058. /// Removes an AcDbEvalContextPair from the context.
  2059. /// </summary>
  2060. ///
  2061. /// <param name="szKey">
  2062. /// The key of the AcDbEvalContextPair to remove from the context.
  2063. /// </param>
  2064. ///
  2065. virtual void removeAt (const ACHAR* szKey);
  2066. /// <summary>
  2067. /// Returns an AcDbEvalContextPair stored in the context.
  2068. /// </summary>
  2069. ///
  2070. /// <param name="pair">
  2071. /// The AcDbEvalContextPair to insert into the context.
  2072. /// </param>
  2073. ///
  2074. /// <returns>
  2075. /// Returns Acad::eOk if successful. Returns Acad::eKeyNotFound if no entry
  2076. /// exists with the specified key.
  2077. /// </returns>
  2078. ///
  2079. /// <remarks>
  2080. /// The <paramref name="pair"/> passed in should be initialized with the
  2081. /// desired key to return in the context. If the key exists <paramref
  2082. /// name="pair"/> is updated with the value from the context.
  2083. /// </remarks>
  2084. ///
  2085. virtual Acad::ErrorStatus getAt (AcDbEvalContextPair& pair) const;
  2086. /// <summary>
  2087. /// Returns a new AcDbEvalContextIterator for the context.
  2088. /// </summary>
  2089. ///
  2090. /// <returns>
  2091. /// A new AcDbEvalContextIterator. Callers must delete the iterator when it
  2092. /// is no longer needed by calling <c>delete</c>.
  2093. /// </returns>
  2094. ///
  2095. virtual AcDbEvalContextIterator* newIterator() const;
  2096. private:
  2097. AcDbImpEvalContext* mpImp;
  2098. friend class AcDbImpEvalContextIterator;
  2099. };
  2100. ////////////////////////////////////////////////////////////////////////
  2101. // class AcDbEvalContextPair
  2102. //////////////////////////////////////////////////////////////////////////
  2103. /// <summary>
  2104. /// The AcDbEvalContextPair class represents a single entry in an
  2105. /// AcDbEvalContext container.
  2106. /// </summary>
  2107. ///
  2108. /// <remarks>
  2109. /// This is a simple key-value pair stored in an AcDbEvalContext. The values
  2110. /// are void pointers. Neither this class nor the AcDbEvalContext class are
  2111. /// responsible for managing the memory allocated to the values stored in the
  2112. /// context.
  2113. /// </remarks>
  2114. ///
  2115. class AcDbEvalContextPair : public AcHeapOperators
  2116. {
  2117. public:
  2118. /// <summary>
  2119. /// Default constructor.
  2120. /// </summary>
  2121. ///
  2122. AcDbEvalContextPair();
  2123. /// <summary>
  2124. /// Constructor.
  2125. /// </summary>
  2126. ///
  2127. /// <param name="szKey">
  2128. /// The key used to lookup the pair in an AcDbEvalContext.
  2129. /// </param>
  2130. /// <param name="pValue">
  2131. /// A pointer to the data stored in the context pair.
  2132. /// </param>
  2133. ///
  2134. AcDbEvalContextPair(const ACHAR* szKey, void *pValue);
  2135. /// <summary>
  2136. /// Destructor.
  2137. /// </summary>
  2138. ///
  2139. virtual ~AcDbEvalContextPair();
  2140. /// <summary>
  2141. /// Sets the key used to lookup the pair in an AcDbEvalContext.
  2142. /// </summary>
  2143. ///
  2144. /// <param name="szKey">
  2145. /// The key used to lookup the pair in an AcDbEvalContext.
  2146. /// </param>
  2147. ///
  2148. void setKey (const ACHAR* szKey);
  2149. /// <summary>
  2150. /// Gets the key used to lookup the pair in an AcDbEvalContext.
  2151. /// </summary>
  2152. ///
  2153. /// <returns>
  2154. /// The key used to lookup the pair in an AcDbEvalContext.
  2155. /// </returns>
  2156. ///
  2157. const ACHAR* key () const;
  2158. /// <summary>
  2159. /// Sets the values stored with the pair in an AcDbEvalContext.
  2160. /// </summary>
  2161. ///
  2162. /// <param name="pValue">
  2163. /// The value to store in the AcDbEvalContextPair.
  2164. /// </param>
  2165. ///
  2166. /// <remarks>
  2167. /// The memory pointed to by <paramref name="pValue"/> must be allocated and
  2168. /// freed by the caller.
  2169. /// </remarks>
  2170. void setValue (void* pValue);
  2171. /// <summary>
  2172. /// Gets the values stored with the pair in an AcDbEvalContext.
  2173. /// </summary>
  2174. ///
  2175. /// <returns>
  2176. /// The value stored in the AcDbEvalContextPair.
  2177. /// </returns>
  2178. ///
  2179. void* value () const;
  2180. private:
  2181. ACHAR* mKey;
  2182. void* mValue;
  2183. };
  2184. ////////////////////////////////////////////////////////////////////////
  2185. // class AcDbEvalContextIterator
  2186. ////////////////////////////////////////////////////////////////////////
  2187. /// <summary>
  2188. /// Provides access to the contents of an AcDbEvalContext collection.
  2189. /// </summary>
  2190. ///
  2191. /// <remarks>
  2192. /// AcDbEvalContextIterator instances are returned by calls to AcDbEvalContext::newIterator().
  2193. /// </remarks>
  2194. ///
  2195. class AcDbEvalContextIterator : public AcRxObject, public AcHeapOperators
  2196. {
  2197. public:
  2198. /// <summary>
  2199. /// Default constructor.
  2200. /// </summary>
  2201. ///
  2202. AcDbEvalContextIterator();
  2203. /// <summary>
  2204. /// Destructor.
  2205. /// </summary>
  2206. ///
  2207. virtual ~AcDbEvalContextIterator();
  2208. ACRX_DECLARE_MEMBERS(AcDbEvalContextIterator);
  2209. /// <summary>
  2210. /// Initializes the iterator to the start of the collection.
  2211. /// </summary>
  2212. ///
  2213. virtual void start();
  2214. /// <summary>
  2215. /// Advances the iterator to the next object in the collection.
  2216. /// </summary>
  2217. ///
  2218. /// <returns>
  2219. /// Returns true when the iterator has reached the end of the collection.
  2220. /// </returns>
  2221. ///
  2222. virtual bool next();
  2223. /// <summary>
  2224. /// Determines whether the iterator has reached the end of the collection.
  2225. /// </summary>
  2226. ///
  2227. /// <returns>
  2228. /// Returns true if the iterator has reached the end of the collection.
  2229. /// </returns>
  2230. ///
  2231. virtual bool done() const;
  2232. /// <summary>
  2233. /// Returns the AcDbEvalContextPair at the current iterator position.
  2234. /// </summary>
  2235. ///
  2236. /// <returns>
  2237. /// The AcDbEvalContextPair at the current iterator position.
  2238. /// </returns>
  2239. virtual AcDbEvalContextPair contextPair() const;
  2240. private:
  2241. AcDbEvalContextIterator(AcDbEvalContext* pContext);
  2242. AcDbImpEvalContextIterator* mpImp;
  2243. friend class AcDbImpEvalContext;
  2244. };
  2245. #pragma pack(pop)