예제 #1
0
static void stretch_draw_state_change (QCADStretchyObject *obj, int x, int y, int xRef, int yRef)
  {
  int Nix ;
  QCADRuler *ruler = QCAD_RULER (obj) ;
  int xMIN = MIN (x, xRef), xMAX = MAX (x, xRef), yMIN = MIN (y, yRef), yMAX = MAX (y, yRef) ;
  QCADStretchyObjectClass *klass = QCAD_STRETCHY_OBJECT_CLASS (g_type_class_peek (g_type_parent (QCAD_TYPE_RULER))) ;

  if (NULL != klass->stretch_draw_state_change)
    klass->stretch_draw_state_change (obj, x, y, xRef, yRef) ;

  ruler->ruler_bounding_box.xWorld = real_to_world_x (xMIN) ;
  ruler->ruler_bounding_box.yWorld = real_to_world_y (yMIN) ;
  ruler->ruler_bounding_box.cxWorld = real_to_world_cx (xMAX - xMIN) ;
  ruler->ruler_bounding_box.cyWorld = real_to_world_cy (yMAX - yMIN) ;

  memcpy (&(QCAD_DESIGN_OBJECT (obj)->bounding_box), &(ruler->ruler_bounding_box), sizeof (WorldRectangle)) ;

  for (Nix = 0 ; Nix < ruler->icLabelsVisible ; Nix++)
    world_rect_union (&(QCAD_DESIGN_OBJECT (obj)->bounding_box), &(QCAD_DESIGN_OBJECT (exp_array_index_1d (ruler->labels, GRADUATION, Nix).lbl)->bounding_box), &(QCAD_DESIGN_OBJECT (obj)->bounding_box)) ;

  QCAD_RULER (obj)->orientation =
    QCAD_RULER_CALCULATE_ORIENTATION (
      ruler->ruler_bounding_box.cxWorld,
      ruler->ruler_bounding_box.cyWorld, x, y, xRef, yRef) ;
  }
예제 #2
0
void qcad_layer_dump (QCADLayer *layer, FILE *pfile)
  {
  GList *lstSelObj = NULL, *lstObj = NULL ;

  fprintf (pfile, "Layer \"%s\"(0x%08X):\n", layer->pszDescription, (int)layer) ;
/*#ifdef GTK_GUI*/
/*  fprintf (pfile, "combo_item = 0x%08X\n", (int)(layer->combo_item)) ;*/
//#endif /* def GTK_GUI */
  if (NULL != layer->lstObjs)
    {
    fprintf (stderr, "lstObjs:|0x%08X|->", (int)(layer->lstObjs)) ;
    for (lstObj = layer->lstObjs ; lstObj != NULL ; lstObj = lstObj->next)
      {
      if (LAYER_TYPE_CELLS == layer->type)
        {
        if (NULL != lstObj->data)
          {
          if (NULL != lstObj->next)
            fprintf (pfile, "|[%.2lf,%.2lf]|0x%08X|->", QCAD_DESIGN_OBJECT (lstObj->data)->x, QCAD_DESIGN_OBJECT (lstObj->data)->y, (int)(lstObj->next)) ;
          else
            fprintf (pfile, "|[%.2lf,%.2lf]|0x%08X|\n", QCAD_DESIGN_OBJECT (lstObj->data)->x, QCAD_DESIGN_OBJECT (lstObj->data)->y, (int)(lstObj->next)) ;
          }
        else
          {
          if (NULL != lstObj->next)
            fprintf (pfile, "|0x%08X|0x%08X|->", (int)(lstObj->data), (int)(lstObj->next)) ;
          else
            fprintf (pfile, "|0x%08X|0x%08X|\n", (int)(lstObj->data), (int)(lstObj->next)) ;
          }
        }
      else
        {
        if (NULL != lstObj->next)
          fprintf (pfile, "|0x%08X|0x%08X|->", (int)(lstObj->data), (int)(lstObj->next)) ;
        else
          fprintf (pfile, "|0x%08X|0x%08X|\n", (int)(lstObj->data), (int)(lstObj->next)) ;
        }
      }
    }
  else
    fprintf (stderr, "lstObjs:|0x%08X|\n", (int)(layer->lstObjs)) ;

  if (NULL == layer->lstSelObjs)
    fprintf (stderr, "lstSelObjs:|0x%08X|\n", (int)(layer->lstSelObjs)) ;
  else
    {
    fprintf (stderr, "lstSelObjs:|0x%08X|->", (int)(layer->lstSelObjs)) ;
    for (lstSelObj = layer->lstSelObjs ; lstSelObj != NULL ; lstSelObj = lstSelObj->next)
      {
	    if (NULL != lstSelObj->next)
        fprintf (pfile, "|0x%08X|0x%08X|->", (int)(lstSelObj->data), (int)(lstSelObj->next)) ;
      else
        fprintf (pfile, "|0x%08X|0x%08X|\n", (int)(lstSelObj->data), (int)(lstSelObj->next)) ;
      }
    }
  }
