This commit is contained in:
Chenwenxuan
2024-03-06 14:54:30 +08:00
commit edac2715f0
1525 changed files with 809982 additions and 0 deletions

View File

@@ -0,0 +1,284 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include <QStringList>
#include "rs_filtercxf.h"
#include <iostream>
#include <fstream>
#include "rs_arc.h"
#include "rs_line.h"
#include "rs_font.h"
#include "rs_utility.h"
#include "rs_system.h"
#include "rs_block.h"
#include "rs_math.h"
#include "rs_debug.h"
/**
* Default constructor.
*/
RS_FilterCXF::RS_FilterCXF() : RS_FilterInterface() {
RS_DEBUG->print("Setting up CXF filter...");
}
/**
* Implementation of the method used for RS_Import to communicate
* with this filter.
*
* @param g The graphic in which the entities from the file
* will be created or the graphics from which the entities are
* taken to be stored in a file.
*/
bool RS_FilterCXF::fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/) {
RS_DEBUG->print("CXF Filter: importing file '%s'...", file.toLatin1().data());
//this->graphic = &g;
bool success = false;
// Load font file as we normally do, but the font doesn't own the
// letters (we'll add them to the graphic instead. Hence 'false').
RS_Font font(file, false);
success = font.loadFont();
if (success==false) {
RS_DEBUG->print(RS_Debug::D_WARNING,
"Cannot open CXF file '%s'.", file.toLatin1().data());
return false;
}
g.addVariable("Names",
font.getNames().join(","), 0);
g.addVariable("LetterSpacing", font.getLetterSpacing(), 0);
g.addVariable("WordSpacing", font.getWordSpacing(), 0);
g.addVariable("LineSpacingFactor", font.getLineSpacingFactor(), 0);
g.addVariable("Authors", font.getAuthors().join(","), 0);
if (!font.getEncoding().isEmpty()) {
g.addVariable("Encoding", font.getEncoding(), 0);
}
RS_BlockList* letterList = font.getLetterList();
for (unsigned i=0; i<font.countLetters(); ++i) {
RS_Block* ch = font.letterAt(i);
QString uCode;
uCode.setNum(ch->getName().at(0).unicode(), 16);
while (uCode.length()<4) {
uCode="0"+uCode;
}
//ch->setName("[" + uCode + "] " + ch->getName());
//letterList->rename(ch, QString("[%1]").arg(ch->getName()));
letterList->rename(ch,
QString("[%1] %2").arg(uCode).arg(ch->getName().at(0)));
g.addBlock(ch, false);
ch->reparent(&g);
}
g.addBlockNotification();
return true;
}
/**
* Implementation of the method used for RS_Export to communicate
* with this filter.
*
* @param file Full path to the CXF file that will be written.
*/
bool RS_FilterCXF::fileExport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/) {
RS_DEBUG->print("CXF Filter: exporting file '%s'...", file.toLatin1().data());
// crashes under windoze xp:
//std::ofstream fout;
RS_DEBUG->print("RS_FilterCXF::fileExport: open");
//fout.open((const char*)file.toLocal8Bit());
FILE* fp;
if ((fp = fopen(file.toLocal8Bit(), "wt")) != NULL) {
RS_DEBUG->print("RS_FilterCXF::fileExport: open: OK");
RS_DEBUG->print("RS_FilterCXF::fileExport: header");
// header:
fprintf(fp, "# Format: QCad II Font\n");
fprintf(fp, "# Creator: %s\n",
(const char*)RS_SYSTEM->getAppName().toLocal8Bit());
fprintf(fp, "# Version: %s\n",
(const char*)RS_SYSTEM->getAppVersion().toLocal8Bit());
RS_DEBUG->print("001");
QString ns = g.getVariableString("Names", "");
if (!ns.isEmpty()) {
QStringList names = ns.split(',');
RS_DEBUG->print("002");
for (int i = 0; i < names.size(); ++i) {
fprintf(fp, "# Name: %s\n",
names.at(i).toLocal8Bit().data() );
}
}
RS_DEBUG->print("003");
QString es = g.getVariableString("Encoding", "");
if (!es.isEmpty()) {
fprintf(fp, "# Encoding: %s\n",
es.toLocal8Bit().data());
}
RS_DEBUG->print("004a");
fprintf(fp, "# LetterSpacing: %f\n",
g.getVariableDouble("LetterSpacing", 3.0));
fprintf(fp, "# WordSpacing: %f\n",
g.getVariableDouble("WordSpacing", 6.75));
fprintf(fp, "# LineSpacingFactor: %f\n",
g.getVariableDouble("LineSpacingFactor", 1.0));
QString sa = g.getVariableString("Authors", "");
RS_DEBUG->print("authors: %s", sa.toLocal8Bit().data());
if (!sa.isEmpty()) {
QStringList authors = sa.split(',');
RS_DEBUG->print("006");
RS_DEBUG->print("count: %d", authors.count());
QString a;
for (QStringList::Iterator it2 = authors.begin();
it2!=authors.end(); ++it2) {
RS_DEBUG->print("006a");
a = QString(*it2);
RS_DEBUG->print("006b");
RS_DEBUG->print("string is: %s", a.toLatin1().data());
RS_DEBUG->print("006b0");
fprintf(fp, "# Author: ");
RS_DEBUG->print("006b1");
fprintf(fp, "%s\n", a.toLatin1().data());
//fout << "# Author: " << a.ascii() << "\n";
}
RS_DEBUG->print("007");
}
RS_DEBUG->print("RS_FilterCXF::fileExport: header: OK");
RS_DEBUG->print("008");
// iterate through blocks (=letters of font)
for (unsigned i=0; i<g.countBlocks(); ++i) {
RS_Block* blk = g.blockAt(i);
RS_DEBUG->print("block: %d", i);
RS_DEBUG->print("001");
if (blk && !blk->isUndone()) {
RS_DEBUG->print("002");
RS_DEBUG->print("002a: %s",
(blk->getName().toLocal8Bit().data()));
fprintf(fp, "\n%s\n",
(blk->getName().toLocal8Bit().data()));
// iterate through entities of this letter:
for (RS_Entity* e=blk->firstEntity(RS2::ResolveAll);
e;
e=blk->nextEntity(RS2::ResolveAll)) {
if (!e->isUndone()) {
RS_DEBUG->print("004");
// lines:
if (e->rtti()==RS2::EntityLine) {
RS_Line* l = (RS_Line*)e;
fprintf(fp, "L %f,%f,%f,%f\n",
l->getStartpoint().x,
l->getStartpoint().y,
l->getEndpoint().x,
l->getEndpoint().y);
}
// arcs:
else if (e->rtti()==RS2::EntityArc) {
RS_Arc* a = (RS_Arc*)e;
if (!a->isReversed()) {
fprintf(fp, "A ");
} else {
fprintf(fp, "AR ");
}
fprintf(fp, "%f,%f,%f,%f,%f\n",
a->getCenter().x,
a->getCenter().y,
a->getRadius(),
RS_Math::rad2deg(a->getAngle1()),
RS_Math::rad2deg(a->getAngle2())
);
}
// Ignore entities other than arcs / lines
else {}
}
RS_DEBUG->print("005");
}
RS_DEBUG->print("006");
}
RS_DEBUG->print("007");
}
//fout.close();
fclose(fp);
RS_DEBUG->print("CXF Filter: exporting file: OK");
return true;
}
else {
RS_DEBUG->print("CXF Filter: exporting file failed");
}
return false;
}
/**
* Streams a double value to the gien stream cutting away trailing 0's.
*
* @param value A double value. e.g. 2.700000
*/
void RS_FilterCXF::stream(std::ofstream& fs, double value) {
fs << RS_Utility::doubleToString(value).toLatin1().data();
}

View File

@@ -0,0 +1,65 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef RS_FILTERCXF_H
#define RS_FILTERCXF_H
#include <fstream>
#include "rs_filterinterface.h"
/**
* This format filter class can import and export CXF (CAM Expert Font) files.
*
* @author Andrew Mustun
*/
class RS_FilterCXF : public RS_FilterInterface {
public:
RS_FilterCXF();
~RS_FilterCXF() {}
/**
* @return RS2::FormatCXF.
*/
virtual bool canImport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatCXF);
}
virtual bool canExport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatCXF);
}
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
void stream(std::ofstream& fs, double value);
static RS_FilterInterface* createFilter(){return new RS_FilterCXF();}
};
#endif

3372
lib/filters/rs_filterdxf.cpp Normal file

File diff suppressed because it is too large Load Diff

222
lib/filters/rs_filterdxf.h Normal file
View File

@@ -0,0 +1,222 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef RS_FILTERDXF_H
#define RS_FILTERDXF_H
#include "rs_filterinterface.h"
#include "rs_block.h"
#include "rs_color.h"
#include "rs_dimension.h"
#include "rs_insert.h"
#include "rs_layer.h"
#include "rs_leader.h"
#include "rs_polyline.h"
#include "rs_solid.h"
#include "rs_text.h"
#include "rs_image.h"
#include "dl_creationinterface.h"
#include "dl_dxf.h"
class RS_Spline;
class LC_SplinePoints;
class RS_Hatch;
class DL_WriterA;
/**
* This format filter class can import and export DXF files.
* It depends on the dxflib library.
*
* @author Andrew Mustun
*/
class RS_FilterDXF : public RS_FilterInterface, DL_CreationInterface {
public:
RS_FilterDXF();
~RS_FilterDXF();
virtual bool canImport(const QString &/*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatDXFOLD);
}
virtual bool canExport(const QString &fileName, RS2::FormatType t) const {
return (t==RS2::FormatDXFOLD || t==RS2::FormatDXFOLD12);
}
// Import:
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
// Methods from DL_CreationInterface:
virtual void addLayer(const DL_LayerData& data);
virtual void addBlock(const DL_BlockData& data);
virtual void endBlock();
virtual void addPoint(const DL_PointData& data);
virtual void addLine(const DL_LineData& data);
virtual void addArc(const DL_ArcData& data);
virtual void addEllipse(const DL_EllipseData& data);
virtual void addCircle(const DL_CircleData& data);
virtual void addPolyline(const DL_PolylineData& data);
virtual void addVertex(const DL_VertexData& data);
virtual void addSpline(const DL_SplineData& data);
virtual void addKnot(const DL_KnotData&) {}
virtual void addControlPoint(const DL_ControlPointData& data);
virtual void addInsert(const DL_InsertData& data);
virtual void addTrace(const DL_TraceData& ) {}
virtual void addSolid(const DL_SolidData& ) {}
virtual void addMTextChunk(const char* text);
virtual void addMText(const DL_MTextData& data);
virtual void addText(const DL_TextData& data);
//virtual void addDimension(const DL_DimensionData& data);
RS_DimensionData convDimensionData(const DL_DimensionData& data);
virtual void addDimAlign(const DL_DimensionData& data,
const DL_DimAlignedData& edata);
virtual void addDimLinear(const DL_DimensionData& data,
const DL_DimLinearData& edata);
virtual void addDimRadial(const DL_DimensionData& data,
const DL_DimRadialData& edata);
virtual void addDimDiametric(const DL_DimensionData& data,
const DL_DimDiametricData& edata);
virtual void addDimAngular(const DL_DimensionData& data,
const DL_DimAngularData& edata);
virtual void addDimAngular3P(const DL_DimensionData& data,
const DL_DimAngular3PData& edata);
virtual void addLeader(const DL_LeaderData& data);
virtual void addLeaderVertex(const DL_LeaderVertexData& data);
virtual void addHatch(const DL_HatchData& data);
virtual void addHatchLoop(const DL_HatchLoopData& data);
virtual void addHatchEdge(const DL_HatchEdgeData& data);
virtual void addImage(const DL_ImageData& data);
virtual void linkImage(const DL_ImageDefData& data);
virtual void endEntity();
virtual void endSequence() {}
virtual void add3dFace(const DL_3dFaceData& data);
virtual void addDimOrdinate(const DL_DimensionData&, const DL_DimOrdinateData&);
virtual void addComment(const char*);
virtual void setVariableVector(const char* key,
double v1, double v2, double v3, int code);
virtual void setVariableString(const char* key, const char* value, int code);
virtual void setVariableInt(const char* key, int value, int code);
virtual void setVariableDouble(const char* key, double value, int code);
// Export:
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType type);
void writeVariables(DL_WriterA& dw);
void writeLayer(DL_WriterA& dw, RS_Layer* l);
void writeLineType(DL_WriterA& dw, RS2::LineType t);
void writeAppid(DL_WriterA& dw, const char* appid);
void writeBlock(DL_WriterA& dw, RS_Block* blk);
void writeEntity(DL_WriterA& dw, RS_Entity* e);
void writeEntity(DL_WriterA& dw, RS_Entity* e, const DL_Attributes& attrib);
void writePoint(DL_WriterA& dw, RS_Point* p, const DL_Attributes& attrib);
void writeLine(DL_WriterA& dw, RS_Line* l, const DL_Attributes& attrib);
void writePolyline(DL_WriterA& dw,
RS_Polyline* l, const DL_Attributes& attrib);
void writeSpline(DL_WriterA& dw,
RS_Spline* s, const DL_Attributes& attrib);
void writeSplinePoints(DL_WriterA& dw,
LC_SplinePoints* s, const DL_Attributes& attrib);
void writeCircle(DL_WriterA& dw, RS_Circle* c, const DL_Attributes& attrib);
void writeArc(DL_WriterA& dw, RS_Arc* a, const DL_Attributes& attrib);
void writeEllipse(DL_WriterA& dw, RS_Ellipse* s, const DL_Attributes& attrib);
void writeInsert(DL_WriterA& dw, RS_Insert* i, const DL_Attributes& attrib);
void writeText(DL_WriterA& dw, RS_Text* t, const DL_Attributes& attrib);
void writeDimension(DL_WriterA& dw, RS_Dimension* d,
const DL_Attributes& attrib);
void writeLeader(DL_WriterA& dw, RS_Leader* l, const DL_Attributes& attrib);
void writeHatch(DL_WriterA& dw, RS_Hatch* h, const DL_Attributes& attrib);
void writeSolid(DL_WriterA& dw, RS_Solid* s, const DL_Attributes& attrib);
void writeImage(DL_WriterA& dw, RS_Image* i, const DL_Attributes& attrib);
void writeEntityContainer(DL_WriterA& dw, RS_EntityContainer* con,
const DL_Attributes& attrib);
void writeAtomicEntities(DL_WriterA& dw, RS_EntityContainer* c,
const DL_Attributes& attrib, RS2::ResolveLevel level);
void writeImageDef(DL_WriterA& dw, RS_Image* i);
void setEntityAttributes(RS_Entity* entity, const DL_Attributes& attrib);
DL_Attributes getEntityAttributes(RS_Entity* entity);
static QString toDxfString(const QString& string);
static QString toNativeString(const char* data, const QString& encoding);
QString getDXFEncoding();
public:
RS_Pen attributesToPen(const DL_Attributes& attrib) const;
static RS_Color numberToColor(int num, bool comp=false);
static int colorToNumber(const RS_Color& col);
static RS2::LineType nameToLineType(const QString& name);
static QString lineTypeToName(RS2::LineType lineType);
//static QString lineTypeToDescription(RS2::LineType lineType);
static RS2::LineWidth numberToWidth(int num);
static int widthToNumber(RS2::LineWidth width);
static RS2::AngleFormat numberToAngleFormat(int num);
static int angleFormatToNumber(RS2::AngleFormat af);
static RS2::Unit numberToUnit(int num);
static int unitToNumber(RS2::Unit unit);
static bool isVariableTwoDimensional(const QString& var);
static RS_FilterInterface* createFilter(){return new RS_FilterDXF();}
private:
/** Pointer to the graphic we currently operate on. */
RS_Graphic* graphic;
/** File name. Used to find out the full path of images. */
QString file;
/** string for concatinating text parts of MTEXT entities. */
QString mtext;
/** Pointer to current polyline entity we're adding vertices to. */
RS_Polyline* polyline;
/** Pointer to current spline entity we're adding control points to. */
RS_Spline* spline;
LC_SplinePoints* splinePoints;
/** Pointer to current leader entity we're adding vertices to. */
RS_Leader* leader;
/** Pointer to current entity container (either block or graphic) */
RS_EntityContainer* currentContainer;
/** Pointer to current hatch or NULL. */
RS_Hatch* hatch;
/** Pointer to current hatch loop or NULL. */
RS_EntityContainer* hatchLoop;
DL_Dxf dxf;
RS_VariableDict variables;
bool omitHatchLoop;
}
;
#endif

File diff suppressed because it is too large Load Diff

119
lib/filters/rs_filterdxf1.h Normal file
View File

@@ -0,0 +1,119 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef RS_FILTERDXF1_H
#define RS_FILTERDXF1_H
#include <QFile>
#include "rs_filterinterface.h"
/**
* This format filter class can import and export old DXF files
* from QCad 1.x.
*
* This is legacy code from QCad 1.x.
*
* @author Andrew Mustun
*/
class RS_FilterDXF1 : public RS_FilterInterface {
public:
RS_FilterDXF1();
virtual bool canImport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatDXF1);
}
virtual bool canExport(const QString& /*fileName*/, RS2::FormatType /*t*/) const {
return false;
}
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
virtual bool fileExport(RS_Graphic& /*g*/, const QString& /*file*/,
RS2::FormatType /*type*/);
bool readFromBuffer();
void reset();
void resetBufP();
void setBufP(int _fBufP);
int getBufP() {
return fBufP;
}
void delBuffer();
void dos2unix();
QString getBufLine();
char* getBufLineCh();
char* getBuf() {
return fBuf;
}
void setBuf(char* _buf) {
fBuf=_buf;
}
void setFSize(unsigned _s) {
fSize=_s;
}
void copyBufFrom(const char* _buf);
bool gotoBufLine(char* _lstr);
bool gotoBufLineString(char* _lstr);
void replaceBinaryBytesBy(char _c);
void separateBuf(char _c1=13,
char _c2=10,
char _c3=0,
char _c4=0);
void removeComment(char _fc='(',
char _lc=')');
bool readFileInBuffer(char* _name, int _bNum=-1);
bool readFileInBuffer(int _bNum=-1);
void strDecodeDxfString(QString& str);
bool mtCompFloat(double _v1, double _v2, double _tol=1.0e-6);
static RS_FilterInterface* createFilter(){return new RS_FilterDXF1();}
static RS2::LineWidth numberToWidth(int num);
static int widthToNumber(RS2::LineWidth width);
protected:
/** Pointer to the graphic we currently operate on. */
RS_Graphic* graphic;
FILE* fPointer; // File pointer
char* fBuf; // Filebuffer
int fBufP; // Filebuffer-Pointer (walks through 'fBuf')
unsigned fSize; // Filesize
bool dosFile; // File is in DOS-format
int numElements;
QString name;
QFile file;
}
;
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,240 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2021 A. Stebich (librecad@mail.lordofbikes.de)
** Copyright (C) 2011 Rallaz, rallazz@gmail.com
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License as published by the Free Software
** Foundation either version 2 of the License, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
**********************************************************************/
#ifndef RS_FILTERDXFRW_H
#define RS_FILTERDXFRW_H
#include "rs_filterinterface.h"
#include "rs_color.h"
#include "rs_dimension.h"
#include "drw_interface.h"
#include "libdxfrw.h"
class RS_Point;
class RS_Line;
class RS_Circle;
class RS_Arc;
class RS_Ellipse;
class RS_Solid;
class RS_Polyline;
class RS_Spline;
class LC_SplinePoints;
class RS_Insert;
class RS_MText;
class RS_Text;
class RS_Hatch;
class RS_Image;
class RS_Leader;
class RS_Polyline;
class DL_WriterA;
/**
* This format filter class can import and export DXF files.
* It depends on the libdxfrw library.
*
* @author Rallaz
*/
class RS_FilterDXFRW : public RS_FilterInterface, DRW_Interface {
public:
RS_FilterDXFRW();
~RS_FilterDXFRW();
virtual bool canImport(const QString &/*fileName*/, RS2::FormatType t) const override {
#ifdef DWGSUPPORT
return (t==RS2::FormatDXFRW || t==RS2::FormatDWG);
#else
return (t==RS2::FormatDXFRW);
#endif
}
virtual bool canExport(const QString &/*fileName*/, RS2::FormatType t) const override {
return (t==RS2::FormatDXFRW || t==RS2::FormatDXFRW2004 || t==RS2::FormatDXFRW2000
|| t==RS2::FormatDXFRW14 || t==RS2::FormatDXFRW12);
}
// Error messages
virtual QString lastError() const override;
// Import:
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType type) override;
// Methods from DRW_CreationInterface:
virtual void addHeader(const DRW_Header* data) override;
virtual void addLType(const DRW_LType& /*data*/) override{}
virtual void addLayer(const DRW_Layer& data) override;
virtual void addDimStyle(const DRW_Dimstyle& data) override;
virtual void addVport(const DRW_Vport& data) override;
virtual void addTextStyle(const DRW_Textstyle& /*data*/) override{}
virtual void addAppId(const DRW_AppId& /*data*/) override{}
virtual void addBlock(const DRW_Block& data) override;
virtual void setBlock(const int handle) override;
virtual void endBlock() override;
virtual void addPoint(const DRW_Point& data) override;
virtual void addLine(const DRW_Line& data) override;
virtual void addRay(const DRW_Ray& data) override;
virtual void addXline(const DRW_Xline& data) override;
virtual void addCircle(const DRW_Circle& data) override;
virtual void addArc(const DRW_Arc& data) override;
virtual void addEllipse(const DRW_Ellipse& data) override;
virtual void addLWPolyline(const DRW_LWPolyline& data) override;
virtual void addText(const DRW_Text& data) override;
virtual void addPolyline(const DRW_Polyline& data) override;
virtual void addSpline(const DRW_Spline* data) override;
virtual void addKnot(const DRW_Entity&) override{}
virtual void addInsert(const DRW_Insert& data) override;
virtual void addTrace(const DRW_Trace& data) override;
virtual void addSolid(const DRW_Solid& data) override;
virtual void addMText(const DRW_MText& data) override;
RS_DimensionData convDimensionData(const DRW_Dimension* data);
virtual void addDimAlign(const DRW_DimAligned *data) override;
virtual void addDimLinear(const DRW_DimLinear *data) override;
virtual void addDimRadial(const DRW_DimRadial *data) override;
virtual void addDimDiametric(const DRW_DimDiametric *data) override;
virtual void addDimAngular(const DRW_DimAngular *data) override;
virtual void addDimAngular3P(const DRW_DimAngular3p *data) override;
virtual void addDimOrdinate(const DRW_DimOrdinate *data) override;
virtual void addLeader(const DRW_Leader *data) override;
virtual void addHatch(const DRW_Hatch* data) override;
virtual void addViewport(const DRW_Viewport& /*data*/) override{}
virtual void addImage(const DRW_Image* data) override;
virtual void linkImage(const DRW_ImageDef* data) override;
virtual void add3dFace(const DRW_3Dface& data) override;
virtual void addComment(const char*) override;
virtual void addPlotSettings(const DRW_PlotSettings* data) override;
// Export:
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType type) override;
virtual void writeHeader(DRW_Header& data) override;
virtual void writeEntities() override;
virtual void writeLTypes() override;
virtual void writeLayers() override;
virtual void writeTextstyles() override;
virtual void writeVports() override;
virtual void writeBlockRecords() override;
virtual void writeBlocks() override;
virtual void writeDimstyles() override;
virtual void writeObjects() override;
virtual void writeAppId() override;
void writePoint(RS_Point* p);
void writeLine(RS_Line* l);
void writeCircle(RS_Circle* c);
void writeArc(RS_Arc* a);
void writeEllipse(RS_Ellipse* s);
void writeSolid(RS_Solid* s);
void writeLWPolyline(RS_Polyline* l);
void writeSpline(RS_Spline* s);
void writeSplinePoints(LC_SplinePoints *s);
void writeInsert(RS_Insert* i);
void writeMText(RS_MText* t);
void writeText(RS_Text* t);
void writeHatch(RS_Hatch* h);
void writeImage(RS_Image* i);
void writeLeader(RS_Leader* l);
void writeDimension(RS_Dimension* d);
void writePolyline(RS_Polyline* p);
/* void writeEntityContainer(DL_WriterA& dw, RS_EntityContainer* con,
const DRW_Entity& attrib);
void writeAtomicEntities(DL_WriterA& dw, RS_EntityContainer* c,
const DRW_Entity& attrib, RS2::ResolveLevel level);*/
void setEntityAttributes(RS_Entity* entity, const DRW_Entity* attrib);
void getEntityAttributes(DRW_Entity* ent, const RS_Entity* entity);
static QString toDxfString(const QString& str);
static QString toNativeString(const QString& data);
public:
RS_Pen attributesToPen(const DRW_Layer* att) const;
static RS_Color numberToColor(int num);
static int colorToNumber(const RS_Color& col, int *rgb);
static RS2::LineType nameToLineType(const QString& name);
static QString lineTypeToName(RS2::LineType lineType);
//static QString lineTypeToDescription(RS2::LineType lineType);
static RS2::LineWidth numberToWidth(DRW_LW_Conv::lineWidth lw);
static DRW_LW_Conv::lineWidth widthToNumber(RS2::LineWidth width);
static RS2::AngleFormat numberToAngleFormat(int num);
static int angleFormatToNumber(RS2::AngleFormat af);
static RS2::Unit numberToUnit(int num);
static int unitToNumber(RS2::Unit unit);
static bool isVariableTwoDimensional(const QString& var);
static RS_FilterInterface* createFilter(){return new RS_FilterDXFRW();}
private:
void prepareBlocks();
void writeEntity(RS_Entity* e);
#ifdef DWGSUPPORT
void printDwgError(int le);
QString printDwgVersion(int v);
#endif
private:
/** Pointer to the graphic we currently operate on. */
RS_Graphic* graphic;
/** File name. Used to find out the full path of images. */
QString file;
/** Pointer to current entity container (either block or graphic) */
RS_EntityContainer* currentContainer;
/** File codePage. Used to find the text coder. */
QString codePage;
/** File version. */
QString versionStr;
int version;
/** Library File version. */
#define LIBDXFRW_VERSION(version,release,patch) (((version) << 16) | ((release) << 8) | (patch))
bool isLibDxfRw {false};
uint libDxfRwVersion;
/** dimension style. */
QString dimStyle;
/** text style. */
QString textStyle;
/** Temporary list to handle unnamed blocks to write R12 dxf. */
QHash <RS_Entity*, QString> noNameBlock;
QHash <QString, QString> fontList;
bool oldMText;
dxfRW *dxfW;
/** If saved version are 2004 or above can save color in RGB value. */
bool exactColor;
/** hash of block containers and handleBlock numbers to read dwg files */
QHash<int, RS_EntityContainer*> blockHash;
/** Pointer to entity container to store possible orphan entities like paper space */
RS_EntityContainer* dummyContainer;
};
#endif

