entities2elements.cpp revision dc7a7dae1757af28215a38f4b71ef84776b38f6c
/*
* Code for converting dxf entities to SVG elements
* There are multiple ways for converting different items
* If possible most DXF enetities will be converted to paths because that is the most flexable object
*
* Author:
* Matt Squires <squiresm@colorado.edu>
*
* Copyright (C) 2005 Matt Squires
*
*/
/*
Matt Squires
SoC 2005
*/
#include"entities2elements.h"
#include"tables2svg_info.h"
#include<iostream>
#include<math.h>
// The names indicate the DXF entitiy first and the SVG element last
// Common elements
char* to_arc(double bulge, double r, double start_ang, double end_ang, int precision,char* delim, char * units, double scaling, char *out){
// This is used for arcs, polylines, and lwpolylines
char temp[50];
// Assume that we are adding to the input and not starting over
// For arcs there is only one radius
// Determine if it is a large arc
//strcat(out," 1,0 "); // Large arc flag...Always use a zero sweep flag
}
else{
//strcat(out," 0,0 "); // Small arc flag...Always use a zero sweep flag
}
// This may be easier if I allow r to be plus and minus, but for now this works
if (bulge > 0){
}
else{
}
}
// Build Coordinate
void coord(entity *ent, int precision,char* delim, char * units, double scaling, char *out); // Pairs of coords with units will be used so often build a function
// Pairs of coords with units will be used so often build a function build a dedicated function for returning such
char temp[20];
strcat(out, gcvt(scaling*ent->ret_x(),precision,temp) ); // There must be a better function for double to ascii conversion that is defined in most libraries
strcat(out, gcvt(-scaling*ent->ret_y(),precision,temp) ); // Because SVG has a the Y-axis pointed down multiply by -1
}
// DXF Polyline -> SVG
void pline2svg(polyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out); // General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported
void pline2svg(polyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){
// 0 is pline2path
// 1 is pline2pline
// 2 is pline2polygon
char delim[2];
double mag_bulge = 0;
double prev_mag_bulge = 0;
if (type < 1){
// Put the first Move To at the first, everything else will be a lineto
prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude
to_arc(pline.bulge(0), pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, units, scaling, out);
}
// If the previous point was a bulge then don't use a line to
}
// If bulge > some precsion then add bulge
to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out);
}
}
}
}
else{
// If bulge > some precsion then add bulge
}
// if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point
}
}
}
// Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element
char *out_ptr;
char temp[20];
int precision = 6;
// Add some line information
pattern2dasharray(plot_info.ret_ltype( ent_ptr->ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information
return out_ptr;
}
// Convert a dxf polyline to a SVG polyline. The conversion is not 1:1 because the SVG pline doesn't support closed objects or curves
char temp[2000];
int precision = 6;
//strcpy(temp," ");
//strcat(out,"<polyline fill=\"none\" stroke=\"black\" stroke-width=\"1\" points=\"");
// Add some line information
// if the DXF pline is closed then add an extra point
return out_ptr;
}
// Convert a dxf polyline to a SVG polygon. The conversion is not 1:1 because the SVG polygone assumes a closed path. If the pline is not closed it will be forced closed
//return pline2svg(pline, 2, 6, units, double scaling,out);
}
// DXF LWPolyline -> SVG
// This could be a template with polyline and lwpolyline but right now it is not that important
void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out); // General function for the conversion of a pline to a SVG element. Very similar functions just make accomidations for parts that may not be supported
void lwpline2svg(lwpolyline pline, int type, int precision, char * units, double scaling, tables plot_info, char *out){
// 0 is pline2path
// 1 is pline2pline
// 2 is pline2polygon
char delim[2];
double mag_bulge = 0;
double prev_mag_bulge = 0;
if (type < 1){
// Put the first Move To at the first, everything else will be a lineto
prev_mag_bulge = sqrt(pow(points[0].ret_bulge(),2)); // Because the bulge value can be positive or negative calculate the magnitude
to_arc(pline.bulge(0),pline.bulge_r(0), pline.bulge_start_angle(0), pline.bulge_end_angle(0), precision, delim, NULL, scaling, out);
}
// If the previous point was a bulge then don't use a line to
}
// If bulge > some precsion then add bulge
if ( ( mag_bulge > pow(0.1,precision) ) && (i < (points.size() - 1) )){ // Make sure the final point doesn't add a bulge on accident
to_arc(pline.bulge(i), pline.bulge_r(i), pline.bulge_start_angle(i), pline.bulge_end_angle(i), precision, delim, units, scaling, out);
}
}
}
}
else{
// If bulge > some precsion then add bulge
}
// if the element is a SVG::pline and the DXF::pline is closed then simulate by adding an extra point
}
}
}
// Convert a dxf polyline to a SVG path. This is the closest conversion of the DXF polyline to an SVG element
char *out_ptr;
char temp[20];
int precision = 6;
// Add some line information
pattern2dasharray(plot_info.ret_ltype( ent_ptr->ret_ltype_name(temp),ent_ptr->ret_layer_name(temp) ), precision, scaling, out); // Add the linetype information
return out_ptr;
}
// DXF ARC -> SVG
// So far this appears to be the only way to convert arcs into something recognized by SVG
char *out_ptr;
char temp[20];
// Calculate the starting point from the center and the start angle. As far as I can tell the rotation is CCW in the dxf notation and it in degrees
strcat(out,gcvt(scaling*(ent_ptr->ret_x()+a.ret_radius()*cos( a.ret_srt_ang()*3.14159/180 )),precision,temp) );
strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_srt_ang()*3.14159/180 )),precision,temp) );
// For arcs there is only one radius
// Determine if it is a large arc
}
else{
}
//The final point
strcat(out,gcvt(scaling*(ent_ptr->ret_x()+a.ret_radius()*cos( a.ret_end_ang()*3.14159/180 )),precision,temp) );
strcat(out,gcvt(-1*scaling*(ent_ptr->ret_y()+a.ret_radius()*sin( a.ret_end_ang()*3.14159/180 )),precision,temp) );
return out_ptr;
}
// DXF Circle -> SVG
char* circle2circle(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){
// Direct conversion of DXF circle to SVG circle
char *out_ptr;
//plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp));
//pattern2dasharray(plot_info.ret_ltype(ent_ptr->ret_ltype_name(temp), ent_ptr->ret_layer_name(temp)), precision, scaling, out); // Add the linetype information
return out_ptr;
}
char* circle2path(circle circ, int precision, char * units, double scaling, tables plot_info, char *out){
// Conversion of DXF circle to SVG circle assuming the path will represent the circle
char *out_ptr;
// The starting point is x-r,y so subtract off the radius from the x coord
return out_ptr;
}
// DXF Line -> SVG
// Directly convert DXF to SVG because it works
char *out_ptr;
char temp[20];
strcat(out,gcvt(-1*ent_ptr->ret_y(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis
strcat(out,gcvt(-1*ln.ret_yf(),precision,temp) ); // Put in an extra minus because of the way SVG has defined the axis
return out_ptr;
}
// Convert DXF line to SVG path
char *out_ptr;
char temp[20];
return out_ptr;
}
// DXF Text -> SVG
char* text2text(text txt, int precision, char * units, double scaling, tables plot_info, char *out){
// Directly convert DXF to SVG because it works
char *out_ptr;
char temp[10000];
// If the text is rotated use the transform matrix
// Apply a translation to the orgin, then a rotation, then a translation back to the original position
double a = ca;
double b = sa;
double c = -sa;
double d = ca;
}
else{
}
/*
strcat(out,gcvt(ent_ptr->ret_x(),precision,temp) );
strcat(out,units);
strcat(out,"\" y=\"-"); // Put in an extra minus because of the way SVG has defined the axis
strcat(out,gcvt(ent_ptr->ret_y(),precision,temp) );
strcat(out,units);
*/
//strcat(out,units);
//strcat(out,units);
// Now put in the text
// Now close the text element
// If the text was rotated finish off the tranform group
}
return out_ptr;
}
// DXF Insert -> SVG
char* insert2group(insert in, int precision, char * units, double scaling, tables plot_info, blocks blks, char *out){
char *out_ptr;
char tmp_char[100000];
// get the block using the name from the insert information
// For now just translations MBS 22 Aug 05
// Now convert the entities in the block
}
}
}
}
}
}
// End the group
return out_ptr;
}
char* write_by_layer(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * layer, char * out){
// output_type = 0 is to std:out
// output_type = 1 is to the input filename but with .dxf on the end
// For now everything will go to stdout later may directed to other places
// Get the various file informations as dependent on the layer type
// It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better
char tmp_char[100000];
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
}
char* write_all(int output_type, entities &ents, tables &tbls, blocks &blks, double scaling, char * units, char * out){
// output_type = 0 is to std:out
// output_type = 1 is to the input filename but with .dxf on the end
// For now everything will go to stdout later may directed to other places
// Get the various file informations as dependent on the layer type
// It would be better to redirect stdout to different places. That would make the code cleaner but I don't think it will work better
char tmp_char[100000];
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
if (output_type == 0){
}
else if (output_type == 1){
}
}
}