Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
cmake_minimum_required(VERSION 3.10)

cmake_policy(SET CMP0048 NEW)
project(DXFRW VERSION 1.0.1)

# set preferred cache variables
set(LIBDXFRW_BUILD_DOC TRUE CACHE BOOL "Build the documentation")
set(LIBDXFRW_BUILD_DWG2DXF TRUE CACHE BOOL "Build the dwg2dxf application")
set(LIBDXFRW_BUILD_TESTS TRUE CACHE BOOL "Build the DWG read tests (requires dwg2dxf)")


# set compiler warnings
Expand Down Expand Up @@ -34,6 +34,7 @@ set(libdxfrw_srcs
src/intern/dwgreader21.cpp
src/intern/dwgreader24.cpp
src/intern/dwgreader27.cpp
src/intern/dwgreader32.cpp
src/intern/dwgutil.cpp
src/intern/dxfreader.cpp
src/intern/dxfwriter.cpp
Expand Down Expand Up @@ -110,6 +111,11 @@ if(LIBDXFRW_BUILD_DWG2DXF)
add_subdirectory(dwg2dxf)
endif()

if(LIBDXFRW_BUILD_TESTS AND LIBDXFRW_BUILD_DWG2DXF)
enable_testing()
add_subdirectory(tests)
endif()

# INSTALLATION
set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/libdxfrw)

Expand Down
73 changes: 70 additions & 3 deletions src/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,55 @@ bool DRW_3Dface::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){
return buf->isGood();
}

bool DRW_Tolerance::parseCode(int code, const std::unique_ptr<dxfReader>& reader){
switch (code) {
case 1:
text = reader->getUtf8String();
break;
case 3:
dimStyleName = reader->getUtf8String();
break;
case 10:
insertionPoint.x = reader->getDouble();
break;
case 20:
insertionPoint.y = reader->getDouble();
break;
case 30:
insertionPoint.z = reader->getDouble();
break;
case 11:
xAxisDirectionVector.x = reader->getDouble();
break;
case 21:
xAxisDirectionVector.y = reader->getDouble();
break;
case 31:
xAxisDirectionVector.z = 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:
return DRW_Entity::parseCode(code, reader);
}
return true;
}

bool DRW_Tolerance::parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs){
(void) v;
(void) buf;
(void) bs;
DRW_DBG("\n********************** parsing TOLERANCE from DWG is not yet implemented **************************\n");
return true;
}

