Add drag context menu entry for junctions in EESchema, fixes lp:783173.

* Add drag context menu entry for junctions that actually form a junction
  with wires to EESchema.
* Add function to test for junctions to SCH_COLLECTOR class.
* Create annotate type and sort order enums to eliminate magic numbers
  used in annotate code.
* Remove duplicate Doxygen comments from annotate.cpp and improve the
  actual Doxygen comments in wxEeschemaStruct.h.
This commit is contained in:
Wayne Stambaugh 2011-05-20 15:21:09 -04:00
parent f81c237d43
commit 6b7ab76199
9 changed files with 167 additions and 123 deletions

View File

@ -20,12 +20,6 @@
#include "lib_pin.h" #include "lib_pin.h"
/**
* Function DeleteAnnotation
* Remove current component annotations
* @param aCurrentSheetOnly : if false: remove all annotations, else remove
* annotation relative to the current sheet only
*/
void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly ) void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
{ {
if( aCurrentSheetOnly ) if( aCurrentSheetOnly )
@ -45,36 +39,11 @@ void SCH_EDIT_FRAME::DeleteAnnotation( bool aCurrentSheetOnly )
} }
/** void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
* Function AnnotateComponents: ANNOTATE_ORDER_T aSortOption,
* ANNOTATE_OPTION_T aAlgoOption,
* Compute the annotation of the components for the whole project, or the bool aResetAnnotation,
* current sheet only. All the components or the new ones only will be bool aRepairTimestamps )
* annotated.
* @param aAnnotateSchematic : true = entire schematic annotation,
* false = current sheet only
* @param aSortOption : 0 = annotate by sorting X position,
* 1 = annotate by sorting Y position,
* 2 = annotate by sorting value
* @param aAlgoOption : 0 = annotate schematic using first free Id number
* 1 = annotate using first free Id number, starting to sheet number * 100
* 2 = annotate using first free Id number, starting to sheet number * 1000
* @param aResetAnnotation : true = remove previous annotation
* false = annotate new components only
* @param aRepairsTimestamps : true = test for duplicate times stamps and
* replace duplicated
* Note: this option could change previous annotation, because time
* stamps are used to handle annotation mainly in complex
* hierarchies.
* When the sheet number is used in annotation,
* for each sheet annotation starts from sheet number * 100
* ( the first sheet uses 100 to 199, the second 200 to 299 ... )
*/
void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
int aSortOption,
int aAlgoOption,
bool aResetAnnotation,
bool aRepairsTimestamps )
{ {
SCH_REFERENCE_LIST references; SCH_REFERENCE_LIST references;
@ -82,13 +51,13 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
SCH_SCREENS screens; SCH_SCREENS screens;
/* Build the sheet list */ // Build the sheet list.
SCH_SHEET_LIST sheets; SCH_SHEET_LIST sheets;
// Test for and replace duplicate time stamps in components and sheets. Duplicate // Test for and replace duplicate time stamps in components and sheets. Duplicate
// time stamps can happen with old schematics, schematic conversions, or manual // time stamps can happen with old schematics, schematic conversions, or manual
// editing of files. // editing of files.
if( aRepairsTimestamps ) if( aRepairTimestamps )
{ {
int count = screens.ReplaceDuplicateTimeStamps(); int count = screens.ReplaceDuplicateTimeStamps();
@ -127,11 +96,11 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
switch( aSortOption ) switch( aSortOption )
{ {
default: default:
case 0: case SORT_BY_X_POSITION:
references.SortByXCoordinate(); references.SortByXCoordinate();
break; break;
case 1: case SORT_BY_Y_POSITION:
references.SortByYCoordinate(); references.SortByYCoordinate();
break; break;
} }
@ -142,14 +111,14 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
switch( aAlgoOption ) switch( aAlgoOption )
{ {
default: default:
case 0: case INCREMENTAL_BY_REF:
break; break;
case 1: case SHEET_NUMBER_X_100:
useSheetNum = true; useSheetNum = true;
break; break;
case 2: case SHEET_NUMBER_X_1000:
useSheetNum = true; useSheetNum = true;
idStep = 1000; idStep = 1000;
break; break;
@ -161,7 +130,7 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
wxArrayString errors; wxArrayString errors;
/* Final control (just in case ... )*/ // Final control (just in case ... ).
if( CheckAnnotate( &errors, !aAnnotateSchematic ) ) if( CheckAnnotate( &errors, !aAnnotateSchematic ) )
{ {
wxString msg; wxString msg;
@ -185,19 +154,6 @@ void SCH_EDIT_FRAME::AnnotateComponents( bool aAnnotateSchematic,
} }
/**
* Function CheckAnnotate
* Check errors relatives to annotation:
* components not annotated
* components having the same reference (duplicates)
* for multiple parts per package components :
* part number > number of parts
* different values between parts
* @param aMessageList = a wxArrayString to store messages.
* @param aOneSheetOnly : true = search is made only in the current sheet
* false = search in whole hierarchy (usual search).
* @return errors count
*/
int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly ) int SCH_EDIT_FRAME::CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly )
{ {
/* build the screen list */ /* build the screen list */

View File

@ -118,7 +118,8 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF
switch( aHotKeyCommandId ) switch( aHotKeyCommandId )
{ {
case HK_DRAG: case HK_DRAG:
if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false ) ) if( m_collectedItems.IsCorner() || m_collectedItems.IsNode( false )
|| m_collectedItems.IsDraggableJunction() )
{ {
item = m_collectedItems[0]; item = m_collectedItems[0];
GetScreen()->SetCurItem( item ); GetScreen()->SetCurItem( item );

View File

@ -135,7 +135,8 @@ void DIALOG_ANNOTATE::OnApplyClick( wxCommandEvent& event )
if (response == wxCANCEL) if (response == wxCANCEL)
return; return;
m_Parent->AnnotateComponents( GetLevel(), GetSortOrder(), GetAnnotateAlgo(), m_Parent->AnnotateComponents( GetLevel(), (ANNOTATE_ORDER_T) GetSortOrder(),
(ANNOTATE_OPTION_T) GetAnnotateAlgo(),
GetResetItems() , true ); GetResetItems() , true );
m_Parent->DrawPanel->Refresh(); m_Parent->DrawPanel->Refresh();

View File

@ -696,6 +696,7 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
case SCH_BUS_ENTRY_T: case SCH_BUS_ENTRY_T:
case SCH_LINE_T: case SCH_LINE_T:
case SCH_JUNCTION_T:
if( ((SCH_ITEM*) aItem )->GetLayer() != LAYER_BUS ) if( ((SCH_ITEM*) aItem )->GetLayer() != LAYER_BUS )
{ {
cmd.SetId( ID_POPUP_SCH_DRAG_WIRE_REQUEST ); cmd.SetId( ID_POPUP_SCH_DRAG_WIRE_REQUEST );
@ -711,7 +712,6 @@ void SCH_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition,
break; break;
case HK_MOVE_COMPONENT_OR_ITEM: // Start move component or other schematic item case HK_MOVE_COMPONENT_OR_ITEM: // Start move component or other schematic item
if( itemInEdit ) if( itemInEdit )
break; break;

View File

@ -40,7 +40,6 @@ static void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel );
static void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* GLabel ); static void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* GLabel );
static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ); static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field ); static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field );
static void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAME* frame );
static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame ); static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame );
@ -118,7 +117,7 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
break; break;
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
AddMenusForJunction( PopMenu, (SCH_JUNCTION*) item, this ); addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
break; break;
case SCH_BUS_ENTRY_T: case SCH_BUS_ENTRY_T:
@ -465,25 +464,27 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text )
} }
void AddMenusForJunction( wxMenu* PopMenu, SCH_JUNCTION* Junction, SCH_EDIT_FRAME* frame ) void SCH_EDIT_FRAME::addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction )
{ {
bool is_new = Junction->IsNew();
SCH_SCREEN* screen = frame->GetScreen();
wxString msg; wxString msg;
SCH_SCREEN* screen = GetScreen();
if( !is_new )
{
if( screen->GetWire( screen->GetCrossHairPosition(), EXCLUDE_END_POINTS_T ) )
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( aMenu, ID_POPUP_SCH_DELETE, msg, delete_xpm );
if( screen->GetWireOrBus( screen->GetCrossHairPosition() ) ) if( !aJunction->IsNew() )
{ {
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm ); if( m_collectedItems.IsDraggableJunction() )
ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ), ADD_MENUITEM( aMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, _( "Drag Junction" ), move_xpm );
if( screen->GetWire( aJunction->m_Pos, EXCLUDE_END_POINTS_T ) )
ADD_MENUITEM( aMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm );
}
if( screen->GetWireOrBus( aJunction->m_Pos ) )
{
ADD_MENUITEM( aMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm );
ADD_MENUITEM( aMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( "Delete Connection" ),
delete_connection_xpm ); delete_connection_xpm );
} }
} }

View File

@ -254,3 +254,44 @@ bool SCH_COLLECTOR::IsNode( bool aIncludePins ) const
return true; return true;
} }
bool SCH_COLLECTOR::IsDraggableJunction() const
{
int wireEndCount = 0;
int wireMidPoint = 0;
int junctionCount = 0;
for( size_t i = 0; i < m_List.size(); i++ )
{
SCH_ITEM* item = (SCH_ITEM*) m_List[ i ];
KICAD_T type = item->Type();
if( type == SCH_JUNCTION_T )
{
junctionCount++;
continue;
}
if( type == SCH_LINE_T )
{
if( item->GetLayer() != LAYER_WIRE )
return false;
SCH_LINE* line = (SCH_LINE*) item;
if( line->IsEndPoint( m_RefPos ) )
wireEndCount++;
else
wireMidPoint++;
continue;
}
// Any other item types indicate that this collection is not a draggable junction.
return false;
}
return (wireEndCount >= 3) || ((wireEndCount >= 1) && (wireMidPoint == 1))
|| ((wireMidPoint >= 2) && (junctionCount == 1));
}

View File

@ -148,6 +148,21 @@ public:
* @return True if the collected items form a node. * @return True if the collected items form a node.
*/ */
bool IsNode( bool aIncludePins = true ) const; bool IsNode( bool aIncludePins = true ) const;
/**
* Function IsDraggableJunction
* tests to see if the collected items form a draggable junction.
* <p>
* Daggable juntions are defined as:
* <ul>
* <li> The intersection of three or more wire end points. </li>
* <li> The intersection of one or more wire end point and one wire mid point. </li>
* <li> The crossing of two or more wire mid points and a junction. </li>
* </ul>
* </p>
* @return True if the collection is a draggable junction.
*/
bool IsDraggableJunction() const;
}; };

