📄 rs_filterdxf.cpp
字号:
/****************************************************************************** $Id: rs_filterdxf.cpp 2371 2005-04-29 11:44:39Z andrew $**** 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.************************************************************************/#include "rs_filterdxf.h"#include <stdio.h>#include "dl_attributes.h"#include "dl_codes.h"#include "dl_writer_ascii.h"#include "rs_dimaligned.h"#include "rs_dimangular.h"#include "rs_dimdiametric.h"#include "rs_dimlinear.h"#include "rs_dimradial.h"#include "rs_fileinfo.h"#include "rs_hatch.h"#include "rs_image.h"#include "rs_leader.h"#include "rs_regexp.h"#include "rs_system.h"#include <qtextcodec.h>/** * Default constructor. * */RS_FilterDXF::RS_FilterDXF() :RS_FilterInterface() { RS_DEBUG->print("RS_FilterDXF::RS_FilterDXF()"); addImportFormat(RS2::FormatDXF); addExportFormat(RS2::FormatDXF); addExportFormat(RS2::FormatDXF12); mtext = ""; polyline = NULL; leader = NULL; hatch = NULL; hatchLoop = NULL; currentContainer = NULL; graphic = NULL; //exportVersion = DL_Codes::VER_2002; //systemVariables.setAutoDelete(true); RS_DEBUG->print("RS_FilterDXF::RS_FilterDXF(): OK");}/** * Destructor. */RS_FilterDXF::~RS_FilterDXF() { RS_DEBUG->print("RS_FilterDXF::~RS_FilterDXF()"); RS_DEBUG->print("RS_FilterDXF::~RS_FilterDXF(): OK");}/** * 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_FilterDXF::fileImport(RS_Graphic& g, const RS_String& file, RS2::FormatType /*type*/) { RS_DEBUG->print("RS_FilterDXF::fileImport"); //RS_DEBUG->timestamp(); RS_DEBUG->print("DXF Filter: importing file '%s'...", (const char*)QFile::encodeName(file)); graphic = &g; currentContainer = graphic; this->file = file; RS_DEBUG->print("graphic->countLayers(): %d", graphic->countLayers()); //graphic->setAutoUpdateBorders(false); RS_DEBUG->print("RS_FilterDXF::fileImport: reading file"); bool success = dxf.in((const char*)QFile::encodeName(file), this); RS_DEBUG->print("RS_FilterDXF::fileImport: reading file: OK"); //graphic->setAutoUpdateBorders(true); if (success==false) { RS_DEBUG->print(RS_Debug::D_WARNING, "Cannot open DXF file '%s'.", (const char*)QFile::encodeName(file)); return false; } RS_DEBUG->print("RS_FilterDXF::fileImport: adding variables"); // add some variables that need to be there for DXF drawings: if (graphic->getVariableString("$DIMSTYLE", "").isEmpty()) { RS_DEBUG->print("RS_FilterDXF::fileImport: adding DIMSTYLE"); graphic->addVariable("$DIMSTYLE", "Standard", 2); RS_DEBUG->print("RS_FilterDXF::fileImport: adding DIMSTYLE: OK"); } RS_DEBUG->print("RS_FilterDXF::fileImport: adding variables: OK"); RS_DEBUG->print("RS_FilterDXF::fileImport: updating inserts"); graphic->updateInserts(); RS_DEBUG->print("RS_FilterDXF::fileImport: updating inserts: OK"); RS_DEBUG->print("RS_FilterDXF::fileImport OK"); //RS_DEBUG->timestamp(); return true;}/** * Implementation of the method which handles layers. */void RS_FilterDXF::addLayer(const DL_LayerData& data) { RS_DEBUG->print("RS_FilterDXF::addLayer"); RS_DEBUG->print(" adding layer: %s", data.name.c_str()); RS_DEBUG->print("RS_FilterDXF::addLayer: creating layer"); RS_Layer* layer = new RS_Layer(data.name.c_str()); RS_DEBUG->print("RS_FilterDXF::addLayer: set pen"); layer->setPen(attributesToPen(attributes)); //layer->setFlags(data.flags&0x07); RS_DEBUG->print("RS_FilterDXF::addLayer: flags"); if (data.flags&0x01) { layer->freeze(true); } if (data.flags&0x04) { layer->lock(true); } RS_DEBUG->print("RS_FilterDXF::addLayer: add layer to graphic"); graphic->addLayer(layer); RS_DEBUG->print("RS_FilterDXF::addLayer: OK");}/** * Implementation of the method which handles blocks. * * @todo Adding blocks to blocks (stack for currentContainer) */void RS_FilterDXF::addBlock(const DL_BlockData& data) { RS_DEBUG->print("RS_FilterDXF::addBlock"); RS_DEBUG->print(" adding block: %s", data.name.c_str()); // Prevent special blocks (paper_space, model_space) from being added: if (RS_String(data.name.c_str()).lower()!="*paper_space0" && RS_String(data.name.c_str()).lower()!="*paper_space" && RS_String(data.name.c_str()).lower()!="*model_space" && RS_String(data.name.c_str()).lower()!="$paper_space0" && RS_String(data.name.c_str()).lower()!="$paper_space" && RS_String(data.name.c_str()).lower()!="$model_space") {#ifndef RS_NO_COMPLEX_ENTITIES if (RS_String(data.name.c_str()).startsWith("__CE")) { RS_EntityContainer* ec = new RS_EntityContainer(); ec->setLayer("0"); currentContainer = ec; graphic->addEntity(ec); //currentContainer->setLayer(graphic->findLayer("0")); } else {#endif RS_Vector bp(data.bpx, data.bpy); RS_Block* block = new RS_Block(graphic, RS_BlockData(data.name.c_str(), bp, false)); //block->setFlags(flags); if (graphic->addBlock(block)) { currentContainer = block; }#ifndef RS_NO_COMPLEX_ENTITIES }#endif }}/** * Implementation of the method which closes blocks. */void RS_FilterDXF::endBlock() { currentContainer = graphic;}/** * Implementation of the method which handles point entities. */void RS_FilterDXF::addPoint(const DL_PointData& data) { RS_Vector v(data.x, data.y); RS_Point* entity = new RS_Point(currentContainer, RS_PointData(v)); setEntityAttributes(entity, attributes); currentContainer->addEntity(entity);}/** * Implementation of the method which handles line entities. */void RS_FilterDXF::addLine(const DL_LineData& data) { RS_DEBUG->print("RS_FilterDXF::addLine"); RS_Vector v1(data.x1, data.y1); RS_Vector v2(data.x2, data.y2); RS_DEBUG->print("RS_FilterDXF::addLine: create line"); if (currentContainer==NULL) { RS_DEBUG->print("RS_FilterDXF::addLine: currentContainer is NULL"); } RS_Line* entity = new RS_Line(currentContainer, RS_LineData(v1, v2)); RS_DEBUG->print("RS_FilterDXF::addLine: set attributes"); setEntityAttributes(entity, attributes); RS_DEBUG->print("RS_FilterDXF::addLine: add entity"); currentContainer->addEntity(entity); RS_DEBUG->print("RS_FilterDXF::addLine: OK");}/** * Implementation of the method which handles arc entities. * * @param angle1 Start angle in deg (!) * @param angle2 End angle in deg (!) */void RS_FilterDXF::addArc(const DL_ArcData& data) { RS_DEBUG->print("RS_FilterDXF::addArc"); //printf("LINE (%12.6f, %12.6f, %12.6f) (%12.6f, %12.6f, %12.6f)\n", // p1[0], p1[1], p1[2], // p2[0], p2[1], p2[2]); RS_Vector v(data.cx, data.cy); RS_ArcData d(v, data.radius, data.angle1/ARAD, data.angle2/ARAD, false); RS_Arc* entity = new RS_Arc(currentContainer, d); setEntityAttributes(entity, attributes); currentContainer->addEntity(entity);}/** * Implementation of the method which handles ellipse entities. * * @param angle1 Start angle in rad (!) * @param angle2 End angle in rad (!) */void RS_FilterDXF::addEllipse(const DL_EllipseData& data) { RS_DEBUG->print("RS_FilterDXF::addEllipse"); RS_Vector v1(data.cx, data.cy); RS_Vector v2(data.mx, data.my); RS_EllipseData ed(v1, v2, data.ratio, data.angle1, data.angle2, false); RS_Ellipse* entity = new RS_Ellipse(currentContainer, ed); setEntityAttributes(entity, attributes); currentContainer->addEntity(entity);}/** * Implementation of the method which handles circle entities. */void RS_FilterDXF::addCircle(const DL_CircleData& data) { RS_DEBUG->print("RS_FilterDXF::addCircle"); //printf("LINE (%12.6f, %12.6f, %12.6f) (%12.6f, %12.6f, %12.6f)\n", // p1[0], p1[1], p1[2], // p2[0], p2[1], p2[2]); RS_Vector v(data.cx, data.cy); RS_CircleData d(v, data.radius); RS_Circle* entity = new RS_Circle(currentContainer, d); setEntityAttributes(entity, attributes); currentContainer->addEntity(entity);}/** * Implementation of the method which handles polyline entities. */void RS_FilterDXF::addPolyline(const DL_PolylineData& data) { RS_DEBUG->print("RS_FilterDXF::addPolyline"); //RS_DEBUG->print("RS_FilterDXF::addPolyline()"); RS_PolylineData d(RS_Vector(false), RS_Vector(false), data.flags&0x1); polyline = new RS_Polyline(currentContainer, d); setEntityAttributes(polyline, attributes); currentContainer->addEntity(polyline);}/** * Implementation of the method which handles polyline vertices. */void RS_FilterDXF::addVertex(const DL_VertexData& data) { RS_DEBUG->print("RS_FilterDXF::addVertex(): %f/%f bulge: %f", data.x, data.y, data.bulge); RS_Vector v(data.x, data.y); if (polyline!=NULL) { polyline->addVertex(v, data.bulge); }}/** * Implementation of the method which handles splines. */void RS_FilterDXF::addSpline(const DL_SplineData& data) { RS_DEBUG->print("RS_FilterDXF::addSpline: degree: %d", data.degree); if (data.degree>=1 && data.degree<=3) { RS_SplineData d(data.degree, ((data.flags&0x1)==0x1)); spline = new RS_Spline(currentContainer, d); setEntityAttributes(spline, attributes); currentContainer->addEntity(spline); } else { RS_DEBUG->print(RS_Debug::D_WARNING, "RS_FilterDXF::addSpline: Invalid degree for spline: %d. " "Accepted values are 1..3.", data.degree); }}/** * Implementation of the method which handles spline control points. */void RS_FilterDXF::addControlPoint(const DL_ControlPointData& data) { RS_DEBUG->print("RS_FilterDXF::addControlPoint: %f/%f", data.x, data.y); RS_Vector v(data.x, data.y); if (spline!=NULL) { spline->addControlPoint(v); spline->update(); }}/** * Implementation of the method which handles inserts. */void RS_FilterDXF::addInsert(const DL_InsertData& data) { RS_DEBUG->print("RS_FilterDXF::addInsert"); if (RS_String(data.name.c_str()).left(3)=="A$C") { return; } RS_Vector ip(data.ipx, data.ipy); RS_Vector sc(data.sx, data.sy); RS_Vector sp(data.colSp, data.rowSp); //cout << "Insert: " << name << " " << ip << " " << cols << "/" << rows << endl; RS_InsertData d(data.name.c_str(), ip, sc, data.angle/ARAD, data.cols, data.rows, sp, NULL, RS2::NoUpdate); RS_Insert* entity = new RS_Insert(currentContainer, d); setEntityAttributes(entity, attributes); RS_DEBUG->print(" id: %d", entity->getId()); //entity->update(); currentContainer->addEntity(entity);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -