Refactoring. Push editing code to toolset.

This commit is contained in:
Jeff Young 2020-10-31 00:25:46 +00:00
parent 7e7ef82f55
commit 0d8789935d
4 changed files with 70 additions and 82 deletions

View File

@ -736,21 +736,6 @@ public:
bool LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy,
const wxString& aFileName );
/**
* Create a new SCH_SHEET_PIN object and add it to \a aSheet at the current cursor position.
*
* @param aSheet The sheet to add the new sheet pin to.
* @return The new sheet pin object created or NULL if the task was aborted by the user.
*/
SCH_SHEET_PIN* CreateSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel );
/**
* Import a hierarchical label with no attached sheet pin.
*
* @param aSheet The sheet to import the new sheet pin to.
*/
SCH_HIERLABEL* ImportHierLabel( SCH_SHEET* aSheet );
/**
* Removes a given junction and heals any wire segments under the junction
*

View File

@ -38,7 +38,6 @@
#include <schematic.h>
#include <symbol_lib_table.h>
#include <dialogs/dialog_sheet_properties.h>
#include <dialogs/dialog_sheet_pin_properties.h>
#include <tool/actions.h>
@ -476,63 +475,6 @@ bool SCH_EDIT_FRAME::EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHi
}
PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = PINSHEETLABEL_SHAPE::PS_INPUT;
SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel )
{
SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
wxString text;
SCH_SHEET_PIN* sheetPin;
if( aLabel )
{
text = aLabel->GetText();
m_lastSheetPinType = aLabel->GetShape();
}
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), text );
sheetPin->SetFlags( IS_NEW );
sheetPin->SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
sheetPin->SetShape( m_lastSheetPinType );
if( !aLabel )
{
DIALOG_SHEET_PIN_PROPERTIES dlg( this, sheetPin );
if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() )
{
delete sheetPin;
return nullptr;
}
}
m_lastSheetPinType = sheetPin->GetShape();
sheetPin->SetPosition( (wxPoint) GetCanvas()->GetViewControls()->GetCursorPosition() );
return sheetPin;
}
SCH_HIERLABEL* SCH_EDIT_FRAME::ImportHierLabel( SCH_SHEET* aSheet )
{
if( !aSheet->GetScreen() )
return nullptr;
for( auto item : aSheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
{
auto label = static_cast<SCH_HIERLABEL*>( item );
/* A global label has been found: check if there a corresponding sheet label. */
if( !aSheet->HasPin( label->GetText() ) )
return label;
}
return nullptr;
}
void SCH_EDIT_FRAME::DrawCurrentSheetToClipboard()
{
wxRect DrawArea;

View File

@ -47,9 +47,11 @@
#include <dialogs/dialog_edit_label.h>
#include <dialogs/dialog_edit_line_style.h>
#include <dialogs/dialog_junction_props.h>
#include <dialogs/dialog_sheet_pin_properties.h>
SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() :
EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveDrawing" ),
m_lastSheetPinType( PINSHEETLABEL_SHAPE::PS_INPUT ),
m_lastGlobalLabelShape( PINSHEETLABEL_SHAPE::PS_INPUT ),
m_lastTextOrientation( LABEL_SPIN_STYLE::LEFT ),
m_lastTextBold( false ),
@ -722,6 +724,60 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
}
SCH_HIERLABEL* SCH_DRAWING_TOOLS::importHierLabel( SCH_SHEET* aSheet )
{
if( !aSheet->GetScreen() )
return nullptr;
for( EDA_ITEM* item : aSheet->GetScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
{
SCH_HIERLABEL* label = static_cast<SCH_HIERLABEL*>( item );
/* A global label has been found: check if there a corresponding sheet label. */
if( !aSheet->HasPin( label->GetText() ) )
return label;
}
return nullptr;
}
SCH_SHEET_PIN* SCH_DRAWING_TOOLS::createSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel )
{
SCHEMATIC_SETTINGS& settings = aSheet->Schematic()->Settings();
wxString text;
SCH_SHEET_PIN* sheetPin;
if( aLabel )
{
text = aLabel->GetText();
m_lastSheetPinType = aLabel->GetShape();
}
sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), text );
sheetPin->SetFlags( IS_NEW );
sheetPin->SetTextSize( wxSize( settings.m_DefaultTextSize, settings.m_DefaultTextSize ) );
sheetPin->SetShape( m_lastSheetPinType );
if( !aLabel )
{
DIALOG_SHEET_PIN_PROPERTIES dlg( m_frame, sheetPin );
if( dlg.ShowModal() != wxID_OK || sheetPin->GetText().IsEmpty() )
{
delete sheetPin;
return nullptr;
}
}
m_lastSheetPinType = sheetPin->GetShape();
sheetPin->SetPosition( (wxPoint) getViewControls()->GetCursorPosition() );
return sheetPin;
}
int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
{
EDA_ITEM* item = nullptr;
@ -849,7 +905,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
if( isImportMode )
{
label = m_frame->ImportHierLabel( sheet );
label = importHierLabel( sheet );
if( !label )
{
@ -861,7 +917,7 @@ int SCH_DRAWING_TOOLS::TwoClickPlace( const TOOL_EVENT& aEvent )
}
}
item = m_frame->CreateSheetPin( sheet, label );
item = createSheetPin( sheet, label );
break;
}
default:

View File

@ -65,6 +65,10 @@ private:
*/
SCH_TEXT* createNewText( const VECTOR2I& aPosition, int aType );
SCH_HIERLABEL* importHierLabel( SCH_SHEET* aSheet );
SCH_SHEET_PIN* createSheetPin( SCH_SHEET* aSheet, SCH_HIERLABEL* aLabel );
void sizeSheet( SCH_SHEET* aSheet, VECTOR2I aPos );
///> Sets up handlers for various events.
@ -72,15 +76,16 @@ private:
private:
// History lists for PlaceComponent()
std::vector<COMPONENT_SELECTION> m_symbolHistoryList;
std::vector<COMPONENT_SELECTION> m_powerHistoryList;
std::vector<COMPONENT_SELECTION> m_symbolHistoryList;
std::vector<COMPONENT_SELECTION> m_powerHistoryList;
PINSHEETLABEL_SHAPE m_lastGlobalLabelShape;
LABEL_SPIN_STYLE m_lastTextOrientation;
bool m_lastTextBold;
bool m_lastTextItalic;
PINSHEETLABEL_SHAPE m_lastSheetPinType;
PINSHEETLABEL_SHAPE m_lastGlobalLabelShape;
LABEL_SPIN_STYLE m_lastTextOrientation;
bool m_lastTextBold;
bool m_lastTextItalic;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
std::unique_ptr<STATUS_TEXT_POPUP> m_statusPopup;
};
#endif /* SCH_DRAWING_TOOLS_H */