[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

DXF import



Hi,

Here's a patch to improve dxf import from visio 2002. I doesn't do such a
great job but that mostly because visio outputs garbage dxf.

Angus
Common subdirectories: dia/plug-ins/dxf/CVS and dia-0.90/plug-ins/dxf/CVS
diff -x Makefile -x .* -x dxf-ex* -x dxf.c -wdNu dia/plug-ins/dxf/Makefile.am dia-0.90/plug-ins/dxf/Makefile.am
--- dia/plug-ins/dxf/Makefile.am	Mon Sep  9 06:36:46 2002
+++ dia-0.90/plug-ins/dxf/Makefile.am	Wed Dec 31 17:00:00 1969
@@ -1,13 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-pkglib_LTLIBRARIES = libdxf_filter.la
-
-libdxf_filter_la_SOURCES = \
-	dxf.c \
-	dxf-export.c \
-	dxf-import.c
-
-libdxf_filter_la_LDFLAGS = -export-dynamic -module -avoid-version
-
-INCLUDES = -I$(top_srcdir)/intl -I$(srcdir)/../../lib $(GTK_CFLAGS) \
-	$(GNOME_CFLAGS) $(PANGOFT2_CFLAGS) $(XML_CFLAGS) $(UNICODE_CFLAGS) 
diff -x Makefile -x .* -x dxf-ex* -x dxf.c -wdNu dia/plug-ins/dxf/autocad_pal.h dia-0.90/plug-ins/dxf/autocad_pal.h
--- dia/plug-ins/dxf/autocad_pal.h	Wed Dec 31 17:00:00 1969
+++ dia-0.90/plug-ins/dxf/autocad_pal.h	Fri Jul  5 10:24:40 2002
@@ -0,0 +1,265 @@
+typedef struct 
+{
+   unsigned char r, g, b;
+} RGB_t;
+
+static RGB_t acad_pal[256] =
+{
+     { 0x00, 0x00, 0x00 },      //0
+     { 0xFF, 0x00, 0x00 },
+     { 0xFF, 0xFF, 0x00 },
+     { 0x00, 0xFF, 0x00 },
+     { 0x00, 0xFF, 0xFF },
+     { 0x00, 0x00, 0xFF },      //5
+     { 0xFF, 0x00, 0xFF },
+     { 0xFF, 0xFF, 0xFF },
+     { 0x41, 0x41, 0x41 },
+     { 0x80, 0x80, 0x80 },
+     { 0xFF, 0x00, 0x00 },      //10
+     { 0xFF, 0xAA, 0xAA },
+     { 0xBD, 0x00, 0x00 },
+     { 0xBD, 0x7E, 0x7E },
+     { 0x81, 0x00, 0x00 },
+     { 0x81, 0x56, 0x56 },      //15
+     { 0x68, 0x00, 0x00 },
+     { 0x68, 0x45, 0x45 },
+     { 0x4F, 0x00, 0x00 },
+     { 0x4F, 0x35, 0x35 },
+     { 0xFF, 0x3F, 0x00 },      //20
+     { 0xFF, 0xBF, 0xAA },
+     { 0xBD, 0x2E, 0x00 },
+     { 0xBD, 0x8D, 0x7E },
+     { 0x81, 0x1F, 0x00 },
+     { 0x81, 0x60, 0x56 },      //25
+     { 0x68, 0x19, 0x00 },
+     { 0x68, 0x4E, 0x45 },
+     { 0x4F, 0x13, 0x00 },
+     { 0x4F, 0x3B, 0x35 },
+     { 0xFF, 0x7F, 0x00 },      //30
+     { 0xFF, 0xD4, 0xAA },
+     { 0xBD, 0x5E, 0x00 },
+     { 0xBD, 0x9D, 0x7E },
+     { 0x81, 0x40, 0x00 },
+     { 0x81, 0x6B, 0x56 },      //35
+     { 0x68, 0x34, 0x00 },
+     { 0x68, 0x56, 0x45 },
+     { 0x4F, 0x27, 0x00 },
+     { 0x4F, 0x42, 0x35 },
+     { 0xFF, 0xBF, 0x00 },      //40
+     { 0xFF, 0xEA, 0xAA },
+     { 0xBD, 0x8D, 0x00 },
+     { 0xBD, 0xAD, 0x7E },
+     { 0x81, 0x60, 0x00 },
+     { 0x81, 0x76, 0x56 },      //45
+     { 0x68, 0x4E, 0x00 },
+     { 0x68, 0x5F, 0x45 },
+     { 0x4F, 0x3B, 0x00 },
+     { 0x4F, 0x49, 0x35 },
+     { 0xFF, 0xFF, 0x00 },      //50
+     { 0xFF, 0xFF, 0xAA },
+     { 0xBD, 0xBD, 0x00 },
+     { 0xBD, 0xBD, 0x7E },
+     { 0x81, 0x81, 0x00 },
+     { 0x81, 0x81, 0x56 },      //55
+     { 0x68, 0x68, 0x00 },
+     { 0x68, 0x68, 0x45 },
+     { 0x4F, 0x4F, 0x00 },
+     { 0x4F, 0x4F, 0x35 },
+     { 0xBF, 0xFF, 0x00 },      //60
+     { 0xEA, 0xFF, 0xAA },
+     { 0x8D, 0xBD, 0x00 },
+     { 0xAD, 0xBD, 0x7E },
+     { 0x60, 0x81, 0x00 },
+     { 0x76, 0x81, 0x56 },      //65
+     { 0x4E, 0x68, 0x00 },
+     { 0x5F, 0x68, 0x45 },
+     { 0x3B, 0x4F, 0x00 },
+     { 0x49, 0x4F, 0x35 },
+     { 0x7F, 0xFF, 0x00 },      //70
+     { 0xD4, 0xFF, 0xAA },
+     { 0x5E, 0xBD, 0x00 },
+     { 0x9D, 0xBD, 0x7E },
+     { 0x40, 0x81, 0x00 },
+     { 0x6B, 0x81, 0x56 },      //75
+     { 0x34, 0x68, 0x00 },
+     { 0x56, 0x68, 0x45 },
+     { 0x27, 0x4F, 0x00 },
+     { 0x42, 0x4F, 0x35 },
+     { 0x3F, 0xFF, 0x00 },      //80
+     { 0xBF, 0xFF, 0xAA },
+     { 0x2E, 0xBD, 0x00 },
+     { 0x8D, 0xBD, 0x7E },
+     { 0x1F, 0x81, 0x00 },
+     { 0x60, 0x81, 0x56 },      //85
+     { 0x19, 0x68, 0x00 },
+     { 0x4E, 0x68, 0x45 },
+     { 0x13, 0x4F, 0x00 },
+     { 0x3B, 0x4F, 0x35 },
+     { 0x00, 0xFF, 0x00 },      //90
+     { 0xAA, 0xFF, 0xAA },
+     { 0x00, 0xBD, 0x00 },
+     { 0x7E, 0xBD, 0x7E },
+     { 0x00, 0x81, 0x00 },
+     { 0x56, 0x81, 0x56 },      //95
+     { 0x00, 0x68, 0x00 },
+     { 0x45, 0x68, 0x45 },
+     { 0x00, 0x4F, 0x00 },
+     { 0x35, 0x4F, 0x35 },
+     { 0x00, 0xFF, 0x3F },      //100
+     { 0xAA, 0xFF, 0xBF },
+     { 0x00, 0xBD, 0x2E },
+     { 0x7E, 0xBD, 0x8D },
+     { 0x00, 0x81, 0x1F },
+     { 0x56, 0x81, 0x60 },      //105
+     { 0x00, 0x68, 0x19 },
+     { 0x45, 0x68, 0x4E },
+     { 0x00, 0x4F, 0x13 },
+     { 0x35, 0x4F, 0x3B },
+     { 0x00, 0xFF, 0x7F },      //110
+     { 0xAA, 0xFF, 0xD4 },
+     { 0x00, 0xBD, 0x5E },
+     { 0x7E, 0xBD, 0x9D },
+     { 0x00, 0x81, 0x40 },
+     { 0x56, 0x81, 0x6B },      //115
+     { 0x00, 0x68, 0x34 },
+     { 0x45, 0x68, 0x56 },
+     { 0x00, 0x4F, 0x27 },
+     { 0x35, 0x4F, 0x42 },
+     { 0x00, 0xFF, 0xBF },      //120
+     { 0xAA, 0xFF, 0xEA },
+     { 0x00, 0xBD, 0x8D },
+     { 0x7E, 0xBD, 0xAD },
+     { 0x00, 0x81, 0x60 },
+     { 0x56, 0x81, 0x76 },      //125
+     { 0x00, 0x68, 0x4E },
+     { 0x45, 0x68, 0x5F },
+     { 0x00, 0x4F, 0x3B },
+     { 0x35, 0x4F, 0x49 },
+     { 0x00, 0xFF, 0xFF },      //130
+     { 0xAA, 0xFF, 0xFF },
+     { 0x00, 0xBD, 0xBD },
+     { 0x7E, 0xBD, 0xBD },
+     { 0x00, 0x81, 0x81 },
+     { 0x56, 0x81, 0x81 },      //135
+     { 0x00, 0x68, 0x68 },
+     { 0x45, 0x68, 0x68 },
+     { 0x00, 0x4F, 0x4F },
+     { 0x35, 0x4F, 0x4F },
+     { 0x00, 0xBF, 0xFF },      //140
+     { 0xAA, 0xEA, 0xFF },
+     { 0x00, 0x8D, 0xBD },
+     { 0x7E, 0xAD, 0xBD },
+     { 0x00, 0x60, 0x81 },
+     { 0x56, 0x76, 0x81 },      //145
+     { 0x00, 0x4E, 0x68 },
+     { 0x45, 0x5F, 0x68 },
+     { 0x00, 0x3B, 0x4F },
+     { 0x35, 0x49, 0x4F },
+     { 0x00, 0x7F, 0xFF },      //150
+     { 0xAA, 0xD4, 0xFF },
+     { 0x00, 0x5E, 0xBD },
+     { 0x7E, 0x9D, 0xBD },
+     { 0x00, 0x40, 0x81 },
+     { 0x56, 0x6B, 0x81 },      //155
+     { 0x00, 0x34, 0x68 },
+     { 0x45, 0x56, 0x68 },
+     { 0x00, 0x27, 0x4F },
+     { 0x35, 0x42, 0x4F },
+     { 0x00, 0x3F, 0xFF },      //160
+     { 0xAA, 0xBF, 0xFF },
+     { 0x00, 0x2E, 0xBD },
+     { 0x7E, 0x8D, 0xBD },
+     { 0x00, 0x1F, 0x81 },
+     { 0x56, 0x60, 0x81 },      //165
+     { 0x00, 0x19, 0x68 },
+     { 0x45, 0x4E, 0x68 },
+     { 0x00, 0x13, 0x4F },
+     { 0x35, 0x3B, 0x4F },
+     { 0x00, 0x00, 0xFF },      //170
+     { 0xAA, 0xAA, 0xFF },
+     { 0x00, 0x00, 0xBD },
+     { 0x7E, 0x7E, 0xBD },
+     { 0x00, 0x00, 0x81 },
+     { 0x56, 0x56, 0x81 },      //175
+     { 0x00, 0x00, 0x68 },
+     { 0x45, 0x45, 0x68 },
+     { 0x00, 0x00, 0x4F },
+     { 0x35, 0x35, 0x4F },
+     { 0x3F, 0x00, 0xFF },      //180
+     { 0xBF, 0xAA, 0xFF },
+     { 0x2E, 0x00, 0xBD },
+     { 0x8D, 0x7E, 0xBD },
+     { 0x1F, 0x00, 0x81 },
+     { 0x60, 0x56, 0x81 },      //185
+     { 0x19, 0x00, 0x68 },
+     { 0x4E, 0x45, 0x68 },
+     { 0x13, 0x00, 0x4F },
+     { 0x3B, 0x35, 0x4F },
+     { 0x7F, 0x00, 0xFF },      //190
+     { 0xD4, 0xAA, 0xFF },
+     { 0x5E, 0x00, 0xBD },
+     { 0x9D, 0x7E, 0xBD },
+     { 0x40, 0x00, 0x81 },
+     { 0x6B, 0x56, 0x81 },      //195
+     { 0x34, 0x00, 0x68 },
+     { 0x56, 0x45, 0x68 },
+     { 0x27, 0x00, 0x4F },
+     { 0x42, 0x35, 0x4F },
+     { 0xBF, 0x00, 0xFF },      //200
+     { 0xEA, 0xAA, 0xFF },
+     { 0x8D, 0x00, 0xBD },
+     { 0xAD, 0x7E, 0xBD },
+     { 0x60, 0x00, 0x81 },
+     { 0x76, 0x56, 0x81 },      //205
+     { 0x4E, 0x00, 0x68 },
+     { 0x5F, 0x45, 0x68 },
+     { 0x3B, 0x00, 0x4F },
+     { 0x49, 0x35, 0x4F },
+     { 0xFF, 0x00, 0xFF },      //210
+     { 0xFF, 0xAA, 0xFF },
+     { 0xBD, 0x00, 0xBD },
+     { 0xBD, 0x7E, 0xBD },
+     { 0x81, 0x00, 0x81 },
+     { 0x81, 0x56, 0x81 },      //215
+     { 0x68, 0x00, 0x68 },
+     { 0x68, 0x45, 0x68 },
+     { 0x4F, 0x00, 0x4F },
+     { 0x4F, 0x35, 0x4F },
+     { 0xFF, 0x00, 0xBF },      //220
+     { 0xFF, 0xAA, 0xEA },
+     { 0xBD, 0x00, 0x8D },
+     { 0xBD, 0x7E, 0xAD },
+     { 0x81, 0x00, 0x60 },
+     { 0x81, 0x56, 0x76 },      //225
+     { 0x68, 0x00, 0x4E },
+     { 0x68, 0x45, 0x5F },
+     { 0x4F, 0x00, 0x3B },
+     { 0x4F, 0x35, 0x49 },
+     { 0xFF, 0x00, 0x7F },      //230
+     { 0xFF, 0xAA, 0xD4 },
+     { 0xBD, 0x00, 0x5E },
+     { 0xBD, 0x7E, 0x9D },
+     { 0x81, 0x00, 0x40 },
+     { 0x81, 0x56, 0x6B },      //235
+     { 0x68, 0x00, 0x34 },
+     { 0x68, 0x45, 0x56 },
+     { 0x4F, 0x00, 0x27 },
+     { 0x4F, 0x35, 0x42 },
+     { 0xFF, 0x00, 0x3F },      //240
+     { 0xFF, 0xAA, 0xBF },
+     { 0xBD, 0x00, 0x2E },
+     { 0xBD, 0x7E, 0x8D },
+     { 0x81, 0x00, 0x1F },
+     { 0x81, 0x56, 0x60 },      //245
+     { 0x68, 0x00, 0x19 },
+     { 0x68, 0x45, 0x4E },
+     { 0x4F, 0x00, 0x13 },
+     { 0x4F, 0x35, 0x3B },
+     { 0x33, 0x33, 0x33 },      //250
+     { 0x50, 0x50, 0x50 },
+     { 0x69, 0x69, 0x69 },
+     { 0x82, 0x82, 0x82 },
+     { 0xBE, 0xBE, 0xBE },
+     { 0xFF, 0xFF, 0xFF }      //255
+};
+
diff -x Makefile -x .* -x dxf-ex* -x dxf.c -wdNu dia/plug-ins/dxf/dxf-import.c dia-0.90/plug-ins/dxf/dxf-import.c
--- dia/plug-ins/dxf/dxf-import.c	Sun Jun 23 15:06:40 2002
+++ dia-0.90/plug-ins/dxf/dxf-import.c	Mon Sep  9 17:01:47 2002
@@ -39,13 +39,29 @@
 #include "object.h"
 #include "properties.h"
 #include "propinternals.h"
+#include "autocad_pal.h"
 
-static real coord_scale = 5.0;
-static real width_scale = 10.0;
+#include "../app/group.h"
+#include "../objects/standard/create.h"
+
+static real coord_scale = 1.0, measure_scale = 1.0;
+static real text_scale = 1.0;
+
+#define WIDTH_SCALE measure_scale
+#define DEFAULT_LINE_WIDTH 0.001
+
+Point extent_min, extent_max;
+Point limit_min, limit_max;
 
 /* maximum line length */
 #define DXF_LINE_LENGTH 256
 
+typedef struct layer_data_tag 
+{
+   char layerName[256];
+   int acad_colour;
+} layer_data_type;
+
 typedef struct _DxfData
 {
     char code[DXF_LINE_LENGTH];
@@ -54,24 +70,33 @@
 
 gboolean import_dxf(const gchar *filename, DiagramData *dia, void* user_data);
 gboolean read_dxf_codes(FILE *filedxf, DxfData *data);
-void read_entity_line_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
-void read_entity_circle_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
-void read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
-void read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
-void read_entity_text_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_line_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_circle_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_solid_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+Object *read_entity_polyline_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_entity_scale_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_entity_textsize_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_entity_mesurement_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
 void read_table_layer_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_section_header_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_section_classes_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
 void read_section_tables_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
 void read_section_entities_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
+void read_section_blocks_dxf(FILE *filedxf, DxfData *data, DiagramData *dia);
 Layer *layer_find_by_name(char *layername, DiagramData *dia);
 LineStyle get_dia_linestyle_dxf(char *dxflinestyle);
 
 /* returns the layer with the given name */
 /* TODO: merge this with other layer code? */
-Layer *layer_find_by_name(char *layername, DiagramData *dia) {
+Layer *layer_find_by_name(char *layername, DiagramData *dia) 
+{
     Layer *matching_layer, *layer;
     int i;
 	
-    matching_layer = dia->active_layer;
+    matching_layer = NULL;
+   
     for (i=0; i<dia->layers->len; i++) {
         layer = (Layer *)g_ptr_array_index(dia->layers, i);
         if(strcmp(layer->name, layername) == 0) {
@@ -79,6 +104,13 @@
             break;
         }
     }
+
+   if( matching_layer == NULL )
+     {
+	matching_layer = new_layer(g_strdup( layername ));
+	data_add_layer(dia, matching_layer);
+     }
+
     return matching_layer;
 }
 
@@ -105,8 +137,9 @@
     { "line_style", PROP_TYPE_LINESTYLE},
     PROP_DESC_END};
 
+
 /* reads a line entity from the dxf file and creates a line object in dia*/
-void read_entity_line_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
+Object *read_entity_line_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
     int codedxf;
     char *old_locale;
 
@@ -124,7 +157,7 @@
     ColorProperty *cprop;
     RealProperty *rprop;
 
-    real line_width = 0.1;
+    real line_width = DEFAULT_LINE_WIDTH;
     LineStyle style = LINESTYLE_SOLID;
     Layer *layer = NULL;
     
@@ -132,7 +165,7 @@
     do {
         if(read_dxf_codes(filedxf, data) == FALSE){
             setlocale(LC_NUMERIC, old_locale);
-            return;
+            return( NULL );
         }
         codedxf = atoi(data->code);
         switch(codedxf){
@@ -141,19 +174,20 @@
         case  8: layer = layer_find_by_name(data->value, dia);
             break;
         case 10:
-            start.x = atof(data->value) / coord_scale;
+            start.x = atof(data->value) * coord_scale * measure_scale;
             break;
         case 11: 
-            end.x = atof(data->value) / coord_scale;
+            end.x = atof(data->value) * coord_scale * measure_scale;
             break;
         case 20: 
-            start.y = (-1)*atof(data->value) / coord_scale;
+            start.y = (-1)*atof(data->value) * coord_scale * measure_scale;
             break;
         case 21: 
-            end.y = (-1)*atof(data->value) / coord_scale;
+            end.y = (-1)*atof(data->value) * coord_scale * measure_scale;
             break;
         case 39: 
-            line_width = atof(data->value) / width_scale;
+            line_width = atof(data->value) * WIDTH_SCALE;
+	   /*printf( "line width %f\n", line_width ); */
             break;
         }	
     } while(codedxf != 0);
@@ -185,6 +219,368 @@
     line_obj->ops->set_props(line_obj, props);
 
     prop_list_free(props);
+   
+   return( line_obj );
+}
+
+static PropDescription dxf_solid_prop_descs[] = {
+     { "line_colour", PROP_TYPE_COLOUR },
+     { "line_width", PROP_TYPE_REAL },
+     { "line_style", PROP_TYPE_LINESTYLE },
+     { "fill_colour", PROP_TYPE_COLOUR },
+     { "show_background", PROP_TYPE_BOOL },
+   PROP_DESC_END};
+
+/* reads a solid entity from the dxf file and creates a polygon object in dia*/
+Object *read_entity_solid_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
+   int codedxf;
+   char *old_locale;
+   
+   /* polygon data */
+   Point p[4];
+   
+   ObjectType *otype = object_get_type("Standard - Polygon");  
+   Handle *h1, *h2;
+   
+   Object *polygon_obj;
+   PolygonCreateData *pcd;
+
+   Color fill_colour = { 0.5, 0.5, 0.5 };
+
+   GPtrArray *props;
+   LinestyleProperty *lsprop;
+   ColorProperty *cprop, *fprop;
+   RealProperty *rprop;
+   BoolProperty *bprop;
+   
+    real line_width = 0.001;
+    LineStyle style = LINESTYLE_SOLID;
+    Layer *layer = NULL;
+   unsigned char colour;
+   
+/*   printf( "Solid " ); */
+   
+    old_locale = setlocale(LC_NUMERIC, "C");
+    do {
+        if(read_dxf_codes(filedxf, data) == FALSE){
+            setlocale(LC_NUMERIC, old_locale);
+            return( NULL );
+        }
+        codedxf = atoi(data->code);
+        switch(codedxf){
+        case 6:	 
+	   style = get_dia_linestyle_dxf(data->value);
+	   break;		
+        case  8: 
+	   layer = layer_find_by_name(data->value, dia);
+	   /*printf( "layer: %s ", data->value );*/
+	   break;
+        case 10:
+	   p[0].x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P0.x: %f ", p[0].x );*/
+	   break;
+        case 11: 
+            p[1].x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P1.x: %f ", p[1].x );*/
+            break;
+        case 12: 
+            p[2].x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P2.x: %f ", p[2].x );*/
+            break;
+        case 13: 
+            p[3].x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P3.x: %f ", p[3].x );*/
+            break;
+        case 20: 
+            p[0].y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P0.y: %f ", p[0].y );*/
+            break;
+        case 21: 
+            p[1].y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P1.y: %f ", p[1].y );*/
+            break;
+        case 22: 
+            p[2].y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P2.y: %f ", p[2].y );*/
+            break;
+        case 23: 
+            p[3].y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "P3.y: %f\n", p[3].y );*/
+            break;
+        case 39: 
+            line_width = atof(data->value) * WIDTH_SCALE;
+	   /*printf( "width %f\n", line_width );*/
+            break;
+        case 62: 
+            colour = atoi(data->value);
+	   fill_colour.red = acad_pal[colour].r / 255.0;
+	   fill_colour.green = acad_pal[colour].g / 255.0;
+	   fill_colour.blue = acad_pal[colour].b / 255.0;
+/*	   printf( "acad colour %d %d %d\n", acad_pal[colour].r, acad_pal[colour].g, acad_pal[colour].b );
+	   printf( "fill colour %f %f %f\n", fill_colour.red, fill_colour.green, fill_colour.blue );*/
+            break;
+        }	
+    } while(codedxf != 0);
+    setlocale(LC_NUMERIC, old_locale);
+
+   pcd = g_new( PolygonCreateData, 1);
+   
+   if( p[2].x != p[3].x && p[2].y != p[3].y )
+     pcd->num_points = 4;
+   else
+     pcd->num_points = 3;
+   
+   pcd->points = g_new( Point, pcd->num_points );
+   
+   memcpy( pcd->points, p, sizeof( Point ) * pcd->num_points );
+
+   polygon_obj = otype->ops->create( NULL, pcd, &h1, &h2 );
+
+   layer_add_object( layer, polygon_obj );
+
+   props = prop_list_from_descs( dxf_solid_prop_descs, pdtpp_true );
+   g_assert(props->len == 5);
+
+   cprop = g_ptr_array_index( props,0 );
+   cprop->color_data = fill_colour;
+
+   rprop = g_ptr_array_index( props,1 );
+   rprop->real_data = line_width;
+
+   lsprop = g_ptr_array_index( props,2 );
+   lsprop->style = style;
+   lsprop->dash = 1.0;
+
+   fprop = g_ptr_array_index( props, 3 );
+   fprop->color_data = fill_colour;
+
+   bprop = g_ptr_array_index( props, 4 );
+   bprop->bool_data = TRUE;
+
+   polygon_obj->ops->set_props( polygon_obj, props );
+
+   prop_list_free(props);
+   
+   return( polygon_obj );
+}
+
+static PropDescription dxf_polyline_prop_descs[] = {
+     { "line_colour", PROP_TYPE_COLOUR },
+     { "line_width", PROP_TYPE_REAL },
+     { "line_style", PROP_TYPE_LINESTYLE },
+   PROP_DESC_END};
+
+int IsEqual( double a, double b )
+{
+   double epsilon = 0.001;
+   
+   if( a == b )
+     return( 1 );
+   
+   if(( a + epsilon ) > b && ( a - epsilon ) < b )
+     return( 1 );
+   
+   return( 0 );
+}
+
+/* reads a polyline entity from the dxf file and creates a polyline object in dia*/
+Object *read_entity_polyline_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
+    int codedxf, i;
+    char *old_locale;
+   
+    /* polygon data */
+    Point *p = NULL, start, end, center;
+    
+    ObjectType *otype = object_get_type("Standard - PolyLine");
+    Handle *h1, *h2;
+    
+    Object *polyline_obj;
+    PolylineCreateData *pcd;
+
+   Color line_colour = { 0.0, 0.0, 0.0 };
+
+   GPtrArray *props;
+   LinestyleProperty *lsprop;
+   ColorProperty *cprop;
+   RealProperty *rprop;
+   
+   real line_width = DEFAULT_LINE_WIDTH;
+   real radius, start_angle;
+   LineStyle style = LINESTYLE_SOLID;
+   Layer *layer = NULL;
+   unsigned char colour, closed = 0;
+   int points = 0;
+   
+    old_locale = setlocale(LC_NUMERIC, "C");
+    do {
+        if(read_dxf_codes(filedxf, data) == FALSE){
+            setlocale(LC_NUMERIC, old_locale);
+            return( NULL );
+        }
+        codedxf = atoi(data->code);
+        switch(codedxf){
+	 case 0:
+	   if( !strcmp( data->value, "VERTEX" ))
+	     {
+		points++;
+		
+		p = realloc( p, sizeof( Point ) * points );
+		
+		/*printf( "Vertex %d\n", points );*/
+		  
+	     }
+	   
+        case 6:	 
+	   style = get_dia_linestyle_dxf(data->value);
+	   break;		
+        case  8: 
+	   layer = layer_find_by_name(data->value, dia);
+	   /*printf( "layer: %s ", data->value );*/
+	   break;
+        case 10:
+	   if( points != 0 )
+	     {
+		p[points-1].x = atof(data->value) * coord_scale * measure_scale;
+		/*printf( "P[%d].x: %f ", points-1, p[points-1].x );*/
+	     }
+	   break;
+        case 20: 
+	   if( points != 0 )
+	     {
+		p[points-1].y = (-1)*atof(data->value) * coord_scale * measure_scale;
+		/*printf( "P[%d].y: %f\n", points-1, p[points-1].y );*/
+	     }
+            break;
+	 case 39: 
+	   line_width = atof(data->value) * WIDTH_SCALE;
+	   /*printf( "width %f\n", line_width );*/
+	   break;
+	 case 42:
+	   /* FIXME - the bulge code doesn't work */
+	   p = realloc( p, sizeof( Point ) * ( points + 10 ));
+
+	   start = p[points-2];
+	   end = p[points-1];
+	   
+	   radius = sqrt( pow( end.x - start.x, 2 ) + pow( end.y - start.y, 2 ))/2;
+
+	   center.x = start.x + ( end.x - start.x )/2;
+	   center.y = start.y + ( end.y - start.y )/2;
+	   
+	   if( IsEqual( start.x, end.x ))
+	     {
+		if( IsEqual( start.y, end.y ))
+		  {
+		     fprintf( stderr, "Bad vertex bulge\n" );
+		  }
+		else if( start.y > center.y )
+		  {
+		     /*start_angle = 90.0;*/
+		     start_angle = M_PI/2;
+		  }
+		else
+		  {
+		     /*start_angle = 270.0;*/
+		     start_angle = M_PI * 1.5;
+		  }
+	     }
+	   else if( IsEqual( start.y, end.y ))
+	     {
+		if( IsEqual( start.x, end.x ))
+		  {
+		     fprintf( stderr, "Bad vertex bulge\n" );
+		  }
+		else if( start.x > center.x )
+		  {
+		     start_angle = 0.0;
+		  }
+		else
+		  {
+		     start_angle = M_PI;
+		  }
+	     }
+	   else
+	     {
+		start_angle = atan( center.y - start.y /center.x - start.x );
+	     }
+	   
+	   /*printf( "start x %f end x %f center x %f\n", start.x, end.x, center.x );
+	   printf( "start y %f end y %f center y %f\n", start.y, end.y, center.y );
+	   printf( "bulge %s %f startx_angle %f\n", data->value, radius, start_angle );*/
+	   
+	   for( i=(points-1); i<(points+9); i++ );
+	     {
+		p[i].x = center.x + cos( start_angle ) * radius;
+		p[i].y = center.y + sin( start_angle ) * radius;
+		start_angle += M_PI/10.0;
+		/*printf( "i %d x %f y %f\n", i, p[i].x, p[i].y );*/
+	     }
+	   points += 10;
+	   
+	   p[points-1] = end;
+	   break;
+	 case 62: 
+	   colour = atoi(data->value);
+	   line_colour.red = acad_pal[colour].r / 255.0;
+	   line_colour.green = acad_pal[colour].g / 255.0;
+	   line_colour.blue = acad_pal[colour].b / 255.0;
+	   break;
+	 case 70:
+	   closed = 1 & atoi( data->value );
+	   /*printf( "closed %d %s", closed, data->value );*/
+	   break;
+        }	
+    } while( strcmp( data->value, "SEQEND" ));
+   
+    setlocale(LC_NUMERIC, old_locale);
+
+   if( points == 0 )
+     {
+	printf( "No vertexes defined\n" );
+	return( NULL );
+     }
+   
+   pcd = g_new( PolylineCreateData, 1);
+   
+   if( closed )
+     {
+	++points;
+	p = realloc( p, sizeof( Point ) * points );
+	p[points-1].x = p[0].x;
+	p[points-1].y = p[0].y;
+     }
+   
+   pcd->num_points = points;
+   pcd->points = g_new( Point, pcd->num_points );
+   
+   memcpy( pcd->points, p, sizeof( Point ) * pcd->num_points );
+   
+   free( p );
+
+   polyline_obj = otype->ops->create( NULL, pcd, &h1, &h2 );
+
+   layer_add_object( layer, polyline_obj );
+
+   props = prop_list_from_descs( dxf_polyline_prop_descs, pdtpp_true );
+   g_assert( props->len == 3 );
+
+   cprop = g_ptr_array_index( props,0 );
+   cprop->color_data = line_colour;
+
+   rprop = g_ptr_array_index( props,1 );
+   rprop->real_data = line_width;
+
+   lsprop = g_ptr_array_index( props,2 );
+   lsprop->style = style;
+   lsprop->dash = 1.0;
+
+   polyline_obj->ops->set_props( polyline_obj, props );
+
+   prop_list_free(props);
+   
+   return( polyline_obj );
 }
 
 static PropDescription dxf_ellipse_prop_descs[] = {
@@ -197,7 +593,8 @@
     PROP_DESC_END};
 
 /* reads a circle entity from the dxf file and creates a circle object in dia*/
-void read_entity_circle_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
+Object *read_entity_circle_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
     int codedxf;
     char *old_locale;
     
@@ -217,14 +614,14 @@
     ColorProperty *cprop;
     GPtrArray *props;
 
-    real line_width = 0.1;
+    real line_width = DEFAULT_LINE_WIDTH;
     Layer *layer = NULL;
     
     old_locale = setlocale(LC_NUMERIC, "C");
     do {
         if(read_dxf_codes(filedxf, data) == FALSE){
             setlocale(LC_NUMERIC, old_locale);
-            return;
+            return( NULL );
         }
         codedxf = atoi(data->code);
         switch(codedxf){
@@ -232,16 +629,16 @@
             layer = layer_find_by_name(data->value, dia);
             break;
         case 10: 
-            center.x = atof(data->value) / coord_scale;
+            center.x = atof(data->value) * coord_scale * measure_scale;
             break;
         case 20: 
-            center.y = (-1)*atof(data->value) / coord_scale;
+            center.y = (-1)*atof(data->value) * coord_scale * measure_scale;
             break;
         case 39: 
-            line_width = atof(data->value) / width_scale;
+            line_width = atof(data->value) * WIDTH_SCALE;
             break;
         case 40: 
-            radius = atof(data->value) / coord_scale;
+            radius = atof(data->value) * coord_scale * measure_scale;
             break;
         }
         
@@ -272,6 +669,8 @@
     
     ellipse_obj->ops->set_props(ellipse_obj, props);
     prop_list_free(props);
+   
+   return( ellipse_obj );
 }
 
 static PropDescription dxf_arc_prop_descs[] = {
@@ -283,7 +682,8 @@
     PROP_DESC_END};
 
 /* reads a circle entity from the dxf file and creates a circle object in dia*/
