Browse Source
Internal unit improvements and Pcbnew s-expression file format changes.
Internal unit improvements and Pcbnew s-expression file format changes.
* Move EDA_TEXT object into separate header and source file. * Compile EDA_TEXT class separately for BOARD_ITEM and SCH_ITEM units. * Compile PAGE_INFO class separately for BOARD_ITEM and SCH_ITEM units. * Minor formatting tweaks to Pcbnew s-expression file. * Move internal unit formatting functions into BOARD_ITEM and SCH_ITEM.pull/1/head
41 changed files with 986 additions and 837 deletions
-
14bitmap2component/bitmap2cmp_gui.cpp
-
3common/CMakeLists.txt
-
362common/base_struct.cpp
-
5common/class_page_info.cpp
-
12common/common.cpp
-
3common/drawtxt.cpp
-
405common/eda_text.cpp
-
49common/sch_item_struct.cpp
-
2eeschema/CMakeLists.txt
-
1eeschema/eeschema.cpp
-
1eeschema/lib_field.h
-
2eeschema/lib_text.h
-
1eeschema/sch_field.h
-
17eeschema/sch_screen.cpp
-
1eeschema/sch_text.h
-
264include/base_struct.h
-
31include/class_board_item.h
-
18include/common.h
-
1include/drawtxt.h
-
271include/eda_text.h
-
1include/plot_common.h
-
29include/sch_item_struct.h
-
1include/wxBasePcbFrame.h
-
13kicad/mainframe.cpp
-
12pcb_calculator/pcb_calculator_frame.cpp
-
74pcbnew/class_board.cpp
-
40pcbnew/class_board_item.cpp
-
60pcbnew/class_dimension.cpp
-
30pcbnew/class_drawsegment.cpp
-
2pcbnew/class_edge_mod.cpp
-
6pcbnew/class_mire.cpp
-
14pcbnew/class_module.cpp
-
18pcbnew/class_netclass.cpp
-
26pcbnew/class_pad.cpp
-
1pcbnew/class_pcb_text.h
-
2pcbnew/class_text_mod.cpp
-
1pcbnew/class_text_mod.h
-
8pcbnew/class_track.cpp
-
18pcbnew/class_zone.cpp
-
2pcbnew/classpcb.cpp
-
2pcbnew/pcb_plot_params.h
@ -0,0 +1,405 @@ |
|||||
|
/*
|
||||
|
* This program source code file is part of KiCad, a free EDA CAD application. |
||||
|
* |
||||
|
* Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com |
||||
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. |
||||
|
* |
||||
|
* This program is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU General Public License |
||||
|
* as published by the Free Software Foundation; either version 2 |
||||
|
* of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program; if not, you may find one here: |
||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
|
* or you may write to the Free Software Foundation, Inc., |
||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
||||
|
*/ |
||||
|
|
||||
|
/**
|
||||
|
* @file eda_text.cpp |
||||
|
* @brief Implementation of base KiCad text object. |
||||
|
*/ |
||||
|
|
||||
|
#include <eda_text.h>
|
||||
|
#include <drawtxt.h>
|
||||
|
#include <macros.h> // MAX
|
||||
|
#include <trigo.h> // RotatePoint
|
||||
|
#include <class_drawpanel.h> // EDA_DRAW_PANEL
|
||||
|
|
||||
|
|
||||
|
// Conversion to application internal units defined at build time.
|
||||
|
#if defined( PCBNEW )
|
||||
|
#include <class_board_item.h>
|
||||
|
#if defined( USE_PCBNEW_NANOMETRES )
|
||||
|
#define MILS_TO_IU( x ) ( x * 25400 );
|
||||
|
#else
|
||||
|
#define MILS_TO_IU( x ) ( x * 10 )
|
||||
|
#endif
|
||||
|
#elif defined( EESCHEMA )
|
||||
|
#include <sch_item_struct.h>
|
||||
|
#define MILS_TO_IU( x ) ( x )
|
||||
|
#else
|
||||
|
#error "Cannot resolve units formatting due to no definition of EESCHEMA or PCBNEW."
|
||||
|
#endif
|
||||
|
|
||||
|
|
||||
|
EDA_TEXT::EDA_TEXT( const wxString& text ) |
||||
|
{ |
||||
|
m_Size.x = m_Size.y = MILS_TO_IU( DEFAULT_SIZE_TEXT ); // Width and height of font.
|
||||
|
m_Orient = 0; // Rotation angle in 0.1 degrees.
|
||||
|
m_Attributs = 0; |
||||
|
m_Mirror = false; // display mirror if true
|
||||
|
m_HJustify = GR_TEXT_HJUSTIFY_CENTER; // Default horizontal justification is centered.
|
||||
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; // Default vertical justification is centered.
|
||||
|
m_Thickness = 0; // thickness
|
||||
|
m_Italic = false; // true = italic shape.
|
||||
|
m_Bold = false; |
||||
|
m_MultilineAllowed = false; // Set to true for multiline text.
|
||||
|
m_Text = text; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
EDA_TEXT::EDA_TEXT( const EDA_TEXT& aText ) |
||||
|
{ |
||||
|
m_Pos = aText.m_Pos; |
||||
|
m_Size = aText.m_Size; |
||||
|
m_Orient = aText.m_Orient; |
||||
|
m_Attributs = aText.m_Attributs; |
||||
|
m_Mirror = aText.m_Mirror; |
||||
|
m_HJustify = aText.m_HJustify; |
||||
|
m_VJustify = aText.m_VJustify; |
||||
|
m_Thickness = aText.m_Thickness; |
||||
|
m_Italic = aText.m_Italic; |
||||
|
m_Bold = aText.m_Bold; |
||||
|
m_MultilineAllowed = aText.m_MultilineAllowed; |
||||
|
m_Text = aText.m_Text; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
EDA_TEXT::~EDA_TEXT() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
int EDA_TEXT::LenSize( const wxString& aLine ) const |
||||
|
{ |
||||
|
return ReturnGraphicTextWidth( aLine, m_Size.x, m_Italic, m_Bold ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
EDA_RECT EDA_TEXT::GetTextBox( int aLine, int aThickness, bool aInvertY ) const |
||||
|
{ |
||||
|
EDA_RECT rect; |
||||
|
wxPoint pos; |
||||
|
wxArrayString* list = NULL; |
||||
|
wxString text = m_Text; |
||||
|
int thickness = ( aThickness < 0 ) ? m_Thickness : aThickness; |
||||
|
|
||||
|
if( m_MultilineAllowed ) |
||||
|
{ |
||||
|
list = wxStringSplit( m_Text, '\n' ); |
||||
|
|
||||
|
if ( list->GetCount() ) // GetCount() == 0 for void strings
|
||||
|
{ |
||||
|
if( aLine >= 0 && (aLine < (int)list->GetCount()) ) |
||||
|
text = list->Item( aLine ); |
||||
|
else |
||||
|
text = list->Item( 0 ); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// calculate the H and V size
|
||||
|
int dx = LenSize( text ); |
||||
|
int dy = GetInterline(); |
||||
|
|
||||
|
/* Creates bounding box (rectangle) for an horizontal text */ |
||||
|
wxSize textsize = wxSize( dx, dy ); |
||||
|
|
||||
|
if( aInvertY ) |
||||
|
rect.SetOrigin( m_Pos.x, -m_Pos.y ); |
||||
|
else |
||||
|
rect.SetOrigin( m_Pos ); |
||||
|
|
||||
|
// extra dy interval for letters like j and y and ]
|
||||
|
int extra_dy = dy - m_Size.y; |
||||
|
rect.Move( wxPoint( 0, -extra_dy / 2 ) ); // move origin by the half extra interval
|
||||
|
|
||||
|
// for multiline texts and aLine < 0, merge all rectangles
|
||||
|
if( m_MultilineAllowed && list && aLine < 0 ) |
||||
|
{ |
||||
|
for( unsigned ii = 1; ii < list->GetCount(); ii++ ) |
||||
|
{ |
||||
|
text = list->Item( ii ); |
||||
|
dx = LenSize( text ); |
||||
|
textsize.x = MAX( textsize.x, dx ); |
||||
|
textsize.y += dy; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
delete list; |
||||
|
|
||||
|
rect.SetSize( textsize ); |
||||
|
|
||||
|
/* Now, calculate the rect origin, according to text justification
|
||||
|
* At this point the rectangle origin is the text origin (m_Pos). |
||||
|
* 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 |
||||
|
* also, note the V justification is relative to the first line |
||||
|
*/ |
||||
|
switch( m_HJustify ) |
||||
|
{ |
||||
|
case GR_TEXT_HJUSTIFY_LEFT: |
||||
|
if( m_Mirror ) |
||||
|
rect.SetX( rect.GetX() - rect.GetWidth() ); |
||||
|
break; |
||||
|
|
||||
|
case GR_TEXT_HJUSTIFY_CENTER: |
||||
|
rect.SetX( rect.GetX() - (rect.GetWidth() / 2) ); |
||||
|
break; |
||||
|
|
||||
|
case GR_TEXT_HJUSTIFY_RIGHT: |
||||
|
if( !m_Mirror ) |
||||
|
rect.SetX( rect.GetX() - rect.GetWidth() ); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
dy = m_Size.y + thickness; |
||||
|
|
||||
|
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: |
||||
|
rect.SetY( rect.GetY() - dy ); |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
rect.Inflate( thickness / 2 ); |
||||
|
rect.Normalize(); // Make h and v sizes always >= 0
|
||||
|
|
||||
|
return rect; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool EDA_TEXT::TextHitTest( const wxPoint& aPoint, int aAccuracy ) const |
||||
|
{ |
||||
|
EDA_RECT rect = GetTextBox( -1 ); // Get the full text area.
|
||||
|
wxPoint location = aPoint; |
||||
|
|
||||
|
rect.Inflate( aAccuracy ); |
||||
|
RotatePoint( &location, m_Pos, -m_Orient ); |
||||
|
|
||||
|
return rect.Contains( location ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool EDA_TEXT::TextHitTest( const EDA_RECT& aRect, bool aContains, int aAccuracy ) const |
||||
|
{ |
||||
|
EDA_RECT rect = aRect; |
||||
|
|
||||
|
rect.Inflate( aAccuracy ); |
||||
|
|
||||
|
if( aContains ) |
||||
|
return rect.Contains( GetTextBox( -1 ) ); |
||||
|
|
||||
|
return rect.Intersects( GetTextBox( -1 ) ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void EDA_TEXT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, |
||||
|
EDA_COLOR_T aColor, int aDrawMode, |
||||
|
EDA_DRAW_MODE_T aFillMode, EDA_COLOR_T aAnchor_color ) |
||||
|
{ |
||||
|
if( m_MultilineAllowed ) |
||||
|
{ |
||||
|
wxPoint pos = m_Pos; |
||||
|
wxArrayString* list = wxStringSplit( m_Text, '\n' ); |
||||
|
wxPoint offset; |
||||
|
|
||||
|
offset.y = GetInterline(); |
||||
|
|
||||
|
RotatePoint( &offset, m_Orient ); |
||||
|
|
||||
|
for( unsigned i = 0; i<list->Count(); i++ ) |
||||
|
{ |
||||
|
wxString txt = list->Item( i ); |
||||
|
DrawOneLineOfText( aPanel, |
||||
|
aDC, |
||||
|
aOffset, |
||||
|
aColor, |
||||
|
aDrawMode, |
||||
|
aFillMode, |
||||
|
i ? UNSPECIFIED : aAnchor_color, |
||||
|
txt, |
||||
|
pos ); |
||||
|
pos += offset; |
||||
|
} |
||||
|
|
||||
|
delete (list); |
||||
|
} |
||||
|
else |
||||
|
DrawOneLineOfText( aPanel, |
||||
|
aDC, |
||||
|
aOffset, |
||||
|
aColor, |
||||
|
aDrawMode, |
||||
|
aFillMode, |
||||
|
aAnchor_color, |
||||
|
m_Text, |
||||
|
m_Pos ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void EDA_TEXT::DrawOneLineOfText( EDA_DRAW_PANEL* aPanel, wxDC* aDC, |
||||
|
const wxPoint& aOffset, EDA_COLOR_T aColor, |
||||
|
int aDrawMode, EDA_DRAW_MODE_T aFillMode, |
||||
|
EDA_COLOR_T aAnchor_color, |
||||
|
wxString& aText, wxPoint aPos ) |
||||
|
{ |
||||
|
int width = m_Thickness; |
||||
|
|
||||
|
if( aFillMode == LINE ) |
||||
|
width = 0; |
||||
|
|
||||
|
if( aDrawMode != -1 ) |
||||
|
GRSetDrawMode( aDC, aDrawMode ); |
||||
|
|
||||
|
/* Draw text anchor, if allowed */ |
||||
|
if( aAnchor_color != UNSPECIFIED ) |
||||
|
{ |
||||
|
|
||||
|
int anchor_size = aDC->DeviceToLogicalXRel( 2 ); |
||||
|
|
||||
|
aAnchor_color = (EDA_COLOR_T) ( aAnchor_color & MASKCOLOR ); |
||||
|
|
||||
|
int cX = aPos.x + aOffset.x; |
||||
|
int cY = aPos.y + aOffset.y; |
||||
|
|
||||
|
GRLine( aPanel->GetClipBox(), aDC, cX - anchor_size, cY, |
||||
|
cX + anchor_size, cY, 0, aAnchor_color ); |
||||
|
|
||||
|
GRLine( aPanel->GetClipBox(), aDC, cX, cY - anchor_size, |
||||
|
cX, cY + anchor_size, 0, aAnchor_color ); |
||||
|
} |
||||
|
|
||||
|
if( aFillMode == SKETCH ) |
||||
|
width = -width; |
||||
|
|
||||
|
wxSize size = m_Size; |
||||
|
|
||||
|
if( m_Mirror ) |
||||
|
size.x = -size.x; |
||||
|
|
||||
|
DrawGraphicText( aPanel, aDC, aOffset + aPos, aColor, aText, m_Orient, size, |
||||
|
m_HJustify, m_VJustify, width, m_Italic, m_Bold ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
wxString EDA_TEXT::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]; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
bool EDA_TEXT::IsDefaultFormatting() const |
||||
|
{ |
||||
|
return ( ( m_Size.x == DEFAULT_SIZE_TEXT ) |
||||
|
&& ( m_Size.y == DEFAULT_SIZE_TEXT ) |
||||
|
&& ( m_Attributs == 0 ) |
||||
|
&& ( m_Mirror == false ) |
||||
|
&& ( m_HJustify == GR_TEXT_HJUSTIFY_CENTER ) |
||||
|
&& ( m_VJustify == GR_TEXT_VJUSTIFY_CENTER ) |
||||
|
&& ( m_Thickness == 0 ) |
||||
|
&& ( m_Italic == false ) |
||||
|
&& ( m_Bold == false ) |
||||
|
&& ( m_MultilineAllowed == false ) ); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
void EDA_TEXT::Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const |
||||
|
throw( IO_ERROR ) |
||||
|
{ |
||||
|
aFormatter->Print( aNestLevel, "(text %s (at %s", |
||||
|
aFormatter->Quotew( m_Text ).c_str(), FMT_IU( m_Pos ).c_str() ); |
||||
|
|
||||
|
if( m_Orient != 0.0 ) |
||||
|
aFormatter->Print( 0, " %s", FMT_ANGLE( m_Orient ).c_str() ); |
||||
|
|
||||
|
aFormatter->Print( 0, ")\n" ); |
||||
|
|
||||
|
if( !IsDefaultFormatting() ) |
||||
|
{ |
||||
|
aFormatter->Print( aNestLevel+1, "(effects\n" ); |
||||
|
|
||||
|
if( ( m_Size.x != DEFAULT_SIZE_TEXT ) || ( m_Size.y != DEFAULT_SIZE_TEXT ) || m_Bold |
||||
|
|| m_Italic ) |
||||
|
{ |
||||
|
aFormatter->Print( aNestLevel+2, "(font" ); |
||||
|
|
||||
|
// Add font support here at some point in the future.
|
||||
|
|
||||
|
if( ( m_Size.x != DEFAULT_SIZE_TEXT ) || ( m_Size.y != DEFAULT_SIZE_TEXT ) ) |
||||
|
aFormatter->Print( 0, " (size %s)", FMT_IU( m_Size ).c_str() ); |
||||
|
|
||||
|
if( m_Bold ) |
||||
|
aFormatter->Print( 0, " bold" ); |
||||
|
|
||||
|
if( m_Bold ) |
||||
|
aFormatter->Print( 0, " italic" ); |
||||
|
|
||||
|
aFormatter->Print( 0, ")\n"); |
||||
|
} |
||||
|
|
||||
|
if( m_Mirror || ( m_HJustify != GR_TEXT_HJUSTIFY_CENTER ) |
||||
|
|| ( m_VJustify != GR_TEXT_VJUSTIFY_CENTER ) ) |
||||
|
{ |
||||
|
aFormatter->Print( aNestLevel+2, "(justify"); |
||||
|
|
||||
|
if( m_HJustify != GR_TEXT_HJUSTIFY_CENTER ) |
||||
|
aFormatter->Print( 0, (m_HJustify == GR_TEXT_HJUSTIFY_LEFT) ? " left" : " right" ); |
||||
|
|
||||
|
if( m_VJustify != GR_TEXT_VJUSTIFY_CENTER ) |
||||
|
aFormatter->Print( 0, (m_VJustify == GR_TEXT_VJUSTIFY_TOP) ? " top" : " bottom" ); |
||||
|
|
||||
|
if( m_Mirror ) |
||||
|
aFormatter->Print( 0, " mirror" ); |
||||
|
|
||||
|
aFormatter->Print( 0, ")\n" ); |
||||
|
} |
||||
|
|
||||
|
// As of now the only place this is used is in Eeschema to hide or show the text.
|
||||
|
if( m_Attributs ) |
||||
|
aFormatter->Print( aNestLevel+2, "hide\n" ); |
||||
|
|
||||
|
aFormatter->Print( aNestLevel+1, ")\n" ); |
||||
|
} |
||||
|
|
||||
|
aFormatter->Print( aNestLevel, ")\n" ); |
||||
|
} |
||||
@ -0,0 +1,271 @@ |
|||||
|
/* |
||||
|
* This program source code file is part of KiCad, a free EDA CAD application. |
||||
|
* |
||||
|
* Copyright (C) 2004 Jean-Pierre Charras, jean-pierre.charras@gipsa-lab.inpg.com |
||||
|
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors. |
||||
|
* |
||||
|
* This program is free software; you can redistribute it and/or |
||||
|
* modify it under the terms of the GNU General Public License |
||||
|
* as published by the Free Software Foundation; either version 2 |
||||
|
* of the License, or (at your option) any later version. |
||||
|
* |
||||
|
* This program is distributed in the hope that it will be useful, |
||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
* GNU General Public License for more details. |
||||
|
* |
||||
|
* You should have received a copy of the GNU General Public License |
||||
|
* along with this program; if not, you may find one here: |
||||
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
||||
|
* or you may search the http://www.gnu.org website for the version 2 license, |
||||
|
* or you may write to the Free Software Foundation, Inc., |
||||
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
||||
|
*/ |
||||
|
|
||||
|
/** |
||||
|
* @file eda_text.h |
||||
|
* @brief Definition of base KiCad text object. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef _EDA_TEXT_H_ |
||||
|
#define _EDA_TEXT_H_ |
||||
|
|
||||
|
#include <common.h> // wxStringSplit |
||||
|
#include <gr_basic.h> // EDA_DRAW_MODE_T |
||||
|
#include <base_struct.h> // EDA_RECT |
||||
|
|
||||
|
|
||||
|
// Graphic Text justify: |
||||
|
// Values -1,0,1 are used in computations, do not change them |
||||
|
enum EDA_TEXT_HJUSTIFY_T { |
||||
|
GR_TEXT_HJUSTIFY_LEFT = -1, |
||||
|
GR_TEXT_HJUSTIFY_CENTER = 0, |
||||
|
GR_TEXT_HJUSTIFY_RIGHT = 1 |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
enum EDA_TEXT_VJUSTIFY_T { |
||||
|
GR_TEXT_VJUSTIFY_TOP = -1, |
||||
|
GR_TEXT_VJUSTIFY_CENTER = 0, |
||||
|
GR_TEXT_VJUSTIFY_BOTTOM = 1 |
||||
|
}; |
||||
|
|
||||
|
/* Options to show solid segments (segments, texts...) */ |
||||
|
enum EDA_DRAW_MODE_T { |
||||
|
LINE = 0, // segments are drawn as lines |
||||
|
FILLED, // normal mode: segments have thickness |
||||
|
SKETCH // sketch mode: segments have thickness, but are not filled |
||||
|
}; |
||||
|
|
||||
|
#define DEFAULT_SIZE_TEXT 60 /* default text height (in mils or 1/1000") */ |
||||
|
|
||||
|
/** |
||||
|
* Class EDA_TEXT |
||||
|
* is a basic class to handle texts (labels, texts on components or footprints |
||||
|
* ..) not used directly. The "used" text classes are derived from EDA_ITEM and |
||||
|
* EDA_TEXT using multiple inheritance. |
||||
|
*/ |
||||
|
class EDA_TEXT |
||||
|
{ |
||||
|
public: |
||||
|
wxString m_Text; |
||||
|
int m_Thickness; ///< pen size used to draw this text |
||||
|
double m_Orient; ///< Orient in 0.1 degrees |
||||
|
wxPoint m_Pos; ///< XY position of anchor text. |
||||
|
wxSize m_Size; ///< XY size of text |
||||
|
bool m_Mirror; ///< true if mirrored |
||||
|
int m_Attributs; ///< bit flags such as visible, etc. |
||||
|
bool m_Italic; ///< should be italic font (if available) |
||||
|
bool m_Bold; ///< should be bold font (if available) |
||||
|
EDA_TEXT_HJUSTIFY_T m_HJustify; ///< horizontal justification |
||||
|
EDA_TEXT_VJUSTIFY_T m_VJustify; ///< vertical justification |
||||
|
|
||||
|
bool m_MultilineAllowed; /**< true to use multiline option, false |
||||
|
* to use only single line text |
||||
|
* Single line is faster in |
||||
|
* calculations than multiline */ |
||||
|
|
||||
|
public: |
||||
|
EDA_TEXT( const wxString& text = wxEmptyString ); |
||||
|
EDA_TEXT( const EDA_TEXT& aText ); |
||||
|
virtual ~EDA_TEXT(); |
||||
|
|
||||
|
/** |
||||
|
* Function SetThickness |
||||
|
* sets text thickness. |
||||
|
* @param aNewThickness is the new text thickness. |
||||
|
*/ |
||||
|
void SetThickness( int aNewThickness ) { m_Thickness = aNewThickness; }; |
||||
|
|
||||
|
/** |
||||
|
* Function GetThickness |
||||
|
* returns text thickness. |
||||
|
* @return int - text thickness. |
||||
|
*/ |
||||
|
int GetThickness() const { return m_Thickness; }; |
||||
|
|
||||
|
void SetOrientation( double aOrientation ) { m_Orient = aOrientation; } |
||||
|
double GetOrientation() const { return m_Orient; } |
||||
|
|
||||
|
void SetItalic( bool isItalic ) { m_Italic = isItalic; } |
||||
|
bool IsItalic() const { return m_Italic; } |
||||
|
|
||||
|
void SetMirrored( bool isMirrored ) { m_Mirror = isMirrored; } |
||||
|
bool IsMirrored() const { return m_Mirror; } |
||||
|
|
||||
|
bool IsDefaultFormatting() const; |
||||
|
|
||||
|
/** |
||||
|
* Function SetSize |
||||
|
* sets text size. |
||||
|
* @param aNewSize is the new text size. |
||||
|
*/ |
||||
|
void SetSize( const wxSize& aNewSize ) { m_Size = aNewSize; }; |
||||
|
|
||||
|
/** |
||||
|
* Function GetSize |
||||
|
* returns text size. |
||||
|
* @return wxSize - text size. |
||||
|
*/ |
||||
|
const wxSize GetSize() const { return m_Size; }; |
||||
|
|
||||
|
/// named differently than the ones using multiple inheritance and including this class |
||||
|
void SetPos( const wxPoint& aPoint ) { m_Pos = aPoint; } |
||||
|
const wxPoint GetPos() const { return m_Pos; } |
||||
|
|
||||
|
int GetLength() const { return m_Text.Length(); }; |
||||
|
|
||||
|
/** |
||||
|
* Function Draw |
||||
|
* @param aPanel = the current DrawPanel |
||||
|
* @param aDC = the current Device Context |
||||
|
* @param aOffset = draw offset (usually (0,0)) |
||||
|
* @param aColor = text color |
||||
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode. |
||||
|
* @param aDisplay_mode = LINE, FILLED or SKETCH |
||||
|
* @param aAnchor_color = anchor color ( UNSPECIFIED = do not draw anchor ). |
||||
|
*/ |
||||
|
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, |
||||
|
const wxPoint& aOffset, EDA_COLOR_T aColor, |
||||
|
int aDrawMode, EDA_DRAW_MODE_T aDisplay_mode = LINE, |
||||
|
EDA_COLOR_T aAnchor_color = UNSPECIFIED ); |
||||
|
|
||||
|
private: |
||||
|
|
||||
|
/** |
||||
|
* Function DrawOneLineOfText |
||||
|
* Draw a single text line. |
||||
|
* Used to draw each line of this EDA_TEXT, that can be multiline |
||||
|
* @param aPanel = the current DrawPanel |
||||
|
* @param aDC = the current Device Context |
||||
|
* @param aOffset = draw offset (usually (0,0)) |
||||
|
* @param aColor = text color |
||||
|
* @param aDrawMode = GR_OR, GR_XOR.., -1 to use the current mode. |
||||
|
* @param aFillMode = LINE, FILLED or SKETCH |
||||
|
* @param aAnchor_color = anchor color ( UNSPECIFIED = do not draw anchor ). |
||||
|
* @param aText = the single line of text to draw. |
||||
|
* @param aPos = the position of this line ). |
||||
|
*/ |
||||
|
void DrawOneLineOfText( EDA_DRAW_PANEL* aPanel, wxDC* aDC, |
||||
|
const wxPoint& aOffset, EDA_COLOR_T aColor, |
||||
|
int aDrawMode, EDA_DRAW_MODE_T aFillMode, |
||||
|
EDA_COLOR_T aAnchor_color, wxString& aText, |
||||
|
wxPoint aPos ); |
||||
|
|
||||
|
public: |
||||
|
|
||||
|
/** |
||||
|
* Function TextHitTest |
||||
|
* Test if \a aPoint is within the bounds of this object. |
||||
|
* @param aPoint- A wxPoint to test |
||||
|
* @param aAccuracy - Amount to inflate the bounding box. |
||||
|
* @return bool - true if a hit, else false |
||||
|
*/ |
||||
|
bool TextHitTest( const wxPoint& aPoint, int aAccuracy = 0 ) const; |
||||
|
|
||||
|
/** |
||||
|
* Function TextHitTest (overloaded) |
||||
|
* Tests if object bounding box is contained within or intersects \a aRect. |
||||
|
* |
||||
|
* @param aRect - Rect to test against. |
||||
|
* @param aContains - Test for containment instead of intersection if true. |
||||
|
* @param aAccuracy - Amount to inflate the bounding box. |
||||
|
* @return bool - true if a hit, else false |
||||
|
*/ |
||||
|
bool TextHitTest( const EDA_RECT& aRect, bool aContains = false, int aAccuracy = 0 ) const; |
||||
|
|
||||
|
/** |
||||
|
* Function LenSize |
||||
|
* @return the text length in internal units |
||||
|
* @param aLine : the line of text to consider. |
||||
|
* For single line text, this parameter is always m_Text |
||||
|
*/ |
||||
|
int LenSize( const wxString& aLine ) const; |
||||
|
|
||||
|
/** |
||||
|
* Function GetTextBox |
||||
|
* useful in multiline texts to calculate the full text or a line area (for |
||||
|
* zones filling, locate functions....) |
||||
|
* @return the rect containing the line of text (i.e. the position and the |
||||
|
* size of one line) this rectangle is calculated for 0 orient text. |
||||
|
* If orientation is not 0 the rect must be rotated to match the |
||||
|
* physical area |
||||
|
* @param aLine The line of text to consider. |
||||
|
* for single line text, aLine is unused |
||||
|
* If aLine == -1, the full area (considering all lines) is returned |
||||
|
* @param aThickness Overrides the current thickness when greater than 0. |
||||
|
* @param aInvertY Invert the Y axis when calculating bounding box. |
||||
|
*/ |
||||
|
EDA_RECT GetTextBox( int aLine = -1, int aThickness = -1, bool aInvertY = false ) const; |
||||
|
|
||||
|
/** |
||||
|
* Function GetInterline |
||||
|
* return the distance between 2 text lines |
||||
|
* has meaning only for multiline texts |
||||
|
*/ |
||||
|
int GetInterline() const |
||||
|
{ |
||||
|
return (( m_Size.y * 14 ) / 10) + m_Thickness; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* Function GetTextStyleName |
||||
|
* @return a wxString with the style name( Normal, Italic, Bold, Bold+Italic) |
||||
|
*/ |
||||
|
wxString GetTextStyleName(); |
||||
|
|
||||
|
void SetText( const wxString& aText ) { m_Text = aText; } |
||||
|
|
||||
|
/** |
||||
|
* Function GetText |
||||
|
* returns the string associated with the text object. |
||||
|
* <p> |
||||
|
* This function is virtual to allow derived classes to override getting the |
||||
|
* string to provide a way for modifying the base string by adding a suffix or |
||||
|
* prefix to the base string. |
||||
|
* </p> |
||||
|
* @return a const wxString object containing the string of the item. |
||||
|
*/ |
||||
|
virtual const wxString GetText() const { return m_Text; } |
||||
|
|
||||
|
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const { return m_HJustify; }; |
||||
|
EDA_TEXT_VJUSTIFY_T GetVertJustify() const { return m_VJustify; }; |
||||
|
void SetHorizJustify( EDA_TEXT_HJUSTIFY_T aType ) { m_HJustify = aType; }; |
||||
|
void SetVertJustify( EDA_TEXT_VJUSTIFY_T aType ) { m_VJustify = aType; }; |
||||
|
|
||||
|
/** |
||||
|
* Function Format |
||||
|
* outputs the object to \a aFormatter in s-expression form. |
||||
|
* |
||||
|
* @param aFormatter The #OUTPUTFORMATTER object to write to. |
||||
|
* @param aNestLevel The indentation next level. |
||||
|
* @param aControlBits The control bit definition for object specific formatting. |
||||
|
* @throw IO_ERROR on write error. |
||||
|
*/ |
||||
|
virtual void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits ) const |
||||
|
throw( IO_ERROR ); |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
|
||||
|
#endif // _EDA_TEXT_H_ |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue