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-2017 Wayne Stambaugh <stambaughw@verizon.net>
6  * Copyright (C) 2004-2017 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 <class_drawpanel.h>
34 #include <confirm.h>
35 #include <schframe.h>
36 #include <msgpanel.h>
37 
38 #include <general.h>
39 #include <class_library.h>
40 #include <sch_component.h>
41 
42 #include <dialog_edit_one_field.h>
43 
44 
46 {
47  wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T,
48  wxT( "Cannot edit invalid schematic field." ) );
49 
50  SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
51 
52  wxCHECK_RET( component != NULL && component->Type() == SCH_COMPONENT_T,
53  wxT( "Invalid schematic field parent item." ) );
54 
55  LIB_PART* part = Prj().SchLibs()->FindLibPart( component->GetLibId() );
56 
57  wxCHECK_RET( part, wxT( "Library part for component <" ) +
58  FROM_UTF8( component->GetLibId().GetLibItemName() ) +
59  wxT( "> could not be found." ) );
60 
61  // Save old component in undo list if not already in edit, or moving.
62  if( aField->GetFlags() == 0 )
63  SaveCopyInUndoList( component, UR_CHANGED );
64 
65  // Don't use GetText() here. If the field is the reference designator and it's parent
66  // component has multiple parts, we don't want the part suffix added to the field.
68 
69  wxString title;
70  title.Printf( _( "Edit %s Field" ), GetChars( aField->GetName() ) );
71 
72  DIALOG_SCH_EDIT_ONE_FIELD dlg( this, title, aField );
73 
74  // The dialog may invoke a kiway player for footprint fields
75  // so we must use a quasimodal
76  if( dlg.ShowQuasiModal() != wxID_OK )
77  {
80  return;
81  }
82 
83  dlg.UpdateField( aField, m_CurrentSheet );
86  OnModify();
87 
88  if( m_autoplaceFields )
89  component->AutoAutoplaceFields( GetScreen() );
90 
91  m_canvas->Refresh();
92 
93  MSG_PANEL_ITEMS items;
94  component->SetCurrentSheetPath( &GetCurrentSheet() );
95  component->GetMsgPanelInfo( items );
96  SetMsgPanel( items );
97 }
98 
99 
101 {
102  wxCHECK_RET( aField != NULL && aField->Type() == SCH_FIELD_T && !aField->GetText().IsEmpty(),
103  wxT( "Cannot rotate invalid schematic field." ) );
104 
105  SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
106 
107  // Save old component in undo list if not already in edit, or moving.
108  if( aField->GetFlags() == 0 )
109  SaveCopyInUndoList( component, UR_CHANGED );
110 
111  if( aField->GetTextAngle() == TEXT_ANGLE_HORIZ )
112  aField->SetTextAngle( TEXT_ANGLE_VERT );
113  else
114  aField->SetTextAngle( TEXT_ANGLE_HORIZ );
115 
116  OnModify();
117 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
#define TEXT_ANGLE_HORIZ
Frequent text rotations, used with {Set,Get}TextAngle(), in 0.1 degrees for now, hoping to migrate to...
Definition: common.h:91
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void RotateField(SCH_FIELD *aField)
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:473
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))
Function SaveCopyInUndoList.
virtual void Refresh(bool eraseBackground=true, const wxRect *rect=NULL) override
Definition: draw_panel.cpp:326
This file is part of the common library.
void OnModify()
Function OnModify Must be called after a schematic change in order to set the "modify" flag of the cu...
Definition: schframe.cpp:761
EDA_ITEM * GetParent() const
Definition: base_struct.h:208
void UpdateField(SCH_FIELD *aField, SCH_SHEET_PATH *aSheetPath)
void MoveCursorToCrossHair()
Function MoveCursorToCrossHair warps the cursor to the current cross hair position.
Definition: draw_panel.cpp:348
void EditComponentFieldText(SCH_FIELD *aField)
Function EditComponentFieldText displays the edit field dialog to edit the parameters of aField...
#define TEXT_ANGLE_VERT
Definition: common.h:92
double GetTextAngle() const
Definition: eda_text.h:164
SCH_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
Definition: schframe.cpp:520
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
SCH_SHEET_PATH * m_CurrentSheet
which sheet we are presently working on.
Definition: schframe.h:120
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Function SetMsgPanel clears the message panel and populates it with the contents of aList...
Definition: draw_frame.cpp:751
int ShowQuasiModal()
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
SCH_SHEET_PATH & GetCurrentSheet()
Definition: schframe.cpp:565
Class LIB_PART defines a library part object.
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
Definition: schframe.h:154
EDA_DRAW_PANEL * m_canvas
The area to draw on.
Definition: draw_frame.h:92
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
void SetIgnoreMouseEvents(bool aIgnore)
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
Definition for part library class.
Message panel definition file.