imgdef.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. //
  12. //
  13. #ifndef __IMGDEF_H
  14. #define __IMGDEF_H 1
  15. #include "dbmain.h"
  16. #include "acgi.h"
  17. #include "gept2dar.h"
  18. #include "gemat2d.h"
  19. #include "AdAChar.h"
  20. #pragma pack (push, 8)
  21. // Forward declarations
  22. //
  23. class RasterImageDefImp; // Opaque type
  24. class AcDbImpRasterImageDefReactor; // Opaque type
  25. namespace Atil
  26. {
  27. class Image;
  28. class FileReadDescriptor;
  29. };
  30. enum ClassVersion
  31. {
  32. kVersion1 = 0, // S039 Oct 21, 1996
  33. kVersion2 = 1, // S052 Jan 16, 1996
  34. kVersion3 = 2 // S061 Mar 21, 1997
  35. };
  36. // Make compiler shut up
  37. //
  38. #pragma warning( disable : 4275 )
  39. #ifdef ISMDLLACCESS
  40. #undef ISMDLLACCESS
  41. #endif
  42. #ifdef ISMDLLACCESSDATA
  43. #undef ISMDLLACCESSDATA
  44. #endif
  45. #ifdef ISM_OBJ // For DwgUnplugged ISMobj.arx:
  46. // Classes to be exported have to have ISMDLLACCESS definition in its header.
  47. // Example: class ISMDLLACCESS AcDbImpRasterImageDef
  48. #define ISMDLLACCESS __declspec(dllexport)
  49. #define ISMDLLACCESSDATA
  50. #else
  51. #define ISMDLLACCESS
  52. #define ISMDLLACCESSDATA __declspec(dllimport)
  53. #endif
  54. // The AcDbRasterImageDef object controls the actual image data
  55. // associated with one or more AcDbRasterImage entities. These objects
  56. // hold image data in one of two ways. The first way is through
  57. // "linking" the raster file to the dwg file as with Xrefs. The second
  58. // way is through "embedding" as with block insert.
  59. //
  60. class IAcReadStream;
  61. class ISMDLLACCESS AcDbRasterImageDef : public AcDbObject
  62. {
  63. public:
  64. static ClassVersion classVersion();
  65. ACRX_DECLARE_MEMBERS(AcDbRasterImageDef);
  66. AcDbRasterImageDef();
  67. virtual ~AcDbRasterImageDef();
  68. RasterImageDefImp* ptrImp() const;
  69. RasterImageDefImp* setPtrImp(RasterImageDefImp* pImp);
  70. // AcDbObject overridden methods
  71. //
  72. virtual Acad::ErrorStatus subErase(Adesk::Boolean erasing);
  73. virtual Acad::ErrorStatus subClose();
  74. virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* filer);
  75. virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* filer) const;
  76. virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* filer);
  77. virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* filer) const;
  78. // AcDbRasterImageDef specific methods
  79. //
  80. virtual AcGiSentScanLines* makeScanLines(
  81. const AcGiRequestScanLines* pReq,
  82. const AcGeMatrix2d& pixToScreen,
  83. AcGePoint2dArray* pActiveClipBndy = 0, // Data will be modified!
  84. Adesk::Boolean draftQuality = false,
  85. Adesk::Boolean isTransparent = false,
  86. const double brightness = 50.0,
  87. const double contrast = 50.0,
  88. const double fade = 0.0
  89. ) const;
  90. virtual Acad::ErrorStatus setSourceFileName(const ACHAR * pPathName);
  91. virtual Acad::ErrorStatus setActiveFileName(const ACHAR * pPathName);
  92. virtual const ACHAR * searchForActivePath();
  93. virtual const ACHAR * sourceFileName() const;
  94. virtual const ACHAR * activeFileName() const;
  95. virtual Acad::ErrorStatus embed();
  96. virtual Adesk::Boolean isEmbedded() const;
  97. virtual Acad::ErrorStatus load();
  98. virtual Acad::ErrorStatus unload(Adesk::Boolean modifyDatabase = true);
  99. virtual Adesk::Boolean isLoaded() const;
  100. virtual AcGeVector2d size() const;
  101. // The following two methods require the image to be loaded,
  102. // otherwise they return default values that may not be correct
  103. // for the image.
  104. //
  105. virtual AcGiImageOrg organization() const;
  106. virtual int colorDepth() const;
  107. virtual const ACHAR * fileType() const;
  108. virtual int entityCount(
  109. Adesk::Boolean* pbLocked = 0
  110. ) const;
  111. virtual void updateEntities() const;
  112. enum Units
  113. {
  114. kNone = 0,
  115. kMillimeter = 1,
  116. kCentimeter = 2,
  117. kMeter = 3,
  118. kKilometer = 4,
  119. kInch = 5,
  120. kFoot = 6,
  121. kYard = 7,
  122. kMile = 8,
  123. kMicroinches = 9,
  124. kMils = 10,
  125. kAngstroms = 11,
  126. kNanometers = 12,
  127. kMicrons = 13,
  128. kDecimeters = 14,
  129. kDekameters = 15,
  130. kHectometers = 16,
  131. kGigameters = 17,
  132. kAstronomical = 18,
  133. kLightYears = 19,
  134. kParsecs = 20
  135. };
  136. virtual Acad::ErrorStatus setResolutionMMPerPixel(
  137. const AcGeVector2d& resMMPerPixel);
  138. virtual AcGeVector2d resolutionMMPerPixel() const;
  139. virtual void setResolutionUnits(
  140. AcDbRasterImageDef::Units units);
  141. virtual Units resolutionUnits() const;
  142. // Thumbnail functions
  143. //
  144. virtual Acad::ErrorStatus loadThumbnail(
  145. Adesk::UInt16& maxWidth,
  146. Adesk::UInt16& maxHeight,
  147. Adesk::UInt8* pPalette = 0,
  148. int nPaletteEntries = 0
  149. );
  150. virtual Acad::ErrorStatus unloadThumbnail();
  151. virtual void* createThumbnailBitmap(
  152. BITMAPINFO*& pBitmapInfo,
  153. Adesk::UInt8 brightness = 50,
  154. Adesk::UInt8 contrast = 50,
  155. Adesk::UInt8 fade = 0
  156. );
  157. ////////////////////////////////////////////////
  158. // Image access
  159. ////////////////////////////////////////////////
  160. // Obtain copy of image
  161. //
  162. virtual Atil::Image* imageCopy(Adesk::Boolean bForceImageLoad = true) const;
  163. virtual Atil::FileReadDescriptor* fileDescCopy() const;
  164. // Open direct access to current image
  165. //
  166. virtual Acad::ErrorStatus openImage(Atil::Image*& pImage);
  167. // Close direct access
  168. //
  169. virtual Acad::ErrorStatus closeImage();
  170. // Create directly from in-memory IE image and/or file descriptor.
  171. //
  172. virtual Acad::ErrorStatus setImage(const Atil::Image* pImage,
  173. const Atil::FileReadDescriptor* pFileDesc,
  174. Adesk::Boolean modifyDatabase = true);
  175. // Set undo store size
  176. //
  177. virtual Acad::ErrorStatus setUndoStoreSize(
  178. unsigned int maxImages = 10
  179. );
  180. virtual unsigned int undoStoreSize() const;
  181. // Get/set "image modified" flag
  182. //
  183. virtual Adesk::Boolean imageModified() const;
  184. virtual Acad::ErrorStatus setImageModified(Adesk::Boolean modified);
  185. //Get the stream associated with the image
  186. virtual IAcReadStream* getReadStream();
  187. // This method will force the ISM to release its hold on the image file.
  188. // This is a dangerous thing to do as if the image file is released it maybe
  189. // erased or changed while the ISM continues to refer to it. The ISM holds
  190. // many items about the image in the file. If any of the statistics of the image
  191. // within the image file, or the format of the image file, while the ISM remains
  192. // in a "loaded" state, the it can cause serious errors that could result in
  193. // drawing or work loss (through an exception).
  194. //
  195. // Take care in making use of this function to alter the look of an image without
  196. // unloading and reloading it from the ISM. Its use is not recommended.
  197. Acad::ErrorStatus forceImageFileClosed(Adesk::Boolean modifyDatabase);
  198. ////////////////////////////////////////////////
  199. // Image dictionary access
  200. ////////////////////////////////////////////////
  201. // Create/get image dictionary
  202. //
  203. static Acad::ErrorStatus createImageDictionary(AcDbDatabase* pDb, AcDbObjectId& dictId);
  204. static AcDbObjectId imageDictionary(AcDbDatabase* pDb);
  205. // Derive image def. name from file name. Handles duplicates.
  206. // Use the following enum constant for the buffer size of
  207. // of newImageName.
  208. //
  209. enum { kMaxSuggestNameSize = 2049 };
  210. // This overload, without the size arg, will go away in a future
  211. // release. Please convert to the other overload.
  212. ADESK_DEPRECATED static Acad::ErrorStatus suggestName(
  213. AcDbDictionary* pImageDictionary,
  214. const ACHAR* pNewImagePathName,
  215. ACHAR* newImageName
  216. );
  217. static Acad::ErrorStatus suggestName(
  218. AcDbDictionary* pImageDictionary,
  219. const ACHAR* pNewImagePathName,
  220. ACHAR* newImageName,
  221. size_t nSize
  222. );
  223. private:
  224. // These are here because otherwise dllexport tries to export the
  225. // private methods of AcDbObject. They're private in AcDbObject
  226. // because vc5 does not properly support array new and delete.
  227. // It tends to call the wrong delete operator and to not call
  228. // the dtors on all elements in the array. So we make them private
  229. // in order to prevent usage of them.
  230. //
  231. #ifdef MEM_DEBUG
  232. #undef new
  233. #undef delete
  234. #endif
  235. void *operator new[](size_t) throw(){ return (void*)0;}
  236. void operator delete[](void *) {};
  237. // Unicode: leave as char for now
  238. void *operator new[](size_t , const char *, int ) throw(){ return (void*)0;}
  239. #ifdef MEM_DEBUG
  240. #define new DEBUG_NEW
  241. #define delete DEBUG_DELETE
  242. #endif
  243. // Data members
  244. //
  245. RasterImageDefImp* mpImp;
  246. static ClassVersion mVersion;
  247. };
  248. //gets the implementation class pointer
  249. inline RasterImageDefImp*
  250. AcDbRasterImageDef::ptrImp() const
  251. {
  252. return mpImp;
  253. }
  254. //sets the implementation class pointer
  255. inline RasterImageDefImp*
  256. AcDbRasterImageDef::setPtrImp(RasterImageDefImp* pImp)
  257. {
  258. RasterImageDefImp* oldImp=mpImp;
  259. mpImp=pImp;
  260. return oldImp;
  261. }
  262. // Persistent reactor used to connect AcDbRasterImage entities to
  263. // AcDbRasterImageDef objects. It can be used by other applications
  264. // as a persistent reactor to receive the special "imageSave" notification.
  265. //
  266. class ISMDLLACCESS AcDbRasterImageDefReactor : public AcDbObject
  267. {
  268. public:
  269. static ClassVersion classVersion();
  270. ACRX_DECLARE_MEMBERS(AcDbRasterImageDefReactor);
  271. AcDbRasterImageDefReactor();
  272. virtual ~AcDbRasterImageDefReactor();
  273. virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* filer);
  274. virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* filer) const;
  275. virtual Acad::ErrorStatus dxfInFields(AcDbDxfFiler* filer);
  276. virtual Acad::ErrorStatus dxfOutFields(AcDbDxfFiler* filer) const;
  277. // Notification
  278. //
  279. virtual void erased(const AcDbObject* dbObj,
  280. Adesk::Boolean pErasing = true
  281. );
  282. virtual void modified(const AcDbObject* dbObj);
  283. // Delete image notification.
  284. //
  285. enum DeleteImageEvent
  286. {
  287. kUnload = 1,
  288. kErase = 2,
  289. };
  290. virtual Adesk::Boolean onDeleteImage(
  291. const AcDbRasterImageDef* pImageDef,
  292. Atil::Image* pImage,
  293. DeleteImageEvent event,
  294. Adesk::Boolean cancelAllowed);
  295. // Enable/disable notification actions
  296. //
  297. static void setEnable(Adesk::Boolean enable);
  298. private:
  299. // These are here because otherwise dllexport tries to export the
  300. // private methods of AcDbObject. They're private in AcDbObject
  301. // because vc5 does not properly support array new and delete.
  302. // It tends to call the wrong delete operator and to not call
  303. // the dtors on all elements in the array. So we make them private
  304. // in order to prevent usage of them.
  305. //
  306. #ifdef MEM_DEBUG
  307. #undef new
  308. #undef delete
  309. #endif
  310. void *operator new[](size_t ) throw() { return (void*)0;}
  311. void operator delete[](void *) {};
  312. // Unicode: leave as char for now
  313. void *operator new[](size_t, const char *, int ) throw(){ return (void*)0;}
  314. #ifdef MEM_DEBUG
  315. #define new DEBUG_NEW
  316. #define delete DEBUG_DELETE
  317. #endif
  318. // Data members
  319. //
  320. AcDbImpRasterImageDefReactor* mpImp;
  321. static ClassVersion mVersion;
  322. };
  323. // Transient reactor to receive the special "onDeleteImage" notification from
  324. // AcDbRasterImageDef objects. This is a pure virtual class, so the developer
  325. // must derive from this and override the onDeleteImage function.
  326. //
  327. class ISMDLLACCESS AcDbRasterImageDefTransReactor : public AcDbObjectReactor
  328. {
  329. public:
  330. ACRX_DECLARE_MEMBERS(AcDbRasterImageDefTransReactor);
  331. virtual ~AcDbRasterImageDefTransReactor();
  332. // Custom notification
  333. //
  334. virtual Adesk::Boolean onDeleteImage(const AcDbRasterImageDef* pImageDef,
  335. Atil::Image* pImage,
  336. AcDbRasterImageDefReactor::DeleteImageEvent event,
  337. Adesk::Boolean cancelAllowed) = 0;
  338. };
  339. class ISMDLLACCESS AcDbRasterImageDefFileAccessReactor : public AcDbObjectReactor
  340. {
  341. public:
  342. ACRX_DECLARE_MEMBERS(AcDbRasterImageDefFileAccessReactor);
  343. virtual ~AcDbRasterImageDefFileAccessReactor();
  344. virtual void onAttach(
  345. const AcDbRasterImageDef*,
  346. const ACHAR * pPath) = 0;
  347. virtual void onDetach(
  348. const AcDbRasterImageDef*,
  349. const ACHAR * pPath) = 0;
  350. virtual Adesk::Boolean onOpen(
  351. const AcDbRasterImageDef*,
  352. const ACHAR * pPath,
  353. const ACHAR * pActivePath,
  354. Adesk::Boolean& replacePath,
  355. ACHAR *& replacementPath) = 0;
  356. virtual Adesk::Boolean onPathChange(
  357. const AcDbRasterImageDef*,
  358. const ACHAR * pPath,
  359. const ACHAR * pActivePath,
  360. Adesk::Boolean& replacePath,
  361. ACHAR *& replacementPath) = 0;
  362. virtual void onClose(
  363. const AcDbRasterImageDef*,
  364. const ACHAR * pPath) = 0;
  365. virtual void onDialog(
  366. AcDbRasterImageDef*,
  367. const ACHAR * pCaption,
  368. const ACHAR * pFileExtensions
  369. ) = 0;
  370. };
  371. //////////////////// inlines ////////////////////
  372. //
  373. inline ClassVersion
  374. AcDbRasterImageDef::classVersion()
  375. { return mVersion; }
  376. inline ClassVersion
  377. AcDbRasterImageDefReactor::classVersion()
  378. { return mVersion; }
  379. #pragma warning( default : 4275 )
  380. #pragma pack (pop)
  381. #endif // __IMGDEF_H