mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 14:50:11 +00:00
Debug: graphical snap anchor debug mode
When working near snap anchors, which come and go rapidly, it's often useful to see what snaps have been calculated. Add an advanced config to show these (EnableSnapAnchorsDebug) on an overlay layer. With more polish this could be a hotkey or something.
This commit is contained in:
parent
6bad4bb1a2
commit
ebef24b6b0
common
eeschema/tools
include
pcbnew/tools
@ -454,6 +454,7 @@ set( COMMON_DRAWING_SHEET_SRCS
|
||||
)
|
||||
|
||||
set( COMMON_PREVIEW_ITEMS_SRCS
|
||||
preview_items/anchor_debug.cpp
|
||||
preview_items/arc_assistant.cpp
|
||||
preview_items/arc_geom_manager.cpp
|
||||
preview_items/centreline_rect_item.cpp
|
||||
|
@ -118,6 +118,7 @@ static const wxChar MaxFileSystemWatchers[] = wxT( "MaxFileSystemWatchers" );
|
||||
static const wxChar MinorSchematicGraphSize[] = wxT( "MinorSchematicGraphSize" );
|
||||
static const wxChar ResolveTextRecursionDepth[] = wxT( "ResolveTextRecursionDepth" );
|
||||
static const wxChar EnableExtensionSnaps[] = wxT( "EnableExtensionSnaps" );
|
||||
static const wxChar EnableSnapAnchorsDebug[] = wxT( "EnableSnapAnchorsDebug" );
|
||||
} // namespace KEYS
|
||||
|
||||
|
||||
@ -282,6 +283,7 @@ ADVANCED_CFG::ADVANCED_CFG()
|
||||
m_ResolveTextRecursionDepth = 3;
|
||||
|
||||
m_EnableExtensionSnaps = false;
|
||||
m_EnableSnapAnchorsDebug = false;
|
||||
|
||||
loadFromConfigFile();
|
||||
}
|
||||
@ -530,6 +532,10 @@ void ADVANCED_CFG::loadSettings( wxConfigBase& aCfg )
|
||||
&m_EnableExtensionSnaps,
|
||||
m_EnableExtensionSnaps ) );
|
||||
|
||||
configParams.push_back( new PARAM_CFG_BOOL( true, AC_KEYS::EnableSnapAnchorsDebug,
|
||||
&m_EnableSnapAnchorsDebug,
|
||||
m_EnableSnapAnchorsDebug ) );
|
||||
|
||||
// Special case for trace mask setting...we just grab them and set them immediately
|
||||
// Because we even use wxLogTrace inside of advanced config
|
||||
wxString traceMasks;
|
||||
|
129
common/preview_items/anchor_debug.cpp
Normal file
129
common/preview_items/anchor_debug.cpp
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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
|
||||
*/
|
||||
|
||||
#include "preview_items/anchor_debug.h"
|
||||
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <gal/painter.h>
|
||||
#include <render_settings.h>
|
||||
|
||||
using namespace KIGFX;
|
||||
|
||||
ANCHOR_DEBUG::ANCHOR_DEBUG() :
|
||||
EDA_ITEM( nullptr, NOT_USED ) // Never added to a BOARD/SCHEMATIC so it needs no type
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ANCHOR_DEBUG* ANCHOR_DEBUG::Clone() const
|
||||
{
|
||||
return new ANCHOR_DEBUG();
|
||||
}
|
||||
|
||||
|
||||
const BOX2I ANCHOR_DEBUG::ViewBBox() const
|
||||
{
|
||||
// We could be a bit more careful here, but also we need to
|
||||
// know the world scale to cover everything exactly, and there
|
||||
// is only one of these.
|
||||
BOX2I bbox;
|
||||
bbox.SetMaximum();
|
||||
return bbox;
|
||||
}
|
||||
|
||||
void ANCHOR_DEBUG::ViewGetLayers( int aLayers[], int& aCount ) const
|
||||
{
|
||||
aLayers[0] = LAYER_GP_OVERLAY;
|
||||
aCount = 1;
|
||||
}
|
||||
|
||||
void ANCHOR_DEBUG::ClearAnchors()
|
||||
{
|
||||
m_nearest.reset();
|
||||
m_anchors.clear();
|
||||
}
|
||||
|
||||
void ANCHOR_DEBUG::AddAnchor( const VECTOR2I& aAnchor )
|
||||
{
|
||||
m_anchors[aAnchor]++;
|
||||
}
|
||||
|
||||
void ANCHOR_DEBUG::SetNearest( const OPT_VECTOR2I& aNearest )
|
||||
{
|
||||
m_nearest = aNearest;
|
||||
}
|
||||
|
||||
void ANCHOR_DEBUG::ViewDraw( int, VIEW* aView ) const
|
||||
{
|
||||
GAL& gal = *aView->GetGAL();
|
||||
RENDER_SETTINGS& settings = *aView->GetPainter()->GetSettings();
|
||||
|
||||
const COLOR4D textColor = settings.GetLayerColor( LAYER_AUX_ITEMS );
|
||||
|
||||
const BOX2D viewportD = aView->GetViewport();
|
||||
const BOX2I viewport( KiROUND( viewportD.GetPosition() ), KiROUND( viewportD.GetSize() ) );
|
||||
|
||||
gal.SetIsFill( false );
|
||||
gal.SetIsStroke( true );
|
||||
gal.SetLineWidth( 1 );
|
||||
|
||||
const int markerRad = aView->ToWorld( 3 );
|
||||
const int markerTextHeight = aView->ToWorld( 6 );
|
||||
const int markerTextGap = aView->ToWorld( 3 );
|
||||
const int summaryTextHeight = aView->ToWorld( 10 );
|
||||
const VECTOR2I textOffset = { markerRad + markerTextGap, 0 };
|
||||
|
||||
TEXT_ATTRIBUTES attributes;
|
||||
attributes.m_Halign = GR_TEXT_H_ALIGN_LEFT;
|
||||
attributes.m_Size = VECTOR2I( markerTextHeight, markerTextHeight );
|
||||
|
||||
const KIFONT::METRICS& fontMetrics = KIFONT::METRICS::Default();
|
||||
const KIFONT::FONT& font = *KIFONT::FONT::GetFont();
|
||||
|
||||
size_t total = 0;
|
||||
for( const auto& [anchor, count] : m_anchors )
|
||||
{
|
||||
if( m_nearest && *m_nearest == anchor )
|
||||
gal.SetStrokeColor( RED );
|
||||
else
|
||||
gal.SetStrokeColor( YELLOW );
|
||||
|
||||
gal.DrawCircle( anchor, markerRad );
|
||||
|
||||
const std::string countStr = std::to_string( count );
|
||||
font.Draw( &gal, countStr, anchor + textOffset, attributes, fontMetrics );
|
||||
|
||||
total += count;
|
||||
}
|
||||
|
||||
gal.SetStrokeColor( textColor );
|
||||
|
||||
const int boundaryMargin = aView->ToWorld( 20 );
|
||||
VECTOR2I fontPos{ viewport.GetLeft(), viewport.GetTop() };
|
||||
fontPos += VECTOR2I{ boundaryMargin, boundaryMargin };
|
||||
|
||||
attributes.m_Size = VECTOR2I{ summaryTextHeight, summaryTextHeight };
|
||||
|
||||
wxString totalStr = wxString::Format( "Current snap anchors: %lu", total );
|
||||
font.Draw( &gal, totalStr, fontPos, attributes, fontMetrics );
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <advanced_config.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
#include <gal/painter.h>
|
||||
#include <math/util.h> // for KiROUND
|
||||
@ -73,8 +74,25 @@ GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr, int aConstructionLayer ) :
|
||||
|
||||
GRID_HELPER::~GRID_HELPER()
|
||||
{
|
||||
KIGFX::VIEW* view = m_toolMgr->GetView();
|
||||
view->Remove( &m_constructionGeomPreview );
|
||||
KIGFX::VIEW& view = *m_toolMgr->GetView();
|
||||
view.Remove( &m_constructionGeomPreview );
|
||||
|
||||
if( m_anchorDebug )
|
||||
view.Remove( m_anchorDebug.get() );
|
||||
}
|
||||
|
||||
|
||||
KIGFX::ANCHOR_DEBUG* GRID_HELPER::enableAndGetAnchorDebug()
|
||||
{
|
||||
static bool permitted = ADVANCED_CFG::GetCfg().m_EnableSnapAnchorsDebug;
|
||||
if( permitted && !m_anchorDebug )
|
||||
{
|
||||
KIGFX::VIEW& view = *m_toolMgr->GetView();
|
||||
m_anchorDebug = std::make_unique<KIGFX::ANCHOR_DEBUG>();
|
||||
view.Add( m_anchorDebug.get() );
|
||||
view.SetVisible( m_anchorDebug.get(), true );
|
||||
}
|
||||
return m_anchorDebug.get();
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,6 +160,16 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GR
|
||||
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE, aGrid );
|
||||
VECTOR2I nearestGrid = Align( aOrigin, aGrid );
|
||||
|
||||
if( KIGFX::ANCHOR_DEBUG* ad = enableAndGetAnchorDebug(); ad )
|
||||
{
|
||||
ad->ClearAnchors();
|
||||
for( const ANCHOR& a : m_anchors )
|
||||
ad->AddAnchor( a.pos );
|
||||
|
||||
ad->SetNearest( nearest ? OPT_VECTOR2I( nearest->pos ) : std::nullopt );
|
||||
m_toolMgr->GetView()->Update( ad, KIGFX::GEOMETRY );
|
||||
}
|
||||
|
||||
showConstructionGeometry( m_enableSnap );
|
||||
|
||||
std::optional<VECTOR2I> snapLineOrigin = getConstructionManager().GetSnapLineOrigin();
|
||||
|
@ -652,6 +652,14 @@ public:
|
||||
*/
|
||||
bool m_EnableExtensionSnaps;
|
||||
|
||||
/**
|
||||
* Enable snap anchors debug visualization.
|
||||
*
|
||||
* Setting name: "EnableSnapAnchorsDebug"
|
||||
* Default value: false
|
||||
*/
|
||||
bool m_EnableSnapAnchorsDebug;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
|
83
include/preview_items/anchor_debug.h
Normal file
83
include/preview_items/anchor_debug.h
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <map>
|
||||
#include <span>
|
||||
|
||||
#include <origin_viewitem.h>
|
||||
|
||||
#include <math/vector2d.h>
|
||||
#include <geometry/seg.h> // OPT_VECTOR2I
|
||||
|
||||
namespace KIGFX
|
||||
{
|
||||
|
||||
/**
|
||||
* View item to draw debug items for anchors.
|
||||
*
|
||||
* This can be handy when verifying how many/where anchors are being placed.
|
||||
*/
|
||||
class ANCHOR_DEBUG : public EDA_ITEM
|
||||
{
|
||||
public:
|
||||
ANCHOR_DEBUG();
|
||||
|
||||
ANCHOR_DEBUG* Clone() const override;
|
||||
|
||||
void ViewGetLayers( int aLayers[], int& aCount ) const override;
|
||||
|
||||
const BOX2I ViewBBox() const override;
|
||||
|
||||
void ViewDraw( int aLayer, VIEW* aView ) const override;
|
||||
|
||||
/**
|
||||
* Get class name.
|
||||
*
|
||||
* @return string "ANCHOR_DEBUG"
|
||||
*/
|
||||
wxString GetClass() const override { return wxT( "ANCHOR_DEBUG" ); }
|
||||
|
||||
void ClearAnchors();
|
||||
|
||||
/**
|
||||
* Add an anchor at the given position.
|
||||
*/
|
||||
void AddAnchor( const VECTOR2I& aAnchor );
|
||||
|
||||
/**
|
||||
* Set the nearest anchor to the given position.
|
||||
*
|
||||
* Pass an empty optional to clear the nearest anchor.
|
||||
*/
|
||||
void SetNearest( const OPT_VECTOR2I& aNearest );
|
||||
|
||||
private:
|
||||
// Store the anchors by location and count
|
||||
std::map<VECTOR2I, size_t> m_anchors;
|
||||
OPT_VECTOR2I m_nearest;
|
||||
};
|
||||
|
||||
} // namespace KIGFX
|
@ -21,8 +21,7 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef __SNAP_INDICATOR_H
|
||||
#define __SNAP_INDICATOR_H
|
||||
#pragma once
|
||||
|
||||
#include <origin_viewitem.h>
|
||||
#include <geometry/point_types.h>
|
||||
@ -72,5 +71,3 @@ private:
|
||||
};
|
||||
|
||||
} // namespace KIGFX
|
||||
|
||||
#endif
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <geometry/point_types.h>
|
||||
#include <math/vector2d.h>
|
||||
#include <preview_items/anchor_debug.h>
|
||||
#include <preview_items/snap_indicator.h>
|
||||
#include <preview_items/construction_geom.h>
|
||||
#include <tool/construction_manager.h>
|
||||
@ -206,6 +207,13 @@ protected:
|
||||
|
||||
void updateSnapPoint( const TYPED_POINT2I& aPoint );
|
||||
|
||||
/**
|
||||
* Enable the anchor debug if permitted and return it
|
||||
*
|
||||
* Returns nullptr if not permitted by the advancd config
|
||||
*/
|
||||
KIGFX::ANCHOR_DEBUG* enableAndGetAnchorDebug();
|
||||
|
||||
std::vector<ANCHOR> m_anchors;
|
||||
|
||||
TOOL_MANAGER* m_toolMgr;
|
||||
@ -232,6 +240,9 @@ private:
|
||||
// and deals with updating the construction helper as well as keeping
|
||||
// track of what geometry is "active" for construction purposes.
|
||||
CONSTRUCTION_MANAGER m_constructionManager;
|
||||
|
||||
/// @brief VIEW_ITEM for visualising anchor points, if enabled
|
||||
std::unique_ptr<KIGFX::ANCHOR_DEBUG> m_anchorDebug;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -181,7 +181,6 @@ void PCB_GRID_HELPER::AddConstructionItems( std::vector<BOARD_ITEM*> aItems, boo
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// For all the elements that get drawn construction geometry,
|
||||
// add something suitable to the construction helper.
|
||||
// This can be nothing.
|
||||
@ -519,6 +518,16 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& a
|
||||
ANCHOR* nearest = nearestAnchor( aOrigin, SNAPPABLE );
|
||||
VECTOR2I nearestGrid = Align( aOrigin, aGrid );
|
||||
|
||||
if( KIGFX::ANCHOR_DEBUG* ad = enableAndGetAnchorDebug(); ad )
|
||||
{
|
||||
ad->ClearAnchors();
|
||||
for( const ANCHOR& anchor : m_anchors )
|
||||
ad->AddAnchor( anchor.pos );
|
||||
|
||||
ad->SetNearest( nearest ? OPT_VECTOR2I{ nearest->pos } : std::nullopt );
|
||||
m_toolMgr->GetView()->Update( ad, KIGFX::GEOMETRY );
|
||||
}
|
||||
|
||||
// The distance to the nearest snap point, if any
|
||||
std::optional<int> snapDist;
|
||||
if( nearest )
|
||||
|
Loading…
Reference in New Issue
Block a user