CGM Objects Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
CgmObjects.h
1 // CgmObjects.h: interface for the CCgmObjects class.
2 //
5 
6 #if !defined(AFX_CGMOBJECTS_H__2E7AF564_0E6D_4CCD_8851_A39A36D9E58D__INCLUDED_)
7 #define AFX_CGMOBJECTS_H__2E7AF564_0E6D_4CCD_8851_A39A36D9E58D__INCLUDED_
8 
9 
10 #pragma once
11 
12 #define MAX_COLOR_INDEXES 4096
13 
14 #include <string>
15 #include <vector>
16 #include <set>
17 
18 #include "ElementList.h"
19 #include "LineEdgeTypes.h"
20 #include "HatchStyles.h"
21 #include "PatternTables.h"
22 #include "AppStruct.h"
23 #include "Clipping.h"
24 #include "Utility/LPoint.h"
25 #include "FontMap.h"
26 #include "Utility/Color.h"
27 #include "Utility/Config.h"
28 #include "Utility/wstring.h"
29 #include "AppStruct.h"
30 #include "Segment.h"
31 #include "CgmObj.h"
32 #include "GeometricPatterns.h"
33 #include "WebcgmConfig.h"
34 
392 namespace Larson {
393 
394 template<class T>
395  class ClassCallback //: public Callback
396  {
397  T* _classPtr;
398  typedef void(T::*fncb)(int dwTime);
399  fncb _cbProc;
400  public:
401  ClassCallback(T* classPtr,fncb cbProc):_classPtr(classPtr),_cbProc(cbProc){}
402  virtual void operator()(int param){
403  (_classPtr->*_cbProc)(param);
404  }
405  };
406 
408  #define CGMI_NO_ERROR 0
409  #define CGMI_OPEN_ERROR 1
410  #define ESYNTAX_ERROR -1
411  #define EUNDEFINED_ELEMENT 10
413  #define EMEMSPACE 11
414  #define EINVAL_BUNDLE 12
415  #define EBADLINX 13
416  #define EBADFILX 14
417  #define EBADPATN 15
418  #define EBADCOLX 16
419  #define ERLEDECODE 17
420  #define EBADDATA 18
421  #define EFIGOPEN 19
422  #define EFIGNOPEN 20
423  #define EPATHOPEN 21
424  #define EPATHNOTOPEN 22
425  #define EBADINDEX 23
426  #define ESEGOPEN 24
429  #define ESEGNOPEN 25
430  #define ENPOINTS 26
431  #define EGDPDATA 27
432  #define EESCDATA 28
433  #define ESTRING_DECODE_ERROR 29
434  #define EREAD_LENGTH 30
435  #define ECTX_DECODE 31
436  #define EPNG_FAILED 32
437  #define EAPS_END_MISSING 33
438  #define EBAD_POINT 34
439  #define EBAD_PARAMETER 35
440  #define ETOO_MANY_UNRECOGNIZED 36
441  #define EINVAL_FONTIX 37
442  #define ENEWREGION 38
443  #define EINVAL_MODE 39
444  #define EINVAL_IX 40
445  #define ENOBEGPIC 41
446  #define ENOBEGINMF 42
447  #define ECHAR_ENCODING 43
448  #define EFILE_NOT_CGM 44
449  #define EUNKNOWN_THROW 98
450  #define EBADSTATE 99
451 
453  typedef struct CgmInError {
454  int klass, element, code;
455  } CgmInError;
456 
457 
458  class CCgmIn;
459  class CDrawBase;
460  class CCgmBaseObj;
461  class CClipping;
462  class CSegment;
463 
466  public:
467  virtual void OnNextElement(long klass, long elementNumber, CCgmIn* pCgmIn) = 0; // pure virtual callback function
468 };
469 
470 
472  class CCgmObjects : public CElementList
473  {
474  friend class CAppStruct;
475 
476 
477  private:
478  ElementCallback* pElementCallback;
479  public:
480  void nextElement(long klass, long elementNumber, CCgmIn* pCgmIn)
481  {
482  if(pElementCallback)
483  pElementCallback->OnNextElement(klass, elementNumber, pCgmIn);
484  };
485 
486  public:
487 
488  enum CharCodingAnnouncer {
489  charCodingBasic7 = 0,
490  charCodingBasic8 = 1,
491  charCodingExt7 = 2,
492  charCodingExt8 = 3
493  };
494 
495  enum ColorModel {
496  colorModelRGB = 1,
497  colorModelCIELAB = 2,
498  colorModelCIELUV = 3,
499  colorModelCMYK = 4,
500  colorModelRGBRelated = 5,
501  colorModelRGBAlpha = 6,
502  colorModelsRGB = 7,
503  colorModelsRGBAlpha = 8
504  };
505 
506  enum RealPrecisionType {
507  realPrecFloat = 0,
508  realPrecFixed = 1
509  };
510 
511  enum ScalingMode {
512  scalingModeAbstract = 0,
513  scalingModeMetric = 1
514  };
515 
516  enum VDCType {
517  vdcTypeInt = 0,
518  vdcTypeReal = 1
519  };
520 
521  enum VdcPrecision {
522  vdcPrecision16int = 0,
523  vdcPrecision32int = 1,
524  vdcPrecision32fp = 2,
525  vdcPrecision64fp = 3 };
526 
527 #ifndef CGMOBJECTS_NO_SAVE
528  typedef struct CGMSaveOptions
532  {
533  bool unicode;
534  VdcPrecision vdcPrecision;
535  int bwRasterCompression;
536  int colorRasterCompression;
537  int autoConvertTo1BPP;
538  std::wstring profileId;
539  std::wstring profileEdition;
540  std::wstring description;
541 
544  /*
545  // 0 = no change
546  // 1 = convert all colors to greyscale
547  // 2 = change all fill colors to greyscale
553  int monoEnhance;
559  int colorConvert;
560 
562  bool bMediaColor;
564  unsigned char mediaColorRed, mediaColorGreen, mediaColorBlue;
565  */
566  } CGMSaveOptions;
567 
568  static void CGMSaveOptionsInit(CGMSaveOptions *pOptions)
569  {
570  pOptions->autoConvertTo1BPP = 0;
571  pOptions->bwRasterCompression = 0; // BwRasterCompressionNone;
572  pOptions->colorRasterCompression = 0; // ColorRasterCompressionNone;
573  pOptions->vdcPrecision= CCgmObjects::vdcPrecision32fp;
574  pOptions->unicode = false;
575  pOptions->profileId = L"WebCGM";
576  pOptions->profileEdition = L"2.0";
577  pOptions->description = L"\"ColourClass:Colour\",\"Source:Larson Software Technology,Inc.\"";
578  pOptions->colorModel = 0;
579  /*
580  pOptions->monoEnhance = 0; // no mono-enhancement
581  pOptions->colorConvert = 0; // no color conversion
582  pOptions->bMediaColor = false; // use backgound color from CGM objects
583  pOptions->mediaColorRed = pOptions->mediaColorGreen = pOptions->mediaColorBlue = 0;
584  */
585  };
586 #endif
587 
589  typedef struct charSet {
590  unsigned char m_csType;
591  std::wstring m_csTail;
592  } charSet;
593 
595  typedef struct {
596  int classCode;
597  int elementIdCode;
599 
601 
604  CCgmObjects(Larson::CConfig* config, webcgmConfig* pWebcgmConfig = NULL);
605 
607  virtual ~CCgmObjects();
608 
611 
613  void ReCalcList(vector<PicElement> &elList);
614 
618  long LoadFile(std::wstring inputFile, int iPicture, std::vector<CgmInError> *pErrorList = NULL, ElementCallback* pElementCallback = NULL);
619 
623  long LoadFile(string inputFile, int iPicture, std::vector<CgmInError> *pErrorList = NULL, ElementCallback* pElementCallback = NULL);
624 
626  void Draw(CDrawBase *pDB, bool showRegions = false, bool exportAps = false);
627 
629  void DrawList(CDrawBase* pDB, vector<PicElement> &gData, bool showRegions = false, bool exportAps = false);
630 
632  bool Merge(CCgmObjects* pMergeObjects, CMatrix* pXForm);
633 
635  Larson::CConfig* getConfig() { return m_pConfig; };
636 
638  void add(CCgmBaseObj *pObj);
639 
641  void add(CSegment *pSegment);
642 
644  void add(CAppStruct *pAppStruct);
645 
647  void closeAppStruct();
648 
650  void add(PicElement& elem);
651 
653  DRect GetBounds(bool locus = false) const;
654 
655 #ifndef CGMOBJECTS_NO_SAVE
656  long Save(const std::wstring& outFile, CGMSaveOptions* pOptions);
658 
661  long Save(const std::string& outFile, std::string profile, CGMSaveOptions* pOptions);
662 #endif
663 
665  // monoEnhance:
666  // 0 = no change
667  // 1 = convert all colors to greyscale
668  // 2 = change all fill colors to greyscale
680  void ConvertColors(int monoEnhance, int colorConvert);
681 
682  void ConvertColorsList(vector<PicElement> &elList, int monoEnhance, int colorConvert);
683 
685  std::string getVersion();
686 
689 
691  std::wstring m_metafileDescription;
692 
694  std::wstring m_metafileId;
695 
698 
701 
703  bool m_unicode;
704 
706  vector<charSet> m_charSets;
707 
709  enum CharCodingAnnouncer m_charCodingAnnouncer;
710 
713 
716 
718  Larson::DPoint m_maxVdcExtent[2];
719 
722 
725 
728 
731 
734 
736  enum ColorModel m_colorModel;
737 
739  struct {
740  long selection;
741  double refWhiteX, refWhiteY, refWhiteZ;
742  double rgbMat[3][3];
743  double abcMat[3][3];
744  long numberEntries;
747 
749  struct {
750  RealPrecisionType type;
751  int exponent;
752  int mantissa;
753  } m_realPrecision;
754 
756  vector<std::wstring> m_symbolLibraryList;
757 
759  struct {
760  int min, max;
762 
764  enum VDCType m_vdcType;
765 
769  double m_defVDCextDy;
770 
772  vector<metafileElementListEntry> m_metafileElementList;
773 
775  vector<CSegment*> m_globalSegments;
776 
778  typedef struct {
779  std::wstring pictureId;
780  long pictureLocationOffset;
781  long apsLocationOffset;
782  } pictureDirEntry;
783 
784  struct {
785  int locationDataType;
786  vector<pictureDirEntry> pictureList;
787  } m_pictureDirectory;
788 
790  struct {
791  long characterSetIndex;
792  long characterSetType;
793  std::wstring tail;
794  long octetsPerCode;
795  long glyphSouce;
796  vector<long> glyphCodeList;
797  } m_glyphMapping;
798 
799 
800 
802  std::wstring m_pictureId;
803 
805  Larson::DPoint m_vdcExtent[2];
806 
808  vector<CSegment*> m_localSegments;
809 
811  enum ScalingMode m_scalingMode;
812 
815 
817  Larson::CColorTableEntry m_colorTable[MAX_COLOR_INDEXES];
818 
820  CColor getColorTable(long index);
821 
824 
827 
830 
833 
836 
837 
844  std::wstring getKeywordValue(std::wstring string, std::wstring keyword);
845 
847  std::wstring ConformCGMFontNames(std::wstring &fontName);
848 
851 
854  long m_curClippingPathIndicator;
855  ClipRectangle* m_curClipRectangle;
856 
859  CColor m_regionDrawLineColor;
860  int m_regionDrawStyle; // 0= outline, 1= fill, 2= fill + outline
861  std::wstring m_hotspotIdPrefix; // APS id prefix of hotspots, * is wildcard
862 
865 
870  Larson::DPoint vdc2nvdc(Larson::DPoint vdc);
871  Larson::DPoint nvdc2vdc(Larson::DPoint nvdc);
872 
875 
878 
879  private:
880  bool containsUnicode(std::wstring &text);
881  short m_curAtaLayerNumber;
882  DRect GetBoundsList(vector<PicElement> const& elList, bool locus = false) const;
883  bool MergeElem(PicElement& elem, CCgmObjects* pMergeObjects, std::set<ClipRectangle*> &clippingRects,
884  std::set<ClippingPath*> &clippingPaths, CMatrix* pXForm);
885 
886  bool clipState;
887  CElementList *m_pCurrentList;
888  Larson::CConfig* m_pConfig;
889  bool m_bModified;
890 
891  void writeFontProperties(CFontProperties* props);
892 #ifndef CGMOBJECTS_NO_SAVE
893  long ExportAppStruct(CAppStruct* pAppStruct, int bwCompression, int colorCompression,
894  bool unicode, bool bRGBa, int vdcPrecision, std::wstring& profile);
895 #endif
896 
897  bool isCGMFontName(std::wstring &fontName);
898  void CollectCustomsFromAppStruct(CAppStruct* pAppStruct, CLineEdgeTypes* leTypes,
899  CHatchStyles* hStyles, bool* pFoundUnicode);
900  int CheckLicense();
901  std::string unicodeToAnsi(wstring wide);
902 
903  public:
904  void AddDemoBanner(CDrawBase *pDB, int iDrawAddFlag = 1, wchar_t *banner = NULL);
905 
906  void *hCGMLIB2;
907 
908  long LoadAllelm01();
909  };
910 
911 #if defined(ANDROID) && defined(WANT_C_API)
912  extern "C" {
913  typedef struct { CCgmObjects real; } c_CCgmObjects;
914 
915  c_CCgmObjects* new_CCgmObjects(void *config, void *webcgmconfig);
916  void delete_CCgmObjects(c_CCgmObjects* p);
917  void draw_CCgmObjects(c_CCgmObjects* p, void *drawable, int bShowRegions, int bExportApps);
918  long SaveA_CCgmObjects(c_CCgmObjects* p, char *outputFile);
919  long LoadFileA_CCgmObjects(c_CCgmObjects* p, char *inputFile, int iPicture);
920  long LoadAllelm01_CCgmObjects(c_CCgmObjects* p);
921  void VDCExtent_CCgmObjects(c_CCgmObjects* p, double *left, double *right, double *top, double *bottom, double *scale);
922  };
923 #endif
924 };
925 
926 #endif // !defined(AFX_CGMOBJECTS_H__2E7AF564_0E6D_4CCD_8851_A39A36D9E58D__INCLUDED_)
void closeAppStruct()
Closes an application structure (APS)
Definition: CgmObjects.cpp:404
CHatchStyles m_hatchStyles
picture Hatch Style definitions
Definition: CgmObjects.h:829
ClipRectangle – Clipping rectangle data container class.
Definition: Clipping.h:44
CFontMap m_fontMap
metafile font map (fontlist) of the loaded CGM file
Definition: CgmObjects.h:700
ClippingPath – ClippingPath data container class.
Definition: Clipping.h:19
int m_integerPrecision
metafile integer precision
Definition: CgmObjects.h:727
void ConvertColors(int monoEnhance, int colorConvert)
convert colors- see SaveOptions for parameter definition
Definition: CgmObjects.cpp:1804
PicElement – Picture element list container, each list element will be pointer to a Graphical Element...
Definition: ElementList.h:25
enum CharCodingAnnouncer m_charCodingAnnouncer
metafile character coding announcer
Definition: CgmObjects.h:709
encountered while in picture open state
Definition: CgmObjects.h:453
vector< CSegment * > m_localSegments
picture (local) segments list
Definition: CgmObjects.h:808
CSegment – Segment class- a segment is a list of picture elements.
Definition: Segment.h:7
bool m_visibility
setable picture visibility
Definition: CgmObjects.h:850
int m_colorIndexPrecision
metafile color index precision
Definition: CgmObjects.h:721
CColor m_regionDrawFillColor
hotspot region highlighting parameters
Definition: CgmObjects.h:858
std::string getVersion()
get version number string
Definition: CgmObjects.cpp:2119
CGeometricPatternTables – pattern tables container class.
Definition: GeometricPatterns.h:15
bool m_unicode
Indicates loaded CGM file contained unicode encoding.
Definition: CgmObjects.h:703
std::wstring ConformCGMFontNames(std::wstring &fontName)
reformat CGM fontName names Helvetica, Time-Roman and Courier to CGM standrd
Definition: CgmObjects.cpp:1840
int colorModel
0= as indciated per m_colorModel, 1= RGB, , 2= RGBA
Definition: CgmObjects.h:543
CHatchStyles – contains user defined Hatch Style definitions.
Definition: HatchStyles.h:20
bool visbilityState
maintains visibility state while drawing picture elements list
Definition: CgmObjects.h:864
CCgmIn – CGM Input class.
Definition: CgmIn.h:40
CFontMap – Container for font objects of a CGM picture and used for text drawing and metrics in DrawB...
Definition: FontMap.h:20
Definition: CgmObjects.h:395
vector< CSegment * > m_globalSegments
metafile (global) segments list
Definition: CgmObjects.h:775
void DrawList(CDrawBase *pDB, vector< PicElement > &gData, bool showRegions=false, bool exportAps=false)
Draw specified list of CGM picture elements.
Definition: CgmObjects.cpp:478
bool m_errorChecking
set to false to disable error checking during LoadFile
Definition: CgmObjects.h:874
int m_encoding
metafile encoding, binary (0) or clear text (1)
Definition: CgmObjects.h:712
std::wstring m_pictureId
picture id of the loaded CGM file
Definition: CgmObjects.h:802
std::wstring m_metafileDescription
Metafile Description string of loaded CGM file.
Definition: CgmObjects.h:691
struct Larson::CCgmObjects::@43 m_colorCalibration
metafile color calibration
CLineEdgeTypes m_lineEdgeTypes
picture Line and Edge definitions
Definition: CgmObjects.h:826
enum ScalingMode m_scalingMode
picture scaling mode, metric or abstract
Definition: CgmObjects.h:811
std::wstring m_metafileId
Metafile Id string of loaded CGM file.
Definition: CgmObjects.h:694
vector< pictureDirEntry > pictureList
0=UI8, 1= UI16, 2- UI32
Definition: CgmObjects.h:786
void ReCalcList(vector< PicElement > &elList)
Re-calculate vdc bounds for all elements in list.
Definition: CgmObjects.cpp:806
int m_namePrecision
metafile name precision
Definition: CgmObjects.h:733
DRect GetBounds(bool locus=false) const
Get actual bounds of picture.
Definition: CgmObjects.cpp:588
CPatternTables m_patternTables
picture Pattern Tables
Definition: CgmObjects.h:832
struct Larson::CCgmObjects::@47 m_glyphMapping
metafile glyph mapping
bool Merge(CCgmObjects *pMergeObjects, CMatrix *pXForm)
Merge an elements list specified by pMergeObjects into this CGM picture elements list.
Definition: CgmObjects.cpp:712
long Save(const std::wstring &outFile, CGMSaveOptions *pOptions)
Save the picture elements list to a CGM file (std::wstring filename)
Definition: CgmObjects.cpp:948
CElementList – Picture elements list.
Definition: ElementList.h:69
struct Larson::CCgmObjects::@44 m_realPrecision
metafile real precision
ClippingPath * m_curClippingPath
maintains clipping state while drawing picture elements list
Definition: CgmObjects.h:853
virtual ~CCgmObjects()
Destructor.
Definition: CgmObjects.cpp:176
void Draw(CDrawBase *pDB, bool showRegions=false, bool exportAps=false)
Draw the entire CGM picture elements list and optionally show regions (hotspots)
Definition: CgmObjects.cpp:414
CCgmObjects(Larson::CConfig *config, webcgmConfig *pWebcgmConfig=NULL)
Constructor.
Definition: CgmObjects.cpp:129
CDrawBase – drawing base class from which all output specific draw classes are derived.
Definition: DrawBase.h:19
enum VDCType m_vdcType
metafile VDC type
Definition: CgmObjects.h:764
bool m_stopDrawing
set to true to abort Draw loop
Definition: CgmObjects.h:877
long LoadFile(std::wstring inputFile, int iPicture, std::vector< CgmInError > *pErrorList=NULL, ElementCallback *pElementCallback=NULL)
std::wstring getKeywordValue(std::wstring string, std::wstring keyword)
Definition: CgmObjects.cpp:2039
int m_maximumColorIndex
metafile maximum color index
Definition: CgmObjects.h:715
CClipping m_clipping
picture clipping data
Definition: CgmObjects.h:823
Larson::DPoint m_maxVdcExtent[2]
metafile maximum vdc extent
Definition: CgmObjects.h:718
long numberGridLocs
number of lookup tabel entries
Definition: CgmObjects.h:745
metafile picture directory
Definition: CgmObjects.h:778
CColor getColorTable(long index)
get a color table entry
Definition: CgmObjects.cpp:2002
webcgmConfig * m_pWebcgmConfig
retain pointer to the WebCGM 2.1 application configurable items
Definition: CgmObjects.h:610
vector< charSet > m_charSets
Character sets of loaded CGM file.
Definition: CgmObjects.h:706
std::wstring m_csTail
type, see enum CharSetType
Definition: CgmObjects.h:591
struct Larson::CCgmObjects::charSet charSet
character set structure
Larson::CColorTableEntry m_colorTable[MAX_COLOR_INDEXES]
picture color table
Definition: CgmObjects.h:817
double m_defVDCextDx
Definition: CgmObjects.h:768
struct Larson::CgmInError CgmInError
encountered while in picture open state
WebCGM 2.1 Application Configurable Items (ACI) file structure.
Definition: WebcgmConfig.h:35
CPatternTables – pattern tables container class.
Definition: PatternTables.h:18
define an interface class for CgmIn element callback
Definition: CgmObjects.h:465
int m_colorPrecision
metafile color precision
Definition: CgmObjects.h:724
struct Larson::CCgmObjects::@45 m_segementPriorityExtent
metafile segment priority extent (min, max)
CCgmBaseObj – graphical element container base class.
Definition: CgmObj.h:121
struct Larson::CCgmObjects::CGMSaveOptions CGMSaveOptions
CAppStruct – Application Structure (APS) container class.
Definition: AppStruct.h:23
CGeometricPatternTables m_geometricPatternTables
picture Geometric Pattern Tables
Definition: CgmObjects.h:835
int m_indexPrecision
metafile index precision
Definition: CgmObjects.h:730
CMatrix – transform matrix class.
Definition: Matrix.h:16
long m_metafileVersion
Metafile Version number of loaded CGM file.
Definition: CgmObjects.h:697
enum ColorModel m_colorModel
metafile color model
Definition: CgmObjects.h:736
double m_scalingFactor
picture scaling factor
Definition: CgmObjects.h:814
vector< std::wstring > m_symbolLibraryList
metafile symbol library list
Definition: CgmObjects.h:756
CFontProperties – FontProperties attributes.
Definition: FontProperties.h:19
void add(CCgmBaseObj *pObj)
Add a graphical element to picture elements list.
Definition: CgmObjects.cpp:385
vector< metafileElementListEntry > m_metafileElementList
metafile elements list
Definition: CgmObjects.h:772
Definition: CgmObjects.h:531
character set structure
Definition: CgmObjects.h:589
CColor m_backgroundColor
Metafile background color.
Definition: CgmObjects.h:688
metafile elements list entry structure
Definition: CgmObjects.h:595
CLineEdgeTypes – contains user defined Line and Edge type definitions.
Definition: LineEdgeTypes.h:20
Larson::CConfig * getConfig()
Get application configuration instance.
Definition: CgmObjects.h:635
CClipping – contsruct and maintain ClippingPath data.
Definition: Clipping.h:62
CCgmObjects – CGM Picture container.
Definition: CgmObjects.h:472
Larson::DPoint m_vdcExtent[2]
picture Vdc Extent
Definition: CgmObjects.h:805
Larson::DPoint vdc2nvdc(Larson::DPoint vdc)
Definition: CgmObjects.cpp:2131