Code Search for Developers
 
 
  

emview_node_component.c from EmStar at Krugle


Show emview_node_component.c syntax highlighted

/*
 *
 * Copyright (c) 2003 The Regents of the University of California.  All 
 * rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * - Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * - Neither the name of the University nor the names of its
 *   contributors may be used to endorse or promote products derived
 *   from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#include "emview_i.h"

char emview_node_component_c_id[] = "$Id: emview_node_component.c,v 1.10 2004/02/27 20:40:34 girod Exp $";

/*
 *  node component field names
 */

int emview_node_flag_name(emview_color_t color)
{
  switch (color) {
  case EMVIEW_COLOR_WHITE:
  case EMVIEW_COLOR_BLACK:
    elog(LOG_WARNING, "White and black are not valid flag colors");
    return 0;

  default:
    break;
  }

  return color - EMVIEW_COLOR_RED + 
    EMVIEW_NODE_FIRST_COLOR_FLAG;
}


static
int emview_node_flag_field_to_index(int field)
{
  field -= EMVIEW_NODE_FIRST_COLOR_FLAG;
  if (field >= EMVIEW_MAX_COLORS)
    field = -1;
  return field;
}


/*
 *  node component creation
 */

static
component_t *emview_node_component_create()
{
  return (component_t *)g_new0(node_component_t, 1);
}

static
void emview_node_component_destroy(component_t *c)
{
  if (c) {
    component_nonexcl_clear(&(((node_component_t*)c)->below), NULL);
    free(c);
  }
}

static
component_t *emview_node_component_copy(component_t *src)
{
  component_t *copy = emview_node_component_create();
  memmove(copy, src, sizeof(node_component_t));
  return copy;
}

static
int emview_node_component_is_exclusive(int field)
{
  int retval = 1;
  if (field == EMVIEW_NODE_BELOW)
    retval = 0;
  return retval;
}

static
void emview_node_component_assign(component_t *c, int field, source_data_t *d)
{
  node_component_t *nc = (node_component_t *)c;
  int flag_index;

  switch (field) {
  case EMVIEW_NODE_BELOW:
    component_nonexcl_append(&(nc->below), d);
    break;

  default:
    flag_index = emview_node_flag_field_to_index(field); 
    if (flag_index < 0)
      goto fail;
    nc->flags[flag_index] = d;
  }

  return;

fail:
  elog(LOG_WARNING, "Illegal field for node component: %d", field);
}


static
void emview_node_component_clear(component_t *c, int field, source_data_t *d)
{
  node_component_t *nc = (node_component_t *)c;
  int flag_index;

  switch (field) {
  case EMVIEW_NODE_ALL:
    component_nonexcl_clear(&(nc->below), NULL);
    memset(&(nc->flags[0]), 0, sizeof(nc->flags));
    break;

  case EMVIEW_NODE_BELOW:
    component_nonexcl_clear(&(nc->below), d);
    break;

  default:
    flag_index = emview_node_flag_field_to_index(field); 
    if (flag_index < 0)
      goto fail;
    nc->flags[flag_index] = NULL;
  }
  
  return;
  
 fail:
  elog(LOG_WARNING, "Illegal field for node component: %d", field);
}


void emview_node_component_checkrefs(component_t *c)
{
  c->referenced = 1;
}


void emview_node_component_layout(component_t *c)
{
  emview_component_extend_upper_right
    (c, EMVIEW_NODE_WIDTH, EMVIEW_NODE_HEIGHT);
}


void emview_node_component_draw(component_t *c)
{
  char buf[20];
  node_component_t *nc = (node_component_t*)c;
  int i,j;
  static GdkGC *gc = NULL;
  static GdkGC *gc2 = NULL;

  if (gc == NULL) {
    gc = gdk_gc_new(_core.gui.window->window);
    gdk_gc_copy(gc, _core.gui.window->style->black_gc);
    gc2 = gdk_gc_new(_core.gui.window->window);
    gdk_gc_copy(gc2, _core.gui.window->style->black_gc);
  }

  /*
   *  draw node flags
   */

  gdk_gc_set_line_attributes(gc, NODE_FLAG_WIDTH, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
  for (i=0,j=1; i<EMVIEW_MAX_COLORS; i++) {
    if (emview_source_data_valid(nc->flags[i]) &&
	nc->flags[i]->int_value) {
      
      /* set color */
      emview_set_fg_color(gc, (i + EMVIEW_COLOR_RED), !c->active);
      
      /* outline the circle */
      gdk_draw_arc(_core.gui.fg_pixmap, gc, FALSE, 
		   c->px - j*NODE_FLAG_WIDTH, 
		   c->py - j*NODE_FLAG_WIDTH, 
		   c->h + j*NODE_FLAG_WIDTH*2, 
		   c->h + j*NODE_FLAG_WIDTH*2,
		   0, 360*64);
      j++;
    }
  }  

  gdk_gc_set_line_attributes(gc, 1, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);

  /* if direct, draw light yellow background */
  if (nc->direct)
    emview_set_fg_color(gc2, EMVIEW_COLOR_YELLOW, 1);
  else
    emview_set_fg_color(gc2, EMVIEW_COLOR_WHITE, 0);

  /* outline is black */
  emview_set_fg_color(gc, EMVIEW_COLOR_BLACK, !c->active);

  /* draw the box */
  gdk_draw_rectangle(_core.gui.fg_pixmap, gc2,
		     TRUE, c->px + (c->h/2) - 1, c->py, 
		     c->w - (c->h/2), c->h);
  
  /* draw the box */
  gdk_draw_rectangle(_core.gui.fg_pixmap, gc,
		     FALSE, c->px + (c->h/2) - 1, c->py, 
		     c->w - (c->h/2), c->h);
  
  /* fill the circle */
  gdk_draw_arc(_core.gui.fg_pixmap, gc2,
	       TRUE, c->px, c->py,
	       c->h, c->h,
	       90*64, 180*64);

  /* outline the circle */
  gdk_draw_arc(_core.gui.fg_pixmap, gc,
	       FALSE, c->px, c->py, 
	       c->h, c->h,
	       90*64, 180*64);
  
  /* draw the node ID */
  sprintf(buf, "%d", nc->id);
  emview_put_label_in_comp(c, buf, EMVIEW_COLOR_NONE, EMVIEW_COLOR_BLACK, EMVIEW_COLOR_NONE,
			   EMVIEW_CENTER, EMVIEW_CENTER,
			   0, 0, 0, 0, !c->active);
  
  /* draw the under-node annotation */
  if (nc->below)
    for (i=0,j=TEXT_BG_PAD*2; i<nc->below->len; i++) {
      source_data_t *data = (source_data_t*)g_ptr_array_index(nc->below, i);
      if (emview_source_data_valid(data)) {
	emview_put_label(c->px + c->w, c->disp->by2 + j, 0, STD_TEXT_HEIGHT,
			 emview_source_data_string_value(data),
			 emview_source_data_bg_color(data),
			 emview_source_data_fg_color(data),
			 EMVIEW_COLOR_NONE, 
			 EMVIEW_CENTER, EMVIEW_LEFT_JUST, TEXT_BG_PAD, 0, 0, 0, !c->active);
	j += STD_TEXT_HEIGHT;
      }
    }
}


/*
 *  init function
 */

void emview_node_component_init()
{
  struct component_vtbl v = {
    name: "Node",
    create: emview_node_component_create,
    destroy: emview_node_component_destroy,
    copy: emview_node_component_copy,
    is_exclusive: emview_node_component_is_exclusive,
    assign: emview_node_component_assign,
    clear: emview_node_component_clear,
    checkrefs: emview_node_component_checkrefs,
    layout: emview_node_component_layout,
    draw: emview_node_component_draw
  };

  _core.components.vtbl[EMVIEW_COMP_TYPE_NODE] = v;  
}




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  emview_analysis.c
  emview_analysis.h
  emview_box_component.c
  emview_component.c
  emview_component.h
  emview_config.c
  emview_config.h
  emview_device.c
  emview_device.h
  emview_gui.c
  emview_gui.h
  emview_gui_menu.c
  emview_i.h
  emview_main.c
  emview_node.c
  emview_node.h
  emview_node_component.c
  emview_slots.c
  emview_source.c
  emview_source.h