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

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
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ include_directories(


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_base.cpp
    ../pcbnew/dialogs/dialog_fp_lib_table.cpp
+207 −0
Original line number Diff line number Diff line
/**
 * @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 );
}
+79 −0
Original line number Diff line number Diff line
/**
 * @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();

};
+58 −0
Original line number Diff line number Diff line
///////////////////////////////////////////////////////////////////////////
// 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 );
	
}
+313 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading