KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eeschema/dialogs/dialog_shape_properties.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) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
25#include <stroke_params.h>
26#include <sch_edit_frame.h>
27#include <sch_shape.h>
30#include <sch_commit.h>
31
32
35 m_frame( aParent ),
36 m_shape( aShape ),
37 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
38{
39 SetTitle( wxString::Format( GetTitle(), aShape->EDA_SHAPE::GetFriendlyName() ) );
40
41 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
42 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
43
45
46 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
47
48 for( const auto& [ lineStyle, lineStyleDesc ] : lineTypeNames )
49 m_borderStyleCombo->Append( lineStyleDesc.name, KiBitmap( lineStyleDesc.bitmap ) );
50
52
53 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
54
58
60 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
61
62 // Required under wxGTK if we want to dismiss the dialog with the ESC key
63 SetFocus();
64
66
67 // Now all widgets have the size fixed, call FinishDialogSettings
69}
70
71
73{
74 if( !wxDialog::TransferDataToWindow() )
75 return false;
76
77 if( m_shape->GetWidth() >= 0 )
78 {
79 m_borderCheckbox->SetValue( true );
81 }
82 else
83 {
84 m_borderCheckbox->SetValue( false );
85
86 m_borderWidth.Enable( false );
87 m_borderColorLabel->Enable( false );
88 m_borderColorSwatch->Enable( false );
89 m_borderStyleLabel->Enable( false );
90 m_borderStyleCombo->Enable( false );
91 }
92
94
95 int style = static_cast<int>( m_shape->GetStroke().GetLineStyle() );
96
97 if( style == -1 )
98 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
99 else if( style < (int) lineTypeNames.size() )
100 m_borderStyleCombo->SetSelection( style );
101 else
102 wxFAIL_MSG( "Line type not found in the type lookup map" );
103
104 m_filledCtrl->SetValue( m_shape->IsFilled() );
106
107 return true;
108}
109
110
111void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
112{
113 bool border = m_borderCheckbox->GetValue();
114
115 if( border && m_borderWidth.GetValue() < 0 )
117
118 m_borderWidth.Enable( border );
119 m_borderColorLabel->Enable( border );
120 m_borderColorSwatch->Enable( border );
121 m_borderStyleLabel->Enable( border );
122 m_borderStyleCombo->Enable( border );
123}
124
125
126void DIALOG_SHAPE_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
127{
128 bool fill = m_filledCtrl->GetValue();
129
130 m_fillColorLabel->Enable( fill );
131 m_fillColorSwatch->Enable( fill );
132}
133
134
136{
137 if( !wxDialog::TransferDataFromWindow() )
138 return false;
139
140 SCH_COMMIT commit( m_frame );
141
142 if( !m_shape->IsNew() )
143 commit.Modify( m_shape, m_frame->GetScreen() );
144
145 STROKE_PARAMS stroke = m_shape->GetStroke();
146
147 if( m_borderCheckbox->GetValue() )
148 stroke.SetWidth( std::max( 0, m_borderWidth.GetIntValue() ) );
149 else
150 stroke.SetWidth( -1 );
151
152 auto it = lineTypeNames.begin();
153 std::advance( it, m_borderStyleCombo->GetSelection() );
154
155 if( it == lineTypeNames.end() )
156 stroke.SetLineStyle( LINE_STYLE::DEFAULT );
157 else
158 stroke.SetLineStyle( it->first );
159
161
162 m_shape->SetStroke( stroke );
163
164 m_shape->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL );
166
167 if( !commit.Empty() )
168 {
169 commit.Push( wxString::Format( _( "Edit %s" ), m_shape->EDA_SHAPE::GetFriendlyName() ),
171 }
172
173 return true;
174}
175
176
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:111
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:104
bool GetOverrideSchItemColors() const
COLOR4D GetColor(int aLayer) const
void SetSwatchColor(const KIGFX::COLOR4D &aColor, bool aSendEvent)
Set the current swatch color directly.
KIGFX::COLOR4D GetSwatchColor() const
void SetDefaultColor(const KIGFX::COLOR4D &aColor)
Sets the color that will be chosen with the "Reset to Default" button in the chooser.
void SetSwatchBackground(const KIGFX::COLOR4D &aBackground)
Set the swatch background color.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
bool Empty() const
Returns status of an item.
Definition: commit.h:142
void onFillChecked(wxCommandEvent &aEvent) override
DIALOG_SHAPE_PROPERTIES(SCH_EDIT_FRAME *aParent, SCH_SHAPE *aShape)
void onBorderChecked(wxCommandEvent &aEvent) override
void SetInitialFocus(wxWindow *aWindow)
Sets the window (usually a wxTextCtrl) that should be focused when the dialog is shown.
Definition: dialog_shim.h:97
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
bool IsNew() const
Definition: eda_item.h:103
bool IsFilled() const
Definition: eda_shape.h:90
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
virtual int GetWidth() const
Definition: eda_shape.h:109
void SetFillMode(FILL_T aFill)
Definition: eda_shape.h:100
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxColour ToColour() const
Definition: color4d.cpp:220
EESCHEMA_SETTINGS * eeconfig() const
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:353
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_shape.cpp:63
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:64
Simple container to manage line stroke parameters.
Definition: stroke_params.h:81
void SetLineStyle(LINE_STYLE aLineStyle)
Definition: stroke_params.h:95
void SetWidth(int aWidth)
Definition: stroke_params.h:92
void SetColor(const KIGFX::COLOR4D &aColor)
Definition: stroke_params.h:98
LINE_STYLE GetLineStyle() const
Definition: stroke_params.h:94
KIGFX::COLOR4D GetColor() const
Definition: stroke_params.h:97
int GetIntValue()
Definition: unit_binder.h:127
virtual long long int GetValue()
Return the current value in Internal Units.
void Enable(bool aEnable)
Enable/disable the label, widget and units label.
virtual void SetValue(long long int aValue)
Set new value (in Internal Units) for the text field, taking care of units conversion.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:154
#define _(s)
@ LAYER_SCHEMATIC_BACKGROUND
Definition: layer_ids.h:382
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:151
#define SKIP_CONNECTIVITY
Definition: sch_commit.h:43
const std::map< LINE_STYLE, struct LINE_STYLE_DESC > lineTypeNames
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94