View File

@ -193,7 +193,7 @@ public:
* @param aPosition The position of the first connection object in drawing units. * @param aPosition The position of the first connection object in drawing units.
* @param aList The pick list to add the connect item to. * @param aList The pick list to add the connect item to.
* @param aFullConnection If true all the objects that make up this connection are * @param aFullConnection If true all the objects that make up this connection are
* add to \aList. Otherwise, only the objects up to the first * add to \a aList. Otherwise, only the objects up to the first
* node are added. * node are added.
* @return The number of items added to \a aList. * @return The number of items added to \a aList.
*/ */

View File

@ -52,6 +52,25 @@ enum fl_rot_cmp {
}; };
/** Schematic annotation order options. */
enum ANNOTATE_ORDER_T {
SORT_BY_X_POSITION, ///< Annotate by X position from left to right.
SORT_BY_Y_POSITION, ///< Annotate by Y position from top to bottom.
UNSORTED, ///< Annotate by position of component in the schematic sheet
///< object list.
};
/** Schematic annotation type options. */
enum ANNOTATE_OPTION_T {
INCREMENTAL_BY_REF, ///< Annotate incrementally using the first free reference number.
SHEET_NUMBER_X_100, ///< Annotate using the first free reference number starting at
///< the sheet number * 100.
SHEET_NUMBER_X_1000, ///< Annotate using the first free reference number starting at
///< the sheet number * 1000.
};
/** /**
* Schematic editor (EESchema) main window. * Schematic editor (EESchema) main window.
*/ */
@ -207,7 +226,7 @@ public:
/** /**
* Function LocateAndShowItem * Function LocateAndShowItem
* checks the schematic at \a aPosition in logical (drawing) units for a item * checks the schematic at \a aPosition in logical (drawing) units for a item
* matching \a aFilterList and \a aGuide. * matching the types in \a aFilterList.
* <p> * <p>
* The search is first performed at the nearest grid position to \a aPosition. If no * The search is first performed at the nearest grid position to \a aPosition. If no
* item if found on grid, then \a aPosition is tested for any items. If the item found * item if found on grid, then \a aPosition is tested for any items. If the item found
@ -226,7 +245,7 @@ public:
/** /**
* Function LocateItem * Function LocateItem
* checks for items at \a aPosition matching \a aFilter. * checks for items at \a aPosition matching the types in \a aFilterList.
* <p> * <p>
* If multiple items are located at \a aPosition, a context menu is displayed to clarify * If multiple items are located at \a aPosition, a context menu is displayed to clarify
* which item the user intended to select. If the user aborts the context menu, NULL is * which item the user intended to select. If the user aborts the context menu, NULL is
@ -303,40 +322,58 @@ public:
/** /**
* Function DeleteAnnotation * Function DeleteAnnotation
* Remove current component annotations * clears the current component annotation.
* @param aCurrentSheetOnly : if false: remove all annotations, else * @param aCurrentSheetOnly Clear the entire schematic annotation if true. Otherwise
* remove annotation relative to the current * only clear the annotation for the current sheet.
* sheet only
*/ */
void DeleteAnnotation( bool aCurrentSheetOnly ); void DeleteAnnotation( bool aCurrentSheetOnly );
/** /**
* Function AnnotateComponents: * Function AnnotateComponents
* *
* Compute the annotation of the components for the whole project, or the * annotates the components in the schematic that are not currently annotated.
* current sheet only. All the components or the new ones only will be *
* annotated. * @param aAnnotateSchematic Annotate the entire schematic if true. Otherwise annotate
* @param aAnnotateSchematic : true = entire schematic annotation, * the current sheet only.
* false = current sheet only * @param aSortOption Define the annotation order. See #ANNOTATE_ORDER_T.
* @param aSortOption : 0 = annotate by sorting X position, * @param aAlgoOption Define the annotation style. See #ANNOTATE_OPTION_T.
* 1 = annotate by sorting Y position, * @param aResetAnnotation Clear any previous annotation if true. Otherwise, keep the
* 2 = annotate by sorting value * existing component annotation.
* @param aAlgoOption : 0 = annotate schematic using first free Id number * @param aRepairTimestamps Test for and repair any duplicate time stamps if true.
* 1 = annotate using first free Id number, starting to sheet number * 100 * Otherwise, keep the existing time stamps. This option
* 2 = annotate using first free Id number, starting to sheet number * 1000 * could change previous annotation because time stamps are
* @param aResetAnnotation : true = remove previous annotation * used to handle annotation in complex hierarchies.
* false = annotate new components only *
* @param aRepairsTimestamps : true = test for duplicate times stamps and * When the sheet number is used in annotation, each sheet annotation starts from sheet
* replace duplicated * number * 100. In other words the first sheet uses 100 to 199, the second sheet uses
* Note: this option could change previous annotation, because time * 200 to 299, and so on.
* stamps are used to handle annotation mainly in complex
* hierarchies.
* When the sheet number is used in annotation,
* for each sheet annotation starts from sheet number * 100
* ( the first sheet uses 100 to 199, the second 200 to 299 ... )
*/ */
void AnnotateComponents( bool aAnnotateSchematic, int aSortOption, int aAlgoOption, void AnnotateComponents( bool aAnnotateSchematic, ANNOTATE_ORDER_T aSortOption,
bool aResetAnnotation, bool aRepairsTimestamps ); ANNOTATE_OPTION_T aAlgoOption, bool aResetAnnotation,
bool aRepairTimestamps );
/**
* Function CheckAnnotate
* checks for annotation errors.
*
* <p>
* The following list of items are checked:
* <ul>
* <li> Components that are not annotated.
* <li> Duplicate component references.
* <li> Multiple part per package components where the part\n
* number is greater number of parts in the package.
* <li> Multiple part per package components where the reference\n
* designator is different between parts.
* </ul>
* </p>
*
* @return Number of annotation errors found.
* @param aMessageList A wxArrayString to store error messages.
* @param aOneSheetOnly Check the current sheet only if true. Otherwise check
* the entire schematic.
*/
int CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly );
// Functions used for hierarchy handling // Functions used for hierarchy handling
/** /**
@ -690,6 +727,14 @@ private:
*/ */
void copyBlockItems( PICKED_ITEMS_LIST& aItemsList ); void copyBlockItems( PICKED_ITEMS_LIST& aItemsList );
/**
* Function addJunctionMenuEntries
* adds the context menu items to \a aMenu for \a aJunction.
* @params aMenu The menu to add the items to.
* @params aJunction The SCH_JUNCTION object selected.
*/
void addJunctionMenuEntries( wxMenu* aMenu, SCH_JUNCTION* aJunction );
public: public:
void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct ); void Key( wxDC* DC, int hotkey, EDA_ITEM* DrawStruct );
@ -756,22 +801,6 @@ public:
// ERC: // ERC:
/**
* Function CheckAnnotate
* Check errors relatives to annotation:
* components not annotated
* components having the same reference (duplicates)
* for multiple parts per package components :
* part number > number of parts
* different values between parts
* @return errors count
* @param aMessageList = a wxArrayString to store messages. If NULL,
* they are displayed in a wxMessageBox
* @param aOneSheetOnly : true = search is made only in the current sheet
* false = search in whole hierarchy (usual search).
*/
int CheckAnnotate( wxArrayString* aMessageList, bool aOneSheetOnly );
/** /**
* Load component libraries defined in project file. * Load component libraries defined in project file.
*/ */