2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************/
|
2008-04-15 19:38:19 +00:00
|
|
|
|
/* component_class.cpp : handle the class SCH_COMPONENT */
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
#include "program.h"
|
|
|
|
|
#include "libcmp.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"
|
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
#include <wx/arrimpl.cpp>
|
2008-04-15 19:38:19 +00:00
|
|
|
|
#include <wx/tokenzr.h>
|
2008-02-27 19:38:16 +00:00
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
WX_DEFINE_OBJARRAY( ArrayOfSheetLists );
|
2008-02-27 19:38:16 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
/***************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
/* class SCH_COMPONENT */
|
2007-09-20 21:06:49 +00:00
|
|
|
|
/***************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
|
/** Function AddHierarchicalReference
|
|
|
|
|
* Add a full hierachical reference (path + local reference)
|
2008-04-16 08:40:31 +00:00
|
|
|
|
* @param aPath = hierarchical path (/<sheet timestamp>/component timestamp> like /05678E50/A23EF560)
|
|
|
|
|
* @param aRef = local reference like C45, R56
|
|
|
|
|
* @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)
|
|
|
|
|
for( unsigned ii = 0; ii<m_PathsAndReferences.GetCount(); ii++ )
|
|
|
|
|
{
|
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
|
h_path = tokenizer.GetNextToken();
|
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;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/****************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
const wxString& ReturnDefaultFieldName( int aFieldNdx )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/****************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
|
|
/* Return the default field name from its index (REFERENCE, VALUE ..)
|
|
|
|
|
* FieldDefaultNameList is not static, because we want the text translation
|
|
|
|
|
* for I18n
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-09-21 04:40:12 +00:00
|
|
|
|
// avoid unnecessarily copying wxStrings at runtime.
|
2007-09-20 21:06:49 +00:00
|
|
|
|
static const wxString FieldDefaultNameList[] = {
|
2008-02-21 12:21:01 +00:00
|
|
|
|
_( "Ref" ), /* Reference of part, i.e. "IC21" */
|
|
|
|
|
_( "Value" ), /* Value of part, i.e. "3.3K" */
|
|
|
|
|
_( "Footprint" ), /* Footprint, used by cvpcb or pcbnew, i.e. "16DIP300" */
|
|
|
|
|
_( "Sheet" ), /* for components which are a schematic file, schematic file name, i.e. "cnt16.sch" */
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "1" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "2" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "3" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "4" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "5" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "6" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "7" ),
|
|
|
|
|
wxString( _( "Field" ) ) + wxT( "8" ),
|
2007-09-21 04:40:12 +00:00
|
|
|
|
wxT( "badFieldNdx!" ) // error, and "sentinel" value
|
2007-09-20 21:06:49 +00:00
|
|
|
|
};
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
if( (unsigned) aFieldNdx > FIELD8 ) // catches < 0 also
|
2008-02-21 12:21:01 +00:00
|
|
|
|
aFieldNdx = FIELD8 + 1; // return the sentinel text
|
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
return FieldDefaultNameList[aFieldNdx];
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
const wxString& SCH_COMPONENT::ReturnFieldName( int aFieldNdx ) const
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/****************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
|
|
|
|
/* Return the Field name from its index (REFERENCE, VALUE ..)
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
|
// avoid unnecessarily copying wxStrings.
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
if( aFieldNdx < FIELD1 || m_Field[aFieldNdx].m_Name.IsEmpty() )
|
|
|
|
|
return ReturnDefaultFieldName( aFieldNdx );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
return m_Field[aFieldNdx].m_Name;
|
|
|
|
|
}
|
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
wxString SCH_COMPONENT::GetPath( DrawSheetPath* sheet )
|
2008-02-21 12:21:01 +00:00
|
|
|
|
/****************************************************************/
|
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
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
const wxString SCH_COMPONENT::GetRef( DrawSheetPath* sheet )
|
2008-02-21 12:21:01 +00:00
|
|
|
|
/********************************************************************/
|
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
|
|
|
|
|
2008-04-15 19:38:19 +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
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
h_ref = tokenizer.GetNextToken();
|
|
|
|
|
|
|
|
|
|
//printf("GetRef hpath: %s\n",CONV_TO_UTF8(m_PathsAndReferences[ii]));
|
|
|
|
|
return h_ref;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if it was not found in m_Paths array, then see if it is in
|
|
|
|
|
// 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.
|
|
|
|
|
if( !m_Field[REFERENCE].m_Text.IsEmpty() )
|
|
|
|
|
{
|
|
|
|
|
SetRef( sheet, m_Field[REFERENCE].m_Text );
|
|
|
|
|
return m_Field[REFERENCE].m_Text;
|
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
2008-04-12 18:39:20 +00:00
|
|
|
|
void SCH_COMPONENT::SetRef( DrawSheetPath* sheet, const wxString& ref )
|
2008-02-21 12:21:01 +00:00
|
|
|
|
/***********************************************************************/
|
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
|
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
|
//check to see if it is already there before inserting it
|
2008-04-15 19:38:19 +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
|
|
|
|
{
|
|
|
|
|
//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
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
if( m_Field[REFERENCE].m_Text.IsEmpty()
|
|
|
|
|
|| ( abs( m_Field[REFERENCE].m_Pos.x - m_Pos.x ) +
|
2008-04-14 19:22:48 +00:00
|
|
|
|
abs( m_Field[REFERENCE].m_Pos.y - m_Pos.y ) > 10000) )
|
2008-02-21 12:21:01 +00:00
|
|
|
|
{
|
|
|
|
|
//move it to a reasonable position..
|
|
|
|
|
m_Field[REFERENCE].m_Pos = m_Pos;
|
|
|
|
|
m_Field[REFERENCE].m_Pos.x += 50; //a slight offset..
|
|
|
|
|
m_Field[REFERENCE].m_Pos.y += 50;
|
|
|
|
|
}
|
|
|
|
|
m_Field[REFERENCE].m_Text = ref; //for drawing.
|
2008-02-12 21:12:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2008-04-16 08:40:31 +00:00
|
|
|
|
/***********************************************************/
|
|
|
|
|
int SCH_COMPONENT::GetUnitSelection( DrawSheetPath* aSheet )
|
|
|
|
|
/***********************************************************/
|
|
|
|
|
|
|
|
|
|
//returns the unit selection, for the given sheet path.
|
|
|
|
|
{
|
|
|
|
|
wxString path = GetPath( aSheet );
|
|
|
|
|
wxString h_path, h_multi;
|
|
|
|
|
wxStringTokenizer tokenizer;
|
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii<m_PathsAndReferences.GetCount(); ii++ )
|
|
|
|
|
{
|
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
|
h_path = tokenizer.GetNextToken();
|
|
|
|
|
if( h_path.Cmp( path ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
tokenizer.GetNextToken(); // Skip reference
|
|
|
|
|
h_multi = tokenizer.GetNextToken();
|
|
|
|
|
long imulti = 1;
|
|
|
|
|
h_multi.ToLong( &imulti );
|
|
|
|
|
return imulti;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//if it was not found in m_Paths array, then use m_Multi.
|
|
|
|
|
// this will happen if we load a version 1 schematic file.
|
|
|
|
|
return m_Multi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
void SCH_COMPONENT::SetUnitSelection( DrawSheetPath* aSheet, int aUnitSelection )
|
|
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
|
|
//Set the unit selection, for the given sheet path.
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
for( unsigned ii = 0; ii<m_PathsAndReferences.GetCount(); ii++ )
|
|
|
|
|
{
|
|
|
|
|
tokenizer.SetString( m_PathsAndReferences[ii], separators );
|
|
|
|
|
h_path = tokenizer.GetNextToken();
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-04-14 19:22:48 +00:00
|
|
|
|
/******************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
const wxString& SCH_COMPONENT::GetFieldValue( int aFieldNdx ) const
|
2008-04-14 19:22:48 +00:00
|
|
|
|
/******************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
{
|
2008-02-21 12:21:01 +00:00
|
|
|
|
// avoid unnecessarily copying wxStrings.
|
|
|
|
|
static const wxString myEmpty = wxEmptyString;
|
|
|
|
|
|
|
|
|
|
if( (unsigned) aFieldNdx > FIELD8 || m_Field[aFieldNdx].m_Text.IsEmpty() )
|
2007-09-20 21:06:49 +00:00
|
|
|
|
return myEmpty;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
return m_Field[aFieldNdx].m_Text;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
|
/*******************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
SCH_COMPONENT::SCH_COMPONENT( const wxPoint& aPos ) :
|
2008-04-12 18:39:20 +00:00
|
|
|
|
SCH_ITEM( NULL, TYPE_SCH_COMPONENT )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/*******************************************************************/
|
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
|
int ii;
|
|
|
|
|
|
|
|
|
|
m_Multi = 0; /* In multi unit chip - which unit to draw. */
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2008-03-20 01:50:21 +00:00
|
|
|
|
m_Pos = aPos;
|
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
|
m_Convert = 0; /* De Morgan Handling */
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
/* The rotation/mirror transformation matrix. pos normal*/
|
|
|
|
|
m_Transform[0][0] = 1;
|
|
|
|
|
m_Transform[0][1] = 0;
|
|
|
|
|
m_Transform[1][0] = 0;
|
|
|
|
|
m_Transform[1][1] = -1;
|
|
|
|
|
|
|
|
|
|
/* initialisation des Fields */
|
|
|
|
|
for( ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
m_Field[ii].m_Pos = m_Pos;
|
|
|
|
|
m_Field[ii].SetLayer( LAYER_FIELDS );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
m_Field[ii].m_FieldId = REFERENCE + ii;
|
|
|
|
|
m_Field[ii].m_Parent = this;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
m_Field[VALUE].SetLayer( LAYER_VALUEPART );
|
|
|
|
|
m_Field[REFERENCE].SetLayer( LAYER_REFERENCEPART );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
m_PrefixString = wxString( _( "U" ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-21 12:21:01 +00:00
|
|
|
|
/************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
EDA_Rect SCH_COMPONENT::GetBoundaryBox() const
|
2008-02-21 12:21:01 +00:00
|
|
|
|
/************************************************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
|
EDA_LibComponentStruct* Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
|
|
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
|
int x0, xm, y0, ym;
|
|
|
|
|
|
|
|
|
|
/* Get the basic Boundary box */
|
|
|
|
|
if( Entry )
|
|
|
|
|
{
|
|
|
|
|
BoundaryBox = Entry->GetBoundaryBox( m_Multi, m_Convert );
|
|
|
|
|
x0 = BoundaryBox.GetX(); xm = BoundaryBox.GetRight();
|
|
|
|
|
|
|
|
|
|
// 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 ...)*/
|
|
|
|
|
int x1 = m_Transform[0][0] * x0 + m_Transform[0][1] * y0;
|
|
|
|
|
|
|
|
|
|
int y1 = m_Transform[1][0] * x0 + m_Transform[1][1] * y0;
|
|
|
|
|
|
|
|
|
|
int x2 = m_Transform[0][0] * xm + m_Transform[0][1] * ym;
|
|
|
|
|
|
|
|
|
|
int y2 = m_Transform[1][0] * xm + m_Transform[1][1] * ym;
|
|
|
|
|
|
|
|
|
|
// H and W must be > 0 for wxRect:
|
|
|
|
|
if( x2 < x1 )
|
|
|
|
|
EXCHG( x2, x1 );
|
|
|
|
|
if( y2 < y1 )
|
|
|
|
|
EXCHG( y2, y1 );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
BoundaryBox.SetX( x1 ); BoundaryBox.SetY( y1 );
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/**************************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
void SCH_COMPONENT::SwapData( SCH_COMPONENT* copyitem )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/**************************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/* Used if undo / redo command:
|
2007-09-20 21:06:49 +00:00
|
|
|
|
* swap data between this and 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 );
|
|
|
|
|
EXCHG( m_Transform[0][0], copyitem->m_Transform[0][0] );
|
|
|
|
|
EXCHG( m_Transform[0][1], copyitem->m_Transform[0][1] );
|
|
|
|
|
EXCHG( m_Transform[1][0], copyitem->m_Transform[1][0] );
|
|
|
|
|
EXCHG( m_Transform[1][1], copyitem->m_Transform[1][1] );
|
|
|
|
|
for( int ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
|
|
|
|
|
{
|
|
|
|
|
m_Field[ii].SwapData( ©item->m_Field[ii] );
|
|
|
|
|
}
|
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
|
|
|
|
|
&& ( g_ItemToUndoCopy->Type() == Type() )
|
|
|
|
|
&& ( (m_Flags & IS_NEW) == 0 ) )
|
|
|
|
|
{
|
|
|
|
|
/* 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 */
|
2008-04-17 16:25:29 +00:00
|
|
|
|
frame->SaveCopyInUndoList( this, IS_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
|
|
|
|
/**********************************************************/
|
|
|
|
|
void SCH_COMPONENT::ClearAnnotation( DrawSheetPath* aSheet )
|
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Suppress annotation ( i.i IC23 changed to IC? and part reset to 1)
|
|
|
|
|
* @param aSheet: DrawSheetPath value: if NULL remove all annotations,
|
|
|
|
|
* else remove annotation relative to this sheetpath
|
2007-09-20 21:06:49 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
{
|
2008-04-21 06:34:56 +00:00
|
|
|
|
wxString defRef = m_PrefixString;
|
|
|
|
|
bool KeepMulti = false;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
EDA_LibComponentStruct* Entry;
|
2008-04-21 06:34:56 +00:00
|
|
|
|
wxString separators( wxT( " " ) );
|
|
|
|
|
wxArrayString reference_fields;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
|
|
Entry = FindLibPart( m_ChipName.GetData(), wxEmptyString, FIND_ROOT );
|
|
|
|
|
|
|
|
|
|
if( Entry && Entry->m_UnitSelectionLocked )
|
|
|
|
|
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
|
|
|
|
|
2008-05-15 11:20:19 +00:00
|
|
|
|
if ( KeepMulti ) // We cannot remove all annotations: part selection must be kept
|
2008-02-21 12:21:01 +00:00
|
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
|
wxString NewHref;
|
|
|
|
|
wxString path;
|
|
|
|
|
if( aSheet )
|
|
|
|
|
path = GetPath( aSheet );;
|
|
|
|
|
for( unsigned int ii = 0; ii< m_PathsAndReferences.GetCount(); ii++ )
|
2008-04-21 06:34:56 +00:00
|
|
|
|
{
|
2008-05-15 11:20:19 +00:00
|
|
|
|
// Break hierachical reference in path, ref and multi selection:
|
|
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[ii], separators );
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
m_PathsAndReferences.Empty(); // Empty strings, but does not free memory because a new annotation will reuse it
|
|
|
|
|
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-02-21 12:21:01 +00:00
|
|
|
|
m_Field[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
|
|
|
|
/**************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
SCH_COMPONENT* SCH_COMPONENT::GenCopy()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/**************************************************************/
|
|
|
|
|
{
|
2008-03-20 01:50:21 +00:00
|
|
|
|
SCH_COMPONENT* new_item = new SCH_COMPONENT( m_Pos );
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
|
int ii;
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2008-04-12 18:39:20 +00:00
|
|
|
|
new_item->m_Multi = m_Multi;
|
|
|
|
|
new_item->m_ChipName = m_ChipName;
|
2008-03-20 01:50:21 +00:00
|
|
|
|
new_item->m_PrefixString = m_PrefixString;
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
new_item->m_Convert = m_Convert;
|
|
|
|
|
new_item->m_Transform[0][0] = m_Transform[0][0];
|
|
|
|
|
new_item->m_Transform[0][1] = m_Transform[0][1];
|
|
|
|
|
new_item->m_Transform[1][0] = m_Transform[1][0];
|
|
|
|
|
new_item->m_Transform[1][1] = m_Transform[1][1];
|
|
|
|
|
new_item->m_TimeStamp = m_TimeStamp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* initialisation des Fields */
|
|
|
|
|
for( ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
|
|
|
|
|
{
|
|
|
|
|
m_Field[ii].PartTextCopy( &new_item->m_Field[ii] );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new_item;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
void SCH_COMPONENT::SetRotationMiroir( int type_rotate )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/******************************************************************/
|
2007-09-20 21:06:49 +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.
|
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
|
int TempMat[2][2];
|
|
|
|
|
bool Transform = FALSE;
|
|
|
|
|
|
|
|
|
|
switch( type_rotate )
|
|
|
|
|
{
|
|
|
|
|
case CMP_ORIENT_0:
|
|
|
|
|
case CMP_NORMAL: /* Position Initiale */
|
|
|
|
|
m_Transform[0][0] = 1;
|
|
|
|
|
m_Transform[1][1] = -1;
|
|
|
|
|
m_Transform[1][0] = m_Transform[0][1] = 0;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_ROTATE_CLOCKWISE: /* Rotate + */
|
|
|
|
|
TempMat[0][0] = TempMat[1][1] = 0;
|
|
|
|
|
TempMat[0][1] = 1;
|
|
|
|
|
TempMat[1][0] = -1;
|
|
|
|
|
Transform = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_ROTATE_COUNTERCLOCKWISE: /* Rotate - */
|
|
|
|
|
TempMat[0][0] = TempMat[1][1] = 0;
|
|
|
|
|
TempMat[0][1] = -1;
|
|
|
|
|
TempMat[1][0] = 1;
|
|
|
|
|
Transform = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_MIROIR_Y: /* MirrorY */
|
|
|
|
|
TempMat[0][0] = -1;
|
|
|
|
|
TempMat[1][1] = 1;
|
|
|
|
|
TempMat[0][1] = TempMat[1][0] = 0;
|
|
|
|
|
Transform = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_MIROIR_X: /* MirrorX */
|
|
|
|
|
TempMat[0][0] = 1;
|
|
|
|
|
TempMat[1][1] = -1;
|
|
|
|
|
TempMat[0][1] = TempMat[1][0] = 0;
|
|
|
|
|
Transform = TRUE;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_ORIENT_90:
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_ORIENT_180:
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CMP_ORIENT_270:
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_CLOCKWISE );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_0 + CMP_MIROIR_X):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_X );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_0 + CMP_MIROIR_Y):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_Y );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_90 + CMP_MIROIR_X):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_90 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_X );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_90 + CMP_MIROIR_Y):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_90 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_Y );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_180 + CMP_MIROIR_X):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_180 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_X );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_180 + CMP_MIROIR_Y):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_180 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_Y );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_270 + CMP_MIROIR_X):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_270 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_X );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case (CMP_ORIENT_270 + CMP_MIROIR_Y):
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_270 );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_Y );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
Transform = FALSE;
|
|
|
|
|
DisplayError( NULL, wxT( "SetRotateMiroir() error: ill value" ) );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( Transform )
|
2008-04-12 18:39:20 +00:00
|
|
|
|
{
|
|
|
|
|
/* The new matrix transform is the old matrix transform modified by the
|
|
|
|
|
* requested transformation, which is the TempMat transform (rot, mirror ..)
|
|
|
|
|
* in order to have (in term of matrix transform):
|
|
|
|
|
* transform coord = new_m_Transform * coord
|
|
|
|
|
* 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:
|
|
|
|
|
* transform coord = old_m_Transform * coord * TempMat
|
|
|
|
|
*/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
int NewMatrix[2][2];
|
|
|
|
|
|
|
|
|
|
NewMatrix[0][0] = m_Transform[0][0] * TempMat[0][0] +
|
|
|
|
|
m_Transform[1][0] * TempMat[0][1];
|
|
|
|
|
|
|
|
|
|
NewMatrix[0][1] = m_Transform[0][1] * TempMat[0][0] +
|
|
|
|
|
m_Transform[1][1] * TempMat[0][1];
|
|
|
|
|
|
|
|
|
|
NewMatrix[1][0] = m_Transform[0][0] * TempMat[1][0] +
|
|
|
|
|
m_Transform[1][0] * TempMat[1][1];
|
|
|
|
|
|
|
|
|
|
NewMatrix[1][1] = m_Transform[0][1] * TempMat[1][0] +
|
|
|
|
|
m_Transform[1][1] * TempMat[1][1];
|
|
|
|
|
|
|
|
|
|
m_Transform[0][0] = NewMatrix[0][0];
|
|
|
|
|
m_Transform[0][1] = NewMatrix[0][1];
|
|
|
|
|
m_Transform[1][0] = NewMatrix[1][0];
|
|
|
|
|
m_Transform[1][1] = NewMatrix[1][1];
|
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
int SCH_COMPONENT::GetRotationMiroir()
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/****************************************************/
|
|
|
|
|
{
|
2007-09-20 21:06:49 +00:00
|
|
|
|
int type_rotate = CMP_ORIENT_0;
|
|
|
|
|
int TempMat[2][2], MatNormal[2][2];
|
|
|
|
|
int ii;
|
|
|
|
|
bool found = FALSE;
|
|
|
|
|
|
|
|
|
|
memcpy( TempMat, m_Transform, sizeof(TempMat) );
|
|
|
|
|
SetRotationMiroir( CMP_ORIENT_0 );
|
|
|
|
|
memcpy( MatNormal, m_Transform, sizeof(MatNormal) );
|
|
|
|
|
|
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
|
{
|
|
|
|
|
if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
found = TRUE; break;
|
|
|
|
|
}
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
|
{
|
|
|
|
|
type_rotate = CMP_MIROIR_X + CMP_ORIENT_0;
|
|
|
|
|
SetRotationMiroir( CMP_NORMAL );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_X );
|
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
|
{
|
|
|
|
|
if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
found = TRUE; break;
|
|
|
|
|
}
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !found )
|
|
|
|
|
{
|
|
|
|
|
type_rotate = CMP_MIROIR_Y + CMP_ORIENT_0;
|
|
|
|
|
SetRotationMiroir( CMP_NORMAL );
|
|
|
|
|
SetRotationMiroir( CMP_MIROIR_Y );
|
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
|
{
|
|
|
|
|
if( memcmp( TempMat, m_Transform, sizeof(MatNormal) ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
found = TRUE; break;
|
|
|
|
|
}
|
|
|
|
|
SetRotationMiroir( CMP_ROTATE_COUNTERCLOCKWISE );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy( m_Transform, TempMat, sizeof(m_Transform) );
|
|
|
|
|
|
|
|
|
|
if( found )
|
|
|
|
|
{
|
|
|
|
|
return type_rotate + ii;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
wxBell(); return CMP_NORMAL;
|
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************/
|
2008-03-20 01:50:21 +00:00
|
|
|
|
wxPoint SCH_COMPONENT::GetScreenCoord( const wxPoint& coord )
|
2007-05-06 16:03:28 +00:00
|
|
|
|
/***********************************************************************/
|
2007-09-20 21:06:49 +00:00
|
|
|
|
|
2008-02-12 21:12:46 +00:00
|
|
|
|
/* Renvoie la coordonn<6E>e du point coord, en fonction de l'orientation
|
2007-09-20 21:06:49 +00:00
|
|
|
|
* du composant (rotation, miroir).
|
2008-04-15 19:38:19 +00:00
|
|
|
|
* Les coord sont toujours relatives a l'ancre (coord 0,0) du composant
|
2007-09-20 21:06:49 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
wxPoint screenpos;
|
|
|
|
|
|
|
|
|
|
screenpos.x = m_Transform[0][0] * coord.x + m_Transform[0][1] * coord.y;
|
|
|
|
|
screenpos.y = m_Transform[1][0] * coord.x + m_Transform[1][1] * coord.y;
|
|
|
|
|
return screenpos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-21 12:21:01 +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:
|
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2008-02-21 12:21:01 +00:00
|
|
|
|
" ref=\"" << ReturnFieldName( 0 ) << '"' <<
|
|
|
|
|
" chipName=\"" << m_ChipName.mb_str() << '"' <<
|
|
|
|
|
m_Pos <<
|
|
|
|
|
" layer=\"" << m_Layer << '"' <<
|
|
|
|
|
"/>\n";
|
|
|
|
|
|
|
|
|
|
// skip the reference, it's been output already.
|
|
|
|
|
for( int i = 1; i<NUMBER_OF_FIELDS; ++i )
|
2007-09-20 21:06:49 +00:00
|
|
|
|
{
|
|
|
|
|
wxString value = GetFieldValue( i );
|
2008-02-21 12:21:01 +00:00
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
if( !value.IsEmpty() )
|
|
|
|
|
{
|
2008-02-21 12:21:01 +00:00
|
|
|
|
NestedSpace( nestLevel + 1, os ) << "<field" <<
|
|
|
|
|
" name=\"" << ReturnFieldName( i ).mb_str() << '"' <<
|
|
|
|
|
" value=\"" << value.mb_str() << "\"/>\n";
|
2007-09-20 21:06:49 +00:00
|
|
|
|
}
|
2008-02-21 12:21:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2007-09-20 21:06:49 +00:00
|
|
|
|
NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
|
2007-05-06 16:03:28 +00:00
|
|
|
|
}
|
2007-09-20 21:06:49 +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
|
|
|
|
|
/****************************************/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Function Save
|
|
|
|
|
* writes the data structures for this object out to a FILE in "*.brd" format.
|
|
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
|
* @return bool - true if success writing else false.
|
2008-04-12 18:39:20 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
int ii, Success = true;
|
|
|
|
|
char Name1[256], Name2[256];
|
|
|
|
|
wxArrayString reference_fields;
|
|
|
|
|
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 )
|
|
|
|
|
{
|
|
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[0], delimiters );
|
|
|
|
|
strncpy( Name1, CONV_TO_UTF8( reference_fields[1] ), sizeof(Name1) );
|
|
|
|
|
}
|
2008-04-12 18:39:20 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if( m_Field[REFERENCE].m_Text.IsEmpty() )
|
|
|
|
|
strncpy( Name1, CONV_TO_UTF8( m_PrefixString ), sizeof(Name1) );
|
|
|
|
|
else
|
|
|
|
|
strncpy( Name1, CONV_TO_UTF8( m_Field[REFERENCE].m_Text ), sizeof(Name1) );
|
|
|
|
|
}
|
|
|
|
|
for( ii = 0; ii < (int) strlen( Name1 ); ii++ )
|
|
|
|
|
{
|
|
|
|
|
if( Name1[ii] <= ' ' )
|
|
|
|
|
Name1[ii] = '~';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( !m_ChipName.IsEmpty() )
|
|
|
|
|
{
|
|
|
|
|
strncpy( Name2, CONV_TO_UTF8( m_ChipName ), sizeof(Name2) );
|
|
|
|
|
for( ii = 0; ii < (int) strlen( Name2 ); ii++ )
|
|
|
|
|
if( Name2[ii] <= ' ' )
|
|
|
|
|
Name2[ii] = '~';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
strncpy( Name2, NULL_STRING, sizeof(Name2) );
|
|
|
|
|
|
|
|
|
|
fprintf( f, "$Comp\n" );
|
|
|
|
|
|
|
|
|
|
if( fprintf( f, "L %s %s\n", Name2, Name1 ) == EOF )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Generation de numero d'unit, convert et Time Stamp*/
|
|
|
|
|
if( fprintf( f, "U %d %d %8.8lX\n", m_Multi, m_Convert, m_TimeStamp ) == EOF )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
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 )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
* this is usefull 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
|
|
|
|
{
|
2008-04-15 19:38:19 +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'
|
|
|
|
|
*/
|
|
|
|
|
reference_fields = wxStringTokenize( m_PathsAndReferences[ii], delimiters );
|
|
|
|
|
if( fprintf( f, "AR Path=\"%s\" Ref=\"%s\" Part=\"%s\" \n",
|
|
|
|
|
CONV_TO_UTF8( reference_fields[0] ),
|
|
|
|
|
CONV_TO_UTF8( reference_fields[1] ),
|
|
|
|
|
CONV_TO_UTF8( reference_fields[2] )
|
|
|
|
|
) == EOF )
|
|
|
|
|
{
|
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
|
|
|
|
}
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for( ii = 0; ii < NUMBER_OF_FIELDS; ii++ )
|
|
|
|
|
{
|
2008-09-17 17:26:25 +00:00
|
|
|
|
const SCH_CMP_FIELD* field = &m_Field[ii];
|
2008-04-12 18:39:20 +00:00
|
|
|
|
if( field->m_Text.IsEmpty() )
|
|
|
|
|
continue;
|
2008-04-15 19:38:19 +00:00
|
|
|
|
if( !field->Save( f ) )
|
2008-04-12 18:39:20 +00:00
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false; break;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
if( !Success )
|
|
|
|
|
return Success;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
|
|
|
|
|
/* Generation du num unit, position, box ( ancienne norme )*/
|
|
|
|
|
if( fprintf( f, "\t%-4d %-4d %-4d\n", m_Multi, m_Pos.x, m_Pos.y ) == EOF )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( fprintf( f, "\t%-4d %-4d %-4d %-4d\n",
|
|
|
|
|
m_Transform[0][0],
|
|
|
|
|
m_Transform[0][1],
|
|
|
|
|
m_Transform[1][0],
|
|
|
|
|
m_Transform[1][1] ) == EOF )
|
|
|
|
|
{
|
2008-04-15 19:38:19 +00:00
|
|
|
|
Success = false;
|
|
|
|
|
return Success;
|
2008-04-12 18:39:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fprintf( f, "$EndComp\n" );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
return Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-09-20 17:20:40 +00:00
|
|
|
|
for( int ii = REFERENCE; ii < NUMBER_OF_FIELDS; ii++ )
|
2008-04-15 19:38:19 +00:00
|
|
|
|
{
|
2008-09-20 17:20:40 +00:00
|
|
|
|
bbox.Merge( m_Field[ii].GetBoundaryBox() );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ... add padding
|
2008-09-20 17:20:40 +00:00
|
|
|
|
bbox.Inflate( PADDING, 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
|
|
|
|
}
|