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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "protos.h"
#include "schframe.h"
/******************************************************************/
void SetStructFather( EDA_BaseStruct* Struct, BASE_SCREEN* Screen )
/******************************************************************/
{
switch( Struct->Type() )
{
case DRAW_POLYLINE_STRUCT_TYPE:
case DRAW_JUNCTION_STRUCT_TYPE:
case DRAW_TEXT_STRUCT_TYPE:
case DRAW_LABEL_STRUCT_TYPE:
case DRAW_GLOBAL_LABEL_STRUCT_TYPE:
case DRAW_HIER_LABEL_STRUCT_TYPE:
case DRAW_LIB_ITEM_STRUCT_TYPE:
case DRAW_SEGMENT_STRUCT_TYPE:
case DRAW_BUSENTRY_STRUCT_TYPE:
case DRAW_SHEET_STRUCT_TYPE:
case DRAW_MARKER_STRUCT_TYPE:
case DRAW_NOCONNECT_STRUCT_TYPE:
Struct->m_Parent = Screen;
break;
case DRAW_SHEETLABEL_STRUCT_TYPE:
case DRAW_PICK_ITEM_STRUCT_TYPE:
break;
default:
break;
}
}
/***************************************************************/
void EDA_BaseStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
/***************************************************************/
/* place the struct in EEDrawList.
* if it is a new item, it it also put in undo list
* for an "old" item, saving it in undo list must be done before editiing, and not here!
*/
{
if( m_Flags & IS_NEW )
{
SCH_SCREEN* screen = (SCH_SCREEN*) frame->GetScreen();
if( !screen->CheckIfOnDrawList( this ) ) //don't want a loop!
screen->AddToDrawList( this );
g_ItemToRepeat = this;
if( frame->m_Ident == SCHEMATIC_FRAME )
( (WinEDA_SchematicFrame*) frame )->SaveCopyInUndoList( this, IS_NEW );
}
m_Flags = 0;
frame->GetScreen()->SetModify();
frame->GetScreen()->SetCurItem( NULL );
frame->DrawPanel->ManageCurseur = NULL;
frame->DrawPanel->ForceCloseManageCurseur = NULL;
if( DC )
{
frame->DrawPanel->CursorOff( DC ); // Erase schematic cursor
RedrawOneStruct( frame->DrawPanel, DC, this, GR_DEFAULT_DRAWMODE );
frame->DrawPanel->CursorOn( DC ); // Display schematic cursor
}
}
/***********************************************************************/
/* Class SCH_SCREEN: classe de gestion d'un affichage pour schematique */
/***********************************************************************/
static int table_zoom[] = { 1, 2, 4, 8, 16, 32, 64, 128, 0 }; /* Valeurs standards du zoom */
/* Constructeur de SCREEN */
SCH_SCREEN::SCH_SCREEN( int screentype, KICAD_T aType ) :
BASE_SCREEN( screentype, aType )
{
EEDrawList = NULL; /* Schematic items list */
m_Zoom = 32;
m_Grid = wxSize( 50, 50 ); /* pas de la grille */
SetZoomList( table_zoom );
SetGridList( g_GridList );
m_UndoRedoCountMax = 10;
m_RefCount = 0;
m_ScreenNumber = 1;
m_NumberOfScreen = 1;
}
/****************************/
SCH_SCREEN::~SCH_SCREEN()
/****************************/
{
ClearUndoRedoList();
FreeDrawList();
}
/***********************************/
void SCH_SCREEN::FreeDrawList()
/***********************************/
/* Routine to clear (free) EESchema drawing list of a screen.
*/
{
EDA_BaseStruct* DrawStruct;
while( EEDrawList != NULL )
{
DrawStruct = EEDrawList;
EEDrawList = EEDrawList->Pnext;
SAFE_DELETE( DrawStruct );
}
EEDrawList = NULL;
}
/**************************************************************/
void SCH_SCREEN::RemoveFromDrawList( EDA_BaseStruct* DrawStruct )
/**************************************************************/
/* If found in EEDrawList, remove DrawStruct from EEDrawList.
* DrawStruct is not deleted or modified
*/
{
if( DrawStruct == EEDrawList )
EEDrawList = EEDrawList->Pnext;
else
{
EDA_BaseStruct* DrawList = EEDrawList;
while( DrawList && DrawList->Pnext )
{
if( DrawList->Pnext == DrawStruct )
{
DrawList->Pnext = DrawList->Pnext->Pnext;
break;
}
DrawList = DrawList->Pnext;
}
}
}
/**************************************************************/
bool SCH_SCREEN::CheckIfOnDrawList( EDA_BaseStruct* st )
/**************************************************************/
{
EDA_BaseStruct* DrawList = EEDrawList;
while( DrawList )
{
if( DrawList == st )
return true;
DrawList = DrawList->Pnext;
}
return false;
}
/**************************************************************/
void SCH_SCREEN::AddToDrawList( EDA_BaseStruct* st )
/**************************************************************/
{ //simple function to add to the head of the drawlist.
st->Pnext = EEDrawList;
EEDrawList = st;
}
/*********************************************************************/
/* Class EDA_ScreenList to handle the list of screens in a hierarchy */
/*********************************************************************/
/*****************************************/
SCH_SCREEN* EDA_ScreenList::GetFirst()
/*****************************************/
{
m_Index = 0;
if( m_List.GetCount() > 0 )
return m_List[0];
return NULL;
}
/*****************************************/
SCH_SCREEN* EDA_ScreenList::GetNext()
/*****************************************/
{
if( m_Index < m_List.GetCount() )
m_Index++;
return GetScreen( m_Index );
}
/************************************************/
SCH_SCREEN* EDA_ScreenList::GetScreen( unsigned int index )
/************************************************/
/* return the m_List[index] item
*/
{
if( index < m_List.GetCount() )
return m_List[index];
return NULL;
}
/************************************************/
void EDA_ScreenList::AddScreenToList( SCH_SCREEN* testscreen )
/************************************************/
{
if( testscreen == NULL )
return;
for( unsigned int i = 0; i< m_List.GetCount(); i++ )
{
if( m_List[i] == testscreen )
return;
}
m_List.Add( testscreen );
#ifdef DEBUG
printf( "EDA_ScreenList::AddScreenToList adding %s\n",
(const char*) testscreen->m_FileName.mb_str(
) );
#endif
}
/************************************************************************/
void EDA_ScreenList::BuildScreenList( EDA_BaseStruct* s )
/************************************************************************/
{
if( s && s->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* ds = (DrawSheetStruct*) s;
s = ds->m_AssociatedScreen;
}
if( s && s->Type() == SCREEN_STRUCT_TYPE )
{
SCH_SCREEN* screen = (SCH_SCREEN*) s;
AddScreenToList( screen );
EDA_BaseStruct* strct = screen->EEDrawList;
while( strct )
{
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{
BuildScreenList( strct );
}
strct = strct->Pnext;
}
}
}
/*********************************************************************/
/* Class EDA_SheetList to handle the list of Sheets in a hierarchy */
/*********************************************************************/
/*****************************************/
DrawSheetPath* EDA_SheetList::GetFirst()
/*****************************************/
{
m_index = 0;
if( m_count > 0 )
return &( m_List[0] );
return NULL;
}
/*****************************************/
DrawSheetPath* EDA_SheetList::GetNext()
/*****************************************/
{
if( m_index < m_count )
m_index++;
return GetSheet( m_index );
}
/************************************************/
DrawSheetPath* EDA_SheetList::GetSheet( int index )
/************************************************/
/* return the m_List[index] item
*/
{
if( index < m_count )
return &(m_List[index]);
return NULL;
}
/************************************************************************/
void EDA_SheetList::BuildSheetList( DrawSheetStruct* sheet )
/************************************************************************/
{
if( m_List == NULL )
{
int count = sheet->CountSheets();
m_count = count;
m_index = 0;
if( m_List )
free( m_List );m_List = NULL;
count *= sizeof(DrawSheetPath);
m_List = (DrawSheetPath*) MyZMalloc( count );
memset( (void*) m_List, 0, count );
m_currList.Clear();
}
m_currList.Push( sheet );
m_List[m_index] = m_currList;
m_index++;
if( sheet->m_AssociatedScreen != NULL )
{
EDA_BaseStruct* strct = m_currList.LastDrawList();
while( strct )
{
if( strct->Type() == DRAW_SHEET_STRUCT_TYPE )
{
DrawSheetStruct* sht = (DrawSheetStruct*) strct;
BuildSheetList( sht );
}
strct = strct->Pnext;
}
}
m_currList.Pop();
}