You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
  6. * Copyright (C) 1992-2015 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. /**
  26. * @file sheetlab.cpp
  27. * @brief Create and edit the SCH_SHEET_PIN items.
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <macros.h>
  32. #include <sch_draw_panel.h>
  33. #include <confirm.h>
  34. #include <sch_edit_frame.h>
  35. #include <sch_sheet.h>
  36. #include <dialog_helpers.h>
  37. #include <dialogs/dialog_sch_edit_sheet_pin.h>
  38. PINSHEETLABEL_SHAPE SCH_EDIT_FRAME::m_lastSheetPinType = NET_INPUT;
  39. wxSize SCH_EDIT_FRAME::m_lastSheetPinTextSize( -1, -1 );
  40. wxPoint SCH_EDIT_FRAME::m_lastSheetPinPosition;
  41. const wxSize &SCH_EDIT_FRAME::GetLastSheetPinTextSize()
  42. {
  43. // Delayed initialization (need the preferences to be loaded)
  44. if( m_lastSheetPinTextSize.x == -1 )
  45. {
  46. m_lastSheetPinTextSize.x = GetDefaultTextSize();
  47. m_lastSheetPinTextSize.y = GetDefaultTextSize();
  48. }
  49. return m_lastSheetPinTextSize;
  50. }
  51. int SCH_EDIT_FRAME::EditSheetPin( SCH_SHEET_PIN* aSheetPin, bool aRedraw )
  52. {
  53. if( aSheetPin == NULL )
  54. return wxID_CANCEL;
  55. DIALOG_SCH_EDIT_SHEET_PIN dlg( this, aSheetPin );
  56. if( dlg.ShowModal() == wxID_CANCEL )
  57. return wxID_CANCEL;
  58. if( aRedraw )
  59. RefreshItem( aSheetPin );
  60. return wxID_OK;
  61. }
  62. SCH_SHEET_PIN* SCH_EDIT_FRAME::CreateSheetPin( SCH_SHEET* aSheet )
  63. {
  64. wxString line;
  65. SCH_SHEET_PIN* sheetPin;
  66. sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), line );
  67. sheetPin->SetFlags( IS_NEW );
  68. sheetPin->SetTextSize( GetLastSheetPinTextSize() );
  69. sheetPin->SetShape( m_lastSheetPinType );
  70. int response = EditSheetPin( sheetPin, false );
  71. if( sheetPin->GetText().IsEmpty() || (response == wxID_CANCEL) )
  72. {
  73. delete sheetPin;
  74. return NULL;
  75. }
  76. m_lastSheetPinType = sheetPin->GetShape();
  77. m_lastSheetPinTextSize = sheetPin->GetTextSize();
  78. sheetPin->SetPosition( GetCrossHairPosition() );
  79. PrepareMoveItem( sheetPin );
  80. OnModify();
  81. return sheetPin;
  82. }
  83. SCH_SHEET_PIN* SCH_EDIT_FRAME::ImportSheetPin( SCH_SHEET* aSheet )
  84. {
  85. EDA_ITEM* item;
  86. SCH_SHEET_PIN* sheetPin;
  87. SCH_HIERLABEL* label = NULL;
  88. if( !aSheet->GetScreen() )
  89. return NULL;
  90. item = aSheet->GetScreen()->GetDrawItems();
  91. for( ; item != NULL; item = item->Next() )
  92. {
  93. if( item->Type() != SCH_HIER_LABEL_T )
  94. continue;
  95. label = (SCH_HIERLABEL*) item;
  96. /* A global label has been found: check if there a corresponding sheet label. */
  97. if( !aSheet->HasPin( label->GetText() ) )
  98. break;
  99. label = NULL;
  100. }
  101. if( label == NULL )
  102. {
  103. DisplayInfoMessage( this, _( "No new hierarchical labels found." ) );
  104. return NULL;
  105. }
  106. sheetPin = new SCH_SHEET_PIN( aSheet, wxPoint( 0, 0 ), label->GetText() );
  107. sheetPin->SetFlags( IS_NEW );
  108. sheetPin->SetTextSize( GetLastSheetPinTextSize() );
  109. m_lastSheetPinType = label->GetShape();
  110. sheetPin->SetShape( label->GetShape() );
  111. sheetPin->SetPosition( GetCrossHairPosition() );
  112. PrepareMoveItem( sheetPin );
  113. return sheetPin;
  114. }