kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #32344
[PATCH] Fix AlignLeft / AlignRight when using Flip Board view
Hi all,
This is a "band-aid" patch for this bug:
https://bugs.launchpad.net/kicad/+bug/1734377
When flip board view is active, item bounding boxes are not flipped. So,
any tools that rely on the bounding boxes may have undesired behavior. We
should probably think about how we actually want this to work, i.e. maybe
having a separate "view coordinate system" and "edit coordinate system" so
that the tools don't have to worry about whether or not the view is
mirrored.
-Jon
From 94f5acd881c04c49ed5eafd8bfd0fab37e89abf3 Mon Sep 17 00:00:00 2001
From: Jon Evans <jon@xxxxxxxxxxxxx>
Date: Sat, 9 Dec 2017 14:16:27 -0500
Subject: [PATCH] Fix AlignLeft / AlignRight when using Flip Board view
Fixes: lp:1734377
* https://bugs.launchpad.net/kicad/+bug/1734377
---
pcbnew/tools/placement_tool.cpp | 30 ++++++++++++++++++++++++++++++
pcbnew/tools/placement_tool.h | 17 +++++++++++++++++
2 files changed, 47 insertions(+)
diff --git a/pcbnew/tools/placement_tool.cpp b/pcbnew/tools/placement_tool.cpp
index 222da9521..010afb2ea 100644
--- a/pcbnew/tools/placement_tool.cpp
+++ b/pcbnew/tools/placement_tool.cpp
@@ -186,6 +186,21 @@ int ALIGN_DISTRIBUTE_TOOL::AlignBottom( const TOOL_EVENT& aEvent )
int ALIGN_DISTRIBUTE_TOOL::AlignLeft( const TOOL_EVENT& aEvent )
+{
+ // Because this tool uses bounding boxes and they aren't mirrored even when
+ // the view is mirrored, we need to call the other one if mirrored.
+ if( getView()->IsMirroredX() )
+ {
+ return doAlignRight();
+ }
+ else
+ {
+ return doAlignLeft();
+ }
+}
+
+
+int ALIGN_DISTRIBUTE_TOOL::doAlignLeft()
{
const SELECTION& selection = m_selectionTool->GetSelection();
@@ -223,6 +238,21 @@ int ALIGN_DISTRIBUTE_TOOL::AlignLeft( const TOOL_EVENT& aEvent )
int ALIGN_DISTRIBUTE_TOOL::AlignRight( const TOOL_EVENT& aEvent )
+{
+ // Because this tool uses bounding boxes and they aren't mirrored even when
+ // the view is mirrored, we need to call the other one if mirrored.
+ if( getView()->IsMirroredX() )
+ {
+ return doAlignLeft();
+ }
+ else
+ {
+ return doAlignRight();
+ }
+}
+
+
+int ALIGN_DISTRIBUTE_TOOL::doAlignRight()
{
const SELECTION& selection = m_selectionTool->GetSelection();
diff --git a/pcbnew/tools/placement_tool.h b/pcbnew/tools/placement_tool.h
index 3888fe05b..daf6b8981 100644
--- a/pcbnew/tools/placement_tool.h
+++ b/pcbnew/tools/placement_tool.h
@@ -81,6 +81,23 @@ public:
void setTransitions() override;
private:
+
+ /**
+ * Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
+ *
+ * NOTE: Uses the bounding box of items, which do not get mirrored even when
+ * the view is mirrored!
+ */
+ int doAlignLeft();
+
+ /**
+ * Aligns selected items using the right edge of their bounding boxes to the right-most item
+ *
+ * NOTE: Uses the bounding box of items, which do not get mirrored even when
+ * the view is mirrored!
+ */
+ int doAlignRight();
+
SELECTION_TOOL* m_selectionTool;
CONTEXT_MENU* m_placementMenu;
--
2.14.1
Follow ups