Commit 09701a74 authored by charras's avatar charras

Eeschema: solved minor problems in libedit in functions locate and move fields.

parent 97cfebcb
...@@ -77,24 +77,24 @@ void LibDrawArc::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffs ...@@ -77,24 +77,24 @@ void LibDrawArc::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOffs
if( fill == FILLED_WITH_BG_BODYCOLOR ) if( fill == FILLED_WITH_BG_BODYCOLOR )
GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
m_Rayon, linewidth, color, m_Rayon, linewidth, color,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE && !aData ) else if( fill == FILLED_SHAPE && !aData )
GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, GRFilledArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
m_Rayon, color, color ); m_Rayon, color, color );
else else
#ifdef DRAW_ARC_WITH_ANGLE #ifdef DRAW_ARC_WITH_ANGLE
GRArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2, GRArc( &aPanel->m_ClipBox, aDC, posc.x, posc.y, pt1, pt2,
m_Rayon, linewidth, color ); m_Rayon, linewidth, color );
#else #else
GRArc1( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, GRArc1( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
posc.x, posc.y, linewidth, color ); posc.x, posc.y, linewidth, color );
#endif #endif
} }
...@@ -126,14 +126,14 @@ void LibDrawCircle::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO ...@@ -126,14 +126,14 @@ void LibDrawCircle::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO
if( fill == FILLED_WITH_BG_BODYCOLOR ) if( fill == FILLED_WITH_BG_BODYCOLOR )
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
m_Rayon, linewidth, color, m_Rayon, linewidth, color,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE ) else if( fill == FILLED_SHAPE )
GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, GRFilledCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
m_Rayon, 0, color, color ); m_Rayon, 0, color, color );
else else
GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, GRCircle( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y,
m_Rayon, linewidth, color ); m_Rayon, linewidth, color );
} }
...@@ -162,9 +162,9 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOff ...@@ -162,9 +162,9 @@ void LibDrawText::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOff
int t1 = (aTransformMatrix[0][0] != 0) ^ (m_Horiz != 0); int t1 = (aTransformMatrix[0][0] != 0) ^ (m_Horiz != 0);
DrawGraphicText( aPanel, aDC, pos1, color, m_Text, DrawGraphicText( aPanel, aDC, pos1, color, m_Text,
t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT, t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT,
m_Size, m_Size,
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, linewidth ); GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER, linewidth );
} }
...@@ -195,14 +195,14 @@ void LibDrawSquare::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO ...@@ -195,14 +195,14 @@ void LibDrawSquare::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aO
if( fill == FILLED_WITH_BG_BODYCOLOR && !aData ) if( fill == FILLED_WITH_BG_BODYCOLOR && !aData )
GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
color, linewidth, color, linewidth,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( m_Fill == FILLED_SHAPE && !aData ) else if( m_Fill == FILLED_SHAPE && !aData )
GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, GRFilledRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
color, color ); color, color );
else else
GRRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y, GRRect( &aPanel->m_ClipBox, aDC, pos1.x, pos1.y, pos2.x, pos2.y,
linewidth, color ); linewidth, color );
} }
...@@ -263,7 +263,7 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, ...@@ -263,7 +263,7 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
{ {
Buf_Poly_Size = m_CornersCount; Buf_Poly_Size = m_CornersCount;
Buf_Poly_Drawings = (int*) realloc( Buf_Poly_Drawings, Buf_Poly_Drawings = (int*) realloc( Buf_Poly_Drawings,
sizeof(int) * 2 * Buf_Poly_Size ); sizeof(int) * 2 * Buf_Poly_Size );
} }
for( int ii = 0, jj = 0; ii < m_CornersCount; ii++, jj += 2 ) for( int ii = 0, jj = 0; ii < m_CornersCount; ii++, jj += 2 )
...@@ -283,14 +283,14 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, ...@@ -283,14 +283,14 @@ void LibDrawPolyline::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
if( fill == FILLED_WITH_BG_BODYCOLOR ) if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount, GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 1, linewidth, color, Buf_Poly_Drawings, 1, linewidth, color,
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) ); ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE ) else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount, GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 1, linewidth, color, color ); Buf_Poly_Drawings, 1, linewidth, color, color );
else else
GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount, GRPoly( &aPanel->m_ClipBox, aDC, m_CornersCount,
Buf_Poly_Drawings, 0, linewidth, color, color ); Buf_Poly_Drawings, 0, linewidth, color, color );
} }
...@@ -337,8 +337,53 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOf ...@@ -337,8 +337,53 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOf
wxString* text = aData ? (wxString*) aData : &m_Text; wxString* text = aData ? (wxString*) aData : &m_Text;
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
DrawGraphicText( aPanel, aDC, text_pos, DrawGraphicText( aPanel, aDC, text_pos,
color, text->GetData(), color, text->GetData(),
m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ, m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
m_Size, m_Size,
m_HJustify, m_VJustify, linewidth ); m_HJustify, m_VJustify, linewidth );
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test, in Field coordinate system
* @return bool - true if a hit, else false
*/
bool LibDrawField::HitTest( const wxPoint& refPos )
{
EDA_Rect bbox; // bounding box for the text
bbox.SetOrigin( m_Pos );
int dx; // X size for the full text
if ( m_FieldId == REFERENCE )
dx = m_Size.x * (m_Text.Len( ) + 1); // The displayed text has one char more (U is displayed U?)
else
dx = m_Size.x * m_Text.Len( );
dx = (int) ((double) dx * 10.0/9); // spacing between char is 0.1 the char size
int dy = m_Size.y;
if( m_Orient )
EXCHG( dx, dy ); // Swap X and Y size for a vertical text
// adjust position of the left bottom corner according to the justification
// pos is at this point correct for a left and top justified text
// Horizontal justification
if( m_HJustify == GR_TEXT_HJUSTIFY_CENTER )
bbox.Offset( -dx / 2, 0 );
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
bbox.Offset( -dx, 0 );
// Vertical justification
if( m_VJustify == GR_TEXT_VJUSTIFY_CENTER )
bbox.Offset( 0, -dy / 2 );
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
bbox.Offset( 0, -dy );
bbox.SetSize( dx, dy );
if( bbox.Inside( refPos ) )
return true;
return false;
} }
...@@ -469,6 +469,13 @@ public: ...@@ -469,6 +469,13 @@ public:
void Copy( LibDrawField* Target ); void Copy( LibDrawField* Target );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor, void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset, int aColor,
int aDrawMode, void * aData, int aTransformMatrix[2][2] ); int aDrawMode, void * aData, int aTransformMatrix[2][2] );
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param refPos A wxPoint to test, in Field coordinate system
* @return bool - true if a hit, else false
*/
bool HitTest( const wxPoint& refPos );
}; };
#endif // CLASSES_BODY_ITEMS_H #endif // CLASSES_BODY_ITEMS_H
...@@ -83,8 +83,6 @@ LibDrawField *Field = (LibDrawField *)CurrentDrawItem; ...@@ -83,8 +83,6 @@ LibDrawField *Field = (LibDrawField *)CurrentDrawItem;
if( (CurrentLibEntry == NULL) || (Field == NULL) ) return; if( (CurrentLibEntry == NULL) || (Field == NULL) ) return;
GRSetDrawMode(DC, g_XorMode);
switch (Field->m_FieldId) switch (Field->m_FieldId)
{ {
case VALUE: case VALUE:
...@@ -100,15 +98,19 @@ LibDrawField *Field = (LibDrawField *)CurrentDrawItem; ...@@ -100,15 +98,19 @@ LibDrawField *Field = (LibDrawField *)CurrentDrawItem;
break; break;
} }
int LineWidth = MAX(Field->m_Width, g_DrawMinimunLineWidth); wxString text = Field->m_Text;
if ( Field->m_FieldId == REFERENCE )
text << wxT("?");
int TransMat[2][2];
TransMat[0][0] = 1; TransMat[1][1] = -1;
TransMat[1][0] = TransMat[0][1] = 0;
if( Field->m_Attributs & TEXT_NO_VISIBLE ) color = DARKGRAY; if( Field->m_Attributs & TEXT_NO_VISIBLE ) color = DARKGRAY;
if( erase ) if( erase )
DrawGraphicText(panel, DC, Field->Draw( panel, DC, wxPoint(0,0),
wxPoint(LastTextPosition.x, - LastTextPosition.y), color,
color, Field->m_Text, g_XorMode, &text, TransMat );
Field->m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
Field->m_Size,
Field->m_HJustify, Field->m_VJustify, LineWidth);
LastTextPosition.x = panel->GetScreen()->m_Curseur.x; LastTextPosition.x = panel->GetScreen()->m_Curseur.x;
...@@ -116,12 +118,9 @@ int LineWidth = MAX(Field->m_Width, g_DrawMinimunLineWidth); ...@@ -116,12 +118,9 @@ int LineWidth = MAX(Field->m_Width, g_DrawMinimunLineWidth);
Field->m_Pos = LastTextPosition; Field->m_Pos = LastTextPosition;
DrawGraphicText(panel, DC, Field->Draw( panel, DC, wxPoint(0,0),
wxPoint(LastTextPosition.x, - LastTextPosition.y), color,
color, Field->m_Text, g_XorMode, &text, TransMat );
Field->m_Orient ? TEXT_ORIENT_VERT : TEXT_ORIENT_HORIZ,
Field->m_Size,
Field->m_HJustify, Field->m_VJustify, LineWidth);
} }
/*******************************************************************/ /*******************************************************************/
...@@ -289,68 +288,29 @@ int LineWidth = MAX(Field->m_Width, g_DrawMinimunLineWidth); ...@@ -289,68 +288,29 @@ int LineWidth = MAX(Field->m_Width, g_DrawMinimunLineWidth);
/****************************************************************************/ /****************************************************************************/
LibDrawField * WinEDA_LibeditFrame::LocateField(EDA_LibComponentStruct *LibEntry) LibDrawField * WinEDA_LibeditFrame::LocateField(EDA_LibComponentStruct *LibEntry)
/****************************************************************************/ /****************************************************************************/
/* Localise le champ (ref ou name) pointe par la souris /* Locate the component fiels (ref, name or auxiliary fields) under the mouse cursor
retourne: return:
pointeur sur le champ (NULL= Pas de champ) pointer on the field (or NULL )
*/ */
{ {
int x0, y0, x1, y1; /* Rectangle d'encadrement des textes a localiser */
int dx, dy; /* Dimensions du texte */ wxPoint refpos;
LibDrawField *Field; refpos.x = GetScreen()->m_Curseur.x;
int hjustify, vjustify; refpos.y = - GetScreen()->m_Curseur.y; // Y axis is from bottom to top in library
/* Test reference */
/* Localisation du Nom */ if ( LibEntry->m_Name.HitTest(refpos) )
x0 = LibEntry->m_Name.m_Pos.x;
y0 = - LibEntry->m_Name.m_Pos.y;
dx = LibEntry->m_Name.m_Size.x * LibEntry->m_Name.m_Text.Len(),
dy = LibEntry->m_Name.m_Size.y;
hjustify = LibEntry->m_Name.m_HJustify; vjustify = LibEntry->m_Name.m_VJustify;
if (LibEntry->m_Name.m_Orient) EXCHG(dx, dy);
if ( hjustify == GR_TEXT_HJUSTIFY_CENTER ) x0 -= dx/2;
else if ( hjustify == GR_TEXT_HJUSTIFY_RIGHT ) x0 -= dx;
if ( vjustify == GR_TEXT_VJUSTIFY_CENTER ) y0 -= dy/2;
else if ( vjustify == GR_TEXT_VJUSTIFY_BOTTOM ) y0 += dy;
x1 = x0 + dx; y1 = y0 + dy;
if( (GetScreen()->m_Curseur.x >= x0) && ( GetScreen()->m_Curseur.x <= x1) &&
(GetScreen()->m_Curseur.y >= y0) && ( GetScreen()->m_Curseur.y <= y1) )
return &LibEntry->m_Name; return &LibEntry->m_Name;
/* Localisation du Prefix */ /* Test Prefix */
x0 = LibEntry->m_Prefix.m_Pos.x; if( LibEntry->m_Prefix.HitTest(refpos) )
y0 = - LibEntry->m_Prefix.m_Pos.y;
dx = LibEntry->m_Prefix.m_Size.x *LibEntry->m_Prefix.m_Text.Len(),
dy = LibEntry->m_Prefix.m_Size.y;
hjustify = LibEntry->m_Prefix.m_HJustify; vjustify = LibEntry->m_Prefix.m_VJustify;
if (LibEntry->m_Prefix.m_Orient) EXCHG(dx, dy);
if ( hjustify == GR_TEXT_HJUSTIFY_CENTER ) x0 -= dx/2;
else if ( hjustify == GR_TEXT_HJUSTIFY_RIGHT ) x0 -= dx;
if ( vjustify == GR_TEXT_VJUSTIFY_CENTER ) y0 -= dy/2;
else if ( vjustify == GR_TEXT_VJUSTIFY_BOTTOM ) y0 -= dy;
x1 = x0 + dx; y1 = y0 + dy;
if( (GetScreen()->m_Curseur.x >= x0) && ( GetScreen()->m_Curseur.x <= x1) &&
(GetScreen()->m_Curseur.y >= y0) && ( GetScreen()->m_Curseur.y <= y1) )
return &LibEntry->m_Prefix; return &LibEntry->m_Prefix;
/* Localisation des autres fields */ /* Localisation des autres fields */
for (Field = LibEntry->Fields; Field != NULL; for (LibDrawField * Field = LibEntry->Fields; Field != NULL;
Field = (LibDrawField*)Field->Pnext) Field = (LibDrawField*)Field->Pnext)
{ {
if ( Field->m_Text.IsEmpty() ) continue; if ( Field->m_Text.IsEmpty() ) continue;
x0 = Field->m_Pos.x; y0 = - Field->m_Pos.y; if (Field->HitTest(refpos) )
dx = Field->m_Size.x * Field->m_Text.Len(),
dy = Field->m_Size.y;
hjustify = Field->m_HJustify; vjustify = Field->m_VJustify;
if (Field->m_Orient) EXCHG(dx, dy);
if (LibEntry->m_Prefix.m_Orient) EXCHG(dx, dy);
if ( hjustify == GR_TEXT_HJUSTIFY_CENTER ) x0 -= dx/2;
else if ( hjustify == GR_TEXT_HJUSTIFY_RIGHT ) x0 -= dx;
if ( vjustify == GR_TEXT_VJUSTIFY_CENTER ) y0 -= dy/2;
else if ( vjustify == GR_TEXT_VJUSTIFY_BOTTOM ) y0 -= dy;
x1 = x0 + dx; y1 = y0 + dy;
if( (GetScreen()->m_Curseur.x >= x0) && ( GetScreen()->m_Curseur.x <= x1) &&
(GetScreen()->m_Curseur.y >= y0) && ( GetScreen()->m_Curseur.y <= y1) )
return(Field); return(Field);
} }
......
...@@ -720,15 +720,18 @@ MODULE* WinEDA_BasePcbFrame::Create_1_Module( wxDC* DC, const wxString& module_n ...@@ -720,15 +720,18 @@ MODULE* WinEDA_BasePcbFrame::Create_1_Module( wxDC* DC, const wxString& module_n
/* Ask fo the new module reference */ /* Ask fo the new module reference */
if( module_name.IsEmpty() ) if( module_name.IsEmpty() )
{ {
if( Get_Message( _( "Module Reference:" ), _("Create module"), Line, this ) != 0 ) if( Get_Message( _( "Module Reference:" ), _("Module Creation:"), Line, this ) != 0 )
{
DisplayInfo(this, _("No reference, aborted"));
return NULL; return NULL;
} }
else else
Line = module_name; Line = module_name;
Line.Trim( TRUE ); Line.Trim( TRUE );
Line.Trim( FALSE ); Line.Trim( FALSE );
// Creates the new module and add it to te bigenning of the linked list of modules // Creates the new module and add it to the head of the linked list of modules
Module = new MODULE( m_Pcb ); Module = new MODULE( m_Pcb );
Module->Pnext = m_Pcb->m_Modules; Module->Pnext = m_Pcb->m_Modules;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment