Пример #1
0
/* Callback when the user clicks on a PCB node in the right node treeview.
 */
static void
node_selection_changed_cb (GtkTreeSelection * selection, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  LibraryMenuType *node_net;
  LibraryEntryType *node;
  ConnectionType conn;
  Coord x, y;
  static gchar *node_name;

  if (selection_holdoff)	/* PCB is highlighting, user is not selecting */
    return;

  /* Toggle off the previous selection.  Look up node_name to make sure
  |  it still exists.  This toggling can get out of sync if a node is
  |  toggled selected, then the net that includes the node is selected
  |  then unselected.
  */
  if ((node = node_get_node_from_name (node_name, &node_net)) != NULL)
    {
      /* If net node belongs to has been highlighted/unhighighed, toggling
      |  if off here will get our on/off toggling out of sync.
      */
      if (node_net == node_selected_net)
        {
          toggle_pin_selected (node);
          ghid_cancel_lead_user ();
        }
      g_free (node_name);
      node_name = NULL;
    }

  /* Get the selected treeview row.
   */
  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      if (node)
        ghid_invalidate_all ();
      return;
    }

  /* From the treeview row, extract the node pointer stored there and
  |  we've got a pointer to the LibraryEntryType (node) the row
  |  represents.
  */
  gtk_tree_model_get (model, &iter, NODE_LIBRARY_COLUMN, &node, -1);

  dup_string (&node_name, node->ListEntry);
  node_selected_net = selected_net;

  /* Now just toggle a select of the node on the layout
   */
  toggle_pin_selected (node);
  IncrementUndoSerialNumber ();

  /* And lead the user to the location */
  if (SeekPad (node, &conn, false))
    switch (conn.type) {
      case PIN_TYPE:
        {
          PinType *pin = (PinType *) conn.ptr2;
          x = pin->X;
          y = pin->Y;
          gui->set_crosshair (x, y, 0);
          ghid_lead_user_to_location (x, y);
          break;
        }
      case PAD_TYPE:
        {
          PadType *pad = (PadType *) conn.ptr2;
          x = pad->Point1.X + (pad->Point2.X - pad->Point1.X) / 2;
          y = pad->Point1.Y + (pad->Point2.Y - pad->Point1.Y) / 2;
          gui->set_crosshair (x, y, 0);
          ghid_lead_user_to_location (x, y);
          break;
        }
    }
}
Пример #2
0
/* Callback when the user clicks on a PCB node in the right node treeview.
 */
static void
node_selection_changed_cb (GtkTreeSelection * selection, gpointer data)
{
  GtkTreeIter iter;
  GtkTreeModel *model;
  LibraryMenuType *node_net;
  LibraryEntryType *node;
  static gchar *node_name;
	gint		x0, y0, margin;

  if (selection_holdoff)	/* PCB is highlighting, user is not selecting */
    return;

  /* Toggle off the previous selection.  Look up node_name to make sure
  |  it still exists.  This toggling can get out of sync if a node is
  |  toggled selected, then the net that includes the node is selected
  |  then unselected.
  */
  if ((node = node_get_node_from_name (node_name, &node_net)) != NULL)
    {
      /* If net node belongs to has been highlighted/unhighighed, toggling
      |  if off here will get our on/off toggling out of sync.
      */
      if (node_net == node_selected_net)
	SelectPin (node, TRUE);
      g_free (node_name);
      node_name = NULL;
    }

  /* Get the selected treeview row.
   */
  if (!gtk_tree_selection_get_selected (selection, &model, &iter))
    {
      if (node)
        ghid_invalidate_all ();
      return;
    }

  /* From the treeview row, extract the node pointer stored there and
  |  we've got a pointer to the LibraryEntryType (node) the row
  |  represents.
  */
  gtk_tree_model_get (model, &iter, NODE_LIBRARY_COLUMN, &node, -1);

  dup_string (&node_name, node->ListEntry);
  node_selected_net = selected_net;

  /* Now just toggle a select of the node on the layout and pan.
   */
  SelectPin (node, TRUE);
  IncrementUndoSerialNumber ();
	margin = gport->view_width / 20;
	if (   Crosshair.X < gport->view_x0 + margin
	    || Crosshair.X > gport->view_x0 + gport->view_width - margin
	    || Crosshair.Y < gport->view_y0 + margin
	    || Crosshair.Y > gport->view_y0 + gport->view_height - margin
	   )
	  {

	    x0 = SIDE_X (Crosshair.X) - gport->view_width / 2;
	    y0 = SIDE_Y (Crosshair.Y) - gport->view_height / 2;
	    gport->view_x0 = x0;
	    gport->view_y0 = y0;
	    ghid_pan_fixup ();
	    gui->set_crosshair (Crosshair.X, Crosshair.Y, HID_SC_WARP_POINTER);
	  }
	ghid_screen_update();
}