bool DRW_Block::parseCode(int code, const std::unique_ptr<dxfReader>& reader){
switch (code) {
case 2:
Expand Down Expand Up @@ -1603,6 +1652,17 @@ bool DRW_Polyline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
facecount = buf->getBitShort();
DRW_DBG("face count: "); DRW_DBG(facecount);
DRW_DBG("flags value: "); DRW_DBG(flags);
} else if (oType == 0x1E) { //POLYLINE_MESH per ODA spec sec 19.4.31
flags = buf->getBitShort();
DRW_DBG("flags value: "); DRW_DBG(flags);
flags |= 16; //bit 4 = 3D polygon mesh
curvetype = buf->getBitShort();
vertexcount = buf->getBitShort(); //M-count
DRW_DBG(" M count: "); DRW_DBG(vertexcount);
facecount = buf->getBitShort(); //N-count
DRW_DBG(" N count: "); DRW_DBG(facecount);
/*dint16 mDensity =*/ buf->getBitShort();
/*dint16 nDensity =*/ buf->getBitShort();
}
if (version > DRW::AC1015){ //2004+
ooCount = buf->getBitLong();
Expand Down Expand Up @@ -2157,7 +2217,8 @@ bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
DRW_DBG("\nnum of knots: "); DRW_DBG(nknots); DRW_DBG(" num of control pt: ");
DRW_DBG(ncontrol); DRW_DBG(" weight bit: "); DRW_DBG(weight);
} else {
DRW_DBG("\ndwg Ellipse, unknouwn scenario\n");
DRW_DBG("\ndwg Spline, unknown scenario "); DRW_DBG(scenario);
DRW_DBG(" (expected 1 or 2)\n");
return false; //RLZ: from doc only 1 or 2 are ok ?
}

Expand All @@ -2170,11 +2231,17 @@ bool DRW_Spline::parseDwg(DRW::Version version, dwgBuffer *buf, duint32 bs){
if (!DRW::reserve( controllist, ncontrol)) {
return false;
}
if (weight && !DRW::reserve(weightlist, ncontrol)) {
return false;
}
for (dint32 i= 0; i<ncontrol; ++i){
controllist.push_back(std::make_shared<DRW_Coord>(buf->get3BitDouble()));
if (weight) {
DRW_DBG("\n w: ");
DRW_DBG(buf->getBitDouble()); //RLZ Warning: D (BD or RD)
//per-control-point weight; required for hyperbola/parabola
//conic detection in consumers (e.g. LibreCAD addSpline)
double w = buf->getBitDouble(); //RLZ Warning: D (BD or RD)
weightlist.push_back(w);
DRW_DBG("\n w: "); DRW_DBG(w);
}
}
if (!DRW::reserve( fitlist, nfit)) {
Expand Down
30 changes: 29 additions & 1 deletion src/drw_entities.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace DRW {
// SURFACE, //encrypted proprietary data can be four types
// TABLE,
TEXT,
// TOLERANCE,
TOLERANCE,
DXF_TRACE,
UNDERLAY,
VERTEX,
Expand Down Expand Up @@ -455,6 +455,34 @@ class DRW_3Dface : public DRW_Trace {

};

//! Class to handle TOLERANCE entries
/*!
* Class to handle tolerance entities (geometric dimensioning tolerance).
*/
class DRW_Tolerance : public DRW_Entity {
SETENTFRIENDS
public:
DRW_Tolerance() {
eType = DRW::TOLERANCE;
extPoint.x = 0;
extPoint.y = 0;
extPoint.z = 1;
dimStyleName = "STANDARD";
}
virtual void applyExtrusion() override {}

protected:
bool parseCode(int code, const std::unique_ptr<dxfReader>& reader) override;
virtual bool parseDwg(DRW::Version v, dwgBuffer *buf, duint32 bs=0) override;

public:
UTF8STRING text; /*!< Visual representation of the tolerance, code 1 */
UTF8STRING dimStyleName; /*!< Dim-style name, code 3 */
DRW_Coord insertionPoint; /*!< Insertion point, codes 10/20/30 */
DRW_Coord xAxisDirectionVector; /*!< X-axis direction in WCS, codes 11/21/31 */
DRW_Coord extPoint; /*!< Extrusion direction, codes 210/220/230 */
};

//! Class to handle block entries
/*!
* Class to handle block entries
Expand Down
4 changes: 2 additions & 2 deletions src/drw_header.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1763,7 +1763,7 @@ bool DRW_Header::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *hBbuf
duint32 endBitPos = 160; //start bit: 16 sentinel + 4 size
DRW_DBG("\nbyte size of data: "); DRW_DBG(size);
if ((DRW::AC1024 <= version && 3 < maintenanceVersion)
|| DRW::AC1032 <= version) { //2010+
|| DRW::AC1032 <= version) { //2010+ MV>3
duint32 hSize = buf->getRawLong32();
endBitPos += 32; //start bit: + 4 height size
DRW_DBG("\n2010+ & MV> 3, height 32b: "); DRW_DBG(hSize);
Expand Down Expand Up @@ -2399,7 +2399,7 @@ fs0.close();

buf->setPosition(size+16+4); //read size +16 start sentinel + 4 size
if ((DRW::AC1024 <= version && 3 < maintenanceVersion)
|| DRW::AC1032 <= version) { //2010+
|| DRW::AC1032 <= version) { //2010+ MV>3
buf->getRawLong32();//advance 4 bytes (hisize)
}
DRW_DBG("\nsetting position to: "); DRW_DBG(buf->getPosition());
Expand Down
19 changes: 19 additions & 0 deletions src/drw_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ class DRW_Interface {
virtual void addTextStyle(const DRW_Textstyle& data) = 0;
/** Called for every AppId entry. */
virtual void addAppId(const DRW_AppId& data) = 0;
/** Called for every named UCS table entry. */
virtual void addUCS(const DRW_UCS& data) { (void) data; }
/** Called for every VIEW table entry. */
virtual void addView(const DRW_View& data) { (void) data; }
/** Called for every TOLERANCE entity. */
virtual void addTolerance(const DRW_Tolerance& data) { (void) data; }
/** Called for every Dictionary (named-object container, ODA fixed type 42). */
virtual void addDictionary(const DRW_Dictionary& data) { (void) data; }
/** Called for every Layout (paperspace, ODA fixed type 82). */
virtual void addLayout(const DRW_Layout& data) { (void) data; }
/** Called for every MLineStyle (ODA fixed type 73). */
virtual void addMLineStyle(const DRW_MLineStyle& data) { (void) data; }

/**
* Called for every block. Note: all entities added after this
Expand Down Expand Up @@ -201,6 +213,13 @@ class DRW_Interface {
virtual void writeDimstyles() = 0;
virtual void writeObjects() = 0;
virtual void writeAppId() = 0;
/** Called when the writer wants the implementation to emit named VIEW
* records. Default-empty for ABI compatibility with consumers (LibreCAD_3,
* dx_iface) that don't carry View data. */
virtual void writeViews() {}
/** Called when the writer wants the implementation to emit named UCS
* records. Default-empty (same rationale as writeViews). */
virtual void writeUCSs() {}
};

#endif
Loading