mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-21 14:41:42 +00:00
Pcbnew: only show point editor chamfer where useful
The chamfer corner action is only meaningful for polygons and zones, so only enable it there. Also move some static logic out of of the interface of PCB_POINT_EDITOR and use SELECTION_CONDITIONS like other similar code.
This commit is contained in:
parent
dad07f590a
commit
0896367753
@ -302,7 +302,10 @@ COLOR4D PCB_RENDER_SETTINGS::GetColor( const BOARD_ITEM* aItem, int aLayer ) con
|
||||
auto ii = m_netColors.find( netCode );
|
||||
|
||||
if( ii != m_netColors.end() )
|
||||
{
|
||||
std::cout << "Found net color: " << ii->second.ToHexString() << std::endl;
|
||||
netColor = ii->second;
|
||||
}
|
||||
|
||||
if( netColor == COLOR4D::UNSPECIFIED )
|
||||
{
|
||||
@ -849,6 +852,7 @@ void PCB_PAINTER::renderNetNameForSegment( const SHAPE_SEGMENT& aSeg, const COLO
|
||||
{
|
||||
VECTOR2I textPosition = start + segV * ( (double) ii / divisions );
|
||||
|
||||
std::cout << "net " << aNetName << " col: " << aColor.ToHexString() << std::endl;
|
||||
if( viewport.Contains( textPosition ) )
|
||||
m_gal->BitmapText( aNetName, textPosition, textOrientation );
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ using namespace std::placeholders;
|
||||
#include <confirm.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tool/point_editor_behavior.h>
|
||||
#include <tool/selection_conditions.h>
|
||||
#include <tools/pcb_actions.h>
|
||||
#include <tools/pcb_selection_tool.h>
|
||||
#include <tools/pcb_point_editor.h>
|
||||
@ -1864,6 +1865,50 @@ void PCB_POINT_EDITOR::Reset( RESET_REASON aReason )
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Condition to check if a point editor can add a corner to the given item.
|
||||
*/
|
||||
static bool canAddCorner( const EDA_ITEM& aItem )
|
||||
{
|
||||
const auto type = aItem.Type();
|
||||
|
||||
if( type == PCB_ZONE_T )
|
||||
return true;
|
||||
|
||||
if( type == PCB_SHAPE_T )
|
||||
{
|
||||
const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
|
||||
const SHAPE_T shapeType = shape.GetShape();
|
||||
return shapeType == SHAPE_T::SEGMENT || shapeType == SHAPE_T::POLY
|
||||
|| shapeType == SHAPE_T::ARC;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Condition to check if a point editor can add a chamfer to a corner
|
||||
* of the given item
|
||||
*/
|
||||
static bool canChamferCorner( const EDA_ITEM& aItem )
|
||||
{
|
||||
const auto type = aItem.Type();
|
||||
|
||||
// Works only for zones and polygons
|
||||
if( type == PCB_ZONE_T )
|
||||
return true;
|
||||
|
||||
if( type == PCB_SHAPE_T )
|
||||
{
|
||||
const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
|
||||
const SHAPE_T shapeType = shape.GetShape();
|
||||
return shapeType == SHAPE_T::POLY;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PCB_POINT_EDITOR::Init()
|
||||
{
|
||||
// Find the selection tool, so they can cooperate
|
||||
@ -1871,11 +1916,32 @@ bool PCB_POINT_EDITOR::Init()
|
||||
|
||||
wxASSERT_MSG( m_selectionTool, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
|
||||
|
||||
const auto addCornerCondition = [&]( const SELECTION& aSelection ) -> bool
|
||||
{
|
||||
const EDA_ITEM* item = aSelection.Front();
|
||||
return ( item != nullptr ) && canAddCorner( *item );
|
||||
};
|
||||
|
||||
const auto addChamferCondition = [&]( const SELECTION& aSelection ) -> bool
|
||||
{
|
||||
const EDA_ITEM* item = aSelection.Front();
|
||||
return ( item != nullptr ) && canChamferCorner( *item );
|
||||
};
|
||||
|
||||
const auto removeCornerCondition = [&]( const SELECTION& aSelection ) -> bool
|
||||
{
|
||||
return PCB_POINT_EDITOR::removeCornerCondition( aSelection );
|
||||
};
|
||||
|
||||
using S_C = SELECTION_CONDITIONS;
|
||||
|
||||
auto& menu = m_selectionTool->GetToolMenu().GetMenu();
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, PCB_POINT_EDITOR::addCornerCondition );
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner,
|
||||
std::bind( &PCB_POINT_EDITOR::removeCornerCondition, this, _1 ) );
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorChamferCorner, PCB_POINT_EDITOR::addCornerCondition );
|
||||
|
||||
// clang-format off
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorAddCorner, S_C::Count( 1 ) && addCornerCondition );
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorRemoveCorner, S_C::Count( 1 ) && removeCornerCondition );
|
||||
menu.AddItem( PCB_ACTIONS::pointEditorChamferCorner, S_C::Count( 1 ) && addChamferCondition );
|
||||
// clang-format on
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -2555,37 +2621,6 @@ EDIT_POINT PCB_POINT_EDITOR::get45DegConstrainer() const
|
||||
}
|
||||
|
||||
|
||||
bool PCB_POINT_EDITOR::canAddCorner( const EDA_ITEM& aItem )
|
||||
{
|
||||
const auto type = aItem.Type();
|
||||
|
||||
// Works only for zones and line segments
|
||||
if( type == PCB_ZONE_T )
|
||||
return true;
|
||||
|
||||
if( type == PCB_SHAPE_T )
|
||||
{
|
||||
const PCB_SHAPE& shape = static_cast<const PCB_SHAPE&>( aItem );
|
||||
const SHAPE_T shapeType = shape.GetShape();
|
||||
return shapeType == SHAPE_T::SEGMENT || shapeType == SHAPE_T::POLY
|
||||
|| shapeType == SHAPE_T::ARC;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool PCB_POINT_EDITOR::addCornerCondition( const SELECTION& aSelection )
|
||||
{
|
||||
if( aSelection.Size() != 1 )
|
||||
return false;
|
||||
|
||||
const EDA_ITEM* item = aSelection.Front();
|
||||
|
||||
return ( item != nullptr ) && canAddCorner( *item );
|
||||
}
|
||||
|
||||
|
||||
// Finds a corresponding vertex in a polygon set
|
||||
static std::pair<bool, SHAPE_POLY_SET::VERTEX_INDEX>
|
||||
findVertex( SHAPE_POLY_SET& aPolySet, const EDIT_POINT& aPoint )
|
||||
|
@ -108,12 +108,6 @@ private:
|
||||
///< Return a point that should be used as a constrainer for 45 degrees mode.
|
||||
EDIT_POINT get45DegConstrainer() const;
|
||||
|
||||
///< Condition to display "Create corner" context menu entry.
|
||||
static bool addCornerCondition( const SELECTION& aSelection );
|
||||
|
||||
///< Determine if the tool can currently add a corner to the given item
|
||||
static bool canAddCorner( const EDA_ITEM& aItem );
|
||||
|
||||
///< Condition to display "Remove corner" context menu entry.
|
||||
bool removeCornerCondition( const SELECTION& aSelection );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user