Commit 09701a74 authored by charras's avatar charras

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

parent 97cfebcb
...@@ -342,3 +342,48 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOf ...@@ -342,3 +342,48 @@ void LibDrawField::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC, const wxPoint& aOf
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