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.

112 lines
3.7 KiB

16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 2004-2017 KiCad Developers, see change_log.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 edit_component_in_schematic.cpp
  27. * @brief Schematic component editing code.
  28. */
  29. #include <fctsys.h>
  30. #include <gr_basic.h>
  31. #include <class_drawpanel.h>
  32. #include <confirm.h>
  33. #include <sch_edit_frame.h>
  34. #include <msgpanel.h>
  35. #include <general.h>
  36. #include <class_library.h>
  37. #include <sch_component.h>
  38. #include <symbol_lib_table.h>
  39. #include <dialog_edit_one_field.h>
  40. void SCH_EDIT_FRAME::EditComponentFieldText( SCH_FIELD* aField )
  41. {
  42. wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
  43. wxT( "Cannot edit invalid schematic field." ) );
  44. SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
  45. wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
  46. wxT( "Invalid schematic field parent item." ) );
  47. // Save old component in undo list if not already in edit, or moving.
  48. if( aField->GetFlags() == 0 )
  49. SaveCopyInUndoList( component, UR_CHANGED );
  50. // Don't use GetText() here. If the field is the reference designator and it's parent
  51. // component has multiple parts, we don't want the part suffix added to the field.
  52. m_canvas->SetIgnoreMouseEvents( true );
  53. wxString title;
  54. title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
  55. DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
  56. // The dialog may invoke a kiway player for footprint fields
  57. // so we must use a quasimodal
  58. if( dlg.ShowQuasiModal() != wxID_OK )
  59. {
  60. m_canvas->MoveCursorToCrossHair();
  61. m_canvas->SetIgnoreMouseEvents( false );
  62. return;
  63. }
  64. dlg.UpdateField( aField, m_CurrentSheet );
  65. m_canvas->MoveCursorToCrossHair();
  66. m_canvas->SetIgnoreMouseEvents( false );
  67. OnModify();
  68. if( m_autoplaceFields )
  69. component->AutoAutoplaceFields( GetScreen() );
  70. m_canvas->Refresh();
  71. MSG_PANEL_ITEMS items;
  72. component->SetCurrentSheetPath( &GetCurrentSheet() );
  73. component->GetMsgPanelInfo( items );
  74. SetMsgPanel( items );
  75. }
  76. void SCH_EDIT_FRAME::RotateField( SCH_FIELD* aField )
  77. {
  78. wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
  79. wxT( "Cannot rotate invalid schematic field." ) );
  80. SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
  81. // Save old component in undo list if not already in edit, or moving.
  82. if( aField->GetFlags() == 0 )
  83. SaveCopyInUndoList( component, UR_CHANGED );
  84. if( aField->GetTextAngle() == TEXT_ANGLE_HORIZ )
  85. aField->SetTextAngle( TEXT_ANGLE_VERT );
  86. else
  87. aField->SetTextAngle( TEXT_ANGLE_HORIZ );
  88. OnModify();
  89. }