1 /*!
2  * \file src/flags.h
3  *
4  * \brief Some commonly used macros not related to a special C-file.
5  *
6  * The file is included by global.h after const.h
7  *
8  * <hr>
9  *
10  * <h1><b>Copyright.</b></h1>\n
11  *
12  * PCB, interactive printed circuit board design
13  *
14  * Copyright (C) 1994,1995,1996 Thomas Nau
15  *
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 2 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, write to the Free Software Foundation, Inc.,
28  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29  *
30  * Contact addresses for paper mail and Email:
31  * Thomas Nau, Schlehenweg 15, 88471 Baustetten, Germany
32  * Thomas.Nau@rz.uni-ulm.de
33  */
34 
35 #ifndef	PCB_FLAGS_H
36 #define	PCB_FLAGS_H
37 
38 #include <stdbool.h>
39 #include "globalconst.h"
40 /*!
41  * \brief Nobody should know about the internals of this except the
42  * macros below that access it.
43  *
44  * This structure must be simple-assignable for now.
45  */
46 typedef struct
47 {
48   unsigned long f;		/* generic flags */
49   unsigned char t[(MAX_LAYER + 1) / 2];  /* thermals */
50 } FlagType;
51 
52 int pcb_flag_eq (FlagType *f1, FlagType *f2);
53 
54 
55 /* ---------------------------------------------------------------------------
56  * some routines for flag setting, clearing, changing and testing
57  */
58 #define	SET_FLAG(F,P)		((P)->Flags.f |= (F))
59 #define	CLEAR_FLAG(F,P)		((P)->Flags.f &= (~(F)))
60 #define	TEST_FLAG(F,P)		((P)->Flags.f & (F) ? 1 : 0)
61 #define	TOGGLE_FLAG(F,P)	((P)->Flags.f ^= (F))
62 #define	ASSIGN_FLAG(F,V,P)	((P)->Flags.f = ((P)->Flags.f & (~(F))) | ((V) ? (F) : 0))
63 #define TEST_FLAGS(F,P)         (((P)->Flags.f & (F)) == (F) ? 1 : 0)
64 
65 #define FLAGS_EQUAL(F1,F2)	pcb_flag_eq(&(F1), &(F2))
66 
67 #define THERMFLAG(L)		(0xf << (4 *((L) % 2)))
68 
69 #define TEST_THERM(L,P)		((P)->Flags.t[(L)/2] & THERMFLAG(L) ? 1 : 0)
70 #define GET_THERM(L,P)		(((P)->Flags.t[(L)/2] >> (4 * ((L) % 2))) & 0xf)
71 #define CLEAR_THERM(L,P)	(P)->Flags.t[(L)/2] &= ~THERMFLAG(L)
72 #define ASSIGN_THERM(L,V,P)	(P)->Flags.t[(L)/2] = ((P)->Flags.t[(L)/2] & ~THERMFLAG(L)) | ((V)  << (4 * ((L) % 2)))
73 
74 //defined in misc.c
75 extern int mem_any_set (unsigned char *, int);
76 #define TEST_ANY_THERMS(P)	mem_any_set((P)->Flags.t, sizeof((P)->Flags.t))
77 
78 /* For passing modified flags to other functions. */
79 FlagType MakeFlags (unsigned int);
80 FlagType OldFlags (unsigned int);
81 FlagType AddFlags (FlagType, unsigned int);
82 FlagType MaskFlags (FlagType, unsigned int);
83 #define    NoFlags() MakeFlags(0)
84 
85 bool ClearFlagOnLinesAndPolygons (int flag, bool undoable);
86 bool ClearFlagOnPinsViasAndPads (int flag, bool undoable);
87 bool ClearFlagOnAllObjects (int flag, bool undoable);
88 
89 #endif  // ifndef PCB_FLAGS_H
90