示例#1
0
文件: undo.c 项目: krattai/monoflow
static void
group_objects_apply(struct GroupObjectsChange *change, Diagram *dia)
{
  GList *list;

  DEBUG_PRINTF(("group_objects_apply()\n"));
  
  change->applied = 1;
  
  diagram_unselect_objects(dia, change->obj_list);
  layer_remove_objects(change->layer, change->obj_list);
  layer_add_object(change->layer, change->group);
  object_add_updates(change->group, dia);

  list = change->obj_list;
  while (list != NULL) {
    DiaObject *obj = (DiaObject *)list->data;
    
  /* Have to hide any open properties dialog
     if it contains some object in cut_list */
    properties_hide_if_shown(dia, obj);

    object_add_updates(obj, dia);

    list = g_list_next(list);
  }

  diagram_tree_add_object(diagram_tree(), dia, change->group);
  diagram_tree_remove_objects(diagram_tree(), change->obj_list);
}
示例#2
0
文件: diagram.c 项目: brunetton/dia
void
diagram_add_object(Diagram *dia, DiaObject *obj)
{
  layer_add_object(dia->data->active_layer, obj);

  diagram_modified(dia);
}
/* imports the given SVG file, returns TRUE if successful */
gboolean
import_drs (const gchar *filename, DiagramData *dia, void* user_data) 
{
  GList *item, *items;
  xmlDocPtr doc = xmlParseFile(filename);

  items = read_items (doc->xmlChildrenNode);
  for (item = items; item != NULL; item = g_list_next (item)) {
    DiaObject *obj = (DiaObject *)item->data;
    layer_add_object(dia->active_layer, obj);
  }
  g_list_free (items);
  xmlFreeDoc(doc);
  return TRUE;
}
示例#4
0
/* imports the given DRS file, returns TRUE if successful */
gboolean
import_drs (const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data) 
{
  GList *item, *items;
  xmlDocPtr doc = xmlParseFile(filename);
  xmlNodePtr root = NULL, node;
  Layer *active_layer = NULL;

  for (node = doc->children; node; node = node->next)
    if (xmlStrcmp (node->name, (const xmlChar *)"drs") == 0)
      root = node;

  if (!root || !(root = find_child_named (root, "diagram"))) {
    dia_context_add_message (ctx, _("Broken file?"));
    return FALSE;
  }

  for (node = root->children; node != NULL; node = node->next) {
    if (xmlStrcmp (node->name, (const xmlChar *)"layer") == 0) {
      xmlChar *str;
      xmlChar *name = xmlGetProp (node, (const xmlChar *)"name");
      Layer *layer = new_layer (g_strdup (name ? (gchar *)name : _("Layer")), dia);

      if (name)
	xmlFree (name);

      str = xmlGetProp (node, (const xmlChar *)"active");
      if (xmlStrcmp (str, (const xmlChar *)"true")) {
	  active_layer = layer;
	xmlFree (str);
      }

      items = read_items (node->children, ctx);
      for (item = items; item != NULL; item = g_list_next (item)) {
        DiaObject *obj = (DiaObject *)item->data;
        layer_add_object(layer, obj);
      }
      g_list_free (items);
      data_add_layer (dia, layer);
    }
  }
  if (active_layer)
    data_set_active_layer (dia, active_layer);
  xmlFreeDoc(doc);
  return TRUE;
}
示例#5
0
文件: pixbuf.c 项目: GNOME/dia
static gboolean
import_data (const gchar *filename, DiagramData *data, DiaContext *ctx, void* user_data)
{
  DiaObjectType *otype = object_get_type("Standard - Image");
  gint width, height;

  if (!otype) /* this would be really broken */
    return FALSE;

  if (!user_data) {
    dia_context_add_message(ctx, _("Calling error, missing user_data."));
    return FALSE;
  }

  if (gdk_pixbuf_get_file_info (filename, &width, &height))
    {
      DiaObject *obj;
      Handle *h1, *h2;
      Point point;
      point.x = point.y = 0.0;

      obj = otype->ops->create(&point, otype->default_user_data, &h1, &h2);
      if (obj)
        {
          GPtrArray *plist = g_ptr_array_new ();

          prop_list_add_filename (plist, "image_file", filename);
          prop_list_add_real (plist, "elem_width", width / 20.0);
          prop_list_add_real (plist, "elem_height", height / 20.0);

          obj->ops->set_props(obj, plist);
          prop_list_free (plist);

          layer_add_object(data->active_layer, obj);
          return TRUE;
        }
    }
  else
    {
      dia_context_add_message(ctx, _("Pixbuf[%s] can't load:\n%s"), 
			      (gchar*)user_data, dia_context_get_filename(ctx));
    }

  return FALSE;
}
示例#6
0
  //! push the current list of objects to Dia
  void endPage()
  {
    DiaObject *group;
    g_return_if_fail (objects != NULL);

    int m = (int)sqrt (num_pages);
    if (m < 2)
      m = 2;
    gchar *name = g_strdup_printf (_("Page %d"), this->pageNum);
    group = create_standard_group (this->objects);
    this->objects = NULL; // Group eats list
    // page advance
    Point advance = { this->page_width * ((this->pageNum - 1) % m),
		      this->page_height * ((this->pageNum - 1) / m)};
    group->ops->move (group, &advance);
    layer_add_object (this->dia->active_layer, group);
    dia_object_set_meta (group, "name", name);
    g_free (name);
  }
