KiCad PCB EDA Suite
edit_component_in_schematic.cpp
Go to the documentation of this file.
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-2018 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 
31 #include <fctsys.h>
32 #include <gr_basic.h>
33 #include <sch_draw_panel.h>
34 #include <confirm.h>
35 #include <sch_edit_frame.h>
36 #include <msgpanel.h>
37 
38 #include <general.h>
39 #include <class_library.h>
40 #include <sch_component.h>
41 #include <symbol_lib_table.h>
42 
45 
46 
48 {
49  wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
50  wxT( "Cannot edit invalid schematic field." ) );
51 
52  SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
53 
54  wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
55  wxT( "Invalid schematic field parent item." ) );
56 
57  // Save old component in undo list if not already in edit, or moving.
59  if( ( aField->GetFlags() & mask ) == 0 ) // i.e. not edited, or moved
60  SaveCopyInUndoList( component, UR_CHANGED );
61 
62  // Don't use GetText() here. If the field is the reference designator and it's parent
63  // component has multiple parts, we don't want the part suffix added to the field.
65 
66  wxString title;
67  title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
68 
69  DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
70 
71  // The dialog may invoke a kiway player for footprint fields
72  // so we must use a quasimodal
73  if( dlg.ShowQuasiModal() != wxID_OK )
74  {
77  return;
78  }
79 
80  dlg.UpdateField( aField, m_CurrentSheet );
83 
84  if( m_autoplaceFields )
85  component->AutoAutoplaceFields( GetScreen() );
86 
87  RefreshItem( aField );
88  OnModify();
89 
90  MSG_PANEL_ITEMS items;
91  component->SetCurrentSheetPath( &GetCurrentSheet() );
92  component->GetMsgPanelInfo( m_UserUnits, items );
93  SetMsgPanel( items );
94 }
95 
96 
98 {
99  wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
100  wxT( "Cannot rotate invalid schematic field." ) );
101 
102  SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
103 
104  // Save old component in undo list if not already in edit, or moving.
105  int mask = EDA_ITEM_ALL_FLAGS - ( SELECTED | HIGHLIGHTED | BRIGHTENED );
106  if( ( aField->GetFlags() & mask ) == 0 )
107  SaveCopyInUndoList( component, UR_CHANGED );
108 
109  if( aField->GetTextAngle() == TEXT_ANGLE_HORIZ )
110  aField->SetTextAngle( TEXT_ANGLE_VERT );
111  else
112  aField->SetTextAngle( TEXT_ANGLE_HORIZ );
113 
114  RefreshItem( aField );
115  OnModify();
116 }
117 
118 
120 {
121  wxCHECK_RET( aComponent != nullptr && aComponent->Type() == SCH_COMPONENT_T,
122  wxT( "Invalid component object pointer. Bad Programmer!" ) );
123 
125 
126  DIALOG_EDIT_COMPONENT_IN_SCHEMATIC dlg( this, aComponent );
127 
128  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
129  // frame. Therefore this dialog as a modal frame parent, MUST be run under
130  // quasimodal mode for the quasimodal frame support to work. So don't use
131  // the QUASIMODAL macros here.
132  int ret = dlg.ShowQuasiModal();
133 
134  m_canvas->SetIgnoreMouseEvents( false );
136 
137  if( ret == wxID_OK )
138  {
139  if( m_autoplaceFields )
140  aComponent->AutoAutoplaceFields( GetScreen() );
141 
142  GetCanvas()->Refresh();
143  }
144 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:169
#define TEXT_ANGLE_HORIZ
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:56
void EditComponent(SCH_COMPONENT *aComponent)
Display the edit component dialog to edit the parameters of aComponent.
void RotateField(SCH_FIELD *aField)
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
#define TEXT_ANGLE_VERT
This file is part of the common library.
void OnModify()
Must be called after a schematic change in order to set the "modify" flag of the current screen* and ...
double GetTextAngle() const
Definition: eda_text.h:177
void UpdateField(SCH_FIELD *aField, SCH_SHEET_PATH *aSheetPath)
void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
virtual void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
void EditComponentFieldText(SCH_FIELD *aField)
Display the edit field dialog to edit the parameters of aField.
#define EDA_ITEM_ALL_FLAGS
Definition: base_struct.h:145
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
#define SELECTED
Definition: base_struct.h:121
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
int ShowQuasiModal()
SCH_DRAW_PANEL * GetCanvas() const override
SCH_SHEET_PATH & GetCurrentSheet()
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
#define BRIGHTENED
item is drawn with a bright contour
Definition: base_struct.h:138
EDA_ITEM * GetParent() const
Definition: base_struct.h:211
Class DIALOG_SCH_EDIT_ONE_FIELD is a the class to handle editing a single component field in the sche...
bool m_autoplaceFields
automatically place component fields
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:126
Definition the SCH_COMPONENT class for Eeschema.
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
#define HIGHLIGHTED
item is drawn in normal colors, when the rest is darkened
Definition: base_struct.h:137
void RefreshItem(SCH_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
Dialog used to edit SCH_COMPONENT objects in a schematic.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:435
void SetIgnoreMouseEvents(bool aIgnore)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:70
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
Definition for part library class.
Message panel definition file.
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:258
EDA_UNITS_T m_UserUnits
Definition: draw_frame.h:123
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201