Commit 3abfb6ca authored by jean-pierre charras's avatar jean-pierre charras

Cvpcb: Add a tool to solve conflict assignments when the schematic netlist and...

Cvpcb: Add a tool to solve conflict assignments when the schematic netlist and the .cmp file do not contain the same assignment and both are valid fpid.
It happens when footprint assignments are modified outside Cvpcb (when editing the footprint assignment field in schematic)
parent a7b916d6
...@@ -21,6 +21,8 @@ include_directories( ...@@ -21,6 +21,8 @@ include_directories(
set( CVPCB_DIALOGS set( CVPCB_DIALOGS
dialogs/fp_conflict_assignment_selector_base.cpp
dialogs/fp_conflict_assignment_selector.cpp
dialogs/dialog_display_options.cpp dialogs/dialog_display_options.cpp
dialogs/dialog_display_options_base.cpp dialogs/dialog_display_options_base.cpp
../pcbnew/dialogs/dialog_fp_lib_table.cpp ../pcbnew/dialogs/dialog_fp_lib_table.cpp
......
/**
* @file fp_choice_selector.cpp
*/
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2010-2014 Jean-Pierre Charras <jp.charras at wanadoo.fr>
* Copyright (C) 1992-2014 Kicad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <common.h>
#include <fp_conflict_assignment_selector.h>
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR( wxWindow* aParent )
: DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE( aParent )
{
m_listFp->InsertColumn( 0, _( "Ref" ) );
m_listFp->InsertColumn( 1, _( "Schematic assignment" ) );
m_listFp->InsertColumn( 2, wxT( "<=" ) );
m_listFp->InsertColumn( 3, wxT( "=>" ) );
m_listFp->InsertColumn( 4, _( "Cmp file assignment" ) );
m_lineCount = 0;
}
void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::Add( const wxString& aRef, const wxString& aFpSchName,
const wxString& aFpCmpName )
{
wxListItem item;
item.SetId( m_lineCount );
item.SetText( aRef );
item.SetColumn( COL_REF );
m_listFp->InsertItem( item );
item.SetText( aFpSchName );
item.SetColumn( COL_FPSCH );
m_listFp->SetItem( item );
item.SetText( wxT("") );
item.SetColumn( COL_SELSCH );
m_listFp->SetItem( item );
item.SetText( wxT("X") );
item.SetColumn( COL_SELCMP );
m_listFp->SetItem( item );
item.SetText( aFpCmpName );
item.SetColumn( COL_FPCMP );
m_listFp->SetItem( item );
m_lineCount ++;
}
int DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::GetSelection( const wxString& aReference )
{
// Find Reference
for( int ii = 0; ii < m_listFp->GetItemCount(); ii++ )
{
if( m_listFp->GetItemText( ii, COL_REF ) == aReference )
{
if( m_listFp->GetItemText( ii, COL_SELSCH ) != wxT("X") )
return 1;
return 0;
}
}
return -1;
}
void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::OnColumnClick( wxListEvent& event )
{
// When clicking on the column title:
// when it is the COL_SELCMP column, set all item choices to cmp file assigment.
// when it is the COL_SELSCH column, set all item choices to schematic assigment.
wxListItem item = event.GetItem();
int column = event.GetColumn();
int colclr, colset;
switch( column )
{
case COL_SELSCH:
colclr = COL_SELCMP;
colset = COL_SELSCH;
break;
case COL_SELCMP:
colclr = COL_SELSCH;
colset = COL_SELCMP;
break;
default:
return;
}
for( int i = 0; i < m_listFp->GetItemCount(); i++ )
{
m_listFp->SetItem( i, colclr, wxT("") );
m_listFp->SetItem( i, colset, wxT("X") );
}
}
void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::OnItemClicked( wxMouseEvent& event )
{
wxPoint pos = event.GetPosition();
int flgs = wxLIST_HITTEST_ONITEMLABEL;
long idx = m_listFp->HitTest( pos, flgs );
// Try to find the column clicked (must be COL_SELCMP or COL_SELSCH)
int colclr = -1, colset;
int minpx = m_listFp->GetColumnWidth( 0 ) + m_listFp->GetColumnWidth( 1 );
int maxpx = minpx + m_listFp->GetColumnWidth( 2 );
if( pos.x > minpx && pos.x < maxpx )
{
colclr = COL_SELCMP;
colset = COL_SELSCH;
}
else
{
minpx = maxpx;
int maxpx = minpx + m_listFp->GetColumnWidth( 3 );
if( pos.x > minpx && pos.x < maxpx )
{
colclr = COL_SELSCH;
colset = COL_SELCMP;
}
}
if( colclr < 0 )
return;
// Move selection to schematic or cmp file choice
// according to the column position (COL_SELCMP or COL_SELSCH)
m_listFp->SetItem( idx, colclr, wxT("") );
m_listFp->SetItem( idx, colset, wxT("X") );
event.Skip();
}
void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::OnSize( wxSizeEvent& aEvent )
{
recalculateColumns();
aEvent.Skip();
}
void DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR::recalculateColumns()
{
const int margin = 16;
int totalLength = 0;
int sel_length = GetTextSize( wxT("XX"), m_listFp ).x;
int maxRefLength = GetTextSize( wxT("XXX"), m_listFp ).x;
sel_length += margin;
m_listFp->SetColumnWidth( COL_SELSCH, sel_length );
m_listFp->SetColumnWidth( COL_SELCMP, sel_length );
// Find max character width of column Reference
for( int i = 0; i < m_listFp->GetItemCount(); i++ )
{
int length = GetTextSize( m_listFp->GetItemText( i, COL_REF ), m_listFp ).x;
if( length > maxRefLength )
maxRefLength = length;
}
// Use the lengths of column texts to create a scale of the max list width
// to set the column widths
maxRefLength += margin;
totalLength = maxRefLength + sel_length + sel_length;
int cwidth = (GetClientSize().x - totalLength) / 2;
m_listFp->SetColumnWidth( COL_REF, maxRefLength );
m_listFp->SetColumnWidth( COL_FPSCH, cwidth - 2 );
m_listFp->SetColumnWidth( COL_FPCMP, cwidth );
}
/**
* @file fp_choice_selector.h
*/
/*
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2010-2014 Jean-Pierre Charras <jp.charras at wanadoo.fr>
* Copyright (C) 1992-2014 Kicad Developers, see CHANGELOG.TXT for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <fp_conflict_assignment_selector_base.h>
class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR : public DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE
{
private:
enum COL_ID
{
COL_REF, COL_FPSCH, COL_SELSCH, COL_SELCMP, COL_FPCMP,
COL_COUNT
};
int m_lineCount;
public:
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR( wxWindow* parent );
/**
* Add a line to the selection list.
* @param aRef = component reference text
* @param aFpSchName = fpid text from the netlist
* @param aFpCmpName = fpid text from the .cmp file
*/
void Add( const wxString& aRef, const wxString& aFpSchName,
const wxString& aFpCmpName );
/**
* @return the selection option:
* 0 for fpid text from the netlist
* 1 for fpid text from the cmp file
* -1 on error
* @param aReference = the compoent schematic reference
*/
int GetSelection( const wxString& aReference );
private:
void OnSize( wxSizeEvent& event );
// Virtual: called when clicking on the column title:
// when it is a column choice, set all item choices.
void OnColumnClick( wxListEvent& event );
void OnItemClicked( wxMouseEvent& event );
void OnCancelClick( wxCommandEvent& event ) { EndModal( wxID_CANCEL ); }
void OnOKClick( wxCommandEvent& event ) { EndModal( wxID_OK ); }
void recalculateColumns();
};
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#include "fp_conflict_assignment_selector_base.h"
///////////////////////////////////////////////////////////////////////////
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_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* bSizerMain;
bSizerMain = new wxBoxSizer( wxVERTICAL );
m_staticTextInfo = new wxStaticText( this, wxID_ANY, wxT("Footprint assignments from schematic netlist and from .cmp file are conflicting\nPlease choose the assignment."), wxDefaultPosition, wxDefaultSize, wxALIGN_CENTRE );
m_staticTextInfo->Wrap( -1 );
bSizerMain->Add( m_staticTextInfo, 0, wxALL|wxEXPAND, 5 );
m_listFp = new wxListCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_HRULES|wxLC_ICON|wxLC_REPORT|wxLC_SINGLE_SEL|wxLC_VRULES );
bSizerMain->Add( m_listFp, 1, wxALL|wxEXPAND, 5 );
m_sdbSizer = new wxStdDialogButtonSizer();
m_sdbSizerOK = new wxButton( this, wxID_OK );
m_sdbSizer->AddButton( m_sdbSizerOK );
m_sdbSizerCancel = new wxButton( this, wxID_CANCEL );
m_sdbSizer->AddButton( m_sdbSizerCancel );
m_sdbSizer->Realize();
bSizerMain->Add( m_sdbSizer, 0, wxALIGN_RIGHT, 5 );
this->SetSizer( bSizerMain );
this->Layout();
this->Centre( wxBOTH );
// Connect Events
this->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnSize ) );
m_listFp->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnItemClicked ), NULL, this );
m_listFp->Connect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnColumnClick ), NULL, this );
m_sdbSizerCancel->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnOKClick ), NULL, this );
}
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::~DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE()
{
// Disconnect Events
this->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnSize ) );
m_listFp->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnItemClicked ), NULL, this );
m_listFp->Disconnect( wxEVT_COMMAND_LIST_COL_CLICK, wxListEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnColumnClick ), NULL, this );
m_sdbSizerCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnCancelClick ), NULL, this );
m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE::OnOKClick ), NULL, this );
}
This diff is collapsed.
///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version Jun 5 2014)
// http://www.wxformbuilder.org/
//
// PLEASE DO "NOT" EDIT THIS FILE!
///////////////////////////////////////////////////////////////////////////
#ifndef __FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE_H__
#define __FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE_H__
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
class DIALOG_SHIM;
#include "dialog_shim.h"
#include <wx/string.h>
#include <wx/stattext.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/listctrl.h>
#include <wx/sizer.h>
#include <wx/button.h>
#include <wx/dialog.h>
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE
///////////////////////////////////////////////////////////////////////////////
class DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE : public DIALOG_SHIM
{
private:
protected:
wxStaticText* m_staticTextInfo;
wxListCtrl* m_listFp;
wxStdDialogButtonSizer* m_sdbSizer;
wxButton* m_sdbSizerOK;
wxButton* m_sdbSizerCancel;
// Virtual event handlers, overide them in your derived class
virtual void OnSize( wxSizeEvent& event ) { event.Skip(); }
virtual void OnItemClicked( wxMouseEvent& event ) { event.Skip(); }
virtual void OnColumnClick( wxListEvent& event ) { event.Skip(); }
virtual void OnCancelClick( wxCommandEvent& event ) { event.Skip(); }
virtual void OnOKClick( wxCommandEvent& event ) { event.Skip(); }
public:
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Footprint Assignment Conflicts"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 478,294 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER );
~DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE();
};
#endif //__FP_CONFLICT_ASSIGNMENT_SELECTOR_BASE_H__
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <cvpcb_mainframe.h> #include <cvpcb_mainframe.h>
#include <cvstruct.h> #include <cvstruct.h>
#include <wildcards_and_files_ext.h> #include <wildcards_and_files_ext.h>
#include <fp_conflict_assignment_selector.h>
void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName ) void CVPCB_MAINFRAME::SetNewPkg( const wxString& aFootprintName )
...@@ -290,6 +291,58 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles() ...@@ -290,6 +291,58 @@ bool CVPCB_MAINFRAME::ReadNetListAndLinkFiles()
} }
} }
// Display a dialog to select footprint selection, if the netlist
// and the .cmp file give 2 different valid footprints
std::vector <int > m_indexes; // indexes of footprints in netlist
for( unsigned ii = 0; ii < m_netlist.GetCount(); ii++ )
{
COMPONENT* component = m_netlist.GetComponent( ii );
if( component->GetAltFPID().empty() )
continue;
if( component->GetFPID().IsLegacy() || component->GetAltFPID().IsLegacy())
continue;
m_indexes.push_back( ii );;
}
// If a n assignment conflict is found,
// open a dialog to chose between schematic assignment
// and .cmp file assignment:
if( m_indexes.size() > 0 )
{
DIALOG_FP_CONFLICT_ASSIGNMENT_SELECTOR dlg( this );
for( unsigned ii = 0; ii < m_indexes.size(); ii++ )
{
COMPONENT* component = m_netlist.GetComponent( m_indexes[ii] );
wxString cmpfpid = component->GetFPID().Format();
wxString schfpid = component->GetAltFPID().Format();
dlg.Add( component->GetReference(), schfpid, cmpfpid );
}
if( dlg.ShowModal() == wxID_OK )
{
// Update the fp selection:
for( unsigned ii = 0; ii < m_indexes.size(); ii++ )
{
COMPONENT* component = m_netlist.GetComponent( m_indexes[ii] );
int choice = dlg.GetSelection( component->GetReference() );
if( choice == 0 ) // the schematic (alt fpid) is chosen:
component->SetFPID( component->GetAltFPID() );
}
}
}
// Populates the component list box:
for( unsigned i = 0; i < m_netlist.GetCount(); i++ ) for( unsigned i = 0; i < m_netlist.GetCount(); i++ )
{ {
COMPONENT* component = m_netlist.GetComponent( i ); COMPONENT* component = m_netlist.GetComponent( i );
......
...@@ -209,6 +209,13 @@ bool CMP_READER::Load( NETLIST* aNetlist ) throw( IO_ERROR, PARSE_ERROR ) ...@@ -209,6 +209,13 @@ bool CMP_READER::Load( NETLIST* aNetlist ) throw( IO_ERROR, PARSE_ERROR )
THROW_IO_ERROR( error ); THROW_IO_ERROR( error );
} }
// For checking purpose, store the existing FPID (if any) in the alternate fpid copy
// if this existing FPID differs from the FPID read from the .cmp file.
// Cvpcb can ask for user to chose the right FPID.
// It happens if the FPIT was modified outside CvPcb.
if( fpid != component->GetFPID() && !component->GetFPID().empty() )
component->SetAltFPID( component->GetFPID() );
component->SetFPID( fpid ); component->SetFPID( fpid );
} }
else else
......
...@@ -98,6 +98,11 @@ class COMPONENT ...@@ -98,6 +98,11 @@ class COMPONENT
/// The #FPID of the footprint assigned to the component. /// The #FPID of the footprint assigned to the component.
FPID m_fpid; FPID m_fpid;
/// The alt FPID of the footprint, when there are 2 different assigned footprints,
/// One from the netlist, the other from the .cmp file.
/// this one is a copy of the netlist footprint assignment
FPID m_altFpid;
/// The #MODULE loaded for #m_fpid. /// The #MODULE loaded for #m_fpid.
std::auto_ptr< MODULE > m_footprint; std::auto_ptr< MODULE > m_footprint;
...@@ -150,9 +155,16 @@ public: ...@@ -150,9 +155,16 @@ public:
m_fpid = aFPID; m_fpid = aFPID;
} }
const FPID& GetFPID() const { return m_fpid; } void SetAltFPID( const FPID& aFPID )
{
m_altFpid = aFPID;
}
const FPID& GetFPID() const { return m_fpid; }
const wxString& GetTimeStamp() const { return m_timeStamp; } const FPID& GetAltFPID() const { return m_altFpid; }
const wxString& GetTimeStamp() const { return m_timeStamp; }
void SetFootprintFilters( const wxArrayString& aFilterList ) void SetFootprintFilters( const wxArrayString& aFilterList )
{ {
...@@ -261,7 +273,7 @@ public: ...@@ -261,7 +273,7 @@ public:
*/ */
void AddComponent( COMPONENT* aComponent ); void AddComponent( COMPONENT* aComponent );
/* /**
* Function GetComponentByReference * Function GetComponentByReference
* returns a #COMPONENT by \a aReference. * returns a #COMPONENT by \a aReference.
* *
...@@ -270,7 +282,7 @@ public: ...@@ -270,7 +282,7 @@ public:
*/ */
COMPONENT* GetComponentByReference( const wxString& aReference ); COMPONENT* GetComponentByReference( const wxString& aReference );
/* /**
* Function GetComponentByTimeStamp * Function GetComponentByTimeStamp
* returns a #COMPONENT by \a aTimeStamp. * returns a #COMPONENT by \a aTimeStamp.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment