Skip to content

Commit

Permalink
add "xschem create_text" command for placing text objects with CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSchippers committed Sep 24, 2023
1 parent abd5f75 commit 75526ca
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 60 deletions.
12 changes: 10 additions & 2 deletions doc/xschem_man/developer_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ <h1>XSCHEM <a id="cmdref">COMMAND REFERENCE</a> DOCUMENTATION</h1><br>








Expand Down Expand Up @@ -575,10 +577,17 @@ <h1>XSCHEM <a id="cmdref">COMMAND REFERENCE</a> DOCUMENTATION</h1><br>
Start a GUI copy operation </pre>
<li><kbd> count_items string separator quoting_chars</kbd></li><pre>
Debug command </pre>
<li><kbd> Create_plot_cmd</kbd></li><pre>
<li><kbd> create_plot_cmd</kbd></li><pre>
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) </pre>
<li><kbd> create_text draw x y rot flip text props size</kbd></li><pre>
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 </pre>
<li><kbd> cut</kbd></li><pre>
Cut selection to clipboard </pre>
<li><kbd> debug n</kbd></li><pre>
Expand Down Expand Up @@ -1320,7 +1329,6 @@ <h1>XSCHEM <a id="cmdref">COMMAND REFERENCE</a> DOCUMENTATION</h1><br>






</ul>
Expand Down
128 changes: 72 additions & 56 deletions src/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3213,87 +3213,103 @@ 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

tclsetvar("props","");
tclsetvar("retval","");

if(!tclgetvar("hsize"))
tclsetvar("hsize","0.4");
if(!tclgetvar("vsize"))
tclsetvar("vsize","0.4");
xctx->semaphore++;
tcleval("enter_text {text:} normal");
xctx->semaphore--;

dbg(1, "place_text(): hsize=%s vsize=%s\n",tclgetvar("hsize"), tclgetvar("vsize") );

txt = (char *)tclgetvar("retval");
if(!txt || !strcmp(txt,"")) return 0; /* dont allocate text object if empty string given */
xctx->push_undo();
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=mx;
t->y0=my;
t->rot=0;
t->flip=0;
t->x0=x;
t->y0=y;
t->rot=(short int) rot;
t->flip=(short int) flip;
t->sel=0;
t->xscale= atof(tclgetvar("hsize"));
t->yscale= atof(tclgetvar("vsize"));
my_strdup(_ALLOC_ID_, &t->prop_ptr, (char *)tclgetvar("props"));
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 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,
#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->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","");

if(!tclgetvar("hsize"))
tclsetvar("hsize","0.4");
if(!tclgetvar("vsize"))
tclsetvar("vsize","0.4");
xctx->semaphore++;
tcleval("enter_text {text:} normal");
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();
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);
Expand Down
5 changes: 4 additions & 1 deletion src/create_graph.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 23 additions & 1 deletion src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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"))
Expand Down
2 changes: 2 additions & 0 deletions src/xschem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 75526ca

Please sign in to comment.