1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
|
/*
* COPYRIGHT
*
* pcb-rnd, interactive printed circuit board design
* Copyright (C) 1994,1995,1996 Thomas Nau
* Copyright (C) 1997, 1998, 1999, 2000, 2001 Harry Eaton
* Copyright (C) 2017,2019,2020 Tibor 'Igor2' Palinkas
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Contact:
* Project page: http://repo.hu/projects/pcb-rnd
* lead developer: http://repo.hu/projects/pcb-rnd/contact.html
* mailing list: pcb-rnd (at) list.repo.hu (send "subscribe")
*
*
* Old contact info:
* Harry Eaton, 6697 Buttonhole Ct, Columbia, MD 21044, USA
* haceaton@aplcomm.jhuapl.edu
*
*/
#include "config.h"
#include "conf_core.h"
#include "board.h"
#include "crosshair.h"
#include "data.h"
#include "draw.h"
#include "tool_logic.h"
#include <librnd/hid/tool.h>
#include "undo.h"
#include "obj_poly_draw.h"
void pcb_tool_rectangle_uninit(void)
{
rnd_hid_notify_crosshair_change(&PCB->hidlib, rnd_false);
pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST;
rnd_hid_notify_crosshair_change(&PCB->hidlib, rnd_true);
}
void pcb_tool_rectangle_notify_mode(rnd_design_t *hl)
{
pcb_board_t *pcb = (pcb_board_t *)hl;
/* do update of position */
pcb_tool_notify_block();
/* create rectangle if both corners are determined
* and width, height are != 0
*/
if (pcb_crosshair.AttachedBox.State == PCB_CH_STATE_THIRD &&
pcb_crosshair.AttachedBox.Point1.X != pcb_crosshair.AttachedBox.Point2.X &&
pcb_crosshair.AttachedBox.Point1.Y != pcb_crosshair.AttachedBox.Point2.Y) {
pcb_poly_t *polygon;
pcb_layer_t *layer = pcb_loose_subc_layer(pcb, PCB_CURRLAYER(pcb), rnd_true);
int flags = PCB_FLAG_CLEARPOLY;
if (conf_core.editor.full_poly)
flags |= PCB_FLAG_FULLPOLY;
if (conf_core.editor.clear_polypoly)
flags |= PCB_FLAG_CLEARPOLYPOLY;
if ((polygon = pcb_poly_new_from_rectangle(layer,
pcb_crosshair.AttachedBox.Point1.X,
pcb_crosshair.AttachedBox.Point1.Y,
pcb_crosshair.AttachedBox.Point2.X,
pcb_crosshair.AttachedBox.Point2.Y,
2 * conf_core.design.clearance,
pcb_flag_make(flags))) != NULL) {
pcb_obj_add_attribs((pcb_any_obj_t *)polygon, pcb->pen_attr, NULL);
pcb_undo_add_obj_to_create(PCB_OBJ_POLY, layer, polygon, polygon);
pcb_undo_inc_serial();
pcb_poly_invalidate_draw(layer, polygon);
pcb_draw();
}
/* reset state to 'first corner' */
pcb_crosshair.AttachedBox.State = PCB_CH_STATE_FIRST;
pcb_subc_as_board_update(PCB);
}
}
void pcb_tool_rectangle_adjust_attached_objects(rnd_design_t *hl)
{
switch (pcb_crosshair.AttachedBox.State) {
case PCB_CH_STATE_SECOND: /* one corner is selected */
{
/* update coordinates */
pcb_crosshair.AttachedBox.Point2.X = pcb_crosshair.X;
pcb_crosshair.AttachedBox.Point2.Y = pcb_crosshair.Y;
break;
}
}
}
rnd_bool pcb_tool_rectangle_anydo_act(rnd_design_t *hl)
{
/* don't allow undo in the middle of an operation */
if (pcb_crosshair.AttachedBox.State != PCB_CH_STATE_FIRST)
return rnd_false;
return rnd_true;
}
void pcb_tool_rectangle_escape(rnd_design_t *hl)
{
if (pcb_crosshair.AttachedBox.State == PCB_CH_STATE_FIRST)
rnd_tool_select_by_name(hl, "arrow");
else
rnd_tool_select_by_name(hl, "rectangle");
}
/* XPM */
static const char *rect_icon[] = {
/* columns rows colors chars-per-pixel */
"21 21 3 1",
" c black",
". c #6EA5D7",
"o c None",
/* pixels */
"ooooooooooooooooooooo",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"oo..................o",
"ooooooooooooooooooooo",
"ooooooooooooooooooooo",
"o oo oo oo ",
"o oo o oooo oo ooo oo",
"o oo o oooo oooooo oo",
"o oo oooo oooooo oo",
"o o oo oo oooooo oo",
"o oo o oooo oooooo oo",
"o oo o oooo oo ooo oo",
"o oo o oo oooo oo",
"ooooooooooooooooooooo"
};
rnd_tool_t pcb_tool_rectangle = {
"rectangle", NULL, NULL, 100, rect_icon, RND_TOOL_CURSOR_NAMED("ul_angle"), 0,
NULL,
pcb_tool_rectangle_uninit,
pcb_tool_rectangle_notify_mode,
NULL,
pcb_tool_rectangle_adjust_attached_objects,
NULL,
pcb_tool_rectangle_anydo_act,
pcb_tool_rectangle_anydo_act,
pcb_tool_rectangle_escape,
0
};
|