Schematic editor locate item changes and other minor fixes.

* Move locate function code into schematic screen object.
* Move test for junction needed into schematic screen object.
* Move test for marking connected items into schematic screen object.
* Move delete item function code into schematic screen object.
* Move delete all markers code into schematic screen object.
* Add method for locating multiple items in schematic screen object.
* Fix minor bug in schematic field object hit test declaration.
* Initial encapsulation work on item picker object.
* Remove duplicate doxygen comments from item picker object source file.
This commit is contained in:
Wayne Stambaugh 2011-03-10 14:36:30 -05:00
parent 628e524075
commit c07b677a20
22 changed files with 723 additions and 1112 deletions

View File

@ -2,6 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2009 jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2009 Kicad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@ -26,7 +27,6 @@
#include "common.h"
#include "base_struct.h"
//#include "sch_item_struct.h"
#include "base_struct.h"
#include "class_undoredo_container.h"
@ -51,20 +51,12 @@ PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST()
}
/** PushItem
* push a picker to the top of the list
* @param aItem = picker to push
*/
void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem )
{
m_ItemsList.push_back( aItem );
}
/** PopItem
* @return the picker from the top of the list
* the picker is removed from the list
*/
ITEM_PICKER PICKED_ITEMS_LIST::PopItem()
{
ITEM_PICKER item;
@ -74,25 +66,29 @@ ITEM_PICKER PICKED_ITEMS_LIST::PopItem()
item = m_ItemsList.back();
m_ItemsList.pop_back();
}
return item;
}
/**
* Function ClearItemsList
* delete only the list of pickers, NOT the picked data itself
*/
bool PICKED_ITEMS_LIST::ContainsItem( EDA_ITEM* aItem ) const
{
for( size_t i = 0; i < m_ItemsList.size(); i++ )
{
if( m_ItemsList[ i ].m_PickedItem == aItem )
return true;
}
return false;
}
void PICKED_ITEMS_LIST::ClearItemsList()
{
m_ItemsList.clear();
}
/**
* Function ClearListAndDeleteItems
* delete the list of pickers, AND the data pointed
* by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
*/
void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{
bool show_error_message = true;
@ -108,13 +104,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
case UR_UNSPECIFIED:
if( show_error_message )
wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) );
show_error_message = false;
break;
case UR_WIRE_IMAGE:
{
// Specific to eeschema: a linked list of wires is stored.
// the wrapper picks only the first item (head of list), and is owner of all picked items
// Specific to eeschema: a linked list of wires is stored. The wrapper picks only
// the first item (head of list), and is owner of all picked items.
EDA_ITEM* item = wrapper.m_PickedItem;
while( item )
@ -144,8 +141,8 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
case UR_LIBEDIT: /* Libedit save always a copy of the current item
* So, the picker is always owner of the picked item
*/
case UR_MODEDIT: /* Specific to the module editor
* (modedit creates a full copy of the current module when changed),
case UR_MODEDIT: /* Specific to the module editor (modedit creates a full
* copy of the current module when changed),
* and the picker is owner of this item
*/
delete wrapper.m_PickedItem;
@ -164,13 +161,6 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
}
/**
* Function GetItemWrapper
* @return the picker of a picked item
* @param aIdx = index of the picker in the picked list
* if this picker does not exist, a picker is returned,
* with its members set to 0 or NULL
*/
ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{
ITEM_PICKER picker;
@ -182,11 +172,6 @@ ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
}
/**
* Function GetPickedItem
* @return a pointer to the picked item, or null if does not exist
* @param aIdx = index of the picked item in the picked list
*/
EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -196,11 +181,6 @@ EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx )
}
/**
* Function GetPickedItemLink
* @return link of the picked item, or null if does not exist
* @param aIdx = index of the picked item in the picked list
*/
EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -210,12 +190,6 @@ EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx )
}
/**
* Function GetPickedItemStatus
* @return the type of undo/redo opertaion associated to the picked item,
* or UR_UNSPECIFIED if does not exist
* @param aIdx = index of the picked item in the picked list
*/
UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -224,12 +198,7 @@ UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
return UR_UNSPECIFIED;
}
/**
* Function GetPickerFlags
* return the value of the picker flag
* @param aIdx = index of the picker in the picked list
* @return the value stored in the picker, if the picker exists, or 0 if does not exist
*/
int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -238,12 +207,7 @@ int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx )
return 0;
}
/**
* Function SetPickedItem
* @param aItem = a pointer to the item to pick
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -256,13 +220,6 @@ bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx )
}
/**
* Function SetPickedItemLink
* Set the link associated to a given picked item
* @param aLink = the link to the item associated to the picked item
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -275,13 +232,6 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx )
}
/**
* Function SetPickedItem
* @param aItem = a pointer to the item to pick
* @param aStatus = the type of undo/redo operation associated to the item to pick
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -295,13 +245,6 @@ bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus,
}
/**
* Function SetPickedItemStatus
* Set the the type of undo/redo operation for a given picked item
* @param aStatus = the type of undo/redo operation associated to the picked item
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -312,13 +255,8 @@ bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aI
else
return false;
}
/**
* Function SetPickerFlags
* Set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags = the value to save in picker
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
*/
bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx )
{
if( aIdx < m_ItemsList.size() )
@ -331,12 +269,6 @@ bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx )
}
/**
* Function RemovePicker
* rem<EFBFBD>ove one entry (one picker) from the list of picked items
* @param aIdx = index of the picker in the picked list
* @return true if ok, or false if did not exist
*/
bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx )
{
if( aIdx >= m_ItemsList.size() )
@ -346,24 +278,12 @@ bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx )
}
/**
* Function CopyList
* copy all data from aSource
* Picked items are not copied. just pointers on them are copied
*/
void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
{
m_ItemsList = aSource.m_ItemsList; // Vector's copy
}
/**
* Function ReversePickersListOrder
* reverses the order of pickers stored in this list
* Useful when pop a list from Undo to Redo (and vice-versa)
* because sometimes undo (or redo) a command needs to keep the
* order of successive changes.
* and obviously, undo and redo are in reverse order
*/
void PICKED_ITEMS_LIST::ReversePickersListOrder()
{
std::vector <ITEM_PICKER> tmp;

View File

@ -33,7 +33,6 @@ extern void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveV
extern void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
extern void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint );
extern void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
extern void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
extern void DuplicateItemsInList( SCH_SCREEN* screen,
PICKED_ITEMS_LIST& aItemsList,
const wxPoint aMoveVector );
@ -522,22 +521,19 @@ void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList )
{
m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists
/* save the new list: */
ITEM_PICKER item;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
// Clear m_Flag member of selected items:
aItemsList.GetPickedItem( ii )->ClearFlags();
/* Make a copy of the original picked item. */
SCH_ITEM* copy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
copy->SetParent( NULL );
// In list the wrapper is owner of the schematic item, we can use the UR_DELETED
// status for the picker because pickers with this status are owner of the picked item
// (or TODO ?: create a new status like UR_DUPLICATE)
item.m_UndoRedoStatus = UR_DELETED;
ITEM_PICKER item( copy, UR_DELETED );
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
// Clear m_Flag member of selected items:
aItemsList.GetPickedItem( ii )->m_Flags = 0;
/* Make a copy of the original picked item. */
SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
DrawStructCopy->SetParent( NULL );
item.m_PickedItem = DrawStructCopy;
m_blockItems.PushItem( item );
}
}
@ -559,13 +555,12 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
PICKED_ITEMS_LIST picklist;
// Creates data, and push it as new data in undo item list buffer
ITEM_PICKER picker( NULL, UR_NEW );
for( unsigned ii = 0; ii < m_blockItems.GetCount(); ii++ )
{
Struct = DuplicateStruct( (SCH_ITEM*) m_blockItems.m_ItemsSelection.GetPickedItem( ii ) );
picker.m_PickedItem = Struct;
// Creates data, and push it as new data in undo item list buffer
ITEM_PICKER picker( Struct, UR_NEW );
picklist.PushItem( picker );
// Clear annotation and init new time stamp for the new components:
@ -574,6 +569,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
( (SCH_COMPONENT*) Struct )->m_TimeStamp = GetTimeStamp();
( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL );
}
SetSchItemParent( Struct, GetScreen() );
Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
Struct->SetNext( GetScreen()->GetDrawItems() );
@ -584,7 +580,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector );
/* clear .m_Flags member for all items */
// Clear flags for all items.
GetScreen()->ClearDrawingState();
OnModify();

View File

@ -26,7 +26,6 @@
static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC );
static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer );
static bool IsJunctionNeeded( SCH_EDIT_FRAME* frame, wxPoint& pos );
static void ComputeBreakPoint( SCH_LINE* segment, const wxPoint& new_pos );
SCH_ITEM* s_OldWiresList;
@ -92,7 +91,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
SCH_LINE* oldsegment, * newsegment, * nextsegment;
wxPoint cursorpos = GetScreen()->GetCrossHairPosition();
if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->m_Flags == 0) )
if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->GetFlags() == 0) )
GetScreen()->SetCurItem( NULL );
if( GetScreen()->GetCurItem() )
@ -134,12 +133,12 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
break;
}
newsegment->m_Flags = IS_NEW;
newsegment->SetFlags( IS_NEW );
if( g_HVLines ) // We need 2 segments to go from a given start pin to an end point
{
nextsegment = new SCH_LINE( *newsegment );
nextsegment->m_Flags = IS_NEW;
nextsegment->SetFlags( IS_NEW );
newsegment->SetNext( nextsegment );
nextsegment->SetBack( newsegment );
}
@ -199,8 +198,9 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
}
newsegment->m_End = cursorpos;
oldsegment->m_Flags = SELECTED;
newsegment->m_Flags = IS_NEW;
oldsegment->ClearFlags( IS_NEW );
oldsegment->SetFlags( SELECTED );
newsegment->SetFlags( IS_NEW );
GetScreen()->SetCurItem( newsegment );
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
@ -210,7 +210,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
* (tested when the connection will be finished)*/
if( oldsegment->m_Start == s_ConnexionStartPoint )
{
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) )
if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
AddJunction( DC, s_ConnexionStartPoint );
}
}
@ -291,28 +291,28 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
while( segment )
{
if( segment->m_Flags )
if( segment->GetFlags() )
{
if( !m_itemToRepeat )
m_itemToRepeat = segment;
}
segment->m_Flags = 0;
segment->ClearFlags();
segment = segment->Next();
}
// Automatic place of a junction on the end point, if needed
if( lastsegment )
{
if( IsJunctionNeeded( this, end_point ) )
if( GetScreen()->IsJunctionNeeded( end_point ) )
AddJunction( DC, end_point );
else if( IsJunctionNeeded( this, alt_end_point ) )
else if( GetScreen()->IsJunctionNeeded( alt_end_point ) )
AddJunction( DC, alt_end_point );
}
/* Automatic place of a junction on the start point if necessary because
* the cleanup can suppress intermediate points by merging wire segments */
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) )
if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
AddJunction( DC, s_ConnexionStartPoint );
GetScreen()->TestDanglingEnds( DrawPanel, DC );
@ -500,14 +500,8 @@ static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC )
parent->SetRepeatItem( NULL );
}
/* Clear m_Flags which is used in edit functions: */
SCH_ITEM* item = screen->GetDrawItems();
while( item )
{
item->m_Flags = 0;
item = item->Next();
}
// Clear flags used in edit functions.
screen->ClearDrawingState();
}
@ -526,7 +520,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
{
wxPoint pos = GetScreen()->GetCrossHairPosition() -
( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos;
m_itemToRepeat->m_Flags = IS_NEW;
m_itemToRepeat->SetFlags( IS_NEW );
( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp();
m_itemToRepeat->Move( pos );
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
@ -546,7 +540,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
GetScreen()->TestDanglingEnds();
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
SaveCopyInUndoList( m_itemToRepeat, UR_NEW );
m_itemToRepeat->m_Flags = 0;
m_itemToRepeat->ClearFlags();
}
}
@ -601,7 +595,7 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
switch( layer )
{
case LAYER_BUS:
item = PickStruct( pos, screen, BUS_T );
item = screen->GetItem( pos, 0, BUS_T );
if( item )
return true;
@ -618,13 +612,14 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
break;
case LAYER_NOTES:
item = PickStruct( pos, screen, DRAW_ITEM_T );
item = screen->GetItem( pos, 0, DRAW_ITEM_T );
if( item )
return true;
break;
case LAYER_WIRE:
item = PickStruct( pos, screen, BUS_ENTRY_T | JUNCTION_T );
item = screen->GetItem( pos, MAX( g_DrawDefaultLineThickness, 3 ),
BUS_ENTRY_T | JUNCTION_T );
if( item )
return true;
@ -643,12 +638,12 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
return true;
}
item = PickStruct( pos, screen, WIRE_T );
item = screen->GetItem( pos, 0, WIRE_T );
if( item )
return true;
item = PickStruct( pos, screen, LABEL_T );
item = screen->GetItem( pos, 0, LABEL_T );
if( item && (item->Type() != SCH_TEXT_T)
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.x == pos.x )
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.y == pos.y ) )
@ -672,29 +667,3 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
return false;
}
/* Return True when a wire is located at pos "pos" if
* - there is no junction.
* - The wire has no ends at pos "pos",
* and therefore it is considered as no connected.
* - One (or more) wire has one end at pos "pos"
* or
* - a pin is on location pos
*/
bool IsJunctionNeeded( SCH_EDIT_FRAME* frame, wxPoint& pos )
{
if( PickStruct( pos, frame->GetScreen(), JUNCTION_T ) )
return false;
if( PickStruct( pos, frame->GetScreen(), WIRE_T | EXCLUDE_ENDPOINTS_T ) )
{
if( PickStruct( pos, frame->GetScreen(), WIRE_T | ENDPOINTS_ONLY_T ) )
return true;
if( frame->GetScreen()->GetPin( pos, NULL, true ) )
return true;
}
return false;
}

View File

@ -120,7 +120,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
wxString Text;
wxString msg;
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), MARKER_T );
item = GetScreen()->GetItem( aPosition, 0, MARKER_T );
if( item )
{
@ -128,7 +128,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_CONNECT_T );
item = GetScreen()->GetItem( aPosition, 0, NO_CONNECT_T );
if( item )
{
@ -136,7 +136,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), JUNCTION_T );
item = GetScreen()->GetItem( aPosition, 0, JUNCTION_T );
if( item )
{
@ -144,7 +144,8 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), WIRE_T | BUS_T | BUS_ENTRY_T );
item = GetScreen()->GetItem( aPosition, MAX( g_DrawDefaultLineThickness, 3 ),
WIRE_T | BUS_T | BUS_ENTRY_T );
if( item ) // We have found a wire: Search for a connected pin at the same location
{
@ -164,17 +165,20 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), DRAW_ITEM_T );
item = GetScreen()->GetItem( aPosition, 0, DRAW_ITEM_T );
if( item )
{
ClearMsgPanel();
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), FIELD_T );
item = GetScreen()->GetItem( aPosition, 0, FIELD_T );
if( item )
{
wxASSERT( item->Type() == SCH_FIELD_T );
SCH_FIELD* Field = (SCH_FIELD*) item;
LibItem = (SCH_COMPONENT*) Field->GetParent();
LibItem->DisplayInfo( this );
@ -182,7 +186,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), LABEL_T | TEXT_T );
item = GetScreen()->GetItem( aPosition, 0, LABEL_T | TEXT_T );
if( item )
{
@ -204,7 +208,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return LibItem;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), COMPONENT_T );
item = GetScreen()->GetItem( aPosition, 0, COMPONENT_T );
if( item )
{
@ -214,7 +218,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), SHEET_T );
item = GetScreen()->GetItem( aPosition, 0, SHEET_T );
if( item )
{
@ -222,7 +226,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item;
}
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_FILTER_T );
item = GetScreen()->GetItem( aPosition );
if( item )
return item;
@ -295,7 +299,7 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey )
{
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else
OnHotKey( aDC, aHotKey, aPosition, NULL );
@ -368,7 +372,7 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey )
{
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else
OnHotKey( aDC, aHotKey, aPosition, NULL );
@ -441,7 +445,7 @@ void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey )
{
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags )
if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else
OnHotKey( aDC, aHotKey, aPosition, NULL );

View File

@ -17,98 +17,36 @@
#include "sch_text.h"
// Imported function:
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
/*
* Mark to "CANDIDATE" all wires or junction connected to "segment" in list
* "ListStruct"
* Search wire stop at an any pin
*
* Used by SCH_EDIT_FRAME::DeleteConnection()
*/
static bool MarkConnected( SCH_EDIT_FRAME* frame, SCH_ITEM* ListStruct, SCH_LINE* segment )
{
EDA_ITEM* Struct;
for( Struct = ListStruct; Struct != NULL; Struct = Struct->Next() )
{
if( Struct->m_Flags )
continue;
if( Struct->Type() == SCH_JUNCTION_T )
{
#define JUNCTION ( (SCH_JUNCTION*) Struct )
if( segment->IsEndPoint( JUNCTION->m_Pos ) )
Struct->m_Flags |= CANDIDATE;
continue;
#undef JUNCTION
}
if( Struct->Type() != SCH_LINE_T )
continue;
#define SEGM ( (SCH_LINE*) Struct )
if( segment->IsEndPoint( SEGM->m_Start ) )
{
if( !frame->GetScreen()->GetPin( SEGM->m_Start, NULL, true ) )
{
Struct->m_Flags |= CANDIDATE;
MarkConnected( frame, ListStruct, SEGM );
}
}
if( segment->IsEndPoint( SEGM->m_End ) )
{
if( !frame->GetScreen()->GetPin( SEGM->m_End, NULL, true ) )
{
Struct->m_Flags |= CANDIDATE;
MarkConnected( frame, ListStruct, SEGM );
}
}
#undef SEGM
}
return TRUE;
}
/*
* Delete a connection, i.e wires or bus connected
* stop on a node (more than 2 wires (bus) connected)
*/
void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
{
SCH_SCREEN* screen = GetScreen();
wxPoint refpos = screen->GetCrossHairPosition();
SCH_ITEM* DelStruct;
SCH_ITEM* item;
EDA_ITEM* tmp;
PICKED_ITEMS_LIST pickList;
SCH_SCREEN* screen = GetScreen();
wxPoint pos = screen->GetCrossHairPosition();
/* Clear .m_Flags member for all items */
// Clear flags member for all items.
screen->ClearDrawingState();
screen->BreakSegmentsOnJunctions();
/* Locate all the wires, bus or junction under the mouse cursor, and put
* them in a list of items to delete
*/
ITEM_PICKER picker( NULL, UR_DELETED );
// Save the list entry point of this screen
SCH_ITEM* savedItems = screen->GetDrawItems();
DelStruct = screen->GetDrawItems();
item = screen->GetDrawItems();
while( DelStruct
&& ( DelStruct = PickStruct( screen->GetCrossHairPosition(), screen,
JUNCTION_T | WIRE_T | BUS_T ) ) != NULL )
while( item && ( item = screen->GetItem( pos, 0, JUNCTION_T | WIRE_T | BUS_T ) ) != NULL )
{
DelStruct->m_Flags = SELECTEDNODE | STRUCT_DELETED;
item->SetFlags( SELECTEDNODE | STRUCT_DELETED );
/* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct;
picker.m_PickedItemType = DelStruct->Type();
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
DelStruct = DelStruct->Next();
screen->SetDrawItems( DelStruct );
item = item->Next();
screen->SetDrawItems( item );
}
screen->SetDrawItems( savedItems ); // Restore the list entry point.
@ -117,150 +55,134 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
*/
if( DeleteFullConnection )
{
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL;
DelStruct = DelStruct->Next() )
SCH_LINE* segment;
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
if( !(DelStruct->m_Flags & SELECTEDNODE) )
if( !(item->GetFlags() & SELECTEDNODE) )
continue;
#define SEGM ( (SCH_LINE*) DelStruct )
if( DelStruct->Type() != SCH_LINE_T )
if( item->Type() != SCH_LINE_T )
continue;
MarkConnected( this, screen->GetDrawItems(), SEGM );
#undef SEGM
screen->MarkConnections( (SCH_LINE*) item );
}
// Search all removable wires (i.e wire with one new dangling end )
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL;
DelStruct = DelStruct->Next() )
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
bool noconnect = FALSE;
bool noconnect = false;
if( DelStruct->m_Flags & STRUCT_DELETED )
if( item->GetFlags() & STRUCT_DELETED )
continue; // Already seen
if( !(DelStruct->m_Flags & CANDIDATE) )
if( !(item->GetFlags() & CANDIDATE) )
continue; // Already seen
if( DelStruct->Type() != SCH_LINE_T )
if( item->Type() != SCH_LINE_T )
continue;
DelStruct->m_Flags |= SKIP_STRUCT;
#define SEGM ( (SCH_LINE*) DelStruct )
item->SetFlags( SKIP_STRUCT );
segment = (SCH_LINE*) item;
/* Test the SEGM->m_Start point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire can
* be deleted */
EDA_ITEM* removed_struct;
for( removed_struct = screen->GetDrawItems();
removed_struct != NULL;
removed_struct = removed_struct->Next() )
SCH_LINE* testSegment = NULL;
for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
{
if( ( removed_struct->m_Flags & STRUCT_DELETED ) == 0 )
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( removed_struct->Type() != SCH_LINE_T )
if( tmp->Type() != SCH_LINE_T )
continue;
#define WIRE ( (SCH_LINE*) removed_struct )
if( WIRE->IsEndPoint( SEGM->m_Start ) )
testSegment = (SCH_LINE*) tmp;
if( testSegment->IsEndPoint( segment->m_Start ) )
break;
}
if( WIRE && !screen->CountConnectedItems( SEGM->m_Start, true ) )
noconnect = TRUE;
if( testSegment && !screen->CountConnectedItems( segment->m_Start, true ) )
noconnect = true;
/* Test the SEGM->m_End point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire
* can be deleted */
for( removed_struct = screen->GetDrawItems();
removed_struct != NULL;
removed_struct = removed_struct->Next() )
for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
{
if( ( removed_struct->m_Flags & STRUCT_DELETED ) == 0 )
if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue;
if( removed_struct->Type() != SCH_LINE_T )
if( tmp->Type() != SCH_LINE_T )
continue;
if( WIRE->IsEndPoint( SEGM->m_End ) )
if( testSegment->IsEndPoint( segment->m_End ) )
break;
}
if( removed_struct && !screen->CountConnectedItems( SEGM->m_End, true ) )
noconnect = TRUE;
if( tmp && !screen->CountConnectedItems( segment->m_End, true ) )
noconnect = true;
DelStruct->m_Flags &= ~SKIP_STRUCT;
item->ClearFlags( SKIP_STRUCT );
if( noconnect )
{
DelStruct->m_Flags |= STRUCT_DELETED;
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct;
picker.m_PickedItemType = DelStruct->Type();
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
DelStruct = screen->GetDrawItems();
item = screen->GetDrawItems();
}
#undef SEGM
}
// Delete redundant junctions (junctions which connect < 3 end wires
// and no pin are removed)
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL;
DelStruct = DelStruct->Next() )
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
if( DelStruct->m_Flags & STRUCT_DELETED )
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( !(DelStruct->m_Flags & CANDIDATE) )
if( !(item->GetFlags() & CANDIDATE) )
continue;
if( DelStruct->Type() == SCH_JUNCTION_T )
{
#define JUNCTION ( (SCH_JUNCTION*) DelStruct )
if( item->Type() != SCH_JUNCTION_T )
continue;
if( screen->CountConnectedItems( JUNCTION->m_Pos, false ) <= 2 )
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( screen->CountConnectedItems( junction->m_Pos, false ) <= 2 )
{
DelStruct->m_Flags |= STRUCT_DELETED;
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct;
picker.m_PickedItemType = DelStruct->Type();
pickList.PushItem( picker );
}
#undef JUNCTION
}
}
// Delete labels attached to wires
wxPoint pos = screen->GetCrossHairPosition();
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL;
DelStruct = DelStruct->Next() )
{
if( DelStruct->m_Flags & STRUCT_DELETED )
continue;
if( DelStruct->Type() != SCH_LABEL_T )
continue;
GetScreen()->SetCrossHairPosition( ( (SCH_TEXT*) DelStruct )->m_Pos );
EDA_ITEM* TstStruct = PickStruct( screen->GetCrossHairPosition(), GetScreen(),
WIRE_T | BUS_T );
if( TstStruct && TstStruct->m_Flags & STRUCT_DELETED )
{
DelStruct->m_Flags |= STRUCT_DELETED;
/* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct;
picker.m_PickedItemType = DelStruct->Type();
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
}
}
screen->SetCrossHairPosition( pos );
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & STRUCT_DELETED )
continue;
if( item->Type() != SCH_LABEL_T )
continue;
tmp = screen->GetItem( ( (SCH_TEXT*) item )->m_Pos, 0, WIRE_T | BUS_T );
if( tmp && tmp->GetFlags() & STRUCT_DELETED )
{
item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */
ITEM_PICKER picker( item, UR_DELETED );
pickList.PushItem( picker );
}
}
}
screen->ClearDrawingState();
@ -273,139 +195,46 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
}
/*
* Locate and delete the item found under the mouse cursor
* If more than one item found: the priority order is:
* 1 : MARKER
* 2 : JUNCTION
* 2 : NOCONNECT
* 3 : WIRE or BUS
* 4 : GRAPHIC ITEM
* 5 : TEXT
* 6 : COMPONENT
* 7 : SHEET
*
* return TRUE if an item was deleted
*/
bool LocateAndDeleteItem( SCH_EDIT_FRAME* frame, wxDC* DC )
bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
{
SCH_ITEM* DelStruct;
SCH_SCREEN* screen = (SCH_SCREEN*) ( frame->GetScreen() );
bool item_deleted = FALSE;
SCH_ITEM* item;
SCH_SCREEN* screen = GetScreen();
bool item_deleted = false;
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, MARKER_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, JUNCTION_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, NO_CONNECT_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, BUS_ENTRY_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, WIRE_T | BUS_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, DRAW_ITEM_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, TEXT_T | LABEL_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, COMPONENT_T );
if( DelStruct == NULL )
DelStruct = PickStruct( screen->GetCrossHairPosition(), screen, SHEET_T );
item = screen->GetItem( screen->GetCrossHairPosition(), 0, MARKER_T );
if( DelStruct )
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, JUNCTION_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, NO_CONNECT_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, BUS_ENTRY_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, WIRE_T | BUS_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, DRAW_ITEM_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, TEXT_T | LABEL_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, COMPONENT_T );
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, SHEET_T );
if( item )
{
frame->SetRepeatItem( NULL );
DeleteStruct( frame->DrawPanel, DC, DelStruct );
frame->GetScreen()->TestDanglingEnds( frame->DrawPanel, DC );
frame->OnModify( );
item_deleted = TRUE;
SetRepeatItem( NULL );
DeleteItem( item );
screen->TestDanglingEnds( DrawPanel, DC );
OnModify();
item_deleted = true;
}
return item_deleted;
}
/*
* Remove definition of a structure in a linked list
* Elements of Drawing
* DrawStruct * = pointer to the structure
* Screen = pointer on the screen of belonging
*
* Note:
* SCH_SHEET_T structures for the screen and structures
* Corresponding keys are not.
* They must be treated separately
*/
void EraseStruct( SCH_ITEM* DrawStruct, SCH_SCREEN* Screen )
{
EDA_ITEM* DrawList;
if( DrawStruct == NULL )
return;
if( Screen == NULL )
return;
Screen->SetModify();
if( DrawStruct->Type() == SCH_SHEET_LABEL_T )
{
// This structure is attached to a sheet, get the parent sheet object.
SCH_SHEET_PIN* sheetLabel = (SCH_SHEET_PIN*) DrawStruct;
SCH_SHEET* sheet = sheetLabel->GetParent();
wxASSERT_MSG( sheet != NULL,
wxT( "Sheet label parent not properly set, bad programmer!" ) );
sheet->RemoveLabel( sheetLabel );
return;
}
else
{
if( DrawStruct == Screen->GetDrawItems() )
{
Screen->SetDrawItems( DrawStruct->Next() );
SAFE_DELETE( DrawStruct );
}
else
{
DrawList = Screen->GetDrawItems();
while( DrawList && DrawList->Next() )
{
if( DrawList->Next() == DrawStruct )
{
DrawList->SetNext( DrawStruct->Next() );
SAFE_DELETE( DrawStruct );
return;
}
DrawList = DrawList->Next();
}
}
}
}
void DeleteAllMarkers( int type )
{
SCH_SCREEN* screen;
SCH_ITEM * DrawStruct, * NextStruct;
SCH_MARKER* Marker;
SCH_SCREENS ScreenList;
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() )
{
for( DrawStruct = screen->GetDrawItems(); DrawStruct != NULL; DrawStruct = NextStruct )
{
NextStruct = DrawStruct->Next();
if( DrawStruct->Type() != SCH_MARKER_T )
continue;
Marker = (SCH_MARKER*) DrawStruct;
if( Marker->GetMarkerType() != type )
continue;
/* Remove marker */
EraseStruct( DrawStruct, screen );
}
}
}

View File

@ -85,7 +85,8 @@ void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
{
/* Delete the old ERC markers, over the whole hierarchy
*/
DeleteAllMarkers( MARK_ERC );
SCH_SCREENS ScreenList;
ScreenList.DeleteAllMarkers( MARK_ERC );
m_MarkersList->ClearList();
m_Parent->DrawPanel->Refresh();
}
@ -427,14 +428,13 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
}
/* Erase all DRC markers */
DeleteAllMarkers( MARK_ERC );
SCH_SCREENS ScreenList;
ScreenList.DeleteAllMarkers( MARK_ERC );
g_EESchemaVar.NbErrorErc = 0;
g_EESchemaVar.NbWarningErc = 0;
/* Cleanup the entire hierarchy */
SCH_SCREENS ScreenList;
for( SCH_SCREEN* Screen = ScreenList.GetFirst();
Screen != NULL;
Screen = ScreenList.GetNext() )

View File

@ -79,8 +79,8 @@ void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC )
void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC )
{
if( aTextItem == NULL )
aTextItem = (SCH_TEXT*) PickStruct( GetScreen()->GetCrossHairPosition(),
GetScreen(), TEXT_T | LABEL_T );
aTextItem = (SCH_TEXT*) GetScreen()->GetItem( GetScreen()->GetCrossHairPosition(), 0,
TEXT_T | LABEL_T );
if( aTextItem == NULL )
return;
@ -348,7 +348,7 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent )
if( (flags & IS_NEW) == 0 ) // Remove old text from current list and save it in undo list
{
text->ClearFlags();
DeleteStruct( DrawPanel, &dc, text ); // old text is really saved in undo list
DeleteItem( text ); // old text is really saved in undo list
GetScreen()->SetCurItem( NULL );
m_itemToRepeat = NULL;
}

View File

@ -265,7 +265,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
SCH_SCREEN* screen = GetScreen();
// itemInEdit == false means no item currently edited. We can ask for editing a new item
bool itemInEdit = screen->GetCurItem() && screen->GetCurItem()->m_Flags;
bool itemInEdit = screen->GetCurItem() && screen->GetCurItem()->GetFlags();
// notBusy == true means no item currently edited and no other command in progress
// We can change active tool and ask for editing a new item
bool notBusy = (!itemInEdit) && (screen->m_BlockLocate.m_State == STATE_NO_BLOCK);
@ -342,7 +342,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case HK_DELETE:
if( notBusy)
{
LocateAndDeleteItem( this, aDC );
DeleteItemAtCrossHair( aDC );
OnModify();
GetScreen()->SetCurItem( NULL );
GetScreen()->TestDanglingEnds( DrawPanel, aDC );
@ -350,7 +350,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_REPEAT_LAST:
if( notBusy && m_itemToRepeat && ( m_itemToRepeat->m_Flags == 0 ) )
if( notBusy && m_itemToRepeat && ( m_itemToRepeat->GetFlags() == 0 ) )
RepeatDrawItem( aDC );
break;
@ -701,7 +701,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
if( aItem->Type() == SCH_JUNCTION_T )
{
// If it's a junction, pick the underlying wire instead
aItem = PickStruct( GetScreen()->GetCrossHairPosition(), GetScreen(), WIRE_T );
aItem = screen->GetItem( screen->GetCrossHairPosition(), 0, WIRE_T );
}
if( aItem == NULL )
@ -716,7 +716,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
}
if( aItem && (aItem->m_Flags == 0) )
if( aItem && (aItem->GetFlags() == 0) )
{
GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
@ -777,7 +777,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
if( aItem == NULL )
{
aItem = PickStruct( GetScreen()->GetCrossHairPosition(), GetScreen(),
aItem = screen->GetItem( screen->GetCrossHairPosition(), 0,
COMPONENT_T | TEXT_T | LABEL_T | SHEET_T );
if( aItem == NULL )
break;
@ -857,7 +857,7 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
cmd.SetEventObject( this );
bool itemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->m_Flags;
bool itemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->GetFlags();
if( aHotKey == 0 )
return;
@ -932,7 +932,7 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break;
case HK_REPEAT_LAST:
if( m_lastDrawItem && (m_lastDrawItem->m_Flags == 0)
if( m_lastDrawItem && (m_lastDrawItem->GetFlags() == 0)
&& ( m_lastDrawItem->Type() == LIB_PIN_T ) )
RepeatPinItem( aDC, (LIB_PIN*) m_lastDrawItem );
break;

View File

@ -23,10 +23,6 @@
#include "template_fieldnames.h"
static SCH_ITEM* LastSnappedStruct = NULL;
static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList );
/**
* Search the smaller (considering its area) component under the mouse
* cursor or the pcb cursor
@ -36,38 +32,39 @@ static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawLi
*/
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
{
SCH_COMPONENT* component = NULL, * lastcomponent = NULL;
SCH_ITEM* DrawList;
EDA_Rect BoundaryBox;
float sizeref = 0, sizecurr;
double area;
EDA_Rect rect;
PICKED_ITEMS_LIST itemList;
SCH_COMPONENT* component = NULL;
SCH_COMPONENT* lastcomponent = NULL;
DrawList = Screen->GetDrawItems();
while( DrawList )
if( Screen->GetItems( Screen->RefPos( true ), itemList, COMPONENT_T ) == 0 )
{
if( !SnapPoint2( Screen->RefPos( true ), COMPONENT_T, DrawList ) )
{
if( !SnapPoint2( Screen->GetCrossHairPosition(), COMPONENT_T, DrawList ) )
break;
if( Screen->GetItems( Screen->GetCrossHairPosition(), itemList, COMPONENT_T ) == 0 )
return NULL;
}
component = (SCH_COMPONENT*) LastSnappedStruct;
DrawList = component->Next();
if( itemList.GetCount() == 1 )
return (SCH_COMPONENT*) itemList.GetPickedItem( 0 );
if( lastcomponent == NULL ) // First time a component is located
for( size_t i = 0; i < itemList.GetCount(); i++ )
{
component = (SCH_COMPONENT*) itemList.GetPickedItem( i );
if( lastcomponent == NULL ) // First component
{
lastcomponent = component;
BoundaryBox = lastcomponent->GetBoundingBox();
sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
rect = lastcomponent->GetBoundingBox();
area = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
}
else
{
BoundaryBox = component->GetBoundingBox();
sizecurr = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() );
rect = component->GetBoundingBox();
double tmp = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
if( sizeref > sizecurr ) // a smallest component is found
if( area > tmp ) // a smaller component is found
{
sizeref = sizecurr;
area = tmp;
lastcomponent = component;
}
}
@ -75,250 +72,3 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
return lastcomponent;
}
/* Search an item at pos refpos
* SearchMask = (bitwise OR):
* COMPONENT_T
* WIRE_T
* BUS_T
* BUS_ENTRY_T
* JUNCTION_T
* DRAW_ITEM_T
* TEXT_T
* LABEL_T
* SHEETITEM
* MARKER_T
* NO_CONNECT_T
* SEARCH_PINITEM
* SHEETLABEL_T
* FIELDCMPITEM
*
* if EXCLUDE_ENDPOINTS_T is set, in wire or bus search and locate,
* start and end points are not included in search
* if ENDPOINTS_ONLY_T is set, in wire or bus search and locate,
* only start and end points are included in search
*
*
* Return:
* pointer on item found or NULL
*
*/
SCH_ITEM* PickStruct( const wxPoint& refpos, SCH_SCREEN* screen, int SearchMask )
{
if( screen == NULL || screen->GetDrawItems() == NULL )
return NULL;
if( SnapPoint2( refpos, SearchMask, screen->GetDrawItems() ) )
{
return LastSnappedStruct;
}
return NULL;
}
/*****************************************************************************
* 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. *
*****************************************************************************/
bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawList )
{
for( ; DrawList != NULL; DrawList = DrawList->Next() )
{
int hitminDist = MAX( g_DrawDefaultLineThickness, 3 );
switch( DrawList->Type() )
{
case SCH_POLYLINE_T:
#undef STRUCT
#define STRUCT ( (SCH_POLYLINE*) DrawList )
if( !( SearchMask & (DRAW_ITEM_T | WIRE_T | BUS_T) ) )
break;
for( unsigned i = 0; i < STRUCT->GetCornerCount() - 1; i++ )
{
if( TestSegmentHit( aPosRef, STRUCT->m_PolyPoints[i],
STRUCT->m_PolyPoints[i + 1], hitminDist ) )
{
LastSnappedStruct = DrawList;
return true;
}
}
break;
case SCH_LINE_T:
#undef STRUCT
#define STRUCT ( (SCH_LINE*) DrawList )
if( !( SearchMask & (DRAW_ITEM_T | WIRE_T | BUS_T) ) )
break;
if( TestSegmentHit( aPosRef, STRUCT->m_Start, STRUCT->m_End, 0 ) )
{
if( ( ( SearchMask & DRAW_ITEM_T ) && ( STRUCT->GetLayer() == LAYER_NOTES ) )
|| ( ( SearchMask & WIRE_T ) && ( STRUCT->GetLayer() == LAYER_WIRE ) )
|| ( ( SearchMask & BUS_T ) && ( STRUCT->GetLayer() == LAYER_BUS ) ) )
{
if( SearchMask & EXCLUDE_ENDPOINTS_T && STRUCT->IsEndPoint( aPosRef ) )
break;
if( SearchMask & ENDPOINTS_ONLY_T && !STRUCT->IsEndPoint( aPosRef ) )
break;
LastSnappedStruct = DrawList;
return true;
}
}
break;
case SCH_BUS_ENTRY_T:
#undef STRUCT
#define STRUCT ( (SCH_BUS_ENTRY*) DrawList )
if( !( SearchMask & (BUS_ENTRY_T) ) )
break;
if( TestSegmentHit( aPosRef, STRUCT->m_Pos, STRUCT->m_End(), hitminDist ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
case SCH_JUNCTION_T:
#undef STRUCT
#define STRUCT ( (SCH_JUNCTION*) DrawList )
if( !(SearchMask & JUNCTION_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
case SCH_NO_CONNECT_T:
#undef STRUCT
#define STRUCT ( (SCH_NO_CONNECT*) DrawList )
if( !(SearchMask & NO_CONNECT_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
case SCH_MARKER_T:
{
#undef STRUCT
#define STRUCT ( (SCH_MARKER*) DrawList )
if( !(SearchMask & MARKER_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
}
case SCH_TEXT_T:
#undef STRUCT
#define STRUCT ( (SCH_TEXT*) DrawList )
if( !( SearchMask & TEXT_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T:
#undef STRUCT
#define STRUCT ( (SCH_TEXT*) DrawList ) // SCH_TEXT is the base
// class of these labels
if( !(SearchMask & LABEL_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
case SCH_COMPONENT_T:
if( !( SearchMask & (COMPONENT_T | FIELD_T) ) )
break;
if( SearchMask & FIELD_T )
{
SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList;
for( int i = REFERENCE; i < DrawLibItem->GetFieldCount(); i++ )
{
SCH_FIELD* field = DrawLibItem->GetField( i );
if( field->m_Attributs & TEXT_NO_VISIBLE )
continue;
if( field->IsVoid() )
continue;
EDA_Rect BoundaryBox = field->GetBoundingBox();
if( BoundaryBox.Contains( aPosRef ) )
{
LastSnappedStruct = field;
return true;
}
}
}
else
{
#undef STRUCT
#define STRUCT ( (SCH_COMPONENT*) DrawList )
EDA_Rect BoundaryBox = STRUCT->GetBoundingBox();
if( BoundaryBox.Contains( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
}
break;
case SCH_SHEET_T:
#undef STRUCT
#define STRUCT ( (SCH_SHEET*) DrawList )
if( !(SearchMask & SHEET_T) )
break;
if( STRUCT->HitTest( aPosRef ) )
{
LastSnappedStruct = DrawList;
return true;
}
break;
default:
{
wxString msg;
msg.Printf( wxT( "SnapPoint2() error: unexpected struct type %d (" ),
DrawList->Type() );
msg << DrawList->GetClass() << wxT( ")" );
wxMessageBox( msg );
break;
}
}
}
return FALSE;
}

View File

@ -31,12 +31,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
SCH_ITEM* item = GetScreen()->GetCurItem();
wxPoint gridPosition = GetGridPosition( aPosition );
if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->m_Flags ) )
if( ( GetToolId() == ID_NO_TOOL_SELECTED ) || ( item && item->GetFlags() ) )
{
DrawPanel->m_AutoPAN_Request = false;
m_itemToRepeat = NULL;
if( item && item->m_Flags )
if( item && item->GetFlags() )
{
switch( item->Type() )
{
@ -77,7 +77,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_HIERARCHY_PUSH_POP_BUTT:
if( ( item && item->m_Flags ) || ( g_RootSheet->CountSheets() == 0 ) )
if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) )
break;
item = LocateAndShowItem( aPosition );
@ -99,7 +99,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_NOCONN_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
m_itemToRepeat = AddNoConnect( aDC, gridPosition );
GetScreen()->SetCurItem( m_itemToRepeat );
@ -116,7 +116,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_JUNCTION_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
m_itemToRepeat = AddJunction( aDC, gridPosition, true );
GetScreen()->SetCurItem( m_itemToRepeat );
@ -134,7 +134,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_WIRETOBUS_ENTRY_BUTT:
case ID_BUSTOBUS_ENTRY_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
item = CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ?
WIRE_TO_BUS : BUS_TO_BUS );
@ -152,7 +152,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_SCHEMATIC_DELETE_ITEM_BUTT:
LocateAndDeleteItem( this, aDC );
DeleteItemAtCrossHair( aDC );
OnModify();
GetScreen()->SetCurItem( NULL );
GetScreen()->TestDanglingEnds();
@ -175,7 +175,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_TEXT_COMMENT_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) );
DrawPanel->m_AutoPAN_Request = true;
@ -188,7 +188,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_LABEL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) );
DrawPanel->m_AutoPAN_Request = true;
@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_GLABEL_BUTT:
case ID_HIERLABEL_BUTT:
if( (item == NULL) || (item->m_Flags == 0) )
if( (item == NULL) || (item->GetFlags() == 0) )
{
if( GetToolId() == ID_GLABEL_BUTT )
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) );
@ -224,7 +224,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_SHEET_SYMBOL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( CreateSheet( aDC ) );
DrawPanel->m_AutoPAN_Request = true;
@ -240,20 +240,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_IMPORT_HLABEL_BUTT:
case ID_SHEET_LABEL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
item = LocateAndShowItem( aPosition );
if( item == NULL )
break;
if( (item->Type() == SCH_SHEET_T) && (item->m_Flags == 0) )
if( (item->Type() == SCH_SHEET_T) && (item->GetFlags() == 0) )
{
if( GetToolId() == ID_IMPORT_HLABEL_BUTT )
GetScreen()->SetCurItem( Import_PinSheet( (SCH_SHEET*) item, aDC ) );
else
GetScreen()->SetCurItem( Create_PinSheet( (SCH_SHEET*) item, aDC ) );
}
else if( (item->Type() == SCH_SHEET_LABEL_T) && (item->m_Flags != 0) )
else if( (item->Type() == SCH_SHEET_LABEL_T) && (item->GetFlags() != 0) )
{
item->Place( this, aDC );
GetScreen()->TestDanglingEnds();
@ -262,7 +262,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_SCH_PLACE_COMPONENT:
if( (item == NULL) || (item->m_Flags == 0) )
if( (item == NULL) || (item->GetFlags() == 0) )
{
GetScreen()->SetCurItem( Load_Component( aDC, wxEmptyString, s_CmpNameList, true ) );
DrawPanel->m_AutoPAN_Request = true;
@ -277,7 +277,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break;
case ID_PLACE_POWER_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
GetScreen()->SetCurItem( Load_Component( aDC, wxT( "power" ),
s_PowerNameList, false ) );
@ -317,12 +317,12 @@ void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
switch( GetToolId() )
{
case ID_NO_TOOL_SELECTED:
if( ( item == NULL ) || ( item->m_Flags == 0 ) )
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
item = LocateAndShowItem( aPosition );
}
if( ( item == NULL ) || ( item->m_Flags != 0 ) )
if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
break;
switch( item->Type() )

View File

@ -64,7 +64,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
}
// Try to locate items at cursor position.
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) )
if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) )
{
DrawStruct = LocateAndShowItem( aPosition, false );
@ -81,7 +81,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
// If Command in progress: add "cancel" and "end tool" menu
if( GetToolId() != ID_NO_TOOL_SELECTED )
{
if( DrawStruct && DrawStruct->m_Flags )
if( DrawStruct && DrawStruct->GetFlags() )
{
ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
}
@ -93,7 +93,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
}
else
{
if( DrawStruct && DrawStruct->m_Flags )
if( DrawStruct && DrawStruct->GetFlags() )
{
ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
PopMenu->AppendSeparator();
@ -112,7 +112,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
GetScreen()->SetCurItem( DrawStruct );
int flags = DrawStruct->m_Flags;
int flags = DrawStruct->GetFlags();
bool is_new = (flags & IS_NEW) ? TRUE : FALSE;
switch( DrawStruct->Type() )
@ -228,7 +228,7 @@ void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field )
{
wxString msg;
if( !Field->m_Flags )
if( !Field->GetFlags() )
{
msg = AddHotkeyName( _( "Move Field" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -259,7 +259,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
if( libEntry )
libComponent = libEntry->GetComponent();
if( !Component->m_Flags )
if( !Component->GetFlags() )
{
msg = _( "Move Component" );
msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text;
@ -325,7 +325,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP,
_( "Edit Component" ), edit_component_xpm );
if( !Component->m_Flags )
if( !Component->GetFlags() )
{
msg = AddHotkeyName( _( "Copy Component" ), s_Schematic_Hokeys_Descr,
HK_COPY_COMPONENT_OR_LABEL );
@ -344,7 +344,7 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
wxMenu* menu_change_type = new wxMenu;
wxString msg;
if( !GLabel->m_Flags )
if( !GLabel->GetFlags() )
{
msg = AddHotkeyName( _( "Move Global Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -381,7 +381,7 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
wxMenu* menu_change_type = new wxMenu;
wxString msg;
if( !HLabel->m_Flags )
if( !HLabel->GetFlags() )
{
msg = AddHotkeyName( _( "Move Hierarchical Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -417,7 +417,7 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
wxMenu* menu_change_type = new wxMenu;
wxString msg;
if( !Label->m_Flags )
if( !Label->GetFlags() )
{
msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -453,7 +453,7 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
wxString msg;
wxMenu* menu_change_type = new wxMenu;
if( !Text->m_Flags )
if( !Text->GetFlags() )
{
msg = AddHotkeyName( _( "Move Text" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -490,11 +490,12 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAME* frame )
{
bool is_new = Junction->IsNew();
SCH_SCREEN* screen = frame->GetScreen();
wxString msg;
if( !is_new )
{
if( PickStruct( frame->GetScreen()->GetCrossHairPosition(), frame->GetScreen(),
if( screen->GetItem( screen->GetCrossHairPosition(), 0,
WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
}
@ -502,7 +503,7 @@ void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAM
msg = AddHotkeyName( _( "Delete Junction" ), s_Schematic_Hokeys_Descr, HK_DELETE );
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_xpm );
if( PickStruct( frame->GetScreen()->GetCrossHairPosition(), frame->GetScreen(), WIRE_T | BUS_T ) )
if( screen->GetItem( screen->GetCrossHairPosition(), 0, WIRE_T | BUS_T ) )
{
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm );
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
@ -514,7 +515,8 @@ void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAM
void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
{
bool is_new = Wire->IsNew();
wxPoint pos = frame->GetScreen()->GetCrossHairPosition();
SCH_SCREEN* screen = frame->GetScreen();
wxPoint pos = screen->GetCrossHairPosition();
wxString msg;
if( is_new )
@ -532,7 +534,7 @@ void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
delete_connection_xpm );
if( PickStruct( frame->GetScreen()->GetCrossHairPosition(), frame->GetScreen(),
if( screen->GetItem( screen->GetCrossHairPosition(), 0,
WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
@ -582,7 +584,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
{
wxString msg;
if( !Sheet->m_Flags )
if( !Sheet->GetFlags() )
{
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ), enter_sheet_xpm );
PopMenu->AppendSeparator();
@ -594,7 +596,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_sheet_xpm );
}
if( Sheet->m_Flags )
if( Sheet->GetFlags() )
{
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), apply_xpm );
}
@ -623,7 +625,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
{
wxString msg;
if( !PinSheet->m_Flags )
if( !PinSheet->GetFlags() )
{
msg = AddHotkeyName( _( "Move PinSheet" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM );
@ -632,7 +634,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_PINSHEET, _( "Edit PinSheet" ), edit_xpm );
if( !PinSheet->m_Flags )
if( !PinSheet->GetFlags() )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete PinSheet" ), delete_pinsheet_xpm );
}

View File

@ -57,7 +57,7 @@ void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint )
{
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Rotate( rotationPoint ); // Place it in its new position.
item->m_Flags = 0;
item->ClearFlags();
}
}
@ -73,7 +73,7 @@ void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
{
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Mirror_Y( aMirrorPoint.x ); // Place it in its new position.
item->m_Flags = 0;
item->ClearFlags();
}
}
@ -84,7 +84,7 @@ void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint
{
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Mirror_X( aMirrorPoint.y ); // Place it in its new position.
item->m_Flags = 0;
item->ClearFlags();
}
}
@ -115,13 +115,11 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
PICKED_ITEMS_LIST itemsList;
ITEM_PICKER itemWrapper;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
itemWrapper.m_PickedItem = item;
itemWrapper.m_UndoRedoStatus = UR_DELETED;
ITEM_PICKER itemWrapper( item, UR_DELETED );
if( item->Type() == SCH_SHEET_LABEL_T )
{
@ -143,37 +141,31 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
}
/* Routine to delete an object from global drawing object list.
* Object is put in Undo list
*/
void DeleteStruct( EDA_DRAW_PANEL* panel, wxDC* DC, SCH_ITEM* DrawStruct )
void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem )
{
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
if( !DrawStruct )
return;
SCH_SCREEN* screen = GetScreen();
if( DrawStruct->Type() == SCH_SHEET_LABEL_T )
if( aItem->Type() == SCH_SHEET_LABEL_T )
{
/* This structure is attached to a node, and is not accessible by
* the global list directly. */
frame->SaveCopyInUndoList( (SCH_ITEM*)( (SCH_SHEET_PIN*) DrawStruct )->GetParent(),
UR_CHANGED );
frame->DeleteSheetLabel( DC ? true : false, (SCH_SHEET_PIN*) DrawStruct );
return;
// This iten is attached to a node, and is not accessible by the global list directly.
SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
wxT( "Sheet label has invalid parent item." ) );
SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED );
sheet->RemoveLabel( (SCH_SHEET_PIN*) aItem );
DrawPanel->RefreshDrawingRect( sheet->GetBoundingBox() );
}
else
{
screen->RemoveFromDrawList( DrawStruct );
screen->RemoveFromDrawList( aItem );
panel->RefreshDrawingRect( DrawStruct->GetBoundingBox() );
aItem->SetNext( NULL );
aItem->SetBack( NULL ); // Only one struct -> no link
/* Unlink the structure */
DrawStruct->SetNext( 0 );
DrawStruct->SetBack( 0 ); // Only one struct -> no link
frame->SaveCopyInUndoList( DrawStruct, UR_DELETED );
SaveCopyInUndoList( aItem, UR_DELETED );
DrawPanel->RefreshDrawingRect( aItem->GetBoundingBox() );
}
}

View File

@ -2,6 +2,8 @@
#ifndef __PROTOS_H__
#define __PROTOS_H__
#include "class_undoredo_container.h"
#include "colors.h"
@ -50,13 +52,9 @@ void SnapLibItemPoint( int OrigX,
bool LibItemInBox( int x1, int y1, int x2, int y2, SCH_COMPONENT* DrawLibItem );
/************/
/* BLOCK.CPP */
/************/
void DeleteStruct( EDA_DRAW_PANEL* panel, wxDC* DC, SCH_ITEM* DrawStruct );
// operations_on_item_lists.cpp
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
/**
* Function DuplicateStruct
@ -75,38 +73,6 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false );
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen );
/* function PickStruct:
* Search at location pos
*
* SearchMask = (bitwise OR):
* LIBITEM
* WIREITEM
* BUSITEM
* RACCORDITEM
* JUNCTIONITEM
* DRAWITEM
* TEXTITEM
* LABELITEM
* SHEETITEM
* MARKERITEM
* NOCONNECTITEM
* SEARCH_PINITEM
* SHEETLABELITEM
* FIELDCMPITEM
*
* if EXCLUDE_WIRE_BUS_ENDPOINTS is set, in wire ou bus search and locate,
* start and end points are not included in search
* if WIRE_BUS_ENDPOINTS_ONLY is set, in wire ou bus search and locate,
* only start and end points are included in search
*
*
* Return:
* Pointer to list of pointers to structures if several items are selected.
* Pointer to the structure if only 1 item is selected.
* NULL if no items are selects.
*/
SCH_ITEM* PickStruct( const wxPoint& refpos, SCH_SCREEN* screen, int SearchMask );
/***************/
/* EEREDRAW.CPP */
@ -142,14 +108,6 @@ bool ClearProjectDrawList( SCH_SCREEN* FirstWindow, bool confirm_deletion );
* clear the screen datas (filenames ..)
*/
/*************/
/* DELETE.CPP */
/*************/
bool LocateAndDeleteItem( SCH_EDIT_FRAME* frame, wxDC* DC );
void EraseStruct( SCH_ITEM* DrawStruct, SCH_SCREEN* Window );
void DeleteAllMarkers( int type );
/**************/
/* PINEDIT.CPP */

View File

@ -447,10 +447,10 @@ void SCH_FIELD::Rotate( wxPoint rotationPoint )
}
bool SCH_FIELD::doHitTest( const wxPoint& aPoint, int aAccuracy ) const
bool SCH_FIELD::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const
{
// Do not hit test hidden fields.
if( !IsVisible() )
// Do not hit test hidden or empty fields.
if( !(aFilter & FIELD_T) || !IsVisible() || IsVoid() )
return false;
EDA_Rect rect = GetBoundingBox();

View File

@ -164,7 +164,7 @@ public:
void* aAuxData, wxPoint * aFindLocation );
private:
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy ) const;
virtual bool doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const;
virtual bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const;
virtual EDA_ITEM* doClone() const;
};

View File

@ -144,15 +144,59 @@ void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM * DrawStruct )
}
void SCH_SCREEN::DeleteItem( SCH_ITEM* aItem )
{
wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invaled item from screen." ) );
SetModify();
if( aItem->Type() == SCH_SHEET_LABEL_T )
{
// This structure is attached to a sheet, get the parent sheet object.
SCH_SHEET_PIN* sheetLabel = (SCH_SHEET_PIN*) aItem;
SCH_SHEET* sheet = sheetLabel->GetParent();
wxCHECK_RET( sheet != NULL,
wxT( "Sheet label parent not properly set, bad programmer!" ) );
sheet->RemoveLabel( sheetLabel );
return;
}
else
{
if( aItem == GetDrawItems() )
{
SetDrawItems( aItem->Next() );
SAFE_DELETE( aItem );
}
else
{
SCH_ITEM* itemList = GetDrawItems();
while( itemList && itemList->Next() )
{
if( itemList->Next() == aItem )
{
itemList->SetNext( aItem->Next() );
SAFE_DELETE( aItem );
return;
}
itemList = itemList->Next();
}
}
}
}
bool SCH_SCREEN::CheckIfOnDrawList( SCH_ITEM* st )
{
SCH_ITEM * DrawList = GetDrawItems();
SCH_ITEM * itemList = GetDrawItems();
while( DrawList )
while( itemList )
{
if( DrawList == st )
if( itemList == st )
return true;
DrawList = DrawList->Next();
itemList = itemList->Next();
}
return false;
@ -178,6 +222,52 @@ int SCH_SCREEN::GetItems( const wxPoint& aPosition, SCH_ITEMS& aItemList ) const
}
int SCH_SCREEN::GetItems( const wxPoint& aPosition, PICKED_ITEMS_LIST& aItemList,
int aAccuracy, int aFilter ) const
{
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->HitTest( aPosition, aAccuracy, (SCH_FILTER_T) aFilter ) )
{
ITEM_PICKER picker( (EDA_ITEM*) item );
aItemList.PushItem( picker );
}
}
return aItemList.GetCount();
}
SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, int aFilter ) const
{
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->HitTest( aPosition, aAccuracy, (SCH_FILTER_T) aFilter ) )
{
if( (aFilter & FIELD_T) && (item->Type() == SCH_COMPONENT_T) )
{
SCH_COMPONENT* component = (SCH_COMPONENT*) item;
for( int i = REFERENCE; i < component->GetFieldCount(); i++ )
{
SCH_FIELD* field = component->GetField( i );
if( field->HitTest( aPosition, aAccuracy ) )
return (SCH_ITEM*) field;
}
if( !(aFilter & COMPONENT_T) )
return NULL;
}
return item;
}
}
return NULL;
}
SCH_ITEM* SCH_SCREEN::ExtractWires( bool CreateCopy )
{
SCH_ITEM* item, * next_item, * new_item, * List = NULL;
@ -244,6 +334,64 @@ void SCH_SCREEN::ReplaceWires( SCH_ITEM* aWireList )
}
void SCH_SCREEN::MarkConnections( SCH_LINE* aSegment )
{
wxCHECK_RET( (aSegment != NULL) && (aSegment->Type() == SCH_LINE_T),
wxT( "Invalid object pointer." ) );
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
{
if( item->GetFlags() & CANDIDATE )
continue;
if( item->Type() == SCH_JUNCTION_T )
{
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( aSegment->IsEndPoint( junction->m_Pos ) )
item->SetFlags( CANDIDATE );
continue;
}
if( item->Type() != SCH_LINE_T )
continue;
SCH_LINE* segment = (SCH_LINE*) item;
if( aSegment->IsEndPoint( segment->m_Start ) && !GetPin( segment->m_Start, NULL, true ) )
{
item->SetFlags( CANDIDATE );
MarkConnections( segment );
}
if( aSegment->IsEndPoint( segment->m_End ) && !GetPin( segment->m_End, NULL, true ) )
{
item->SetFlags( CANDIDATE );
MarkConnections( segment );
}
}
}
bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition ) const
{
if( GetItem( aPosition, 0, JUNCTION_T ) )
return false;
if( GetItem( aPosition, 0, WIRE_T | EXCLUDE_ENDPOINTS_T ) )
{
if( GetItem( aPosition, 0, WIRE_T | ENDPOINTS_ONLY_T ) )
return true;
if( GetPin( aPosition, NULL, true ) )
return true;
}
return false;
}
/* Routine cleaning:
* - Includes segments or buses aligned in only 1 segment
* - Detects identical objects superimposed
@ -269,10 +417,9 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
if( line->MergeOverlap( (SCH_LINE*) TstDrawList ) )
{
/* keep the bits set in .m_Flags, because the deleted
* segment can be flagged */
DrawList->m_Flags |= TstDrawList->m_Flags;
EraseStruct( TstDrawList, this );
// Keep the current flags, because the deleted segment can be flagged.
DrawList->SetFlags( TstDrawList->GetFlags() );
DeleteItem( TstDrawList );
TstDrawList = GetDrawItems();
Modify = true;
}
@ -293,6 +440,7 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
if( aCanvas && Modify )
aCanvas->Refresh();
return Modify;
}
@ -372,18 +520,6 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, int aDrawMode, int aC
}
/**
* Function ClearUndoORRedoList
* free the undo or redo list from List element
* Wrappers are deleted.
* datas pointed by wrappers are deleted if not in use in schematic
* i.e. when they are copy of a schematic item or they are no more in use
* (DELETED)
* @param aList = the UNDO_REDO_CONTAINER to clear
* @param aItemCount = the count of items to remove. < 0 for all items
* items (commands stored in list) are removed from the beginning of the list.
* So this function can be called to remove old commands
*/
void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
{
if( aItemCount == 0 )
@ -411,12 +547,12 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
void SCH_SCREEN::ClearDrawingState()
{
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() )
item->m_Flags = 0;
item->ClearFlags();
}
LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
bool aEndPointOnly )
bool aEndPointOnly ) const
{
SCH_ITEM* item;
SCH_COMPONENT* component = NULL;
@ -465,59 +601,6 @@ SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition )
}
bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition ) const
{
SCH_ITEMS items;
int wireEndPoints = 0;
if( GetItems( aPosition, items ) == 0 )
return false;
bool isJunctionNeeded = false;
bool isWireMidpoint = false;
for( size_t i = 0; i < items.size(); i++ )
{
KICAD_T itemType = items[i].Type();
if( itemType == SCH_JUNCTION_T )
{
isJunctionNeeded = false;
break;
}
else if( itemType == SCH_LINE_T )
{
SCH_LINE* line = ( SCH_LINE* ) &items[i];
if( !line->IsConnectable() )
continue;
if( !line->IsEndPoint( aPosition ) )
isWireMidpoint = true;
else
wireEndPoints += 1;
if( ( isWireMidpoint && ( wireEndPoints != 0 ) ) || ( wireEndPoints > 2 ) )
isJunctionNeeded = true;
}
else if( itemType == SCH_COMPONENT_T )
{
SCH_COMPONENT* component = ( SCH_COMPONENT* ) &items[i];
if( !component->IsConnected( aPosition ) )
continue;
if( isWireMidpoint || wireEndPoints > 2 )
isJunctionNeeded = true;
}
}
items.release();
return isJunctionNeeded;
}
int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const
{
SCH_ITEM* item;
@ -578,7 +661,7 @@ void SCH_SCREEN::SelectBlockItems()
for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
{
item = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
item->m_Flags = SELECTED;
item->SetFlags( SELECTED );
}
if( !m_BlockLocate.IsDragging() )
@ -589,6 +672,7 @@ void SCH_SCREEN::SelectBlockItems()
m_BlockLocate.Inflate(1);
unsigned last_select_id = pickedlist->GetCount();
unsigned ii = 0;
for( ; ii < last_select_id; ii++ )
{
item = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
@ -596,19 +680,22 @@ void SCH_SCREEN::SelectBlockItems()
if( item->Type() == SCH_LINE_T )
{
item->IsSelectStateChanged( m_BlockLocate );
if( ( item->m_Flags & SELECTED ) == 0 )
if( ( item->GetFlags() & SELECTED ) == 0 )
{ // This is a special case:
// this selected wire has no ends in block.
// But it was selected (because it intersects the selecting area),
// so we must keep it selected and select items connected to it
// Note: an other option could be: remove it from drag list
item->m_Flags |= SELECTED | SKIP_STRUCT;
item->SetFlags( SELECTED | SKIP_STRUCT );
std::vector< wxPoint > connections;
item->GetConnectionPoints( connections );
for( size_t i = 0; i < connections.size(); i++ )
addConnectedItemsToBlock( connections[i] );
}
pickedlist->SetPickerFlags( item->m_Flags, ii );
pickedlist->SetPickerFlags( item->GetFlags(), ii );
}
else if( item->IsConnectable() )
{
@ -633,11 +720,11 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position )
for( item = GetDrawItems(); item != NULL; item = item->Next() )
{
picker.m_PickedItem = item;
picker.m_PickedItemType = item->Type();
picker.SetItem( item );
picker.SetItemType( item->Type() );
if( !item->IsConnectable() || !item->IsConnected( position )
|| (item->m_Flags & SKIP_STRUCT) )
|| (item->GetFlags() & SKIP_STRUCT) )
continue;
if( item->IsSelected() && item->Type() != SCH_LINE_T )
@ -647,23 +734,23 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position )
if( item->Type() == SCH_LINE_T )
{
if( ! item->IsSelected() ) // First time this line is tested
item->m_Flags = SELECTED | STARTPOINT | ENDPOINT;
item->SetFlags( SELECTED | STARTPOINT | ENDPOINT );
else // second time (or more) this line is tested
addinlist = false;
SCH_LINE* line = (SCH_LINE*) item;
if( line->m_Start == position )
item->m_Flags &= ~STARTPOINT;
item->ClearFlags( STARTPOINT );
else if( line->m_End == position )
item->m_Flags &= ~ENDPOINT;
item->ClearFlags( ENDPOINT );
}
else
item->m_Flags = SELECTED;
item->SetFlags( SELECTED );
if( addinlist )
{
picker.m_PickerFlags = item->m_Flags;
picker.m_PickerFlags = item->GetFlags();
m_BlockLocate.m_ItemsSelection.PushItem( picker );
}
}
@ -683,8 +770,8 @@ int SCH_SCREEN::UpdatePickList()
// An item is picked if its bounding box intersects the reference area.
if( item->HitTest( area ) )
{
picker.m_PickedItem = item;
picker.m_PickedItemType = item->Type();
picker.SetItem( item );
picker.SetItemType( item->Type() );
m_BlockLocate.PushItem( picker );
}
}
@ -947,3 +1034,30 @@ void SCH_SCREENS::SetDate( const wxString& aDate )
for( size_t i = 0; i < m_screens.size(); i++ )
m_screens[i]->m_Date = aDate;
}
void SCH_SCREENS::DeleteAllMarkers( int aMarkerType )
{
SCH_ITEM* item;
SCH_ITEM* nextItem;
SCH_MARKER* marker;
SCH_SCREEN* screen;
for( screen = GetFirst(); screen != NULL; screen = GetNext() )
{
for( item = screen->GetDrawItems(); item != NULL; item = nextItem )
{
nextItem = item->Next();
if( item->Type() != SCH_MARKER_T )
continue;
marker = (SCH_MARKER*) item;
if( marker->GetMarkerType() != aMarkerType )
continue;
screen->DeleteItem( marker );
}
}
}

View File

@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( item == NULL )
break;
DeleteStruct( DrawPanel, &dc, item );
DeleteItem( item );
screen->SetCurItem( NULL );
m_itemToRepeat = NULL;
screen->TestDanglingEnds( DrawPanel, &dc );

View File

@ -209,7 +209,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
if( aItem )
{
itemWrapper.m_PickedItemType = aItem->Type();
itemWrapper.m_PickerFlags = aItem->m_Flags;
itemWrapper.m_PickerFlags = aItem->GetFlags();
}
switch( aCommandType )
@ -329,12 +329,14 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
// complex command
for( int ii = aList->GetCount() - 1; ii >= 0; ii-- )
{
ITEM_PICKER itemWrapper = aList->GetItemWrapper( ii );
item = (SCH_ITEM*) itemWrapper.m_PickedItem;
item = (SCH_ITEM*) aList->GetPickedItem( ii );
if( item )
item->m_Flags = 0;
SCH_ITEM* image = (SCH_ITEM*) itemWrapper.m_Link;
switch( itemWrapper.m_UndoRedoStatus )
item->ClearFlags();
SCH_ITEM* image = (SCH_ITEM*) aList->GetPickedItemLink( ii );
switch( aList->GetPickedItemStatus( ii ) )
{
case UR_CHANGED: /* Exchange old and new data for each item */
SwapData( item, image );
@ -352,10 +354,10 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
break;
case UR_MOVED:
item->m_Flags = aList->GetPickerFlags( ii );
item->Move( aRedoCommand ?
aList->m_TransformPoint : -aList->m_TransformPoint );
item->m_Flags = 0;
item->ClearFlags();
item->SetFlags( aList->GetPickerFlags( ii ) );
item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
item->ClearFlags();
break;
case UR_MIRRORED_Y:
@ -385,12 +387,13 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
/* Exchange the current wires and the old wires */
alt_item = GetScreen()->ExtractWires( false );
aList->SetPickedItem( alt_item, ii );
while( item )
{
SCH_ITEM* nextitem = item->Next();
item->SetNext( GetScreen()->GetDrawItems() );
GetScreen()->SetDrawItems( item );
item->m_Flags = 0;
item->ClearFlags();
item = nextitem;
}
@ -400,7 +403,7 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
{
wxString msg;
msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
itemWrapper.m_UndoRedoStatus );
aList->GetPickedItemStatus( ii ) );
wxMessageBox( msg );
}
break;

View File

@ -244,36 +244,3 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC )
return NewSheetLabel;
}
/*
* Remove sheet label.
*
* This sheet label can not be put in a pile "undelete" because it would not
* Possible to link it back it's 'SCH_SHEET' parent.
*/
void SCH_EDIT_FRAME::DeleteSheetLabel( bool aRedraw, SCH_SHEET_PIN* aSheetLabelToDel )
{
SCH_SHEET* parent = (SCH_SHEET*) aSheetLabelToDel->GetParent();
wxASSERT( parent );
wxASSERT( parent->Type() == SCH_SHEET_T );
#if 0 && defined(DEBUG)
std::cout << "\n\nbefore deleting:\n" << std::flush;
parent->Show( 0, std::cout );
std::cout << "\n\n\n" << std::flush;
#endif
parent->RemoveLabel( aSheetLabelToDel );
if( aRedraw )
DrawPanel->RefreshDrawingRect( parent->GetBoundingBox() );
#if 0 && defined(DEBUG)
std::cout << "\n\nafter deleting:\n" << std::flush;
parent->Show( 0, std::cout );
std::cout << "~after deleting\n\n" << std::flush;
#endif
}

View File

@ -14,6 +14,7 @@ class LIB_PIN;
class SCH_COMPONENT;
class SCH_SHEET_PATH;
class SCH_SHEET_PIN;
class SCH_LINE;
/* Max number of sheets in a hierarchy project: */
@ -94,6 +95,29 @@ public:
*/
int GetItems( const wxPoint& aPosition, SCH_ITEMS& aItemList ) const;
/**
* Function FindItem
* checks \a aPosition within a distance of \a aAccuracy for items of type \a aFilter.
* @param aPosition Position in drawing units.
* @param aAccuracy The maximum distance within \a Position to check for an item.
* @param aFilter The type of items to find.
* @return The item found that meets the search criteria or NULL if none found.
*/
SCH_ITEM* GetItem( const wxPoint& aPosition, int aAccuracy = 0,
int aFilter = NO_FILTER_T ) const;
/**
* Function GetItems
* checks \a aPosition within a distance of \a aAccuracy for items of type \a aFilter.
* @param aPosition Position in drawing units.
* @param aItemList The list to add found items to.
* @param aAccuracy The maximum distance within \a Position to check for an item.
* @param aFilter The type of items to find.
* @return The number of items found that meets the search criteria.
*/
int GetItems( const wxPoint& aPosition, PICKED_ITEMS_LIST& aItemList, int aAccuracy = 0,
int aFilter = NO_FILTER_T ) const;
void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
/**
@ -113,6 +137,15 @@ public:
*/
void RemoveFromDrawList( SCH_ITEM* aItem );
/**
* Function DeleteItem
* removes \a aItem from the linked list and deletes the object. If \a aItem is
* is a schematic sheet label, it is removed from the screen associated with the
* sheet that contains the label to be deleted.
* @param aItem The schematic object to be deleted from the screen.
*/
void DeleteItem( SCH_ITEM* aItem );
bool CheckIfOnDrawList( SCH_ITEM* st );
void AddToDrawList( SCH_ITEM* st );
@ -149,6 +182,15 @@ public:
*/
void ReplaceWires( SCH_ITEM* aWireList );
/**
* Functions MarkConnections
* add all wires and junctions connected to \a aSegment which are not connected any
* component pin to \a aItemList.
* @param aSegment The segment to test for connections.
* @param aItemList List of items to add connections.
*/
void MarkConnections( SCH_LINE* aSegment );
/**
* Function BreakSegment
* checks every wire and bus for a intersection at \a aPoint and break into two segments
@ -227,7 +269,7 @@ public:
* @return The pin item if found, otherwise NULL.
*/
LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
bool aEndPointOnly = false );
bool aEndPointOnly = false ) const;
/**
* Function GetSheetLabel
@ -268,6 +310,7 @@ public:
int UpdatePickList();
virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_ITEM*) aItem ); }
virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem )
{
BASE_SCREEN::InsertItem( aIter, (EDA_ITEM*) aItem );
@ -323,6 +366,14 @@ public:
*/
void SetDate( const wxString& aDate );
/**
* Function DeleteAllMarkers
* deletes all electronic rules check markers of \a aMarkerType from all the screens in
* the list.
* @param aType Type of markers to be deleted.
*/
void DeleteAllMarkers( int aMarkerType );
private:
void AddScreenToList( SCH_SCREEN* aScreen );
void BuildScreenList( EDA_ITEM* aItem );

View File

@ -2,6 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application.
*
* Copyright (C) 2009 jean-pierre.charras@gipsa-lab.inpg.fr
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2009 Kicad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
@ -28,18 +29,22 @@
#include "base_struct.h"
class PICKED_ITEMS_LIST;
/**
* Undo Redo considerations:
* Basically we have 3 cases
* New item
* Deleted item
* Modified item
* there is also a specfific case in eeschema, when wires are modified
* there is also a specific case in eeschema, when wires are modified
* If an item is modified, a copy of the "old" item parameters value is held.
* When an item is deleted or added (new item) the pointer points the item, and there is
* no other copy.
* However, because there are some commands that concern a lot of items
* and modify them, but modifications are easy tu undo/redo,
* and modify them, but modifications are easy to undo/redo,
* so a copy of old items is not necessary. They are block command
* Move block
* Rotate block
@ -47,12 +52,14 @@
* and they are undo/redo by the same command
*/
/* Type of undo/redo operations
* each type must be redo/undoed by a specfic operation
* each type must be redo/undone by a specific operation
*/
enum UndoRedoOpType {
UR_UNSPECIFIED = 0, // illegal
UR_CHANGED, // params of items have a value changed: undo is made by exchange values with a copy of these values
UR_CHANGED, // params of items have a value changed: undo is made by exchange
// values with a copy of these values
UR_NEW, // new item, undo by changing in deleted
UR_DELETED, // deleted item, undo by changing in deleted
UR_MOVED, // moved item, undo by move it
@ -62,43 +69,58 @@ enum UndoRedoOpType {
UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
UR_FLIPPED, // flipped (board items only), undo by flipping it
UR_WIRE_IMAGE, // Specific to eeschema: handle wires changes
UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of the current module when changed)
UR_LIBEDIT // Specific to the component editor (libedit creates a full copy of the current component when changed)
UR_MODEDIT, // Specific to the module editor (modedit creates a full copy of
// the current module when changed)
UR_LIBEDIT // Specific to the component editor (libedit creates a full copy
// of the current component when changed)
};
class ITEM_PICKER
{
friend class PICKED_ITEMS_LIST;
public:
UndoRedoOpType m_UndoRedoStatus; /* type of operation to undo/redo for this item */
EDA_ITEM* m_PickedItem; /* Pointer on the schematic or board item that is concerned (picked),
* or in undo redo commands, the copy of an edited item.
*/
KICAD_T m_PickedItemType; /* type of schematic or board item that is concerned
*/
int m_PickerFlags; /* a copy of m_Flags member. usefull in mode/drag undo/redo commands */
EDA_ITEM* m_Link; /* Pointer on an other item. Used in undo redo command
* used when a duplicate exists i.e. when an item is modified,
* and the copy of initial item exists (the duplicate)
* m_Item points the duplicate (i.e the old copy of an active item)
* and m_Link points the active item in schematic
*/
EDA_ITEM* m_PickedItem; /* Pointer on the schematic or board item that is concerned
* (picked), or in undo redo commands, the copy of an
* edited item. */
KICAD_T m_PickedItemType; /* type of schematic or board item that is concerned */
int m_PickerFlags; /* a copy of m_Flags member. useful in mode/drag
* undo/redo commands */
EDA_ITEM* m_Link; /* Pointer on an other item. Used in undo redo command
* used when a duplicate exists i.e. when an item is
* modified, and the copy of initial item exists (the
* duplicate) m_Item points the duplicate (i.e the old
* copy of an active item) and m_Link points the active
* item in schematic */
public:
ITEM_PICKER( EDA_ITEM* aItem = NULL, UndoRedoOpType aUndoRedoStatus = UR_UNSPECIFIED );
EDA_ITEM* GetItem() const { return m_PickedItem; }
void SetItem( EDA_ITEM* aItem ) { m_PickedItem = aItem; }
KICAD_T GetItemType() const { return m_PickedItemType; }
void SetItemType( KICAD_T aType ) { m_PickedItemType = aType; }
};
/* Class PICKED_ITEMS_LIST
/**
* Class PICKED_ITEMS_LIST
* is a holder to handle information on schematic or board items.
* The information held is a pointer on each item, and the command made.
*/
class PICKED_ITEMS_LIST
{
public:
UndoRedoOpType m_Status; /* info about operation to undo/redo for this item. can be UR_UNSPECIFIED */
wxPoint m_TransformPoint; /* used to undo redo command by the same command:
* we usually need to know the rotate point or the move vector
*/
UndoRedoOpType m_Status; /* info about operation to undo/redo for this item. can be
* UR_UNSPECIFIED */
wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
* need to know the rotate point or the move vector */
private:
std::vector <ITEM_PICKER> m_ItemsList;
@ -106,34 +128,41 @@ public:
PICKED_ITEMS_LIST();
~PICKED_ITEMS_LIST();
/** PushItem
* push a picker to the top of the list
* @param aItem = picker to push
/**
* Function PushItem
* pushes \a aItem to the top of the list
* @param aItem Picker to push on to the list.
*/
void PushItem( ITEM_PICKER& aItem );
/** PopItem
* @return the picker from the top of the list
* the picker is removed from the list
/**
* Function PopItem
* @return The picker removed from the top of the list.
*/
ITEM_PICKER PopItem();
/**
* Function IsItemInList
* @return True if \a aItem is found in the pick list.
*/
bool ContainsItem( EDA_ITEM* aItem ) const;
/**
* Function ClearItemsList
* delete only the list of pickers, NOT the picked data itself
* deletes only the list of pickers, NOT the picked data itself.
*/
void ClearItemsList();
/**
* Function ClearListAndDeleteItems
* delete the list of pickers, AND the data pointed
* by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded
* deletes the list of pickers, AND the data pointed by m_PickedItem or
* m_PickedItemLink, according to the type of undo/redo command recorded
*/
void ClearListAndDeleteItems();
/**
* Function GetCount
* @return the count of pickers stored in this list
* @return The count of pickers stored in this list.
*/
unsigned GetCount() const
{
@ -142,19 +171,18 @@ public:
/**
* Function ReversePickersListOrder
* reverses the order of pickers stored in this list
* Useful when pop a list from Undo to Redo (and vice-versa)
* because sometimes undo (or redo) a command needs to keep the
* order of successive changes.
* and obviously, undo and redo are in reverse order
* reverses the order of pickers stored in this list.
* <p>
* This is useful when pop a list from Undo to Redo (and vice-versa) because
* sometimes undo (or redo) a command needs to keep the order of successive
* changes. Obviously, undo and redo are in reverse order
*/
void ReversePickersListOrder();
/**
* Function GetItemWrapper
* @return the picker of a picked item
* @param aIdx = index of the picker in the picked list
* @return The picker of a picked item.
* @param aIdx Index of the picker in the picked list
* if this picker does not exist, a picker is returned,
* with its members set to 0 or NULL
*/
@ -162,94 +190,96 @@ public:
/**
* Function GetPickedItem
* @return a pointer to the picked item
* @param aIdx = index of the picked item in the picked list
* @return A pointer to the picked item
* @param aIdx Index of the picked item in the picked list
*/
EDA_ITEM* GetPickedItem( unsigned int aIdx );
/**
* Function GetPickedItemLink
* @return link of the picked item, or null if does not exist
* @param aIdx = index of the picked item in the picked list
* @param aIdx Index of the picked item in the picked list
*/
EDA_ITEM* GetPickedItemLink( unsigned int aIdx );
/**
* Function GetPickedItemStatus
* @return the type of undo/redo opertaion associated to the picked item,
* @return The type of undo/redo operation associated to the picked item,
* or UR_UNSPECIFIED if does not exist
* @param aIdx = index of the picked item in the picked list
* @param aIdx Index of the picked item in the picked list
*/
UndoRedoOpType GetPickedItemStatus( unsigned int aIdx );
/**
* Function GetPickerFlags
* return the value of the picker flag
* @param aIdx = index of the picker in the picked list
* @return the value stored in the picker, if the picker exists, or 0 if does not exist
* returns the value of the picker flag.
* @param aIdx Index of the picker in the picked list
* @return The value stored in the picker, if the picker exists, or 0 if does not exist
*/
int GetPickerFlags( unsigned aIdx );
/**
* Function SetPickedItem
* @param aItem = a pointer to the item to pick
* @param aIdx = index of the picker in the picked list
* @return true if the pixker exists, or false if does not exist
* @param aItem A pointer to the item to pick
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
/**
* Function SetPickedItem
* @param aItem = a pointer to the item to pick
* @param aStatus = the type of undo/redo operation associated to the item to pick
* @param aIdx = index of the picker in the picked list
* @return true if the pixker exists, or false if does not exist
* @param aItem A pointer to the item to pick
* @param aStatus The type of undo/redo operation associated to the item to pick
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx );
/**
* Function SetPickedItemLink
* Set the link associated to a given picked item
* set the link associated to a given picked item.
* @param aLink = the link to the item associated to the picked item
* @param aIdx = index of the picker in the picked list
* @return true if the pixker exists, or false if does not exist
* @return true if the picker exists, or false if does not exist
*/
bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
/**
* Function SetPickedItemStatus
* Set the type of undo/redo operation for a given picked item
* @param aStatus = the type of undo/redo operation associated to the picked item
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
* sets the type of undo/redo operation for a given picked item.
* @param aStatus The type of undo/redo operation associated to the picked item
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
/**
* Function SetPickerFlags
* Set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags = the value to save in picker
* @param aIdx = index of the picker in the picked list
* @return true if the picker exists, or false if does not exist
* set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags The flag value to save in picker
* @param aIdx Index of the picker in the picked list
* @return True if the picker exists or false if does not exist
*/
bool SetPickerFlags( int aFlags, unsigned aIdx );
/**
* Function RemovePicker
* remove one entry (one picker) from the list of picked items
* @param aIdx = index of the picker in the picked list
* @return true if ok, or false if did not exist
* removes one entry (one picker) from the list of picked items.
* @param aIdx Index of the picker in the picked list
* @return True if ok or false if did not exist
*/
bool RemovePicker( unsigned aIdx );
/**
* Function CopyList
* copy all data from aSource
* Items picked are not copied. just pointer on them are copied
* copies all data from aSource to the list.
* Items picked are not copied. just pointer in them are copied
* @param aSource The list of items to copy to the list.
*/
void CopyList( const PICKED_ITEMS_LIST& aSource );
};
/**
* Class UNDO_REDO_CONTAINER
* is a holder to handle alist of undo (or redo) command.
@ -264,8 +294,11 @@ public:
UNDO_REDO_CONTAINER();
~UNDO_REDO_CONTAINER();
void PushCommand( PICKED_ITEMS_LIST* aCommand );
PICKED_ITEMS_LIST* PopCommand();
void ClearCommandList();
};

View File

@ -123,7 +123,6 @@ public:
*/
static wxString GetDefaultFieldName( int aFieldNdx );
/**
* Function AddTemplateFieldName
* inserts or appends a wanted symbol field name into the fieldnames
@ -208,6 +207,26 @@ public:
SCH_ITEM* LocateAndShowItem( const wxPoint& aPosition, bool aIncludePin = true );
SCH_ITEM* LocateItem( const wxPoint& aPosition, bool aIncludePin );
/**
* Function DeleteItemAtCrossHair
* delete the item found under the cross hair.
* <p>
* If more than one item found, the priority order is:
* <ol>
* Marker
* Junction
* No connect
* Wire or bus
* Graphic item
* Text
* Component
* Sheet
* </ol></p>
* @param aDC The device context to update if and item is deleted.
* @return True if an item was deleted.
*/
bool DeleteItemAtCrossHair( wxDC* DC );
/**
* Function FillFootprintFieldForAllInstancesofComponent
* searches for component "aReference", and places a Footprint in
@ -508,8 +527,12 @@ private:
SCH_SHEET_PIN* Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC );
public:
void DeleteSheetLabel( bool aRedraw,
SCH_SHEET_PIN* aSheetLabelToDel );
/**
* Function DeleteItem
* removes \a aItem from the current screen and saves it in the undo list.
* @param aItem The item to remove from the current screen.
*/
void DeleteItem( SCH_ITEM* aItem );
int GetLabelIncrement() const { return m_repeatLabelDelta; }