From 0d8789935d8204301b800c1db0005fbecf8a89ee Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 31 Oct 2020 00:25:46 +0000 Subject: [PATCH] Refactoring. Push editing code to toolset. --- eeschema/sch_edit_frame.h | 15 ------- eeschema/sheet.cpp | 58 --------------------------- eeschema/tools/sch_drawing_tools.cpp | 60 +++++++++++++++++++++++++++- eeschema/tools/sch_drawing_tools.h | 19 +++++---- 4 files changed, 70 insertions(+), 82 deletions(-) diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 2d8384e45c..92c5c271e1 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -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 * diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index a1f8fcadd1..ca122e3649 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include @@ -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( 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; diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 81524c255c..1b45917512 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -47,9 +47,11 @@ #include #include #include +#include SCH_DRAWING_TOOLS::SCH_DRAWING_TOOLS() : EE_TOOL_BASE( "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( 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: diff --git a/eeschema/tools/sch_drawing_tools.h b/eeschema/tools/sch_drawing_tools.h index 517a0a0021..d51797fe13 100644 --- a/eeschema/tools/sch_drawing_tools.h +++ b/eeschema/tools/sch_drawing_tools.h @@ -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 m_symbolHistoryList; - std::vector m_powerHistoryList; + std::vector m_symbolHistoryList; + std::vector 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 m_statusPopup; + std::unique_ptr m_statusPopup; }; #endif /* SCH_DRAWING_TOOLS_H */