Example #1
0
/** Allocates a new drill_stats structure
   @return drill_stats pointer on success, NULL on ERROR */
gerbv_drill_stats_t *
gerbv_drill_stats_new(void) {

    gerbv_drill_stats_t *stats;
    gerbv_drill_list_t *drill_list;
    gerbv_error_list_t *error_list;

    /* Malloc space for new stats struct.  Return NULL if error. */
    if ((stats = (gerbv_drill_stats_t *)g_malloc(sizeof(gerbv_drill_stats_t))) == NULL) {
        return NULL;
    }

    /* Set new stats struct to zero */
    memset((void *)stats, 0, sizeof(gerbv_drill_stats_t));

    /* Initialize drill list */
    drill_list = gerbv_drill_stats_new_drill_list();
    if (drill_list == NULL)
        GERB_FATAL_ERROR("malloc drill_list failed\n");
    stats->drill_list = (gerbv_drill_list_t *) drill_list;

    /* Initialize error list */
    error_list = gerbv_drill_stats_new_error_list();
    if (error_list == NULL)
        GERB_FATAL_ERROR("malloc error_list failed\n");
    stats->error_list = (gerbv_error_list_t *) error_list;

    stats->detect = NULL;

    return stats;
}
Example #2
0
/* ------------------------------------------------------- */
void
gerbv_stats_add_error(gerbv_error_list_t *error_list_in,
                      int layer, const char *error_text,
                      gerbv_message_type_t type) {

    gerbv_error_list_t *error_list_new;
    gerbv_error_list_t *error_last = NULL;
    gerbv_error_list_t *error;

    /* Replace embedded error messages */
    switch (type) {
        case GERBV_MESSAGE_FATAL:
            GERB_FATAL_ERROR("%s",error_text);
            break;
        case GERBV_MESSAGE_ERROR:
            GERB_COMPILE_ERROR("%s",error_text);
            break;
        case GERBV_MESSAGE_WARNING:
            GERB_COMPILE_WARNING("%s",error_text);
            break;
        case GERBV_MESSAGE_NOTE:
            break;
    }

    /* First handle case where this is the first list element */
    if (error_list_in->error_text == NULL) {
        error_list_in->layer = layer;
        error_list_in->error_text = g_strdup_printf("%s", error_text);
        error_list_in->type = type;
        error_list_in->next = NULL;
        return;
    }

    /* Next check to see if this error is already in the list */
    for(error = error_list_in; error != NULL; error = error->next) {
        if ((strcmp(error->error_text, error_text) == 0) &&
            (error->layer == layer) ) {
            return;  /* This error text is already in the error list */
        }
        error_last = error;  /* point to last element in error list */
    }
    /* This error text is unique.  Therefore, add it to the list */

    /* Now malloc space for new error list element */
    error_list_new = (gerbv_error_list_t *) g_malloc(sizeof(gerbv_error_list_t));
    if (error_list_new == NULL) {
        GERB_FATAL_ERROR(_("malloc error_list failed\n"));
    }

    /* Set member elements */
    error_list_new->layer = layer;
    error_list_new->error_text = g_strdup_printf("%s", error_text);
    error_list_new->type = type;
    error_list_new->next = NULL;
    error_last->next = error_list_new;

    return;
}
Example #3
0
/* ------------------------------------------------------- */
void
drill_stats_add_to_drill_list(gerbv_drill_list_t *drill_list_in, 
			      int drill_num_in, double drill_size_in,
			      char *drill_unit_in) {

    gerbv_drill_list_t *drill_list_new;
    gerbv_drill_list_t *drill;
    gerbv_drill_list_t *drill_last = NULL;

    dprintf ("%s(%p, %d, %g, \"%s\")\n", __FUNCTION__, drill_list_in, drill_num_in,
	     drill_size_in, drill_unit_in);

    dprintf("   ---> Entering drill_stats_add_to_drill_list, first drill_num in list = %d ...\n", 
	    drill_list_in->drill_num);

    /* First check for empty list.  If empty, then just add this drill */
    if (drill_list_in->drill_num == -1) {
	dprintf("    .... In drill_stats_add_to_drill_list, adding first drill, no %d\n", 
		drill_num_in);
	drill_list_in->drill_num = drill_num_in;
	drill_list_in->drill_size = drill_size_in;
	drill_list_in->drill_count = 0;
	drill_list_in->drill_unit = g_strdup_printf("%s", drill_unit_in);
	drill_list_in->next = NULL;
	return;
    }
    /* Else check to see if this drill is already in the list */
    for(drill = drill_list_in; 
	drill != NULL; 
	drill = (gerbv_drill_list_t *) drill->next) {
	dprintf("checking this drill_num %d against that in list %d.\n", 
		drill_num_in, drill->drill_num);
	if (drill_num_in == drill->drill_num) {
	    dprintf("   .... In drill_stats_add_to_drill_list, drill no %d already in list\n", 
		    drill_num_in);
	    return;  /* Found it in list, so return */
	}
	drill_last = drill;
    }

    /* Now malloc space for new drill list element */
    drill_list_new = (gerbv_drill_list_t *) g_malloc(sizeof(gerbv_drill_list_t));
    if (drill_list_new == NULL) {
	GERB_FATAL_ERROR("malloc format failed\n");
    }

    /* Now set various parameters based upon calling args */
    dprintf("    .... In drill_stats_add_to_drill_list, adding new drill, no %d\n", 
	    drill_num_in);
    drill_list_new->drill_num = drill_num_in;
    drill_list_new->drill_size = drill_size_in;
    drill_list_new->drill_count = 0;
    drill_list_new->drill_unit = g_strdup_printf("%s", drill_unit_in);
    drill_list_new->next = NULL;
    drill_last->next = drill_list_new;

    dprintf("   <---- ... leaving drill_stats_add_to_drill_list.\n");
    return;
}
Example #4
0
void
gerb_fclose(gerb_file_t *fd)
{
    if (fd) {
#ifdef HAVE_SYS_MMAN_H
	if (munmap(fd->data, fd->datalen) < 0)
	    GERB_FATAL_ERROR("munmap: %s", strerror(errno));
#else
	g_free(fd->data);
#endif   
	if (fclose(fd->fd) == EOF)
	    GERB_FATAL_ERROR("fclose: %s", strerror(errno));
	g_free(fd);
    }

    return;
} /* gerb_fclose */
Example #5
0
/* ------------------------------------------------------- */
void
gerbv_stats_add_to_D_list(gerbv_aperture_list_t *D_list_in,
			 int number) {
  
  gerbv_aperture_list_t *D_list;
  gerbv_aperture_list_t *D_list_last=NULL;
  gerbv_aperture_list_t *D_list_new;

    dprintf("   ----> Entering add_to_D_list, numbr = %d\n", number);

    /* First handle case where this is the first list element */
    if (D_list_in->number == -1) {
	dprintf("     .... Adding first D code to D code list ... \n"); 
	dprintf("     .... Aperture number = %d ... \n", number); 
        D_list_in->number = number;
	D_list_in->count = 0;
        D_list_in->next = NULL;
	dprintf("   <---  .... Leaving add_to_D_list.\n"); 
        return;
    }

    /* Look to see if this is already in list */
    for(D_list = D_list_in; 
	D_list != NULL; 
	D_list = D_list->next) {
        if (D_list->number == number) {
  	    dprintf("    .... Found in D list .... \n");
	    dprintf("   <---  .... Leaving add_to_D_list.\n"); 
            return;  
        }
        D_list_last = D_list;  /* point to last element in list */
    }

    /* This aperture number is unique.  Therefore, add it to the list */
    dprintf("     .... Adding another D code to D code list ... \n"); 
	
    /* Malloc space for new aperture list element */
    D_list_new = (gerbv_aperture_list_t *) g_malloc(sizeof(gerbv_aperture_list_t));
    if (D_list_new == NULL) {
        GERB_FATAL_ERROR(_("malloc D_list failed\n"));
    }

    /* Set member elements */
    D_list_new->number = number;
    D_list_new->count = 0;
    D_list_new->next = NULL;
    D_list_last->next = D_list_new;

    dprintf("   <---  .... Leaving add_to_D_list.\n"); 

    return;
}
Example #6
0
static void 
gerbv_gdk_draw_amacro(GdkPixmap *pixmap, GdkGC *gc, 
		      gerbv_simplified_amacro_t *s, double scale, 
		      gint x, gint y)
{
    gerbv_simplified_amacro_t *ls = s;

    dprintf(_("Drawing simplified aperture macros:\n"));
    while (ls != NULL) {

	switch (ls->type) {
	case GERBV_APTYPE_MACRO_CIRCLE:
	    gerbv_gdk_draw_prim1(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Circle\n"));
	    break;
	case GERBV_APTYPE_MACRO_OUTLINE:
	    gerbv_gdk_draw_prim4(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Outline\n"));
	    break;
	case GERBV_APTYPE_MACRO_POLYGON:
	    gerbv_gdk_draw_prim5(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Polygon\n"));
	    break;
	case GERBV_APTYPE_MACRO_MOIRE:
	    gerbv_gdk_draw_prim6(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Moire\n"));
	    break;
	case GERBV_APTYPE_MACRO_THERMAL:
	    gerbv_gdk_draw_prim7(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Thermal\n"));
	    break;
	case GERBV_APTYPE_MACRO_LINE20:
	    gerbv_gdk_draw_prim20(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Line 20\n"));
	    break;
	case GERBV_APTYPE_MACRO_LINE21:
	    gerbv_gdk_draw_prim21(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Line 21\n"));
	    break;
	case GERBV_APTYPE_MACRO_LINE22:
	    gerbv_gdk_draw_prim22(pixmap, gc, ls->parameter, scale, x, y);
	    dprintf(_("  Line 22\n"));
	    break;
	default:
	    GERB_FATAL_ERROR(_("Unknown simplified aperture macro"));
	}

	ls = ls->next;
    }

} /* gerbv_gdk_draw_amacro */
Example #7
0
/** Allocates a new gerbv_stats structure
   @return gerbv_stats pointer on success, NULL on ERROR */
gerbv_stats_t *
gerbv_stats_new(void) {

    gerbv_stats_t *stats;
    gerbv_error_list_t *error_list;
    gerbv_aperture_list_t *aperture_list;
    gerbv_aperture_list_t *D_code_list;

    /* Malloc space for new stats struct.  Return NULL if error. */
    if ((stats = (gerbv_stats_t *)g_malloc(sizeof(gerbv_stats_t))) == NULL) {
        return NULL;
    }

    /* Set new stats struct to zero */
    memset((void *)stats, 0, sizeof(gerbv_stats_t));

    /* Initialize error list */
    error_list = gerbv_stats_new_error_list();
    if (error_list == NULL)
        GERB_FATAL_ERROR(_("malloc error_list failed\n"));
    stats->error_list = (gerbv_error_list_t *) error_list;

    /* Initialize aperture list */
    aperture_list = gerbv_stats_new_aperture_list();
    if (aperture_list == NULL)
        GERB_FATAL_ERROR(_("malloc aperture_list failed\n"));
    stats->aperture_list = (gerbv_aperture_list_t *) aperture_list;

    /* Initialize D codes list */
    D_code_list = gerbv_stats_new_aperture_list();
    if (D_code_list == NULL)
        GERB_FATAL_ERROR(_("malloc D_code_list failed\n"));
    stats->D_code_list = (gerbv_aperture_list_t *) D_code_list;

    return stats;
}
Example #8
0
/* ------------------------------------------------------------------ */
void 
main_save_as_project_from_filename(gerbv_project_t *gerbvProject, gchar *filename) 
{
	
    /*
     * Save project filename for later use
     */
    if (gerbvProject->project) {
	g_free(gerbvProject->project);
	gerbvProject->project = NULL;
    }
    gerbvProject->project = g_strdup(filename);
    if (gerbvProject->project == NULL)
	GERB_FATAL_ERROR(_("malloc gerbvProject->project failed\n"));
    main_save_project_from_filename (gerbvProject, filename);
} /* gerbv_save_as_project_from_filename */
Example #9
0
/*	------------------------------------------------------------------
 *	pick_and_place_convert_pnp_data_to_image
 *	------------------------------------------------------------------
 *	Description: Render a parsedPickAndPlaceData array into a gerb_image.
 *	Notes:
 *	------------------------------------------------------------------
 */
gerbv_image_t *
pick_and_place_convert_pnp_data_to_image(GArray *parsedPickAndPlaceData, gint boardSide) 
{
    gerbv_image_t *image = NULL;
    gerbv_net_t *curr_net = NULL;
    int i;
    gerbv_transf_t *tr_rot = gerb_transf_new();
    gerbv_drill_stats_t *stats;  /* Eventually replace with pick_place_stats */
    gboolean foundElement = FALSE;
    
    /* step through and make sure we have an element on the layer before
       we actually create a new image for it and fill it */
    for (i = 0; i < parsedPickAndPlaceData->len; i++) {
	PnpPartData partData = g_array_index(parsedPickAndPlaceData, PnpPartData, i);
	
	if ((boardSide == 0) && !((partData.layer[0]=='b') || (partData.layer[0]=='B')))
		continue;
	if ((boardSide == 1) && !((partData.layer[0]=='t') || (partData.layer[0]=='T')))
		continue;
		
	foundElement = TRUE;
    }
    if (!foundElement)
    	return NULL;

    image = gerbv_create_image(image, "Pick and Place (X-Y) File");
    if (image == NULL) {
	GERB_FATAL_ERROR(_("malloc image failed\n"));
    }
	
    image->format = (gerbv_format_t *)g_malloc(sizeof(gerbv_format_t));
    if (image->format == NULL) {
	GERB_FATAL_ERROR(_("malloc format failed\n"));
    }
    memset((void *)image->format, 0, sizeof(gerbv_format_t));
    
    image->layertype = GERBV_LAYERTYPE_PICKANDPLACE;
    stats = gerbv_drill_stats_new();
    if (stats == NULL)
        GERB_FATAL_ERROR(_("malloc pick_place_stats failed\n"));
    image->drill_stats = stats;


    curr_net = image->netlist;
    curr_net->layer = image->layers;
    curr_net->state = image->states;
    pick_and_place_reset_bounding_box (curr_net);	
    image->info->min_x = HUGE_VAL;
    image->info->min_y = HUGE_VAL;
    image->info->max_x = -HUGE_VAL;
    image->info->max_y = -HUGE_VAL;

    image->aperture[0] = (gerbv_aperture_t *)g_malloc(sizeof(gerbv_aperture_t));
    memset((void *) image->aperture[0], 0, sizeof(gerbv_aperture_t));
    image->aperture[0]->type = GERBV_APTYPE_CIRCLE;
    image->aperture[0]->amacro = NULL;
    image->aperture[0]->parameter[0] = 0.01;
    image->aperture[0]->nuf_parameters = 1;

    for (i = 0; i < parsedPickAndPlaceData->len; i++) {
	PnpPartData partData = g_array_index(parsedPickAndPlaceData, PnpPartData, i);
	float radius,labelOffset;  
	                       
	curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	curr_net = curr_net->next;
	
	assert(curr_net);
	memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	curr_net->layer = image->layers;
	curr_net->state = image->states;
	if ((partData.rotation > 89) && (partData.rotation < 91))
		labelOffset = fabs(partData.length/2);
	else if ((partData.rotation > 179) && (partData.rotation < 181))
		labelOffset = fabs(partData.width/2);
	else if ((partData.rotation > 269) && (partData.rotation < 271))
		labelOffset = fabs(partData.length/2);
	else if ((partData.rotation > -91) && (partData.rotation < -89))
		labelOffset = fabs(partData.length/2);
	else if ((partData.rotation > -181) && (partData.rotation < -179))
		labelOffset = fabs(partData.width/2);
	else if ((partData.rotation > -271) && (partData.rotation < -269))
		labelOffset = fabs(partData.length/2);
	else labelOffset = fabs(partData.width/2);
	
	partData.rotation *= M_PI/180; /* convert deg to rad */
	/* check if the entry is on the specified layer */
	if ((boardSide == 0) && !((partData.layer[0]=='b') || (partData.layer[0]=='B')))
		continue;
	if ((boardSide == 1) && !((partData.layer[0]=='t') || (partData.layer[0]=='T')))
		continue;

	/* this first net is just a label holder, so calculate the lower
	      left location to line up above the element */

	curr_net->start_x = curr_net->stop_x = partData.mid_x;
	curr_net->start_y = curr_net->stop_y = partData.mid_y + labelOffset + 0.01;   
	curr_net->aperture = 0;
	curr_net->aperture_state = GERBV_APERTURE_STATE_OFF;
	curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	curr_net->layer = image->layers;
	curr_net->state = image->states;
	pick_and_place_reset_bounding_box (curr_net);

	/* assign a label to this first draw primitive, in case we want
	* to render some text next to the mark
	*/
	if (strlen (partData.designator) > 0) {
	curr_net->label = g_string_new (partData.designator);
	}

	gerb_transf_reset(tr_rot);
	gerb_transf_shift(tr_rot, partData.mid_x, partData.mid_y);
	gerb_transf_rotate(tr_rot, -partData.rotation);
	    
	if ((partData.shape == PART_SHAPE_RECTANGLE) ||
	    (partData.shape == PART_SHAPE_STD)) {
	    // TODO: draw rectangle length x width taking into account rotation or pad x,y


	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    gerb_transf_apply(partData.length/2, partData.width/2, tr_rot, 
			      &curr_net->start_x, &curr_net->start_y);
	    gerb_transf_apply(-partData.length/2, partData.width/2, tr_rot, 
			      &curr_net->stop_x, &curr_net->stop_y);
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    
	    gerb_transf_apply(-partData.length/2, partData.width/2, tr_rot, 
			      &curr_net->start_x, &curr_net->start_y);
	    gerb_transf_apply(-partData.length/2, -partData.width/2, tr_rot, 
			      &curr_net->stop_x, &curr_net->stop_y);
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    
	    gerb_transf_apply(-partData.length/2, -partData.width/2, tr_rot, 
			      &curr_net->start_x, &curr_net->start_y);
	    gerb_transf_apply(partData.length/2, -partData.width/2, tr_rot, 
			      &curr_net->stop_x, &curr_net->stop_y);
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    
	    gerb_transf_apply(partData.length/2, -partData.width/2, tr_rot, 
			      &curr_net->start_x, &curr_net->start_y);
	    gerb_transf_apply(partData.length/2, partData.width/2, tr_rot, 
			      &curr_net->stop_x, &curr_net->stop_y);
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    
	    if (partData.shape == PART_SHAPE_RECTANGLE) {
		gerb_transf_apply(partData.length/4, -partData.width/2, tr_rot, 
				  &curr_net->start_x, &curr_net->start_y);
		gerb_transf_apply(partData.length/4, partData.width/2, tr_rot, 
				  &curr_net->stop_x, &curr_net->stop_y);
	    } else {
		gerb_transf_apply(partData.length/4, partData.width/2, tr_rot, 
				  &curr_net->start_x, &curr_net->start_y);
		gerb_transf_apply(partData.length/4, partData.width/4, tr_rot, 
				  &curr_net->stop_x, &curr_net->stop_y);
		
		curr_net->aperture = 0;
		curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
		curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
		curr_net->layer = image->layers;
		curr_net->state = image->states;
		pick_and_place_reset_bounding_box (curr_net);
		
		curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
		curr_net = curr_net->next;
		assert(curr_net);
		memset((void *)curr_net, 0, sizeof(gerbv_net_t));
		gerb_transf_apply(partData.length/2, partData.width/4, tr_rot, 
				  &curr_net->start_x, &curr_net->start_y);
		gerb_transf_apply(partData.length/4, partData.width/4, tr_rot, 
				  &curr_net->stop_x, &curr_net->stop_y);     
	    }
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    /* calculate a rough radius for the min/max screen calcs later */
	    radius = max (partData.length/2, partData.width/2);
	} else {
	    gdouble tmp_x,tmp_y;
	    
	    curr_net->start_x = partData.mid_x;
	    curr_net->start_y = partData.mid_y;
	    gerb_transf_apply( partData.pad_x -  partData.mid_x, 
			       partData.pad_y - partData.mid_y, tr_rot, &tmp_x, &tmp_y);
			       
	    curr_net->stop_x = tmp_x;
	    curr_net->stop_y = tmp_y;
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_LINEARx1;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    
	    curr_net->next = (gerbv_net_t *)g_malloc(sizeof(gerbv_net_t));
	    curr_net = curr_net->next;
	    assert(curr_net);
	    memset((void *)curr_net, 0, sizeof(gerbv_net_t));
	    
	    curr_net->start_x = partData.mid_x;
	    curr_net->start_y = partData.mid_y;
	    curr_net->stop_x = partData.pad_x;
	    curr_net->stop_y = partData.pad_y;
	    
	    curr_net->aperture = 0;
	    curr_net->aperture_state = GERBV_APERTURE_STATE_ON;
	    curr_net->interpolation = GERBV_INTERPOLATION_CW_CIRCULAR;
	    curr_net->layer = image->layers;
	    curr_net->state = image->states;
	    pick_and_place_reset_bounding_box (curr_net);
	    
	    curr_net->cirseg = g_new0 (gerbv_cirseg_t,1);
	    curr_net->cirseg->angle1 = 0.0;
	    curr_net->cirseg->angle2 = 360.0;
	    curr_net->cirseg->cp_x = partData.mid_x;
	    curr_net->cirseg->cp_y = partData.mid_y;
	    radius = sqrt((partData.pad_x-partData.mid_x)*(partData.pad_x-partData.mid_x) +
			  (partData.pad_y-partData.mid_y)*(partData.pad_y-partData.mid_y));
	    if (radius < 0.001)
	    	radius = 0.1;
	    curr_net->cirseg->width = 2*radius; /* fabs(pad_x-mid_x) */
	    curr_net->cirseg->height = 2*radius;
	}

	/* 
	 * update min and max numbers so the screen zoom-to-fit 
	 *function will work
	 */
	image->info->min_x = min(image->info->min_x, (partData.mid_x - radius - 0.02));
	image->info->min_y = min(image->info->min_y, (partData.mid_y - radius - 0.02));
	image->info->max_x = max(image->info->max_x, (partData.mid_x + radius + 0.02));
	image->info->max_y = max(image->info->max_y, (partData.mid_y + radius + 0.02));
    }
    curr_net->next = NULL;
    
    gerb_transf_free(tr_rot);
    return image;
} /* pick_and_place_convert_pnp_data_to_image */
Example #10
0
/*	------------------------------------------------------------------
 *	pick_and_place_check_file_type
 *	------------------------------------------------------------------
 *	Description: Tries to parse the given file into a pick-and-place
 *		data set. If it fails to read any good rows, then returns
 *		FALSE, otherwise it returns TRUE.
 *	Notes: 
 *	------------------------------------------------------------------
 */
gboolean
pick_and_place_check_file_type(gerb_file_t *fd, gboolean *returnFoundBinary)
{
    char *buf;
    int len = 0;
    int i;
    char *letter;
    gboolean found_binary = FALSE;
    gboolean found_G54 = FALSE;
    gboolean found_M0 = FALSE;
    gboolean found_M2 = FALSE;
    gboolean found_G2 = FALSE;
    gboolean found_ADD = FALSE;
    gboolean found_comma = FALSE;
    gboolean found_R = FALSE;
    gboolean found_U = FALSE;
    gboolean found_C = FALSE;
    gboolean found_boardside = FALSE;

    buf = malloc(MAXL);
    if (buf == NULL)
	GERB_FATAL_ERROR(_("malloc buf failed while checking for pick-place file.\n"));

    while (fgets(buf, MAXL, fd->fd) != NULL) {
	len = strlen(buf);
     
	/* First look through the file for indications of its type */
	
	/* check for non-binary file */
	for (i = 0; i < len; i++) {
	    if (!isprint((int) buf[i]) && (buf[i] != '\r') && 
                (buf[i] != '\n') && (buf[i] != '\t')) {
		found_binary = TRUE;
	    }
	}
	
	if (g_strstr_len(buf, len, "G54")) {
	    found_G54 = TRUE;
	}
	if (g_strstr_len(buf, len, "M00")) {
	    found_M0 = TRUE;
	}
	if (g_strstr_len(buf, len, "M02")) {
	    found_M2 = TRUE;
	}
	if (g_strstr_len(buf, len, "G02")) {
	    found_G2 = TRUE;
	}
	if (g_strstr_len(buf, len, "ADD")) {
	    found_ADD = TRUE;
	}
	if (g_strstr_len(buf, len, ",")) {
	    found_comma = TRUE;
	}
	/* Semicolon can be separator too */
	if (g_strstr_len(buf, len, ";")) {
	    found_comma = TRUE;
	}
	
	/* Look for refdes -- This is dumb, but what else can we do? */
	if ((letter = g_strstr_len(buf, len, "R")) != NULL) {
	    if (isdigit((int) letter[1])) { /* grab char after R */
		found_R = TRUE;
	    }
	}
	if ((letter = g_strstr_len(buf, len, "C")) != NULL) {
	    if (isdigit((int) letter[1])) { /* grab char after C */
		found_C = TRUE;
	    }
	}
	if ((letter = g_strstr_len(buf, len, "U")) != NULL) {
	    if (isdigit((int) letter[1])) { /* grab char after U */
		found_U = TRUE;
	    }
	}
	
	/* Look for board side indicator since this is required
	 * by many vendors */
	if (g_strstr_len(buf, len, "top")) {
	    found_boardside = TRUE;
	}
	if (g_strstr_len(buf, len, "Top")) {
	    found_boardside = TRUE;
	}
	if (g_strstr_len(buf, len, "TOP")) {
	    found_boardside = TRUE;
	}
	/* Also look for evidence of "Layer" in header.... */
	if (g_strstr_len(buf, len, "ayer")) {
	    found_boardside = TRUE;
	}
	if (g_strstr_len(buf, len, "AYER")) {
	    found_boardside = TRUE;
	}
	
    }
    rewind(fd->fd);
    free(buf);

    /* Now form logical expression determining if this is a pick-place file */
    *returnFoundBinary = found_binary;
    if (found_G54) 
	return FALSE;
    if (found_M0) 
	return FALSE;
    if (found_M2) 
	return FALSE;
    if (found_G2) 
	return FALSE;
    if (found_ADD) 
	return FALSE;
    if (found_comma && (found_R || found_C || found_U) && 
	found_boardside) 
	return TRUE;
    
    return FALSE;
    
} /* pick_and_place_check_file_type */
Example #11
0
/* ------------------------------------------------------------------ */
void 
main_open_project_from_filename(gerbv_project_t *gerbvProject, gchar *filename) 
{
	project_list_t *project_list, *originalList;
	gint i,maxLayerNumber = -1;

	dprintf(_("Opening project = %s\n"), (gchar *) filename);
	originalList = project_list = read_project_file(filename);

	if (project_list) {
		/* first, get the max layer number in the project list */
		while (project_list) {
			if (project_list->layerno > maxLayerNumber)
				maxLayerNumber = project_list->layerno;
			project_list = project_list->next;
		}
		project_list = originalList;
		/* increase the layer count each time and find (if any) the corresponding entry */
		for (i = -1; i<=maxLayerNumber; i++){
			project_list = originalList;
			while (project_list) {
				if (project_list->layerno == i) {
					GdkColor colorTemplate = {0,project_list->rgb[0],
					project_list->rgb[1],project_list->rgb[2]};
					if (i == -1) {
						gerbvProject->background = colorTemplate;
					}
					else {
						gchar *fullName = NULL;
						gchar *dirName = NULL;
						gint fileIndex = gerbvProject->last_loaded + 1;

						if (!g_path_is_absolute (project_list->filename)) {
							/* build the full pathname to the layer */
							dirName = g_path_get_dirname (filename);
							fullName = g_build_filename (dirName,
								project_list->filename, NULL);
						}
						else {
							fullName = g_strdup (project_list->filename);
						}
						if (gerbv_open_image(gerbvProject, fullName,
								fileIndex, FALSE, 
								project_list->attr_list, 
								project_list->n_attr, TRUE) == -1) {
							GERB_MESSAGE(_("could not read file: %s"), fullName);
						}
						else {
							g_free (dirName);
							g_free (fullName);
							/* 
							* Change color from default to from the project list
							*/
							gerbvProject->file[fileIndex]->color = colorTemplate;
							gerbvProject->file[fileIndex]->transform.inverted = project_list->inverted;
							gerbvProject->file[fileIndex]->isVisible = project_list->visible;
						}
					}
				}
				project_list = project_list->next;
			}
		}
		project_destroy_project_list (originalList);
		/*
		* Save project filename for later use
		*/
		if (gerbvProject->project) {
		g_free(gerbvProject->project);
		gerbvProject->project = NULL;
		}
		gerbvProject->project = g_strdup (filename);
		if (gerbvProject->project == NULL)
		GERB_FATAL_ERROR(_("malloc gerbvProject->project failed\n"));
	}
	else {
		GERB_MESSAGE(_("could not read %s[%d]\n"), (gchar *) filename,
		gerbvProject->last_loaded);
	}
} /* gerbv_open_project_from_filename */
Example #12
0
/* ------------------------------------------------------- */
void
gerbv_stats_add_aperture(gerbv_aperture_list_t *aperture_list_in,
			int layer, int number, gerbv_aperture_type_t type,
			double parameter[5]) {

    gerbv_aperture_list_t *aperture_list_new;
    gerbv_aperture_list_t *aperture_last = NULL;
    gerbv_aperture_list_t *aperture;
    int i;

    dprintf("   --->  Entering gerbv_stats_add_aperture ....\n"); 

    /* First handle case where this is the first list element */
    if (aperture_list_in->number == -1) {
	dprintf("     .... Adding first aperture to aperture list ... \n"); 
	dprintf("     .... Aperture type = %d ... \n", type); 
        aperture_list_in->number = number;
        aperture_list_in->type = type;
	aperture_list_in->layer = layer;
	for(i=0; i<5; i++) { 
	    aperture_list_in->parameter[i] = parameter[i];
	}
        aperture_list_in->next = NULL;
	dprintf("   <---  .... Leaving gerbv_stats_add_aperture.\n"); 
        return;
    }

    /* Next check to see if this aperture is already in the list */
    for(aperture = aperture_list_in; 
	aperture != NULL; 
	aperture = aperture->next) {
        if ((aperture->number == number) &&
            (aperture->layer == layer) ) {
	  dprintf("     .... This aperture is already in the list ... \n"); 
	    dprintf("   <---  .... Leaving gerbv_stats_add_aperture.\n"); 
            return;  
        }
        aperture_last = aperture;  /* point to last element in list */
    }
    /* This aperture number is unique.  Therefore, add it to the list */
    dprintf("     .... Adding another aperture to list ... \n"); 
    dprintf("     .... Aperture type = %d ... \n", type); 
	
    /* Now malloc space for new aperture list element */
    aperture_list_new = (gerbv_aperture_list_t *) g_malloc(sizeof(gerbv_aperture_list_t));
    if (aperture_list_new == NULL) {
        GERB_FATAL_ERROR(_("malloc aperture_list failed\n"));
    }

    /* Set member elements */
    aperture_list_new->layer = layer;
    aperture_list_new->number = number;
    aperture_list_new->type = type;
    aperture_list_new->next = NULL;
    for(i=0; i<5; i++) { 
	aperture_list_new->parameter[i] = parameter[i];
    }
    aperture_last->next = aperture_list_new;

    dprintf("   <---  .... Leaving gerbv_stats_add_aperture.\n"); 

    return;
}