7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-21 00:21:25 +00:00

Pcbnew: allow to copy the ruler co-ordinates

This commit is contained in:
John Beard 2024-11-03 22:41:29 +08:00
parent 328a2e7d00
commit e6e1253fea
9 changed files with 67 additions and 42 deletions

View File

@ -79,7 +79,7 @@ void ARC_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
preview_ctx.DrawLineWithAngleHighlight( origin, m_constructMan.GetStartRadiusEnd(),
dimFirstLine );
std::vector<wxString> cursorStrings;
wxArrayString cursorStrings;
if( m_constructMan.GetStep() == ARC_GEOM_MANAGER::SET_START )
{

View File

@ -89,7 +89,7 @@ void BEZIER_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
dashSize, dashSize / 2, false );
}
std::vector<wxString> cursorStrings;
wxArrayString cursorStrings;
if( step >= BEZIER_GEOM_MANAGER::BEZIER_STEPS::SET_END )
{

View File

@ -117,7 +117,7 @@ KIGFX::COLOR4D KIGFX::PREVIEW::GetShadowColor( const KIGFX::COLOR4D& aColor )
void KIGFX::PREVIEW::DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& aCursorPos,
const VECTOR2D& aTextQuadrant,
const std::vector<wxString>& aStrings,
const wxArrayString& aStrings,
bool aDrawingDropShadows )
{
KIGFX::GAL* gal = aView->GetGAL();

View File

@ -52,35 +52,6 @@ static int getShadowLayer( KIGFX::GAL* aGal )
}
static void drawCursorStrings( KIGFX::VIEW* aView, const VECTOR2D& aCursor,
const VECTOR2D& aRulerVec, const EDA_IU_SCALE& aIuScale, EDA_UNITS aUnits,
bool aDrawingDropShadows, bool aFlipX, bool aFlipY )
{
// draw the cursor labels
std::vector<wxString> cursorStrings;
VECTOR2D temp = aRulerVec;
if( aFlipX )
temp.x = -temp.x;
if( aFlipY )
temp.y = -temp.y;
cursorStrings.push_back( DimensionLabel( "x", temp.x, aIuScale, aUnits ) );
cursorStrings.push_back( DimensionLabel( "y", temp.y, aIuScale, aUnits ) );
cursorStrings.push_back( DimensionLabel( "r", aRulerVec.EuclideanNorm(), aIuScale, aUnits ) );
EDA_ANGLE angle = -EDA_ANGLE( aRulerVec );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(), aIuScale,
EDA_UNITS::DEGREES ) );
temp = aRulerVec;
DrawTextNextToCursor( aView, aCursor, -temp, cursorStrings, aDrawingDropShadows );
}
static double getTickLineWidth( const TEXT_DIMS& textDims, bool aDrawingDropShadows )
{
double width = textDims.StrokeWidth * 0.8;
@ -362,8 +333,8 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
VECTOR2D rulerVec( end - origin );
drawCursorStrings( aView, end, rulerVec, m_iuScale, m_userUnits, drawingDropShadows, m_flipX,
m_flipY );
wxArrayString cursorStrings = GetDimensionStrings();
DrawTextNextToCursor( aView, end, -rulerVec, cursorStrings, drawingDropShadows );
// basic tick size
const double minorTickLen = 5.0 / gal->GetWorldScale();
@ -399,3 +370,29 @@ void RULER_ITEM::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
}
gal->PopDepth();
}
wxArrayString RULER_ITEM::GetDimensionStrings() const
{
const VECTOR2D rulerVec = m_geomMgr.GetEnd() - m_geomMgr.GetOrigin();
VECTOR2D temp = rulerVec;
if( m_flipX )
temp.x = -temp.x;
if( m_flipY )
temp.y = -temp.y;
wxArrayString cursorStrings;
cursorStrings.push_back( DimensionLabel( "x", temp.x, m_iuScale, m_userUnits ) );
cursorStrings.push_back( DimensionLabel( "y", temp.y, m_iuScale, m_userUnits ) );
cursorStrings.push_back(
DimensionLabel( "r", rulerVec.EuclideanNorm(), m_iuScale, m_userUnits ) );
EDA_ANGLE angle = -EDA_ANGLE( rulerVec );
cursorStrings.push_back( DimensionLabel( wxString::FromUTF8( "θ" ), angle.AsDegrees(),
m_iuScale, EDA_UNITS::DEGREES ) );
return cursorStrings;
}

View File

@ -79,7 +79,7 @@ void TWO_POINT_ASSISTANT::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
gal.ResetTextAttributes();
std::vector<wxString> cursorStrings;
wxArrayString cursorStrings;
if( m_shape == GEOM_SHAPE::SEGMENT )
{

View File

@ -78,7 +78,7 @@ COLOR4D GetShadowColor( const COLOR4D& aColor );
* @param aStrings list of strings to draw, top to bottom.
*/
void DrawTextNextToCursor( KIGFX::VIEW* aView, const VECTOR2D& aCursorPos,
const VECTOR2D& aTextQuadrant, const std::vector<wxString>& aStrings,
const VECTOR2D& aTextQuadrant, const wxArrayString& aStrings,
bool aDrawingDropShadows );
} // PREVIEW

View File

@ -62,6 +62,11 @@ public:
void SetShowOriginArrowHead( bool aShow ) { m_showOriginArrowHead = aShow; }
/**
* Get the strings for the dimensions of the ruler
*/
wxArrayString GetDimensionStrings() const;
#if defined(DEBUG)
void Show( int x, std::ostream& st ) const override
{

View File

@ -21,19 +21,22 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <pcbnew_settings.h>
#include <footprint_editor_settings.h>
#include "tools/pcb_viewer_tools.h"
#include <wx/clipbrd.h>
#include <3d_viewer/eda_3d_viewer_frame.h>
#include <footprint_editor_settings.h>
#include <gal/graphics_abstraction_layer.h>
#include <kiplatform/ui.h>
#include <pcb_base_frame.h>
#include <pcbnew_settings.h>
#include <preview_items/ruler_item.h>
#include <pgm_base.h>
#include <settings/settings_manager.h>
#include <tool/actions.h>
#include <tools/pcb_grid_helper.h>
#include <tools/pcb_actions.h>
#include <tools/pcb_viewer_tools.h>
bool PCB_VIEWER_TOOLS::Init()
@ -54,6 +57,9 @@ bool PCB_VIEWER_TOOLS::Init()
ctxMenu.AddCheckItem( PCB_ACTIONS::toggleHV45Mode, activeToolCondition, 2 );
ctxMenu.AddSeparator( activeToolCondition, 2 );
ctxMenu.AddItem( ACTIONS::copy, activeToolCondition, 3 );
ctxMenu.AddSeparator( activeToolCondition, 3 );
frame()->AddStandardSubMenus( *m_menu.get() );
return true;
@ -356,6 +362,20 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
canvas()->Refresh();
evt->SetPassEvent();
}
else if( evt->IsAction( &ACTIONS::copy ) )
{
if( originSet )
{
wxArrayString cursorStrings = ruler.GetDimensionStrings();
wxString text = wxJoin( cursorStrings, '\n' );
if( wxTheClipboard->Open() )
{
wxTheClipboard->SetData( new wxTextDataObject( text ) );
wxTheClipboard->Close();
}
}
}
else if( evt->IsClick( BUT_RIGHT ) )
{
m_menu->ShowContextMenu();
@ -379,6 +399,7 @@ int PCB_VIEWER_TOOLS::MeasureTool( const TOOL_EVENT& aEvent )
void PCB_VIEWER_TOOLS::setTransitions()
{
// clang-format off
Go( &PCB_VIEWER_TOOLS::Show3DViewer, ACTIONS::show3DViewer.MakeEvent() );
// Display modes
@ -388,4 +409,5 @@ void PCB_VIEWER_TOOLS::setTransitions()
Go( &PCB_VIEWER_TOOLS::TextOutlines, PCB_ACTIONS::textOutlines.MakeEvent() );
Go( &PCB_VIEWER_TOOLS::MeasureTool, ACTIONS::measureTool.MakeEvent() );
// clang-format on
}

View File

@ -27,8 +27,9 @@
#include <board.h>
#include <tool/tool_interactive.h>
#include <pcbnew_settings.h>
#include <pcb_base_frame.h>
#include <pcb_view.h>
class PCB_BASE_FRAME;
/**
* Tool useful for viewing footprints.