Exemple #1
0
/*!
 * \brief After laoding and before drawing ShapeInfo needs to be realised
 * @param : the shape to realise
 * 
 * Puts the ShapeInfo into a form suitable for actual use (lazy loading)
 *
 * \extends _ShapeInfo
 */
void
shape_info_realise(ShapeInfo* info)
{
  GList* tmp;
  
  for (tmp = info->display_list; tmp != NULL; tmp = tmp->next) {
    GraphicElement *el = tmp->data;
    if (el->type == GE_TEXT) {
          /* set default values for text style */
      if (!el->text.s.font_height)
        el->text.s.font_height = FONT_HEIGHT_DEFAULT;
      if (!el->text.s.font)
        el->text.s.font = dia_font_new_from_style(DIA_FONT_SANS,1.0);
      if (el->text.s.alignment == -1)
        el->text.s.alignment = TEXT_ALIGNMENT_DEFAULT;
      if (!el->text.object) {
        el->text.object = new_text(el->text.string,
                                   el->text.s.font,
                                   el->text.s.font_height,
                                   &el->text.anchor,
                                   &color_black,
                                   el->text.s.alignment);
      }
      text_calc_boundingbox(el->text.object, &el->text.text_bounds);
    }
  }  
}
Exemple #2
0
static DiaObject *
annotation_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Annotation *annotation;
  Connection *conn;
  LineBBExtras *extra;
  DiaObject *obj; 
  Point offs;
  Point defaultlen = { 1.0, 1.0 };
  DiaFont* font;

  annotation = g_malloc0(sizeof(Annotation));

  conn = &annotation->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);
 
  obj = &conn->object;
  extra = &conn->extra_spacing;

  obj->type = &sadtannotation_type;
  obj->ops = &annotation_ops;
  
  connection_init(conn, 3, 0);

  font = dia_font_new_from_style(DIA_FONT_SANS,ANNOTATION_FONTHEIGHT);
  annotation->text = new_text("", font,
                              ANNOTATION_FONTHEIGHT,
                              &conn->endpoints[1],
                              &color_black,
                              ALIGN_CENTER);
  dia_font_unref(font);

  offs.x = .3 * ANNOTATION_FONTHEIGHT;
  if (conn->endpoints[1].y < conn->endpoints[0].y)
    offs.y = 1.3 * ANNOTATION_FONTHEIGHT;
  else
    offs.y = -.3 * ANNOTATION_FONTHEIGHT;
  point_add(&annotation->text->position,&offs);
  
  annotation->text_handle.id = HANDLE_MOVE_TEXT;
  annotation->text_handle.type = HANDLE_MINOR_CONTROL;
  annotation->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  annotation->text_handle.connected_to = NULL;
  obj->handles[2] = &annotation->text_handle;

  extra->start_trans = 
    extra->end_trans = ANNOTATION_ZLEN;
  extra->start_long = 
    extra->end_long = ANNOTATION_LINE_WIDTH/2.0;
  annotation_update_data(annotation);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return &annotation->connection.object;
}
static DiaFont *
_parse_font (xmlNodePtr node)
{
  DiaFont *font = NULL;
  xmlChar *str;
  xmlChar *fam = xmlGetProp(node, (const xmlChar *)"family");
  real size = _parse_real (node, "size");

  if (size <= 0.0)
    size = 1.0;
  if (fam)
    font = dia_font_new ((const char *)fam, 0, size);
  if (!font)
    font = dia_font_new_from_style (DIA_FONT_SANS, size);
  str = xmlGetProp(node, (const xmlChar *)"weight");
  if (str) {
    dia_font_set_weight_from_string (font, (const char*)str);
    xmlFree (str);
  }
  str = xmlGetProp(node, (const xmlChar *)"slant");
  if (str) {
    dia_font_set_slant_from_string (font, (const char*)str);
    xmlFree (str);
  }

  if (fam)
    xmlFree (fam);

  return font;
}
Exemple #4
0
/* creation here */
static DiaObject *
message_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Message *message;
  Connection *conn;
  LineBBExtras *extra;
  DiaObject *obj;

  if (message_font == NULL) {
    message_font =
      dia_font_new_from_style (DIA_FONT_SANS, MESSAGE_FONTHEIGHT);
  }

  message = g_malloc0(sizeof(Message));

  conn = &message->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  conn->endpoints[1].x += 1.5;

  obj = &conn->object;
  extra = &conn->extra_spacing;

  obj->type = &jackson_phenomenon_type;
  obj->ops = &message_ops;

  connection_init(conn, 3, 0);

  message->text = g_strdup("");
  message->text_width = 0.0;
  message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y);

  message->text_handle.id = HANDLE_MOVE_TEXT;
  message->text_handle.type = HANDLE_MINOR_CONTROL;
  message->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  message->text_handle.connected_to = NULL;
  obj->handles[2] = &message->text_handle;

  extra->start_long = extra->start_trans =  extra->end_long = MESSAGE_WIDTH/2.0;
  extra->end_trans = MAX(MESSAGE_WIDTH,MESSAGE_ARROWLEN)/2.0;

  message_update_data(message);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];

  /* init type */
  switch (GPOINTER_TO_INT(user_data)) {
    case 1: message->type=MSG_SHARED; break;
    case 2: message->type=MSG_REQ; break;
    default: message->type=MSG_SHARED; break;
  }
    
  if (GPOINTER_TO_INT(user_data)!=0) message->init=-1; else message->init=0;
  return &message->connection.object;
}
Exemple #5
0
/* creation stuff */
static DiaObject 
*actor_create(Point *startpoint,
	   void *user_data,
	   Handle **handle1,
	   Handle **handle2)
{
  Actor *actor;
  Element *elem;
  DiaObject *obj;
  Point p;
  int i;
  DiaFont *font = NULL;

  actor = g_malloc0(sizeof(Actor));
  elem = &actor->element;
  obj = &elem->object;

  obj->type = &istar_actor_type;

  obj->ops = &actor_ops;

  elem->corner = *startpoint;
  elem->width = ACTOR_RADIUS;
  elem->height = ACTOR_RADIUS;

  font = dia_font_new_from_style( DIA_FONT_SANS, ACTOR_FONT);
  p = *startpoint;
  p.x += elem->width / 2.0;
  p.y += elem->height / 2.0 + ACTOR_FONT / 2;
  actor->text = new_text("", font, ACTOR_FONT, &p, &ACTOR_FG_COLOR, ALIGN_CENTER);
  dia_font_unref(font);

  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &actor->connections[i];
    actor->connections[i].object = obj;
    actor->connections[i].connected = NULL;
  }
  actor->connections[16].flags = CP_FLAGS_MAIN;

  /* init */
  switch (GPOINTER_TO_INT(user_data)) {
    case 1: actor->type=ACTOR_UNSPECIFIED; break;
    case 2:  actor->type=ACTOR_AGENT; break;
    case 3:  actor->type=ACTOR_POSITION; break;
    case 4:  actor->type=ACTOR_ROLE; break;
    default: actor->type=ACTOR_UNSPECIFIED; break;
  }

  if (GPOINTER_TO_INT(user_data)!=0) actor->init=-1; else actor->init=0;

  actor_update_data(actor, ANCHOR_MIDDLE, ANCHOR_MIDDLE);

  *handle1 = NULL;
  *handle2 = obj->handles[7];

  return &actor->element.object;
}
Exemple #6
0
static DiaObject *
component_create(Point *startpoint,
		    void *user_data,
		    Handle **handle1,
		    Handle **handle2)
{
  Component *cmp;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;
  
  cmp = g_malloc0(sizeof(Component));
  elem = &cmp->element;
  obj = &elem->object;
  
  obj->type = &component_type;

  obj->ops = &component_ops;

  obj->flags |= DIA_OBJECT_CAN_PARENT;

  elem->corner = *startpoint;
  cmp->line_color = attributes_get_foreground();
  cmp->fill_color = attributes_get_background();

  font = dia_font_new_from_style (DIA_FONT_SANS, 0.8);
  p = *startpoint;
  p.x += COMPONENT_CWIDTH + COMPONENT_MARGIN_X;
  p.y += 2*COMPONENT_CHEIGHT;
  
  cmp->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT);
  text_get_attributes(cmp->text,&cmp->attrs);

  dia_font_unref(font);
  
  element_init(elem, 8, NUM_CONNECTIONS);
  
  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &cmp->connections[i];
    cmp->connections[i].object = obj;
    cmp->connections[i].connected = NULL;
  }
  cmp->connections[10].flags = CP_FLAGS_MAIN;
  elem->extra_spacing.border_trans = COMPONENT_BORDERWIDTH/2.0;
  cmp->stereotype = NULL;
  cmp->st_stereotype = NULL;
  component_update_data(cmp);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }

  *handle1 = NULL;
  *handle2 = NULL;
  return &cmp->element.object;
}
Exemple #7
0
static DiaObject *
compfeat_create(Point *startpoint,
		void *user_data,
		Handle **handle1,
		Handle **handle2)
{
  Compfeat *compfeat;
  OrthConn *orth;
  DiaObject *obj;
  Point p;
  DiaFont *font;

  font = dia_font_new_from_style(DIA_FONT_MONOSPACE, 0.8);

  compfeat = g_new0(Compfeat, 1);
  compfeat->role = compfeat->roletmp = GPOINTER_TO_INT(user_data);
  compfeat->line_width = 0.1;

  orth = &compfeat->orth;
  obj = &orth->object;

  obj->type = &compfeat_type;
  obj->ops = &compfeat_ops;

  orthconn_init(orth, startpoint);

  p = *startpoint;
  p.y -= COMPPROP_TEXTOFFSET;

  compfeat->line_color = attributes_get_foreground();
  compfeat->text = new_text("", font,
			    COMPPROP_FONTHEIGHT, &p, &compfeat->line_color,
			    ALIGN_CENTER);
  dia_font_unref(font);

  compfeat->text_handle.id = HANDLE_MOVE_TEXT;
  compfeat->text_handle.type = HANDLE_MINOR_CONTROL;
  compfeat->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  compfeat->text_handle.connected_to = NULL;
  compfeat->text_handle.pos = compfeat->text_pos = p;
  object_add_handle(obj, &compfeat->text_handle);

  if (compfeat->role == COMPPROP_FACET
      || compfeat->role == COMPPROP_EVENTSOURCE) {
    int pos = obj->num_connections;
    object_add_connectionpoint(&orth->object, &compfeat->cp);
    obj->connections[pos] = &compfeat->cp;
    compfeat->cp.object = obj;
    compfeat->cp.connected = NULL;
  }

  compfeat_update_data(compfeat);

  *handle1 = orth->handles[0];
  *handle2 = orth->handles[orth->numpoints-2];

  return &compfeat->orth.object;
}
Exemple #8
0
static DiaObject *
attribute_create(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  Attribute *attribute;
  Element *elem;
  DiaObject *obj;
  int i;

  attribute = g_malloc0(sizeof(Attribute));
  elem = &attribute->element;
  obj = &elem->object;
  
  obj->type = &attribute_type;
  obj->ops = &attribute_ops;

  elem->corner = *startpoint;
  elem->width = DEFAULT_WIDTH;
  elem->height = DEFAULT_HEIGHT;

  attribute->border_width =  attributes_get_default_linewidth();
  attribute->border_color = attributes_get_foreground();
  attribute->inner_color = attributes_get_background();

  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &attribute->connections[i];
    attribute->connections[i].object = obj;
    attribute->connections[i].connected = NULL;
  }
  attribute->connections[8].flags = CP_FLAGS_MAIN;

  attribute->key = FALSE;
  attribute->weakkey = FALSE;
  attribute->derived = FALSE;
  attribute->multivalue = FALSE;
  attribute->font = dia_font_new_from_style(DIA_FONT_MONOSPACE,FONT_HEIGHT);
  attribute->font_height = FONT_HEIGHT;
  attribute->name = g_strdup(_("Attribute"));

  attribute->name_width =
    dia_font_string_width(attribute->name,
                          attribute->font, attribute->font_height);

  attribute_update_data(attribute);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }

  *handle1 = NULL;
  *handle2 = obj->handles[0];
  return &attribute->element.object;
}
Exemple #9
0
static DiaObject *
transition_create(Point *startpoint,
                  void *user_data,
                  Handle **handle1,
                  Handle **handle2)
{
  Transition *transition;
  OrthConn *orth;
  DiaObject *obj;
  Point temp_point;
  
  if (transition_font == NULL) {
    transition_font = 
      dia_font_new_from_style (DIA_FONT_SANS, TRANSITION_FONTHEIGHT);
  }

  transition = g_malloc0(sizeof(Transition));
  
  orth = &transition->orth;
  obj = &orth->object;
  obj->type = &uml_transition_type;
  obj->ops = &uml_transition_ops;
  
  orthconn_init(orth, startpoint);
  
  transition->text_color = color_black;
  transition->line_color = attributes_get_foreground();
  /* Prepare the handles for trigger and guard text */
  transition->trigger_text_handle.id = HANDLE_MOVE_TRIGGER_TEXT;
  transition->trigger_text_handle.type = HANDLE_MINOR_CONTROL;
  transition->trigger_text_handle.connect_type = HANDLE_NONCONNECTABLE;
  transition->trigger_text_handle.connected_to = NULL;
  temp_point = *startpoint;
  temp_point.y -= TEXT_HANDLE_DISTANCE_FROM_STARTPOINT;
  transition->trigger_text_pos = temp_point;
  transition->trigger_text_handle.pos = temp_point;
  object_add_handle(obj, &transition->trigger_text_handle);  
  
  transition->guard_text_handle.id = HANDLE_MOVE_GUARD_TEXT;
  transition->guard_text_handle.type = HANDLE_MINOR_CONTROL;
  transition->guard_text_handle.connect_type = HANDLE_NONCONNECTABLE;
  transition->guard_text_handle.connected_to = NULL;
  temp_point = *startpoint;
  temp_point.y += TEXT_HANDLE_DISTANCE_FROM_STARTPOINT;
  transition->guard_text_pos = transition->guard_text_handle.pos = temp_point;
  object_add_handle(obj, &transition->guard_text_handle);
  
  transition->guard_text = NULL;
  transition->trigger_text = NULL;
  transition->action_text = NULL;
  
  uml_transition_update_data(transition);
   
  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return obj;
}
Exemple #10
0
static DiaObject *
function_create(Point *startpoint,
		void *user_data,
		Handle **handle1,
		Handle **handle2)
{
  Function *pkg;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;
  
  pkg = g_malloc0(sizeof(Function));
  elem = &pkg->element;
  obj = &elem->object;
  
  obj->type = &function_type;

  obj->ops = &function_ops;

  elem->corner = *startpoint;

  font = dia_font_new_from_style (DIA_FONT_SANS,FUNCTION_FONTHEIGHT);
  
  pkg->is_wish = FALSE;
  pkg->is_user = FALSE;

  /* The text position is recalculated later */
  p.x = 0.0;
  p.y = 0.0;
  pkg->text = new_text("", font, FUNCTION_FONTHEIGHT, &p, &color_black,
                       ALIGN_CENTER);
  dia_font_unref(font);
  
  element_init(elem, 8, NUM_CONNECTIONS);
  
  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &pkg->connections[i];
    pkg->connections[i].object = obj;
    pkg->connections[i].connected = NULL;
  }
  pkg->connections[8].flags = CP_FLAGS_MAIN;

  pkg->element.extra_spacing.border_trans = FUNCTION_FONTHEIGHT / FUNCTION_BORDERWIDTH_SCALE/2.0;
  function_update_data(pkg);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }


  *handle1 = NULL;
  *handle2 = NULL;

  return &pkg->element.object;
}
Exemple #11
0
static DiaObject *
message_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Message *message;
  Connection *conn;
  LineBBExtras *extra;
  DiaObject *obj;

  message = g_malloc0(sizeof(Message));

  /* old defaults */
  message->font_height = 0.8;
  message->font =
      dia_font_new_from_style (DIA_FONT_SANS, message->font_height);
  message->line_width = 0.1;

  conn = &message->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  conn->endpoints[1].x += 1.5;
 
  obj = &conn->object;
  extra = &conn->extra_spacing;

  obj->type = &message_type;
  obj->ops = &message_ops;
  
  connection_init(conn, 3, 0);

  message->text_color = color_black;
  message->line_color = attributes_get_foreground();
  message->text = g_strdup("");
  message->text_width = 0.0;
  message->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  message->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) + 0.5;

  message->text_handle.id = HANDLE_MOVE_TEXT;
  message->text_handle.type = HANDLE_MINOR_CONTROL;
  message->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  message->text_handle.connected_to = NULL;
  obj->handles[2] = &message->text_handle;
  
  extra->start_long = 
    extra->start_trans = 
    extra->end_long = message->line_width/2.0;
  extra->end_trans = MAX(message->line_width,MESSAGE_ARROWLEN)/2.0;
  
  message_update_data(message);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return &message->connection.object;
}
Exemple #12
0
static DiaObject *
basestation_create(Point *startpoint,
                   void *user_data,
                   Handle **handle1,
                   Handle **handle2)
{
    Basestation *basestation;
    Element *elem;
    DiaObject *obj;
    Point p;
    DiaFont *font;
    int i;

    basestation = g_new0(Basestation, 1);
    elem = &basestation->element;
    obj = &elem->object;

    obj->type = &basestation_type;
    obj->ops = &basestation_ops;
    elem->corner = *startpoint;
    elem->width = BASESTATION_WIDTH;
    elem->height = BASESTATION_HEIGHT;

    font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8);
    p = *startpoint;
    p.y += BASESTATION_HEIGHT -
           dia_font_descent(_("Base Station"), font, 0.8);

    basestation->text = new_text(_("Base Station"),
                                 font, 0.8, &p, &color_black, ALIGN_CENTER);
    dia_font_unref(font);
    basestation->line_colour = color_black;
    basestation->fill_colour = color_white;
    basestation->sectors = 3;

    element_init(elem, 8, NUM_CONNECTIONS);

    for (i=0; i<NUM_CONNECTIONS; i++) {
        obj->connections[i] = &basestation->connections[i];
        basestation->connections[i].object = obj;
        basestation->connections[i].connected = NULL;
        basestation->connections[i].flags = 0;
    }
    basestation->connections[8].flags = CP_FLAGS_MAIN;

    elem->extra_spacing.border_trans = BASESTATION_LINEWIDTH/2.0;
    basestation_update_data(basestation);

    for (i=0; i<8; i++) {
        obj->handles[i]->type = HANDLE_NON_MOVABLE;
    }

    *handle1 = NULL;
    *handle2 = NULL;
    return &basestation->element.object;
}
Exemple #13
0
static DiaObject *
usecase_create(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  Usecase *usecase;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;

  usecase = g_malloc0(sizeof(Usecase));
  elem = &usecase->element;
  obj = &elem->object;

  obj->type = &usecase_type;
  obj->ops = &usecase_ops;
  elem->corner = *startpoint;
  elem->width = USECASE_WIDTH;
  elem->height = USECASE_HEIGHT;

  usecase->line_width = attributes_get_default_linewidth();
  usecase->line_color = attributes_get_foreground();
  usecase->fill_color = attributes_get_background();

  font = dia_font_new_from_style(DIA_FONT_SANS, 0.8);
  p = *startpoint;
  p.x += USECASE_WIDTH/2.0;
  p.y += USECASE_HEIGHT/2.0;

  usecase->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER);
  dia_font_unref(font);

  usecase->text_outside = 0;
  usecase->collaboration = 0;
  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &usecase->connections[i];
    usecase->connections[i].object = obj;
    usecase->connections[i].connected = NULL;
  }
  usecase->connections[8].flags = CP_FLAGS_MAIN;
  elem->extra_spacing.border_trans = 0.0;
  usecase_update_data(usecase);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }

  *handle1 = NULL;
  *handle2 = NULL;
  return &usecase->element.object;
}
Exemple #14
0
static DiaObject *
textobj_load(ObjectNode obj_node, int version, DiaContext *ctx)
{
  Textobj *textobj;
  DiaObject *obj;
  AttributeNode attr;
  Point startpoint = {0.0, 0.0};

  textobj = g_malloc0(sizeof(Textobj));
  obj = &textobj->object;
  
  obj->type = &textobj_type;
  obj->ops = &textobj_ops;

  object_load(obj, obj_node, ctx);

  attr = object_find_attribute(obj_node, "text");
  if (attr != NULL) {
    textobj->text = data_text(attribute_first_data(attr), ctx);
  } else {
    DiaFont* font = dia_font_new_from_style(DIA_FONT_MONOSPACE,1.0);
    textobj->text = new_text("", font, 1.0,
			     &startpoint, &color_black, ALIGN_CENTER);
    dia_font_unref(font);
  }

  attr = object_find_attribute(obj_node, "valign");
  if (attr != NULL)
    textobj->vert_align = data_enum(attribute_first_data(attr), ctx);
  else if (version == 0) {
    textobj->vert_align = VALIGN_FIRST_LINE;
  }

  /* default visibility must be off to keep compatibility */
  textobj->fill_color = attributes_get_background();
  attr = object_find_attribute(obj_node, "fill_color");
  if (attr)
    data_color(attribute_first_data(attr), &textobj->fill_color, ctx);
  attr = object_find_attribute(obj_node, "show_background");
  if (attr)
    textobj->show_background = data_boolean(attribute_first_data(attr), ctx);
  else
    textobj->show_background = FALSE;

  object_init(obj, 1, 0);

  obj->handles[0] = &textobj->text_handle;
  textobj->text_handle.id = HANDLE_TEXT;
  textobj->text_handle.type = HANDLE_MAJOR_CONTROL;
  textobj->text_handle.connect_type = HANDLE_CONNECTABLE;
  textobj->text_handle.connected_to = NULL;

  textobj_update_data(textobj);

  return &textobj->object;
}
Exemple #15
0
static DiaObject *
largepackage_create(Point *startpoint,
		    void *user_data,
		    Handle **handle1,
		    Handle **handle2)
{
  LargePackage *pkg;
  Element *elem;
  DiaObject *obj;
  int i;
  
  pkg = g_malloc0(sizeof(LargePackage));
  elem = &pkg->element;
  obj = &elem->object;
  
  obj->type = &largepackage_type;

  obj->ops = &largepackage_ops;

  obj->flags |= DIA_OBJECT_CAN_PARENT;

  elem->corner = *startpoint;

  element_init(elem, 8, NUM_CONNECTIONS);

  elem->width = 4.0;
  elem->height = 4.0;
  
  pkg->line_width = attributes_get_default_linewidth();
  pkg->text_color = color_black;
  pkg->line_color = attributes_get_foreground();
  pkg->fill_color = attributes_get_background();
  pkg->font = dia_font_new_from_style(DIA_FONT_MONOSPACE,
                                      LARGEPACKAGE_FONTHEIGHT);
  
  pkg->stereotype = NULL;
  pkg->st_stereotype = NULL;
  pkg->name = g_strdup("");

  pkg->topwidth = 2.0;
  pkg->topheight = LARGEPACKAGE_FONTHEIGHT*2 + 0.1*2;

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &pkg->connections[i];
    pkg->connections[i].object = obj;
    pkg->connections[i].connected = NULL;
  }
  pkg->connections[8].flags = CP_FLAGS_MAIN;
  pkg->element.extra_spacing.border_trans = pkg->line_width/2.0;
  largepackage_update_data(pkg);

  *handle1 = NULL;
  *handle2 = obj->handles[7];
  return &pkg->element.object;
}
Exemple #16
0
static DiaObject *
note_create(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  Note *note;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;
  
  note = g_malloc0(sizeof(Note));
  elem = &note->element;
  obj = &elem->object;
  
  obj->type = &note_type;

  obj->ops = &note_ops;

  elem->corner = *startpoint;

  note->line_width = attributes_get_default_linewidth();
  note->line_color = attributes_get_foreground();
  note->fill_color = attributes_get_background();

  font = dia_font_new_from_style (DIA_FONT_MONOSPACE, 0.8);
  p = *startpoint;
  p.x += note->line_width/2.0 + NOTE_MARGIN_X;
  p.y += note->line_width/2.0 + NOTE_CORNER + dia_font_ascent("A",font, 0.8);
  
  note->text = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT);
  dia_font_unref(font);

  element_init(elem, 8, NUM_CONNECTIONS);
  
  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &note->connections[i];
    note->connections[i].object = obj;
    note->connections[i].connected = NULL;
  }
  note->connections[NUM_CONNECTIONS-1].flags = CP_FLAGS_MAIN;

  elem->extra_spacing.border_trans = note->line_width/2.0;
  note_update_data(note);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }

  *handle1 = NULL;
  *handle2 = NULL;
  return &note->element.object;
}
Exemple #17
0
static DiaObject *
flow_load(ObjectNode obj_node, int version, DiaContext *ctx)
{
  Flow *flow;
  AttributeNode attr;
  Connection *conn;
  DiaObject *obj;
  LineBBExtras *extra;

  flow = g_malloc0(sizeof(Flow));

  conn = &flow->connection;
  obj = &conn->object;
  extra = &conn->extra_spacing;

  obj->type = &flow_type;
  obj->ops = &flow_ops;

  connection_load(conn, obj_node, ctx);
  
  connection_init(conn, 3, 0);

  flow->text = NULL;
  attr = object_find_attribute(obj_node, "text");
  if (attr != NULL)
    flow->text = data_text(attribute_first_data(attr), ctx);
  else { /* pathologic */
    DiaFont *font = dia_font_new_from_style(DIA_FONT_SANS, FLOW_FONTHEIGHT);

    flow->text = new_text("", font, FLOW_FONTHEIGHT, &obj->position, &color_black, ALIGN_CENTER);
    dia_font_unref(font);  
  }

  attr = object_find_attribute(obj_node, "type");
  if (attr != NULL)
    flow->type = (FlowType)data_int(attribute_first_data(attr), ctx);

  flow->text_handle.id = HANDLE_MOVE_TEXT;
  flow->text_handle.type = HANDLE_MINOR_CONTROL;
  flow->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  flow->text_handle.connected_to = NULL;
  flow->text_handle.pos = flow->text->position;
  obj->handles[2] = &flow->text_handle;

  extra->start_long = 
    extra->end_long =
    extra->start_trans = FLOW_WIDTH/2.0;
  extra->end_trans = MAX(FLOW_WIDTH, FLOW_ARROWLEN) / 2.0;
  
  flow->textpos = flow->text->position;
  flow_update_data(flow);
  
  return &flow->connection.object;
}
Exemple #18
0
/** Get the default font.
 * Note that there is currently no way for the user to set these.
 * @param font A place to return the default font description set by the user
 * @param font_height A place to return the default font height set by the user
 */
void
attributes_get_default_font(DiaFont **font, real *font_height)
{
	if (!attributes_font) {
		attributes_font = dia_font_new_from_style(DIA_FONT_SANS,
                                              attributes_font_height);
	}
	if (font)
		*font = dia_font_ref(attributes_font);
	if (font_height)
		*font_height = attributes_font_height;
}
Exemple #19
0
static DiaObject *
radiocell_create(Point *startpoint,
		 void *user_data,
		 Handle **handle1,
		 Handle **handle2)
{
  RadioCell *radiocell;
  PolyShape *poly;
  DiaObject *obj;
  DiaFont *font;
  int i = 0;

  radiocell = g_new0(RadioCell, 1);
  poly = &radiocell->poly;
  obj = &poly->object;
  obj->type = &radiocell_type;
  obj->ops = &radiocell_ops;

  radiocell->radius = 4.;

  /* do not use default_properties.show_background here */
  radiocell->show_background = FALSE;
  radiocell->fill_colour = color_white;
  radiocell->line_colour = color_black;
  radiocell->line_width = RADIOCELL_LINEWIDTH;
  attributes_get_default_line_style(&radiocell->line_style,
				    &radiocell->dashlength);

  font = dia_font_new_from_style(DIA_FONT_MONOSPACE, RADIOCELL_FONTHEIGHT);
  radiocell->text = new_text("", font, RADIOCELL_FONTHEIGHT, startpoint,
			     &color_black, ALIGN_CENTER);
  dia_font_unref(font);

  polyshape_init(poly, 6);

  radiocell->center = *startpoint;
  /* rather broken but otherwise we will always calculate from unitialized data
   * see polyshape_update_data() */
  poly->points[0].y = startpoint->y;
  poly->points[0].x = startpoint->x - radiocell->radius;
  poly->points[3].x = startpoint->x + radiocell->radius;

  radiocell_update_data(radiocell);
  *handle1 = poly->object.handles[0];
  *handle2 = poly->object.handles[2];

  for (i=0;i<6;i++) {
    poly->object.handles[i]->id = HANDLE_CUSTOM1 + i;
  }

  return &radiocell->poly.object;
}
Exemple #20
0
static DiaObject *
state_create_activity(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  State *state;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;
  
  state = g_malloc0(sizeof(State));
  elem = &state->element;
  obj = &elem->object;
  
  obj->type = &activity_type;
  obj->ops = &state_ops;
  elem->corner = *startpoint;
  elem->width = STATE_WIDTH;
  elem->height = STATE_HEIGHT;

  state->line_color = attributes_get_foreground();
  state->fill_color = attributes_get_background();

  font = dia_font_new_from_style (DIA_FONT_SANS, 0.8);
  p = *startpoint;
  p.x += STATE_WIDTH/2.0;
  p.y += STATE_HEIGHT/2.0;
  
  state->text = new_text("", font, 0.8, &p, &color_black, ALIGN_CENTER);
  text_get_attributes(state->text,&state->attrs);
  element_init(elem, 8, 8);
  
  for (i=0;i<8;i++) {
    obj->connections[i] = &state->connections[i];
    state->connections[i].object = obj;
    state->connections[i].connected = NULL;
  }
  elem->extra_spacing.border_trans = 0.0;
  state_update_data(state);

  for (i=0;i<8;i++) {
    obj->handles[i]->type = HANDLE_NON_MOVABLE;
  }

  *handle1 = NULL;
  *handle2 = NULL;
  return &state->element.object;;
}
Exemple #21
0
DiaFont*
dia_font_new(const char *family, DiaFontStyle style, real height)
{
  DiaFont* font = dia_font_new_from_style(style, height);
  gboolean changed;

  changed = family != NULL && strcmp (pango_font_description_get_family(font->pfd), family) != 0;
  pango_font_description_set_family(font->pfd, family);

  if (changed)
    _dia_font_adjust_size (font, font->height, TRUE);

  return font;
}
Exemple #22
0
static DiaObject *
constraint_create(Point *startpoint,
		  void *user_data,
		  Handle **handle1,
		  Handle **handle2)
{
  Constraint *constraint;
  Connection *conn;
  DiaObject *obj;
  Point defaultlen = { 1.0, 1.0 };

  constraint = g_malloc0(sizeof(Constraint));

  /* old defaults */
  constraint->font_height = 0.8;
  constraint->font =
      dia_font_new_from_style (DIA_FONT_MONOSPACE, constraint->font_height);
  constraint->line_width = 0.1;

  conn = &constraint->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  point_add(&conn->endpoints[1], &defaultlen);

  obj = &conn->object;

  obj->type = &constraint_type;
  obj->ops = &constraint_ops;
  
  connection_init(conn, 3, 0);

  constraint->text_color = color_black;
  constraint->line_color = attributes_get_foreground();
  constraint->text = g_strdup("");
  constraint->text_pos.x = 0.5*(conn->endpoints[0].x + conn->endpoints[1].x);
  constraint->text_pos.y = 0.5*(conn->endpoints[0].y + conn->endpoints[1].y) - 0.2;

  constraint->text_handle.id = HANDLE_MOVE_TEXT;
  constraint->text_handle.type = HANDLE_MINOR_CONTROL;
  constraint->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  constraint->text_handle.connected_to = NULL;
  obj->handles[2] = &constraint->text_handle;
  
  constraint->brtext = NULL;
  constraint_update_data(constraint);

  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  return &constraint->connection.object;
}
Exemple #23
0
static void
dia_font_check_for_font(int font) 
{
  DiaFont *check;
  PangoFont *loaded;
  static real height = 1.0;

  check = dia_font_new_from_style(font, height);
  loaded = pango_context_load_font(dia_font_get_context(), check->pfd);
  if (!loaded) {
    message_error(_("Can't load font %s.\n"), dia_font_get_family(check));
  } else {
    g_object_unref (loaded);
  }
}
Exemple #24
0
static DiaObject *node_create(Point *startpoint, void *user_data, Handle **handle1, Handle **handle2)
{
  Node *node;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;
  int i;
  
  node = g_malloc0(sizeof(Node));
  
  /* old defaults */
  node->line_width = 0.1;

  elem = &node->element;
  obj = &elem->object;
  
  obj->type = &node_type;

  obj->ops = &node_ops;

  elem->corner = *startpoint;

  node->line_color = attributes_get_foreground();
  node->fill_color = attributes_get_background();

  font = dia_font_new_from_style (DIA_FONT_SANS, 0.8);
  /* The text position is recalculated later */
  p.x = 0.0;
  p.y = 0.0;
  node->name = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT);
  dia_font_unref(font);
  
  element_init(elem, 8, NUM_CONNECTIONS);

  for (i=0;i<NUM_CONNECTIONS;i++) {
    obj->connections[i] = &node->connections[i];
    node->connections[i].object = obj;
    node->connections[i].connected = NULL;
  }
  node->connections[8].flags = CP_FLAGS_MAIN;
  elem->extra_spacing.border_trans = node->line_width/2.0;
  node_update_data(node);

  *handle1 = NULL;
  *handle2 = obj->handles[7];
  return &node->element.object;
}
Exemple #25
0
static DiaObject *
realizes_create(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  Realizes *realize;
  OrthConn *orth;
  DiaObject *obj;
  PolyBBExtras *extra;

  realize = g_malloc0(sizeof(Realizes));
  /* old defaults */
  realize->font_height = 0.8;
  realize->font =
      dia_font_new_from_style (DIA_FONT_MONOSPACE, realize->font_height);
  realize->line_width = 0.1;

  orth = &realize->orth;
  obj = &orth->object;
  extra = &orth->extra_spacing;

  obj->type = &realizes_type;

  obj->ops = &realizes_ops;

  orthconn_init(orth, startpoint);

  realize->text_color = color_black;
  realize->line_color = attributes_get_foreground();

  realize->name = NULL;
  realize->stereotype = NULL;
  realize->st_stereotype = NULL;
  realize->text_width = 0;

  extra->start_trans = realize->line_width/2.0 + REALIZES_TRIANGLESIZE;
  extra->start_long = 
    extra->middle_trans = 
    extra->end_trans = 
    extra->end_long = realize->line_width/2.0;

  realizes_update_data(realize);
  
  *handle1 = orth->handles[0];
  *handle2 = orth->handles[orth->numpoints-2];
  return &realize->orth.object;
}
Exemple #26
0
Text *
data_text(AttributeNode text_attr, DiaContext *ctx)
{
  char *string = NULL;
  DiaFont *font;
  real height;
  Point pos = {0.0, 0.0};
  Color col;
  Alignment align;
  AttributeNode attr;
  Text *text;

  attr = composite_find_attribute(text_attr, "string");
  if (attr != NULL)
    string = data_string(attribute_first_data(attr), ctx);

  height = 1.0;
  attr = composite_find_attribute(text_attr, "height");
  if (attr != NULL)
    height = data_real(attribute_first_data(attr), ctx);

  attr = composite_find_attribute(text_attr, "font");
  if (attr != NULL) {
    font = data_font(attribute_first_data(attr), ctx);
  } else {
    font = dia_font_new_from_style(DIA_FONT_SANS,1.0);
  }
  
  attr = composite_find_attribute(text_attr, "pos");
  if (attr != NULL)
    data_point(attribute_first_data(attr), &pos, ctx);

  col = color_black;
  attr = composite_find_attribute(text_attr, "color");
  if (attr != NULL)
    data_color(attribute_first_data(attr), &col, ctx);

  align = ALIGN_LEFT;
  attr = composite_find_attribute(text_attr, "alignment");
  if (attr != NULL)
    align = data_enum(attribute_first_data(attr), ctx);
  
  text = new_text(string ? string : "", font, height, &pos, &col, align);
  if (font) dia_font_unref(font);
  if (string) g_free(string);
  return text;
}
Exemple #27
0
/** *NOT A CALLBACK* 

    Caller must set:    - obj->type
    ---------------     - obj->ops

*/
DiaObject *aadlbox_create(Point *startpoint, void *user_data, 
			  Handle **handle1, Handle **handle2)
{

  Aadlbox *aadlbox;
  Element *elem;
  DiaObject *obj;
  Point p;
  DiaFont *font;

  aadlbox = g_malloc0(sizeof(Aadlbox));
  elem = &aadlbox->element;
  obj = &elem->object;

  obj->flags |= DIA_OBJECT_CAN_PARENT;

  elem->corner = *startpoint;

  aadlbox->specific = (Aadlbox_specific *) user_data;

  aadlbox->num_ports = 0;
  aadlbox->ports = NULL;

  aadlbox->line_color = attributes_get_foreground();
  aadlbox->fill_color = attributes_get_background();

  font = dia_font_new_from_style (DIA_FONT_SANS, 0.8);
  /* The text position is recalculated later */
  p.x = 0.0;
  p.y = 0.0;
  aadlbox->name = new_text("", font, 0.8, &p, &color_black, ALIGN_LEFT);
  text_get_attributes(aadlbox->name,&aadlbox->attrs);
  dia_font_unref(font);

  element_init(elem, 8, 0);  /* 8 handles and 0 connection */

  elem->extra_spacing.border_trans = AADLBOX_BORDERWIDTH/2.0;
  aadlbox_update_data(aadlbox);

  *handle1 = NULL;
  *handle2 = obj->handles[7];
  return &aadlbox->element.object;
}
Exemple #28
0
static DiaObject *
chronoref_create(Point *startpoint,
	   void *user_data,
	   Handle **handle1,
	   Handle **handle2)
{
  Chronoref *chronoref;
  Element *elem;
  DiaObject *obj;

  chronoref = g_new0(Chronoref,1);
  elem = &(chronoref->element);

  obj =  &(chronoref->element.object);
  obj->type = &chronoref_type;
  obj->ops = &chronoref_ops;

  chronoref->scale = connpointline_create(obj,0); 

  elem->corner = *startpoint;
  elem->width = 20.0;
  elem->height = 1.0;

  element_init(elem, 8, 0);

  chronoref->font = dia_font_new_from_style (DIA_FONT_SANS,1.0);
  chronoref->font_size = 1.0;
  chronoref->font_color = color_black;
  chronoref->start_time = 0.0;
  chronoref->end_time = 20.0;
  chronoref->time_step = 5.0;
  chronoref->time_lstep = 1.0;
  chronoref->color = color_black;
  chronoref->main_lwidth = .1;
  chronoref->light_lwidth = .05;

  chronoref_update_data(chronoref);

  *handle1 = NULL;
  *handle2 = obj->handles[7];  
  return &chronoref->element.object;
}
Exemple #29
0
static DiaObject *
dependency_create(Point *startpoint,
	       void *user_data,
  	       Handle **handle1,
	       Handle **handle2)
{
  Dependency *dep;
  OrthConn *orth;
  DiaObject *obj;

  if (dep_font == NULL) {
      dep_font = dia_font_new_from_style(DIA_FONT_MONOSPACE, DEPENDENCY_FONTHEIGHT);
  }
  
  dep = g_new0(Dependency, 1);
  orth = &dep->orth;
  obj = (DiaObject *)dep;
  
  obj->type = &dependency_type;

  obj->ops = &dependency_ops;

  orthconn_init(orth, startpoint);

  dep->text_color = color_black;
  dep->line_color = attributes_get_foreground();
  dep->draw_arrow = TRUE;
  dep->name = NULL;
  dep->stereotype = NULL;
  dep->st_stereotype = NULL;
  dep->text_width = 0;

  dependency_update_data(dep);
  
  *handle1 = orth->handles[0];
  *handle2 = orth->handles[orth->numpoints-2];

  return (DiaObject *)dep;
}
Exemple #30
0
static DiaObject *
flow_create(Point *startpoint,
	    void *user_data,
	    Handle **handle1,
	    Handle **handle2)
{
  Flow *flow;
  Connection *conn;
  DiaObject *obj;
  LineBBExtras *extra;
  Point p ;
  Point n ;
  DiaFont *font;

  flow = g_malloc0(sizeof(Flow));

  conn = &flow->connection;
  conn->endpoints[0] = *startpoint;
  conn->endpoints[1] = *startpoint;
  conn->endpoints[1].x += 1.5;
 
  obj = &conn->object;
  extra = &conn->extra_spacing;

  obj->type = &flow_type;
  obj->ops = &flow_ops;
  
  connection_init(conn, 3, 0);

  p = conn->endpoints[1] ;
  point_sub( &p, &conn->endpoints[0] ) ;
  point_scale( &p, 0.5 ) ;
  n.x = p.y ;
  n.y = -p.x ;
  if ( fabs(n.x) < 1.e-5 && fabs(n.y) < 1.e-5 ) {
    n.x = 0. ;
    n.y = -1. ;
  } else {
    point_normalize( &n ) ;
  }
  point_scale( &n, 0.5*FLOW_FONTHEIGHT ) ;

  point_add( &p, &n ) ;
  point_add( &p, &conn->endpoints[0] ) ;
  flow->textpos = p;

  font = dia_font_new_from_style(DIA_FONT_SANS, FLOW_FONTHEIGHT);

  flow->text = new_text("", font, FLOW_FONTHEIGHT, &p, &color_black, ALIGN_CENTER);
  dia_font_unref(font);  

  flow->text_handle.id = HANDLE_MOVE_TEXT;
  flow->text_handle.type = HANDLE_MINOR_CONTROL;
  flow->text_handle.connect_type = HANDLE_NONCONNECTABLE;
  flow->text_handle.connected_to = NULL;
  flow->text_handle.pos = p;
  obj->handles[2] = &flow->text_handle;

  extra->start_long = 
    extra->end_long =
    extra->start_trans = FLOW_WIDTH/2.0;
  extra->end_trans = MAX(FLOW_WIDTH, FLOW_ARROWLEN) / 2.0;
  flow_update_data(flow);
  *handle1 = obj->handles[0];
  *handle2 = obj->handles[1];
  
  return &flow->connection.object;
}