Skip to content

Commit

Permalink
Merge pull request LibreCAD#3 from TNick/dwgsupp
Browse files Browse the repository at this point in the history
Add DRW_Text::parseDwg(); added getThickness(); added getExtrusion()
  • Loading branch information
Rallaz committed Mar 20, 2013
2 parents 14eb5f7 + 502a475 commit 7fd3cd2
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 7 deletions.
83 changes: 83 additions & 0 deletions libraries/libdxfrw/src/drw_entities.cpp
Expand Up @@ -819,6 +819,89 @@ void DRW_Text::parseCode(int code, dxfReader *reader){
}
}

bool DRW_Text::parseDwg(DRW::Version version, dwgBuffer *buf){
bool ret = DRW_Entity::parseDwg(version, buf);
if (!ret)
return ret;
DBG("\n***************************** parsing text *********************************************\n");

if (version < DRW::AC1015) {//14-
basePoint.z = buf->getBitDouble(); /* Elevation BD --- */
basePoint.x = buf->getRawDouble(); /* Insertion pt 2RD 10 */
basePoint.y = buf->getRawDouble();
secPoint.x = buf->getRawDouble(); /* Alignment pt 2RD 11 */
secPoint.y = buf->getRawDouble();
extPoint.x = buf->getBitDouble(); /* Extrusion 3BD 210 */
extPoint.y = buf->getBitDouble();
extPoint.z = buf->getBitDouble();
thickness = buf->getBitDouble(); /* Thickness BD 39 */
oblique = buf->getBitDouble(); /* Oblique ang BD 51 */
angle = buf->getBitDouble(); /* Rotation ang BD 50 */
height = buf->getBitDouble(); /* Height BD 40 */
widthscale = buf->getBitDouble(); /* Width factor BD 41 */
text = buf->getVariableUtf8Text(); /* Text value TV 1 */
textgen = buf->getBitShort(); /* Generation BS 71 */
alignH = (HAlign)buf->getBitShort(); /* Horiz align. BS 72 */
alignV = (VAlign)buf->getBitShort(); /* Vert align. BS 73 */
}
if (version > DRW::AC1014) {//2000+
duint8 data_flags = buf->getRawChar8(); /* DataFlags RC Used to determine presence of subsquent data */
if ( data_flags & 0x01 )
{ /* Elevation RD --- present if !(DataFlags & 0x01) */
basePoint.z = buf->getRawDouble();
}
basePoint.x = buf->getRawDouble(); /* Insertion pt 2RD 10 */
basePoint.y = buf->getRawDouble();
if ( data_flags & 0x02 )
{ /* Alignment pt 2DD 11 present if !(DataFlags & 0x02), use 10 & 20 values for 2 default values.*/
extPoint.x = buf->getDefaultDouble(basePoint.x);
extPoint.y = buf->getDefaultDouble(basePoint.y);
}
else
{
extPoint = basePoint;
}
buf->getExtrusion(&extPoint); /* Extrusion BE 210 */
thickness = buf->getThickness(true); /* Thickness BT 39 */
if ( data_flags & 0x04 )
{ /* Oblique ang RD 51 present if !(DataFlags & 0x04) */
oblique = buf->getRawDouble();
}
if ( data_flags & 0x08 )
{ /* Rotation ang RD 50 present if !(DataFlags & 0x08) */
angle = buf->getRawDouble();
}
height = buf->getRawDouble(); /* Height RD 40 */
if ( data_flags & 0x10 )
{ /* Width factor RD 41 present if !(DataFlags & 0x10) */
widthscale = buf->getRawDouble();
}
text = buf->getVariableUtf8Text(); /* Text value TV 1 */
if ( data_flags & 0x20 )
{ /* Generation BS 71 present if !(DataFlags & 0x20) */
textgen = buf->getBitShort();
}
if ( data_flags & 0x40 )
{ /* Horiz align. BS 72 present if !(DataFlags & 0x40) */
alignH = (HAlign)buf->getBitShort();
}
if ( data_flags & 0x80 )
{ /* Vert align. BS 73 present if !(DataFlags & 0x80) */
alignV = (VAlign)buf->getBitShort();
}
}

/* Common Entity Handle Data */
ret = DRW_Entity::parseDwgEntHandle(version, buf);
if (!ret)
return ret;

styleH = buf->getHandle(); /* H 7 STYLE (hard pointer) */

/* CRC X --- */
return buf->isGood();
}

void DRW_MText::parseCode(int code, dxfReader *reader){
switch (code) {
case 1:
Expand Down
4 changes: 3 additions & 1 deletion libraries/libdxfrw/src/drw_entities.h
Expand Up @@ -479,17 +479,19 @@ class DRW_Text : public DRW_Line {

virtual void applyExtrusion(){} //RLZ TODO
void parseCode(int code, dxfReader *reader);
virtual bool parseDwg(DRW::Version version, dwgBuffer *buf);

public:
double height; /*!< height text, code 40 */
UTF8STRING text; /*!< text string, code 1 */
double angle; /*!< rotation angle in degrees (360), code 50 */
double widthscale; /*!< width factor, code 41 */
double oblique; /*!< oblique angle, code 51 */
UTF8STRING style; /*!< stile name, code 7 */
UTF8STRING style; /*!< style name, code 7 */
int textgen; /*!< text generation, code 71 */
enum HAlign alignH; /*!< horizontal align, code 72 */
enum VAlign alignV; /*!< vertical align, code 73 */
dwgHandle styleH; /*!< handle for text style */
};

//! Class to handle insert entries
Expand Down
46 changes: 44 additions & 2 deletions libraries/libdxfrw/src/dwgbuffer.cpp
Expand Up @@ -412,7 +412,35 @@ std::string dwgBuffer::getVariableUtf8Text(){
return decoder->toUtf8(strData);
}

//void getExtrusion(DRW_Coord *ext); //BE
void dwgBuffer::getExtrusion(DRW_Coord *ext)
{

/*
Bit Extrusion
For R13-R14 this is 3BD.
We are asserting that the version is not R13-R14; this values should
be read by the user
*/

/*
For R2000, this is a single bit, followed optionally
by 3BD.*/
duint8 def_val = getBit();
if ( def_val )
{ /* If the single bit is 1, the extrusion value is assumed to be 0,0,1 and
no explicit extrusion is stored. */
ext->x = 0;
ext->y = 0;
ext->z = 1;
}
else
{ /* If the single bit is 0, then it will be followed by 3BD. */
ext->x = getBitDouble();
ext->y = getBitDouble();
ext->z = getBitDouble();
}
}

/**Reads compresed Double with default (max. 64 + 2 bits) returns a floating point double of 64 bits (DD) **/
double dwgBuffer::getDefaultDouble(double d){
Expand Down Expand Up @@ -454,7 +482,21 @@ double dwgBuffer::getDefaultDouble(double d){
return getRawDouble();
}

//void getThickness();//BT

/* BitThickness
* For R13-R14, this is a BD. We are asserting that the version
* is not R13-R14; this value should be read by the user
* For R2000+, this is a single bit, If the bit is one,
* the thickness value is assumed to be 0.0, if not a BD follow
*/
double dwgBuffer::getThickness(bool b_R2000_style) {
if ( b_R2000_style )
/* If the bit is one, the thickness value is assumed to be 0.0.*/
if ( getBit() == 1 )
return 0.0;
/*R13-R14 or bit == 0*/
return getBitDouble();
}

/**Reads raw short 16 bits big-endian order, returns a unsigned short crc & size **/
duint16 dwgBuffer::getBERawShort16(){
Expand Down
4 changes: 2 additions & 2 deletions libraries/libdxfrw/src/dwgbuffer.h
Expand Up @@ -130,9 +130,9 @@ class dwgBuffer {
//H, T, TU, TV, X, U, SN,
std::string getVariableText();
std::string getVariableUtf8Text();
// void getExtrusion(DRW_Coord *ext); //BE
void getExtrusion(DRW_Coord *ext); //BE
double getDefaultDouble(double d); //DD
// void getThickness();//BT
double getThickness(bool b_R2000_style);//BT
//3DD, CMC, TC

duint16 getBERawShort16();
Expand Down
4 changes: 2 additions & 2 deletions libraries/libdxfrw/src/dwgreader.cpp
Expand Up @@ -430,7 +430,7 @@ bool dwgReader15::readDwgEntity(objHandle& obj, DRW_Interface& intfa){
parseAttribs(&e);
intfa.addLWPolyline();
break; }*/
/* case 1: {
case 1: {
DRW_Text e;
ret = e.parseDwg(version, &buff);
if (e.handleBlock != currBlock) {
Expand All @@ -439,7 +439,7 @@ bool dwgReader15::readDwgEntity(objHandle& obj, DRW_Interface& intfa){
}
parseAttribs(&e);
intfa.addText(e);
break; }*/
break; }
default:
break;
}
Expand Down

0 comments on commit 7fd3cd2

Please sign in to comment.