xschem/src/move.c

1480 lines
51 KiB
C
Raw Normal View History

2020-08-08 15:47:34 +02:00
/* File: move.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.
* Copyright (C) 1998-2020 Stefan Frederik Schippers
*
* 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"
static double rx1, rx2, ry1, ry2;
static int move_rot = 0;
static int move_flip = 0;
2020-08-08 15:47:34 +02:00
static double x1=0.0, y_1=0.0, x2=0.0, y_2=0.0, deltax = 0.0, deltay = 0.0;
/* static int i,c,n,k; */
static int lastsel;
static int rotatelocal=0;
2020-08-08 15:47:34 +02:00
void rebuild_selected_array() /* can be used only if new selected set is lower */
2020-12-02 15:10:47 +01:00
/* that is, xctx->sel_array[] size can not increase */
2020-08-08 15:47:34 +02:00
{
int i,c;
dbg(1, "rebuild selected array\n");
2020-12-02 15:10:47 +01:00
if(!xctx->need_reb_sel_arr) return;
xctx->lastsel=0;
for(i=0;i<xctx->texts;i++)
if(xctx->text[i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = xTEXT;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = TEXTLAYER;
2020-08-08 15:47:34 +02:00
}
for(i=0;i<xctx->instances;i++)
if(xctx->inst[i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = ELEMENT;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = WIRELAYER;
2020-08-08 15:47:34 +02:00
}
for(i=0;i<xctx->wires;i++)
if(xctx->wire[i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = WIRE;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = WIRELAYER;
2020-08-08 15:47:34 +02:00
}
for(c=0;c<cadlayers;c++)
{
for(i=0;i<xctx->arcs[c];i++)
if(xctx->arc[c][i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = ARC;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = c;
2020-08-08 15:47:34 +02:00
}
for(i=0;i<xctx->rects[c];i++)
if(xctx->rect[c][i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = xRECT;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = c;
2020-08-08 15:47:34 +02:00
}
for(i=0;i<xctx->lines[c];i++)
if(xctx->line[c][i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = LINE;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = c;
2020-08-08 15:47:34 +02:00
}
for(i=0;i<xctx->polygons[c];i++)
if(xctx->poly[c][i].sel)
2020-08-08 15:47:34 +02:00
{
check_selected_storage();
2020-12-02 15:10:47 +01:00
xctx->sel_array[xctx->lastsel].type = POLYGON;
xctx->sel_array[xctx->lastsel].n = i;
xctx->sel_array[xctx->lastsel++].col = c;
2020-08-08 15:47:34 +02:00
}
}
2020-12-02 15:10:47 +01:00
xctx->need_reb_sel_arr=0;
2020-08-08 15:47:34 +02:00
}
void check_collapsing_objects()
{
int j,i, c;
int found=0;
j=0;
for(i=0;i<xctx->wires;i++)
2020-08-08 15:47:34 +02:00
{
if(xctx->wire[i].x1==xctx->wire[i].x2 && xctx->wire[i].y1 == xctx->wire[i].y2)
2020-08-08 15:47:34 +02:00
{
my_free(812, &xctx->wire[i].prop_ptr);
my_free(813, &xctx->wire[i].node);
2020-08-08 15:47:34 +02:00
found=1;
j++;
2020-08-08 15:47:34 +02:00
continue;
}
if(j)
2020-08-08 15:47:34 +02:00
{
xctx->wire[i-j] = xctx->wire[i];
2020-08-08 15:47:34 +02:00
}
}
xctx->wires -= j;
2020-08-08 15:47:34 +02:00
/* option: remove degenerated lines */
for(c=0;c<cadlayers;c++)
{
j = 0;
for(i=0;i<xctx->lines[c];i++)
2020-08-08 15:47:34 +02:00
{
if(xctx->line[c][i].x1==xctx->line[c][i].x2 && xctx->line[c][i].y1 == xctx->line[c][i].y2)
2020-08-08 15:47:34 +02:00
{
my_free(814, &xctx->line[c][i].prop_ptr);
2020-08-08 15:47:34 +02:00
found=1;
j++;
continue;
}
if(j)
2020-08-08 15:47:34 +02:00
{
xctx->line[c][i-j] = xctx->line[c][i];
2020-08-08 15:47:34 +02:00
}
}
xctx->lines[c] -= j;
}
2020-08-08 15:47:34 +02:00
for(c=0;c<cadlayers;c++)
{
2020-08-08 15:47:34 +02:00
j = 0;
for(i=0;i<xctx->rects[c];i++)
2020-08-08 15:47:34 +02:00
{
if(xctx->rect[c][i].x1==xctx->rect[c][i].x2 || xctx->rect[c][i].y1 == xctx->rect[c][i].y2)
2020-08-08 15:47:34 +02:00
{
my_free(815, &xctx->rect[c][i].prop_ptr);
2020-08-08 15:47:34 +02:00
found=1;
j++;
continue;
}
if(j)
2020-08-08 15:47:34 +02:00
{
xctx->rect[c][i-j] = xctx->rect[c][i];
2020-08-08 15:47:34 +02:00
}
}
xctx->rects[c] -= j;
}
2020-08-08 15:47:34 +02:00
if(found) {
2020-12-02 15:10:47 +01:00
xctx->need_reb_sel_arr=1;
2020-08-08 15:47:34 +02:00
rebuild_selected_array();
}
}
void update_symbol_bboxes(int rot, int flip)
2020-08-08 15:47:34 +02:00
{
int i, n, save_flip, save_rot;
for(i=0;i<lastsel;i++)
{
2020-12-02 15:10:47 +01:00
n = xctx->sel_array[i].n;
2020-12-02 12:50:08 +01:00
dbg(1, "update_symbol_bboxes(): i=%d, lastsel=%d, n=%d\n", i, lastsel, n);
dbg(1, "update_symbol_bboxes(): symbol flip=%d, rot=%d\n", xctx->inst[n].flip, xctx->inst[n].rot);
2020-12-02 15:10:47 +01:00
if(xctx->sel_array[i].type == ELEMENT) {
save_flip = xctx->inst[n].flip;
save_rot = xctx->inst[n].rot;
xctx->inst[n].flip = flip ^ xctx->inst[n].flip;
xctx->inst[n].rot = (xctx->inst[n].rot + rot) & 0x3;
symbol_bbox(n, &xctx->inst[n].x1, &xctx->inst[n].y1, &xctx->inst[n].x2, &xctx->inst[n].y2 );
xctx->inst[n].rot = save_rot;
xctx->inst[n].flip = save_flip;
2020-08-08 15:47:34 +02:00
}
}
}
void draw_selection(GC g, int interruptable)
{
int i, c, k, n;
double angle; /* arc */
#ifdef HAS_CAIRO
int customfont;
#endif
2020-12-02 15:10:47 +01:00
if(g == gc[SELLAYER]) lastsel = xctx->lastsel;
2020-08-08 15:47:34 +02:00
for(i=0;i<lastsel;i++)
{
2020-12-02 15:10:47 +01:00
c = xctx->sel_array[i].col;n = xctx->sel_array[i].n;
switch(xctx->sel_array[i].type)
2020-08-08 15:47:34 +02:00
{
case xTEXT:
if(rotatelocal) {
2020-11-17 01:29:47 +01:00
ROTATION(move_rot, move_flip, xctx->text[n].x0, xctx->text[n].y0,
xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
#ifdef HAS_CAIRO
customfont = set_text_custom_font(&xctx->text[n]);
2020-08-08 15:47:34 +02:00
#endif
draw_temp_string(g,ADD, xctx->text[n].txt_ptr,
(xctx->text[n].rot +
( (move_flip && (xctx->text[n].rot & 1) ) ? move_rot+2 : move_rot) ) & 0x3,
xctx->text[n].flip^move_flip, xctx->text[n].hcenter, xctx->text[n].vcenter,
2020-08-08 15:47:34 +02:00
rx1+deltax, ry1+deltay,
xctx->text[n].xscale, xctx->text[n].yscale);
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
if(customfont) cairo_restore(cairo_ctx);
2020-08-08 15:47:34 +02:00
#endif
break;
case xRECT:
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
if(xctx->rect[c][n].sel==SELECTED)
2020-08-08 15:47:34 +02:00
{
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
}
else if(xctx->rect[c][n].sel==SELECTED1)
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
ry1+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==SELECTED2)
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
ry1+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==SELECTED3)
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
ry2+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==SELECTED4)
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
ry2+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==(SELECTED1|SELECTED2))
2020-08-08 15:47:34 +02:00
{
ry1+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==(SELECTED3|SELECTED4))
2020-08-08 15:47:34 +02:00
{
ry2+=deltay;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==(SELECTED1|SELECTED3))
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
else if(xctx->rect[c][n].sel==(SELECTED2|SELECTED4))
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
RECTORDER(rx1,ry1,rx2,ry2);
drawtemprect(g, ADD, rx1, ry1, rx2, ry2);
}
break;
case POLYGON:
2020-08-08 15:47:34 +02:00
{
double *x = my_malloc(223, sizeof(double) *xctx->poly[c][n].points);
double *y = my_malloc(224, sizeof(double) *xctx->poly[c][n].points);
if(xctx->poly[c][n].sel==SELECTED || xctx->poly[c][n].sel==SELECTED1) {
for(k=0;k<xctx->poly[c][n].points; k++) {
if( xctx->poly[c][n].sel==SELECTED || xctx->poly[c][n].selected_point[k]) {
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
ROTATION(move_rot, move_flip, xctx->poly[c][n].x[0], xctx->poly[c][n].y[0],
xctx->poly[c][n].x[k], xctx->poly[c][n].y[k], rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->poly[c][n].x[k], xctx->poly[c][n].y[k], rx1,ry1);
2020-08-08 15:47:34 +02:00
}
x[k] = rx1 + deltax;
y[k] = ry1 + deltay;
} else {
x[k] = xctx->poly[c][n].x[k];
y[k] = xctx->poly[c][n].y[k];
2020-08-08 15:47:34 +02:00
}
}
drawtemppolygon(g, NOW, x, y, xctx->poly[c][n].points);
2020-08-08 15:47:34 +02:00
}
my_free(816, &x);
my_free(817, &y);
}
break;
case WIRE:
if(rotatelocal) {
2020-11-17 01:29:47 +01:00
ROTATION(move_rot, move_flip, xctx->wire[n].x1, xctx->wire[n].y1,
xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->wire[n].x1, xctx->wire[n].y1,
xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
2020-08-08 15:47:34 +02:00
ORDER(rx1,ry1,rx2,ry2);
if(xctx->wire[n].sel==SELECTED)
2020-08-08 15:47:34 +02:00
{
if(xctx->wire[n].bus)
2020-08-08 15:47:34 +02:00
drawtempline(g, THICK, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
else
drawtempline(g, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
}
else if(xctx->wire[n].sel==SELECTED1)
2020-08-08 15:47:34 +02:00
{
if(xctx->wire[n].bus)
2020-08-08 15:47:34 +02:00
drawtempline(g, THICK, rx1+deltax, ry1+deltay, rx2, ry2);
else
drawtempline(g, ADD, rx1+deltax, ry1+deltay, rx2, ry2);
}
else if(xctx->wire[n].sel==SELECTED2)
2020-08-08 15:47:34 +02:00
{
if(xctx->wire[n].bus)
2020-08-08 15:47:34 +02:00
drawtempline(g, THICK, rx1, ry1, rx2+deltax, ry2+deltay);
else
drawtempline(g, ADD, rx1, ry1, rx2+deltax, ry2+deltay);
}
break;
case LINE:
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->line[c][n].x1, xctx->line[c][n].y1,
xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->line[c][n].x1, xctx->line[c][n].y1,
xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
ORDER(rx1,ry1,rx2,ry2);
if(xctx->line[c][n].sel==SELECTED)
2020-08-08 15:47:34 +02:00
{
if(xctx->line[c][n].bus)
drawtempline(g, THICK, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
else
drawtempline(g, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
2020-08-08 15:47:34 +02:00
}
else if(xctx->line[c][n].sel==SELECTED1)
2020-08-08 15:47:34 +02:00
{
if(xctx->line[c][n].bus)
drawtempline(g, THICK, rx1+deltax, ry1+deltay, rx2, ry2);
else
drawtempline(g, ADD, rx1+deltax, ry1+deltay, rx2, ry2);
2020-08-08 15:47:34 +02:00
}
else if(xctx->line[c][n].sel==SELECTED2)
2020-08-08 15:47:34 +02:00
{
if(xctx->line[c][n].bus)
drawtempline(g, THICK, rx1, ry1, rx2+deltax, ry2+deltay);
else
drawtempline(g, ADD, rx1, ry1, rx2+deltax, ry2+deltay);
2020-08-08 15:47:34 +02:00
}
break;
case ARC:
if(rotatelocal) {
/* rotate center wrt itself: do nothing */
rx1 = xctx->arc[c][n].x;
ry1 = xctx->arc[c][n].y;
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->arc[c][n].x, xctx->arc[c][n].y, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
angle = xctx->arc[c][n].a;
if(move_flip) {
angle = 270.*move_rot+180.-xctx->arc[c][n].b-xctx->arc[c][n].a;
2020-08-08 15:47:34 +02:00
} else {
angle = xctx->arc[c][n].a+move_rot*270.;
2020-08-08 15:47:34 +02:00
}
angle = fmod(angle, 360.);
if(angle<0.) angle+=360.;
if(xctx->arc[c][n].sel==SELECTED) {
drawtemparc(g, ADD, rx1+deltax, ry1+deltay, xctx->arc[c][n].r, angle, xctx->arc[c][n].b);
} else if(xctx->arc[c][n].sel==SELECTED1) {
drawtemparc(g, ADD, rx1, ry1, fabs(xctx->arc[c][n].r+deltax), angle, xctx->arc[c][n].b);
} else if(xctx->arc[c][n].sel==SELECTED3) {
angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+xctx->arc[c][n].b, 360.));
2020-08-08 15:47:34 +02:00
if(angle<0.) angle +=360.;
if(angle==0) angle=360.;
drawtemparc(g, ADD, rx1, ry1, xctx->arc[c][n].r, xctx->arc[c][n].a, angle);
} else if(xctx->arc[c][n].sel==SELECTED2) {
2020-08-08 15:47:34 +02:00
angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+angle, 360.));
if(angle<0.) angle +=360.;
drawtemparc(g, ADD, rx1, ry1, xctx->arc[c][n].r, angle, xctx->arc[c][n].b);
2020-08-08 15:47:34 +02:00
}
break;
case ELEMENT:
if(rotatelocal) {
2020-11-17 01:29:47 +01:00
ROTATION(move_rot, move_flip, xctx->inst[n].x0, xctx->inst[n].y0,
xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
for(k=0;k<cadlayers;k++)
draw_temp_symbol(ADD, g, n, k, move_flip,
( move_flip && (xctx->inst[n].rot & 1) ) ? move_rot+2 : move_rot,
rx1-xctx->inst[n].x0+deltax,ry1-xctx->inst[n].y0+deltay);
2020-08-08 15:47:34 +02:00
break;
}
#ifdef __unix__
if(XPending(display) && interruptable)
{
drawtemparc(g, END, 0.0, 0.0, 0.0, 0.0, 0.0);
drawtemprect(g, END, 0.0, 0.0, 0.0, 0.0);
drawtempline(g, END, 0.0, 0.0, 0.0, 0.0);
lastsel = i+1;
return;
}
#else
if (interruptable)
{
drawtemparc(g, END, 0.0, 0.0, 0.0, 0.0, 0.0);
drawtemprect(g, END, 0.0, 0.0, 0.0, 0.0);
drawtempline(g, END, 0.0, 0.0, 0.0, 0.0);
lastsel = i + 1;
return;
}
#endif
}
drawtemparc(g, END, 0.0, 0.0, 0.0, 0.0, 0.0);
drawtemprect(g, END, 0.0, 0.0, 0.0, 0.0);
drawtempline(g, END, 0.0, 0.0, 0.0, 0.0);
lastsel = i;
}
static struct int_hashentry *nodetable[HASHSIZE];
void find_inst_hash_clear(void)
{
free_int_hash(nodetable);
}
void find_inst_to_be_redrawn(const char *node)
{
int i, p, rects;
xSymbol * sym;
if(int_hash_lookup(nodetable, node, 0, XINSERT_NOREPLACE)) return;
2020-10-04 11:19:50 +02:00
dbg(1, "find_inst_to_be_redrawn(): node=%s\n", node);
for(i=0; i < xctx->instances; i++) {
sym = xctx->inst[i].ptr + xctx->sym;
rects = sym->rects[PINLAYER];
for(p = 0; p < rects; p++) {
if(node && xctx->inst[i].node[p] && !strcmp(xctx->inst[i].node[p], node )) {
symbol_bbox(i, &xctx->inst[i].x1, &xctx->inst[i].y1, &xctx->inst[i].x2, &xctx->inst[i].y2 );
bbox(ADD, xctx->inst[i].x1, xctx->inst[i].y1, xctx->inst[i].x2, xctx->inst[i].y2 );
}
}
}
for(i=0;i < xctx->wires; i++) {
if(node && xctx->wire[i].node && !strcmp(xctx->wire[i].node, node )) {
if(xctx->wire[i].bus){
int ov, y1, y2;
ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE;
if(xctx->wire[i].y1 < xctx->wire[i].y2) { y1 = xctx->wire[i].y1-ov; y2 = xctx->wire[i].y2+ov; }
else { y1 = xctx->wire[i].y1+ov; y2 = xctx->wire[i].y2-ov; }
bbox(ADD, xctx->wire[i].x1-ov, y1 , xctx->wire[i].x2+ov , y2 );
} else {
int ov, y1, y2;
ov = cadhalfdotsize;
if(xctx->wire[i].y1 < xctx->wire[i].y2) { y1 = xctx->wire[i].y1-ov; y2 = xctx->wire[i].y2+ov; }
else { y1 = xctx->wire[i].y1+ov; y2 = xctx->wire[i].y2-ov; }
bbox(ADD, xctx->wire[i].x1-ov, y1 , xctx->wire[i].x2+ov , y2 );
}
}
}
}
2020-08-08 15:47:34 +02:00
void copy_objects(int what)
{
int c, i, n, k;
/* xRect tmp; */
2020-08-08 15:47:34 +02:00
double angle;
int newpropcnt;
double tmpx, tmpy;
int textlayer;
const char *str;
2020-08-08 15:47:34 +02:00
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
char *textfont;
/* int customfont; */
2020-08-08 15:47:34 +02:00
#endif
if(what & START)
2020-08-08 15:47:34 +02:00
{
rotatelocal=0;
dbg(1, "copy_objects(): START copy\n");
2020-08-08 15:47:34 +02:00
rebuild_selected_array();
save_selection(1);
deltax = deltay = 0.0;
2020-12-02 15:10:47 +01:00
lastsel = xctx->lastsel;
x1=xctx->mousex_snap;y_1=xctx->mousey_snap;
move_flip = 0;move_rot = 0;
2020-12-02 15:10:47 +01:00
xctx->ui_state|=STARTCOPY;
2020-08-08 15:47:34 +02:00
}
if(what & ABORT) /* draw objects while moving */
{
char *str = NULL; /* 20161122 overflow safe */
draw_selection(gctiled,0);
move_rot=move_flip=deltax=deltay=0;
2020-12-02 15:10:47 +01:00
xctx->ui_state&=~STARTCOPY;
2020-08-08 15:47:34 +02:00
my_strdup(225, &str, user_conf_dir);
my_strcat(226, &str, "/.selection.sch");
xunlink(str);
update_symbol_bboxes(0, 0);
2020-08-08 15:47:34 +02:00
my_free(818, &str);
}
if(what & RUBBER) /* draw objects while moving */
{
2020-12-02 15:10:47 +01:00
x2=xctx->mousex_snap;y_2=xctx->mousey_snap;
2020-08-08 15:47:34 +02:00
draw_selection(gctiled,0);
deltax = x2-x1; deltay = y_2 - y_1;
draw_selection(gc[SELLAYER],1);
}
if(what & ROTATELOCAL ) {
2020-08-08 15:47:34 +02:00
rotatelocal=1;
}
2020-08-08 15:47:34 +02:00
if(what & ROTATE) {
draw_selection(gctiled,0);
move_rot= (move_rot+1) & 0x3;
update_symbol_bboxes(move_rot, move_flip);
}
2020-08-08 15:47:34 +02:00
if(what & FLIP)
{
draw_selection(gctiled,0);
move_flip = !move_flip;
update_symbol_bboxes(move_rot, move_flip);
2020-08-08 15:47:34 +02:00
}
if(what & END) /* copy selected objects */
{
int firstw, firsti;
int save_draw;
/* if the copy operation involved move_flip or rotations the original element bboxes were changed.
restore them now */
update_symbol_bboxes(0, 0);
2020-08-08 15:47:34 +02:00
save_draw = draw_window;
draw_window=1; /* temporarily re-enable draw to window together with pixmap */
draw_selection(gctiled,0);
bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
2020-08-08 15:47:34 +02:00
newpropcnt=0;
set_modify(1); push_undo(); /* 20150327 push_undo */
firstw = firsti = 1;
2020-12-02 15:10:47 +01:00
for(i=0;i<xctx->lastsel;i++)
{
2020-12-02 15:10:47 +01:00
n = xctx->sel_array[i].n;
if(xctx->sel_array[i].type == WIRE)
{
if(firstw) {
2020-12-02 15:10:47 +01:00
xctx->prep_hash_wires=0;
firstw = 0;
}
check_wire_storage();
/*
if(xctx->wire[n].bus){
int ov, y1, y2;
ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE;
if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; }
else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; }
bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 );
} else {
int ov, y1, y2;
ov = cadhalfdotsize;
if(xctx->wire[n].y1 < xctx->wire[n].y2) { y1 = xctx->wire[n].y1-ov; y2 = xctx->wire[n].y2+ov; }
else { y1 = xctx->wire[n].y1+ov; y2 = xctx->wire[n].y2-ov; }
bbox(ADD, xctx->wire[n].x1-ov, y1 , xctx->wire[n].x2+ov , y2 );
}
*/
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->wire[n].x1, xctx->wire[n].y1,
xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->wire[n].x1, xctx->wire[n].y1,
xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2);
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->wire[n].x1, xctx->wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->wire[n].x2, xctx->wire[n].y2, rx2,ry2);
}
if( xctx->wire[n].sel & (SELECTED|SELECTED1) )
{
rx1+=deltax;
ry1+=deltay;
}
if( xctx->wire[n].sel & (SELECTED|SELECTED2) )
{
rx2+=deltax;
ry2+=deltay;
}
tmpx=rx1; /* used as temporary storage */
tmpy=ry1;
ORDER(rx1,ry1,rx2,ry2);
if( tmpx == rx2 && tmpy == ry2)
{
if(xctx->wire[n].sel == SELECTED1) xctx->wire[n].sel = SELECTED2;
else if(xctx->wire[n].sel == SELECTED2) xctx->wire[n].sel = SELECTED1;
}
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->wires;
storeobject(-1, rx1,ry1,rx2,ry2,WIRE,0,xctx->wire[n].sel,xctx->wire[n].prop_ptr);
xctx->wire[n].sel=0;
if(xctx->wire[n].bus)
drawline(WIRELAYER, THICK, rx1,ry1,rx2,ry2, 0);
else
drawline(WIRELAYER, ADD, rx1,ry1,rx2,ry2, 0);
}
drawline(WIRELAYER, END, 0.0, 0.0, 0.0, 0.0, 0);
}
2020-08-08 15:47:34 +02:00
for(k=0;k<cadlayers;k++)
{
2020-12-02 15:10:47 +01:00
for(i=0;i<xctx->lastsel;i++)
2020-08-08 15:47:34 +02:00
{
2020-12-02 15:10:47 +01:00
c = xctx->sel_array[i].col;n = xctx->sel_array[i].n;
switch(xctx->sel_array[i].type)
2020-08-08 15:47:34 +02:00
{
case LINE:
if(c!=k) break;
/* bbox(ADD, xctx->line[c][n].x1, xctx->line[c][n].y1, xctx->line[c][n].x2, xctx->line[c][n].y2) */
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->line[c][n].x1, xctx->line[c][n].y1,
xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->line[c][n].x1, xctx->line[c][n].y1,
xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->line[c][n].x1, xctx->line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->line[c][n].x2, xctx->line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
if( xctx->line[c][n].sel & (SELECTED|SELECTED1) )
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
ry1+=deltay;
}
if( xctx->line[c][n].sel & (SELECTED|SELECTED2) )
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
ry2+=deltay;
}
tmpx=rx1;
tmpy=ry1;
ORDER(rx1,ry1,rx2,ry2);
if( tmpx == rx2 && tmpy == ry2)
{
if(xctx->line[c][n].sel == SELECTED1) xctx->line[c][n].sel = SELECTED2;
else if(xctx->line[c][n].sel == SELECTED2) xctx->line[c][n].sel = SELECTED1;
2020-08-08 15:47:34 +02:00
}
if(xctx->line[c][n].bus)
drawline(k, THICK, rx1,ry1,rx2,ry2, xctx->line[c][n].dash);
else
drawline(k, ADD, rx1,ry1,rx2,ry2, xctx->line[c][n].dash);
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->lines[c];
storeobject(-1, rx1, ry1, rx2, ry2, LINE, c, xctx->line[c][n].sel, xctx->line[c][n].prop_ptr);
xctx->line[c][n].sel=0;
2020-08-08 15:47:34 +02:00
break;
case POLYGON:
2020-08-08 15:47:34 +02:00
if(c!=k) break;
{
xPoly *p = &xctx->poly[c][n];
/* double bx1, by1, bx2, by2; */
double *x = my_malloc(227, sizeof(double) *p->points);
double *y = my_malloc(228, sizeof(double) *p->points);
2020-08-08 15:47:34 +02:00
int j;
for(j=0; j<p->points; j++) {
/*
if(j==0 || p->x[j] < bx1) bx1 = p->x[j];
if(j==0 || p->y[j] < by1) by1 = p->y[j];
if(j==0 || p->x[j] > bx2) bx2 = p->x[j];
if(j==0 || p->y[j] > by2) by2 = p->y[j];
*/
if( p->sel==SELECTED || p->selected_point[j]) {
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
ROTATION(move_rot, move_flip, p->x[0], p->y[0], p->x[j], p->y[j], rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, p->x[j], p->y[j], rx1,ry1);
2020-08-08 15:47:34 +02:00
}
x[j] = rx1+deltax;
y[j] = ry1+deltay;
} else {
x[j] = p->x[j];
y[j] = p->y[j];
2020-08-08 15:47:34 +02:00
}
}
/* bbox(ADD, bx1, by1, bx2, by2); */
drawpolygon(k, NOW, x, y, p->points, p->fill, p->dash); /* 20180914 added fill */
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->polygons[c];
store_poly(-1, x, y, p->points, c, p->sel, p->prop_ptr);
p->sel=0;
2020-08-08 15:47:34 +02:00
my_free(819, &x);
my_free(820, &y);
}
break;
case ARC:
if(c!=k) break;
/*
arc_bbox(xctx->arc[c][n].x, xctx->arc[c][n].y, xctx->arc[c][n].r, xctx->arc[c][n].a, xctx->arc[c][n].b,
2020-08-08 15:47:34 +02:00
&tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2);
bbox(ADD, tmp.x1, tmp.y1, tmp.x2, tmp.y2);
*/
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
/* rotate center wrt itself: do nothing */
rx1 = xctx->arc[c][n].x;
ry1 = xctx->arc[c][n].y;
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->arc[c][n].x, xctx->arc[c][n].y, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
angle = xctx->arc[c][n].a;
if(move_flip) {
angle = 270.*move_rot+180.-xctx->arc[c][n].b-xctx->arc[c][n].a;
2020-08-08 15:47:34 +02:00
} else {
angle = xctx->arc[c][n].a+move_rot*270.;
2020-08-08 15:47:34 +02:00
}
angle = fmod(angle, 360.);
if(angle<0.) angle+=360.;
xctx->arc[c][n].sel=0;
drawarc(k, ADD, rx1+deltax, ry1+deltay,
xctx->arc[c][n].r, angle, xctx->arc[c][n].b, xctx->arc[c][n].fill, xctx->arc[c][n].dash);
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->arcs[c];
2020-08-08 15:47:34 +02:00
store_arc(-1, rx1+deltax, ry1+deltay,
xctx->arc[c][n].r, angle, xctx->arc[c][n].b, c, SELECTED, xctx->arc[c][n].prop_ptr);
2020-08-08 15:47:34 +02:00
break;
case xRECT:
if(c!=k) break;
/* bbox(ADD, xctx->rect[c][n].x1, xctx->rect[c][n].y1, xctx->rect[c][n].x2, xctx->rect[c][n].y2); */
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
RECTORDER(rx1,ry1,rx2,ry2);
xctx->rect[c][n].sel=0;
drawrect(k, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay, xctx->rect[c][n].dash);
2020-08-08 15:47:34 +02:00
filledrect(k, ADD, rx1+deltax, ry1+deltay, rx2+deltax, ry2+deltay);
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->rects[c];
storeobject(-1, rx1+deltax, ry1+deltay,
rx2+deltax, ry2+deltay,xRECT, c, SELECTED, xctx->rect[c][n].prop_ptr);
2020-08-08 15:47:34 +02:00
break;
case xTEXT:
if(k!=TEXTLAYER) break;
check_text_storage();
/*
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
customfont = set_text_custom_font(&xctx->text[n]);
2020-08-08 15:47:34 +02:00
#endif
text_bbox(xctx->text[n].txt_ptr, xctx->text[n].xscale,
xctx->text[n].yscale, xctx->text[n].rot,xctx->text[n].flip, xctx->text[n].hcenter, xctx->text[n].vcenter,
xctx->text[n].x0, xctx->text[n].y0,
&rx1,&ry1, &rx2,&ry2);
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
if(customfont) cairo_restore(cairo_ctx);
2020-08-08 15:47:34 +02:00
#endif
bbox(ADD, rx1, ry1, rx2, ry2 );
*/
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->text[n].x0, xctx->text[n].y0,
xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
xctx->text[xctx->texts].txt_ptr=NULL;
my_strdup(229, &xctx->text[xctx->texts].txt_ptr,xctx->text[n].txt_ptr);
xctx->text[n].sel=0;
2020-08-08 15:47:34 +02:00
dbg(2, "copy_objects(): current str=%s\n",
xctx->text[xctx->texts].txt_ptr);
xctx->text[xctx->texts].x0=rx1+deltax;
xctx->text[xctx->texts].y0=ry1+deltay;
xctx->text[xctx->texts].rot=(xctx->text[n].rot +
( (move_flip && (xctx->text[n].rot & 1) ) ? move_rot+2 : move_rot) ) & 0x3;
xctx->text[xctx->texts].flip=move_flip^xctx->text[n].flip;
xctx->text[xctx->texts].sel=SELECTED;
xctx->text[xctx->texts].prop_ptr=NULL;
xctx->text[xctx->texts].font=NULL;
my_strdup(230, &xctx->text[xctx->texts].prop_ptr, xctx->text[n].prop_ptr);
my_strdup(231, &xctx->text[xctx->texts].font, get_tok_value(xctx->text[xctx->texts].prop_ptr, "font", 0));
str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "hcenter", 0);
xctx->text[xctx->texts].hcenter = strcmp(str, "true") ? 0 : 1;
str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "vcenter", 0);
xctx->text[xctx->texts].vcenter = strcmp(str, "true") ? 0 : 1;
str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "layer", 0);
if(str[0]) xctx->text[xctx->texts].layer = atoi(str);
else xctx->text[xctx->texts].layer = -1;
xctx->text[xctx->texts].flags = 0;
str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "slant", 0);
xctx->text[xctx->texts].flags |= strcmp(str, "oblique") ? 0 : TEXT_OBLIQUE;
xctx->text[xctx->texts].flags |= strcmp(str, "italic") ? 0 : TEXT_ITALIC;
str = get_tok_value(xctx->text[xctx->texts].prop_ptr, "weight", 0);
xctx->text[xctx->texts].flags |= strcmp(str, "bold") ? 0 : TEXT_BOLD;
xctx->text[xctx->texts].xscale=xctx->text[n].xscale;
xctx->text[xctx->texts].yscale=xctx->text[n].yscale;
textlayer = xctx->text[xctx->texts].layer;
2020-08-08 15:47:34 +02:00
if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
#ifdef HAS_CAIRO
textfont = xctx->text[xctx->texts].font;
if((textfont && textfont[0]) || xctx->text[xctx->texts].flags) {
char *font = xctx->text[xctx->texts].font;
int flags = xctx->text[xctx->texts].flags;
cairo_font_slant_t slant;
cairo_font_weight_t weight;
textfont = (font && font[0]) ? font : cairo_font_name;
weight = ( flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
slant = CAIRO_FONT_SLANT_NORMAL;
if(flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC;
if(flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
cairo_save(cairo_ctx);
cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face (cairo_ctx, textfont, slant, weight);
cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight);
2020-08-08 15:47:34 +02:00
}
#endif
draw_string(textlayer, ADD, xctx->text[xctx->texts].txt_ptr, /* draw moved txt */
xctx->text[xctx->texts].rot, xctx->text[xctx->texts].flip,
xctx->text[xctx->texts].hcenter, xctx->text[xctx->texts].vcenter,
2020-08-08 15:47:34 +02:00
rx1+deltax,ry1+deltay,
xctx->text[xctx->texts].xscale, xctx->text[xctx->texts].yscale);
#ifndef HAS_CAIRO
drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0);
drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0);
#endif
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
if( (textfont && textfont[0]) || xctx->text[xctx->texts].flags) {
cairo_restore(cairo_ctx);
cairo_restore(xctx->cairo_save_ctx);
2020-08-08 15:47:34 +02:00
}
#endif
2020-12-02 15:10:47 +01:00
xctx->sel_array[i].n=xctx->texts;
xctx->texts++;
2020-08-08 15:47:34 +02:00
dbg(2, "copy_objects(): done copy string\n");
break;
case ELEMENT:
if(k==0) {
if(firsti) {
2020-12-02 15:10:47 +01:00
xctx->prep_hash_inst = 0;
firsti = 0;
}
2020-08-08 15:47:34 +02:00
check_inst_storage();
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->inst[n].x0, xctx->inst[n].y0,
xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->inst[n].x0, xctx->inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
xctx->inst[xctx->instances] = xctx->inst[n];
xctx->inst[xctx->instances].prop_ptr=NULL;
xctx->inst[xctx->instances].instname=NULL;
xctx->inst[xctx->instances].node=NULL;
xctx->inst[xctx->instances].name=NULL;
my_strdup(232, &xctx->inst[xctx->instances].name, xctx->inst[n].name);
my_strdup(233, &xctx->inst[xctx->instances].prop_ptr, xctx->inst[n].prop_ptr);
my_strdup2(234, &xctx->inst[xctx->instances].instname, get_tok_value(xctx->inst[n].prop_ptr, "name",0));
xctx->inst[n].sel=0;
xctx->inst[xctx->instances].flags = xctx->inst[n].flags;
xctx->inst[xctx->instances].flags &= ~4; /* do not propagate hilight */
xctx->inst[xctx->instances].x0 = rx1+deltax;
xctx->inst[xctx->instances].y0 = ry1+deltay;
xctx->inst[xctx->instances].sel = SELECTED;
xctx->inst[xctx->instances].rot = (xctx->inst[xctx->instances].rot +
( (move_flip && (xctx->inst[xctx->instances].rot & 1) ) ? move_rot+2 : move_rot) ) & 0x3;
xctx->inst[xctx->instances].flip = (move_flip? !xctx->inst[n].flip:xctx->inst[n].flip);
/* the newpropcnt argument is zero for the 1st call and used in */
/* new_prop_string() for cleaning some internal caches. */
if(!newpropcnt) hash_all_names(xctx->instances);
new_prop_string(xctx->instances, xctx->inst[n].prop_ptr,newpropcnt++, dis_uniq_names);
my_strdup2(235, &xctx->inst[xctx->instances].instname,
get_tok_value(xctx->inst[xctx->instances].prop_ptr, "name", 0));
2020-12-02 15:10:47 +01:00
n=xctx->sel_array[i].n=xctx->instances;
xctx->instances++;
2020-08-08 15:47:34 +02:00
}
break;
2020-12-02 15:10:47 +01:00
} /* end switch(xctx->sel_array[i].type) */
} /* end for(i=0;i<xctx->lastsel;i++) */
if(k == 0 ) {
/* force these vars to 0 to trigger a prepare_netlist_structs(0) needed by symbol_bbox->translate
* to translate @#n:net_name texts */
2020-12-02 15:10:47 +01:00
xctx->need_reb_sel_arr=1;
rebuild_selected_array();
if(!firsti || !firstw) {
2020-12-02 15:10:47 +01:00
xctx->prep_net_structs=0;
xctx->prep_hi_structs=0;
}
if(show_pin_net_names) {
prepare_netlist_structs(0);
}
2020-08-08 15:47:34 +02:00
}
2020-12-02 15:10:47 +01:00
for(i = 0; i < xctx->lastsel; i++) {
n = xctx->sel_array[i].n;
if(k == 0) {
2020-12-02 15:10:47 +01:00
if(xctx->sel_array[i].type == ELEMENT) {
int p;
symbol_bbox(n, &xctx->inst[n].x1, &xctx->inst[n].y1, &xctx->inst[n].x2, &xctx->inst[n].y2 );
bbox(ADD, xctx->inst[n].x1, xctx->inst[n].y1, xctx->inst[n].x2, xctx->inst[n].y2 );
if(show_pin_net_names) for(p = 0; p < (xctx->inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) {
if( xctx->inst[n].node && xctx->inst[n].node[p]) {
find_inst_to_be_redrawn(xctx->inst[n].node[p]);
}
}
}
2020-12-02 15:10:47 +01:00
if(show_pin_net_names && xctx->sel_array[i].type == WIRE) {
find_inst_to_be_redrawn(xctx->wire[n].node);
}
}
}
if(show_pin_net_names) find_inst_hash_clear();
2020-08-08 15:47:34 +02:00
filledrect(k, END, 0.0, 0.0, 0.0, 0.0);
2020-09-02 23:59:58 +02:00
drawarc(k, END, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
drawrect(k, END, 0.0, 0.0, 0.0, 0.0, 0);
drawline(k, END, 0.0, 0.0, 0.0, 0.0, 0);
} /* end for(k=0;k<cadlayers;k++) */
2020-08-08 15:47:34 +02:00
check_collapsing_objects();
update_conn_cues(1, 1);
2020-12-02 15:10:47 +01:00
xctx->ui_state &= ~STARTCOPY;
x1=y_1=x2=y_2=move_rot=move_flip=deltax=deltay=0;
2020-08-08 15:47:34 +02:00
bbox(SET , 0.0 , 0.0 , 0.0 , 0.0);
draw();
bbox(END , 0.0 , 0.0 , 0.0 , 0.0);
rotatelocal=0;
draw_window = save_draw;
}
draw_selection(gc[SELLAYER], 0);
}
2020-08-08 15:47:34 +02:00
/* merge param unused, RFU */
void move_objects(int what, int merge, double dx, double dy)
{
int c, i, n, k;
xRect tmp;
2020-08-08 15:47:34 +02:00
double angle;
double tx1,ty1; /* temporaries for swapping coordinates 20070302 */
int textlayer;
#ifdef HAS_CAIRO
int customfont;
#endif
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
char *textfont;
#endif
xInstance * const inst = xctx->inst;
xLine ** const line = xctx->line;
xWire * const wire = xctx->wire;
2020-08-08 15:47:34 +02:00
if(what & START)
2020-08-08 15:47:34 +02:00
{
rotatelocal=0;
2020-08-08 15:47:34 +02:00
deltax = deltay = 0.0;
rebuild_selected_array();
2020-12-02 15:10:47 +01:00
lastsel = xctx->lastsel;
if(xctx->lastsel==1 && xctx->sel_array[0].type==ARC &&
xctx->arc[c=xctx->sel_array[0].col][n=xctx->sel_array[0].n].sel!=SELECTED) {
x1 = xctx->arc[c][n].x;
y_1 = xctx->arc[c][n].y;
2020-12-02 15:10:47 +01:00
} else {x1=xctx->mousex_snap;y_1=xctx->mousey_snap;}
move_flip = 0;move_rot = 0;
2020-12-02 15:10:47 +01:00
xctx->ui_state|=STARTMOVE;
2020-08-08 15:47:34 +02:00
}
if(what & ABORT) /* draw objects while moving */
{
draw_selection(gctiled,0);
move_rot=move_flip=deltax=deltay=0;
2020-12-02 15:10:47 +01:00
xctx->ui_state &= ~STARTMOVE;
xctx->ui_state &= ~PLACE_SYMBOL;
update_symbol_bboxes(0, 0);
2020-08-08 15:47:34 +02:00
}
if(what & RUBBER) /* abort operation */
{
2020-12-02 15:10:47 +01:00
x2=xctx->mousex_snap;y_2=xctx->mousey_snap;
2020-08-08 15:47:34 +02:00
draw_selection(gctiled,0);
deltax = x2-x1; deltay = y_2 - y_1;
draw_selection(gc[SELLAYER],1);
}
if(what & ROTATELOCAL) {
2020-08-08 15:47:34 +02:00
rotatelocal=1;
}
2020-08-08 15:47:34 +02:00
if(what & ROTATE) {
draw_selection(gctiled,0);
move_rot= (move_rot+1) & 0x3;
update_symbol_bboxes(move_rot, move_flip);
}
2020-08-08 15:47:34 +02:00
if(what & FLIP)
{
draw_selection(gctiled,0);
move_flip = !move_flip;
update_symbol_bboxes(move_rot, move_flip);
2020-08-08 15:47:34 +02:00
}
if(what & END) /* move selected objects */
{
int firsti, firstw;
int save_draw;
2020-08-08 15:47:34 +02:00
save_draw = draw_window;
draw_window=1; /* temporarily re-enable draw to xctx->window together with pixmap */
2020-08-08 15:47:34 +02:00
draw_selection(gctiled,0);
bbox(START, 0.0 , 0.0 , 0.0 , 0.0);
set_modify(1);
2020-12-02 15:10:47 +01:00
if( !(xctx->ui_state & (STARTMERGE | PLACE_SYMBOL)) ) {
2020-08-08 15:47:34 +02:00
dbg(1, "move_objects(): push undo state\n");
push_undo(); /* 20150327 push_undo */
}
2020-12-02 15:10:47 +01:00
xctx->ui_state &= ~PLACE_SYMBOL;
2020-08-08 15:47:34 +02:00
if(dx!=0.0 || dy!=0.0) {
deltax = dx;
deltay = dy;
}
/* calculate moving symbols bboxes before actually doing the move */
firsti = firstw = 1;
2020-12-02 15:10:47 +01:00
for(i=0;i<xctx->lastsel;i++)
{
2020-12-02 15:10:47 +01:00
n = xctx->sel_array[i].n;
if( xctx->sel_array[i].type == ELEMENT) {
int p;
symbol_bbox(n, &inst[n].x1, &inst[n].y1, &inst[n].x2, &inst[n].y2 );
bbox(ADD, inst[n].x1, inst[n].y1, inst[n].x2, inst[n].y2 );
if(show_pin_net_names) for(p = 0; p < (inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) {
if( inst[n].node && inst[n].node[p]) {
find_inst_to_be_redrawn(inst[n].node[p]);
}
}
}
2020-12-02 15:10:47 +01:00
if(show_pin_net_names && xctx->sel_array[i].type == WIRE) {
find_inst_to_be_redrawn(wire[n].node);
}
}
if(show_pin_net_names) find_inst_hash_clear();
2020-08-08 15:47:34 +02:00
for(k=0;k<cadlayers;k++)
{
2020-12-02 15:10:47 +01:00
for(i=0;i<xctx->lastsel;i++)
2020-08-08 15:47:34 +02:00
{
2020-12-02 15:10:47 +01:00
c = xctx->sel_array[i].col;n = xctx->sel_array[i].n;
switch(xctx->sel_array[i].type)
2020-08-08 15:47:34 +02:00
{
case WIRE:
if(firstw) {
2020-12-02 15:10:47 +01:00
xctx->prep_hash_wires=0;
firstw = 0;
}
if(k == 0) {
if(wire[n].bus){
int ov, y1, y2;
ov = INT_BUS_WIDTH(xctx->lw)> cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE;
if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; }
else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; }
bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 );
} else {
int ov, y1, y2;
ov = cadhalfdotsize;
if(wire[n].y1 < wire[n].y2) { y1 = wire[n].y1-ov; y2 = wire[n].y2+ov; }
else { y1 = wire[n].y1+ov; y2 = wire[n].y2-ov; }
bbox(ADD, wire[n].x1-ov, y1 , wire[n].x2+ov , y2 );
}
if(rotatelocal) {
ROTATION(move_rot, move_flip, wire[n].x1, wire[n].y1, wire[n].x1, wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, rx2,ry2);
} else {
ROTATION(move_rot, move_flip, x1, y_1, wire[n].x1, wire[n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, wire[n].x2, wire[n].y2, rx2,ry2);
}
if( wire[n].sel & (SELECTED|SELECTED1) )
{
rx1+=deltax;
ry1+=deltay;
}
if( wire[n].sel & (SELECTED|SELECTED2) )
{
rx2+=deltax;
ry2+=deltay;
}
wire[n].x1=rx1;
wire[n].y1=ry1;
ORDER(rx1,ry1,rx2,ry2);
if( wire[n].x1 == rx2 && wire[n].y1 == ry2)
{
if(wire[n].sel == SELECTED1) wire[n].sel = SELECTED2;
else if(wire[n].sel == SELECTED2) wire[n].sel = SELECTED1;
}
wire[n].x1=rx1;
wire[n].y1=ry1;
wire[n].x2=rx2;
wire[n].y2=ry2;
} else if(k == WIRELAYER) {
if(wire[n].bus)
drawline(WIRELAYER, THICK, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0);
else
drawline(WIRELAYER, ADD, wire[n].x1, wire[n].y1, wire[n].x2, wire[n].y2, 0);
2020-08-08 15:47:34 +02:00
}
break;
case LINE:
if(c!=k) break;
bbox(ADD, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2);
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
ROTATION(move_rot, move_flip, line[c][n].x1, line[c][n].y1, line[c][n].x1, line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, line[c][n].x1, line[c][n].y1, line[c][n].x2, line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, line[c][n].x1, line[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, line[c][n].x2, line[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
if( line[c][n].sel & (SELECTED|SELECTED1) )
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
ry1+=deltay;
}
if( line[c][n].sel & (SELECTED|SELECTED2) )
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
ry2+=deltay;
}
line[c][n].x1=rx1;
line[c][n].y1=ry1;
2020-08-08 15:47:34 +02:00
ORDER(rx1,ry1,rx2,ry2);
if( line[c][n].x1 == rx2 && line[c][n].y1 == ry2)
2020-08-08 15:47:34 +02:00
{
if(line[c][n].sel == SELECTED1) line[c][n].sel = SELECTED2;
else if(line[c][n].sel == SELECTED2) line[c][n].sel = SELECTED1;
2020-08-08 15:47:34 +02:00
}
line[c][n].x1=rx1;
line[c][n].y1=ry1;
line[c][n].x2=rx2;
line[c][n].y2=ry2;
if(line[c][n].bus)
drawline(k, THICK, line[c][n].x1, line[c][n].y1,
line[c][n].x2, line[c][n].y2, line[c][n].dash);
else
drawline(k, ADD, line[c][n].x1, line[c][n].y1,
line[c][n].x2, line[c][n].y2, line[c][n].dash);
2020-08-08 15:47:34 +02:00
break;
case POLYGON:
2020-08-08 15:47:34 +02:00
if(c!=k) break;
{
xPoly *p = &xctx->poly[c][n];
2020-08-08 15:47:34 +02:00
double bx1=0., by1=0., bx2=0., by2=0.;
int j;
double savex0, savey0;
savex0 = p->x[0];
savey0 = p->y[0];
for(j=0; j<p->points; j++) {
if(j==0 || p->x[j] < bx1) bx1 = p->x[j];
if(j==0 || p->y[j] < by1) by1 = p->y[j];
if(j==0 || p->x[j] > bx2) bx2 = p->x[j];
if(j==0 || p->y[j] > by2) by2 = p->y[j];
2020-08-08 15:47:34 +02:00
if( p->sel==SELECTED || p->selected_point[j]) {
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
ROTATION(move_rot, move_flip, savex0, savey0, p->x[j], p->y[j], rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, p->x[j], p->y[j], rx1,ry1);
2020-08-08 15:47:34 +02:00
}
p->x[j] = rx1+deltax;
p->y[j] = ry1+deltay;
2020-08-08 15:47:34 +02:00
}
2020-08-08 15:47:34 +02:00
}
bbox(ADD, bx1, by1, bx2, by2);
drawpolygon(k, NOW, p->x, p->y, p->points, p->fill, p->dash);
2020-08-08 15:47:34 +02:00
}
break;
case ARC:
if(c!=k) break;
if(xctx->arc[c][n].fill)
arc_bbox(xctx->arc[c][n].x, xctx->arc[c][n].y, xctx->arc[c][n].r, 0, 360,
&tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2);
2020-08-08 15:47:34 +02:00
else
arc_bbox(xctx->arc[c][n].x, xctx->arc[c][n].y, xctx->arc[c][n].r, xctx->arc[c][n].a, xctx->arc[c][n].b,
&tmp.x1, &tmp.y1, &tmp.x2, &tmp.y2);
2020-08-08 15:47:34 +02:00
dbg(1, "move_objects(): arc_bbox: %g %g %g %g\n", tmp.x1, tmp.y1, tmp.x2, tmp.y2);
bbox(ADD, tmp.x1, tmp.y1, tmp.x2, tmp.y2);
if(rotatelocal) {
/* rotate center wrt itself: do nothing */
rx1 = xctx->arc[c][n].x;
ry1 = xctx->arc[c][n].y;
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->arc[c][n].x, xctx->arc[c][n].y, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
angle = xctx->arc[c][n].a;
if(move_flip) {
angle = 270.*move_rot+180.-xctx->arc[c][n].b-xctx->arc[c][n].a;
2020-08-08 15:47:34 +02:00
} else {
angle = xctx->arc[c][n].a+move_rot*270.;
2020-08-08 15:47:34 +02:00
}
angle = fmod(angle, 360.);
if(angle<0.) angle+=360.;
if(xctx->arc[c][n].sel == SELECTED) {
xctx->arc[c][n].x = rx1+deltax;
xctx->arc[c][n].y = ry1+deltay;
xctx->arc[c][n].a = angle;
} else if(xctx->arc[c][n].sel == SELECTED1) {
xctx->arc[c][n].x = rx1;
xctx->arc[c][n].y = ry1;
if(xctx->arc[c][n].r+deltax) xctx->arc[c][n].r = fabs(xctx->arc[c][n].r+deltax);
xctx->arc[c][n].a = angle;
} else if(xctx->arc[c][n].sel == SELECTED2) {
2020-08-08 15:47:34 +02:00
angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+angle, 360.));
if(angle<0.) angle +=360.;
xctx->arc[c][n].x = rx1;
xctx->arc[c][n].y = ry1;
xctx->arc[c][n].a = angle;
} else if(xctx->arc[c][n].sel==SELECTED3) {
angle = ROUND(fmod(atan2(-deltay, deltax)*180./XSCH_PI+xctx->arc[c][n].b, 360.));
2020-08-08 15:47:34 +02:00
if(angle<0.) angle +=360.;
if(angle==0) angle=360.;
xctx->arc[c][n].x = rx1;
xctx->arc[c][n].y = ry1;
xctx->arc[c][n].b = angle;
2020-08-08 15:47:34 +02:00
}
drawarc(k, ADD, xctx->arc[c][n].x, xctx->arc[c][n].y, xctx->arc[c][n].r,
xctx->arc[c][n].a, xctx->arc[c][n].b, xctx->arc[c][n].fill, xctx->arc[c][n].dash);
2020-08-08 15:47:34 +02:00
break;
case xRECT:
if(c!=k) break;
bbox(ADD, xctx->rect[c][n].x1, xctx->rect[c][n].y1, xctx->rect[c][n].x2, xctx->rect[c][n].y2);
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x1, xctx->rect[c][n].y1, rx1,ry1);
ROTATION(move_rot, move_flip, x1, y_1, xctx->rect[c][n].x2, xctx->rect[c][n].y2, rx2,ry2);
2020-08-08 15:47:34 +02:00
}
if( xctx->rect[c][n].sel == SELECTED) {
2020-08-08 15:47:34 +02:00
rx1+=deltax;
ry1+=deltay;
rx2+=deltax;
ry2+=deltay;
}
else if( xctx->rect[c][n].sel == SELECTED1) { /* 20070302 stretching on rectangles */
2020-08-08 15:47:34 +02:00
rx1+=deltax;
ry1+=deltay;
}
else if( xctx->rect[c][n].sel == SELECTED2) {
2020-08-08 15:47:34 +02:00
rx2+=deltax;
ry1+=deltay;
}
else if( xctx->rect[c][n].sel == SELECTED3) {
2020-08-08 15:47:34 +02:00
rx1+=deltax;
ry2+=deltay;
}
else if( xctx->rect[c][n].sel == SELECTED4) {
2020-08-08 15:47:34 +02:00
rx2+=deltax;
ry2+=deltay;
}
else if(xctx->rect[c][n].sel==(SELECTED1|SELECTED2))
2020-08-08 15:47:34 +02:00
{
ry1+=deltay;
}
else if(xctx->rect[c][n].sel==(SELECTED3|SELECTED4))
2020-08-08 15:47:34 +02:00
{
ry2+=deltay;
}
else if(xctx->rect[c][n].sel==(SELECTED1|SELECTED3))
2020-08-08 15:47:34 +02:00
{
rx1+=deltax;
}
else if(xctx->rect[c][n].sel==(SELECTED2|SELECTED4))
2020-08-08 15:47:34 +02:00
{
rx2+=deltax;
}
tx1 = rx1;
ty1 = ry1;
RECTORDER(rx1,ry1,rx2,ry2);
if( rx2 == tx1) {
if(xctx->rect[c][n].sel==SELECTED1) xctx->rect[c][n].sel = SELECTED2;
else if(xctx->rect[c][n].sel==SELECTED2) xctx->rect[c][n].sel = SELECTED1;
else if(xctx->rect[c][n].sel==SELECTED3) xctx->rect[c][n].sel = SELECTED4;
else if(xctx->rect[c][n].sel==SELECTED4) xctx->rect[c][n].sel = SELECTED3;
2020-08-08 15:47:34 +02:00
}
if( ry2 == ty1) {
if(xctx->rect[c][n].sel==SELECTED1) xctx->rect[c][n].sel = SELECTED3;
else if(xctx->rect[c][n].sel==SELECTED3) xctx->rect[c][n].sel = SELECTED1;
else if(xctx->rect[c][n].sel==SELECTED2) xctx->rect[c][n].sel = SELECTED4;
else if(xctx->rect[c][n].sel==SELECTED4) xctx->rect[c][n].sel = SELECTED2;
2020-08-08 15:47:34 +02:00
}
xctx->rect[c][n].x1 = rx1;
xctx->rect[c][n].y1 = ry1;
xctx->rect[c][n].x2 = rx2;
xctx->rect[c][n].y2 = ry2;
drawrect(k, ADD, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x2, xctx->rect[c][n].y2, xctx->rect[c][n].dash);
filledrect(c, ADD, xctx->rect[c][n].x1, xctx->rect[c][n].y1,
xctx->rect[c][n].x2, xctx->rect[c][n].y2);
2020-08-08 15:47:34 +02:00
break;
case xTEXT:
if(k!=TEXTLAYER) break;
#ifdef HAS_CAIRO
customfont = set_text_custom_font(&xctx->text[n]);
2020-08-08 15:47:34 +02:00
#endif
text_bbox(xctx->text[n].txt_ptr, xctx->text[n].xscale,
xctx->text[n].yscale, xctx->text[n].rot,xctx->text[n].flip, xctx->text[n].hcenter,
xctx->text[n].vcenter, xctx->text[n].x0, xctx->text[n].y0, &rx1,&ry1, &rx2,&ry2);
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
if(customfont) cairo_restore(cairo_ctx);
2020-08-08 15:47:34 +02:00
#endif
bbox(ADD, rx1, ry1, rx2, ry2 );
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
2020-11-16 12:33:06 +01:00
ROTATION(move_rot, move_flip, xctx->text[n].x0, xctx->text[n].y0,
xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, xctx->text[n].x0, xctx->text[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
xctx->text[n].x0=rx1+deltax;
xctx->text[n].y0=ry1+deltay;
xctx->text[n].rot=(xctx->text[n].rot +
( (move_flip && (xctx->text[n].rot & 1) ) ? move_rot+2 : move_rot) ) & 0x3;
xctx->text[n].flip=move_flip^xctx->text[n].flip;
textlayer = xctx->text[n].layer;
2020-08-08 15:47:34 +02:00
if(textlayer < 0 || textlayer >= cadlayers) textlayer = TEXTLAYER;
#ifdef HAS_CAIRO
textfont = xctx->text[n].font;
if((textfont && textfont[0]) || xctx->text[n].flags) {
cairo_font_slant_t slant;
cairo_font_weight_t weight;
textfont = (xctx->text[n].font && xctx->text[n].font[0]) ? xctx->text[n].font : cairo_font_name;
weight = ( xctx->text[n].flags & TEXT_BOLD) ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL;
slant = CAIRO_FONT_SLANT_NORMAL;
if(xctx->text[n].flags & TEXT_ITALIC) slant = CAIRO_FONT_SLANT_ITALIC;
if(xctx->text[n].flags & TEXT_OBLIQUE) slant = CAIRO_FONT_SLANT_OBLIQUE;
cairo_save(cairo_ctx);
cairo_save(xctx->cairo_save_ctx);
cairo_select_font_face (cairo_ctx, textfont, slant, weight);
cairo_select_font_face (xctx->cairo_save_ctx, textfont, slant, weight);
2020-08-08 15:47:34 +02:00
}
#endif
draw_string(textlayer, ADD, xctx->text[n].txt_ptr, /* draw moved txt */
xctx->text[n].rot, xctx->text[n].flip, xctx->text[n].hcenter, xctx->text[n].vcenter,
xctx->text[n].x0, xctx->text[n].y0,
xctx->text[n].xscale, xctx->text[n].yscale);
#ifndef HAS_CAIRO
drawrect(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0);
drawline(textlayer, END, 0.0, 0.0, 0.0, 0.0, 0);
#endif
2020-08-08 15:47:34 +02:00
#ifdef HAS_CAIRO
if( (textfont && textfont[0]) || xctx->text[n].flags) {
cairo_restore(cairo_ctx);
cairo_restore(xctx->cairo_save_ctx);
2020-08-08 15:47:34 +02:00
}
#endif
break;
2020-08-08 15:47:34 +02:00
case ELEMENT:
if(k==0) {
if(firsti) {
2020-12-02 15:10:47 +01:00
xctx->prep_hash_inst=0;
firsti = 0;
}
2020-08-08 15:47:34 +02:00
if(rotatelocal) {
ROTATION(move_rot, move_flip, inst[n].x0, inst[n].y0, inst[n].x0, inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
} else {
ROTATION(move_rot, move_flip, x1, y_1, inst[n].x0, inst[n].y0, rx1,ry1);
2020-08-08 15:47:34 +02:00
}
inst[n].x0 = rx1+deltax;
inst[n].y0 = ry1+deltay;
inst[n].rot = (inst[n].rot +
( (move_flip && (inst[n].rot & 1) ) ? move_rot+2 : move_rot) ) & 0x3;
inst[n].flip = move_flip ^ inst[n].flip;
2020-08-08 15:47:34 +02:00
}
break;
2020-12-02 15:10:47 +01:00
} /* end switch(xctx->sel_array[i].type) */
} /* end for(i=0;i<xctx->lastsel;i++) */
if(k == 0 ) {
/* force these vars to 0 to trigger a prepare_netlist_structs(0) needed by symbol_bbox->translate
* to translate @#n:net_name texts */
if(!firsti || !firstw) {
2020-12-02 15:10:47 +01:00
xctx->prep_net_structs=0;
xctx->prep_hi_structs=0;
}
if(show_pin_net_names) {
prepare_netlist_structs(0);
}
}
2020-12-02 15:10:47 +01:00
for(i = 0; i < xctx->lastsel; i++) {
n = xctx->sel_array[i].n;
if(k == 0) {
2020-12-02 15:10:47 +01:00
if(xctx->sel_array[i].type == ELEMENT) {
int p;
symbol_bbox(n, &inst[n].x1, &inst[n].y1, &inst[n].x2, &inst[n].y2 );
bbox(ADD, inst[n].x1, inst[n].y1, inst[n].x2, inst[n].y2 );
if(show_pin_net_names) for(p = 0; p < (inst[n].ptr + xctx->sym)->rects[PINLAYER]; p++) {
if( inst[n].node && inst[n].node[p]) {
find_inst_to_be_redrawn(inst[n].node[p]);
}
}
}
2020-12-02 15:10:47 +01:00
if(show_pin_net_names && xctx->sel_array[i].type == WIRE) {
find_inst_to_be_redrawn(wire[n].node);
}
}
/* draw_symbol(ADD,k, n,k, 0, 0, 0.0, 0.0); */
2020-08-08 15:47:34 +02:00
}
if(show_pin_net_names) find_inst_hash_clear();
2020-08-08 15:47:34 +02:00
filledrect(k, END, 0.0, 0.0, 0.0, 0.0);
2020-09-02 23:59:58 +02:00
drawarc(k, END, 0.0, 0.0, 0.0, 0.0, 0.0, 0, 0);
drawrect(k, END, 0.0, 0.0, 0.0, 0.0, 0);
drawline(k, END, 0.0, 0.0, 0.0, 0.0, 0);
} /*end for(k=0;k<cadlayers;k++) */
2020-08-08 15:47:34 +02:00
check_collapsing_objects();
update_conn_cues(1, 1);
2020-12-02 15:10:47 +01:00
xctx->ui_state &= ~STARTMOVE;
xctx->ui_state &= ~STARTMERGE;
x1=y_1=x2=y_2=move_rot=move_flip=deltax=deltay=0;
bbox(SET , 0.0 , 0.0 , 0.0 , 0.0);
2020-12-02 15:10:47 +01:00
dbg(2, "move_objects(): bbox= %d %d %d %d\n", xctx->areax1, xctx->areay1, xctx->areaw, xctx->areah);
2020-08-08 15:47:34 +02:00
draw();
bbox(END , 0.0 , 0.0 , 0.0 , 0.0);
rotatelocal=0;
draw_window =save_draw;
}
draw_selection(gc[SELLAYER], 0);
}