1
/********************************************************/
2
/* methodes pour les structures de base: */
3
/* EDA_BaseStruct (classe non utilisable seule) */
4
/* EDA_TextStruct (classe non utilisable seule) */
5
/********************************************************/
7
/* Fichier base_struct.cpp */
14
#include "base_struct.h"
20
// DrawStructureType names for error messages only:
21
static wxString DrawStructureTypeName[MAX_STRUCT_TYPE_ID+1]
56
wxT("Text (lib item)"),
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"),
75
ID_TEXTBOX_LIST = 8010
79
/******************************************************************************/
80
EDA_BaseStruct::EDA_BaseStruct(EDA_BaseStruct * parent, int idType)
81
/******************************************************************************/
84
m_StructType = idType;
85
m_Parent = parent; /* Chainage hierarchique sur struct racine */
89
/********************************************/
90
EDA_BaseStruct::EDA_BaseStruct(int idType)
91
/********************************************/
94
m_StructType = idType;
97
/********************************************/
98
void EDA_BaseStruct::InitVars(void)
99
/********************************************/
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
110
m_Selected = 0; /* Used by block commands, and selective editing */
114
/* Gestion de l'etat (status) de la structure (active, deleted..) */
115
int EDA_BaseStruct::GetState(int type)
117
return(m_Status & type);
120
void EDA_BaseStruct::SetState(int type, int state )
122
if( state ) m_Status |= type; /* state = ON ou OFF */
123
else m_Status &= ~type;
127
/*********************************************************/
128
void EDA_BaseStruct::AddToChain(EDA_BaseStruct * laststruct)
129
/*********************************************************/
131
addition d'une nouvelle struct a la liste chain�e, apres la structure laststruct
134
Pnext = laststruct->Pnext;
136
laststruct->Pnext = this;
140
/**************************************************************************************/
141
void EDA_BaseStruct::Draw(WinEDA_DrawPanel * panel, wxDC * DC, const wxPoint & offset,
142
int draw_mode, int Color)
143
/**************************************************************************************/
148
msg.Printf( wxT("EDA_BaseStruct::Draw() error. Method for struct type %d used but not implemented ("),
150
msg += ReturnClassName() + wxT(")\n");
151
printf ( CONV_TO_UTF8(msg));
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...)
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.
172
int ii = m_StructType;
175
if ( (ii < 0) || (ii > MAX_STRUCT_TYPE_ID) ) ii = MAX_STRUCT_TYPE_ID;
176
classname = DrawStructureTypeName[ii];
183
/**********************************************************************************************/
184
EDA_BaseLineStruct::EDA_BaseLineStruct(EDA_BaseStruct * StructFather, DrawStructureType idtype):
185
EDA_BaseStruct(StructFather, idtype)
186
/**********************************************************************************************/
189
m_Width = 0; // 0 = line, > 0 = tracks, bus ...
193
/*********************************************************/
194
/* EDA_TextStruct (classe de base, non utilis�e seule */
195
/*********************************************************/
196
EDA_TextStruct::EDA_TextStruct(const wxString & text)
199
m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT; /* XY size of font */
200
m_Orient = 0; /* Orient in 0.1 degrees */
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 ... */
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� */
214
EDA_TextStruct::~EDA_TextStruct(void)
216
if( m_TextDrawings ) /* pointeur sur la liste des segments de dessin */
218
free(m_TextDrawings); m_TextDrawings = NULL;
220
m_TextDrawingsSize = 0; /* nombre de sommets a dessiner */
223
/********************************/
224
int EDA_TextStruct::Len_Size(void)
225
/********************************/
226
// Return the text lenght in internal units
228
int nbchar = m_Text.Len();
230
if ( nbchar == 0 ) return 0;
232
len = ((10 * m_Size.x ) / 9) * nbchar;
237
/*************************************************/
238
int EDA_TextStruct::Locate(const wxPoint & posref)
239
/*************************************************/
242
1 if posref is inside the text area.
247
int spot_cX, spot_cY;
249
dx = (Pitch() * GetLength()) / 2;
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;
259
/*******************************/
260
int EDA_TextStruct::Pitch(void)
261
/*******************************/
262
/* retourne le pas entre 2 caracteres
265
return ((10 * m_Size.x ) / 9) + m_Width;
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
/***************************************************************/
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 ).
284
int ii, jj, kk, ll, nbpoints;
287
if( m_TextDrawings == NULL) /* pointeur sur la liste des segments de dessin */
289
if( m_TextDrawings == NULL) return;
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);
298
if ( zoom > m_ZoomLevelDrawable)
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,
310
/* trace ancre du texte ? */
311
if( anchor_color != -1)
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);
325
while (ii < m_TextDrawingsSize)
327
nbpoints = m_TextDrawings[jj];
328
if (nbpoints > 50 ) nbpoints = 50;
329
for ( kk = 0, ll = 0; (kk < nbpoints) && (ii < m_TextDrawingsSize) ; kk++)
331
coord[ll] = m_TextDrawings[ii] + offset.x + m_Pos.x;
333
coord[ll] = m_TextDrawings[ii] + offset.y + m_Pos.y;
340
for ( kk = 0, ll = 0; kk < (nbpoints-1); kk ++, ll+= 2 )
342
if( display_mode == SKETCH)
343
GRCSegm(&panel->m_ClipBox, DC,
344
coord[ll],coord[ll+1],
345
coord[ll+2],coord[ll+3],
348
else GRFillCSegm(&panel->m_ClipBox, DC,
349
coord[ll],coord[ll+1],
350
coord[ll+2],coord[ll+3],
355
GRPoly(&panel->m_ClipBox, DC, nbpoints, coord, 0, color, color);
361
/****************************************/
362
void EDA_TextStruct::CreateDrawData(void)
363
/****************************************/
364
/* Cree le tableau de donn�es n�cessaire au trace d'un texte (pcb, module..)
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
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';
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;
388
if( m_TextDrawings ) /* pointeur sur la liste des segments de dessin */
390
free(m_TextDrawings); m_TextDrawings = 0;
392
m_TextDrawingsSize = 0; /* nombre de segments a dessiner */
394
nbchar = m_Text.Length();
395
if ( nbchar == 0 ) return;
399
espacement = Pitch();
402
size_h = -size_h; espacement = - espacement;
405
kk = 0; ptr = m_Text.GetData() ; /* ptr pointe 1er caractere du texte */
407
/* calcul de la position du debut des textes: ox et oy */
408
ox = cX = 0; oy = cY = 0;
410
/* Calcul du cadrage du texte */
411
dx = (espacement * nbchar) / 2;
412
dy = size_v / 2; /* Decalage du debut du texte / centre */
414
ux0 = uy0 = 0; /* Decalage du centre du texte / ccord de ref */
416
if( (m_Orient == 0) || (m_Orient == 1800) ) /* Texte Horizontal */
420
case GR_TEXT_HJUSTIFY_CENTER:
423
case GR_TEXT_HJUSTIFY_RIGHT:
427
case GR_TEXT_HJUSTIFY_LEFT:
434
case GR_TEXT_VJUSTIFY_CENTER:
437
case GR_TEXT_VJUSTIFY_TOP:
441
case GR_TEXT_VJUSTIFY_BOTTOM:
447
else /* Texte Vertical */
451
case GR_TEXT_HJUSTIFY_CENTER:
454
case GR_TEXT_HJUSTIFY_RIGHT:
458
case GR_TEXT_HJUSTIFY_LEFT:
465
case GR_TEXT_VJUSTIFY_CENTER:
468
case GR_TEXT_VJUSTIFY_TOP:
472
case GR_TEXT_VJUSTIFY_BOTTOM:
477
cX += ux0; cY += uy0;
478
ox = cX - dx; ; oy = cY + dy;
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;
487
RotatePoint(&ux0, &uy0, cX, cY, m_Orient);
488
RotatePoint(&dx, &dy, cX, cY, m_Orient);
490
coord = (int*) MyMalloc( (coord_count_max+2) * sizeof(int));
492
coord[1] = ux0; coord[2] = uy0;
493
coord[3] = dx; coord[4] = dy;
495
jj = 5; ii = jj+1; nbpoints = 0;
499
AsciiCode = (*ptr) & 255;
500
ptcar = graphic_fonte_shape[AsciiCode] ; /* ptcar pointe la description
501
du caractere a dessiner */
503
for(endcar = FALSE; ! endcar; ptcar++)
505
f_cod = *ptcar ; /* get code n de la forme selectionnee */
509
endcar = TRUE;/* fin du caractere */
513
if(nbpoints && (plume == 'D' ) )
515
if ( jj >= coord_count_max )
517
coord_count_max *= 2;
518
coord = (int*)realloc( coord, coord_count_max * sizeof(int) );
520
coord[jj] = nbpoints;
523
plume = f_cod; nbpoints = 0;
528
nbpoints = 1; /* 1 point va suivre (origine du trac�) */
533
k1 = f_cod; /* trace sur axe V */
534
k1 = - ((k1 * size_v) / 9) ;
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 )
543
coord_count_max *= 2;
544
coord = (int*)realloc( coord, coord_count_max * sizeof(int) );
546
coord[ii] = dx; ii++; coord[ii] = dy; ii++;
551
} /* end boucle for = end trace de 1 caractere */
553
ptr++; ox += espacement;
554
} /* end trace du texte */
556
m_TextDrawings = (int*) realloc( coord, ii * sizeof(int) );
557
m_TextDrawingsSize = ii; //taille (en int) du tableau
562
/******************************/
563
void EDA_Rect::Normalize(void)
564
/******************************/
565
// Ensure the height ant width are >= 0
569
m_Size.y = - m_Size.y;
574
m_Size.x = - m_Size.x;
580
/*******************************************/
581
bool EDA_Rect::Inside(const wxPoint & point)
582
/*******************************************/
583
/* Return TRUE if point is in Rect
587
int rel_posx = point.x - m_Pos.x;
588
int rel_posy = point.y - m_Pos.y;
589
wxSize size = m_Size;
593
size.x = -size.x; rel_posx += size.x;
598
size.y = -size.y; rel_posy += size.y;
600
return ( (rel_posx >= 0) && (rel_posy >= 0)
601
&& ( rel_posy <= size.y)
602
&& ( rel_posx <= size.x)
606
/**************************************************/
607
EDA_Rect& EDA_Rect::Inflate(wxCoord dx, wxCoord dy)
608
/**************************************************/
610
if (-2*dx > m_Size.x)
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;
619
// The inflate is valid.
624
if (-2*dy > m_Size.y)
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;
633
// The inflate is valid.
643
/**************************/
644
/* class DrawPickedStruct */
645
/**************************/
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
654
/*******************************************************************/
655
DrawPickedStruct::DrawPickedStruct(EDA_BaseStruct *pickedstruct ) :
656
EDA_BaseStruct(DRAW_PICK_ITEM_STRUCT_TYPE)
657
/*******************************************************************/
659
m_PickedStruct = pickedstruct;
662
DrawPickedStruct::~DrawPickedStruct(void)
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
674
DrawPickedStruct * wrapp_struct, * next_struct;
676
for ( wrapp_struct = Next(); wrapp_struct != NULL; wrapp_struct = next_struct)
678
next_struct = wrapp_struct->Next();