← Back to team overview

kicad-developers team mailing list archive

Re: [Patch] pcbnew clipboard support

 

Hi tom!

I took a look at your branch and your changes are a lot more smooth than mine, I went back to your implementation and added the net propagation stuff, they did indeed crash kicad when copying between different PCBs. How should I submit this patch to you?

Also, I think that we should think how we should address the situation proper, since if we copy from a pcb with 4 layers to a pcb with 2 layers. What would be the correct way?

Personally I think that warning the user with a dialog if extra layers are going to be added, explaining that extra layers will be added is the correct way of doing this. But when doing this, this [1] bug must be addressed, since it will become more problematic with copy-pasting.

[1] https://bugs.launchpad.net/kicad/+bug/893950

My attached patch makes applies on top of your changes tom.

 -Kristoffer

On 09/25/2017 11:46 AM, Tomasz Wlostowski wrote:
On 25.09.2017 10:03, Kristoffer Ödmark wrote:
Maybe I could get access to the work you have done and cherry pick
patches from there, or just test it and see the difference?

Hi,

Sorry, I totally forgot to send you the link:

https://github.com/twlostow/kicad-dev/tree/tom-copypasta

Tom


- Kristoffer

On 09/25/2017 01:15 AM, Kristoffer Ödmark wrote:
On 09/25/2017 12:21 AM, Tomasz Wlostowski wrote:

Hi Kristoffer,

I've had some time to work on your code during the past few days (I
wasn't aware you're still improving it). I fixed the crashes, refactored
placement of pasted items, fixed the zone refill issue, added snapping
to item's anchors and selection of a reference point.

I was not sure that I would find time to improve the code myself.
I fixed the crashes, and refactored the placement, and fixed the
zone-refill aswell.

The adding of a reference point I assume are all on the copy-side of
the code, I have not changed that one in a while so that could be
merged to either one of our branches

The only outstanding bug I'm aware of is with net code propagation (not
updated after pasting items).
I am not sure what you mean here? I add all the nets that are not
existing on the current board and that are used by the imported items,
I add them as new nets on the current board ( by creating a
NETINFO_ITEM with -1 as netcode and adding it )
pcbnew_control.cpp:847-860 in my branch for an example of how. And it
seems to work.


How do you want to proceed with this? I'd like to merge the copy&paste
feature as soon as possible.
I would also like the functionality merged as soon as possible and
although it is unfortunate that we have now done some duplicate work,
it seems you have made some more improvements than me. Merge what you
seem fit.


Best,
Tom



>From 441e4d499b9b5c32583ef909c98ebccde383f058 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20=C3=96dmark?= <kristoffer.odmark90@xxxxxxxxx>
Date: Mon, 25 Sep 2017 23:37:59 +0200
Subject: [PATCH] Propagate nets and layers when moving from one layer to the
 other

---
 pcbnew/tools/pcbnew_control.cpp | 60 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp
index ff9248645..34d0d0dbe 100644
--- a/pcbnew/tools/pcbnew_control.cpp
+++ b/pcbnew/tools/pcbnew_control.cpp
@@ -835,14 +835,56 @@ int PCBNEW_CONTROL::AppendBoardFromFile( const TOOL_EVENT& aEvent )
 int PCBNEW_CONTROL::placeBoardItems( BOARD* aBoard )
 {
     std::vector<BOARD_ITEM*> items;
+    auto currentBoard = board();
+
+    PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
+
+    if( currentBoard->GetCopperLayerCount() < aBoard->GetCopperLayerCount() )
+    {
+
+        if( !IsOK( editFrame, _( "Pasting will add extra layers to the PCB, continue? ") ) )
+            return 0;
+
+        currentBoard->SetCopperLayerCount( aBoard->GetCopperLayerCount() );
+        currentBoard->SetEnabledLayers( aBoard->GetEnabledLayers() );
+
+        editFrame->ReCreateLayerBox();
+        editFrame->ReFillLayerWidget();
+    }
 
     for( auto track : aBoard->Tracks() )
     {
+        if( !currentBoard->FindNet( track->GetNetname() ) )
+        {
+            NETINFO_ITEM* newNet = new NETINFO_ITEM( currentBoard,
+                        track->GetNet()->GetNetname(), -1 );
+            currentBoard->Add( newNet );
+            currentBoard->BuildListOfNets();
+        }
+        track->SetParent( currentBoard );
+        track->SetNet( currentBoard->FindNet( track->GetNetname()) );
         items.push_back( track );
     }
 
     for( auto module : aBoard->Modules() )
     {
+        module->SetParent( currentBoard );
+        for( auto pad : module->Pads() )
+        {
+        // Check if the net is there by name, otherwise, add a new net and
+        // reassign the item to the new net
+            if( !currentBoard->FindNet( pad->GetNet()->GetNetname() ) )
+            {
+                // A net with -1 in netcode will be autoassigned a net
+                NETINFO_ITEM* newNet = new NETINFO_ITEM( currentBoard,
+                        pad->GetNet()->GetNetname(), -1 );
+                currentBoard->Add( newNet );
+                currentBoard->BuildListOfNets();
+            }
+            pad->SetParent( module );
+            pad->SetNet( currentBoard->FindNet( pad->GetNetname() ) );
+        }
+
         items.push_back( module );
     }
 
@@ -853,9 +895,27 @@ int PCBNEW_CONTROL::placeBoardItems( BOARD* aBoard )
 
     for( auto zone : aBoard->Zones() )
     {
+        // Check if the net is there by name, otherwise, add a new net and
+        // reassign the item to the new net
+        if( !currentBoard->FindNet( zone->GetNet()->GetNetname() ) )
+        {
+            NETINFO_ITEM* newNet = new NETINFO_ITEM( currentBoard,
+                    zone->GetNet()->GetNetname(), -1 );
+            currentBoard->Add( newNet );
+            currentBoard->BuildListOfNets();
+        }
+        zone->SetParent( currentBoard );
+        zone->SetNet( currentBoard->FindNet( zone->GetNetname() ) );
         items.push_back( zone );
     }
 
+    // A lot of changes to the nets may have happen, be on the safe side
+    // and rebuild these things
+    currentBoard->BuildListOfNets();
+    currentBoard->SynchronizeNetsAndNetClasses();
+    currentBoard->GetConnectivity()->RecalculateRatsnest();
+
+    // the list of items should now be sanitized to fit on the current board
     return placeBoardItems( items );
 }
 
-- 
2.14.1


Follow ups

References