dbunderlayhost.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. #ifndef ACDB_DBDWFHOST_H
  14. #define ACDB_DBDWFHOST_H
  15. #include "dbmain.h"
  16. #include "acstring.h"
  17. #pragma pack (push, 8)
  18. class AcImpUnderlayLayer;
  19. class IAcReadStream;
  20. class AcUnderlayLayer
  21. {
  22. public:
  23. AcUnderlayLayer();
  24. ~AcUnderlayLayer();
  25. ACDB_PORT AcUnderlayLayer(AcUnderlayLayer const &);
  26. ACDB_PORT AcUnderlayLayer const & operator= (AcUnderlayLayer const &);
  27. friend ACDB_PORT bool operator == (AcUnderlayLayer const & l, AcUnderlayLayer const & r);
  28. typedef enum {
  29. kOff=0,
  30. kOn=1} State;
  31. AcString name() const;
  32. State state() const;
  33. Acad::ErrorStatus setName(const AcString& name);
  34. Acad::ErrorStatus setState(State state);
  35. private:
  36. AcImpUnderlayLayer* m_pImpUnderlayLayer;
  37. };
  38. /// <summary>
  39. /// Provides additional information for drawing an underlay.
  40. /// </summary>
  41. struct AcDbUnderlayDrawContext
  42. {
  43. ///<summary>Contrast at which the item should be drawn.</summary>
  44. Adesk::UInt8 contrast;
  45. ///<summary>The fade for the item to be drawn.</summary>
  46. Adesk::UInt8 fade;
  47. ///<summary>True if the item should be drawn monochrome.</summary>
  48. bool monochrome;
  49. ///<summary>True if the item should consider changing some of the colors to make them more visible on the current background.</summary>
  50. bool adjustColorForBackground;
  51. ///<summary>An null terminated array of UnderlayLayers to have their state set before drawing.</summary>
  52. AcUnderlayLayer** pLayers;
  53. };
  54. /// <summary>
  55. /// used by the AcDbUnderlayItem::version() function as the version at the time the application was
  56. /// compiled.
  57. /// </summary>
  58. const int kItemVersionNumber = 1;
  59. /// <summary>
  60. /// This interface is implemented by host applications that wish to support underlays.
  61. /// AcDbUnderlayDefinition and AcDbUnderlayReference uses this interface to accomplish their mission.
  62. /// </summary>
  63. class ADESK_NO_VTABLE AcDbUnderlayItem
  64. {
  65. public:
  66. /// <summary>
  67. /// Destroys the item. All resources related to item should be freed.
  68. /// </summary>
  69. virtual ~AcDbUnderlayItem() = 0;
  70. /// <summary>
  71. /// Gets the unique name (within the file) for the item.
  72. /// </summary>
  73. /// <returns>Returns the name of the item.</returns>
  74. virtual AcString getName() const = 0;
  75. /// <summary>
  76. /// Gets the preview bitmap for the item.
  77. /// </summary>
  78. /// <param name="thumbnail">Contains the bitmap upon successful return. The caller is repsonsible for freeing this data structure using GlobalFree().</param>
  79. /// <returns>Returns Acad::eOk if successful.</returns>
  80. virtual Acad::ErrorStatus getThumbnail(
  81. BITMAPINFO*& thumbnail) const = 0;
  82. /// <summary>
  83. /// Gets the extents in item-model coordinates. AcDbUnderlayReference::transform() provides the transformation matrix from item-model coordinates to
  84. /// block space coordinates (block space coordinates usually equal to WCS coordinates unless the AcDbUnderlayReference is part of a block).
  85. /// </summary>
  86. /// <param name="min">Minimum point.</param>
  87. /// <param name="max">Maximum point.</param>
  88. /// <returns>Returns Acad::eOk if successful.</returns>
  89. virtual Acad::ErrorStatus getExtents(
  90. AcGePoint2d& min,
  91. AcGePoint2d& max) const = 0;
  92. /// <summary>
  93. /// Gets the units used by the item.
  94. /// </summary>
  95. /// <returns>Returns the units used by the item.</returns>
  96. virtual AcDb::UnitsValue getUnits() const = 0;
  97. /// <summary>
  98. /// Specifies whether or not the item is using only some of the content of the sheet/model represented
  99. /// by the item
  100. /// </summary>
  101. /// <returns>Returns true if the item is not using all of the content, otherwise returns false.</returns>
  102. virtual bool usingPartialContent() const = 0;
  103. /// <summary>
  104. /// Draws the item for all viewports or for a given viewport. The <paramref name="pWorldDraw"/> and <paramref name="pViewportdraw"/> parameters cannot be both
  105. /// non-null at the same time.
  106. /// </summary>
  107. /// <param name="pWorldDraw">NULL if no viewport-independent drawing should be done. Otherwise non-null.</param>
  108. /// <param name="pViewportDraw">NULL if no dependent drawing should be done. Otherwise non-null.</param>
  109. /// <param name="context">Additional parameters on how the underlay should be drawn.</param>
  110. /// <returns>Returns Acad::eOk if successful.</returns>
  111. virtual Acad::ErrorStatus draw(
  112. AcGiWorldDraw* pWorldDraw,
  113. AcGiViewportDraw* pViewportDraw,
  114. const AcDbUnderlayDrawContext& context) const = 0;
  115. /// <summary>
  116. /// Provides a transformation matrix that transforms underlay geometry to the item-model coordinates. This is usually an identity matrix or
  117. /// a simple translation that "rebases" the geometry to a "base point".
  118. /// </summary>
  119. /// <returns>Returns a transformation matrix that transforms underlay geometry to the item-model coordinates.</returns>
  120. virtual AcGeMatrix3d modelTransform() const = 0;
  121. /// <summary>
  122. /// Obtains osnap points for the underlay item. See also AcDbEntity::getOsnapPoints.
  123. /// </summary>
  124. /// <param name="modelToWorld">transformation matrix from "item-model" to block space coordinates (block space coordinates usually equal to WCS coordinates unless the AcDbUnderlayReference is part of a block).</param>
  125. /// <param name="osnapMode">Input osnap mode being requested.</param>
  126. /// <param name="gsSelectionMark">Input GS marker of the subentity involved in the object snap operation.</param>
  127. /// <param name="pickPoint">Input point (in WCS coordinates) picked during the object snap operation.</param>
  128. /// <param name="lastPoint">Input point (in WCS coordinates) selected just before pickPoint.</param>
  129. /// <param name="viewXform">Input transformation matrix to transform from WCS to DCS.</param>
  130. /// <param name="snapPoints">Input pre-existing array to append osnap points to (may already contain points); output with object snap points appended.</param>
  131. /// <param name="geomIds">Not in use</param>
  132. /// <returns>Returns Acad::eOk if successful</returns>
  133. virtual Acad::ErrorStatus getOsnapPoints(const AcGeMatrix3d& modelToWorld,
  134. AcDb::OsnapMode osnapMode,
  135. Adesk::GsMarker gsSelectionMark,
  136. const AcGePoint3d& pickPoint,
  137. const AcGePoint3d& lastPoint,
  138. const AcGeMatrix3d& viewXform,
  139. AcGePoint3dArray& snapPoints,
  140. AcDbIntArray & geomIds)
  141. const = 0;
  142. /// <summary>
  143. /// Obtains the subentity at a given selection marker. See also: AcDbEntity::subentPtr and AcDbEntity::getFullSubentPathsAtGsMarker.
  144. /// </summary>
  145. /// <param name="modelToWorld">Transformation matrix from "item-model" to block space coordinates (block space coordinates usually equal to WCS coordinates unless the AcDbUnderlayReference is part of a block).</param>
  146. /// <param name="gsSelectionMark">The selection marker for which the subentity is requested. Underlays do not support multiple subentities for a gs marker.</param>
  147. /// <returns>Returns Acad::eOk if successful</returns>
  148. virtual AcDbEntity* getSubEntityAtGsMarker(const AcGeMatrix3d& modelToWorld,Adesk::GsMarker gsSelectionMark) const = 0;
  149. /// <summary>
  150. /// Intersect the underlay item with another object. See also AcDbEntity::intersectWith.
  151. /// </summary>
  152. /// <param name="modelToWorld">Transformation matrix from "item-model" to block space coordinates (block space coordinates usually equal to WCS coordinates unless the AcDbUnderlayReference is part of a block).</param>
  153. /// <param name="pEnt">Input entity with which "this" entity is to intersect.</param>
  154. /// <param name="intType">Input type of intersection requested.</param>
  155. /// <param name="projPlane">Input projection plane for the apparent intersection of the two entities.</param>
  156. /// <param name="points">Output with the points of intersection appended.</param>
  157. /// <param name="thisGsMarker">Input GS marker of subentity of "this" entity that's involved in the intersection operation. Use the 0 default if not applicable.</param>
  158. /// <param name="otherGsMarker">Input GS marker of subentity of the entity pointed to by pEnt that's involved in the intersection operation. Use the 0 default if not applicable.</param>
  159. /// <returns>Returns Acad::eOk if successful.</returns>
  160. virtual Acad::ErrorStatus intersectWith(const AcGeMatrix3d& modelToWorld,
  161. const AcDbEntity* pEnt,
  162. AcDb::Intersect intType,
  163. const AcGePlane* projPlane,
  164. AcGePoint3dArray& points,
  165. Adesk::GsMarker thisGsMarker,
  166. Adesk::GsMarker otherGsMarker) const = 0;
  167. /// <summary>
  168. /// Get number of underlay layers - default implementation returns 0
  169. /// </summary>
  170. /// <returns>Returns number of layers or 0 if no layer information available</returns>
  171. virtual Adesk::UInt32 underlayLayerCount() const { return 0; }
  172. /// <summary>
  173. /// Get Underlay layer name
  174. /// for the layer at given index
  175. /// </summary>
  176. /// <returns>Returns Acad::eOk if successful</returns>
  177. virtual Acad::ErrorStatus getUnderlayLayer(int idx, AcUnderlayLayer& layer) const {
  178. UNREFERENCED_PARAMETER(idx);
  179. UNREFERENCED_PARAMETER(layer);
  180. return Acad::eNotImplemented;
  181. }
  182. /// <summary>
  183. /// Used to determine the version of the underlayItem.
  184. /// </summary>
  185. /// <returns> Returns the version number in effect when the application was compiled when called
  186. /// from the application, returns current version when called internally</returns>
  187. int version() const;
  188. };
  189. class ADESK_NO_VTABLE AcDbDgnUnderlayItem : public AcDbUnderlayItem
  190. {
  191. public:
  192. /// <summary>
  193. /// Gets a boolean indicating whether the underlayItem uses master units
  194. /// in the DGN file when the DGN file is being translated to DWG for
  195. /// the underlay to use.
  196. /// </summary>
  197. /// <returns>
  198. /// Returns true, if the underlay uses Master units during translation.
  199. /// </returns>
  200. virtual bool useMasterUnits() const = 0;
  201. /// <summary>
  202. /// Sets a boolean indicating whether the underlayItem uses master units
  203. /// in the DGN file when the DGN file is being translated to DWG for
  204. /// the underlay to use.
  205. /// WARNING: Do not use this method on an item that is in use by AcDbUnderlayReferences
  206. /// that are currently displayed on screen. Instead, use the
  207. /// AcDbDgnDefinition::setUseMasterUnits() which will cause all references to
  208. /// update their graphics.
  209. /// </summary>
  210. /// <param name="bUseMasterUnits">
  211. /// Input bool indicating whether or not to use master units during translation.
  212. /// </param>
  213. virtual void setUseMasterUnits(bool bUseMasterUnits) = 0;
  214. /// <summary>
  215. /// Gets a boolean indicating whether raster images should be displayed
  216. /// in referenced (xref) DGN files.
  217. /// </summary>
  218. /// <returns>
  219. /// Returns true, if images should be displayed in referenced DGN files.
  220. /// </returns>
  221. virtual bool showRasterRef() const = 0;
  222. /// <summary>
  223. /// Sets a boolean indicating whether raster images should be displayed
  224. /// in referenced DGN files.
  225. /// </summary>
  226. /// <param name="bShow">
  227. /// Input bool indicating whether or not to display raster images in
  228. /// referenced DGN files.
  229. /// </param>
  230. virtual void setShowRasterRef(bool bShow) = 0;
  231. };
  232. /// <summary>
  233. /// This interface is implemented by host applications that wish to support underlays.
  234. /// AcDbUnderlayDefinition and AcDbUnderlayReference use this interface to accomplish their mission.
  235. /// </summary>
  236. class ADESK_NO_VTABLE AcDbUnderlayFile
  237. {
  238. public:
  239. /// <summary>
  240. /// Destroys the file. All resources related to file should be freed.
  241. /// </summary>
  242. virtual ~AcDbUnderlayFile() = 0;
  243. /// <summary>
  244. /// Gets the number of items in the file.
  245. /// </summary>
  246. /// <returns>Returns the number of items in the file.</returns>
  247. virtual int getItemCount() const = 0;
  248. /// <summary>
  249. /// Gets an item by index.
  250. /// </summary>
  251. /// <param name="i">Index of the item to be retrieved.</param>
  252. /// <param name="pItem">Variable that receives the item upon successful return.</param>
  253. /// <returns>Returns Acad::eOk if successful.</returns>
  254. virtual Acad::ErrorStatus getItem(
  255. int i,
  256. AcDbUnderlayItem*& pItem) const = 0;
  257. /// <summary>
  258. /// Gets an item by name.
  259. /// </summary>
  260. /// <param name="name">Name of the item to be retrieved.</param>
  261. /// <param name="pItem">Variable that receives the item upon successful return.</param>
  262. /// <returns>Returns Acad::eOk if successful.</returns>
  263. virtual Acad::ErrorStatus getItem(
  264. const ACHAR* name,
  265. AcDbUnderlayItem*& pItem) const = 0;
  266. };
  267. /// <summary>
  268. /// This interface is implemented by host applications that wish to support underlays.
  269. /// AcDbUnderlayDefinition and AcDbUnderlayReference use this interface to accomplish their mission.
  270. /// </summary>
  271. class ADESK_NO_VTABLE AcDbUnderlayHost
  272. {
  273. public:
  274. /// <summary>
  275. /// Gets an underlay file.
  276. /// </summary>
  277. /// <param name="fullPath">Fully qualified path to the file to open.</param>
  278. /// <param name="password">Optional password. If the password is NULL but is required then getFile will prompt the user for password.</param>
  279. /// <param name="pFile">Variable that receives the file upon successful return.</param>
  280. /// <returns>Returns Acad::eOk if successful.</returns>
  281. virtual Acad::ErrorStatus getFile(
  282. const ACHAR* fullPath,
  283. const wchar_t* password,
  284. AcDbUnderlayFile*& pFile) const = 0;
  285. /// <summary>
  286. /// This function sets pFile to point to an AcDbUnderlayFile that for the
  287. /// file in the stream pointed to by IAcReadStream for the file pointed to by pFile.
  288. /// </summary>
  289. /// <param name="pFileStream">Input the IAcReadStream for the file</param>
  290. /// <param name="password">Input optional password. If the password is NULL but is required then getFile will prompt the user for password.</param>
  291. /// <param name="pFile">Output the AcDbUnderlayFile object for the stream</param>
  292. /// <returns>Returns Acad::eOk if successful.</returns>
  293. virtual Acad::ErrorStatus getFile(
  294. IAcReadStream* pFileStream,
  295. const wchar_t* password,
  296. AcDbUnderlayFile*& pFile) const = 0;
  297. /// <summary>
  298. /// Implements the uniform underlay color adjustment algorithm.
  299. /// The algorithm performs the following operations:
  300. /// 1. Interpolates <paramref name="rgbInputColor"/> towards <paramref name="rgbCurrentBackgroundColor"/> in RGB space <paramref name="drawContext.fade"/> percent.
  301. /// 2. Converts the resulting RGB color to HSL.
  302. /// 3. Interpolates the lightness of the resulting color towards <paramref name="hslFadedContrastColor"/> <paramref name="drawContext.contrast"/> percent.
  303. /// 4. If <paramref name="drawContext.monochrome"/> is true it sets the hue and saturation of the resulting color to 0.
  304. /// 5. Converst the resulting HSL value to RGB and stores it in <paramref name="rgbResult"/>.
  305. /// </summary>
  306. /// <param name="rgbResult">The resulting RGB value where x is red [0,1], y is green and z [0,1] is blue [0,1].</param>
  307. /// <param name="rgbInputColor">The input RGB value where x is red [0,1], y is green [0,1] and z is blue [0,1].</param>
  308. /// <param name="rgbCurrentBackgroundColor">The current background color in RGB that the underlay content will be renderred against.</param>
  309. /// <param name="hslFadedContrastColor">The contrast color in HSL.</param>
  310. /// <param name="drawContext">Provides additional input parameters for the color adjustment algorithm.</param>
  311. static void getAdjustedColor(
  312. AcGeVector3d& rgbResult,
  313. const AcGeVector3d& rgbInputColor,
  314. const AcGeVector3d& rgbCurrentBackgroundColor,
  315. const AcGeVector3d& hslFadedContrastColor,
  316. const AcDbUnderlayDrawContext& drawContext);
  317. protected:
  318. ///<summary>Destructor.</summary>
  319. virtual ~AcDbUnderlayHost() = 0;
  320. };
  321. /// <summary>
  322. /// Gets the current DWF underlay host.
  323. /// </summary>
  324. /// <returns>returns the DWF underlay host.</returns>
  325. ACDB_PORT AcDbUnderlayHost*
  326. acdbGetCurrentDwfHost();
  327. /// <summary>
  328. /// Sets the current DWF underlay host.
  329. /// </summary>
  330. /// <param name="pHost">The new host application to use.</param>
  331. /// <returns>Returns the previous DWF underlay host.</returns>
  332. ACDB_PORT AcDbUnderlayHost*
  333. acdbSetCurrentDwfHost(
  334. AcDbUnderlayHost* pHost);
  335. /// <summary>
  336. /// Gets the current DGN underlay host.
  337. /// </summary>
  338. /// <returns>returns the DGN underlay host.</returns>
  339. ACDB_PORT AcDbUnderlayHost*
  340. acdbGetCurrentDgnHost();
  341. /// <summary>
  342. /// Sets the current DGN underlay host.
  343. /// </summary>
  344. /// <param name="pHost">The new host application to use.</param>
  345. /// <returns>Returns the previous DGN underlay host.</returns>
  346. ACDB_PORT AcDbUnderlayHost*
  347. acdbSetCurrentDgnHost(
  348. AcDbUnderlayHost* pHost);
  349. /// <summary>
  350. /// Gets the current DGN underlay host that uses the current document for OLE entities.
  351. /// </summary>
  352. /// <returns>returns the DGN underlay host.</returns>
  353. ACDB_PORT AcDbUnderlayHost*
  354. acdbGetCurrentDgnDocHost();
  355. /// <summary>
  356. /// Sets the current DGN underlay host that uses the current document for OLE entities.
  357. /// </summary>
  358. /// <param name="pHost">The new host application to use.</param>
  359. /// <returns>Returns the previous DGN underlay host.</returns>
  360. ACDB_PORT AcDbUnderlayHost*
  361. acdbSetCurrentDgnDocHost(
  362. AcDbUnderlayHost* pHost);
  363. /// <summary>
  364. /// Converts a color from RGB to HSL (also known as HLS) color space.
  365. /// </summary>
  366. /// <param name="rgb">The resulting RGB value where x is red [0,1], y is green and z [0,1] is blue [0,1].</param>
  367. /// <param name="hsl">The input HSL value where x is the hue [0,1], y is the saturation [0,1] and z is lightness [0,360].</param>
  368. ACDB_PORT void
  369. acdbConvertRgbToHsl(
  370. const AcGeVector3d& rgb,
  371. AcGeVector3d& hsl
  372. );
  373. /// <summary>
  374. /// Converts a color from HSL(also known as HLS) RGB color space.
  375. /// </summary>
  376. /// <param name="hsl">The resulting HSL value where x is the hue [0,1], y is the saturation [0,1] and z is lightness [0,360].</param>
  377. /// <param name="rgb">The input RGB value where x is red [0,1], y is green [0,1] and z is blue [0,1].</param>
  378. ACDB_PORT void
  379. acdbConvertHslToRgb(
  380. const AcGeVector3d& hsl,
  381. AcGeVector3d& rgb);
  382. /// <summary>
  383. /// This function returns true when it is called while a DGN to DWG file translation is in progress.
  384. /// </summary>
  385. bool acdbIsDgnToDwgInProgress();
  386. /// <summary>
  387. /// Gets the current PDF underlay host.
  388. /// </summary>
  389. /// <returns>returns the PDF underlay host.</returns>
  390. ACDB_PORT AcDbUnderlayHost*
  391. acdbGetCurrentPdfHost();
  392. /// <summary>
  393. /// Sets the current PDF underlay host.
  394. /// </summary>
  395. /// <param name="pHost">The new host application to use.</param>
  396. /// <returns>Returns the previous DWF underlay host.</returns>
  397. ACDB_PORT AcDbUnderlayHost*
  398. acdbSetCurrentPdfHost(AcDbUnderlayHost* pHost);
  399. #pragma pack (pop)
  400. #endif