~jeru-sheng/kicad/kicad-feature

« back to all changes in this revision

Viewing changes to common/base_struct.cpp

  • Committer: plyatov
  • Date: 2007-05-06 16:03:28 UTC
  • Revision ID: svn-v4:16bec504-3128-0410-b3e8-8e38c2123bca:trunk/kicad:13
Initial import of KiCad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
        /********************************************************/
 
2
        /* methodes pour les structures de base:                                */
 
3
        /*              EDA_BaseStruct (classe non utilisable seule)    */
 
4
        /*              EDA_TextStruct (classe non utilisable seule)    */
 
5
        /********************************************************/
 
6
 
 
7
                /* Fichier base_struct.cpp */
 
8
 
 
9
#include "fctsys.h"
 
10
#include "gr_basic.h"
 
11
#include "trigo.h"
 
12
#include "common.h"
 
13
#include "wxstruct.h"
 
14
#include "base_struct.h"
 
15
#include "grfonte.h"
 
16
 
 
17
#include "macros.h"
 
18
 
 
19
 
 
20
// DrawStructureType names for error messages only:
 
21
static wxString DrawStructureTypeName[MAX_STRUCT_TYPE_ID+1]
 
22
 = {
 
23
wxT("Not init"),
 
24
 
 
25
wxT("Pcb"),
 
26
wxT("Equipot"),
 
27
wxT("Module"),
 
28
wxT("Pad"),
 
29
wxT("DrawSegment"),
 
30
wxT("Text (pcb)"),
 
31
wxT("Text module"),
 
32
wxT("edge module"),
 
33
wxT("track"),
 
34
wxT("zone"),
 
35
wxT("via"),
 
36
wxT("marker"),
 
37
wxT("cotation"),
 
38
wxT("mire"),
 
39
wxT("screen"),
 
40
wxT("block"),
 
41
wxT("edge zone"),
 
42
 
 
43
wxT("Polyline"),
 
44
wxT("Junction"),
 
45
wxT("Text"),
 
46
wxT("Label"),
 
47
wxT("Glob label"),
 
48
wxT("Lib item"),
 
49
wxT("Pick struct"),
 
50
wxT("Segment"),
 
51
wxT("Raccord"),
 
52
wxT("Sheet"),
 
53
wxT("Sheet label"),
 
54
wxT("Marker"),
 
55
wxT("No connect"),
 
56
wxT("Text (lib item)"),
 
57
wxT("Screen"),
 
58
wxT("Block locate"),
 
59
wxT("Library component"),
 
60
wxT("lib cmp draw circle"),
 
61
wxT("lib cmp draw graphic text"),
 
62
wxT("lib cmp draw rect"),
 
63
wxT("lib cmp draw poly line"),
 
64
wxT("lib cmp draw line"),
 
65
wxT("lib cmp pin"),
 
66
wxT("lib cmp field"),
 
67
wxT("unknown"),
 
68
wxT("unknown")
 
69
};
 
70
 
 
71
 
 
72
 
 
73
 
 
74
enum textbox {
 
75
        ID_TEXTBOX_LIST = 8010
 
76
};
 
77
 
 
78
 
 
79
/******************************************************************************/
 
80
EDA_BaseStruct::EDA_BaseStruct(EDA_BaseStruct * parent, int idType)
 
81
/******************************************************************************/
 
82
{
 
83
        InitVars();
 
84
        m_StructType = idType;
 
85
        m_Parent = parent;      /* Chainage hierarchique sur struct racine */
 
86
}
 
87
 
 
88
 
 
89
/********************************************/
 
90
EDA_BaseStruct::EDA_BaseStruct(int idType)
 
91
/********************************************/
 
92
{
 
93
        InitVars();
 
94
        m_StructType = idType;
 
95
}
 
96
 
 
97
/********************************************/
 
98
void EDA_BaseStruct::InitVars(void)
 
99
/********************************************/
 
