2009-07-27 14:32:40 +00:00
|
|
|
/**************************************************************/
|
|
|
|
/* class_sch_component.cpp : handle the class SCH_COMPONENT */
|
|
|
|
/**************************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
2010-06-17 16:30:10 +00:00
|
|
|
#include "appl_wxstruct.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "class_drawpanel.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2010-09-05 17:01:48 +00:00
|
|
|
#include "trigo.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
2007-11-05 07:07:00 +00:00
|
|
|
#include "macros.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "protos.h"
|
2009-09-25 18:49:04 +00:00
|
|
|
#include "class_library.h"
|
2010-10-26 20:25:48 +00:00
|
|
|
#include "dialogs/dialog_schematic_find.h"
|
2010-10-08 20:40:57 +00:00
|
|
|
#include "lib_rectangle.h"
|
2010-10-22 12:11:52 +00:00
|
|
|
#include "lib_pin.h"
|
|
|
|
#include "lib_text.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
#include <wx/tokenzr.h>
|
2008-02-27 19:38:16 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
static LIB_COMPONENT* DummyCmp;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Descr component <DUMMY> used when a component is not found in library,
|
|
|
|
* to draw a dummy shape
|
|
|
|
* This component is a 400 mils square with the text ??
|
|
|
|
* DEF DUMMY U 0 40 Y Y 1 0 N
|
|
|
|
* F0 "U" 0 -350 60 H V
|
|
|
|
* F1 "DUMMY" 0 350 60 H V
|
|
|
|
* DRAW
|
|
|
|
* T 0 0 0 150 0 0 0 ??
|
|
|
|
* S -200 200 200 -200 0 1 0
|
|
|
|
* ENDDRAW
|
|
|
|
* ENDDEF
|
|
|
|
*/
|
|
|
|
void CreateDummyCmp()
|
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
DummyCmp = new LIB_COMPONENT( wxEmptyString );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
LIB_RECTANGLE* Square = new LIB_RECTANGLE( DummyCmp );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
Square->Move( wxPoint( -200, 200 ) );
|
|
|
|
Square->SetEndPosition( wxPoint( 200, -200 ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
LIB_TEXT* Text = new LIB_TEXT( DummyCmp );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
Text->m_Size.x = Text->m_Size.y = 150;
|
|
|
|
Text->m_Text = wxT( "??" );
|
|
|
|
|
2009-09-29 18:38:21 +00:00
|
|
|
DummyCmp->AddDrawItem( Square );
|
|
|
|
DummyCmp->AddDrawItem( Text );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos, SCH_ITEM* aParent ) :
|
|
|
|
SCH_ITEM( aParent, TYPE_SCH_COMPONENT )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
Init( aPos );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent,
|
|
|
|
SCH_SHEET_PATH* sheet, int unit, int convert,
|
|
|
|
const wxPoint& pos, bool setNewItemFlag ) :
|
2009-10-16 17:18:23 +00:00
|
|
|
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
Init( pos );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
m_Multi = unit;
|
|
|
|
m_Convert = convert;
|
|
|
|
m_ChipName = libComponent.GetName();
|
|
|
|
m_TimeStamp = GetTimeStamp();
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
if( setNewItemFlag )
|
|
|
|
m_Flags = IS_NEW | IS_MOVED;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// Import user defined fields from the library component:
|
2010-05-08 16:32:35 +00:00
|
|
|
LIB_FIELD_LIST libFields;
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2009-10-21 20:02:25 +00:00
|
|
|
libComponent.GetFields( libFields );
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
for( LIB_FIELD_LIST::iterator it = libFields.begin(); it!=libFields.end(); ++it )
|
2008-10-06 05:44:29 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
// Can no longer insert an empty name, since names are now keys. The
|
|
|
|
// field index is not used beyond the first MANDATORY_FIELDS
|
|
|
|
if( it->m_Name.IsEmpty() )
|
2009-10-16 17:18:23 +00:00
|
|
|
continue;
|
2008-10-18 13:42:21 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// See if field by same name already exists.
|
|
|
|
SCH_FIELD* schField = FindField( it->m_Name );
|
|
|
|
|
|
|
|
if( !schField )
|
2009-10-21 20:02:25 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD fld( wxPoint( 0, 0 ), GetFieldCount(), this, it->m_Name );
|
|
|
|
schField = AddField( fld );
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
schField->m_Pos = m_Pos + it->m_Pos;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
schField->ImportValues( *it );
|
|
|
|
|
|
|
|
schField->m_Text = it->m_Text;
|
|
|
|
}
|
2009-10-21 20:02:25 +00:00
|
|
|
|
|
|
|
wxString msg = libComponent.GetReferenceField().m_Text;
|
|
|
|
|
|
|
|
if( msg.IsEmpty() )
|
|
|
|
msg = wxT( "U" );
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2009-10-27 10:55:46 +00:00
|
|
|
m_PrefixString = msg;
|
2009-10-21 20:02:25 +00:00
|
|
|
|
|
|
|
// update the reference -- just the prefix for now.
|
2009-10-27 10:55:46 +00:00
|
|
|
msg += wxT( "?" );
|
2009-10-21 20:02:25 +00:00
|
|
|
SetRef( sheet, msg );
|
|
|
|
|
|
|
|
/* Use the schematic component name instead of the library value field
|
|
|
|
* name.
|
|
|
|
*/
|
|
|
|
GetField( VALUE )->m_Text = m_ChipName;
|
2008-10-06 05:44:29 +00:00
|
|
|
}
|
|
|
|
|
2008-10-19 18:31:09 +00:00
|
|
|
|
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aTemplate ) :
|
|
|
|
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
/* assignment of all fields, including field vector elements, and linked
|
|
|
|
* list pointers */
|
2008-10-19 18:31:09 +00:00
|
|
|
*this = aTemplate;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* set linked list pointers to null, before this they were copies of
|
|
|
|
* aTemplate's */
|
2008-10-19 18:31:09 +00:00
|
|
|
Pback = NULL;
|
|
|
|
Pnext = NULL;
|
|
|
|
m_Son = NULL;
|
|
|
|
|
2008-11-24 06:53:43 +00:00
|
|
|
// Re-parent the fields, which before this had aTemplate as parent
|
2010-09-05 17:01:48 +00:00
|
|
|
for( int i = 0; i<GetFieldCount(); ++i )
|
2008-10-19 18:31:09 +00:00
|
|
|
{
|
2008-11-24 06:53:43 +00:00
|
|
|
GetField( i )->SetParent( this );
|
2008-10-19 18:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
void SCH_COMPONENT::Init( const wxPoint& pos )
|
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Pos = pos;
|
|
|
|
m_Multi = 0; // In multi unit chip - which unit to draw.
|
2010-06-17 16:30:10 +00:00
|
|
|
m_Convert = 0; // De Morgan Handling
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// The rotation/mirror transformation matrix. pos normal
|
2010-10-20 20:24:26 +00:00
|
|
|
m_Transform = TRANSFORM();
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// construct only the mandatory fields, which are the first 4 only.
|
|
|
|
for( int i = 0; i < MANDATORY_FIELDS; ++i )
|
2009-10-16 17:18:23 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD field( pos, i, this, TEMPLATE_FIELDNAME::GetDefaultFieldName( i ) );
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
if( i==REFERENCE )
|
|
|
|
field.SetLayer( LAYER_REFERENCEPART );
|
|
|
|
else if( i==VALUE )
|
|
|
|
field.SetLayer( LAYER_VALUEPART );
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// else keep LAYER_FIELDS from SCH_FIELD constructor
|
2009-10-16 17:18:23 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// SCH_FIELD's implicitly created copy constructor is called in here
|
2009-10-16 17:18:23 +00:00
|
|
|
AddField( field );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_PrefixString = wxString( _( "U" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*****************************************************************************
|
2009-10-30 19:26:25 +00:00
|
|
|
* Routine to draw the given part at given position, transformed/mirror as *
|
|
|
|
* specified, and in the given drawing mode. Only this one is visible... *
|
2009-04-05 20:49:15 +00:00
|
|
|
*****************************************************************************/
|
|
|
|
void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
2009-10-16 17:18:23 +00:00
|
|
|
const wxPoint& offset, int DrawMode, int Color,
|
|
|
|
bool DrawPinText )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
bool dummy = FALSE;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
2009-08-27 11:41:56 +00:00
|
|
|
|
|
|
|
if( Entry == NULL )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-16 17:18:23 +00:00
|
|
|
/* Create a dummy component if the actual component can not be found. */
|
2009-04-05 20:49:15 +00:00
|
|
|
dummy = TRUE;
|
|
|
|
if( DummyCmp == NULL )
|
|
|
|
CreateDummyCmp();
|
|
|
|
Entry = DummyCmp;
|
|
|
|
}
|
|
|
|
|
2009-10-16 17:18:23 +00:00
|
|
|
Entry->Draw( panel, DC, m_Pos + offset, dummy ? 0 : m_Multi,
|
|
|
|
dummy ? 0 : m_Convert, DrawMode, Color, m_Transform,
|
2009-10-17 06:23:18 +00:00
|
|
|
DrawPinText, false );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD* field = GetField( REFERENCE );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-30 18:06:12 +00:00
|
|
|
if( field->IsVisible() && !( field->m_Flags & IS_MOVED ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2009-10-05 17:52:41 +00:00
|
|
|
if( Entry->GetPartCount() > 1 )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
field->m_AddExtraText = true;
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
field->m_AddExtraText = false;
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
for( int ii = VALUE; ii < GetFieldCount(); ii++ )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
field = GetField( ii );
|
|
|
|
|
|
|
|
if( field->m_Flags & IS_MOVED )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
field->Draw( panel, DC, offset, DrawMode );
|
|
|
|
}
|
2009-10-16 17:18:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Draw the component boundary box */
|
|
|
|
{
|
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
BoundaryBox = GetBoundaryBox();
|
2009-12-30 18:06:12 +00:00
|
|
|
GRRect( &panel->m_ClipBox, DC, BoundaryBox, BROWN );
|
|
|
|
#if 1
|
|
|
|
if( GetField( REFERENCE )->IsVisible() )
|
|
|
|
{
|
|
|
|
BoundaryBox = GetField( REFERENCE )->GetBoundaryBox();
|
|
|
|
GRRect( &panel->m_ClipBox, DC, BoundaryBox, BROWN );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( GetField( VALUE )->IsVisible() )
|
|
|
|
{
|
|
|
|
BoundaryBox = GetField( VALUE )->GetBoundaryBox();
|
|
|
|
GRRect( &panel->m_ClipBox, DC, BoundaryBox, BROWN );
|
|
|
|
}
|
|
|
|
#endif
|
2009-10-16 17:18:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
/**
|
|
|
|
* Function AddHierarchicalReference
|
2009-10-30 19:26:25 +00:00
|
|
|
* adds a full hierarchical reference (path + local reference)
|
2009-04-05 20:49:15 +00:00
|
|
|
* @param aPath = hierarchical path (/<sheet timestamp>/component timestamp>
|
|
|
|
* like /05678E50/A23EF560)
|
2008-04-16 08:40:31 +00:00
|
|
|
* @param aRef = local reference like C45, R56
|
2009-04-05 20:49:15 +00:00
|
|
|
* @param aMulti = part selection, used in multi part per package (0 or 1 for
|
|
|
|
* non multi)
|
2008-04-12 18:39:20 +00:00
|
|
|
*/
|
2008-04-16 08:40:31 +00:00
|
|
|
void SCH_COMPONENT::AddHierarchicalReference( const wxString& aPath,
|
|
|
|
const wxString& aRef,
|
|
|
|
int aMulti )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
wxString h_path, h_ref;
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
|
|
|
|
// Search for an existing path and remove it if found (should not occur)
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
h_path = tokenizer.GetNextToken();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
if( h_path.Cmp( aPath ) == 0 )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2008-04-16 08:40:31 +00:00
|
|
|
m_PathsAndReferences.RemoveAt( ii );
|
|
|
|
ii--;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
h_ref = aPath + wxT( " " ) + aRef;
|
|
|
|
h_ref << wxT( " " ) << aMulti;
|
2008-04-15 19:38:19 +00:00
|
|
|
m_PathsAndReferences.Add( h_ref );
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
wxString SCH_COMPONENT::ReturnFieldName( int aFieldNdx ) const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD* field = GetField( aFieldNdx );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
if( field )
|
|
|
|
{
|
|
|
|
if( !field->m_Name.IsEmpty() )
|
|
|
|
return field->m_Name;
|
|
|
|
else
|
2010-06-17 16:30:10 +00:00
|
|
|
return TEMPLATE_FIELDNAME::GetDefaultFieldName( aFieldNdx );
|
2008-10-06 05:44:29 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
return wxEmptyString;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
wxString SCH_COMPONENT::GetPath( SCH_SHEET_PATH* sheet )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2008-02-21 12:21:01 +00:00
|
|
|
wxString str;
|
|
|
|
|
|
|
|
str.Printf( wxT( "%8.8lX" ), m_TimeStamp );
|
|
|
|
return sheet->Path() + str;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
const wxString SCH_COMPONENT::GetRef( SCH_SHEET_PATH* sheet )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
wxString path = GetPath( sheet );
|
|
|
|
wxString h_path, h_ref;
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
wxString separators( wxT( " " ) );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
h_path = tokenizer.GetNextToken();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
if( h_path.Cmp( path ) == 0 )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
h_ref = tokenizer.GetNextToken();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* printf( "GetRef hpath: %s\n",
|
2010-09-05 17:01:48 +00:00
|
|
|
* CONV_TO_UTF8( m_PathsAndReferences[ii] ) ); */
|
2008-04-15 19:38:19 +00:00
|
|
|
return h_ref;
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
// if it was not found in m_Paths array, then see if it is in
|
2008-02-21 12:21:01 +00:00
|
|
|
// m_Field[REFERENCE] -- if so, use this as a default for this path.
|
|
|
|
// this will happen if we load a version 1 schematic file.
|
|
|
|
// it will also mean that multiple instances of the same sheet by default
|
|
|
|
// all have the same component references, but perhaps this is best.
|
2008-10-18 13:42:21 +00:00
|
|
|
if( !GetField( REFERENCE )->m_Text.IsEmpty() )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-10-18 13:42:21 +00:00
|
|
|
SetRef( sheet, GetField( REFERENCE )->m_Text );
|
|
|
|
return GetField( REFERENCE )->m_Text;
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
return m_PrefixString;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_COMPONENT::SetRef( SCH_SHEET_PATH* sheet, const wxString& ref )
|
2008-02-12 21:12:46 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
wxString path = GetPath( sheet );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
bool notInArray = true;
|
|
|
|
|
|
|
|
wxString h_path, h_ref;
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
wxString separators( wxT( " " ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
// check to see if it is already there before inserting it
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
h_path = tokenizer.GetNextToken();
|
|
|
|
if( h_path.Cmp( path ) == 0 )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
// just update the reference text, not the timestamp.
|
2008-04-15 19:38:19 +00:00
|
|
|
h_ref = h_path + wxT( " " ) + ref;
|
|
|
|
h_ref += wxT( " " );
|
|
|
|
tokenizer.GetNextToken(); // Skip old reference
|
|
|
|
h_ref += tokenizer.GetNextToken(); // Add part selection
|
|
|
|
// Ann the part selection
|
|
|
|
m_PathsAndReferences[ii] = h_ref;
|
2008-02-21 12:21:01 +00:00
|
|
|
notInArray = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( notInArray )
|
2008-04-16 08:40:31 +00:00
|
|
|
AddHierarchicalReference( path, ref, m_Multi );
|
2008-04-14 19:22:48 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD* rf = GetField( REFERENCE );
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
if( rf->m_Text.IsEmpty()
|
2010-09-05 17:01:48 +00:00
|
|
|
|| ( abs( rf->m_Pos.x - m_Pos.x ) +
|
|
|
|
abs( rf->m_Pos.y - m_Pos.y ) > 10000 ) )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
// move it to a reasonable position
|
|
|
|
rf->m_Pos = m_Pos;
|
|
|
|
rf->m_Pos.x += 50; // a slight offset
|
|
|
|
rf->m_Pos.y += 50;
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
rf->m_Text = ref; // for drawing.
|
2009-10-30 19:26:25 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
// Reinit the m_PrefixString member if needed
|
|
|
|
wxString prefix = ref;
|
2010-09-05 17:01:48 +00:00
|
|
|
while( prefix.Last() == '?' or isdigit( prefix.Last() ) )
|
2009-10-27 19:30:32 +00:00
|
|
|
prefix.RemoveLast();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-10-27 19:30:32 +00:00
|
|
|
if( m_PrefixString != prefix )
|
|
|
|
m_PrefixString = prefix;
|
2008-02-12 21:12:46 +00:00
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-04-25 10:12:30 +00:00
|
|
|
/** function SetTimeStamp
|
|
|
|
* Change the old time stamp to the new time stamp.
|
|
|
|
* the time stamp is also modified in paths
|
|
|
|
* @param aNewTimeStamp = new time stamp
|
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_COMPONENT::SetTimeStamp( long aNewTimeStamp )
|
2009-04-25 10:12:30 +00:00
|
|
|
{
|
|
|
|
wxString string_timestamp, string_oldtimestamp;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
string_timestamp.Printf( wxT( "%8.8X" ), aNewTimeStamp );
|
|
|
|
string_oldtimestamp.Printf( wxT( "%8.8X" ), m_TimeStamp );
|
2009-04-25 10:12:30 +00:00
|
|
|
m_TimeStamp = aNewTimeStamp;
|
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
m_PathsAndReferences[ii].Replace( string_oldtimestamp.GetData(),
|
2010-09-05 17:01:48 +00:00
|
|
|
string_timestamp.GetData() );
|
|
|
|
}
|
2009-04-25 10:12:30 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
/***********************************************************/
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
//returns the unit selection, for the given sheet path.
|
2009-04-05 20:49:15 +00:00
|
|
|
/***********************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_COMPONENT::GetUnitSelection( SCH_SHEET_PATH* aSheet )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
|
|
|
wxString path = GetPath( aSheet );
|
|
|
|
wxString h_path, h_multi;
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
h_path = tokenizer.GetNextToken();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
if( h_path.Cmp( path ) == 0 )
|
|
|
|
{
|
|
|
|
tokenizer.GetNextToken(); // Skip reference
|
|
|
|
h_multi = tokenizer.GetNextToken();
|
|
|
|
long imulti = 1;
|
|
|
|
h_multi.ToLong( &imulti );
|
|
|
|
return imulti;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// if it was not found in m_Paths array, then use m_Multi.
|
2008-04-16 08:40:31 +00:00
|
|
|
// this will happen if we load a version 1 schematic file.
|
|
|
|
return m_Multi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/****************************************************************************/
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
//Set the unit selection, for the given sheet path.
|
2009-04-05 20:49:15 +00:00
|
|
|
/****************************************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_COMPONENT::SetUnitSelection( SCH_SHEET_PATH* aSheet,
|
|
|
|
int aUnitSelection )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
|
|
|
wxString path = GetPath( aSheet );
|
|
|
|
|
|
|
|
bool notInArray = true;
|
|
|
|
|
|
|
|
wxString h_path, h_ref;
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
|
|
|
|
//check to see if it is already there before inserting it
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-16 08:40:31 +00:00
|
|
|
{
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
h_path = tokenizer.GetNextToken();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
if( h_path.Cmp( path ) == 0 )
|
|
|
|
{
|
|
|
|
//just update the unit selection.
|
|
|
|
h_ref = h_path + wxT( " " );
|
|
|
|
h_ref += tokenizer.GetNextToken(); // Add reference
|
|
|
|
h_ref += wxT( " " );
|
|
|
|
h_ref << aUnitSelection; // Add part selection
|
|
|
|
// Ann the part selection
|
|
|
|
m_PathsAndReferences[ii] = h_ref;
|
|
|
|
notInArray = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( notInArray )
|
|
|
|
AddHierarchicalReference( path, m_PrefixString, aUnitSelection );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_FIELD* SCH_COMPONENT::GetField( int aFieldNdx ) const
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
const SCH_FIELD* field;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
|
|
|
if( (unsigned) aFieldNdx < m_Fields.size() )
|
|
|
|
field = &m_Fields[aFieldNdx];
|
|
|
|
else
|
|
|
|
field = NULL;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
wxASSERT( field );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// use cast to remove const-ness
|
2009-12-02 21:44:03 +00:00
|
|
|
return (SCH_FIELD*) field;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD* SCH_COMPONENT::AddField( const SCH_FIELD& aField )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
int newNdx = m_Fields.size();
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-10-06 05:44:29 +00:00
|
|
|
m_Fields.push_back( aField );
|
2010-06-17 16:30:10 +00:00
|
|
|
return &m_Fields[newNdx];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SCH_FIELD* SCH_COMPONENT::FindField( const wxString& aFieldName )
|
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
for( unsigned i = 0; i<m_Fields.size(); ++i )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
if( aFieldName == m_Fields[i].m_Name )
|
|
|
|
return &m_Fields[i];
|
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
return NULL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
LIB_PIN* SCH_COMPONENT::GetPin( const wxString& number )
|
|
|
|
{
|
|
|
|
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
|
|
|
|
|
|
|
if( Entry == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return Entry->GetPin( number, m_Multi, m_Convert );
|
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-12-30 18:06:12 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundaryBox
|
|
|
|
* returns the orthogonal, bounding box of this object for display purposes.
|
|
|
|
* This box should be an enclosing perimeter for graphic items and pins.
|
|
|
|
* this include only fields defined in library
|
|
|
|
* use GetBoundingBox() to include fields in schematic
|
|
|
|
*/
|
2008-03-20 01:50:21 +00:00
|
|
|
EDA_Rect SCH_COMPONENT::GetBoundaryBox() const
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
2010-09-05 17:01:48 +00:00
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
int x0, xm, y0, ym;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/* Get the basic Boundary box */
|
|
|
|
if( Entry )
|
|
|
|
{
|
|
|
|
BoundaryBox = Entry->GetBoundaryBox( m_Multi, m_Convert );
|
2009-04-05 20:49:15 +00:00
|
|
|
x0 = BoundaryBox.GetX();
|
|
|
|
xm = BoundaryBox.GetRight();
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
// We must reverse Y values, because matrix orientation
|
|
|
|
// suppose Y axis normal for the library items coordinates,
|
2008-02-21 12:21:01 +00:00
|
|
|
// m_Transform reverse Y values, but BoundaryBox is already reversed!
|
2007-09-20 21:06:49 +00:00
|
|
|
y0 = -BoundaryBox.GetY();
|
|
|
|
ym = -BoundaryBox.GetBottom();
|
|
|
|
}
|
|
|
|
else /* if lib Entry not found, give a reasonable size */
|
|
|
|
{
|
|
|
|
x0 = y0 = -50;
|
|
|
|
xm = ym = 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Compute the real Boundary box (rotated, mirrored ...)*/
|
2010-10-20 20:24:26 +00:00
|
|
|
int x1 = m_Transform.x1 * x0 + m_Transform.y1 * y0;
|
|
|
|
int y1 = m_Transform.x2 * x0 + m_Transform.y2 * y0;
|
|
|
|
int x2 = m_Transform.x1 * xm + m_Transform.y1 * ym;
|
|
|
|
int y2 = m_Transform.x2 * xm + m_Transform.y2 * ym;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
// H and W must be > 0:
|
2007-09-20 21:06:49 +00:00
|
|
|
if( x2 < x1 )
|
|
|
|
EXCHG( x2, x1 );
|
|
|
|
if( y2 < y1 )
|
|
|
|
EXCHG( y2, y1 );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
BoundaryBox.SetX( x1 );
|
|
|
|
BoundaryBox.SetY( y1 );
|
2007-09-20 21:06:49 +00:00
|
|
|
BoundaryBox.SetWidth( x2 - x1 );
|
|
|
|
BoundaryBox.SetHeight( y2 - y1 );
|
|
|
|
|
|
|
|
BoundaryBox.Offset( m_Pos );
|
|
|
|
return BoundaryBox;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
|
2009-12-21 12:05:36 +00:00
|
|
|
/* Used in undo / redo command:
|
2007-09-20 21:06:49 +00:00
|
|
|
* swap data between this and copyitem
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
EXCHG( m_ChipName, copyitem->m_ChipName );
|
2007-09-20 21:06:49 +00:00
|
|
|
EXCHG( m_Pos, copyitem->m_Pos );
|
|
|
|
EXCHG( m_Multi, copyitem->m_Multi );
|
|
|
|
EXCHG( m_Convert, copyitem->m_Convert );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
TRANSFORM tmp = m_Transform;
|
|
|
|
m_Transform = copyitem->m_Transform;
|
|
|
|
copyitem->m_Transform = tmp;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-10-17 18:45:14 +00:00
|
|
|
m_Fields.swap( copyitem->m_Fields ); // std::vector's swap()
|
2008-10-18 13:42:21 +00:00
|
|
|
|
2008-10-19 10:13:04 +00:00
|
|
|
// Reparent items after copying data
|
2008-10-19 18:31:09 +00:00
|
|
|
// (after swap(), m_Parent member does not point to the right parent):
|
2008-10-18 13:42:21 +00:00
|
|
|
for( int ii = 0; ii < copyitem->GetFieldCount(); ++ii )
|
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
copyitem->GetField( ii )->SetParent( copyitem );
|
2008-10-18 13:42:21 +00:00
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-10-18 13:42:21 +00:00
|
|
|
for( int ii = 0; ii < GetFieldCount(); ++ii )
|
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
GetField( ii )->SetParent( this );
|
2008-10-18 13:42:21 +00:00
|
|
|
}
|
2010-06-17 16:30:10 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
EXCHG( m_PathsAndReferences, copyitem->m_PathsAndReferences );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
void SCH_COMPONENT::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
/* save old text in undo list */
|
|
|
|
if( g_ItemToUndoCopy
|
2010-09-05 17:01:48 +00:00
|
|
|
&& ( g_ItemToUndoCopy->Type() == Type() )
|
|
|
|
&& ( ( m_Flags & IS_NEW ) == 0 ) )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
/* restore old values and save new ones */
|
2008-03-20 01:50:21 +00:00
|
|
|
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
/* save in undo list */
|
2009-07-26 17:16:42 +00:00
|
|
|
frame->SaveCopyInUndoList( this, UR_CHANGED );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
/* restore new values */
|
2008-03-20 01:50:21 +00:00
|
|
|
SwapData( (SCH_COMPONENT*) g_ItemToUndoCopy );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
SAFE_DELETE( g_ItemToUndoCopy );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM::Place( frame, DC );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
/**
|
|
|
|
* Suppress annotation ( i.i IC23 changed to IC? and part reset to 1)
|
2009-12-02 21:44:03 +00:00
|
|
|
* @param aSheet: SCH_SHEET_PATH value: if NULL remove all annotations,
|
2009-04-05 20:49:15 +00:00
|
|
|
* else remove annotation relative to this sheetpath
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_COMPONENT::ClearAnnotation( SCH_SHEET_PATH* aSheet )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-09-18 14:56:05 +00:00
|
|
|
wxString defRef = m_PrefixString;
|
|
|
|
bool KeepMulti = false;
|
|
|
|
LIB_COMPONENT* Entry;
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
wxArrayString reference_fields;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-09-18 14:56:05 +00:00
|
|
|
Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2010-06-24 18:31:43 +00:00
|
|
|
if( Entry && Entry->UnitsLocked() )
|
2008-04-15 19:38:19 +00:00
|
|
|
KeepMulti = true;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
while( defRef.Last() == '?' )
|
|
|
|
defRef.RemoveLast();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
defRef.Append( wxT( "?" ) );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
wxString multi = wxT( "1" );
|
2008-09-20 17:20:40 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
// We cannot remove all annotations: part selection must be kept
|
|
|
|
if( KeepMulti )
|
2008-02-21 12:21:01 +00:00
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
wxString NewHref;
|
|
|
|
wxString path;
|
|
|
|
if( aSheet )
|
2009-04-05 20:49:15 +00:00
|
|
|
path = GetPath( aSheet );
|
|
|
|
for( unsigned int ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-21 06:34:56 +00:00
|
|
|
{
|
2009-10-30 19:26:25 +00:00
|
|
|
// Break hierarchical reference in path, ref and multi selection:
|
2009-04-05 20:49:15 +00:00
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[ii],
|
|
|
|
separators );
|
2008-05-15 11:20:19 +00:00
|
|
|
if( aSheet == NULL || reference_fields[0].Cmp( path ) == 0 )
|
|
|
|
{
|
|
|
|
if( KeepMulti ) // Get and keep part selection
|
|
|
|
multi = reference_fields[2];
|
|
|
|
NewHref = reference_fields[0];
|
|
|
|
NewHref << wxT( " " ) << defRef << wxT( " " ) << multi;
|
|
|
|
m_PathsAndReferences[ii] = NewHref;
|
|
|
|
}
|
2008-04-21 06:34:56 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
2008-05-15 11:20:19 +00:00
|
|
|
else
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
// Empty strings, but does not free memory because a new annotation
|
|
|
|
// will reuse it
|
|
|
|
m_PathsAndReferences.Empty();
|
2008-05-15 11:20:19 +00:00
|
|
|
m_Multi = 1;
|
|
|
|
}
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2008-04-21 06:34:56 +00:00
|
|
|
// These 2 changes do not work in complex hierarchy.
|
|
|
|
// When a clear annotation is made, the calling function must call a
|
|
|
|
// UpdateAllScreenReferences for the active sheet.
|
2008-05-15 11:20:19 +00:00
|
|
|
// But this call cannot made here.
|
2008-10-06 05:44:29 +00:00
|
|
|
m_Fields[REFERENCE].m_Text = defRef; //for drawing.
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/******************************************************************/
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/* Compute the new matrix transform for a schematic component
|
2007-09-20 21:06:49 +00:00
|
|
|
* in order to have the requested transform (type_rotate = rot, mirror..)
|
|
|
|
* which is applied to the initial transform.
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
/*****************************************************************/
|
2010-01-13 21:15:54 +00:00
|
|
|
void SCH_COMPONENT::SetOrientation( int aOrientation )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
TRANSFORM temp = TRANSFORM();
|
|
|
|
bool Transform = false;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
switch( aOrientation )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
|
|
|
case CMP_ORIENT_0:
|
|
|
|
case CMP_NORMAL: /* Position Initiale */
|
2010-10-20 20:24:26 +00:00
|
|
|
m_Transform.x1 = 1;
|
|
|
|
m_Transform.y2 = -1;
|
|
|
|
m_Transform.x2 = m_Transform.y1 = 0;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ROTATE_CLOCKWISE: /* Rotate + */
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = temp.y2 = 0;
|
|
|
|
temp.y1 = 1;
|
|
|
|
temp.x2 = -1;
|
|
|
|
Transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ROTATE_COUNTERCLOCKWISE: /* Rotate - */
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = temp.y2 = 0;
|
|
|
|
temp.y1 = -1;
|
|
|
|
temp.x2 = 1;
|
|
|
|
Transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case CMP_MIRROR_Y: /* MirrorY */
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = -1;
|
|
|
|
temp.y2 = 1;
|
|
|
|
temp.y1 = temp.x2 = 0;
|
|
|
|
Transform = true;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case CMP_MIRROR_X: /* MirrorX */
|
2010-10-20 20:24:26 +00:00
|
|
|
temp.x1 = 1;
|
|
|
|
temp.y2 = -1;
|
|
|
|
temp.y1 = temp.x2 = 0;
|
|
|
|
Transform = TRUE;
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ORIENT_90:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ORIENT_180:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CMP_ORIENT_270:
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_ROTATE_CLOCKWISE );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_0 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_0 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_0 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_90 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_90 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_90 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_90 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_180 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_180 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_180 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_180 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_270 + CMP_MIRROR_X ):
|
|
|
|
SetOrientation( CMP_ORIENT_270 );
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
case ( CMP_ORIENT_270 + CMP_MIRROR_Y ):
|
|
|
|
SetOrientation( CMP_ORIENT_270 );
|
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Transform = FALSE;
|
2009-07-27 14:32:40 +00:00
|
|
|
wxMessageBox( wxT( "SetRotateMiroir() error: ill value" ) );
|
2007-09-20 21:06:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Transform )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
|
|
|
/* The new matrix transform is the old matrix transform modified by the
|
2009-04-05 20:49:15 +00:00
|
|
|
* requested transformation, which is the TempMat transform (rot,
|
|
|
|
* mirror ..) in order to have (in term of matrix transform):
|
2008-04-12 18:39:20 +00:00
|
|
|
* transform coord = new_m_Transform * coord
|
2009-04-05 20:49:15 +00:00
|
|
|
* where transform coord is the coord modified by new_m_Transform from
|
|
|
|
* the initial value coord.
|
|
|
|
* new_m_Transform is computed (from old_m_Transform and TempMat) to
|
|
|
|
* have:
|
2008-04-12 18:39:20 +00:00
|
|
|
* transform coord = old_m_Transform * coord * TempMat
|
|
|
|
*/
|
2010-10-20 20:24:26 +00:00
|
|
|
TRANSFORM newTransform;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-10-20 20:24:26 +00:00
|
|
|
newTransform.x1 = m_Transform.x1 * temp.x1 + m_Transform.x2 * temp.y1;
|
|
|
|
newTransform.y1 = m_Transform.y1 * temp.x1 + m_Transform.y2 * temp.y1;
|
|
|
|
newTransform.x2 = m_Transform.x1 * temp.x2 + m_Transform.x2 * temp.y2;
|
|
|
|
newTransform.y2 = m_Transform.y1 * temp.x2 + m_Transform.y2 * temp.y2;
|
|
|
|
m_Transform = newTransform;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
/** function GetOrientation()
|
2009-04-09 11:34:41 +00:00
|
|
|
* Used to display component orientation (in dialog editor or info)
|
|
|
|
* @return the orientation and mirror
|
|
|
|
* Note: Because there are different ways to have a given orientation/mirror,
|
2009-12-02 21:44:03 +00:00
|
|
|
* the orientation/mirror is not necessary what the used does
|
2009-04-09 11:34:41 +00:00
|
|
|
* (example : a mirrorX then a mirrorY give no mirror but rotate the component).
|
|
|
|
* So this function find a rotation and a mirror value
|
2010-01-13 21:15:54 +00:00
|
|
|
* ( CMP_MIRROR_X because this is the first mirror option tested)
|
2009-04-09 11:34:41 +00:00
|
|
|
* but can differs from the orientation made by an user
|
2010-01-13 21:15:54 +00:00
|
|
|
* ( a CMP_MIRROR_Y is find as a CMP_MIRROR_X + orientation 180, because they
|
2009-12-02 21:44:03 +00:00
|
|
|
* are equivalent)
|
2009-04-09 11:34:41 +00:00
|
|
|
*
|
2009-12-02 21:44:03 +00:00
|
|
|
*/
|
2010-01-13 21:15:54 +00:00
|
|
|
int SCH_COMPONENT::GetOrientation()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
int type_rotate = CMP_ORIENT_0;
|
2010-10-20 20:24:26 +00:00
|
|
|
TRANSFORM transform;
|
2010-09-05 17:01:48 +00:00
|
|
|
int ii;
|
2009-04-17 08:51:02 +00:00
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
#define ROTATE_VALUES_COUNT 12
|
2009-12-02 21:44:03 +00:00
|
|
|
|
|
|
|
// list of all possibilities, but only the first 8 are actually used
|
|
|
|
int rotate_value[ROTATE_VALUES_COUNT] =
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
CMP_ORIENT_0, CMP_ORIENT_90, CMP_ORIENT_180,
|
|
|
|
CMP_ORIENT_270,
|
|
|
|
CMP_MIRROR_X + CMP_ORIENT_0, CMP_MIRROR_X + CMP_ORIENT_90,
|
2010-01-13 21:15:54 +00:00
|
|
|
CMP_MIRROR_X + CMP_ORIENT_180, CMP_MIRROR_X + CMP_ORIENT_270,
|
2010-09-05 17:01:48 +00:00
|
|
|
CMP_MIRROR_Y + CMP_ORIENT_0, CMP_MIRROR_Y + CMP_ORIENT_90,
|
2010-01-13 21:15:54 +00:00
|
|
|
CMP_MIRROR_Y + CMP_ORIENT_180, CMP_MIRROR_Y + CMP_ORIENT_270
|
2009-04-09 11:34:41 +00:00
|
|
|
};
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
// Try to find the current transform option:
|
2010-10-20 20:24:26 +00:00
|
|
|
transform = m_Transform;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
for( ii = 0; ii < ROTATE_VALUES_COUNT; ii++ )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-04-09 11:34:41 +00:00
|
|
|
type_rotate = rotate_value[ii];
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( type_rotate );
|
2010-10-20 20:24:26 +00:00
|
|
|
|
|
|
|
if( transform == m_Transform )
|
2009-04-09 11:34:41 +00:00
|
|
|
return type_rotate;
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
// Error: orientation not found in list (should not happen)
|
2010-09-05 17:01:48 +00:00
|
|
|
wxMessageBox( wxT( "Component orientation matrix internal error" ) );
|
2010-10-20 20:24:26 +00:00
|
|
|
m_Transform = transform;
|
|
|
|
|
2009-04-09 11:34:41 +00:00
|
|
|
return CMP_NORMAL;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
2009-10-30 19:26:25 +00:00
|
|
|
* Returns the coordinated point, depending on the orientation of the
|
|
|
|
* component (rotation, mirror).
|
|
|
|
* The coordinates are always relative to the anchor position of the component.
|
2007-09-20 21:06:49 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
wxPoint SCH_COMPONENT::GetScreenCoord( const wxPoint& coord )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2010-10-20 20:24:26 +00:00
|
|
|
return m_Transform.TransformCoordinate( coord );
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
#if defined(DEBUG)
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
2008-02-21 12:21:01 +00:00
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
2007-09-20 21:06:49 +00:00
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
2008-03-20 01:50:21 +00:00
|
|
|
void SCH_COMPONENT::Show( int nestLevel, std::ostream& os )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
// for now, make it look like XML:
|
2009-12-02 21:44:03 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
|
2010-07-19 15:40:54 +00:00
|
|
|
<< " ref=\"" << CONV_TO_UTF8( ReturnFieldName( 0 ) )
|
2009-12-02 21:44:03 +00:00
|
|
|
<< '"' << " chipName=\""
|
2010-09-05 17:01:48 +00:00
|
|
|
<< CONV_TO_UTF8( m_ChipName ) << '"' << m_Pos
|
2009-12-02 21:44:03 +00:00
|
|
|
<< " layer=\"" << m_Layer
|
2010-08-03 05:11:05 +00:00
|
|
|
<< '"' << ">\n";
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
// skip the reference, it's been output already.
|
2009-04-05 20:49:15 +00:00
|
|
|
for( int i = 1; i < GetFieldCount(); ++i )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2008-10-06 05:44:29 +00:00
|
|
|
wxString value = GetField( i )->m_Text;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
if( !value.IsEmpty() )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
NestedSpace( nestLevel + 1, os ) << "<field" << " name=\""
|
2010-07-19 15:40:54 +00:00
|
|
|
<< CONV_TO_UTF8( ReturnFieldName( i ) )
|
2010-09-05 17:01:48 +00:00
|
|
|
<< '"' << " value=\""
|
2010-07-19 15:40:54 +00:00
|
|
|
<< CONV_TO_UTF8( value ) << "\"/>\n";
|
2007-09-20 21:06:49 +00:00
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-19 15:40:54 +00:00
|
|
|
NestedSpace( nestLevel, os ) << "</" << CONV_TO_UTF8( GetClass().Lower() )
|
2009-12-02 21:44:03 +00:00
|
|
|
<< ">\n";
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2007-09-20 21:06:49 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
bool SCH_COMPONENT::Save( FILE* f ) const
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
int ii;
|
2008-04-15 19:38:19 +00:00
|
|
|
char Name1[256], Name2[256];
|
|
|
|
wxArrayString reference_fields;
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
static wxString delimiters( wxT( " " ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
|
|
|
|
//this is redundant with the AR entries below, but it makes the
|
|
|
|
//files backwards-compatible.
|
2008-04-15 19:38:19 +00:00
|
|
|
if( m_PathsAndReferences.GetCount() > 0 )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[0],
|
|
|
|
delimiters );
|
|
|
|
strncpy( Name1, CONV_TO_UTF8( reference_fields[1] ), sizeof( Name1 ) );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
2008-04-12 18:39:20 +00:00
|
|
|
else
|
|
|
|
{
|
2008-10-18 13:42:21 +00:00
|
|
|
if( GetField( REFERENCE )->m_Text.IsEmpty() )
|
2009-04-05 20:49:15 +00:00
|
|
|
strncpy( Name1, CONV_TO_UTF8( m_PrefixString ), sizeof( Name1 ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
strncpy( Name1, CONV_TO_UTF8( GetField( REFERENCE )->m_Text ),
|
2010-09-05 17:01:48 +00:00
|
|
|
sizeof( Name1 ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
for( ii = 0; ii < (int) strlen( Name1 ); ii++ )
|
|
|
|
{
|
2009-09-01 10:26:43 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2010-09-05 17:01:48 +00:00
|
|
|
if( Name1[ii] == ' ' )
|
2009-09-01 10:26:43 +00:00
|
|
|
#else
|
2010-09-05 17:01:48 +00:00
|
|
|
if( Name1[ii] <= ' ' )
|
2009-09-01 10:26:43 +00:00
|
|
|
#endif
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
Name1[ii] = '~';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_ChipName.IsEmpty() )
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
strncpy( Name2, CONV_TO_UTF8( m_ChipName ), sizeof( Name2 ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
for( ii = 0; ii < (int) strlen( Name2 ); ii++ )
|
2009-09-01 10:26:43 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-09-01 10:26:43 +00:00
|
|
|
if( Name2[ii] == ' ' )
|
|
|
|
#else
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
if( Name2[ii] <= ' ' )
|
2009-09-01 10:26:43 +00:00
|
|
|
#endif
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
Name2[ii] = '~';
|
|
|
|
}
|
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
strncpy( Name2, NULL_STRING, sizeof( Name2 ) );
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
if( fprintf( f, "$Comp\n" ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
|
|
|
if( fprintf( f, "L %s %s\n", Name2, Name1 ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-10-30 19:26:25 +00:00
|
|
|
/* Generate unit number, convert and time stamp*/
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fprintf( f, "U %d %d %8.8lX\n", m_Multi, m_Convert,
|
|
|
|
m_TimeStamp ) == EOF )
|
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
/* Save the position */
|
2008-04-12 18:39:20 +00:00
|
|
|
if( fprintf( f, "P %d %d\n", m_Pos.x, m_Pos.y ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
/* If this is a complex hierarchy; save hierarchical references.
|
2008-04-16 08:40:31 +00:00
|
|
|
* but for simple hierarchies it is not necessary.
|
|
|
|
* the reference inf is already saved
|
2009-10-30 19:26:25 +00:00
|
|
|
* this is useful for old eeschema version compatibility
|
2008-04-15 19:38:19 +00:00
|
|
|
*/
|
|
|
|
if( m_PathsAndReferences.GetCount() > 1 )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
for( unsigned int ii = 0; ii < m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
/*format:
|
|
|
|
* AR Path="/140/2" Ref="C99" Part="1"
|
|
|
|
* where 140 is the uid of the containing sheet
|
|
|
|
* and 2 is the timestamp of this component.
|
|
|
|
* (timestamps are actually 8 hex chars)
|
|
|
|
* Ref is the conventional component reference for this 'path'
|
|
|
|
* Part is the conventional component part selection for this 'path'
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[ii],
|
|
|
|
delimiters );
|
2008-04-15 19:38:19 +00:00
|
|
|
if( fprintf( f, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
|
2010-09-05 17:01:48 +00:00
|
|
|
CONV_TO_UTF8( reference_fields[0] ),
|
|
|
|
CONV_TO_UTF8( reference_fields[1] ),
|
|
|
|
CONV_TO_UTF8( reference_fields[2] ) ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// update the ugly field index, which I would like to see go away someday soon.
|
2010-09-05 17:01:48 +00:00
|
|
|
for( unsigned i = 0; i<m_Fields.size(); ++i )
|
2008-04-12 18:39:20 +00:00
|
|
|
{
|
2010-06-17 16:30:10 +00:00
|
|
|
SCH_FIELD* fld = GetField( i );
|
|
|
|
fld->m_FieldId = i; // we don't need field Ids, please be gone.
|
|
|
|
}
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// Fixed fields:
|
|
|
|
// Save fixed fields which are non blank.
|
2010-09-05 17:01:48 +00:00
|
|
|
for( unsigned i = 0; i<MANDATORY_FIELDS; ++i )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD* fld = GetField( i );
|
|
|
|
if( !fld->m_Text.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( !fld->Save( f ) )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2008-10-06 05:44:29 +00:00
|
|
|
|
2010-06-17 16:30:10 +00:00
|
|
|
// User defined fields:
|
|
|
|
// The *policy* about which user defined fields are part of a symbol is now
|
|
|
|
// only in the dialog editors. No policy should be enforced here, simply
|
|
|
|
// save all the user defined fields, they are present because a dialog editor
|
|
|
|
// thought they should be. If you disagree, go fix the dialog editors.
|
2010-09-05 17:01:48 +00:00
|
|
|
for( unsigned i = MANDATORY_FIELDS; i<m_Fields.size(); ++i )
|
2010-06-17 16:30:10 +00:00
|
|
|
{
|
|
|
|
SCH_FIELD* fld = GetField( i );
|
|
|
|
if( !fld->Save( f ) )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/* Unit number, position, box ( old standard ) */
|
2008-04-12 18:39:20 +00:00
|
|
|
if( fprintf( f, "\t%-4d %-4d %-4d\n", m_Multi, m_Pos.x, m_Pos.y ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
|
|
|
if( fprintf( f, "\t%-4d %-4d %-4d %-4d\n",
|
2010-10-20 20:24:26 +00:00
|
|
|
m_Transform.x1, m_Transform.y1, m_Transform.x2, m_Transform.y2 ) == EOF )
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( fprintf( f, "$EndComp\n" ) == EOF )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-30 18:06:12 +00:00
|
|
|
/**
|
|
|
|
* Function GetBoundingBox
|
|
|
|
* returns the orthogonal, bounding box of this object for display purposes.
|
|
|
|
* This box should be an enclosing perimeter for visible components of this
|
|
|
|
* object, and the units should be in the pcb or schematic coordinate system.
|
|
|
|
* It is OK to overestimate the size by a few counts.
|
|
|
|
*/
|
2008-04-15 19:38:19 +00:00
|
|
|
EDA_Rect SCH_COMPONENT::GetBoundingBox()
|
|
|
|
{
|
|
|
|
const int PADDING = 40;
|
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
// This gives a reasonable approximation (but some things are missing so...)
|
|
|
|
EDA_Rect bbox = GetBoundaryBox();
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
// Include BoundingBoxes of fields
|
2008-10-06 05:44:29 +00:00
|
|
|
for( int ii = 0; ii < GetFieldCount(); ii++ )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
if( !GetField( ii )->IsVisible() )
|
2009-12-30 18:06:12 +00:00
|
|
|
continue;
|
2008-10-18 13:42:21 +00:00
|
|
|
bbox.Merge( GetField( ii )->GetBoundaryBox() );
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ... add padding
|
2009-12-30 18:06:12 +00:00
|
|
|
bbox.Inflate( PADDING );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2008-09-20 17:20:40 +00:00
|
|
|
return bbox;
|
2008-04-12 18:39:20 +00:00
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2009-04-17 08:51:02 +00:00
|
|
|
void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-02-17 13:22:25 +00:00
|
|
|
// search for the component in lib
|
|
|
|
// Entry and root_component can differ if Entry is an alias
|
2010-10-25 15:43:42 +00:00
|
|
|
LIB_ALIAS* alias = CMP_LIBRARY::FindLibraryEntry( m_ChipName );
|
2010-02-17 13:22:25 +00:00
|
|
|
LIB_COMPONENT* root_component = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-10-25 15:43:42 +00:00
|
|
|
if( (alias == NULL) || (root_component == NULL) )
|
2009-10-14 19:43:31 +00:00
|
|
|
return;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
wxString msg;
|
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
frame->ClearMsgPanel();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-10-14 19:43:31 +00:00
|
|
|
frame->AppendMsgPanel( _( "Reference" ),
|
2010-09-05 17:01:48 +00:00
|
|
|
GetRef( ( (WinEDA_SchematicFrame*) frame )->GetSheet() ),
|
2009-10-14 19:43:31 +00:00
|
|
|
DARKCYAN );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-10-04 18:54:14 +00:00
|
|
|
if( root_component->IsPower() )
|
2009-10-14 19:43:31 +00:00
|
|
|
msg = _( "Power symbol" );
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
2009-10-14 19:43:31 +00:00
|
|
|
msg = _( "Name" );
|
|
|
|
frame->AppendMsgPanel( msg, GetField( VALUE )->m_Text, DARKCYAN );
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-02-17 13:22:25 +00:00
|
|
|
// Display component reference in library and library
|
|
|
|
frame->AppendMsgPanel( _( "Component" ), m_ChipName, BROWN );
|
2010-10-25 15:43:42 +00:00
|
|
|
if( alias->GetName() != root_component->GetName() )
|
2010-02-17 13:22:25 +00:00
|
|
|
frame->AppendMsgPanel( _( "Alias of" ), root_component->GetName(), BROWN );
|
2010-10-25 15:43:42 +00:00
|
|
|
frame->AppendMsgPanel( _( "Library" ), alias->GetLibraryName(), BROWN );
|
2009-09-18 14:56:05 +00:00
|
|
|
|
2010-02-17 13:22:25 +00:00
|
|
|
// Display description of the component, and keywords found in lib
|
2010-10-25 15:43:42 +00:00
|
|
|
frame->AppendMsgPanel( _( "Description" ), alias->GetDescription(), DARKCYAN );
|
|
|
|
frame->AppendMsgPanel( _( "Key words" ), alias->GetKeyWords(), DARKCYAN );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2009-07-27 14:32:40 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-07-27 14:32:40 +00:00
|
|
|
/** virtual function Mirror_Y
|
|
|
|
* mirror item relative to an Y axis
|
|
|
|
* @param aYaxis_position = the y axis position
|
|
|
|
*/
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_COMPONENT::Mirror_Y( int aYaxis_position )
|
2009-07-27 14:32:40 +00:00
|
|
|
{
|
|
|
|
int dx = m_Pos.x;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-01-13 21:15:54 +00:00
|
|
|
SetOrientation( CMP_MIRROR_Y );
|
2009-07-27 14:32:40 +00:00
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
dx -= m_Pos.x; // dx,0 is the move vector for this transform
|
|
|
|
|
|
|
|
for( int ii = 0; ii < GetFieldCount(); ii++ )
|
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
/* move the fields to the new position because the component itself
|
|
|
|
* has moved */
|
2009-07-27 14:32:40 +00:00
|
|
|
GetField( ii )->m_Pos.x -= dx;
|
|
|
|
}
|
|
|
|
}
|
2010-03-16 18:22:59 +00:00
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
/** virtual function Mirror_X
|
|
|
|
* mirror item relative to an X axis
|
|
|
|
* @param aXaxis_position = the x axis position
|
|
|
|
*/
|
|
|
|
void SCH_COMPONENT::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
int dy = m_Pos.y;
|
|
|
|
|
|
|
|
SetOrientation( CMP_MIRROR_X );
|
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
dy -= m_Pos.y; // dy,0 is the move vector for this transform
|
|
|
|
|
|
|
|
for( int ii = 0; ii < GetFieldCount(); ii++ )
|
|
|
|
{
|
|
|
|
/* move the fields to the new position because the component itself
|
|
|
|
* has moved */
|
|
|
|
GetField( ii )->m_Pos.y -= dy;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_COMPONENT::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
wxPoint prev = m_Pos;
|
|
|
|
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
|
|
|
|
//SetOrientation( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
SetOrientation( CMP_ROTATE_CLOCKWISE );
|
|
|
|
|
|
|
|
for( int ii = 0; ii < GetFieldCount(); ii++ )
|
|
|
|
{
|
|
|
|
/* move the fields to the new position because the component itself
|
|
|
|
* has moved */
|
|
|
|
GetField( ii )->m_Pos.x -= prev.x - m_Pos.x;
|
|
|
|
GetField( ii )->m_Pos.y -= prev.y - m_Pos.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint * aFindLocation )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2010-04-01 13:15:48 +00:00
|
|
|
// Search reference.
|
|
|
|
// reference is a special field because a part identifier is added
|
|
|
|
// in multi parts per package
|
2010-10-20 19:43:58 +00:00
|
|
|
// the .m_AddExtraText of the field must be set to add this identifier:
|
2010-04-01 13:15:48 +00:00
|
|
|
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2010-04-01 13:15:48 +00:00
|
|
|
if( Entry && Entry->GetPartCount() > 1 )
|
2010-09-05 17:01:48 +00:00
|
|
|
GetField( REFERENCE )->m_AddExtraText = true;
|
2010-04-01 13:15:48 +00:00
|
|
|
else
|
|
|
|
GetField( REFERENCE )->m_AddExtraText = false;
|
2010-03-16 18:22:59 +00:00
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( GetField( REFERENCE )->Matches( aSearchData, aAuxData, aFindLocation ) )
|
2010-03-16 18:22:59 +00:00
|
|
|
return true;
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
if( GetField( VALUE )->Matches( aSearchData, aAuxData, aFindLocation ) )
|
2010-04-01 13:15:48 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_FIELDS ) )
|
|
|
|
return false;
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
for( size_t i = VALUE + 1; i < m_Fields.size(); i++ )
|
2010-03-16 18:22:59 +00:00
|
|
|
{
|
2010-10-20 19:43:58 +00:00
|
|
|
if( GetField( i )->Matches( aSearchData, aAuxData, aFindLocation ) )
|
2010-03-16 18:22:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-20 19:43:58 +00:00
|
|
|
// Search for a match in pin name or pin number.
|
|
|
|
// @TODO: see if the Matches method must be made in LIB_PIN.
|
|
|
|
// when Matches method will be used in Libedit, this is the best
|
|
|
|
// Currently, Pins are tested here.
|
|
|
|
if( !( aSearchData.GetFlags() & FR_SEARCH_ALL_PINS ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if( Entry )
|
|
|
|
{
|
|
|
|
LIB_PIN_LIST pinList;
|
|
|
|
Entry->GetPins( pinList, m_Multi, m_Convert );
|
|
|
|
// Search for a match in pinList
|
|
|
|
for( unsigned ii = 0; ii < pinList.size(); ii ++ )
|
|
|
|
{
|
|
|
|
LIB_PIN* pin = pinList[ii];
|
|
|
|
wxString pinNum;
|
|
|
|
pin->ReturnPinStringNum( pinNum );
|
|
|
|
if( SCH_ITEM::Matches(pin->m_PinName, aSearchData ) ||
|
|
|
|
SCH_ITEM::Matches(pinNum, aSearchData ) )
|
|
|
|
{
|
|
|
|
if( aFindLocation )
|
|
|
|
{
|
|
|
|
wxPoint pinpos = pin->m_Pos;
|
2010-10-20 20:24:26 +00:00
|
|
|
pinpos = m_Transform.TransformCoordinate( pinpos );
|
2010-10-20 19:43:58 +00:00
|
|
|
*aFindLocation = pinpos + m_Pos;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-16 18:22:59 +00:00
|
|
|
return false;
|
|
|
|
}
|