KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2022 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
33 m_frame( aParent ),
34 m_shape( aShape ),
35 m_borderWidth( aParent, m_borderWidthLabel, m_borderWidthCtrl, m_borderWidthUnits, true )
36{
37 SetTitle( wxString::Format( GetTitle(), aShape->ShowShape() ) );
38
39 m_helpLabel1->SetFont( KIUI::GetInfoFont( this ).Italic() );
40 m_helpLabel2->SetFont( KIUI::GetInfoFont( this ).Italic() );
41
43
44 m_borderColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
45
46 for( const std::pair<const PLOT_DASH_TYPE, lineTypeStruct>& typeEntry : lineTypeNames )
47 m_borderStyleCombo->Append( typeEntry.second.name, KiBitmap( typeEntry.second.bitmap ) );
48
50
51 m_fillColorSwatch->SetDefaultColor( COLOR4D::UNSPECIFIED );
52
56
58 m_infoBar->ShowMessage( _( "Note: individual item colors overridden in Preferences." ) );
59
60 // Required under wxGTK if we want to dismiss the dialog with the ESC key
61 SetFocus();
62
64
65 // Now all widgets have the size fixed, call FinishDialogSettings
67}
68
69
71{
72 if( !wxDialog::TransferDataToWindow() )
73 return false;
74
75 if( m_shape->GetWidth() >= 0 )
76 {
77 m_borderCheckbox->SetValue( true );
79 }
80 else
81 {
82 m_borderCheckbox->SetValue( false );
83
84 m_borderWidth.Enable( false );
85 m_borderColorLabel->Enable( false );
86 m_borderColorSwatch->Enable( false );
87 m_borderStyleLabel->Enable( false );
88 m_borderStyleCombo->Enable( false );
89 }
90
92
93 int style = static_cast<int>( m_shape->GetStroke().GetPlotStyle() );
94
95 if( style == -1 )
96 m_borderStyleCombo->SetStringSelection( DEFAULT_STYLE );
97 else if( style < (int) lineTypeNames.size() )
98 m_borderStyleCombo->SetSelection( style );
99 else
100 wxFAIL_MSG( "Line type not found in the type lookup map" );
101
102 m_filledCtrl->SetValue( m_shape->IsFilled() );
104
105 return true;
106}
107
108
109void DIALOG_SHAPE_PROPERTIES::onBorderChecked( wxCommandEvent& event )
110{
111 bool border = m_borderCheckbox->GetValue();
112
113 if( border && m_borderWidth.GetValue() < 0 )
115
116 m_borderWidth.Enable( border );
117 m_borderColorLabel->Enable( border );
118 m_borderColorSwatch->Enable( border );
119 m_borderStyleLabel->Enable( border );
120 m_borderStyleCombo->Enable( border );
121}
122
123
124void DIALOG_SHAPE_PROPERTIES::onFillChecked( wxCommandEvent& aEvent )
125{
126 bool fill = m_filledCtrl->GetValue();
127
128 m_fillColorLabel->Enable( fill );
129 m_fillColorSwatch->Enable( fill );
130}
131
132
134{
135 if( !wxDialog::TransferDataFromWindow() )
136 return false;
137
138 if( !m_shape->IsNew() )
139 {
140 m_frame->SaveCopyInUndoList( m_frame->GetScreen(), m_shape, UNDO_REDO::CHANGED, false,
141 false );
142 }
143
144 STROKE_PARAMS stroke = m_shape->GetStroke();
145
146 if( m_borderCheckbox->GetValue() )
147 stroke.SetWidth( std::max( (long long int) 0, m_borderWidth.GetValue() ) );
148 else
149 stroke.SetWidth( -1 );
150
151 auto it = lineTypeNames.begin();
152 std::advance( it, m_borderStyleCombo->GetSelection() );
153
154 if( it == lineTypeNames.end() )
155 stroke.SetPlotStyle( PLOT_DASH_TYPE::DEFAULT );
156 else
157 stroke.SetPlotStyle( it->first );
158
160
161 m_shape->SetStroke( stroke );
162
163 m_shape->SetFillMode( m_filledCtrl->GetValue() ? FILL_T::FILLED_WITH_COLOR : FILL_T::NO_FILL );
165
166 return true;
167}
168
169
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:106
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.
Class DIALOG_SHAPE_PROPERTIES_BASE.
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
wxString ShowShape() const
Definition: eda_shape.cpp:57
void SetFillColor(const COLOR4D &aColor)
Definition: eda_shape.h:106
COLOR4D GetFillColor() const
Definition: eda_shape.h:105
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:103
wxColour ToColour() const
Definition: color4d.cpp:219
EESCHEMA_SETTINGS * eeconfig() const
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend, bool aDirtyConnectivity=true)
Create a copy of the current schematic item, and put it in the undo list.
void SetStroke(const STROKE_PARAMS &aStroke) override
Definition: sch_shape.cpp:61
STROKE_PARAMS GetStroke() const override
Definition: sch_shape.h:64
Simple container to manage line stroke parameters.
Definition: stroke_params.h:88
void SetWidth(int aWidth)
Definition: stroke_params.h:99
void SetColor(const KIGFX::COLOR4D &aColor)
KIGFX::COLOR4D GetColor() const
PLOT_DASH_TYPE GetPlotStyle() const
void SetPlotStyle(PLOT_DASH_TYPE aPlotStyle)
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:380
wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:156
const std::map< PLOT_DASH_TYPE, struct lineTypeStruct > lineTypeNames
Definition: stroke_params.h:70
constexpr int MilsToIU(int mils) const
Definition: base_units.h:94