예제 #3
0
static gboolean button_pressed (GtkWidget *widget, GdkEventButton *event, gpointer data)
  {
  QCADDesignObject *obj = NULL ;
  double xWorld = real_to_world_x (event->x), yWorld = real_to_world_y (event->y) ;

  if (1 != event->button) return FALSE ;

#ifdef DESIGNER
  world_to_grid_pt (&xWorld, &yWorld) ;
#endif /* def DESIGNER */

//  fprintf (stderr, "QCADRectangleElectrode::button_pressed:Calling qcad_rectangle_electrode_new\n") ;
  obj = QCAD_DESIGN_OBJECT (qcad_object_new_from_object (qcad_object_get_default (QCAD_TYPE_RECTANGLE_ELECTRODE))) ;
//  fprintf (stderr, "QCADRectangleElectrode::button_pressed:Calling qcad_design_object_move\n") ;
  qcad_design_object_move_to (obj, xWorld, yWorld) ;

#ifdef DESIGNER
  if (NULL != drop_function)
    if ((*drop_function) (obj))
      return FALSE ;
#endif /* def DESIGNER */

  g_object_unref (obj) ;

  return FALSE ;
  }
예제 #4
0
static void copy (QCADDesignObject *src, QCADDesignObject *dst)
  {
  GList *llItr = NULL ;
  QCADLayer *srcLayer = NULL, *dstLayer = NULL ;

  if (NULL == src || NULL == dst) return ;
  if (!(QCAD_IS_LAYER (src) && QCAD_IS_LAYER (dst))) return ;
  srcLayer = QCAD_LAYER (src) ;
  dstLayer = QCAD_LAYER (dst) ;

  dstLayer->type = srcLayer->type ;
/*  dstLayer->status = srcLayer->status ;*/
  dstLayer->pszDescription = (NULL == srcLayer->pszDescription ? NULL : g_strdup (srcLayer->pszDescription)) ;

  for (llItr = g_list_last (srcLayer->lstObjs) ; llItr != NULL ; llItr = llItr->prev)
    {
    if (NULL != llItr->data)
      qcad_do_container_add (QCAD_DO_CONTAINER (dstLayer),
        qcad_design_object_new_from_object (QCAD_DESIGN_OBJECT (llItr->data))) ;
    if (llItr == srcLayer->llContainerIter)
      dstLayer->llContainerIter = dstLayer->lstObjs ;
    }
/*#ifdef GTK_GUI*/
/*  // SHALLOW COPY of combo item*/
/*  dstLayer->combo_item = srcLayer->combo_item ;*/
//#endif /* def GTK_GUI */
  // NOT COPYING THE DEFAULT PROPERTIES HASH TABLE !!!
  }
예제 #5
0
gboolean button_pressed_ACTION_ROTATE (GtkWidget *widget, GdkEventButton *event, gpointer data)
  {
  project_OP *project_options = (project_OP *)data ;
  QCADDesignObject *htobj = NULL ;
  GdkRegion *rgn = NULL ;

  if (NULL != (htobj = QCAD_DESIGN_OBJECT (design_hit_test (project_options->design, event->x, event->y))))
    if (QCAD_IS_CELL (htobj))
      {
      GdkRectangle rcReal ;
      selection_renderer_draw (project_options->srSelection, project_options->design, widget->window, GDK_XOR) ;
      qcad_cell_rotate_dots (QCAD_CELL (htobj), PI / 4.0) ;
      selection_renderer_update (project_options->srSelection, project_options->design) ;
      selection_renderer_draw (project_options->srSelection, project_options->design, widget->window, GDK_XOR) ;

      world_to_real_rect (&(htobj->bounding_box), &rcReal) ;

      rgn = gdk_region_new () ;
      gdk_region_union_with_rect (rgn, &rcReal) ;

      // redraw_async takes care of destroying rgn
      redraw_async (rgn) ;
      }

  return FALSE ;
  }
예제 #6
0
static void move (QCADDesignObject *obj, double dxWorld, double dyWorld)
  {
  int Nix ;
  QCADRuler *ruler = QCAD_RULER (obj) ;

  QCAD_DESIGN_OBJECT_CLASS (g_type_class_peek (g_type_parent (QCAD_TYPE_RULER)))->move (obj, dxWorld, dyWorld) ;

  for (Nix = 0 ; Nix < ruler->icLabelsVisible ; Nix++)
    qcad_design_object_move (QCAD_DESIGN_OBJECT (exp_array_index_1d (ruler->labels, GRADUATION, Nix).lbl), dxWorld, dyWorld) ;
  }
예제 #7
0
static void qcad_ruler_instance_init (GObject *object, gpointer data)
  {
  DBG_OO (fprintf (stderr, "QCADRuler::instance_init:Entering\n")) ;
  QCAD_RULER (object)->labels = exp_array_new (sizeof (GRADUATION), 1) ;
  memcpy (&(QCAD_DESIGN_OBJECT (object)->clr), &clrCyan, sizeof (GdkColor)) ;
  QCAD_RULER (object)->ruler_bounding_box.xWorld =
  QCAD_RULER (object)->ruler_bounding_box.yWorld =
  QCAD_RULER (object)->ruler_bounding_box.cxWorld =
  QCAD_RULER (object)->ruler_bounding_box.cyWorld = 0.0 ;
  DBG_OO (fprintf (stderr, "QCADRuler::instance_init:Leaving\n")) ;
  }
예제 #8
0
gboolean qcad_layer_get_extents (QCADLayer *layer, WorldRectangle *extents, gboolean bSelection)
  {
  gboolean bHaveBaseLine = FALSE ;
  WorldRectangle rcWorld ;
  GList *lstObj = NULL, *llMaster = NULL ;
  double x, y ;

  if (NULL == layer || NULL == extents) return FALSE ;

  llMaster = (bSelection ? layer->lstSelObjs : layer->lstObjs) ;

  if (NULL != (lstObj = llMaster))
    {
    while (NULL != lstObj)
      if (NULL == lstObj->data)
        lstObj = lstObj->next ;
      else
        break ;
    if (NULL != lstObj)
      {
      qcad_design_object_get_bounds_box (QCAD_DESIGN_OBJECT (lstObj->data), extents) ;
      bHaveBaseLine = TRUE ;

      for (lstObj = lstObj->next ; lstObj != NULL ; lstObj = lstObj->next)
        if (NULL != lstObj->data)
          {
          x = extents->xWorld ;
          y = extents->yWorld ;
          qcad_design_object_get_bounds_box (QCAD_DESIGN_OBJECT (lstObj->data), &rcWorld) ;
          extents->xWorld = MIN (extents->xWorld, rcWorld.xWorld) ;
          extents->yWorld = MIN (extents->yWorld, rcWorld.yWorld) ;
          extents->cxWorld = MAX (x + extents->cxWorld, rcWorld.xWorld + rcWorld.cxWorld) - extents->xWorld ;
          extents->cyWorld = MAX (y + extents->cyWorld, rcWorld.yWorld + rcWorld.cyWorld) - extents->yWorld ;
          }
      }
    }
  return bHaveBaseLine ;
  }
예제 #9
0
static void qcad_label_instance_init (GObject *object, gpointer data)
  {
  DBG_OO (fprintf (stderr, "QCADLabel::instance_init:Entering\n")) ;
  QCAD_LABEL (object)->psz = g_strdup (_("Label")) ;
  QCAD_LABEL (object)->bNeedsEPMDraw = TRUE ;
  QCAD_LABEL (object)->bShrinkWrap = TRUE ;
#ifdef GTK_GUI
  QCAD_LABEL (object)->epm = NULL ;
#endif /* def GTK_GUI */
  QCAD_DESIGN_OBJECT (object)->x =
  QCAD_DESIGN_OBJECT (object)->y =
  QCAD_DESIGN_OBJECT (object)->bounding_box.xWorld =
  QCAD_DESIGN_OBJECT (object)->bounding_box.yWorld =
  QCAD_DESIGN_OBJECT (object)->bounding_box.cxWorld =
  QCAD_DESIGN_OBJECT (object)->bounding_box.cyWorld = 0.0 ;
  memcpy (&(QCAD_DESIGN_OBJECT (object)->clr), &clrBlue, sizeof (GdkColor)) ;
  qcad_label_shrinkwrap (QCAD_LABEL (object)) ;
  DBG_OO (fprintf (stderr, "QCADLabel::instance_init:Leaving\n")) ;
  }
예제 #10
0
void qcad_label_shrinkwrap (QCADLabel *label)
  {
  // This function has no effect if there's no Gtk, because there's no way to measure the (cx,cy) of a
  // string without Gdk
  #ifdef GTK_GUI
  int cx, cy ;
  char *pszFont ;

  get_string_dimensions (label->psz, pszFont = g_strdup_printf ("Courier %d", world_to_real_cy (CYFONT)), &cx, &cy) ;
  g_free (pszFont) ;

  QCAD_DESIGN_OBJECT (label)->bounding_box.cxWorld = real_to_world_cx (cx + 2.0 * XTOP_LABEL_OFFSET) ;
  QCAD_DESIGN_OBJECT (label)->bounding_box.cyWorld = real_to_world_cy (cy + 2.0 * YTOP_LABEL_OFFSET) ;
  QCAD_DESIGN_OBJECT (label)->x = QCAD_DESIGN_OBJECT (label)->bounding_box.cxWorld / 2.0 + QCAD_DESIGN_OBJECT (label)->bounding_box.xWorld ;
  QCAD_DESIGN_OBJECT (label)->y = QCAD_DESIGN_OBJECT (label)->bounding_box.cyWorld / 2.0 + QCAD_DESIGN_OBJECT (label)->bounding_box.yWorld ;
  #endif /* def GTK_GUI */
  }
예제 #11
0
static QCADLabel *get_label_from_array (EXP_ARRAY *ar, int idx, double dCurrentGrad, GdkColor *clr)
  {
  GRADUATION grad = {NULL, 0.0} ;
  GRADUATION *ar_grad = NULL ;

  if (idx == ar->icUsed)
    {
    grad.lbl = qcad_label_new ("%.2lf", dCurrentGrad) ;
    grad.dVal = dCurrentGrad ;
    exp_array_insert_vals (ar, &grad, 1, 1, -1) ;
    ar_grad = &grad ;
    }
  else
  if ((ar_grad = &exp_array_index_1d (ar, GRADUATION, idx))->dVal != dCurrentGrad)
    {
    qcad_label_set_text (QCAD_LABEL (ar_grad->lbl), "%.2lf", dCurrentGrad) ;
    ar_grad->dVal = dCurrentGrad ;
    }

  memcpy (&(QCAD_DESIGN_OBJECT (ar_grad->lbl)->clr), clr, sizeof (GdkColor)) ;

  return ar_grad->lbl ;
  }
예제 #12
0
static void precompute (QCADElectrode *electrode)
  {
  int Nix, Nix1 ;
  WorldPoint ptSrcLine, ptDstLine ;
  double factor1, factor2, dstx_minus_srcx, dsty_minus_srcy ;
  double pt1x_minus_pt0x, pt1y_minus_pt0y, pt3x_minus_pt2x, pt3y_minus_pt2y ;
  double reciprocal_of_x_divisions, reciprocal_of_y_divisions ;
  QCADRectangleElectrode *rc_electrode = QCAD_RECTANGLE_ELECTRODE (electrode) ;
  QCADDesignObject *obj = QCAD_DESIGN_OBJECT (electrode) ;
  double 
    kose =  cos (rc_electrode->angle),
    msin = -sin (rc_electrode->angle),
    sine =  sin (rc_electrode->angle),
    half_cx = rc_electrode->cxWorld / 2.0,
    half_cy = rc_electrode->cyWorld / 2.0,
    xMin, yMin, xMax, yMax ;
  WorldPoint pt[4] = {{0,0},{0,0},{0,0},{0,0}}, ptCenter = {0,0} ;

  // Call parent precompute function
  QCAD_ELECTRODE_CLASS (g_type_class_peek (g_type_parent (QCAD_TYPE_RECTANGLE_ELECTRODE)))->precompute (electrode) ;

  ptCenter.xWorld = obj->bounding_box.xWorld + obj->bounding_box.cxWorld / 2.0 ;
  ptCenter.yWorld = obj->bounding_box.yWorld + obj->bounding_box.cyWorld / 2.0 ;

  // Create corner points
  pt[0].xWorld = ptCenter.xWorld - half_cx ;
  pt[0].yWorld = ptCenter.yWorld - half_cy ;
  pt[1].xWorld = ptCenter.xWorld + half_cx ;
  pt[1].yWorld = ptCenter.yWorld - half_cy ;
  pt[2].xWorld = ptCenter.xWorld + half_cx ;
  pt[2].yWorld = ptCenter.yWorld + half_cy ;
  pt[3].xWorld = ptCenter.xWorld - half_cx ;
  pt[3].yWorld = ptCenter.yWorld + half_cy ;

  if (0 != rc_electrode->angle)
    {
    // rotate corner points
    rc_electrode->precompute_params.pt[0].xWorld = kose * pt[0].xWorld + sine * pt[0].yWorld ;
    rc_electrode->precompute_params.pt[0].yWorld = msin * pt[0].xWorld + kose * pt[0].yWorld ;
    rc_electrode->precompute_params.pt[1].xWorld = kose * pt[1].xWorld + sine * pt[1].yWorld ;
    rc_electrode->precompute_params.pt[1].yWorld = msin * pt[1].xWorld + kose * pt[1].yWorld ;
    rc_electrode->precompute_params.pt[2].xWorld = kose * pt[2].xWorld + sine * pt[2].yWorld ;
    rc_electrode->precompute_params.pt[2].yWorld = msin * pt[2].xWorld + kose * pt[2].yWorld ;
    rc_electrode->precompute_params.pt[3].xWorld = kose * pt[3].xWorld + sine * pt[3].yWorld ;
    rc_electrode->precompute_params.pt[3].yWorld = msin * pt[3].xWorld + kose * pt[3].yWorld ;

    // Find binding box
    xMin = MIN (rc_electrode->precompute_params.pt[0].xWorld, MIN (rc_electrode->precompute_params.pt[1].xWorld, MIN (rc_electrode->precompute_params.pt[2].xWorld, rc_electrode->precompute_params.pt[3].xWorld))) ;
    xMax = MAX (rc_electrode->precompute_params.pt[0].xWorld, MAX (rc_electrode->precompute_params.pt[1].xWorld, MAX (rc_electrode->precompute_params.pt[2].xWorld, rc_electrode->precompute_params.pt[3].xWorld))) ;
    yMin = MIN (rc_electrode->precompute_params.pt[0].yWorld, MIN (rc_electrode->precompute_params.pt[1].yWorld, MIN (rc_electrode->precompute_params.pt[2].yWorld, rc_electrode->precompute_params.pt[3].yWorld))) ;
    yMax = MAX (rc_electrode->precompute_params.pt[0].yWorld, MAX (rc_electrode->precompute_params.pt[1].yWorld, MAX (rc_electrode->precompute_params.pt[2].yWorld, rc_electrode->precompute_params.pt[3].yWorld))) ;

    obj->bounding_box.xWorld = xMin ;
    obj->bounding_box.yWorld = yMin ;
    obj->bounding_box.cxWorld = xMax - xMin ;
    obj->bounding_box.cyWorld = yMax - yMin ;
    obj->x = obj->bounding_box.xWorld + obj->bounding_box.cxWorld / 2.0 ;
    obj->y = obj->bounding_box.yWorld + obj->bounding_box.cyWorld / 2.0 ;

    // move points back
    rc_electrode->precompute_params.pt[0].xWorld += ptCenter.xWorld - obj->x ;
    rc_electrode->precompute_params.pt[0].yWorld += ptCenter.yWorld - obj->y ;
    rc_electrode->precompute_params.pt[1].xWorld += ptCenter.xWorld - obj->x ;
    rc_electrode->precompute_params.pt[1].yWorld += ptCenter.yWorld - obj->y ;
    rc_electrode->precompute_params.pt[2].xWorld += ptCenter.xWorld - obj->x ;
    rc_electrode->precompute_params.pt[2].yWorld += ptCenter.yWorld - obj->y ;
    rc_electrode->precompute_params.pt[3].xWorld += ptCenter.xWorld - obj->x ;
    rc_electrode->precompute_params.pt[3].yWorld += ptCenter.yWorld - obj->y ;
    obj->bounding_box.xWorld += ptCenter.xWorld - obj->x ;
    obj->bounding_box.yWorld += ptCenter.yWorld - obj->y ;
    obj->x = ptCenter.xWorld ;
    obj->y = ptCenter.yWorld ;
    }
  else
    {
    rc_electrode->precompute_params.pt[0] = pt[0] ;
    rc_electrode->precompute_params.pt[1] = pt[1] ;
    rc_electrode->precompute_params.pt[2] = pt[2] ;
    rc_electrode->precompute_params.pt[3] = pt[3] ;
    obj->bounding_box.xWorld = pt[0].xWorld ;
    obj->bounding_box.yWorld = pt[0].yWorld ;
    obj->bounding_box.cxWorld = rc_electrode->cxWorld ;
    obj->bounding_box.cyWorld = rc_electrode->cyWorld ;
    obj->x = obj->bounding_box.xWorld + obj->bounding_box.cxWorld / 2.0 ;
    obj->y = obj->bounding_box.yWorld + obj->bounding_box.cyWorld / 2.0 ;
    }

  if (NULL != rc_electrode->precompute_params.pts)
    exp_array_free (rc_electrode->precompute_params.pts) ;

  rc_electrode->precompute_params.pts = exp_array_new (sizeof (WorldPoint), 2) ;

  for (Nix = 0 ; Nix < rc_electrode->n_y_divisions ; Nix++)
    exp_array_insert_vals (rc_electrode->precompute_params.pts, NULL, rc_electrode->n_x_divisions, 2, -1, TRUE, 0, TRUE) ;

  // This is a faaar better place to multiply by 1e9 than get_potential
  rc_electrode->precompute_params.rho_factor = 1e9 * QCAD_ELECTRODE (rc_electrode)->precompute_params.capacitance / (rc_electrode->n_x_divisions * rc_electrode->n_y_divisions) ;
  pt1x_minus_pt0x = rc_electrode->precompute_params.pt[1].xWorld - rc_electrode->precompute_params.pt[0].xWorld ;
  pt1y_minus_pt0y = rc_electrode->precompute_params.pt[1].yWorld - rc_electrode->precompute_params.pt[0].yWorld ;
  pt3x_minus_pt2x = rc_electrode->precompute_params.pt[3].xWorld - rc_electrode->precompute_params.pt[2].xWorld ;
  pt3y_minus_pt2y = rc_electrode->precompute_params.pt[3].yWorld - rc_electrode->precompute_params.pt[2].yWorld ;
  reciprocal_of_x_divisions = 1.0 / rc_electrode->n_x_divisions ;
  reciprocal_of_y_divisions = 1.0 / rc_electrode->n_y_divisions ;
  
  for (Nix = 0 ; Nix < rc_electrode->n_x_divisions ; Nix++)
    {
    factor1 = reciprocal_of_x_divisions * (Nix + 0.5) ;
    factor2 = reciprocal_of_x_divisions * ((rc_electrode->n_x_divisions - Nix) - 0.5) ;

    ptSrcLine.xWorld = rc_electrode->precompute_params.pt[0].xWorld + pt1x_minus_pt0x * factor1 ;
    ptSrcLine.yWorld = rc_electrode->precompute_params.pt[0].yWorld + pt1y_minus_pt0y * factor1 ;
    ptDstLine.xWorld = rc_electrode->precompute_params.pt[2].xWorld + pt3x_minus_pt2x * factor2 ;
    ptDstLine.yWorld = rc_electrode->precompute_params.pt[2].yWorld + pt3y_minus_pt2y * factor2 ;

    dstx_minus_srcx = ptDstLine.xWorld - ptSrcLine.xWorld ;
    dsty_minus_srcy = ptDstLine.yWorld - ptSrcLine.yWorld ;
    for (Nix1 = 0 ; Nix1 < rc_electrode->n_y_divisions ; Nix1++)
      {
      exp_array_index_2d (rc_electrode->precompute_params.pts, WorldPoint, Nix1, Nix).xWorld = 
        ptSrcLine.xWorld + dstx_minus_srcx * reciprocal_of_y_divisions * (Nix1 + 0.5) ;
      exp_array_index_2d (rc_electrode->precompute_params.pts, WorldPoint, Nix1, Nix).yWorld = 
        ptSrcLine.yWorld + dsty_minus_srcy * reciprocal_of_y_divisions * (Nix1 + 0.5) ;
      }
    }
  }
