2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************/
|
2009-09-02 18:12:45 +00:00
|
|
|
/* Module to handle Get & Place Library Part */
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-01-29 14:26:20 +00:00
|
|
|
#include "gr_basic.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "class_sch_screen.h"
|
|
|
|
#include "wxEeschemaStruct.h"
|
2011-03-02 00:46:08 +00:00
|
|
|
#include "kicad_device_context.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
#include "class_library.h"
|
2010-11-11 21:10:27 +00:00
|
|
|
#include "sch_component.h"
|
2010-02-16 16:21:52 +00:00
|
|
|
#include "viewlib_frame.h"
|
2011-03-02 00:46:08 +00:00
|
|
|
#include "eeschema_id.h"
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-11-20 10:59:59 +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
|
|
|
|
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase );
|
2011-01-21 19:30:59 +00:00
|
|
|
static void ExitPlaceCmp( EDA_DRAW_PANEL* Panel, wxDC* DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-10-20 20:24:26 +00:00
|
|
|
static TRANSFORM OldTransform;
|
|
|
|
static wxPoint OldPos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
wxString SCH_EDIT_FRAME::SelectFromLibBrowser( void )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
wxSemaphore semaphore( 0, 1 );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
/* Close the current Lib browser, if open, and open a new one, in "modal" mode */
|
2009-10-16 17:18:23 +00:00
|
|
|
if( m_ViewlibFrame )
|
|
|
|
{
|
|
|
|
m_ViewlibFrame->Destroy();
|
|
|
|
m_ViewlibFrame = NULL;
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2010-11-20 21:59:00 +00:00
|
|
|
m_ViewlibFrame = new LIB_VIEW_FRAME( this, NULL, &semaphore );
|
2011-02-11 20:48:13 +00:00
|
|
|
m_ViewlibFrame->AdjustScrollBars( wxPoint( 0 , 0 ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
// Show the library viewer frame until it is closed
|
2009-10-01 14:17:47 +00:00
|
|
|
while( semaphore.TryWait() == wxSEMA_BUSY ) // Wait for viewer closing event
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
wxYield();
|
|
|
|
wxMilliSleep( 50 );
|
|
|
|
}
|
|
|
|
|
2010-11-20 10:59:59 +00:00
|
|
|
return m_ViewlibFrame->GetSelectedComponent();
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-09-02 18:12:45 +00:00
|
|
|
/*
|
|
|
|
* load from a library and place a component
|
2007-08-20 01:20:48 +00:00
|
|
|
* if libname != "", search in lib "libname"
|
|
|
|
* else search in all loaded libs
|
|
|
|
*/
|
2010-12-08 20:12:46 +00:00
|
|
|
SCH_COMPONENT* SCH_EDIT_FRAME::Load_Component( wxDC* DC,
|
|
|
|
const wxString& libname,
|
|
|
|
wxArrayString& HistoryList,
|
|
|
|
bool UseLibBrowser )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
int CmpCount = 0;
|
|
|
|
int unit = 1;
|
|
|
|
int convert = 1;
|
|
|
|
LIB_COMPONENT* Entry = NULL;
|
|
|
|
SCH_COMPONENT* Component = NULL;
|
|
|
|
CMP_LIBRARY* Library = NULL;
|
|
|
|
wxString Name, keys, msg;
|
|
|
|
bool AllowWildSeach = TRUE;
|
|
|
|
static wxString lastCommponentName;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-12 21:47:54 +00:00
|
|
|
m_itemToRepeat = NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->m_IgnoreMouseEvents = TRUE;
|
|
|
|
|
|
|
|
if( !libname.IsEmpty() )
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
Library = CMP_LIBRARY::FindLibrary( libname );
|
|
|
|
|
|
|
|
if( Library != NULL )
|
|
|
|
CmpCount = Library->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ask for a component name or key words */
|
|
|
|
msg.Printf( _( "component selection (%d items loaded):" ), CmpCount );
|
|
|
|
|
2010-11-20 10:59:59 +00:00
|
|
|
DIALOG_GET_COMPONENT dlg( this, GetComponentDialogPosition(), HistoryList,
|
2010-12-08 20:12:46 +00:00
|
|
|
msg, UseLibBrowser );
|
2009-10-16 17:18:23 +00:00
|
|
|
dlg.SetComponentName( lastCommponentName );
|
|
|
|
|
|
|
|
if ( dlg.ShowModal() == wxID_CANCEL )
|
2009-10-18 13:12:00 +00:00
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2009-10-16 17:18:23 +00:00
|
|
|
return NULL;
|
2009-10-18 13:12:00 +00:00
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
if( dlg.m_GetExtraFunction )
|
|
|
|
{
|
|
|
|
Name = SelectFromLibBrowser();
|
|
|
|
unit = m_ViewlibFrame->GetUnit();
|
|
|
|
convert = m_ViewlibFrame->GetConvert();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Name = dlg.GetComponentName();
|
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Name.IsEmpty() )
|
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2009-10-16 17:18:23 +00:00
|
|
|
return NULL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2010-10-22 15:02:11 +00:00
|
|
|
#ifndef KICAD_KEEPCASE
|
2009-10-16 17:18:23 +00:00
|
|
|
Name.MakeUpper();
|
2010-10-22 15:02:11 +00:00
|
|
|
#endif
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Name.GetChar( 0 ) == '=' )
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
|
|
|
keys = Name.AfterFirst( '=' );
|
2009-08-27 11:41:56 +00:00
|
|
|
Name = DataBaseGetName( this, keys, Name );
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2009-08-27 11:41:56 +00:00
|
|
|
if( Name.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( Name == wxT( "*" ) )
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( GetNameOfPartToLoad( this, Library, Name ) == 0 )
|
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( Name.Contains( wxT( "?" ) ) || Name.Contains( wxT( "*" ) ) )
|
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
2009-08-27 11:41:56 +00:00
|
|
|
Name = DataBaseGetName( this, keys, Name );
|
|
|
|
if( Name.IsEmpty() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
if( ( Entry == NULL ) && AllowWildSeach ) /* Search with wildcard */
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
|
|
|
AllowWildSeach = FALSE;
|
|
|
|
wxString wildname = wxChar( '*' ) + Name + wxChar( '*' );
|
|
|
|
Name = wildname;
|
2009-08-27 11:41:56 +00:00
|
|
|
Name = DataBaseGetName( this, keys, Name );
|
|
|
|
|
|
|
|
if( !Name.IsEmpty() )
|
2009-09-18 14:56:05 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
{
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DrawPanel->m_IgnoreMouseEvents = FALSE;
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Entry == NULL )
|
|
|
|
{
|
|
|
|
msg = _( "Failed to find part " ) + Name + _( " in library" );
|
2009-10-16 17:18:23 +00:00
|
|
|
DisplayError( this, msg );
|
2007-08-20 01:20:48 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
lastCommponentName = Name;
|
2007-08-20 01:20:48 +00:00
|
|
|
AddHistoryComponentName( HistoryList, Name );
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( ShowWhileMoving, ExitPlaceCmp );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
Component = new SCH_COMPONENT( *Entry, GetSheet(), unit, convert,
|
2011-02-11 20:48:13 +00:00
|
|
|
GetScreen()->GetCrossHairPosition(), true );
|
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
|
2010-12-14 15:56:30 +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
|
2009-10-27 10:55:46 +00:00
|
|
|
Component->GetField( VALUE )->m_Text = Name;
|
2009-04-17 08:51:02 +00:00
|
|
|
Component->DisplayInfo( this );
|
2011-01-07 19:24:24 +00:00
|
|
|
Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2009-10-27 10:55:46 +00:00
|
|
|
|
2008-12-31 16:49:45 +00:00
|
|
|
return Component;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/**
|
|
|
|
* Move a component.
|
|
|
|
*/
|
2011-02-03 19:27:28 +00:00
|
|
|
static void ShowWhileMoving( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
|
|
|
|
bool aErase )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
wxPoint move_vector;
|
2011-02-03 19:27:28 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) aPanel->GetScreen();
|
2008-12-31 16:49:45 +00:00
|
|
|
SCH_COMPONENT* Component = (SCH_COMPONENT*) screen->GetCurItem();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-03 19:27:28 +00:00
|
|
|
if( aErase )
|
2008-03-16 04:47:43 +00:00
|
|
|
{
|
2011-02-03 19:27:28 +00:00
|
|
|
Component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2008-03-16 04:47:43 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
move_vector = screen->GetCrossHairPosition() - Component->m_Pos;
|
2009-07-27 14:32:40 +00:00
|
|
|
Component->Move( move_vector );
|
2011-02-03 19:27:28 +00:00
|
|
|
Component->Draw( aPanel, aDC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
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
|
|
|
* Routine to rotate and mirror a component.
|
|
|
|
*
|
|
|
|
** If DC == NULL: no repaint
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-03-03 19:55:44 +00:00
|
|
|
void SCH_EDIT_FRAME::OnChangeComponentOrientation( wxCommandEvent& aEvent )
|
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-03-03 19:55:44 +00:00
|
|
|
int orientation;
|
|
|
|
|
|
|
|
switch( aEvent.GetId() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2011-03-03 19:55:44 +00:00
|
|
|
case ID_POPUP_SCH_MIROR_X_CMP:
|
|
|
|
orientation = CMP_MIRROR_X;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_MIROR_Y_CMP:
|
|
|
|
orientation = CMP_MIRROR_Y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE:
|
|
|
|
orientation = CMP_ROTATE_COUNTERCLOCKWISE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE:
|
|
|
|
orientation = CMP_ROTATE_CLOCKWISE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_SCH_ORIENT_NORMAL_CMP:
|
|
|
|
default:
|
|
|
|
orientation = CMP_NORMAL;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-03 19:55:44 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
if( component->GetFlags() == 0 )
|
|
|
|
SaveCopyInUndoList( item, UR_CHANGED );
|
2011-03-03 19:55:44 +00:00
|
|
|
|
|
|
|
INSTALL_UNBUFFERED_DC( dc, DrawPanel );
|
|
|
|
|
|
|
|
// Erase the previous component in it's current orientation.
|
|
|
|
|
|
|
|
DrawPanel->CrossHairOff( &dc );
|
|
|
|
|
|
|
|
if( component->GetFlags() )
|
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
|
|
|
else
|
|
|
|
DrawPanel->RefreshDrawingRect( component->GetBoundingBox() );
|
|
|
|
|
|
|
|
component->SetOrientation( orientation );
|
|
|
|
|
|
|
|
/* Redraw the component in the new position. */
|
|
|
|
if( component->GetFlags() )
|
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
|
|
|
else
|
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
|
|
|
|
|
|
|
DrawPanel->CrossHairOn( &dc );
|
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, &dc );
|
|
|
|
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
|
|
|
* Abort a place component command in progress.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2011-01-21 19:30:59 +00:00
|
|
|
static void ExitPlaceCmp( EDA_DRAW_PANEL* Panel, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
SCH_SCREEN* screen = (SCH_SCREEN*) Panel->GetScreen();
|
2008-04-17 16:25:29 +00:00
|
|
|
|
2008-12-31 16:49:45 +00:00
|
|
|
SCH_COMPONENT* Component = (SCH_COMPONENT*) screen->GetCurItem();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
if( Component->m_Flags & IS_NEW )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2008-12-31 16:49:45 +00:00
|
|
|
Component->m_Flags = 0;
|
|
|
|
SAFE_DELETE( Component );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2009-11-04 20:46:53 +00:00
|
|
|
else if( Component )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2009-07-27 14:32:40 +00:00
|
|
|
wxPoint move_vector = OldPos - Component->m_Pos;
|
|
|
|
Component->Move( move_vector );
|
2010-12-14 21:39:31 +00:00
|
|
|
Component->SetTransform( OldTransform );
|
2008-12-31 16:49:45 +00:00
|
|
|
Component->m_Flags = 0;
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
Panel->Refresh( true );
|
2008-04-17 16:25:29 +00:00
|
|
|
screen->SetCurItem( NULL );
|
2007-06-05 12:10:51 +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-03-02 00:46:08 +00:00
|
|
|
INSTALL_UNBUFFERED_DC( dc, DrawPanel );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
|
|
|
|
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
|
|
|
|
2011-03-02 00:46:08 +00:00
|
|
|
int 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 )
|
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-03-02 00:46:08 +00:00
|
|
|
component->Draw( DrawPanel, &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-03-02 00:46:08 +00:00
|
|
|
component->SetUnitSelection( GetSheet(), unit );
|
|
|
|
component->SetUnit( unit );
|
|
|
|
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 )
|
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2011-03-02 00:46:08 +00:00
|
|
|
component->Draw( DrawPanel, &dc, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2011-03-25 19:16:05 +00:00
|
|
|
screen->TestDanglingEnds( DrawPanel, &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
|
|
|
}
|
|
|
|
|
|
|
|
if( DrawComponent->m_Flags )
|
2011-01-07 19:24:24 +00:00
|
|
|
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
|
|
|
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
|
|
|
|
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
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Redraw the component in the new position. */
|
2007-08-20 01:20:48 +00:00
|
|
|
if( DrawComponent->m_Flags & IS_MOVED )
|
2011-01-07 19:24:24 +00:00
|
|
|
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2007-08-20 01:20:48 +00:00
|
|
|
else
|
2010-12-14 15:56:30 +00:00
|
|
|
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
GetScreen()->TestDanglingEnds( DrawPanel, DC );
|
2010-02-18 20:07:29 +00:00
|
|
|
OnModify( );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-08 20:12:46 +00:00
|
|
|
void SCH_EDIT_FRAME::StartMovePart( SCH_COMPONENT* Component, wxDC* DC )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( Component == NULL )
|
|
|
|
return;
|
2010-12-08 20:12:46 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
if( Component->Type() != SCH_COMPONENT_T )
|
2007-08-20 01:20:48 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if( Component->m_Flags == 0 )
|
|
|
|
{
|
2008-12-08 15:27:13 +00:00
|
|
|
if( g_ItemToUndoCopy )
|
|
|
|
{
|
2008-03-16 04:47:43 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
|
|
|
}
|
2010-12-21 15:13:09 +00:00
|
|
|
|
|
|
|
g_ItemToUndoCopy = Component->Clone();
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOff( DC );
|
|
|
|
GetScreen()->SetCrossHairPosition( Component->m_Pos );
|
|
|
|
DrawPanel->MoveCursorToCrossHair();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->SetMouseCapture( ShowWhileMoving, ExitPlaceCmp );
|
2008-03-16 04:47:43 +00:00
|
|
|
GetScreen()->SetCurItem( Component );
|
2007-08-20 01:20:48 +00:00
|
|
|
OldPos = Component->m_Pos;
|
2010-12-14 21:39:31 +00:00
|
|
|
OldTransform = Component->GetTransform();
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2008-03-16 04:47:43 +00:00
|
|
|
#if 1
|
2008-12-08 15:27:13 +00:00
|
|
|
|
2008-03-16 04:47:43 +00:00
|
|
|
// switch from normal mode to xor mode for the duration of the move, first
|
2009-11-04 20:46:53 +00:00
|
|
|
// by erasing fully any "normal drawing mode" primitives with the
|
2011-01-30 22:22:38 +00:00
|
|
|
// RefreshDrawingRect(), then by drawing the first time in xor mode so that
|
2009-11-04 20:46:53 +00:00
|
|
|
// subsequent xor drawing modes will fully erase this first copy.
|
2008-03-16 04:47:43 +00:00
|
|
|
|
|
|
|
Component->m_Flags |= IS_MOVED; // omit redrawing the component, erase only
|
2011-01-30 22:22:38 +00:00
|
|
|
DrawPanel->RefreshDrawingRect( Component->GetBoundingBox() );
|
2008-03-16 04:47:43 +00:00
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode, g_GhostColor );
|
2008-03-16 04:47:43 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2011-01-07 19:24:24 +00:00
|
|
|
Component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
|
2008-03-16 04:47:43 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Component->m_Flags |= IS_MOVED;
|
2008-03-16 04:47:43 +00:00
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, FALSE );
|
2008-03-16 04:47:43 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DrawPanel->m_AutoPAN_Request = TRUE;
|
|
|
|
|
2011-02-11 20:48:13 +00:00
|
|
|
DrawPanel->CrossHairOn( DC );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|