Skip to content

Commit

Permalink
Patches from SolveSpace (#19)
Browse files Browse the repository at this point in the history
* Add improved CMake buildsystem.

* Delete all allocated items in destructors.

* Read and write knot weights in DRW_Spline.

* Add forgotten initialization for DRW_Dimension::length.

* Set $DIMSCALE default value to 1.0.

The old value was likely a copy-paste error.

* Don't write $DIMTXSTY (handle of referenced STYLE) by default.

QCad doesn't display any dimensions where it's set.

* Adjust DRW_Dimstyle defaults to match DRW_Header::write.

* Initialize DRW dimension type in dimension subclass constructors.

* Add DRW_Entity::setWidthMm.

In principle there's an algebraic relationship between the DXF line
width value and line thickness in millimeters, and everything except
AutoCAD accepts any value from the range, but AutoCAD ignores all
values except a few chosen ones.

* Don't use pure virtual functions in DRW_Interface.

This forced API consumers to implement a lot of useless empty
functions for no good reason.

* Fix H/V align reading for MTEXT.

* Remove unused DRW_Interface::setBlock.

* Silence -Wunused-parameter warnings.

These are all in our default implementation of DRW_Interface, which
ignores everything it receives, so it's OK.

* Add DRW_Dimension::{has,get,set}ActualMeasurement.

* Don't add spline control points twice.

This caused a double free when deallocating DRW_Hatch.

* Remove dwgR::testReader().

* Implement variants of read/write functions that take std::[io]stream*.

* Remove the fileName field from dwgR/dxfRW.

It's more trouble than it's worth when supporting Windows. Instead,
require the caller to always use the appropriate overload of
std::[io]fstream constructor (possibly the wchar_t* one).

* In POLYLINE, use vertex type that matches the polyline type.

This makes polylines readable in AutoCAD again.

* Fix type conversion warnings.

* Fix GCC warning -Wmisleading-indentation.

* Added more codes for colors supported by DXF.

* Add support for $TDCREATE.

According to documentation $TDCREATE has code 40 and contains "Local date/time of drawing creation (see “Special Handling of Date/Time Variables”)".

* Fix opening files saved as DXF R10 in AutoCAD.

When saving in the AC1006 format, several DIMSTYLE groups were
erroneously omitted.

* Up to DXF R12, the default layer "0" may be left undefined.

Some standards mandate the default layer to be unused.

* Use DRW_Block::layer when writing blocks.

Before, the layer was hardcoded to "0" in the writer.

* Misc typos: length

Found via codespell and grep

* Misc. source typos: compressed

Found via `codespell`

* Misc. typos

* DRW_Coord: Simplify constructor/assignment.

Having a user-specified assignment operator but default copy-constructor
violates rule of 2/3/5/0.

Found by clazy.

* Add const-qualifiers to DRW_Dimension getters

getExtrusion and getName was missing const qualifiers.

* Read extrusion tags for dimension entities

Dimension entities support DXF codes 210, 220, 230 and and DRW_Dimension
already had a extPoint member, but the tags were never used when
parsing.

---------

Co-authored-by: whitequark <[email protected]>
Co-authored-by: EvilSpirit <[email protected]>
Co-authored-by: Roman Telezhynskyi <[email protected]>
Co-authored-by: luz.paz <[email protected]>
Co-authored-by: Johannes Rehnman <[email protected]>
  • Loading branch information
6 people authored Apr 15, 2024
1 parent c84ce8e commit 8c57f68
Show file tree
Hide file tree
Showing 33 changed files with 477 additions and 409 deletions.
84 changes: 73 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,82 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(libdxfrw)
if(MSVC)
# Disable some overly strict MSVC warnings.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4244 -wd4800 -wd4805")
endif()

file(GLOB libdxfrw_sources src/*.cpp)
file(GLOB libdxfrw_headers include/*.h)
file(GLOB libdxfrw_intern_sources src/intern/*.cpp)
set(intern_HEADERS
src/intern/drw_cptable932.h
src/intern/drw_cptable936.h
src/intern/drw_cptable949.h
src/intern/drw_cptable950.h
src/intern/drw_cptables.h
src/intern/drw_dbg.h
src/intern/drw_textcodec.h
src/intern/dwgbuffer.h
src/intern/dwgreader15.h
src/intern/dwgreader18.h
src/intern/dwgreader21.h
src/intern/dwgreader24.h
src/intern/dwgreader27.h
src/intern/dwgreader.h
src/intern/dwgutil.h
src/intern/dxfreader.h
src/intern/dxfwriter.h
src/intern/rscodec.h)

if(WIN32)
set(intern_SOURCES
src/intern/drw_dbg.cpp
src/intern/drw_textcodec.cpp
src/intern/dwgbuffer.cpp
src/intern/dwgreader15.cpp
src/intern/dwgreader18.cpp
src/intern/dwgreader21.cpp
src/intern/dwgreader24.cpp
src/intern/dwgreader27.cpp
src/intern/dwgreader.cpp
src/intern/dwgutil.cpp
src/intern/dxfreader.cpp
src/intern/dxfwriter.cpp
src/intern/rscodec.cpp)

include_directories(vs2013/packages/libiconv.1.14.0.11/build/native/include)
link_directories(vs2013/packages/libiconv.1.14.0.11/build/native/lib)
endif()
include_directories(include)
set(libdxfrw_HEADERS
src/drw_base.h
src/drw_interface.h
src/drw_header.h
src/drw_classes.h
src/drw_entities.h
src/drw_objects.h
src/libdxfrw.h)

set(libdxfrw_SOURCES
src/drw_header.cpp
src/drw_classes.cpp
src/drw_entities.cpp
src/drw_objects.cpp
src/libdxfrw.cpp)

set(libdwgr_HEADERS
src/libdwgr.h)

add_library(dxfrw STATIC ${libdxfrw_sources} ${libdxfrw_intern_sources})
set(libdwgr_SOURCES
src/libdwgr.cpp)

install(FILES ${libdxfrw_headers} DESTINATION include)
add_library(dxfrw STATIC
${intern_HEADERS}
${intern_SOURCES}
${libdxfrw_HEADERS}
${libdxfrw_SOURCES}
${libdwgr_HEADERS}
${libdwgr_SOURCES})

target_include_directories(dxfrw PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/intern/)

target_include_directories(dxfrw PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/)

install(FILES ${libdxfrw_HEADERS} DESTINATION include)

if(WIN32)
install(TARGETS dxfrw
Expand All @@ -29,4 +91,4 @@ else()
install(TARGETS dxfrw
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
endif()
endif()
33 changes: 23 additions & 10 deletions src/drw_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,25 @@ enum DBG_LEVEL {

//! Special codes for colors
enum ColorCodes {
ColorByBlock = 0,
Red = 1,
Yellow = 2,
Green = 3,
Cyan = 4,
Blue = 5,
Magenta = 6,
White = 7,
Gray = 8,
Brown = 15,
LRed = 23,
LGreen = 121,
LCyan = 131,
LBlue = 163,
LMagenta = 221,
Black = 250,
LGray = 252,
ColorByLayer = 256,
ColorByBlock = 0

};

//! Spaces
Expand Down Expand Up @@ -151,14 +168,10 @@ 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){}

DRW_Coord& operator = (const DRW_Coord& data) {
x = data.x; y = data.y; z = data.z;
return *this;
}
/*!< convert to unitary vector */
/*! convert to unitary vector */
void unitize(){
double dist;
dist = sqrt(x*x + y*y + z*z);
Expand All @@ -170,9 +183,9 @@ class DRW_Coord {
}

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


Expand Down
98 changes: 82 additions & 16 deletions src/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "intern/drw_dbg.h"


//! Calculate arbitary axis
//! Calculate arbitrary axis
/*!
* Calculate arbitary axis for apply extrusions
* Calculate arbitrary axis for apply extrusions
* @author Rallaz
*/
void DRW_Entity::calculateAxis(DRW_Coord extPoint){
Expand Down Expand Up @@ -50,9 +50,9 @@ void DRW_Entity::calculateAxis(DRW_Coord extPoint){
extAxisY.unitize();
}

//! Extrude a point using arbitary axis
//! Extrude a point using arbitrary axis
/*!
* apply extrusion in a point using arbitary axis (previous calculated)
* apply extrusion in a point using arbitrary axis (previous calculated)
* @author Rallaz
*/
void DRW_Entity::extrudePoint(DRW_Coord extPoint, DRW_Coord *point){
Expand Down Expand Up @@ -1332,10 +1332,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 @@ -1427,6 +1427,59 @@ void DRW_MText::parseCode(int code, dxfReader *reader){
case 44:
interlin = reader->getDouble();
break;
case 71: {
// Attachment point
Attach a = (Attach)reader->getInt32();

switch(a) {
case TopLeft:
alignV = VTop;
alignH = HLeft;
break;
case TopCenter:
alignV = VTop;
alignH = HCenter;
break;
case TopRight:
alignV = VTop;
alignH = HRight;
break;
case MiddleLeft:
alignV = VMiddle;
alignH = HLeft;
break;
case MiddleCenter:
alignV = VMiddle;
alignH = HCenter;
break;
case MiddleRight:
alignV = VMiddle;
alignH = HRight;
break;
case BottomLeft:
alignV = VBottom;
alignH = HLeft;
break;
case BottomCenter:
alignV = VBottom;
alignH = HCenter;
break;
case BottomRight:
alignV = VBottom;
alignH = HRight;
break;
}
} break;
case 72:
// To prevent redirection to DRW_Text::parseCode.
// This code meaning is different for MTEXT.
// Actually: Drawing direction
break;
case 73:
// To prevent redirection to DRW_Text::parseCode.
// This code meaning is different for MTEXT.
// Actually: Mtext line spacing style
break;
default:
DRW_Text::parseCode(code, reader);
break;
Expand Down Expand Up @@ -1464,7 +1517,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 @@ -1912,8 +1965,7 @@ bool DRW_Hatch::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
}
for (dint32 j = 0; j < spline->ncontrol;++j){
// pt0 2RD 10 control point
DRW_Coord* crd = new DRW_Coord(buf->get2RawDouble());
spline->controllist.push_back(crd);
DRW_Coord *crd = new DRW_Coord(buf->get2RawDouble());
if(isRational)
crd->z = buf->getBitDouble(); //RLZ: investigate how store weight
spline->controllist.push_back(crd);
Expand Down Expand Up @@ -1971,8 +2023,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 @@ -2088,8 +2140,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 @@ -2366,6 +2419,10 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){
case 41:
linefactor = reader->getDouble();
break;
case 42:
actual = reader->getDouble();
hasActual = (actual != 0.0);
break;
case 53:
rot = reader->getDouble();
break;
Expand All @@ -2381,6 +2438,15 @@ void DRW_Dimension::parseCode(int code, dxfReader *reader){
case 51:
hdir = reader->getDouble();
break;
case 210:
extPoint.x = reader->getDouble();
break;
case 220:
extPoint.y = reader->getDouble();
break;
case 230:
extPoint.z = reader->getDouble();
break;
default:
DRW_Entity::parseCode(code, reader);
break;
Expand Down Expand Up @@ -2946,7 +3012,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 @@ -2961,8 +3027,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
Loading

0 comments on commit 8c57f68

Please sign in to comment.