2009-05-28 18:27:50 +00:00
|
|
|
/****************************************/
|
2010-12-10 19:47:44 +00:00
|
|
|
/* Basic classes for Kicad: */
|
|
|
|
/* EDA_ITEM */
|
|
|
|
/* EDA_TextStruct */
|
2009-05-28 18:27:50 +00:00
|
|
|
/****************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "trigo.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "macros.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "class_base_screen.h"
|
|
|
|
#include "drawtxt.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
enum textbox {
|
2007-08-04 20:05:54 +00:00
|
|
|
ID_TEXTBOX_LIST = 8010
|
2007-05-06 16:03:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( EDA_ITEM* parent, KICAD_T idType )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
InitVars();
|
|
|
|
m_StructType = idType;
|
2009-11-23 15:16:50 +00:00
|
|
|
m_Parent = parent;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( KICAD_T idType )
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
InitVars();
|
|
|
|
m_StructType = idType;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM::EDA_ITEM( const EDA_ITEM& base )
|
2009-09-25 18:49:04 +00:00
|
|
|
{
|
|
|
|
m_StructType = base.m_StructType;
|
|
|
|
m_Parent = base.m_Parent;
|
|
|
|
m_Son = base.m_Son;
|
|
|
|
m_Flags = base.m_Flags;
|
|
|
|
m_TimeStamp = base.m_TimeStamp;
|
|
|
|
m_Status = base.m_Status;
|
|
|
|
m_Selected = base.m_Selected;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void EDA_ITEM::InitVars()
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
m_StructType = TYPE_NOT_INIT;
|
2008-11-24 06:53:43 +00:00
|
|
|
Pnext = NULL; // Linked list: Link (next struct)
|
|
|
|
Pback = NULL; // Linked list: Link (previous struct)
|
|
|
|
m_Parent = NULL; // Linked list: Link (parent struct)
|
|
|
|
m_Son = NULL; // Linked list: Link (son struct)
|
|
|
|
m_List = NULL; // I am not on any list yet
|
|
|
|
m_Image = NULL; // Link to an image copy for undelete or abort command
|
|
|
|
m_Flags = 0; // flags for editions and other
|
|
|
|
m_TimeStamp = 0; // Time stamp used for logical links
|
2007-08-04 20:05:54 +00:00
|
|
|
m_Status = 0;
|
2008-11-24 06:53:43 +00:00
|
|
|
m_Selected = 0; // Used by block commands, and selective editing
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void EDA_ITEM::SetModified()
|
2010-12-07 16:10:42 +00:00
|
|
|
{
|
|
|
|
m_Flags |= IS_CHANGED;
|
|
|
|
|
|
|
|
// If this a child object, then the parent modification state also needs to be set.
|
|
|
|
if( m_Parent )
|
|
|
|
m_Parent->SetModified();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
// see base_struct.h
|
2010-12-08 20:12:46 +00:00
|
|
|
SEARCH_RESULT EDA_ITEM::IterateForward( EDA_ITEM* listStart,
|
|
|
|
INSPECTOR* inspector,
|
|
|
|
const void* testData,
|
|
|
|
const KICAD_T scanTypes[] )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2010-12-08 20:12:46 +00:00
|
|
|
EDA_ITEM* p = listStart;
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-09 21:15:08 +00:00
|
|
|
for( ; p; p = p->Pnext )
|
|
|
|
{
|
|
|
|
if( SEARCH_QUIT == p->Visit( inspector, testData, scanTypes ) )
|
|
|
|
return SEARCH_QUIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SEARCH_CONTINUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// see base_struct.h
|
|
|
|
// many classes inherit this method, be careful:
|
2010-12-08 20:12:46 +00:00
|
|
|
SEARCH_RESULT EDA_ITEM::Visit( INSPECTOR* inspector, const void* testData,
|
|
|
|
const KICAD_T scanTypes[] )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
KICAD_T stype;
|
2007-08-24 03:40:04 +00:00
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
#if 0 && defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
std::cout << GetClass().mb_str() << ' ';
|
2007-08-24 03:40:04 +00:00
|
|
|
#endif
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
for( const KICAD_T* p = scanTypes; (stype = *p) != EOT; ++p )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
|
|
|
// If caller wants to inspect my type
|
2007-09-01 12:00:30 +00:00
|
|
|
if( stype == Type() )
|
2007-08-09 21:15:08 +00:00
|
|
|
{
|
|
|
|
if( SEARCH_QUIT == inspector->Inspect( this, testData ) )
|
|
|
|
return SEARCH_QUIT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-13 16:44:14 +00:00
|
|
|
return SEARCH_CONTINUE;
|
2007-08-09 21:15:08 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
#if defined(DEBUG)
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
// A function that should have been in wxWidgets
|
2007-08-09 21:15:08 +00:00
|
|
|
std::ostream& operator<<( std::ostream& out, const wxSize& size )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
out << " width=\"" << size.GetWidth() << "\" height=\"" << size.GetHeight() << "\"";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-08 03:50:44 +00:00
|
|
|
// A function that should have been in wxWidgets
|
2007-08-09 21:15:08 +00:00
|
|
|
std::ostream& operator<<( std::ostream& out, const wxPoint& pt )
|
2007-08-08 03:50:44 +00:00
|
|
|
{
|
|
|
|
out << " x=\"" << pt.x << "\" y=\"" << pt.y << "\"";
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2008-03-13 16:44:14 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2007-08-06 02:02:39 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
void EDA_ITEM::Show( int nestLevel, std::ostream& os ) const
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-04-22 16:38:23 +00:00
|
|
|
// XML output:
|
2008-03-13 16:44:14 +00:00
|
|
|
wxString s = GetClass();
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << ">"
|
2008-12-16 19:44:57 +00:00
|
|
|
<< " Need ::Show() override for this class "
|
|
|
|
<< "</" << s.Lower().mb_str() << ">\n";
|
2007-08-06 02:02:39 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 16:44:14 +00:00
|
|
|
|
|
|
|
/**
|
2007-08-06 02:02:39 +00:00
|
|
|
* Function NestedSpace
|
|
|
|
* outputs nested space for pretty indenting.
|
|
|
|
* @param nestLevel The nest count
|
|
|
|
* @param os The ostream&, where to output
|
|
|
|
* @return std::ostream& - for continuation.
|
|
|
|
**/
|
2010-12-08 20:12:46 +00:00
|
|
|
std::ostream& EDA_ITEM::NestedSpace( int nestLevel, std::ostream& os )
|
2007-08-06 02:02:39 +00:00
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
for( int i = 0; i<nestLevel; ++i )
|
2008-12-16 19:44:57 +00:00
|
|
|
os << " ";
|
|
|
|
|
|
|
|
// number of spaces here controls indent per nest level
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2007-08-06 02:02:39 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
#endif
|
2007-08-06 02:02:39 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2007-09-13 11:28:58 +00:00
|
|
|
/**************************************************/
|
|
|
|
/* EDA_TextStruct (basic class, not directly used */
|
|
|
|
/**************************************************/
|
2007-08-04 20:05:54 +00:00
|
|
|
EDA_TextStruct::EDA_TextStruct( const wxString& text )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-12-16 19:44:57 +00:00
|
|
|
m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT; /* XY size of font */
|
|
|
|
m_Orient = 0; /* Orient in 0.1 degrees */
|
2007-08-04 20:05:54 +00:00
|
|
|
m_Attributs = 0;
|
2008-12-20 20:38:39 +00:00
|
|
|
m_Mirror = false; // display mirror if true
|
2009-05-01 16:46:56 +00:00
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
|
2008-12-16 19:44:57 +00:00
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; /* Justifications Horiz et Vert du texte */
|
2010-11-27 13:09:18 +00:00
|
|
|
m_Thickness = 0; /* thickness */
|
2009-04-29 12:10:15 +00:00
|
|
|
m_Italic = false; /* true = italic shape */
|
2009-05-28 17:39:40 +00:00
|
|
|
m_Bold = false;
|
2009-05-05 17:32:07 +00:00
|
|
|
m_MultilineAllowed = false; // Set to true only for texts that can use multiline.
|
2009-04-29 12:10:15 +00:00
|
|
|
m_Text = text;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_TextStruct::~EDA_TextStruct()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
/**
|
|
|
|
* Function LenSize
|
|
|
|
* @return the text lenght in internal units
|
|
|
|
* @param aLine : the line of text to consider.
|
|
|
|
* For single line text, this parameter is always m_Text
|
|
|
|
*/
|
2009-05-28 17:39:40 +00:00
|
|
|
int EDA_TextStruct::LenSize( const wxString& aLine ) const
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
return ReturnGraphicTextWidth(aLine, m_Size.x, m_Italic, m_Bold ) + m_Thickness;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect EDA_TextStruct::GetTextBox( int aLine, int aThickness, bool aInvertY ) const
|
2009-05-07 17:10:53 +00:00
|
|
|
{
|
|
|
|
EDA_Rect rect;
|
|
|
|
wxPoint pos;
|
|
|
|
wxArrayString* list = NULL;
|
2010-12-10 19:47:44 +00:00
|
|
|
wxString text = m_Text;
|
|
|
|
int thickness = ( aThickness < 0 ) ? m_Thickness : aThickness;
|
2009-05-07 17:10:53 +00:00
|
|
|
|
|
|
|
if( m_MultilineAllowed )
|
|
|
|
{
|
|
|
|
list = wxStringSplit( m_Text, '\n' );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-12-29 11:36:17 +00:00
|
|
|
if ( list->GetCount() ) // GetCount() == 0 for void strings
|
|
|
|
{
|
|
|
|
if( aLine >= 0 && (aLine < (int)list->GetCount()) )
|
2010-12-10 19:47:44 +00:00
|
|
|
text = list->Item( aLine );
|
2009-12-29 11:36:17 +00:00
|
|
|
else
|
2010-12-10 19:47:44 +00:00
|
|
|
text = list->Item( 0 );
|
2009-12-29 11:36:17 +00:00
|
|
|
}
|
2009-05-07 17:10:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// calculate the H and V size
|
2010-12-10 19:47:44 +00:00
|
|
|
int dx = LenSize( text );
|
2009-11-28 09:24:37 +00:00
|
|
|
int dy = GetInterline();
|
2009-05-07 17:10:53 +00:00
|
|
|
|
|
|
|
/* Creates bounding box (rectangle) for an horizontal text */
|
|
|
|
wxSize textsize = wxSize( dx, dy );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
if( aInvertY )
|
|
|
|
rect.SetOrigin( m_Pos.x, -m_Pos.y );
|
|
|
|
else
|
|
|
|
rect.SetOrigin( m_Pos );
|
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
// extra dy interval for letters like j and y and ]
|
|
|
|
int extra_dy = dy - m_Size.y;
|
2010-12-10 19:47:44 +00:00
|
|
|
rect.Move( wxPoint( 0, -extra_dy / 2 ) ); // move origin by the half extra interval
|
2009-05-07 17:10:53 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
// for multiline texts and aLine < 0, merge all rectangles
|
2009-12-29 11:36:17 +00:00
|
|
|
if( m_MultilineAllowed && list && aLine < 0 )
|
2009-05-07 17:10:53 +00:00
|
|
|
{
|
|
|
|
for( unsigned ii = 1; ii < list->GetCount(); ii++ )
|
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
text = list->Item( ii );
|
|
|
|
dx = LenSize( text );
|
2009-05-07 17:10:53 +00:00
|
|
|
textsize.x = MAX( textsize.x, dx );
|
|
|
|
textsize.y += dy;
|
|
|
|
}
|
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
delete list;
|
|
|
|
|
|
|
|
rect.SetSize( textsize );
|
2010-12-10 19:47:44 +00:00
|
|
|
rect.Inflate( thickness / 2 ); // ensure a small margin
|
2009-05-07 17:10:53 +00:00
|
|
|
|
|
|
|
/* Now, calculate the rect origin, according to text justification
|
2009-06-11 14:26:17 +00:00
|
|
|
* At this point the rectangle origin is the text origin (m_Pos).
|
2010-12-10 19:47:44 +00:00
|
|
|
* This is true only for left and top text justified texts (using top to bottom Y axis
|
|
|
|
* orientation). and must be recalculated for others justifications
|
2009-05-07 17:10:53 +00:00
|
|
|
* also, note the V justification is relative to the first line
|
|
|
|
*/
|
|
|
|
switch( m_HJustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_HJUSTIFY_LEFT:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_HJUSTIFY_CENTER:
|
|
|
|
rect.SetX( rect.GetX() - (rect.GetWidth() / 2) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_HJUSTIFY_RIGHT:
|
|
|
|
rect.SetX( rect.GetX() - rect.GetWidth() );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
dy = m_Size.y + thickness;
|
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
switch( m_VJustify )
|
|
|
|
{
|
|
|
|
case GR_TEXT_VJUSTIFY_TOP:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_CENTER:
|
|
|
|
rect.SetY( rect.GetY() - (dy / 2) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GR_TEXT_VJUSTIFY_BOTTOM:
|
2009-05-12 12:12:34 +00:00
|
|
|
rect.SetY( rect.GetY() - dy );
|
2009-05-07 17:10:53 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rect.Normalize(); // Make h and v sizes always >= 0
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
bool EDA_TextStruct::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-05-07 17:10:53 +00:00
|
|
|
EDA_Rect rect = GetTextBox( -1 ); // Get the full text area.
|
2010-12-10 19:47:44 +00:00
|
|
|
wxPoint location = aPoint;
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
rect.Inflate( aAccuracy );
|
2009-05-07 17:10:53 +00:00
|
|
|
RotatePoint( &location, m_Pos, -m_Orient );
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
return rect.Inside( location );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
bool EDA_TextStruct::TextHitTest( const EDA_Rect& aRect, bool aContains, int aAccuracy ) const
|
2008-01-06 12:43:57 +00:00
|
|
|
{
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContains )
|
|
|
|
return rect.Inside( GetTextBox( -1 ) );
|
|
|
|
|
|
|
|
return rect.Intersects( GetTextBox( -1 ) );
|
2008-01-06 12:43:57 +00:00
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************************/
|
2008-12-16 19:44:57 +00:00
|
|
|
void EDA_TextStruct::Draw( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
|
|
|
const wxPoint& aOffset, EDA_Colors aColor,
|
|
|
|
int aDrawMode,
|
2009-06-28 16:50:42 +00:00
|
|
|
GRTraceMode aFillMode, EDA_Colors aAnchor_color )
|
2007-05-06 16:03:28 +00:00
|
|
|
/***************************************************************/
|
2009-04-29 12:10:15 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Draw
|
2009-05-01 16:46:56 +00:00
|
|
|
* Draws this, that can be a multiline text
|
2008-12-16 19:44:57 +00:00
|
|
|
* @param aPanel = the current DrawPanel
|
|
|
|
* @param aDC = the current Device Context
|
|
|
|
* @param aOffset = draw offset (usually (0,0))
|
|
|
|
* @param EDA_Colors aColor = text color
|
|
|
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode.
|
2009-06-04 19:39:50 +00:00
|
|
|
* @param aFillMode = FILAIRE, FILLED or SKETCH
|
2008-12-16 19:44:57 +00:00
|
|
|
* @param EDA_Colors aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ).
|
2007-08-04 20:05:54 +00:00
|
|
|
*/
|
|
|
|
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2009-05-07 17:10:53 +00:00
|
|
|
if( m_MultilineAllowed )
|
2009-05-05 17:32:07 +00:00
|
|
|
{
|
|
|
|
wxPoint pos = m_Pos;
|
|
|
|
wxArrayString* list = wxStringSplit( m_Text, '\n' );
|
2009-05-07 17:10:53 +00:00
|
|
|
wxPoint offset;
|
2009-05-01 16:46:56 +00:00
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
offset.y = GetInterline();
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2009-05-05 17:32:07 +00:00
|
|
|
RotatePoint( &offset, m_Orient );
|
|
|
|
for( unsigned i = 0; i<list->Count(); i++ )
|
|
|
|
{
|
2009-05-07 17:10:53 +00:00
|
|
|
wxString txt = list->Item( i );
|
2009-05-05 17:32:07 +00:00
|
|
|
DrawOneLineOfText( aPanel,
|
2009-05-07 17:10:53 +00:00
|
|
|
aDC,
|
|
|
|
aOffset,
|
|
|
|
aColor,
|
|
|
|
aDrawMode,
|
2009-06-04 19:39:50 +00:00
|
|
|
aFillMode,
|
2009-05-07 17:10:53 +00:00
|
|
|
aAnchor_color,
|
|
|
|
txt,
|
|
|
|
pos );
|
2009-05-05 17:32:07 +00:00
|
|
|
pos += offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete (list);
|
|
|
|
}
|
|
|
|
else
|
2009-05-01 16:46:56 +00:00
|
|
|
DrawOneLineOfText( aPanel,
|
2009-05-07 17:10:53 +00:00
|
|
|
aDC,
|
|
|
|
aOffset,
|
|
|
|
aColor,
|
|
|
|
aDrawMode,
|
2009-06-04 19:39:50 +00:00
|
|
|
aFillMode,
|
2009-05-07 17:10:53 +00:00
|
|
|
aAnchor_color,
|
|
|
|
m_Text,
|
|
|
|
m_Pos );
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
2008-03-13 16:44:14 +00:00
|
|
|
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function DrawOneLineOfText
|
2009-05-01 16:46:56 +00:00
|
|
|
* Draw a single text line.
|
|
|
|
* Used to draw each line of this EDA_TextStruct, that can be multiline
|
|
|
|
* @param aPanel = the current DrawPanel
|
|
|
|
* @param aDC = the current Device Context
|
|
|
|
* @param aOffset = draw offset (usually (0,0))
|
|
|
|
* @param EDA_Colors aColor = text color
|
|
|
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode.
|
2009-06-04 19:39:50 +00:00
|
|
|
* @param aFillMode = FILAIRE, FILLED or SKETCH
|
2009-05-01 16:46:56 +00:00
|
|
|
* @param EDA_Colors aAnchor_color = anchor color ( UNSPECIFIED_COLOR = do not draw anchor ).
|
|
|
|
* @param EDA_Colors aText = the single line of text to draw.
|
|
|
|
* @param EDA_Colors aPos = the position of this line ).
|
|
|
|
*/
|
|
|
|
void EDA_TextStruct::DrawOneLineOfText( WinEDA_DrawPanel* aPanel, wxDC* aDC,
|
2009-05-07 17:10:53 +00:00
|
|
|
const wxPoint& aOffset, EDA_Colors aColor,
|
|
|
|
int aDrawMode,
|
2009-06-28 16:50:42 +00:00
|
|
|
GRTraceMode aFillMode, EDA_Colors aAnchor_color,
|
2009-05-07 17:10:53 +00:00
|
|
|
wxString& aText, wxPoint aPos )
|
2009-04-28 19:34:42 +00:00
|
|
|
{
|
2010-11-27 13:09:18 +00:00
|
|
|
int width = m_Thickness;
|
2009-04-29 12:10:15 +00:00
|
|
|
|
2009-06-04 19:39:50 +00:00
|
|
|
if( aFillMode == FILAIRE )
|
2009-04-29 12:10:15 +00:00
|
|
|
width = 0;
|
|
|
|
|
|
|
|
if( aDrawMode != -1 )
|
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
/* Draw text anchor, if allowed */
|
|
|
|
if( aAnchor_color != UNSPECIFIED_COLOR )
|
|
|
|
{
|
2010-02-08 18:15:42 +00:00
|
|
|
|
|
|
|
#if USE_WX_ZOOM
|
|
|
|
int anchor_size = aDC->DeviceToLogicalXRel( 2 );
|
|
|
|
#else
|
2009-04-29 12:10:15 +00:00
|
|
|
int anchor_size = aPanel->GetScreen()->Unscale( 2 );
|
2010-02-08 18:15:42 +00:00
|
|
|
#endif
|
|
|
|
|
2009-05-07 17:10:53 +00:00
|
|
|
aAnchor_color = (EDA_Colors) ( aAnchor_color & MASKCOLOR );
|
2009-04-29 12:10:15 +00:00
|
|
|
|
2009-05-01 16:46:56 +00:00
|
|
|
int cX = aPos.x + aOffset.x;
|
|
|
|
int cY = aPos.y + aOffset.y;
|
2009-04-29 12:10:15 +00:00
|
|
|
|
|
|
|
GRLine( &aPanel->m_ClipBox, aDC, cX - anchor_size, cY,
|
|
|
|
cX + anchor_size, cY, 0, aAnchor_color );
|
|
|
|
|
|
|
|
GRLine( &aPanel->m_ClipBox, aDC, cX, cY - anchor_size,
|
|
|
|
cX, cY + anchor_size, 0, aAnchor_color );
|
|
|
|
}
|
|
|
|
|
2009-06-04 19:39:50 +00:00
|
|
|
if( aFillMode == SKETCH )
|
2009-04-29 12:10:15 +00:00
|
|
|
width = -width;
|
|
|
|
|
|
|
|
wxSize size = m_Size;
|
|
|
|
|
|
|
|
if( m_Mirror )
|
|
|
|
size.x = -size.x;
|
|
|
|
|
|
|
|
DrawGraphicText( aPanel, aDC,
|
2009-05-01 16:46:56 +00:00
|
|
|
aOffset + aPos, aColor, aText,
|
2009-04-29 12:10:15 +00:00
|
|
|
m_Orient, size,
|
2009-05-28 17:39:40 +00:00
|
|
|
m_HJustify, m_VJustify, width, m_Italic, m_Bold );
|
2009-04-28 19:34:42 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-11-17 18:41:20 +00:00
|
|
|
/**
|
|
|
|
* Function GetStyleName
|
|
|
|
* @return a wwString withe the style name( Normal, Italic, Bold, Bold+Italic)
|
|
|
|
*/
|
|
|
|
wxString EDA_TextStruct::GetTextStyleName()
|
|
|
|
{
|
|
|
|
int style = 0;
|
|
|
|
if( m_Italic )
|
|
|
|
style = 1;
|
|
|
|
if( m_Bold )
|
|
|
|
style += 2;
|
|
|
|
wxString stylemsg[4] = {
|
|
|
|
_("Normal"),
|
|
|
|
_("Italic"),
|
|
|
|
_("Bold"),
|
|
|
|
_("Bold+Italic")
|
|
|
|
};
|
|
|
|
|
|
|
|
return stylemsg[style];
|
|
|
|
}
|
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
|
2008-12-16 19:44:57 +00:00
|
|
|
/******************/
|
|
|
|
/* Class EDA_Rect */
|
|
|
|
/******************/
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
void EDA_Rect::Normalize()
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************/
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
// Ensure the height ant width are >= 0
|
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
if( m_Size.y < 0 )
|
|
|
|
{
|
|
|
|
m_Size.y = -m_Size.y;
|
|
|
|
m_Pos.y -= m_Size.y;
|
|
|
|
}
|
|
|
|
if( m_Size.x < 0 )
|
|
|
|
{
|
|
|
|
m_Size.x = -m_Size.x;
|
|
|
|
m_Pos.x -= m_Size.x;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Move
|
2009-11-28 09:24:37 +00:00
|
|
|
* Move this rectangle by the aMoveVector value (this is a relative move)
|
|
|
|
* @param aMoveVector = a wxPoint that is the value to move this rectangle
|
|
|
|
*/
|
|
|
|
void EDA_Rect::Move( const wxPoint& aMoveVector )
|
|
|
|
{
|
|
|
|
m_Pos += aMoveVector;
|
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Return TRUE if point is in Rect
|
2007-08-04 20:05:54 +00:00
|
|
|
* Accept rect size < 0
|
|
|
|
*/
|
2010-12-10 19:47:44 +00:00
|
|
|
bool EDA_Rect::Inside( const wxPoint& point ) const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-04 20:05:54 +00:00
|
|
|
int rel_posx = point.x - m_Pos.x;
|
|
|
|
int rel_posy = point.y - m_Pos.y;
|
2009-04-29 12:10:15 +00:00
|
|
|
wxSize size = m_Size;
|
2007-08-04 20:05:54 +00:00
|
|
|
|
|
|
|
if( size.x < 0 )
|
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
size.x = -size.x;
|
2008-01-19 20:34:10 +00:00
|
|
|
rel_posx += size.x;
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( size.y < 0 )
|
|
|
|
{
|
2008-03-15 10:24:32 +00:00
|
|
|
size.y = -size.y;
|
2008-01-19 20:34:10 +00:00
|
|
|
rel_posy += size.y;
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-13 16:44:14 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
return (rel_posx >= 0) && (rel_posy >= 0) && ( rel_posy <= size.y) && ( rel_posx <= size.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool EDA_Rect::Inside( const EDA_Rect& aRect ) const
|
|
|
|
{
|
|
|
|
wxRect rect = aRect;
|
|
|
|
wxRect me = wxRect();
|
|
|
|
|
|
|
|
return me.Contains( rect );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-04 20:05:54 +00:00
|
|
|
|
2008-03-13 16:44:14 +00:00
|
|
|
bool EDA_Rect::Intersects( const EDA_Rect aRect ) const
|
|
|
|
{
|
|
|
|
// this logic taken from wxWidgets' geometry.cpp file:
|
2008-05-17 19:10:36 +00:00
|
|
|
bool rc;
|
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
int left = MAX( m_Pos.x, aRect.m_Pos.x );
|
|
|
|
int right = MIN( m_Pos.x + m_Size.x, aRect.m_Pos.x + aRect.m_Size.x );
|
|
|
|
int top = MAX( m_Pos.y, aRect.m_Pos.y );
|
|
|
|
int bottom = MIN( m_Pos.y + m_Size.y, aRect.m_Pos.y + aRect.m_Size.y );
|
2008-03-13 16:44:14 +00:00
|
|
|
|
|
|
|
if( left < right && top < bottom )
|
2008-05-17 19:10:36 +00:00
|
|
|
rc = true;
|
|
|
|
else
|
|
|
|
rc = false;
|
|
|
|
|
|
|
|
return rc;
|
2008-03-13 16:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-21 19:16:25 +00:00
|
|
|
/**************************************************/
|
|
|
|
EDA_Rect& EDA_Rect::Inflate( int aDelta )
|
|
|
|
/**************************************************/
|
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Inflate
|
2009-10-21 19:16:25 +00:00
|
|
|
* Inflate "this": move each horizontal edgeand each vertical edge by aDelta
|
|
|
|
* toward rect outside
|
|
|
|
* if aDelta is negative, move toward rect inside (deflate)
|
|
|
|
* Works for positive and negative rect size
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
Inflate( aDelta, aDelta );
|
2009-10-23 14:35:24 +00:00
|
|
|
return *this;
|
2009-10-21 19:16:25 +00:00
|
|
|
}
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/**************************************************/
|
2007-08-04 20:05:54 +00:00
|
|
|
EDA_Rect& EDA_Rect::Inflate( wxCoord dx, wxCoord dy )
|
2007-05-06 16:03:28 +00:00
|
|
|
/**************************************************/
|
2008-03-18 11:53:52 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function Inflate
|
2008-03-18 11:53:52 +00:00
|
|
|
* Inflate "this": move each horizontal edge by dx and each vertical edge by dy
|
|
|
|
* toward rect outside
|
|
|
|
* if dx and/or dy is negative, move toward rect inside (deflate)
|
|
|
|
* Works for positive and negative rect size
|
|
|
|
*
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x >= 0 )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x < -2 * dx )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more width than we have,
|
|
|
|
m_Pos.x += m_Size.x / 2;
|
|
|
|
m_Size.x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.x -= dx;
|
|
|
|
m_Size.x += 2 * dx;
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-18 11:53:52 +00:00
|
|
|
else // size.x < 0:
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.x > -2 * dx )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more width than we have,
|
|
|
|
m_Pos.x -= m_Size.x / 2;
|
|
|
|
m_Size.x = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.x += dx;
|
|
|
|
m_Size.x -= 2 * dx; // m_Size.x <0: inflate when dx > 0
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
|
|
|
|
2008-03-18 11:53:52 +00:00
|
|
|
|
|
|
|
if( m_Size.y >= 0 )
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.y < -2 * dy )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more height than we have,
|
|
|
|
m_Pos.y += m_Size.y / 2;
|
|
|
|
m_Size.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.y -= dy;
|
|
|
|
m_Size.y += 2 * dy;
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2008-03-18 11:53:52 +00:00
|
|
|
else // size.y < 0:
|
2007-08-04 20:05:54 +00:00
|
|
|
{
|
2008-03-18 11:53:52 +00:00
|
|
|
if( m_Size.y > 2 * dy )
|
|
|
|
{
|
|
|
|
// Don't allow deflate to eat more height than we have,
|
|
|
|
m_Pos.y -= m_Size.y / 2;
|
|
|
|
m_Size.y = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The inflate is valid.
|
|
|
|
m_Pos.y += dy;
|
|
|
|
m_Size.y -= 2 * dy; // m_Size.y <0: inflate when dy > 0
|
|
|
|
}
|
2007-08-04 20:05:54 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
/**
|
|
|
|
* Function Merge
|
|
|
|
* modifies Position and Size of this in order to contain the given rect
|
2008-03-15 10:24:32 +00:00
|
|
|
* mainly used to calculate bounding boxes
|
|
|
|
* @param aRect = given rect to merge with this
|
|
|
|
*/
|
2008-03-16 04:47:43 +00:00
|
|
|
void EDA_Rect::Merge( const EDA_Rect& aRect )
|
2008-03-15 10:24:32 +00:00
|
|
|
{
|
|
|
|
Normalize(); // ensure width and height >= 0
|
|
|
|
EDA_Rect rect = aRect;
|
|
|
|
rect.Normalize(); // ensure width and height >= 0
|
2009-04-29 12:10:15 +00:00
|
|
|
wxPoint end = GetEnd();
|
2008-03-18 11:53:52 +00:00
|
|
|
wxPoint rect_end = rect.GetEnd();
|
2008-03-15 10:24:32 +00:00
|
|
|
|
2008-03-16 04:47:43 +00:00
|
|
|
// Change origin and size in order to contain the given rect
|
|
|
|
m_Pos.x = MIN( m_Pos.x, rect.m_Pos.x );
|
2008-03-15 10:24:32 +00:00
|
|
|
m_Pos.y = MIN( m_Pos.y, rect.m_Pos.y );
|
2008-03-18 11:53:52 +00:00
|
|
|
end.x = MAX( end.x, rect_end.x );
|
|
|
|
end.y = MAX( end.y, rect_end.y );
|
2008-03-15 10:24:32 +00:00
|
|
|
SetEnd( end );
|
|
|
|
}
|
2010-11-17 18:41:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Merge
|
|
|
|
* modifies Position and Size of this in order to contain the given point
|
|
|
|
* mainly used to calculate bounding boxes
|
|
|
|
* @param aPoint = given point to merge with this
|
|
|
|
*/
|
|
|
|
void EDA_Rect::Merge( const wxPoint& aPoint )
|
|
|
|
{
|
|
|
|
Normalize(); // ensure width and height >= 0
|
|
|
|
|
|
|
|
wxPoint end = GetEnd();
|
|
|
|
// Change origin and size in order to contain the given rect
|
|
|
|
m_Pos.x = MIN( m_Pos.x, aPoint.x );
|
|
|
|
m_Pos.y = MIN( m_Pos.y, aPoint.y );
|
|
|
|
end.x = MAX( end.x, aPoint.x );
|
|
|
|
end.y = MAX( end.y, aPoint.y );
|
|
|
|
SetEnd( end );
|
|
|
|
}
|