diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 1069f49b2b..56e89c8aa9 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -238,6 +238,7 @@ set( EESCHEMA_SRCS toolbars_lib_view.cpp toolbars_sch_editor.cpp transform.cpp + sch_iref.cpp netlist_exporters/netlist_exporter.cpp netlist_exporters/netlist_exporter_cadstar.cpp diff --git a/eeschema/default_values.h b/eeschema/default_values.h index 7c087fb261..4dd3202498 100644 --- a/eeschema/default_values.h +++ b/eeschema/default_values.h @@ -66,4 +66,10 @@ ///< The offset of the pin name string from the end of the pin in mils. #define DEFAULT_PIN_NAME_OFFSET 20 +///< The intersheets references prefix string +#define DEFAULT_IREF_PREFIX "[" + +///< The intersheets references suffix string +#define DEFAULT_IREF_SUFFIX "]" + #endif diff --git a/eeschema/dialogs/dialog_edit_label.cpp b/eeschema/dialogs/dialog_edit_label.cpp index c8520823e4..768c2dfed6 100644 --- a/eeschema/dialogs/dialog_edit_label.cpp +++ b/eeschema/dialogs/dialog_edit_label.cpp @@ -40,6 +40,7 @@ #include #include #include +#include class SCH_EDIT_FRAME; class SCH_TEXT; @@ -345,6 +346,19 @@ bool DIALOG_LABEL_EDITOR::TransferDataFromWindow() m_Parent->GetCanvas()->Refresh(); m_Parent->OnModify(); + if( m_CurrentText->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( m_CurrentText ); + SCH_IREF* iref = label->GetIref(); + + if( iref ) + { + if( iref->GetBoundingBox().Intersects( label->GetBoundingBox() ) ) + iref->PlaceAtDefaultPosition(); + iref->CopyParentStyle(); + } + } + return true; } diff --git a/eeschema/dialogs/panel_setup_formatting.cpp b/eeschema/dialogs/panel_setup_formatting.cpp index e785d8b889..aadd319dbb 100644 --- a/eeschema/dialogs/panel_setup_formatting.cpp +++ b/eeschema/dialogs/panel_setup_formatting.cpp @@ -71,6 +71,12 @@ bool PANEL_SETUP_FORMATTING::TransferDataToWindow() m_pinSymbolSize.SetValue( settings.m_PinSymbolSize ); m_junctionSize.SetValue( settings.m_JunctionSize ); + m_showIntersheetsReferences->SetValue( settings.m_IntersheetsRefShow ); + m_radioFormatStandard->SetValue( !settings.m_IntersheetsRefFormatShort ); + m_radioFormatAbbreviated->SetValue( settings.m_IntersheetsRefFormatShort ); + m_prefixCtrl->ChangeValue( settings.m_IntersheetsRefPrefix ); + m_suffixCtrl->ChangeValue( settings.m_IntersheetsRefSuffix ); + wxString offsetRatio = wxString::Format( "%f", settings.m_TextOffsetRatio * 100.0 ); m_textOffsetRatioCtrl->SetValue( offsetRatio ); @@ -108,6 +114,11 @@ bool PANEL_SETUP_FORMATTING::TransferDataFromWindow() settings.m_PinSymbolSize = (int) m_pinSymbolSize.GetValue(); settings.m_JunctionSize = (int) m_junctionSize.GetValue(); + settings.m_IntersheetsRefShow = m_showIntersheetsReferences->GetValue(); + settings.m_IntersheetsRefFormatShort = !m_radioFormatStandard->GetValue(); + settings.m_IntersheetsRefPrefix = m_prefixCtrl->GetValue(); + settings.m_IntersheetsRefSuffix = m_suffixCtrl->GetValue(); + double dtmp = 0.0; wxString msg = m_textOffsetRatioCtrl->GetValue(); msg.ToDouble( &dtmp ); @@ -133,6 +144,12 @@ void PANEL_SETUP_FORMATTING::ImportSettingsFrom( SCHEMATIC_SETTINGS& aSettings ) m_pinSymbolSize.SetValue( aSettings.m_PinSymbolSize ); m_junctionSize.SetValue( aSettings.m_JunctionSize ); + m_showIntersheetsReferences->SetValue( aSettings.m_IntersheetsRefShow ); + m_radioFormatStandard->SetValue( aSettings.m_IntersheetsRefFormatShort ); + m_radioFormatAbbreviated->SetValue( !aSettings.m_IntersheetsRefFormatShort ); + m_prefixCtrl->ChangeValue( aSettings.m_IntersheetsRefPrefix ); + m_suffixCtrl->ChangeValue( aSettings.m_IntersheetsRefSuffix ); + wxString offsetRatio = wxString::Format( "%f", aSettings.m_TextOffsetRatio * 100.0 ); m_textOffsetRatioCtrl->SetValue( offsetRatio ); } diff --git a/eeschema/dialogs/panel_setup_formatting_base.cpp b/eeschema/dialogs/panel_setup_formatting_base.cpp index d1e281198d..a21369cd2c 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.cpp +++ b/eeschema/dialogs/panel_setup_formatting_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.9.0 Sep 17 2020) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -147,16 +147,51 @@ PANEL_SETUP_FORMATTING_BASE::PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWi wxBoxSizer* bRightColumn; bRightColumn = new wxBoxSizer( wxVERTICAL ); + wxStaticBoxSizer* sbSizerIREf; + sbSizerIREf = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Intersheets References") ), wxVERTICAL ); + + m_showIntersheetsReferences = new wxCheckBox( sbSizerIREf->GetStaticBox(), wxID_ANY, _("Show intersheets references"), wxDefaultPosition, wxDefaultSize, 0 ); + sbSizerIREf->Add( m_showIntersheetsReferences, 0, wxALL, 5 ); + + m_radioFormatStandard = new wxRadioButton( sbSizerIREf->GetStaticBox(), wxID_ANY, _("Standard (1,2,3)"), wxDefaultPosition, wxDefaultSize, 0 ); + m_radioFormatStandard->SetValue( true ); + sbSizerIREf->Add( m_radioFormatStandard, 0, wxALL, 5 ); + + m_radioFormatAbbreviated = new wxRadioButton( sbSizerIREf->GetStaticBox(), wxID_ANY, _("Abbreviated (1..3)"), wxDefaultPosition, wxDefaultSize, 0 ); + sbSizerIREf->Add( m_radioFormatAbbreviated, 0, wxALL, 5 ); + + wxGridSizer* gSizer1; + gSizer1 = new wxGridSizer( 0, 2, 0, 0 ); + + m_prefixLabel = new wxStaticText( sbSizerIREf->GetStaticBox(), wxID_ANY, _("Prefix"), wxDefaultPosition, wxDefaultSize, 0 ); + m_prefixLabel->Wrap( -1 ); + gSizer1->Add( m_prefixLabel, 0, wxALL, 5 ); + + m_prefixCtrl = new wxTextCtrl( sbSizerIREf->GetStaticBox(), wxID_ANY, _("["), wxDefaultPosition, wxDefaultSize, 0 ); + gSizer1->Add( m_prefixCtrl, 0, wxALL, 5 ); + + m_suffixLabel = new wxStaticText( sbSizerIREf->GetStaticBox(), wxID_ANY, _("Suffix"), wxDefaultPosition, wxDefaultSize, 0 ); + m_suffixLabel->Wrap( -1 ); + gSizer1->Add( m_suffixLabel, 0, wxALL, 5 ); + + m_suffixCtrl = new wxTextCtrl( sbSizerIREf->GetStaticBox(), wxID_ANY, _("]"), wxDefaultPosition, wxDefaultSize, 0 ); + gSizer1->Add( m_suffixCtrl, 0, wxALL, 5 ); + + + sbSizerIREf->Add( gSizer1, 1, wxEXPAND, 5 ); + + + bRightColumn->Add( sbSizerIREf, 0, wxALL|wxEXPAND, 5 ); + bRightColumn->Add( 0, 0, 0, wxEXPAND, 5 ); - bPanelSizer->Add( bRightColumn, 1, wxEXPAND, 5 ); + bPanelSizer->Add( bRightColumn, 1, wxLEFT|wxTOP, 10 ); this->SetSizer( bPanelSizer ); this->Layout(); - bPanelSizer->Fit( this ); } PANEL_SETUP_FORMATTING_BASE::~PANEL_SETUP_FORMATTING_BASE() diff --git a/eeschema/dialogs/panel_setup_formatting_base.fbp b/eeschema/dialogs/panel_setup_formatting_base.fbp index 328f184e31..252f03d34b 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.fbp +++ b/eeschema/dialogs/panel_setup_formatting_base.fbp @@ -14,6 +14,7 @@ panel_setup_formatting_base 1000 none + 1 PanelSetupFormatting @@ -25,6 +26,7 @@ 1 1 UI + 0 1 0 @@ -43,7 +45,7 @@ PANEL_SETUP_FORMATTING_BASE - -1,-1 + 633,418 ; forward_declare @@ -1242,14 +1244,484 @@ - 5 - wxEXPAND + 10 + wxLEFT|wxTOP 1 bRightColumn wxVERTICAL none + + 5 + wxALL|wxEXPAND + 0 + + wxID_ANY + Intersheets References + + sbSizerIREf + wxVERTICAL + 1 + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Show intersheets references + + 0 + + + 0 + + 1 + m_showIntersheetsReferences + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Standard (1,2,3) + + 0 + + + 0 + + 1 + m_radioFormatStandard + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 1 + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Abbreviated (1..3) + + 0 + + + 0 + + 1 + m_radioFormatAbbreviated + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + 0 + + + + + + + 5 + wxEXPAND + 1 + + 2 + 0 + + gSizer1 + none + 0 + 0 + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Prefix + 0 + + 0 + + + 0 + + 1 + m_prefixLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_prefixCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + [ + + + + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Suffix + 0 + + 0 + + + 0 + + 1 + m_suffixLabel + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + + + -1 + + + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + + 0 + + 1 + m_suffixCtrl + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + ] + + + + + + + + + 5 wxEXPAND diff --git a/eeschema/dialogs/panel_setup_formatting_base.h b/eeschema/dialogs/panel_setup_formatting_base.h index d92e9560da..93e7e448dd 100644 --- a/eeschema/dialogs/panel_setup_formatting_base.h +++ b/eeschema/dialogs/panel_setup_formatting_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.9.0 Sep 17 2020) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include /////////////////////////////////////////////////////////////////////////// @@ -49,10 +51,17 @@ class PANEL_SETUP_FORMATTING_BASE : public wxPanel wxStaticText* m_jctSizeLabel; wxTextCtrl* m_jctSizeCtrl; wxStaticText* m_jctSizeUnits; + wxCheckBox* m_showIntersheetsReferences; + wxRadioButton* m_radioFormatStandard; + wxRadioButton* m_radioFormatAbbreviated; + wxStaticText* m_prefixLabel; + wxTextCtrl* m_prefixCtrl; + wxStaticText* m_suffixLabel; + wxTextCtrl* m_suffixCtrl; public: - PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); + PANEL_SETUP_FORMATTING_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 633,418 ), long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString ); ~PANEL_SETUP_FORMATTING_BASE(); }; diff --git a/eeschema/eeschema_settings.cpp b/eeschema/eeschema_settings.cpp index 32610bd378..fdb7916afc 100644 --- a/eeschema/eeschema_settings.cpp +++ b/eeschema/eeschema_settings.cpp @@ -338,6 +338,7 @@ EESCHEMA_SETTINGS::EESCHEMA_SETTINGS() : m_params.emplace_back( new PARAM( "system.last_symbol_lib_dir", &m_lastSymbolLibDir, "" ) ); + } diff --git a/eeschema/eeschema_settings.h b/eeschema/eeschema_settings.h index b6ce9304f3..c67c41aee3 100644 --- a/eeschema/eeschema_settings.h +++ b/eeschema/eeschema_settings.h @@ -73,6 +73,10 @@ public: wxString field_names; bool hv_lines_only; int repeat_label_increment; + bool intersheets_ref_show; + bool intersheets_ref_short; + wxString intersheets_ref_prefix; + wxString intersheets_ref_suffix; }; struct INPUT diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index bac4555495..8604fd413a 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -59,7 +59,6 @@ #include #include - bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) { wxString msg; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index 1aa57d66e2..3813cd6025 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1132,6 +1133,7 @@ void SCH_EDIT_FRAME::UpdateTitle() void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags ) { + SCHEMATIC_SETTINGS& settings = Schematic().Settings(); SCH_SHEET_LIST list = Schematic().GetSheets(); PROF_COUNTER timer; @@ -1149,14 +1151,182 @@ void SCH_EDIT_FRAME::RecalculateConnections( SCH_CLEANUP_FLAGS aCleanupFlags ) timer.Stop(); wxLogTrace( "CONN_PROFILE", "SchematicCleanUp() %0.4f ms", timer.msecs() ); + if( settings.m_IntersheetsRefShow == true ) + RecomputeIntersheetsRefs(); + Schematic().ConnectionGraph()->Recalculate( list, true ); } +int SCH_EDIT_FRAME::RecomputeIntersheetsRefs() +{ + SCHEMATIC_SETTINGS& settings = Schematic().Settings(); + std::vector pagesNumbers; + SCH_GLOBALLABEL* gLabel; + SCH_IREF* iref; + + m_labelTable.clear(); + + SCH_SCREENS screens( Schematic().Root() ); + + /* Iterate over screens */ + for( SCH_SCREEN* screen = screens.GetFirst(); screen != NULL; screen = screens.GetNext() ) + { + + pagesNumbers.clear(); + + /* Find in which sheets this screen is used */ + for( const SCH_SHEET_PATH& sheet : Schematic().GetSheets() ) + { + + if( sheet.LastScreen() == screen ) + pagesNumbers.push_back( sheet.GetPageNumber() ); + + } + + for( SCH_ITEM* item : screen->Items() ) + { + + if( item->Type() == SCH_GLOBAL_LABEL_T ) + { + gLabel = static_cast( item ); + m_labelTable.push_back( gLabel ); + + if( gLabel->GetIref() == nullptr ) + { + iref = new SCH_IREF(); + gLabel->SetIref( iref ); + + iref->SetParent( gLabel ); + iref->SetFlags( IS_NEW ); + iref->SetScreen( screen ); + + if( gLabel->GetIrefSavedPosition() != wxDefaultPosition ) + iref->SetPosition( gLabel->GetIrefSavedPosition() ); + else + iref->PlaceAtDefaultPosition(); + + iref->CopyParentStyle(); + } + else + { + iref = gLabel->GetIref(); + } + + iref->GetRefTable()->clear(); + iref->GetRefTable()->insert( iref->GetRefTable()->end(), + pagesNumbers.begin(), + pagesNumbers.end() ); + + } + } + } + + /* Fill intersheets references for each global label */ + for( SCH_GLOBALLABEL* item : m_labelTable ) + { + for( SCH_GLOBALLABEL* iter : m_labelTable ) + { + if( iter->GetText().IsSameAs( item->GetText() ) && ( iter != item ) ) + iter->GetIref()->GetRefTable()->insert( iter->GetIref()->GetRefTable()->end(), + item->GetIref()->GetRefTable()->begin(), + item->GetIref()->GetRefTable()->end() ); + } + } + + /* Refresh all global labels */ + for( SCH_GLOBALLABEL* item : m_labelTable ) + { + wxString text, tmp; + + iref = item->GetIref(); + + sort( iref->GetRefTable()->begin(), iref->GetRefTable()->end() ); + iref->GetRefTable()->erase( unique( iref->GetRefTable()->begin(), iref->GetRefTable()->end() ), + iref->GetRefTable()->end() ); + + text.Printf( "%s", settings.m_IntersheetsRefPrefix ); + + if( ( settings.m_IntersheetsRefFormatShort ) && ( iref->GetRefTable()->size() > 2 ) ) + { + tmp.Printf( "%d..%d", iref->GetRefTable()->front(), iref->GetRefTable()->back() ); + text.Append( tmp ); + } + else + { + + for( int ref : *( iref->GetRefTable() ) ) + { + tmp.Printf( "%d,", ref ); + text.Append( tmp ); + } + + if( text.Last() == ',' ) + text.RemoveLast(); + } + + text.Append( settings.m_IntersheetsRefSuffix ); + + iref->SetText( text ); + + SCH_SCREEN* screen = iref->GetScreen(); + + if( !screen->CheckIfOnDrawList( iref ) ) + AddToScreen( iref, screen ); + + iref->ClearFlags( IS_NEW ); + + screen->SetModify(); + Refresh( iref ); + + iref->ClearEditFlags(); + GetCanvas()->Refresh(); + } + + return 0; +} + +void SCH_EDIT_FRAME::RemoveAllIntersheetsRefs() +{ + SCH_SHEET_LIST sheets = Schematic().GetSheets(); + std::vector irefList; + SCH_GLOBALLABEL* gLabel; + + SCH_SCREENS screens( Schematic().Root() ); + + for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() ) + { + + for( SCH_ITEM* item : screen->Items() ) + { + if( item->Type() == SCH_GLOBAL_LABEL_T ) + { + gLabel = (SCH_GLOBALLABEL*)( item ); + SCH_IREF* iref = gLabel->GetIref(); + + if( iref ) + { + gLabel->SetIref( nullptr ); + gLabel->SetIrefSavedPosition( wxDefaultPosition ); + irefList.push_back( iref ); + } + } + } + } + + for( SCH_IREF* iref : irefList ) + RemoveFromScreen( iref, iref->GetScreen() ); +} void SCH_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) { + SCHEMATIC_SETTINGS& settings = Schematic().Settings(); SCH_BASE_FRAME::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged ); + if( settings.m_IntersheetsRefShow == false ) + RemoveAllIntersheetsRefs(); + else + RecomputeIntersheetsRefs(); + GetCanvas()->GetView()->UpdateAllItems( KIGFX::ALL ); GetCanvas()->Refresh(); diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index be9513622d..4b1cc52ba7 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -136,6 +136,8 @@ private: static PINSHEETLABEL_SHAPE m_lastSheetPinType; ///< Last sheet pin type. + std::vector m_labelTable; + protected: /** * Save the schematic files that have been modified and not yet saved. @@ -946,6 +948,10 @@ public: */ void UpdateSymbolFromEditor( const LIB_PART& aSymbol ); + int RecomputeIntersheetsRefs(); + + void RemoveAllIntersheetsRefs(); + DECLARE_EVENT_TABLE() }; diff --git a/eeschema/sch_iref.cpp b/eeschema/sch_iref.cpp new file mode 100644 index 0000000000..08212de274 --- /dev/null +++ b/eeschema/sch_iref.cpp @@ -0,0 +1,116 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019-2020 Franck Jullien, franck.jullien at gmail.com + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include +#include +#include +#include + +SCH_IREF::SCH_IREF( const wxPoint& pos, const wxString& text, SCH_GLOBALLABEL* aParent, KICAD_T aType ) + : SCH_TEXT( pos, text, SCH_IREF_T ) + +{ + m_Layer = LAYER_GLOBLABEL; + m_parent = aParent; + SetMultilineAllowed( false ); +} + +void SCH_IREF::PlaceAtDefaultPosition() +{ + wxPoint offset; + + int labelLen = m_parent->GetBoundingBox().GetSizeMax(); + + switch( m_parent->GetLabelSpinStyle() ) + { + default: + case LABEL_SPIN_STYLE::LEFT: offset.x -= labelLen; break; + case LABEL_SPIN_STYLE::UP: offset.y -= labelLen; break; + case LABEL_SPIN_STYLE::RIGHT: offset.x += labelLen; break; + case LABEL_SPIN_STYLE::BOTTOM: offset.y += labelLen; break; + } + + SetTextPos( m_parent->GetPosition() + offset ); +} + +wxPoint SCH_IREF::GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const +{ + return m_parent->GetSchematicTextOffset( aSettings ); +} + +EDA_ITEM* SCH_IREF::Clone() const +{ + return new SCH_IREF( *this ); +} + +void SCH_IREF::SetIrefOrientation( LABEL_SPIN_STYLE aSpinStyle ) +{ + wxPoint pt = GetTextPos() - GetParent()->GetPosition(); + int offset = std::max( abs( pt.x ), abs( pt.y ) ); + + switch( aSpinStyle ) + { + case LABEL_SPIN_STYLE::RIGHT: + SetTextAngle( TEXT_ANGLE_HORIZ ); + SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); + SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + pt.y = 0; + pt.x = offset; + break; + case LABEL_SPIN_STYLE::UP: + SetTextAngle( TEXT_ANGLE_VERT ); + SetHorizJustify( GR_TEXT_HJUSTIFY_LEFT ); + SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + pt.y = -offset; + pt.x = 0; + break; + case LABEL_SPIN_STYLE::LEFT: + SetTextAngle( TEXT_ANGLE_HORIZ ); + SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + pt.y = 0; + pt.x = -offset; + break; + case LABEL_SPIN_STYLE::BOTTOM: + SetTextAngle( TEXT_ANGLE_VERT ); + SetHorizJustify( GR_TEXT_HJUSTIFY_RIGHT ); + SetVertJustify( GR_TEXT_VJUSTIFY_CENTER ); + pt.y = offset; + pt.x = 0; + break; + } + + SetPosition( GetParent()->GetPosition() + pt ); +} + +void SCH_IREF::CopyParentStyle() +{ + SetTextSize( m_parent->GetTextSize() ); + SetItalic( m_parent->IsItalic() ); + SetBold( m_parent->IsBold() ); + SetTextThickness( m_parent->GetTextThickness() ); + SetIrefOrientation( m_parent->GetLabelSpinStyle() ); +} diff --git a/eeschema/sch_iref.h b/eeschema/sch_iref.h new file mode 100644 index 0000000000..0735214049 --- /dev/null +++ b/eeschema/sch_iref.h @@ -0,0 +1,93 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/** + * @file sch_iref.h + * @brief Definitions of the SCH_IREF class and derivatives for Eeschema. + */ + +#ifndef CLASS_IREF_H +#define CLASS_IREF_H + + +#include + +class SCH_TEXT; +class SCH_GLOBALLABEL; + +class SCH_IREF : public SCH_TEXT +{ +public: + SCH_IREF( const wxPoint& pos = wxPoint( 0, 0 ), const wxString& text = wxEmptyString, + SCH_GLOBALLABEL* aParent = nullptr, KICAD_T aType = SCH_IREF_T ); + + ~SCH_IREF() { } + + static inline bool ClassOf( const EDA_ITEM* aItem ) + { + return aItem && SCH_IREF_T == aItem->Type(); + } + + wxString GetClass() const override + { + return wxT( "SCH_IREF" ); + } + + EDA_ITEM* Clone() const override; + + std::vector* GetRefTable() { return &m_refTable; } + + bool IsDangling() const override { return false; } + + wxPoint GetSchematicTextOffset() const + { + return wxPoint(0, 0); + } + + void CopyParentStyle(); + void PlaceAtDefaultPosition(); + + wxPoint GetSchematicTextOffset( RENDER_SETTINGS* aSettings ) const override; + + SCH_GLOBALLABEL* GetParent() { return m_parent; } + + void SetParent( SCH_GLOBALLABEL* parent ) { m_parent = parent; } + + int GetOwnPageNumber() { return m_ownPageNumber; } + + void SetOwnPageNumber( int page ) { m_ownPageNumber = page; } + + SCH_SCREEN* GetScreen() { return m_screen; } + + void SetScreen( SCH_SCREEN* screen ) { m_screen = screen; } + +private: + void SetIrefOrientation( LABEL_SPIN_STYLE aSpinStyle ); + + std::vector m_refTable; + SCH_GLOBALLABEL* m_parent; + int m_ownPageNumber; + SCH_SCREEN* m_screen; +}; + +#endif diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index cc8b9abae7..50ab643871 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -220,6 +221,7 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) HANDLE_ITEM( SCH_BUS_BUS_ENTRY_T, SCH_BUS_ENTRY_BASE ); HANDLE_ITEM( SCH_BITMAP_T, SCH_BITMAP ); HANDLE_ITEM( SCH_MARKER_T, SCH_MARKER ); + HANDLE_ITEM( SCH_IREF_T, SCH_TEXT ); default: return false; } @@ -1287,6 +1289,7 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer ) case SCH_SHEET_PIN_T: aLayer = LAYER_SHEETLABEL; break; case SCH_HIER_LABEL_T: aLayer = LAYER_HIERLABEL; break; case SCH_GLOBAL_LABEL_T: aLayer = LAYER_GLOBLABEL; break; + case SCH_IREF_T: aLayer = LAYER_GLOBLABEL; break; case SCH_LABEL_T: aLayer = LAYER_LOCLABEL; break; default: aLayer = LAYER_NOTES; break; } @@ -1352,6 +1355,7 @@ void SCH_PAINTER::draw( SCH_TEXT *aText, int aLayer ) drawDanglingSymbol( aText->GetTextPos(), Mils2iu( DANGLING_SYMBOL_SIZE / 2 ), drawingShadows ); } + } diff --git a/eeschema/sch_sexpr_parser.cpp b/eeschema/sch_sexpr_parser.cpp index 7345edfb54..66c09de325 100644 --- a/eeschema/sch_sexpr_parser.cpp +++ b/eeschema/sch_sexpr_parser.cpp @@ -2692,8 +2692,19 @@ SCH_TEXT* SCH_SEXPR_PARSER::parseSchText() parseEDA_TEXT( static_cast( text.get() ) ); break; + case T_iref: + { + if( text->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( text.get() ); + label->SetIrefSavedPosition( parseXY() ); + NeedRIGHT(); + } + break; + } + default: - Expecting( "at, shape, or effects" ); + Expecting( "at, shape, iref or effects" ); } } diff --git a/eeschema/sch_sexpr_plugin.cpp b/eeschema/sch_sexpr_plugin.cpp index 0818a87655..03a8f12cf4 100644 --- a/eeschema/sch_sexpr_plugin.cpp +++ b/eeschema/sch_sexpr_plugin.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1181,6 +1182,18 @@ void SCH_SEXPR_PLUGIN::saveText( SCH_TEXT* aText, int aNestLevel ) if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) || ( aText->Type() == SCH_HIER_LABEL_T ) ) m_out->Print( 0, " (shape %s)", getSheetPinShapeToken( aText->GetShape() ) ); + if( ( aText->Type() == SCH_GLOBAL_LABEL_T ) ) + { + SCH_GLOBALLABEL* label = static_cast( aText ); + + if( label->GetIref() != nullptr ) + { + SCH_IREF* iref = label->GetIref(); + m_out->Print( 0, " (iref %s %s)", FormatInternalUnits( iref->GetPosition().x ).c_str(), + FormatInternalUnits( iref->GetPosition().y ).c_str() ); + } + } + if( aText->GetText().Length() < 50 ) { m_out->Print( 0, " (at %s %s %s)", diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 80aa56a3c5..960e4ce9a7 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -44,6 +44,7 @@ #include #include #include +#include using KIGFX::SCH_RENDER_SETTINGS; @@ -808,7 +809,9 @@ SCH_GLOBALLABEL::SCH_GLOBALLABEL( const wxPoint& pos, const wxString& text ) m_Layer = LAYER_GLOBLABEL; m_shape = PINSHEETLABEL_SHAPE::PS_BIDI; m_isDangling = true; + m_iref = nullptr; SetMultilineAllowed( false ); + m_savedIrefPos = wxDefaultPosition; } diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 3f655938f4..1566d491a4 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -34,7 +34,7 @@ class NETLIST_OBJECT_LIST; class HTML_MESSAGE_BOX; - +class SCH_IREF; /* * Spin style for text items of all kinds on schematics @@ -418,8 +418,16 @@ public: EDA_ITEM* Clone() const override; + SCH_IREF* GetIref() { return m_iref; } + void SetIref( SCH_IREF* iref ) { m_iref = iref; } + + wxPoint GetIrefSavedPosition() { return m_savedIrefPos; } + void SetIrefSavedPosition( wxPoint pos ) { m_savedIrefPos = pos; } + private: bool doIsConnected( const wxPoint& aPosition ) const override { return EDA_TEXT::GetTextPos() == aPosition; } + SCH_IREF* m_iref; + wxPoint m_savedIrefPos; }; diff --git a/eeschema/schematic.keywords b/eeschema/schematic.keywords index 2f3c3dd726..a74515bc25 100644 --- a/eeschema/schematic.keywords +++ b/eeschema/schematic.keywords @@ -101,6 +101,7 @@ rev right scale shape +iref sheet size solid diff --git a/eeschema/schematic_settings.cpp b/eeschema/schematic_settings.cpp index f8922686e5..a812d15dca 100644 --- a/eeschema/schematic_settings.cpp +++ b/eeschema/schematic_settings.cpp @@ -41,7 +41,11 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin m_TextOffsetRatio( 0.08 ), m_PinSymbolSize( DEFAULT_TEXT_SIZE * IU_PER_MILS / 2 ), m_JunctionSize( DEFAULT_JUNCTION_DIAM * IU_PER_MILS ), - m_SpiceAdjustPassiveValues( false ) + m_SpiceAdjustPassiveValues( false ), + m_IntersheetsRefShow ( false ), + m_IntersheetsRefFormatShort (false ), + m_IntersheetsRefPrefix ( DEFAULT_IREF_PREFIX ), + m_IntersheetsRefSuffix ( DEFAULT_IREF_SUFFIX ) { EESCHEMA_SETTINGS* appSettings = dynamic_cast( Kiface().KifaceSettings() ); @@ -57,6 +61,26 @@ SCHEMATIC_SETTINGS::SCHEMATIC_SETTINGS( JSON_SETTINGS* aParent, const std::strin appSettings ? appSettings->m_Drawing.pin_symbol_size : DEFAULT_TEXT_SIZE / 2; int defaultJunctionSize = appSettings ? appSettings->m_Drawing.default_junction_size : DEFAULT_JUNCTION_DIAM; + bool defaultIntersheetsRefShow = + appSettings ? appSettings->m_Drawing.intersheets_ref_show : false; + bool defaultIntersheetsRefFormatShort = + appSettings ? appSettings->m_Drawing.intersheets_ref_short : false; + wxString defaultIntersheetsRefPrefix = + appSettings ? appSettings->m_Drawing.intersheets_ref_prefix : DEFAULT_IREF_PREFIX; + wxString defaultIntersheetsRefSuffix = + appSettings ? appSettings->m_Drawing.intersheets_ref_suffix : DEFAULT_IREF_SUFFIX; + + m_params.emplace_back( new PARAM( "drawing.intersheets_ref_show", + &m_IntersheetsRefShow, false ) ); + + m_params.emplace_back( new PARAM( "drawing.intersheets_ref_short", + &m_IntersheetsRefFormatShort, false ) ); + + m_params.emplace_back( new PARAM( "drawing.intersheets_ref_prefix", + &m_IntersheetsRefPrefix, "[" ) ); + + m_params.emplace_back( new PARAM( "drawing.intersheets_ref_suffix", + &m_IntersheetsRefSuffix, "]" ) ); m_params.emplace_back( new PARAM_SCALED( "drawing.default_line_thickness", &m_DefaultLineWidth, Mils2iu( defaultLineThickness ), diff --git a/eeschema/schematic_settings.h b/eeschema/schematic_settings.h index a4f7ff3320..ebb3124939 100644 --- a/eeschema/schematic_settings.h +++ b/eeschema/schematic_settings.h @@ -50,6 +50,11 @@ public: int m_PinSymbolSize; int m_JunctionSize; + bool m_IntersheetsRefShow; + bool m_IntersheetsRefFormatShort; + wxString m_IntersheetsRefPrefix; + wxString m_IntersheetsRefSuffix; + wxString m_PageLayoutDescrFile; wxString m_PlotDirectoryName; diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 327348bb64..d202534b14 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -458,6 +459,15 @@ int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent ) else textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().RotateCCW() ); + if( item->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( item ); + SCH_IREF* iref = label->GetIref(); + + if( iref ) + iref->CopyParentStyle(); + } + break; } @@ -641,6 +651,16 @@ int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent ) textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().MirrorX() ); else textItem->SetLabelSpinStyle( textItem->GetLabelSpinStyle().MirrorY() ); + + if( item->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( item ); + SCH_IREF* iref = label->GetIref(); + + if( iref ) + iref->CopyParentStyle(); + } + break; } @@ -828,6 +848,14 @@ int SCH_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) case SCH_NO_CONNECT_T: newItem->SetParent( m_frame->GetScreen() ); m_frame->AddToScreen( newItem, m_frame->GetScreen() ); + + if( newItem->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( newItem ); + label->SetIref( nullptr ); + label->SetIrefSavedPosition( wxDefaultPosition ); + } + break; case SCH_SHEET_T: @@ -1028,6 +1056,16 @@ int SCH_EDIT_TOOL::DoDelete( const TOOL_EVENT& aEvent ) sheet->RemovePin( pin ); } + else if( sch_item->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = (SCH_GLOBALLABEL*) sch_item; + SCH_IREF* iref = label->GetIref(); + + m_frame->RemoveFromScreen( sch_item, m_frame->GetScreen() ); + + if( iref ) + m_frame->RemoveFromScreen( iref, m_frame->GetScreen() ); + } else { m_frame->RemoveFromScreen( sch_item, m_frame->GetScreen() ); diff --git a/eeschema/tools/sch_editor_control.cpp b/eeschema/tools/sch_editor_control.cpp index 974b7b875a..0d2c613b39 100644 --- a/eeschema/tools/sch_editor_control.cpp +++ b/eeschema/tools/sch_editor_control.cpp @@ -1529,6 +1529,13 @@ int SCH_EDITOR_CONTROL::Paste( const TOOL_EVENT& aEvent ) updatePastedInstances( pastePath, clipPath, sheet, forceKeepAnnotations ); } + if( item->Type() == SCH_GLOBAL_LABEL_T ) + { + SCH_GLOBALLABEL* label = static_cast( item ); + label->SetIref( nullptr ); + label->SetIrefSavedPosition( wxDefaultPosition ); + } + item->SetFlags( IS_NEW | IS_PASTED | IS_MOVED ); m_frame->AddItemToScreenAndUndoList( m_frame->GetScreen(), (SCH_ITEM*) item, i > 0 ); diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index e49317b6d6..3ceac7a06e 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,7 @@ static const KICAD_T movableItems[] = SCH_COMPONENT_T, SCH_SHEET_PIN_T, SCH_SHEET_T, + SCH_IREF_T, EOT }; @@ -703,6 +705,36 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta ) break; } + case SCH_GLOBAL_LABEL_T: + { + SCH_GLOBALLABEL* label = static_cast( aItem ); + EDA_ITEM* iref = (EDA_ITEM*) ( label->GetIref() ); + static_cast( aItem )->Move( (wxPoint) aDelta ); + + if( iref ) + static_cast( iref )->Move( (wxPoint) aDelta ); + + break; + } + case SCH_IREF_T: + { + SCH_IREF* iref = static_cast( aItem ); + wxPoint pt = (wxPoint) aDelta; + + int style = iref->GetParent()->GetLabelSpinStyle(); + + if( iref->GetParent()->IsSelected() ) + break; + + if( ( style == LABEL_SPIN_STYLE::RIGHT ) || ( style == LABEL_SPIN_STYLE::LEFT ) ) + pt.y = 0; + + if( ( style == LABEL_SPIN_STYLE::UP ) || ( style == LABEL_SPIN_STYLE::BOTTOM ) ) + pt.x = 0; + + iref->Move( pt ); + break; + } default: static_cast( aItem )->Move( (wxPoint) aDelta ); break; diff --git a/include/core/typeinfo.h b/include/core/typeinfo.h index 2b9ba1900c..e97d5d33f1 100644 --- a/include/core/typeinfo.h +++ b/include/core/typeinfo.h @@ -137,6 +137,7 @@ enum KICAD_T SCH_SHEET_PIN_T, SCH_SHEET_T, SCH_PIN_T, + SCH_IREF_T, // Be prudent with these types: // they should be used only to locate a specific field type among SCH_FIELD_Ts