예제 #13
0
//-------------------------------------------------------------------//
//!Finds all cells within a specified radius and sets the selected cells array//
int select_cells_in_radius(QCADCell ***sorted_cells,
  QCADCell *cell,
  double world_radius,
  int the_cells_layer,
  int number_of_cell_layers,
  int *number_of_cells_in_layer,
  double layer_separation,
  QCADCell ***p_selected_cells,
  int **p_neighbour_layer)
  {
  int i,j,k;
  int number_of_selected_cells = 0 ;

  g_assert (cell != NULL);

  for(i = 0; i < number_of_cell_layers; i++)
    for(j = 0; j < number_of_cells_in_layer[i]; j++)
	    if (sorted_cells[i][j] != cell)
		    if (sqrt ((QCAD_DESIGN_OBJECT(sorted_cells[i][j])->x - QCAD_DESIGN_OBJECT(cell)->x) *
			            (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->x - QCAD_DESIGN_OBJECT(cell)->x) +
                  (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->y - QCAD_DESIGN_OBJECT(cell)->y) *
                  (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->y - QCAD_DESIGN_OBJECT(cell)->y) +
                  ((double) ABS(the_cells_layer-i)*layer_separation) *
                  ((double) ABS(the_cells_layer-i)*layer_separation)) < world_radius)
			    number_of_selected_cells++;

  if (number_of_selected_cells > 0)
    {
	  //printf("there were %d neighours\n", number_of_selected_cells);

	  (*p_selected_cells) = g_malloc0 (sizeof (QCADCell *) * number_of_selected_cells);
	  (*p_neighbour_layer) = g_malloc0 (sizeof (int) * number_of_selected_cells);

	  // catch any memory allocation errors //
	  if ((*p_selected_cells) == NULL)
      {
		  fprintf (stderr, "memory allocation error in select_cells_in_radius();\n");
		  exit (1);
  	  }

	  k = 0;
	  for(i = 0; i < number_of_cell_layers; i++)
   	  for(j = 0; j < number_of_cells_in_layer[i]; j++)
        {

		    if (sorted_cells[i][j] != cell)
          {
			    if (sqrt ((QCAD_DESIGN_OBJECT(sorted_cells[i][j])->x - QCAD_DESIGN_OBJECT(cell)->x) *
			              (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->x - QCAD_DESIGN_OBJECT(cell)->x) +
                    (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->y - QCAD_DESIGN_OBJECT(cell)->y) *
                    (QCAD_DESIGN_OBJECT(sorted_cells[i][j])->y - QCAD_DESIGN_OBJECT(cell)->y) +
                    ((double) ABS(the_cells_layer-i)*layer_separation) *
                    ((double) ABS(the_cells_layer-i)*layer_separation)) < world_radius)
            {
				    //if(sorted_cells[i][j] == NULL)printf("sorted cells appear to have null member\n");
				    (*p_selected_cells)[k] = sorted_cells[i][j];
				    (*p_neighbour_layer)[k] = i;
				    k++;
  			    }
		      }
	      }
    }

  return number_of_selected_cells;
  } //select_cells_in_radius
