From 75526cacbec283a70ef8369ac1348e9c5490a143 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Sun, 24 Sep 2023 03:16:53 +0200 Subject: [PATCH] add "xschem create_text" command for placing text objects with CLI --- doc/xschem_man/developer_info.html | 12 ++- src/actions.c | 134 ++++++++++++++++------------- src/create_graph.tcl | 5 +- src/scheduler.c | 24 +++++- src/xschem.h | 2 + 5 files changed, 114 insertions(+), 63 deletions(-) diff --git a/doc/xschem_man/developer_info.html b/doc/xschem_man/developer_info.html index ba388d4f..02e7669d 100644 --- a/doc/xschem_man/developer_info.html +++ b/doc/xschem_man/developer_info.html @@ -508,6 +508,8 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns" + + @@ -575,10 +577,17 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns" Start a GUI copy operation
  • count_items string separator quoting_chars
  •     Debug command 
    -
  • Create_plot_cmd
  • +   
  • create_plot_cmd
  •     Create an xplot file in netlist/simulation directory with
        the list of highlighted nodes in a format the selected waveform
        viewer understands (bespice, gaw, ngspice) 
    +
  • create_text draw x y rot flip text props size
  • +   Create a text object
    +     draw is a flag. If set to 1 will draw the created text
    +     x, y, rot, flip specify the position and orientation
    +     text is the text string
    +     props is the attribute string
    +     size sets the size 
  • cut
  •     Cut selection to clipboard 
  • debug n
  • @@ -1320,7 +1329,6 @@ C {verilog_timescale.sym} 1050 -100 0 0 {name=s1 timestep="1ns" precision="1ns"
     
     
     
    -
     
     
      
    diff --git a/src/actions.c b/src/actions.c
    index 05875a68..dfa084d4 100644
    --- a/src/actions.c
    +++ b/src/actions.c
    @@ -3213,17 +3213,81 @@ double ceil_to_n_digits(double x, int n)
       return ceil(x / scale) * scale;
     }
     
    -int place_text(int draw_text, double mx, double my)
    +
    +
    +int create_text(int draw_text, double x, double y, int rot, int flip, const char *txt,
    +    const char *props, double hsize, double vsize)
     {
    -  char *txt;
       int textlayer;
    -  /* const char *str; */
    +  xText *t;
       int save_draw;
    -  xText *t = &xctx->text[xctx->texts];
       #if HAS_CAIRO==1
       const char  *textfont;
       #endif
     
    +  check_text_storage();
    +  t = &xctx->text[xctx->texts];
    +  t->txt_ptr=NULL;
    +  t->prop_ptr=NULL;  /*  20111006 added missing initialization of pointer */
    +  t->floater_ptr = NULL;
    +  t->font=NULL;
    +  t->floater_instname=NULL;
    +  my_strdup(_ALLOC_ID_, &t->txt_ptr, txt);
    +  t->x0=x;
    +  t->y0=y;
    +  t->rot=(short int) rot;
    +  t->flip=(short int) flip;
    +  t->sel=0;
    +  t->xscale= hsize;
    +  t->yscale= vsize;
    +  my_strdup(_ALLOC_ID_, &t->prop_ptr, props);
    +  /*  debug ... */
    +  /*  t->prop_ptr=NULL; */
    +  dbg(1, "place_text(): done text input\n");
    +  set_text_flags(t);
    +  textlayer = t->layer;
    +  if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
    +
    +  if(draw_text) {
    +    #if HAS_CAIRO==1
    +    textfont = t->font;
    +    if((textfont && textfont[0]) || (t->flags & (TEXT_BOLD | TEXT_OBLIQUE | TEXT_ITALIC))) {
    +      cairo_font_slant_t slant;
    +      cairo_font_weight_t weight;
    +      textfont = (t->font && t->font[0]) ? t->font : tclgetvar("cairo_font_name");
    +      weight = ( t->flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
    +      slant = CAIRO_FONT_SLANT_NORMAL;
    +      if(t->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC;
    +      if(t->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
    +      cairo_save(xctx->cairo_ctx);
    +      cairo_save(xctx->cairo_save_ctx);
    +      xctx->cairo_font =
    +            cairo_toy_font_face_create(textfont, slant, weight);
    +      cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
    +      cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
    +      cairo_font_face_destroy(xctx->cairo_font);
    +    }
    +    #endif
    +    save_draw=xctx->draw_window;
    +    xctx->draw_window=1;
    +    draw_string(textlayer, NOW, get_text_floater(xctx->texts), t->rot, t->flip,
    +        t->hcenter, t->vcenter, t->x0,t->y0, t->xscale, t->yscale);
    +    xctx->draw_window = save_draw;
    +    #if HAS_CAIRO==1
    +    if((textfont && textfont[0]) || (t->flags & (TEXT_BOLD | TEXT_OBLIQUE | TEXT_ITALIC))) {
    +      cairo_restore(xctx->cairo_ctx);
    +      cairo_restore(xctx->cairo_save_ctx);
    +    }
    +    #endif
    +  }
    +  xctx->texts++;
    +  return 1;
    +}
    +
    +int place_text(int draw_text, double mx, double my)
    +{
    +  char *txt, *props, *hsize, *vsize;
    +
       tclsetvar("props","");
       tclsetvar("retval","");
     
    @@ -3236,64 +3300,16 @@ int place_text(int draw_text, double mx, double my)
       xctx->semaphore--;
     
       dbg(1, "place_text(): hsize=%s vsize=%s\n",tclgetvar("hsize"), tclgetvar("vsize") );
    -
    +  /* get: retval, hsize, vsize, props,  */
       txt =  (char *)tclgetvar("retval");
    +  props =  (char *)tclgetvar("props");
    +  hsize =  (char *)tclgetvar("hsize");
    +  vsize =  (char *)tclgetvar("vsize");
       if(!txt || !strcmp(txt,"")) return 0;   /*  dont allocate text object if empty string given */
       xctx->push_undo();
    -  check_text_storage();
    -  t->txt_ptr=NULL;
    -  t->prop_ptr=NULL;  /*  20111006 added missing initialization of pointer */
    -  t->floater_ptr = NULL;
    -  t->font=NULL;
    -  t->floater_instname=NULL;
    -  my_strdup(_ALLOC_ID_, &t->txt_ptr, txt);
    -  t->x0=mx;
    -  t->y0=my;
    -  t->rot=0;
    -  t->flip=0;
    -  t->sel=0;
    -  t->xscale= atof(tclgetvar("hsize"));
    -  t->yscale= atof(tclgetvar("vsize"));
    -  my_strdup(_ALLOC_ID_, &t->prop_ptr, (char *)tclgetvar("props"));
    -  /*  debug ... */
    -  /*  t->prop_ptr=NULL; */
    -  dbg(1, "place_text(): done text input\n");
    -  set_text_flags(t);
    -  textlayer = t->layer;
    -  if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
    -  #if HAS_CAIRO==1
    -  textfont = t->font;
    -  if((textfont && textfont[0]) || (t->flags & (TEXT_BOLD | TEXT_OBLIQUE | TEXT_ITALIC))) {
    -    cairo_font_slant_t slant;
    -    cairo_font_weight_t weight;
    -    textfont = (t->font && t->font[0]) ? t->font : tclgetvar("cairo_font_name");
    -    weight = ( t->flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
    -    slant = CAIRO_FONT_SLANT_NORMAL;
    -    if(t->flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC;
    -    if(t->flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
    -    cairo_save(xctx->cairo_ctx);
    -    cairo_save(xctx->cairo_save_ctx);
    -    xctx->cairo_font =
    -          cairo_toy_font_face_create(textfont, slant, weight);
    -    cairo_set_font_face(xctx->cairo_ctx, xctx->cairo_font);
    -    cairo_set_font_face(xctx->cairo_save_ctx, xctx->cairo_font);
    -    cairo_font_face_destroy(xctx->cairo_font);
    -  }
    -  #endif
    -  save_draw=xctx->draw_window;
    -  xctx->draw_window=1;
    -  if(draw_text) {
    -    draw_string(textlayer, NOW, get_text_floater(xctx->texts), 0, 0,
    -        t->hcenter, t->vcenter, t->x0,t->y0, t->xscale, t->yscale);
    -  }
    -  xctx->draw_window = save_draw;
    -  #if HAS_CAIRO==1
    -  if((textfont && textfont[0]) || (t->flags & (TEXT_BOLD | TEXT_OBLIQUE | TEXT_ITALIC))) {
    -    cairo_restore(xctx->cairo_ctx);
    -    cairo_restore(xctx->cairo_save_ctx);
    -  }
    -  #endif
    -  xctx->texts++;
    +  dbg(0,"props=%s, txt=%s\n", props, txt);
    +
    +  create_text(draw_text, mx, my, 0, 0, txt, props, atof(hsize), atof(vsize));
       select_text(xctx->texts - 1, SELECTED, 0);
       rebuild_selected_array(); /* sets xctx->ui_state |= SELECTION */
       drawtemprect(xctx->gc[SELLAYER], END, 0.0, 0.0, 0.0, 0.0);
    diff --git a/src/create_graph.tcl b/src/create_graph.tcl
    index ae5eaf6c..99855dc3 100644
    --- a/src/create_graph.tcl
    +++ b/src/create_graph.tcl
    @@ -22,9 +22,12 @@
     
     
     # procedure to create a graph in an empty xschem window and display waveforms
    -proc create_graph {rawfile node {analysis tran} {color {4 5 6 7 8 9 10 11 12 13 14}}} {
    +proc create_graph {title rawfile node {analysis tran} {color {4 5 6 7 8 9 10 11 12 13 14}}} {
       # clear window if not already empty
       xschem clear force
    +
    +  # add title text
    +  xschem create_text 1 30 -350 0 0 $title {} 0.5
       # clear loaded raw file if any
       xschem raw_clear
       # set current layer to graph layer (grey, layer 2)
    diff --git a/src/scheduler.c b/src/scheduler.c
    index c429f4cf..860314f9 100644
    --- a/src/scheduler.c
    +++ b/src/scheduler.c
    @@ -555,7 +555,7 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
             Tcl_SetResult(interp, my_itoa(count_items(argv[2], argv[3], argv[4])), TCL_VOLATILE);
           }
         }
    -    /* Create_plot_cmd
    +    /* create_plot_cmd
          *   Create an xplot file in netlist/simulation directory with
          *   the list of highlighted nodes in a format the selected waveform
          *   viewer understands (bespice, gaw, ngspice) */
    @@ -566,6 +566,28 @@ int xschem(ClientData clientdata, Tcl_Interp *interp, int argc, const char * arg
           Tcl_ResetResult(interp);
         }
     
    +
    +    /* create_text draw x y rot flip text props size
    +     *   Create a text object
    +     *     draw is a flag. If set to 1 will draw the created text
    +     *     x, y, rot, flip specify the position and orientation
    +     *     text is the text string
    +     *     props is the attribute string
    +     *     size sets the size */
    +    else if(!strcmp(argv[1], "create_text") )
    +    {
    +      if(!xctx) {Tcl_SetResult(interp, not_avail, TCL_STATIC); return TCL_ERROR;}
    +
    +      if(argc > 9) {
    +        create_text(atoi(argv[2]), atof(argv[3]), atof(argv[4]), atoi(argv[5]), atoi(argv[6]),
    +                    argv[7], argv[8], atof(argv[9]), atof(argv[9]));
    +      }
    +      Tcl_ResetResult(interp);
    +    } 
    +
    +
    +
    +
         /* cut
          *   Cut selection to clipboard */
         else if(!strcmp(argv[1], "cut"))
    diff --git a/src/xschem.h b/src/xschem.h
    index add74f37..b2bfd05c 100644
    --- a/src/xschem.h
    +++ b/src/xschem.h
    @@ -1430,6 +1430,8 @@ extern int tclvareval(const char *script, ...);
     extern const char *tcl_hook2(const char *res);
     extern void statusmsg(char str[],int n);
     extern int place_text(int draw_text, double mx, double my);
    +extern int create_text(int draw_text, double x, double y, int rot, int flip, const char *txt,
    +       const char *props, double hsize, double vsize);
     extern void init_inst_iterator(Iterator_ctx *ctx, double x1, double y1, double x2, double y2);
     extern Instentry *inst_iterator_next(Iterator_ctx *ctx);
     extern void init_wire_iterator(Iterator_ctx *ctx, double x1, double y1, double x2, double y2);