From b356275e76320b89644ab291f21714600eb97683 Mon Sep 17 00:00:00 2001 From: Robbert Lagerweij Date: Thu, 8 Feb 2018 17:01:36 +0100 Subject: [PATCH] pcbnew: add align center and align middle tools and related icons NEW: add placement tools that allow aligning the centers of items in a selection, both vertically and horizonally --- bitmaps_png/CMakeLists.txt | 2 + bitmaps_png/cpp_26/align_items_center.cpp | 31 ++ bitmaps_png/cpp_26/align_items_middle.cpp | 31 ++ bitmaps_png/sources/align_items_center.svg | 494 ++++++++++++++++++++ bitmaps_png/sources/align_items_middle.svg | 498 +++++++++++++++++++++ include/bitmaps.h | 2 + pcbnew/tools/pcb_actions.h | 6 + pcbnew/tools/placement_tool.cpp | 82 ++++ pcbnew/tools/placement_tool.h | 14 + 9 files changed, 1160 insertions(+) create mode 100644 bitmaps_png/cpp_26/align_items_center.cpp create mode 100644 bitmaps_png/cpp_26/align_items_middle.cpp create mode 100644 bitmaps_png/sources/align_items_center.svg create mode 100644 bitmaps_png/sources/align_items_middle.svg diff --git a/bitmaps_png/CMakeLists.txt b/bitmaps_png/CMakeLists.txt index 258e41aba8..6d5023b4cc 100644 --- a/bitmaps_png/CMakeLists.txt +++ b/bitmaps_png/CMakeLists.txt @@ -138,6 +138,8 @@ set( BMAPS_MID add_zone_cutout add_zone align_items + align_items_center + align_items_middle anchor annotate_down_right annotate_right_down diff --git a/bitmaps_png/cpp_26/align_items_center.cpp b/bitmaps_png/cpp_26/align_items_center.cpp new file mode 100644 index 0000000000..87f52fe70a --- /dev/null +++ b/bitmaps_png/cpp_26/align_items_center.cpp @@ -0,0 +1,31 @@ + +/* Do not modify this file, it was automatically generated by the + * PNG2cpp CMake script, using a *.png file as input. + */ + +#include + +static const unsigned char png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1a, 0x08, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4a, 0x4c, + 0xce, 0x00, 0x00, 0x00, 0xdf, 0x49, 0x44, 0x41, 0x54, 0x48, 0xc7, 0x63, 0x60, 0x18, 0x05, 0xd8, + 0x80, 0x83, 0x03, 0x0b, 0xa3, 0x4a, 0xf8, 0x77, 0x06, 0xa5, 0xd0, 0xff, 0xc8, 0x18, 0x2c, 0x06, + 0x94, 0x43, 0x55, 0x2c, 0xe5, 0xcb, 0xc5, 0x20, 0x17, 0x25, 0x88, 0x82, 0x41, 0x62, 0xc4, 0x00, + 0x15, 0x4f, 0x76, 0x90, 0xc1, 0xc1, 0xd3, 0x7e, 0xfd, 0x0f, 0x9d, 0xf9, 0x1f, 0x8c, 0x41, 0x6c, + 0xb0, 0x85, 0x20, 0x39, 0x38, 0x50, 0x48, 0xe0, 0x60, 0x54, 0x0e, 0xff, 0x85, 0xe1, 0x22, 0x90, + 0x18, 0x50, 0x8e, 0x7a, 0x16, 0xa9, 0x44, 0xf3, 0x81, 0x04, 0xbd, 0xbb, 0x5f, 0xff, 0xf7, 0x9f, + 0xf8, 0x05, 0x8c, 0x41, 0x6c, 0x88, 0x42, 0xa0, 0x1c, 0xb5, 0x2d, 0x0a, 0x98, 0xfc, 0x0d, 0xae, + 0x10, 0xc4, 0x1e, 0x18, 0x8b, 0x64, 0x42, 0x39, 0x31, 0xe2, 0x10, 0x24, 0x46, 0x55, 0x8b, 0x8c, + 0xd3, 0x58, 0x81, 0xf1, 0xf5, 0x03, 0x4b, 0x1c, 0xfe, 0x00, 0xc9, 0x51, 0xcf, 0x22, 0x90, 0xcb, + 0x81, 0x6c, 0xdf, 0xde, 0x77, 0xf0, 0x38, 0x04, 0xb1, 0xc1, 0xf2, 0x20, 0x39, 0x6a, 0x5b, 0x14, + 0x34, 0xf5, 0x27, 0x5c, 0x1e, 0xc4, 0x1e, 0xbc, 0x16, 0xc5, 0x27, 0xa6, 0x3e, 0xc4, 0x65, 0x51, + 0x42, 0x52, 0xea, 0xff, 0xa4, 0xe4, 0xd4, 0xff, 0xb8, 0x2c, 0x02, 0xc9, 0x25, 0xa7, 0x40, 0xe4, + 0xb1, 0x59, 0x04, 0x94, 0x7b, 0x30, 0x8c, 0x83, 0x6e, 0xf0, 0xa4, 0x3a, 0xba, 0xe5, 0x23, 0xba, + 0x95, 0x0c, 0x43, 0xaf, 0xf4, 0xa6, 0x5b, 0x7d, 0x44, 0xb7, 0x1a, 0x96, 0xae, 0x6d, 0x86, 0x51, + 0x40, 0x22, 0x00, 0x00, 0x7a, 0x89, 0xca, 0x92, 0x6e, 0xf9, 0x69, 0x42, 0x00, 0x00, 0x00, 0x00, + 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, +}; + +const BITMAP_OPAQUE align_items_center_xpm[1] = {{ png, sizeof( png ), "align_items_center_xpm" }}; + +//EOF diff --git a/bitmaps_png/cpp_26/align_items_middle.cpp b/bitmaps_png/cpp_26/align_items_middle.cpp new file mode 100644 index 0000000000..1ed8cc0390 --- /dev/null +++ b/bitmaps_png/cpp_26/align_items_middle.cpp @@ -0,0 +1,31 @@ + +/* Do not modify this file, it was automatically generated by the + * PNG2cpp CMake script, using a *.png file as input. + */ + +#include + +static const unsigned char png[] = { + 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, + 0x00, 0x00, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x1a, 0x08, 0x06, 0x00, 0x00, 0x00, 0xa9, 0x4a, 0x4c, + 0xce, 0x00, 0x00, 0x00, 0xe5, 0x49, 0x44, 0x41, 0x54, 0x48, 0xc7, 0x63, 0x60, 0x18, 0x30, 0x20, + 0xe5, 0xcb, 0xc5, 0x20, 0x17, 0x25, 0x88, 0x0b, 0xc7, 0x25, 0xa4, 0x3e, 0xc4, 0x27, 0x0f, 0xd6, + 0x4f, 0x10, 0x28, 0x24, 0x70, 0x30, 0x2a, 0x87, 0xff, 0x62, 0x50, 0x0a, 0xfd, 0x4f, 0x2e, 0x06, + 0xeb, 0x07, 0x9a, 0x83, 0xdf, 0x22, 0x95, 0x68, 0x3e, 0x90, 0x62, 0xef, 0xee, 0xd7, 0xff, 0xfd, + 0x27, 0x7e, 0x21, 0x19, 0x83, 0xf4, 0x81, 0x2d, 0x04, 0x99, 0x43, 0x8c, 0x45, 0x01, 0x93, 0xbf, + 0xfd, 0x0f, 0x9d, 0xf9, 0x9f, 0x64, 0x0c, 0xd2, 0x37, 0x38, 0x2d, 0xa2, 0x7d, 0xd0, 0xd1, 0x2d, + 0x31, 0x10, 0x91, 0xbc, 0xe3, 0x13, 0x53, 0xff, 0x53, 0x9e, 0xbc, 0xb1, 0x01, 0x99, 0x50, 0x4e, + 0xbc, 0x16, 0x81, 0xe4, 0x29, 0x06, 0xc6, 0x69, 0xac, 0xc0, 0xa0, 0xf8, 0x41, 0x20, 0xa8, 0x7e, + 0x80, 0xd4, 0x51, 0x66, 0x11, 0xc8, 0xb5, 0x40, 0xc3, 0x7c, 0x7b, 0xdf, 0x61, 0x8d, 0x7c, 0x90, + 0x38, 0xd8, 0x42, 0x8a, 0x7d, 0x05, 0xb5, 0x28, 0x68, 0xea, 0x4f, 0xac, 0xc9, 0x19, 0x24, 0x3e, + 0x34, 0x2d, 0xa2, 0x7d, 0xd0, 0xd1, 0x2d, 0x31, 0xd0, 0x2d, 0x79, 0x63, 0x01, 0x69, 0x69, 0x69, + 0xff, 0xc9, 0xd7, 0xed, 0xe0, 0xc0, 0xc2, 0xa8, 0x12, 0xfe, 0x9d, 0x92, 0xa2, 0x07, 0x23, 0x48, + 0x41, 0xe6, 0x01, 0xcd, 0x45, 0x2b, 0x4c, 0x3d, 0xd9, 0x41, 0x92, 0xc1, 0xd3, 0x7e, 0x91, 0x55, + 0x6a, 0xa3, 0x63, 0x90, 0x39, 0x90, 0xc2, 0x15, 0x68, 0xee, 0xa8, 0x45, 0xd4, 0xb1, 0x88, 0x6e, + 0x89, 0x81, 0xb4, 0xe4, 0x7d, 0x97, 0x61, 0x30, 0x03, 0x00, 0xb8, 0x97, 0xbe, 0x3f, 0x90, 0xee, + 0x47, 0x63, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82, +}; + +const BITMAP_OPAQUE align_items_middle_xpm[1] = {{ png, sizeof( png ), "align_items_middle_xpm" }}; + +//EOF diff --git a/bitmaps_png/sources/align_items_center.svg b/bitmaps_png/sources/align_items_center.svg new file mode 100644 index 0000000000..41dc92cda7 --- /dev/null +++ b/bitmaps_png/sources/align_items_center.svg @@ -0,0 +1,494 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bitmaps_png/sources/align_items_middle.svg b/bitmaps_png/sources/align_items_middle.svg new file mode 100644 index 0000000000..5a968855b3 --- /dev/null +++ b/bitmaps_png/sources/align_items_middle.svg @@ -0,0 +1,498 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/include/bitmaps.h b/include/bitmaps.h index 97ee8d7d12..dd9f9b71ce 100644 --- a/include/bitmaps.h +++ b/include/bitmaps.h @@ -67,6 +67,8 @@ EXTERN_BITMAP( annotate_down_right_xpm ) EXTERN_BITMAP( annotate_right_down_xpm ) EXTERN_BITMAP( annotate_xpm ) EXTERN_BITMAP( align_items_xpm ) +EXTERN_BITMAP( align_items_center_xpm ) +EXTERN_BITMAP( align_items_middle_xpm ) EXTERN_BITMAP( apply_pad_settings_xpm ) EXTERN_BITMAP( array_xpm ) EXTERN_BITMAP( auto_associe_xpm ) diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index 62f57e617e..af596e0e92 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -234,6 +234,12 @@ public: /// Align items to the right edge of selection bounding box static TOOL_ACTION alignRight; + /// Align items to the middle of selection bounding box + static TOOL_ACTION alignCenterX; + + /// Align items to the center of selection bounding box + static TOOL_ACTION alignCenterY; + /// Distributes items evenly along the horizontal axis static TOOL_ACTION distributeHorizontally; diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp index db6c6744f5..c01c7a2378 100644 --- a/pcbnew/tools/placement_tool.cpp +++ b/pcbnew/tools/placement_tool.cpp @@ -57,6 +57,16 @@ TOOL_ACTION PCB_ACTIONS::alignRight( "pcbnew.AlignAndDistribute.alignRight", _( "Align to Right" ), _( "Aligns selected items to the right edge" ), right_xpm ); +TOOL_ACTION PCB_ACTIONS::alignCenterX( "pcbnew.AlignAndDistribute.alignCenterX", + AS_GLOBAL, 0, + _( "Align to Middle" ), + _( "Aligns selected items to the vertical center" ), align_items_middle_xpm ); + +TOOL_ACTION PCB_ACTIONS::alignCenterY( "pcbnew.AlignAndDistribute.alignCenterY", + AS_GLOBAL, 0, + _( "Align to Center" ), + _( "Aligns selected items to the horizontal center" ), align_items_center_xpm ); + TOOL_ACTION PCB_ACTIONS::distributeHorizontally( "pcbnew.AlignAndDistribute.distributeHorizontally", AS_GLOBAL, 0, _( "Distribute Horizontally" ), @@ -100,6 +110,8 @@ bool ALIGN_DISTRIBUTE_TOOL::Init() m_placementMenu->Add( PCB_ACTIONS::alignBottom ); m_placementMenu->Add( PCB_ACTIONS::alignLeft ); m_placementMenu->Add( PCB_ACTIONS::alignRight ); + m_placementMenu->Add( PCB_ACTIONS::alignCenterX ); + m_placementMenu->Add( PCB_ACTIONS::alignCenterY ); m_placementMenu->AppendSeparator(); m_placementMenu->Add( PCB_ACTIONS::distributeHorizontally ); m_placementMenu->Add( PCB_ACTIONS::distributeVertically ); @@ -126,6 +138,16 @@ bool SortTopmostY( const std::pair left, const std::pair< return ( left.second.GetY() < right.second.GetY() ); } +bool SortCenterX( const std::pair left, const std::pair right) +{ + return ( left.second.GetCenter().x < right.second.GetCenter().x ); +} + +bool SortCenterY( const std::pair left, const std::pair right) +{ + return ( left.second.GetCenter().y < right.second.GetCenter().y ); +} + bool SortBottommostY( const std::pair left, const std::pair right) { return ( left.second.GetBottom() > right.second.GetBottom() ); @@ -298,6 +320,64 @@ int ALIGN_DISTRIBUTE_TOOL::doAlignRight() } +int ALIGN_DISTRIBUTE_TOOL::AlignCenterX( const TOOL_EVENT& aEvent ) +{ + const SELECTION& selection = m_selectionTool->GetSelection(); + + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.StageItems( selection, CHT_MODIFY ); + + auto itemsToAlign = GetBoundingBoxes( selection ); + std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortCenterX ); + + // after sorting use the x coordinate of the middle item as a target for all other items + const int targetX = itemsToAlign.at( itemsToAlign.size() / 2 ).second.GetCenter().x; + + // Move the selected items + for( auto& i : itemsToAlign ) + { + int difference = targetX - i.second.GetCenter().x; + i.first->Move( wxPoint( difference, 0 ) ); + } + + commit.Push( _( "Align to middle" ) ); + + return 0; +} + + +int ALIGN_DISTRIBUTE_TOOL::AlignCenterY( const TOOL_EVENT& aEvent ) +{ + const SELECTION& selection = m_selectionTool->GetSelection(); + + if( selection.Size() <= 1 ) + return 0; + + BOARD_COMMIT commit( getEditFrame() ); + commit.StageItems( selection, CHT_MODIFY ); + + auto itemsToAlign = GetBoundingBoxes( selection ); + std::sort( itemsToAlign.begin(), itemsToAlign.end(), SortCenterY ); + + // after sorting use the y coordinate of the middle item as a target for all other items + const int targetY = itemsToAlign.at( itemsToAlign.size() / 2 ).second.GetCenter().y; + + // Move the selected items + for( auto& i : itemsToAlign ) + { + int difference = targetY - i.second.GetCenter().y; + i.first->Move( wxPoint( 0, difference ) ); + } + + commit.Push( _( "Align to center" ) ); + + return 0; +} + + int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally( const TOOL_EVENT& aEvent ) { const SELECTION& selection = m_selectionTool->GetSelection(); @@ -401,6 +481,8 @@ void ALIGN_DISTRIBUTE_TOOL::setTransitions() Go( &ALIGN_DISTRIBUTE_TOOL::AlignBottom, PCB_ACTIONS::alignBottom.MakeEvent() ); Go( &ALIGN_DISTRIBUTE_TOOL::AlignLeft, PCB_ACTIONS::alignLeft.MakeEvent() ); Go( &ALIGN_DISTRIBUTE_TOOL::AlignRight, PCB_ACTIONS::alignRight.MakeEvent() ); + Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterX, PCB_ACTIONS::alignCenterX.MakeEvent() ); + Go( &ALIGN_DISTRIBUTE_TOOL::AlignCenterY, PCB_ACTIONS::alignCenterY.MakeEvent() ); Go( &ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally, PCB_ACTIONS::distributeHorizontally.MakeEvent() ); Go( &ALIGN_DISTRIBUTE_TOOL::DistributeVertically, PCB_ACTIONS::distributeVertically.MakeEvent() ); diff --git a/pcbnew/tools/placement_tool.h b/pcbnew/tools/placement_tool.h index 150eb92e0e..a14d38badf 100644 --- a/pcbnew/tools/placement_tool.h +++ b/pcbnew/tools/placement_tool.h @@ -68,6 +68,20 @@ public: */ int AlignRight( const TOOL_EVENT& aEvent ); + /** + * Function AlignCenterX() + * Sets the x coordinate of the midpoint of each of the selected items to + * the value of the x coordinate of the center of the middle selected item. + */ + int AlignCenterX( const TOOL_EVENT& aEvent ); + + /** + * Function AlignCenterX() + * Sets the y coordinate of the midpoint of each of the selected items to + * the value of the y coordinate of the center of the middle selected item. + */ + int AlignCenterY( const TOOL_EVENT& aEvent ); + /** * Function DistributeHorizontally() * Distributes the selected items along the X axis.