CFx SDK Documentation  2023 SP0
TfDwgFiler.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 #ifndef _OdTfDwgFiler_h_Included_
24 #define _OdTfDwgFiler_h_Included_
25 
26 #define STL_USING_SET
27 #define STL_USING_STACK
28 #define STL_USING_STREAM
29 #include "OdaSTL.h"
30 #include "DbFiler.h"
31 #include "RxDynamicModule.h"
32 #include <OdPlatformStreamer.h>
33 #include "../../ThirdParty/tinyxml/tinyxml.h"
34 #include "Tf/Tf.h"
35 #include "DbHistoryManager.h"
36 #include "OdBinaryData.h"
37 #include "OdList.h"
38 
39 
40 class OdTfDwgFilerImpl;
41 class TiXmlDocument;
42 class OdTfDiffFilerImpl;
43 class ChangesCalculation;
44 
46 {
47  char *pBinaryData;
50 
51 };
52 
53 class OdTfDwgFiler : public OdDbDwgFiler
54 {
55  friend class ChangesCalculation;
56  OdTfDwgFilerImpl* m_pImpl;
57  ChangesCalculation* m_pChangesCalc;
58  bool m_usesMultiUserEdit;
59  bool m_bApplyDiff;
60  bool m_bPassXmlData;
61  bool m_bPassXmlDataByCondition;
62  size_t m_sizeStack;
63  TiXmlString m_nameStackCondition;
64  OdTf::TypesEnum m_type;
65  inline void checkChanges(OdTf::TypesEnum tBase, void *value, OdString string = OdString());
66  void wrHexBinaryValue(const void* buffer, OdUInt32 numBytes);
67  void wrHandleValue(const OdDbHandle& value);
68  void wrStringValue(const OdString &value);
69  void wrObjectIdValue(OdTf::TypesEnum tBase, const OdDbObjectId &id);
70  template<class T>
71  void wrValue(OdTf::TypesEnum tBase, const T &value, OdUInt32 countBytes = 0);
72  void wrGeValue(OdTf::TypesEnum tBase, OdUInt8 countPoints , double , double , double z = 0);
73 
74 public:
75  OdTfDiffFilerImpl *m_pFilerXmlData;
76  void setChangesCalc(ChangesCalculation *pointer) { m_pChangesCalc = pointer; }
77  OdTfDwgFilerImpl* getImpl() {return m_pImpl;};
78  bool& bApplyDiff() { return m_bApplyDiff; };
79  void setUsedMUE() {m_usesMultiUserEdit = true;};
80 
85  virtual FilerType filerType() const ODRX_OVERRIDE { return kUndoFiler; }
87  virtual void seek(OdInt64 offset, OdDb::FilerSeekType seekType) ODRX_OVERRIDE {}
88  virtual OdUInt64 tell() const ODRX_OVERRIDE { return 0; }
89  virtual bool rdBool() ODRX_OVERRIDE;
90  virtual OdString rdString();
91  virtual void rdBytes(void* buffer, OdUInt32 numBytes);
92  virtual OdInt8 rdInt8();
93  virtual OdUInt8 rdUInt8();
94  virtual OdInt16 rdInt16();
95  virtual OdInt32 rdInt32();
96  virtual OdInt64 rdInt64();
97  virtual void* rdAddress();
98  virtual double rdDouble();
109  virtual void wrBool(bool value);
110  virtual void wrString(const OdString &value);
111  virtual void wrBytes(const void* buffer, OdUInt32 numBytes);
112  virtual void wrInt8(OdInt8 value);
113  virtual void wrUInt8(OdUInt8 value);
114  virtual void wrInt16(OdInt16 value);
115  virtual void wrInt32(OdInt32 value);
116  virtual void wrInt64(OdInt64 value);
117  virtual void wrAddress(const void* value);
118  virtual void wrDouble(double value);
119  virtual void wrDbHandle(const OdDbHandle& value);
120  virtual void wrSoftOwnershipId(const OdDbObjectId& value);
121  virtual void wrHardOwnershipId(const OdDbObjectId& value);
122  virtual void wrSoftPointerId(const OdDbObjectId& value);
123  virtual void wrHardPointerId(const OdDbObjectId& value);
124  virtual void wrPoint2d(const OdGePoint2d& value);
125  virtual void wrPoint3d(
126  const OdGePoint3d& value);
127 
132  virtual void wrVector2d(
133  const OdGeVector2d& value);
134 
139  virtual void wrVector3d(
140  const OdGeVector3d& value);
141 
146  virtual void wrScale3d(
147  const OdGeScale3d& value);
148 
149  virtual bool usesReferences() const ODRX_OVERRIDE { return true; }
150 
152 
153  static TiXmlDocument* saveDwgToXml(OdDbDatabase* pDb, const char* pcszXsdFilename, OdDbObjectId idObj);
154 
155  // undo specific overrides
156  virtual void wrDatabase(OdDbDatabase* pDb);
158  virtual void wrClass(const OdRxClass* c);
159  virtual OdRxClass* rdClass();
160 };
161 
163 {
164  friend class OdTfDwgFiler;
165 public:
174  void calculateDifference(OdDbDatabase *pDb, OdStreamBufPtr bufPtr, const char *filePath);
175 
176 private:
177  OdTfDiffFilerImpl *m_pFilerServerData;
178  OdTfDwgFilerImpl *m_filer;
179  OdSmartPtr<OdTfDwgFiler> m_pFiler;
180  OdString m_tableName;
181  OdStreamBuf *m_buf;
182  bool m_bForceWrite;
183  bool m_eraseFlag;
189  void initParts(const char *filePath);
190 
197  void matchingPositionScheme(OdTf::TypesEnum &t1, OdTf::TypesEnum &t2, OdTfDwgFiler *actual);
201  void writeAppendedObjectsToXml();
205  void writeLogMessageToXml();
209  void writeId_StringStreamsToXml();
222  void parsingPartialUndo(OdInt32 &numRev, OdInt32 &nextDataStream, OdInt32 &sizeDataStream, OdInt32 &curPos, OdInt32 &nextRecPos,
223  OdInt32 *massDataLengthRevision, OdInt16 &opCode, bool &partialUndo );
230  void getLenghtEachRevision(OdInt32 &countRevision, OdInt32 *massDataLengthRevision);
240  void isDifferentWrite(void* value, OdTf::TypesEnum t, OdString &string, const void * buf = 0x0, OdUInt32 numBytes = 0);
250  void seekToNextData(OdInt32 &curPos, OdInt32 &sizeDataStream, OdInt32 &nextRecPos, OdInt32 &nextDataStream, OdInt32 & numRev, OdInt32 *massDataLenghtRevision);
251 
252  template <class T>
253  OdString rdString(T *buf)
254  {
255  OdInt16 strLen;
256  buf->getBytes(&strLen, 2);
257  OdBinaryData buff;
258  buff.resize(strLen * 2);
259  buf->getBytes(buff.asArrayPtr(), buff.length());
260  const OdUInt8* pBuff = buff.asArrayPtr();
261  return OdPlatformStreamer::getUnicodeStrFromBuffer(pBuff, strLen);
262  }
263 };
264 
265 
267 {
268 
269 public:
272  {
273  //delete m_handleMap;
274  };
275 
276 
278  {
281  size_t s_numInList;
282  TRecordNewObject() : s_pos(-1) { ; };
284  : s_name(name), s_pos(pos), s_numInList(num) {;};
285  };
298  OdDbHandleMap applyDifference(OdDbDatabase *pDb, bool bApplyDiff, bool bPreserveHandles, const char *filePath);
306  static void writeData(OdTf::TypesEnum t, OdTfDwgFilerImpl *m_filer, OdTfDiffFilerImpl *schemeIter, OdString *tableNameFromXml = 0);
307  template<class T>
314  static inline void checkCondition(T value, OdTfDwgFilerImpl *schemeIter);
315 
316 private:
317  BinaryDataStruct m_binDataAC;
318  OdTfDwgFilerImpl *m_filer;
319  OdSmartPtr<OdTfDwgFiler> m_pFiler;
320  OdList<std::pair<OdUInt32, char*> > m_listBinObjects;
321  std::map<OdDbHandle, TRecordNewObject> m_mapCreatedObjects;
329  void writePartialUndoData(OdDbHandle handle, OdString tableName, TiXmlDocument &schema);
336  void appendedObjectData(OdTfDiffFilerImpl *schemeIter, OdTf::TypesEnum &t);
347  void init(OdDbDatabase * pDb, TiXmlDocument &schema, TiXmlDocument &xml, TiXmlElement *pRoot, bool bApplyDiff, const char *filePath);
352  void writeInformationData();
361  void changeDataAddedObject(OdDbDatabase * pDb, TiXmlDocument &schema, OdString &tableName, OdDbHandle &handle);
367  char* getFinalData(OdUInt32 &size, OdInt32 mergeBlockingAndMarks);
368 
369 
370  TiXmlElement* stepBeginOfTable(TiXmlElement *e)
371  {
372  while (strcmp(e->Parent()->Value(), "TeighaDrawing") != 0)
373  e = (TiXmlElement*)e->Parent();
374  return (TiXmlElement*)e;
375  }
376 
377  TiXmlElement* stepToLastDiffItemInPrevTable(TiXmlElement *e)
378  {
379  if (strcmp(e->Value(), "handleNotSystemData") == 0)
380  {
381  while (strcmp(e->Parent()->Value(), "TeighaDrawing") != 0)
382  e = (TiXmlElement*)e->Parent();
383  }
384  TiXmlElement *n = (TiXmlElement*)e->PreviousSibling()->LastChild();
385  do
386  {
387  while (n->LastChild())
388  n = (TiXmlElement*)n->LastChild();
389  while (n->NextSiblingElement())
390  n = n->NextSiblingElement();
391  } while (n->NextSiblingElement() || n->FirstChildElement());
392 
393  return n;
394  };
395 
396 };
397 
398 
399 
400 inline OdUInt32 encodeToBase64(const unsigned char* bytesToEncode, OdUInt32 length,
401  OdAnsiString& sOut, bool inQuotes = false)
402 {
403  static const char* base64Dict = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
404 
405  //char* res = new char[len * 8 / 6 + 2];
406  char* res = sOut.getBuffer(length * 8 / 6 + 4 + (inQuotes ? 2 : 0));
407  if (inQuotes)
408  *res++ = '\"';
409 
410  OdUInt32 len = length,
411  finalLen = 0,
412  i = 0,
413  j = 0;
414  unsigned char charArraySrc[3];
415  unsigned char charArrayFin[4];
416 
417  while (len--) {
418  charArraySrc[i++] = *(bytesToEncode++);
419  if (i == 3) {
420  charArrayFin[0] = (charArraySrc[0] & 0xfc) >> 2;
421  charArrayFin[1] = ((charArraySrc[0] & 0x03) << 4) + ((charArraySrc[1] & 0xf0) >> 4);
422  charArrayFin[2] = ((charArraySrc[1] & 0x0f) << 2) + ((charArraySrc[2] & 0xc0) >> 6);
423  charArrayFin[3] = charArraySrc[2] & 0x3f;
424 
425  for (i = 0; i < 4; i++)
426  res[finalLen++] = base64Dict[charArrayFin[i]];
427  i = 0;
428  }
429  }
430 
431  if (i != 0)
432  {
433  for (j = i; j < 3; j++)
434  charArraySrc[j] = '\0';
435 
436  charArrayFin[0] = (charArraySrc[0] & 0xfc) >> 2;
437  charArrayFin[1] = ((charArraySrc[0] & 0x03) << 4) + ((charArraySrc[1] & 0xf0) >> 4);
438  charArrayFin[2] = ((charArraySrc[1] & 0x0f) << 2) + ((charArraySrc[2] & 0xc0) >> 6);
439  charArrayFin[3] = charArraySrc[2] & 0x3f;
440 
441  for (j = 0; j < i + 1; j++)
442  res[finalLen++] = base64Dict[charArrayFin[j]];
443 
444  while ((i++ < 3))
445  res[finalLen++] = '=';
446  }
447 
448  ODA_ASSERT_ONCE(finalLen <= (length * 8 / 6 + 3));
449  if (inQuotes)
450  {
451  res[finalLen] = '\"';
452  res[finalLen + 1] = 0; // res[finalLen + 1] = 0;
453  finalLen += 2;
454  }
455  else
456  res[finalLen] = 0; // res[finalLen + 1] = 0;
457 
458  //sOut.releaseBuffer();
459  return finalLen;
460 }
461 
462 inline OdUInt32 decodeBase64(const OdAnsiString& stringToDecode, OdBinaryData& out)
463 {
464  static unsigned char* decode64Dict = NULL;
465  if (!decode64Dict)
466  {
467  static const char* base64Dict = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
468  static OdBinaryData dataDict;
469  dataDict.resize(256);
470  decode64Dict = dataDict.asArrayPtr();
471  for (OdUInt32 i = 0; i < 64; i++)
472  decode64Dict[base64Dict[i]] = (unsigned char)i;
473  }
474 
475  OdUInt32 length = stringToDecode.getLength();
476  if (length % 4 != 0)
477  return -1;
478  const char* pToDecode = stringToDecode.c_str();
479 
480  OdUInt32 outLength = length * 3 / 4;
481  outLength -= (pToDecode[length - 2] == '=') ? 2 : ((pToDecode[length - 1] == '=') ? 1 : 0);
482 
483  out.resize(outLength);
484  unsigned char* data = (unsigned char*)out.asArrayPtr();
485 
486  for (OdUInt32 i = 0, j = 0; i < length;)
487  {
488  OdUInt32 sextet_a = (pToDecode[i] == '=') ? (0 & i++) : decode64Dict[pToDecode[i++]];
489  OdUInt32 sextet_b = (pToDecode[i] == '=') ? (0 & i++) : decode64Dict[pToDecode[i++]];
490  OdUInt32 sextet_c = (pToDecode[i] == '=') ? (0 & i++) : decode64Dict[pToDecode[i++]];
491  OdUInt32 sextet_d = (pToDecode[i] == '=') ? (0 & i++) : decode64Dict[pToDecode[i++]];
492 
493  OdUInt32 triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 6);
494 
495  if (j < outLength)
496  data[j++] = (triple >> 2 * 8) & 0xFF;
497  if (j < outLength)
498  data[j++] = (triple >> 1 * 8) & 0xFF;
499  if (j < outLength)
500  data[j++] = (triple >> 0 * 8) & 0xFF;
501  }
502  return outLength;
503 }
504 
506 {
507  OdAnsiString ansiStr(data);
508  OdBinaryData out;
509  decodeBase64(ansiStr, out);
510  const OdUInt8* pBuff = out.asArrayPtr();
511  return OdPlatformStreamer::getUnicodeStrFromBuffer(pBuff, out.size() / 2);
512 }
513 
515 
516 
517 
518 
519 #endif
std::map< OdDbHandle, OdDbHandle > OdDbHandleMap
#define ODA_ASSERT_ONCE(exp)
Definition: DebugStuff.h:51
#define NULL
Definition: GsProperties.h:177
unsigned int OdUInt32
short OdInt16
signed char OdInt8
int OdInt32
unsigned char OdUInt8
#define ODRX_OVERRIDE
OdString OdString
Definition: OdString.h:1224
OdUInt32 decodeBase64(const OdAnsiString &stringToDecode, OdBinaryData &out)
Definition: TfDwgFiler.h:462
OdString decodeBase64ToOdString(const char *data)
Definition: TfDwgFiler.h:505
OdUInt32 encodeToBase64(const unsigned char *bytesToEncode, OdUInt32 length, OdAnsiString &sOut, bool inQuotes=false)
Definition: TfDwgFiler.h:400
static void writeData(OdTf::TypesEnum t, OdTfDwgFilerImpl *m_filer, OdTfDiffFilerImpl *schemeIter, OdString *tableNameFromXml=0)
static void checkCondition(T value, OdTfDwgFilerImpl *schemeIter)
OdDbHandleMap applyDifference(OdDbDatabase *pDb, bool bApplyDiff, bool bPreserveHandles, const char *filePath)
void calculateDifference(OdDbDatabase *pDb, OdStreamBufPtr bufPtr, const char *filePath)
size_type length() const
Definition: OdArray.h:1054
size_type size() const
Definition: OdArray.h:893
const T * asArrayPtr() const
Definition: OdArray.h:1094
void resize(size_type logicalLength, const T &value)
Definition: OdArray.h:834
@ kUndoFiler
Definition: DbFiler.h:84
Definition: Int64.h:43
Definition: OdList.h:45
static OdString getUnicodeStrFromBuffer(const OdUInt8 *&buffer, OdInt32 size)
void setChangesCalc(ChangesCalculation *pointer)
Definition: TfDwgFiler.h:76
virtual OdDbDatabase * database() const ODRX_OVERRIDE
OdTfDwgFilerImpl * getImpl()
Definition: TfDwgFiler.h:77
virtual OdDbObjectId rdSoftOwnershipId()
virtual void wrPoint2d(const OdGePoint2d &value)
virtual OdInt64 rdInt64()
OdTfDiffFilerImpl * m_pFilerXmlData
Definition: TfDwgFiler.h:75
virtual OdDbObjectId rdHardPointerId()
virtual void wrVector2d(const OdGeVector2d &value)
virtual OdDbDatabase * rdDatabase()
virtual void wrBytes(const void *buffer, OdUInt32 numBytes)
virtual void wrDbHandle(const OdDbHandle &value)
virtual void wrSoftOwnershipId(const OdDbObjectId &value)
virtual void wrHardOwnershipId(const OdDbObjectId &value)
virtual OdInt8 rdInt8()
virtual void wrDatabase(OdDbDatabase *pDb)
virtual void wrHardPointerId(const OdDbObjectId &value)
virtual void seek(OdInt64 offset, OdDb::FilerSeekType seekType) ODRX_OVERRIDE
Definition: TfDwgFiler.h:87
virtual void rdBytes(void *buffer, OdUInt32 numBytes)
virtual OdUInt64 tell() const ODRX_OVERRIDE
Definition: TfDwgFiler.h:88
virtual void wrScale3d(const OdGeScale3d &value)
virtual OdDbObjectId rdSoftPointerId()
ODRX_DECLARE_MEMBERS(OdTfDwgFiler)
virtual OdInt32 rdInt32()
virtual OdGeScale3d rdScale3d()
virtual void wrInt8(OdInt8 value)
virtual void wrUInt8(OdUInt8 value)
virtual void addReference(OdDbObjectId id, OdDb::ReferenceType rt) ODRX_OVERRIDE
virtual void wrInt32(OdInt32 value)
virtual OdString rdString()
virtual OdUInt8 rdUInt8()
virtual void * rdAddress()
virtual OdDbHandle rdDbHandle()
virtual OdRxClass * rdClass()
virtual void wrClass(const OdRxClass *c)
virtual OdDbObjectId rdHardOwnershipId()
virtual OdGePoint2d rdPoint2d()
virtual void wrInt16(OdInt16 value)
virtual OdGeVector2d rdVector2d()
virtual double rdDouble()
virtual void wrBool(bool value)
virtual void wrSoftPointerId(const OdDbObjectId &value)
virtual OdInt16 rdInt16()
virtual bool usesReferences() const ODRX_OVERRIDE
Definition: TfDwgFiler.h:149
virtual void wrInt64(OdInt64 value)
virtual OdGeVector3d rdVector3d()
virtual OdGePoint3d rdPoint3d()
virtual void wrAddress(const void *value)
static TiXmlDocument * saveDwgToXml(OdDbDatabase *pDb, const char *pcszXsdFilename, OdDbObjectId idObj)
virtual void wrString(const OdString &value)
virtual bool rdBool() ODRX_OVERRIDE
void setUsedMUE()
Definition: TfDwgFiler.h:79
bool & bApplyDiff()
Definition: TfDwgFiler.h:78
virtual void wrVector3d(const OdGeVector3d &value)
virtual void wrDouble(double value)
virtual void wrPoint3d(const OdGePoint3d &value)
virtual FilerType filerType() const ODRX_OVERRIDE
Definition: TfDwgFiler.h:85
GLenum void ** pointer
Definition: gles2_ext.h:288
GLfloat GLfloat GLfloat z
Definition: gles2_ext.h:318
GLuint buffer
Definition: gles2_ext.h:178
GLsizeiptr size
Definition: gles2_ext.h:182
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
GLuint const GLchar * name
Definition: gles2_ext.h:265
GLuint GLsizei GLsizei * length
Definition: gles2_ext.h:274
GLintptr offset
Definition: gles2_ext.h:183
GLsizei const GLfloat * value
Definition: gles2_ext.h:302
ReferenceType
Definition: DbObjectId.h:62
FilerSeekType
Definition: OdStreamBuf.h:49
@ countBytes
Definition: Tf.h:383
TypesEnum
Definition: Tf.h:390
TRecordNewObject(OdString name, OdUInt32 pos, size_t num)
Definition: TfDwgFiler.h:283
OdUInt32 size
Definition: TfDwgFiler.h:48
char * pBinaryData
Definition: TfDwgFiler.h:47
OdUInt32 posBinaryData
Definition: TfDwgFiler.h:49