1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __editstate_h
19 #define __editstate_h
20 
21 /*
22  * A GSearchContext is used to control a string search operation.
23  */
24 typedef struct {
25   int		mode;		/* Search mode */
26 
27   char		*target;	/* Target string */
28 
29   HashElem	*m_elem;	/* Current position in table of modules */
30   HashElem	*g_elem;	/* Current position in table of gates */
31   HashElem	*n_elem;	/* Current position in table of nets */
32 } GSearchContext;
33 
34 /*****************************************************************************
35  *
36  * A GCutBuffer is used to implement the cut/paste buffer.  It holds anything
37  * that has been put here through the cut/copy commands, and can be pasted
38  * using the paste command.  The selected item can be either a group of gates
39  * and wires, or it can be a block of text if cut/copied from the HDL editor.
40  * When the cut buffer contains gates/wires, and a paste is done to an HDL
41  * module, the items are converted to text.  When the cut buffer contains
42  * text and the paste is done to a netlist module, the text is converted
43  * to a comment object.
44  *
45  *****************************************************************************/
46 typedef struct {
47   int		cb_minx,cb_maxx;	/* Minimum and maximum x value for cut objects */
48   int		cb_miny,cb_maxy;	/* Minimum and maximum y value for cut objects */
49   int		cb_ctrx,cb_ctry;	/* Center point of selected region */
50 
51   GModuleDef    *cb_lastTarget;		/* Target of the last yank operation */
52   int		cb_dx,cb_dy;		/* Offset for yank operations */
53   GModuleDef	*cb_buf;		/* Gates/nets represented as a module */
54 } GCutBuffer;
55 
56 /*****************************************************************************
57  *
58  * A GSelection is used to keep track of the set of gates and wires that are
59  * currently selected.
60  *
61  *****************************************************************************/
62 typedef struct {
63   SHash		*s_gates;	/* Gates in the selection */
64   SHash		*s_wires;	/* Wires between gates in s_gates */
65   SHash		*s_edgeWires;	/* Wires with one end in s_gates */
66   int		s_hasAnchored;	/* Selection has anchored gates */
67 } GSelection;
68 
69 /*****************************************************************************
70  *
71  * An editstate is the context in which a module is edited.
72  *
73  *****************************************************************************/
74 struct EditState_str {
75   GModuleDef	*env;			/* Module edited in this block */
76   GCElement	*inst;			/* Module instance (if opened from instance) */
77   GSimModule	*smod;			/* Corresponding simulation module */
78 
79   int save_x,save_y;			/* Saved origin position */
80 
81   unsigned isInterface : 1;		/* Set if this is the module interface context */
82 
83   /*
84    * The clip region is used when updating a portion of the screen such as
85    * when scrolling.
86    */
87   struct {
88     int isActive;			/* Set if clipping is active */
89     int xmin,ymin;			/* The minimum and maximum */
90     int xmax,ymax;			/* coordinates of the clip region */
91   } clip;
92 
93   EditState *parent;			/* The parent edit state */
94 };
95 
96 EditState *new_EditState();
97 void delete_EditState(EditState*);
98 
99 void editstate_saveOrig(EditState *es);
100 void editstate_fullUpdate(EditState *es);
101 void editstate_regionUpdate(EditState *es,int xmin,int ymin,int xmax,int ymax);
102 void editstate_setCurrent(EditState *es);
103 int editstate_setPath(EditState **es,const char *path);
104 int editstate_checkPath(EditState **es,const char *path);
105 void editstate_flushModules(EditState **es);
106 void editstate_Init(EditState *es);
107 void editstate_update(EditState *es);
108 void editstate_push(EditState **es,GModuleDef *M,GCElement *g);
109 void editstate_pop(EditState **es);
110 void editstate_navigateToModule(EditState **es,GModuleDef *M);
111 char *editstate_getPath(EditState *es,char *buf);
112 void editstate_makeRootAtTop(EditState **es);
113 int editstate_isInterfaceMode();
114 int editstate_getInterfaceMode();
115 EditState *EditState_moveToError(int n,EditState *es);
116 
117 EditState *outoferrorblocks(EditState *es,EditState *o);
118 
119 void EditState_unselectAll(EditState*);
120 void EditState_selectGate(EditState *es,int tx,int ty);
121 void EditState_unselectGate(EditState *es);
122 
123 void sel_rotate(EditState*,int);
124 void sel_clear(EditState *es,int doDraw);
125 void sel_move(EditState*,int,int);
126 void sel_draw(EditState*);
127 void sel_dropFixup(EditState*);
128 void sel_delete(EditState*);
129 void sel_copy(EditState*);
130 void sel_copyAppend(EditState*);
131 void sel_kill(EditState*);
132 void sel_killAppend(EditState*);
133 void sel_hdlyank(EditState*);
134 void sel_yank(EditState*);
135 int sel_select(EditState*);
136 int sel_selectAll(EditState *es);
137 int sel_isSelGate(GCElement *g);
138 void sel_appendGate(EditState*,GCElement*,int);
139 void sel_unselectGate(EditState*,GCElement*);
140 int sel_num(EditState*);
141 void sel_updateMenuState();
142 int sel_refinish(EditState *es);
143 int sel_finish(EditState *es);
144 void sel_anchor(EditState *es,int);
145 void sel_setTech(EditState *es,const char*);
146 void sel_alignHorz(EditState *es);
147 void sel_alignVert(EditState *es);
148 void sel_clearDelta();
149 int sel_writeToFile(const char*);
150 void sel_interfaceReset(EditState *es);
151 
152 void EditState_selectobject(EditState *es);
153 void EditState_dropobject(EditState *es);
154 void EditState_moveobject(EditState *es);
155 
156 void setEditMode(EditState *es,int mode);
157 int modifyOK(EditState *es,unsigned flags);
158 
159 GSearchContext *new_GSearchContext();
160 void GSearchContext_clear(GSearchContext*);
161 void GSearchContext_find(GSearchContext *sc,const char *target,int mode,int qual);
162 void GSearchContext_list(GSearchContext *sc,const char *target,int mode,int qual,const char *result);
163 void GSearchContext_setPosition(GModuleDef *M,GCElement *g,GNet *n);
164 void GSearchContext_goto(const char *spec);
165 
166 GModuleDef *env_findModule(const char *n);
167 GModuleDef *env_findAdd(const char *name,int isMain);
168 int env_rename(const char *old,const char *newName);
169 GModuleDef *env_defineModule(const char *name,int);
170 int env_delete(EditState*,const char*);
171 GModuleDef *env_removeModule(const char *name,int force);
172 void env_insertModule(GModuleDef *);
173 void env_copy(EditState *es,const char *src,const char *dst);
174 void env_updateMTCircuit();
175 GCElement *env_getInterface(GCElement *g);
176 void env_clear(GModuleDef *e);
177 void env_checkname(GCElement *g);
178 void env_markenv(GModuleDef *env);
179 
180 #endif
181 
182