View File

@@ -0,0 +1,109 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2021 A. Stebich (librecad@mail.lordofbikes.de)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef RS_FILTERINTERFACE_H
#define RS_FILTERINTERFACE_H
#include "rs_graphic.h"
#include <QObject>
/**
* This is the interface that must be implemented for all
* format filter classes. The RS_FileIO class
* uses the methods defined in here to interact with the format
* filter classes.
*
* @author Andrew Mustun
*/
class RS_FilterInterface {
public:
/**
* Constructor.
*/
RS_FilterInterface() = default;
/**
* Destructor.
*/
virtual ~RS_FilterInterface()=default;
/**
* Checks if this filter can import the given file type.
*
* @retval true if the filter can import the file type
* @retval false otherwise.
*/
virtual bool canImport(const QString &fileName, RS2::FormatType t) const = 0;
/**
* Checks if this filter can export the given file type.
*
* @return true if the filter can export the file type,
* false otherwise.
*/
virtual bool canExport(const QString &fileName, RS2::FormatType t) const = 0;
/**
* The implementation of this method in a inherited format
* class should read a file from disk and put the entities
* into the current entity container.
*/
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType type) = 0;
/**
* The implementation of this method in a inherited format
* class should write the entities in the current entity container
* to a file on the disk.
*/
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType type) = 0;
/**
* Request the error message for the last import/export action, based on member variable \p errorCode.
* The default implementation is for existing filters, inherited without error handling methods.
* It is strongly recommend for new implementations to overwrite this method with some useful error messages.
*/
virtual QString lastError() const {
return QObject::tr( "undefined error", "RS_FilterInterface");
};
/**
* Request the error code for the last import/export action.
* The default value 0 means no error.
*/
virtual int lastErrorCode() const {
return errorCode;
};
static RS_FilterInterface * createFilter(){return NULL;}
protected:
int errorCode {0}; //< error code for last import/export action
};
#endif

3395
lib/filters/rs_filterjww.cpp Normal file

File diff suppressed because it is too large Load Diff

242
lib/filters/rs_filterjww.h Normal file
View File

@@ -0,0 +1,242 @@
/****************************************************************************
** $Id: rs_filterjww.h,v 1.1.1.2 2010/02/08 11:58:24 zeronemo2007 Exp $
**
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
** This file is part of the qcadlib Library project.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid qcadlib Professional Edition licenses may use
** this file in accordance with the qcadlib Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.ribbonsoft.com for further details.
**
** Contact info@ribbonsoft.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#ifndef RS_FILTERJWW_H
#define RS_FILTERJWW_H
#include "rs_filterinterface.h"
#include "rs_color.h"
#include "rs_dimension.h"
#include "dl_creationinterface.h"
#include "dl_jww.h"
class RS_Point;
class RS_Line;
class RS_Circle;
class RS_Arc;
class RS_Ellipse;
class RS_Solid;
class RS_Polyline;
class RS_Spline;
class LC_SplinePoints;
class RS_Insert;
class RS_MText;
class RS_Text;
class RS_Hatch;
class RS_Image;
class RS_Leader;
class RS_Polyline;
class DL_WriterA;
/**
* This format filter class can import and export JWW files.
* It depends on the jwwlib library.
*
* @author Andrew Mustun
*/
class RS_FilterJWW : public RS_FilterInterface, DL_CreationInterface {
public:
RS_FilterJWW();
~RS_FilterJWW();
/**
* @return RS2::FormatJWW.
*/
//RS2::FormatType rtti() const{
// return RS2::FormatJWW;
//}
/*
virtual bool canImport(RS2::FormatType t) {
return (t==RS2::FormatJWW);
}
virtual bool canExport(RS2::FormatType t) {
return (t==RS2::FormatJWW || t==RS2::FormatJWW12);
}*/
// Import:
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
// Methods from DL_CreationInterface:
virtual void addLayer(const DL_LayerData& data);
virtual void addBlock(const DL_BlockData& data);
virtual void endBlock();
virtual void addPoint(const DL_PointData& data);
virtual void addLine(const DL_LineData& data);
virtual void addArc(const DL_ArcData& data);
virtual void addEllipse(const DL_EllipseData& data);
virtual void addCircle(const DL_CircleData& data);
virtual void addPolyline(const DL_PolylineData& data);
virtual void addVertex(const DL_VertexData& data);
virtual void addSpline(const DL_SplineData& data);
virtual void addKnot(const DL_KnotData&) {}
virtual void addControlPoint(const DL_ControlPointData& data);
virtual void addInsert(const DL_InsertData& data);
virtual void addTrace(const DL_TraceData& ) {}
virtual void addSolid(const DL_SolidData& ) {}
virtual void addMTextChunk(const char* text);
virtual void addMText(const DL_MTextData& data);
virtual void addText(const DL_TextData& data);
//virtual void addDimension(const DL_DimensionData& data);
RS_DimensionData convDimensionData(const DL_DimensionData& data);
virtual void addDimAlign(const DL_DimensionData& data,
const DL_DimAlignedData& edata);
virtual void addDimLinear(const DL_DimensionData& data,
const DL_DimLinearData& edata);
virtual void addDimRadial(const DL_DimensionData& data,
const DL_DimRadialData& edata);
virtual void addDimDiametric(const DL_DimensionData& data,
const DL_DimDiametricData& edata);
virtual void addDimAngular(const DL_DimensionData& data,
const DL_DimAngularData& edata);
virtual void addDimAngular3P(const DL_DimensionData& data,
const DL_DimAngular3PData& edata);
virtual void addLeader(const DL_LeaderData& data);
virtual void addLeaderVertex(const DL_LeaderVertexData& data);
virtual void addHatch(const DL_HatchData& data);
virtual void addHatchLoop(const DL_HatchLoopData& data);
virtual void addHatchEdge(const DL_HatchEdgeData& data);
virtual void addImage(const DL_ImageData& data);
virtual void linkImage(const DL_ImageDefData& data);
virtual void endEntity();
virtual void endSequence() {}
virtual void add3dFace(const DL_3dFaceData& data);
virtual void addDimOrdinate(const DL_DimensionData&, const DL_DimOrdinateData&);
virtual void addComment(const char*);
virtual void setVariableVector(const char* key,
double v1, double v2, double v3, int code);
virtual void setVariableString(const char* key, const char* value, int code);
virtual void setVariableInt(const char* key, int value, int code);
virtual void setVariableDouble(const char* key, double value, int code);
// Export:
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType type);
void writeVariables(DL_WriterA& dw);
void writeLayer(DL_WriterA& dw, RS_Layer* l);
void writeLineType(DL_WriterA& dw, RS2::LineType t);
void writeAppid(DL_WriterA& dw, const char* appid);
void writeBlock(DL_WriterA& dw, RS_Block* blk);
void writeEntity(DL_WriterA& dw, RS_Entity* e);
void writeEntity(DL_WriterA& dw, RS_Entity* e, const DL_Attributes& attrib);
void writePoint(DL_WriterA& dw, RS_Point* p, const DL_Attributes& attrib);
void writeLine(DL_WriterA& dw, RS_Line* l, const DL_Attributes& attrib);
void writePolyline(DL_WriterA& dw,
RS_Polyline* l, const DL_Attributes& attrib);
void writeSpline(DL_WriterA& dw,
RS_Spline* s, const DL_Attributes& attrib);
void writeSplinePoints(DL_WriterA& dw,
LC_SplinePoints* s, const DL_Attributes& attrib);
void writeCircle(DL_WriterA& dw, RS_Circle* c, const DL_Attributes& attrib);
void writeArc(DL_WriterA& dw, RS_Arc* a, const DL_Attributes& attrib);
void writeEllipse(DL_WriterA& dw, RS_Ellipse* s, const DL_Attributes& attrib);
void writeInsert(DL_WriterA& dw, RS_Insert* i, const DL_Attributes& attrib);
void writeText(DL_WriterA& dw, RS_MText* t, const DL_Attributes& attrib);
void writeDimension(DL_WriterA& dw, RS_Dimension* d,
const DL_Attributes& attrib);
void writeLeader(DL_WriterA& dw, RS_Leader* l, const DL_Attributes& attrib);
void writeHatch(DL_WriterA& dw, RS_Hatch* h, const DL_Attributes& attrib);
void writeSolid(DL_WriterA& dw, RS_Solid* s, const DL_Attributes& attrib);
void writeImage(DL_WriterA& dw, RS_Image* i, const DL_Attributes& attrib);
void writeEntityContainer(DL_WriterA& dw, RS_EntityContainer* con,
const DL_Attributes& attrib);
void writeAtomicEntities(DL_WriterA& dw, RS_EntityContainer* c,
const DL_Attributes& attrib, RS2::ResolveLevel level);
void writeImageDef(DL_WriterA& dw, RS_Image* i);
void setEntityAttributes(RS_Entity* entity, const DL_Attributes& attrib);
DL_Attributes getEntityAttributes(RS_Entity* entity);
static QString toDxfString(const QString& string);
QString toNativeString(const char* data, const QString& encoding);
QString getDXFEncoding();
public:
RS_Pen attributesToPen(const DL_Attributes& attrib) const;
static RS_Color numberToColor(int num, bool comp=false);
static int colorToNumber(const RS_Color& col);
static RS2::LineType nameToLineType(const QString& name);
static QString lineTypeToName(RS2::LineType lineType);
//static QString lineTypeToDescription(RS2::LineType lineType);
static RS2::LineWidth numberToWidth(int num);
static int widthToNumber(RS2::LineWidth width);
static RS2::AngleFormat numberToAngleFormat(int num);
static int angleFormatToNumber(RS2::AngleFormat af);
static RS2::Unit numberToUnit(int num);
static int unitToNumber(RS2::Unit unit);
static bool isVariableTwoDimensional(const QString& var);
virtual bool canImport(const QString & /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatJWW);
}
virtual bool canExport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatJWW);
}
static RS_FilterInterface *createFilter() {return new RS_FilterJWW();}
private:
/** Pointer to the graphic we currently operate on. */
RS_Graphic* graphic;
/** File name. Used to find out the full path of images. */
QString file;
/** string for concatinating text parts of MTEXT entities. */
QString mtext;
/** Pointer to current polyline entity we're adding vertices to. */
RS_Polyline* polyline;
/** Pointer to current spline entity we're adding control points to. */
RS_Spline* spline;
LC_SplinePoints* splinePoints;
/** Pointer to current leader entity we're adding vertices to. */
RS_Leader* leader;
/** Pointer to current entity container (either block or graphic) */
RS_EntityContainer* currentContainer;
/** Pointer to current hatch or NULL. */
RS_Hatch* hatch;
/** Pointer to current hatch loop or NULL. */
RS_EntityContainer* hatchLoop;
DL_Jww jww;
RS_VariableDict variables;
}
;
#endif