示例#7
0
void
dia::Layer::add_object (Object* o)
{
    g_return_if_fail (self != NULL);
    layer_add_object (self, o->Self());
}
示例#8
0
/* reads an ellipse entity from the dxf file and creates an ellipse object in dia*/
static DiaObject *
read_entity_ellipse_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    /* ellipse data */
    Point center = {0, 0};
    real width = 1.0;
    real ratio_width_height = 1.0;
    
    DiaObjectType *otype = object_get_type("Standard - Ellipse");
    Handle *h1, *h2;
    
    DiaObject *ellipse_obj; 
    RGB_t color = { 0, };
    Color line_colour;
    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    Layer *layer = dia->active_layer;
    
    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case  8: 
            layer = layer_find_by_name(data->value, dia);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10: 
            center.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 11: 
            ratio_width_height = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 20: 
            center.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
            break;
        case 40: 
            width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE; /* XXX what scale */
            break;
	case 62 :
            color = pal_get_rgb (atoi(data->value));
            break;
        }
    } while(data->code != 0);
 
    center.x -= width;
    center.y -= (width*ratio_width_height);
    ellipse_obj = otype->ops->create(&center, otype->default_user_data,
                                     &h1, &h2);

    _color_init_from_rgb (&line_colour, color);

    props = g_ptr_array_new ();

    prop_list_add_point (props, "elem_corner", &center);
    prop_list_add_real (props, "elem_width", width);
    prop_list_add_real (props, "elem_height", width * ratio_width_height);
    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    prop_list_add_show_background (props, FALSE);
    
    ellipse_obj->ops->set_props(ellipse_obj, props);
    prop_list_free(props);

    if (layer)
        layer_add_object(layer, ellipse_obj);
    else
        return ellipse_obj;

    return NULL; /* don't add it twice */
}
示例#9
0
static DiaObject *
read_entity_text_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    RGB_t color = { 0, };

    /* text data */
    Point location = {0, 0};
    real height = text_scale * coord_scale * measure_scale;
    real y_offset = 0;
    Alignment textalignment = ALIGN_LEFT;
    char *textvalue = NULL, *textp;
    
    DiaObjectType *otype = object_get_type("Standard - Text");
    Handle *h1, *h2;
    
    DiaObject *text_obj;
    Color text_colour;

    TextProperty *tprop;
    GPtrArray *props;

    Layer *layer = dia->active_layer;

    do {
        if (read_dxf_codes(filedxf, data) == FALSE) {
            return( NULL );
        }
        switch (data->code) {
        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);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10: 
            location.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "Found text location x: %f\n", location.x );*/
            break;
        case 11:
            location.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "Found text location x: %f\n", location.x );*/
            break;
        case 20:
            location.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "Found text location y: %f\n", location.y );*/
            break;
        case 21:
            location.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*location.y = (-1)*g_ascii_strtod(data->value, NULL) / text_scale;*/
	   /*printf( "Found text location y: %f\n", location.y );*/
            break;
        case 40: 
            height = g_ascii_strtod(data->value, NULL) * text_scale * coord_scale * measure_scale;
	   /*printf( "text height %f\n", height );*/
            break;
	 case 62: 
	    color = pal_get_rgb (atoi(data->value));
            break;
        case 72: 
	   switch(atoi(data->value))
	     {
	      case 0:
		textalignment = ALIGN_LEFT;
                break;
	      case 1: 
		textalignment = ALIGN_CENTER;
                break;
	      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(data->code != 0);
  
    location.y += y_offset * height;
    _color_init_from_rgb (&text_colour, color);
    text_obj = otype->ops->create(&location, otype->default_user_data,
                                  &h1, &h2);
    props = prop_list_from_descs(dxf_text_prop_descs,pdtpp_true);
    g_assert(props->len == 1);

    tprop = g_ptr_array_index(props,0);
    g_free(tprop->text_data);
    tprop->text_data = textvalue;
    tprop->attr.alignment = textalignment;
    tprop->attr.position.x = location.x;
    tprop->attr.position.y = location.y;

    attributes_get_default_font(&tprop->attr.font, &tprop->attr.height);
    tprop->attr.color = text_colour;
    tprop->attr.height = height;
        
    text_obj->ops->set_props(text_obj, props);
    prop_list_free(props);
   
    if (layer)
        layer_add_object(layer, text_obj);
    else
        return text_obj;

    return NULL; /* don't add it twice */
}
示例#10
0
/* reads a circle entity from the dxf file and creates a circle object in dia*/
static DiaObject *
read_entity_arc_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    /* arc data */
    Point start, end;
    Point center = {0, 0};
    real radius = 1.0, start_angle = 0.0, end_angle=360.0;
    real curve_distance;

    DiaObjectType *otype = object_get_type("Standard - Arc");  
    Handle *h1, *h2;
  
    DiaObject *arc_obj;
    RGB_t color  = { 0, };
    Color line_colour;
    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    Layer *layer = dia->active_layer;
		
    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case  8: 
            layer = layer_find_by_name(data->value, dia);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10: 
            center.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 20: 
            center.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
            break;
        case 40: 
            radius = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 50:
            start_angle = g_ascii_strtod(data->value, NULL)*M_PI/180.0;
            break;
        case 51:
            end_angle = g_ascii_strtod(data->value, NULL)*M_PI/180.0;
            break;
	case 62 :
            color = pal_get_rgb (atoi(data->value));
            break;
        }
    } while(data->code != 0);

    /* printf("c.x=%f c.y=%f s",center.x,center.y); */
    start.x = center.x + cos(start_angle) * radius; 
    start.y = center.y - sin(start_angle) * radius;
    end.x = center.x + cos(end_angle) * radius;
    end.y = center.y - sin(end_angle) * radius;
    /*printf("s.x=%f s.y=%f e.x=%f e.y=%f\n",start.x,start.y,end.x,end.y);*/


    if (end_angle < start_angle) end_angle += 2.0*M_PI;
    curve_distance = radius * (1 - cos ((end_angle - start_angle)/2));

    /*printf("start_angle: %f end_angle: %f radius:%f  curve_distance:%f\n",
      start_angle,end_angle,radius,curve_distance);*/
   
    arc_obj = otype->ops->create(&center, otype->default_user_data,
                                     &h1, &h2);
    
    _color_init_from_rgb (&line_colour, color);

    props = g_ptr_array_new ();
    prop_list_add_point (props, "start_point", &start);
    prop_list_add_point (props, "end_point", &end);
    prop_list_add_real (props, "curve_distance", curve_distance);
    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    
    arc_obj->ops->set_props(arc_obj, props);
    prop_list_free(props);
   
    if (layer)
        layer_add_object(layer, arc_obj);
    else
        return arc_obj ;

    return NULL; /* don't add it twice */
}
示例#11
0
/* reads a polyline entity from the dxf file and creates a polyline object in dia*/
static DiaObject *
read_entity_polyline_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    int i;
   
        /* polygon data */
    Point *p = NULL, start, end, center;
    
    DiaObjectType *otype = object_get_type("Standard - PolyLine");
    Handle *h1, *h2;
    
    DiaObject *polyline_obj;
    MultipointCreateData *pcd;

    Color line_colour;

    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    real radius, start_angle = 0;
    LineStyle style = LINESTYLE_SOLID;
    Layer *layer = dia->active_layer;
    RGB_t color = { 0, };
    unsigned char closed = 0;
    int points = 0;
    real bulge = 0.0;
    int bulge_end = -1;
    gboolean bulge_x_avail = FALSE, bulge_y_avail = FALSE;

    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
            case 0:
                if( !strcmp( data->value, "VERTEX" ))
                {
                    points++;
		
                    p = g_realloc( p, sizeof( Point ) * points );
		
                        /*printf( "Vertex %d\n", points );*/
		  
                }
		break;	   
            case 6:	 
                style = get_dia_linestyle_dxf(data->value);
                break;		
            case  8: 
                layer = layer_find_by_name(data->value, dia);
	        color = pal_get_rgb (_dxf_color_get_by_layer (layer));
                    /*printf( "layer: %s ", data->value );*/
                break;
            case 10:
                if( points != 0 )
                {
                    p[points-1].x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
                        /*printf( "P[%d].x: %f ", points-1, p[points-1].x );*/
		    bulge_x_avail = (bulge_end == points);
                }
                break;
            case 20: 
                if( points != 0 )
                {
                    p[points-1].y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
                        /*printf( "P[%d].y: %f\n", points-1, p[points-1].y );*/
		    bulge_y_avail = (bulge_end == points);
                }
                break;
            case 39: 
                line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
                    /*printf( "width %f\n", line_width );*/
                break;
	    case 40: /* default starting width */
	    case 41: /* default ending width */
	        line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
		break;
            case 42:
                bulge = g_ascii_strtod(data->value, NULL);
		/* The bulge is meant to be _between_ two VERTEX, here: p[points-1] and p[points,]
		 * but we have not yet read the end point; so just remember the point to 'bulge to' */
		bulge_end = points+1;
		bulge_x_avail = bulge_y_avail = FALSE;
                break;
            case 62: 
                color = pal_get_rgb (atoi(data->value));
                break;
            case 70:
                closed = 1 & atoi( data->value );
                    /*printf( "closed %d %s", closed, data->value );*/
                break;
        }
	if (points == bulge_end && bulge_x_avail && bulge_y_avail) {
	    /* turn the last segment into a bulge */

                p = g_realloc( p, sizeof( Point ) * ( points + 10 ));

                if (points < 2)
                    continue;
                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( is_equal( start.x, end.x ))
                {
                    if( is_equal( start.y, end.y ))
                    {
                        continue; /* better than complaining? */
                        g_warning("Bad vertex bulge");
                    }
                    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( is_equal( start.y, end.y ))
                {
                    if( is_equal( start.x, end.x ))
                    {
                        continue;
                        g_warning("Bad vertex bulge");
                    }
                    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 * bulge);
                        /*printf( "i %d x %f y %f\n", i, p[i].x, p[i].y );*/
                }
                points += 10;
	   
                p[points-1] = end;
	  
	}
    } while( strcmp( data->value, "SEQEND" ));
   
    if( points == 0 )
    {
        printf( "No vertexes defined\n" );
        return( NULL );
    }
   
    pcd = g_new( MultipointCreateData, 1);
   
    if( closed )
    {
	otype = object_get_type("Standard - Polygon");
    }
   
    pcd->num_points = points;
    pcd->points = g_new( Point, pcd->num_points );
   
    memcpy( pcd->points, p, sizeof( Point ) * pcd->num_points );
   
    g_free( p );

    polyline_obj = otype->ops->create( NULL, pcd, &h1, &h2 );

    _color_init_from_rgb (&line_colour, color);

    props = g_ptr_array_new ();

    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    prop_list_add_line_style (props, style, 1.0);

    polyline_obj->ops->set_props( polyline_obj, props );

    prop_list_free(props);

    if (layer)
       layer_add_object( layer, polyline_obj );
    else
       return polyline_obj;
       
    return NULL; /* don't add it twice */
}
示例#12
0
/* reads a solid entity from the dxf file and creates a polygon object in dia*/
static DiaObject *
read_entity_solid_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
   /* polygon data */
   Point p[4];
   
   DiaObjectType *otype = object_get_type("Standard - Polygon");  
   Handle *h1, *h2;
   
   DiaObject *polygon_obj;
   MultipointCreateData *pcd;

   Color fill_colour;

   GPtrArray *props;
   
   real line_width = 0.001;
   LineStyle style = LINESTYLE_SOLID;
   Layer *layer = dia->active_layer;
   RGB_t color  = { 127, 127, 127 };
   
/*   printf( "Solid " ); */

   memset(p, 0, sizeof(p));

    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case 6:	 
	   style = get_dia_linestyle_dxf(data->value);
	   break;		
        case  8: 
	   layer = layer_find_by_name(data->value, dia);
	   color = pal_get_rgb (_dxf_color_get_by_layer (layer));
	   /*printf( "layer: %s ", data->value );*/
	   break;
        case 10:
	   p[0].x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P0.x: %f ", p[0].x );*/
	   break;
        case 11: 
            p[1].x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P1.x: %f ", p[1].x );*/
            break;
        case 12: /* bot only swapped, but special for only 3 points given */
            p[2].x = p[3].x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P2.x: %f ", p[2].x );*/
            break;
        case 13: /* SOLID order swapped compared to Dia's */
            p[2].x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P3.x: %f ", p[3].x );*/
            break;
        case 20: 
            p[0].y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P0.y: %f ", p[0].y );*/
            break;
        case 21: 
            p[1].y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P1.y: %f ", p[1].y );*/
            break;
        case 22: 
            p[2].y = p[3].y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P2.y: %f ", p[2].y );*/
            break;
        case 23: 
            p[2].y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
	   /*printf( "P3.y: %f\n", p[3].y );*/
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
	   /*printf( "width %f\n", line_width );*/
            break;
        case 62: 
            color = pal_get_rgb (atoi(data->value));
            break;
        }	
    } while(data->code != 0);

   pcd = g_new( MultipointCreateData, 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 );

    _color_init_from_rgb (&fill_colour, color);

   props = g_ptr_array_new ();

   prop_list_add_line_colour (props, &fill_colour);
   prop_list_add_line_width (props, line_width);
   prop_list_add_line_style (props, style, 1.0);
   prop_list_add_fill_colour (props, &fill_colour);
   prop_list_add_show_background (props, TRUE);

   polygon_obj->ops->set_props( polygon_obj, props );

   prop_list_free(props);

   if (layer)
      layer_add_object( layer, polygon_obj );
   else
      return polygon_obj;

   return NULL;
}
示例#13
0
/* reads a line entity from the dxf file and creates a line object in dia*/
static DiaObject *
read_entity_line_dxf(FILE *filedxf, DxfData *data, DiagramData *dia)
{
    /* line data */
    Point start, end;
    
    DiaObjectType *otype = object_get_type("Standard - Line");  
    Handle *h1, *h2;
    
    DiaObject *line_obj;
    Color line_colour;
    RGB_t color = { 0, };
    GPtrArray *props;

    real line_width = DEFAULT_LINE_WIDTH;
    LineStyle style = LINESTYLE_SOLID;
    Layer *layer = dia->active_layer;
    
    end.x=0;
    end.y=0;

    props = g_ptr_array_new();

    do {
        if(read_dxf_codes(filedxf, data) == FALSE){
            return( NULL );
        }
        switch(data->code){
        case 6:	 style = get_dia_linestyle_dxf(data->value);
            break;		
        case  8: 
	    layer = layer_find_by_name(data->value, dia);
	    color = pal_get_rgb (_dxf_color_get_by_layer (layer));
            break;
        case 10:
            start.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 11: 
            end.x = g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 20: 
            start.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 21: 
            end.y = (-1)*g_ascii_strtod(data->value, NULL) * coord_scale * measure_scale;
            break;
        case 39: 
            line_width = g_ascii_strtod(data->value, NULL) * WIDTH_SCALE;
	   /*printf( "line width %f\n", line_width ); */
            break;
	case 62 :
            color = pal_get_rgb (atoi(data->value));
            break;
        }	
    } while(data->code != 0);

    _color_init_from_rgb (&line_colour, color);
    line_obj = otype->ops->create(&start, otype->default_user_data,
                                  &h1, &h2);

    prop_list_add_point (props, "start_point", &start);
    prop_list_add_point (props, "end_point", &end);
    prop_list_add_line_colour (props, &line_colour);
    prop_list_add_line_width (props, line_width);
    prop_list_add_line_style (props, style, 1.0);

    line_obj->ops->set_props(line_obj, props);

    prop_list_free(props);

    if (layer)
      layer_add_object(layer, line_obj);
    else
      return line_obj;
    /* don't add it it twice */
    return NULL;
}
示例#14
0
/* reads the blocks section of the dxf file */
static void
read_section_blocks_dxf(FILE *filedxf, DxfData *data, DiagramData *dia) 
{
    int group_items = 0, group = 0;
    GList *group_list = NULL;
    DiaObject *obj = NULL;
    Layer *group_layer = NULL;
   
    if (read_dxf_codes(filedxf, data) == FALSE){
        return;		
    }
    do {  
        if((data->code == 0) && (strcmp(data->value, "LINE") == 0)) {
            obj = read_entity_line_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "SOLID") == 0)) {
            obj = read_entity_solid_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "VERTEX") == 0)) {
            read_entity_line_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "POLYLINE") == 0)) {
            obj = read_entity_polyline_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "CIRCLE") == 0)) {
            obj = read_entity_circle_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "ELLIPSE") == 0)) {
            obj = read_entity_ellipse_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "TEXT") == 0)) {
            obj = read_entity_text_dxf(filedxf, data, dia);
        } else if((data->code == 0) && (strcmp(data->value, "ARC") == 0)) {
            obj = read_entity_arc_dxf(filedxf,data,dia);
        } else if((data->code == 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;

                if(data->code == 8) {
                    group_layer = layer_find_by_name( data->value, dia );
		    data_set_active_layer (dia, group_layer);
		}

            } while(data->code != 0);
	
        } else if((data->code == 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;
        }
      
    } while((data->code != 0) || (strcmp(data->value, "ENDSEC") != 0));
}