CGM Objects Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
DrawBase.h
1 // DrawBase.h: interface for the CDrawBase class.
2 //
5 
6 #if !defined(AFX_DRAWBASE_H__CA9A4F64_A587_44FB_A36B_8C173B304AA7__INCLUDED_)
7 #define AFX_DRAWBASE_H__CA9A4F64_A587_44FB_A36B_8C173B304AA7__INCLUDED_
8 
9 #pragma once
10 
11 #include "CgmObjects.h"
12 #include "CgmObj.h"
13 #include "Geometry.h"
14 #include "Utility/wstring.h"
15 
16 namespace Larson
17 {
19  class CDrawBase
20  {
21  typedef struct matStr { double m[3][3]; } matStr;
22  typedef struct mptStr { double x, y, z; } mptStr;
23 
24  typedef struct edgeInfo { double y_max, y_min, Mi, B, x1, y1, x2, y2; } edgeInfo;
25 
26  typedef struct emFillStruct {
27  long hatch_interval; /* hatch scan line interval */
28  double hatch_thickness, /* hatch line thickness*/
29  hatch_blanks, /* number of blank scans between hatch lines */
30  /* NOTE: thickness + blanks = interval */
31  hatch_do;
32  int custom_index;
33  double *f_mat_rot;
34  double *b_mat_rot;
35  long rx, ry, sx, sy, px, py;
36  double *cpts;
37  int cptsNum;
38  long cur_pts;
39  CColor *pa;
40  CColor *fill_color;
41 
42  long p1x, p1y, p2x, p2y;
43  double A[3], B[3], C[3], D0, dblpx, dblpy;
44  long r[3], g[3], b[3];
45  long sxp1;
46  double ea, eb, ec, ed;
47 
48  DPoint *points;
49 
50  double lx1, ly1, lx2, ly2, ly_max;
51 
52  edgeInfo *edge_info;
53  long *edge_flags;
54 
55  // 7aug2013- use long for worst case even though CgmObjs use short lineType
56  long *line_type; // custom hatch definitions can have multiple line types
57 
58  DRect orgRect;
59 
60  } emFillStruct;
61 
62  public:
63  typedef struct { int x, y; } IPoint;
64  typedef struct DrawInfo {
65  DRect window, viewport;
66  DRect clientRect;
67  double rotation;
68  int originFlag;
69  double resolution; // resolution of output device
70  } DrawInfo;
71 
72  CDrawBase();
73  virtual ~CDrawBase();
74 
75  enum OriginFlag {
76  lowerLeft = 0,
77  upperLeft = 1
78  };
79 
80  enum ProcessFlag {
81  firstCgmObjects = 0,
82  middleCgmObjects = 1,
83  lastCgmObjects = 2,
84  onlyCgmObjects = 3,
85  preDrawSetup = 4,
86  postDrawCleanup = 5
87  };
88 
90  virtual long setLineAttr(CCgmBaseObj*) = 0;
91 
93  virtual long setFillAttr(CCgmBaseObj*) = 0;
94 
96  virtual bool applyClipping(CCgmBaseObj*, DRect*) = 0;
97 
99  virtual void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pPts, long count, bool close) = 0;
100 
102  virtual void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pPts, long count) = 0;
103 
104 // draw a char from freetype outline in device coordinates
105  virtual void drawDCGlyph(CCgmBaseObj *pCgmBaseObj, DPoint &charPos, void* glyph, bool fillChar, double dScaleUp);
106 
108  virtual void drawCellArray(CCgmCellArray *pCCgmCellArray);
109 
111  virtual void open() = 0;
112 
114  virtual void close() = 0;
115 
117  virtual void setDisplay(void* pDisplay, void* pOther = 0) = 0;
118 
120  virtual void setTransform(DRect *window, DRect *viewport, DRect *clientRect, double rotation = 0.0, int originFlag = 0);
121 
122  virtual void setHardclip(DRect *hardclip);
123 
125  virtual void clear() = 0;
126 
127  virtual void flush() = 0;
128  virtual void drawDCdots(CCgmBaseObj *pCgmBaseObj, DPoint *pPts, long count) = 0;
129  virtual void unApplyClipping(CCgmBaseObj*) = 0;
130  virtual void eraseDCarea(DRect *area) = 0;
131 
132  virtual void begAps(CAppStruct *) { return; };
133  virtual void endAps(CAppStruct *) { return; };
134 
135  virtual DPoint *VdcToDPts(DPoint *pPts, long *nPts, bool removeDups = false, bool bNint = false);
136  inline DPoint VdcToDPt(DPoint dPt, bool bNint = false)
137  {
138  DPoint VdcPt;
139  if (m_pXForm)
140  VdcPt = m_pXForm->transformPt(dPt);
141  else
142  VdcPt = dPt;
143 
144  DPoint DPt;
145  DPt.x = ((VdcPt.x * m_vdcToCcMatrix[0][0]) + (VdcPt.y * m_vdcToCcMatrix[0][1]) + m_vdcToCcMatrix[0][2]);
146  DPt.y = ((VdcPt.x * m_vdcToCcMatrix[1][0]) + (VdcPt.y * m_vdcToCcMatrix[1][1]) + m_vdcToCcMatrix[1][2]);
147 
148  if(bNint)
149  {
150  DPt.x = NINT(DPt.x);
151  DPt.y = NINT(DPt.y);
152  }
153 
154  return DPt;
155  }
156  inline DPoint VdcToDVec(DPoint dVec, bool bNint = false)
157  {
158  DPoint vdcVec;
159  if (m_pXForm)
160  vdcVec = m_pXForm->transformVec(dVec);
161  else
162  vdcVec = dVec;
163 
164  DPoint vec;
165  vec.x = ((vdcVec.x * m_vdcToCcMatrix[0][0]) + (vdcVec.y * m_vdcToCcMatrix[0][1]));
166  vec.y = ((vdcVec.x * m_vdcToCcMatrix[1][0]) + (vdcVec.y * m_vdcToCcMatrix[1][1]));
167 
168  if(bNint)
169  {
170  vec.x = NINT(vec.x);
171  vec.y = NINT(vec.y);
172  }
173 
174  return vec;
175  }
176 
177  virtual LPoint *VdcToLPts(DPoint *pPts, long *nPts, bool removeDups = false);
178  inline LPoint VdcToLPt(DPoint dPt)
179  {
180  DPoint VdcPt;
181  if (m_pXForm)
182  VdcPt = m_pXForm->transformPt(dPt);
183  else
184  VdcPt = dPt;
185 
186  LPoint LPt;
187 
188  LPt.x = NINT((double)((VdcPt.x * m_vdcToCcMatrix[0][0]) + (VdcPt.y * m_vdcToCcMatrix[0][1]) +
189  m_vdcToCcMatrix[0][2]) );
190  LPt.y = NINT((double)((VdcPt.x * m_vdcToCcMatrix[1][0]) + (VdcPt.y * m_vdcToCcMatrix[1][1]) +
191  m_vdcToCcMatrix[1][2]) );
192 
193  return LPt;
194  }
195  inline LPoint VdcToLVec(DPoint dVec)
196  {
197  DPoint vdcVec;
198  if (m_pXForm)
199  vdcVec = m_pXForm->transformVec(dVec);
200  else
201  vdcVec = dVec;
202 
203  LPoint lVec;
204 
205  lVec.x = NINT((double)((vdcVec.x * m_vdcToCcMatrix[0][0]) + (vdcVec.y * m_vdcToCcMatrix[0][1])) );
206  lVec.y = NINT((double)((vdcVec.x * m_vdcToCcMatrix[1][0]) + (vdcVec.y * m_vdcToCcMatrix[1][1])) );
207 
208  return lVec;
209  }
210 
211  virtual Larson::CDrawBase::IPoint *VdcToIPts(DPoint *pPts, int *nPts, bool removeDups = false);
212  inline Larson::CDrawBase::IPoint VdcToIPt(DPoint dPt)
213  {
214  DPoint VdcPt;
215  if (m_pXForm)
216  VdcPt = m_pXForm->transformPt(dPt);
217  else
218  VdcPt = dPt;
219 
220  IPoint IPt;
221 
222  IPt.x = ININT((double)((VdcPt.x * m_vdcToCcMatrix[0][0]) + (VdcPt.y * m_vdcToCcMatrix[0][1]) +
223  m_vdcToCcMatrix[0][2]) );
224  IPt.y = ININT((double)((VdcPt.x * m_vdcToCcMatrix[1][0]) + (VdcPt.y * m_vdcToCcMatrix[1][1]) +
225  m_vdcToCcMatrix[1][2]) );
226 
227  return IPt;
228  }
229  inline IPoint VdcToIVec(DPoint dVec)
230  {
231  DPoint vdcVec;
232  if (m_pXForm)
233  vdcVec = m_pXForm->transformVec(dVec);
234  else
235  vdcVec = dVec;
236 
237  IPoint IVec;
238 
239  IVec.x = ININT((double)((vdcVec.x * m_vdcToCcMatrix[0][0]) + (vdcVec.y * m_vdcToCcMatrix[0][1])) );
240  IVec.y = ININT((double)((vdcVec.x * m_vdcToCcMatrix[1][0]) + (vdcVec.y * m_vdcToCcMatrix[1][1])) );
241 
242  return IVec;
243  }
244 
245  virtual DPoint IPtToVdcPt(IPoint lPt);
246  virtual DPoint LPtToVdcPt(LPoint lPt);
247  virtual DPoint DPtToVdcPt(DPoint dcPt);
248  virtual DPoint DVecToVdcVec(DPoint dcVec);
249 
250  virtual long WeightToCc(double scale, int specMode, double scaleFactor = 1.0);
251  virtual double WeightToD(double scale, int specMode, double scaleFactor = 1.0);
252 
253  virtual double OneDcIsVdc();
254 
255  virtual void PreProcess(CCgmObjects*, enum ProcessFlag ) { return; };
256  virtual void PostProcess(CCgmObjects*, enum ProcessFlag ) { return; };
257 
258  void CalcTextExpFactors(CCgmText *pCgmText, CCgmText *pTextOwner, CTextExtent *pTotalExtent,
259  double *pHFac, double *pEFac);
260 
261  virtual void drawRect(CCgmRect *pCgmRect);
262  virtual void drawText(CCgmText *pCgmText);
263  virtual void drawPoly(CCgmPoly *pCgmPoly);
264  virtual void drawTrace(CCgmTrace *pCgmTrace);
265  virtual void drawTraceVariableAreaPos(CCgmTrace *pCgmTrace, float m[2][3]);
266  virtual void drawTraceVariableAreaNeg(CCgmTrace *pCgmTrace, float m[2][3]);
267  virtual void drawTraceBackground(CCgmTrace *pCgmTrace, float m[2][3], long flag);
268  virtual void drawEllipse(CCgmEllipse *pCgmEllipse);
269  virtual void drawCircle(CCgmCircle *pCgmCircle);
270  virtual void drawHyperbolicArc(CCgmHyperbolicArc *pCgmHyperbolicArc);
271  virtual void drawParabolicArc(CCgmParabolicArc *pCgmParabolicArc);
272  virtual void drawNurb(CCgmNurb *pCgmNurb);
273  virtual void drawTileArray(CCgmTileArray *pCgmTileArray);
274  virtual void drawFigure(CCgmFigure *pCgmFigure);
275  virtual void drawPath(CCgmBaseObj *pCgmBaseObj, Path *pPath, bool fill);
276 
277  virtual DPoint drawDCArrowHead(CCgmBaseObj*, DPoint* p1, DPoint* p2, double width);
278  void emulDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt, bool close);
279  long emulDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pDa, long cnt, bool bCustomHatch = false);
280 
282  void drawDCdegen(CCgmBaseObj *pCgmBaseObj, DPoint *pts, bool bOnePt = true);
283 
284  void traceBackgroundRun(CCgmTrace *pCgmTrace, DPoint P, DPoint Q, DPoint R);
285 
286  void traceBackgroundInterpolated(CCgmTrace *pCgmTrace, DPoint P, DPoint Q, DPoint R, float m[2][3], bool group);
287 
288  long traceBackgroundInterpolatedLeft2Center(CCgmTrace *pCgmTrace, DPoint P, DPoint Q, DPoint R,
289  long left, unsigned long *left_list, long oi, long mid,
290  long cen, unsigned long *cen_list, long type, long first, long last, long final, long nC, long nCl, long nR,
291  unsigned long *CA,
292  long *ci, long mc, long cM, long *gCol, long nflg, long nrep, long csm, long *last_cell);
293 
294  long traceBackgroundInterpolatedCenter2Right(CCgmTrace *pCgmTrace, DPoint P, DPoint Q, DPoint R,
295  long cen, unsigned long *cen_list, long type, long first, long last,
296  long final, long mid, long right, unsigned long *right_list, long oi, long nC, long nCr, long nR,
297  unsigned long *CA,
298  long *ci, long mc, long cM, long *gCol, long nflg, long nrep, long csm, long *last_cell);
299 
300  void traceBackgroundInterpolatedFlushCells(CCgmTrace *pCgmTrace, long csm, long *cell_count,
301  DPoint P, DPoint Q, DPoint R, long nC, long nR, long *last_cell, unsigned long *CA, long type);
302 
303  void setLineWidthControl(double minimum, double maximum, double multiplier);
304 
305  void setTempDir(std::wstring tempDir);
306 
307  void setCanDrawBoth(bool bCanDrawBoth) { m_bCanDrawBoth = bCanDrawBoth; };
308 
309  double degreesToRadians(double degrees);
310  double radiansToDegrees(double radians);
311  void rotatePt(double angle, DPoint *point);
312  void rotatePts(DPoint& center, double angle, DPoint *points, int npoints);
313 
314  void setMinMarkerSize(double size);
315  void setMinCharHeight(double height);
316 
317  CColor m_backgroundColor;
318  CDeviceColor m_deviceColor;
319 
320  DrawInfo m_drawInfo;
321 
322  double m_vdcToCcMatrix[2][3];
323  double m_ccToVdcMatrix[2][3];
324  double m_stepValue;
325 
326  bool m_hardclipValid;
327  DRect m_hardclip;
328 
329  bool m_removeDups;
330  bool m_nint;
331 
332  emFillStruct m_emFillStruct;
333  long m_nRotateHatchNPattern90; // 0-no, 1-pos/neg hatch, 2-all
334 
335  long m_clippingPathIndex;
336 
341  double m_dMultLineWidth;
342 
345 
348 
351  double m_dBaseTextScaleUp;
354 
355  CMatrix* m_pXForm;
356 
357  std::wstring *m_psTempDir;
358 
359  std::string encodingByType_n_Tail(int type, wchar_t tail);
360 
361  long getNumCircleSegments(double r, long maxNum = 0);
362  DPoint* elCirclePolygon(DPoint, double, long*, DPoint*);
363 
364  double m_dMaxPenDCwidth; // the widest line a CDrawXXX::drawDCline() can draw
365  // or you want to allow it to draw (some OpenGL can handle very
366  // wide lines but the line ends look like crap so we limit
367  // it to 3 pixels wide)
368 
369  private:
370 
371  bool m_bINemulDCline; // let's drawDCline know if we are already hitting the wall
372 
373  bool m_bCanDrawBoth; // DrawXXX's fill functions also draw edge at same time
374 
375  bool m_bProcessingTraceGroup;
376 
377  // emulate line support functions and variables
378  void elDrawDashedPolyline(CCgmBaseObj*, double, long, DPoint*, long, float*, bool);
379  void elDrawLineCap(CCgmBaseObj*, DPoint*, double, double, double, long);
380  void elDrawLineJoin(CCgmBaseObj*, DPoint*, double, double, double);
381  long swrdst(double, double, double, double, double, double,
382  double, double*, double*, double*, double*, double*, double*);
383  long swrltl(double, double, double, double, double, double,
384  double, double, double*, double*);
385 
386  // emulate fill support functions
387  void efPolyInsert(long);
388  void efFillScan(CCgmBaseObj*, double);
389  void efPlotVect(CCgmBaseObj*, double, double, double);
390  void efPlotPat(CCgmBaseObj*, long, long, long);
391  void efPlotHor(CCgmBaseObj*, long, long, long);
392  void efPlotPix(CCgmBaseObj*, long, long, long);
393  void efFlushPts(CCgmBaseObj*, long);
394  void efRefGeometry(CCgmBaseObj*);
395  void efMatSet(matStr*, double, double, double, double, double, double, double, double, double);
396  void efMatMul(matStr*, matStr*, matStr*);
397  void efPtMul(mptStr*, matStr*, mptStr*);
398 
399  };
400 };
401 
402 /* use std::vector instead
403 class CDoubleArray
404 {
405 //Internal Data Members
406 protected:
407  unsigned int _size; //Count items.
408  unsigned int _room; //Available space.
409  double* _data; //The list.
410  unsigned int _grow; //Grow by increment.
411 public:
412  //<summary>Default constructor.</summary>
413  //<param name="grow">Array growth increment.</param>
414  CDoubleArray(unsigned int grow = 4):
415  _size(0),
416  _room(0),
417  _data(NULL),
418  _grow(grow)
419  {
420  _data = (double*)malloc(sizeof(double)*_grow);
421  _room = (_data) ? _grow : 0;
422  }
423  ~CDoubleArray(){ if(_data) free(_data); }
424 public:
425  bool empty(){ return (_size == 0); } //True if there is no data in the array.
426  void remove_all(){ _size = 0; } //Remove all data elements from the array.
427  void clear() //Free any allocated memory.
428  {
429  if(_data)
430  {
431  _data = (double*)realloc(_data,sizeof(double)*_grow); //Reallocate to first growth increment.
432  _room = _grow; //Mark it as such.
433  _size = 0; //Mark array as empty.
434  }
435  }
436  virtual double& operator[](unsigned int i) //Access element at subscript, or dummy value if overflow.
437  {
438  static double dummy = 0;
439  if(i < _size) return _data[i]; else return dummy;
440  }
441  unsigned int size(){ return _size; } //Count data elements in the array.
442  virtual double at(unsigned int i) //Access element at subscript, or NULL if overflow.
443  {
444  static double dummy = 0;
445  if(i < _size) return _data[i]; else return dummy;
446  }
447  long push_back(double element) //Append a new element to the array.
448  {
449  if(_data) //Fail if no array.
450  {
451  if(_size < _room) //There is enough allocated space.
452  {
453  _data[_size] = element; //Set it.
454  _size++; //Increment our count of elements.
455  return _size-1; //Return the element's subscript.
456  }
457  else //Not enough room.
458  {
459  double* temp = (double*)realloc(_data,sizeof(double)*(_size+_grow)); //Grow the array.
460  if(temp) //Reallocation succeeded.
461  {
462  _room += _grow; //Increment available space.
463  _data = temp; //Assign reallocated value to array pointer.
464  _data[_size] = element; //Set the element to be added.
465  _size++; //Increment our count of elements.
466  return _size-1; //Return the element's subscript.
467  }
468  }
469  }
470  return -1; //Something failed, so return a bad subscript.
471  }
472  long insert(unsigned int i, double element)
473  {
474  if(_data) //Fail if no array
475  {
476  if(_size < _room) //There is enough allocated space.
477  {
478  if(i >= _size) i = _size;
479  for(unsigned int m = _size; m > i; m--) _data[m] = _data[m-1];
480  _data[i] = element; //Set it.
481  _size++; //Increment our count of elements
482  return i; //Return the element's subscript.
483  }
484  else //Not enough room.
485  {
486  double* temp = (double*)realloc(_data,sizeof(double)*(_size+_grow)); //Grow the array.
487  if(temp) //Reallocation succeeded.
488  {
489  _room += _grow; //Increment available space.
490  _data = temp; //Assign reallocated value to array pointer.
491  if(i >= _size) i = _size;
492  for(unsigned int m = _size; m > i; m--) _data[m] = _data[m-1];
493  _data[i] = element; //Set it.
494  _size++; //Increment our count of elements
495  return i; //Return the element's subscript.
496  }
497  }
498  }
499  return -1; //Something failed, so return a bad subscript
500  }
501 };
502 */
503 
504 #endif // !defined(AFX_DRAWBASE_H__CA9A4F64_A587_44FB_A36B_8C173B304AA7__INCLUDED_)
505 
virtual void close()=0
close device and release memory
virtual void drawDCline(CCgmBaseObj *pCgmBaseObj, DPoint *pPts, long count, bool close)=0
draw a series of connected or unconnected lines specified by pPts in device coordinates ...
double m_dMinLineWidth
minimum line width in pixel units
Definition: DrawBase.h:338
double m_dDCmaxDrawableLineWidth
maximum DC line width that CDrawXXX can handle (0 => unlimited)
Definition: DrawBase.h:344
Definition: DrawBase.h:63
Definition: DrawBase.h:64
virtual void open()=0
open device for drawing
double m_dMinMarkerSize
minimum marker size in pixel units
Definition: DrawBase.h:347
double m_dMaxLineWidth
maximum line width in pixel units
Definition: DrawBase.h:340
CDrawBase – drawing base class from which all output specific draw classes are derived.
Definition: DrawBase.h:19
DPoint transformPt(DPoint point)
translate a point
Definition: Matrix.h:128
virtual long setFillAttr(CCgmBaseObj *)=0
apply fill attributes
virtual void setDisplay(void *pDisplay, void *pOther=0)=0
select target device
virtual long setLineAttr(CCgmBaseObj *)=0
apply line attributes
virtual void drawDCfill(CCgmBaseObj *pCgmBaseObj, DPoint *pPts, long count)=0
fill a polygonal area specified by pPts in device coordinates
virtual void clear()=0
clear display area and set to background color if indicated
CCgmBaseObj – graphical element container base class.
Definition: CgmObj.h:121
double m_dStrokeCharLargerThan
CDrawBase will stroke text characters who's height in pixel units exceeds.
Definition: DrawBase.h:353
CMatrix – transform matrix class.
Definition: Matrix.h:16
DPoint transformVec(DPoint vec)
translate a vector
Definition: Matrix.h:139
double m_dMinCharHeight
minimum character in pixel units
Definition: DrawBase.h:350
void drawDCdegen(CCgmBaseObj *pCgmBaseObj, DPoint *pts, bool bOnePt=true)
give 1 point or 2 draw the degenerate line (now a point) or fill (now a line or point) from the attri...
Definition: DrawBase.cpp:6796
virtual void drawCellArray(CCgmCellArray *pCCgmCellArray)
draw a cell array as specfied by pCCgmCellArray, points are in VDC units
Definition: DrawBase.cpp:1947
virtual bool applyClipping(CCgmBaseObj *, DRect *)=0
apply clipping rectangle and protection regions if either or both are indicated
virtual void setTransform(DRect *window, DRect *viewport, DRect *clientRect, double rotation=0.0, int originFlag=0)
set VDC to device coordinates transform
Definition: DrawBase.cpp:205