From b762f6aab7ad3338ca603cb4db2f53dee11a33d3 Mon Sep 17 00:00:00 2001 From: stambaughw Date: Tue, 29 Sep 2009 18:38:21 +0000 Subject: [PATCH] Component library editor improvements. * Eliminate external direct manipulation of component draw item pointer. * Add draw item remove, add, and locate methods to library component object. * Remove redundant locate pin, field, and draw item code. * Fix add new pin drawing bug that left initial pin draw in place. * Improved best zoom calculations for small components. * Library component bounding box calculation now includes fields. * Removed unnecessary header file "libcmp.h". * Fixed potential locate draw item bug in library editor hot key handler. --- common/sch_item_struct.cpp | 1 - eeschema/block.cpp | 30 +- eeschema/block_libedit.cpp | 109 +----- eeschema/class_BodyItem_Text.cpp | 8 + eeschema/class_libentry.cpp | 205 +++++++++-- eeschema/class_libentry.h | 50 +++ eeschema/class_libentry_fields.cpp | 8 + eeschema/class_libentry_fields.h | 17 +- eeschema/class_pin.cpp | 13 + eeschema/class_sch_component.cpp | 4 +- eeschema/classes_body_items.cpp | 79 +++++ eeschema/classes_body_items.h | 23 +- eeschema/controle.cpp | 15 +- eeschema/dangling_ends.cpp | 19 +- .../dialog_edit_component_in_schematic.cpp | 2 +- eeschema/edit_component_in_lib.cpp | 21 +- eeschema/getpart.cpp | 28 +- eeschema/hotkeys.cpp | 25 +- eeschema/libcmp.h | 23 -- eeschema/libedit.cpp | 4 +- eeschema/libedit_onleftclick.cpp | 73 ++-- eeschema/libedit_undo_redo.cpp | 6 +- eeschema/libeditfrm.h | 6 +- eeschema/libfield.cpp | 56 +-- eeschema/libframe.cpp | 6 + eeschema/locate.cpp | 254 +++----------- eeschema/netform.cpp | 118 +++---- eeschema/netlist.cpp | 44 ++- eeschema/pinedit-dialog.h | 5 +- eeschema/pinedit.cpp | 322 ++++++++---------- eeschema/plot.cpp | 2 +- eeschema/protos.h | 29 -- eeschema/symbdraw.cpp | 47 ++- eeschema/symbedit.cpp | 28 +- include/base_struct.h | 2 +- 35 files changed, 775 insertions(+), 907 deletions(-) delete mode 100644 eeschema/libcmp.h diff --git a/common/sch_item_struct.cpp b/common/sch_item_struct.cpp index ea0b818ceb..93eb366281 100644 --- a/common/sch_item_struct.cpp +++ b/common/sch_item_struct.cpp @@ -13,7 +13,6 @@ #include "program.h" #include "general.h" -#include "libcmp.h" #include "protos.h" /* Constructor and destructor for SCH_ITEM */ diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 27ab0d4d82..407cbe87cc 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -861,51 +861,47 @@ static LIB_DRAW_ITEM* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem, */ { LIB_COMPONENT* Entry; - static LIB_DRAW_ITEM* NextItem; + static LibDrawPin* NextPin; static int Multi, convert, TransMat[2][2]; - LIB_DRAW_ITEM* DEntry; int orient; LibDrawPin* Pin; static wxPoint CmpPosition; if( aDrawLibItem ) { - NextItem = NULL; + NextPin = NULL; Entry = CMP_LIBRARY::FindLibraryComponent( aDrawLibItem->m_ChipName ); if( Entry == NULL ) return NULL; - DEntry = Entry->m_Drawings; + Pin = Entry->GetNextPin(); Multi = aDrawLibItem->m_Multi; convert = aDrawLibItem->m_Convert; CmpPosition = aDrawLibItem->m_Pos; memcpy( TransMat, aDrawLibItem->m_Transform, sizeof(TransMat) ); } else - DEntry = NextItem; + Pin = NextPin; - for( ; DEntry != NULL; DEntry = DEntry->Next() ) + for( ; Pin != NULL; NextPin = Entry->GetNextPin( Pin ) ) { - /* 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; - if( DEntry->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; + wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE ); - Pin = (LibDrawPin*) DEntry; + /* Elimination des elements non relatifs a l'unite */ + if( Multi && Pin->m_Unit && ( Pin->m_Unit != Multi ) ) + continue; + if( convert && Pin->m_Convert && ( Pin->m_Convert != convert ) ) + continue; /* Calcul de l'orientation reelle de la Pin */ orient = Pin->ReturnPinDrawOrient( TransMat ); /* Calcul de la position du point de reference */ aPosition = TransformCoordinate( TransMat, Pin->m_Pos ) + CmpPosition; - NextItem = DEntry->Next(); - return DEntry; + return Pin; } - NextItem = NULL; + NextPin = NULL; return NULL; } diff --git a/eeschema/block_libedit.cpp b/eeschema/block_libedit.cpp index ba63de495f..68ea7bc43b 100644 --- a/eeschema/block_libedit.cpp +++ b/eeschema/block_libedit.cpp @@ -19,7 +19,6 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); -static void MirrorMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ); /* @@ -77,6 +76,7 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC ) { int ItemCount = 0; int MustDoPlace = 0; + wxPoint pt; if( GetScreen()->m_BlockLocate.GetCount() ) { @@ -147,7 +147,9 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC ) g_EditPinByPinIsOn ); if( ItemCount ) SaveCopyInUndoList( m_component ); - MirrorMarkedItems( m_component, GetScreen()->m_BlockLocate.Centre() ); + pt = GetScreen()->m_BlockLocate.Centre(); + pt.y *= -1; + m_component->MirrorSelectedItemsH( pt ); break; case BLOCK_ZOOM: /* Window Zoom */ @@ -191,7 +193,7 @@ int WinEDA_LibeditFrame::HandleBlockEnd( wxDC* DC ) void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC ) { bool err = FALSE; - wxPoint offset; + wxPoint pt; if( DrawPanel->ManageCurseur == NULL ) { @@ -212,18 +214,18 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC ) case BLOCK_PRESELECT_MOVE: /* Move with preselection list*/ GetScreen()->m_BlockLocate.ClearItemsList(); SaveCopyInUndoList( m_component ); - offset = GetScreen()->m_BlockLocate.m_MoveVector; - offset.y *= -1; - m_component->MoveSelectedItems( offset ); + pt = GetScreen()->m_BlockLocate.m_MoveVector; + pt.y *= -1; + m_component->MoveSelectedItems( pt ); DrawPanel->Refresh( TRUE ); break; case BLOCK_COPY: /* Copy */ GetScreen()->m_BlockLocate.ClearItemsList(); SaveCopyInUndoList( m_component ); - offset = GetScreen()->m_BlockLocate.m_MoveVector; - offset.y *= -1; - m_component->CopySelectedItems( offset ); + pt = GetScreen()->m_BlockLocate.m_MoveVector; + pt.y *= -1; + m_component->CopySelectedItems( pt ); break; case BLOCK_PASTE: /* Paste (recopie du dernier bloc sauve */ @@ -232,7 +234,9 @@ void WinEDA_LibeditFrame::HandleBlockPlace( wxDC* DC ) case BLOCK_MIRROR_Y: /* Invert by popup menu, from block move */ SaveCopyInUndoList( m_component ); - MirrorMarkedItems( m_component, GetScreen()->m_BlockLocate.Centre() ); + pt = GetScreen()->m_BlockLocate.Centre(); + pt.y *= -1; + m_component->MirrorSelectedItemsH( pt ); break; case BLOCK_ZOOM: // Handled by HandleBlockEnd @@ -305,88 +309,3 @@ void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) g_XorMode, -1, DefaultTransformMatrix, true, true, true ); } - - -/* - * Mirror marked items, refer to a Vertical axis at position offset - */ -void MirrorMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ) -{ -#define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x; - LIB_DRAW_ITEM* item; - - if( LibEntry == NULL ) - return; - - offset.y = -offset.y; // Y axis for lib items is Down to Up: reverse y offset value - item = LibEntry->m_Drawings; - for( ; item != NULL; item = item->Next() ) - { - if( item->m_Selected == 0 ) - continue; - - switch( item->Type() ) - { - case COMPONENT_PIN_DRAW_TYPE: - SETMIRROR( ( (LibDrawPin*) item )->m_Pos.x ); - - switch( ( (LibDrawPin*) item )->m_Orient ) - { - case PIN_RIGHT: - ( (LibDrawPin*) item )->m_Orient = PIN_LEFT; - break; - - case PIN_LEFT: - ( (LibDrawPin*) item )->m_Orient = PIN_RIGHT; - break; - - case PIN_UP: - case PIN_DOWN: - break; - } - - break; - - case COMPONENT_ARC_DRAW_TYPE: - { - SETMIRROR( ( (LibDrawArc*) item )->m_Pos.x ); - SETMIRROR( ( (LibDrawArc*) item )->m_ArcStart.x ); - SETMIRROR( ( (LibDrawArc*) item )->m_ArcEnd.x ); - EXCHG( ( (LibDrawArc*) item )->m_ArcStart, - ( (LibDrawArc*) item )->m_ArcEnd ); - break; - } - - case COMPONENT_CIRCLE_DRAW_TYPE: - SETMIRROR( ( (LibDrawCircle*) item )->m_Pos.x ); - break; - - case COMPONENT_RECT_DRAW_TYPE: - SETMIRROR( ( (LibDrawSquare*) item )->m_Pos.x ); - SETMIRROR( ( (LibDrawSquare*) item )->m_End.x ); - break; - - case COMPONENT_POLYLINE_DRAW_TYPE: - { - unsigned ii, imax = ( (LibDrawPolyline*) item )->GetCornerCount(); - for( ii = 0; ii < imax; ii ++ ) - { - SETMIRROR( ( (LibDrawPolyline*) item )->m_PolyPoints[ii].x ); - } - } - break; - - case COMPONENT_LINE_DRAW_TYPE: - break; - - case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: - SETMIRROR( ( (LibDrawText*) item )->m_Pos.x ); - break; - - default: - break; - } - - item->m_Flags = item->m_Selected = 0; - } -} diff --git a/eeschema/class_BodyItem_Text.cpp b/eeschema/class_BodyItem_Text.cpp index c5abe43afa..bf952318df 100644 --- a/eeschema/class_BodyItem_Text.cpp +++ b/eeschema/class_BodyItem_Text.cpp @@ -226,6 +226,14 @@ void LibDrawText::DoMove( const wxPoint& newPosition ) } +void LibDrawText::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 9b274ecab7..d6b0b20394 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -326,7 +326,6 @@ LIB_COMPONENT::LIB_COMPONENT( const LIB_COMPONENT& component, LibDrawField* oldField; LibDrawField* newField; - m_Prefix = component.m_Prefix; m_AliasList = component.m_AliasList; m_FootprintList = component.m_FootprintList; @@ -336,6 +335,7 @@ 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 ); @@ -505,24 +505,83 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item, item->Draw( panel, dc, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransformMatrix ); - if( m_Drawings == item ) + if( item->Type() != COMPONENT_FIELD_DRAW_TYPE ) { - m_Drawings = item->Next(); - SAFE_DELETE( item ); + if( m_Drawings == item ) + { + m_Drawings = item->Next(); + SAFE_DELETE( item ); + return; + } + + while( prevItem ) + { + if( prevItem->Next() == item ) + { + prevItem->SetNext( item->Next() ); + SAFE_DELETE( item ); + break; + } + + prevItem = prevItem->Next(); + } + } + else + { + LibDrawField* field; + + for( field = m_Fields; field != NULL; field = field->Next() ) + { + if( field == item ) + { + m_Fields.Remove( field ); + delete field; + break; + } + } + } +} + + +void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* item ) +{ + wxASSERT( item != NULL ); + + if( m_Drawings == NULL ) + { + m_Drawings = item; + item->SetNext( NULL ); return; } - while( prevItem ) - { - if( prevItem->Next() == item ) - { - prevItem->SetNext( item->Next() ); - SAFE_DELETE( item ); - break; - } + LIB_DRAW_ITEM* i = m_Drawings; - prevItem = prevItem->Next(); + while( i->Next() != NULL ) + i = i->Next(); + + i->SetNext( item ); + item->SetNext( NULL ); + SortDrawItems(); +} + + +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(); + + LIB_DRAW_ITEM* i = ( item == NULL ) ? m_Drawings : item->Next(); + + while( i != NULL ) + { + if( i->Type() == type ) + return i; + + i = i->Next(); } + + return i; } @@ -535,7 +594,7 @@ void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* item, bool LIB_COMPONENT::Save( FILE* aFile ) { LIB_DRAW_ITEM* DrawEntry; - LibDrawField* Field; + LibDrawField* Field; /* Sort just in clase sorting was not done properly. */ SortDrawItems(); @@ -940,7 +999,7 @@ void LIB_COMPONENT::SortDrawItems() if( Entry == NULL ) return; /* Pas d'alias pour ce composant */ - /* calcul du nombre d'items */ + for( nbitems = 0; Entry != NULL; Entry = Entry->Next() ) nbitems++; @@ -978,23 +1037,25 @@ void LIB_COMPONENT::SortDrawItems() /**********************************************************************/ EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert ) { - LIB_DRAW_ITEM* DrawEntry; - EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); + LIB_DRAW_ITEM* item; + EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); - for( DrawEntry = m_Drawings; DrawEntry != NULL; - DrawEntry = DrawEntry->Next() ) + for( item = m_Drawings; item != NULL; item = item->Next() ) { - if( DrawEntry->m_Unit > 0 ) // The item is non common to units - if( ( m_UnitCount > 1 ) && ( Unit > 0 ) - && ( Unit != DrawEntry->m_Unit ) ) - continue; - if( DrawEntry->m_Convert > 0 ) // The item is not common to all convert - if( ( Convert > 0 ) && ( Convert != DrawEntry->m_Convert ) ) - continue; + 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 ) ) ) + continue; - bBox.Merge( DrawEntry->GetBoundingBox() ); + bBox.Merge( item->GetBoundingBox() ); } + bBox.Merge( m_Name.GetBoundingBox() ); + bBox.Merge( m_Prefix.GetBoundingBox() ); + return bBox; } @@ -1172,6 +1233,22 @@ 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; + + m_Name.m_Flags = 0; + m_Prefix.m_Flags = 0; + + for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() ) + field->m_Flags = 0; +} + + int LIB_COMPONENT::SelectItems( EDA_Rect& rect, int unit, int convert, bool editPinByPin ) { @@ -1318,3 +1395,77 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& offset ) MoveSelectedItems( offset ); SortDrawItems(); } + +void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& center ) +{ + LIB_DRAW_ITEM* item; + LibDrawField* field; + + for( item = m_Drawings; item != NULL; item = item->Next() ) + { + if( item->m_Selected == 0 ) + continue; + + item->SetOffset( center ); + item->m_Flags = item->m_Selected = 0; + } + + if( m_Name.m_Selected ) + { + m_Name.SetOffset( center ); + m_Name.m_Flags = m_Name.m_Selected = 0; + } + + if( m_Prefix.m_Selected ) + { + m_Prefix.SetOffset( center ); + m_Prefix.m_Flags = m_Prefix.m_Selected = 0; + } + + for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() ) + { + if( field->m_Selected ) + { + field->SetOffset( center ); + field->m_Flags = field->m_Selected = 0; + } + } + + SortDrawItems(); +} + + +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() ) + { + 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( type == COMPONENT_FIELD_DRAW_TYPE || type == TYPE_NOT_INIT ) + { + if( m_Name.HitTest( pt ) ) + return &m_Name; + if( m_Prefix.HitTest( pt ) ) + return &m_Prefix; + + for( field = m_Fields.GetFirst(); field != NULL; field = field->Next() ) + { + if( field->HitTest( pt ) ) + return field; + } + } + + + return NULL; +} diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 2fd69e43ad..641675a00e 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -204,6 +204,13 @@ public: bool showPinText = true, bool drawFields = true, bool onlySelected = false ); + /** + * Add a new draw item to the draw object list. + * + * @param item - New draw object to add to component. + */ + void AddDrawItem( LIB_DRAW_ITEM* item ); + /** * Remove draw item from list. * @@ -215,6 +222,23 @@ public: WinEDA_DrawPanel* panel = NULL, wxDC* dc = NULL ); + /** + * Return the next draw object pointer. + * + * @param item - Pointer to the current draw item. Setting item NULL + * with return the first item of type in the list. + * + */ + + LIB_DRAW_ITEM* GetNextDrawItem( LIB_DRAW_ITEM* item = NULL, + KICAD_T type = TYPE_NOT_INIT ); + + LibDrawPin* GetNextPin( LibDrawPin* item = NULL ) + { + return (LibDrawPin*) GetNextDrawItem( (LIB_DRAW_ITEM*) item, + COMPONENT_PIN_DRAW_TYPE ); + } + /** * Move the component offset. * @@ -249,6 +273,11 @@ public: return m_AliasList.Index( name ) != wxNOT_FOUND; } + /** + * Clears the status flag all draw objects in this component. + */ + void ClearStatus( void ); + /** * Checks all draw objects of component to see if they are with block. * @@ -294,6 +323,27 @@ public: * make sense in this context. */ void CopySelectedItems( const wxPoint& offset ); + + /** + * Horizontally (X axis) mirror selected draw items about a point. + * + * @param center - Center point to mirror around. + */ + void MirrorSelectedItemsH( const wxPoint& center ); + + /** + * Locate a draw object. + * + * @param unit - Unit number of draw item. + * @param convert - Body style of draw item. + * @param type - Draw object type, set to 0 to search for any type. + * @param pt - Coordinate for hit testing. + * + * @return LIB_DRAW_ITEM - Pointer the the draw object if found. + * Otherwise NULL. + */ + LIB_DRAW_ITEM* LocateDrawItem( int unit, int convert, KICAD_T type, + const wxPoint& pt ); }; diff --git a/eeschema/class_libentry_fields.cpp b/eeschema/class_libentry_fields.cpp index dae6327d2f..f7efcf1fb1 100644 --- a/eeschema/class_libentry_fields.cpp +++ b/eeschema/class_libentry_fields.cpp @@ -437,6 +437,14 @@ void LibDrawField::DoMove( const wxPoint& newPosition ) } +void LibDrawField::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; +} + + /* * If the field is the reference, return reference like schematic, * i.e U -> U? or U?A or the field text for others diff --git a/eeschema/class_libentry_fields.h b/eeschema/class_libentry_fields.h index 720dff22a3..d11e106e1f 100644 --- a/eeschema/class_libentry_fields.h +++ b/eeschema/class_libentry_fields.h @@ -74,6 +74,13 @@ public: int aColor, int aDrawMode, void* aData, const int aTransformMatrix[2][2] ); + /** + * Return the bounding rectangle of the field text. + * + * @return EDA_Rect - Bounding rectangle. + */ + virtual EDA_Rect GetBoundingBox() { return GetTextBox(); } + /** * Function HitTest * tests if the given wxPoint is within the bounds of this object. @@ -82,13 +89,16 @@ public: */ bool HitTest( const wxPoint& refPos ); - /** Function HitTest + /** + * Function HitTest * @return true if the point aPosRef is near this object * @param aPosRef = a wxPoint to test - * @param aThreshold = max distance to this object (usually the half thickness of a line) + * @param aThreshold = max distance to this object (usually the half + * thickness of a line) * @param aTransMat = the transform matrix */ - virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] ); + virtual bool HitTest( wxPoint aPosRef, int aThreshold, + const int aTransMat[2][2] ); void operator=( const LibDrawField& field ) { @@ -127,6 +137,7 @@ protected: 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 ); }; #endif // CLASS_LIBENTRY_FIELDS_H diff --git a/eeschema/class_pin.cpp b/eeschema/class_pin.cpp index bc2f5b8e54..c1e9ef0b56 100644 --- a/eeschema/class_pin.cpp +++ b/eeschema/class_pin.cpp @@ -1113,6 +1113,19 @@ void LibDrawPin::DoMove( const wxPoint& newPosition ) } +void LibDrawPin::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; + + if( m_Orient == PIN_RIGHT ) + m_Orient = PIN_LEFT; + else if( m_Orient == PIN_LEFT ) + m_Orient = PIN_RIGHT; +} + + /** Function LibDrawPin::DisplayInfo * Displays info (pin num and name, orientation ... * on the Info window diff --git a/eeschema/class_sch_component.cpp b/eeschema/class_sch_component.cpp index b94a1eda18..82ae05ff39 100644 --- a/eeschema/class_sch_component.cpp +++ b/eeschema/class_sch_component.cpp @@ -45,8 +45,8 @@ void CreateDummyCmp() Text->m_Size.x = Text->m_Size.y = 150; Text->m_Text = wxT( "??" ); - DummyCmp->m_Drawings = Square; - Square->SetNext( Text ); + DummyCmp->AddDrawItem( Square ); + DummyCmp->AddDrawItem( Text ); } diff --git a/eeschema/classes_body_items.cpp b/eeschema/classes_body_items.cpp index 1199c0a41a..c58ffeabf3 100644 --- a/eeschema/classes_body_items.cpp +++ b/eeschema/classes_body_items.cpp @@ -311,6 +311,21 @@ void LibDrawArc::DoMove( const wxPoint& newPosition ) } +void LibDrawArc::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; + m_ArcStart.x -= center.x; + m_ArcStart.x *= -1; + m_ArcStart.x += center.x; + m_ArcEnd.x -= center.x; + m_ArcEnd.x *= -1; + m_ArcEnd.x += center.x; + EXCHG( m_ArcStart, m_ArcEnd ); +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ @@ -608,6 +623,14 @@ void LibDrawCircle::DoMove( const wxPoint& newPosition ) } +void LibDrawCircle::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ @@ -793,6 +816,17 @@ void LibDrawSquare::DoMove( const wxPoint& newPosition ) } +void LibDrawSquare::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; + m_End.x -= center.x; + m_End.x *= -1; + m_End.x += center.x; +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ @@ -1006,6 +1040,17 @@ void LibDrawSegment::DoMove( const wxPoint& newPosition ) } +void LibDrawSegment::DoMirrorHorizontal( const wxPoint& center ) +{ + m_Pos.x -= center.x; + m_Pos.x *= -1; + m_Pos.x += center.x; + m_End.x -= center.x; + m_End.x *= -1; + m_End.x += center.x; +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ @@ -1255,6 +1300,19 @@ void LibDrawPolyline::DoMove( const wxPoint& newPosition ) } +void LibDrawPolyline::DoMirrorHorizontal( const wxPoint& center ) +{ + size_t i, imax = m_PolyPoints.size(); + + for( i = 0; i < imax; i++ ) + { + m_PolyPoints[i].x -= center.x; + m_PolyPoints[i].x *= -1; + m_PolyPoints[i].x += center.x; + } +} + + void LibDrawPolyline::AddPoint( const wxPoint& point ) { m_PolyPoints.push_back( point ); @@ -1580,6 +1638,27 @@ void LibDrawBezier::DoMove( const wxPoint& newPosition ) } +void LibDrawBezier::DoMirrorHorizontal( const wxPoint& center ) +{ + size_t i, imax = m_PolyPoints.size(); + + for( i = 0; i < imax; i++ ) + { + m_PolyPoints[i].x -= center.x; + m_PolyPoints[i].x *= -1; + m_PolyPoints[i].x += center.x; + } + + imax = m_BezierPoints.size(); + for( i = 0; i < imax; i++ ) + { + m_BezierPoints[i].x -= center.x; + m_BezierPoints[i].x *= -1; + m_BezierPoints[i].x += center.x; + } +} + + /** Function GetPenSize * @return the size of the "pen" that be used to draw or plot this item */ diff --git a/eeschema/classes_body_items.h b/eeschema/classes_body_items.h index bf77575cd0..256fb34ab4 100644 --- a/eeschema/classes_body_items.h +++ b/eeschema/classes_body_items.h @@ -114,7 +114,9 @@ public: LIB_DRAW_ITEM( const LIB_DRAW_ITEM& item ); virtual ~LIB_DRAW_ITEM() { } - /** Function Draw (virtual pure) + /** + * Function Draw (virtual pure) + * * Draw A body item * @param aPanel = DrawPanel to use (can be null) mainly used for clipping * purposes @@ -241,6 +243,16 @@ public: */ wxPoint GetPosition( void ) { return DoGetPosition(); } + /** + * Mirror the draw object along the horizontal (X) axis about a point. + * + * @param center - Point to mirror around. + */ + void MirrorHorizontal( const wxPoint& center ) + { + DoMirrorHorizontal( center ); + } + protected: virtual LIB_DRAW_ITEM* DoGenCopy() = 0; @@ -254,6 +266,7 @@ protected: virtual bool DoTestInside( EDA_Rect& rect ) = 0; virtual void DoMove( const wxPoint& newPosition ) = 0; virtual wxPoint DoGetPosition( void ) = 0; + virtual void DoMirrorHorizontal( const wxPoint& center ) = 0; }; @@ -387,6 +400,7 @@ protected: 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 ); }; @@ -462,6 +476,7 @@ protected: 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 ); }; @@ -533,6 +548,7 @@ protected: 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 ); }; @@ -611,6 +627,7 @@ protected: 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 ); }; @@ -681,6 +698,7 @@ protected: 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 ); }; /**********************************/ @@ -750,6 +768,7 @@ protected: 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 ); }; @@ -830,6 +849,7 @@ protected: 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 ); }; /**********************************************************/ @@ -910,6 +930,7 @@ protected: 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 ); }; #endif // CLASSES_BODY_ITEMS_H diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index f6856e5e16..79c127a7cd 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -215,9 +215,8 @@ SCH_ITEM* WinEDA_SchematicFrame:: SchematicGeneralLocateAndDisplay( const wxPoin } -/*************************************************************************************/ -void WinEDA_SchematicFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) -/*************************************************************************************/ +void WinEDA_SchematicFrame::GeneralControle( wxDC* DC, + wxPoint MousePositionInPixels ) { wxRealPoint delta; SCH_SCREEN* screen = GetScreen(); @@ -309,11 +308,10 @@ void WinEDA_SchematicFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPi } -/*************************************************************************************/ -void WinEDA_LibeditFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) -/*************************************************************************************/ +void WinEDA_LibeditFrame::GeneralControle( wxDC* DC, + wxPoint MousePositionInPixels ) { - wxRealPoint delta; + wxRealPoint delta; SCH_SCREEN* screen = GetScreen(); wxPoint curpos, oldpos; int hotkey = 0; @@ -402,11 +400,10 @@ void WinEDA_LibeditFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixe } -/*****************************************************************************/ void WinEDA_ViewlibFrame::GeneralControle( wxDC* DC, wxPoint MousePositionInPixels ) { - wxRealPoint delta; + wxRealPoint delta; SCH_SCREEN* screen = GetScreen(); wxPoint curpos, oldpos; int hotkey = 0; diff --git a/eeschema/dangling_ends.cpp b/eeschema/dangling_ends.cpp index 0f02db7b46..785a894c3c 100644 --- a/eeschema/dangling_ends.cpp +++ b/eeschema/dangling_ends.cpp @@ -392,20 +392,17 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList ) if( Entry == NULL ) break; - LIB_DRAW_ITEM* DrawLibItem = Entry->m_Drawings; - for( ; DrawLibItem != NULL; DrawLibItem = DrawLibItem->Next() ) + for( LibDrawPin* Pin = Entry->GetNextPin(); Pin != NULL; + Pin = Entry->GetNextPin( Pin ) ) { - if( DrawLibItem->Type() != COMPONENT_PIN_DRAW_TYPE ) + wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE ); + + if( Pin->m_Unit && STRUCT->m_Multi + && ( STRUCT->m_Multi != Pin->m_Unit ) ) continue; - LibDrawPin* Pin = (LibDrawPin*) DrawLibItem; - - if( Pin->m_Unit && DrawLibItem->m_Unit - && (DrawLibItem->m_Unit != Pin->m_Unit) ) - continue; - - if( Pin->m_Convert && DrawLibItem->m_Convert - && (DrawLibItem->m_Convert != Pin->m_Convert) ) + if( Pin->m_Convert && STRUCT->m_Convert + && ( STRUCT->m_Convert != Pin->m_Convert ) ) continue; item = new DanglingEndHandle( PIN_END ); diff --git a/eeschema/dialog_edit_component_in_schematic.cpp b/eeschema/dialog_edit_component_in_schematic.cpp index 3dbb88e76f..c459bdde08 100644 --- a/eeschema/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialog_edit_component_in_schematic.cpp @@ -680,7 +680,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyOptionsToPanel() convertCheckBox->SetValue( true ); } - if( m_LibEntry == NULL || LookForConvertPart( m_LibEntry ) <= 1 ) + if( m_LibEntry == NULL || !m_LibEntry->HasConversion() ) { convertCheckBox->Enable( false ); } diff --git a/eeschema/edit_component_in_lib.cpp b/eeschema/edit_component_in_lib.cpp index 8bfae6d962..5075e67819 100644 --- a/eeschema/edit_component_in_lib.cpp +++ b/eeschema/edit_component_in_lib.cpp @@ -377,7 +377,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit ) /* Traitement des unites enlevees ou rajoutees */ if( OldNumUnits > component->m_UnitCount ) { - DrawItem = component->m_Drawings; + DrawItem = component->GetNextDrawItem(); for( ; DrawItem != NULL; DrawItem = NextDrawItem ) { NextDrawItem = DrawItem->Next(); @@ -410,7 +410,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit ) if( OldNumUnits < component->m_UnitCount ) { - DrawItem = component->m_Drawings; + DrawItem = component->GetNextDrawItem(); for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) { /* Duplication des items pour autres elements */ @@ -419,13 +419,13 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit ) for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ ) { NextDrawItem = DrawItem->GenCopy(); - NextDrawItem->SetNext( component->m_Drawings ); - component->m_Drawings = NextDrawItem; NextDrawItem->m_Unit = ii; + component->AddDrawItem( NextDrawItem ); } } } } + return TRUE; } @@ -446,7 +446,8 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() { /* Traitement des elements a ajouter ( pins seulement ) */ if( component ) - DrawItem = component->m_Drawings; + DrawItem = component->GetNextDrawItem(); + for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) { /* Duplication des items pour autres elements */ @@ -456,7 +457,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() { if( FlagDel == 0 ) { - if( IsOK( this, _( "Create pins for Convert items" ) ) ) + if( IsOK( this, _( "Create pins for convert items." ) ) ) FlagDel = 1; else { @@ -467,10 +468,10 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() return FALSE; } } + NextDrawItem = DrawItem->GenCopy(); - NextDrawItem->SetNext( component->m_Drawings ); - component->m_Drawings = NextDrawItem; - NextDrawItem->m_Convert = 2; + NextDrawItem->m_Convert = 2; + component->AddDrawItem( NextDrawItem ); } } } @@ -478,7 +479,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert() { /* Traitement des elements � supprimer */ if( component ) - DrawItem = component->m_Drawings; + DrawItem = component->GetNextDrawItem(); for( ; DrawItem != NULL; DrawItem = NextDrawItem ) { NextDrawItem = DrawItem->Next(); diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 6ce40b237f..d8651237c4 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -402,7 +402,7 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent, if( LibEntry == NULL ) return; - if( ( ii = LookForConvertPart( LibEntry ) ) < 2 ) + if( !LibEntry->HasConversion() ) { DisplayError( this, wxT( "No convert found" ) ); return; @@ -430,32 +430,6 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent, } -/* - * Retourne la plus grande valeur trouvee dans la liste des elements - * "drawings" du composant LibEntry, pour le membre .Convert - * Si il n'y a pas de representation type "convert", la valeur - * retournee est 0 ou 1 - * Si il y a une representation type "convert", - * la valeur retournee est > 1 (typiquement 2) - */ -int LookForConvertPart( LIB_COMPONENT* LibEntry ) -{ - int ii; - LIB_DRAW_ITEM* DrawLibEntry; - - DrawLibEntry = LibEntry->m_Drawings; - ii = 0; - while( DrawLibEntry ) - { - if( ii < DrawLibEntry->m_Convert ) - ii = DrawLibEntry->m_Convert; - DrawLibEntry = DrawLibEntry->Next(); - } - - return ii; -} - - void WinEDA_SchematicFrame::StartMovePart( SCH_COMPONENT* Component, wxDC* DC ) { diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index b00c95439b..61aede0b5f 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -471,16 +471,13 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, cmd.SetEventObject( this ); + wxPoint MousePos = GetScreen()->m_MousePosition; bool ItemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->m_Flags; if( hotkey == 0 ) return; - wxPoint MousePos = GetScreen()->m_MousePosition; - - LIB_DRAW_ITEM* DrawEntry = LocateItemUsingCursor(); - // Remap the control key Ctrl A (0x01) to GR_KB_CTRL + 'A' (easier to // handle...) if( (hotkey & GR_KB_CTRL) != 0 ) @@ -564,18 +561,16 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, break; case HK_EDIT_PIN: - if( DrawEntry ) - m_drawItem = DrawEntry; - if( m_drawItem ) - { - if( m_drawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) - InstallPineditFrame( this, DC, MousePos ); - } + m_drawItem = LocateItemUsingCursor(); + + if( m_drawItem && m_drawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) + InstallPineditFrame( this, DC, MousePos ); + break; case HK_DELETE_PIN: - if( DrawEntry ) - m_drawItem = DrawEntry; + m_drawItem = LocateItemUsingCursor(); + if( m_drawItem ) { wxCommandEvent evt; @@ -585,8 +580,8 @@ void WinEDA_LibeditFrame::OnHotKey( wxDC* DC, int hotkey, break; case HK_MOVE_PIN: - if( DrawEntry ) - m_drawItem = DrawEntry; + m_drawItem = LocateItemUsingCursor(); + if( m_drawItem ) { wxCommandEvent evt; diff --git a/eeschema/libcmp.h b/eeschema/libcmp.h deleted file mode 100644 index 1d459b4fd2..0000000000 --- a/eeschema/libcmp.h +++ /dev/null @@ -1,23 +0,0 @@ -/*****************************************************************/ -/* Headers for library definition and lib component definitions */ -/*****************************************************************/ - -#ifndef LIBCMP_H -#define LIBCMP_H - - -enum LocateDrawStructType -{ - LOCATE_COMPONENT_ARC_DRAW_TYPE = 1, - LOCATE_COMPONENT_CIRCLE_DRAW_TYPE = 2, - LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE = 4, - LOCATE_COMPONENT_RECT_DRAW_TYPE = 8, - LOCATE_LINE_DRAW_TYPE = 0x10, - LOCATE_COMPONENT_POLYLINE_DRAW_TYPE = 0x20, - LOCATE_COMPONENT_LINE_DRAW_TYPE = 0x40 -}; - -#define LOCATE_ALL_DRAW_ITEM 0xFFFFFFFF - - -#endif // LIBCMP_H diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index 4d2e1106a3..2ea2c59a69 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -179,7 +179,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, m_showDeMorgan = false; - if( LookForConvertPart( m_component ) > 1 ) + if( m_component->HasConversion() ) m_showDeMorgan = true; GetBaseScreen()->ClrModify(); @@ -265,7 +265,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) if( !IsOK( this, msg ) ) return; - bool success = m_library->Save( fn.GetFullPath() ); + bool success = m_library->Save( fn.GetFullPath(), true ); MsgPanel->EraseMsgBox(); diff --git a/eeschema/libedit_onleftclick.cpp b/eeschema/libedit_onleftclick.cpp index 46554e3944..11efc90e05 100644 --- a/eeschema/libedit_onleftclick.cpp +++ b/eeschema/libedit_onleftclick.cpp @@ -14,7 +14,6 @@ #include "program.h" #include "general.h" -#include "libcmp.h" #include "protos.h" #include "libeditfrm.h" #include "class_libentry.h" @@ -51,25 +50,16 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) } else { - DrawEntry = LocatePin( GetScreen()->m_MousePosition, m_component, - m_unit, m_convert ); - if( DrawEntry == NULL ) - { - DrawEntry = LocateDrawItem( (SCH_SCREEN*)GetScreen(), - GetScreen()->m_MousePosition, - m_component, m_unit, m_convert, - LOCATE_ALL_DRAW_ITEM ); - } + DrawEntry = + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_MousePosition ); - if( DrawEntry == NULL ) - DrawEntry = LocatePin( GetScreen()->m_Curseur, m_component, - m_unit, m_convert ); if( DrawEntry == NULL ) { - DrawEntry = LocateDrawItem( (SCH_SCREEN*)GetScreen(), - GetScreen()->m_Curseur, - m_component, m_unit, m_convert, - LOCATE_ALL_DRAW_ITEM ); + DrawEntry = + m_component->LocateDrawItem( m_unit, m_convert, + TYPE_NOT_INIT, + GetScreen()->m_Curseur ); } if( DrawEntry ) @@ -121,26 +111,16 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) break; case ID_LIBEDIT_DELETE_ITEM_BUTT: - DrawEntry = LocatePin( GetScreen()->m_MousePosition, m_component, - m_unit, m_convert ); - if( DrawEntry == NULL ) - { - DrawEntry = LocateDrawItem( (SCH_SCREEN*)GetScreen(), - GetScreen()->m_MousePosition, - m_component, m_unit, m_convert, - LOCATE_ALL_DRAW_ITEM ); - } + DrawEntry = + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_MousePosition ); - if( DrawEntry == NULL ) - DrawEntry = LocatePin( GetScreen()->m_Curseur, - m_component, m_unit, - m_convert ); if( DrawEntry == NULL ) { - DrawEntry = LocateDrawItem( (SCH_SCREEN*)GetScreen(), - GetScreen()->m_Curseur, - m_component, m_unit, m_convert, - LOCATE_ALL_DRAW_ITEM ); + DrawEntry = + m_component->LocateDrawItem( m_unit, m_convert, + TYPE_NOT_INIT, + GetScreen()->m_Curseur ); } if( DrawEntry == NULL ) DisplayCmpDoc(); @@ -185,29 +165,14 @@ void WinEDA_LibeditFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos ) if( ( DrawEntry == NULL ) || ( DrawEntry->m_Flags == 0 ) ) { // We can locate an item - DrawEntry = LocatePin( GetScreen()->m_MousePosition, m_component, - m_unit, m_convert ); - if( DrawEntry == NULL ) - DrawEntry = LocatePin( GetScreen()->m_Curseur, m_component, - m_unit, m_convert ); + DrawEntry = m_drawItem = + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_MousePosition ); if( DrawEntry == NULL ) { DrawEntry = m_drawItem = - LocateDrawItem( (SCH_SCREEN*) GetScreen(), - GetScreen()->m_MousePosition, m_component, - m_unit, m_convert, LOCATE_ALL_DRAW_ITEM ); - } - if( DrawEntry == NULL ) - { - DrawEntry = m_drawItem = - LocateDrawItem( (SCH_SCREEN*) GetScreen(), - GetScreen()->m_Curseur, m_component, m_unit, - m_convert, LOCATE_ALL_DRAW_ITEM ); - } - if( DrawEntry == NULL ) - { - DrawEntry = m_drawItem = - (LIB_DRAW_ITEM*) LocateField( m_component ); + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_Curseur ); } if( DrawEntry == NULL ) { diff --git a/eeschema/libedit_undo_redo.cpp b/eeschema/libedit_undo_redo.cpp index e92101e4a4..504afd52f6 100644 --- a/eeschema/libedit_undo_redo.cpp +++ b/eeschema/libedit_undo_redo.cpp @@ -31,9 +31,9 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, ITEM_PICKER wrapper(CopyItem, UR_LIBEDIT); lastcmd->PushItem(wrapper); GetScreen()->PushCommandToUndoList( lastcmd ); - /* Clear current flags (which can be temporary set by a current edit command) */ - for( item = CopyItem->m_Drawings; item != NULL; item = item->Next() ) - item->m_Flags = 0; + /* Clear current flags (which can be temporary set by a current edit + * command) */ + CopyItem->ClearStatus(); /* Clear redo list, because after new save there is no redo to do */ GetScreen()->ClearUndoORRedoList( GetScreen()->m_RedoList ); diff --git a/eeschema/libeditfrm.h b/eeschema/libeditfrm.h index 3c1d294b6b..7602285c5c 100644 --- a/eeschema/libeditfrm.h +++ b/eeschema/libeditfrm.h @@ -110,10 +110,7 @@ public: LIB_DRAW_ITEM* GetDrawItem( void ) { return m_drawItem; } - void SetDrawItem( LIB_DRAW_ITEM* drawItem ) - { - m_drawItem = drawItem; - } + void SetDrawItem( LIB_DRAW_ITEM* drawItem ); bool GetShowDeMorgan( void ) { return m_showDeMorgan; } @@ -163,7 +160,6 @@ private: void EditSymbolText( wxDC* DC, LIB_DRAW_ITEM* DrawItem ); void RotateSymbolText( wxDC* DC ); void DeleteDrawPoly( wxDC* DC ); - LibDrawField* LocateField( LIB_COMPONENT* LibEntry ); LIB_DRAW_ITEM* LocateItemUsingCursor(); void RotateField( wxDC* DC, LibDrawField* Field ); void PlaceField( wxDC* DC, LibDrawField* Field ); diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index 01e88b1690..51da30f9f4 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -10,7 +10,6 @@ #include "program.h" #include "general.h" -#include "libcmp.h" #include "protos.h" #include "libeditfrm.h" #include "class_library.h" @@ -263,38 +262,6 @@ void WinEDA_LibeditFrame::RotateField( wxDC* DC, LibDrawField* Field ) } -/* - * Locate the component fiels (ref, name or auxiliary fields) under the - * mouse cursor - * return: - * pointer on the field (or NULL ) - */ -LibDrawField* WinEDA_LibeditFrame::LocateField( LIB_COMPONENT* LibEntry ) -{ - wxPoint refpos = GetScreen()->m_Curseur; - /* Test reference */ - if( LibEntry->m_Name.HitTest( refpos ) ) - return &LibEntry->m_Name; - - /* Test Prefix */ - if( LibEntry->m_Prefix.HitTest( refpos ) ) - return &LibEntry->m_Prefix; - - /* Test others fields */ - for( LibDrawField* field = LibEntry->m_Fields; field != NULL; - field = field->Next() ) - { - if( field->m_Text.IsEmpty() ) - continue; - - if( field->HitTest( refpos ) ) - return field; - } - - return NULL; -} - - LIB_DRAW_ITEM* WinEDA_LibeditFrame::LocateItemUsingCursor() { LIB_DRAW_ITEM* DrawEntry = m_drawItem; @@ -304,26 +271,15 @@ LIB_DRAW_ITEM* WinEDA_LibeditFrame::LocateItemUsingCursor() if( ( DrawEntry == NULL ) || ( DrawEntry->m_Flags == 0 ) ) { - DrawEntry = LocatePin( GetScreen()->m_Curseur, m_component, - m_unit, m_convert ); + DrawEntry = m_drawItem = + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_MousePosition ); + if( DrawEntry == NULL ) { DrawEntry = m_drawItem = - LocateDrawItem( (SCH_SCREEN*) GetScreen(), - GetScreen()->m_MousePosition, m_component, - m_unit, m_convert, LOCATE_ALL_DRAW_ITEM ); - } - if( DrawEntry == NULL ) - { - DrawEntry = m_drawItem = - LocateDrawItem( (SCH_SCREEN*) GetScreen(), - GetScreen()->m_Curseur, m_component, - m_unit, m_convert, LOCATE_ALL_DRAW_ITEM ); - } - if( DrawEntry == NULL ) - { - DrawEntry = m_drawItem = - (LIB_DRAW_ITEM*) LocateField( m_component ); + m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, + GetScreen()->m_Curseur ); } } diff --git a/eeschema/libframe.cpp b/eeschema/libframe.cpp index bd28f15664..86e6807d57 100644 --- a/eeschema/libframe.cpp +++ b/eeschema/libframe.cpp @@ -203,6 +203,12 @@ void WinEDA_LibeditFrame::LoadSettings() } +void WinEDA_LibeditFrame::SetDrawItem( LIB_DRAW_ITEM* drawItem ) +{ + m_drawItem = drawItem; +} + + /** * Save library editor frame specific configuration settings. * diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index 1299c0f4b3..29ea232f70 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -8,7 +8,6 @@ #include "trigo.h" #include "macros.h" -#include "libcmp.h" #include "general.h" #include "class_marker_sch.h" #include "protos.h" @@ -25,13 +24,14 @@ static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList, double aScaleFactor ); -/*********************************************************************/ -SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) -/*********************************************************************/ - -/* Search the smaller (considering its area) component under the mouse cursor or the pcb cursor - * If more than 1 component is found, a pointer to the smaller component is returned +/** + * Search the smaller (considering its area) component under the mouse + * cursor or the pcb cursor + * + * If more than 1 component is found, a pointer to the smaller component is + * returned */ +SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) { SCH_COMPONENT* component = NULL, * lastcomponent = NULL; SCH_ITEM* DrawList; @@ -111,7 +111,8 @@ SCH_ITEM* PickStruct( const wxPoint& refpos, BASE_SCREEN* screen, int SearchMask return NULL; if( ( Snapped = SnapPoint2( refpos, SearchMask, - screen->EEDrawList, screen->GetScalingFactor() ) ) != FALSE ) + screen->EEDrawList, + screen->GetScalingFactor() ) ) != FALSE ) { return LastSnappedStruct; } @@ -162,12 +163,12 @@ int PickItemsInBlock( BLOCK_SELECTOR& aBlock, BASE_SCREEN* aScreen ) /***************************************************************************** -* Routine to search all objects for the closest point to a given point, in * -* drawing space, and snap it to that points if closer than SnapDistance. * -* Note we use L1 norm as distance measure, as it is the fastest. * +* Routine to search all objects for the closest point to a given point, in * +* drawing space, and snap it to that points if closer than SnapDistance. * +* Note we use L1 norm as distance measure, as it is the fastest. * * This routine updates LastSnappedStruct to the last object used in to snap * -* a point. This variable is global to this module only (see above). * -* The routine returns TRUE if point was snapped. * +* a point. This variable is global to this module only (see above). * +* The routine returns TRUE if point was snapped. * *****************************************************************************/ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList, double aScaleFactor ) @@ -371,9 +372,9 @@ bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, /***************************************************************************** -* Routine to test if an object has non empty intersection with the box * +* Routine to test if an object has non empty intersection with the box * * defined by x1/y1 and x2/y2 (x1 < x2, y1 < y2), and return TRUE if so. This * -* routine is used to pick all points in a given box. * +* routine is used to pick all points in a given box. * *****************************************************************************/ bool DrawStructInBox( int x1, int y1, int x2, int y2, SCH_ITEM* DrawStruct ) { @@ -613,114 +614,15 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, } - -/*********************************************************************************/ -LIB_DRAW_ITEM* LocateDrawItem( SCH_SCREEN* Screen, - const wxPoint& aRefPoint, - LIB_COMPONENT* LibEntry, - int Unit, - int Convert, - int masque ) -/*********************************************************************************/ - -/* Locates a body item( not pins ) - * Unit = part number (if Unit = 0, all parts are considered) - * Convert = convert value for shape (si Convert = 0, all shapes are considered) - * remember the Y axis is from bottom to top in library entries for graphic items. - */ -{ - LIB_DRAW_ITEM* DrawItem; - - if( LibEntry == NULL ) - return NULL; - - if( LibEntry->Type != ROOT ) - { - wxMessageBox( wxT( "Error in LocateDrawItem: Entry is ALIAS" ) ); - return NULL; - } - - DrawItem = LibEntry->m_Drawings; - - for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) - { - if( Unit && DrawItem->m_Unit && (Unit != DrawItem->m_Unit) ) - continue; - if( Convert && DrawItem->m_Convert && (Convert != DrawItem->m_Convert) ) - continue; - - switch( DrawItem->Type() ) - { - case COMPONENT_ARC_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_ARC_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_CIRCLE_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_CIRCLE_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_RECT_DRAW_TYPE: // Locate a rect if the mouse cursor is on a side of this rectangle - if( (masque & LOCATE_COMPONENT_RECT_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_POLYLINE_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_BEZIER_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_POLYLINE_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_LINE_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_LINE_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE: - if( (masque & LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE) == 0 ) - break; - if( DrawItem->HitTest( aRefPoint ) ) - return DrawItem; - break; - - default: - ; - } - } - - return NULL; -} - - -/*******************************************************************/ -LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, - SCH_COMPONENT* eComponent ) -/*******************************************************************/ - -/** Find a PIN in a component +/** + * Find a PIN in a component * @param pin_number = pin number (string) * @param pin_number = pin number (string) * @return a pointer on the pin, or NULL if not found */ +LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, + SCH_COMPONENT* eComponent ) { - LIB_DRAW_ITEM* DrawItem; LIB_COMPONENT* Entry; LibDrawPin* Pin; int Unit, Convert; @@ -730,103 +632,42 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, if( Entry == NULL ) return NULL; - if( Entry->Type != ROOT ) - { - wxMessageBox( wxT( "LocatePinByNumber() error: Entry is ALIAS" ) ); - return NULL; - } + wxASSERT( Entry->Type == ROOT ); Unit = eComponent->m_Multi; Convert = eComponent->m_Convert; - DrawItem = Entry->m_Drawings; - for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) + for( Pin = Entry->GetNextPin(); Pin != NULL; + Pin = Entry->GetNextPin( Pin ) ) { - if( DrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) /* Pin Trouvee */ - { - Pin = (LibDrawPin*) DrawItem; + wxASSERT( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ); - if( Unit && DrawItem->m_Unit && (DrawItem->m_Unit != Unit) ) - continue; + if( Unit && Pin->m_Unit && ( Pin->m_Unit != Unit ) ) + continue; - if( Convert && DrawItem->m_Convert && (DrawItem->m_Convert != Convert) ) - continue; - wxString pNumber; - Pin->ReturnPinStringNum( pNumber ); - if( ePin_Number == pNumber ) - return Pin; - } + if( Convert && Pin->m_Convert && ( Pin->m_Convert != Convert ) ) + continue; + + wxString pNumber; + Pin->ReturnPinStringNum( pNumber ); + + if( ePin_Number == pNumber ) + return Pin; } return NULL; } -/*******************************************************************/ -LIB_DRAW_ITEM* LocatePin( const wxPoint& RefPos, LIB_COMPONENT* Entry, - int Unit, int convert, SCH_COMPONENT* DrawLibItem ) -/*******************************************************************/ - -/* Routine de localisation d'une PIN de la PartLib pointee par Entry - * retourne un pointeur sur la pin, ou NULL si pas trouve - * Si Unit = 0, le numero d'unite n'est pas teste - * Si convert = 0, le numero convert n'est pas teste - */ -{ - if( Entry == NULL ) - return NULL; - - if( Entry->Type != ROOT ) - { - wxMessageBox( wxT( "LocatePin() error: Entry is ALIAS" ) ); - return NULL; - } - - LIB_DRAW_ITEM* DrawItem = Entry->m_Drawings; - for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) - { - if( DrawItem->Type() == COMPONENT_PIN_DRAW_TYPE ) /* Pin Trouvee */ - { - LibDrawPin* Pin = (LibDrawPin*) DrawItem; - - if( Unit && DrawItem->m_Unit && (DrawItem->m_Unit != Unit) ) - continue; - - if( convert && DrawItem->m_Convert && (DrawItem->m_Convert != convert) ) - continue; - - if( DrawLibItem == NULL ) - { - if ( Pin->HitTest( RefPos ) ) - return DrawItem; - } - - else - { - int mindist = Pin->m_Width ? Pin->m_Width / 2 : g_DrawDefaultLineThickness / 2; - - // Have a minimal tolerance for hit test - if( mindist < 3 ) - mindist = 3; // = 3 mils - if ( Pin->HitTest( RefPos - DrawLibItem->m_Pos, mindist, DrawLibItem->m_Transform ) ) - return DrawItem; - } - } - } - - return NULL; -} - - -/***********************************************************************************/ -Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet, const wxPoint& pos ) -/***********************************************************************************/ +Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet, + const wxPoint& pos ) { int size, dy, minx, maxx; Hierarchical_PIN_Sheet_Struct* SheetLabel; SheetLabel = Sheet->m_Label; - while( (SheetLabel) && (SheetLabel->Type()==DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE) ) + while( SheetLabel + && SheetLabel->Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE ) { size = ( SheetLabel->GetLength() + 1 ) * SheetLabel->m_Size.x; if( SheetLabel->m_Edge ) @@ -846,17 +687,16 @@ Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet, const w } -/**************************************************************************/ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, SCH_COMPONENT** libpart ) -/**************************************************************************/ { SCH_ITEM* DrawStruct; LIB_COMPONENT* Entry; SCH_COMPONENT* LibItem = NULL; LibDrawPin* Pin = NULL; - for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Next() ) + for( DrawStruct = DrawList; DrawStruct != NULL; + DrawStruct = DrawStruct->Next() ) { if( DrawStruct->Type() != TYPE_SCH_COMPONENT ) continue; @@ -865,8 +705,10 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, if( Entry == NULL ) continue; - Pin = (LibDrawPin*) LocatePin( RefPos, Entry, LibItem->m_Multi, - LibItem->m_Convert, LibItem ); + Pin = (LibDrawPin*) Entry->LocateDrawItem( LibItem->m_Multi, + LibItem->m_Convert, + COMPONENT_PIN_DRAW_TYPE, + RefPos ); if( Pin ) break; } @@ -877,20 +719,20 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, } -/***************************************************************/ Hierarchical_PIN_Sheet_Struct* LocateAnyPinSheet( const wxPoint& RefPos, SCH_ITEM* DrawList ) -/***************************************************************/ { SCH_ITEM* DrawStruct; Hierarchical_PIN_Sheet_Struct* PinSheet = NULL; - for( DrawStruct = DrawList; DrawStruct != NULL; DrawStruct = DrawStruct->Next() ) + for( DrawStruct = DrawList; DrawStruct != NULL; + DrawStruct = DrawStruct->Next() ) { if( DrawStruct->Type() != DRAW_SHEET_STRUCT_TYPE ) continue; + PinSheet = LocateSheetLabel( (DrawSheetStruct*) DrawStruct, - RefPos ); + RefPos ); if( PinSheet ) break; } diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index a173563a52..cc15be1c70 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -18,12 +18,14 @@ /* Routines locales */ -static void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, const wxString& FullFileName ); +static void Write_GENERIC_NetList( WinEDA_SchematicFrame* frame, + const wxString& FullFileName ); static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with_pcbnew ); static void WriteNetListCADSTAR( WinEDA_SchematicFrame* frame, FILE* f ); static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ); -static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, bool use_netnames ); +static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, + bool use_netnames ); static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ); static void AddPinToComponentPinList( SCH_COMPONENT* Component, @@ -97,21 +99,19 @@ void WriteNetList( WinEDA_SchematicFrame* frame, const wxString& FileNameNL, } -/****************************************************************************/ -static SCH_COMPONENT* FindNextComponentAndCreatPinList( - EDA_BaseStruct* DrawList, DrawSheetPath* sheet ) -/****************************************************************************/ - -/* Find a "suitable" component from the DrawList +/* Find a "suitable" component from the DrawList * build its pin list s_SortedComponentPinList. * The list is sorted by pin num - * A suitable component is a "new" real component (power symbols are not considered) + * A suitable component is a "new" real component (power symbols are not + * considered) * Must be deallocated by the user */ +static SCH_COMPONENT* FindNextComponentAndCreatPinList( EDA_BaseStruct* DrawList, + DrawSheetPath* sheet ) { SCH_COMPONENT* Component = NULL; LIB_COMPONENT* Entry; - LIB_DRAW_ITEM* DEntry; + LibDrawPin* Pin; s_SortedComponentPinList.clear(); for( ; DrawList != NULL; DrawList = DrawList->Next() ) @@ -129,14 +129,16 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( //if( Component->m_FlagControlMulti == 1 ) // continue; /* yes */ // removed because with multiple instances of one schematic - // (several sheets pointing to 1 screen), this will be erroneously be toggled. + // (several sheets pointing to 1 screen), this will be erroneously be + // toggled. Entry = CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName ); if( Entry == NULL ) continue; - if( Entry->m_UnitCount > 1 ) // Multi parts per package: test if already visited: + // Multi parts per package: test if already visited: + if( Entry->m_UnitCount > 1 ) { bool found = false; for( unsigned jj = 0; jj < s_ReferencesAlreadyFound.GetCount(); jj++ ) @@ -156,29 +158,29 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( } } - DEntry = Entry->m_Drawings; if( Entry->m_UnitCount <= 1 ) // One part per package { - for( ; DEntry != NULL; DEntry = DEntry->Next() ) + for( Pin = Entry->GetNextPin(); Pin != NULL; + Pin = Entry->GetNextPin( Pin ) ) { - if( DEntry->Type() != COMPONENT_PIN_DRAW_TYPE ) + wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE ); + + if( Pin->m_Unit + && ( Pin->m_Unit != Component->GetUnitSelection( sheet ) ) ) continue; - if( DEntry->m_Unit - && ( DEntry->m_Unit != Component->GetUnitSelection( sheet ) ) ) + if( Pin->m_Convert + && ( Pin->m_Convert != Component->m_Convert ) ) continue; - if( DEntry->m_Convert - && (DEntry->m_Convert != Component->m_Convert) ) - continue; - { - AddPinToComponentPinList( Component, sheet, (LibDrawPin*) DEntry ); - } + + AddPinToComponentPinList( Component, sheet, Pin ); } } else // Multiple parts per package: Collect all parts ans pins for this reference FindAllsInstancesOfComponent( Component, Entry, sheet ); /* Sort Pins in s_SortedComponentPinList by pin number */ - sort( s_SortedComponentPinList.begin(), s_SortedComponentPinList.end(),SortPinsByNum ); + sort( s_SortedComponentPinList.begin(), + s_SortedComponentPinList.end(), SortPinsByNum ); /* Remove duplicate Pins in s_SortedComponentPinList */ EraseDuplicatePins( s_SortedComponentPinList ); @@ -373,7 +375,7 @@ static void WriteNetListPspice( WinEDA_SchematicFrame* frame, FILE* f, /* Routine de generation du fichier netliste ( Format PSPICE ) * si use_netnames = TRUE * les nodes sont identifies par le netname - * sinon les nodes sont identifies par le netnumber + * sinon les nodes sont identifies par le netnumber * * tous les textes graphiques commen�ant par [.-+]pspice ou [.-+]gnucap * sont consideres comme des commandes a placer dans la netliste @@ -754,29 +756,30 @@ static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList ) } -/**********************************************************************************/ +/** + * Used for multiple parts per package components. + * + * Search all instances of Component_in, + * Calls AddPinToComponentPinList() to and pins founds to the current + * component pin list + */ static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in, LIB_COMPONENT* Entry, DrawSheetPath* Sheet_in ) -/**********************************************************************************/ - -/** - * Used for multiple parts per package components - * Search all instances of Component_in, - * Calls AddPinToComponentPinList() to and pins founds to the current component pin list - */ { EDA_BaseStruct* SchItem; SCH_COMPONENT* Component2; - LIB_DRAW_ITEM* DEntry; + LibDrawPin* pin; DrawSheetPath* sheet; wxString str, Reference = Component_in->GetRef( Sheet_in ); EDA_SheetList SheetList; - for( sheet = SheetList.GetFirst(); sheet != NULL; sheet = SheetList.GetNext() ) + for( sheet = SheetList.GetFirst(); sheet != NULL; + sheet = SheetList.GetNext() ) { - for( SchItem = sheet->LastDrawList(); SchItem; SchItem = SchItem->Next() ) + for( SchItem = sheet->LastDrawList(); SchItem; + SchItem = SchItem->Next() ) { if( SchItem->Type() != TYPE_SCH_COMPONENT ) continue; @@ -787,41 +790,40 @@ static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in, if( str.CmpNoCase( Reference ) != 0 ) continue; - if( Entry && Entry->m_Drawings != NULL ) + if( Entry == NULL ) + continue; + + for( pin = Entry->GetNextPin(); pin != NULL; + pin = Entry->GetNextPin( pin ) ) { - DEntry = Entry->m_Drawings; - for( ; DEntry != NULL; DEntry = DEntry->Next() ) - { - if( DEntry->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; - if( DEntry->m_Unit - && ( DEntry->m_Unit != Component2->GetUnitSelection( sheet ) ) ) - continue; - if( DEntry->m_Convert - && (DEntry->m_Convert != Component2->m_Convert) ) + wxASSERT( pin->Type() != COMPONENT_PIN_DRAW_TYPE ); + + if( pin->m_Unit + && ( pin->m_Unit != Component2->GetUnitSelection( sheet ) ) ) + continue; + + if( pin->m_Convert + && ( pin->m_Convert != Component2->m_Convert ) ) continue; - // A suitable pin in found: add it to the current list - AddPinToComponentPinList( Component2, sheet, (LibDrawPin*) DEntry ); - } + // A suitable pin in found: add it to the current list + AddPinToComponentPinList( Component2, sheet, pin ); } } } } -/**************************************************************************/ -static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 ) -/**************************************************************************/ - -/* Routine de comparaison pour le tri des pins par numero croissant +/* + Routine de comparaison pour le tri des pins par numero croissant * du tableau des pins s_SortedComponentPinList par qsort() */ +static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 ) { int Num1, Num2; char Line[5]; - Num1 = Pin1->m_PinNum; + Num1 = Pin1->m_PinNum; Num2 = Pin2->m_PinNum; Line[4] = 0; memcpy( Line, &Num1, 4 ); Num1 = atoi( Line ); @@ -1055,7 +1057,7 @@ static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ) + NetcodeName; //NetcodeName << wxT("_") << - // g_NetObjectslist[jj].m_SheetList.PathHumanReadable(); + // g_NetObjectslist[jj].m_SheetList.PathHumanReadable(); } } else // this net has no name: create a default name $ @@ -1113,7 +1115,7 @@ static void WriteListOfNetsCADSTAR( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ) aObjectsList[ii]->m_Flag = 1; // Recherche des pins redondantes et mise a 1 de m_Flag, - // pour ne pas generer plusieurs fois la connexion + // pour ne pas generer plusieurs fois la connexion for( jj = ii + 1; jj < aObjectsList.size(); jj++ ) { if( aObjectsList[jj]->GetNet() != NetCode ) diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index 6e06f4712a..592202e2f3 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -355,7 +355,7 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, NETLIST_OBJECT* new_item; SCH_COMPONENT* DrawLibItem; LIB_COMPONENT* Entry; - LIB_DRAW_ITEM* DEntry; + LibDrawPin* pin; Hierarchical_PIN_Sheet_Struct* SheetLabel; DrawSheetPath list; @@ -479,43 +479,38 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, if( Entry == NULL ) break; - if( Entry->m_Drawings == NULL ) - break; - - DEntry = Entry->m_Drawings; - - for( ; DEntry; DEntry = DEntry->Next() ) + for( pin = Entry->GetNextPin(); pin != NULL; + pin = Entry->GetNextPin( pin ) ) { - LibDrawPin* Pin = (LibDrawPin*) DEntry; - if( DEntry->Type() != COMPONENT_PIN_DRAW_TYPE ) + wxASSERT( pin->Type() == COMPONENT_PIN_DRAW_TYPE ); + + if( pin->m_Unit + && ( pin->m_Unit != DrawLibItem->GetUnitSelection( sheetlist ) ) ) continue; - if( DEntry->m_Unit && ( DEntry->m_Unit != DrawLibItem->GetUnitSelection( sheetlist ) ) ) - continue; - - if( DEntry->m_Convert - && (DEntry->m_Convert != DrawLibItem->m_Convert) ) + if( pin->m_Convert + && ( pin->m_Convert != DrawLibItem->m_Convert ) ) continue; wxPoint pos2 = TransformCoordinate( DrawLibItem->m_Transform, - Pin->m_Pos ) + DrawLibItem->m_Pos; + pin->m_Pos ) + DrawLibItem->m_Pos; new_item = new NETLIST_OBJECT(); new_item->m_SheetListInclude = *sheetlist; - new_item->m_Comp = DEntry; + new_item->m_Comp = pin; new_item->m_SheetList = *sheetlist; new_item->m_Type = NET_PIN; new_item->m_Link = DrawLibItem; - new_item->m_ElectricalType = Pin->m_PinType; - new_item->m_PinNum = Pin->m_PinNum; - new_item->m_Label = &Pin->m_PinName; + new_item->m_ElectricalType = pin->m_PinType; + new_item->m_PinNum = pin->m_PinNum; + new_item->m_Label = &pin->m_PinName; new_item->m_Start = new_item->m_End = pos2; aNetItemBuffer.push_back( new_item ); - if( ( (int) Pin->m_PinType == (int) PIN_POWER_IN ) - && ( Pin->m_Attributs & PINNOTDRAW ) ) + if( ( (int) pin->m_PinType == (int) PIN_POWER_IN ) + && ( pin->m_Attributs & PINNOTDRAW ) ) { /* Il y a un PIN_LABEL Associe */ new_item = new NETLIST_OBJECT(); @@ -523,7 +518,7 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, new_item->m_Comp = NULL; new_item->m_SheetList = *sheetlist; new_item->m_Type = NET_PINLABEL; - new_item->m_Label = &Pin->m_PinName; + new_item->m_Label = &pin->m_PinName; new_item->m_Start = pos2; new_item->m_End = new_item->m_Start; @@ -545,8 +540,7 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, list = *sheetlist; list.Push( STRUCT ); SheetLabel = STRUCT->m_Label; - for( ; SheetLabel != NULL; - SheetLabel = SheetLabel->Next() ) + for( ; SheetLabel != NULL; SheetLabel = SheetLabel->Next() ) { ii = IsBusLabel( SheetLabel->m_Text ); new_item = new NETLIST_OBJECT(); @@ -573,7 +567,7 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, { wxString msg; msg.Printf( wxT( "Netlist: unexpected struct type %d" ), - DrawList->Type() ); + DrawList->Type() ); wxMessageBox( msg ); break; } diff --git a/eeschema/pinedit-dialog.h b/eeschema/pinedit-dialog.h index d7992c8df2..ec444439b5 100644 --- a/eeschema/pinedit-dialog.h +++ b/eeschema/pinedit-dialog.h @@ -27,7 +27,6 @@ #include "common.h" #include "program.h" -#include "libcmp.h" #include "general.h" #include "eeschema_id.h" #include "libeditfrm.h" @@ -133,8 +132,8 @@ public: void NewSizePin(int newsize); void SetPinShape( int newshape); void SetPinType(int newtype); - void SetPinOrient(int neworient); - void SetAttributsPin(bool draw, bool unit, bool convert); + void SetPinOrientation(int neworient); + void SetPinAttributes(bool draw, bool unit, bool convert); ////@begin WinEDA_PinPropertiesFrame member variables wxTextCtrl* m_PinNameCtrl; diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index 81379ff5a8..5885b21169 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -102,8 +102,11 @@ void WinEDA_PinPropertiesFrame::PinPropertiesAccept( wxCommandEvent& event ) NewSizePin( LastPinSize ); SetPinShape( LastPinShape ); SetPinType( LastPinType ); - SetPinOrient( LastPinOrient ); - SetAttributsPin( true, true, true ); // Set all attributes (visibility, common to units and common to convert options) + SetPinOrientation( LastPinOrient ); + + // Set all attributes (visibility, common to units and common to + // convert options) + SetPinAttributes( true, true, true ); item->DisplayInfo( m_Parent ); m_Parent->DrawPanel->Refresh(); @@ -125,22 +128,19 @@ void WinEDA_LibeditFrame::InitEditOnePin() LibDrawPin* Pin; LibDrawPin* CurrentPin = (LibDrawPin*) m_drawItem; - if( m_component == NULL || CurrentPin == NULL ) + if( m_component == NULL || CurrentPin == NULL + || m_drawItem->Type() != COMPONENT_PIN_DRAW_TYPE ) return; - /* Marquage des pins a traiter,Si edition d'une pin non deja selectionnee */ - Pin = (LibDrawPin*) m_component->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + for( Pin = m_component->GetNextPin(); Pin != NULL; + Pin = m_component->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( Pin == CurrentPin ) continue; if( ( Pin->m_Pos == CurrentPin->m_Pos ) && ( Pin->m_Orient == CurrentPin->m_Orient ) && ( !( CurrentPin->m_Flags & IS_NEW ) ) - && ( g_EditPinByPinIsOn == false ) // This is set by the tool of the main toolbar - ) + && ( g_EditPinByPinIsOn == false ) ) Pin->m_Flags |= IS_LINKED | IN_EDIT; else Pin->m_Flags = 0; @@ -150,12 +150,10 @@ void WinEDA_LibeditFrame::InitEditOnePin() } -/*************************************************************/ -static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC ) -/*************************************************************/ - -/* Used to abort the move pin command. +/** + * Clean up after aborting a move pin command. */ +static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC ) { WinEDA_LibeditFrame* parent = (WinEDA_LibeditFrame*) Panel->GetParent(); @@ -164,14 +162,15 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC ) LibDrawPin* CurrentPin = (LibDrawPin*) parent->GetDrawItem(); - if( CurrentPin && ( CurrentPin->m_Flags & IS_NEW ) ) - CurrentPin->GetParent()->RemoveDrawItem( CurrentPin, Panel, DC ); + if( CurrentPin == NULL || CurrentPin->Type() != COMPONENT_PIN_DRAW_TYPE ) + return; + + if( CurrentPin->m_Flags & IS_NEW ) + delete CurrentPin; + else + CurrentPin->m_Flags = 0; /* clear edit flags */ - LIB_DRAW_ITEM* item = CurrentPin->GetParent()->m_Drawings; - for( ; item != NULL; item = item->Next() ) - item->m_Flags = 0; - Panel->ManageCurseur = NULL; Panel->ForceCloseManageCurseur = NULL; parent->SetDrawItem( NULL ); @@ -180,10 +179,10 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC ) } -/********************************************/ +/** + * Managed cursor callback for placing component pins. + */ void WinEDA_LibeditFrame::PlacePin( wxDC* DC ) -/********************************************/ -/* Routine de fin de deplacement de la pin selectionnee */ { LibDrawPin* Pin; LibDrawPin* CurrentPin = (LibDrawPin*) m_drawItem; @@ -197,23 +196,18 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC ) newpos.x = GetScreen()->m_Curseur.x; newpos.y = -GetScreen()->m_Curseur.y; - Pin = (LibDrawPin*) m_component->m_Drawings; - // Tst for an other pin in same new position: - for( ; Pin != NULL; Pin = Pin->Next() ) + for( Pin = m_component->GetNextPin(); Pin != NULL; + Pin = m_component->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; - if( Pin == CurrentPin ) - continue; - if( newpos != Pin->m_Pos ) - continue; - if( Pin->m_Flags ) + if( Pin == CurrentPin || newpos != Pin->m_Pos || Pin->m_Flags ) continue; + if( ask_for_pin && !g_EditPinByPinIsOn ) { DrawPanel->m_IgnoreMouseEvents = true; - status = IsOK( this, _( "Occupied by other pin. Continue?" ) ); + status = IsOK( this, _( "This position is already occupied by \ +another pin. Continue?" ) ); DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = false; if( !status ) @@ -226,24 +220,22 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC ) DrawPanel->ManageCurseur = NULL; DrawPanel->ForceCloseManageCurseur = NULL; GetScreen()->SetModify(); - CurrentPin->m_Pos = newpos; + if( CurrentPin->m_Flags & IS_NEW ) { LastPinOrient = CurrentPin->m_Orient; LastPinType = CurrentPin->m_PinType; LastPinShape = CurrentPin->m_PinShape; - CreateImagePins( CurrentPin, m_unit, m_convert, - m_showDeMorgan ); + CreateImagePins( CurrentPin, m_unit, m_convert, m_showDeMorgan ); m_lastDrawItem = CurrentPin; + m_component->AddDrawItem( m_drawItem ); } /* Put linked pins in new position, and clear flags */ - Pin = (LibDrawPin*) m_component->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + for( Pin = m_component->GetNextPin(); Pin != NULL; + Pin = m_component->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( Pin->m_Flags == 0 ) continue; Pin->m_Pos = CurrentPin->m_Pos; @@ -259,17 +251,13 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC ) m_drawItem = NULL; }; -/***********************************************************/ -void WinEDA_PinPropertiesFrame::SetPinOrient( int neworient ) -/***********************************************************/ -/* Routine de Rotation de la pin courante*/ + +void WinEDA_PinPropertiesFrame::SetPinOrientation( int neworient ) { LibDrawPin* CurrentPin = (LibDrawPin*) m_Parent->GetDrawItem(); LibDrawPin* Pin, * RefPin = CurrentPin; - if( CurrentPin == NULL || CurrentPin->GetParent() == NULL ) - return; - if( RefPin == NULL ) + if( CurrentPin == NULL || CurrentPin->GetParent() == NULL || RefPin == NULL ) return; m_Parent->GetScreen()->SetModify(); @@ -277,8 +265,9 @@ void WinEDA_PinPropertiesFrame::SetPinOrient( int neworient ) /* Rotation */ RefPin->m_Orient = neworient; - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { if( Pin->m_Flags == 0 ) continue; @@ -289,26 +278,22 @@ void WinEDA_PinPropertiesFrame::SetPinOrient( int neworient ) } -/*************************************************/ -void WinEDA_LibeditFrame::StartMovePin( wxDC* DC ) -/*************************************************/ - -/* Prepare le deplacement d'une pin : - * Localise la pin pointee par le curseur, et si elle existe active - * la fonction de gestion curseur ( DrawMovePin() ). +/** + * Prepare le deplacement d'une pin : + * Localise la pin pointee par le curseur, et si elle existe active + * la fonction de gestion curseur ( DrawMovePin() ). */ +void WinEDA_LibeditFrame::StartMovePin( wxDC* DC ) { LibDrawPin* Pin; LibDrawPin* CurrentPin = (LibDrawPin*) m_drawItem; wxPoint startPos; /* Marquage des pins a traiter */ - Pin = (LibDrawPin*) m_component->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = m_component->GetNextPin(); + for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) { Pin->m_Flags = 0; - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( Pin == CurrentPin ) continue; if( ( Pin->m_Pos == CurrentPin->m_Pos ) @@ -346,12 +331,18 @@ static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) return; LibDrawPin* CurrentPin = (LibDrawPin*) parent->GetDrawItem(); - wxPoint pinpos = CurrentPin->m_Pos; - bool showPinText = true; + + if( CurrentPin == NULL || CurrentPin->Type() != COMPONENT_PIN_DRAW_TYPE ) + return; + + wxPoint pinpos = CurrentPin->m_Pos; + bool showPinText = true; /* Erase pin in old position */ if( erase || ( CurrentPin->m_Flags & IS_NEW ) ) { + wxLogDebug( _( "Initial pin position (%d, %d)" ), + PinPreviousPos.x, PinPreviousPos.y ); CurrentPin->m_Pos = PinPreviousPos; CurrentPin->Draw( panel, DC, wxPoint( 0, 0 ), -1, g_XorMode, &showPinText, DefaultTransformMatrix ); @@ -360,14 +351,14 @@ static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) /* Redraw pin in new position */ CurrentPin->m_Pos.x = panel->GetScreen()->m_Curseur.x; CurrentPin->m_Pos.y = -panel->GetScreen()->m_Curseur.y; - CurrentPin->Draw( panel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + CurrentPin->Draw( panel, DC, wxPoint( 0, 0 ), -1, wxCOPY, &showPinText, DefaultTransformMatrix ); PinPreviousPos = CurrentPin->m_Pos; /* Keep the original position for existing pin (for Undo command) - * and the current position for a new pin */ - if( (CurrentPin->m_Flags & IS_NEW) == 0 ) + * and the current position for a new pin */ + if( ( CurrentPin->m_Flags & IS_NEW ) == 0 ) CurrentPin->m_Pos = pinpos; } @@ -390,14 +381,10 @@ void WinEDA_PinPropertiesFrame::SetPinShape( int newshape ) m_Parent->GetScreen()->SetModify(); CurrentPin->DisplayInfo( m_Parent ); - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; - if( Pin->m_Flags == 0 ) - continue; - if( Pin->m_Convert != CurrentPin->m_Convert ) + if( Pin->m_Flags == 0 || Pin->m_Convert != CurrentPin->m_Convert ) continue; Pin->m_PinShape = newshape; } @@ -423,11 +410,9 @@ void WinEDA_PinPropertiesFrame::SetPinType( int newtype ) CurrentPin->m_PinType = newtype; m_Parent->GetScreen()->SetModify(); - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( Pin->m_Flags == 0 ) continue; Pin->m_PinType = newtype; @@ -462,11 +447,9 @@ void WinEDA_PinPropertiesFrame::SetPinName( const wxString& newname, int newsize m_Parent->GetScreen()->SetModify(); /* Traitement des autres pins */ - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( (Pin->m_Flags & IS_LINKED) == 0 ) continue; if( newsize >= 0 ) @@ -504,14 +487,11 @@ void WinEDA_PinPropertiesFrame::SetPinNum( const wxString& newnum, int newsize ) CurrentPin->SetPinNumFromString( buf ); m_Parent->GetScreen()->SetModify(); - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; - if( ( Pin->m_Flags & IS_LINKED ) == 0 ) - continue; - if( Pin->m_Unit != CurrentPin->m_Unit ) + if( ( Pin->m_Flags & IS_LINKED ) == 0 + || Pin->m_Unit != CurrentPin->m_Unit ) continue; if( newsize >= 0 ) Pin->m_PinNumSize = newsize; @@ -532,8 +512,8 @@ void WinEDA_LibeditFrame::DeletePin( wxDC* DC, * Sinon seule la pin de l'unite en convert courante sera effacee */ { - LIB_DRAW_ITEM* DrawItem; - wxPoint PinPos; + LibDrawPin* tmp; + wxPoint PinPos; if( LibEntry == NULL || Pin == NULL ) return; @@ -544,46 +524,43 @@ void WinEDA_LibeditFrame::DeletePin( wxDC* DC, /* Effacement des autres pins de meme coordonnees */ if( g_EditPinByPinIsOn == false ) { - DrawItem = LibEntry->m_Drawings; - for( ; DrawItem != NULL; ) + tmp = LibEntry->GetNextPin(); + + while( tmp != NULL ) { - if( DrawItem->Type() != COMPONENT_PIN_DRAW_TYPE ) - { - DrawItem = DrawItem->Next(); - continue; - } - Pin = (LibDrawPin*) DrawItem; - DrawItem = DrawItem->Next(); + Pin = tmp; + tmp = LibEntry->GetNextPin( Pin ); + if( Pin->m_Pos != PinPos ) continue; + LibEntry->RemoveDrawItem( (LIB_DRAW_ITEM*) Pin ); } } + GetScreen()->SetModify(); } -/*********************************************/ +/* + * Create a new pin. + */ void WinEDA_LibeditFrame::CreatePin( wxDC* DC ) -/*********************************************/ -/* Creation d'une nouvelle pin */ { - LIB_DRAW_ITEM* DrawItem; - LibDrawPin* CurrentPin; - bool showPinText = true; + LibDrawPin* CurrentPin; + bool showPinText = true; if( m_component == NULL ) return; /* Effacement des flags */ - DrawItem = m_component->m_Drawings; - for( ; DrawItem != NULL; DrawItem = DrawItem->Next() ) - DrawItem->m_Flags = 0; + m_component->ClearStatus(); - CurrentPin = new LibDrawPin(m_component); + CurrentPin = new LibDrawPin( m_component ); m_drawItem = CurrentPin; - if( CurrentPin == NULL ) + + if( CurrentPin == NULL || CurrentPin->Type() != COMPONENT_PIN_DRAW_TYPE ) return; CurrentPin->m_Flags = IS_NEW; CurrentPin->m_Unit = m_unit; @@ -614,21 +591,17 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC ) else CurrentPin->m_Attributs &= ~PINNOTDRAW; - CurrentPin->SetNext( m_component->m_Drawings ); - m_component->m_Drawings = CurrentPin; - m_component->SortDrawItems(); - if( DC ) - CurrentPin->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + CurrentPin->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, wxCOPY, &showPinText, DefaultTransformMatrix ); + PinPreviousPos = CurrentPin->m_Pos; + wxLogDebug( _( "Initial pin position (%d, %d)" ), + PinPreviousPos.x, PinPreviousPos.y ); DrawPanel->m_IgnoreMouseEvents = true; InstallPineditFrame( this, DC, wxPoint( -1, -1 ) ); DrawPanel->MouseToCursorSchema(); DrawPanel->m_IgnoreMouseEvents = false; - - PinPreviousPos = CurrentPin->m_Pos; - DrawPanel->ManageCurseur = DrawMovePin; DrawPanel->ForceCloseManageCurseur = AbortPinMove; @@ -637,27 +610,25 @@ void WinEDA_LibeditFrame::CreatePin( wxDC* DC ) } -/*********************************************************/ -void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw, - bool unit, bool convert ) -/*********************************************************/ - /* si draw == true - * - Ajuste le flag visible / invisible (.U.Pin.Flags bit 0 ) de la pin - * editee + * - Ajuste le flag visible / invisible (.U.Pin.Flags bit 0 ) de la pin + * editee * - * si unit == true - * - Modifie l'attribut Commun / Particulier U.Pin.Unit = 0 ou Num Unite - * de la pin editee + * si unit == true + * - Modifie l'attribut Commun / Particulier U.Pin.Unit = 0 ou Num Unite + * de la pin editee * - * si convert == true - * - Modifie l'attribut Commun / Particulier U.Pin.Convert = 0 ou Num Unite - * de la pin editee + * si convert == true + * - Modifie l'attribut Commun / Particulier U.Pin.Convert = 0 ou Num Unite + * de la pin editee * */ +void WinEDA_PinPropertiesFrame::SetPinAttributes( bool draw, bool unit, + bool convert ) { - LIB_DRAW_ITEM* DrawItem; - LibDrawPin* Pin, * CurrentPin = (LibDrawPin*) m_Parent->GetDrawItem(); + LibDrawPin* tmp; + LibDrawPin* Pin; + LibDrawPin* CurrentPin = (LibDrawPin*) m_Parent->GetDrawItem(); if( CurrentPin == NULL ) return; @@ -671,23 +642,19 @@ void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw, else CurrentPin->m_Unit = m_Parent->GetUnit(); - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - if( CurrentPin->m_Unit == 0 ) { - DrawItem = CurrentPin->GetParent()->m_Drawings; - for( ; DrawItem != NULL; ) + tmp = CurrentPin->GetParent()->GetNextPin(); + + while( tmp != NULL ) { - Pin = (LibDrawPin*) DrawItem; - DrawItem = DrawItem->Next(); - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; - if( Pin->m_Flags == 0 ) - continue; - if( Pin == CurrentPin ) + Pin = tmp; + tmp = CurrentPin->GetParent()->GetNextPin( Pin ); + + if( Pin->m_Flags == 0 || Pin == CurrentPin ) continue; if( CurrentPin->m_Convert - && (CurrentPin->m_Convert != Pin->m_Convert) ) + && ( CurrentPin->m_Convert != Pin->m_Convert ) ) continue; if( CurrentPin->m_Pos != Pin->m_Pos ) continue; @@ -708,18 +675,18 @@ void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw, if( CurrentPin->m_Convert == 0 ) /* Effacement des pins redondantes */ { - DrawItem = CurrentPin->GetParent()->m_Drawings; - for( ; DrawItem != NULL; ) + tmp = CurrentPin->GetParent()->GetNextPin(); + + while( tmp != NULL ) { - Pin = (LibDrawPin*) DrawItem; - DrawItem = DrawItem->Next(); - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; + Pin = tmp; + tmp = CurrentPin->GetParent()->GetNextPin( Pin ); + if( Pin->m_Flags == 0 ) continue; if( Pin == CurrentPin ) continue; - if( CurrentPin->m_Unit && (CurrentPin->m_Unit != Pin->m_Unit) ) + if( CurrentPin->m_Unit && ( CurrentPin->m_Unit != Pin->m_Unit ) ) continue; if( CurrentPin->m_Pos != Pin->m_Pos ) continue; @@ -738,8 +705,8 @@ void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw, else CurrentPin->m_Attributs &= ~PINNOTDRAW; - Pin = (LibDrawPin*) CurrentPin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = CurrentPin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = CurrentPin->GetParent()->GetNextPin( Pin ) ) { if( Pin->m_Flags == 0 ) continue; @@ -777,11 +744,9 @@ void WinEDA_PinPropertiesFrame::NewSizePin( int newsize ) if( g_EditPinByPinIsOn == false ) { - Pin = (LibDrawPin*) Pin->GetParent()->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = Pin->GetParent()->GetNextPin(); + for( ; Pin != NULL; Pin = Pin->GetParent()->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( Pin->m_Pos != RefPin->m_Pos ) continue; if( Pin->m_Orient != RefPin->m_Orient ) @@ -815,8 +780,7 @@ static void CreateImagePins( LibDrawPin* Pin, int unit, int convert, NewPin->m_Convert = 1; else NewPin->m_Convert = 2; - NewPin->SetNext( Pin->GetParent()->m_Drawings ); - Pin->GetParent()->m_Drawings = NewPin; + Pin->GetParent()->AddDrawItem( NewPin ); } for( ii = 1; ii <= Pin->GetParent()->m_UnitCount; ii++ ) @@ -829,8 +793,7 @@ static void CreateImagePins( LibDrawPin* Pin, int unit, int convert, if( convert != 0 ) NewPin->m_Convert = 1; NewPin->m_Unit = ii; - NewPin->SetNext( Pin->GetParent()->m_Drawings ); - Pin->GetParent()->m_Drawings = NewPin; + Pin->GetParent()->AddDrawItem( NewPin ); /* Creation pour la representation "Convert" */ if( CreateConv == false ) @@ -840,8 +803,7 @@ static void CreateImagePins( LibDrawPin* Pin, int unit, int convert, NewPin->m_Convert = 2; if( Pin->m_Unit != 0 ) NewPin->m_Unit = ii; - NewPin->SetNext( Pin->GetParent()->m_Drawings ); - Pin->GetParent()->m_Drawings = NewPin; + Pin->GetParent()->AddDrawItem( NewPin ); } } @@ -869,16 +831,14 @@ void WinEDA_LibeditFrame::GlobalSetPins( wxDC* DC, GetScreen()->SetModify(); - Pin = (LibDrawPin*) m_component->m_Drawings; - for( ; Pin != NULL; Pin = Pin->Next() ) + Pin = m_component->GetNextPin(); + for( ; Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) { - if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE ) - continue; if( ( Pin->m_Convert ) && ( Pin->m_Convert != m_convert ) ) continue; // Is it the "selected mode" ? - if( selected && (Pin->m_Selected & IS_SELECTED) == 0 ) + if( selected && ( Pin->m_Selected & IS_SELECTED ) == 0 ) continue; Pin->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, @@ -919,10 +879,9 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LibDrawPin* SourcePin ) return; Pin = (LibDrawPin*)SourcePin->GenCopy(); - Pin->SetNext( m_component->m_Drawings ); - m_component->m_Drawings = Pin; - Pin->m_Flags = IS_NEW; + m_component->AddDrawItem( Pin ); + Pin->m_Flags = IS_NEW; Pin->m_Pos.x += g_RepeatStep.x; ox = Pin->m_Pos.x; Pin->m_Pos.y += -g_RepeatStep.y; @@ -975,16 +934,15 @@ void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event ) return; // Construction de la liste des pins: - Pin = (LibDrawPin*) m_component->m_Drawings; - for( nb_pins = 0; Pin != NULL; Pin = Pin->Next() ) + Pin = m_component->GetNextPin(); + for( nb_pins = 0; Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) { - if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE ) - nb_pins++; + nb_pins++; } PinList = (LibDrawPin**) MyZMalloc( (nb_pins + 1) * sizeof(LibDrawPin*) ); - Pin = (LibDrawPin*) m_component->m_Drawings; - for( ii = 0; Pin != NULL; Pin = Pin->Next() ) + Pin = m_component->GetNextPin(); + for( ii = 0; Pin != NULL; Pin = m_component->GetNextPin( Pin ) ) { if( Pin->Type() == COMPONENT_PIN_DRAW_TYPE ) PinList[ii++] = Pin; @@ -1010,10 +968,10 @@ void WinEDA_LibeditFrame::OnCheckComponent( wxCommandEvent& event ) curr_pin->ReturnPinStringNum( StringPinNum ); msg.Printf( _( "Duplicate pin %s at location (%d, %d) conflicts \ with pin %s at location (%d, %d)" ), - (const wxChar*)StringPinNum, - (const wxChar*)curr_pin->m_PinName, + (const wxChar*) StringPinNum, + (const wxChar*) curr_pin->m_PinName, curr_pin->m_Pos.x, -curr_pin->m_Pos.y, - (const wxChar*)Pin->m_PinName, + (const wxChar*) Pin->m_PinName, Pin->m_Pos.x, -Pin->m_Pos.y ); if( m_component->m_UnitCount > 1 ) diff --git a/eeschema/plot.cpp b/eeschema/plot.cpp index 96bb7424e4..9c0d465585 100644 --- a/eeschema/plot.cpp +++ b/eeschema/plot.cpp @@ -65,7 +65,7 @@ static void PlotLibPart( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem ) Multi = DrawLibItem->m_Multi; convert = DrawLibItem->m_Convert; - for( LIB_DRAW_ITEM* DEntry = Entry->m_Drawings; + for( LIB_DRAW_ITEM* DEntry = Entry->GetNextDrawItem(); DEntry != NULL; DEntry = DEntry->Next() ) { /* Elimination des elements non relatifs a l'unite */ diff --git a/eeschema/protos.h b/eeschema/protos.h index b4bade6e79..777e127f47 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -21,14 +21,6 @@ class DrawSheetStruct; class LibDrawPin; -LIB_DRAW_ITEM* LocatePin( const wxPoint& RefPos, - LIB_COMPONENT* Entry, - int Unit, - int Convert, - SCH_COMPONENT* DrawItem = NULL ); - -/* Routine de localisation d'une PIN de la PartLib pointee par Entry */ - wxString ReturnDefaultFieldName( int aFieldNdx ); @@ -158,13 +150,6 @@ SCH_ITEM* PickStruct( const wxPoint& refpos, int SearchMask ); -LIB_DRAW_ITEM* LocateDrawItem( SCH_SCREEN* Screen, - const wxPoint& refpoint, - LIB_COMPONENT* LibEntry, - int Unit, - int Convert, - int masque ); - Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet, const wxPoint& pos ); LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, @@ -252,20 +237,6 @@ void EraseStruct( SCH_ITEM* DrawStruct, SCH_SCREEN* Window ); void DeleteAllMarkers( int type ); -/**************/ -/* GETPART.CPP */ -/**************/ - -int LookForConvertPart( LIB_COMPONENT* LibEntry ); - -/* Retourne la plus grande valeur trouvee dans la liste des elements - * "drawings" du composant LibEntry, pour le membre .Convert - * Si il n'y a pas de representation type "convert", la valeur - * retournee est 0 ou 1 - * Si il y a une representation type "convert", - * la valeur retournee est > 1 (typiquement 2) */ - - /**************/ /* PINEDIT.CPP */ /**************/ diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index cf6339ea92..da3cbee9a2 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -140,13 +140,12 @@ void WinEDA_LibeditFrame::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) } -/****************************************************************/ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC ) -/****************************************************************/ { LIB_DRAW_ITEM* item; + WinEDA_LibeditFrame* parent = ( WinEDA_LibeditFrame* ) Panel->GetParent(); - item = ( ( WinEDA_LibeditFrame* ) Panel->GetParent() )->GetDrawItem(); + item = parent->GetDrawItem(); if( item == NULL ) return; @@ -164,6 +163,7 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC ) DefaultTransformMatrix ); SAFE_DELETE( item ); + parent->SetDrawItem( NULL ); } else { @@ -297,12 +297,10 @@ error" ) ); } -/********************************************************/ -void WinEDA_LibeditFrame::GraphicItemBeginDraw( wxDC* DC ) -/********************************************************/ - -/* Routine de creation d'un nouvel element type LibraryDrawStruct +/* + * Routine de creation d'un nouvel element type LibraryDrawStruct */ +void WinEDA_LibeditFrame::GraphicItemBeginDraw( wxDC* DC ) { if( m_drawItem == NULL ) return; @@ -520,16 +518,14 @@ static void SymbolDisplayDraw( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ) } -/******************************************************/ -void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) -/******************************************************/ - -/* Place la structure courante en liste des structures du composant - * courant, si elle existe et redessine toujours celle ci +/* + * Place la structure courante en liste des structures du composant + * courant, si elle existe et redessine toujours celle ci * Parametres: (tous globaux) * m_drawItem * m_component */ +void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) { if( m_component == NULL || m_drawItem == NULL ) return; @@ -538,11 +534,12 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) { if( StateDrawArc == 1 ) /* Trace d'arc en cours: doit etre termine */ { - DisplayError( this, wxT( "Arc in progress.." ), 10 ); return; + DisplayError( this, wxT( "Arc in progress.." ) ); + return; } else { - if( (m_drawItem->m_Flags & IS_MOVED) == 0 ) + if( ( m_drawItem->m_Flags & IS_MOVED ) == 0 ) SymbolDisplayDraw( DrawPanel, DC, FALSE ); } } @@ -552,8 +549,7 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) if( m_drawItem->m_Flags & IS_NEW ) { SaveCopyInUndoList( m_component ); - m_drawItem->SetNext( m_component->m_Drawings ); - m_component->m_Drawings = m_drawItem; + m_component->AddDrawItem( m_drawItem ); switch( m_drawItem->Type() ) { @@ -581,8 +577,6 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) default: ; } - - m_component->SortDrawItems(); } if( m_ID_current_state ) @@ -590,7 +584,7 @@ void WinEDA_LibeditFrame::EndDrawGraphicItem( wxDC* DC ) else SetCursor( wxCURSOR_ARROW ); - if( (m_drawItem->m_Flags & IS_MOVED) ) + if( m_drawItem->m_Flags & IS_MOVED ) { wxPoint pos; pos.x = GetScreen()->m_Curseur.x + InitPosition.x - StartCursor.x, @@ -702,12 +696,10 @@ static void ComputeArc( LibDrawArc* DrawItem, wxPoint ArcCentre ) } -/***************************************************/ -void WinEDA_LibeditFrame::DeleteDrawPoly( wxDC* DC ) -/**************************************************/ - -/* Used for deleting last entered segment while creating a Polyline +/* + * Used for deleting last entered segment while creating a Polyline */ +void WinEDA_LibeditFrame::DeleteDrawPoly( wxDC* DC ) { if( m_drawItem == NULL || m_drawItem->Type() != COMPONENT_POLYLINE_DRAW_TYPE ) @@ -718,7 +710,8 @@ void WinEDA_LibeditFrame::DeleteDrawPoly( wxDC* DC ) m_drawItem->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, NULL, DefaultTransformMatrix ); - while( Poly->GetCornerCount() > 2 ) // First segment is kept, only its end point is changed + // First segment is kept, only its end point is changed + while( Poly->GetCornerCount() > 2 ) { Poly->m_PolyPoints.pop_back(); unsigned idx = Poly->GetCornerCount() - 1; diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index 78dbd75369..4158d29a44 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -96,9 +96,9 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void ) DisplayError( this, _( "Warning: more than 1 part in Symbol File" ) ); Component = (LIB_COMPONENT*) Lib->GetFirstEntry(); - DrawEntry = Component->m_Drawings; + DrawEntry = Component->GetNextDrawItem(); - while( DrawEntry ) + while( DrawEntry != NULL ) { if( DrawEntry->m_Unit ) DrawEntry->m_Unit = m_unit; @@ -107,14 +107,9 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void ) DrawEntry->m_Flags = IS_NEW; DrawEntry->m_Selected = IS_SELECTED; - if( DrawEntry->Next() == NULL ) /* Fin de liste trouvee */ - { - DrawEntry->SetNext( m_component->m_Drawings ); - m_component->m_Drawings = Component->m_Drawings; - Component->m_Drawings = NULL; - break; - } - + LIB_DRAW_ITEM* newItem = DrawEntry->GenCopy(); + newItem->SetParent( m_component ); + m_component->AddDrawItem( newItem ); DrawEntry = DrawEntry->Next(); } @@ -122,13 +117,7 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void ) m_component->RemoveDuplicateDrawItems(); // Clear flags - DrawEntry = m_component->m_Drawings; - while( DrawEntry ) - { - DrawEntry->m_Flags = 0; - DrawEntry->m_Selected = 0; - DrawEntry = DrawEntry->Next(); - } + m_component->ClearSelectedItems(); GetScreen()->SetModify(); DrawPanel->Refresh(); @@ -151,7 +140,7 @@ void WinEDA_LibeditFrame::SaveOneSymbol() wxString msg; FILE* ExportFile; - if( m_component->m_Drawings == NULL ) + if( m_component->GetNextDrawItem() == NULL ) return; /* Creation du fichier symbole */ @@ -215,11 +204,12 @@ void WinEDA_LibeditFrame::SaveOneSymbol() /* Position / orientation / visibilite des champs */ m_component->m_Prefix.Save( ExportFile ); m_component->m_Name.Save( ExportFile ); - DrawEntry = m_component->m_Drawings; + DrawEntry = m_component->GetNextDrawItem(); if( DrawEntry ) { fprintf( ExportFile, "DRAW\n" ); + for( ; DrawEntry != NULL; DrawEntry = DrawEntry->Next() ) { /* Elimination des elements non relatifs a l'unite */ diff --git a/include/base_struct.h b/include/base_struct.h index 179b1238a8..87dca7926c 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -255,7 +255,7 @@ protected: public: - int m_Flags; // flags for editing and other misc. uses + int m_Flags; // flags for editing and other uses. unsigned long m_TimeStamp; // Time stamp used for logical links int m_Selected; /* Used by block commands, and selective editing */