예제 #14
0
static void draw (QCADDesignObject *obj, GdkDrawable *dst, GdkFunction rop)
  {
  GdkGC *gc = NULL ;
  GdkRectangle rcReal ;
  QCADRuler *ruler = QCAD_RULER (obj) ;
  double
    dCurrentGrad = 0 ;
  int iPowerOfTen = 0 ;
  int idx = -1 ;
  gboolean bVertical = (QCAD_RULER_ORIENTATION_EAST == ruler->orientation || QCAD_RULER_ORIENTATION_WEST == ruler->orientation) ;
  QCADLabel *lblGrad = NULL ;

  world_to_real_rect (&(ruler->ruler_bounding_box), &rcReal) ;

  gc = gdk_gc_new (dst) ;
  gdk_gc_set_function (gc, rop) ;
  gdk_gc_set_foreground (gc, &(obj->clr)) ;

  // Graduation lines should be at least MIN_GRADATION_DISTANCE_PIXELS pixels apart
  iPowerOfTen =
    (int)ceil (log10 (bVertical
      ? real_to_world_cy (MIN_GRADATION_DISTANCE_PIXELS)
      : real_to_world_cx (MIN_GRADATION_DISTANCE_PIXELS))) ;

  ruler->icLabelsVisible = 0 ;

  if (bVertical)
    {
    int xBeg = 0, xEnd = 0, xMid = 0, yReal = 0.0 ;
    double xBegWorld, xEndWorld, xMidWorld, yWorld ;

    if (QCAD_RULER_ORIENTATION_WEST == ruler->orientation)
      {
      xBeg = world_to_real_x (xBegWorld = ruler->ruler_bounding_box.xWorld),
      xEnd = world_to_real_x (xEndWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld) ;
      }
    else
      {
      xBeg = world_to_real_x (xBegWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld),
      xEnd = world_to_real_x (xEndWorld = ruler->ruler_bounding_box.xWorld) ;
      }
    xMid = world_to_real_x (xMidWorld = ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld / 2.0) ;

    for (dCurrentGrad = 0 ; dCurrentGrad < ruler->ruler_bounding_box.cyWorld ; dCurrentGrad += pow (10, iPowerOfTen))
      {
      idx++ ;
      idx %= 10 ;
      yReal = world_to_real_y (yWorld = ruler->ruler_bounding_box.yWorld + dCurrentGrad) ;
      gdk_draw_line (dst, gc, xBeg, yReal, (0 == idx ? xEnd : xMid), yReal) ;

      if (0 == idx)
        {
        lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, dCurrentGrad, &(obj->clr)) ;
        qcad_label_shrinkwrap (lblGrad) ;
        qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xEndWorld, yWorld) ;
        qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
        }
      }
    gdk_draw_line (dst, gc, xBeg, rcReal.y, xBeg, rcReal.y + rcReal.height) ;

    lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, ruler->ruler_bounding_box.cyWorld, &(obj->clr)) ;
    qcad_label_shrinkwrap (lblGrad) ;
    qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xBegWorld, ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld) ;
    qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
    }
  else
    {
    int yBeg = 0, yEnd = 0, yMid = 0, xReal = 0.0 ;
    double yBegWorld, yEndWorld, yMidWorld, xWorld ;

    if (QCAD_RULER_ORIENTATION_NORTH == ruler->orientation)
      {
      yBeg = world_to_real_y (yBegWorld = ruler->ruler_bounding_box.yWorld),
      yEnd = world_to_real_y (yEndWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld) ;
      }
    else
      {
      yBeg = world_to_real_y (yBegWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld),
      yEnd = world_to_real_y (yEndWorld = ruler->ruler_bounding_box.yWorld) ;
      }
    yMid = world_to_real_y (yMidWorld = ruler->ruler_bounding_box.yWorld + ruler->ruler_bounding_box.cyWorld / 2.0) ;

    for (dCurrentGrad = 0 ; dCurrentGrad < ruler->ruler_bounding_box.cxWorld ; dCurrentGrad += pow (10, iPowerOfTen))
      {
      idx++ ;
      idx %= 10 ;
      xReal = world_to_real_x (xWorld = ruler->ruler_bounding_box.xWorld + dCurrentGrad) ;
      gdk_draw_line (dst, gc, xReal, yBeg, xReal, (0 == idx ? yEnd : yMid)) ;

      if (0 == idx)
        {
        lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, dCurrentGrad, &(obj->clr)) ;
        qcad_label_shrinkwrap (lblGrad) ;
        qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), xWorld, yEndWorld) ;
        qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
        }
      }
    gdk_draw_line (dst, gc, rcReal.x, yBeg, rcReal.x + rcReal.width, yBeg) ;

    lblGrad = get_label_from_array (ruler->labels, (ruler->icLabelsVisible)++, ruler->ruler_bounding_box.cxWorld, &(obj->clr)) ;
    qcad_label_shrinkwrap (lblGrad) ;
    qcad_design_object_move_to (QCAD_DESIGN_OBJECT (lblGrad), ruler->ruler_bounding_box.xWorld + ruler->ruler_bounding_box.cxWorld, yBegWorld) ;
    qcad_design_object_draw (QCAD_DESIGN_OBJECT (lblGrad), dst, rop) ;
    }

  g_object_unref (gc) ;
  }
예제 #15
0
static void qcad_layer_compound_do_added (QCADCompoundDO *cdo, QCADDesignObject *obj, gpointer data)
  {qcad_layer_track_new_object (QCAD_LAYER (data), obj, NULL, QCAD_DESIGN_OBJECT (cdo)) ;}