100
{
 
101
        m_StructType = TYPE_NOT_INIT;
 
102
        Pnext = NULL;           /* Linked list: Link (next struct)  */
 
103
        Pback = NULL;           /* Linked list: Link (previous struct) */
 
104
        m_Parent = NULL;        /* Linked list: Link (parent struct) */
 
105
        m_Son = NULL;           /* Linked list: Link (son struct) */
 
106
        m_Image = NULL;         /* Link to an image copy for undelete or abort command */
 
107
        m_Flags = 0;            /* flags for editions and other */
 
108
        m_TimeStamp = 0;        // Time stamp used for logical links
 
109
        m_Status = 0;
 
110
        m_Selected = 0;         /* Used by block commands, and selective editing */
 
111
}
 
112
 
 
113
 
 
114
/* Gestion de l'etat (status) de la structure (active, deleted..) */
 
115
int EDA_BaseStruct::GetState(int type)
 
116
{
 
117
        return(m_Status & type);
 
118
}
 
119
 
 
120
void EDA_BaseStruct::SetState(int type, int state )
 
121
{
 
122
        if( state ) m_Status |= type;   /* state = ON ou OFF */
 
123
        else m_Status &= ~type;
 
124
}
 
125
 
 
126
 
 
127
/*********************************************************/
 
128
void EDA_BaseStruct::AddToChain(EDA_BaseStruct * laststruct)
 
129
/*********************************************************/
 
130
/*
 
131
addition d'une nouvelle struct a la liste chain�e, apres la structure laststruct
 
132
*/
 
133
{
 
134
        Pnext = laststruct->Pnext;
 
135
        Pback = laststruct;
 
136
        laststruct->Pnext = this;
 
137
}
 
138
 
 
139
 
 
140
/**************************************************************************************/
 
141
void EDA_BaseStruct::Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset,
 
142
        int draw_mode, int Color)
 
143
/**************************************************************************************/
 
144
/* Virtual
 
145
*/
 
146
{
 
147
        wxString msg, name;
 
148
        msg.Printf( wxT("EDA_BaseStruct::Draw() error. Method for struct type %d used but not implemented ("),
 
149
                m_StructType);
 
150
        msg += ReturnClassName() + wxT(")\n");
 
151
        printf ( CONV_TO_UTF8(msg));
 
152
}
 
153
 
 
154
#if 0
 
155
/**************************************************************/
 
156
void EDA_BaseStruct::Place(WinEDA_DrawFrame * frame, wxDC * DC)
 
157
/**************************************************************/
 
158
/* fonction virtuelle de placement: non utilisee en pcbnew (utilisee eeschema)
 
159
---- A mieux utiliser (TODO...)
 
160
*/
 
161
{
 
162
}
 
163
#endif
 
164
 
 
165
/*********************************************/
 
166
wxString EDA_BaseStruct::ReturnClassName(void)
 
167
/*********************************************/
 
168
/* Used at run time for diags: return the class name of the item,
 
169
        from its .m_StructType value.
 
170
*/
 
171
{
 
172
int ii = m_StructType;
 
173
wxString classname;
 
174
 
 
175
        if ( (ii < 0) || (ii > MAX_STRUCT_TYPE_ID) ) ii = MAX_STRUCT_TYPE_ID;
 
176
        classname = DrawStructureTypeName[ii];
 
177
 
 
178
        return classname;
 
179
}
 
180
 
 
181
 
 
182
 
 
183
/**********************************************************************************************/
 
184
EDA_BaseLineStruct::EDA_BaseLineStruct(EDA_BaseStruct * StructFather, DrawStructureType idtype):
 
185
                                EDA_BaseStruct(StructFather, idtype)
 
186
/**********************************************************************************************/
 
187
{
 
188
        m_Layer = 0;
 
189
        m_Width = 0;                // 0 = line, > 0 = tracks, bus ...
 
190
};
 
191
 
 
192
 
 
193
/*********************************************************/
 
194
/* EDA_TextStruct (classe de base, non utilis�e seule */
 
195
/*********************************************************/
 
196
EDA_TextStruct::EDA_TextStruct(const wxString & text)
 
