2011-10-19 20:32:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-08-31 07:43:37 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2008-2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
|
2011-10-19 20:32:21 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2011-10-07 14:41:30 +00:00
|
|
|
/**
|
|
|
|
* @file getpart.cpp
|
2012-08-31 07:43:37 +00:00
|
|
|
* @brief functions to get and place library components.
|
2011-10-07 14:41:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <appl_wxstruct.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wxEeschemaStruct.h>
|
|
|
|
#include <kicad_device_context.h>
|
2013-01-12 17:32:24 +00:00
|
|
|
#include <msgpanel.h>
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <general.h>
|
|
|
|
#include <protos.h>
|
|
|
|
#include <class_library.h>
|
|
|
|
#include <sch_component.h>
|
2012-02-19 19:53:11 +00:00
|
|
|
#include <libeditframe.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <viewlib_frame.h>
|
|
|
|
#include <eeschema_id.h>
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <dialog_get_component.h>
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
wxString SCH_BASE_FRAME::SelectComponentFromLibBrowser( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
wxSemaphore semaphore( 0, 1 );
|
2011-04-09 10:52:14 +00:00
|
|
|
wxString cmpname;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
// Close the current Lib browser, if open, and open a new one, in "modal" mode:
|
|
|
|
LIB_VIEW_FRAME * viewlibFrame = LIB_VIEW_FRAME::GetActiveLibraryViewer();;
|
|
|
|
if( viewlibFrame )
|
|
|
|
viewlibFrame->Destroy();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
viewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore,
|
2012-09-11 19:03:21 +00:00
|
|
|
KICAD_DEFAULT_DRAWFRAME_STYLE | wxFRAME_FLOAT_ON_PARENT );
|
2007-08-20 01:20:48 +00:00
|
|
|
// Show the library viewer frame until it is closed
|
2012-08-31 07:43:37 +00:00
|
|
|
// Wait for viewer closing event:
|
|
|
|
while( semaphore.TryWait() == wxSEMA_BUSY )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
wxYield();
|
|
|
|
wxMilliSleep( 50 );
|
|
|
|
}
|
|
|
|
|
2012-09-12 09:53:11 +00:00
|
|
|
cmpname = viewlibFrame->GetSelectedComponent();
|
|
|
|
viewlibFrame->Destroy();
|
2011-04-09 10:52:14 +00:00
|
|
|
|
|
|
|
return cmpname;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 23:58:29 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
wxString SCH_BASE_FRAME::SelectComponentFromLibrary( const wxString& aLibname,
|
|
|
|
wxArrayString& aHistoryList,
|
|
|
|
bool aUseLibBrowser,
|
|
|
|
int* aUnit,
|
|
|
|
int* aConvert )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
int CmpCount = 0;
|
2012-02-19 19:53:11 +00:00
|
|
|
LIB_COMPONENT* libEntry = NULL;
|
|
|
|
CMP_LIBRARY* currLibrary = NULL;
|
|
|
|
wxString cmpName, keys, msg;
|
|
|
|
bool allowWildSeach = true;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( !aLibname.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
currLibrary = CMP_LIBRARY::FindLibrary( aLibname );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( currLibrary != NULL )
|
|
|
|
CmpCount = currLibrary->GetCount();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
CmpCount += lib.GetCount();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-09 17:49:01 +00:00
|
|
|
// Ask for a component name or key words
|
|
|
|
msg.Printf( _( "Component selection (%d items loaded):" ), CmpCount );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2013-01-10 12:18:43 +00:00
|
|
|
DIALOG_GET_COMPONENT dlg( this, aHistoryList, msg, aUseLibBrowser );
|
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( aHistoryList.GetCount() )
|
2012-02-19 19:53:11 +00:00
|
|
|
dlg.SetComponentName( aHistoryList[0] );
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
if ( dlg.ShowModal() == wxID_CANCEL )
|
2012-02-19 19:53:11 +00:00
|
|
|
return wxEmptyString;
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
if( dlg.m_GetExtraFunction )
|
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
cmpName = SelectComponentFromLibBrowser();
|
|
|
|
if( aUnit )
|
2012-09-12 09:53:11 +00:00
|
|
|
*aUnit = LIB_VIEW_FRAME::GetUnit();
|
2012-02-19 19:53:11 +00:00
|
|
|
if( aConvert )
|
2012-09-12 09:53:11 +00:00
|
|
|
*aConvert = LIB_VIEW_FRAME::GetConvert();
|
2012-02-19 19:53:11 +00:00
|
|
|
if( !cmpName.IsEmpty() )
|
|
|
|
AddHistoryComponentName( aHistoryList, cmpName );
|
|
|
|
return cmpName;
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-19 19:53:11 +00:00
|
|
|
cmpName = dlg.GetComponentName();
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( cmpName.IsEmpty() )
|
|
|
|
return wxEmptyString;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
// Here, cmpName contains the component name,
|
|
|
|
// or "*" if the Select All dialog button was pressed
|
|
|
|
|
2010-10-22 15:02:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
2012-02-19 19:53:11 +00:00
|
|
|
cmpName.MakeUpper();
|
2010-10-22 15:02:11 +00:00
|
|
|
#endif
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( dlg.IsKeyword() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
allowWildSeach = false;
|
|
|
|
keys = cmpName;
|
|
|
|
cmpName = DataBaseGetName( this, keys, cmpName );
|
|
|
|
|
|
|
|
if( cmpName.IsEmpty() )
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
else if( cmpName == wxT( "*" ) )
|
|
|
|
{
|
|
|
|
allowWildSeach = false;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( GetNameOfPartToLoad( this, currLibrary, cmpName ) == 0 )
|
|
|
|
return wxEmptyString;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2012-02-19 19:53:11 +00:00
|
|
|
else if( cmpName.Contains( wxT( "?" ) ) || cmpName.Contains( wxT( "*" ) ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
allowWildSeach = false;
|
|
|
|
cmpName = DataBaseGetName( this, keys, cmpName );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( cmpName.IsEmpty() )
|
|
|
|
return wxEmptyString;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2012-02-19 19:53:11 +00:00
|
|
|
|
|
|
|
libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );
|
|
|
|
|
2012-11-23 09:10:37 +00:00
|
|
|
if( ( libEntry == NULL ) && allowWildSeach ) // Search with wildcard
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
allowWildSeach = false;
|
|
|
|
wxString wildname = wxChar( '*' ) + cmpName + wxChar( '*' );
|
|
|
|
cmpName = wildname;
|
|
|
|
cmpName = DataBaseGetName( this, keys, cmpName );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( !cmpName.IsEmpty() )
|
|
|
|
libEntry = CMP_LIBRARY::FindLibraryComponent( cmpName, aLibname );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( libEntry == NULL )
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
if( libEntry == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2012-11-23 09:10:37 +00:00
|
|
|
msg.Printf( _( "Failed to find part <%s> in library" ), GetChars( cmpName ) );
|
2012-02-19 19:53:11 +00:00
|
|
|
DisplayError( this, msg );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
AddHistoryComponentName( aHistoryList, cmpName );
|
|
|
|
return cmpName;
|
|
|
|
}
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
|
|
|
|
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* aDC,
|
|
|
|
const wxString& aLibname,
|
|
|
|
wxArrayString& aHistoryList,
|
|
|
|
bool aUseLibBrowser )
|
|
|
|
{
|
|
|
|
int unit = 1;
|
|
|
|
int convert = 1;
|
|
|
|
m_itemToRepeat = NULL;
|
|
|
|
m_canvas->SetIgnoreMouseEvents( true );
|
|
|
|
|
|
|
|
wxString Name = SelectComponentFromLibrary( aLibname, aHistoryList, aUseLibBrowser,
|
|
|
|
&unit, &convert );
|
|
|
|
|
|
|
|
if( Name.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
|
|
|
m_canvas->MoveCursorToCrossHair();
|
|
|
|
return NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
|
|
|
Name.MakeUpper();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( Name, aLibname );
|
|
|
|
|
2011-12-29 20:11:42 +00:00
|
|
|
m_canvas->SetIgnoreMouseEvents( false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
{
|
2012-02-19 19:53:11 +00:00
|
|
|
wxString msg;
|
|
|
|
msg.Printf( _( "Failed to find part <%s> in library" ), GetChars( Name ) );
|
|
|
|
wxMessageBox( msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-19 19:53:11 +00:00
|
|
|
SCH_COMPONENT* component;
|
2011-12-08 21:05:43 +00:00
|
|
|
component = new SCH_COMPONENT( *Entry, m_CurrentSheet, unit, convert,
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->GetCrossHairPosition(), true );
|
2011-10-19 20:32:21 +00:00
|
|
|
|
2010-02-17 13:22:25 +00:00
|
|
|
// Set the m_ChipName value, from component name in lib, for aliases
|
|
|
|
// Note if Entry is found, and if Name is an alias of a component,
|
|
|
|
// alias exists because its root component was found
|
2011-10-19 20:32:21 +00:00
|
|
|
component->SetLibName( Name );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-02-17 13:22:25 +00:00
|
|
|
// Set the component value that can differ from component name in lib, for aliases
|
2013-03-18 19:36:07 +00:00
|
|
|
component->GetField( VALUE )->SetText( Name );
|
2013-01-12 17:32:24 +00:00
|
|
|
|
|
|
|
MSG_PANEL_ITEMS items;
|
2013-05-24 23:58:29 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
component->SetCurrentSheetPath( &GetCurrentSheet() );
|
|
|
|
component->GetMsgPanelInfo( items );
|
2013-05-24 23:58:29 +00:00
|
|
|
|
2013-01-12 17:32:24 +00:00
|
|
|
SetMsgPanel( items );
|
2013-01-30 16:15:45 +00:00
|
|
|
component->Draw( m_canvas, aDC, wxPoint( 0, 0 ), g_XorMode );
|
2011-10-19 20:32:21 +00:00
|
|
|
component->SetFlags( IS_NEW );
|
2012-02-19 19:53:11 +00:00
|
|
|
MoveItem( (SCH_ITEM*) component, aDC );
|
2009-10-27 10:55:46 +00:00
|
|
|
|
2011-10-19 20:32:21 +00:00
|
|
|
return component;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-10-28 20:30:50 +00:00
|
|
|
void SCH_EDIT_FRAME::OrientComponent( COMPONENT_ORIENTATION_T aOrientation )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-03 19:55:44 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( item != NULL && item->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Cannot change orientation of invalid schematic item." ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-03 19:55:44 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( component->GetFlags() == 0 )
|
2011-10-26 20:46:04 +00:00
|
|
|
{
|
2011-03-25 19:16:05 +00:00
|
|
|
SaveCopyInUndoList( item, UR_CHANGED );
|
2011-10-26 20:46:04 +00:00
|
|
|
GetScreen()->SetCurItem( NULL );
|
|
|
|
}
|
2011-03-03 19:55:44 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2011-03-03 19:55:44 +00:00
|
|
|
|
|
|
|
// Erase the previous component in it's current orientation.
|
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOff( &dc );
|
2011-03-03 19:55:44 +00:00
|
|
|
|
|
|
|
if( component->GetFlags() )
|
2012-03-12 10:04:40 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-03 19:55:44 +00:00
|
|
|
else
|
2012-03-12 10:04:40 +00:00
|
|
|
{
|
|
|
|
component->SetFlags( IS_MOVED ); // do not redraw the component
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->RefreshDrawingRect( component->GetBoundingBox() );
|
2012-03-12 10:04:40 +00:00
|
|
|
component->ClearFlags( IS_MOVED );
|
|
|
|
}
|
2011-03-03 19:55:44 +00:00
|
|
|
|
2011-10-28 20:30:50 +00:00
|
|
|
component->SetOrientation( aOrientation );
|
2011-03-03 19:55:44 +00:00
|
|
|
|
|
|
|
/* Redraw the component in the new position. */
|
|
|
|
if( component->GetFlags() )
|
2012-03-12 10:04:40 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
|
2011-03-03 19:55:44 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2011-03-03 19:55:44 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->CrossHairOn( &dc );
|
|
|
|
GetScreen()->TestDanglingEnds( m_canvas, &dc );
|
2011-03-03 19:55:44 +00:00
|
|
|
OnModify();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/*
|
2009-11-04 20:46:53 +00:00
|
|
|
* Handle select part in multi-part component.
|
2009-09-02 18:12:45 +00:00
|
|
|
*/
|
2011-03-02 00:46:08 +00:00
|
|
|
void SCH_EDIT_FRAME::OnSelectUnit( wxCommandEvent& aEvent )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2011-03-02 00:46:08 +00:00
|
|
|
SCH_SCREEN* screen = GetScreen();
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_ITEM* item = screen->GetCurItem();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
wxCHECK_RET( item != NULL && item->Type() == SCH_COMPONENT_T,
|
|
|
|
wxT( "Cannot select unit of invalid schematic item." ) );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, m_canvas );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->MoveCursorToCrossHair();
|
2011-03-02 00:46:08 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
int unit = aEvent.GetId() + 1 - ID_POPUP_SCH_SELECT_UNIT1;
|
|
|
|
|
|
|
|
LIB_COMPONENT* libEntry = CMP_LIBRARY::FindLibraryComponent( component->GetLibName() );
|
|
|
|
|
|
|
|
if( libEntry == NULL )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
wxCHECK_RET( (unit >= 1) && (unit <= libEntry->GetPartCount()),
|
|
|
|
wxString::Format( wxT( "Cannot select unit %d from component "), unit ) +
|
|
|
|
libEntry->GetName() );
|
|
|
|
|
|
|
|
int unitCount = libEntry->GetPartCount();
|
|
|
|
|
|
|
|
if( (unitCount <= 1) || (component->GetUnit() == unit) )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( unit < 1 )
|
|
|
|
unit = 1;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
if( unit > unitCount )
|
|
|
|
unit = unitCount;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2013-03-28 19:12:46 +00:00
|
|
|
STATUS_FLAGS flags = component->GetFlags();
|
2011-01-18 10:42:49 +00:00
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
if( !flags ) // No command in progress: save in undo list
|
|
|
|
SaveCopyInUndoList( component, UR_CHANGED );
|
|
|
|
|
|
|
|
if( flags )
|
2011-12-22 13:28:11 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Update the unit number. */
|
2011-12-08 21:05:43 +00:00
|
|
|
component->SetUnitSelection( m_CurrentSheet, unit );
|
2011-03-02 00:46:08 +00:00
|
|
|
component->SetUnit( unit );
|
2011-04-11 11:45:16 +00:00
|
|
|
component->ClearFlags();
|
|
|
|
component->SetFlags( flags ); // Restore m_Flag modified by SetUnit()
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Redraw the component in the new position. */
|
2011-03-02 00:46:08 +00:00
|
|
|
if( flags )
|
2011-12-22 13:28:11 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
component->Draw( m_canvas, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
screen->TestDanglingEnds( m_canvas, &dc );
|
2011-03-02 00:46:08 +00:00
|
|
|
OnModify();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* LibEntry;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( DrawComponent == NULL )
|
|
|
|
return;
|
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
LibEntry = CMP_LIBRARY::FindLibraryComponent( DrawComponent->GetLibName() );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( LibEntry == NULL )
|
|
|
|
return;
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
if( !LibEntry->HasConversion() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-09-02 18:12:45 +00:00
|
|
|
DisplayError( this, wxT( "No convert found" ) );
|
|
|
|
return;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 19:12:46 +00:00
|
|
|
STATUS_FLAGS flags = DrawComponent->GetFlags();
|
2011-12-21 13:42:02 +00:00
|
|
|
|
|
|
|
if( DrawComponent->GetFlags() )
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawComponent->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawComponent->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-12-14 15:56:30 +00:00
|
|
|
DrawComponent->SetConvert( DrawComponent->GetConvert() + 1 );
|
|
|
|
|
2009-10-01 16:46:13 +00:00
|
|
|
// ensure m_Convert = 0, 1 or 2
|
|
|
|
// 0 and 1 = shape 1 = not converted
|
|
|
|
// 2 = shape 2 = first converted shape
|
|
|
|
// > 2 is not used but could be used for more shapes
|
|
|
|
// like multiple shapes for a programmable component
|
|
|
|
// When m_Convert = val max, return to the first shape
|
2010-12-14 15:56:30 +00:00
|
|
|
if( DrawComponent->GetConvert() > 2 )
|
|
|
|
DrawComponent->SetConvert( 1 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-04-29 08:17:14 +00:00
|
|
|
DrawComponent->ClearFlags();
|
|
|
|
DrawComponent->SetFlags( flags ); // Restore m_Flag (modified by SetConvert())
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Redraw the component in the new position. */
|
2011-12-21 13:42:02 +00:00
|
|
|
if( DrawComponent->IsMoving() )
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawComponent->Draw( m_canvas, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-12-22 13:28:11 +00:00
|
|
|
DrawComponent->Draw( m_canvas, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-12-22 13:28:11 +00:00
|
|
|
GetScreen()->TestDanglingEnds( m_canvas, DC );
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|