← Back to team overview

kicad-developers team mailing list archive

Re: Back annotate references from PCB

 

Dear all!
Thanks for your helpful comments. I want to show you draft of what
I've done for just now.
I know, that sometimes people don't like if somebody change their
code, I just rearranged some. In existing algorithms I divide method
to 2 parts for I could reuse it in my patch(made
checkForDuplicatedElements from SCH_REFERENCE_LIST::CheckAnnotation).
I just cannot find better solution to do that. And I added some helper
functions to the SCH_REFERENCE with witch you can get data about
component faster. I would say that changes should be in separate
commit. If them acceptable, should I divide my patch when it will be
ready?
In old pieces where I touched the code, I tried to leave code
formatting like it was. I'm not sure if I had to. Git checks suggest
to reformat it, but I feel it looks better like it's done already.
I almost haven't done anything with design. I just added "Back
annotate from PCB" option to the annotation dialog (see in the
screenshot) and I had a plan to grey out some not useful(for back
annoation) dialog options when you chose that option and enable them
back when you moved to another one.
But... Eeli came with idea that if PCB holds not only references, but
also footprints and values, we can back-annotate them to the schematic
as well. I would say, you need to have checkboxes then with options
"references, values, footprints" and probably that's better to make a
new dialog for that. I don't like to create new dialog, but if I will
add them to existing annotation dialog, I believe that will look
messy. What would you think?
Can you advice me with some code design? In my primary job I usually
want to split functions on small pieces, but in that case it will be
too much methods in the class. So, normally I'm trying to split
classes as well. Now I see that SCH_EDIT_FRAME is already very big. So
I don't want to have more than one method for back-annotation. Is it
ok to use some independent function, (which is not member of
SCH_EDIT_FRAME) like I did in annotate.cpp (int
getPcbModulesFromCPTREE) ?
And if you have any other code suggestions please, don't hesitate to tell.
Wayne, I've checked my code behavior with multi components, with
components re-used in schematics in one project or separate projects,
with PCB which is not up to date with schematic and it don't break it.
If it found any errors it opens "Update PCB from Schematic" dialog
Another thing is: I was looking for undo/redo feature and now it holds
different changes for different sheets. Basically if you back annotate
more than one sch files, you can run undo only for one sheet. I would
say in that case there's no point to implement undo/redo feature now,
as it will confuse a lot. Or undo behavior has to be changed somehow.
You don't have undo feature in annotation either, probably for same
reason.

Many thanks, I hope my patch is not very bad.
You can find that patch in my fork:
https://github.com/jasuramme/kicad-source-mirror/commit/64dc222de6149cc789158db80bbe0696cf47dc3d


On Wed, 27 Nov 2019 at 11:15, mitjan696-ubuntu@xxxxxxxxxxx
<mitjan696-ubuntu@xxxxxxxxxxx> wrote:
>
> I'll offer my thoughts on the subject bear in mind that I have zero knowledge of KiCad code internals and I could not really follow parts of this discussion.
>
> With back-annotation you really have a locking issue. Before re-annotating the layout, you have to make sure that the layout is in sync with schematics. And once you re-annotate the layout you have to make sure that there are no changes made to schematics until you back-annotate the schematics.
>
> Now I see two options how to do this:
> a. backannotate when a single footprint reference changes
>     1. Detect when a footprint reference changes
>     2. notify the user that you'll update layout from schematics
>     3. update the pcb from schematics
>     4. if update went without changes, change the reference of a footprint
>     5. back-annotate the schematics
> b. backannotate only when references for whole board have been changed
>     1. when the user triggers geographical renaming (from the tools menu) open a GUI to let the user select how should the renaming proceed (up-down, left to right, ...)
>     2. when the user selects the strategy notify the user that you'll update layout from schematics
>     3. update the pcb from schematics once
>     4. if update went without changes, change the reference for all the footprints
>     5. back-annotate the schematics once
>
> Option a is universal so that user could change references manually and it makes realization of option b much simpler. It could even be implemented as an action plugin. But then the geographical re-annotation of a whole board would run much slower when the backend of this method uses option a as you would have a lot of back and forth between schematics and layout. But on the other hand it might serve as a starting point for pin and unit swapping back-annotation.
>
> Most tools that I've worked with used some kind of form of option b (usually the back-annotation was partly manual with importing the back-annotation info in a file format). I think that the reason behind it is that most common footprint reference re-annotation is geographical. I've never heard of some other strategy.
>
> Thanks for working on it, I'll appreciate any kind of solution.
>
>
> On Sunday, 24 November 2019, 13:56:17 CET, Alexander Shuklin <jasuramme@xxxxxxxxx> wrote:
>
>
> Hi Eeli,
> no, you are actually right.
> I just don't want to make a new dialog before we will be sure that we
> definitely need it. But in case that you will propagate not only
> references you suppose to have new one.
>
> On Sun, 24 Nov 2019 at 12:27, Eeli Kaikkonen <eeli.kaikkonen@xxxxxxxxx> wrote:
> >
> > I probably don't understand everything which has been said, but as far as I can see there are actually two things going on which could and should be independent.
> >
> > 1. Doing geographical reannotation in pcb.
> > 2. Propagating changes made in the pcb back to the schematic.
> >
> > I believe they should be completely different, and number 2 should be generic, taking care of all changes which reasonably can be propagated from the board to the schematic. Basically Update PCB from Schematic backwards, i.e. Update Schematic from Board. With a similar UI dialog, of course. Undo could also be similar. Or do I just think it's so "simple" and can't see something?
> >
> > It's easy to see that number 1 isn't difficult and could be done with a python script (although many people would like to see it in the main KiCad, I think).
> >
> > Eeli Kaikkonen
> >
> > su 24. marrask. 2019 klo 8.57 Alexander Shuklin (jasuramme@xxxxxxxxx) kirjoitti:
> >>
> >> Hi Eeli and Brian,
> >> Sorry for delay, unfortunately I cannot answer too often.
> >>
> >> > It has occurred to me (Alexander please chime in) that once back annotation has been solved subject to all the issues raised by Wayne and others that it would be a general solution.
> >>
> >> Unfortunately no. All stuff mentioned by Wayne is has to be
> >> implemented in back-annotation, that's situations which back
> >> annotation will have to care about, otherwise it will be crap. I meant
> >> I see some general tool as geometrical (geographical?) re-annotation
> >> in pcbnew, which do left->right top->down or opposite directions being
> >> in C++ GUI, but if you want re-annotate in some different manner, you
> >> are free to use python scripts, as you could easily back annotate
> >> after that.
> >>
> >> > Can this do other kinds of changes than just annotation? I'm thinking of changing the footprint or value
> >>
> >> Of course that's possible, and not a big deal to add this into
> >> back-annotation algorithm. I just think how to do it better. I would
> >> say we will need to have some GUI for that then. I mean, you probably
> >> want to choose what do you want to back-annotate... or maybe not. And
> >> unfortunately at this point you cannot do that with python, as there
> >> no python scripts in schematic editor. If it will be useful, I can do
> >> that of course. Eeli, what I would suggest, I believe in few days I
> >> will make draft commit and mark it (Work In Progress) to show how It
> >> works, and we could discuss how it's gonna work with values and
> >> footprints it will not be a big deal to change it.
> >>
> >> On Sat, 23 Nov 2019 at 21:03, Brian Piccioni
> >> <brian@xxxxxxxxxxxxxxxxxxxxx> wrote:
> >> >
> >> > It has occurred to me (Alexander please chime in) that once back annotation has been solved subject to all the issues raised by Wayne and others that it would be a general solution.
> >> >
> >> >
> >> >
> >> > Of course, this would end up being a sizeable change to Kicad since the various edit functions, etc., who have to be modified to incorporate the feature.
> >> >
> >> >
> >> >
> >> > Like you I often fiddle with different packages and values and I typically switch to eeSchema, make the change, then hit F8 to update the PCB. It seems to me it would be easier for the appropriate changes to simply be reflected back to the schematic.
> >> >
> >> >
> >> >
> >> > Brian
> >> >
> >> >
> >> >
> >> > From: Eeli Kaikkonen
> >> > Sent: November 23, 2019 12:56 PM
> >> > To: kicad-developers
> >> > Subject: Re: [Kicad-developers] Back annotate references from PCB
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > la 23. marrask. 2019 klo 14.52 Brian Piccioni (brian@xxxxxxxxxxxxxxxxxxxxx) kirjoitti:
> >> >
> >> > By having a single integrated tool analogous to “Update PCB >From Schematic” can ensure coherency.
> >> >
> >> > Can this do other kinds of changes than just annotation? I'm thinking of changing the footprint or value. For example I could use Change Footprint feature in pcbnew and propagate that change to eeschema. That's not so difficult to do in eeshcema and update the board, but often it would feel much more natural to e.g. test if 0402 R package would be physically better for some situation than 0603 and then update the shcematic based on the board if it fits.
> >> >
> >> >
> >> >
> >> > Eeli Kaikkonen
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > 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
>
> _______________________________________________
> 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 64dc222de6149cc789158db80bbe0696cf47dc3d Mon Sep 17 00:00:00 2001
From: Alexander <alexandr.shuklin@xxxxxxxxxxxx>
Date: Thu, 28 Nov 2019 14:49:01 +0300
Subject: [PATCH] EEschema: adding back annotation feature [DRAFT][WIP]
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.24.0"

This is a multi-part message in MIME format.
--------------2.24.0
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


ADDED: Back annotation algorithm

CHANGED: EEschema->tools->Annotate Schematic dialog
---
 eeschema/annotate.cpp                     | 214 ++++++++++++-
 eeschema/component_references_lister.cpp  |  61 ++--
 eeschema/dialogs/dialog_annotate.cpp      |  87 +++--
 eeschema/dialogs/dialog_annotate_base.cpp | 286 ++++++++---------
 eeschema/dialogs/dialog_annotate_base.fbp | 368 +---------------------
 eeschema/dialogs/dialog_annotate_base.h   |  71 ++---
 eeschema/sch_edit_frame.cpp               |  21 ++
 eeschema/sch_edit_frame.h                 |  18 ++
 eeschema/sch_reference_list.h             |  31 +-
 include/mail_type.h                       |   3 +-
 pcbnew/cross-probing.cpp                  |  16 +-
 11 files changed, 585 insertions(+), 591 deletions(-)


--------------2.24.0
Content-Type: text/x-patch; name="0001-EEschema-adding-back-annotation-feature-DRAFT-WIP.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-EEschema-adding-back-annotation-feature-DRAFT-WIP.patch"

diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp
index 353f40f4a..8bc45041a 100644
--- a/eeschema/annotate.cpp
+++ b/eeschema/annotate.cpp
@@ -27,16 +27,15 @@
  */
 
 #include <algorithm>
-
-#include <fctsys.h>
-#include <sch_draw_panel.h>
+#include <boost/property_tree/ptree.hpp>
+#include <class_library.h>
 #include <confirm.h>
+#include <fctsys.h>
+#include <ptree.h>
 #include <reporter.h>
+#include <sch_draw_panel.h>
 #include <sch_edit_frame.h>
-
 #include <sch_reference_list.h>
-#include <class_library.h>
-
 
 void mapExistingAnnotation( std::map<timestamp_t, wxString>& aMap )
 {
@@ -78,6 +77,209 @@ void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
     OnModify();
 }
 
+// used locally in back-annotation
+struct PCB_MODULE_DATA
+{
+    wxString ref;
+    wxString value;
+};
+
+using PCB_MODULES      = std::map<wxString, PCB_MODULE_DATA>;
+using PCB_MODULES_ITEM = std::pair<wxString, PCB_MODULE_DATA>;
+using CHANGELIST_ITEM  = std::pair<SCH_REFERENCE, PCB_MODULE_DATA>;
+using CHANGELIST       = std::deque<CHANGELIST_ITEM>;
+
+int getPcbModulesFromCPTREE( const CPTREE& tree, REPORTER& aReporter, PCB_MODULES& aModules )
+{
+    int errors = 0;
+    aModules.clear();
+    for( auto& item : tree )
+    {
+        wxString path, value;
+        wxASSERT( item.first == "ref" );
+        wxString ref = (UTF8&) item.second.front().first;
+        try
+        {
+            path = (UTF8&) item.second.get_child( "timestamp" ).front().first;
+            value = (UTF8&) item.second.get_child( "value" ).front().first;
+        }
+        catch( boost::property_tree::ptree_bad_path& e )
+        {
+            wxASSERT_MSG( true, "Cannot parse PCB netlist for back-annotation" );
+        }
+
+        auto nearestItem = aModules.lower_bound( path );
+        if( nearestItem != aModules.end() && nearestItem->first == path )
+        {
+            wxString msg;
+            msg.Printf( _( "Pcb footprints %s and %s linked to same component" ),
+                    nearestItem->second.ref, ref );
+            aReporter.ReportHead( msg, REPORTER::RPT_ERROR );
+            ++errors;
+        }
+        else
+        {
+            PCB_MODULE_DATA data{ ref, value };
+            aModules.insert( nearestItem, PCB_MODULES_ITEM( path, data ) );
+        }
+    }
+    return errors;
+}
+
+bool SCH_EDIT_FRAME::BackAnnotateComponents(
+        const std::string& aNetlist, REPORTER& aReporter, bool aDryRun )
+{
+    wxString msg;
+    //Read incoming std::string from KiwayMailIn to the property tree
+    DSNLEXER lexer( aNetlist, FROM_UTF8( __func__ ) );
+    PTREE    doc;
+    Scan( &doc, &lexer );
+    CPTREE&     back_anno = doc.get_child( "pcb_netlist" );
+    PCB_MODULES pcbModules;
+    int         errorsFound = getPcbModulesFromCPTREE( back_anno, aReporter, pcbModules );
+
+    // Build the sheet list and get all used components
+    SCH_SHEET_LIST     sheets( g_RootSheet );
+    SCH_REFERENCE_LIST refs;
+    sheets.GetComponents( refs );
+
+    refs.SortByTimeStamp();
+    errorsFound += refs.checkForDuplicatedElements( aReporter );
+
+    // Get all multi units components, such as U1A, U1B, etc...
+    SCH_MULTI_UNIT_REFERENCE_MAP schMultiunits;
+    sheets.GetMultiUnitComponents( schMultiunits );
+    // We will store here pcb components references, which has no representation in shematic
+    std::deque<UTF8> pcbUnconnected;
+
+    // Remove multi units and power symbols here
+    for( size_t i = 0; i < refs.GetCount(); ++i )
+    {
+        if( refs[i].GetComp()->GetUnitCount() > 1
+                or !refs[i].GetComp()->GetPartRef().lock()->IsNormal() )
+            refs.RemoveItem( i-- );
+    }
+
+    // Find links between PCB footprints and schematic components. Once any link found,
+    // component will be removed from corresponding list.
+    CHANGELIST changeList;
+    for( auto& module : pcbModules )
+    {
+        // Data retrieved from PCB
+        const wxString& pcbPath = module.first;
+        const wxString& pcbRef = module.second.ref;
+        const wxString& pcbValue = module.second.value;
+        bool            foundInMultiunit = false;
+
+        for( SCH_MULTI_UNIT_REFERENCE_MAP::iterator part = schMultiunits.begin();
+                part != schMultiunits.end(); ++part )
+        {
+            SCH_REFERENCE_LIST& partRefs = part->second;
+
+            // If pcb unit found in multi unit components, process all units straight away
+            if( partRefs.FindRefByPath( pcbPath ) >= 0 )
+            {
+                foundInMultiunit = true;
+                for( size_t i = 0; i < partRefs.GetCount(); ++i )
+                {
+                    SCH_REFERENCE& schRef = partRefs[i];
+                    if( schRef.GetRef() != pcbRef )
+                        changeList.push_back( CHANGELIST_ITEM( schRef, module.second ) );
+                }
+                schMultiunits.erase( part );
+                break;
+            }
+        }
+        if( foundInMultiunit )
+            // We deleted all multi units from references list, so we don't need to go further
+            continue;
+
+        // Process simple components
+        int refIdx = refs.FindRefByPath( pcbPath );
+        if( refIdx >= 0 )
+        {
+            SCH_REFERENCE& schRef = refs[refIdx];
+            if( schRef.GetRef() != pcbRef )
+                changeList.push_back( CHANGELIST_ITEM( schRef, module.second ) );
+            refs.RemoveItem( refIdx );
+        }
+        else
+        {
+            // We haven't found link between footprint and common units or multi-units
+            msg.Printf( _( "Cannot find component for %s footprint" ), pcbRef );
+            ++errorsFound;
+            aReporter.ReportTail( msg, REPORTER::RPT_ERROR );
+        }
+    }
+
+
+    // Report
+    for( size_t i = 0; i < refs.GetCount(); ++i )
+    {
+        msg.Printf( _( "Cannot find footprint for %s component" ), refs[i].GetRef() );
+        aReporter.ReportTail( msg, REPORTER::RPT_ERROR );
+        ++errorsFound;
+    }
+
+    for( auto& comp : schMultiunits )
+    {
+        auto& refList = comp.second;
+        for( size_t i = 0; i < refList.GetCount(); ++i )
+        {
+            msg.Printf( _( "Cannot find footprint for %s%s component" ), refs[i].GetRef(),
+                    LIB_PART::SubReference( refs[i].GetUnit(), false ) );
+            aReporter.ReportTail( msg, REPORTER::RPT_ERROR );
+        }
+        ++errorsFound;
+    }
+
+    // Apply changes from change list
+    for( auto& item : changeList )
+    {
+        SCH_REFERENCE&   ref = item.first;
+        PCB_MODULE_DATA& module = item.second;
+        if( ref.GetComp()->GetUnitCount() <= 1 )
+            msg.Printf( _( "Change %s -> %s" ), ref.GetRef(), module.ref );
+        else
+        {
+            wxString unit = LIB_PART::SubReference( ref.GetUnit() );
+            msg.Printf( _( "Change %s%s -> %s%s" ), ref.GetRef(), unit, module.ref, unit );
+        }
+        aReporter.ReportHead( msg, aDryRun ? REPORTER::RPT_INFO : REPORTER::RPT_ACTION );
+        if( !aDryRun )
+            item.first.GetComp()->SetRef( &item.first.GetSheetPath(), item.second.ref );
+    }
+
+    // Report
+    if( !errorsFound )
+    {
+        if( !aDryRun )
+        {
+            aReporter.ReportTail( _( "Schematic is back-annotated." ), REPORTER::RPT_ACTION );
+            g_CurrentSheet->UpdateAllScreenReferences();
+            SetSheetNumberAndCount();
+
+            SyncView();
+            OnModify();
+            GetCanvas()->Refresh();
+        }
+        else
+            aReporter.ReportTail(
+                    _( "No errors  during dry run. Ready to go." ), REPORTER::RPT_ACTION );
+    }
+    else
+    {
+        msg.Printf( _( "Found %d errors. Fix them and run back annotation again." ), errorsFound );
+        aReporter.ReportTail( msg, REPORTER::RPT_ERROR );
+    }
+
+
+    if( errorsFound )
+        return false;
+    else
+        return true;
+}
+
 
 void SCH_EDIT_FRAME::AnnotateComponents( bool              aAnnotateSchematic,
                                          ANNOTATE_ORDER_T  aSortOption,
diff --git a/eeschema/component_references_lister.cpp b/eeschema/component_references_lister.cpp
index 7f357866a..9ced15f0e 100644
--- a/eeschema/component_references_lister.cpp
+++ b/eeschema/component_references_lister.cpp
@@ -162,6 +162,13 @@ int SCH_REFERENCE_LIST::FindUnit( size_t aIndex, int aUnit )
     return -1;
 }
 
+int SCH_REFERENCE_LIST::FindRefByPath( const wxString& aPath ) const
+{
+    for( size_t i = 0; i < componentFlatList.size(); ++i )
+        if( componentFlatList[i].GetPath() == aPath )
+            return i;
+    return -1;
+}
 
 void SCH_REFERENCE_LIST::RemoveSubComponentsFromList()
 {
@@ -531,6 +538,35 @@ void SCH_REFERENCE_LIST::Annotate( bool aUseSheetNum, int aSheetIntervalId, int
     }
 }
 
+int SCH_REFERENCE_LIST::checkForDuplicatedElements( REPORTER& aReporter )
+{
+    int      error = 0;
+    wxString msg;
+    for( size_t ii = 0; ii < componentFlatList.size() - 1; ii++ )
+    {
+        if(  ( componentFlatList[ii].m_TimeStamp != componentFlatList[ii + 1].m_TimeStamp )
+          || ( componentFlatList[ii].GetSheetPath() != componentFlatList[ii + 1].GetSheetPath() )  )
+            continue;
+
+        // Same time stamp found.
+        wxString full_path;
+
+        full_path.Printf( wxT( "%s%8.8X" ),
+                          GetChars( componentFlatList[ii].GetSheetPath().Path() ),
+                          componentFlatList[ii].m_TimeStamp );
+
+        msg.Printf( _( "Duplicate time stamp (%s) for %s%d and %s%d" ),
+                    full_path,
+                    componentFlatList[ii].GetRef(),
+                    componentFlatList[ii].m_NumRef,
+                    componentFlatList[ii + 1].GetRef(),
+                    componentFlatList[ii + 1].m_NumRef );
+
+        aReporter.Report( msg, REPORTER::RPT_WARNING );
+        error++;
+    }
+    return error;
+}
 
 int SCH_REFERENCE_LIST::CheckAnnotation( REPORTER& aReporter )
 {
@@ -694,30 +730,7 @@ int SCH_REFERENCE_LIST::CheckAnnotation( REPORTER& aReporter )
 
     // count the duplicated time stamps
     SortByTimeStamp();
-
-    for( int ii = 0; ii < imax; ii++ )
-    {
-        if(  ( componentFlatList[ii].m_TimeStamp != componentFlatList[ii + 1].m_TimeStamp )
-          || ( componentFlatList[ii].GetSheetPath() != componentFlatList[ii + 1].GetSheetPath() )  )
-            continue;
-
-        // Same time stamp found.
-        wxString full_path;
-
-        full_path.Printf( wxT( "%s%8.8X" ),
-                          GetChars( componentFlatList[ii].GetSheetPath().Path() ),
-                          componentFlatList[ii].m_TimeStamp );
-
-        msg.Printf( _( "Duplicate time stamp (%s) for %s%d and %s%d" ),
-                    full_path,
-                    componentFlatList[ii].GetRef(),
-                    componentFlatList[ii].m_NumRef,
-                    componentFlatList[ii + 1].GetRef(),
-                    componentFlatList[ii + 1].m_NumRef );
-
-        aReporter.Report( msg, REPORTER::RPT_WARNING );
-        error++;
-    }
+    error += checkForDuplicatedElements( aReporter );
 
     return error;
 }
diff --git a/eeschema/dialogs/dialog_annotate.cpp b/eeschema/dialogs/dialog_annotate.cpp
index 13792e985..5dbeb7466 100644
--- a/eeschema/dialogs/dialog_annotate.cpp
+++ b/eeschema/dialogs/dialog_annotate.cpp
@@ -69,6 +69,7 @@ private:
     void OnCloseClick( wxCommandEvent& event ) override;
     void OnClose( wxCloseEvent& event ) override;
     void OnApplyClick( wxCommandEvent& event ) override;
+    void OnRbOptionsChanged( wxCommandEvent& event ) override;
 
     // User functions:
     bool GetLevel();
@@ -191,33 +192,55 @@ void DIALOG_ANNOTATE::OnClose( wxCloseEvent& event )
 
 void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
 {
-    wxString    message;
 
-    // Ask for confirmation of destructive actions.
-    if( GetResetItems() )
+    m_MessageWindow->Clear();
+    REPORTER& reporter = m_MessageWindow->Reporter();
+    m_MessageWindow->SetLazyUpdate( true ); // Don't update after each message
+    wxString message;
+    if( m_rbOptions->GetSelection() == 3 )
     {
-        if( GetLevel() )
-            message += _( "Clear and annotate all of the symbols on the entire schematic?" );
-        else
-            message += _( "Clear and annotate all of the symbols on the current sheet?" );
-
-        message += _( "\n\nThis operation will change the current annotation and cannot be undone." );
-
+        message = _( "This operation will change the current annotation and cannot be undone." );
         KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
-        dlg.SetOKLabel( _( "Clear and Annotate" ) );
-        dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
-
         if( dlg.ShowModal() == wxCANCEL )
             return;
+        std::string netlist;
+        if( !m_Parent->FetchNetlistFromPCB( netlist ) )
+            return;
+        if( !m_Parent->BackAnnotateComponents( netlist, reporter, false ) )
+        {
+            message = _( "Errors occured. Please, fix them and run back-annotation again." );
+            KIDIALOG errDlg( this, message, _( "Error" ), wxOK | wxICON_ERROR );
+            errDlg.ShowModal();
+            wxCommandEvent dummy;
+            m_Parent->OnUpdatePCB( dummy );
+            return;
+        }
+    }
+    else
+    {
+        // Ask for confirmation of destructive actions.
+        if( GetResetItems() )
+        {
+            if( GetLevel() )
+                message += _( "Clear and annotate all of the symbols on the entire schematic?" );
+            else
+                message += _( "Clear and annotate all of the symbols on the current sheet?" );
+
+            message += _(
+                    "\n\nThis operation will change the current annotation and cannot be undone." );
+
+            KIDIALOG dlg( this, message, _( "Confirmation" ), wxOK | wxCANCEL | wxICON_WARNING );
+            dlg.SetOKLabel( _( "Clear and Annotate" ) );
+            dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
+
+            if( dlg.ShowModal() == wxCANCEL )
+                return;
+        }
+
+        m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
+                (ANNOTATE_OPTION_T) GetAnnotateAlgo(), GetStartNumber(), GetResetItems(), true,
+                GetLockUnits(), reporter );
     }
-
-    m_MessageWindow->Clear();
-    REPORTER& reporter = m_MessageWindow->Reporter();
-    m_MessageWindow->SetLazyUpdate( true );     // Don't update after each message
-
-    m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
-                                  (ANNOTATE_OPTION_T) GetAnnotateAlgo(), GetStartNumber(),
-                                  GetResetItems() , true, GetLockUnits(), reporter );
 
     m_MessageWindow->Flush( true );                   // Now update to show all messages
 
@@ -304,6 +327,28 @@ int DIALOG_ANNOTATE::GetStartNumber()
     return ValueFromString( EDA_UNITS_T::UNSCALED_UNITS, m_textNumberAfter->GetValue() );
 }
 
+void DIALOG_ANNOTATE::OnRbOptionsChanged( wxCommandEvent& event )
+{
+    if( event.GetInt() == 3 )
+    {
+        m_MessageWindow->Clear();
+        REPORTER& reporter = m_MessageWindow->Reporter();
+        m_MessageWindow->SetLazyUpdate( true );
+        std::string netlist;
+        if( !m_Parent->FetchNetlistFromPCB( netlist ) )
+            return;
+        m_Parent->BackAnnotateComponents( netlist, reporter, true );
+        m_MessageWindow->Flush( true );
+        m_Parent->GetCanvas()->Refresh();
+        m_btnClear->Enable();
+    }
+    else
+    {
+        m_MessageWindow->Clear();
+        m_btnClear->Disable();
+    }
+}
+
 
 void SCH_EDIT_FRAME::OnAnnotate( wxCommandEvent& event )
 {
diff --git a/eeschema/dialogs/dialog_annotate_base.cpp b/eeschema/dialogs/dialog_annotate_base.cpp
index 221d06676..7e1694603 100644
--- a/eeschema/dialogs/dialog_annotate_base.cpp
+++ b/eeschema/dialogs/dialog_annotate_base.cpp
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Dec 30 2017)
+// C++ code generated with wxFormBuilder (version Sep  1 2019)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO *NOT* EDIT THIS FILE!
@@ -13,149 +13,151 @@
 
 DIALOG_ANNOTATE_BASE::DIALOG_ANNOTATE_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style )
 {
-	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
-	
-	wxBoxSizer* bmainSizer;
-	bmainSizer = new wxBoxSizer( wxVERTICAL );
-	
-	wxBoxSizer* bupperSizer;
-	bupperSizer = new wxBoxSizer( wxVERTICAL );
-	
-	m_userMessage = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
-	m_userMessage->Wrap( 1 );
-	m_userMessage->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
-	m_userMessage->Hide();
-	
-	bupperSizer->Add( m_userMessage, 0, wxALL|wxEXPAND, 5 );
-	
-	wxFlexGridSizer* fgSizer1;
-	fgSizer1 = new wxFlexGridSizer( 2, 2, 0, 0 );
-	fgSizer1->AddGrowableCol( 0 );
-	fgSizer1->AddGrowableCol( 1 );
-	fgSizer1->SetFlexibleDirection( wxBOTH );
-	fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
-	
-	wxString m_rbScopeChoices[] = { _("Use the entire schematic"), _("Use the current page only") };
-	int m_rbScopeNChoices = sizeof( m_rbScopeChoices ) / sizeof( wxString );
-	m_rbScope = new wxRadioBox( this, wxID_ANY, _("Scope:"), wxDefaultPosition, wxDefaultSize, m_rbScopeNChoices, m_rbScopeChoices, 1, wxRA_SPECIFY_COLS );
-	m_rbScope->SetSelection( 0 );
-	fgSizer1->Add( m_rbScope, 0, wxALL|wxEXPAND, 5 );
-	
-	wxStaticBoxSizer* sbSizer1;
-	sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Order:") ), wxVERTICAL );
-	
-	wxBoxSizer* bSizerXpos;
-	bSizerXpos = new wxBoxSizer( wxHORIZONTAL );
-	
-	m_rbSortBy_X_Position = new wxRadioButton( sbSizer1->GetStaticBox(), ID_SORT_BY_X_POSITION, _("Sort components by &X position"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
-	bSizerXpos->Add( m_rbSortBy_X_Position, 0, wxBOTTOM|wxTOP, 3 );
-	
-	
-	bSizerXpos->Add( 0, 0, 1, 0, 5 );
-	
-	annotate_down_right_bitmap = new wxStaticBitmap( sbSizer1->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerXpos->Add( annotate_down_right_bitmap, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
-	
-	
-	sbSizer1->Add( bSizerXpos, 0, wxEXPAND, 5 );
-	
-	wxBoxSizer* bSizerYpos;
-	bSizerYpos = new wxBoxSizer( wxHORIZONTAL );
-	
-	m_rbSortBy_Y_Position = new wxRadioButton( sbSizer1->GetStaticBox(), ID_SORT_BY_Y_POSITION, _("Sort components by &Y position"), wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerYpos->Add( m_rbSortBy_Y_Position, 0, wxBOTTOM|wxTOP, 3 );
-	
-	
-	bSizerYpos->Add( 0, 0, 1, 0, 5 );
-	
-	annotate_right_down_bitmap = new wxStaticBitmap( sbSizer1->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerYpos->Add( annotate_right_down_bitmap, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
-	
-	
-	sbSizer1->Add( bSizerYpos, 0, wxEXPAND, 5 );
-	
-	
-	fgSizer1->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 );
-	
-	wxString m_rbOptionsChoices[] = { _("Keep existing annotations"), _("Reset existing annotations"), _("Reset, but keep order of multi-unit parts") };
-	int m_rbOptionsNChoices = sizeof( m_rbOptionsChoices ) / sizeof( wxString );
-	m_rbOptions = new wxRadioBox( this, wxID_ANY, _("Options:"), wxDefaultPosition, wxDefaultSize, m_rbOptionsNChoices, m_rbOptionsChoices, 1, wxRA_SPECIFY_COLS );
-	m_rbOptions->SetSelection( 0 );
-	fgSizer1->Add( m_rbOptions, 0, wxALL|wxEXPAND, 5 );
-	
-	wxStaticBoxSizer* sbSizer2;
-	sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Numbering:") ), wxVERTICAL );
-	
-	wxGridBagSizer* gbSizer1;
-	gbSizer1 = new wxGridBagSizer( 0, 0 );
-	gbSizer1->SetFlexibleDirection( wxBOTH );
-	gbSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
-	
-	m_rbFirstFree = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_FIRST_FREE, _("Use first free number after:"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
-	gbSizer1->Add( m_rbFirstFree, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxTOP, 2 );
-	
-	m_textNumberAfter = new wxTextCtrl( sbSizer2->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 60,-1 ), 0 );
-	gbSizer1->Add( m_textNumberAfter, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxLEFT, 2 );
-	
-	m_rbSheetX100 = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_SHEET_X_100, _("First free after sheet number X 100"), wxDefaultPosition, wxDefaultSize, 0 );
-	gbSizer1->Add( m_rbSheetX100, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxTOP, 4 );
-	
-	m_rbSheetX1000 = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_SHEET_X_1000, _("First free after sheet number X 1000"), wxDefaultPosition, wxDefaultSize, 0 );
-	gbSizer1->Add( m_rbSheetX1000, wxGBPosition( 2, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxTOP, 2 );
-	
-	
-	sbSizer2->Add( gbSizer1, 1, wxEXPAND, 5 );
-	
-	
-	fgSizer1->Add( sbSizer2, 1, wxALL|wxEXPAND, 5 );
-	
-	
-	bupperSizer->Add( fgSizer1, 0, wxBOTTOM|wxEXPAND, 5 );
-	
-	m_MessageWindow = new WX_HTML_REPORT_PANEL( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
-	m_MessageWindow->SetMinSize( wxSize( -1,120 ) );
-	
-	bupperSizer->Add( m_MessageWindow, 5, wxEXPAND|wxRIGHT|wxLEFT, 5 );
-	
-	
-	bmainSizer->Add( bupperSizer, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 6 );
-	
-	wxBoxSizer* m_buttonsSizer;
-	m_buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
-	
-	m_btnClear = new wxButton( this, ID_CLEAR_ANNOTATION_CMP, _("Clear Annotation"), wxDefaultPosition, wxDefaultSize, 0 );
-	m_buttonsSizer->Add( m_btnClear, 0, wxEXPAND|wxALL, 10 );
-	
-	m_sdbSizer1 = new wxStdDialogButtonSizer();
-	m_sdbSizer1OK = new wxButton( this, wxID_OK );
-	m_sdbSizer1->AddButton( m_sdbSizer1OK );
-	m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
-	m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
-	m_sdbSizer1->Realize();
-	
-	m_buttonsSizer->Add( m_sdbSizer1, 1, wxALL|wxEXPAND, 5 );
-	
-	
-	bmainSizer->Add( m_buttonsSizer, 0, wxEXPAND|wxLEFT, 5 );
-	
-	
-	this->SetSizer( bmainSizer );
-	this->Layout();
-	bmainSizer->Fit( this );
-	
-	// Connect Events
-	this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_ANNOTATE_BASE::OnClose ) );
-	m_btnClear->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnClearAnnotationCmpClick ), NULL, this );
-	m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnCloseClick ), NULL, this );
-	m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnApplyClick ), NULL, this );
+    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
+
+    wxBoxSizer* bmainSizer;
+    bmainSizer = new wxBoxSizer( wxVERTICAL );
+
+    wxBoxSizer* bupperSizer;
+    bupperSizer = new wxBoxSizer( wxVERTICAL );
+
+    m_userMessage = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
+    m_userMessage->Wrap( 1 );
+    m_userMessage->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
+    m_userMessage->Hide();
+
+    bupperSizer->Add( m_userMessage, 0, wxALL|wxEXPAND, 5 );
+
+    wxFlexGridSizer* fgSizer1;
+    fgSizer1 = new wxFlexGridSizer( 2, 2, 0, 0 );
+    fgSizer1->AddGrowableCol( 0 );
+    fgSizer1->AddGrowableCol( 1 );
+    fgSizer1->SetFlexibleDirection( wxBOTH );
+    fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+
+    wxString m_rbScopeChoices[] = { _("Use the entire schematic"), _("Use the current page only") };
+    int m_rbScopeNChoices = sizeof( m_rbScopeChoices ) / sizeof( wxString );
+    m_rbScope = new wxRadioBox( this, wxID_ANY, _("Scope:"), wxDefaultPosition, wxDefaultSize, m_rbScopeNChoices, m_rbScopeChoices, 1, wxRA_SPECIFY_COLS );
+    m_rbScope->SetSelection( 0 );
+    fgSizer1->Add( m_rbScope, 0, wxALL|wxEXPAND, 5 );
+
+    wxStaticBoxSizer* sbSizer1;
+    sbSizer1 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Order:") ), wxVERTICAL );
+
+    wxBoxSizer* bSizerXpos;
+    bSizerXpos = new wxBoxSizer( wxHORIZONTAL );
+
+    m_rbSortBy_X_Position = new wxRadioButton( sbSizer1->GetStaticBox(), ID_SORT_BY_X_POSITION, _("Sort components by &X position"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
+    bSizerXpos->Add( m_rbSortBy_X_Position, 0, wxBOTTOM|wxTOP, 3 );
+
+
+    bSizerXpos->Add( 0, 0, 1, 0, 5 );
+
+    annotate_down_right_bitmap = new wxStaticBitmap( sbSizer1->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
+    bSizerXpos->Add( annotate_down_right_bitmap, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
+
+
+    sbSizer1->Add( bSizerXpos, 0, wxEXPAND, 5 );
+
+    wxBoxSizer* bSizerYpos;
+    bSizerYpos = new wxBoxSizer( wxHORIZONTAL );
+
+    m_rbSortBy_Y_Position = new wxRadioButton( sbSizer1->GetStaticBox(), ID_SORT_BY_Y_POSITION, _("Sort components by &Y position"), wxDefaultPosition, wxDefaultSize, 0 );
+    bSizerYpos->Add( m_rbSortBy_Y_Position, 0, wxBOTTOM|wxTOP, 3 );
+
+
+    bSizerYpos->Add( 0, 0, 1, 0, 5 );
+
+    annotate_right_down_bitmap = new wxStaticBitmap( sbSizer1->GetStaticBox(), wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
+    bSizerYpos->Add( annotate_right_down_bitmap, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
+
+
+    sbSizer1->Add( bSizerYpos, 0, wxEXPAND, 5 );
+
+
+    fgSizer1->Add( sbSizer1, 0, wxALL|wxEXPAND, 5 );
+
+    wxString m_rbOptionsChoices[] = { _("Keep existing annotations"), _("Reset existing annotations"), _("Reset, but keep order of multi-unit parts"), _("Back annotate from PCB") };
+    int m_rbOptionsNChoices = sizeof( m_rbOptionsChoices ) / sizeof( wxString );
+    m_rbOptions = new wxRadioBox( this, wxID_ANY, _("Options:"), wxDefaultPosition, wxDefaultSize, m_rbOptionsNChoices, m_rbOptionsChoices, 1, wxRA_SPECIFY_COLS );
+    m_rbOptions->SetSelection( 0 );
+    fgSizer1->Add( m_rbOptions, 0, wxALL|wxEXPAND, 5 );
+
+    wxStaticBoxSizer* sbSizer2;
+    sbSizer2 = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Numbering:") ), wxVERTICAL );
+
+    wxGridBagSizer* gbSizer1;
+    gbSizer1 = new wxGridBagSizer( 0, 0 );
+    gbSizer1->SetFlexibleDirection( wxBOTH );
+    gbSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
+
+    m_rbFirstFree = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_FIRST_FREE, _("Use first free number after:"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP );
+    gbSizer1->Add( m_rbFirstFree, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxTOP, 2 );
+
+    m_textNumberAfter = new wxTextCtrl( sbSizer2->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 60,-1 ), 0 );
+    gbSizer1->Add( m_textNumberAfter, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxLEFT, 2 );
+
+    m_rbSheetX100 = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_SHEET_X_100, _("First free after sheet number X 100"), wxDefaultPosition, wxDefaultSize, 0 );
+    gbSizer1->Add( m_rbSheetX100, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxTOP, 4 );
+
+    m_rbSheetX1000 = new wxRadioButton( sbSizer2->GetStaticBox(), wxID_SHEET_X_1000, _("First free after sheet number X 1000"), wxDefaultPosition, wxDefaultSize, 0 );
+    gbSizer1->Add( m_rbSheetX1000, wxGBPosition( 2, 0 ), wxGBSpan( 1, 2 ), wxBOTTOM|wxTOP, 2 );
+
+
+    sbSizer2->Add( gbSizer1, 1, wxEXPAND, 5 );
+
+
+    fgSizer1->Add( sbSizer2, 1, wxALL|wxEXPAND, 5 );
+
+
+    bupperSizer->Add( fgSizer1, 0, wxBOTTOM|wxEXPAND, 5 );
+
+    m_MessageWindow = new WX_HTML_REPORT_PANEL( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
+    m_MessageWindow->SetMinSize( wxSize( -1,120 ) );
+
+    bupperSizer->Add( m_MessageWindow, 5, wxEXPAND|wxRIGHT|wxLEFT, 5 );
+
+
+    bmainSizer->Add( bupperSizer, 1, wxEXPAND|wxTOP|wxRIGHT|wxLEFT, 6 );
+
+    wxBoxSizer* m_buttonsSizer;
+    m_buttonsSizer = new wxBoxSizer( wxHORIZONTAL );
+
+    m_btnClear = new wxButton( this, ID_CLEAR_ANNOTATION_CMP, _("Clear Annotation"), wxDefaultPosition, wxDefaultSize, 0 );
+    m_buttonsSizer->Add( m_btnClear, 0, wxEXPAND|wxALL, 10 );
+
+    m_sdbSizer1 = new wxStdDialogButtonSizer();
+    m_sdbSizer1OK = new wxButton( this, wxID_OK );
+    m_sdbSizer1->AddButton( m_sdbSizer1OK );
+    m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL );
+    m_sdbSizer1->AddButton( m_sdbSizer1Cancel );
+    m_sdbSizer1->Realize();
+
+    m_buttonsSizer->Add( m_sdbSizer1, 1, wxALL|wxEXPAND, 5 );
+
+
+    bmainSizer->Add( m_buttonsSizer, 0, wxEXPAND|wxLEFT, 5 );
+
+
+    this->SetSizer( bmainSizer );
+    this->Layout();
+    bmainSizer->Fit( this );
+
+    // Connect Events
+    this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_ANNOTATE_BASE::OnClose ) );
+    m_rbOptions->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnRbOptionsChanged ), NULL, this );
+    m_btnClear->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnClearAnnotationCmpClick ), NULL, this );
+    m_sdbSizer1Cancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnCloseClick ), NULL, this );
+    m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnApplyClick ), NULL, this );
 }
 
 DIALOG_ANNOTATE_BASE::~DIALOG_ANNOTATE_BASE()
 {
-	// Disconnect Events
-	this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_ANNOTATE_BASE::OnClose ) );
-	m_btnClear->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnClearAnnotationCmpClick ), NULL, this );
-	m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnCloseClick ), NULL, this );
-	m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnApplyClick ), NULL, this );
-	
+    // Disconnect Events
+    this->Disconnect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_ANNOTATE_BASE::OnClose ) );
+    m_rbOptions->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnRbOptionsChanged ), NULL, this );
+    m_btnClear->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnClearAnnotationCmpClick ), NULL, this );
+    m_sdbSizer1Cancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnCloseClick ), NULL, this );
+    m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_ANNOTATE_BASE::OnApplyClick ), NULL, this );
+
 }
diff --git a/eeschema/dialogs/dialog_annotate_base.fbp b/eeschema/dialogs/dialog_annotate_base.fbp
index 0780a1988..5c272ae00 100644
--- a/eeschema/dialogs/dialog_annotate_base.fbp
+++ b/eeschema/dialogs/dialog_annotate_base.fbp
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 <wxFormBuilder_Project>
-    <FileVersion major="1" minor="13" />
+    <FileVersion major="1" minor="15" />
     <object class="Project" expanded="1">
         <property name="class_decoration"></property>
         <property name="code_generation">C++</property>
@@ -14,6 +14,7 @@
         <property name="file">dialog_annotate_base</property>
         <property name="first_id">1000</property>
         <property name="help_provider">none</property>
+        <property name="indent_with_spaces"></property>
         <property name="internationalize">1</property>
         <property name="name">dialog_annotate_base</property>
         <property name="namespace"></property>
@@ -52,42 +53,7 @@
             <property name="window_extra_style"></property>
             <property name="window_name"></property>
             <property name="window_style"></property>
-            <event name="OnActivate"></event>
-            <event name="OnActivateApp"></event>
-            <event name="OnAuiFindManager"></event>
-            <event name="OnAuiPaneButton"></event>
-            <event name="OnAuiPaneClose"></event>
-            <event name="OnAuiPaneMaximize"></event>
-            <event name="OnAuiPaneRestore"></event>
-            <event name="OnAuiRender"></event>
-            <event name="OnChar"></event>
             <event name="OnClose">OnClose</event>
-            <event name="OnEnterWindow"></event>
-            <event name="OnEraseBackground"></event>
-            <event name="OnHibernate"></event>
-            <event name="OnIconize"></event>
-            <event name="OnIdle"></event>
-            <event name="OnInitDialog"></event>
-            <event name="OnKeyDown"></event>
-            <event name="OnKeyUp"></event>
-            <event name="OnKillFocus"></event>
-            <event name="OnLeaveWindow"></event>
-            <event name="OnLeftDClick"></event>
-            <event name="OnLeftDown"></event>
-            <event name="OnLeftUp"></event>
-            <event name="OnMiddleDClick"></event>
-            <event name="OnMiddleDown"></event>
-            <event name="OnMiddleUp"></event>
-            <event name="OnMotion"></event>
-            <event name="OnMouseEvents"></event>
-            <event name="OnMouseWheel"></event>
-            <event name="OnPaint"></event>
-            <event name="OnRightDClick"></event>
-            <event name="OnRightDown"></event>
-            <event name="OnRightUp"></event>
-            <event name="OnSetFocus"></event>
-            <event name="OnSize"></event>
-            <event name="OnUpdateUI"></event>
             <object class="wxBoxSizer" expanded="1">
                 <property name="minimum_size"></property>
                 <property name="name">bmainSizer</property>
@@ -135,6 +101,7 @@
                                 <property name="hidden">1</property>
                                 <property name="id">wxID_ANY</property>
                                 <property name="label"></property>
+                                <property name="markup">0</property>
                                 <property name="max_size"></property>
                                 <property name="maximize_button">0</property>
                                 <property name="maximum_size"></property>
@@ -160,29 +127,6 @@
                                 <property name="window_name"></property>
                                 <property name="window_style"></property>
                                 <property name="wrap">1</property>
-                                <event name="OnChar"></event>
-                                <event name="OnEnterWindow"></event>
-                                <event name="OnEraseBackground"></event>
-                                <event name="OnKeyDown"></event>
-                                <event name="OnKeyUp"></event>
-                                <event name="OnKillFocus"></event>
-                                <event name="OnLeaveWindow"></event>
-                                <event name="OnLeftDClick"></event>
-                                <event name="OnLeftDown"></event>
-                                <event name="OnLeftUp"></event>
-                                <event name="OnMiddleDClick"></event>
-                                <event name="OnMiddleDown"></event>
-                                <event name="OnMiddleUp"></event>
-                                <event name="OnMotion"></event>
-                                <event name="OnMouseEvents"></event>
-                                <event name="OnMouseWheel"></event>
-                                <event name="OnPaint"></event>
-                                <event name="OnRightDClick"></event>
-                                <event name="OnRightDown"></event>
-                                <event name="OnRightUp"></event>
-                                <event name="OnSetFocus"></event>
-                                <event name="OnSize"></event>
-                                <event name="OnUpdateUI"></event>
                             </object>
                         </object>
                         <object class="sizeritem" expanded="1">
@@ -265,30 +209,6 @@
                                         <property name="window_extra_style"></property>
                                         <property name="window_name"></property>
                                         <property name="window_style"></property>
-                                        <event name="OnChar"></event>
-                                        <event name="OnEnterWindow"></event>
-                                        <event name="OnEraseBackground"></event>
-                                        <event name="OnKeyDown"></event>
-                                        <event name="OnKeyUp"></event>
-                                        <event name="OnKillFocus"></event>
-                                        <event name="OnLeaveWindow"></event>
-                                        <event name="OnLeftDClick"></event>
-                                        <event name="OnLeftDown"></event>
-                                        <event name="OnLeftUp"></event>
-                                        <event name="OnMiddleDClick"></event>
-                                        <event name="OnMiddleDown"></event>
-                                        <event name="OnMiddleUp"></event>
-                                        <event name="OnMotion"></event>
-                                        <event name="OnMouseEvents"></event>
-                                        <event name="OnMouseWheel"></event>
-                                        <event name="OnPaint"></event>
-                                        <event name="OnRadioBox"></event>
-                                        <event name="OnRightDClick"></event>
-                                        <event name="OnRightDown"></event>
-                                        <event name="OnRightUp"></event>
-                                        <event name="OnSetFocus"></event>
-                                        <event name="OnSize"></event>
-                                        <event name="OnUpdateUI"></event>
                                     </object>
                                 </object>
                                 <object class="sizeritem" expanded="1">
@@ -303,7 +223,6 @@
                                         <property name="orient">wxVERTICAL</property>
                                         <property name="parent">1</property>
                                         <property name="permission">none</property>
-                                        <event name="OnUpdateUI"></event>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
                                             <property name="flag">wxEXPAND</property>
@@ -375,30 +294,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRadioButton"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                                 <object class="sizeritem" expanded="0">
@@ -467,29 +362,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                             </object>
@@ -565,30 +437,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRadioButton"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                                 <object class="sizeritem" expanded="0">
@@ -657,29 +505,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                             </object>
@@ -704,7 +529,7 @@
                                         <property name="caption"></property>
                                         <property name="caption_visible">1</property>
                                         <property name="center_pane">0</property>
-                                        <property name="choices">&quot;Keep existing annotations&quot; &quot;Reset existing annotations&quot; &quot;Reset, but keep order of multi-unit parts&quot;</property>
+                                        <property name="choices">&quot;Keep existing annotations&quot; &quot;Reset existing annotations&quot; &quot;Reset, but keep order of multi-unit parts&quot; &quot;Back annotate from PCB&quot;</property>
                                         <property name="close_button">1</property>
                                         <property name="context_help"></property>
                                         <property name="context_menu">1</property>
@@ -750,30 +575,7 @@
                                         <property name="window_extra_style"></property>
                                         <property name="window_name"></property>
                                         <property name="window_style"></property>
-                                        <event name="OnChar"></event>
-                                        <event name="OnEnterWindow"></event>
-                                        <event name="OnEraseBackground"></event>
-                                        <event name="OnKeyDown"></event>
-                                        <event name="OnKeyUp"></event>
-                                        <event name="OnKillFocus"></event>
-                                        <event name="OnLeaveWindow"></event>
-                                        <event name="OnLeftDClick"></event>
-                                        <event name="OnLeftDown"></event>
-                                        <event name="OnLeftUp"></event>
-                                        <event name="OnMiddleDClick"></event>
-                                        <event name="OnMiddleDown"></event>
-                                        <event name="OnMiddleUp"></event>
-                                        <event name="OnMotion"></event>
-                                        <event name="OnMouseEvents"></event>
-                                        <event name="OnMouseWheel"></event>
-                                        <event name="OnPaint"></event>
-                                        <event name="OnRadioBox"></event>
-                                        <event name="OnRightDClick"></event>
-                                        <event name="OnRightDown"></event>
-                                        <event name="OnRightUp"></event>
-                                        <event name="OnSetFocus"></event>
-                                        <event name="OnSize"></event>
-                                        <event name="OnUpdateUI"></event>
+                                        <event name="OnRadioBox">OnRbOptionsChanged</event>
                                     </object>
                                 </object>
                                 <object class="sizeritem" expanded="1">
@@ -788,7 +590,6 @@
                                         <property name="orient">wxVERTICAL</property>
                                         <property name="parent">1</property>
                                         <property name="permission">none</property>
-                                        <event name="OnUpdateUI"></event>
                                         <object class="sizeritem" expanded="1">
                                             <property name="border">5</property>
                                             <property name="flag">wxEXPAND</property>
@@ -869,30 +670,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRadioButton"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                                 <object class="gbsizeritem" expanded="1">
@@ -960,33 +737,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnText"></event>
-                                                        <event name="OnTextEnter"></event>
-                                                        <event name="OnTextMaxLen"></event>
-                                                        <event name="OnTextURL"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                                 <object class="gbsizeritem" expanded="1">
@@ -1054,30 +804,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRadioButton"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                                 <object class="gbsizeritem" expanded="1">
@@ -1145,30 +871,6 @@
                                                         <property name="window_extra_style"></property>
                                                         <property name="window_name"></property>
                                                         <property name="window_style"></property>
