Commit 76d04d6a authored by stambaughw's avatar stambaughw

Library component and draw object improvements and compile warning fix.

* Library component draw items now stored in Boost ptr_vector.
* Updated draw item object comparison to include greater and less than condition.
* Moved set parts per package code from component edit dialog to component object.
* Moved set alternate body style code from component edit dialog to component object.
* Tweaked component library file draw item sort order for improved file readability.
* Documented component object draw item sort ordering.
* Moved plot code to the appropriate library component and draw item objects.
* Fixed compiler type conversion warning in plot_common.h.
parent f765a408
......@@ -505,7 +505,7 @@ static void ComputeReferenceNumber( std::vector <OBJ_CMP_TO_LIST>& aComponentsLi
}
/* Annotation of one part per package components (trivial case)*/
if( aComponentsList[ii].m_Entry->m_UnitCount <= 1 )
if( aComponentsList[ii].m_Entry->GetPartCount() <= 1 )
{
if( aComponentsList[ii].m_IsNew )
{
......@@ -520,7 +520,7 @@ static void ComputeReferenceNumber( std::vector <OBJ_CMP_TO_LIST>& aComponentsLi
/* Annotation of multi-part components ( n parts per package )
* (complex case) */
NumberOfUnits = aComponentsList[ii].m_Entry->m_UnitCount;
NumberOfUnits = aComponentsList[ii].m_Entry->GetPartCount();
if( aComponentsList[ii].m_IsNew )
{
......@@ -709,7 +709,7 @@ int WinEDA_SchematicFrame::CheckAnnotate( wxArrayString* aMessageList, bool aOne
}
// Annotate error
if( MAX( ComponentsList[ii].m_Entry->m_UnitCount, 1 ) < ComponentsList[ii].m_Unit )
if( MAX( ComponentsList[ii].m_Entry->GetPartCount(), 1 ) < ComponentsList[ii].m_Unit )
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
......@@ -721,7 +721,7 @@ int WinEDA_SchematicFrame::CheckAnnotate( wxArrayString* aMessageList, bool aOne
Buff.GetData() );
Buff.Printf( _( " unit %d and no more than %d parts" ),
ComponentsList[ii].m_Unit, ComponentsList[ii].m_Entry->m_UnitCount );
ComponentsList[ii].m_Unit, ComponentsList[ii].m_Entry->GetPartCount() );
msg << Buff;
if( aMessageList )
{
......@@ -777,7 +777,7 @@ int WinEDA_SchematicFrame::CheckAnnotate( wxArrayString* aMessageList, bool aOne
/* Test error if units are different but number of parts per package
* too hight (ex U3 ( 1 part) and we find U3B this is an error) */
if( ComponentsList[ii].m_Entry->m_UnitCount != ComponentsList[ii + 1].m_Entry->m_UnitCount )
if( ComponentsList[ii].m_Entry->GetPartCount() != ComponentsList[ii + 1].m_Entry->GetPartCount() )
{
if( ComponentsList[ii].m_NumRef >= 0 )
Buff << ComponentsList[ii].m_NumRef;
......
......@@ -650,7 +650,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef(
Unit = ' ';
Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName );
if( Entry )
Multi = Entry->m_UnitCount;
Multi = Entry->GetPartCount();
if( ( Multi > 1 ) && aIncludeSubComponents )
#if defined (KICAD_GOST)
......@@ -749,7 +749,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal(
Unit = ' ';
Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName );
if( Entry )
Multi = Entry->m_UnitCount;
Multi = Entry->GetPartCount();
if( ( Multi > 1 ) && aIncludeSubComponents )
{
......
......@@ -11,6 +11,7 @@
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "drawtxt.h"
#include "trigo.h"
......@@ -248,6 +249,23 @@ void LibDrawText::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawText::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
/* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped. */
int t1 = ( transform[0][0] != 0 ) ^ ( m_Orient != 0 );
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
plotter->text( pos, UNSPECIFIED_COLOR, m_Text,
t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT,
m_Size, GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
GetPenSize(), m_Italic, m_Bold );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......
......@@ -7,6 +7,7 @@
#include "kicad_string.h"
#include "confirm.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "gr_basic.h"
#include "program.h"
......@@ -15,134 +16,7 @@
#include "class_library.h"
#include "class_libentry.h"
int SortItemsFct(const void* ref, const void* item)
{
#define Ref ( *(LIB_DRAW_ITEM**) (ref) )
#define Item ( *(LIB_DRAW_ITEM**) (item) )
#define BEFORE -1
#define AFTER 1
int fill_ref = 0, fill_item = 0;
switch( Ref->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
{
const LibDrawArc* draw = (const LibDrawArc*) Ref;
fill_ref = draw->m_Fill;
break;
}
case COMPONENT_CIRCLE_DRAW_TYPE:
{
const LibDrawCircle* draw = (const LibDrawCircle*) Ref;
fill_ref = draw->m_Fill;
break;
}
case COMPONENT_RECT_DRAW_TYPE:
{
const LibDrawSquare* draw = (const LibDrawSquare*) Ref;
fill_ref = draw->m_Fill;
break;
}
case COMPONENT_POLYLINE_DRAW_TYPE:
{
const LibDrawPolyline* draw = (const LibDrawPolyline*) Ref;
fill_ref = draw->m_Fill;
break;
}
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
if( Item->Type() == COMPONENT_PIN_DRAW_TYPE )
return BEFORE;
if( Item->Type() == COMPONENT_GRAPHIC_TEXT_DRAW_TYPE )
return 0;
return 1;
break;
case COMPONENT_PIN_DRAW_TYPE:
if( Item->Type() == COMPONENT_PIN_DRAW_TYPE )
{
int ii;
// Sort the pins by orientation
ii = ( (LibDrawPin*) Ref )->m_Orient -
( (LibDrawPin*) Item )->m_Orient;
if( ii )
return ii;
/* We sort the pins by position (x or y).
* note: at this point, most of pins have same x pos or y pos,
* because they are sorted by orientation and generally are
* vertically or horizontally aligned */
wxPoint pos_ref, pos_tst;
pos_ref = ( (LibDrawPin*) Ref )->m_Pos;
pos_tst = ( (LibDrawPin*) Item )->m_Pos;
if( (ii = pos_ref.x - pos_tst.x) )
return ii;
ii = pos_ref.y - pos_tst.y;
return ii;
}
else
return AFTER;
break;
default:
;
}
/* Test de l'item */
switch( Item->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
{
const LibDrawArc* draw = (const LibDrawArc*) Item;
fill_item = draw->m_Fill;
break;
}
case COMPONENT_CIRCLE_DRAW_TYPE:
{
const LibDrawCircle* draw = (const LibDrawCircle*) Item;
fill_item = draw->m_Fill;
break;
}
case COMPONENT_RECT_DRAW_TYPE:
{
const LibDrawSquare* draw = (const LibDrawSquare*) Item;
fill_item = draw->m_Fill;
break;
}
case COMPONENT_POLYLINE_DRAW_TYPE:
{
const LibDrawPolyline* draw = (const LibDrawPolyline*) Item;
fill_item = draw->m_Fill;
break;
}
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
return BEFORE;
break;
case COMPONENT_PIN_DRAW_TYPE:
return BEFORE;
break;
default:
;
}
if( fill_ref & fill_item )
return 0;
if( fill_ref )
return BEFORE;
return AFTER;
}
#include <boost/foreach.hpp>
/*********************/
......@@ -169,7 +43,7 @@ CMP_LIB_ENTRY::CMP_LIB_ENTRY( LibrEntryType type, const wxString& name,
}
CMP_LIB_ENTRY::CMP_LIB_ENTRY( const CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib ) :
CMP_LIB_ENTRY::CMP_LIB_ENTRY( CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib ) :
EDA_BaseStruct( entry )
{
Type = entry.Type;
......@@ -274,7 +148,7 @@ LIB_ALIAS::LIB_ALIAS( const wxString& name, LIB_COMPONENT* root,
}
LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& alias, CMP_LIBRARY* lib ) :
LIB_ALIAS::LIB_ALIAS( LIB_ALIAS& alias, CMP_LIBRARY* lib ) :
CMP_LIB_ENTRY( alias )
{
m_root = alias.m_root;
......@@ -303,7 +177,6 @@ void LIB_ALIAS::SetComponent( LIB_COMPONENT* root )
LIB_COMPONENT::LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib ) :
CMP_LIB_ENTRY( ROOT, name, lib )
{
m_Drawings = NULL;
m_LastDate = 0;
m_UnitCount = 1;
m_TextInside = 40;
......@@ -316,13 +189,10 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib ) :
}
LIB_COMPONENT::LIB_COMPONENT( const LIB_COMPONENT& component,
CMP_LIBRARY* lib ) :
LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib ) :
CMP_LIB_ENTRY( component, lib )
{
LIB_DRAW_ITEM* oldItem;
LIB_DRAW_ITEM* newItem;
LIB_DRAW_ITEM* lastItem = NULL;
LibDrawField* oldField;
LibDrawField* newField;
......@@ -335,26 +205,17 @@ LIB_COMPONENT::LIB_COMPONENT( const LIB_COMPONENT& component,
m_DrawPinNum = component.m_DrawPinNum;
m_DrawPinName = component.m_DrawPinName;
m_LastDate = component.m_LastDate;
m_Drawings = NULL;
m_Prefix.SetParent( this );
for( oldItem = component.m_Drawings; oldItem != NULL;
oldItem = oldItem->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& oldItem, component.GetDrawItemList() )
{
if( ( oldItem->m_Flags & IS_NEW ) != 0 )
if( ( oldItem.m_Flags & IS_NEW ) != 0 )
continue;
newItem = oldItem->GenCopy();
if( lastItem == NULL )
m_Drawings = newItem;
else
lastItem->SetNext( newItem );
newItem = oldItem.GenCopy();
newItem->SetParent( this );
lastItem = newItem;
newItem->SetNext( NULL );
m_Drawings.push_back( newItem );
}
for( oldField = component.m_Fields; oldField != NULL;
......@@ -369,19 +230,6 @@ LIB_COMPONENT::LIB_COMPONENT( const LIB_COMPONENT& component,
LIB_COMPONENT::~LIB_COMPONENT()
{
LIB_DRAW_ITEM* DrawItem;
LIB_DRAW_ITEM* NextDrawItem;
/* suppression des elements dependants */
DrawItem = m_Drawings;
m_Drawings = NULL;
while( DrawItem )
{
NextDrawItem = DrawItem->Next();
SAFE_DELETE( DrawItem );
DrawItem = NextDrawItem;
}
}
......@@ -399,38 +247,37 @@ void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
GRSetDrawMode( dc, drawMode );
for( drawItem = m_Drawings; drawItem != NULL; drawItem = drawItem->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, m_Drawings )
{
if( onlySelected && drawItem->m_Selected == 0 )
if( onlySelected && drawItem.m_Selected == 0 )
continue;
// Do not draw an item while moving (the cursor handler does that)
if( drawItem->m_Flags & IS_MOVED )
if( drawItem.m_Flags & IS_MOVED )
continue;
/* Do not draw items not attached to the current part */
if( multi && drawItem->m_Unit && ( drawItem->m_Unit != multi ) )
if( multi && drawItem.m_Unit && ( drawItem.m_Unit != multi ) )
continue;
if( convert && drawItem->m_Convert
&& ( drawItem->m_Convert != convert ) )
if( convert && drawItem.m_Convert && ( drawItem.m_Convert != convert ) )
continue;
if( drawItem->Type() == COMPONENT_PIN_DRAW_TYPE )
if( drawItem.Type() == COMPONENT_PIN_DRAW_TYPE )
{
drawItem->Draw( panel, dc, offset, color, drawMode, &showPinText,
transformMatrix );
drawItem.Draw( panel, dc, offset, color, drawMode, &showPinText,
transformMatrix );
}
else
{
bool force_nofill =
( screen->m_IsPrinting
&& drawItem->m_Fill == FILLED_WITH_BG_BODYCOLOR
&& drawItem.m_Fill == FILLED_WITH_BG_BODYCOLOR
&& GetGRForceBlackPenState() );
drawItem->Draw( panel, dc, offset, color, drawMode,
(void*) force_nofill, transformMatrix );
drawItem.Draw( panel, dc, offset, color, drawMode,
(void*) force_nofill, transformMatrix );
}
}
......@@ -493,13 +340,33 @@ void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc,
}
void LIB_COMPONENT::Plot( PLOTTER* plotter, int unit, int convert,
const wxPoint& offset, const int transform[2][2] )
{
wxASSERT( plotter != NULL );
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( unit && item.m_Unit && ( item.m_Unit != unit ) )
continue;
if( convert && item.m_Convert && ( item.m_Convert != convert ) )
continue;
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
bool fill = plotter->get_color_mode();
item.Plot( plotter, offset, fill, transform );
}
}
void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item,
WinEDA_DrawPanel* panel,
wxDC* dc )
{
wxASSERT( item != NULL );
LIB_DRAW_ITEM* prevItem = m_Drawings;
LIB_DRAW_ITEM_LIST::iterator i;
if( dc != NULL )
item->Draw( panel, dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL,
......@@ -507,23 +374,13 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item,
if( item->Type() != COMPONENT_FIELD_DRAW_TYPE )
{
if( m_Drawings == item )
for( i = m_Drawings.begin(); i < m_Drawings.end(); i++ )
{
m_Drawings = item->Next();
SAFE_DELETE( item );
return;
}
while( prevItem )
{
if( prevItem->Next() == item )
if( *i == item )
{
prevItem->SetNext( item->Next() );
SAFE_DELETE( item );
m_Drawings.erase( i );
break;
}
prevItem = prevItem->Next();
}
}
else
......@@ -547,41 +404,30 @@ void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* item )
{
wxASSERT( item != NULL );
if( m_Drawings == NULL )
{
m_Drawings = item;
item->SetNext( NULL );
return;
}
LIB_DRAW_ITEM* i = m_Drawings;
while( i->Next() != NULL )
i = i->Next();
i->SetNext( item );
item->SetNext( NULL );
SortDrawItems();
m_Drawings.push_back( item );
m_Drawings.sort();
}
LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* item,
KICAD_T type )
{
if( type == TYPE_NOT_INIT )
return ( item == NULL ) ? m_Drawings : item->Next();
if( m_Drawings.empty() )
return NULL;
LIB_DRAW_ITEM* i = ( item == NULL ) ? m_Drawings : item->Next();
if( item == NULL && type == TYPE_NOT_INIT )
return &m_Drawings[0];
while( i != NULL )
for( size_t i = 0; i < m_Drawings.size() - 1; i++ )
{
if( i->Type() == type )
return i;
if( item != &m_Drawings[i] )
continue;
i = i->Next();
if( type == TYPE_NOT_INIT || m_Drawings[ i + 1 ].Type() == type )
return &m_Drawings[ i + 1 ];
}
return i;
return NULL;
}
......@@ -593,12 +439,8 @@ LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* item,
*/
bool LIB_COMPONENT::Save( FILE* aFile )
{
LIB_DRAW_ITEM* DrawEntry;
LibDrawField* Field;
/* Sort just in clase sorting was not done properly. */
SortDrawItems();
/* First line: it s a comment (component name for readers) */
if( fprintf( aFile, "#\n# %s\n#\n", CONV_TO_UTF8( m_Name.m_Text ) ) < 0 )
return false;
......@@ -683,21 +525,19 @@ bool LIB_COMPONENT::Save( FILE* aFile )
}
/* Save graphics items (including pins) */
if( m_Drawings )
if( !m_Drawings.empty() )
{
/* we sort the draw items, in order to have an edition more easy,
* when a file editing "by hand" is made */
SortDrawItems();
m_Drawings.sort();
if( fprintf( aFile, "DRAW\n" ) < 0 )
return false;
DrawEntry = m_Drawings;
while( DrawEntry )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( !DrawEntry->Save( aFile ) )
if( !item.Save( aFile ) )
return false;
DrawEntry = DrawEntry->Next();
}
if( fprintf( aFile, "ENDDRAW\n" ) < 0 )
......@@ -823,7 +663,7 @@ bool LIB_COMPONENT::Load( FILE* file, char* line, int* lineNum,
}
/* If we are here, this part is O.k. - put it in: */
SortDrawItems();
m_Drawings.sort();
return true;
}
......@@ -833,8 +673,6 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* f, char* line,
int* lineNum, wxString& errorMsg )
{
LIB_DRAW_ITEM* newEntry = NULL;
LIB_DRAW_ITEM* headEntry = NULL;
LIB_DRAW_ITEM* tailEntry = NULL;
while( true )
{
......@@ -881,7 +719,6 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* f, char* line,
default:
errorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] );
m_Drawings = headEntry;
return false;
}
......@@ -902,22 +739,14 @@ to flush to end of drawing section." );
}
} while( strncmp( line, "ENDDRAW", 7 ) != 0 );
SAFE_DELETE( headEntry );
return false;
}
else
{
if( headEntry == NULL )
headEntry = tailEntry = newEntry;
else
{
tailEntry->SetNext( newEntry );
tailEntry = newEntry;
}
m_Drawings.push_back( newEntry );
}
}
m_Drawings = headEntry;
return true;
}
......@@ -986,48 +815,6 @@ bool LIB_COMPONENT::LoadFootprints( FILE* file, char* line,
}
/* TODO translate comment to english TODO
* Trie les �l�ments graphiques d'un composant lib pour am�liorer
* le trac�:
* items remplis en premier, pins en dernier
* En cas de superposition d'items, c'est plus lisible
*/
void LIB_COMPONENT::SortDrawItems()
{
LIB_DRAW_ITEM** Bufentry, ** BufentryBase, * Entry = m_Drawings;
int ii, nbitems;
if( Entry == NULL )
return; /* Pas d'alias pour ce composant */
for( nbitems = 0; Entry != NULL; Entry = Entry->Next() )
nbitems++;
BufentryBase =
(LIB_DRAW_ITEM**) MyZMalloc( (nbitems + 1) *
sizeof(LIB_DRAW_ITEM*) );
/* memorisation du chainage : */
for( Entry = m_Drawings, ii = 0; Entry != NULL; Entry = Entry->Next() )
BufentryBase[ii++] = Entry;
/* Tri du chainage */
qsort( BufentryBase, nbitems, sizeof(LIB_DRAW_ITEM*), SortItemsFct );
/* Mise a jour du chainage. Remarque:
* le dernier element de BufEntryBase (BufEntryBase[nbitems]) est NULL*/
m_Drawings = *BufentryBase;
Bufentry = BufentryBase;
for( ii = 0; ii < nbitems; ii++ )
{
(*Bufentry)->SetNext( *(Bufentry + 1) );
Bufentry++;
}
MyFree( BufentryBase );
}
/**********************************************************************/
/* Return the component boundary box ( in user coordinates )
* The unit Unit, and the shape Convert are considered.
......@@ -1037,20 +824,18 @@ void LIB_COMPONENT::SortDrawItems()
/**********************************************************************/
EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert )
{
LIB_DRAW_ITEM* item;
EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( ( item->m_Unit > 0 )
&& ( ( m_UnitCount > 1 ) && ( Unit > 0 )
&& ( Unit != item->m_Unit ) ) )
if( ( item.m_Unit > 0 ) && ( ( m_UnitCount > 1 ) && ( Unit > 0 )
&& ( Unit != item.m_Unit ) ) )
continue;
if( item->m_Convert > 0
&& ( ( Convert > 0 ) && ( Convert != item->m_Convert ) ) )
if( item.m_Convert > 0
&& ( ( Convert > 0 ) && ( Convert != item.m_Convert ) ) )
continue;
bBox.Merge( item->GetBoundingBox() );
bBox.Merge( item.GetBoundingBox() );
}
bBox.Merge( m_Name.GetBoundingBox() );
......@@ -1160,8 +945,6 @@ bool LIB_COMPONENT::LoadDateAndTime( char* Line )
void LIB_COMPONENT::SetOffset( const wxPoint& offset )
{
LIB_DRAW_ITEM* DrawEntry;
m_Name.SetOffset( offset );
m_Prefix.SetOffset( offset );
......@@ -1170,62 +953,24 @@ void LIB_COMPONENT::SetOffset( const wxPoint& offset )
field->SetOffset( offset );
}
DrawEntry = m_Drawings;
while( DrawEntry )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
DrawEntry->SetOffset( offset );
DrawEntry = DrawEntry->Next();
item.SetOffset( offset );
}
}
void LIB_COMPONENT::RemoveDuplicateDrawItems()
{
LIB_DRAW_ITEM* DEntryRef;
LIB_DRAW_ITEM* DEntryCompare;
bool deleted;
DEntryRef = m_Drawings;
while( DEntryRef )
{
if( DEntryRef->Next() == NULL )
return;
DEntryCompare = DEntryRef->Next();
if( DEntryCompare == NULL )
return;
deleted = false;
while( DEntryCompare )
{
if( DEntryRef == DEntryCompare )
{
RemoveDrawItem( DEntryRef, NULL, NULL );
deleted = true;
break;
}
DEntryCompare = DEntryCompare->Next();
}
if( !deleted )
DEntryRef = DEntryRef->Next();
else
DEntryRef = m_Drawings;
}
m_Drawings.unique();
}
bool LIB_COMPONENT::HasConversion() const
{
LIB_DRAW_ITEM* entry;
for( entry = m_Drawings; entry != NULL; entry = entry->Next() )
BOOST_FOREACH( const LIB_DRAW_ITEM& item, m_Drawings )
{
if( entry->m_Convert > 1 )
if( item.m_Convert > 1 )
return true;
}
......@@ -1235,11 +980,10 @@ bool LIB_COMPONENT::HasConversion() const
void LIB_COMPONENT::ClearStatus( void )
{
LIB_DRAW_ITEM* item;
LibDrawField* field;
for( item = m_Drawings; item != NULL; item = item->Next() )
item->m_Flags = 0;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
item.m_Flags = 0;
m_Name.m_Flags = 0;
m_Prefix.m_Flags = 0;
......@@ -1252,28 +996,27 @@ void LIB_COMPONENT::ClearStatus( void )
int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert,
bool editPinByPin )
{
LIB_DRAW_ITEM* item;
int ItemsCount = 0;
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
item->m_Selected = 0;
item.m_Selected = 0;
if( ( item->m_Unit && item->m_Unit != unit )
|| ( item->m_Convert && item->m_Convert != convert ) )
if( ( item.m_Unit && item.m_Unit != unit )
|| ( item.m_Convert && item.m_Convert != convert ) )
{
if( item->Type() != COMPONENT_PIN_DRAW_TYPE )
if( item.Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
// Specific rules for pins.
if( editPinByPin || m_UnitSelectionLocked
|| ( item->m_Convert && item->m_Convert != convert ) )
|| ( item.m_Convert && item.m_Convert != convert ) )
continue;
}
if( item->Inside( rect ) )
if( item.Inside( rect ) )
{
item->m_Selected = IS_SELECTED;
item.m_Selected = IS_SELECTED;
ItemsCount++;
}
}
......@@ -1306,16 +1049,15 @@ int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert,
void LIB_COMPONENT::MoveSelectedItems( const wxPoint& offset )
{
LIB_DRAW_ITEM* item;
LibDrawField* field;
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item->m_Selected == 0 )
if( item.m_Selected == 0 )
continue;
item->SetOffset( offset );
item->m_Flags = item->m_Selected = 0;
item.SetOffset( offset );
item.m_Flags = item.m_Selected = 0;
}
if( m_Name.m_Selected )
......@@ -1339,17 +1081,16 @@ void LIB_COMPONENT::MoveSelectedItems( const wxPoint& offset )
}
}
SortDrawItems();
m_Drawings.sort();
}
void LIB_COMPONENT::ClearSelectedItems( void )
{
LIB_DRAW_ITEM* item;
LibDrawField* field;
for( item = m_Drawings; item != NULL; item = item->Next() )
item->m_Flags = item->m_Selected = 0;
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
item.m_Flags = item.m_Selected = 0;
m_Name.m_Flags = m_Name.m_Selected = 0;
m_Prefix.m_Flags = m_Prefix.m_Selected = 0;
......@@ -1361,53 +1102,46 @@ void LIB_COMPONENT::ClearSelectedItems( void )
void LIB_COMPONENT::DeleteSelectedItems( void )
{
LIB_DRAW_ITEM* item;
LIB_DRAW_ITEM* nextItem;
LIB_DRAW_ITEM_LIST::iterator i = m_Drawings.begin();
for( item = m_Drawings; item != NULL; item = nextItem )
while( i != m_Drawings.end() )
{
nextItem = item->Next();
if( item->m_Selected == 0 )
continue;
RemoveDrawItem( item );
if( i->m_Selected == 0 )
i++;
else
i = m_Drawings.erase( i );
}
}
void LIB_COMPONENT::CopySelectedItems( const wxPoint& offset )
{
LIB_DRAW_ITEM* item;
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item->m_Selected == 0 )
if( item.m_Selected == 0 )
continue;
item->m_Selected = 0;
LIB_DRAW_ITEM* newItem = item->GenCopy();
item.m_Selected = 0;
LIB_DRAW_ITEM* newItem = item.GenCopy();
newItem->m_Selected = IS_SELECTED;
newItem->SetNext( m_Drawings );
m_Drawings = newItem;
m_Drawings.push_back( newItem );
}
MoveSelectedItems( offset );
SortDrawItems();
m_Drawings.sort();
}
void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
{
LIB_DRAW_ITEM* item;
LibDrawField* field;
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( item->m_Selected == 0 )
if( item.m_Selected == 0 )
continue;
item->SetOffset( center );
item->m_Flags = item->m_Selected = 0;
item.SetOffset( center );
item.m_Flags = item.m_Selected = 0;
}
if( m_Name.m_Selected )
......@@ -1431,25 +1165,24 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center )
}
}
SortDrawItems();
m_Drawings.sort();
}
LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
KICAD_T type, const wxPoint& pt )
{
LIB_DRAW_ITEM* item;
LibDrawField* field;
for( item = m_Drawings; item != NULL; item = item->Next() )
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
if( ( unit && item->m_Unit && ( unit != item->m_Unit) )
|| ( convert && item->m_Convert && ( convert != item->m_Convert ) )
|| ( ( item->Type() != type ) && ( type != TYPE_NOT_INIT ) ) )
if( ( unit && item.m_Unit && ( unit != item.m_Unit) )
|| ( convert && item.m_Convert && ( convert != item.m_Convert ) )
|| ( ( item.Type() != type ) && ( type != TYPE_NOT_INIT ) ) )
continue;
if( item->HitTest( pt ) )
return item;
if( item.HitTest( pt ) )
return &item;
}
if( type == COMPONENT_FIELD_DRAW_TYPE || type == TYPE_NOT_INIT )
......@@ -1466,6 +1199,84 @@ LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int unit, int convert,
}
}
return NULL;
}
void LIB_COMPONENT::SetPartCount( int count )
{
LIB_DRAW_ITEM_LIST::iterator i;
if( m_UnitCount == count )
return;
if( count < m_UnitCount )
{
i = m_Drawings.begin();
while( i != m_Drawings.end() )
{
if( i->m_Unit > count )
i = m_Drawings.erase( i );
else
i++;
}
}
else
{
int prevCount = m_UnitCount;
for( i = m_Drawings.begin(); i != m_Drawings.end(); i++ )
{
if( i->m_Unit != 1 )
continue;
for( int j = prevCount + 1; j <= count; j++ )
{
LIB_DRAW_ITEM* newItem = i->GenCopy();
newItem->m_Unit = j;
m_Drawings.push_back( newItem );
}
}
m_Drawings.sort();
}
m_UnitCount = count;
}
void LIB_COMPONENT::SetConversion( bool asConvert )
{
if( asConvert == HasConversion() )
return;
if( asConvert )
{
BOOST_FOREACH( LIB_DRAW_ITEM& item, m_Drawings )
{
/* Only pins are duplicated. */
if( item.Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
if( item.m_Convert == 1 )
{
LIB_DRAW_ITEM* newItem = item.GenCopy();
newItem->m_Convert = 2;
m_Drawings.push_back( newItem );
}
}
}
else
{
LIB_DRAW_ITEM_LIST::iterator i = m_Drawings.begin();
while( i != m_Drawings.end() )
{
if( i->m_Convert > 1 )
i = m_Drawings.erase( i );
else
i++;
}
}
}
......@@ -53,7 +53,7 @@ public:
public:
CMP_LIB_ENTRY( LibrEntryType CmpType, const wxString& name,
CMP_LIBRARY* lib = NULL );
CMP_LIB_ENTRY( const CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib = NULL );
CMP_LIB_ENTRY( CMP_LIB_ENTRY& entry, CMP_LIBRARY* lib = NULL );
virtual ~CMP_LIB_ENTRY();
......@@ -112,7 +112,6 @@ public:
wxArrayString m_FootprintList; /* list of suitable footprint names
* for the component (wildcard names
* accepted) */
int m_UnitCount; /* Units (or sections) per package */
bool m_UnitSelectionLocked; /* True if units are different
* and their selection is
* locked (i.e. if part A cannot
......@@ -125,9 +124,12 @@ public:
bool m_DrawPinNum;
bool m_DrawPinName;
DLIST<LibDrawField> m_Fields; /* Auxiliary Field list (id >= 2 ) */
LIB_DRAW_ITEM * m_Drawings; /* How to draw this part */
long m_LastDate; // Last change Date
protected:
int m_UnitCount; /* Units (or sections) per package */
LIB_DRAW_ITEM_LIST m_Drawings; /* How to draw this part */
public:
virtual wxString GetClass() const
{
......@@ -136,14 +138,12 @@ public:
LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib = NULL );
LIB_COMPONENT( const LIB_COMPONENT& component, CMP_LIBRARY* lib = NULL );
LIB_COMPONENT( LIB_COMPONENT& component, CMP_LIBRARY* lib = NULL );
~LIB_COMPONENT();
EDA_Rect GetBoundaryBox( int Unit, int Convert );
void SortDrawItems();
bool SaveDateAndTime( FILE* ExportFile );
bool LoadDateAndTime( char* Line );
......@@ -204,6 +204,17 @@ public:
bool showPinText = true, bool drawFields = true,
bool onlySelected = false );
/**
* Plot component to plotter.
*
* @param plotter - Plotter object to plot to.
* @param unit - Component part to plot.
* @param convert - Component alternate body style to plot.
* @param transform - Component plot transform matrix.
*/
void Plot( PLOTTER* plotter, int unit, int convert, const wxPoint& offset,
const int transform[2][2] );
/**
* Add a new draw item to the draw object list.
*
......@@ -344,6 +355,40 @@ public:
*/
LIB_DRAW_ITEM* LocateDrawItem( int unit, int convert, KICAD_T type,
const wxPoint& pt );
/**
* Return a reference to the draw item list.
*
* @return LIB_DRAW_ITEM_LIST& - Reference to the draw item object list.
*/
LIB_DRAW_ITEM_LIST& GetDrawItemList( void ) { return m_Drawings; }
/**
* Set the part per package count.
*
* If the count is greater than the current count, then the all of the
* current draw items are duplicated for each additional part. If the
* count is less than the current count, all draw objects for parts
* greater that count are removed from the component.
*
* @param count - Number of parts per package.
*/
void SetPartCount( int count );
int GetPartCount( void ) { return m_UnitCount; }
/**
* Set or clear the alternate body style (DeMorgan) for the component.
*
* If the component already has an alternate body style set and a
* asConvert if false, all of the existing draw items for the alternate
* body style are remove. If the alternate body style is not set and
* asConvert is true, than the base draw items are duplicated and
* added to the component.
*
* @param asConvert - Set or clear the component alternate body style.
*/
void SetConversion( bool asConvert );
};
......@@ -365,7 +410,7 @@ protected:
public:
LIB_ALIAS( const wxString& name, LIB_COMPONENT* root,
CMP_LIBRARY* lib = NULL );
LIB_ALIAS( const LIB_ALIAS& alias, CMP_LIBRARY* lib = NULL );
LIB_ALIAS( LIB_ALIAS& alias, CMP_LIBRARY* lib = NULL );
~LIB_ALIAS();
virtual wxString GetClass() const
......
......@@ -9,6 +9,7 @@
#include "drawtxt.h"
#include "kicad_string.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "trigo.h"
#include "program.h"
......@@ -356,7 +357,7 @@ bool LibDrawField::HitTest( wxPoint aPosRef, int aThreshold,
extraCharCount++;
m_Text.Append('?');
LIB_COMPONENT* parent = (LIB_COMPONENT*)m_Parent;
if ( parent && ( parent->m_UnitCount > 1 ) )
if ( parent && ( parent->GetPartCount() > 1 ) )
{
m_Text.Append('A');
extraCharCount++;
......@@ -477,6 +478,12 @@ void LibDrawField::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawField::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
}
/*
* If the field is the reference, return reference like schematic,
* i.e U -> U? or U?A or the field text for others
......@@ -490,7 +497,7 @@ wxString LibDrawField::GetFullText( int unit )
wxString text = m_Text;
if( GetParent()->m_UnitCount > 1 )
if( GetParent()->GetPartCount() > 1 )
{
#if defined(KICAD_GOST)
text.Printf( wxT( "%s?.%c" ),
......
......@@ -132,12 +132,28 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the field draw object specific comparison.
*
* The sort order for field is as follows:
*
* - Field ID, REFERENCE, VALUE, etc.
* - Field string, case insensitive compare.
* - Field horizontal (X) position.
* - Field vertical (Y) position.
* - Field width.
* - Field height.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
#endif // CLASS_LIBENTRY_FIELDS_H
......@@ -18,6 +18,10 @@
#include "class_libentry.h"
extern void PlotPinSymbol( PLOTTER* plotter, const wxPoint& pos,
int len, int orient, int Shape );
const wxChar* MsgPinElectricType[] =
{
wxT( "input" ),
......@@ -1149,6 +1153,24 @@ void LibDrawPin::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawPin::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
if( m_Attributs & PINNOTDRAW )
return;
int orient = ReturnPinDrawOrient( transform );
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
plotter->set_current_line_width( GetPenSize() );
PlotPinSymbol( plotter, pos, m_PinLen, orient, m_PinShape );
PlotPinTexts( plotter, pos, orient, GetParent()->m_TextInside,
GetParent()->m_DrawPinNum, GetParent()->m_DrawPinName,
GetPenSize() );
}
/** Function LibDrawPin::DisplayInfo
* Displays info (pin num and name, orientation ...
* on the Info window
......
......@@ -426,7 +426,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC )
Entry = CMP_LIBRARY::FindLibraryComponent( component->m_ChipName );
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
m_AddExtraText = 1;
}
}
......
......@@ -191,7 +191,7 @@ void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
if( ( ( field->m_Attributs & TEXT_NO_VISIBLE ) == 0 )
&& !( field->m_Flags & IS_MOVED ) )
{
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
{
field->m_AddExtraText = true;
field->Draw( panel, DC, offset, DrawMode );
......
......@@ -6,6 +6,7 @@
#include "gr_basic.h"
#include "common.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "drawtxt.h"
#include "trigo.h"
#include "bezier_curves.h"
......@@ -91,22 +92,22 @@ bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& other ) const
bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_ITEM& other ) const
{
int result = Type() - other.Type();
int result = m_Convert - other.m_Convert;
if( result < 0 )
return true;
if( result != 0 )
return result < 0;
result = m_Unit - other.m_Unit;
if( result < 0 )
return true;
if( result != 0 )
return result < 0;
result = m_Convert - other.m_Convert;
result = Type() - other.Type();
if( result < 0 )
return true;
if( result != 0 )
return result < 0;
return DoCompare( other ) < 0;
return ( DoCompare( other ) < 0 );
}
......@@ -358,6 +359,28 @@ void LibDrawArc::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawArc::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
int t1 = m_t1;
int t2 = m_t2;
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
MapAngles( &t1, &t2, transform );
if( fill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->arc( pos, -t2, -t1, m_Radius, FILLED_SHAPE, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->arc( pos, -t2, -t1, m_Radius, m_Fill, GetPenSize() );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -672,6 +695,22 @@ void LibDrawCircle::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawCircle::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
if( fill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->circle( pos, m_Radius * 2, FILLED_SHAPE, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->circle( pos, m_Radius * 2, m_Fill, GetPenSize() );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -888,6 +927,25 @@ void LibDrawSquare::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawSquare::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
wxPoint end = TransformCoordinate( transform, m_End ) + offset;
if( fill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->rect( pos, end, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->rect( pos, end, m_Fill, GetPenSize() );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -1133,6 +1191,23 @@ void LibDrawSegment::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawSegment::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
int points[4];
wxPoint pos = TransformCoordinate( transform, m_Pos ) + offset;
wxPoint end = TransformCoordinate( transform, m_End ) + offset;
points[0] = pos.x;
points[1] = pos.y;
points[2] = end.x;
points[3] = end.y;
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->poly( 2, points, m_Fill, GetPenSize() );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -1407,6 +1482,35 @@ void LibDrawPolyline::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawPolyline::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
size_t i;
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
for( i = 0; i < m_PolyPoints.size(); i++ )
{
wxPoint pos = m_PolyPoints[i];
pos = TransformCoordinate( transform, pos ) + offset;
Poly[i * 2] = pos.x;
Poly[i * 2 + 1] = pos.y;
}
if( fill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->poly( i, Poly, m_Fill, GetPenSize() );
MyFree( Poly );
}
void LibDrawPolyline::AddPoint( const wxPoint& point )
{
m_PolyPoints.push_back( point );
......@@ -1764,6 +1868,35 @@ void LibDrawBezier::DoMirrorHorizontal( const wxPoint& center )
}
void LibDrawBezier::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
wxASSERT( plotter != NULL );
size_t i;
int* Poly = (int*) MyMalloc( sizeof(int) * 2 * GetCornerCount() );
for( i = 0; i < m_PolyPoints.size(); i++ )
{
wxPoint pos = m_PolyPoints[i];
pos = TransformCoordinate( transform, pos ) + offset;
Poly[i * 2] = pos.x;
Poly[i * 2 + 1] = pos.y;
}
if( fill && m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->poly( i, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->poly( i, Poly, m_Fill, GetPenSize() );
MyFree( Poly );
}
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......
......@@ -266,13 +266,30 @@ public:
DoMirrorHorizontal( center );
}
/**
* Plot the draw item using the plot object.
*
* @param plotter - The plot object to plot to.
*/
void Plot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] )
{
DoPlot( plotter, offset, fill, transform );
}
protected:
virtual LIB_DRAW_ITEM* DoGenCopy() = 0;
/**
* Provide the draw object specific comparison.
*
* This is called by the == operator.
* This is called by the == and < operators.
*
* The sort order is as follows:
* - Component alternate part (DeMorgan) number.
* - Component part number.
* - KICAD_T enum value.
* - Result of derived classes comparison.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const = 0;
virtual void DoOffset( const wxPoint& offset ) = 0;
......@@ -280,6 +297,8 @@ protected:
virtual void DoMove( const wxPoint& newPosition ) = 0;
virtual wxPoint DoGetPosition( void ) = 0;
virtual void DoMirrorHorizontal( const wxPoint& center ) = 0;
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] ) = 0;
};
......@@ -396,30 +415,43 @@ public:
int aColor, int aDrawMode, void* aData,
const int aTransformMatrix[2][2] );
void DrawPinSymbol( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& pin_pos, int orient,
int DrawMode, int Color = -1 );
void DrawPinTexts( WinEDA_DrawPanel* panel, wxDC* DC,
wxPoint& pin_pos, int orient,
int TextInside, bool DrawPinNum,
bool DrawPinName, int Color, int DrawMode );
void PlotPinTexts( PLOTTER *plotter,
wxPoint& pin_pos,
int orient,
int TextInside,
bool DrawPinNum,
bool DrawPinNameint,
int aWidth);
void DrawPinSymbol( WinEDA_DrawPanel* panel, wxDC* DC,
const wxPoint& pin_pos, int orient,
int DrawMode, int Color = -1 );
void DrawPinTexts( WinEDA_DrawPanel* panel, wxDC* DC,
wxPoint& pin_pos, int orient,
int TextInside, bool DrawPinNum,
bool DrawPinName, int Color, int DrawMode );
void PlotPinTexts( PLOTTER *plotter,
wxPoint& pin_pos,
int orient,
int TextInside,
bool DrawPinNum,
bool DrawPinNameint,
int aWidth );
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the pin draw object specific comparison.
*
* The sort order is as follows:
* - Pin number.
* - Pin name, case insensitive compare.
* - Pin horizontal (X) position.
* - Pin vertical (Y) position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
......@@ -490,12 +522,24 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the arc draw object specific comparison.
*
* The sort order is as follows:
* - Arc horizontal (X) position.
* - Arc vertical (Y) position.
* - Arc start angle.
* - Arc end angle.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
......@@ -562,12 +606,24 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the circle draw object specific comparison.
*
* The sort order is as follows:
* - Circle horizontal (X) position.
* - Circle vertical (Y) position.
* - Circle radius.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
......@@ -643,12 +699,26 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the text draw object specific comparison.
*
* The sort order is as follows:
* - Text string, case insensitive compare.
* - Text horizontal (X) position.
* - Text vertical (Y) position.
* - Text width.
* - Text height.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
......@@ -714,12 +784,25 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the rectangle draw object specific comparison.
*
* The sort order is as follows:
* - Rectangle horizontal (X) start position.
* - Rectangle vertical (Y) start position.
* - Rectangle horizontal (X) end position.
* - Rectangle vertical (Y) end position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
/**********************************/
......@@ -784,12 +867,25 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the line segment draw object specific comparison.
*
* The sort order is as follows:
* - Line segment horizontal (X) start position.
* - Line segment vertical (Y) start position.
* - Line segment horizontal (X) end position.
* - Line segment vertical (Y) end position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_Pos; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
......@@ -865,12 +961,23 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the ployline segment draw object specific comparison.
*
* The sort order for each polyline segment point is as follows:
* - Line segment point horizontal (X) position.
* - Line segment point vertical (Y) position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_PolyPoints[0]; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
/**********************************************************/
......@@ -904,7 +1011,7 @@ public:
virtual bool Save( FILE* aFile ) const;
virtual bool Load( char* line, wxString& errorMsg );
void AddPoint( const wxPoint& point );
void AddPoint( const wxPoint& point );
/** Function GetCornerCount
* @return the number of corners
......@@ -946,12 +1053,23 @@ public:
protected:
virtual LIB_DRAW_ITEM* DoGenCopy();
/**
* Provide the bezier curve draw object specific comparison.
*
* The sort order for each bezier curve segment point is as follows:
* - Bezier point horizontal (X) point position.
* - Bezier point vertical (Y) point position.
*/
virtual int DoCompare( const LIB_DRAW_ITEM& other ) const;
virtual void DoOffset( const wxPoint& offset );
virtual bool DoTestInside( EDA_Rect& rect );
virtual void DoMove( const wxPoint& newPosition );
virtual wxPoint DoGetPosition( void ) { return m_PolyPoints[0]; }
virtual void DoMirrorHorizontal( const wxPoint& center );
virtual void DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
const int transform[2][2] );
};
#endif // CLASSES_BODY_ITEMS_H
......@@ -107,7 +107,7 @@ void WinEDA_CreateCmpDialog::SetComponentData( LIB_COMPONENT & component )
WinEDA_LibeditFrame* parent = (WinEDA_LibeditFrame*) GetParent();
parent->SetShowDeMorgan( m_AsConvert->GetValue() );
component.m_UnitCount = m_PartsCount->GetSelection() + 1;
component.SetPartCount( m_PartsCount->GetSelection() + 1 );
component.m_Prefix.m_Text = m_Reference->GetValue();
if ( m_PinNameInside->GetValue() == FALSE)
component.m_TextInside = 0;
......@@ -122,7 +122,7 @@ void WinEDA_CreateCmpDialog::SetComponentData( LIB_COMPONENT & component )
/* Set the option "Units locked".
Obviously, cannot be TRUE if there is only one part */
component.m_UnitSelectionLocked = m_PartsAreLocked->GetValue();
if ( component.m_UnitCount <= 1 )
if ( component.GetPartCount() <= 1 )
component.m_UnitSelectionLocked = FALSE;
}
......
......@@ -625,7 +625,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel()
int choiceCount = unitChoice->GetCount();
// Remove non existing choices (choiceCount must be <= number for parts)
int unitcount = m_LibEntry ? m_LibEntry->m_UnitCount : 1;
int unitcount = m_LibEntry ? m_LibEntry->GetPartCount() : 1;
if( unitcount < 1 )
unitcount = 1;
......
......@@ -107,7 +107,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitBasicPanel()
m_ShowPinNumButt->SetValue( component->m_DrawPinNum );
m_ShowPinNameButt->SetValue( component->m_DrawPinName );
m_PinsNameInsideButt->SetValue( component->m_TextInside != 0 );
m_SelNumberOfUnits->SetValue( component->m_UnitCount );
m_SelNumberOfUnits->SetValue( component->GetPartCount() );
m_SetSkew->SetValue( component->m_TextInside );
m_OptionPower->SetValue( component->m_Options == ENTRY_POWER );
m_OptionPartsLocked->SetValue( component->m_UnitSelectionLocked );
......@@ -226,7 +226,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event )
/* Set the option "Units locked".
* Obviously, cannot be TRUE if there is only one part */
component->m_UnitSelectionLocked = m_OptionPartsLocked->GetValue();
if( component->m_UnitCount <= 1 )
if( component->GetPartCount() <= 1 )
component->m_UnitSelectionLocked = FALSE;
/* Update the footprint filter list */
......@@ -348,163 +348,57 @@ edited!" ),
}
/********************************************************************/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
/********************************************************************/
/* Routine de modification du nombre d'unites par package pour le
* composant courant;
/*
* Change the number of parts per package.
*/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
{
int OldNumUnits, ii, FlagDel = -1;
LIB_DRAW_ITEM* DrawItem, * NextDrawItem;
LIB_COMPONENT* component = m_Parent->GetComponent();
if( component == NULL )
return FALSE;
/* Si pas de changement: termine */
if( component->m_UnitCount == MaxUnit )
return FALSE;
if( component == NULL || component->GetPartCount() == MaxUnit
|| MaxUnit < 1 )
return false;
OldNumUnits = component->m_UnitCount;
if( OldNumUnits < 1 )
OldNumUnits = 1;
if( MaxUnit < component->GetPartCount()
&& !IsOK( this, _( "Delete extra parts from component?" ) ) )
return false;
component->m_UnitCount = MaxUnit;
/* Traitement des unites enlevees ou rajoutees */
if( OldNumUnits > component->m_UnitCount )
{
DrawItem = component->GetNextDrawItem();
for( ; DrawItem != NULL; DrawItem = NextDrawItem )
{
NextDrawItem = DrawItem->Next();
if( DrawItem->m_Unit > MaxUnit ) /* Item a effacer */
{
if( FlagDel < 0 )
{
if( IsOK( this, _( "Delete units" ) ) )
{
/* Si part selectee n'existe plus: selection 1ere unit */
if( m_Parent->GetUnit() > MaxUnit )
m_Parent->SetUnit( 1 );
FlagDel = 1;
}
else
{
FlagDel = 0;
MaxUnit = OldNumUnits;
component->m_UnitCount = MaxUnit;
return FALSE;
}
}
component->RemoveDrawItem( DrawItem );
}
}
return TRUE;
}
if( OldNumUnits < component->m_UnitCount )
{
DrawItem = component->GetNextDrawItem();
for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
{
/* Duplication des items pour autres elements */
if( DrawItem->m_Unit == 1 )
{
for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ )
{
NextDrawItem = DrawItem->GenCopy();
NextDrawItem->m_Unit = ii;
component->AddDrawItem( NextDrawItem );
}
}
}
}
return TRUE;
component->SetPartCount( MaxUnit );
return true;
}
/*****************************************************/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
/*****************************************************/
/* cr�e ou efface (selon option AsConvert) les �l�ments
* de la repr�sentation convertie d'un composant
/*
* Set or clear the component alternate body style ( DeMorgan ).
*/
bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
{
int FlagDel = 0;
LIB_DRAW_ITEM* DrawItem = NULL, * NextDrawItem;
LIB_COMPONENT* component = m_Parent->GetComponent();
if( m_Parent->GetShowDeMorgan() ) /* Representation convertie a creer */
{
/* Traitement des elements a ajouter ( pins seulement ) */
if( component )
DrawItem = component->GetNextDrawItem();
if( component == NULL
|| ( m_Parent->GetShowDeMorgan() == component->HasConversion() ) )
return false;
for( ; DrawItem != NULL; DrawItem = DrawItem->Next() )
{
/* Duplication des items pour autres elements */
if( DrawItem->Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
if( DrawItem->m_Convert == 1 )
{
if( FlagDel == 0 )
{
if( IsOK( this, _( "Create pins for convert items." ) ) )
FlagDel = 1;
else
{
if( IsOK( this, _( "Part as \"De Morgan\" anymore" ) ) )
return TRUE;
m_Parent->SetShowDeMorgan( false );
return FALSE;
}
}
NextDrawItem = DrawItem->GenCopy();
NextDrawItem->m_Convert = 2;
component->AddDrawItem( NextDrawItem );
}
}
if( m_Parent->GetShowDeMorgan()
&& !IsOK( this, _( "Add new pins for alternate body style \
( DeMorgan ) to component?" ) ) )
{
m_Parent->SetShowDeMorgan( false );
return false;
}
else /* Representation convertie a supprimer */
if( !m_Parent->GetShowDeMorgan()
&& !IsOK( this, _( "Delete alternate body style (DeMorgan) draw \
items from component?" ) ) )
{
/* Traitement des elements � supprimer */
if( component )
DrawItem = component->GetNextDrawItem();
for( ; DrawItem != NULL; DrawItem = NextDrawItem )
{
NextDrawItem = DrawItem->Next();
if( DrawItem->m_Convert > 1 ) /* Item a effacer */
{
if( FlagDel == 0 )
{
if( IsOK( this, _( "Delete Convert items" ) ) )
{
m_Parent->SetConvert( 1 );
FlagDel = 1;
}
else
{
m_Parent->SetShowDeMorgan( true );
return FALSE;
}
}
m_Parent->GetScreen()->SetModify();
component->RemoveDrawItem( DrawItem );
}
}
m_Parent->SetShowDeMorgan( true );
return false;
}
return TRUE;
component->SetConversion( m_Parent->GetShowDeMorgan() );
m_Parent->GetScreen()->SetModify();
return true;
}
......
......@@ -71,7 +71,7 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC )
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
m_Multiflag = 1;
}
}
......@@ -122,7 +122,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC )
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
flag = 1;
}
}
......@@ -266,7 +266,7 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC )
if( Entry != NULL )
{
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
flag = 1;
}
}
......@@ -304,7 +304,7 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC
if( Entry == NULL )
return;
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
flag = 1;
wxString ref = Cmp->GetRef(GetSheet());
......
......@@ -353,7 +353,7 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
if( LibEntry == NULL )
return;
m_UnitCount = LibEntry->m_UnitCount;
m_UnitCount = LibEntry->GetPartCount();
if( m_UnitCount <= 1 )
return;
......
......@@ -348,13 +348,13 @@ void WinEDA_LibeditFrame::UpdatePartSelectList()
if( m_SelpartBox->GetCount() != 0 )
m_SelpartBox->Clear();
if( m_component == NULL || m_component->m_UnitCount <= 1 )
if( m_component == NULL || m_component->GetPartCount() <= 1 )
{
m_SelpartBox->Append( wxEmptyString );
}
else
{
for( int i = 0; i < m_component->m_UnitCount; i++ )
for( int i = 0; i < m_component->GetPartCount(); i++ )
{
wxString msg;
msg.Printf( _( "Part %c" ), 'A' + i );
......@@ -425,7 +425,7 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event )
void WinEDA_LibeditFrame::OnUpdatePinByPin( wxUpdateUIEvent& event )
{
event.Enable( ( m_component != NULL )
&& ( ( m_component->m_UnitCount > 1 ) || m_showDeMorgan ) );
&& ( ( m_component->GetPartCount() > 1 ) || m_showDeMorgan ) );
if( m_HToolBar )
m_HToolBar->ToggleTool( event.GetId(), g_EditPinByPinIsOn );
......@@ -441,7 +441,7 @@ void WinEDA_LibeditFrame::OnUpdatePartNumber( wxUpdateUIEvent& event )
* so use the pointer to alias combobox to directly enable or disable.
*/
m_SelpartBox->Enable( m_component != NULL
&& m_component->m_UnitCount > 1 );
&& m_component->GetPartCount() > 1 );
}
......
......@@ -138,7 +138,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( EDA_BaseStruct* DrawList
continue;
// Multi parts per package: test if already visited:
if( Entry->m_UnitCount > 1 )
if( Entry->GetPartCount() > 1 )
{
bool found = false;
for( unsigned jj = 0; jj < s_ReferencesAlreadyFound.GetCount(); jj++ )
......@@ -158,7 +158,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( EDA_BaseStruct* DrawList
}
}
if( Entry->m_UnitCount <= 1 ) // One part per package
if( Entry->GetPartCount() <= 1 ) // One part per package
{
for( Pin = Entry->GetNextPin(); Pin != NULL;
Pin = Entry->GetNextPin( Pin ) )
......
......@@ -332,10 +332,10 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP,
_( "Convert" ), component_select_alternate_shape_xpm );
if( libComponent && ( libComponent->m_UnitCount >= 2 ) )
if( libComponent && ( libComponent->GetPartCount() >= 2 ) )
{
wxMenu* sel_unit_menu = new wxMenu; int ii;
for( ii = 0; ii < libComponent->m_UnitCount; ii++ )
for( ii = 0; ii < libComponent->GetPartCount(); ii++ )
{
wxString num_unit;
num_unit.Printf( _( "Unit %d %c" ), ii + 1,
......
......@@ -783,7 +783,7 @@ static void CreateImagePins( LibDrawPin* Pin, int unit, int convert,
Pin->GetParent()->AddDrawItem( NewPin );
}
for( ii = 1; ii <= Pin->GetParent()->m_UnitCount; ii++ )
for( ii = 1; ii <= Pin->GetParent()->GetPartCount(); ii++ )
{
if( ii == unit || Pin->m_Unit == 0 )
continue; /* Pin commune a toutes les unites */
......@@ -974,7 +974,7 @@ with pin %s at location (%d, %d)" ),
(const wxChar*) Pin->m_PinName,
Pin->m_Pos.x, -Pin->m_Pos.y );
if( m_component->m_UnitCount > 1 )
if( m_component->GetPartCount() > 1 )
{
aux_msg.Printf( _( " in part %c" ), 'A' + curr_pin->m_Unit );
msg += aux_msg;
......
......@@ -21,8 +21,6 @@ static void Plot_Hierarchical_PIN_Sheet( PLOTTER* plotter,
Hierarchical_PIN_Sheet_Struct* Struct );
static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem,
int FieldNumber, int IsMulti, int DrawMode );
static void PlotPinSymbol( PLOTTER* plotter, const wxPoint& pos,
int len, int orient, int Shape );
/***/
......@@ -51,200 +49,22 @@ static void PlotLibPart( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem )
/*************************************************/
/* Polt a component */
{
int ii, t1, t2, * Poly, orient;
LIB_COMPONENT* Entry;
int TransMat[2][2], Multi, convert;
EDA_Colors CharColor = UNSPECIFIED_COLOR;
wxPoint pos;
bool draw_bgfill = false;
int TransMat[2][2];
Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName );
if( Entry == NULL )
return;;
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
Multi = DrawLibItem->m_Multi;
convert = DrawLibItem->m_Convert;
for( LIB_DRAW_ITEM* DEntry = Entry->GetNextDrawItem();
DEntry != NULL; DEntry = DEntry->Next() )
{
/* Elimination des elements non relatifs a l'unite */
if( Multi && DEntry->m_Unit && (DEntry->m_Unit != Multi) )
continue;
if( convert && DEntry->m_Convert && (DEntry->m_Convert != convert) )
continue;
int thickness = DEntry->GetPenSize();
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
draw_bgfill = plotter->get_color_mode();
switch( DEntry->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
{
LibDrawArc* Arc = (LibDrawArc*) DEntry;
t1 = Arc->m_t1;
t2 = Arc->m_t2;
pos = TransformCoordinate( TransMat, Arc->m_Pos ) + DrawLibItem->m_Pos;
MapAngles( &t1, &t2, TransMat );
if( draw_bgfill && Arc->m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->arc( pos, -t2, -t1, Arc->m_Radius, FILLED_SHAPE, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->arc( pos, -t2, -t1, Arc->m_Radius, Arc->m_Fill,
thickness );
}
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
{
LibDrawCircle* Circle = (LibDrawCircle*) DEntry;
pos = TransformCoordinate( TransMat, Circle->m_Pos ) + DrawLibItem->m_Pos;
if( draw_bgfill && Circle->m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->circle( pos, Circle->m_Radius * 2, FILLED_SHAPE, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->circle( pos,
Circle->m_Radius * 2,
Circle->m_Fill,
thickness );
}
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
{
LibDrawText* Text = (LibDrawText*) DEntry;
/* The text orientation may need to be flipped if the
* transformation matrix causes xy axes to be flipped. */
t1 = (TransMat[0][0] != 0) ^ (Text->m_Orient != 0);
pos = TransformCoordinate( TransMat, Text->m_Pos ) + DrawLibItem->m_Pos;
plotter->text( pos, CharColor,
Text->m_Text,
t1 ? TEXT_ORIENT_HORIZ : TEXT_ORIENT_VERT,
Text->m_Size,
GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_CENTER,
thickness, Text->m_Italic, Text->m_Bold );
}
break;
case COMPONENT_RECT_DRAW_TYPE:
{
LibDrawSquare* Square = (LibDrawSquare*) DEntry;
pos = TransformCoordinate( TransMat, Square->m_Pos ) + DrawLibItem->m_Pos;
wxPoint end =
TransformCoordinate( TransMat, Square->m_End ) + DrawLibItem->m_Pos;
if( draw_bgfill && Square->m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->rect( pos, end, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->rect( pos, end, Square->m_Fill, thickness );
}
break;
case COMPONENT_PIN_DRAW_TYPE: /* Trace des Pins */
{
LibDrawPin* Pin = (LibDrawPin*) DEntry;
if( Pin->m_Attributs & PINNOTDRAW )
break;
/* Calcul de l'orientation reelle de la Pin */
orient = Pin->ReturnPinDrawOrient( TransMat );
/* compute Pin Pos */
pos = TransformCoordinate( TransMat, Pin->m_Pos ) + DrawLibItem->m_Pos;
/* Dessin de la pin et du symbole special associe */
thickness = Pin->GetPenSize();
plotter->set_current_line_width( thickness );
PlotPinSymbol( plotter, pos, Pin->m_PinLen, orient, Pin->m_PinShape );
Pin->PlotPinTexts( plotter, pos, orient,
Entry->m_TextInside,
Entry->m_DrawPinNum, Entry->m_DrawPinName,
thickness );
}
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
{
LibDrawPolyline* polyline = (LibDrawPolyline*) DEntry;
Poly = (int*) MyMalloc( sizeof(int) * 2 * polyline->GetCornerCount() );
for( ii = 0; ii < (int) polyline->GetCornerCount(); ii++ )
{
pos = polyline->m_PolyPoints[ii];
pos = TransformCoordinate( TransMat, pos ) + DrawLibItem->m_Pos;
Poly[ii * 2] = pos.x;
Poly[ii * 2 + 1] = pos.y;
}
if( draw_bgfill && polyline->m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->poly( ii, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->poly( ii, Poly, polyline->m_Fill, thickness );
MyFree( Poly );
}
break;
case COMPONENT_BEZIER_DRAW_TYPE:
{
LibDrawBezier* polyline = (LibDrawBezier*) DEntry;
Poly = (int*) MyMalloc( sizeof(int) * 2 * polyline->GetCornerCount() );
for( ii = 0; ii < (int) polyline->GetCornerCount(); ii++ )
{
pos = polyline->m_PolyPoints[ii];
pos = TransformCoordinate( TransMat, pos ) + DrawLibItem->m_Pos;
Poly[ii * 2] = pos.x;
Poly[ii * 2 + 1] = pos.y;
}
if( draw_bgfill && polyline->m_Fill == FILLED_WITH_BG_BODYCOLOR )
{
plotter->set_color( ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
plotter->poly( ii, Poly, FILLED_WITH_BG_BODYCOLOR, 0 );
}
plotter->set_color( ReturnLayerColor( LAYER_DEVICE ) );
plotter->poly( ii, Poly, polyline->m_Fill, thickness );
MyFree( Poly );
}
default:
D( printf( "Drawing Type=%d\n", DEntry->Type() ) );
}
/* Fin Switch */
}
/* Fin Boucle de dessin */
/* Trace des champs, avec placement et orientation selon orient. du
* composant
* Si la reference commence par # elle n'est pas tracee
*/
if( (Entry->m_Prefix.m_Attributs & TEXT_NO_VISIBLE) == 0 )
{
if( Entry->m_UnitCount > 1 )
PlotTextField( plotter, DrawLibItem, REFERENCE, 1, 0 );
else
PlotTextField( plotter, DrawLibItem, REFERENCE, 0, 0 );
}
memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) );
if( (Entry->m_Name.m_Attributs & TEXT_NO_VISIBLE) == 0 )
PlotTextField( plotter, DrawLibItem, VALUE, 0, 0 );
Entry->Plot( plotter, DrawLibItem->m_Multi, DrawLibItem->m_Convert,
DrawLibItem->m_Pos, TransMat );
for( ii = 2; ii < NUMBER_OF_FIELDS; ii++ )
for( int i = 0; i < NUMBER_OF_FIELDS; i++ )
{
PlotTextField( plotter, DrawLibItem, ii, 0, 0 );
PlotTextField( plotter, DrawLibItem, i, 0, 0 );
}
}
......@@ -396,8 +216,8 @@ static void PlotTextField( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem,
/**************************************************************************/
static void PlotPinSymbol( PLOTTER* plotter, const wxPoint& pos,
int len, int orient, int Shape )
void PlotPinSymbol( PLOTTER* plotter, const wxPoint& pos,
int len, int orient, int Shape )
/**************************************************************************/
/* Trace la pin du symbole en cours de trace
......
......@@ -111,7 +111,7 @@ void WinEDA_bodygraphics_PropertiesFrame::bodygraphics_PropertiesAccept( wxComma
break;
}
item->GetParent()->SortDrawItems();
item->GetParent()->GetDrawItemList().sort();
m_Parent->GetScreen()->SetModify();
......
......@@ -21,6 +21,8 @@
#include "libeditfrm.h"
#include "class_library.h"
#include <boost/foreach.hpp>
/*
* Read a component shape file (a symbol file *.sym )and add data (graphic
......@@ -32,7 +34,6 @@
void WinEDA_LibeditFrame::LoadOneSymbol( void )
{
LIB_COMPONENT* Component;
LIB_DRAW_ITEM* DrawEntry;
FILE* ImportFile;
wxString msg, err;
CMP_LIBRARY* Lib;
......@@ -93,24 +94,23 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void )
}
if( Lib->GetCount() > 1 )
DisplayError( this, _( "Warning: more than 1 part in Symbol File" ) );
DisplayError( this, _( "Warning: more than 1 part in symbol file." ) );
Component = (LIB_COMPONENT*) Lib->GetFirstEntry();
DrawEntry = Component->GetNextDrawItem();
LIB_DRAW_ITEM_LIST& drawList = Component->GetDrawItemList();
while( DrawEntry != NULL )
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList )
{
if( DrawEntry->m_Unit )
DrawEntry->m_Unit = m_unit;
if( DrawEntry->m_Convert )
DrawEntry->m_Convert = m_convert;
DrawEntry->m_Flags = IS_NEW;
DrawEntry->m_Selected = IS_SELECTED;
LIB_DRAW_ITEM* newItem = DrawEntry->GenCopy();
if( item.m_Unit )
item.m_Unit = m_unit;
if( item.m_Convert )
item.m_Convert = m_convert;
item.m_Flags = IS_NEW;
item.m_Selected = IS_SELECTED;
LIB_DRAW_ITEM* newItem = item.GenCopy();
newItem->SetParent( m_component );
m_component->AddDrawItem( newItem );
DrawEntry = DrawEntry->Next();
}
// Remove duplicated drawings:
......@@ -136,11 +136,10 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void )
*/
void WinEDA_LibeditFrame::SaveOneSymbol()
{
LIB_DRAW_ITEM* DrawEntry;
wxString msg;
FILE* ExportFile;
wxString msg;
FILE* ExportFile;
if( m_component->GetNextDrawItem() == NULL )
if( m_component->GetDrawItemList().empty() )
return;
/* Creation du fichier symbole */
......@@ -204,28 +203,23 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
/* Position / orientation / visibilite des champs */
m_component->m_Prefix.Save( ExportFile );
m_component->m_Name.Save( ExportFile );
DrawEntry = m_component->GetNextDrawItem();
if( DrawEntry )
LIB_DRAW_ITEM_LIST& drawList = m_component->GetDrawItemList();
fprintf( ExportFile, "DRAW\n" );
BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList )
{
fprintf( ExportFile, "DRAW\n" );
for( ; DrawEntry != NULL; DrawEntry = DrawEntry->Next() )
{
/* Elimination des elements non relatifs a l'unite */
if( m_unit && DrawEntry->m_Unit
&& ( DrawEntry->m_Unit != m_unit ) )
continue;
if( m_convert && DrawEntry->m_Convert
&& ( DrawEntry->m_Convert != m_convert ) )
continue;
DrawEntry->Save( ExportFile );
}
fprintf( ExportFile, "ENDDRAW\n" );
/* Elimination des elements non relatifs a l'unite */
if( m_unit && item.m_Unit && ( item.m_Unit != m_unit ) )
continue;
if( m_convert && item.m_Convert && ( item.m_Convert != m_convert ) )
continue;
item.Save( ExportFile );
}
fprintf( ExportFile, "ENDDRAW\n" );
fprintf( ExportFile, "ENDDEF\n" );
fclose( ExportFile );
}
......
......@@ -128,7 +128,7 @@ void WinEDA_ViewlibFrame::ReCreateHToolbar()
int jj = 1;
if( component )
jj = MAX( component->m_UnitCount, 1 );
jj = MAX( component->GetPartCount(), 1 );
SelpartBox->Clear();
for( ii = 0; ii < jj; ii++ )
{
......
......@@ -63,7 +63,14 @@ enum KICAD_T {
SCREEN_STRUCT_TYPE,
BLOCK_LOCATE_STRUCT_TYPE,
// Draw Items in library component
/*
* Draw items in library component.
*
* The order of these items effects the sort order for items inside the
* "DRAW/ENDDRAW" section of the component definition in a library file.
* If you add a new draw item, type, please make sure you add it so the
* sort order is logical.
*/
LIBCOMPONENT_STRUCT_TYPE,
COMPONENT_ARC_DRAW_TYPE,
COMPONENT_CIRCLE_DRAW_TYPE,
......@@ -71,9 +78,14 @@ enum KICAD_T {
COMPONENT_RECT_DRAW_TYPE,
COMPONENT_POLYLINE_DRAW_TYPE,
COMPONENT_LINE_DRAW_TYPE,
COMPONENT_BEZIER_DRAW_TYPE,
COMPONENT_PIN_DRAW_TYPE,
/*
* Fields are not saved inside the "DRAW/ENDDRAW". Add new draw item
* types before this line.
*/
COMPONENT_FIELD_DRAW_TYPE,
COMPONENT_BEZIER_DRAW_TYPE,
// End value
MAX_STRUCT_TYPE_ID
......
......@@ -207,7 +207,7 @@ public:
virtual void set_current_line_width( int width )
{
/* Handy override */
current_pen_width = pen_diameter;
current_pen_width = wxRound( pen_diameter );
};
virtual void set_default_line_width( int width ) {};
virtual void set_dash( bool dashed );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment