xschem/src/store.c

360 lines
11 KiB
C
Raw Normal View History

2020-08-08 15:47:34 +02:00
/* File: store.c
*
2020-08-08 15:47:34 +02:00
* This file is part of XSCHEM,
* a schematic capture and Spice/Vhdl/Verilog netlisting tool for circuit
2020-08-08 15:47:34 +02:00
* simulation.
2022-06-24 00:36:12 +02:00
* Copyright (C) 1998-2022 Stefan Frederik Schippers
2020-08-08 15:47:34 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "xschem.h"
void check_wire_storage(void)
{
if(xctx->wires >= xctx->maxw)
2020-08-08 15:47:34 +02:00
{
xctx->maxw=(1+xctx->wires / CADMAXWIRES)*CADMAXWIRES;
2023-02-09 21:04:22 +01:00
my_realloc(1111, &xctx->wire, sizeof(xWire)*xctx->maxw);
2020-08-08 15:47:34 +02:00
}
}
void check_selected_storage(void)
{
2020-12-02 15:10:47 +01:00
if(xctx->lastsel >= xctx->maxsel)
2020-08-08 15:47:34 +02:00
{
2020-12-02 15:10:47 +01:00
xctx->maxsel=(1+xctx->lastsel / MAXGROUP) * MAXGROUP;
2023-02-09 21:04:22 +01:00
my_realloc(1112, &xctx->sel_array, sizeof(Selected)*xctx->maxsel);
2020-08-08 15:47:34 +02:00
}
}
void check_text_storage(void)
{
if(xctx->texts >= xctx->maxt)
2020-08-08 15:47:34 +02:00
{
xctx->maxt=(1 + xctx->texts / CADMAXTEXT) * CADMAXTEXT;
2023-02-09 21:04:22 +01:00
my_realloc(1113, &xctx->text, sizeof(xText)*xctx->maxt);
2020-08-08 15:47:34 +02:00
}
}
void check_symbol_storage(void)
{
int i;
if(xctx->symbols >= xctx->maxs)
2020-08-08 15:47:34 +02:00
{
dbg(1, "check_symbol_storage(): more than maxs, %s\n",
xctx->sch[xctx->currsch] );
xctx->maxs=(1 + xctx->symbols / ELEMDEF) * ELEMDEF;
2023-02-09 21:04:22 +01:00
my_realloc(1114, &xctx->sym, sizeof(xSymbol)*xctx->maxs);
for(i=xctx->symbols;i<xctx->maxs;i++) {
2023-02-09 21:04:22 +01:00
xctx->sym[i].poly=my_calloc(1115, cadlayers, sizeof(xPoly *));
if(xctx->sym[i].poly==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].arc=my_calloc(1116, cadlayers, sizeof(xArc *));
if(xctx->sym[i].arc==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].line=my_calloc(1117, cadlayers, sizeof(xLine *));
if(xctx->sym[i].line==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].rect=my_calloc(1118, cadlayers, sizeof(xRect *));
if(xctx->sym[i].rect==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].lines=my_calloc(1119, cadlayers, sizeof(int));
if(xctx->sym[i].lines==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].rects=my_calloc(1120, cadlayers, sizeof(int));
if(xctx->sym[i].rects==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].polygons=my_calloc(1121, cadlayers, sizeof(int));
if(xctx->sym[i].polygons==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
2023-02-09 21:04:22 +01:00
xctx->sym[i].arcs=my_calloc(1122, cadlayers, sizeof(int));
if(xctx->sym[i].arcs==NULL){
2020-08-08 15:47:34 +02:00
fprintf(errfp, "check_symbol_storage(): calloc error\n");tcleval( "exit");
}
}
}
}
#undef ZERO_REALLOC
2020-08-08 15:47:34 +02:00
void check_inst_storage(void)
{
if(xctx->instances >= xctx->maxi)
2020-08-08 15:47:34 +02:00
{
xctx->maxi=(1 + xctx->instances / ELEMINST) * ELEMINST;
2023-02-09 21:04:22 +01:00
my_realloc(1123, &xctx->inst, sizeof(xInstance)*xctx->maxi);
#ifdef ZERO_REALLOC
memset(xctx->inst + xctx->instances, 0, sizeof(xInstance) * (xctx->maxi - xctx->instances));
#endif
2020-08-08 15:47:34 +02:00
}
}
void check_arc_storage(int c)
{
if(xctx->arcs[c] >= xctx->maxa[c])
2020-08-08 15:47:34 +02:00
{
xctx->maxa[c]=(1 + xctx->arcs[c] / CADMAXOBJECTS) * CADMAXOBJECTS;
2023-02-09 21:04:22 +01:00
my_realloc(1124, &xctx->arc[c], sizeof(xArc)*xctx->maxa[c]);
#ifdef ZERO_REALLOC
memset(xctx->arc[c] + xctx->arcs[c], 0, sizeof(xArc) * (xctx->maxa[c] - xctx->arcs[c]));
#endif
2020-08-08 15:47:34 +02:00
}
}
void check_box_storage(int c)
{
if(xctx->rects[c] >= xctx->maxr[c])
2020-08-08 15:47:34 +02:00
{
xctx->maxr[c]=(1 + xctx->rects[c] / CADMAXOBJECTS) * CADMAXOBJECTS;
2023-02-09 21:04:22 +01:00
my_realloc(1125, &xctx->rect[c], sizeof(xRect)*xctx->maxr[c]);
#ifdef ZERO_REALLOC
memset(xctx->rect[c] + xctx->rects[c], 0, sizeof(xRect) * (xctx->maxr[c] - xctx->rects[c]));
#endif
2020-08-08 15:47:34 +02:00
}
}
void check_line_storage(int c)
{
if(xctx->lines[c] >= xctx->maxl[c])
2020-08-08 15:47:34 +02:00
{
xctx->maxl[c]=(1 + xctx->lines[c] / CADMAXOBJECTS) * CADMAXOBJECTS;
2023-02-09 21:04:22 +01:00
my_realloc(1126, &xctx->line[c], sizeof(xLine)*xctx->maxl[c]);
#ifdef ZERO_REALLOC
memset(xctx->line[c] + xctx->lines[c], 0, sizeof(xLine) * (xctx->maxl[c] - xctx->lines[c]));
#endif
2020-08-08 15:47:34 +02:00
}
}
void check_polygon_storage(int c)
2020-08-08 15:47:34 +02:00
{
if(xctx->polygons[c] >= xctx->maxp[c])
2020-08-08 15:47:34 +02:00
{
xctx->maxp[c]=(1 + xctx->polygons[c] / CADMAXOBJECTS) * CADMAXOBJECTS;
2023-02-09 21:04:22 +01:00
my_realloc(1127, &xctx->poly[c], sizeof(xPoly)*xctx->maxp[c]);
#ifdef ZERO_REALLOC
memset(xctx->poly[c] + xctx->polygons[c], 0, sizeof(xPoly) * (xctx->maxp[c] - xctx->polygons[c]));
#endif
2020-08-08 15:47:34 +02:00
}
}
void store_arc(int pos, double x, double y, double r, double a, double b,
unsigned int rectc, unsigned short sel, char *prop_ptr)
2020-08-08 15:47:34 +02:00
{
int n, j;
2020-09-02 23:59:58 +02:00
const char *dash;
check_arc_storage(rectc);
if(pos==-1) n=xctx->arcs[rectc];
2020-08-08 15:47:34 +02:00
else
{
for(j=xctx->arcs[rectc];j>pos;j--)
2020-08-08 15:47:34 +02:00
{
xctx->arc[rectc][j]=xctx->arc[rectc][j-1];
2020-08-08 15:47:34 +02:00
}
n=pos;
}
xctx->arc[rectc][n].x = x;
xctx->arc[rectc][n].y = y;
xctx->arc[rectc][n].r = r;
xctx->arc[rectc][n].a = a;
xctx->arc[rectc][n].b = b;
xctx->arc[rectc][n].prop_ptr = NULL;
2023-02-09 21:04:22 +01:00
my_strdup(1128, &xctx->arc[rectc][n].prop_ptr, prop_ptr);
xctx->arc[rectc][n].sel = sel;
if( !strcmp(get_tok_value(xctx->arc[rectc][n].prop_ptr,"fill",0),"true") )
xctx->arc[rectc][n].fill =1;
2020-08-08 15:47:34 +02:00
else
xctx->arc[rectc][n].fill =0;
dash = get_tok_value(xctx->arc[rectc][n].prop_ptr,"dash",0);
2020-09-03 00:19:39 +02:00
if( strcmp(dash, "") ) {
int d = atoi(dash);
2022-04-28 10:12:16 +02:00
xctx->arc[rectc][n].dash = (char) (d >= 0 ? d : 0);
2020-09-03 00:19:39 +02:00
} else
xctx->arc[rectc][n].dash = 0;
2020-09-02 23:59:58 +02:00
xctx->arcs[rectc]++;
2020-08-08 15:47:34 +02:00
set_modify(1);
}
void store_poly(int pos, double *x, double *y, int points, unsigned int rectc,
unsigned short sel, char *prop_ptr)
2020-08-08 15:47:34 +02:00
{
int n, j;
const char *dash;
check_polygon_storage(rectc);
if(pos==-1) n=xctx->polygons[rectc];
2020-08-08 15:47:34 +02:00
else
{
for(j=xctx->polygons[rectc];j>pos;j--)
2020-08-08 15:47:34 +02:00
{
xctx->poly[rectc][j]=xctx->poly[rectc][j-1];
2020-08-08 15:47:34 +02:00
}
n=pos;
}
dbg(2, "store_poly(): storing POLYGON %d\n",n);
xctx->poly[rectc][n].x=NULL;
xctx->poly[rectc][n].y=NULL;
xctx->poly[rectc][n].selected_point=NULL;
xctx->poly[rectc][n].prop_ptr=NULL;
2023-02-09 21:04:22 +01:00
xctx->poly[rectc][n].x= my_calloc(1129, points, sizeof(double));
xctx->poly[rectc][n].y= my_calloc(1130, points, sizeof(double));
xctx->poly[rectc][n].selected_point= my_calloc(1131, points, sizeof(unsigned short));
my_strdup(1132, &xctx->poly[rectc][n].prop_ptr, prop_ptr);
2020-08-08 15:47:34 +02:00
for(j=0;j<points; j++) {
xctx->poly[rectc][n].x[j] = x[j];
xctx->poly[rectc][n].y[j] = y[j];
2020-08-08 15:47:34 +02:00
}
xctx->poly[rectc][n].points = points;
xctx->poly[rectc][n].sel = sel;
2020-08-08 15:47:34 +02:00
if( !strcmp(get_tok_value(xctx->poly[rectc][n].prop_ptr,"fill",0),"true") )
xctx->poly[rectc][n].fill =1;
2020-08-08 15:47:34 +02:00
else
xctx->poly[rectc][n].fill =0;
dash = get_tok_value(xctx->poly[rectc][n].prop_ptr,"dash",0);
2020-09-03 00:19:39 +02:00
if( strcmp(dash, "") ) {
int d = atoi(dash);
2022-04-28 10:12:16 +02:00
xctx->poly[rectc][n].dash = (char) (d >= 0 ? d : 0);
2020-09-03 00:19:39 +02:00
} else
xctx->poly[rectc][n].dash = 0;
2020-08-08 15:47:34 +02:00
xctx->polygons[rectc]++;
2020-08-08 15:47:34 +02:00
set_modify(1);
}
void storeobject(int pos, double x1,double y1,double x2,double y2,
unsigned short type, unsigned int rectc,
2020-08-08 15:47:34 +02:00
unsigned short sel, const char *prop_ptr)
{
int n, j;
const char *dash;
2020-08-08 15:47:34 +02:00
if(type == LINE)
{
check_line_storage(rectc);
2020-08-08 15:47:34 +02:00
if(pos==-1) n=xctx->lines[rectc];
2020-08-08 15:47:34 +02:00
else
{
for(j=xctx->lines[rectc];j>pos;j--)
2020-08-08 15:47:34 +02:00
{
xctx->line[rectc][j]=xctx->line[rectc][j-1];
2020-08-08 15:47:34 +02:00
}
n=pos;
}
dbg(2, "storeobject(): storing LINE %d\n",n);
xctx->line[rectc][n].x1=x1;
xctx->line[rectc][n].x2=x2;
xctx->line[rectc][n].y1=y1;
xctx->line[rectc][n].y2=y2;
xctx->line[rectc][n].prop_ptr=NULL;
2023-02-09 21:04:22 +01:00
my_strdup(1133, &xctx->line[rectc][n].prop_ptr, prop_ptr);
xctx->line[rectc][n].sel=sel;
if( prop_ptr && !strcmp(get_tok_value(prop_ptr, "bus", 0), "true") )
xctx->line[rectc][n].bus = 1;
else
xctx->line[rectc][n].bus = 0;
if(prop_ptr && (dash = get_tok_value(prop_ptr,"dash",0))[0]) {
2020-09-03 00:19:39 +02:00
int d = atoi(dash);
2022-04-28 10:12:16 +02:00
xctx->line[rectc][n].dash = (char) (d >= 0 ? d : 0);
2020-09-03 00:19:39 +02:00
} else
xctx->line[rectc][n].dash = 0;
xctx->lines[rectc]++;
2020-08-08 15:47:34 +02:00
set_modify(1);
}
if(type == xRECT)
{
check_box_storage(rectc);
if(pos==-1) n=xctx->rects[rectc];
2020-08-08 15:47:34 +02:00
else
{
for(j=xctx->rects[rectc];j>pos;j--)
2020-08-08 15:47:34 +02:00
{
xctx->rect[rectc][j]=xctx->rect[rectc][j-1];
2020-08-08 15:47:34 +02:00
}
n=pos;
}
dbg(2, "storeobject(): storing RECT %d\n",n);
xctx->rect[rectc][n].x1=x1;
xctx->rect[rectc][n].x2=x2;
xctx->rect[rectc][n].y1=y1;
xctx->rect[rectc][n].y2=y2;
xctx->rect[rectc][n].prop_ptr=NULL;
2022-01-19 23:28:19 +01:00
xctx->rect[rectc][n].extraptr=NULL;
2023-02-09 21:04:22 +01:00
my_strdup(1134, &xctx->rect[rectc][n].prop_ptr, prop_ptr);
xctx->rect[rectc][n].sel=sel;
if(prop_ptr && (dash = get_tok_value(prop_ptr,"dash",0))[0]) {
2020-09-03 00:19:39 +02:00
int d = atoi(dash);
2022-04-28 10:12:16 +02:00
xctx->rect[rectc][n].dash = (char) (d >= 0 ? d : 0);
2020-09-03 00:19:39 +02:00
} else
xctx->rect[rectc][n].dash = 0;
if(!strcmp(get_tok_value(xctx->rect[rectc][n].prop_ptr,"fill",0),"false") )
xctx->rect[rectc][n].fill =0;
else
xctx->rect[rectc][n].fill =1;
set_rect_flags(&xctx->rect[rectc][n]); /* set cached .flags bitmask from on attributes */
if(rectc == GRIDLAYER && (xctx->rect[rectc][n].flags & 1024)) {
xRect *r = &xctx->rect[GRIDLAYER][n];
draw_image(0, r, &r->x1, &r->y1, &r->x2, &r->y2, 0, 0);
}
xctx->rects[rectc]++;
2020-08-08 15:47:34 +02:00
set_modify(1);
}
if(type == WIRE)
{
check_wire_storage();
if(pos==-1) n=xctx->wires;
2020-08-08 15:47:34 +02:00
else
{
for(j=xctx->wires;j>pos;j--)
2020-08-08 15:47:34 +02:00
{
xctx->wire[j]=xctx->wire[j-1];
2020-08-08 15:47:34 +02:00
}
n=pos;
}
dbg(2, "storeobject(): storing WIRE %d\n",n);
xctx->wire[n].x1=x1;
xctx->wire[n].y1=y1;
xctx->wire[n].x2=x2;
xctx->wire[n].y2=y2;
xctx->wire[n].prop_ptr=NULL;
xctx->wire[n].node=NULL;
xctx->wire[n].end1=0;
xctx->wire[n].end2=0;
2023-02-09 21:04:22 +01:00
my_strdup(1135, &xctx->wire[n].prop_ptr, prop_ptr);
if(prop_ptr && !strcmp(get_tok_value(prop_ptr,"bus",0), "true")) xctx->wire[n].bus=1;
else xctx->wire[n].bus=0;
xctx->wire[n].sel=sel;
xctx->wires++;
2020-08-08 15:47:34 +02:00
set_modify(1);
}
}