-                                                        <event name="OnChar"></event>
-                                                        <event name="OnEnterWindow"></event>
-                                                        <event name="OnEraseBackground"></event>
-                                                        <event name="OnKeyDown"></event>
-                                                        <event name="OnKeyUp"></event>
-                                                        <event name="OnKillFocus"></event>
-                                                        <event name="OnLeaveWindow"></event>
-                                                        <event name="OnLeftDClick"></event>
-                                                        <event name="OnLeftDown"></event>
-                                                        <event name="OnLeftUp"></event>
-                                                        <event name="OnMiddleDClick"></event>
-                                                        <event name="OnMiddleDown"></event>
-                                                        <event name="OnMiddleUp"></event>
-                                                        <event name="OnMotion"></event>
-                                                        <event name="OnMouseEvents"></event>
-                                                        <event name="OnMouseWheel"></event>
-                                                        <event name="OnPaint"></event>
-                                                        <event name="OnRadioButton"></event>
-                                                        <event name="OnRightDClick"></event>
-                                                        <event name="OnRightDown"></event>
-                                                        <event name="OnRightUp"></event>
-                                                        <event name="OnSetFocus"></event>
-                                                        <event name="OnSize"></event>
-                                                        <event name="OnUpdateUI"></event>
                                                     </object>
                                                 </object>
                                             </object>
@@ -1232,29 +934,6 @@
                                 <property name="window_extra_style"></property>
                                 <property name="window_name"></property>
                                 <property name="window_style">wxTAB_TRAVERSAL</property>
-                                <event name="OnChar"></event>
-                                <event name="OnEnterWindow"></event>
-                                <event name="OnEraseBackground"></event>
-                                <event name="OnKeyDown"></event>
-                                <event name="OnKeyUp"></event>
-                                <event name="OnKillFocus"></event>
-                                <event name="OnLeaveWindow"></event>
-                                <event name="OnLeftDClick"></event>
-                                <event name="OnLeftDown"></event>
-                                <event name="OnLeftUp"></event>
-                                <event name="OnMiddleDClick"></event>
-                                <event name="OnMiddleDown"></event>
-                                <event name="OnMiddleUp"></event>
-                                <event name="OnMotion"></event>
-                                <event name="OnMouseEvents"></event>
-                                <event name="OnMouseWheel"></event>
-                                <event name="OnPaint"></event>
-                                <event name="OnRightDClick"></event>
-                                <event name="OnRightDown"></event>
-                                <event name="OnRightUp"></event>
-                                <event name="OnSetFocus"></event>
-                                <event name="OnSize"></event>
-                                <event name="OnUpdateUI"></event>
                             </object>
                         </object>
                     </object>
@@ -1283,25 +962,31 @@
                                 <property name="aui_row"></property>
                                 <property name="best_size"></property>
                                 <property name="bg"></property>
+                                <property name="bitmap"></property>
                                 <property name="caption"></property>
                                 <property name="caption_visible">1</property>
                                 <property name="center_pane">0</property>
                                 <property name="close_button">1</property>
                                 <property name="context_help"></property>
                                 <property name="context_menu">1</property>
+                                <property name="current"></property>
                                 <property name="default">0</property>
                                 <property name="default_pane">0</property>
+                                <property name="disabled"></property>
                                 <property name="dock">Dock</property>
                                 <property name="dock_fixed">0</property>
                                 <property name="docking">Left</property>
                                 <property name="enabled">1</property>
                                 <property name="fg"></property>
                                 <property name="floatable">1</property>
+                                <property name="focus"></property>
                                 <property name="font"></property>
                                 <property name="gripper">0</property>
                                 <property name="hidden">0</property>
                                 <property name="id">ID_CLEAR_ANNOTATION_CMP</property>
                                 <property name="label">Clear Annotation</property>
+                                <property name="margins"></property>
+                                <property name="markup">0</property>
                                 <property name="max_size"></property>
                                 <property name="maximize_button">0</property>
                                 <property name="maximum_size"></property>
@@ -1316,6 +1001,8 @@
                                 <property name="permission">protected</property>
                                 <property name="pin_button">1</property>
                                 <property name="pos"></property>
+                                <property name="position"></property>
+                                <property name="pressed"></property>
                                 <property name="resize">Resizable</property>
                                 <property name="show">1</property>
                                 <property name="size"></property>
@@ -1331,29 +1018,6 @@
                                 <property name="window_name"></property>
                                 <property name="window_style"></property>
                                 <event name="OnButtonClick">OnClearAnnotationCmpClick</event>
-                                <event name="OnChar"></event>
-                                <event name="OnEnterWindow"></event>
-                                <event name="OnEraseBackground"></event>
-                                <event name="OnKeyDown"></event>
-                                <event name="OnKeyUp"></event>
-                                <event name="OnKillFocus"></event>
-                                <event name="OnLeaveWindow"></event>
-                                <event name="OnLeftDClick"></event>
-                                <event name="OnLeftDown"></event>
-                                <event name="OnLeftUp"></event>
-                                <event name="OnMiddleDClick"></event>
-                                <event name="OnMiddleDown"></event>
-                                <event name="OnMiddleUp"></event>
-                                <event name="OnMotion"></event>
-                                <event name="OnMouseEvents"></event>
-                                <event name="OnMouseWheel"></event>
-                                <event name="OnPaint"></event>
-                                <event name="OnRightDClick"></event>
-                                <event name="OnRightDown"></event>
-                                <event name="OnRightUp"></event>
-                                <event name="OnSetFocus"></event>
-                                <event name="OnSize"></event>
-                                <event name="OnUpdateUI"></event>
                             </object>
                         </object>
                         <object class="sizeritem" expanded="1">
@@ -1372,14 +1036,8 @@
                                 <property name="minimum_size"></property>
                                 <property name="name">m_sdbSizer1</property>
                                 <property name="permission">protected</property>
-                                <event name="OnApplyButtonClick"></event>
                                 <event name="OnCancelButtonClick">OnCloseClick</event>
-                                <event name="OnContextHelpButtonClick"></event>
-                                <event name="OnHelpButtonClick"></event>
-                                <event name="OnNoButtonClick"></event>
                                 <event name="OnOKButtonClick">OnApplyClick</event>
-                                <event name="OnSaveButtonClick"></event>
-                                <event name="OnYesButtonClick"></event>
                             </object>
                         </object>
                     </object>
diff --git a/eeschema/dialogs/dialog_annotate_base.h b/eeschema/dialogs/dialog_annotate_base.h
index 7ea011d4a..5c27f5669 100644
--- a/eeschema/dialogs/dialog_annotate_base.h
+++ b/eeschema/dialogs/dialog_annotate_base.h
@@ -1,12 +1,11 @@
 ///////////////////////////////////////////////////////////////////////////
-// C++ code generated with wxFormBuilder (version Dec 30 2017)
+// C++ code generated with wxFormBuilder (version Sep  1 2019)
 // http://www.wxformbuilder.org/
 //
 // PLEASE DO *NOT* EDIT THIS FILE!
 ///////////////////////////////////////////////////////////////////////////
 
-#ifndef __DIALOG_ANNOTATE_BASE_H__
-#define __DIALOG_ANNOTATE_BASE_H__
+#pragma once
 
 #include <wx/artprov.h>
 #include <wx/xrc/xmlres.h>
@@ -48,38 +47,38 @@ class WX_HTML_REPORT_PANEL;
 ///////////////////////////////////////////////////////////////////////////////
 class DIALOG_ANNOTATE_BASE : public DIALOG_SHIM
 {
-	private:
-	
-	protected:
-		wxStaticText* m_userMessage;
-		wxRadioBox* m_rbScope;
-		wxRadioButton* m_rbSortBy_X_Position;
-		wxStaticBitmap* annotate_down_right_bitmap;
-		wxRadioButton* m_rbSortBy_Y_Position;
-		wxStaticBitmap* annotate_right_down_bitmap;
-		wxRadioBox* m_rbOptions;
-		wxRadioButton* m_rbFirstFree;
-		wxTextCtrl* m_textNumberAfter;
-		wxRadioButton* m_rbSheetX100;
-		wxRadioButton* m_rbSheetX1000;
-		WX_HTML_REPORT_PANEL* m_MessageWindow;
-		wxButton* m_btnClear;
-		wxStdDialogButtonSizer* m_sdbSizer1;
-		wxButton* m_sdbSizer1OK;
-		wxButton* m_sdbSizer1Cancel;
-		
-		// Virtual event handlers, overide them in your derived class
-		virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
-		virtual void OnClearAnnotationCmpClick( wxCommandEvent& event ) { event.Skip(); }
-		virtual void OnCloseClick( wxCommandEvent& event ) { event.Skip(); }
-		virtual void OnApplyClick( wxCommandEvent& event ) { event.Skip(); }
-		
-	
-	public:
-		
-		DIALOG_ANNOTATE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Annotate Schematic"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); 
-		~DIALOG_ANNOTATE_BASE();
-	
+    private:
+
+    protected:
+        wxStaticText* m_userMessage;
+        wxRadioBox* m_rbScope;
+        wxRadioButton* m_rbSortBy_X_Position;
+        wxStaticBitmap* annotate_down_right_bitmap;
+        wxRadioButton* m_rbSortBy_Y_Position;
+        wxStaticBitmap* annotate_right_down_bitmap;
+        wxRadioBox* m_rbOptions;
+        wxRadioButton* m_rbFirstFree;
+        wxTextCtrl* m_textNumberAfter;
+        wxRadioButton* m_rbSheetX100;
+        wxRadioButton* m_rbSheetX1000;
+        WX_HTML_REPORT_PANEL* m_MessageWindow;
+        wxButton* m_btnClear;
+        wxStdDialogButtonSizer* m_sdbSizer1;
+        wxButton* m_sdbSizer1OK;
+        wxButton* m_sdbSizer1Cancel;
+
+        // Virtual event handlers, overide them in your derived class
+        virtual void OnClose( wxCloseEvent& event ) { event.Skip(); }
+        virtual void OnRbOptionsChanged( wxCommandEvent& event ) { event.Skip(); }
+        virtual void OnClearAnnotationCmpClick( wxCommandEvent& event ) { event.Skip(); }
+        virtual void OnCloseClick( wxCommandEvent& event ) { event.Skip(); }
+        virtual void OnApplyClick( wxCommandEvent& event ) { event.Skip(); }
+
+
+    public:
+
+        DIALOG_ANNOTATE_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Annotate Schematic"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
+        ~DIALOG_ANNOTATE_BASE();
+
 };
 
-#endif //__DIALOG_ANNOTATE_BASE_H__
diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp
index cd4922cd7..116917053 100644
--- a/eeschema/sch_edit_frame.cpp
+++ b/eeschema/sch_edit_frame.cpp
@@ -643,6 +643,27 @@ void SCH_EDIT_FRAME::OnUpdatePCB( wxCommandEvent& event )
     Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_UPDATE, payload, this );
 }
 
+bool SCH_EDIT_FRAME::FetchNetlistFromPCB( std::string& aNetlist )
+{
+    if( Kiface().IsSingle() )
+    {
+        DisplayError( this, _( "Cannot update fetch PCB netlist because eeschema is opened in "
+                               "stand-alone mode, you must launch the KiCad project manager "
+                               "and create a project." ) );
+        return false;
+    }
+
+    KIWAY_PLAYER* player = Kiway().Player( FRAME_PCB_EDITOR, false ); // test open already.
+
+    if( !player )
+    {
+        DisplayError( this, _( "Please open Pcbnew and run back-annotation again" ) );
+        return false;
+    }
+
+    Kiway().ExpressMail( FRAME_PCB_EDITOR, MAIL_PCB_GET_NETLIST, aNetlist, this );
+    return true;
+}
 
 wxFindReplaceData* SCH_EDIT_FRAME::GetFindReplaceData()
 {
diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h
index c8df4ca28..7b5731f81 100644
--- a/eeschema/sch_edit_frame.h
+++ b/eeschema/sch_edit_frame.h
@@ -502,6 +502,16 @@ public:
                              bool aResetAnnotation, bool aRepairTimestamps, bool aLockUnits,
                              REPORTER& aReporter );
 
+    /**
+     * @brief Back annotate schematics from PCB layout. Annotating is made by unique
+     * paths, which consists of "sheet path/unique Id"
+     * @param aNetlist \ref NETLIST recieved from PCB via KiWay and packed to std::string
+     * @param aReporter A sink for error messages.  Use NULL_REPORTER if you don't need errors.
+     * @param aDryRun if it's dry run
+     * @return true if there no any errors.
+     */
+    bool BackAnnotateComponents( const std::string& aNetlist, REPORTER& aReporter, bool aDryRun );
+
     /**
      * Check for annotation errors.
      *
@@ -680,6 +690,14 @@ public:
     void OnUpdatePCB( wxCommandEvent& event );
     void OnAnnotate( wxCommandEvent& event );
 
+    /**
+      * @brief Get netlist from PCB editor. Fails if PCB editor closed or
+      * eeschema opened in stand-alone mode
+      * @param aNetlist reference to std::container where netlist will be stored
+      * @return true if success
+      */
+    bool FetchNetlistFromPCB( std::string& aNetlist );
+
 private:
     // Sets up the tool framework
     void setupTools();
diff --git a/eeschema/sch_reference_list.h b/eeschema/sch_reference_list.h
index 047af4257..43615dbf6 100644
--- a/eeschema/sch_reference_list.h
+++ b/eeschema/sch_reference_list.h
@@ -93,15 +93,21 @@ public:
     SCH_REFERENCE( SCH_COMPONENT* aComponent, LIB_PART* aLibComponent,
                    SCH_SHEET_PATH& aSheetPath );
 
-    SCH_COMPONENT* GetComp() const          { return m_RootCmp; }
+    SCH_COMPONENT* GetComp() const             { return m_RootCmp; }
 
-    LIB_PART*      GetLibPart() const       { return m_Entry; }
+    LIB_PART*      GetLibPart() const          { return m_Entry; }
 
     const SCH_SHEET_PATH& GetSheetPath() const { return m_SheetPath; }
 
-    int GetUnit() const                     { return m_Unit; }
+    int GetUnit() const                        { return m_Unit; }
+
+    void SetSheetNumber( int aSheetNumber )    { m_SheetNum = aSheetNumber; }
+
+    const wxString GetPath() const
+    {
+        return m_RootCmp ? m_RootCmp->GetPath( &m_SheetPath ) : "";
+    }
 
-    void SetSheetNumber( int aSheetNumber ) { m_SheetNum = aSheetNumber; }
 
     /**
      * Function Annotate
@@ -334,6 +340,14 @@ public:
      */
     int CheckAnnotation( REPORTER& aReporter );
 
+    /**
+     * @brief Check components having same references designator. Must be called with references
+     * sorted by timestamp \ref SortByTimeStamp()
+     * @param aReporter A sink for error messages.  Use NULL_REPORTER if you don't need errors.
+     * @return The number of errors found.
+     */
+    int checkForDuplicatedElements( REPORTER& aReporter );
+
     /**
      * Function sortByXCoordinate
      * sorts the list of references by X position.
@@ -374,7 +388,7 @@ public:
 
     /**
      * Function SortComponentsByTimeStamp
-     * sort the flat list by Time Stamp.
+     * sort the flat list by Time Stamp (sheet path + timestamp).
      * Useful to detect duplicate Time Stamps
      */
     void SortByTimeStamp()
@@ -428,6 +442,13 @@ public:
      */
     int FindUnit( size_t aIndex, int aUnit );
 
+    /**
+     * @brief Searches unit with designated path
+     * @param aPath path to search
+     * @return index in aComponentsList if found or -1 if not found
+     */
+    int FindRefByPath( const wxString& aPath ) const;
+
     /**
      * Function GetRefsInUse
      * adds all the reference designator numbers greater than \a aMinRefId to \a aIdList
diff --git a/include/mail_type.h b/include/mail_type.h
index ba29b5bc1..aacd1d706 100644
--- a/include/mail_type.h
+++ b/include/mail_type.h
@@ -42,7 +42,8 @@ enum MAIL_T
     MAIL_EESCHEMA_NETLIST,          ///< SCH->CVPCB netlist immediately after launching CVPCB
     MAIL_PCB_UPDATE,                ///< SCH->PCB forward update
     MAIL_IMPORT_FILE,               ///< Import a different format file
-    MAIL_SCH_GET_NETLIST,           ///< Fetch a netlist
+    MAIL_SCH_GET_NETLIST,           ///< Fetch a netlist from schematics
+    MAIL_PCB_GET_NETLIST,           ///< Fetch a netlist from PCB layout
     MAIL_SCH_REFRESH,               ///< The the schematic editor to refresh the display.
 
     MAIL_LIB_EDIT,
diff --git a/pcbnew/cross-probing.cpp b/pcbnew/cross-probing.cpp
index e020a26d3..b2c69ae2e 100644
--- a/pcbnew/cross-probing.cpp
+++ b/pcbnew/cross-probing.cpp
@@ -327,10 +327,24 @@ void PCB_EDIT_FRAME::SendCrossProbeNetName( const wxString& aNetName )
 
 void PCB_EDIT_FRAME::KiwayMailIn( KIWAY_EXPRESS& mail )
 {
-    const std::string& payload = mail.GetPayload();
+    std::string& payload = mail.GetPayload();
 
     switch( mail.Command() )
     {
+    case MAIL_PCB_GET_NETLIST:
+    {
+        NETLIST          netlist;
+        STRING_FORMATTER sf;
+        for( auto& module : this->GetBoard()->Modules() )
+        {
+            netlist.AddComponent( new COMPONENT( module->GetFPID(), module->GetReference(),
+                    module->GetValue(), module->GetPath() ) );
+        }
+        netlist.Format(
+                "pcb_netlist", &sf, 0, CTL_OMIT_FILTERS | CTL_OMIT_NETS | CTL_OMIT_FILTERS );
+        payload = sf.GetString();
+        break;
+    }
     case MAIL_CROSS_PROBE:
         ExecuteRemoteCommand( payload.c_str() );
         break;

--------------2.24.0--


Attachment: annotate2.png
Description: PNG image

Attachment: annotate.png
Description: PNG image


Follow ups

References