197
{
 
198
        m_Layer = 0;
 
199
        m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT;        /* XY size of font */
 
200
        m_Orient = 0;                               /* Orient in 0.1 degrees */
 
201
        m_Attributs = 0;
 
202
        m_Miroir = 0;                                                           // vue normale / miroir
 
203
        m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
 
204
        m_VJustify = GR_TEXT_VJUSTIFY_CENTER;   /* Justifications Horiz et Vert du texte */
 
205
        m_Width = 0;                                                    /* epaisseur du trait */
 
206
        m_CharType = 0;                                                 /* normal, bold, italic ... */
 
207
        m_Text = text;
 
208
        m_ZoomLevelDrawable = 0;                                /* Niveau de zoom acceptable pour affichage normal */
 
209
        m_TextDrawings = NULL;                                  /* Pointeur sur le dessin du caractere */
 
210
        m_TextDrawingsSize = 0;                 /* taille du tableau point� */
 
211
}
 
212
 
 
213
 
 
214
EDA_TextStruct::~EDA_TextStruct(void)
 
215
{
 
216
        if( m_TextDrawings )    /* pointeur sur la liste des segments de dessin */
 
217
                {
 
218
                free(m_TextDrawings); m_TextDrawings = NULL;
 
219
                }
 
220
        m_TextDrawingsSize = 0;                 /* nombre de sommets a dessiner */
 
221
}
 
222
 
 
223
/********************************/
 
224
int EDA_TextStruct::Len_Size(void)
 
225
/********************************/
 
226
// Return the text lenght in internal units
 
227
{
 
228
int nbchar = m_Text.Len();
 
229
int len;
 
230
        if ( nbchar == 0 ) return 0;
 
231
 
 
232
        len = ((10 * m_Size.x ) / 9) * nbchar;
 
233
        return len;
 
234
}
 
235
 
 
236
 
 
237
/*************************************************/
 
238
int EDA_TextStruct::Locate(const wxPoint & posref)
 
239
/*************************************************/
 
240
/* locate function
 
241
        return:
 
242
                1 if posref is inside the text area.
 
243
                0 else.
 
244
*/
 
245
{
 
246
int dx, dy;
 
247
int spot_cX, spot_cY;
 
248
 
 
249
        dx = (Pitch() * GetLength()) / 2;
 
250
        dy = m_Size.y /2 ;
 
251
 
 
252
        /* Is the ref point inside the text area ?  */
 
253
        spot_cX = posref.x - m_Pos.x ; spot_cY = posref.y - m_Pos.y ;
 
254
        RotatePoint(&spot_cX, &spot_cY, - m_Orient);
 
255
        if( (abs(spot_cX) <= abs(dx) ) && ( abs(spot_cY) <= abs(dy) ) ) return 1;
 
256
        return 0;
 
257
}
 
258
 
 
259
/*******************************/
 
260
int EDA_TextStruct::Pitch(void)
 
261
/*******************************/
 
262
/* retourne le pas entre 2 caracteres
 
263
*/
 
264
{
 
265
        return ((10 * m_Size.x ) / 9) + m_Width;
 
266
}
 
267
 
 
268
/***************************************************************/
 
269
void EDA_TextStruct::Draw(WinEDA_DrawPanel * panel, wxDC * DC,
 
270
                                const wxPoint & offset, int color, int draw_mode,
 
271
                                int display_mode, int anchor_color)
 
272
/***************************************************************/
 
273
/*
 
274
 Trace de 1 texte type EDA_TextStruct.
 
275
        offset = Offset de trace (usuellement (0,0)
 
276
        color = couleur du texte
 
277
        draw_mode = GR_OR, GR_XOR.., -1 si mode courant.
 
278
        display_mose = FILAIRE, FILLED ou SKETCH
 
279
    anchor_color = couleur de l'ancre ( -1 si pas d'ancre ).
 
280
*/
 
281
{
 
282
int zoom;
 
283
int coord[104];
 
284
int ii, jj, kk, ll, nbpoints;
 
285
int width;
 
286
 
 
287
        if( m_TextDrawings == NULL)     /* pointeur sur la liste des segments de dessin */
 
288
                CreateDrawData();
 
289
        if( m_TextDrawings == NULL)     return;
 
290
 
 
291
        zoom = panel->GetZoom();
 
292
        width = m_Width / zoom;
 
293
        if ( display_mode == FILAIRE ) width = 0;
 
294
        /* choix de la couleur du texte : */
 
295
        if ( draw_mode != -1 ) GRSetDrawMode(DC, draw_mode);
 
296
 
 
297
        /* trace du texte */
 
298
        if ( zoom > m_ZoomLevelDrawable)
 
299
                {
 
300
                GRLine(&panel->m_ClipBox, DC,
 
301
                        m_TextDrawings[1] + offset.x + m_Pos.x,
 
302
                        m_TextDrawings[2] + offset.y + m_Pos.y,
 
303
                        m_TextDrawings[3] + offset.x + m_Pos.x,
 
304
                        m_TextDrawings[4] + offset.y + m_Pos.y,
 
305
                        color);
 
306
                }
 
307
 
 
308
        else
 
309
                {
 
310
                /* trace ancre du texte ? */
 
311
                if( anchor_color != -1)
 
312
                        {
 
313
                        int anchor_size = 2 * zoom;
 
314
                        anchor_color &= MASKCOLOR;
 
315
                        /* calcul de la position du texte */
 
316
                        int cX = m_Pos.x - offset.x;
 
317
                        int cY = m_Pos.y - offset.y;
 
318
                        /* trace ancre du texte */
 
319
                        GRLine(&panel->m_ClipBox, DC, cX - anchor_size, cY,
 
320
                                cX + anchor_size, cY, anchor_color);
 
321
                        GRLine(&panel->m_ClipBox, DC, cX, cY - anchor_size ,
 
322
                                cX, cY + anchor_size , anchor_color);
 
323
                        }
 
324
                jj = 5; ii = jj+1;
 
325
                while (ii < m_TextDrawingsSize)
 
326
                        {
 
327
                        nbpoints = m_TextDrawings[jj];
 
328
                        if (nbpoints > 50 ) nbpoints = 50;
 
329
                        for ( kk = 0, ll = 0; (kk < nbpoints) && (ii < m_TextDrawingsSize) ; kk++)
 
330
                                {
 
331
                                coord[ll] = m_TextDrawings[ii] + offset.x + m_Pos.x;
 
332
                                ll++; ii++;
 
333
                                coord[ll] = m_TextDrawings[ii] + offset.y + m_Pos.y;
 
334
                                ll++; ii++;
 
335
                                }
 
336
                        jj = ii; ii++;
 
337
 
 
338
                        if( width > 2)
 
339
                                {
 
340
                                for ( kk = 0, ll = 0; kk < (nbpoints-1); kk ++, ll+= 2 )
 
341
                                        {
 
342
                                        if( display_mode == SKETCH)
 
343
                                                GRCSegm(&panel->m_ClipBox, DC,
 
344
                                                coord[ll],coord[ll+1],
 
345
                                                coord[ll+2],coord[ll+3],
 
346
                                                m_Width, color) ;
 
347
 
 
348
                                        else GRFillCSegm(&panel->m_ClipBox, DC,
 
349
                                                coord[ll],coord[ll+1],
 
350
                                                coord[ll+2],coord[ll+3],
 
351
                                                m_Width, color) ;
 
352
                                        }
 
353
                                }
 
354
                        else
 
355
                                GRPoly(&panel->m_ClipBox, DC, nbpoints, coord, 0, color, color);
 
356
 
 
357
                        }
 
358
                 }
 
359
}
 
360
 
 
361
/****************************************/
 
362
void EDA_TextStruct::CreateDrawData(void)
 
363
/****************************************/
 
364
/* Cree le tableau de donn�es n�cessaire au trace d'un texte (pcb, module..)
 
365
        Met a jour:
 
366
        m_ZoomLevelDrawable     Niveau de zoom acceptable pour affichage normal
 
367
        m_TextDrawings                  Pointeur sur le tableau de donn�es
 
368
        m_TextDrawingsSize      taille (en int) du tableau
 
369
 Codage dans le tableau:
 
370
        Suite des coord des sommets des polygones a tracer pr�c�d� du nombre de sommets
 
371
        nn xx1 yy1 xx2 yy2 .. xxn yyn mm  xx1 yy1 xx2 yy2 .. xxm yym
 
372
        les 2 premiers sommets sont le segment symbolisant le texte pour les
 
373
        affichages a trop petite echelle
 
374
*/
 
375
{
 
376
int ii, jj, kk,nbchar, nbpoints, AsciiCode, endcar;
 
377
int k1 , k2 , x0 , y0 ;
 
378
int size_h , size_v , espacement ;
 
379
char f_cod , plume = 'U';
 
380
const wxChar * ptr;
 
381
const SH_CODE * ptcar;
 
382
int ux0, uy0, dx, dy;   // Coord de trace des segments de texte & variables de calcul */
 
383
int cX, cY;                             // Centre du texte
 
384
int ox, oy;                             // coord de trace du caractere courant
 
385
int * coord;                    // liste des coord des segments a tracer
 
386
int coord_count_max = 1000;
 
387
 
 
388
        if( m_TextDrawings )    /* pointeur sur la liste des segments de dessin */
 
389
        {
 
390
                free(m_TextDrawings); m_TextDrawings = 0;
 
391
        }
 
392
        m_TextDrawingsSize = 0;                 /* nombre de segments a dessiner */
 
393
 
 
394
        nbchar = m_Text.Length();
 
395
        if ( nbchar == 0 ) return;
 
396
 
 
397
        size_h = m_Size.x;
 
398
        size_v = m_Size.y;
 
399
        espacement = Pitch();
 
400
        if ( m_Miroir == 0 )
 
401
                {
 
402
                size_h = -size_h; espacement = - espacement;
 
403
                }
 
404
 
 
405
        kk = 0; ptr = m_Text.GetData() ; /* ptr pointe 1er caractere du texte */
 
406
 
 
407
        /* calcul de la position du debut des textes: ox et oy */
 
408
        ox = cX = 0; oy = cY = 0;
 
409
 
 
410
        /* Calcul du cadrage du texte */
 
411
        dx = (espacement * nbchar) / 2;
 
412
        dy = size_v / 2;        /* Decalage du debut du texte / centre */
 
413
 
 
414
        ux0 = uy0 = 0;  /* Decalage du centre du texte / ccord de ref */
 
415
 
 
416
        if( (m_Orient == 0) || (m_Orient == 1800) ) /* Texte Horizontal */
 
417
                {
 
418
                switch(m_HJustify)
 
419
                        {
 
420
                        case GR_TEXT_HJUSTIFY_CENTER:
 
421
                                break;
 
422
 
 
423
                        case GR_TEXT_HJUSTIFY_RIGHT:
 
424
                                ux0 = - dx;
 
425
                                break;
 
426
 
 
427
                        case GR_TEXT_HJUSTIFY_LEFT:
 
428
                                ux0 = dx;
 
429
                                break;
 
430
                        }
 
431
 
 
432
                switch(m_VJustify)
 
433
                        {
 
434
                        case GR_TEXT_VJUSTIFY_CENTER:
 
435
                                break;
 
436
 
 
437
                        case GR_TEXT_VJUSTIFY_TOP:
 
438
                                uy0 = dy;
 
439
                                break;
 
440
 
 
441
                        case GR_TEXT_VJUSTIFY_BOTTOM:
 
442
                                uy0 = -dy;
 
443
                                break;
 
444
                        }
 
445
                }
 
446
 
 
447
        else    /* Texte Vertical */
 
448
                {
 
449
                switch(m_HJustify)
 
450
                        {
 
451
                        case GR_TEXT_HJUSTIFY_CENTER:
 
452
                                break;
 
453
 
 
454
                        case GR_TEXT_HJUSTIFY_RIGHT:
 
455
                                ux0 = - dy;
 
456
                                break;
 
457
 
 
458
                        case GR_TEXT_HJUSTIFY_LEFT:
 
459
                                ux0 = dy;
 
460
                                break;
 
461
                        }
 
462
 
 
463
                switch(m_VJustify)
 
464
                        {
 
465
                        case GR_TEXT_VJUSTIFY_CENTER:
 
466
                                break;
 
467
 
 
468
                        case GR_TEXT_VJUSTIFY_TOP:
 
469
                                uy0 = dx;
 
470
                                break;
 
471
 
 
472
                        case GR_TEXT_VJUSTIFY_BOTTOM:
 
473
                                uy0 = -dx;
 
474
                                break;
 
475
                        }
 
476
                }
 
477
        cX += ux0; cY += uy0;
 
478
        ox = cX - dx; ; oy = cY + dy;
 
479
 
 
480
        /* lorsque les chars sont trop petits pour etre dessines,
 
481
        le texte est symbolise par une barre */
 
482
        m_ZoomLevelDrawable = m_Size.x / 3;
 
483
        dx = (espacement * nbchar) / 2;
 
484
        dy = size_v / 2;         /* Decalage du debut du texte / centre */
 
485
        ux0 = cX - dx; uy0 = cY;
 
486
        dx += cX; dy = cY;
 
487
        RotatePoint(&ux0, &uy0, cX, cY, m_Orient);
 
488
        RotatePoint(&dx, &dy, cX, cY, m_Orient);
 
489
                
 
490
        coord = (int*) MyMalloc( (coord_count_max+2) * sizeof(int));
 
491
        coord[0] = 2;
 
492
        coord[1] = ux0; coord[2] = uy0;
 
493
        coord[3] = dx; coord[4] = dy;
 
494
 
 
495
        jj = 5; ii = jj+1; nbpoints = 0;
 
496
        while(kk++ < nbchar)
 
497
                {
 
498
                x0 = 0 ; y0 = 0 ;
 
499
                AsciiCode = (*ptr) & 255;
 
500
                ptcar = graphic_fonte_shape[AsciiCode] ; /* ptcar pointe la description
 
501
                                                du caractere a dessiner */
 
502
 
 
503
                for(endcar = FALSE; ! endcar; ptcar++)
 
504
                        {
 
505
                         f_cod = *ptcar ; /* get code n de la forme selectionnee */
 
506
                         switch(f_cod)
 
507
                                 {
 
508
                                 case 'X' :
 
509
                                        endcar = TRUE;/* fin du caractere */
 
510
                                        break;
 
511
 
 
512
                                 case 'U' :
 
513
                                                if(nbpoints && (plume == 'D' ) )
 
514
                                                        {
 
515
                                                        if ( jj >= coord_count_max )
 
516
                                                        {
 
517
                                                                coord_count_max *= 2;
 
518
                                                                coord = (int*)realloc( coord, coord_count_max * sizeof(int) );
 
519
                                                        }
 
520
                                                        coord[jj] = nbpoints;
 
521
                                                        jj = ii; ii++;
 
522
                                                        }
 
523
                                                plume = f_cod; nbpoints = 0;
 
524
                                                break;
 
525
 
 
526
                                 case 'D' :
 
527
                                        plume = f_cod;
 
528
                                        nbpoints = 1;   /* 1 point va suivre (origine du trac�) */
 
529
                                        break ;
 
530
 
 
531
                                 default  :
 
532
                                        {
 
533
                                        k1 = f_cod; /* trace sur axe V */
 
534
                                        k1 = - ((k1 * size_v) / 9) ;
 
535
                                        ptcar++ ;
 
536
                                        f_cod = *ptcar  ;
 
537
                                        k2 = f_cod; /* trace sur axe H */
 
538
                                        k2 = (k2 * size_h) / 9 ;
 
539
                                        dx = k2 + ox; dy = k1 + oy;
 
540
                                        RotatePoint(&dx, &dy, cX, cY, m_Orient);
 
541
                                        if ( ii >= coord_count_max )
 
542
                                        {
 
543
                                                coord_count_max *= 2;
 
544
                                                coord = (int*)realloc( coord, coord_count_max * sizeof(int) );
 
545
                                        }
 
546
                                        coord[ii] = dx;  ii++; coord[ii] = dy; ii++;
 
547
                                        nbpoints++;
 
548
                                        break ;
 
549
                                        }
 
550
                                 } /* end switch */
 
551
                        } /* end boucle for = end trace de 1 caractere */
 
552
 
 
553
                ptr++; ox += espacement;
 
554
                } /* end trace du texte */
 
555
 
 
556
        m_TextDrawings = (int*) realloc( coord, ii * sizeof(int) );
 
557
        m_TextDrawingsSize = ii;        //taille (en int) du tableau
 
558
}
 
559
 
 
560
 
 
561
 
 
562
/******************************/
 
563
void EDA_Rect::Normalize(void)
 
564
/******************************/
 
565
// Ensure the height ant width are >= 0
 
566
{
 
567
        if ( m_Size.y < 0 )
 
568
        {
 
569
                m_Size.y = - m_Size.y;
 
570
                m_Pos.y -= m_Size.y;
 
571
        }
 
572
        if ( m_Size.x < 0 )
 
573
        {
 
574
                m_Size.x = - m_Size.x;
 
575
                m_Pos.x -= m_Size.x;
 
576
        }
 
577
}
 
578
 
 
579
 
 
580
/*******************************************/
 
581
bool EDA_Rect::Inside(const wxPoint & point)
 
582
/*******************************************/
 
583
/* Return TRUE if point is in Rect
 
584
        Accept rect size < 0
 
585
*/
 
586
{
 
587
int rel_posx = point.x - m_Pos.x;
 
588
int rel_posy = point.y - m_Pos.y;
 
589
wxSize size = m_Size;
 
590
 
 
591
        if ( size.x < 0 )
 
592
        {
 
593
                size.x = -size.x; rel_posx += size.x;
 
594
        }
 
595
 
 
596
        if ( size.y < 0 )
 
597
        {
 
598
                size.y = -size.y; rel_posy += size.y;
 
599
        }
 
600
        return ( (rel_posx >= 0) && (rel_posy >= 0)
 
601
          && ( rel_posy <= size.y)
 
602
          && ( rel_posx <= size.x)
 
603
          );
 
604
}
 
605
 
 
606
/**************************************************/
 
607
EDA_Rect& EDA_Rect::Inflate(wxCoord dx, wxCoord dy)
 
608
/**************************************************/
 
609
{
 
610
     if (-2*dx > m_Size.x)
 
611
     {
 
612
                // Don't allow deflate to eat more width than we have,
 
613
                // a well-defined rectangle cannot have negative width.
 
614
                m_Pos.x += m_Size.x/2;
 
615
                m_Size.x = 0;
 
616
     }
 
617
     else
 
618
     {
 
619
                // The inflate is valid.
 
620
                m_Pos.x-=dx;
 
621
                m_Size.x += 2*dx;
 
622
     }
 
623
 
 
624
     if (-2*dy > m_Size.y)
 
625
     {
 
626
                // Don't allow deflate to eat more height than we have,
 
627
                // a well-defined rectangle cannot have negative height.
 
628
                m_Pos.y += m_Size.y / 2;
 
629
        m_Size.y = 0;
 
630
     }
 
631
     else
 
632
     {
 
633
                // The inflate is valid.
 
634
                m_Pos.y -= dy;
 
635
                m_Size.y += 2*dy;
 
636
     }
 
637
 
 
638
    return *this;
 
639
}
 
640
 
 
641
 
 
642
 
 
643
        /**************************/
 
644
        /* class DrawPickedStruct */
 
645
        /**************************/
 
646
 
 
647
/* This class has only one useful member: .m_PickedStruct, used as a link.
 
648
        It does not describe really an item.
 
649
        It is used to create a linked list of selected items (in block selection).
 
650
        Each DrawPickedStruct item has is member: .m_PickedStruct pointing the
 
651
        real selected item
 
652
*/
 
653
 
 
654
/*******************************************************************/
 
655
DrawPickedStruct::DrawPickedStruct(EDA_BaseStruct *pickedstruct ) :
 
656
                        EDA_BaseStruct(DRAW_PICK_ITEM_STRUCT_TYPE)
 
657
/*******************************************************************/
 
658
{
 
659
        m_PickedStruct = pickedstruct;
 
660
}
 
661
 
 
662
DrawPickedStruct::~DrawPickedStruct(void)
 
663
{
 
664
}
 
665
 
 
666
 
 
667
/*********************************************/
 
668
void DrawPickedStruct::DeleteWrapperList(void)
 
669
/*********************************************/
 
670
/* Delete this item all the items of the linked list
 
671
        Free the wrapper, but DOES NOT delete the picked items linked by .m_PickedStruct
 
672
*/
 
673
{
 
674
DrawPickedStruct * wrapp_struct, * next_struct;
 
675
 
 
676
        for ( wrapp_struct = Next(); wrapp_struct != NULL; wrapp_struct = next_struct)
 
677
        {
 
678
                next_struct = wrapp_struct->Next();
 
679
                delete wrapp_struct;
 
680
        }
 
681
}