Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches from SolveSpace #19

Merged
merged 32 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f12a4e6
Add improved CMake buildsystem.
whitequark Dec 30, 2015
42be927
Delete all allocated items in destructors.
Evil-Spirit Dec 28, 2015
518812a
Read and write knot weights in DRW_Spline.
Evil-Spirit Dec 28, 2015
6eac1d4
Add forgotten initialization for DRW_Dimension::length.
Evil-Spirit Feb 16, 2016
2cc441a
Set $DIMSCALE default value to 1.0.
Evil-Spirit Feb 16, 2016
3b703d0
Don't write $DIMTXSTY (handle of referenced STYLE) by default.
Evil-Spirit Feb 16, 2016
a1e4ea0
Adjust DRW_Dimstyle defaults to match DRW_Header::write.
Evil-Spirit Feb 16, 2016
53da7e8
Initialize DRW dimension type in dimension subclass constructors.
Evil-Spirit Feb 16, 2016
b3951a4
Add DRW_Entity::setWidthMm.
Evil-Spirit Feb 17, 2016
a39aeda
Don't use pure virtual functions in DRW_Interface.
Evil-Spirit Feb 16, 2016
d369fc3
Fix H/V align reading for MTEXT.
Evil-Spirit Apr 26, 2016
3ac5f50
Remove unused DRW_Interface::setBlock.
whitequark May 7, 2016
fd8d324
Silence -Wunused-parameter warnings.
whitequark May 7, 2016
65bfb6c
Add DRW_Dimension::{has,get,set}ActualMeasurement.
Evil-Spirit May 17, 2016
7976446
Don't add spline control points twice.
Evil-Spirit Aug 10, 2016
e5bdcab
Remove dwgR::testReader().
whitequark Oct 9, 2016
e57da1b
Implement variants of read/write functions that take std::[io]stream*.
Evil-Spirit Oct 8, 2016
9e32c4b
Remove the fileName field from dwgR/dxfRW.
whitequark Oct 9, 2016
fc43586
In POLYLINE, use vertex type that matches the polyline type.
Evil-Spirit Feb 4, 2017
b244923
Fix type conversion warnings.
whitequark Mar 10, 2017
27d1c60
Fix GCC warning -Wmisleading-indentation.
dismine Jul 25, 2017
0311944
Added more codes for colors supported by DXF.
dismine Jul 25, 2017
096ad4f
Add support for $TDCREATE.
dismine Jul 25, 2017
0e353ed
Fix opening files saved as DXF R10 in AutoCAD.
dismine Jul 27, 2017
e80a9db
Up to DXF R12, the default layer "0" may be left undefined.
dismine Jul 27, 2017
57cc07c
Use DRW_Block::layer when writing blocks.
dismine Jul 27, 2017
28be97e
Misc typos: length
luzpaz Mar 5, 2018
3efc5e7
Misc. source typos: compressed
luzpaz Mar 5, 2018
ab17517
Misc. typos
luzpaz Mar 5, 2018
126d47e
DRW_Coord: Simplify constructor/assignment.
rpavlik Aug 21, 2019
f236550
Add const-qualifiers to DRW_Dimension getters
johreh Jun 23, 2020
465ad9d
Read extrusion tags for dimension entities
johreh Jun 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
89 changes: 73 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 Down Expand Up @@ -2946,7 +3003,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 +3018,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