2007-08-24 15:10:46 +00:00
|
|
|
/****************************************/
|
|
|
|
/* Modules to handle component drawing. */
|
|
|
|
/****************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "drawtxt.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "component_class.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
2008-09-19 08:19:15 +00:00
|
|
|
//#define DRAW_ARC_WITH_ANGLE // Used to select function to draw arcs
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2008-09-18 17:10:54 +00:00
|
|
|
/* Local functions */
|
|
|
|
/* Descr component <DUMMY> used when a component is not found in library,
|
|
|
|
* to draw a dummy shape
|
2007-08-24 15:10:46 +00:00
|
|
|
* This component is a 400 mils square with the text ??
|
|
|
|
* DEF DUMMY U 0 40 Y Y 1 0 N
|
|
|
|
* F0 "U" 0 -350 60 H V
|
|
|
|
* F1 "DUMMY" 0 350 60 H V
|
|
|
|
* DRAW
|
|
|
|
* T 0 0 0 150 0 0 0 ??
|
|
|
|
* S -200 200 200 -200 0 1 0
|
|
|
|
* ENDDRAW
|
|
|
|
* ENDDEF
|
|
|
|
*/
|
2008-09-18 17:10:54 +00:00
|
|
|
static void CreateDummyCmp();
|
2008-09-13 18:59:57 +00:00
|
|
|
static void DrawLibPartAux( WinEDA_DrawPanel * panel, wxDC * DC,
|
|
|
|
SCH_COMPONENT * Component,
|
|
|
|
EDA_LibComponentStruct * Entry,
|
|
|
|
const wxPoint &Pos,
|
2009-01-02 17:07:50 +00:00
|
|
|
const int TransMat[2][2],
|
2007-08-24 15:10:46 +00:00
|
|
|
int Multi, int convert,
|
|
|
|
int DrawMode, int Color = -1, bool DrawPinText = TRUE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-09-18 17:10:54 +00:00
|
|
|
/* Local variables */
|
|
|
|
static EDA_LibComponentStruct* DummyCmp;
|
2008-09-13 18:59:57 +00:00
|
|
|
|
|
|
|
/***************************************************************************/
|
2009-01-02 17:07:50 +00:00
|
|
|
wxPoint TransformCoordinate( const int aTransformMatrix[2][2], const wxPoint& aPosition )
|
2008-09-13 18:59:57 +00:00
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
/** Function TransformCoordinate
|
|
|
|
* Calculate the wew coordinate from the old one, according to the transform matrix.
|
|
|
|
* @param aTransformMatrix = rotation, mirror .. matrix
|
|
|
|
* @param aPosition = the position to transform
|
|
|
|
* @return the new coordinate
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
wxPoint new_pos;
|
|
|
|
|
|
|
|
new_pos.x = (aTransformMatrix[0][0] * aPosition.x) + (aTransformMatrix[0][1] * aPosition.y);
|
|
|
|
new_pos.y = (aTransformMatrix[1][0] * aPosition.x) + (aTransformMatrix[1][1] * aPosition.y);
|
|
|
|
return new_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************/
|
2008-09-18 17:10:54 +00:00
|
|
|
void CreateDummyCmp()
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************/
|
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
DummyCmp = new EDA_LibComponentStruct( NULL );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
LibDrawSquare* Square = new LibDrawSquare();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Square->m_Pos = wxPoint( -200, 200 );
|
|
|
|
Square->m_End = wxPoint( 200, -200 );
|
|
|
|
Square->m_Width = 4;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawText* Text = new LibDrawText();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Text->m_Size.x = Text->m_Size.y = 150;
|
|
|
|
Text->m_Text = wxT( "??" );
|
|
|
|
|
|
|
|
DummyCmp->m_Drawings = Square;
|
2008-11-24 06:53:43 +00:00
|
|
|
Square->SetNext( Text );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void DrawLibEntry( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
EDA_LibComponentStruct* LibEntry,
|
2008-09-17 17:26:25 +00:00
|
|
|
const wxPoint & aOffset,
|
2007-08-24 15:10:46 +00:00
|
|
|
int Multi, int convert,
|
|
|
|
int DrawMode, int Color )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************************/
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/* Routine de dessin d'un composant d'une librairie
|
|
|
|
* LibEntry = pointeur sur la description en librairie
|
|
|
|
* posX, posY = position du composant
|
|
|
|
* DrawMode = GrOR ..
|
|
|
|
* Color = 0 : dessin en vraies couleurs, sinon couleur = Color
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-24 15:10:46 +00:00
|
|
|
* Une croix symbolise le point d'accrochage (ref position) du composant
|
2008-03-20 01:50:21 +00:00
|
|
|
*
|
2007-08-24 15:10:46 +00:00
|
|
|
* Le composant est toujours trace avec orientation 0
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int color;
|
|
|
|
wxString Prefix;
|
|
|
|
LibDrawField* Field;
|
|
|
|
wxPoint text_pos;
|
|
|
|
|
|
|
|
|
2008-09-17 17:26:25 +00:00
|
|
|
DrawLibPartAux( panel, DC, NULL, LibEntry, aOffset,
|
2009-01-02 17:07:50 +00:00
|
|
|
DefaultTransformMatrix, Multi,
|
2008-09-13 18:59:57 +00:00
|
|
|
convert, DrawMode, Color );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
/* Trace des 2 champs ref et value (Attention aux coord: la matrice
|
|
|
|
* de transformation change de signe les coord Y */
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
if( LibEntry->m_Prefix.m_Attributs & TEXT_NO_VISIBLE )
|
|
|
|
{
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
2008-09-19 08:19:15 +00:00
|
|
|
color = g_InvisibleItemColor;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-09-17 17:26:25 +00:00
|
|
|
else color = Color;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
if( LibEntry->m_UnitCount > 1 )
|
2008-11-05 11:41:15 +00:00
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
Prefix.Printf( wxT( "%s?.%c" ), LibEntry->m_Prefix.m_Text.GetData(), Multi + '1' - 1);
|
|
|
|
#else
|
2007-08-24 15:10:46 +00:00
|
|
|
Prefix.Printf( wxT( "%s?%c" ), LibEntry->m_Prefix.m_Text.GetData(), Multi + 'A' - 1 );
|
2008-11-05 11:41:15 +00:00
|
|
|
#endif
|
2007-08-24 15:10:46 +00:00
|
|
|
else
|
|
|
|
Prefix = LibEntry->m_Prefix.m_Text + wxT( "?" );
|
|
|
|
|
|
|
|
if( (LibEntry->m_Prefix.m_Flags & IS_MOVED) == 0 )
|
2009-01-02 17:07:50 +00:00
|
|
|
LibEntry->m_Prefix.Draw( panel, DC, aOffset, color, DrawMode, &Prefix, DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
if( LibEntry->m_Name.m_Attributs & TEXT_NO_VISIBLE )
|
|
|
|
{
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
2008-09-19 08:19:15 +00:00
|
|
|
color = g_InvisibleItemColor;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-09-17 17:26:25 +00:00
|
|
|
else color = Color;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
if( (LibEntry->m_Name.m_Flags & IS_MOVED) == 0 )
|
2009-01-02 17:07:50 +00:00
|
|
|
LibEntry->m_Name.Draw( panel, DC, aOffset, color, DrawMode, NULL, DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2008-12-31 15:01:29 +00:00
|
|
|
for( Field = LibEntry->m_Fields; Field != NULL; Field = Field->Next() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
if( Field->m_Text.IsEmpty() )
|
|
|
|
return;
|
|
|
|
if( (Field->m_Flags & IS_MOVED) != 0 )
|
|
|
|
continue;
|
|
|
|
if( Field->m_Attributs & TEXT_NO_VISIBLE )
|
|
|
|
{
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
2008-09-19 08:19:15 +00:00
|
|
|
color = g_InvisibleItemColor;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-09-17 17:26:25 +00:00
|
|
|
else color = Color;
|
2009-01-02 17:07:50 +00:00
|
|
|
Field->Draw( panel, DC, aOffset, color, DrawMode, NULL, DefaultTransformMatrix );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
// Trace de l'ancre
|
2009-01-29 14:26:20 +00:00
|
|
|
int len = panel->GetScreen()->Unscale( 3 );
|
2008-09-17 17:26:25 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, aOffset.x, aOffset.y - len, aOffset.x, aOffset.y + len, 0, color );
|
|
|
|
GRLine( &panel->m_ClipBox, DC, aOffset.x - len, aOffset.y, aOffset.x + len, aOffset.y, 0, color );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Routine to draw the given part at given position, transformed/mirror as *
|
|
|
|
* specified, and in the given drawing mode. Only this one is visible... *
|
|
|
|
*****************************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
2008-09-13 18:59:57 +00:00
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
EDA_LibComponentStruct* Entry;
|
|
|
|
int ii;
|
|
|
|
bool dummy = FALSE;
|
|
|
|
|
|
|
|
if( ( Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT ) ) == NULL )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
|
|
|
/* composant non trouve, on affiche un composant "dummy" */
|
2007-08-24 15:10:46 +00:00
|
|
|
dummy = TRUE;
|
|
|
|
if( DummyCmp == NULL )
|
|
|
|
CreateDummyCmp();
|
|
|
|
Entry = DummyCmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawLibPartAux( panel, DC, this, Entry, m_Pos + offset,
|
2008-09-13 18:59:57 +00:00
|
|
|
m_Transform,
|
|
|
|
dummy ? 0 : m_Multi,
|
|
|
|
dummy ? 0 : m_Convert,
|
|
|
|
DrawMode );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
/* Trace des champs, avec placement et orientation selon orient. du
|
|
|
|
* composant
|
|
|
|
*/
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
SCH_CMP_FIELD* field = GetField( REFERENCE );
|
|
|
|
|
|
|
|
if( ( (field->m_Attributs & TEXT_NO_VISIBLE) == 0 )
|
|
|
|
&& !(field->m_Flags & IS_MOVED) )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
if( Entry->m_UnitCount > 1 )
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
field->m_AddExtraText = true;
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
else
|
2008-04-14 19:22:48 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
field->m_AddExtraText = false;
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
2008-04-14 19:22:48 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
for( ii = VALUE; ii < GetFieldCount(); ii++ )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
field = GetField( ii );
|
|
|
|
|
|
|
|
if( field->m_Flags & IS_MOVED )
|
2007-08-24 15:10:46 +00:00
|
|
|
continue;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************************************/
|
2008-09-17 17:26:25 +00:00
|
|
|
void SCH_CMP_FIELD::Draw( WinEDA_DrawPanel* panel,
|
2008-09-13 18:59:57 +00:00
|
|
|
wxDC* DC,
|
|
|
|
const wxPoint& offset,
|
|
|
|
int DrawMode,
|
|
|
|
int Color )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Routine de trace des textes type Field du composant.
|
2007-08-24 15:10:46 +00:00
|
|
|
* entree:
|
|
|
|
* DrawMode: mode de trace
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
int orient;
|
|
|
|
EDA_Colors color;
|
2008-09-13 18:59:57 +00:00
|
|
|
wxPoint pos; /* Position des textes */
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) m_Parent;
|
2008-12-16 19:44:57 +00:00
|
|
|
GRTextHorizJustifyType hjustify;
|
|
|
|
GRTextVertJustifyType vjustify;
|
2008-09-13 18:59:57 +00:00
|
|
|
int LineWidth = MAX( m_Width, g_DrawMinimunLineWidth );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_Attributs & TEXT_NO_VISIBLE )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( IsVoid() )
|
2007-08-24 15:10:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
/* Calcul de la position des textes, selon orientation du composant */
|
2008-04-14 19:22:48 +00:00
|
|
|
orient = m_Orient;
|
|
|
|
hjustify = m_HJustify; vjustify = m_VJustify;
|
2008-09-13 18:59:57 +00:00
|
|
|
pos = m_Pos - DrawLibItem->m_Pos;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
pos = DrawLibItem->GetScreenCoord( pos );
|
2008-04-14 19:22:48 +00:00
|
|
|
pos += DrawLibItem->m_Pos;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
/* Y a t-il rotation (pour l'orientation, la justification)*/
|
|
|
|
if( DrawLibItem->m_Transform[0][1] ) // Rotation du composant de 90deg
|
|
|
|
{
|
|
|
|
if( orient == TEXT_ORIENT_HORIZ )
|
|
|
|
orient = TEXT_ORIENT_VERT;
|
|
|
|
else
|
|
|
|
orient = TEXT_ORIENT_HORIZ;
|
|
|
|
/* Y a t-il rotation, miroir (pour les justifications)*/
|
2008-12-16 19:44:57 +00:00
|
|
|
GRTextHorizJustifyType tmp = hjustify;
|
|
|
|
hjustify = (GRTextHorizJustifyType) vjustify;
|
|
|
|
vjustify = (GRTextVertJustifyType) tmp;
|
2007-08-24 15:10:46 +00:00
|
|
|
if( DrawLibItem->m_Transform[1][0] < 0 )
|
2008-12-16 19:44:57 +00:00
|
|
|
switch ( vjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
if( DrawLibItem->m_Transform[1][0] > 0 )
|
2008-12-16 19:44:57 +00:00
|
|
|
switch ( hjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Texte horizontal: Y a t-il miroir (pour les justifications)*/
|
|
|
|
if( DrawLibItem->m_Transform[0][0] < 0 )
|
2008-12-16 19:44:57 +00:00
|
|
|
switch ( hjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_RIGHT;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
|
|
|
hjustify = GR_TEXT_HJUSTIFY_LEFT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
if( DrawLibItem->m_Transform[1][1] > 0 )
|
2008-12-16 19:44:57 +00:00
|
|
|
switch ( vjustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_TOP;
|
|
|
|
break;
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
vjustify = GR_TEXT_VJUSTIFY_BOTTOM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( m_FieldId == REFERENCE )
|
2007-08-24 15:10:46 +00:00
|
|
|
color = ReturnLayerColor( LAYER_REFERENCEPART );
|
2008-04-14 19:22:48 +00:00
|
|
|
else if( m_FieldId == VALUE )
|
2007-08-24 15:10:46 +00:00
|
|
|
color = ReturnLayerColor( LAYER_VALUEPART );
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( LAYER_FIELDS );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
if( !m_AddExtraText || (m_FieldId != REFERENCE) )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-12-14 19:45:05 +00:00
|
|
|
DrawGraphicText( panel, DC, pos, color, m_Text,
|
2008-09-13 18:59:57 +00:00
|
|
|
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
|
|
|
|
m_Size,
|
2008-12-28 18:00:37 +00:00
|
|
|
hjustify, vjustify, LineWidth, m_Italic );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2008-12-16 19:44:57 +00:00
|
|
|
else // For more than one part per package, we must add the part selection to the reference )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-12-16 19:44:57 +00:00
|
|
|
/* Adding A ou B ... or .1 .2 ... to the reference */
|
2008-04-14 19:22:48 +00:00
|
|
|
wxString fulltext = m_Text;
|
2008-11-05 11:41:15 +00:00
|
|
|
#if defined(KICAD_GOST)
|
|
|
|
fulltext.Append( '.');
|
|
|
|
fulltext.Append( '1' - 1 + DrawLibItem->m_Multi );
|
|
|
|
#else
|
2007-08-24 15:10:46 +00:00
|
|
|
fulltext.Append( 'A' - 1 + DrawLibItem->m_Multi );
|
2008-11-05 11:41:15 +00:00
|
|
|
#endif
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
DrawGraphicText( panel, DC, pos, color, fulltext,
|
2008-09-13 18:59:57 +00:00
|
|
|
orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
|
|
|
|
m_Size,
|
2008-12-28 18:00:37 +00:00
|
|
|
hjustify, vjustify, LineWidth, m_Italic );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
EDA_LibComponentStruct* FindLibPart( const wxChar* Name, const wxString& LibName, int Alias )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*
|
2007-08-24 15:10:46 +00:00
|
|
|
* Routine to find a part in one of the libraries given its name.
|
|
|
|
* Name = Name of part.
|
|
|
|
* LibName = Name of Lib; if "": seach in all libs
|
|
|
|
* Alias = Flag: si flag != 0, retourne un pointeur sur une part ou un alias
|
|
|
|
* si flag = 0, retourne un pointeur sur une part meme si le nom
|
|
|
|
* correspond a un alias
|
|
|
|
* Alias = FIND_ROOT, ou Alias = FIND_ALIAS
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-09-13 18:59:57 +00:00
|
|
|
EDA_LibComponentStruct* Entry;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-21 04:40:12 +00:00
|
|
|
static EDA_LibComponentStruct DummyEntry( wxEmptyString ); /* Used only to call PQFind. */
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
LibraryStruct* Lib = g_LibraryList;
|
|
|
|
|
2008-09-13 18:59:57 +00:00
|
|
|
DummyEntry.m_Drawings = NULL; /* Used only to call PQFind. */
|
2007-08-24 15:10:46 +00:00
|
|
|
DummyEntry.m_Name.m_Text = Name;
|
|
|
|
|
|
|
|
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
Entry = NULL;
|
2007-09-21 04:40:12 +00:00
|
|
|
FindLibName.Empty();
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
while( Lib )
|
|
|
|
{
|
|
|
|
if( !LibName.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( Lib->m_Name != LibName )
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
Lib = Lib->m_Pnext;
|
2007-09-21 04:40:12 +00:00
|
|
|
continue;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
if( Lib == NULL )
|
|
|
|
break;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Entry = (EDA_LibComponentStruct*) PQFind( Lib->m_Entries, &DummyEntry );
|
|
|
|
if( Entry != NULL )
|
|
|
|
{
|
|
|
|
FindLibName = Lib->m_Name;
|
|
|
|
break;
|
|
|
|
}
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Lib = Lib->m_Pnext;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Si le nom est un alias, recherche du vrai composant */
|
|
|
|
if( Entry )
|
|
|
|
{
|
|
|
|
if( (Entry->Type != ROOT ) && (Alias == FIND_ROOT) )
|
|
|
|
Entry = FindLibPart( ( (EDA_LibCmpAliasStruct*) Entry )->m_RootName.GetData(),
|
2008-09-13 18:59:57 +00:00
|
|
|
Lib->m_Name, FIND_ROOT );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Entry;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Routine to draw the given part at given position, transformed/mirror as
|
|
|
|
* specified, and in the given drawing mode.
|
|
|
|
* if Color < 0: Draw in normal color
|
|
|
|
* else draw in color = Color
|
|
|
|
*****************************************************************************/
|
|
|
|
/* DrawMode = GrXOR, GrOR ..*/
|
2007-08-24 15:10:46 +00:00
|
|
|
void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC,
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* Component,
|
2007-08-24 15:10:46 +00:00
|
|
|
EDA_LibComponentStruct* Entry,
|
|
|
|
const wxPoint& Pos,
|
2009-01-02 17:07:50 +00:00
|
|
|
const int TransMat[2][2],
|
2007-08-24 15:10:46 +00:00
|
|
|
int Multi, int convert, int DrawMode,
|
|
|
|
int Color, bool DrawPinText )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-09-13 18:59:57 +00:00
|
|
|
wxPoint pos1, pos2;
|
2008-09-14 04:27:22 +00:00
|
|
|
LibEDA_BaseStruct* DEntry;
|
|
|
|
bool force_nofill;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
if( Entry->m_Drawings == NULL )
|
|
|
|
return;
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
for( DEntry = Entry->m_Drawings; DEntry != NULL; DEntry = DEntry->Next() )
|
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
/* Do not draw items not attached to the current part */
|
2007-08-24 15:10:46 +00:00
|
|
|
if( Multi && DEntry->m_Unit && (DEntry->m_Unit != Multi) )
|
|
|
|
continue;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
if( convert && DEntry->m_Convert && (DEntry->m_Convert != convert) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( DEntry->m_Flags & IS_MOVED )
|
2008-09-14 04:27:22 +00:00
|
|
|
continue; // Do do draw here an item while moving (the cursor handler does that)
|
2008-03-20 01:50:21 +00:00
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
force_nofill = false;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( DEntry->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
case COMPONENT_PIN_DRAW_TYPE:
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
DrawPinPrms prms( Entry, DrawPinText );
|
|
|
|
DEntry->Draw( panel, DC, Pos, Color, DrawMode, &prms, TransMat );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
2007-08-24 15:10:46 +00:00
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
|
|
|
default:
|
2008-09-14 04:27:22 +00:00
|
|
|
if( g_IsPrinting && DEntry->m_Fill == FILLED_WITH_BG_BODYCOLOR
|
|
|
|
&& GetGRForceBlackPenState() )
|
|
|
|
force_nofill = true;
|
|
|
|
DEntry->Draw( panel, DC, Pos, Color, DrawMode, (void*) force_nofill, TransMat );
|
2007-08-24 15:10:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( g_DebugLevel > 4 ) /* Draw the component boundary box */
|
|
|
|
{
|
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
if( Component )
|
|
|
|
BoundaryBox = Component->GetBoundaryBox();
|
|
|
|
else
|
|
|
|
BoundaryBox = Entry->GetBoundaryBox( Multi, convert );
|
2008-09-13 18:59:57 +00:00
|
|
|
int x1 = BoundaryBox.GetX();
|
|
|
|
int y1 = BoundaryBox.GetY();
|
|
|
|
int x2 = BoundaryBox.GetRight();
|
|
|
|
int y2 = BoundaryBox.GetBottom();
|
2007-08-24 15:10:46 +00:00
|
|
|
GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
|
2008-10-06 05:44:29 +00:00
|
|
|
BoundaryBox = Component->GetField( REFERENCE )->GetBoundaryBox();
|
2007-08-24 15:10:46 +00:00
|
|
|
x1 = BoundaryBox.GetX();
|
|
|
|
y1 = BoundaryBox.GetY();
|
|
|
|
x2 = BoundaryBox.GetRight();
|
|
|
|
y2 = BoundaryBox.GetBottom();
|
|
|
|
GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
|
2008-10-06 05:44:29 +00:00
|
|
|
BoundaryBox = Component->GetField( VALUE )->GetBoundaryBox();
|
2007-08-24 15:10:46 +00:00
|
|
|
x1 = BoundaryBox.GetX();
|
|
|
|
y1 = BoundaryBox.GetY();
|
|
|
|
x2 = BoundaryBox.GetRight();
|
|
|
|
y2 = BoundaryBox.GetBottom();
|
|
|
|
GRRect( &panel->m_ClipBox, DC, x1, y1, x2, y2, BROWN );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Routine to rotate the given angular direction by the given Transformation. *
|
|
|
|
* Input (and output) angles must be as follows: *
|
|
|
|
* Unit is 0.1 degre *
|
|
|
|
* Angle1 in [0..3600], Angle2 > Angle1 in [0..7200]. Arc is assumed to be less *
|
|
|
|
* than 180.0 degrees. *
|
|
|
|
* Algorithm: *
|
|
|
|
* Map the angles to a point on the unit circle which is mapped using the *
|
|
|
|
* transform (only mirror and rotate so it remains on the unit circle) to *
|
|
|
|
* a new point which is used to detect new angle. *
|
|
|
|
*****************************************************************************/
|
2009-01-02 17:07:50 +00:00
|
|
|
bool MapAngles( int* Angle1, int* Angle2, const int TransMat[2][2] )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int Angle, Delta;
|
|
|
|
double x, y, t;
|
|
|
|
bool swap = FALSE;
|
|
|
|
|
|
|
|
Delta = *Angle2 - *Angle1;
|
|
|
|
if( Delta >= 1800 )
|
|
|
|
{
|
|
|
|
*Angle1 -= 1;
|
|
|
|
*Angle2 += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
x = cos( *Angle1 * M_PI / 1800.0 );
|
|
|
|
y = sin( *Angle1 * M_PI / 1800.0 );
|
|
|
|
t = x * TransMat[0][0] + y * TransMat[0][1];
|
|
|
|
y = x * TransMat[1][0] + y * TransMat[1][1];
|
|
|
|
x = t;
|
|
|
|
*Angle1 = (int) (atan2( y, x ) * 1800.0 / M_PI + 0.5);
|
|
|
|
|
|
|
|
x = cos( *Angle2 * M_PI / 1800.0 );
|
|
|
|
y = sin( *Angle2 * M_PI / 1800.0 );
|
|
|
|
t = x * TransMat[0][0] + y * TransMat[0][1];
|
|
|
|
y = x * TransMat[1][0] + y * TransMat[1][1];
|
|
|
|
x = t;
|
|
|
|
*Angle2 = (int) (atan2( y, x ) * 1800.0 / M_PI + 0.5);
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE( *Angle1 );
|
|
|
|
NORMALIZE_ANGLE( *Angle2 );
|
|
|
|
if( *Angle2 < *Angle1 )
|
|
|
|
*Angle2 += 3600;
|
|
|
|
|
|
|
|
if( *Angle2 - *Angle1 > 1800 )
|
|
|
|
{ /* Need to swap the two angles. */
|
|
|
|
Angle = (*Angle1);
|
|
|
|
*Angle1 = (*Angle2);
|
|
|
|
*Angle2 = Angle;
|
|
|
|
|
|
|
|
NORMALIZE_ANGLE( *Angle1 );
|
|
|
|
NORMALIZE_ANGLE( *Angle2 );
|
|
|
|
if( *Angle2 < *Angle1 )
|
|
|
|
*Angle2 += 3600;
|
|
|
|
swap = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Delta >= 1800 )
|
|
|
|
{
|
|
|
|
*Angle1 += 1;
|
|
|
|
*Angle2 -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return swap;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Routine to display an outline version of given library entry. *
|
|
|
|
* This routine is applied by the PlaceLibItem routine above. *
|
|
|
|
*****************************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void DrawingLibInGhost( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
EDA_LibComponentStruct* LibEntry,
|
2008-03-20 01:50:21 +00:00
|
|
|
SCH_COMPONENT* DrawLibItem, int PartX, int PartY,
|
2007-08-24 15:10:46 +00:00
|
|
|
int multi, int convert, int Color, bool DrawPinText )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int DrawMode = g_XorMode;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
DrawLibPartAux( panel, DC, DrawLibItem, LibEntry, wxPoint( PartX, PartY ),
|
2008-09-13 18:59:57 +00:00
|
|
|
DrawLibItem->m_Transform,
|
|
|
|
multi, convert, DrawMode, Color, DrawPinText );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************************/
|
|
|
|
/* Routine to draw One LibraryDrawStruct at given position, */
|
|
|
|
/* matrice de transformation 1 0 0 -1 (normale) */
|
|
|
|
/* DrawMode = GrXOR, GrOR .. */
|
|
|
|
/************************************************************/
|
|
|
|
/* Utilise en LibEdit et Lib Browse */
|
2008-09-14 04:27:22 +00:00
|
|
|
void DrawLibraryDrawStruct( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
EDA_LibComponentStruct* aLibEntry,
|
|
|
|
wxPoint aPosition,
|
|
|
|
LibEDA_BaseStruct* aDrawItem,
|
|
|
|
int aDrawMode, int aColor )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
int TransMat[2][2];
|
|
|
|
bool no_fill;
|
|
|
|
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
TransMat[0][0] = 1;
|
|
|
|
TransMat[0][1] = TransMat[1][0] = 0;
|
|
|
|
TransMat[1][1] = -1;
|
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
no_fill = false;
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
switch( aDrawItem->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
case COMPONENT_PIN_DRAW_TYPE: /* Trace des Pins */
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
2008-09-14 04:27:22 +00:00
|
|
|
DrawPinPrms prms( aLibEntry, true );
|
|
|
|
aDrawItem->Draw( aPanel, aDC, aPosition, aColor, aDrawMode, &prms, TransMat );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2008-09-14 04:27:22 +00:00
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
2007-08-24 15:10:46 +00:00
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
|
|
|
default:
|
2008-09-14 04:27:22 +00:00
|
|
|
if( g_IsPrinting && aDrawItem->m_Fill == FILLED_WITH_BG_BODYCOLOR
|
|
|
|
&& GetGRForceBlackPenState() )
|
|
|
|
no_fill = true;
|
|
|
|
aDrawItem->Draw( aPanel, aDC, aPosition, aColor, aDrawMode, (void*) no_fill, TransMat );
|
|
|
|
break;
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|