-void read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
+Object *read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
     int codedxf;
     char *old_locale;
     
@@ -303,14 +703,14 @@
     RealProperty *rprop;
     GPtrArray *props;
 
-    real line_width = 0.1;
+    real line_width = DEFAULT_LINE_WIDTH;
     Layer *layer = NULL;
 		
     old_locale = setlocale(LC_NUMERIC, "C");
     do {
         if(read_dxf_codes(filedxf, data) == FALSE){
             setlocale(LC_NUMERIC,old_locale);
-            return;
+            return( NULL );
         }
         codedxf = atoi(data->code);
         switch(codedxf){
@@ -318,16 +718,16 @@
             layer = layer_find_by_name(data->value, dia);
             break;
         case 10: 
-            center.x = atof(data->value) / coord_scale;
+            center.x = atof(data->value) * coord_scale * measure_scale;
             break;
         case 20: 
-            center.y = (-1)*atof(data->value) / coord_scale;
+            center.y = (-1)*atof(data->value) * coord_scale * measure_scale;
             break;
         case 39: 
-            line_width = atof(data->value) / width_scale;
+            line_width = atof(data->value) * WIDTH_SCALE;
             break;
         case 40: 
-            radius = atof(data->value) / coord_scale;
+            radius = atof(data->value) * coord_scale * measure_scale;
             break;
         case 50:
             start_angle = atof(data->value)*M_PI/180.0;
@@ -373,10 +773,12 @@
     
     arc_obj->ops->set_props(arc_obj, props);
     prop_list_free(props);
+   
+   return( arc_obj );
 }
 
 /* reads an ellipse entity from the dxf file and creates an ellipse object in dia*/
-void read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
+Object *read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
     int codedxf;
     char *old_locale;
     
@@ -396,14 +798,14 @@
     ColorProperty *cprop;
     GPtrArray *props;
 
-    real line_width = 0.1;
+    real line_width = DEFAULT_LINE_WIDTH;
     Layer *layer = NULL;
     
     old_locale = setlocale(LC_NUMERIC, "C");
     do {
         if(read_dxf_codes(filedxf, data) == FALSE){
             setlocale(LC_NUMERIC, old_locale);
-            return;
+            return( NULL );
         }
         codedxf = atoi(data->code);
         switch(codedxf){
@@ -411,16 +813,16 @@
             layer = layer_find_by_name(data->value, dia);
             break;
         case 10: 
-            center.x = atof(data->value) / coord_scale;
+            center.x = atof(data->value) * coord_scale * measure_scale;
             break;
         case 11: 
-            ratio_width_height = atof(data->value) / coord_scale;
+            ratio_width_height = atof(data->value) * coord_scale * measure_scale;
             break;
         case 20: 
-            center.y = (-1)*atof(data->value) / coord_scale;
+            center.y = (-1)*atof(data->value) * coord_scale * measure_scale;
             break;
         case 39: 
-            line_width = atof(data->value) / width_scale;
+            line_width = atof(data->value) * WIDTH_SCALE;
             break;
         case 40: 
             width = atof(data->value) * 2; /* XXX what scale */
@@ -453,22 +855,25 @@
     
     ellipse_obj->ops->set_props(ellipse_obj, props);
     prop_list_free(props);
+   
+   return( ellipse_obj );
 }
 
 static PropDescription dxf_text_prop_descs[] = {
     { "text", PROP_TYPE_TEXT },
     PROP_DESC_END};
 
-void read_entity_text_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+Object *read_entity_text_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
 {
-    int codedxf;
+   int codedxf, colour;
     char *old_locale;
     
     /* text data */
     Point location;
-    real height = 10.0;
+   real height = text_scale * coord_scale * measure_scale;
+   real y_offset = 0;
     Alignment textalignment = ALIGN_LEFT;
-    char *textvalue = NULL;
+   char *textvalue = NULL, *textp;
     
     ObjectType *otype = object_get_type("Standard - Text");
     Handle *h1, *h2;
@@ -485,36 +890,106 @@
     do {
         if (read_dxf_codes(filedxf, data) == FALSE) {
             setlocale(LC_NUMERIC,old_locale);
-            return;
+            return( NULL );
         }
         codedxf = atoi(data->code);
         switch (codedxf) {
-        case  1: textvalue = g_strdup(data->value);
+        case  1: 
+	   textvalue = g_strdup(data->value);
+	   textp = textvalue;
+	   /* FIXME - poor tab to space converter */
+	   do 
+	     {
+		if( textp[0] == '^' && textp[1] == 'I' )
+		  {
+		     textp[0] = ' ';
+		     textp[1] = ' ';
+		     textp++;
+		  }
+		
+	     }
+	   while( *(++textp) != '\0' );
+		
+	   /*printf( "Found text: %s\n", textvalue );*/
             break;
         case  8: layer = layer_find_by_name(data->value, dia);
             break;
         case 10: 
-            location.x = atof(data->value) / coord_scale;
+            location.x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "Found text location x: %f\n", location.x );*/
+            break;
+        case 11:
+            location.x = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "Found text location x: %f\n", location.x );*/
             break;
         case 20:
-            location.y = (-1)*atof(data->value) / coord_scale;
+            location.y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "Found text location y: %f\n", location.y );*/
+            break;
+        case 21:
+            location.y = (-1)*atof(data->value) * coord_scale * measure_scale;
+	   /*location.y = (-1)*atof(data->value) / text_scale;*/
+	   printf( "Found text location y: %f\n", location.y );
             break;
         case 40: 
-            height = atof(data->value) / coord_scale;
+            height = atof(data->value) * coord_scale * measure_scale;
+	   /*printf( "text height %f\n", height );*/
+            break;
+	 case 62: 
+	   colour = atoi(data->value);
+	   text_colour.red = acad_pal[colour].r / 255.0;
+	   text_colour.green = acad_pal[colour].g / 255.0;
+	   text_colour.blue = acad_pal[colour].b / 255.0;
             break;
         case 72: 
-            switch(atoi(data->value)){
-            case 0: textalignment = ALIGN_LEFT;
+	   switch(atoi(data->value))
+	     {
+	      case 0:
+		textalignment = ALIGN_LEFT;
                 break;
-            case 1: textalignment = ALIGN_CENTER;
+	      case 1: 
+		textalignment = ALIGN_CENTER;
                 break;
-            case 2: textalignment = ALIGN_RIGHT;
+	      case 2: 
+		textalignment = ALIGN_RIGHT;
+                break;	
+	      case 3:
+		// FIXME - it's not clear what these are
+                break;
+	      case 4: 
+		// FIXME - it's not clear what these are
+                break;	
+	      case 5: 
+		// FIXME - it's not clear what these are
+                break;	
+            }
+	   break;
+        case 73: 
+	   switch(atoi(data->value))
+	     {
+	      case 0:
+	      case 1:
+		// FIXME - not really the same vertical alignment
+		// 0 = baseline
+		// 1 = bottom
+		y_offset = 0;
+                break;
+	      case 2: 
+		// 2 = middle
+		y_offset = 0.5;
+                break;	
+	      case 3:
+		// 3 = top
+		y_offset = 1;
                 break;	
             }
+	   break;
         }
     } while(codedxf != 0);
     setlocale(LC_NUMERIC,old_locale);
   
+   location.y += y_offset * height;
+   
     text_obj = otype->ops->create(&location, otype->default_user_data,
                                   &h1, &h2);
     layer_add_object(layer, text_obj);
@@ -527,17 +1002,19 @@
     tprop->attr.alignment = textalignment;
     tprop->attr.position.x = location.x;
     tprop->attr.position.y = location.y;
-    tprop->attr.font = dia_font_new_from_style(DIA_FONT_MONOSPACE,height);
+    tprop->attr.font = font_getfont(_("Courier"));
     tprop->attr.height = height;
+   tprop->attr.color = text_colour;
         
     text_obj->ops->set_props(text_obj, props);
     prop_list_free(props);
+   
+   return( text_obj );
 }
 
 /* reads the layer table from the dxf file and creates the layers */
 void read_table_layer_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
     int codedxf;