View File

@@ -0,0 +1,285 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include <QTextStream>
#include <QStringList>
#include <QDate>
#include "rs_filterlff.h"
#include "rs_arc.h"
#include "rs_line.h"
#include "rs_font.h"
#include "rs_utility.h"
#include "rs_system.h"
#include "rs_block.h"
#include "rs_polyline.h"
#include "rs_insert.h"
#include "rs_debug.h"
/**
* Default constructor.
*/
RS_FilterLFF::RS_FilterLFF() : RS_FilterInterface() {
RS_DEBUG->print("Setting up LFF filter...");
}
/**
* Implementation of the method used for RS_Import to communicate
* with this filter.
*
* @param g The graphic in which the entities from the file
* will be created or the graphics from which the entities are
* taken to be stored in a file.
*/
bool RS_FilterLFF::fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/) {
RS_DEBUG->print("LFF Filter: importing file '%s'...", file.toLatin1().data());
//this->graphic = &g;
bool success = false;
// Load font file as we normally do, but the font doesn't own the
// letters (we'll add them to the graphic instead. Hence 'false').
RS_Font font(file, false);
success = font.loadFont();
if (success==false) {
RS_DEBUG->print(RS_Debug::D_WARNING,
"Cannot open LFF file '%s'.", file.toLatin1().data());
return false;
}
g.addVariable("Names",
font.getNames().join(","), 0);
g.addVariable("LetterSpacing", font.getLetterSpacing(), 0);
g.addVariable("WordSpacing", font.getWordSpacing(), 0);
g.addVariable("LineSpacingFactor", font.getLineSpacingFactor(), 0);
g.addVariable("Authors", font.getAuthors().join(","), 0);
g.addVariable("License", font.getFileLicense(), 0);
g.addVariable("Created", font.getFileCreate(), 0);
if (!font.getEncoding().isEmpty()) {
g.addVariable("Encoding", font.getEncoding(), 0);
}
font.generateAllFonts();
RS_BlockList* letterList = font.getLetterList();
for (unsigned i=0; i<font.countLetters(); ++i) {
RS_Block* ch = font.letterAt(i);
QString uCode;
uCode.setNum(ch->getName().at(0).unicode(), 16);
while (uCode.length()<4) {
// uCode.rightJustified(4, '0');
uCode="0"+uCode;
}
//ch->setName("[" + uCode + "] " + ch->getName());
//letterList->rename(ch, QString("[%1]").arg(ch->getName()));
letterList->rename(ch,
QString("[%1] %2").arg(uCode).arg(ch->getName().at(0)));
g.addBlock(ch, false);
ch->reparent(&g);
}
g.addBlockNotification();
return true;
}
QString clearZeros(double num, int prec){
QString str = QString::number(num, 'f', prec);
int i = str.length()- 1;
while (str.at(i) == '0' && i>1) {
--i;
}
if (str.at(i) != '.')
i++;
return str.left(i);
}
/**
* Implementation of the method used for RS_Export to communicate
* with this filter.
*
* @param file Full path to the LFF file that will be written.
*/
bool RS_FilterLFF::fileExport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/) {
RS_DEBUG->print("LFF Filter: exporting file '%s'...", file.toLatin1().data());
RS_DEBUG->print("RS_FilterLFF::fileExport: open");
QFile f(file);
QTextStream ts(&f);
ts.setCodec("UTF-8");
if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
RS_DEBUG->print("RS_FilterLFF::fileExport: open: OK");
RS_DEBUG->print("RS_FilterLFF::fileExport: header");
// header:
ts << "# Format: LibreCAD Font 1\n";
ts << QString("# Creator: %1\n").arg(RS_SYSTEM->getAppName());
ts << QString("# Version: %1\n").arg(RS_SYSTEM->getAppVersion());
QString ns = g.getVariableString("Names", "");
if (!ns.isEmpty()) {
QStringList names = ns.split(',');
RS_DEBUG->print("002");
for (int i = 0; i < names.size(); ++i) {
ts << QString("# Name: %1\n").arg(names.at(i));
}
}
QString es = g.getVariableString("Encoding", "");
ts << QString("# Encoding: UTF-8\n");
ts << QString("# LetterSpacing: %1\n").arg(
g.getVariableDouble("LetterSpacing", 3.0));
ts << QString("# WordSpacing: %1\n").arg(
g.getVariableDouble("WordSpacing", 6.75));
ts << QString("# LineSpacingFactor: %1\n").arg(
g.getVariableDouble("LineSpacingFactor", 1.0));
QString dateline = QDate::currentDate().toString ("yyyy-MM-dd");
ts << QString("# Created: %1\n").arg(
g.getVariableString("Created", dateline));
ts << QString("# Last modified: %1\n").arg(dateline);
QString sa = g.getVariableString("Authors", "");
RS_DEBUG->print("authors: %s", sa.toLocal8Bit().data());
if (!sa.isEmpty()) {
QStringList authors = sa.split(',');
RS_DEBUG->print("count: %d", authors.count());
QString a;
for (int i = 0; i < authors.size(); ++i) {
ts << QString("# Author: %1\n").arg(authors.at(i));
}
}
es = g.getVariableString("License", "");
if (!es.isEmpty()) {
ts << QString("# License: %1\n").arg(es);
} else
ts << "# License: unknown\n";
RS_DEBUG->print("RS_FilterLFF::fileExport: header: OK");
// iterate through blocks (=letters of font)
for (unsigned i=0; i<g.countBlocks(); ++i) {
RS_Block* blk = g.blockAt(i);
RS_DEBUG->print("block: %d", i);
if (blk && !blk->isUndone()) {
RS_DEBUG->print("002a: %s",
(blk->getName().toLocal8Bit().data()));
ts << QString("\n%1\n").arg(blk->getName());
// iterate through entities of this letter:
for (RS_Entity* e=blk->firstEntity(RS2::ResolveNone);
e;
e=blk->nextEntity(RS2::ResolveNone)) {
if (!e->isUndone()) {
// lines:
if (e->rtti()==RS2::EntityLine) {
RS_Line* l = (RS_Line*)e;
ts << clearZeros(l->getStartpoint().x, 5) << ',';
ts << clearZeros(l->getStartpoint().y, 5) << ';';
ts << clearZeros(l->getEndpoint().x, 5) << ',';
ts << clearZeros(l->getEndpoint().y, 5) << '\n';
}
// arcs:
else if (e->rtti()==RS2::EntityArc) {
RS_Arc* a = (RS_Arc*)e;
ts << clearZeros(a->getStartpoint().x, 5) << ',';
ts << clearZeros(a->getStartpoint().y, 5) << ';';
ts << clearZeros(a->getEndpoint().x, 5) << ',';
ts << clearZeros(a->getEndpoint().y, 5) << ",A";
ts << clearZeros(a->getBulge(), 5) << '\n';
}
else if (e->rtti()==RS2::EntityBlock) {
RS_Block* b = (RS_Block*)e;
QString uCode;
uCode.setNum(b->getName().at(0).unicode(), 16);
if (uCode.length()<4) {
uCode = uCode.rightJustified(4, '0');
}
ts << QString("C%1\n").arg(uCode);
}
else if (e->rtti()==RS2::EntityPolyline) {
RS_Polyline* p = (RS_Polyline*)e;
ts << clearZeros(p->getStartpoint().x, 5) << ',';
ts << clearZeros(p->getStartpoint().y, 5);
for (RS_Entity* e2=p->firstEntity(RS2::ResolveNone);
e2;
e2=p->nextEntity(RS2::ResolveNone)) {
if (e2->rtti()==RS2::EntityLine){
RS_Line* l = (RS_Line*)e2;
ts << ';' << clearZeros(l->getEndpoint().x, 5) << ',';
ts << clearZeros(l->getEndpoint().y, 5);
} else if (e2->rtti()==RS2::EntityArc){
RS_Arc* a = (RS_Arc*)e2;
ts << ';' << clearZeros(a->getEndpoint().x, 5) << ',';
ts << clearZeros(a->getEndpoint().y, 5) <<",A";
ts << clearZeros(a->getBulge(), 5);
}
}
ts<<'\n';
}
// Ignore entities other than arcs / lines
else {}
}
}
}
}
f.close();
RS_DEBUG->print("LFF Filter: exporting file: OK");
return true;
}
else {
RS_DEBUG->print("LFF Filter: exporting file failed");
}
return false;
}
/**
* Streams a double value to the gien stream cutting away trailing 0's.
*
* @param value A double value. e.g. 2.700000
*/
void RS_FilterLFF::stream(std::ofstream& fs, double value) {
fs << RS_Utility::doubleToString(value).toLatin1().data();
}

View File

@@ -0,0 +1,71 @@
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2011 Rallaz (rallazz@gmail.com)
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
**
**
** This file is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#ifndef RS_FILTERLFF_H
#define RS_FILTERLFF_H
#include <fstream>
#include "rs_filterinterface.h"
/**
* This format filter class can import and export LFF (LibreCAD Font File) files.
*
* @author Rallaz
*/
class RS_FilterLFF : public RS_FilterInterface {
public:
RS_FilterLFF();
~RS_FilterLFF() {}
/**
* @return RS2::FormatLFF.
*/
RS2::FormatType rtti() const{
return RS2::FormatLFF;
}
virtual bool canImport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatLFF);
}
virtual bool canExport(const QString& /*fileName*/, RS2::FormatType t) const {
return (t==RS2::FormatLFF);
}
virtual bool fileImport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
virtual bool fileExport(RS_Graphic& g, const QString& file, RS2::FormatType /*type*/);
void stream(std::ofstream& fs, double value);
static RS_FilterInterface *createFilter() {return new RS_FilterLFF();}
};
#endif