2007-09-01 12:00:30 +00:00
|
|
|
/****************************/
|
|
|
|
/* EESchema - eesavlib.cpp */
|
|
|
|
/****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/* Functions to save schematic libraries and library components (::Save()
|
|
|
|
* members)
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "confirm.h"
|
|
|
|
#include "kicad_string.h"
|
|
|
|
#include "gestfich.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2008-12-28 18:00:37 +00:00
|
|
|
/** Function CopyDrawEntryStruct
|
|
|
|
* Duplicate a DrawLibItem
|
2009-04-05 20:49:15 +00:00
|
|
|
* the new item is only created, it is not put in the current component linked
|
|
|
|
* list
|
2007-09-13 11:28:58 +00:00
|
|
|
* @param DrawEntry = DrawLibItem * item to duplicate
|
|
|
|
* @return a pointer to the new item
|
2009-04-05 20:49:15 +00:00
|
|
|
* A better way to duplicate a DrawLibItem is to have a virtual GenCopy() in
|
|
|
|
* LibEDA_BaseStruct class (ToDo).
|
2007-09-01 12:00:30 +00:00
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
LibEDA_BaseStruct* CopyDrawEntryStruct( wxWindow* frame,
|
|
|
|
LibEDA_BaseStruct* DrawItem )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
LibEDA_BaseStruct* NewDrawItem = NULL;
|
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
switch( DrawItem->Type() )
|
|
|
|
{
|
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawArc*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawCircle*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawSquare*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_PIN_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawPin*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawText*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
|
|
|
NewDrawItem = ( (LibDrawPolyline*) DrawItem )->GenCopy();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
msg.Printf( wxT( "CopyDrawLibEntryStruct: unknown Draw Type %d" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
DrawItem->Type() );
|
2007-09-01 12:00:30 +00:00
|
|
|
DisplayError( frame, msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewDrawItem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*
|
|
|
|
* Routine de copie d'une partlib
|
2007-09-01 12:00:30 +00:00
|
|
|
* Parametres d'entree: pointeur sur la structure de depart
|
|
|
|
* Parametres de sortie: pointeur sur la structure creee
|
|
|
|
* Do not copy new items ( i.e. with m_Flag & IS_NEW)
|
|
|
|
*/
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_LibComponentStruct* CopyLibEntryStruct( wxWindow* frame,
|
|
|
|
EDA_LibComponentStruct* OldEntry )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_LibComponentStruct* NewStruct;
|
|
|
|
LibEDA_BaseStruct* NewDrawings, * OldDrawings;
|
|
|
|
LibEDA_BaseStruct* LastItem;
|
|
|
|
LibDrawField* OldField, * NewField;
|
|
|
|
|
|
|
|
if( OldEntry->Type != ROOT )
|
|
|
|
{
|
|
|
|
DisplayError( frame, wxT( "CopyLibEntryStruct(): Type != ROOT" ) );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewStruct = new EDA_LibComponentStruct( NULL );
|
|
|
|
|
|
|
|
OldEntry->m_Prefix.Copy( &NewStruct->m_Prefix );
|
|
|
|
OldEntry->m_Name.Copy( &NewStruct->m_Name );
|
|
|
|
|
|
|
|
NewStruct->m_UnitCount = OldEntry->m_UnitCount;
|
|
|
|
NewStruct->m_TextInside = OldEntry->m_TextInside;
|
|
|
|
NewStruct->m_DrawPinNum = OldEntry->m_DrawPinNum;
|
|
|
|
NewStruct->m_DrawPinName = OldEntry->m_DrawPinName;
|
|
|
|
NewStruct->m_Options = OldEntry->m_Options;
|
|
|
|
NewStruct->m_UnitSelectionLocked = OldEntry->m_UnitSelectionLocked;
|
|
|
|
|
|
|
|
/* Copie des sous structures: */
|
|
|
|
NewStruct->m_AliasList = OldEntry->m_AliasList;
|
|
|
|
NewStruct->m_Doc = OldEntry->m_Doc;
|
|
|
|
NewStruct->m_KeyWord = OldEntry->m_KeyWord;
|
|
|
|
NewStruct->m_DocFile = OldEntry->m_DocFile;
|
|
|
|
|
|
|
|
/* Copie des champs */
|
2009-04-05 20:49:15 +00:00
|
|
|
for( OldField = OldEntry->m_Fields; OldField != NULL;
|
|
|
|
OldField = OldField->Next() )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
|
|
|
NewField = OldField->GenCopy();
|
2008-12-31 15:01:29 +00:00
|
|
|
NewStruct->m_Fields.PushBack( NewField );
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copie des elements type Drawing */
|
|
|
|
LastItem = NULL;
|
2009-04-05 20:49:15 +00:00
|
|
|
for( OldDrawings = OldEntry->m_Drawings; OldDrawings != NULL;
|
|
|
|
OldDrawings = OldDrawings->Next() )
|
2007-09-01 12:00:30 +00:00
|
|
|
{
|
|
|
|
if( ( OldDrawings->m_Flags & IS_NEW) != 0 )
|
|
|
|
continue;
|
2008-04-16 19:12:40 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
NewDrawings = CopyDrawEntryStruct( frame, OldDrawings );
|
|
|
|
if( NewDrawings )
|
|
|
|
{
|
|
|
|
if( LastItem == NULL )
|
|
|
|
NewStruct->m_Drawings = NewDrawings;
|
|
|
|
else
|
2008-11-24 06:53:43 +00:00
|
|
|
LastItem->SetNext( NewDrawings );
|
2007-09-01 12:00:30 +00:00
|
|
|
|
|
|
|
LastItem = NewDrawings;
|
2008-11-24 06:53:43 +00:00
|
|
|
NewDrawings->SetNext( NULL );
|
2007-09-01 12:00:30 +00:00
|
|
|
}
|
2007-09-13 11:28:58 +00:00
|
|
|
else // Should nevers occurs, just in case...
|
2009-04-05 20:49:15 +00:00
|
|
|
{ // CopyDrawEntryStruct() was not able to duplicate the type
|
|
|
|
// of OldDrawings
|
2008-04-16 19:12:40 +00:00
|
|
|
// occurs when an unexpected type is encountered
|
2007-09-01 12:00:30 +00:00
|
|
|
DisplayError( frame, wxT( "CopyLibEntryStruct(): error: aborted" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the footprint filter list */
|
|
|
|
for( unsigned ii = 0; ii < OldEntry->m_FootprintList.GetCount(); ii++ )
|
|
|
|
NewStruct->m_FootprintList.Add( OldEntry->m_FootprintList[ii] );
|
|
|
|
|
|
|
|
return NewStruct;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|