Exemplo n.º 1
0
void tDxfExport2::writeLayers(tModel *m)
{

    tList<tElement*> layers = m->elements(iLayer::theType(), true);

    dw->tableLayers(layers.count()+1);

    dxf.writeLayer(*dw,
        DL_LayerData("0", 0),
        DL_Attributes(
            std::string(""),      // leave empty
            DL_Codes::black,      // default color
            100,                  // default width        writeTables(m);
            "CONTINUOUS"));       // default line style

    DL_Codes::color colors[] = { DL_Codes::black, DL_Codes::green, DL_Codes::red, DL_Codes::brown, DL_Codes::yellow, DL_Codes::cyan, DL_Codes::magenta, DL_Codes::gray,
                                 DL_Codes::blue, DL_Codes::l_blue, DL_Codes::l_green, DL_Codes::l_cyan, DL_Codes::l_red, DL_Codes::l_magenta, DL_Codes::l_gray, DL_Codes::white};

    for (int i=0;i<layers.count(); i++) {
        dxf.writeLayer(*dw,
                       DL_LayerData(layers.at(i)->intrface()->name().toStdString().data(), 0),
                       DL_Attributes(
                           std::string(""),
                           colors[i%16],
                           100,
                           "CONTINUOUS"));
    }

    dw->tableEnd();
}
Exemplo n.º 2
0
void DL_Jww::CreateSunpou(DL_CreationInterface* creationInterface, CDataSunpou& DSunpou)
{
	string lName = HEX[DSunpou.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSunpou.m_nGLayer] + "-" +
													HEX[DSunpou.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSunpou.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));
	int width;
	if(DSunpou.m_nPenWidth > 26)
		width = 0;
	else
		width = DSunpou.m_nPenWidth;
	int color = colTable[DSunpou.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DSunpou.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DSunpou.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DSunpou.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	CreateSen(creationInterface, DSunpou.m_Sen);	//線分メンバ
	CreateMoji(creationInterface, DSunpou.m_Moji);	//文字メンバ
#ifdef FINISHED
//	if(DSunpou.nOldVersionSave >=420){
////	jwWORD m_bSxfMode;	//SXFのモード
//		CreateSen(graphic, DSunpou.m_SenHo1);	//補助線1
//		CreateSen(graphic, DSunpou.m_SenHo2);	//補助線2
//		CreateTen(graphic, DSunpou.m_Ten1);	//矢印(点)1
//		CreateTen(graphic, DSunpou.m_Ten2);	//矢印(点)2
//		CreateTen(graphic, DSunpou.m_TenHo1);	//基準点1
//		CreateTen(graphic, DSunpou.m_TenHo2);	//基準点2
//	}
#endif
}
Exemplo n.º 3
0
void DL_Jww::CreateTen(DL_CreationInterface* creationInterface, CDataTen& DTen)
{
	string lName = HEX[DTen.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DTen.m_nGLayer] + "-" +
													HEX[DTen.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DTen.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));
	int width;
	if(DTen.m_nPenWidth > 26)
		width = 0;
	else
		width = DTen.m_nPenWidth;
	int color = colTable[DTen.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DTen.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DTen.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DTen.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	DL_PointData d(DTen.m_start.x, DTen.m_start.y, 0.0);
	creationInterface->addPoint(d);
#ifdef FINISHED
	RS_PointData data2(RS_Vector(0.0, 0.0));
	RS_Point*	point;

	data2.pos = RS_Vector(DTen.m_start.x, DTen.m_start.y);
	point = new RS_Point(graphic, data2);
	RS2::LineType ltype = lTable[DTen.m_nPenStyle];
	RS_Color col = colTable[DTen.m_nPenColor];
	RS2::LineWidth lw = lWidth[DTen.m_nPenWidth > 26 ? 0 :DTen.m_nPenWidth];//RS2::Width12
	point->setPen(RS_Pen(col, RS2::Width23, ltype));
	//画層設定
	RS_String lName = HEX[DTen.m_nGLayer > 0x0f ? 0 : DTen.m_nGLayer] + "-" + 
		HEX[DTen.m_nLayer > 0x0f ? 0: DTen.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	point->setLayer(lName);
	// add the line to the graphic
	graphic->addEntity(point);
#ifdef DEBUG
std::cout << *point;
#endif
#endif
}
Exemplo n.º 4
0
bool DxfProfilesExporter::SaveVerticalProfiles(	const QSharedPointer<DistanceMapGenerationTool::Map>& map,
												ccPolyline* profile,
												QString filename,
												unsigned angularStepCount,
												double heightStep,
												const Parameters& params,
												ccMainAppInterface* app/*=0*/)
{
#ifdef CC_DXF_SUPPORT
	assert(c_pageMargin_mm < c_profileMargin_mm);
	assert(2.0*c_profileMargin_mm < std::min(c_pageWidth_mm,c_pageHeight_mm));

	if (!map || !profile || angularStepCount == 0 || heightStep <= 0)
	{
		//invalid parameters
		return false;
	}

	//Theoretical profile bounding box
	PointCoordinateType profileBBMin[3],profileBBMax[3];
	profile->getAssociatedCloud()->getBoundingBox(profileBBMin,profileBBMax);
	//Mix with the map's boundaries along 'Y'
	double yMin = std::max(map->yMin,static_cast<double>(profileBBMin[1]));
	double yMax = std::min(map->yMin + static_cast<double>(map->ySteps) * map->yStep, static_cast<double>(profileBBMax[1]));
	const double ySpan = yMax - yMin;
	//For the 'X' dimension, it's easier to stick with the th. profile
	const double xMin = profileBBMin[0];
//	const double xMax = profileBBMax[0];
	const double xSpan = profileBBMax[0] - profileBBMin[0];

	if (xSpan == 0.0 || ySpan == 0.0)
	{
		if (app)
			app->dispToConsole(QString("Internal error: null profile?!"),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return false;
	}

	DL_Dxf dxf;
	DL_WriterA* dw = dxf.out(qPrintable(filename), DL_VERSION_R12);
	if (!dw)
	{
		if (app)
			app->dispToConsole(QString("Failed to open '%1' file for writing!").arg(filename),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return false;
	}

	//write header
	dxf.writeHeader(*dw);

	//add dimensions
	dw->dxfString(9, "$INSBASE");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$EXTMIN");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$EXTMAX");
	dw->dxfReal(10,c_pageWidth_mm);
	dw->dxfReal(20,c_pageHeight_mm);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$LIMMIN");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfString(9, "$LIMMAX");
	dw->dxfReal(10,c_pageWidth_mm);
	dw->dxfReal(20,c_pageHeight_mm);

	//close header
	dw->sectionEnd();

	//Opening the Tables Section
	dw->sectionTables();
	//Writing the Viewports
	dxf.writeVPort(*dw);

	//Writing the Linetypes (all by default)
	{
		dw->tableLineTypes(25);
		dxf.writeLineType(*dw, DL_LineTypeData("BYBLOCK", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BYLAYER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CONTINUOUS", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO02W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO03W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO04W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO05W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOTX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHEDX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDEX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOTX2", 0));
		dw->tableEnd();
	}

	//Writing the Layers
	dw->tableLayers(angularStepCount+3);
	QStringList profileNames;
	{
		//default layer
		dxf.writeLayer(*dw, 
			DL_LayerData("0", 0), 
			DL_Attributes(
			std::string(""),      // leave empty
			DL_Codes::black,      // default color
			100,                  // default width (in 1/100 mm)
			"CONTINUOUS"));       // default line style

		//theoretical profile layer
		dxf.writeLayer(*dw, 
			DL_LayerData(PROFILE_LAYER, 0), 
			DL_Attributes(
			std::string(""),
			DL_Codes::red,
			s_lineWidth,
			"CONTINUOUS"));

		//legend layer
		dxf.writeLayer(*dw, 
			DL_LayerData(LEGEND_LAYER, 0), 
			DL_Attributes(
			std::string(""),
			DL_Codes::black,
			s_lineWidth,
			"CONTINUOUS"));

		//vert. profile layers
		for (unsigned i=0; i<angularStepCount; ++i)
		{
			//default layer name
			QString layerName = QString(VERT_PROFILE_LAYER).arg(i+1,3,10,QChar('0'));
			//but we use the profile title if we have one!
			//DGM: nope, as it may be longer than 31 characters (R14 limit)
			//if (params.profileTitles.size() >= static_cast<int>(angularStepCount))
			//{
			//	layerName = params.profileTitles[i];
			//	layerName.replace(QChar(' '),QChar('_'));
			//}

			profileNames << layerName;
			dxf.writeLayer(*dw, 
				DL_LayerData(layerName.toStdString(), 0), 
				DL_Attributes(
				std::string(""),
				i == 0 ? DL_Codes::green : -DL_Codes::green, //invisible if negative!
				s_lineWidth,
				"CONTINUOUS"));
		}
	}
	dw->tableEnd();

	//Writing Various Other Tables
	//dxf.writeStyle(*dw); //DXFLIB V2.5
	dxf.writeStyle(*dw,DL_StyleData("Standard",0,0.0,0.75,0.0,0,2.5,"txt","")); //DXFLIB V3.3
	dxf.writeView(*dw);
	dxf.writeUcs(*dw);

	dw->tableAppid(1);
	dw->tableAppidEntry(0x12);
	dw->dxfString(2, "ACAD");
	dw->dxfInt(70, 0);
	dw->tableEnd();

	//Writing Dimension Styles
	dxf.writeDimStyle(	*dw, 
						/*arrowSize*/1, 
						/*extensionLineExtension*/1,
						/*extensionLineOffset*/1,
						/*dimensionGap*/1,
						/*dimensionTextSize*/1);
	
	//Writing Block Records
	dxf.writeBlockRecord(*dw);
	//dxf.writeBlockRecord(*dw, "myblock1");
	//dxf.writeBlockRecord(*dw, "myblock2");
	dw->tableEnd();

	//Ending the Tables Section
	dw->sectionEnd();

	//Writing the Blocks Section
	{
		dw->sectionBlocks();

		dxf.writeBlock(*dw,  DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Model_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space0");

		dw->sectionEnd();
	}

	//Writing the Entities Section
	{
		dw->sectionEntities();

		//we make the profile fit in the middle of the page (21.0 x 29.7 cm)
		double scale = std::min((c_pageWidth_mm - 2.0 * c_profileMargin_mm)/xSpan,
								(c_pageHeight_mm - 2.0 * c_profileMargin_mm)/ySpan);

		//min corner of profile area
		const double x0 = (c_pageWidth_mm - xSpan*scale) / 2.0;
		const double y0 = (c_pageHeight_mm - ySpan*scale) / 2.0;

		//write theoretical profile (polyline)
		{
			unsigned vertexCount = profile->size();
			dxf.writePolyline(	*dw,
								DL_PolylineData(static_cast<int>(vertexCount),0,0,0),
								DL_Attributes(PROFILE_LAYER, DL_Codes::bylayer, -1, "BYLAYER"));

			for (unsigned i=0; i<vertexCount; ++i)
			{
				const CCVector3* P = profile->getPoint(i);
				dxf.writeVertex(*dw, DL_VertexData(x0+(P->x-xMin)*scale,y0+(P->y-yMin)*scale,0.0));
			}

			dxf.writePolylineEnd(*dw);
		}

		//write legend
		{
			DL_Attributes DefaultLegendMaterial(LEGEND_LAYER, DL_Codes::bylayer, -1, "BYLAYER");

			//write page contour
			{
				dxf.writePolyline(	*dw,
									DL_PolylineData(4,0,0,1),
									DefaultLegendMaterial);

				dxf.writeVertex(*dw, DL_VertexData(	c_pageMargin_mm, c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageMargin_mm, c_pageHeight_mm-c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageWidth_mm-c_pageMargin_mm, c_pageHeight_mm-c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageWidth_mm-c_pageMargin_mm, c_pageMargin_mm, 0.0));

				dxf.writePolylineEnd(*dw);
			}

			double xLegend = c_pageMargin_mm + 2.0*c_textHeight_mm;
			double yLegend = c_pageMargin_mm + 2.0*c_textHeight_mm;
			const double legendWidth_mm = 20.0;
			
			//deviation magnification factor
			QString magnifyStr = QString::number(params.devMagnifyCoef);
			dxf.writeText(	*dw,
				DL_TextData(xLegend,yLegend,0.0,xLegend,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,(QString("Deviation magnification factor: ")+magnifyStr).toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//units
			QString unitsStr("mm");
			dxf.writeText(	*dw,
				DL_TextData(xLegend,yLegend,0.0,xLegend,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,(QString("Deviation units: ")+unitsStr).toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//true profile line (red)
			dxf.writeLine(	*dw,
							DL_LineData(xLegend,yLegend,0,xLegend+legendWidth_mm,yLegend,0.0),
							DL_Attributes(LEGEND_LAYER, DL_Codes::green, -1, "BYLAYER"));

			dxf.writeText(	*dw,
				DL_TextData(xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,params.legendRealProfileTitle.toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//theoretical profile line (red)
			dxf.writeLine(	*dw,
							DL_LineData(xLegend,yLegend,0,xLegend+legendWidth_mm,yLegend,0.0),
							DL_Attributes(LEGEND_LAYER, DL_Codes::red, -1, "BYLAYER"));

			dxf.writeText(	*dw,
				DL_TextData(xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,params.legendTheoProfileTitle.toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);
		}

		//write vertical profiles
		for (unsigned angleStep=0; angleStep<angularStepCount; ++angleStep)
		{			
			std::vector<VertStepData> polySteps;
			try
			{
				polySteps.reserve(map->ySteps);
			}
			catch(std::bad_alloc)
			{
				//not enough memory
				dw->dxfEOF();
				dw->close();
				delete dw;
				return false;
			}

			unsigned iMap = static_cast<unsigned>(static_cast<double>(angleStep * map->xSteps) / static_cast<double>(angularStepCount));
			for (unsigned jMap=0; jMap < map->ySteps; ++jMap)
			{
				const DistanceMapGenerationTool::MapCell& cell = map->at(iMap + jMap * map->xSteps);
				
				VertStepData step;
				step.height = map->yMin + static_cast<double>(jMap) * map->yStep;

				if (step.height >= yMin && step.height <= yMax)
				{
					//find corresponding radius
					bool found = false;
					for (unsigned i=1; i<profile->size(); ++i)
					{
						const CCVector3* A = profile->getPoint(i-1);
						const CCVector3* B = profile->getPoint(i);

						double alpha = static_cast<double>((step.height - A->y)/(B->y - A->y));
						if (alpha >= 0.0 && alpha <= 1.0)
						{
							//we deduce the right radius by linear interpolation
							step.radius_th = A->x + alpha * (B->x - A->x);
							found = true;
							break;
						}
					}

					if (found)
					{
						step.deviation = cell.count ? cell.value : 0.0;
						polySteps.push_back(step);
					}
				}
			}	

			const DL_Attributes DefaultMaterial(profileNames[angleStep].toStdString(), DL_Codes::bylayer, -1, "BYLAYER");
			const DL_Attributes GrayMaterial(profileNames[angleStep].toStdString(), DL_Codes::l_gray, -1, "");

			//write layer title
			if (static_cast<int>(angleStep) < params.profileTitles.size())
			{
				const QString& title = params.profileTitles[angleStep];

				CCVector3d Ptop(c_pageWidth_mm / 2.0, y0 + ySpan * scale + c_profileMargin_mm / 2.0, 0.0);

				dxf.writeText(	*dw,
					DL_TextData(Ptop.x,Ptop.y,Ptop.z,Ptop.x,Ptop.y,Ptop.z,c_textHeight_mm,1.0,0,1,0,title.toStdString(),"STANDARD",0.0),
					GrayMaterial);

			}
			
			//write corresponding polyline
			{
				dxf.writePolyline(	*dw,
									DL_PolylineData(static_cast<int>(polySteps.size()),0,0,0),
									DefaultMaterial);

				for (size_t i=0; i<polySteps.size(); ++i)
				{
					const VertStepData& step = polySteps[i];
					dxf.writeVertex(*dw, DL_VertexData(	x0 + (step.radius_th + step.deviation * params.devMagnifyCoef - xMin) * scale,
														y0 + (step.height - yMin) * scale, 0.0));
				}

				dxf.writePolylineEnd(*dw);
			}

			//write corresponding 'deviation bars' and labels
			CCVector3d pageShift(x0 - xMin * scale, y0 - yMin * scale, 0.0);
			{
				size_t lastStep = 0;
				for (size_t i=0; i<polySteps.size(); ++i)
				{
					const VertStepData& step = polySteps[i];
					bool displayIt = (i == 0 || i+1 == polySteps.size());
					if (!displayIt)
					{
						double dh = polySteps[i].height - polySteps[lastStep].height;
						double next_dh = polySteps[i+1].height - polySteps[lastStep].height;
						if (dh >= heightStep || (next_dh > heightStep && fabs(dh - heightStep) < fabs(next_dh - heightStep)))
						{
							displayIt = true;
						}
					}

					if (displayIt)
					{
						CCVector3d Pheight(step.radius_th,step.height,0.0);
						CCVector3d Pdev(step.radius_th + step.deviation * params.devMagnifyCoef,step.height,0.0);

						//page scaling
						Pheight = pageShift + Pheight * scale;
						Pdev = pageShift + Pdev * scale;

						//deviation bar
						dxf.writeLine(*dw,
										DL_LineData(Pheight.x,Pheight.y,Pheight.z,Pdev.x,Pdev.y,Pdev.z),
										GrayMaterial);

						//labels

						//Horizontal justification: 0 = Left , 1 = Center, 2 = Right
						int hJustification = 0;
						//Vertical justification: 0 = Baseline, 1 = Bottom, 2 = Middle, 3 = Top
						int vJustification = 2;

						if (step.deviation < 0.0)
						{
							//deviation label on the left
							Pdev.x -= 2.0*c_textMargin_mm;
							//opposite for the height label
							Pheight.x += c_textMargin_mm;
							hJustification = 2; //Right
						}
						else
						{
							//deviation label on the right
							Pdev.x += 2.0*c_textMargin_mm;
							//opposite for the height label
							Pheight.x -= c_textMargin_mm;
							hJustification = 0; //Left
						}

						QString devText = QString::number(polySteps[i].deviation * params.devLabelMultCoef,'f',params.precision);
						dxf.writeText(	*dw,
							DL_TextData(Pdev.x,Pdev.y,Pdev.z,Pdev.x,Pdev.y,Pdev.z,c_textHeight_mm,1.0,0,hJustification,vJustification,devText.toStdString(),"STANDARD",0.0),
							DefaultMaterial);

						QString heightText = QString::number(polySteps[i].height,'f',params.precision);
						dxf.writeText(	*dw,
							DL_TextData(Pheight.x,Pheight.y,Pheight.z,Pheight.x,Pheight.y,Pheight.z,c_textHeight_mm,1.0,0,2-hJustification,vJustification,heightText.toStdString(),"STANDARD",0.0),
							GrayMaterial);
						
						lastStep = i;
					}
				}
			}
		}

		dw->sectionEnd();

	}

	//Writing the Objects Section
	dxf.writeObjects(*dw);
	dxf.writeObjectsEnd(*dw);

	//Ending and Closing the File
	dw->dxfEOF();
	dw->close();
	delete dw;
	dw = 0;

	return true;

#else
	return false;
#endif
}
Exemplo n.º 5
0
bool DxfProfilesExporter::SaveHorizontalProfiles(	const QSharedPointer<DistanceMapGenerationTool::Map>& map,
													ccPolyline* profile,
													QString filename,
													unsigned heightStepCount,
													double angularStep_rad,
													double radToUnitConvFactor,
													QString angleUnit,
													const Parameters& params,
													ccMainAppInterface* app/*= 0*/)
{
#ifdef CC_DXF_SUPPORT
	assert(c_pageMargin_mm < c_profileMargin_mm);
	assert(2.0*c_profileMargin_mm < std::min(c_pageWidth_mm,c_pageHeight_mm));

	if (!map || !profile || heightStepCount == 0 || angularStep_rad <= 0)
	{
		//invalid parameters
		return false;
	}

	//Theoretical profile bounding box
	PointCoordinateType profileBBMin[3],profileBBMax[3];
	profile->getAssociatedCloud()->getBoundingBox(profileBBMin,profileBBMax);
	//Mix with the map's boundaries along 'Y'
	double yMin = std::max(	map->yMin + 0.5 * map->xStep, //central height of first row
							static_cast<double>(profileBBMin[1]));
	double yMax = std::min(	map->yMin + (static_cast<double>(map->ySteps)-0.5) * map->yStep, //central height of last row
							static_cast<double>(profileBBMax[1]));
	const double ySpan = yMax - yMin;

	//For the 'X' dimension, it's easier to stick with the th. profile
//	const double xMin = profileBBMin[0];
	const double xMax = profileBBMax[0];
	const double xSpan = profileBBMax[0] - profileBBMin[0];
	//shortcut for clarity
	const double& maxRadius = xMax;

	if (xSpan == 0.0 || ySpan == 0.0)
	{
		if (app)
			app->dispToConsole(QString("Internal error: null profile?!"),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return false;
	}

	DL_Dxf dxf;
	DL_WriterA* dw = dxf.out(qPrintable(filename), DL_VERSION_R12);
	if (!dw)
	{
		if (app)
			app->dispToConsole(QString("Failed to open '%1' file for writing!").arg(filename),ccMainAppInterface::ERR_CONSOLE_MESSAGE);
		return false;
	}

	//write header
	dxf.writeHeader(*dw);

	//add dimensions
	dw->dxfString(9, "$INSBASE");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$EXTMIN");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$EXTMAX");
	dw->dxfReal(10,c_pageWidth_mm);
	dw->dxfReal(20,c_pageHeight_mm);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$LIMMIN");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfString(9, "$LIMMAX");
	dw->dxfReal(10,c_pageWidth_mm);
	dw->dxfReal(20,c_pageHeight_mm);

	//close header
	dw->sectionEnd();

	//Opening the Tables Section
	dw->sectionTables();
	//Writing the Viewports
	dxf.writeVPort(*dw);

	//Writing the Linetypes (all by default)
	{
		dw->tableLineTypes(25);
		dxf.writeLineType(*dw, DL_LineTypeData("BYBLOCK", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BYLAYER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CONTINUOUS", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO02W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO03W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO04W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO05W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOTX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHEDX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDEX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOTX2", 0));
		dw->tableEnd();
	}

	//Writing the Layers
	dw->tableLayers(heightStepCount+2);
	QStringList profileNames;
	{
		//default layer
		dxf.writeLayer(*dw, 
			DL_LayerData("0", 0), 
			DL_Attributes(
			std::string(""),      // leave empty
			DL_Codes::black,      // default color
			100,                  // default width (in 1/100 mm)
			"CONTINUOUS"));       // default line style

		//legend layer
		dxf.writeLayer(*dw, 
			DL_LayerData(LEGEND_LAYER, 0), 
			DL_Attributes(
			std::string(""),
			DL_Codes::black,
			s_lineWidth,
			"CONTINUOUS"));

		//horiz. profile layers
		for (unsigned i=0; i<heightStepCount; ++i)
		{
			//default profile name
			QString layerName = QString(HORIZ_PROFILE_LAYER).arg(i+1,3,10,QChar('0'));
			//but we use the profile title if we have one!
			//DGM: nope, as it may be longer than 31 characters (R14 limit)
			//if (params.profileTitles.size() == 1)
			//{
			//	//profile height
			//	double height = yMin + static_cast<double>(i) / static_cast<double>(heightStepCount-1) * ySpan;
			//	layerName = QString(params.profileTitles[0]).arg(height,0,'f',params.precision);
			//	layerName.replace(QChar(' '),QChar('_'));
			//}

			profileNames << layerName;
			dxf.writeLayer(*dw, 
				DL_LayerData(layerName.toStdString(), 0), 
				DL_Attributes(
				std::string(""),
				i == 0 ? DL_Codes::green : -DL_Codes::green, //invisible if negative!
				s_lineWidth,
				"CONTINUOUS"));
		}
	}
	dw->tableEnd();

	//Writing Various Other Tables
	//dxf.writeStyle(*dw); //DXFLIB V2.5
	dxf.writeStyle(*dw,DL_StyleData("Standard",0,0.0,0.75,0.0,0,2.5,"txt","")); //DXFLIB V3.3
	dxf.writeView(*dw);
	dxf.writeUcs(*dw);

	dw->tableAppid(1);
	dw->tableAppidEntry(0x12);
	dw->dxfString(2, "ACAD");
	dw->dxfInt(70, 0);
	dw->tableEnd();

	//Writing Dimension Styles
	dxf.writeDimStyle(	*dw, 
						/*arrowSize*/1, 
						/*extensionLineExtension*/1,
						/*extensionLineOffset*/1,
						/*dimensionGap*/1,
						/*dimensionTextSize*/1);
	
	//Writing Block Records
	dxf.writeBlockRecord(*dw);
	dw->tableEnd();

	//Ending the Tables Section
	dw->sectionEnd();

	//Writing the Blocks Section
	{
		dw->sectionBlocks();

		dxf.writeBlock(*dw,  DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Model_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space0");

		dw->sectionEnd();
	}

	//Writing the Entities Section
	{
		dw->sectionEntities();

		//we make the profile fit in the middle of the page (21.0 x 29.7 cm)
		double scale = std::min((c_pageWidth_mm - 2.0 * c_profileMargin_mm)/(2.0*maxRadius),
								(c_pageHeight_mm - 2.0 * c_profileMargin_mm)/(2.0*maxRadius));

		//min corner of profile area
//		const double x0 = (c_pageWidth_mm - 2.0*maxRadius*scale) / 2.0;
		const double y0 = (c_pageHeight_mm - 2.0*maxRadius*scale) / 2.0;
		//center of profile area
		const double xc = c_pageWidth_mm / 2.0;
		const double yc = c_pageHeight_mm / 2.0;

		//write legend
		{
			DL_Attributes DefaultLegendMaterial(LEGEND_LAYER, DL_Codes::bylayer, -1, "BYLAYER");

			//write page contour
			{
				dxf.writePolyline(	*dw,
									DL_PolylineData(4,0,0,1),
									DefaultLegendMaterial);

				dxf.writeVertex(*dw, DL_VertexData(	c_pageMargin_mm, c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageMargin_mm, c_pageHeight_mm-c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageWidth_mm-c_pageMargin_mm, c_pageHeight_mm-c_pageMargin_mm, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	c_pageWidth_mm-c_pageMargin_mm, c_pageMargin_mm, 0.0));

				dxf.writePolylineEnd(*dw);
			}

			double xLegend = c_pageMargin_mm + 2.0*c_textHeight_mm;
			double yLegend = c_pageMargin_mm + 2.0*c_textHeight_mm;
			const double legendWidth_mm = 20.0;

			//Y axis
			double axisTip = maxRadius*scale + 5.0;
			dxf.writeLine(	*dw,
							DL_LineData(xc, yc, 0.0, xc, yc-axisTip, 0.0),
							DefaultLegendMaterial);

			//Y axis tip as triangle
			{
				double axisTipSize = 3.0;

				dxf.writePolyline(	*dw,
									DL_PolylineData(3,0,0,1), //closed polyline!
									DefaultLegendMaterial);
				dxf.writeVertex(*dw, DL_VertexData(	xc, yc-(axisTip+axisTipSize), 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	xc-axisTipSize/2.0, yc-axisTip, 0.0));
				dxf.writeVertex(*dw, DL_VertexData(	xc+axisTipSize/2.0, yc-axisTip, 0.0));
				dxf.writePolylineEnd(*dw);

				dxf.writeText(	*dw,
								DL_TextData(xc,yc-(axisTip+2.0*axisTipSize),0.0,xc,yc-(axisTip+2.0*axisTipSize),0.0,c_textHeight_mm,1.0,0,1,3,"Y","STANDARD",0.0),
								DefaultLegendMaterial);
			}
			
			//deviation magnification factor
			QString magnifyStr = QString::number(params.devMagnifyCoef);
			dxf.writeText(	*dw,
				DL_TextData(xLegend,yLegend,0.0,xLegend,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,(QString("Deviation magnification factor: ")+magnifyStr).toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//units
			QString unitsStr("mm");
			dxf.writeText(	*dw,
				DL_TextData(xLegend,yLegend,0.0,xLegend,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,(QString("Deviation units: ")+unitsStr).toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//true profile line (red)
			dxf.writeLine(	*dw,
							DL_LineData(xLegend,yLegend,0,xLegend+legendWidth_mm,yLegend,0.0),
							DL_Attributes(LEGEND_LAYER, DL_Codes::green, -1, "BYLAYER"));

			dxf.writeText(	*dw,
				DL_TextData(xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,params.legendRealProfileTitle.toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);

			//next line
			yLegend += c_textHeight_mm*2.0;

			//theoretical profile line (red)
			dxf.writeLine(	*dw,
							DL_LineData(xLegend,yLegend,0,xLegend+legendWidth_mm,yLegend,0.0),
							DL_Attributes(LEGEND_LAYER, DL_Codes::red, -1, "BYLAYER"));

			dxf.writeText(	*dw,
				DL_TextData(xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,xLegend+legendWidth_mm+c_textMargin_mm,yLegend,0.0,c_textHeight_mm,1.0,0,0,0,params.legendTheoProfileTitle.toStdString(),"STANDARD",0.0),
				DefaultLegendMaterial);
		}

		//profile values (fixed size: one per angular step of the input grid)
		std::vector<HorizStepData> polySteps;
		try
		{
			polySteps.resize(map->xSteps);
		}
		catch(std::bad_alloc)
		{
			//not engouh memory
			dw->dxfEOF();
			dw->close();
			delete dw;
			return false;
		}

		//write horizontal profiles
		for (unsigned heightStep=0; heightStep<heightStepCount; ++heightStep)
		{			
			//profile height
			double height = yMin + static_cast<double>(heightStep) / static_cast<double>(heightStepCount-1) * ySpan;

			//corresponding index in map
			if (height < map->yMin || height >= map->yMin + static_cast<double>(map->ySteps) * map->yStep)
			{
				assert(false); //we have computed yMin and yMax so that those values are totally included inside the map's boundaries...
				continue;
			}
			unsigned jMap = static_cast<unsigned>((height-map->yMin)/map->yStep);
			assert(jMap < map->ySteps);

			//find corresponding radius
			double currentRadius = 0.0;
			{
				bool found = false;
				for (unsigned i=1; i<profile->size(); ++i)
				{
					const CCVector3* A = profile->getPoint(i-1);
					const CCVector3* B = profile->getPoint(i);

					double alpha = static_cast<double>((height - A->y)/(B->y - A->y));
					if (alpha >= 0.0 && alpha <= 1.0)
					{
						//we deduce the right radius by linear interpolation
						currentRadius = A->x + alpha * (B->x - A->x);
						found = true;
						break;
					}
				}

				if (!found)
				{
					assert(false); //we have computed yMin and yMax so that 'height' is totally included inside the profile's boundaries...
					continue;
				}
			}

			const QString& currentLayer = profileNames[heightStep];
			const DL_Attributes DefaultMaterial(currentLayer.toStdString(), DL_Codes::bylayer, -1, "BYLAYER");
			const DL_Attributes GrayMaterial(currentLayer.toStdString(), DL_Codes::l_gray, -1, "");

			//write layer title
			if (params.profileTitles.size() == 1)
			{
				QString title = QString(params.profileTitles[0]).arg(height,0,'f',params.precision);

				CCVector3d Ptop(xc, y0 + 2.0 * maxRadius * scale + c_profileMargin_mm / 2.0, 0.0);

				dxf.writeText(	*dw,
					DL_TextData(Ptop.x,Ptop.y,Ptop.z,Ptop.x,Ptop.y,Ptop.z,c_textHeight_mm,1.0,0,1,0,title.toStdString(),"STANDARD",0.0),
					GrayMaterial);
			}

			//write theoretical profile (polyline = circle)
			{
				dxf.writeCircle(*dw,
									DL_CircleData(xc, yc, 0.0, currentRadius*scale),
									DL_Attributes(currentLayer.toStdString(), DL_Codes::red, -1, "BYLAYER"));
			}

			assert(polySteps.size() == map->xSteps);
			{
				const DistanceMapGenerationTool::MapCell* cell = &map->at(jMap * map->xSteps);
				for (unsigned iMap=0; iMap<map->xSteps; ++iMap, ++cell)
				{
					HorizStepData step;
					step.angle_rad = 2.0*M_PI * static_cast<double>(iMap)/static_cast<double>(map->xSteps);
					step.deviation = cell->count ? cell->value : 0.0;
					polySteps[iMap] = step;
				}
			}

			//profile "direction"
			double cwSign = map->counterclockwise ? -1.0 : 1.0;

			CCVector3d pageShift(xc,yc,0.0);

			//write profile polyline
			{
				dxf.writePolyline(	*dw,
									DL_PolylineData(static_cast<int>(polySteps.size()),0,0,1), //closed shape!
									DefaultMaterial);

				for (size_t i=0; i<polySteps.size(); ++i)
				{
					const HorizStepData& step = polySteps[i];
					double radius = currentRadius + step.deviation * params.devMagnifyCoef;
					dxf.writeVertex(*dw, DL_VertexData(	pageShift.x - (cwSign * radius * sin(step.angle_rad)) * scale,
														pageShift.y - (radius * cos(step.angle_rad)) * scale,
														0.0));
				}

				dxf.writePolylineEnd(*dw);
			}

			//write corresponding 'deviation bars' and labels
			{
				size_t lastStep = 0;
				for (size_t i=0; i<polySteps.size(); ++i)
				{
					const HorizStepData& step = polySteps[i];
					bool displayIt = (i == 0/*|| i+1 == polySteps.size()*/); //warning: cycle
					if (i != 0)
					{
						double dAngle = polySteps[i].angle_rad - polySteps[lastStep].angle_rad;
						double next_dAngle = (i+1 == polySteps.size() ? polySteps[0].angle_rad + 2.0*M_PI : polySteps[i+1].angle_rad) - polySteps[lastStep].angle_rad;
						if (dAngle >= angularStep_rad || (next_dAngle > angularStep_rad && fabs(dAngle - angularStep_rad) < fabs(next_dAngle - angularStep_rad)))
						{
							displayIt = true;
						}
					}

					if (displayIt && i != 0) //we skip 0 as we always display a vertical axis!
					{
						CCVector3d relativePos( -cwSign * sin(step.angle_rad),
												-cos(step.angle_rad),
												0.0);
						CCVector3d Pangle = relativePos * currentRadius;
						CCVector3d Pdev = relativePos * (currentRadius + step.deviation * params.devMagnifyCoef);

						//page scaling
						Pangle = pageShift + Pangle * scale;
						Pdev = pageShift + Pdev * scale;

						//deviation bar
						dxf.writeLine(*dw,
										DL_LineData(Pangle.x,Pangle.y,Pangle.z,Pdev.x,Pdev.y,Pdev.z),
										GrayMaterial);

						//labels

						//justification depends on the current angle
						const double c_angleMargin_rad = 5.0 / 180.0 * M_PI; //margin: 5 degrees
						const double c_margin = sin(c_angleMargin_rad);

						//Horizontal justification: 0 = Left , 1 = Center, 2 = Right
						int hJustification = 1;
						if (relativePos.x < -c_margin) //point on the left
							hJustification = 2; //Right
						else if (relativePos.x > c_margin) //point on the right
							hJustification = 0; //Left

						//Vertical justification: 0 = Baseline, 1 = Bottom, 2 = Middle, 3 = Top
						int vJustification = 2;
						if (relativePos.y < -c_margin) //point in the lower part
							vJustification = 3; //Top
						else if (relativePos.y > c_margin) //point in the upper part
							vJustification = 1; //Bottom

						int hJustificationDev = hJustification;
						int hJustificationAng = hJustification;
						int vJustificationDev = vJustification;
						int vJustificationAng = vJustification;

						//negative deviation: profile is inside the circle
						// - deviation is displayed insde
						// - angle is displayed outside
						if (step.deviation < 0.0)
						{
							Pdev -= relativePos * 2.0*c_textMargin_mm;
							Pangle += relativePos * c_textMargin_mm;
							//invert dev. text justification
							if (hJustificationDev != 1)
								hJustificationDev = 2-hJustificationDev; // 0 <-> 2
							if (vJustificationDev != 2)
								vJustificationDev = 4-vJustificationDev; // 1 <-> 3
						}
						else
						{
							Pdev += relativePos * 2.0*c_textMargin_mm;
							Pangle -= relativePos * c_textMargin_mm;
							//invert ang. text justification
							if (hJustificationAng != 1)
								hJustificationAng = 2-hJustificationAng; // 0 <-> 2
							if (vJustificationAng != 2)
								vJustificationAng = 4-vJustificationAng; // 1 <-> 3
						}

						QString devText = QString::number(polySteps[i].deviation * params.devLabelMultCoef,'f',params.precision);
						dxf.writeText(	*dw,
							DL_TextData(Pdev.x,Pdev.y,Pdev.z,Pdev.x,Pdev.y,Pdev.z,c_textHeight_mm,1.0,0,hJustificationDev,vJustificationDev,devText.toStdString(),"STANDARD",0.0),
							DefaultMaterial);

						QString angleText = QString::number(polySteps[i].angle_rad *radToUnitConvFactor,'f',params.precision)+angleUnit;
						dxf.writeText(	*dw,
							DL_TextData(Pangle.x,Pangle.y,Pangle.z,Pangle.x,Pangle.y,Pangle.z,c_textHeight_mm,1.0,0,hJustificationAng,vJustificationAng,angleText.toStdString(),"STANDARD",0.0),
							GrayMaterial);
						
						lastStep = i;
					}
				}
			}
		}

		dw->sectionEnd();

	}

	//Writing the Objects Section
	dxf.writeObjects(*dw);
	dxf.writeObjectsEnd(*dw);

	//Ending and Closing the File
	dw->dxfEOF();
	dw->close();
	delete dw;
	dw = 0;

	return true;

#else
	return false;
#endif
}
Exemplo n.º 6
0
void DL_Jww::CreateMoji(DL_CreationInterface* creationInterface, CDataMoji& DMoji)
{
	string lName = HEX[DMoji.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DMoji.m_nGLayer] + "-" +
													HEX[DMoji.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DMoji.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));

	int width;
	if(DMoji.m_nPenWidth > 26)
		width = 0;
	else
		width = DMoji.m_nPenWidth;
	int color = colTable[DMoji.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DMoji.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DMoji.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DMoji.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	DL_TextData d(
		// insertion point
		DMoji.m_start.x, DMoji.m_start.y, 0.0,
		// alignment point
		0.0, 0.0, 0.0,
		// height
		DMoji.m_dSizeY,
		// x scale
		1.0,
		// generation flags
		0,
		// h just
		0,
		// v just
		0,
		// text
		DMoji.m_string,
		// style
		string("japanese"),
		// angle
		DMoji.m_degKakudo / 180.0 * M_PI);

	creationInterface->addText(d);
#ifdef FINISHED
	QTextCodec* codec = QTextCodec::codecForName("SJIS");
	RS_TextData data3(RS_Vector(0.0, 0.0),
				10,//double height,
				10,//double width,
				RS2::VAlignMiddle,
				RS2::HAlignCenter,
				RS2::LeftToRight,
				RS2::AtLeast,
				1.0,//double lineSpacingFactor,
				RS_String(""),//const RS_String& text,
				RS_String(""),
				0.0,//double angle,
				RS2::Update);
	RS_Text*	text;
	data3.insertionPoint = RS_Vector(DMoji.m_start.x, DMoji.m_start.y);
	data3.height = DMoji.m_dSizeY;
	data3.width = DMoji.m_dSizeX;
	data3.valign = RS2::VAlignBottom;//VAlignMiddle;
	data3.halign = RS2::HAlignLeft;//HAlignCenter;
	data3.drawingDirection = RS2::LeftToRight;
	data3.lineSpacingStyle = RS2::Exact;
	data3.lineSpacingFactor = DMoji.m_dKankaku;//1.0;
	//コード変換
	size_t left = DMoji.m_string.length();
	char* sjis = (char *)DMoji.m_string.c_str();
	char buf[200];
	//memset(buf, NULL, 1000);
	char* p = buf;
	size_t bufleft = 200;
#ifdef _WINDOWS
	// エンコーディングの変換:iconvを使う場合
	iconv_t cd = iconv_open(UTF8_CES, SHIFTJIS_CES);
#ifdef	DEBUG
printf("sjis = %x, p = %x\n", sjis, p);
#endif
	size_t r = iconv(cd, (const char **)(&sjis), &left, &p, &bufleft);//const_cast<char**>
#ifdef	DEBUG
printf("sjis = %x, p = %x\n", sjis, p);
printf("sjis = %x %x %x %x, p = %x %x %x %x\n", sjis[0],sjis[1],sjis[2],sjis[3], buf[0],buf[1],buf[2],buf[3]);
printf("r = %d, left = %d, bufleft = %d\n", r, left, bufleft);
#endif
	*p = '\0';
	iconv_close(cd);
#else
//	int ires = SJIS2UTF8N(sjis,buf,bufleft);
	int nBytesOut;
	strcpy(buf,(const char *)CUnicodeF::sjis_to_euc((const unsigned char *)sjis/*, &nBytesOut*/));
//	QTextCodec* codec = QTextCodec::codecForName("eucJP");
//	data3.text = codec->toUnicode(buf);
#endif
//	data3.text = codec->toUnicode(sjis);
	data3.text = RS_String::fromUtf8(buf);
	data3.style = RS_String("japanese-euc");
	data3.angle = DMoji.m_degKakudo / 180.0 * M_PI;
#ifdef DEBUG
RS_DEBUG->setLevel(RS_Debug::D_DEBUGGING);
#endif
	data3.updateMode = RS2::Update;
	//jwDWORD m_nMojiShu;//文字種(斜体文字は20000、ボールド体は10000を加えた数値)

	text = new RS_Text(graphic, data3);
	RS2::LineType ltype = lTable[DMoji.m_nPenStyle];
	RS_Color col = colTable[DMoji.m_nPenColor];
	RS2::LineWidth lw = lWidth[DMoji.m_nPenWidth > 26 ? 0 : DMoji.m_nPenWidth];//RS2::Width12
	text->setPen(RS_Pen(col, RS2::Width08, ltype));

	//画層設定
	RS_String lName = HEX[DMoji.m_nGLayer > 0x0f ? 0: DMoji.m_nGLayer] + "-" +
		HEX[DMoji.m_nLayer > 0x0f ? 0 : DMoji.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	text->setLayer(lName);
	// add the line to the graphic
	graphic->addEntity(text);
#ifdef DEBUG
std::cout << data3.height << "  " << data3.width << std::endl;
std::cout << *text;
#endif
#endif
}
Exemplo n.º 7
0
void DL_Jww::CreateEnko(DL_CreationInterface* creationInterface, CDataEnko& DEnko)
{
	string lName = HEX[DEnko.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nGLayer] + "-" +
													HEX[DEnko.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DEnko.m_nLayer];

	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));

	int width;
	if(DEnko.m_nPenWidth > 26)
		width = 0;
	else
		width = DEnko.m_nPenWidth;
	int color = colTable[DEnko.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DEnko.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DEnko.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DEnko.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );

	double angle1, angle2;
	//正円
	if(DEnko.m_bZenEnFlg){
		if(DEnko.m_dHenpeiRitsu == 1.0){
			DL_CircleData d(DEnko.m_start.x, DEnko.m_start.y, 0.0, DEnko.m_dHankei);
			creationInterface->addCircle(d);
		}else{
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			//楕円
			DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
							DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0,
							DEnko.m_dHenpeiRitsu,
							angle1, angle2);

			creationInterface->addEllipse(d);
		}
	}else{
		if(DEnko.m_dHenpeiRitsu == 1.0){
			//円弧
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			DL_ArcData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
					DEnko.m_dHankei,
					Deg(angle1),
					Deg(angle2));

			creationInterface->addArc(d);
		}else{
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			//楕円
			DL_EllipseData d(DEnko.m_start.x, DEnko.m_start.y, 0.0,
							DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku), 0.0,
							DEnko.m_dHenpeiRitsu,
							angle1, angle2);

			creationInterface->addEllipse(d);
		}
	}
#ifdef FINISHED
	RS_CircleData data1(RS_Vector(0.0, 0.0), 0.0);
	RS_Circle* circle;
	RS_ArcData arc_data(RS_Vector(0.0, 0.0), 0.0, 0.0, 0.0, false);
	RS_Arc* arc;
	RS_Ellipse* elps;
	//正円
	if(DEnko.m_bZenEnFlg){
		if(DEnko.m_dHenpeiRitsu == 1.0){
			data1.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y);
			data1.radius = DEnko.m_dHankei;
			circle = new RS_Circle(graphic, data1);
			RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
			RS_Color col = colTable[DEnko.m_nPenColor];
			RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
			circle->setPen(RS_Pen(col, lw, ltype));

			RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
				HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
			if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
				RS_Layer* layer = new RS_Layer(lName);
				graphic->addLayer(layer);
			}
			circle->setLayer(lName);
			// add the line to the graphic
			graphic->addEntity(circle);
#ifdef DEBUG
std::cout << *circle;
#endif
		}else{
			//楕円
			double angle1, angle2;
			if(DEnko.m_radEnkoKaku > 0.0){
				angle1 = DEnko.m_radKaishiKaku;
				angle2 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
			}else{
				angle1 = DEnko.m_radKaishiKaku + DEnko.m_radEnkoKaku;
				angle2 = DEnko.m_radKaishiKaku;
			}
			angle1 = angle1 - floor(angle1 / (M_PI * 2.0)) * M_PI * 2.0;
			angle2 = angle2 - floor(angle2 / (M_PI * 2.0)) * M_PI * 2.0;
			if( angle2 <= angle1 )
				angle1 = angle1 - M_PI * 2.0;
			RS_EllipseData elps_data(RS_Vector(DEnko.m_start.x, DEnko.m_start.y),
									RS_Vector(DEnko.m_dHankei * cos(DEnko.m_radKatamukiKaku), DEnko.m_dHankei * sin(DEnko.m_radKatamukiKaku)),
									DEnko.m_dHenpeiRitsu,
									angle1, angle2, false);
			elps = new RS_Ellipse(graphic, elps_data);
			RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
			RS_Color col = colTable[DEnko.m_nPenColor];
			RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
			elps->setPen(RS_Pen(col, lw, ltype));

			RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
				HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
			if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
				RS_Layer* layer = new RS_Layer(lName);
				graphic->addLayer(layer);
			}
			elps->setLayer(lName);
			// add the line to the graphic
			graphic->addEntity(elps);
		}
	}else{
		//円弧
		arc_data.center = RS_Vector(DEnko.m_start.x, DEnko.m_start.y);
		arc_data.radius = DEnko.m_dHankei;
		if(DEnko.m_radEnkoKaku > 0.0){
			arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
			arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
		}else{
			arc_data.angle1 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku + DEnko.m_radEnkoKaku;
			arc_data.angle2 = DEnko.m_radKaishiKaku + DEnko.m_radKatamukiKaku;
		}
		if( arc_data.angle2 <= arc_data.angle1 )
			arc_data.angle1 = arc_data.angle1 - M_PI * 2.0;
		arc_data.angle1 = Deg(arc_data.angle1);
		arc_data.angle2 = Deg(arc_data.angle2);
		arc_data.reversed = false;
		arc = new RS_Arc(graphic, arc_data);
		RS2::LineType ltype = lTable[DEnko.m_nPenStyle];
		RS_Color col = colTable[DEnko.m_nPenColor];
		RS2::LineWidth lw = lWidth[DEnko.m_nPenWidth > 26 ? 0 : DEnko.m_nPenWidth];//RS2::Width12
		arc->setPen(RS_Pen(col, lw, ltype));

		RS_String lName = HEX[DEnko.m_nGLayer > 0x0f ? 0:DEnko.m_nGLayer] + "-" +
			HEX[DEnko.m_nLayer > 0x0f ? 0: DEnko.m_nLayer];
		if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
std::cout << lName.ascii() << std::endl;
#endif
			RS_Layer* layer = new RS_Layer(lName);
			graphic->addLayer(layer);
		}
		arc->setLayer(lName);
		// add the line to the graphic
		graphic->addEntity(arc);
	}
#endif
}
Exemplo n.º 8
0
void DL_Jww::CreateSen(DL_CreationInterface* creationInterface, CDataSen& DSen)
{
	string lName = HEX[DSen.m_nGLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSen.m_nGLayer] + "-" +
													HEX[DSen.m_nLayer > ArraySize(HEX)-1 ? ArraySize(HEX)-1: DSen.m_nLayer];
	// add layer
	creationInterface->addLayer(DL_LayerData(lName,0));
//#ifdef	DEBUG
if(DSen.m_nPenStyle > ArraySize(lTable)-1)
	std::cout << "線種番号 " << (jwWORD)DSen.m_nPenStyle << std::endl;   //線種番号
if(DSen.m_nPenColor > ArraySize(colTable)-1)
	std::cout << "線色番号 " << (jwWORD)DSen.m_nPenColor << std::endl;   //線色番号
if(DSen.m_nPenWidth > 26)
	std::cout << "線色幅 " << (jwWORD)DSen.m_nPenWidth << std::endl;//線色幅
//#endif
	int width;
	if(DSen.m_nPenWidth > 26)
		width = 0;
	else
		width = DSen.m_nPenWidth;
	int color = colTable[DSen.m_nPenColor > ArraySize(colTable)-1 ? ArraySize(colTable)-1 : DSen.m_nPenColor];
	attrib = DL_Attributes(values[8],	  // layer
			       color,	      // color
			       width,	      // width
			       lTable[DSen.m_nPenStyle > ArraySize(lTable)-1 ? ArraySize(lTable)-1 : DSen.m_nPenStyle]);	  // linetype
	creationInterface->setAttributes(attrib);

	creationInterface->setExtrusion(0.0, 0.0, 1.0, 0.0 );
	// correct some impossible attributes for layers:
/*
	attrib = creationInterface->getAttributes();
	if (attrib.getColor()==256 || attrib.getColor()==0) {
		attrib.setColor(7);
	}
	if (attrib.getWidth()<0) {
		attrib.setWidth(1);
	}
	if (!strcasecmp(attrib.getLineType().c_str(), "BYLAYER") ||
			!strcasecmp(attrib.getLineType().c_str(), "BYBLOCK")) {
		attrib.setLineType("CONTINUOUS");
	}
*/
	DL_LineData d(DSen.m_start.x,
				DSen.m_start.y,
				0.0,
				DSen.m_end.x,
				DSen.m_end.y,
				0.0);

	creationInterface->addLine(d);

#ifdef FINISHED
	RS_LineData data(RS_Vector(0.0, 0.0), RS_Vector(0.0, 0.0));
	RS_Line* line;

	data.startpoint = RS_Vector(DSen.m_start.x, DSen.m_start.y);
	data.endpoint = RS_Vector(DSen.m_end.x, DSen.m_end.y);
	line = new RS_Line(graphic, data);
	RS2::LineType ltype = lTable[DSen.m_nPenStyle];
	RS_Color col = colTable[DSen.m_nPenColor];
	RS2::LineWidth lw = lWidth[DSen.m_nPenWidth>26 ? 0 : DSen.m_nPenWidth];
	line->setPen(RS_Pen(col, lw, ltype));
			//画層設定
//画層
// m_nGLayer-m_nLayer
//_0-0_ から_0-F_
//	 ...
//_F-0_ から_F-F_
	RS_String lName = HEX[DSen.m_nGLayer > 0x0f ? 0: DSen.m_nGLayer] + "-" +
		HEX[DSen.m_nLayer > 0x0f ? 0: DSen.m_nLayer];
	if( graphic->findLayer(lName) == (RS_Layer*)NULL ){
#ifdef DEBUG
cout << jwdoc->vSen[i].m_nGLayer << " " << jwdoc->vSen[i].m_nLayer << endl;
std::cout << lName.ascii() << std::endl;
#endif
		RS_Layer* layer = new RS_Layer(lName);
		graphic->addLayer(layer);
	}
	line->setLayer(lName);
#ifdef	DEBUG
std::cout << "線種番号 " << (jwWORD)DSen.m_nPenStyle << std::endl;   //線種番号
std::cout << "線色番号 " << (jwWORD)DSen.m_nPenColor << std::endl;   //線色番号
std::cout << "線色幅 " << (jwWORD)DSen.m_nPenWidth << std::endl;//線色幅
#endif

	// add the line to the graphic
	graphic->addEntity(line);
	std::cout << *line;
#endif
}
Exemplo n.º 9
0
int main() {
    DL_Dxf dxf;
    DL_WriterA* dw = dxf.out("dimension.dxf", DL_Codes::AC1015);
 
    // section header:
    dxf.writeHeader(*dw);
    dw->sectionEnd();
 
    // section tables:
    dw->sectionTables();

    // VPORT:
    dxf.writeVPort(*dw);

    // LTYPE:
    dw->tableLinetypes(1);
    dxf.writeLinetype(*dw, DL_LinetypeData("CONTINUOUS", "Continuous", 0, 0, 0.0));
    dxf.writeLinetype(*dw, DL_LinetypeData("BYLAYER", "", 0, 0, 0.0));
    dxf.writeLinetype(*dw, DL_LinetypeData("BYBLOCK", "", 0, 0, 0.0));
    dw->tableEnd();

    // LAYER:
    dw->tableLayers(1);
    dxf.writeLayer(
        *dw,
        DL_LayerData("0", 0),
        DL_Attributes("", 1, 0x00ff0000, 15, "CONTINUOUS")
    );
    dw->tableEnd();

    // STYLE:
    dw->tableStyle(1);
    DL_StyleData style("Standard", 0, 0.0, 1.0, 0.0, 0, 2.5, "txt", "");
    style.bold = false;
    style.italic = false;
    dxf.writeStyle(*dw, style);
    dw->tableEnd();

    // VIEW:
    dxf.writeView(*dw);

    // UCS:
    dxf.writeUcs(*dw);

    // APPID:
    dw->tableAppid(1);
    dxf.writeAppid(*dw, "ACAD");
    dw->tableEnd();

    // DIMSTYLE:
    dxf.writeDimStyle(*dw, 2.5, 0.625, 0.625, 0.625, 2.5);

    // BLOCK_RECORD:
    dxf.writeBlockRecord(*dw);
    dw->tableEnd();

    dw->sectionEnd();
 
    // BLOCK:
    dw->sectionBlocks();
    dxf.writeBlock(*dw, DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Model_Space");
    dxf.writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Paper_Space");
    dxf.writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Paper_Space0");
    dw->sectionEnd();
 
    // ENTITIES:
    dw->sectionEntities();
 
    DL_Attributes attributes("0", 256, -1, -1, "BYLAYER");

    // LINE:
    DL_LineData lineData(10, 5, 0, 30, 5, 0);
    dxf.writeLine(*dw, lineData, attributes);
 
    // DIMENSION:
    DL_DimensionData dimData(10.0,                  // def point (dimension line pos)
                             50.0,
                             0.0,
                             0,                     // text pos (irrelevant if flag 0x80 (128) set for type
                             0,
                             0.0,
                             0x1,                   // type: aligned with auto text pos (0x80 NOT set)
                             8,                     // attachment point: bottom center
                             2,                     // line spacing: exact
                             1.0,                   // line spacing factor
                             "",                    // text
                             "Standard",            // style
                             0.0,                   // text angle
                             1.0,                   // linear factor
                             1.0);                  // dim scale

    DL_DimAlignedData dimAlignedData(10.0,          // extension point 1
                                     5.0,
                                     0.0,
                                     30.0,          // extension point 2
                                     5.0,
                                     0.0);

    dxf.writeDimAligned(*dw, dimData, dimAlignedData, attributes);
 
    // end section ENTITIES:
    dw->sectionEnd();
    dxf.writeObjects(*dw, "MY_OBJECTS");
    dxf.writeObjectsEnd(*dw);
 
    dw->dxfEOF();
    dw->close();
    delete dw;
 
    return 0;
}
Exemplo n.º 10
0
    dw->dxfString(9, "$LIMMIN");
    dw->dxfReal(10, 0.0);
    dw->dxfReal(20, 0.0);
    dw->sectionEnd();
    dw->sectionTables();
    dxf->writeVPort(*dw);
    dw->tableLinetypes(25);
    dxf->writeLinetype(*dw, DL_LinetypeData("BYBLOCK", "BYBLOCK", 0, 0, 0.0));
    dxf->writeLinetype(*dw, DL_LinetypeData("BYLAYER", "BYLAYER", 0, 0, 0.0));
    dxf->writeLinetype(*dw, DL_LinetypeData("CONTINUOUS", "Continuous", 0, 0, 0.0));
    dw->tableEnd();
    int numberOfLayers = 3;
    dw->tableLayers(numberOfLayers);

    dxf->writeLayer(*dw,
                   DL_LayerData("0", 0),
                   DL_Attributes(
                       std::string(""),      // leave empty
                       DL_Codes::black,        // default color
                       100,                  // default width
                       "CONTINUOUS", 1.0));       // default line style

    dxf->writeLayer(*dw,
                   DL_LayerData("mainlayer", 0),
                   DL_Attributes(
                       std::string(""),
                       DL_Codes::red,
                       100,
                       "CONTINUOUS", 1.0));

    dxf->writeLayer(*dw,
Exemplo n.º 11
0
CC_FILE_ERROR DxfFilter::saveToFile(ccHObject* root, const char* filename)
{
#ifndef CC_DXF_SUPPORT

	ccLog::Error("[DXF] DXF format not supported! Check compilation parameters!");
	return CC_FERR_CONSOLE_ERROR;

#else

	if (!root || !filename)
		return CC_FERR_BAD_ARGUMENT;

	ccHObject::Container polylines;
	root->filterChildren(polylines,true,CC_POLY_LINE);

	//only polylines are handled for now
	size_t polyCount = polylines.size();
	if (!polyCount)
		return CC_FERR_NO_SAVE;

	//get global bounding box
	ccBBox box;
	for (size_t i=0; i<polyCount; ++i)
	{
		ccBBox polyBox = polylines[i]->getBB();
		if (i)
		{
			box += polyBox;
		}
		else
		{
			box = polyBox;
		}
	}

	CCVector3 diag = box.getDiagVec();
	double baseSize = static_cast<double>(std::max(diag.x,diag.y));
	double lineWidth = baseSize / 40.0;
	double pageMargin = baseSize / 20.0;

	DL_Dxf dxf;
	DL_WriterA* dw = dxf.out(qPrintable(filename), DL_VERSION_R12);
	if (!dw)
	{
		return CC_FERR_WRITING;
	}

	//write header
	dxf.writeHeader(*dw);

	//add dimensions
	dw->dxfString(9, "$INSBASE");
	dw->dxfReal(10,0.0);
	dw->dxfReal(20,0.0);
	dw->dxfReal(30,0.0);
	dw->dxfString(9, "$EXTMIN");
	dw->dxfReal(10,static_cast<double>(box.minCorner().x)-pageMargin);
	dw->dxfReal(20,static_cast<double>(box.minCorner().y)-pageMargin);
	dw->dxfReal(30,static_cast<double>(box.minCorner().z)-pageMargin);
	dw->dxfString(9, "$EXTMAX");
	dw->dxfReal(10,static_cast<double>(box.maxCorner().x)+pageMargin);
	dw->dxfReal(20,static_cast<double>(box.maxCorner().y)+pageMargin);
	dw->dxfReal(30,static_cast<double>(box.maxCorner().z)+pageMargin);
	dw->dxfString(9, "$LIMMIN");
	dw->dxfReal(10,static_cast<double>(box.minCorner().x)-pageMargin);
	dw->dxfReal(20,static_cast<double>(box.minCorner().y)-pageMargin);
	dw->dxfString(9, "$LIMMAX");
	dw->dxfReal(10,static_cast<double>(box.maxCorner().x)+pageMargin);
	dw->dxfReal(20,static_cast<double>(box.maxCorner().y)+pageMargin);

	//close header
	dw->sectionEnd();

	//Opening the Tables Section
	dw->sectionTables();
	//Writing the Viewports
	dxf.writeVPort(*dw);

	//Writing the Linetypes (all by default)
	{
		dw->tableLineTypes(25);
		dxf.writeLineType(*dw, DL_LineTypeData("BYBLOCK", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BYLAYER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CONTINUOUS", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO02W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO03W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO04W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("ACAD_ISO05W100", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("BORDERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTER2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("CENTERX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHDOTX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHED2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DASHEDX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDE2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DIVIDEX2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOT2", 0));
		dxf.writeLineType(*dw, DL_LineTypeData("DOTX2", 0));
		dw->tableEnd();
	}

	//Writing the Layers
	dw->tableLayers(static_cast<int>(polyCount)+1);
	QStringList layerNames;
	{
		//default layer
		dxf.writeLayer(*dw, 
			DL_LayerData("0", 0), 
			DL_Attributes(
			std::string(""),      // leave empty
			DL_Codes::black,      // default color
			100,                  // default width (in 1/100 mm)
			"CONTINUOUS"));       // default line style

		//polylines layers
		for (unsigned i=0; i<polyCount; ++i)
		{
			//default layer name
			//TODO: would be better to use the polyline name!
			//but it can't be longer than 31 characters (R14 limit)
			QString layerName = QString("POLYLINE_%1").arg(i+1,3,10,QChar('0'));

			layerNames << layerName;
			dxf.writeLayer(*dw, 
				DL_LayerData(layerName.toStdString(), 0), 
				DL_Attributes(
				std::string(""),
				i == 0 ? DL_Codes::green : /*-*/DL_Codes::green, //invisible if negative!
				lineWidth,
				"CONTINUOUS"));
		}
	}
	dw->tableEnd();

	//Writing Various Other Tables
	dxf.writeStyle(*dw);
	dxf.writeView(*dw);
	dxf.writeUcs(*dw);

	dw->tableAppid(1);
	dw->tableAppidEntry(0x12);
	dw->dxfString(2, "ACAD");
	dw->dxfInt(70, 0);
	dw->tableEnd();

	//Writing Dimension Styles
	dxf.writeDimStyle(	*dw, 
						/*arrowSize*/1, 
						/*extensionLineExtension*/1,
						/*extensionLineOffset*/1,
						/*dimensionGap*/1,
						/*dimensionTextSize*/1);
	
	//Writing Block Records
	dxf.writeBlockRecord(*dw);
	dw->tableEnd();

	//Ending the Tables Section
	dw->sectionEnd();

	//Writing the Blocks Section
	{
		dw->sectionBlocks();

		dxf.writeBlock(*dw,  DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Model_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space");

		dxf.writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
		dxf.writeEndBlock(*dw, "*Paper_Space0");

		dw->sectionEnd();
	}

	//Writing the Entities Section
	{
		dw->sectionEntities();

		//write polylines
		for (unsigned i=0; i<polyCount; ++i)
		{
			const ccPolyline* poly = static_cast<ccPolyline*>(polylines[i]);
			unsigned vertexCount = poly->size();
			int flags = poly->isClosed() ? 1 : 0;
			if (!poly->is2DMode())
				flags |= 8; //3D polyline
			dxf.writePolyline(	*dw,
								DL_PolylineData(static_cast<int>(vertexCount),0,0,flags),
								DL_Attributes(layerNames[i].toStdString(), DL_Codes::bylayer, -1, "BYLAYER") );

			for (unsigned i=0; i<vertexCount; ++i)
			{
				CCVector3 P;
				poly->getPoint(i,P);
				dxf.writeVertex(*dw, DL_VertexData(	P.x, P.y, P.y ) );
			}

			dxf.writePolylineEnd(*dw);
		}

		dw->sectionEnd();
	}

	//Writing the Objects Section
	dxf.writeObjects(*dw);
	dxf.writeObjectsEnd(*dw);

	//Ending and Closing the File
	dw->dxfEOF();
	dw->close();
	delete dw;
	dw = 0;

	ccLog::Print("[DXF] File %s saved successfully",filename);

	return CC_FERR_NO_ERROR;

#endif
}
Exemplo n.º 12
0
int main() {
    DL_Dxf dxf;
    DL_WriterA* dw = dxf.out("hatch.dxf", DL_Codes::AC1015);
 
    // section header:
    dxf.writeHeader(*dw);
    dw->sectionEnd();
 
    // section tables:
    dw->sectionTables();

    // VPORT:
    dxf.writeVPort(*dw);

    // LTYPE:
    dw->tableLinetypes(1);
    dxf.writeLinetype(*dw, DL_LinetypeData("CONTINUOUS", "Continuous", 0, 0, 0.0));
    dxf.writeLinetype(*dw, DL_LinetypeData("BYLAYER", "", 0, 0, 0.0));
    dxf.writeLinetype(*dw, DL_LinetypeData("BYBLOCK", "", 0, 0, 0.0));
    dw->tableEnd();

    // LAYER:
    dw->tableLayers(1);
    dxf.writeLayer(
        *dw,
        DL_LayerData("0", 0),
        DL_Attributes("", 2, 0, 100, "CONTINUOUS")
    );
    dw->tableEnd();

    // STYLE:
    dw->tableStyle(1);
    DL_StyleData style("Standard", 0, 0.0, 1.0, 0.0, 0, 2.5, "txt", "");
    style.bold = false;
    style.italic = false;
    dxf.writeStyle(*dw, style);
    dw->tableEnd();

    // VIEW:
    dxf.writeView(*dw);

    // UCS:
    dxf.writeUcs(*dw);

    // APPID:
    dw->tableAppid(1);
    dxf.writeAppid(*dw, "ACAD");
    dw->tableEnd();

    // DIMSTYLE:
    dxf.writeDimStyle(*dw, 2.5, 0.625, 0.625, 0.625, 2.5);

    // BLOCK_RECORD:
    dxf.writeBlockRecord(*dw);
    dw->tableEnd();

    dw->sectionEnd();
 
    // BLOCK:
    dw->sectionBlocks();
    dxf.writeBlock(*dw, DL_BlockData("*Model_Space", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Model_Space");
    dxf.writeBlock(*dw, DL_BlockData("*Paper_Space", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Paper_Space");
    dxf.writeBlock(*dw, DL_BlockData("*Paper_Space0", 0, 0.0, 0.0, 0.0));
    dxf.writeEndBlock(*dw, "*Paper_Space0");
    dw->sectionEnd();
 
    // ENTITIES:
    dw->sectionEntities();
 
    DL_Attributes attributes("0", 2, 0, -1, "BYLAYER");
 
    // start hatch with one loop:
    DL_HatchData data(1, false, 100.0, 0.0, "ESCHER", 0.0, 0.0);
    dxf.writeHatch1(*dw, data, attributes);
 
    // start loop:
    DL_HatchLoopData lData(1);
    dxf.writeHatchLoop1(*dw, lData);
 
    // write edge:
    DL_HatchEdgeData eData(
        0.0,
        0.0,
        100.0,
        0.0,
        M_PI*2,
        true
    );
    dxf.writeHatchEdge(*dw, eData);
 
    // end loop:
    dxf.writeHatchLoop2(*dw, lData);
 
    // end hatch:
    dxf.writeHatch2(*dw, data, attributes);
 
    // end section ENTITIES:
    dw->sectionEnd();
    dxf.writeObjects(*dw, "MY_OBJECTS");
    dxf.writeObjectsEnd(*dw);
 
    dw->dxfEOF();
    dw->close();
    delete dw;
 
    return 0;
}