-    Layer *layer;
 	
     do {
         if(read_dxf_codes(filedxf, data) == FALSE){
@@ -546,13 +1023,129 @@
         else {
             codedxf = atoi(data->code);
             if(codedxf == 2){
-                layer = new_layer(g_strdup(data->value));
-                data_add_layer(dia, layer);	
+	       layer_find_by_name( data->value, dia );
             }
         }
     } while ((codedxf != 0) || (strcmp(data->value, "ENDTAB") != 0));
 }
 
+/* reads a scale entity from the dxf file */
+void read_entity_scale_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
+   int codedxf;
+
+   if(read_dxf_codes(filedxf, data) == FALSE)
+      return;
+
+   codedxf = atoi(data->code);
+       
+   switch(codedxf)
+     {
+      case 40: 
+	coord_scale = atof(data->value);
+	printf( "Scale: %f\n", coord_scale );
+	break;
+      
+      default:
+	break;
+     }	
+   
+}
+
+/* reads a scale entity from the dxf file */
+void read_entity_measurement_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
+{
+    int codedxf;
+
+   if(read_dxf_codes(filedxf, data) == FALSE)
+      return;
+
+   codedxf = atoi(data->code);
+       
+   switch(codedxf)
+     {
+      case 70:
+	// value 0 = English, 1 = Metric
+	if( atoi( data->value ) == 0 )
+	  measure_scale = 2.54;
+	else
+	  measure_scale = 1.0;
+	/*printf( "Measure Scale: %f\n", measure_scale );*/
+	break;
+      
+      default:
+	break;
+     }	
+   
+}
+
+/* reads a textsize entity from the dxf file */
+void read_entity_textsize_dxf(FILE *filedxf, DxfData *data, DiagramData *dia){
+   int codedxf;
+
+   if(read_dxf_codes(filedxf, data) == FALSE)
+     return;
+     
+   codedxf = atoi(data->code);
+
+   switch(codedxf)
+     {
+      case 40:
+	text_scale = atof(data->value);
+	/*printf( "Text Size: %f\n", text_scale );*/
+	break;		
+      default:
+	break;
+     }	
+
+}
+
+/* reads the headers section of the dxf file */
+void read_section_header_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) {
+    int codedxf;
+	
+    if(read_dxf_codes(filedxf, data) == FALSE){
+        return;
+    }
+    do {
+       codedxf = atoi(data->code);
+       if((codedxf == 9) && (strcmp(data->value, "$DIMSCALE") == 0)) {
+	  read_entity_scale_dxf(filedxf, data, dia);
+        } else if((codedxf == 9) && (strcmp(data->value, "$TEXTSIZE") == 0)) {
+	  read_entity_textsize_dxf(filedxf, data, dia);
+        } else if((codedxf == 9) && (strcmp(data->value, "$MEASUREMENT") == 0)) {
+	  read_entity_measurement_dxf(filedxf, data, dia);
+        } else {
+	   if(read_dxf_codes(filedxf, data) == FALSE){
+	      return;
+	   }
+	   
+	}
+    } while ((codedxf != 0) || (strcmp(data->value, "ENDSEC") != 0));
+}
+
+/* reads the classes section of the dxf file */
+void read_section_classes_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) {
+    int codedxf;
+	
+    if(read_dxf_codes(filedxf, data) == FALSE){
+        return;
+    }
+    do {
+       codedxf = atoi(data->code);
+       if((codedxf == 9) && (strcmp(data->value, "$LTSCALE") == 0)) {
+	  read_entity_scale_dxf(filedxf, data, dia);
+        } else if((codedxf == 9) && (strcmp(data->value, "$TEXTSIZE") == 0)) {
+	  read_entity_textsize_dxf(filedxf, data, dia);
+        } else {
+	   if(read_dxf_codes(filedxf, data) == FALSE){
+	      return;
+	   }
+	   
+	}
+    } while ((codedxf != 0) || (strcmp(data->value, "ENDSEC") != 0));
+}
+
 /* reads the tables section of the dxf file */
 void read_section_tables_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) {
     int codedxf;
@@ -584,6 +1177,12 @@
     do {  
         if((codedxf == 0) && (strcmp(data->value, "LINE") == 0)) {
             read_entity_line_dxf(filedxf, data, dia);
+        } else if((codedxf == 0) && (strcmp(data->value, "VERTEX") == 0)) {
+            read_entity_line_dxf(filedxf, data, dia);
+        } else if((codedxf == 0) && (strcmp(data->value, "SOLID") == 0)) {
+            read_entity_solid_dxf(filedxf, data, dia);
+        } else if((codedxf == 0) && (strcmp(data->value, "POLYLINE") == 0)) {
+            read_entity_polyline_dxf(filedxf, data, dia);
         } else if((codedxf == 0) && (strcmp(data->value, "CIRCLE") == 0)) {
             read_entity_circle_dxf(filedxf, data, dia);
         } else if((codedxf == 0) && (strcmp(data->value, "ELLIPSE") == 0)) {
@@ -593,9 +1192,6 @@
         } else if((codedxf == 0) && (strcmp(data->value, "ARC") == 0)) {
                read_entity_arc_dxf(filedxf,data,dia);
         } else {
-            /* if (codedxf == 0) {
-                g_warning("unknown DXF entity: %s",data->value);
-                }*/
             if(read_dxf_codes(filedxf, data) == FALSE) {
                 return;
             }
@@ -604,6 +1200,93 @@
     } while((codedxf != 0) || (strcmp(data->value, "ENDSEC") != 0));
 }
 
+/* reads the blocks section of the dxf file */
+void read_section_blocks_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) 
+{
+   int codedxf, group_items = 0, group;
+   GList *group_list;
+   Object *obj = NULL;
+   Layer *group_layer = NULL;
+   
+   if (read_dxf_codes(filedxf, data) == FALSE){
+      return;		
+   }
+   codedxf = atoi(data->code);
+   do {  
+      if((codedxf == 0) && (strcmp(data->value, "LINE") == 0)) {
+	 read_entity_line_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "SOLID") == 0)) {
+	 obj = read_entity_solid_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "VERTEX") == 0)) {
+	 read_entity_line_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "POLYLINE") == 0)) {
+	 obj = read_entity_polyline_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "CIRCLE") == 0)) {
+	 read_entity_circle_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "ELLIPSE") == 0)) {
+	 read_entity_ellipse_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "TEXT") == 0)) {
+	 obj = read_entity_text_dxf(filedxf, data, dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "ARC") == 0)) {
+	 read_entity_arc_dxf(filedxf,data,dia);
+      } else if((codedxf == 0) && (strcmp(data->value, "BLOCK") == 0)) {
+	 printf( "Begin group\n" );
+	 
+	 group = TRUE;
+	 group_items = 0;
+	 group_list = NULL;
+	 group_layer = NULL;
+	 
+	 do {
+	    if(read_dxf_codes(filedxf, data) == FALSE)
+	      return;
+
+	    codedxf = atoi(data->code);
+
+	    if( codedxf == 8 )
+	      group_layer = layer_find_by_name( data->value, dia ); 
+
+	 } while( codedxf != 0 );
+	
+      } else if((codedxf == 0) && (strcmp(data->value, "ENDBLK") == 0)) {
+	 printf( "End group %d\n", group_items );
+
+	 if( group && group_items > 0 && group_list != NULL )
+	   {
+	      obj = group_create( group_list );
+	      if( NULL == group_layer )
+		layer_add_object( dia->active_layer, obj );
+	      else
+		layer_add_object( group_layer, obj );
+	   }
+	 
+	 group = FALSE;
+	 group_items = 0;
+	 group_list = NULL;
+	 obj = NULL;
+				  
+	 if(read_dxf_codes(filedxf, data) == FALSE)
+	   return;
+	 
+      } else {
+	 if(read_dxf_codes(filedxf, data) == FALSE) {
+	    return;
+	 }
+      }
+      
+      if( group && obj != NULL )
+	{
+	   group_items++;
+
+	   group_list = g_list_prepend( group_list, obj );
+	   
+	   obj = NULL;
+	}
+      
+      codedxf = atoi(data->code);		
+   } while((codedxf != 0) || (strcmp(data->value, "ENDSEC") != 0));
+}
+
 /* imports the given dxf-file, returns TRUE if successful */
 gboolean import_dxf(const gchar *filename, DiagramData *dia, void* user_data){
     FILE *filedxf;
@@ -621,18 +1304,39 @@
     do {
         if(read_dxf_codes(filedxf, data) == FALSE) {
             g_free(data);
+	   printf( "read_dxf_codes failed\n" );
             return FALSE;
         }
         else {
             codedxf = atoi(data->code);
             if(codedxf == 2) {
                 if(strcmp(data->value, "ENTITIES") == 0) {
+		   /*printf( "reading section entities\n" );*/
                     read_section_entities_dxf(filedxf, data, dia);
                 }
+                else if(strcmp(data->value, "BLOCKS") == 0) {
+		   /*printf( "reading section BLOCKS\n" );*/
+                    read_section_blocks_dxf(filedxf, data, dia);
+                }
+                else if(strcmp(data->value, "CLASSES") == 0) {
+		   /*printf( "reading section CLASSES\n" );*/
+                    read_section_classes_dxf(filedxf, data, dia);
+                }
+                else if(strcmp(data->value, "HEADER") == 0) {
+		   /*printf( "reading section HEADER\n" );*/
+                    read_section_header_dxf(filedxf, data, dia);
+                }
                 else if(strcmp(data->value, "TABLES") == 0) {
+		  /*printf( "reading section tables\n" );*/
                     read_section_tables_dxf(filedxf, data, dia);
                 }
+	       else if(strcmp(data->value, "OBJECTS") == 0) {
+		  /*printf( "reading section objects\n" );*/
+                    read_section_entities_dxf(filedxf, data, dia);
             }
+	    }
+	   else
+	     printf( "Unknown dxf code %d\n", codedxf );
         }
     }while((codedxf != 0) || (strcmp(data->value, "EOF") != 0));
     


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index] Mail converted by Mofo Magic and the Flying D

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

GuideSMACK