From dc9882c3b99cfd7f86a9852dc53c5641f85c3cf3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 12 Mar 2020 13:56:44 +0000 Subject: [PATCH] Fix a few bugs with Sheet field dragging and rotating. Fixes https://gitlab.com/kicad/code/kicad/issues/4046 --- .../dialogs/dialog_schematic_find_base.cpp | 117 +++-- .../dialogs/dialog_schematic_find_base.fbp | 497 ++---------------- eeschema/dialogs/dialog_schematic_find_base.h | 23 +- eeschema/sch_base_frame.cpp | 2 + eeschema/sch_edit_frame.h | 2 +- eeschema/sch_field.cpp | 173 +++--- eeschema/sheet.cpp | 4 +- eeschema/tools/sch_drawing_tools.cpp | 2 +- eeschema/tools/sch_edit_tool.cpp | 9 +- 9 files changed, 223 insertions(+), 606 deletions(-) diff --git a/eeschema/dialogs/dialog_schematic_find_base.cpp b/eeschema/dialogs/dialog_schematic_find_base.cpp index 027666894a..aca5d8ab04 100644 --- a/eeschema/dialogs/dialog_schematic_find_base.cpp +++ b/eeschema/dialogs/dialog_schematic_find_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -12,136 +12,137 @@ DIALOG_SCH_FIND_BASE::DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); - + wxBoxSizer* mainSizer; mainSizer = new wxBoxSizer( wxVERTICAL ); - + wxBoxSizer* topSizer; topSizer = new wxBoxSizer( wxHORIZONTAL ); - + wxBoxSizer* leftSizer; leftSizer = new wxBoxSizer( wxVERTICAL ); - + wxFlexGridSizer* leftGridSizer; leftGridSizer = new wxFlexGridSizer( 3, 2, 3, 3 ); leftGridSizer->AddGrowableCol( 1 ); leftGridSizer->SetFlexibleDirection( wxBOTH ); leftGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); - + m_staticText1 = new wxStaticText( this, wxID_ANY, _("&Search for:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText1->Wrap( -1 ); leftGridSizer->Add( m_staticText1, 0, wxALIGN_CENTER_VERTICAL, 6 ); - - m_comboFind = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxTE_PROCESS_ENTER ); + + m_comboFind = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_DROPDOWN|wxTE_PROCESS_ENTER ); m_comboFind->SetToolTip( _("Text with optional wildcards") ); m_comboFind->SetMinSize( wxSize( 220,-1 ) ); - + leftGridSizer->Add( m_comboFind, 0, wxEXPAND, 6 ); - + m_staticReplace = new wxStaticText( this, wxID_ANY, _("Replace &with:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticReplace->Wrap( -1 ); m_staticReplace->Hide(); - + leftGridSizer->Add( m_staticReplace, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); - - m_comboReplace = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER ); + + m_comboReplace = new wxComboBox( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER ); m_comboReplace->Hide(); - + leftGridSizer->Add( m_comboReplace, 0, wxEXPAND, 5 ); - + m_staticDirection = new wxStaticText( this, wxID_ANY, _("Direction:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticDirection->Wrap( -1 ); m_staticDirection->Hide(); - + leftGridSizer->Add( m_staticDirection, 0, 0, 5 ); - + wxBoxSizer* directionSizer; directionSizer = new wxBoxSizer( wxVERTICAL ); - + m_radioForward = new wxRadioButton( this, wxID_ANY, _("F&orward"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP ); m_radioForward->Hide(); - + directionSizer->Add( m_radioForward, 0, wxALL, 3 ); - + m_radioBackward = new wxRadioButton( this, wxID_ANY, _("&Backward"), wxDefaultPosition, wxDefaultSize, 0 ); m_radioBackward->Hide(); - + directionSizer->Add( m_radioBackward, 0, wxALL, 3 ); - - + + leftGridSizer->Add( directionSizer, 1, wxEXPAND, 5 ); - - + + leftSizer->Add( leftGridSizer, 0, wxALL|wxEXPAND, 5 ); - + wxGridBagSizer* gbSizer2; gbSizer2 = new wxGridBagSizer( 0, 20 ); gbSizer2->SetFlexibleDirection( wxHORIZONTAL ); gbSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_NONE ); - + m_checkMatchCase = new wxCheckBox( this, wxID_ANY, _("&Match case"), wxDefaultPosition, wxDefaultSize, 0 ); gbSizer2->Add( m_checkMatchCase, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); - + m_checkWholeWord = new wxCheckBox( this, wxID_ANY, _("Words"), wxDefaultPosition, wxDefaultSize, 0 ); - m_checkWholeWord->SetValue(true); + m_checkWholeWord->SetValue(true); gbSizer2->Add( m_checkWholeWord, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); - + m_checkWildcardMatch = new wxCheckBox( this, wxID_ANY, _("Wildcards"), wxDefaultPosition, wxDefaultSize, 0 ); gbSizer2->Add( m_checkWildcardMatch, wxGBPosition( 0, 2 ), wxGBSpan( 1, 1 ), wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); - - m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search all com&ponent fields"), wxDefaultPosition, wxDefaultSize, 0 ); + + m_checkAllFields = new wxCheckBox( this, wxID_ANY, _("Search user-defined fields"), wxDefaultPosition, wxDefaultSize, 0 ); gbSizer2->Add( m_checkAllFields, wxGBPosition( 1, 0 ), wxGBSpan( 1, 3 ), wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search all pin &names and numbers"), wxDefaultPosition, wxDefaultSize, 0 ); + + m_checkAllPins = new wxCheckBox( this, wxID_ANY, _("Search pin &names and numbers"), wxDefaultPosition, wxDefaultSize, 0 ); gbSizer2->Add( m_checkAllPins, wxGBPosition( 2, 0 ), wxGBSpan( 1, 3 ), wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_checkCurrentSheetOnly = new wxCheckBox( this, wxID_ANY, _("Search the current &sheet only"), wxDefaultPosition, wxDefaultSize, 0 ); gbSizer2->Add( m_checkCurrentSheetOnly, wxGBPosition( 3, 0 ), wxGBSpan( 1, 3 ), wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - + m_checkReplaceReferences = new wxCheckBox( this, wxID_ANY, _("Replace componen&t reference designators"), wxDefaultPosition, wxDefaultSize, 0 ); m_checkReplaceReferences->Hide(); - + gbSizer2->Add( m_checkReplaceReferences, wxGBPosition( 4, 0 ), wxGBSpan( 1, 3 ), wxBOTTOM|wxRIGHT|wxLEFT, 5 ); - - + + leftSizer->Add( gbSizer2, 1, wxEXPAND, 5 ); - - + + topSizer->Add( leftSizer, 1, wxEXPAND|wxALL, 5 ); - + wxBoxSizer* rightSizer; rightSizer = new wxBoxSizer( wxVERTICAL ); - + m_buttonFind = new wxButton( this, wxID_FIND, _("&Find"), wxDefaultPosition, wxDefaultSize, 0 ); - m_buttonFind->SetDefault(); + + m_buttonFind->SetDefault(); rightSizer->Add( m_buttonFind, 0, wxALL|wxEXPAND, 6 ); - + m_buttonReplace = new wxButton( this, wxID_REPLACE, _("&Replace"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonReplace->Hide(); - + rightSizer->Add( m_buttonReplace, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 6 ); - + m_buttonReplaceAll = new wxButton( this, wxID_REPLACE_ALL, _("Replace &All"), wxDefaultPosition, wxDefaultSize, 0 ); m_buttonReplaceAll->Hide(); - + rightSizer->Add( m_buttonReplaceAll, 0, wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT, 6 ); - + m_buttonCancel = new wxButton( this, wxID_CANCEL, _("Close"), wxDefaultPosition, wxDefaultSize, 0 ); rightSizer->Add( m_buttonCancel, 0, wxBOTTOM|wxLEFT|wxRIGHT|wxEXPAND, 6 ); - - + + topSizer->Add( rightSizer, 0, wxALL|wxEXPAND, 6 ); - - + + mainSizer->Add( topSizer, 1, wxEXPAND, 5 ); - - + + this->SetSizer( mainSizer ); this->Layout(); mainSizer->Fit( this ); - + this->Centre( wxBOTH ); - + // Connect Events this->Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( DIALOG_SCH_FIND_BASE::OnClose ) ); m_comboFind->Connect( wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler( DIALOG_SCH_FIND_BASE::OnSearchForText ), NULL, this ); @@ -184,5 +185,5 @@ DIALOG_SCH_FIND_BASE::~DIALOG_SCH_FIND_BASE() m_buttonReplaceAll->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_FIND_BASE::OnReplace ), NULL, this ); m_buttonReplaceAll->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SCH_FIND_BASE::OnUpdateReplaceAllUI ), NULL, this ); m_buttonCancel->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SCH_FIND_BASE::OnCancel ), NULL, this ); - + } diff --git a/eeschema/dialogs/dialog_schematic_find_base.fbp b/eeschema/dialogs/dialog_schematic_find_base.fbp index 740bba0c70..4403e4af4e 100644 --- a/eeschema/dialogs/dialog_schematic_find_base.fbp +++ b/eeschema/dialogs/dialog_schematic_find_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_schematic_find_base 1000 none + 1 dialog_sch_find @@ -52,42 +53,7 @@ - - - - - - - - - OnClose - - - - - - - - - - - - - - - - - - - - - - - - - - mainSizer @@ -160,6 +126,7 @@ 0 wxID_ANY &Search for: + 0 0 @@ -185,29 +152,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -273,31 +217,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - OnSearchForText OnTextEnter OnUpdateDrcUI @@ -336,6 +255,7 @@ 1 wxID_ANY Replace &with: + 0 0 @@ -361,29 +281,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -449,32 +346,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - OnTextEnter OnUpdateDrcUI @@ -512,6 +383,7 @@ 1 wxID_ANY Direction: + 0 0 @@ -537,29 +409,6 @@ -1 - - - - - - - - - - - - - - - - - - - - - - - @@ -633,30 +482,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -721,30 +546,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -831,30 +632,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -922,30 +700,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -1013,30 +768,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -1075,7 +807,7 @@ 0 0 wxID_ANY - Search all com&ponent fields + Search user-defined fields 0 @@ -1104,30 +836,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -1166,7 +875,7 @@ 0 0 wxID_ANY - Search all pin &names and numbers + Search pin &names and numbers 0 @@ -1195,30 +904,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -1286,30 +972,7 @@ - OnOptions - - - - - - - - - - - - - - - - - - - - - - @@ -1377,30 +1040,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -1431,25 +1070,31 @@ + 1 0 1 1 + 1 0 + Dock 0 Left 1 1 + 0 0 wxID_FIND &Find + + 0 0 @@ -1464,6 +1109,8 @@ protected 1 + + Resizable 1 @@ -1479,29 +1126,6 @@ OnFind - - - - - - - - - - - - - - - - - - - - - - - @@ -1519,25 +1143,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 1 wxID_REPLACE &Replace + + 0 0 @@ -1552,6 +1182,8 @@ protected 1 + + Resizable 1 @@ -1567,28 +1199,6 @@ OnReplace - - - - - - - - - - - - - - - - - - - - - - OnUpdateReplaceUI @@ -1607,25 +1217,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 1 wxID_REPLACE_ALL Replace &All + + 0 0 @@ -1640,6 +1256,8 @@ protected 1 + + Resizable 1 @@ -1655,28 +1273,6 @@ OnReplace - - - - - - - - - - - - - - - - - - - - - - OnUpdateReplaceAllUI @@ -1695,25 +1291,31 @@ + 1 0 1 1 + 0 0 + Dock 0 Left 1 1 + 0 0 wxID_CANCEL Close + + 0 0 @@ -1728,6 +1330,8 @@ protected 1 + + Resizable 1 @@ -1743,29 +1347,6 @@ OnCancel - - - - - - - - - - - - - - - - - - - - - - - diff --git a/eeschema/dialogs/dialog_schematic_find_base.h b/eeschema/dialogs/dialog_schematic_find_base.h index 3cc6a7b904..aeea732218 100644 --- a/eeschema/dialogs/dialog_schematic_find_base.h +++ b/eeschema/dialogs/dialog_schematic_find_base.h @@ -1,12 +1,11 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 30 2017) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! /////////////////////////////////////////////////////////////////////////// -#ifndef __DIALOG_SCHEMATIC_FIND_BASE_H__ -#define __DIALOG_SCHEMATIC_FIND_BASE_H__ +#pragma once #include #include @@ -23,6 +22,9 @@ #include #include #include +#include +#include +#include #include #include @@ -35,7 +37,7 @@ class DIALOG_SCH_FIND_BASE : public DIALOG_SHIM { private: - + protected: wxStaticText* m_staticText1; wxComboBox* m_comboFind; @@ -55,7 +57,7 @@ class DIALOG_SCH_FIND_BASE : public DIALOG_SHIM wxButton* m_buttonReplace; wxButton* m_buttonReplaceAll; wxButton* m_buttonCancel; - + // Virtual event handlers, overide them in your derived class virtual void OnClose( wxCloseEvent& event ) { event.Skip(); } virtual void OnSearchForText( wxCommandEvent& event ) { event.Skip(); } @@ -67,13 +69,12 @@ class DIALOG_SCH_FIND_BASE : public DIALOG_SHIM virtual void OnUpdateReplaceUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnUpdateReplaceAllUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnCancel( wxCommandEvent& event ) { event.Skip(); } - - + + public: - - DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Find"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + DIALOG_SCH_FIND_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Find"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); ~DIALOG_SCH_FIND_BASE(); - + }; -#endif //__DIALOG_SCHEMATIC_FIND_BASE_H__ diff --git a/eeschema/sch_base_frame.cpp b/eeschema/sch_base_frame.cpp index 8e08aba676..55383fb776 100644 --- a/eeschema/sch_base_frame.cpp +++ b/eeschema/sch_base_frame.cpp @@ -370,6 +370,8 @@ void SCH_BASE_FRAME::RefreshItem( EDA_ITEM* aItem, bool isAddOrDelete ) // Component children are drawn from their parents. Mark them for re-paint. if( parent && parent->Type() == SCH_COMPONENT_T ) GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT ); + else if( parent && parent->Type() == SCH_SHEET_T ) + GetCanvas()->GetView()->Update( parent, KIGFX::REPAINT ); } GetCanvas()->Refresh(); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 3fce7b8c29..9dede208e6 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -807,7 +807,7 @@ public: * it can happens when the edited sheet used an existying file, or becomes a new instance * of a already existing sheet. */ - bool EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, bool* aClearAnnotationNewItems ); + bool EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, bool* aClearAnnotationNewItems ); void InitSheet( SCH_SHEET* aSheet, const wxString& aNewFilename ); diff --git a/eeschema/sch_field.cpp b/eeschema/sch_field.cpp index 56a4efdb54..731a908548 100644 --- a/eeschema/sch_field.cpp +++ b/eeschema/sch_field.cpp @@ -80,19 +80,23 @@ const wxString SCH_FIELD::GetFullyQualifiedText() const // Note that the IDs of FIELDS and SHEETS overlap, so one must check *both* the // id and the parent's type. - if( m_id == REFERENCE && m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) + if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { - // For more than one part per package, we must add the part selection - // A, B, ... or 1, 2, .. to the reference. SCH_COMPONENT* component = static_cast( m_Parent ); - if( component->GetUnitCount() > 1 ) - text << LIB_PART::SubReference( component->GetUnit() ); + if( m_id == REFERENCE ) + { + // For more than one part per package, we must add the part selection + // A, B, ... or 1, 2, .. to the reference. + if( component->GetUnitCount() > 1 ) + text << LIB_PART::SubReference( component->GetUnit() ); + } } - if( m_id == SHEETFILENAME && m_Parent && m_Parent->Type() == SCH_SHEET_T ) + if( m_Parent && m_Parent->Type() == SCH_SHEET_T ) { - text = _( "File: " ) + text; + if( m_id == SHEETFILENAME ) + text = _( "File: " ) + text; } return text; @@ -122,7 +126,6 @@ void SCH_FIELD::Print( wxDC* aDC, const wxPoint& aOffset ) int orient; COLOR4D color; wxPoint textpos; - SCH_COMPONENT* parentComponent = dynamic_cast( m_Parent ); int lineWidth = GetThickness(); if( lineWidth == 0 ) // Use default values for pen size @@ -142,12 +145,17 @@ void SCH_FIELD::Print( wxDC* aDC, const wxPoint& aOffset ) // Calculate the text orientation according to the component orientation. orient = GetTextAngle(); - if( parentComponent && parentComponent->GetTransform().y1 ) // Rotate component 90 degrees. + if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { - if( orient == TEXT_ANGLE_HORIZ ) - orient = TEXT_ANGLE_VERT; - else - orient = TEXT_ANGLE_HORIZ; + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + + if( parentComponent && parentComponent->GetTransform().y1 ) // Rotate component 90 degrees. + { + if( orient == TEXT_ANGLE_HORIZ ) + orient = TEXT_ANGLE_VERT; + else + orient = TEXT_ANGLE_HORIZ; + } } /* Calculate the text justification, according to the component @@ -221,12 +229,13 @@ const EDA_RECT SCH_FIELD::GetBoundingBox() const if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + // Due to the Y axis direction, we must mirror the bounding box, // relative to the text position: MIRROR( begin.y, pos.y ); MIRROR( end.y, pos.y ); - SCH_COMPONENT* parentComponent = static_cast( m_Parent ); transform = parentComponent->GetTransform(); } else @@ -271,31 +280,37 @@ bool SCH_FIELD::Matches( wxFindReplaceData& aSearchData, void* aAuxData ) { wxString text = GetFullyQualifiedText(); int flags = aSearchData.GetFlags(); - bool isReference = m_Parent && m_Parent->Type() == SCH_COMPONENT_T && m_id == REFERENCE; - bool isValue = m_Parent && m_Parent->Type() == SCH_COMPONENT_T && m_id == VALUE; + bool searchUserDefinedFields = flags & FR_SEARCH_ALL_FIELDS; + bool searchAndReplace = flags & FR_SEARCH_REPLACE; + bool replaceReferences = flags & FR_REPLACE_REFERENCES; - // User defined fields have an ID of -1. - if( !isReference && !isValue && !( flags & FR_SEARCH_ALL_FIELDS ) ) - return false; - - if( ( flags & FR_SEARCH_REPLACE ) && isReference && !( flags & FR_REPLACE_REFERENCES ) ) - return false; - - wxLogTrace( traceFindItem, wxT( " child item " ) + wxLogTrace( traceFindItem, wxT( " child item " ) + GetSelectMenuText( EDA_UNITS::MILLIMETRES ) ); - // Take sheet path into account which effects the reference field and the unit for - // components with multiple parts. - if( isReference && aAuxData != NULL ) + if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { - SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent; + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); - wxCHECK_MSG( component != NULL, false, wxT( "No symbol associated with field" ) + text ); + if( !searchUserDefinedFields && m_id >= MANDATORY_FIELDS ) + return false; - text = component->GetRef( (SCH_SHEET_PATH*) aAuxData ); + if( searchAndReplace && m_id == REFERENCE && !replaceReferences ) + return false; - if( component->GetUnitCount() > 1 ) - text << LIB_PART::SubReference( component->GetUnit() ); + // Take sheet path into account which effects the reference field and the unit for + // components with multiple parts. + if( m_id == REFERENCE && aAuxData != NULL ) + { + text = parentComponent->GetRef( (SCH_SHEET_PATH*) aAuxData ); + + if( parentComponent->GetUnitCount() > 1 ) + text << LIB_PART::SubReference( parentComponent->GetUnit() ); + } + } + else if( m_Parent && m_Parent->Type() == SCH_SHEET_T ) + { + if( !searchUserDefinedFields && m_id >= SHEET_MANDATORY_FIELDS ) + return false; } return SCH_ITEM::Matches( text, aSearchData ); @@ -306,9 +321,11 @@ bool SCH_FIELD::IsReplaceable() const { if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + if( m_id == VALUE ) { - LIB_PART* part = static_cast( GetParent() )->GetPartRef().get(); + LIB_PART* part = parentComponent->GetPartRef().get(); if( part && part->IsPower() ) return false; @@ -316,6 +333,7 @@ bool SCH_FIELD::IsReplaceable() const } else if( m_Parent && m_Parent->Type() == SCH_SHEET_T ) { + // See comments in SCH_FIELD::Replace(), below. if( m_id == SHEETFILENAME ) return false; } @@ -326,36 +344,42 @@ bool SCH_FIELD::IsReplaceable() const bool SCH_FIELD::Replace( wxFindReplaceData& aSearchData, void* aAuxData ) { - bool isReplaced = false; - wxString text = GetFullyQualifiedText(); + bool isReplaced = false; if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T && m_id == REFERENCE ) { - wxCHECK_MSG( aAuxData != NULL, false, - wxT( "Cannot replace reference designator without valid sheet path." ) ); + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); - wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false, - wxT( "Invalid replace symbol reference field call." ) ) ; + if( m_id == REFERENCE ) + { + wxCHECK_MSG( aAuxData != NULL, false, + wxT( "Cannot replace reference designator without valid sheet path." ) ); - SCH_COMPONENT* component = (SCH_COMPONENT*) m_Parent; + wxCHECK_MSG( aSearchData.GetFlags() & FR_REPLACE_REFERENCES, false, + wxT( "Invalid replace symbol reference field call." ) ) ; - text = component->GetRef( (SCH_SHEET_PATH*) aAuxData ); + wxString text = parentComponent->GetRef( (SCH_SHEET_PATH*) aAuxData ); - // if( component->GetUnitCount() > 1 ) - // text << LIB_PART::SubReference( component->GetUnit() ); + isReplaced = EDA_ITEM::Replace( aSearchData, text ); - isReplaced = EDA_ITEM::Replace( aSearchData, text ); - - if( isReplaced ) - component->SetRef( (SCH_SHEET_PATH*) aAuxData, text ); + if( isReplaced ) + parentComponent->SetRef( (SCH_SHEET_PATH*) aAuxData, text ); + } + else + { + isReplaced = EDA_TEXT::Replace( aSearchData ); + } } - else if( m_Parent && m_Parent->Type() == SCH_SHEET_T && m_id == SHEETFILENAME ) - { - // This is likely too dangerous to allow.... - } - else + else if( m_Parent && m_Parent->Type() == SCH_SHEET_T ) { isReplaced = EDA_TEXT::Replace( aSearchData ); + + if( m_id == SHEETFILENAME && isReplaced ) + { + // If we allowed this we'd have a bunch of work to do here, including warning + // about it not being undoable, checking for recursive hierarchies, reloading + // sheets, etc. See DIALOG_SCH_SHEET_PROPS::TransferDataFromWindow(). + } } return isReplaced; @@ -442,11 +466,6 @@ bool SCH_FIELD::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) void SCH_FIELD::Plot( PLOTTER* aPlotter ) { - SCH_COMPONENT* parent = ( SCH_COMPONENT* ) GetParent(); - - wxCHECK_RET( parent != NULL && parent->Type() == SCH_COMPONENT_T, - wxT( "Cannot plot field with invalid parent." ) ); - COLOR4D color = aPlotter->ColorSettings()->GetColor( GetLayer() ); if( !IsVisible() ) @@ -459,12 +478,17 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter ) * orientation/mirror */ int orient = GetTextAngle(); - if( parent->GetTransform().y1 ) // Rotate component 90 deg. + if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { - if( orient == TEXT_ANGLE_HORIZ ) - orient = TEXT_ANGLE_VERT; - else - orient = TEXT_ANGLE_HORIZ; + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + + if( parentComponent->GetTransform().y1 ) // Rotate component 90 deg. + { + if( orient == TEXT_ANGLE_HORIZ ) + orient = TEXT_ANGLE_VERT; + else + orient = TEXT_ANGLE_HORIZ; + } } /* Calculate the text justification, according to the component @@ -493,29 +517,36 @@ void SCH_FIELD::Plot( PLOTTER* aPlotter ) void SCH_FIELD::SetPosition( const wxPoint& aPosition ) { - wxPoint pos = GetParentPosition(); - // Actual positions are calculated by the rotation/mirror transform of the // parent component of the field. The inverse transform is used to calculate // the position relative to the parent component. if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) { - SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent(); - wxPoint pt = aPosition - pos; + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + wxPoint relativePos = aPosition - parentComponent->GetPosition(); - pos += component->GetTransform().InverseTransform().TransformCoordinate( pt ); + parentComponent->GetTransform().InverseTransform().TransformCoordinate( relativePos ); + + SetTextPos( relativePos + parentComponent->GetPosition() ); } - SetTextPos( pos ); + SetTextPos( aPosition ); } wxPoint SCH_FIELD::GetPosition() const { - SCH_COMPONENT* component = (SCH_COMPONENT*) GetParent(); - wxPoint pos = GetTextPos() - component->GetPosition(); + if( m_Parent && m_Parent->Type() == SCH_COMPONENT_T ) + { + SCH_COMPONENT* parentComponent = static_cast( m_Parent ); + wxPoint relativePos = GetTextPos() - parentComponent->GetPosition(); - return component->GetTransform().TransformCoordinate( pos ) + component->GetPosition(); + parentComponent->GetTransform().TransformCoordinate( relativePos ); + + return relativePos + parentComponent->GetPosition(); + } + + return GetTextPos(); } diff --git a/eeschema/sheet.cpp b/eeschema/sheet.cpp index a935816a86..113ebea7ea 100644 --- a/eeschema/sheet.cpp +++ b/eeschema/sheet.cpp @@ -476,8 +476,8 @@ bool SCH_EDIT_FRAME::LoadSheetFromFile( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHier } -bool SCH_EDIT_FRAME::EditSheet( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, - bool* aClearAnnotationNewItems ) +bool SCH_EDIT_FRAME::EditSheetProperties( SCH_SHEET* aSheet, SCH_SHEET_PATH* aHierarchy, + bool* aClearAnnotationNewItems ) { if( aSheet == NULL || aHierarchy == NULL ) return false; diff --git a/eeschema/tools/sch_drawing_tools.cpp b/eeschema/tools/sch_drawing_tools.cpp index 4ebe96d8e5..fa05bb284e 100644 --- a/eeschema/tools/sch_drawing_tools.cpp +++ b/eeschema/tools/sch_drawing_tools.cpp @@ -848,7 +848,7 @@ int SCH_DRAWING_TOOLS::DrawSheet( const TOOL_EVENT& aEvent ) getViewControls()->SetAutoPan( false ); getViewControls()->CaptureCursor( false ); - if( m_frame->EditSheet( (SCH_SHEET*)sheet, g_CurrentSheet, nullptr ) ) + if( m_frame->EditSheetProperties((SCH_SHEET*) sheet, g_CurrentSheet, nullptr ) ) { sheet->AutoplaceFields( /* aScreen */ NULL, /* aManual */ false ); diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 7992ce47cd..f26592382b 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1224,12 +1224,13 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) case SCH_SHEET_T: { - bool doClearAnnotation; - bool doRefresh = false; + SCH_SHEET* sheet = static_cast( item ); + bool doClearAnnotation; + bool doRefresh = false; // Keep track of existing sheet paths. EditSheet() can modify this list SCH_SHEET_LIST initial_sheetpathList( g_RootSheet ); - doRefresh = m_frame->EditSheet( (SCH_SHEET*) item, g_CurrentSheet, &doClearAnnotation ); + doRefresh = m_frame->EditSheetProperties( sheet, g_CurrentSheet, &doClearAnnotation ); if( doClearAnnotation ) // happens when the current sheet load a existing file { // we must clear "new" components annotation @@ -1239,7 +1240,7 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent ) // Clear annotation of g_CurrentSheet itself, because its sheetpath // is not a new path, but components managed by its sheet path must have // their annotation cleared, because they are new: - ((SCH_SHEET*) item)->GetScreen()->ClearAnnotation( g_CurrentSheet ); + sheet->GetScreen()->ClearAnnotation( g_CurrentSheet ); } if( doRefresh )