kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #08454
Junction cleanup
Hi,
The attached patch adds testing and cleanup of multiple junctions in the
same spot to the function SCH_SCREEN::SchematicCleanUp
After some testing I'm still not quite sure why multiple junctions are
being placed automatically. I can not seem to get it to happen
consistently, but it happens often enough that the few schematics I
looked at all had duplicate junctions. I may try and dig into that
deeper later. The benefit of adding this to the SchematicCleanUp
function is that it will clean up existing schematics as soon as someone
makes a wire.
I also cleaned up SCH_EDIT_FRAME::EndSegment and removed what seemed to
be a lot of unnecessary copying of wires back and forth to a temporary
DLIST and the screen. It did not affect the undo/redo and everything
seems to work fine after my changes from my testing. It should also
speed up creating wires.
Next spare time I get I plan on adding hit testing for manually placing
junctions and no-connects to prevent multiples from being placed manually.
Moses
=== modified file 'eeschema/bus-wire-junction.cpp'
--- eeschema/bus-wire-junction.cpp 2012-03-19 07:48:29 +0000
+++ eeschema/bus-wire-junction.cpp 2012-06-17 04:00:25 +0000
@@ -255,14 +255,7 @@
screen->SetCurItem( NULL );
m_canvas->EndMouseCapture( -1, -1, wxEmptyString, false );
- DLIST< SCH_ITEM > tmp;
-
- for( item = s_wires.begin(); item != NULL; item = item->Next() )
- tmp.PushBack( (SCH_ITEM*) item->Clone() );
-
- // Temporarily add the new segments to the schematic item list to test if any
- // junctions are required.
- screen->Append( tmp );
+ screen->Append( s_wires );
// Correct and remove segments that need merged.
screen->SchematicCleanUp( NULL, DC );
@@ -271,27 +264,15 @@
// removed by a cleanup, a junction may be needed to connect the segment's end point
// which is also the same as the previous segment's start point.
if( screen->IsJunctionNeeded( segment->GetEndPoint() ) )
- s_wires.Append( AddJunction( DC, segment->GetEndPoint() ) );
+ screen->Append( AddJunction( DC, segment->GetEndPoint() ) );
else if( screen->IsJunctionNeeded( segment->GetStartPoint() ) )
- s_wires.Append( AddJunction( DC, segment->GetStartPoint() ) );
+ screen->Append( AddJunction( DC, segment->GetStartPoint() ) );
// Automatically place a junction on the start point if necessary because the cleanup
// can suppress intermediate points by merging wire segments.
if( screen->IsJunctionNeeded( s_startPoint ) )
- s_wires.Append( AddJunction( DC, s_startPoint ) );
-
- // Make a copy of the original wires, buses, and junctions.
- for( item = s_oldWires.begin(); item != NULL; item = item->Next() )
- tmp.PushBack( (SCH_ITEM*) item->Clone() );
-
- // Restore the old wires.
- if( tmp.GetCount() != 0 )
- screen->ReplaceWires( tmp );
-
- // Now add the new wires and any required junctions to the schematic item list.
- screen->Append( s_wires );
-
- screen->SchematicCleanUp( NULL, DC );
+ screen->Append( AddJunction( DC, s_startPoint ) );
+
m_canvas->Refresh();
// Put the snap shot of the previous wire, buses, and junctions in the undo/redo list.
=== modified file 'eeschema/sch_screen.cpp'
--- eeschema/sch_screen.cpp 2012-05-27 00:19:12 +0000
+++ eeschema/sch_screen.cpp 2012-06-17 04:05:27 +0000
@@ -434,14 +434,14 @@
for( ; item != NULL; item = item->Next() )
{
- if( item->Type() != SCH_LINE_T )
+ if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) )
continue;
testItem = item->Next();
while( testItem )
{
- if( testItem->Type() == SCH_LINE_T )
+ if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) )
{
SCH_LINE* line = (SCH_LINE*) item;
@@ -458,6 +458,21 @@
testItem = testItem->Next();
}
}
+ else if ( ( ( item->Type() == SCH_JUNCTION_T ) && ( testItem->Type() == SCH_JUNCTION_T ) ) && ( testItem != item ) )
+ {
+ if ( testItem->HitTest( item->GetPosition() ) )
+ {
+ // Keep the current flags, because the deleted segment can be flagged.
+ item->SetFlags( testItem->GetFlags() );
+ DeleteItem( testItem );
+ testItem = m_drawList.begin();
+ modified = true;
+ }
+ else
+ {
+ testItem = testItem->Next();
+ }
+ }
else
{
testItem = testItem->Next();