kicad/eeschema/sch_text.h

585 lines
17 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
2021-03-25 21:13:01 +00:00
* Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.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
*/
2008-02-21 20:49:15 +00:00
#ifndef CLASS_TEXT_LABEL_H
#define CLASS_TEXT_LABEL_H
#include <eda_text.h>
2019-05-10 19:57:24 +00:00
#include <sch_item.h>
#include <sch_field.h>
#include <sch_connection.h> // for CONNECTION_TYPE
class NETLIST_OBJECT_LIST;
class HTML_MESSAGE_BOX;
/*
* Spin style for text items of all kinds on schematics
* Basically a higher level abstraction of rotation and justification of text
*/
class LABEL_SPIN_STYLE
{
public:
enum SPIN : int
{
LEFT = 0,
UP = 1,
RIGHT = 2,
BOTTOM = 3
};
LABEL_SPIN_STYLE() = default;
constexpr LABEL_SPIN_STYLE( SPIN aSpin ) : m_spin( aSpin )
{
}
constexpr bool operator==( SPIN a ) const
{
return m_spin == a;
}
constexpr bool operator!=( SPIN a ) const
{
return m_spin != a;
}
operator int() const
{
return static_cast<int>( m_spin );
}
LABEL_SPIN_STYLE RotateCW();
LABEL_SPIN_STYLE RotateCCW();
/**
* Mirror the label spin style across the X axis or simply swaps up and bottom.
*/
LABEL_SPIN_STYLE MirrorX();
/**
* Mirror the label spin style across the Y axis or simply swaps left and right.
*/
LABEL_SPIN_STYLE MirrorY();
private:
SPIN m_spin;
};
2008-02-21 20:49:15 +00:00
2021-03-25 21:13:01 +00:00
/*
* Shape/Type of #SCH_HIERLABEL, #SCH_GLOBALLABEL and #SCH_NETCLASS_FLAG.
*/
enum LABEL_FLAG_SHAPE
{
L_INPUT,
L_OUTPUT,
L_BIDI,
L_TRISTATE,
L_UNSPECIFIED,
F_FIRST,
F_DOT = F_FIRST,
F_ROUND,
F_DIAMOND,
F_RECTANGLE
};
2008-02-21 20:49:15 +00:00
extern const char* SheetLabelType[]; /* names of types of labels */
class SCH_TEXT : public SCH_ITEM, public EDA_TEXT
{
2008-02-21 20:49:15 +00:00
public:
SCH_TEXT( const VECTOR2I& aPos = VECTOR2I( 0, 0 ), const wxString& aText = wxEmptyString,
KICAD_T aType = SCH_TEXT_T );
SCH_TEXT( const SCH_TEXT& aText );
2008-03-20 01:50:21 +00:00
~SCH_TEXT() { }
2008-02-21 20:49:15 +00:00
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_TEXT_T == aItem->Type();
}
2016-09-25 17:06:49 +00:00
virtual wxString GetClass() const override
2008-02-21 20:49:15 +00:00
{
2008-03-20 01:50:21 +00:00
return wxT( "SCH_TEXT" );
2008-02-21 20:49:15 +00:00
}
wxString GetShownText( int aDepth = 0 ) const override;
/**
* Increment the label text, if it ends with a number.
*
* @param aIncrement = the increment value to add to the number ending the text.
*/
bool IncrementLabel( int aIncrement );
2008-02-21 20:49:15 +00:00
2010-11-12 15:17:10 +00:00
/**
* Set a spin or rotation angle, along with specific horizontal and vertical justification
* styles with each angle.
*
2021-03-25 21:13:01 +00:00
* @param aSpinStyle Spin style as per #LABEL_SPIN_STYLE storage class, may be the enum
* values or int value
*/
virtual void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle );
2020-11-16 13:15:54 +00:00
LABEL_SPIN_STYLE GetLabelSpinStyle() const { return m_spin_style; }
virtual LABEL_FLAG_SHAPE GetShape() const { return L_UNSPECIFIED; }
virtual void SetShape( LABEL_FLAG_SHAPE aShape ) { }
2010-11-12 15:17:10 +00:00
/**
* This offset depends on the orientation, the type of text, and the area required to
* draw the associated graphic symbol or to put the text above a wire.
2021-03-25 21:13:01 +00:00
*
* @return the offset between the SCH_TEXT position and the text itself position
*/
virtual VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const;
void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
2008-02-21 20:49:15 +00:00
void SwapData( SCH_ITEM* aItem ) override;
const EDA_RECT GetBoundingBox() const override;
2008-04-15 19:38:19 +00:00
bool operator<( const SCH_ITEM& aItem ) const override;
2020-12-20 18:18:54 +00:00
int GetTextOffset( const RENDER_SETTINGS* aSettings = nullptr ) const;
2020-04-14 12:25:00 +00:00
int GetPenWidth() const override;
2022-01-07 00:47:23 +00:00
KIFONT::FONT* GetDrawFont() const override;
void Move( const VECTOR2I& aMoveVector ) override
{
EDA_TEXT::Offset( aMoveVector );
}
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
void Rotate( const VECTOR2I& aCenter ) override;
virtual void Rotate90( bool aClockwise );
2020-11-18 23:34:03 +00:00
virtual void MirrorSpinStyle( bool aLeftRight );
2020-12-20 18:27:51 +00:00
bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override
{
return SCH_ITEM::Matches( GetText(), aSearchData );
}
2020-12-20 18:27:51 +00:00
bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override
{
return EDA_TEXT::Replace( aSearchData );
}
2016-09-25 17:06:49 +00:00
virtual bool IsReplaceable() const override { return true; }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
2019-12-20 14:11:39 +00:00
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAPS GetMenuImage() const override;
VECTOR2I GetPosition() const override { return EDA_TEXT::GetTextPos(); }
void SetPosition( const VECTOR2I& aPosition ) override { EDA_TEXT::SetTextPos( aPosition ); }
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
void Plot( PLOTTER* aPlotter ) const override;
EDA_ITEM* Clone() const override
{
return new SCH_TEXT( *this );
}
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
2008-04-22 16:38:23 +00:00
#if defined(DEBUG)
2016-09-25 17:06:49 +00:00
void Show( int nestLevel, std::ostream& os ) const override;
2008-04-22 16:38:23 +00:00
#endif
2020-05-09 20:27:06 +00:00
static HTML_MESSAGE_BOX* ShowSyntaxHelp( wxWindow* aParentWindow );
2021-03-25 21:13:01 +00:00
protected:
/**
* The orientation of text and any associated drawing elements of derived objects.
* - 0 is the horizontal and left justified.
* - 1 is vertical and top justified.
* - 2 is horizontal and right justified. It is the equivalent of the mirrored 0 orientation.
* - 3 is vertical and bottom justified. It is the equivalent of the mirrored 1 orientation.
*
* This is a duplication of m_Orient, m_HJustified, and m_VJustified in #EDA_TEXT but is
* easier to handle than 3 parameters when editing and reading and saving files.
*/
LABEL_SPIN_STYLE m_spin_style;
2008-02-21 20:49:15 +00:00
};
class SCH_LABEL_BASE : public SCH_TEXT
{
public:
SCH_LABEL_BASE( const VECTOR2I& aPos, const wxString& aText, KICAD_T aType );
SCH_LABEL_BASE( const SCH_LABEL_BASE& aLabel );
// Abstract class
virtual wxString GetClass() const override = 0;
bool IsType( const KICAD_T aScanTypes[] ) const override;
void SwapData( SCH_ITEM* aItem ) override;
LABEL_FLAG_SHAPE GetShape() const override { return m_shape; }
void SetShape( LABEL_FLAG_SHAPE aShape ) override { m_shape = aShape; }
static const wxString GetDefaultFieldName( const wxString& aName, bool aUseDefaultName );
virtual int GetMandatoryFieldCount() { return 0; }
std::vector<SCH_FIELD>& GetFields() { return m_fields; }
const std::vector<SCH_FIELD>& GetFields() const { return m_fields; }
/**
* Set multiple schematic fields.
*
* @param aFields are the fields to set in this symbol.
*/
void SetFields( const std::vector<SCH_FIELD>& aFields )
{
m_fields = aFields; // vector copying, length is changed possibly
}
void Move( const VECTOR2I& aMoveVector ) override
{
SCH_TEXT::Move( aMoveVector );
for( SCH_FIELD& field : m_fields )
field.Offset( aMoveVector );
}
void Rotate( const VECTOR2I& aCenter ) override;
void Rotate90( bool aClockwise ) override;
void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
virtual bool ResolveTextVar( wxString* token, int aDepth ) const;
wxString GetShownText( int aDepth = 0 ) const override;
void RunOnChildren( const std::function<void( SCH_ITEM* )>& aFunction ) override;
SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override;
2022-01-07 14:49:17 +00:00
VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;
/**
* Calculate the graphic shape (a polygon) associated to the text.
*
* @param aPoints A buffer to fill with polygon corners coordinates
* @param Pos Position of the shape, for texts and labels: do nothing
*/
virtual void CreateGraphicShape( const RENDER_SETTINGS* aSettings,
std::vector<VECTOR2I>& aPoints, const VECTOR2I& Pos ) const
{
aPoints.clear();
}
int GetLabelBoxExpansion( const RENDER_SETTINGS* aSettings = nullptr ) const;
/**
* Return the bounding box of the label only, without taking in account its fields.
*/
virtual const EDA_RECT GetBodyBoundingBox() const;
/**
* Return the bounding box of the label including its fields.
*/
const EDA_RECT GetBoundingBox() const override;
bool HitTest( const VECTOR2I& aPosition, int aAccuracy = 0 ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
std::vector<VECTOR2I> GetConnectionPoints() const override;
void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) override;
bool UpdateDanglingState( std::vector<DANGLING_END_ITEM>& aItemList,
const SCH_SHEET_PATH* aPath = nullptr ) override;
bool IsDangling() const override { return m_isDangling; }
void SetIsDangling( bool aIsDangling ) { m_isDangling = aIsDangling; }
void ViewGetLayers( int aLayers[], int& aCount ) const override;
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
void Plot( PLOTTER* aPlotter ) const override;
void Print( const RENDER_SETTINGS* aSettings, const VECTOR2I& offset ) override;
protected:
std::vector<SCH_FIELD> m_fields;
LABEL_FLAG_SHAPE m_shape;
CONNECTION_TYPE m_connectionType;
bool m_isDangling;
};
class SCH_LABEL : public SCH_LABEL_BASE
2008-02-21 20:49:15 +00:00
{
public:
SCH_LABEL( const VECTOR2I& aPos = VECTOR2I( 0, 0 ), const wxString& aText = wxEmptyString );
// Do not create a copy constructor. The one generated by the compiler is adequate.
2008-03-20 01:50:21 +00:00
~SCH_LABEL() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_LABEL_T == aItem->Type();
}
2016-09-25 17:06:49 +00:00
wxString GetClass() const override
2008-02-21 20:49:15 +00:00
{
return wxT( "SCH_LABEL" );
2008-02-21 20:49:15 +00:00
}
2008-04-15 19:38:19 +00:00
const EDA_RECT GetBodyBoundingBox() const override;
2009-11-28 09:24:37 +00:00
2016-09-25 17:06:49 +00:00
bool IsConnectable() const override { return true; }
bool CanConnect( const SCH_ITEM* aItem ) const override
{
return aItem->Type() == SCH_LINE_T &&
( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
}
2019-12-20 14:11:39 +00:00
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAPS GetMenuImage() const override;
2016-09-25 17:06:49 +00:00
bool IsReplaceable() const override { return true; }
EDA_ITEM* Clone() const override
{
return new SCH_LABEL( *this );
}
bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
2021-03-25 21:13:01 +00:00
{
return m_isDangling && GetPosition() == aPos;
}
private:
bool doIsConnected( const VECTOR2I& aPosition ) const override
2021-03-25 21:13:01 +00:00
{
return EDA_TEXT::GetTextPos() == aPosition;
}
2008-02-21 20:49:15 +00:00
};
class SCH_NETCLASS_FLAG : public SCH_LABEL_BASE
{
public:
SCH_NETCLASS_FLAG( const VECTOR2I& aPos = VECTOR2I( 0, 0 ) );
SCH_NETCLASS_FLAG( const SCH_NETCLASS_FLAG& aClassLabel );
~SCH_NETCLASS_FLAG() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_NETCLASS_FLAG_T == aItem->Type();
}
wxString GetClass() const override
{
return wxT( "SCH_NETCLASS_FLAG" );
}
EDA_ITEM* Clone() const override
{
return new SCH_NETCLASS_FLAG( *this );
}
int GetPinLength() const { return m_pinLength; }
void SetPinLength( int aLength ) { m_pinLength = aLength; }
void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos ) const override;
void AutoplaceFields( SCH_SCREEN* aScreen, bool aManual ) override;
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
bool IsConnectable() const override { return true; }
bool CanConnect( const SCH_ITEM* aItem ) const override
{
return aItem->Type() == SCH_LINE_T &&
( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
}
private:
int m_pinLength;
int m_symbolSize;
};
class SCH_GLOBALLABEL : public SCH_LABEL_BASE
2008-02-21 20:49:15 +00:00
{
public:
SCH_GLOBALLABEL( const VECTOR2I& aPos = VECTOR2I( 0, 0 ), const wxString& aText = wxEmptyString );
SCH_GLOBALLABEL( const SCH_GLOBALLABEL& aGlobalLabel );
2008-03-20 01:50:21 +00:00
~SCH_GLOBALLABEL() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_GLOBAL_LABEL_T == aItem->Type();
}
2016-09-25 17:06:49 +00:00
wxString GetClass() const override
2008-02-21 20:49:15 +00:00
{
return wxT( "SCH_GLOBALLABEL" );
2008-02-21 20:49:15 +00:00
}
EDA_ITEM* Clone() const override
{
return new SCH_GLOBALLABEL( *this );
}
int GetMandatoryFieldCount() override { return 1; }
2020-11-18 23:34:03 +00:00
void MirrorSpinStyle( bool aLeftRight ) override;
void MirrorHorizontally( int aCenter ) override;
void MirrorVertically( int aCenter ) override;
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;
void CreateGraphicShape( const RENDER_SETTINGS* aRenderSettings, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos ) const override;
bool ResolveTextVar( wxString* token, int aDepth ) const override;
2016-09-25 17:06:49 +00:00
bool IsConnectable() const override { return true; }
bool CanConnect( const SCH_ITEM* aItem ) const override
{
return aItem->Type() == SCH_LINE_T &&
( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
}
void ViewGetLayers( int aLayers[], int& aCount ) const override;
2019-12-20 14:11:39 +00:00
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAPS GetMenuImage() const override;
bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
2020-11-15 17:03:27 +00:00
{
return m_isDangling && GetPosition() == aPos;
}
private:
bool doIsConnected( const VECTOR2I& aPosition ) const override
2020-11-15 17:03:27 +00:00
{
return EDA_TEXT::GetTextPos() == aPosition;
}
2008-02-21 20:49:15 +00:00
};
class SCH_HIERLABEL : public SCH_LABEL_BASE
2008-02-21 20:49:15 +00:00
{
public:
SCH_HIERLABEL( const VECTOR2I& aPos = VECTOR2I( 0, 0 ), const wxString& aText = wxEmptyString,
KICAD_T aType = SCH_HIER_LABEL_T );
// Do not create a copy constructor. The one generated by the compiler is adequate.
2008-03-20 01:50:21 +00:00
~SCH_HIERLABEL() { }
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && SCH_HIER_LABEL_T == aItem->Type();
}
2016-09-25 17:06:49 +00:00
wxString GetClass() const override
2008-02-21 20:49:15 +00:00
{
return wxT( "SCH_HIERLABEL" );
2008-02-21 20:49:15 +00:00
}
void SetLabelSpinStyle( LABEL_SPIN_STYLE aSpinStyle ) override;
VECTOR2I GetSchematicTextOffset( const RENDER_SETTINGS* aSettings ) const override;
void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos ) const override;
void CreateGraphicShape( const RENDER_SETTINGS* aSettings, std::vector<VECTOR2I>& aPoints,
const VECTOR2I& aPos, LABEL_FLAG_SHAPE aShape ) const;
const EDA_RECT GetBodyBoundingBox() const override;
2016-09-25 17:06:49 +00:00
bool IsConnectable() const override { return true; }
bool CanConnect( const SCH_ITEM* aItem ) const override
{
return aItem->Type() == SCH_LINE_T &&
( aItem->GetLayer() == LAYER_WIRE || aItem->GetLayer() == LAYER_BUS );
}
2019-12-20 14:11:39 +00:00
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAPS GetMenuImage() const override;
EDA_ITEM* Clone() const override
{
return new SCH_HIERLABEL( *this );
}
bool IsPointClickableAnchor( const VECTOR2I& aPos ) const override
2021-03-25 21:13:01 +00:00
{
return m_isDangling && GetPosition() == aPos;
}
private:
bool doIsConnected( const VECTOR2I& aPosition ) const override
2021-03-25 21:13:01 +00:00
{
return EDA_TEXT::GetTextPos() == aPosition;
}
2008-02-21 20:49:15 +00:00
};
#endif /* CLASS_TEXT_LABEL_H */