Commit c07b677a authored by Wayne Stambaugh's avatar Wayne Stambaugh

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.
parent 628e5240
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * 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) 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. * Copyright (C) 2009 Kicad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -26,7 +27,6 @@ ...@@ -26,7 +27,6 @@
#include "common.h" #include "common.h"
#include "base_struct.h" #include "base_struct.h"
//#include "sch_item_struct.h"
#include "base_struct.h" #include "base_struct.h"
#include "class_undoredo_container.h" #include "class_undoredo_container.h"
...@@ -51,20 +51,12 @@ PICKED_ITEMS_LIST::~PICKED_ITEMS_LIST() ...@@ -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 ) void PICKED_ITEMS_LIST::PushItem( ITEM_PICKER& aItem )
{ {
m_ItemsList.push_back( 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 PICKED_ITEMS_LIST::PopItem()
{ {
ITEM_PICKER item; ITEM_PICKER item;
...@@ -74,25 +66,29 @@ ITEM_PICKER PICKED_ITEMS_LIST::PopItem() ...@@ -74,25 +66,29 @@ ITEM_PICKER PICKED_ITEMS_LIST::PopItem()
item = m_ItemsList.back(); item = m_ItemsList.back();
m_ItemsList.pop_back(); m_ItemsList.pop_back();
} }
return item; return item;
} }
/** bool PICKED_ITEMS_LIST::ContainsItem( EDA_ITEM* aItem ) const
* Function ClearItemsList {
* delete only the list of pickers, NOT the picked data itself 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() void PICKED_ITEMS_LIST::ClearItemsList()
{ {
m_ItemsList.clear(); 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() void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
{ {
bool show_error_message = true; bool show_error_message = true;
...@@ -108,13 +104,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() ...@@ -108,13 +104,14 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
case UR_UNSPECIFIED: case UR_UNSPECIFIED:
if( show_error_message ) if( show_error_message )
wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) ); wxMessageBox( wxT( "ClearUndoORRedoList() error: UR_UNSPECIFIED command type" ) );
show_error_message = false; show_error_message = false;
break; break;
case UR_WIRE_IMAGE: case UR_WIRE_IMAGE:
{ {
// Specific to eeschema: a linked list of wires is stored. // Specific to eeschema: a linked list of wires is stored. The wrapper picks only
// the wrapper picks only the first item (head of list), and is owner of all picked items // the first item (head of list), and is owner of all picked items.
EDA_ITEM* item = wrapper.m_PickedItem; EDA_ITEM* item = wrapper.m_PickedItem;
while( item ) while( item )
...@@ -144,9 +141,9 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() ...@@ -144,9 +141,9 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems()
case UR_LIBEDIT: /* Libedit save always a copy of the current item case UR_LIBEDIT: /* Libedit save always a copy of the current item
* So, the picker is always owner of the picked item * So, the picker is always owner of the picked item
*/ */
case UR_MODEDIT: /* Specific to the module editor case UR_MODEDIT: /* Specific to the module editor (modedit creates a full
* (modedit creates a full copy of the current module when changed), * copy of the current module when changed),
* and the picker is owner of this item * and the picker is owner of this item
*/ */
delete wrapper.m_PickedItem; delete wrapper.m_PickedItem;
break; break;
...@@ -164,13 +161,6 @@ void PICKED_ITEMS_LIST::ClearListAndDeleteItems() ...@@ -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 PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx )
{ {
ITEM_PICKER picker; ITEM_PICKER picker;
...@@ -182,11 +172,6 @@ ITEM_PICKER PICKED_ITEMS_LIST::GetItemWrapper( unsigned int aIdx ) ...@@ -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 ) EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -196,11 +181,6 @@ EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItem( unsigned int aIdx ) ...@@ -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 ) EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -210,12 +190,6 @@ EDA_ITEM* PICKED_ITEMS_LIST::GetPickedItemLink( unsigned int aIdx ) ...@@ -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 ) UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -224,12 +198,7 @@ UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx ) ...@@ -224,12 +198,7 @@ UndoRedoOpType PICKED_ITEMS_LIST::GetPickedItemStatus( unsigned int aIdx )
return UR_UNSPECIFIED; 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 ) int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -238,12 +207,7 @@ int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx ) ...@@ -238,12 +207,7 @@ int PICKED_ITEMS_LIST::GetPickerFlags( unsigned aIdx )
return 0; 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 ) bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -256,13 +220,6 @@ bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, unsigned aIdx ) ...@@ -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 ) bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -275,13 +232,6 @@ bool PICKED_ITEMS_LIST::SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx ) ...@@ -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 ) bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -295,13 +245,6 @@ bool PICKED_ITEMS_LIST::SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, ...@@ -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 ) bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -312,13 +255,8 @@ bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aI ...@@ -312,13 +255,8 @@ bool PICKED_ITEMS_LIST::SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aI
else else
return false; 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 ) bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx )
{ {
if( aIdx < m_ItemsList.size() ) if( aIdx < m_ItemsList.size() )
...@@ -331,12 +269,6 @@ bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx ) ...@@ -331,12 +269,6 @@ bool PICKED_ITEMS_LIST::SetPickerFlags( int aFlags, unsigned aIdx )
} }
/**
* Function RemovePicker
* rem�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 ) bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx )
{ {
if( aIdx >= m_ItemsList.size() ) if( aIdx >= m_ItemsList.size() )
...@@ -346,24 +278,12 @@ bool PICKED_ITEMS_LIST::RemovePicker( unsigned aIdx ) ...@@ -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 ) void PICKED_ITEMS_LIST::CopyList( const PICKED_ITEMS_LIST& aSource )
{ {
m_ItemsList = aSource.m_ItemsList; // Vector's copy 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() void PICKED_ITEMS_LIST::ReversePickersListOrder()
{ {
std::vector <ITEM_PICKER> tmp; std::vector <ITEM_PICKER> tmp;
......
...@@ -33,7 +33,6 @@ extern void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveV ...@@ -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 RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
extern void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint ); extern void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint );
extern void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center ); 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, extern void DuplicateItemsInList( SCH_SCREEN* screen,
PICKED_ITEMS_LIST& aItemsList, PICKED_ITEMS_LIST& aItemsList,
const wxPoint aMoveVector ); const wxPoint aMoveVector );
...@@ -522,22 +521,19 @@ void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList ) ...@@ -522,22 +521,19 @@ void SCH_EDIT_FRAME::copyBlockItems( PICKED_ITEMS_LIST& aItemsList )
{ {
m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists m_blockItems.ClearListAndDeleteItems(); // delete previous saved list, if exists
/* save the new list: */
ITEM_PICKER item;
// 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;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
// Clear m_Flag member of selected items: // Clear m_Flag member of selected items:
aItemsList.GetPickedItem( ii )->m_Flags = 0; aItemsList.GetPickedItem( ii )->ClearFlags();
/* Make a copy of the original picked item. */ /* Make a copy of the original picked item. */
SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) ); SCH_ITEM* copy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
DrawStructCopy->SetParent( NULL ); copy->SetParent( NULL );
item.m_PickedItem = DrawStructCopy;
// 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_PICKER item( copy, UR_DELETED );
m_blockItems.PushItem( item ); m_blockItems.PushItem( item );
} }
} }
...@@ -559,13 +555,12 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) ...@@ -559,13 +555,12 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
PICKED_ITEMS_LIST picklist; 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++ ) for( unsigned ii = 0; ii < m_blockItems.GetCount(); ii++ )
{ {
Struct = DuplicateStruct( (SCH_ITEM*) m_blockItems.m_ItemsSelection.GetPickedItem( 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 ); picklist.PushItem( picker );
// Clear annotation and init new time stamp for the new components: // Clear annotation and init new time stamp for the new components:
...@@ -574,6 +569,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) ...@@ -574,6 +569,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
( (SCH_COMPONENT*) Struct )->m_TimeStamp = GetTimeStamp(); ( (SCH_COMPONENT*) Struct )->m_TimeStamp = GetTimeStamp();
( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL ); ( (SCH_COMPONENT*) Struct )->ClearAnnotation( NULL );
} }
SetSchItemParent( Struct, GetScreen() ); SetSchItemParent( Struct, GetScreen() );
Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); Struct->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
Struct->SetNext( GetScreen()->GetDrawItems() ); Struct->SetNext( GetScreen()->GetDrawItems() );
...@@ -584,7 +580,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC ) ...@@ -584,7 +580,7 @@ void SCH_EDIT_FRAME::PasteListOfItems( wxDC* DC )
MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector ); MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector );
/* clear .m_Flags member for all items */ // Clear flags for all items.
GetScreen()->ClearDrawingState(); GetScreen()->ClearDrawingState();
OnModify(); OnModify();
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC ); static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC );
static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer ); 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 ); static void ComputeBreakPoint( SCH_LINE* segment, const wxPoint& new_pos );
SCH_ITEM* s_OldWiresList; SCH_ITEM* s_OldWiresList;
...@@ -92,7 +91,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) ...@@ -92,7 +91,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
SCH_LINE* oldsegment, * newsegment, * nextsegment; SCH_LINE* oldsegment, * newsegment, * nextsegment;
wxPoint cursorpos = GetScreen()->GetCrossHairPosition(); wxPoint cursorpos = GetScreen()->GetCrossHairPosition();
if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->m_Flags == 0) ) if( GetScreen()->GetCurItem() && (GetScreen()->GetCurItem()->GetFlags() == 0) )
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
if( GetScreen()->GetCurItem() ) if( GetScreen()->GetCurItem() )
...@@ -134,12 +133,12 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) ...@@ -134,12 +133,12 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
break; 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 if( g_HVLines ) // We need 2 segments to go from a given start pin to an end point
{ {
nextsegment = new SCH_LINE( *newsegment ); nextsegment = new SCH_LINE( *newsegment );
nextsegment->m_Flags = IS_NEW; nextsegment->SetFlags( IS_NEW );
newsegment->SetNext( nextsegment ); newsegment->SetNext( nextsegment );
nextsegment->SetBack( newsegment ); nextsegment->SetBack( newsegment );
} }
...@@ -199,8 +198,9 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) ...@@ -199,8 +198,9 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
} }
newsegment->m_End = cursorpos; newsegment->m_End = cursorpos;
oldsegment->m_Flags = SELECTED; oldsegment->ClearFlags( IS_NEW );
newsegment->m_Flags = IS_NEW; oldsegment->SetFlags( SELECTED );
newsegment->SetFlags( IS_NEW );
GetScreen()->SetCurItem( newsegment ); GetScreen()->SetCurItem( newsegment );
DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false ); DrawPanel->m_mouseCaptureCallback( DrawPanel, DC, wxDefaultPosition, false );
...@@ -210,7 +210,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type ) ...@@ -210,7 +210,7 @@ void SCH_EDIT_FRAME::BeginSegment( wxDC* DC, int type )
* (tested when the connection will be finished)*/ * (tested when the connection will be finished)*/
if( oldsegment->m_Start == s_ConnexionStartPoint ) if( oldsegment->m_Start == s_ConnexionStartPoint )
{ {
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) ) if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
AddJunction( DC, s_ConnexionStartPoint ); AddJunction( DC, s_ConnexionStartPoint );
} }
} }
...@@ -291,28 +291,28 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC ) ...@@ -291,28 +291,28 @@ void SCH_EDIT_FRAME::EndSegment( wxDC* DC )
while( segment ) while( segment )
{ {
if( segment->m_Flags ) if( segment->GetFlags() )
{ {
if( !m_itemToRepeat ) if( !m_itemToRepeat )
m_itemToRepeat = segment; m_itemToRepeat = segment;
} }
segment->m_Flags = 0; segment->ClearFlags();
segment = segment->Next(); segment = segment->Next();
} }
// Automatic place of a junction on the end point, if needed // Automatic place of a junction on the end point, if needed
if( lastsegment ) if( lastsegment )
{ {
if( IsJunctionNeeded( this, end_point ) ) if( GetScreen()->IsJunctionNeeded( end_point ) )
AddJunction( DC, 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 ); AddJunction( DC, alt_end_point );
} }
/* Automatic place of a junction on the start point if necessary because /* Automatic place of a junction on the start point if necessary because
* the cleanup can suppress intermediate points by merging wire segments */ * the cleanup can suppress intermediate points by merging wire segments */
if( IsJunctionNeeded( this, s_ConnexionStartPoint ) ) if( GetScreen()->IsJunctionNeeded( s_ConnexionStartPoint ) )
AddJunction( DC, s_ConnexionStartPoint ); AddJunction( DC, s_ConnexionStartPoint );
GetScreen()->TestDanglingEnds( DrawPanel, DC ); GetScreen()->TestDanglingEnds( DrawPanel, DC );
...@@ -500,14 +500,8 @@ static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC ) ...@@ -500,14 +500,8 @@ static void AbortCreateNewLine( EDA_DRAW_PANEL* Panel, wxDC* DC )
parent->SetRepeatItem( NULL ); parent->SetRepeatItem( NULL );
} }
/* Clear m_Flags which is used in edit functions: */ // Clear flags used in edit functions.
SCH_ITEM* item = screen->GetDrawItems(); screen->ClearDrawingState();
while( item )
{
item->m_Flags = 0;
item = item->Next();
}
} }
...@@ -526,7 +520,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC ) ...@@ -526,7 +520,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
{ {
wxPoint pos = GetScreen()->GetCrossHairPosition() - wxPoint pos = GetScreen()->GetCrossHairPosition() -
( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos; ( (SCH_COMPONENT*) m_itemToRepeat )->m_Pos;
m_itemToRepeat->m_Flags = IS_NEW; m_itemToRepeat->SetFlags( IS_NEW );
( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp(); ( (SCH_COMPONENT*) m_itemToRepeat )->m_TimeStamp = GetTimeStamp();
m_itemToRepeat->Move( pos ); m_itemToRepeat->Move( pos );
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode ); m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
...@@ -546,7 +540,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC ) ...@@ -546,7 +540,7 @@ void SCH_EDIT_FRAME::RepeatDrawItem( wxDC* DC )
GetScreen()->TestDanglingEnds(); GetScreen()->TestDanglingEnds();
m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE ); m_itemToRepeat->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
SaveCopyInUndoList( m_itemToRepeat, UR_NEW ); 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 ) ...@@ -601,7 +595,7 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
switch( layer ) switch( layer )
{ {
case LAYER_BUS: case LAYER_BUS:
item = PickStruct( pos, screen, BUS_T ); item = screen->GetItem( pos, 0, BUS_T );
if( item ) if( item )
return true; return true;
...@@ -618,13 +612,14 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer ) ...@@ -618,13 +612,14 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
break; break;
case LAYER_NOTES: case LAYER_NOTES:
item = PickStruct( pos, screen, DRAW_ITEM_T ); item = screen->GetItem( pos, 0, DRAW_ITEM_T );
if( item ) if( item )
return true; return true;
break; break;
case LAYER_WIRE: 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 ) if( item )
return true; return true;
...@@ -643,12 +638,12 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer ) ...@@ -643,12 +638,12 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
return true; return true;
} }
item = PickStruct( pos, screen, WIRE_T ); item = screen->GetItem( pos, 0, WIRE_T );
if( item ) if( item )
return true; return true;
item = PickStruct( pos, screen, LABEL_T ); item = screen->GetItem( pos, 0, LABEL_T );
if( item && (item->Type() != SCH_TEXT_T) if( item && (item->Type() != SCH_TEXT_T)
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.x == pos.x ) && ( ( (SCH_GLOBALLABEL*) item )->m_Pos.x == pos.x )
&& ( ( (SCH_GLOBALLABEL*) item )->m_Pos.y == pos.y ) ) && ( ( (SCH_GLOBALLABEL*) item )->m_Pos.y == pos.y ) )
...@@ -672,29 +667,3 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer ) ...@@ -672,29 +667,3 @@ static bool IsTerminalPoint( SCH_SCREEN* screen, const wxPoint& pos, int layer )
return false; 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;
}
...@@ -120,7 +120,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -120,7 +120,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
wxString Text; wxString Text;
wxString msg; wxString msg;
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), MARKER_T ); item = GetScreen()->GetItem( aPosition, 0, MARKER_T );
if( item ) if( item )
{ {
...@@ -128,7 +128,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -128,7 +128,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_CONNECT_T ); item = GetScreen()->GetItem( aPosition, 0, NO_CONNECT_T );
if( item ) if( item )
{ {
...@@ -136,7 +136,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -136,7 +136,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), JUNCTION_T ); item = GetScreen()->GetItem( aPosition, 0, JUNCTION_T );
if( item ) if( item )
{ {
...@@ -144,7 +144,8 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -144,7 +144,8 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; 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 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 ...@@ -164,17 +165,20 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), DRAW_ITEM_T ); item = GetScreen()->GetItem( aPosition, 0, DRAW_ITEM_T );
if( item ) if( item )
{ {
ClearMsgPanel(); ClearMsgPanel();
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), FIELD_T ); item = GetScreen()->GetItem( aPosition, 0, FIELD_T );
if( item ) if( item )
{ {
wxASSERT( item->Type() == SCH_FIELD_T );
SCH_FIELD* Field = (SCH_FIELD*) item; SCH_FIELD* Field = (SCH_FIELD*) item;
LibItem = (SCH_COMPONENT*) Field->GetParent(); LibItem = (SCH_COMPONENT*) Field->GetParent();
LibItem->DisplayInfo( this ); LibItem->DisplayInfo( this );
...@@ -182,7 +186,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -182,7 +186,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), LABEL_T | TEXT_T ); item = GetScreen()->GetItem( aPosition, 0, LABEL_T | TEXT_T );
if( item ) if( item )
{ {
...@@ -204,7 +208,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -204,7 +208,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return LibItem; return LibItem;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), COMPONENT_T ); item = GetScreen()->GetItem( aPosition, 0, COMPONENT_T );
if( item ) if( item )
{ {
...@@ -214,7 +218,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -214,7 +218,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), SHEET_T ); item = GetScreen()->GetItem( aPosition, 0, SHEET_T );
if( item ) if( item )
{ {
...@@ -222,7 +226,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin ...@@ -222,7 +226,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, bool aIncludePin
return item; return item;
} }
item = (SCH_ITEM*) PickStruct( aPosition, GetScreen(), NO_FILTER_T ); item = GetScreen()->GetItem( aPosition );
if( item ) if( item )
return item; return item;
...@@ -295,7 +299,7 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH ...@@ -295,7 +299,7 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey ) if( aHotKey )
{ {
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else else
OnHotKey( aDC, aHotKey, aPosition, NULL ); OnHotKey( aDC, aHotKey, aPosition, NULL );
...@@ -368,7 +372,7 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH ...@@ -368,7 +372,7 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey ) if( aHotKey )
{ {
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else else
OnHotKey( aDC, aHotKey, aPosition, NULL ); OnHotKey( aDC, aHotKey, aPosition, NULL );
...@@ -441,7 +445,7 @@ void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH ...@@ -441,7 +445,7 @@ void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH
if( aHotKey ) if( aHotKey )
{ {
if( screen->GetCurItem() && screen->GetCurItem()->m_Flags ) if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() )
OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() );
else else
OnHotKey( aDC, aHotKey, aPosition, NULL ); OnHotKey( aDC, aHotKey, aPosition, NULL );
......
...@@ -17,98 +17,36 @@ ...@@ -17,98 +17,36 @@
#include "sch_text.h" #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 * Delete a connection, i.e wires or bus connected
* stop on a node (more than 2 wires (bus) connected) * stop on a node (more than 2 wires (bus) connected)
*/ */
void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection ) void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
{ {
SCH_SCREEN* screen = GetScreen(); SCH_ITEM* item;
wxPoint refpos = screen->GetCrossHairPosition(); EDA_ITEM* tmp;
SCH_ITEM* DelStruct;
PICKED_ITEMS_LIST pickList; 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->ClearDrawingState();
screen->BreakSegmentsOnJunctions(); 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 // Save the list entry point of this screen
SCH_ITEM* savedItems = screen->GetDrawItems(); SCH_ITEM* savedItems = screen->GetDrawItems();
DelStruct = screen->GetDrawItems(); item = screen->GetDrawItems();
while( DelStruct while( item && ( item = screen->GetItem( pos, 0, JUNCTION_T | WIRE_T | BUS_T ) ) != NULL )
&& ( DelStruct = PickStruct( screen->GetCrossHairPosition(), screen,
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: */ /* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct; ITEM_PICKER picker( item, UR_DELETED );
picker.m_PickedItemType = DelStruct->Type();
pickList.PushItem( picker ); pickList.PushItem( picker );
DelStruct = DelStruct->Next(); item = item->Next();
screen->SetDrawItems( DelStruct ); screen->SetDrawItems( item );
} }
screen->SetDrawItems( savedItems ); // Restore the list entry point. screen->SetDrawItems( savedItems ); // Restore the list entry point.
...@@ -117,150 +55,134 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection ) ...@@ -117,150 +55,134 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
*/ */
if( DeleteFullConnection ) if( DeleteFullConnection )
{ {
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL; SCH_LINE* segment;
DelStruct = DelStruct->Next() )
for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
{ {
if( !(DelStruct->m_Flags & SELECTEDNODE) ) if( !(item->GetFlags() & SELECTEDNODE) )
continue; continue;
#define SEGM ( (SCH_LINE*) DelStruct ) if( item->Type() != SCH_LINE_T )
if( DelStruct->Type() != SCH_LINE_T )
continue; continue;
MarkConnected( this, screen->GetDrawItems(), SEGM ); screen->MarkConnections( (SCH_LINE*) item );
#undef SEGM
} }
// Search all removable wires (i.e wire with one new dangling end ) // Search all removable wires (i.e wire with one new dangling end )
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL; for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
DelStruct = DelStruct->Next() )
{ {
bool noconnect = FALSE; bool noconnect = false;
if( DelStruct->m_Flags & STRUCT_DELETED ) if( item->GetFlags() & STRUCT_DELETED )
continue; // Already seen continue; // Already seen
if( !(DelStruct->m_Flags & CANDIDATE) ) if( !(item->GetFlags() & CANDIDATE) )
continue; // Already seen continue; // Already seen
if( DelStruct->Type() != SCH_LINE_T ) if( item->Type() != SCH_LINE_T )
continue; continue;
DelStruct->m_Flags |= SKIP_STRUCT; item->SetFlags( SKIP_STRUCT );
#define SEGM ( (SCH_LINE*) DelStruct )
segment = (SCH_LINE*) item;
/* Test the SEGM->m_Start point: if this point was connected to /* Test the SEGM->m_Start point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire can * an STRUCT_DELETED wire, and now is not connected, the wire can
* be deleted */ * be deleted */
EDA_ITEM* removed_struct; SCH_LINE* testSegment = NULL;
for( removed_struct = screen->GetDrawItems();
removed_struct != NULL; for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
removed_struct = removed_struct->Next() )
{ {
if( ( removed_struct->m_Flags & STRUCT_DELETED ) == 0 ) if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue; continue;
if( removed_struct->Type() != SCH_LINE_T ) if( tmp->Type() != SCH_LINE_T )
continue; continue;
#define WIRE ( (SCH_LINE*) removed_struct ) testSegment = (SCH_LINE*) tmp;
if( WIRE->IsEndPoint( SEGM->m_Start ) )
if( testSegment->IsEndPoint( segment->m_Start ) )
break; break;
} }
if( WIRE && !screen->CountConnectedItems( SEGM->m_Start, true ) ) if( testSegment && !screen->CountConnectedItems( segment->m_Start, true ) )
noconnect = TRUE; noconnect = true;
/* Test the SEGM->m_End point: if this point was connected to /* Test the SEGM->m_End point: if this point was connected to
* an STRUCT_DELETED wire, and now is not connected, the wire * an STRUCT_DELETED wire, and now is not connected, the wire
* can be deleted */ * can be deleted */
for( removed_struct = screen->GetDrawItems(); for( tmp = screen->GetDrawItems(); tmp != NULL; tmp = tmp->Next() )
removed_struct != NULL;
removed_struct = removed_struct->Next() )
{ {
if( ( removed_struct->m_Flags & STRUCT_DELETED ) == 0 ) if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
continue; continue;
if( removed_struct->Type() != SCH_LINE_T )
if( tmp->Type() != SCH_LINE_T )
continue; continue;
if( WIRE->IsEndPoint( SEGM->m_End ) )
if( testSegment->IsEndPoint( segment->m_End ) )
break; break;
} }
if( removed_struct && !screen->CountConnectedItems( SEGM->m_End, true ) ) if( tmp && !screen->CountConnectedItems( segment->m_End, true ) )
noconnect = TRUE; noconnect = true;
DelStruct->m_Flags &= ~SKIP_STRUCT; item->ClearFlags( SKIP_STRUCT );
if( noconnect ) if( noconnect )
{ {
DelStruct->m_Flags |= STRUCT_DELETED; item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */ /* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct; ITEM_PICKER picker( item, UR_DELETED );
picker.m_PickedItemType = DelStruct->Type();
pickList.PushItem( picker ); pickList.PushItem( picker );
DelStruct = screen->GetDrawItems(); item = screen->GetDrawItems();
} }
#undef SEGM
} }
// Delete redundant junctions (junctions which connect < 3 end wires // Delete redundant junctions (junctions which connect < 3 end wires
// and no pin are removed) // and no pin are removed)
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL; for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
DelStruct = DelStruct->Next() )
{ {
if( DelStruct->m_Flags & STRUCT_DELETED ) if( item->GetFlags() & STRUCT_DELETED )
continue; continue;
if( !(DelStruct->m_Flags & CANDIDATE) ) if( !(item->GetFlags() & CANDIDATE) )
continue; continue;
if( DelStruct->Type() == SCH_JUNCTION_T ) if( item->Type() != SCH_JUNCTION_T )
continue;
SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
if( screen->CountConnectedItems( junction->m_Pos, false ) <= 2 )
{ {
#define JUNCTION ( (SCH_JUNCTION*) DelStruct ) item->SetFlags( STRUCT_DELETED );
if( screen->CountConnectedItems( JUNCTION->m_Pos, false ) <= 2 ) /* Put this structure in the picked list: */
{ ITEM_PICKER picker( item, UR_DELETED );
DelStruct->m_Flags |= STRUCT_DELETED; pickList.PushItem( picker );
/* 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 for( item = screen->GetDrawItems(); item != NULL; item = item->Next() )
wxPoint pos = screen->GetCrossHairPosition();
for( DelStruct = screen->GetDrawItems(); DelStruct != NULL;
DelStruct = DelStruct->Next() )
{ {
if( DelStruct->m_Flags & STRUCT_DELETED ) if( item->GetFlags() & STRUCT_DELETED )
continue; continue;
if( DelStruct->Type() != SCH_LABEL_T ) if( item->Type() != SCH_LABEL_T )
continue; continue;
GetScreen()->SetCrossHairPosition( ( (SCH_TEXT*) DelStruct )->m_Pos ); tmp = screen->GetItem( ( (SCH_TEXT*) item )->m_Pos, 0, WIRE_T | BUS_T );
EDA_ITEM* TstStruct = PickStruct( screen->GetCrossHairPosition(), GetScreen(),
WIRE_T | BUS_T );
if( TstStruct && TstStruct->m_Flags & STRUCT_DELETED ) if( tmp && tmp->GetFlags() & STRUCT_DELETED )
{ {
DelStruct->m_Flags |= STRUCT_DELETED; item->SetFlags( STRUCT_DELETED );
/* Put this structure in the picked list: */ /* Put this structure in the picked list: */
picker.m_PickedItem = DelStruct; ITEM_PICKER picker( item, UR_DELETED );
picker.m_PickedItemType = DelStruct->Type();
pickList.PushItem( picker ); pickList.PushItem( picker );
} }
} }
screen->SetCrossHairPosition( pos );
} }
screen->ClearDrawingState(); screen->ClearDrawingState();
...@@ -273,139 +195,46 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection ) ...@@ -273,139 +195,46 @@ void SCH_EDIT_FRAME::DeleteConnection( bool DeleteFullConnection )
} }
/* bool SCH_EDIT_FRAME::DeleteItemAtCrossHair( wxDC* DC )
* 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 )
{ {
SCH_ITEM* DelStruct; SCH_ITEM* item;
SCH_SCREEN* screen = (SCH_SCREEN*) ( frame->GetScreen() ); SCH_SCREEN* screen = GetScreen();
bool item_deleted = FALSE; 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 );
if( DelStruct )
{
frame->SetRepeatItem( NULL );
DeleteStruct( frame->DrawPanel, DC, DelStruct );
frame->GetScreen()->TestDanglingEnds( frame->DrawPanel, DC );
frame->OnModify( );
item_deleted = TRUE;
}
return item_deleted;
}
item = screen->GetItem( screen->GetCrossHairPosition(), 0, MARKER_T );
/* if( item == NULL )
* Remove definition of a structure in a linked list item = screen->GetItem( screen->GetCrossHairPosition(), 0, JUNCTION_T );
* 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 ) if( item == NULL )
return; item = screen->GetItem( screen->GetCrossHairPosition(), 0, NO_CONNECT_T );
if( Screen == NULL ) if( item == NULL )
return; item = screen->GetItem( screen->GetCrossHairPosition(), 0, BUS_ENTRY_T );
Screen->SetModify(); if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, WIRE_T | BUS_T );
if( DrawStruct->Type() == SCH_SHEET_LABEL_T ) if( item == NULL )
{ item = screen->GetItem( screen->GetCrossHairPosition(), 0, DRAW_ITEM_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( item == NULL )
{ item = screen->GetItem( screen->GetCrossHairPosition(), 0, TEXT_T | LABEL_T );
if( DrawList->Next() == DrawStruct )
{
DrawList->SetNext( DrawStruct->Next() );
SAFE_DELETE( DrawStruct );
return;
}
DrawList = DrawList->Next();
}
}
}
}
if( item == NULL )
item = screen->GetItem( screen->GetCrossHairPosition(), 0, COMPONENT_T );
void DeleteAllMarkers( int type ) if( item == NULL )
{ item = screen->GetItem( screen->GetCrossHairPosition(), 0, SHEET_T );
SCH_SCREEN* screen;
SCH_ITEM * DrawStruct, * NextStruct;
SCH_MARKER* Marker;
SCH_SCREENS ScreenList;
for( screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() ) if( item )
{ {
for( DrawStruct = screen->GetDrawItems(); DrawStruct != NULL; DrawStruct = NextStruct ) SetRepeatItem( NULL );
{ DeleteItem( item );
NextStruct = DrawStruct->Next(); screen->TestDanglingEnds( DrawPanel, DC );
OnModify();
if( DrawStruct->Type() != SCH_MARKER_T ) item_deleted = true;
continue;
Marker = (SCH_MARKER*) DrawStruct;
if( Marker->GetMarkerType() != type )
continue;
/* Remove marker */
EraseStruct( DrawStruct, screen );
}
} }
return item_deleted;
} }
...@@ -85,7 +85,8 @@ void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event ) ...@@ -85,7 +85,8 @@ void DIALOG_ERC::OnEraseDrcMarkersClick( wxCommandEvent& event )
{ {
/* Delete the old ERC markers, over the whole hierarchy /* Delete the old ERC markers, over the whole hierarchy
*/ */
DeleteAllMarkers( MARK_ERC ); SCH_SCREENS ScreenList;
ScreenList.DeleteAllMarkers( MARK_ERC );
m_MarkersList->ClearList(); m_MarkersList->ClearList();
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();
} }
...@@ -427,14 +428,13 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList ) ...@@ -427,14 +428,13 @@ void DIALOG_ERC::TestErc( wxArrayString* aMessagesList )
} }
/* Erase all DRC markers */ /* Erase all DRC markers */
DeleteAllMarkers( MARK_ERC ); SCH_SCREENS ScreenList;
ScreenList.DeleteAllMarkers( MARK_ERC );
g_EESchemaVar.NbErrorErc = 0; g_EESchemaVar.NbErrorErc = 0;
g_EESchemaVar.NbWarningErc = 0; g_EESchemaVar.NbWarningErc = 0;
/* Cleanup the entire hierarchy */
SCH_SCREENS ScreenList;
for( SCH_SCREEN* Screen = ScreenList.GetFirst(); for( SCH_SCREEN* Screen = ScreenList.GetFirst();
Screen != NULL; Screen != NULL;
Screen = ScreenList.GetNext() ) Screen = ScreenList.GetNext() )
......
...@@ -79,8 +79,8 @@ void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC ) ...@@ -79,8 +79,8 @@ void SCH_EDIT_FRAME::StartMoveTexte( SCH_TEXT* aTextItem, wxDC* aDC )
void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC ) void SCH_EDIT_FRAME::ChangeTextOrient( SCH_TEXT* aTextItem, wxDC* aDC )
{ {
if( aTextItem == NULL ) if( aTextItem == NULL )
aTextItem = (SCH_TEXT*) PickStruct( GetScreen()->GetCrossHairPosition(), aTextItem = (SCH_TEXT*) GetScreen()->GetItem( GetScreen()->GetCrossHairPosition(), 0,
GetScreen(), TEXT_T | LABEL_T ); TEXT_T | LABEL_T );
if( aTextItem == NULL ) if( aTextItem == NULL )
return; return;
...@@ -348,7 +348,7 @@ void SCH_EDIT_FRAME::OnConvertTextType( wxCommandEvent& aEvent ) ...@@ -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 if( (flags & IS_NEW) == 0 ) // Remove old text from current list and save it in undo list
{ {
text->ClearFlags(); 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 ); GetScreen()->SetCurItem( NULL );
m_itemToRepeat = NULL; m_itemToRepeat = NULL;
} }
......
...@@ -265,7 +265,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -265,7 +265,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
// itemInEdit == false means no item currently edited. We can ask for editing a new item // 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 // 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 // We can change active tool and ask for editing a new item
bool notBusy = (!itemInEdit) && (screen->m_BlockLocate.m_State == STATE_NO_BLOCK); 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, ...@@ -342,7 +342,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case HK_DELETE: case HK_DELETE:
if( notBusy) if( notBusy)
{ {
LocateAndDeleteItem( this, aDC ); DeleteItemAtCrossHair( aDC );
OnModify(); OnModify();
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
GetScreen()->TestDanglingEnds( DrawPanel, aDC ); GetScreen()->TestDanglingEnds( DrawPanel, aDC );
...@@ -350,7 +350,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -350,7 +350,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break; break;
case HK_REPEAT_LAST: case HK_REPEAT_LAST:
if( notBusy && m_itemToRepeat && ( m_itemToRepeat->m_Flags == 0 ) ) if( notBusy && m_itemToRepeat && ( m_itemToRepeat->GetFlags() == 0 ) )
RepeatDrawItem( aDC ); RepeatDrawItem( aDC );
break; break;
...@@ -701,7 +701,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -701,7 +701,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
if( aItem->Type() == SCH_JUNCTION_T ) if( aItem->Type() == SCH_JUNCTION_T )
{ {
// If it's a junction, pick the underlying wire instead // 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 ) if( aItem == NULL )
...@@ -716,7 +716,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -716,7 +716,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break; break;
} }
if( aItem && (aItem->m_Flags == 0) ) if( aItem && (aItem->GetFlags() == 0) )
{ {
GetScreen()->SetCurItem( (SCH_ITEM*) aItem ); GetScreen()->SetCurItem( (SCH_ITEM*) aItem );
...@@ -777,8 +777,8 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -777,8 +777,8 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
if( aItem == NULL ) if( aItem == NULL )
{ {
aItem = PickStruct( GetScreen()->GetCrossHairPosition(), GetScreen(), aItem = screen->GetItem( screen->GetCrossHairPosition(), 0,
COMPONENT_T | TEXT_T | LABEL_T | SHEET_T ); COMPONENT_T | TEXT_T | LABEL_T | SHEET_T );
if( aItem == NULL ) if( aItem == NULL )
break; break;
...@@ -857,7 +857,7 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -857,7 +857,7 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
cmd.SetEventObject( this ); cmd.SetEventObject( this );
bool itemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->m_Flags; bool itemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->GetFlags();
if( aHotKey == 0 ) if( aHotKey == 0 )
return; return;
...@@ -932,8 +932,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, ...@@ -932,8 +932,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break; break;
case HK_REPEAT_LAST: 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 ) ) && ( m_lastDrawItem->Type() == LIB_PIN_T ) )
RepeatPinItem( aDC, (LIB_PIN*) m_lastDrawItem ); RepeatPinItem( aDC, (LIB_PIN*) m_lastDrawItem );
break; break;
......
...@@ -23,10 +23,6 @@ ...@@ -23,10 +23,6 @@
#include "template_fieldnames.h" #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 * Search the smaller (considering its area) component under the mouse
* cursor or the pcb cursor * cursor or the pcb cursor
...@@ -36,38 +32,39 @@ static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawLi ...@@ -36,38 +32,39 @@ static bool SnapPoint2( const wxPoint& aPosRef, int SearchMask, SCH_ITEM* DrawLi
*/ */
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
{ {
SCH_COMPONENT* component = NULL, * lastcomponent = NULL; double area;
SCH_ITEM* DrawList; EDA_Rect rect;
EDA_Rect BoundaryBox; PICKED_ITEMS_LIST itemList;
float sizeref = 0, sizecurr; 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( Screen->GetItems( Screen->GetCrossHairPosition(), itemList, COMPONENT_T ) == 0 )
{ return NULL;
if( !SnapPoint2( Screen->GetCrossHairPosition(), COMPONENT_T, DrawList ) ) }
break;
}
component = (SCH_COMPONENT*) LastSnappedStruct; if( itemList.GetCount() == 1 )
DrawList = component->Next(); 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; lastcomponent = component;
BoundaryBox = lastcomponent->GetBoundingBox(); rect = lastcomponent->GetBoundingBox();
sizeref = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() ); area = ABS( (double) rect.GetWidth() * (double) rect.GetHeight() );
} }
else else
{ {
BoundaryBox = component->GetBoundingBox(); rect = component->GetBoundingBox();
sizecurr = ABS( (float) BoundaryBox.GetWidth() * BoundaryBox.GetHeight() ); 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; lastcomponent = component;
} }
} }
...@@ -75,250 +72,3 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ) ...@@ -75,250 +72,3 @@ SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen )
return lastcomponent; 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;
}
...@@ -31,12 +31,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -31,12 +31,12 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
SCH_ITEM* item = GetScreen()->GetCurItem(); SCH_ITEM* item = GetScreen()->GetCurItem();
wxPoint gridPosition = GetGridPosition( aPosition ); 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; DrawPanel->m_AutoPAN_Request = false;
m_itemToRepeat = NULL; m_itemToRepeat = NULL;
if( item && item->m_Flags ) if( item && item->GetFlags() )
{ {
switch( item->Type() ) switch( item->Type() )
{ {
...@@ -77,7 +77,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -77,7 +77,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_HIERARCHY_PUSH_POP_BUTT: case ID_HIERARCHY_PUSH_POP_BUTT:
if( ( item && item->m_Flags ) || ( g_RootSheet->CountSheets() == 0 ) ) if( ( item && item->GetFlags() ) || ( g_RootSheet->CountSheets() == 0 ) )
break; break;
item = LocateAndShowItem( aPosition ); item = LocateAndShowItem( aPosition );
...@@ -99,7 +99,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -99,7 +99,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_NOCONN_BUTT: case ID_NOCONN_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
m_itemToRepeat = AddNoConnect( aDC, gridPosition ); m_itemToRepeat = AddNoConnect( aDC, gridPosition );
GetScreen()->SetCurItem( m_itemToRepeat ); GetScreen()->SetCurItem( m_itemToRepeat );
...@@ -116,7 +116,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -116,7 +116,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_JUNCTION_BUTT: case ID_JUNCTION_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
m_itemToRepeat = AddJunction( aDC, gridPosition, true ); m_itemToRepeat = AddJunction( aDC, gridPosition, true );
GetScreen()->SetCurItem( m_itemToRepeat ); GetScreen()->SetCurItem( m_itemToRepeat );
...@@ -134,7 +134,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -134,7 +134,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_WIRETOBUS_ENTRY_BUTT: case ID_WIRETOBUS_ENTRY_BUTT:
case ID_BUSTOBUS_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 ) ? item = CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ?
WIRE_TO_BUS : BUS_TO_BUS ); WIRE_TO_BUS : BUS_TO_BUS );
...@@ -152,7 +152,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -152,7 +152,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_SCHEMATIC_DELETE_ITEM_BUTT: case ID_SCHEMATIC_DELETE_ITEM_BUTT:
LocateAndDeleteItem( this, aDC ); DeleteItemAtCrossHair( aDC );
OnModify(); OnModify();
GetScreen()->SetCurItem( NULL ); GetScreen()->SetCurItem( NULL );
GetScreen()->TestDanglingEnds(); GetScreen()->TestDanglingEnds();
...@@ -175,7 +175,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -175,7 +175,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_TEXT_COMMENT_BUTT: case ID_TEXT_COMMENT_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) ); GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_NOTES ) );
DrawPanel->m_AutoPAN_Request = true; DrawPanel->m_AutoPAN_Request = true;
...@@ -188,7 +188,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -188,7 +188,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_LABEL_BUTT: case ID_LABEL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) ); GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_LOCLABEL ) );
DrawPanel->m_AutoPAN_Request = true; DrawPanel->m_AutoPAN_Request = true;
...@@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_GLABEL_BUTT: case ID_GLABEL_BUTT:
case ID_HIERLABEL_BUTT: case ID_HIERLABEL_BUTT:
if( (item == NULL) || (item->m_Flags == 0) ) if( (item == NULL) || (item->GetFlags() == 0) )
{ {
if( GetToolId() == ID_GLABEL_BUTT ) if( GetToolId() == ID_GLABEL_BUTT )
GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) ); GetScreen()->SetCurItem( CreateNewText( aDC, LAYER_GLOBLABEL ) );
...@@ -224,7 +224,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -224,7 +224,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_SHEET_SYMBOL_BUTT: case ID_SHEET_SYMBOL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
GetScreen()->SetCurItem( CreateSheet( aDC ) ); GetScreen()->SetCurItem( CreateSheet( aDC ) );
DrawPanel->m_AutoPAN_Request = true; DrawPanel->m_AutoPAN_Request = true;
...@@ -240,20 +240,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -240,20 +240,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case ID_IMPORT_HLABEL_BUTT: case ID_IMPORT_HLABEL_BUTT:
case ID_SHEET_LABEL_BUTT: case ID_SHEET_LABEL_BUTT:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
item = LocateAndShowItem( aPosition ); item = LocateAndShowItem( aPosition );
if( item == NULL ) if( item == NULL )
break; 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 ) if( GetToolId() == ID_IMPORT_HLABEL_BUTT )
GetScreen()->SetCurItem( Import_PinSheet( (SCH_SHEET*) item, aDC ) ); GetScreen()->SetCurItem( Import_PinSheet( (SCH_SHEET*) item, aDC ) );
else else
GetScreen()->SetCurItem( Create_PinSheet( (SCH_SHEET*) item, aDC ) ); 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 ); item->Place( this, aDC );
GetScreen()->TestDanglingEnds(); GetScreen()->TestDanglingEnds();
...@@ -262,7 +262,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -262,7 +262,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_SCH_PLACE_COMPONENT: 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 ) ); GetScreen()->SetCurItem( Load_Component( aDC, wxEmptyString, s_CmpNameList, true ) );
DrawPanel->m_AutoPAN_Request = true; DrawPanel->m_AutoPAN_Request = true;
...@@ -277,7 +277,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -277,7 +277,7 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_PLACE_POWER_BUTT: 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" ), GetScreen()->SetCurItem( Load_Component( aDC, wxT( "power" ),
s_PowerNameList, false ) ); s_PowerNameList, false ) );
...@@ -317,12 +317,12 @@ void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -317,12 +317,12 @@ void SCH_EDIT_FRAME::OnLeftDClick( wxDC* aDC, const wxPoint& aPosition )
switch( GetToolId() ) switch( GetToolId() )
{ {
case ID_NO_TOOL_SELECTED: case ID_NO_TOOL_SELECTED:
if( ( item == NULL ) || ( item->m_Flags == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
item = LocateAndShowItem( aPosition ); item = LocateAndShowItem( aPosition );
} }
if( ( item == NULL ) || ( item->m_Flags != 0 ) ) if( ( item == NULL ) || ( item->GetFlags() != 0 ) )
break; break;
switch( item->Type() ) switch( item->Type() )
......
...@@ -64,7 +64,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -64,7 +64,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
} }
// Try to locate items at cursor position. // Try to locate items at cursor position.
if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) ) if( (DrawStruct == NULL) || (DrawStruct->GetFlags() == 0) )
{ {
DrawStruct = LocateAndShowItem( aPosition, false ); DrawStruct = LocateAndShowItem( aPosition, false );
...@@ -81,7 +81,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -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 Command in progress: add "cancel" and "end tool" menu
if( GetToolId() != ID_NO_TOOL_SELECTED ) 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 ); ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
} }
...@@ -93,7 +93,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -93,7 +93,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
} }
else else
{ {
if( DrawStruct && DrawStruct->m_Flags ) if( DrawStruct && DrawStruct->GetFlags() )
{ {
ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm ); ADD_MENUITEM( PopMenu, ID_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm );
PopMenu->AppendSeparator(); PopMenu->AppendSeparator();
...@@ -112,7 +112,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -112,7 +112,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
GetScreen()->SetCurItem( DrawStruct ); GetScreen()->SetCurItem( DrawStruct );
int flags = DrawStruct->m_Flags; int flags = DrawStruct->GetFlags();
bool is_new = (flags & IS_NEW) ? TRUE : FALSE; bool is_new = (flags & IS_NEW) ? TRUE : FALSE;
switch( DrawStruct->Type() ) switch( DrawStruct->Type() )
...@@ -228,7 +228,7 @@ void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field ) ...@@ -228,7 +228,7 @@ void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field )
{ {
wxString msg; wxString msg;
if( !Field->m_Flags ) if( !Field->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move Field" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move Field" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -259,7 +259,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -259,7 +259,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
if( libEntry ) if( libEntry )
libComponent = libEntry->GetComponent(); libComponent = libEntry->GetComponent();
if( !Component->m_Flags ) if( !Component->GetFlags() )
{ {
msg = _( "Move Component" ); msg = _( "Move Component" );
msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text; msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text;
...@@ -325,7 +325,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) ...@@ -325,7 +325,7 @@ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component )
ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP, ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, ID_POPUP_SCH_GENERIC_EDIT_CMP,
_( "Edit Component" ), edit_component_xpm ); _( "Edit Component" ), edit_component_xpm );
if( !Component->m_Flags ) if( !Component->GetFlags() )
{ {
msg = AddHotkeyName( _( "Copy Component" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Copy Component" ), s_Schematic_Hokeys_Descr,
HK_COPY_COMPONENT_OR_LABEL ); HK_COPY_COMPONENT_OR_LABEL );
...@@ -344,7 +344,7 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel ) ...@@ -344,7 +344,7 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel )
wxMenu* menu_change_type = new wxMenu; wxMenu* menu_change_type = new wxMenu;
wxString msg; wxString msg;
if( !GLabel->m_Flags ) if( !GLabel->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move Global Label" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move Global Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -381,7 +381,7 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel ) ...@@ -381,7 +381,7 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel )
wxMenu* menu_change_type = new wxMenu; wxMenu* menu_change_type = new wxMenu;
wxString msg; wxString msg;
if( !HLabel->m_Flags ) if( !HLabel->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move Hierarchical Label" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move Hierarchical Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -417,7 +417,7 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label ) ...@@ -417,7 +417,7 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label )
wxMenu* menu_change_type = new wxMenu; wxMenu* menu_change_type = new wxMenu;
wxString msg; wxString msg;
if( !Label->m_Flags ) if( !Label->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move Label" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -453,7 +453,7 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text ) ...@@ -453,7 +453,7 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
wxString msg; wxString msg;
wxMenu* menu_change_type = new wxMenu; wxMenu* menu_change_type = new wxMenu;
if( !Text->m_Flags ) if( !Text->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move Text" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move Text" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -490,19 +490,20 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text ) ...@@ -490,19 +490,20 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAME* frame ) void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAME* frame )
{ {
bool is_new = Junction->IsNew(); bool is_new = Junction->IsNew();
SCH_SCREEN* screen = frame->GetScreen();
wxString msg; wxString msg;
if( !is_new ) if( !is_new )
{ {
if( PickStruct( frame->GetScreen()->GetCrossHairPosition(), frame->GetScreen(), if( screen->GetItem( screen->GetCrossHairPosition(), 0,
WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) ) WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
} }
msg = AddHotkeyName( _( "Delete Junction" ), s_Schematic_Hokeys_Descr, HK_DELETE ); msg = AddHotkeyName( _( "Delete Junction" ), s_Schematic_Hokeys_Descr, HK_DELETE );
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, msg, delete_xpm ); 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_NODE, _( "Delete Node" ), delete_node_xpm );
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ), ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
...@@ -514,7 +515,8 @@ void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAM ...@@ -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 ) void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
{ {
bool is_new = Wire->IsNew(); bool is_new = Wire->IsNew();
wxPoint pos = frame->GetScreen()->GetCrossHairPosition(); SCH_SCREEN* screen = frame->GetScreen();
wxPoint pos = screen->GetCrossHairPosition();
wxString msg; wxString msg;
if( is_new ) if( is_new )
...@@ -532,8 +534,8 @@ void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame ) ...@@ -532,8 +534,8 @@ void AddMenusForWire( wxMenu* PopMenu, SCH_LINE* Wire, SCH_EDIT_FRAME* frame )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ), ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
delete_connection_xpm ); delete_connection_xpm );
if( PickStruct( frame->GetScreen()->GetCrossHairPosition(), frame->GetScreen(), if( screen->GetItem( screen->GetCrossHairPosition(), 0,
WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) ) WIRE_T | BUS_T | EXCLUDE_ENDPOINTS_T ) )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
PopMenu->AppendSeparator(); PopMenu->AppendSeparator();
...@@ -582,7 +584,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet ) ...@@ -582,7 +584,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
{ {
wxString msg; wxString msg;
if( !Sheet->m_Flags ) if( !Sheet->GetFlags() )
{ {
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ), enter_sheet_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ), enter_sheet_xpm );
PopMenu->AppendSeparator(); PopMenu->AppendSeparator();
...@@ -594,7 +596,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet ) ...@@ -594,7 +596,7 @@ void AddMenusForHierchicalSheet( wxMenu* PopMenu, SCH_SHEET* Sheet )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_sheet_xpm ); 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 ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), apply_xpm );
} }
...@@ -623,7 +625,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet ) ...@@ -623,7 +625,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
{ {
wxString msg; wxString msg;
if( !PinSheet->m_Flags ) if( !PinSheet->GetFlags() )
{ {
msg = AddHotkeyName( _( "Move PinSheet" ), s_Schematic_Hokeys_Descr, msg = AddHotkeyName( _( "Move PinSheet" ), s_Schematic_Hokeys_Descr,
HK_MOVE_COMPONENT_OR_ITEM ); HK_MOVE_COMPONENT_OR_ITEM );
...@@ -632,7 +634,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet ) ...@@ -632,7 +634,7 @@ void AddMenusForPinSheet( wxMenu* PopMenu, SCH_SHEET_PIN* PinSheet )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_PINSHEET, _( "Edit PinSheet" ), edit_xpm ); 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 ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete PinSheet" ), delete_pinsheet_xpm );
} }
......
...@@ -57,7 +57,7 @@ void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint ) ...@@ -57,7 +57,7 @@ void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& rotationPoint )
{ {
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii ); SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Rotate( rotationPoint ); // Place it in its new position. 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 ) ...@@ -73,7 +73,7 @@ void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint )
{ {
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii ); SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Mirror_Y( aMirrorPoint.x ); // Place it in its new position. 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 ...@@ -84,7 +84,7 @@ void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint
{ {
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii ); SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
item->Mirror_X( aMirrorPoint.y ); // Place it in its new position. 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 ) ...@@ -115,13 +115,11 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen();
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent(); SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
PICKED_ITEMS_LIST itemsList; PICKED_ITEMS_LIST itemsList;
ITEM_PICKER itemWrapper;
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ ) for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{ {
SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii ); SCH_ITEM* item = (SCH_ITEM*) aItemsList.GetPickedItem( ii );
itemWrapper.m_PickedItem = item; ITEM_PICKER itemWrapper( item, UR_DELETED );
itemWrapper.m_UndoRedoStatus = UR_DELETED;
if( item->Type() == SCH_SHEET_LABEL_T ) if( item->Type() == SCH_SHEET_LABEL_T )
{ {
...@@ -143,37 +141,31 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList ) ...@@ -143,37 +141,31 @@ void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList )
} }
/* Routine to delete an object from global drawing object list. void SCH_EDIT_FRAME::DeleteItem( SCH_ITEM* aItem )
* Object is put in Undo list
*/
void DeleteStruct( EDA_DRAW_PANEL* panel, wxDC* DC, SCH_ITEM* DrawStruct )
{ {
SCH_SCREEN* screen = (SCH_SCREEN*) panel->GetScreen(); wxCHECK_RET( aItem != NULL, wxT( "Cannot delete invalid item." ) );
SCH_EDIT_FRAME* frame = (SCH_EDIT_FRAME*) panel->GetParent();
if( !DrawStruct ) SCH_SCREEN* screen = GetScreen();
return;
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 // This iten is attached to a node, and is not accessible by the global list directly.
* the global list directly. */ SCH_SHEET* sheet = (SCH_SHEET*) aItem->GetParent();
frame->SaveCopyInUndoList( (SCH_ITEM*)( (SCH_SHEET_PIN*) DrawStruct )->GetParent(), wxCHECK_RET( (sheet != NULL) && (sheet->Type() == SCH_SHEET_T),
UR_CHANGED ); wxT( "Sheet label has invalid parent item." ) );
frame->DeleteSheetLabel( DC ? true : false, (SCH_SHEET_PIN*) DrawStruct ); SaveCopyInUndoList( (SCH_ITEM*) sheet, UR_CHANGED );
return; sheet->RemoveLabel( (SCH_SHEET_PIN*) aItem );
DrawPanel->RefreshDrawingRect( sheet->GetBoundingBox() );
} }
else else
{ {
screen->RemoveFromDrawList( DrawStruct ); screen->RemoveFromDrawList( aItem );
panel->RefreshDrawingRect( DrawStruct->GetBoundingBox() );
/* Unlink the structure */ aItem->SetNext( NULL );
DrawStruct->SetNext( 0 ); aItem->SetBack( NULL ); // Only one struct -> no link
DrawStruct->SetBack( 0 ); // Only one struct -> no link
frame->SaveCopyInUndoList( DrawStruct, UR_DELETED ); SaveCopyInUndoList( aItem, UR_DELETED );
DrawPanel->RefreshDrawingRect( aItem->GetBoundingBox() );
} }
} }
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
#ifndef __PROTOS_H__ #ifndef __PROTOS_H__
#define __PROTOS_H__ #define __PROTOS_H__
#include "class_undoredo_container.h"
#include "colors.h" #include "colors.h"
...@@ -50,13 +52,9 @@ void SnapLibItemPoint( int OrigX, ...@@ -50,13 +52,9 @@ void SnapLibItemPoint( int OrigX,
bool LibItemInBox( int x1, int y1, int x2, int y2, SCH_COMPONENT* DrawLibItem ); 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 // operations_on_item_lists.cpp
void DeleteItemsInList( EDA_DRAW_PANEL* panel, PICKED_ITEMS_LIST& aItemsList );
/** /**
* Function DuplicateStruct * Function DuplicateStruct
...@@ -75,38 +73,6 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false ); ...@@ -75,38 +73,6 @@ SCH_ITEM* DuplicateStruct( SCH_ITEM* DrawStruct, bool aClone = false );
SCH_COMPONENT* LocateSmallestComponent( SCH_SCREEN* Screen ); 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 */ /* EEREDRAW.CPP */
...@@ -142,14 +108,6 @@ bool ClearProjectDrawList( SCH_SCREEN* FirstWindow, bool confirm_deletion ); ...@@ -142,14 +108,6 @@ bool ClearProjectDrawList( SCH_SCREEN* FirstWindow, bool confirm_deletion );
* clear the screen datas (filenames ..) * 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 */ /* PINEDIT.CPP */
......
...@@ -447,10 +447,10 @@ void SCH_FIELD::Rotate( wxPoint rotationPoint ) ...@@ -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. // Do not hit test hidden or empty fields.
if( !IsVisible() ) if( !(aFilter & FIELD_T) || !IsVisible() || IsVoid() )
return false; return false;
EDA_Rect rect = GetBoundingBox(); EDA_Rect rect = GetBoundingBox();
......
...@@ -164,7 +164,7 @@ public: ...@@ -164,7 +164,7 @@ public:
void* aAuxData, wxPoint * aFindLocation ); void* aAuxData, wxPoint * aFindLocation );
private: 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 bool doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const;
virtual EDA_ITEM* doClone() const; virtual EDA_ITEM* doClone() const;
}; };
......
...@@ -144,15 +144,59 @@ void SCH_SCREEN::RemoveFromDrawList( SCH_ITEM * DrawStruct ) ...@@ -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 ) 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; return true;
DrawList = DrawList->Next();
itemList = itemList->Next();
} }
return false; return false;
...@@ -178,6 +222,52 @@ int SCH_SCREEN::GetItems( const wxPoint& aPosition, SCH_ITEMS& aItemList ) const ...@@ -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* SCH_SCREEN::ExtractWires( bool CreateCopy )
{ {
SCH_ITEM* item, * next_item, * new_item, * List = NULL; SCH_ITEM* item, * next_item, * new_item, * List = NULL;
...@@ -244,6 +334,64 @@ void SCH_SCREEN::ReplaceWires( SCH_ITEM* aWireList ) ...@@ -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: /* Routine cleaning:
* - Includes segments or buses aligned in only 1 segment * - Includes segments or buses aligned in only 1 segment
* - Detects identical objects superimposed * - Detects identical objects superimposed
...@@ -269,10 +417,9 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) ...@@ -269,10 +417,9 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
if( line->MergeOverlap( (SCH_LINE*) TstDrawList ) ) if( line->MergeOverlap( (SCH_LINE*) TstDrawList ) )
{ {
/* keep the bits set in .m_Flags, because the deleted // Keep the current flags, because the deleted segment can be flagged.
* segment can be flagged */ DrawList->SetFlags( TstDrawList->GetFlags() );
DrawList->m_Flags |= TstDrawList->m_Flags; DeleteItem( TstDrawList );
EraseStruct( TstDrawList, this );
TstDrawList = GetDrawItems(); TstDrawList = GetDrawItems();
Modify = true; Modify = true;
} }
...@@ -293,6 +440,7 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC ) ...@@ -293,6 +440,7 @@ bool SCH_SCREEN::SchematicCleanUp( EDA_DRAW_PANEL* aCanvas, wxDC* aDC )
if( aCanvas && Modify ) if( aCanvas && Modify )
aCanvas->Refresh(); aCanvas->Refresh();
return Modify; return Modify;
} }
...@@ -372,18 +520,6 @@ void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, int aDrawMode, int aC ...@@ -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 ) void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount )
{ {
if( aItemCount == 0 ) if( aItemCount == 0 )
...@@ -411,12 +547,12 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount ...@@ -411,12 +547,12 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
void SCH_SCREEN::ClearDrawingState() void SCH_SCREEN::ClearDrawingState()
{ {
for( SCH_ITEM* item = GetDrawItems(); item != NULL; item = item->Next() ) 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, LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
bool aEndPointOnly ) bool aEndPointOnly ) const
{ {
SCH_ITEM* item; SCH_ITEM* item;
SCH_COMPONENT* component = NULL; SCH_COMPONENT* component = NULL;
...@@ -465,59 +601,6 @@ SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition ) ...@@ -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 int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const
{ {
SCH_ITEM* item; SCH_ITEM* item;
...@@ -578,7 +661,7 @@ void SCH_SCREEN::SelectBlockItems() ...@@ -578,7 +661,7 @@ void SCH_SCREEN::SelectBlockItems()
for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ ) for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
{ {
item = (SCH_ITEM*) pickedlist->GetPickedItem( ii ); item = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
item->m_Flags = SELECTED; item->SetFlags( SELECTED );
} }
if( !m_BlockLocate.IsDragging() ) if( !m_BlockLocate.IsDragging() )
...@@ -589,6 +672,7 @@ void SCH_SCREEN::SelectBlockItems() ...@@ -589,6 +672,7 @@ void SCH_SCREEN::SelectBlockItems()
m_BlockLocate.Inflate(1); m_BlockLocate.Inflate(1);
unsigned last_select_id = pickedlist->GetCount(); unsigned last_select_id = pickedlist->GetCount();
unsigned ii = 0; unsigned ii = 0;
for( ; ii < last_select_id; ii++ ) for( ; ii < last_select_id; ii++ )
{ {
item = (SCH_ITEM*)pickedlist->GetPickedItem( ii ); item = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
...@@ -596,19 +680,22 @@ void SCH_SCREEN::SelectBlockItems() ...@@ -596,19 +680,22 @@ void SCH_SCREEN::SelectBlockItems()
if( item->Type() == SCH_LINE_T ) if( item->Type() == SCH_LINE_T )
{ {
item->IsSelectStateChanged( m_BlockLocate ); item->IsSelectStateChanged( m_BlockLocate );
if( ( item->m_Flags & SELECTED ) == 0 )
if( ( item->GetFlags() & SELECTED ) == 0 )
{ // This is a special case: { // This is a special case:
// this selected wire has no ends in block. // this selected wire has no ends in block.
// But it was selected (because it intersects the selecting area), // But it was selected (because it intersects the selecting area),
// so we must keep it selected and select items connected to it // so we must keep it selected and select items connected to it
// Note: an other option could be: remove it from drag list // 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; std::vector< wxPoint > connections;
item->GetConnectionPoints( connections ); item->GetConnectionPoints( connections );
for( size_t i = 0; i < connections.size(); i++ ) for( size_t i = 0; i < connections.size(); i++ )
addConnectedItemsToBlock( connections[i] ); addConnectedItemsToBlock( connections[i] );
} }
pickedlist->SetPickerFlags( item->m_Flags, ii );
pickedlist->SetPickerFlags( item->GetFlags(), ii );
} }
else if( item->IsConnectable() ) else if( item->IsConnectable() )
{ {
...@@ -633,11 +720,11 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position ) ...@@ -633,11 +720,11 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position )
for( item = GetDrawItems(); item != NULL; item = item->Next() ) for( item = GetDrawItems(); item != NULL; item = item->Next() )
{ {
picker.m_PickedItem = item; picker.SetItem( item );
picker.m_PickedItemType = item->Type(); picker.SetItemType( item->Type() );
if( !item->IsConnectable() || !item->IsConnected( position ) if( !item->IsConnectable() || !item->IsConnected( position )
|| (item->m_Flags & SKIP_STRUCT) ) || (item->GetFlags() & SKIP_STRUCT) )
continue; continue;
if( item->IsSelected() && item->Type() != SCH_LINE_T ) if( item->IsSelected() && item->Type() != SCH_LINE_T )
...@@ -647,23 +734,23 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position ) ...@@ -647,23 +734,23 @@ void SCH_SCREEN::addConnectedItemsToBlock( const wxPoint& position )
if( item->Type() == SCH_LINE_T ) if( item->Type() == SCH_LINE_T )
{ {
if( ! item->IsSelected() ) // First time this line is tested 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 else // second time (or more) this line is tested
addinlist = false; addinlist = false;
SCH_LINE* line = (SCH_LINE*) item; SCH_LINE* line = (SCH_LINE*) item;
if( line->m_Start == position ) if( line->m_Start == position )
item->m_Flags &= ~STARTPOINT; item->ClearFlags( STARTPOINT );
else if( line->m_End == position ) else if( line->m_End == position )
item->m_Flags &= ~ENDPOINT; item->ClearFlags( ENDPOINT );
} }
else else
item->m_Flags = SELECTED; item->SetFlags( SELECTED );
if( addinlist ) if( addinlist )
{ {
picker.m_PickerFlags = item->m_Flags; picker.m_PickerFlags = item->GetFlags();
m_BlockLocate.m_ItemsSelection.PushItem( picker ); m_BlockLocate.m_ItemsSelection.PushItem( picker );
} }
} }
...@@ -683,8 +770,8 @@ int SCH_SCREEN::UpdatePickList() ...@@ -683,8 +770,8 @@ int SCH_SCREEN::UpdatePickList()
// An item is picked if its bounding box intersects the reference area. // An item is picked if its bounding box intersects the reference area.
if( item->HitTest( area ) ) if( item->HitTest( area ) )
{ {
picker.m_PickedItem = item; picker.SetItem( item );
picker.m_PickedItemType = item->Type(); picker.SetItemType( item->Type() );
m_BlockLocate.PushItem( picker ); m_BlockLocate.PushItem( picker );
} }
} }
...@@ -947,3 +1034,30 @@ void SCH_SCREENS::SetDate( const wxString& aDate ) ...@@ -947,3 +1034,30 @@ void SCH_SCREENS::SetDate( const wxString& aDate )
for( size_t i = 0; i < m_screens.size(); i++ ) for( size_t i = 0; i < m_screens.size(); i++ )
m_screens[i]->m_Date = aDate; 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 );
}
}
}
...@@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -204,7 +204,7 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
if( item == NULL ) if( item == NULL )
break; break;
DeleteStruct( DrawPanel, &dc, item ); DeleteItem( item );
screen->SetCurItem( NULL ); screen->SetCurItem( NULL );
m_itemToRepeat = NULL; m_itemToRepeat = NULL;
screen->TestDanglingEnds( DrawPanel, &dc ); screen->TestDanglingEnds( DrawPanel, &dc );
......
...@@ -209,7 +209,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem, ...@@ -209,7 +209,7 @@ void SCH_EDIT_FRAME::SaveCopyInUndoList( SCH_ITEM* aItem,
if( aItem ) if( aItem )
{ {
itemWrapper.m_PickedItemType = aItem->Type(); itemWrapper.m_PickedItemType = aItem->Type();
itemWrapper.m_PickerFlags = aItem->m_Flags; itemWrapper.m_PickerFlags = aItem->GetFlags();
} }
switch( aCommandType ) switch( aCommandType )
...@@ -329,12 +329,14 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed ...@@ -329,12 +329,14 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
// complex command // complex command
for( int ii = aList->GetCount() - 1; ii >= 0; ii-- ) for( int ii = aList->GetCount() - 1; ii >= 0; ii-- )
{ {
ITEM_PICKER itemWrapper = aList->GetItemWrapper( ii ); item = (SCH_ITEM*) aList->GetPickedItem( ii );
item = (SCH_ITEM*) itemWrapper.m_PickedItem;
if( item ) if( item )
item->m_Flags = 0; item->ClearFlags();
SCH_ITEM* image = (SCH_ITEM*) itemWrapper.m_Link;
switch( itemWrapper.m_UndoRedoStatus ) SCH_ITEM* image = (SCH_ITEM*) aList->GetPickedItemLink( ii );
switch( aList->GetPickedItemStatus( ii ) )
{ {
case UR_CHANGED: /* Exchange old and new data for each item */ case UR_CHANGED: /* Exchange old and new data for each item */
SwapData( item, image ); SwapData( item, image );
...@@ -352,10 +354,10 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed ...@@ -352,10 +354,10 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
break; break;
case UR_MOVED: case UR_MOVED:
item->m_Flags = aList->GetPickerFlags( ii ); item->ClearFlags();
item->Move( aRedoCommand ? item->SetFlags( aList->GetPickerFlags( ii ) );
aList->m_TransformPoint : -aList->m_TransformPoint ); item->Move( aRedoCommand ? aList->m_TransformPoint : -aList->m_TransformPoint );
item->m_Flags = 0; item->ClearFlags();
break; break;
case UR_MIRRORED_Y: case UR_MIRRORED_Y:
...@@ -385,12 +387,13 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed ...@@ -385,12 +387,13 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
/* Exchange the current wires and the old wires */ /* Exchange the current wires and the old wires */
alt_item = GetScreen()->ExtractWires( false ); alt_item = GetScreen()->ExtractWires( false );
aList->SetPickedItem( alt_item, ii ); aList->SetPickedItem( alt_item, ii );
while( item ) while( item )
{ {
SCH_ITEM* nextitem = item->Next(); SCH_ITEM* nextitem = item->Next();
item->SetNext( GetScreen()->GetDrawItems() ); item->SetNext( GetScreen()->GetDrawItems() );
GetScreen()->SetDrawItems( item ); GetScreen()->SetDrawItems( item );
item->m_Flags = 0; item->ClearFlags();
item = nextitem; item = nextitem;
} }
...@@ -400,7 +403,7 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed ...@@ -400,7 +403,7 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed
{ {
wxString msg; wxString msg;
msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ), msg.Printf( wxT( "PutDataInPreviousState() error (unknown code %X)" ),
itemWrapper.m_UndoRedoStatus ); aList->GetPickedItemStatus( ii ) );
wxMessageBox( msg ); wxMessageBox( msg );
} }
break; break;
......
...@@ -244,36 +244,3 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC ) ...@@ -244,36 +244,3 @@ SCH_SHEET_PIN* SCH_EDIT_FRAME::Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC )
return NewSheetLabel; 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
}
...@@ -14,6 +14,7 @@ class LIB_PIN; ...@@ -14,6 +14,7 @@ class LIB_PIN;
class SCH_COMPONENT; class SCH_COMPONENT;
class SCH_SHEET_PATH; class SCH_SHEET_PATH;
class SCH_SHEET_PIN; class SCH_SHEET_PIN;
class SCH_LINE;
/* Max number of sheets in a hierarchy project: */ /* Max number of sheets in a hierarchy project: */
...@@ -94,6 +95,29 @@ public: ...@@ -94,6 +95,29 @@ public:
*/ */
int GetItems( const wxPoint& aPosition, SCH_ITEMS& aItemList ) const; 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 ) { }; void Place( SCH_EDIT_FRAME* frame, wxDC* DC ) { };
/** /**
...@@ -113,6 +137,15 @@ public: ...@@ -113,6 +137,15 @@ public:
*/ */
void RemoveFromDrawList( SCH_ITEM* aItem ); 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 ); bool CheckIfOnDrawList( SCH_ITEM* st );
void AddToDrawList( SCH_ITEM* st ); void AddToDrawList( SCH_ITEM* st );
...@@ -149,6 +182,15 @@ public: ...@@ -149,6 +182,15 @@ public:
*/ */
void ReplaceWires( SCH_ITEM* aWireList ); 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 * Function BreakSegment
* checks every wire and bus for a intersection at \a aPoint and break into two segments * checks every wire and bus for a intersection at \a aPoint and break into two segments
...@@ -227,7 +269,7 @@ public: ...@@ -227,7 +269,7 @@ public:
* @return The pin item if found, otherwise NULL. * @return The pin item if found, otherwise NULL.
*/ */
LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL, LIB_PIN* GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent = NULL,
bool aEndPointOnly = false ); bool aEndPointOnly = false ) const;
/** /**
* Function GetSheetLabel * Function GetSheetLabel
...@@ -268,6 +310,7 @@ public: ...@@ -268,6 +310,7 @@ public:
int UpdatePickList(); int UpdatePickList();
virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_ITEM*) aItem ); } virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_ITEM*) aItem ); }
virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem ) virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem )
{ {
BASE_SCREEN::InsertItem( aIter, (EDA_ITEM*) aItem ); BASE_SCREEN::InsertItem( aIter, (EDA_ITEM*) aItem );
...@@ -323,9 +366,17 @@ public: ...@@ -323,9 +366,17 @@ public:
*/ */
void SetDate( const wxString& aDate ); 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: private:
void AddScreenToList( SCH_SCREEN* aScreen ); void AddScreenToList( SCH_SCREEN* aScreen );
void BuildScreenList( EDA_ITEM* aItem ); void BuildScreenList( EDA_ITEM* aItem );
}; };
#endif /* CLASS_SCREEN_H */ #endif /* CLASS_SCREEN_H */
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* This program source code file is part of KICAD, a free EDA CAD application. * 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) 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. * Copyright (C) 2009 Kicad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -28,18 +29,22 @@ ...@@ -28,18 +29,22 @@
#include "base_struct.h" #include "base_struct.h"
class PICKED_ITEMS_LIST;
/** /**
* Undo Redo considerations: * Undo Redo considerations:
* Basically we have 3 cases * Basically we have 3 cases
* New item * New item
* Deleted item * Deleted item
* Modified 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. * 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 * When an item is deleted or added (new item) the pointer points the item, and there is
* no other copy. * no other copy.
* However, because there are some commands that concern a lot of items * 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 * so a copy of old items is not necessary. They are block command
* Move block * Move block
* Rotate block * Rotate block
...@@ -47,12 +52,14 @@ ...@@ -47,12 +52,14 @@
* and they are undo/redo by the same command * and they are undo/redo by the same command
*/ */
/* Type of undo/redo operations /* 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 { enum UndoRedoOpType {
UR_UNSPECIFIED = 0, // illegal 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_NEW, // new item, undo by changing in deleted
UR_DELETED, // deleted item, undo by changing in deleted UR_DELETED, // deleted item, undo by changing in deleted
UR_MOVED, // moved item, undo by move it UR_MOVED, // moved item, undo by move it
...@@ -62,43 +69,58 @@ enum UndoRedoOpType { ...@@ -62,43 +69,58 @@ enum UndoRedoOpType {
UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it UR_ROTATED_CLOCKWISE, // Rotated item (clockwise), undo by rotating it
UR_FLIPPED, // flipped (board items only), undo by flipping it UR_FLIPPED, // flipped (board items only), undo by flipping it
UR_WIRE_IMAGE, // Specific to eeschema: handle wires changes 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_MODEDIT, // Specific to the module editor (modedit creates a full copy of
UR_LIBEDIT // Specific to the component editor (libedit creates a full copy of the current component when changed) // 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 class ITEM_PICKER
{ {
friend class PICKED_ITEMS_LIST;
public: public:
UndoRedoOpType m_UndoRedoStatus; /* type of operation to undo/redo for this item */ 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), EDA_ITEM* m_PickedItem; /* Pointer on the schematic or board item that is concerned
* or in undo redo commands, the copy of an edited item. * (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 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 */ 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 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, * used when a duplicate exists i.e. when an item is
* and the copy of initial item exists (the duplicate) * modified, and the copy of initial item exists (the
* m_Item points the duplicate (i.e the old copy of an active item) * duplicate) m_Item points the duplicate (i.e the old
* and m_Link points the active item in schematic * 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 ); 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. * is a holder to handle information on schematic or board items.
* The information held is a pointer on each item, and the command made. * The information held is a pointer on each item, and the command made.
*/ */
class PICKED_ITEMS_LIST class PICKED_ITEMS_LIST
{ {
public: public:
UndoRedoOpType m_Status; /* info about operation to undo/redo for this item. can be UR_UNSPECIFIED */ UndoRedoOpType m_Status; /* info about operation to undo/redo for this item. can be
wxPoint m_TransformPoint; /* used to undo redo command by the same command: * UR_UNSPECIFIED */
* we usually need to know the rotate point or the move vector wxPoint m_TransformPoint; /* used to undo redo command by the same command: usually
*/ * need to know the rotate point or the move vector */
private: private:
std::vector <ITEM_PICKER> m_ItemsList; std::vector <ITEM_PICKER> m_ItemsList;
...@@ -106,150 +128,158 @@ public: ...@@ -106,150 +128,158 @@ public:
PICKED_ITEMS_LIST(); PICKED_ITEMS_LIST();
~PICKED_ITEMS_LIST(); ~PICKED_ITEMS_LIST();
/** PushItem /**
* push a picker to the top of the list * Function PushItem
* @param aItem = picker to push * pushes \a aItem to the top of the list
* @param aItem Picker to push on to the list.
*/ */
void PushItem( ITEM_PICKER& aItem ); void PushItem( ITEM_PICKER& aItem );
/** PopItem /**
* @return the picker from the top of the list * Function PopItem
* the picker is removed from the list * @return The picker removed from the top of the list.
*/ */
ITEM_PICKER PopItem(); ITEM_PICKER PopItem();
/**
* Function IsItemInList
* @return True if \a aItem is found in the pick list.
*/
bool ContainsItem( EDA_ITEM* aItem ) const;
/** /**
* Function ClearItemsList * 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(); void ClearItemsList();
/** /**
* Function ClearListAndDeleteItems * Function ClearListAndDeleteItems
* delete the list of pickers, AND the data pointed * deletes the list of pickers, AND the data pointed by m_PickedItem or
* by m_PickedItem or m_PickedItemLink, according to the type of undo/redo command recorded * m_PickedItemLink, according to the type of undo/redo command recorded
*/ */
void ClearListAndDeleteItems(); void ClearListAndDeleteItems();
/** /**
* Function GetCount * Function GetCount
* @return the count of pickers stored in this list * @return The count of pickers stored in this list.
*/ */
unsigned GetCount() const unsigned GetCount() const
{ {
return m_ItemsList.size(); return m_ItemsList.size();
} }
/** /**
* Function ReversePickersListOrder * Function ReversePickersListOrder
* reverses the order of pickers stored in this list * reverses the order of pickers stored in this list.
* Useful when pop a list from Undo to Redo (and vice-versa) * <p>
* because sometimes undo (or redo) a command needs to keep the * This is useful when pop a list from Undo to Redo (and vice-versa) because
* order of successive changes. * sometimes undo (or redo) a command needs to keep the order of successive
* and obviously, undo and redo are in reverse order * changes. Obviously, undo and redo are in reverse order
*/ */
void ReversePickersListOrder(); void ReversePickersListOrder();
/** /**
* Function GetItemWrapper * Function GetItemWrapper
* @return the picker of a picked item * @return The picker of a picked item.
* @param aIdx = index of the picker in the picked list * @param aIdx Index of the picker in the picked list
* if this picker does not exist, a picker is returned, * if this picker does not exist, a picker is returned,
* with its members set to 0 or NULL * with its members set to 0 or NULL
*/ */
ITEM_PICKER GetItemWrapper( unsigned int aIdx ); ITEM_PICKER GetItemWrapper( unsigned int aIdx );
/** /**
* Function GetPickedItem * Function GetPickedItem
* @return a pointer to the picked item * @return A pointer to the picked item
* @param aIdx = index of the picked item in the picked list * @param aIdx Index of the picked item in the picked list
*/ */
EDA_ITEM* GetPickedItem( unsigned int aIdx ); EDA_ITEM* GetPickedItem( unsigned int aIdx );
/** /**
* Function GetPickedItemLink * Function GetPickedItemLink
* @return link of the picked item, or null if does not exist * @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 ); EDA_ITEM* GetPickedItemLink( unsigned int aIdx );
/** /**
* Function GetPickedItemStatus * 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 * 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 ); UndoRedoOpType GetPickedItemStatus( unsigned int aIdx );
/** /**
* Function GetPickerFlags * Function GetPickerFlags
* return the value of the picker flag * returns the value of the picker flag.
* @param aIdx = index of the picker in the picked list * @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 * @return The value stored in the picker, if the picker exists, or 0 if does not exist
*/ */
int GetPickerFlags( unsigned aIdx ); int GetPickerFlags( unsigned aIdx );
/** /**
* Function SetPickedItem * Function SetPickedItem
* @param aItem = a pointer to the item to pick * @param aItem A pointer to the item to pick
* @param aIdx = index of the picker in the picked list * @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 SetPickedItem( EDA_ITEM* aItem, unsigned aIdx ); bool SetPickedItem( EDA_ITEM* aItem, unsigned aIdx );
/** /**
* Function SetPickedItem * Function SetPickedItem
* @param aItem = a pointer to the item to pick * @param aItem A pointer to the item to pick
* @param aStatus = the type of undo/redo operation associated 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 * @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 SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx ); bool SetPickedItem( EDA_ITEM* aItem, UndoRedoOpType aStatus, unsigned aIdx );
/** /**
* Function SetPickedItemLink * 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 aLink = the link to the item associated to the picked item
* @param aIdx = index of the picker in the picked list * @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 ); bool SetPickedItemLink( EDA_ITEM* aLink, unsigned aIdx );
/** /**
* Function SetPickedItemStatus * Function SetPickedItemStatus
* Set the type of undo/redo operation for a given picked item * 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 aStatus The type of undo/redo operation associated to the picked item
* @param aIdx = index of the picker in the picked list * @param aIdx Index of the picker in the picked list
* @return true if the picker exists, or false if does not exist * @return True if the picker exists or false if does not exist
*/ */
bool SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx ); bool SetPickedItemStatus( UndoRedoOpType aStatus, unsigned aIdx );
/** /**
* Function SetPickerFlags * Function SetPickerFlags
* Set the flags of the picker (usually to the picked item m_Flags value) * set the flags of the picker (usually to the picked item m_Flags value)
* @param aFlags = the value to save in picker * @param aFlags The flag value to save in picker
* @param aIdx = index of the picker in the picked list * @param aIdx Index of the picker in the picked list
* @return true if the picker exists, or false if does not exist * @return True if the picker exists or false if does not exist
*/ */
bool SetPickerFlags( int aFlags, unsigned aIdx ); bool SetPickerFlags( int aFlags, unsigned aIdx );
/** /**
* Function RemovePicker * Function RemovePicker
* remove one entry (one picker) from the list of picked items * removes one entry (one picker) from the list of picked items.
* @param aIdx = index of the picker in the picked list * @param aIdx Index of the picker in the picked list
* @return true if ok, or false if did not exist * @return True if ok or false if did not exist
*/ */
bool RemovePicker( unsigned aIdx ); bool RemovePicker( unsigned aIdx );
/** /**
* Function CopyList * Function CopyList
* copy all data from aSource * copies all data from aSource to the list.
* Items picked are not copied. just pointer on them are copied * 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 ); void CopyList( const PICKED_ITEMS_LIST& aSource );
}; };
/** /**
* Class UNDO_REDO_CONTAINER * Class UNDO_REDO_CONTAINER
* is a holder to handle alist of undo (or redo) command. * is a holder to handle alist of undo (or redo) command.
...@@ -258,15 +288,18 @@ public: ...@@ -258,15 +288,18 @@ public:
class UNDO_REDO_CONTAINER class UNDO_REDO_CONTAINER
{ {
public: public:
std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands std::vector <PICKED_ITEMS_LIST*> m_CommandsList; // the list of possible undo/redo commands
public: public:
UNDO_REDO_CONTAINER(); UNDO_REDO_CONTAINER();
~UNDO_REDO_CONTAINER(); ~UNDO_REDO_CONTAINER();
void PushCommand( PICKED_ITEMS_LIST* aCommand );
void PushCommand( PICKED_ITEMS_LIST* aCommand );
PICKED_ITEMS_LIST* PopCommand(); PICKED_ITEMS_LIST* PopCommand();
void ClearCommandList();
void ClearCommandList();
}; };
......
...@@ -123,7 +123,6 @@ public: ...@@ -123,7 +123,6 @@ public:
*/ */
static wxString GetDefaultFieldName( int aFieldNdx ); static wxString GetDefaultFieldName( int aFieldNdx );
/** /**
* Function AddTemplateFieldName * Function AddTemplateFieldName
* inserts or appends a wanted symbol field name into the fieldnames * inserts or appends a wanted symbol field name into the fieldnames
...@@ -208,6 +207,26 @@ public: ...@@ -208,6 +207,26 @@ public:
SCH_ITEM* LocateAndShowItem( const wxPoint& aPosition, bool aIncludePin = true ); SCH_ITEM* LocateAndShowItem( const wxPoint& aPosition, bool aIncludePin = true );
SCH_ITEM* LocateItem( const wxPoint& aPosition, bool aIncludePin ); 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 * Function FillFootprintFieldForAllInstancesofComponent
* searches for component "aReference", and places a Footprint in * searches for component "aReference", and places a Footprint in
...@@ -508,8 +527,12 @@ private: ...@@ -508,8 +527,12 @@ private:
SCH_SHEET_PIN* Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC ); SCH_SHEET_PIN* Import_PinSheet( SCH_SHEET* Sheet, wxDC* DC );
public: 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; } int GetLabelIncrement() const { return m_repeatLabelDelta; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment