Skip to content

Commit

Permalink
libdxfrw update
Browse files Browse the repository at this point in the history
synced libdxfrw with upstream version
fcd977cc7f8f6cc7f012e5b72d33cf7d77b3fa69; created new branch LibreCAD_2
there to track changes
  • Loading branch information
lordofbikes committed Nov 10, 2021
1 parent 415f8fc commit 33b34d4
Show file tree
Hide file tree
Showing 39 changed files with 1,255 additions and 1,225 deletions.
1 change: 1 addition & 0 deletions libraries/libdxfrw/libdxfrw.pro
Expand Up @@ -30,6 +30,7 @@ QT -= svg
SOURCES += \
src/libdxfrw.cpp \
src/libdwgr.cpp \
src/drw_base.cpp \
src/drw_header.cpp \
src/drw_classes.cpp \
src/drw_entities.cpp \
Expand Down
94 changes: 75 additions & 19 deletions libraries/libdxfrw/src/drw_base.h
Expand Up @@ -17,8 +17,8 @@
#define DRW_VERSION "0.6.3"

#include <string>
#include <list>
#include <cmath>
#include <unordered_map>

#ifdef DRW_ASSERTS
# define drw_assert(a) assert(a)
Expand Down Expand Up @@ -67,16 +67,46 @@ namespace DRW {

//! Version numbers for the DXF Format.
enum Version {
UNKNOWNV, /*!< UNKNOWN VERSION. */
AC1006, /*!< R10. */
AC1009, /*!< R11 & R12. */
AC1012, /*!< R13. */
AC1014, /*!< R14. */
AC1015, /*!< ACAD 2000. */
AC1018, /*!< ACAD 2004. */
AC1021, /*!< ACAD 2007. */
AC1024, /*!< ACAD 2010. */
AC1027 /*!< ACAD 2013. */
UNKNOWNV, //!< UNKNOWN VERSION.
MC00, //!< DWG Release 1.1
AC12, //!< DWG Release 1.2
AC14, //!< DWG Release 1.4
AC150, //!< DWG Release 2.0
AC210, //!< DWG Release 2.10
AC1002, //!< DWG Release 2.5
AC1003, //!< DWG Release 2.6
AC1004, //!< DWG Relase 9
AC1006, //!< DWG Release 10
AC1009, //!< DWG Release 11/12 (LT R1/R2)
AC1012, //!< DWG Release 13 (LT95)
AC1014, //!< DWG Release 14/14.01 (LT97/LT98)
AC1015, //!< AutoCAD 2000/2000i/2002
AC1018, //!< AutoCAD 2004/2005/2006
AC1021, //!< AutoCAD 2007/2008/2009
AC1024, //!< AutoCAD 2010/2011/2012
AC1027, //!< AutoCAD 2013/2014/2015/2016/2017
AC1032, //!< AutoCAD 2018/2019/2020
};

const std::unordered_map< const char*, DRW::Version > dwgVersionStrings {
{ "MC0.0", DRW::MC00 },
{ "AC1.2", DRW::AC12 },
{ "AC1.4", DRW::AC14 },
{ "AC1.50", DRW::AC150 },
{ "AC2.10", DRW::AC210 },
{ "AC1002", DRW::AC1002 },
{ "AC1003", DRW::AC1003 },
{ "AC1004", DRW::AC1004 },
{ "AC1006", DRW::AC1006 },
{ "AC1009", DRW::AC1009 },
{ "AC1012", DRW::AC1012 },
{ "AC1014", DRW::AC1014 },
{ "AC1015", DRW::AC1015 },
{ "AC1018", DRW::AC1018 },
{ "AC1021", DRW::AC1021 },
{ "AC1024", DRW::AC1024 },
{ "AC1027", DRW::AC1027 },
{ "AC1032", DRW::AC1032 },
};

enum error {
Expand All @@ -96,11 +126,37 @@ BAD_READ_OBJECTS, /*!< error in objects read process. */
BAD_READ_SECTION, /*!< error in sections read process. */
};

enum DBG_LEVEL {
NONE,
DEBUG
enum class DebugLevel {
None,
Debug
};

/**
* Interface for debug printers.
*
* The base class is silent and ignores all debugging.
*/
class DebugPrinter {
public:
virtual void printS(const std::string &s){(void)s;}
virtual void printI(long long int i){(void)i;}
virtual void printUI(long long unsigned int i){(void)i;}
virtual void printD(double d){(void)d;}
virtual void printH(long long int i){(void)i;}
virtual void printB(int i){(void)i;}
virtual void printHL(int c, int s, int h){(void)c;(void)s;(void)h;}
virtual void printPT(double x, double y, double z){(void)x;(void)y;(void)z;}
DebugPrinter()=default;
virtual ~DebugPrinter()=default;
};

/**
* Sets a custom debug printer to use when outputting debug messages.
*
* Ownership of `printer` is transferred.
*/
void setCustomDebugPrinter( DebugPrinter* printer );

//! Special codes for colors
enum ColorCodes {
ColorByLayer = 256,
Expand Down Expand Up @@ -151,7 +207,7 @@ enum TransparencyCodes {
*/
class DRW_Coord {
public:
DRW_Coord():x(0), y(0),z(0) {}
DRW_Coord()=default;
DRW_Coord(double ix, double iy, double iz): x(ix), y(iy),z(iz){}

/*!< convert to unitary vector */
Expand All @@ -166,9 +222,9 @@ class DRW_Coord {
}

public:
double x;
double y;
double z;
double x{0};
double y{0};
double z{0};
};


Expand Down Expand Up @@ -236,7 +292,7 @@ class DRW_Variant {
void setCoordX(double d) { if (vType == COORD) vdata.x = d;}
void setCoordY(double d) { if (vType == COORD) vdata.y = d;}
void setCoordZ(double d) { if (vType == COORD) vdata.z = d;}
enum TYPE type() { return vType;}
enum TYPE type() const { return vType;}
int code() { return vCode;} /*!< returns dxf code of this value*/

private:
Expand Down
31 changes: 15 additions & 16 deletions libraries/libdxfrw/src/drw_entities.cpp
Expand Up @@ -1222,7 +1222,7 @@ bool DRW_LWPolyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_DBG("end flags value: "); DRW_DBG(flags);

if (vertexnum > 0) { //verify if is lwpol without vertex (empty)
// add vertexs
// add vertexes
vertex = std::make_shared<DRW_Vertex2D>();
vertex->x = buf->getRawDouble();
vertex->y = buf->getRawDouble();
Expand Down Expand Up @@ -1267,7 +1267,7 @@ bool DRW_LWPolyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
}
}
}
if (DRW_DBGGL == DRW_dbg::DEBUG){
if (DRW_DBGGL == DRW_dbg::Level::Debug){
DRW_DBG("\nVertex list: ");
for (auto& pv: vertlist) {
DRW_DBG("\n x: "); DRW_DBG(pv->x); DRW_DBG(" y: "); DRW_DBG(pv->y); DRW_DBG(" bulge: "); DRW_DBG(pv->bulge);
Expand Down Expand Up @@ -1331,10 +1331,10 @@ bool DRW_Text::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
return ret;
DRW_DBG("\n***************************** parsing text *********************************************\n");

// DataFlags RC Used to determine presence of subsquent data, set to 0xFF for R14-
// DataFlags RC Used to determine presence of subsequent data, set to 0xFF for R14-
duint8 data_flags = 0x00;
if (version > DRW::AC1014) {//2000+
data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsquent data */
data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsequent data */
DRW_DBG("data_flags: "); DRW_DBG(data_flags); DRW_DBG("\n");
if ( !(data_flags & 0x01) ) { /* Elevation RD --- present if !(DataFlags & 0x01) */
basePoint.z = buf->getRawDouble();
Expand Down Expand Up @@ -1469,7 +1469,7 @@ bool DRW_MText::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_UNUSED(ext_ht);
/* Extents wid BD Undocumented and not present in DXF or entget The extents
rectangle, when rotated the same as the text, fits the actual text image on
the screen (altough we've seen it include an extra row of text in height). */
the screen (although we've seen it include an extra row of text in height). */
double ext_wid = buf->getBitDouble();
DRW_UNUSED(ext_wid);
/* Text TV 1 All text in one long string (without '\n's 3 for line wrapping).
Expand Down Expand Up @@ -1911,7 +1911,6 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
}
for (dint32 j = 0; j < spline->ncontrol;++j){
std::shared_ptr<DRW_Coord> crd = std::make_shared<DRW_Coord>(buf->get2RawDouble());
spline->controllist.push_back(crd);
if(isRational)
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
spline->controllist.push_back(crd);
Expand Down Expand Up @@ -1968,8 +1967,8 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_DBG("\ndef line: "); DRW_DBG(angleL); DRW_DBG(","); DRW_DBG(ptL.x); DRW_DBG(","); DRW_DBG(ptL.y);
DRW_DBG(","); DRW_DBG(offL.x); DRW_DBG(","); DRW_DBG(offL.y); DRW_DBG(","); DRW_DBG(angleL);
for (duint16 i = 0 ; i < numDashL; ++i){
double lenghtL = buf->getBitDouble();
DRW_DBG(","); DRW_DBG(lenghtL);
double lengthL = buf->getBitDouble();
DRW_DBG(","); DRW_DBG(lengthL);
}
}//end deflines
} //end not solid
Expand Down Expand Up @@ -2085,8 +2084,9 @@ void DRW_Spline::parseCode(int code, dxfReader *reader){
case 40:
knotslist.push_back(reader->getDouble());
break;
// case 41:
// break;
case 41:
weightlist.push_back(reader->getDouble());
break;
default:
DRW_Entity::parseCode(code, reader);
break;
Expand Down Expand Up @@ -2158,7 +2158,7 @@ bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
for (dint32 i= 0; i<nfit; ++i)
fitlist.push_back(std::make_shared<DRW_Coord>(buf->get3BitDouble()));

if (DRW_DBGGL == DRW_dbg::DEBUG){
if (DRW_DBGGL == DRW_dbg::Level::Debug) {
DRW_DBG("\nknots list: ");
for (auto const& v: knotslist) {
DRW_DBG("\n"); DRW_DBG(v);
Expand All @@ -2171,7 +2171,6 @@ bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
for (auto const& v: fitlist) {
DRW_DBG("\n"); DRW_DBGPT(v->x, v->y, v->z);
}

}

/* Common Entity Handle Data */
Expand Down Expand Up @@ -2795,7 +2794,7 @@ bool DRW_Leader::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
dint32 nPt = buf->getBitLong();
DRW_DBG(" Num pts "); DRW_DBG(nPt);

// add vertexs
// add vertexes
for (int i = 0; i< nPt; i++){
DRW_Coord vertex = buf->get3BitDouble();
vertexlist.push_back(std::make_shared<DRW_Coord>(vertex));
Expand Down Expand Up @@ -2943,7 +2942,7 @@ bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
frozenLyCount = buf->getBitLong();
DRW_DBG("Frozen Layer count?: "); DRW_DBG(frozenLyCount); DRW_DBG("\n");
DRW_DBG("Status Flags?: "); DRW_DBG(buf->getBitLong()); DRW_DBG("\n");
//RLZ: Warning needed separate string bufer
//RLZ: Warning needed separate string buffer
DRW_DBG("Style sheet?: "); DRW_DBG(sBuf->getVariableText(version, false)); DRW_DBG("\n");
DRW_DBG("Render mode?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n");
DRW_DBG("UCS OMore...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n");
Expand All @@ -2958,8 +2957,8 @@ bool DRW_Viewport::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_DBG("ShadePlot Mode...: "); DRW_DBG(buf->getBitShort()); DRW_DBG("\n");
}
if (version > DRW::AC1018) {//2007+
DRW_DBG("Use def Ligth...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n");
DRW_DBG("Def ligth tipe?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n");
DRW_DBG("Use def Light...: "); DRW_DBG(buf->getBit()); DRW_DBG("\n");
DRW_DBG("Def light type?: "); DRW_DBG(buf->getRawChar8()); DRW_DBG("\n");
DRW_DBG("Brightness: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n");
DRW_DBG("Contrast: "); DRW_DBG(buf->getBitDouble()); DRW_DBG("\n");
// DRW_DBG("Ambient Cmc or Enc: "); DRW_DBG(buf->getCmColor(version)); DRW_DBG("\n");
Expand Down
5 changes: 3 additions & 2 deletions libraries/libdxfrw/src/drw_entities.h
Expand Up @@ -824,6 +824,7 @@ class DRW_Spline : public DRW_Entity {
double tolfit; /*!< fit point tolerance, code 44, default 0.0000001 */

std::vector<double> knotslist; /*!< knots list, code 40 */
std::vector<double> weightlist; /*!< weight list, code 41 */
std::vector<std::shared_ptr<DRW_Coord>> controllist; /*!< control points list, code 10, 20 & 30 */
std::vector<std::shared_ptr<DRW_Coord>> fitlist; /*!< fit points list, code 11, 21 & 31 */

Expand Down Expand Up @@ -1061,7 +1062,7 @@ class DRW_Dimension : public DRW_Entity {
double getDir() const { return rot;} /*!< rotation angle of the dimension text, code 53 (optional) default 0 */
void setDir(const double d) { rot = d;}

DRW_Coord getExtrusion(){return extPoint;} /*!< extrusion, code 210, 220 & 230 */
DRW_Coord getExtrusion() const {return extPoint;} /*!< extrusion, code 210, 220 & 230 */
void setExtrusion(const DRW_Coord p) {extPoint =p;}
std::string getName(){return name;} /*!< Name of the block that contains the entities, code 2 */
void setName(const std::string s) {name = s;}
Expand Down Expand Up @@ -1207,7 +1208,7 @@ class DRW_DimDiametric : public DRW_Dimension {

DRW_Coord getDiameter1Point() const {return getPt5();} /*!< First definition point for diameter, code 15, 25 & 35 */
void setDiameter1Point(const DRW_Coord p){setPt5(p);}
DRW_Coord getDiameter2Point() const {return getDefPoint();} /*!< Oposite point for diameter, code 10, 20 & 30 */
DRW_Coord getDiameter2Point() const {return getDefPoint();} /*!< Opposite point for diameter, code 10, 20 & 30 */
void setDiameter2Point(const DRW_Coord p){setDefPoint(p);}
double getLeaderLength() const {return getRa40();} /*!< Leader length, code 40 */
void setLeaderLength(const double d) {setRa40(d);}
Expand Down

0 comments on commit 33b34d4

Please sign in to comment.