kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #32133
Re: [PATCH] Remove shorted wire (fixes lp:1678449)
Hi Wayne-
Thank makes sense. The two-pin check was arbitrary, based on the bug
report's examples. But there's no fundamental reason not to extend this to
arbitrary pins.
The attached patch does this.
Best-
Seth
On Sat, Dec 2, 2017 at 12:23 PM, Wayne Stambaugh <stambaughw@xxxxxxxxx>
wrote:
> Seth,
>
> Even though technically we are in a feature freeze and the bug severity
> is wish list, I would consider this patch since it's fairly trivial. My
> only question is why the arbitrary limit of items with only two
> connection points? The same bug will occur with any symbol with pins
> directly across from each other not just symbols with only two pins
> across from each other. I'm guessing this will complicate the code but
> your solution is not complete.
>
> Cheers,
>
> Wayne
>
> On 12/1/2017 7:44 PM, Seth Hillbrand wrote:
> > When laying out a schematic, it is often necessary to add resistors or
> > capacitors to existing wires. Currently, placing a resistor on top of a
> > wire in Eeschema will connect both ends, resulting in a short across the
> > resistor that needs to be removed.
> >
> > The attached patch removes the shorted wire when a two-ended component
> > is placed directly on a wire.
> >
> > The associated bug report is https://bugs.launchpad.
> net/kicad/+bug/1678449
> >
> > -Seth
> >
> >
> >
> > _______________________________________________
> > Mailing list: https://launchpad.net/~kicad-developers
> > Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> > Unsubscribe : https://launchpad.net/~kicad-developers
> > More help : https://help.launchpad.net/ListHelp
> >
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help : https://help.launchpad.net/ListHelp
>
From 7fdc3d8f1268ea172b20d34f61b7b90db9d2d25f Mon Sep 17 00:00:00 2001
From: Seth Hillbrand <hillbrand@xxxxxxxxxxx>
Date: Fri, 1 Dec 2017 14:53:23 -0800
Subject: [PATCH] Eeschema: Remove wire under a placed component
CHANGE: In Eeschema, when placing a component directly over an existing
wire, the wire is automatically removed where it shorted pins.
This helps workflow in Eeschema, allowing one to quickly add components
to existing lines.
Fixes: lp:1678449
* https://bugs.launchpad.net/kicad/+bug/1678449
---
eeschema/bus-wire-junction.cpp | 45 +++++++++++++++++++++++++++++++++++++++++-
eeschema/schframe.cpp | 9 ++++++---
eeschema/schframe.h | 14 ++++++++++++-
3 files changed, 63 insertions(+), 5 deletions(-)
diff --git a/eeschema/bus-wire-junction.cpp b/eeschema/bus-wire-junction.cpp
index c5882810a..05a521afd 100644
--- a/eeschema/bus-wire-junction.cpp
+++ b/eeschema/bus-wire-junction.cpp
@@ -437,6 +437,45 @@ void SCH_EDIT_FRAME::SaveWireImage()
}
+void SCH_EDIT_FRAME::TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend )
+{
+ SCH_LINE* line;
+
+ if( aStart == aEnd )
+ return;
+
+ for( SCH_ITEM* item = GetScreen()->GetDrawItems(); item; item = item->Next() )
+ {
+ if( item->GetFlags() & STRUCT_DELETED )
+ continue;
+
+ if( item->Type() != SCH_LINE_T || item->GetLayer() != LAYER_WIRE )
+ continue;
+
+ line = (SCH_LINE*) item;
+ if( !IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aStart ) ||
+ !IsPointOnSegment( line->GetStartPoint(), line->GetEndPoint(), aEnd ) )
+ continue;
+
+ // Step 1: break the segment on one end. return_line remains line if not broken.
+ // Ensure that *line points to the segment containing aEnd
+ SCH_LINE* return_line = line;
+ aAppend |= BreakSegment( line, aStart, aAppend, &return_line );
+ if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aEnd ) )
+ line = return_line;
+
+ // Step 2: break the remaining segment. return_line remains line if not broken.
+ // Ensure that *line _also_ contains aStart. This is our overlapping segment
+ aAppend |= BreakSegment( line, aEnd, aAppend, &return_line );
+ if( IsPointOnSegment( return_line->GetStartPoint(), return_line->GetEndPoint(), aStart ) )
+ line = return_line;
+
+ SaveCopyInUndoList( (SCH_ITEM*)line, UR_DELETED, aAppend );
+ GetScreen()->Remove( (SCH_ITEM*)line );
+ }
+}
+
+
bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend )
{
SCH_ITEM* item = NULL;
@@ -531,7 +570,8 @@ bool SCH_EDIT_FRAME::SchematicCleanUp( bool aAppend )
}
-bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE *aSegment, const wxPoint& aPoint, bool aAppend )
+bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend,
+ SCH_LINE** aNewSegment )
{
if( !IsPointOnSegment( aSegment->GetStartPoint(), aSegment->GetEndPoint(), aPoint )
|| aSegment->IsEndPoint( aPoint ) )
@@ -545,6 +585,9 @@ bool SCH_EDIT_FRAME::BreakSegment( SCH_LINE *aSegment, const wxPoint& aPoint, bo
aSegment->SetEndPoint( aPoint );
GetScreen()->Append( newSegment );
+ if( aNewSegment )
+ *aNewSegment = newSegment;
+
return true;
}
diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp
index f2f28d51b..063aaf615 100644
--- a/eeschema/schframe.cpp
+++ b/eeschema/schframe.cpp
@@ -1446,10 +1446,13 @@ void SCH_EDIT_FRAME::addCurrentItemToList( bool aRedraw )
{
std::vector< wxPoint > pts;
item->GetConnectionPoints( pts );
- for( auto i : pts )
+ for( auto i = pts.begin(); i != pts.end(); i++ )
{
- if( screen->IsJunctionNeeded( i, true ) )
- AddJunction( i, true );
+ for( auto j = i + 1; j != pts.end(); j++ )
+ TrimWire( *i, *j, true );
+
+ if( screen->IsJunctionNeeded( *i, true ) )
+ AddJunction( *i, true );
}
screen->TestDanglingEnds();
}
diff --git a/eeschema/schframe.h b/eeschema/schframe.h
index 90366584d..e08082d7f 100644
--- a/eeschema/schframe.h
+++ b/eeschema/schframe.h
@@ -471,9 +471,11 @@ public:
* @param aSegment Line segment to break
* @param aPoint Point at which to break the segment
* @param aAppend Add the changes to the previous undo state
+ * @param aNewSegment Pointer to the newly created segment (if given and created)
* @return True if any wires or buses were broken.
*/
- bool BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend = false );
+ bool BreakSegment( SCH_LINE* aSegment, const wxPoint& aPoint, bool aAppend = false,
+ SCH_LINE** aNewSegment = NULL );
/**
* Checks every wire and bus for a intersection at \a aPoint and break into two segments
@@ -958,6 +960,16 @@ private:
bool SchematicCleanUp( bool aAppend = false );
/**
+ * If any single wire passes through _both points_, remove the portion between the two points,
+ * potentially splitting the wire into two.
+ *
+ * @param aStart The starting point for trimmming
+ * @param aEnd The ending point for trimming
+ * @param aAppend Should the line changes be appended to a previous undo state
+ */
+ void TrimWire( const wxPoint& aStart, const wxPoint& aEnd, bool aAppend = true );
+
+ /**
* Start moving \a aItem using the mouse.
*
* @param aItem A pointer to an SCH_ITEM to move.
--
2.11.0
Follow ups
References