kicad/pcbnew/class_dimension.h

266 lines
8.0 KiB
C
Raw Normal View History

/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 1992-2017 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
*/
/**
* @file class_dimension.h
* @brief DIMENSION class definition.
*/
2011-12-14 04:29:25 +00:00
#ifndef DIMENSION_H_
#define DIMENSION_H_
#include <class_board_item.h>
#include <class_pcb_text.h>
class LINE_READER;
class TEXTE_PCB;
class MSG_PANEL_ITEM;
/**
* DIMENSION
*
* For better understanding of the points that make a dimension:
*
* m_featureLineGO m_featureLineDO
* | |
* | |
* | |
* | m_arrowG2F m_arrowD2F |
* | / \ |
* m_crossBarO|/____________________________\|m_crossBarF
* |\ m_Text /|
* | \ / |
* | m_arrowG1F m_arrowD1F |
* | |
* m_featureLineGF m_featureLineDF
*/
class DIMENSION : public BOARD_ITEM
{
int m_Width; ///< Line width
int m_Shape; ///< Currently always 0.
2019-12-20 14:11:39 +00:00
EDA_UNITS m_Unit; ///< 0 = inches, 1 = mm
bool m_UseMils; ///< If inches, use mils.
int m_Value; ///< value of PCB dimensions.
int m_Height; ///< length of feature lines
2012-12-19 19:31:36 +00:00
TEXTE_PCB m_Text;
public:
// TODO private: These member should be private. they are public only due to legacy code
2012-12-19 19:31:36 +00:00
wxPoint m_crossBarO, m_crossBarF;
wxPoint m_featureLineGO, m_featureLineGF;
wxPoint m_featureLineDO, m_featureLineDF;
wxPoint m_arrowD1F, m_arrowD2F;
wxPoint m_arrowG1F, m_arrowG2F;
DIMENSION( BOARD_ITEM* aParent );
// Do not create a copy constructor & operator=.
// The ones generated by the compiler are adequate.
~DIMENSION();
static inline bool ClassOf( const EDA_ITEM* aItem )
{
return aItem && PCB_DIMENSION_T == aItem->Type();
}
bool IsType( const KICAD_T aScanTypes[] ) const override
{
if( BOARD_ITEM::IsType( aScanTypes ) )
return true;
for( const KICAD_T* p = aScanTypes; *p != EOT; ++p )
{
if( *p == PCB_LOCATE_GRAPHIC_T )
return true;
}
return false;
}
void SetValue( int aValue ) { m_Value = aValue; }
int GetValue() const { return m_Value; }
const wxPoint GetPosition() const override;
2016-09-24 18:53:15 +00:00
void SetPosition( const wxPoint& aPos ) override;
void SetTextSize( const wxSize& aTextSize )
2007-12-01 03:42:52 +00:00
{
m_Text.SetTextSize( aTextSize );
2007-12-01 03:42:52 +00:00
}
2008-04-01 05:21:50 +00:00
void SetLayer( PCB_LAYER_ID aLayer ) override;
2009-08-03 07:55:08 +00:00
2011-12-14 04:29:25 +00:00
void SetShape( int aShape ) { m_Shape = aShape; }
int GetShape() const { return m_Shape; }
2011-12-14 04:29:25 +00:00
int GetWidth() const { return m_Width; }
2011-12-14 04:29:25 +00:00
void SetWidth( int aWidth ) { m_Width = aWidth; }
/**
* Function SetOrigin
* Sets a new origin of the crossbar line. All remaining lines are adjusted after that.
* @param aOrigin is the new point to be used as the new origin of the crossbar line.
* @param aPrecision number of decimal places for mils (scaled appropriately for other units).
*/
void SetOrigin( const wxPoint& aOrigin, int aPrecision );
/**
* Function GetOrigin
* @return Origin of the crossbar line.
*/
const wxPoint& GetOrigin() const
{
return m_featureLineGO;
}
/**
* Function SetEnd
* Sets a new end of the crossbar line. All remaining lines are adjusted after that.
* @param aEnd is the new point to be used as the new end of the crossbar line.
* @param aPrecision number of decimal places for mils (scaled appropriately for other units).
*/
void SetEnd( const wxPoint& aEnd, int aPrecision );
/**
* Function GetEnd
* @return End of the crossbar line.
*/
const wxPoint& GetEnd()
{
return m_featureLineDO;
}
/**
* Function SetHeight
* Sets the length of feature lines.
* @param aHeight is the new height.
* @param aPrecision number of decimal places for mils (scaled appropriately for other units).
*/
void SetHeight( int aHeight, int aPrecision );
/**
* Function GetHeight
* Returns the length of feature lines.
*/
int GetHeight() const
{
return m_Height;
}
/**
* Function UpdateHeight
* Updates stored height basing on points coordinates.
*/
void UpdateHeight();
/**
* Function GetAngle
* Returns angle of the crossbar.
* @return Angle of the crossbar line expressed in radians.
*/
double GetAngle() const
{
wxPoint delta( m_featureLineDO - m_featureLineGO );
return atan2( (double)delta.y, (double)delta.x );
}
2010-11-12 15:17:10 +00:00
/**
* Function AdjustDimensionDetails
* Calculate coordinates of segments used to draw the dimension.
* @param aPrecision number of decimal places for mils (scaled appropriately for other units).
*/
void AdjustDimensionDetails( int aPrecision );
2019-12-20 14:11:39 +00:00
void GetUnits( EDA_UNITS& aUnits, bool& aUseMils ) const
{
aUnits = m_Unit;
aUseMils = m_UseMils;
}
2019-12-20 14:11:39 +00:00
void SetUnits( EDA_UNITS aUnits, bool aUseMils )
{
m_Unit = aUnits;
m_UseMils = aUseMils;
}
2012-12-19 19:31:36 +00:00
void SetText( const wxString& NewText );
const wxString GetText() const;
TEXTE_PCB& Text() { return m_Text; }
TEXTE_PCB& Text() const { return *(const_cast<TEXTE_PCB*> (&m_Text)); }
2008-04-01 05:21:50 +00:00
/**
* Function Move
* @param offset : moving vector
*/
2016-09-24 18:53:15 +00:00
void Move( const wxPoint& offset ) override;
void Rotate( const wxPoint& aRotCentre, double aAngle ) override;
void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override;
2008-04-01 05:21:50 +00:00
/**
* Function Mirror
* Mirror the Dimension , relative to a given horizontal axis
* the text is not mirrored. only its position (and angle) is mirrored
* the layer is not changed
* @param axis_pos : vertical axis position
*/
void Mirror( const wxPoint& axis_pos, bool aMirrorLeftRight = false );
void GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList ) override;
2008-04-01 05:21:50 +00:00
bool HitTest( const wxPoint& aPosition, int aAccuracy ) const override;
bool HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy = 0 ) const override;
2008-01-06 12:43:57 +00:00
2016-09-24 18:53:15 +00:00
wxString GetClass() const override
2007-08-08 20:51:08 +00:00
{
return wxT( "DIMENSION" );
}
// Virtual function
const EDA_RECT GetBoundingBox() const override;
2019-12-20 14:11:39 +00:00
wxString GetSelectMenuText( EDA_UNITS aUnits ) const override;
BITMAP_DEF GetMenuImage() const override;
EDA_ITEM* Clone() const override;
2016-09-24 18:53:15 +00:00
virtual const BOX2I ViewBBox() const override;
2013-09-16 12:44:03 +00:00
virtual void SwapData( BOARD_ITEM* aImage ) override;
#if defined(DEBUG)
2016-09-24 18:53:15 +00:00
virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); }
#endif
};
2012-12-19 19:31:36 +00:00
#endif // DIMENSION_H_