Exemple #1
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
void o_complex_rotate_world(TOPLEVEL *toplevel,
                            int centerx, int centery,
                            int angle, OBJECT *object)
{
  int x, y;
  int newx, newy;

  g_return_if_fail (object!=NULL);
  g_return_if_fail ((object->type == OBJ_COMPLEX) ||
                    (object->type == OBJ_PLACEHOLDER));

  x = object->complex->x + (-centerx);
  y = object->complex->y + (-centery);

  rotate_point_90(x, y, angle, &newx, &newy);

  x = newx + (centerx);
  y = newy + (centery);

  o_complex_translate_world(toplevel,
                            -object->complex->x,
                            -object->complex->y, object);
  o_glist_rotate_world (toplevel, 0, 0, angle, object->complex->prim_objs);

  object->complex->x = 0;
  object->complex->y = 0;

  o_complex_translate_world(toplevel, x, y, object);

  object->complex->angle = ( object->complex->angle + angle ) % 360;
}
Exemple #2
0
/*! \brief Rotate all objects in list.
 *  \par Function Description
 *  Given an object <B>list</B>, and the center of rotation
 *  (<B>centerx</B>,<B>centery</B>, this function traverses all the selection
 *  list, rotating each object through angle <B>angle</B>.
 *  The list contains a given object and all its attributes
 *  (refdes, pinname, pinlabel, ...).
 *  There is a second pass to run the rotate hooks of non-simple objects,
 *  like pin or complex objects, for example.
 *
 *  \param [in] w_current  The GschemToplevel object.
 *  \param [in] centerx    Center x coordinate of rotation.
 *  \param [in] centery    Center y coordinate of rotation.
 *  \param [in] angle      Angle to rotate the objects through.
 *  \param [in] list       The list of objects to rotate.
 */
void o_rotate_world_update(GschemToplevel *w_current,
                           int centerx, int centery, int angle, GList *list)
{
  TOPLEVEL *toplevel = gschem_toplevel_get_toplevel (w_current);
  OBJECT *o_current;
  GList *o_iter;

  /* this is okay if you just hit rotate and have nothing selected */
  if (list == NULL) {
    i_action_stop (w_current);
    i_set_state(w_current, SELECT);
    return;
  }

  o_invalidate_glist (w_current, list);

  /* Find connected objects, removing each object in turn from the
   * connection list. We only _really_ want those objects connected
   * to the selection, not those within in it.
   */
  for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) {
    o_current = o_iter->data;

    s_conn_remove_object_connections (toplevel, o_current);
  }

  o_glist_rotate_world( toplevel, centerx, centery, angle, list );

  /* Find connected objects, adding each object in turn back to the
   * connection list. We only _really_ want those objects connected
   * to the selection, not those within in it.
   */
  for (o_iter = list; o_iter != NULL; o_iter = g_list_next (o_iter)) {
    o_current = o_iter->data;

    s_conn_update_object (o_current->page, o_current);
  }

  o_invalidate_glist (w_current, list);

  /* Run rotate-objects-hook */
  g_run_hook_object_list (w_current, "%rotate-objects-hook", list);

  /* Don't save the undo state if we are inside an action */
  /* This is useful when rotating the selection while moving, for example */
  gschem_toplevel_page_content_changed (w_current, toplevel->page_current);
  if (!w_current->inside_action) {
    o_undo_savestate_old(w_current, UNDO_ALL);
  }

  if (w_current->event_state == ROTATEMODE) {
    i_set_state(w_current, SELECT);
  }
}
Exemple #3
0
/*! \todo Finish function documentation!!!
 *  \brief
 *  \par Function Description
 *
 */
void o_place_rotate (GSCHEM_TOPLEVEL *w_current)
{
  TOPLEVEL *toplevel = w_current->toplevel;

  o_glist_rotate_world (toplevel,
                        w_current->first_wx, w_current->first_wy, 90,
                        toplevel->page_current->place_list);


  /* Run rotate-objects-hook */
  g_run_hook_object_list ("%rotate-objects-hook",
                          toplevel->page_current->place_list);
}
Exemple #4
0
/*! \brief Rotate the objects being placed
 *
 *  \par Function Description
 *  This function erases the objects in the place list, rotates
 *  them, runs %rotate-objects-hook, and redraws the objects after
 *  rotating.
 *
 *  \param [in] w_current   The GschemToplevel object.
 */
void o_place_rotate (GschemToplevel *w_current)
{
  GschemPageView *page_view = gschem_toplevel_get_current_page_view (w_current);
  g_return_if_fail (page_view != NULL);

  PAGE *page = gschem_page_view_get_page (page_view);
  g_return_if_fail (page != NULL);

  o_place_invalidate_rubber (w_current, FALSE);

  o_glist_rotate_world (page->toplevel,
                        w_current->first_wx,
                        w_current->first_wy,
                        90,
                        page->place_list);

  /* Run rotate-objects-hook */
  g_run_hook_object_list (w_current, "%rotate-objects-hook", page->place_list);

  o_place_invalidate_rubber (w_current, TRUE);
}
Exemple #5
0
/*! \brief
 *  \par Function Description
 *
 */
OBJECT *o_complex_new(TOPLEVEL *toplevel,
		      char type,
		      int color, int x, int y, int angle,
		      int mirror, const CLibSymbol *clib,
		      const gchar *basename,
		      int selectable)
{
  OBJECT *new_node=NULL;
  OBJECT *new_prim_obj;
  GList *prim_objs;
  GList *iter;
  int loaded_normally = FALSE;

  gchar *buffer = NULL;

  new_node = s_basic_new_object(type, "complex");

  if (clib != NULL) {
    new_node->complex_basename = g_strdup (s_clib_symbol_get_name (clib));
  } else {
    new_node->complex_basename = g_strdup (basename);
  }


  new_node->complex_embedded = FALSE;
  new_node->color = color;
  new_node->selectable = selectable;

  new_node->complex = (COMPLEX *) g_malloc(sizeof(COMPLEX));
  new_node->complex->angle = angle;
  new_node->complex->mirror = mirror;
  new_node->complex->x = x;
  new_node->complex->y = y;

  prim_objs = NULL;

  /* get the symbol data */
  if (clib != NULL) {
    buffer = s_clib_symbol_get_data (clib);
  }

  if (clib == NULL || buffer == NULL) {

    char *not_found_text = NULL;
    int left, right, top, bottom;
    int x_offset, y_offset;

    /* filename was NOT found */
    loaded_normally = FALSE;

    /* Put placeholder into object list.  Changed by SDB on
     * 1.19.2005 to fix problem that symbols were silently
     * deleted by gattrib when RC files were messed up.  */
    new_node->type = OBJ_PLACEHOLDER;

    /* Mark the origin of the missing component */
    new_prim_obj = o_line_new(toplevel, OBJ_LINE,
                           DETACHED_ATTRIBUTE_COLOR,
                           x - 50, y, x + 50, y);
    prim_objs = g_list_append (prim_objs, new_prim_obj);
    new_prim_obj = o_line_new(toplevel, OBJ_LINE,
                           DETACHED_ATTRIBUTE_COLOR,
                           x, y + 50, x, y - 50); 
    prim_objs = g_list_append (prim_objs, new_prim_obj);

    /* Add some useful text */
    not_found_text = 
      g_strdup_printf (_("Component not found:\n %s"),
		       new_node->complex_basename);
    new_prim_obj = o_text_new(toplevel,
                           OBJ_TEXT, DETACHED_ATTRIBUTE_COLOR, 
                           x + NOT_FOUND_TEXT_X, 
                           y + NOT_FOUND_TEXT_Y, LOWER_LEFT, 0, 
                           not_found_text, 8,
                           VISIBLE, SHOW_NAME_VALUE);
    prim_objs = g_list_append (prim_objs, new_prim_obj);
    g_free(not_found_text);

    /* figure out where to put the hazard triangle */
    world_get_text_bounds (toplevel, new_prim_obj, &left, &top, &right, &bottom);
    x_offset = (right - left) / 4;
    y_offset = bottom - top + 100;  /* 100 is just an additional offset */

    /* add hazard triangle */
    new_prim_obj = o_line_new(toplevel, OBJ_LINE,
                           DETACHED_ATTRIBUTE_COLOR,
                           x + NOT_FOUND_TEXT_X + x_offset, 
                           y + NOT_FOUND_TEXT_Y + y_offset, 
                           x + NOT_FOUND_TEXT_X + x_offset + 600, 
                           y + NOT_FOUND_TEXT_Y + y_offset); 
    o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID,
                       50, -1, -1);
    prim_objs = g_list_append (prim_objs, new_prim_obj);
    new_prim_obj = o_line_new(toplevel, OBJ_LINE,
                           DETACHED_ATTRIBUTE_COLOR,
                           x + NOT_FOUND_TEXT_X + x_offset, 
                           y + NOT_FOUND_TEXT_Y + y_offset, 
                           x + NOT_FOUND_TEXT_X + x_offset + 300, 
                           y + NOT_FOUND_TEXT_Y + y_offset + 500); 
    o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID,
                       50, -1, -1);
    prim_objs = g_list_append (prim_objs, new_prim_obj);
    new_prim_obj = o_line_new(toplevel, OBJ_LINE,
                           DETACHED_ATTRIBUTE_COLOR,
                           x + NOT_FOUND_TEXT_X + x_offset + 300, 
                           y + NOT_FOUND_TEXT_Y + y_offset + 500, 
                           x + NOT_FOUND_TEXT_X + x_offset + 600, 
                           y + NOT_FOUND_TEXT_Y + y_offset); 
    o_set_line_options(toplevel, new_prim_obj, END_ROUND, TYPE_SOLID,
                       50, -1, -1);
    prim_objs = g_list_append (prim_objs, new_prim_obj);
    new_prim_obj = o_text_new(toplevel,
                           OBJ_TEXT, DETACHED_ATTRIBUTE_COLOR, 
                           x + NOT_FOUND_TEXT_X + x_offset + 270, 
                           y + NOT_FOUND_TEXT_Y + y_offset + 90, 
                           LOWER_LEFT, 0, "!", 18,
                           VISIBLE, SHOW_NAME_VALUE);
    prim_objs = g_list_append (prim_objs, new_prim_obj);

  } else {

    /* filename was found */
    loaded_normally = TRUE;

    /* add connections till translated */
    prim_objs = o_read_buffer (toplevel, prim_objs, buffer, -1, new_node->complex_basename);

    g_free (buffer);

  }

  /* do not mirror/rotate/translate/connect the primitive objects if the
   * component was not loaded via o_read 
   */
  if (loaded_normally == TRUE) {
    if (mirror) {
      o_glist_mirror_world (toplevel, 0, 0, prim_objs);
    }

    o_glist_rotate_world (toplevel, 0, 0, angle, prim_objs);
    o_glist_translate_world (toplevel, x, y, prim_objs);
  }

  new_node->complex->prim_objs = prim_objs;

  /* set the parent field now */
  for (iter = prim_objs; iter != NULL; iter = g_list_next (iter)) {
    OBJECT *tmp = iter->data;
    tmp->parent = new_node;
  }

  o_complex_recalc(toplevel, new_node);

  return new_node;
}