270 lines
8.2 KiB
C++
270 lines
8.2 KiB
C++
|
/*
|
|||
|
* @file test_creationclass.cpp
|
|||
|
*/
|
|||
|
|
|||
|
/*****************************************************************************
|
|||
|
** $Id: test_creationclass.cpp 8865 2008-02-04 18:54:02Z andrew $
|
|||
|
**
|
|||
|
** This is part of the dxflib library
|
|||
|
** Copyright (C) 2001 Andrew Mustun
|
|||
|
**
|
|||
|
** This program is free software; you can redistribute it and/or modify
|
|||
|
** it under the terms of the GNU Library General Public License as
|
|||
|
** published by the Free Software Foundation.
|
|||
|
**
|
|||
|
** 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 Library General Public License for more details.
|
|||
|
**
|
|||
|
** You should have received a copy of the GNU Library General Public License
|
|||
|
** along with this program; if not, write to the Free Software
|
|||
|
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
******************************************************************************/
|
|||
|
|
|||
|
#include "test_creationclass.h"
|
|||
|
|
|||
|
#include <iostream>
|
|||
|
#include <stdio.h>
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Default constructor.
|
|||
|
*/
|
|||
|
Test_CreationClass::Test_CreationClass()
|
|||
|
{
|
|||
|
BlockObj newblock;
|
|||
|
newblock.drawflag = true;
|
|||
|
newblock.name = "entities";
|
|||
|
myblock.push_back(newblock);//先插入一个空块,以供后面处理
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles layers.
|
|||
|
*/
|
|||
|
void Test_CreationClass::addLayer(const DL_LayerData& data)
|
|||
|
{
|
|||
|
//printf("LAYER: %s flags: %d\n", data.name.c_str(), data.flags);
|
|||
|
//printAttributes();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles point entities.
|
|||
|
*/
|
|||
|
void Test_CreationClass::addPoint(const DL_PointData& data)
|
|||
|
{
|
|||
|
//printf("POINT (%6.3f, %6.3f, %6.3f)\n",
|
|||
|
// data.x, data.y, data.z);
|
|||
|
//printAttributes();
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles line entities.
|
|||
|
*/
|
|||
|
void Test_CreationClass::addLine(const DL_LineData& data)
|
|||
|
{
|
|||
|
DXFLine myline;
|
|||
|
myline.beginpoint = Point2D32f(data.x1, data.y1);
|
|||
|
myline.endpoint = Point2D32f(data.x2, data.y2);
|
|||
|
myblock[myblock.size() - 1].line.push_back(myline);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles arc entities.
|
|||
|
*/
|
|||
|
void Test_CreationClass::addArc(const DL_ArcData& data)
|
|||
|
{
|
|||
|
DXFArc myarc;
|
|||
|
myarc.centerpoint = Point2D32f(data.cx, data.cy);
|
|||
|
myarc.radius = data.radius;
|
|||
|
myarc.bangle = data.angle1;
|
|||
|
myarc.eangle = data.angle2;
|
|||
|
myblock[myblock.size() - 1].arc.push_back(myarc);
|
|||
|
/* printf("ARC (%6.3f, %6.3f, %6.3f) %6.3f, %6.3f, %6.3f\n",
|
|||
|
data.cx, data.cy, data.cz,
|
|||
|
data.radius, data.angle1, data.angle2);
|
|||
|
printAttributes();*/
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles circle entities.
|
|||
|
*/
|
|||
|
void Test_CreationClass::addCircle(const DL_CircleData& data)
|
|||
|
{
|
|||
|
DXFCircle mycircle;
|
|||
|
mycircle.centerpoint = Point2D32f(data.cx, data.cy);
|
|||
|
mycircle.radius = data.radius;
|
|||
|
myblock[myblock.size() - 1].circle.push_back(mycircle);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles polyline entities.
|
|||
|
* 多线实体起点标志位
|
|||
|
*/
|
|||
|
void Test_CreationClass::addPolyline(const DL_PolylineData& data)
|
|||
|
{
|
|||
|
DXFPolyLineEntities mypolylineentities;
|
|||
|
mypolylineentities.isclose = data.flags;//闭合标志位,1表示闭合,0表示非闭合
|
|||
|
myblock[myblock.size() - 1].polylineentities.push_back(mypolylineentities);
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* Sample implementation of the method which handles vertices.
|
|||
|
* 顶点对像,描绘多线实体
|
|||
|
*/
|
|||
|
void Test_CreationClass::addVertex(const DL_VertexData& data)
|
|||
|
{
|
|||
|
Point2D32f myvertex=Point2D32f(data.x, data.y);
|
|||
|
myblock[myblock.size() - 1].polylineentities[myblock[myblock.size() - 1].polylineentities.size() - 1].vertex.push_back(myvertex);
|
|||
|
}
|
|||
|
|
|||
|
void Test_CreationClass::add3dFace(const DL_3dFaceData& data)
|
|||
|
{
|
|||
|
printf("3DFACE\n");
|
|||
|
for (int i=0; i<4; i++) {
|
|||
|
printf(" corner %d: %6.3f %6.3f %6.3f\n",
|
|||
|
i, data.x[i], data.y[i], data.z[i]);
|
|||
|
}
|
|||
|
printAttributes();
|
|||
|
}
|
|||
|
void Test_CreationClass::addSpline(const DL_SplineData&data)
|
|||
|
{
|
|||
|
Spline mySplineEnt;
|
|||
|
mySplineEnt.degree = data.degree;
|
|||
|
mySplineEnt.flags = data.flags;
|
|||
|
mySplineEnt.nControl =data.nControl;
|
|||
|
mySplineEnt.nFit =data.nFit;
|
|||
|
mySplineEnt.nKnots =data.nKnots;
|
|||
|
mySplineEnt.tangentStartX =data.tangentStartX;
|
|||
|
mySplineEnt.tangentStartY =data.tangentStartY;
|
|||
|
mySplineEnt.tangentStartZ =data.tangentStartZ;
|
|||
|
mySplineEnt.tangentEndX =data.tangentEndX;
|
|||
|
mySplineEnt.tangentEndY =data.tangentEndY;
|
|||
|
mySplineEnt.tangentEndZ =data.tangentEndZ;
|
|||
|
myblock[myblock.size() - 1].splineLst.push_back(mySplineEnt);
|
|||
|
}
|
|||
|
void Test_CreationClass::addControlPoint(const DL_ControlPointData&data)
|
|||
|
{
|
|||
|
int splineSize = myblock[myblock.size() - 1].splineLst.size();
|
|||
|
Point3DW32f ctrPnt;
|
|||
|
ctrPnt.x = data.x;
|
|||
|
ctrPnt.y = data.y;
|
|||
|
ctrPnt.z = data.z;
|
|||
|
ctrPnt.w = data.w;
|
|||
|
myblock[myblock.size() - 1].splineLst[splineSize-1].ctrPntLst.push_back(ctrPnt);
|
|||
|
}
|
|||
|
void Test_CreationClass::addFitPoint(const DL_FitPointData&data)
|
|||
|
{
|
|||
|
int splineSize = myblock[myblock.size() - 1].splineLst.size();
|
|||
|
Point3D32f fitPnt;
|
|||
|
fitPnt.x = data.x;
|
|||
|
fitPnt.y = data.y;
|
|||
|
fitPnt.z = data.z;
|
|||
|
myblock[myblock.size() - 1].splineLst[splineSize-1].fitPntLst.push_back(fitPnt);
|
|||
|
}
|
|||
|
void Test_CreationClass::addKnot(const DL_KnotData&data)
|
|||
|
{
|
|||
|
int splineSize = myblock[myblock.size() - 1].splineLst.size();
|
|||
|
myblock[myblock.size() - 1].splineLst[splineSize-1].knotLst.push_back(data.k);
|
|||
|
}
|
|||
|
void Test_CreationClass::addText(const DL_TextData& data)
|
|||
|
{
|
|||
|
DXFText text;
|
|||
|
text.angle = data.angle;
|
|||
|
text.apx = data.apx;
|
|||
|
text.apy = data.apy;
|
|||
|
text.apz = data.apz;
|
|||
|
text.height = data.height;
|
|||
|
text.hJustification = data.hJustification;
|
|||
|
text.ipx = data.ipx;
|
|||
|
text.ipy = data.ipy;
|
|||
|
text.ipz = data.ipz;
|
|||
|
text.style = data.style;
|
|||
|
text.text = data.text;
|
|||
|
text.textGenerationFlags = data.textGenerationFlags;
|
|||
|
text.vJustification = data.vJustification;
|
|||
|
text.xScaleFactor = data.xScaleFactor;
|
|||
|
myblock[myblock.size() - 1].textLst.push_back(text);
|
|||
|
}
|
|||
|
void Test_CreationClass::addMText(const DL_MTextData& data)
|
|||
|
{
|
|||
|
DXFMText text;
|
|||
|
text.angle = data.angle;
|
|||
|
text.attachmentPoint = data.attachmentPoint;
|
|||
|
text.dirx = data.dirx;
|
|||
|
text.diry = data.diry;
|
|||
|
text.dirz = data.dirz;
|
|||
|
text.height = data.height;
|
|||
|
text.drawingDirection = data.drawingDirection;
|
|||
|
text.ipx = data.ipx;
|
|||
|
text.ipy = data.ipy;
|
|||
|
text.ipz = data.ipz;
|
|||
|
text.style = data.style;
|
|||
|
text.text = data.text;
|
|||
|
text.lineSpacingFactor = data.lineSpacingFactor;
|
|||
|
text.lineSpacingStyle = data.lineSpacingStyle;
|
|||
|
text.width = data.width;
|
|||
|
myblock[myblock.size() - 1].mtextLst.push_back(text);
|
|||
|
}
|
|||
|
void Test_CreationClass::addInsert(const DL_InsertData & data)
|
|||
|
{
|
|||
|
vector<BlockObj> ::iterator itor;//容器迭代器
|
|||
|
itor = myblock.begin();
|
|||
|
while (itor != myblock.end())
|
|||
|
{
|
|||
|
if (!itor->name.compare(data.name))//插入块名称比较,相同则表示插入该块
|
|||
|
{
|
|||
|
itor->ipx = data.ipx;
|
|||
|
itor->ipy = data.ipy;
|
|||
|
itor->ipz = data.ipz;
|
|||
|
itor->sx = data.sx;
|
|||
|
itor->sy = data.sy;
|
|||
|
itor->sz = data.sz;
|
|||
|
itor->drawflag = true;//只有被插入的对象才进行绘制
|
|||
|
break;
|
|||
|
}
|
|||
|
itor++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Test_CreationClass::addBlock(const DL_BlockData & data)
|
|||
|
{
|
|||
|
myblock[myblock.size() - 1].name=data.name;
|
|||
|
myblock[myblock.size() - 1].drawflag = false;
|
|||
|
myblock[myblock.size() - 1].ipx = data.bpx;
|
|||
|
myblock[myblock.size() - 1].ipy = data.bpy;
|
|||
|
myblock[myblock.size() - 1].ipz = data.bpz;
|
|||
|
}
|
|||
|
|
|||
|
void Test_CreationClass::endBlock()//因为dxflib没给出ENTITIES的标志位,为方便,将entitues也当成一个需要绘制的块进行处理,与正在的block的区别只在于块在插入的时候才绘制,而entities则一定会绘制
|
|||
|
{
|
|||
|
BlockObj newblock;
|
|||
|
newblock.drawflag = true;
|
|||
|
newblock.name = "entities";
|
|||
|
myblock.push_back(newblock);
|
|||
|
}
|
|||
|
|
|||
|
void Test_CreationClass::printAttributes()
|
|||
|
{
|
|||
|
printf(" Attributes: Layer: %s, ", attributes.getLayer().c_str());
|
|||
|
printf(" Color: ");
|
|||
|
if (attributes.getColor()==256) {
|
|||
|
printf("BYLAYER");
|
|||
|
} else if (attributes.getColor()==0) {
|
|||
|
printf("BYBLOCK");
|
|||
|
} else {
|
|||
|
printf("%d", attributes.getColor());
|
|||
|
}
|
|||
|
printf(" Width: ");
|
|||
|
if (attributes.getWidth()==-1) {
|
|||
|
printf("BYLAYER");
|
|||
|
} else if (attributes.getWidth()==-2) {
|
|||
|
printf("BYBLOCK");
|
|||
|
} else if (attributes.getWidth()==-3) {
|
|||
|
printf("DEFAULT");
|
|||
|
} else {
|
|||
|
printf("%d", attributes.getWidth());
|
|||
|
}
|
|||
|
printf(" Type: %s\n", attributes.getLinetype().c_str());
|
|||
|
}
|