31#include <wx/filedlg.h>
37#include <wx/bmpbuttn.h>
91 const wxPoint& aPos,
const wxSize& aSize )
const
95#if wxCHECK_VERSION( 3, 3, 0 )
96 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
98 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
100 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
101 aProperty->GetMaxLength() );
102 wxPGWindowList ret( win,
nullptr );
134 wxVariant var = aProperty->GetValue();
136 if( var.GetType() == wxT(
"std::optional<int>" ) )
140 if( variantData->Value().has_value() )
141 m_unitBinder->ChangeValue( variantData->Value().value() );
145 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
149 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
151 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
153 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
157 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
162 else if( !aProperty->IsValueUnspecified() )
164 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
170 wxWindow* aCtrl, wxEvent& aEvent )
const
172 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
174 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
176 if( !textCtrl->HasFocus() )
178 textCtrl->SelectAll();
184 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
189 wxWindow* aCtrl )
const
194 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
195 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
196 wxString textVal = textCtrl->GetValue();
198 if( textVal == wxT(
"<...>" ) )
210 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
213 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
223 changed = ( aVariant.IsNull() || angle.
AsDegrees() != aVariant.GetDouble() );
235 changed = ( aVariant.IsNull() ||
result != aVariant.GetLongLong() );
243 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
246 std::optional<int>
result;
250 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
254 aVariant = wxVariant( std::optional<int>() );
261 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
265 aVariant = wxVariant(
result );
273 changed = ( aVariant.IsNull() ||
result != aVariant.GetLong() );
284 if( !changed && aVariant.IsNull() )
298 const wxPoint& aPos,
const wxSize& aSize )
const
303 if( aProperty->IsValueUnspecified() )
304 aProperty->SetValueFromInt( 0 );
306 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
311 wxEvent& aEvent )
const
318 const wxPoint& aPos,
const wxSize& aSize )
const
329 colorProp->GetBackgroundColor(), defColor,
331 editor->SetPosition( aPos );
335 wxString propName = colorProp->GetName();
337 editor->Bind( COLOR_SWATCH_CHANGED,
338 [=]( wxCommandEvent& aEvt )
340 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
347 aGrid->ChangePropertyValue( prop, val );
351#if wxCHECK_VERSION( 3, 3, 0 )
352 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
354 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
360 editor->GetNewSwatchColor();
362 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
365 aGrid->DrawItem( prop );
375 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
385 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
388 color = data->
Color();
402 wxWindow* aCtrl )
const
404 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
405 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
406 wxString textVal = textCtrl->GetValue();
408 if( textVal == wxT(
"<...>" ) )
416 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
420 if( textVal.empty() )
422 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
425 aVariant = wxVariant( std::optional<double>() );
430 textVal.ToDouble( &dblValue );
431 std::optional<double>
result( dblValue );
432 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
436 aVariant = wxVariant(
result );
437 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
444 textVal.ToDouble( &
result );
445 changed = ( aVariant.IsNull() ||
result != aVariant.GetDouble() );
450 textCtrl->SetValue( wxString::Format( wxS(
"%g" ),
result ) );
456 if( !changed && aVariant.IsNull() )
465 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
466 wxVariant var = aProperty->GetValue();
468 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
470 if( var.GetType() == wxT(
"std::optional<double>" ) )
475 if( variantData->Value().has_value() )
476 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
480 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
482 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
484 else if( !aProperty->IsValueUnspecified() )
486 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric "
515 const wxPoint& aPos,
const wxSize& aSize )
const
517 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
519 buttons->Finalize( aGrid, aPos );
520 wxSize textSize = buttons->GetPrimarySize();
521 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
522 aProperty->GetValueAsString(),
nullptr, 0,
523 aProperty->GetMaxLength() );
524 wxPGWindowList ret( textCtrl, buttons );
530 wxEvent& aEvent )
const
532 if( aEvent.GetEventType() == wxEVT_BUTTON )
534 wxString fpid = aProperty->GetValue().GetString();
538 if( frame->ShowModal( &fpid,
m_frame ) )
539 aGrid->ChangePropertyValue( aProperty, fpid );
547 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
574 const wxPoint& aPos,
const wxSize& aSize )
const
576 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
578 wxString urlValue = aProperty->GetValueAsString();
579 bool hasUrl = !( urlValue.IsEmpty() || urlValue == wxS(
"~" ) );
581 buttons->Finalize( aGrid, aPos );
582 wxSize textSize = buttons->GetPrimarySize();
583 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
584 aProperty->GetValueAsString(),
nullptr, 0,
585 aProperty->GetMaxLength() );
586 wxPGWindowList ret( textCtrl, buttons );
592 wxEvent& aEvent )
const
594 if( aEvent.GetEventType() == wxEVT_BUTTON )
596 wxString filename = aProperty->GetValue().GetString();
598 if( filename.IsEmpty() || filename == wxS(
"~" ) )
600 wxFileDialog openFileDialog(
m_frame,
_(
"Open file" ), wxS(
"" ), wxS(
"" ),
601 _(
"All Files" ) + wxS(
" (*.*)|*.*" ),
602 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
606 if( openFileDialog.ShowModal() == wxID_OK )
608 filename = openFileDialog.GetPath();
609 aGrid->ChangePropertyValue( aProperty, wxString::Format( wxS(
"file://%s" ),
619 if( wxObject* src = aEvent.GetEventObject() )
621 wxString newUrl = aProperty->GetValueAsString();
622 bool hasUrl = !( newUrl.IsEmpty() || newUrl == wxS(
"~" ) );
625 if( wxWindow* win = wxDynamicCast( src, wxWindow ) )
627 if( wxBitmapButton* bb = wxDynamicCast( win, wxBitmapButton ) )
629 bb->SetBitmap( bmp );
631 else if( wxButton* b = wxDynamicCast( win, wxButton ) )
635 else if( wxWindow* parent = win->GetParent() )
637 if( wxPGMultiButton* buttons = wxDynamicCast( parent, wxPGMultiButton ) )
639 wxWindow* btn0 = buttons->GetButton( 0 );
640 if( wxBitmapButton* bb0 = wxDynamicCast( btn0, wxBitmapButton ) )
641 bb0->SetBitmap( bmp );
642 else if( wxButton* b0 = wxDynamicCast( btn0, wxButton ) )
643 b0->SetBitmap( bmp );
651 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
const KIGFX::COLOR4D & Color()
A simple color swatch of the kind used to set layer colors.
const EDA_ANGLE & Angle()
void SetAngle(const EDA_ANGLE &aAngle)
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
static const COLOR4D UNSPECIFIED
For legacy support; used as a value to indicate color hasn't been set yet.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
A wxEnumProperty that displays a color next to the enum value.
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
static const wxString EDITOR_NAME
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aWindow, wxEvent &aEvent) const override
KIGFX::COLOR4D colorFromVariant(const wxVariant &aVariant) const
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
KIGFX::COLOR4D colorFromProperty(wxPGProperty *aProperty) const
void UpdateFrame(EDA_DRAW_FRAME *aFrame)
PG_FPID_EDITOR(EDA_DRAW_FRAME *aFrame)
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aCtrl, wxEvent &aEvent) const override
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
std::unique_ptr< PROPERTY_EDITOR_UNIT_BINDER > m_unitBinder
wxPGWindowList CreateControls(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
static const wxString EDITOR_NAME
void UpdateControl(wxPGProperty *aProperty, wxWindow *aCtrl) const override
void UpdateFrame(EDA_DRAW_FRAME *aFrame)
When restarting an editor, the instance of PG_UNIT_EDITOR may be the same but the referenced frame is...
PG_UNIT_EDITOR(EDA_DRAW_FRAME *aFrame)
bool GetValueFromControl(wxVariant &aVariant, wxPGProperty *aProperty, wxWindow *aCtrl) const override
bool OnEvent(wxPropertyGrid *aPropGrid, wxPGProperty *aProperty, wxWindow *aCtrl, wxEvent &aEvent) const override
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
virtual ~PG_UNIT_EDITOR()
static const wxString EDITOR_NAME
PG_URL_EDITOR(EDA_DRAW_FRAME *aFrame)
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
void UpdateFrame(EDA_DRAW_FRAME *aFrame)
wxPGWindowList CreateControls(wxPropertyGrid *aGrid, wxPGProperty *aProperty, const wxPoint &aPos, const wxSize &aSize) const override
bool OnEvent(wxPropertyGrid *aGrid, wxPGProperty *aProperty, wxWindow *aCtrl, wxEvent &aEvent) const override
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths, std::vector< EMBEDDED_FILES * > aFilesStack)
Open a document (file) with the suitable browser.
This file is part of the common library.
@ FRAME_FOOTPRINT_CHOOSER
static std::string strValue(double aValue)
wxString result
Test unit parsing edge cases and error handling.