31#include <wx/filedlg.h>
36#include <wx/bmpbuttn.h>
90 const wxPoint& aPos,
const wxSize& aSize )
const
94#if wxCHECK_VERSION( 3, 3, 0 )
95 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
97 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
99 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
100 aProperty->GetMaxLength() );
101 wxPGWindowList ret( win,
nullptr );
133 wxVariant var = aProperty->GetValue();
135 if( var.GetType() == wxT(
"std::optional<int>" ) )
139 if( variantData->Value().has_value() )
140 m_unitBinder->ChangeValue( variantData->Value().value() );
144 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
148 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
150 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
152 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
156 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
161 else if( !aProperty->IsValueUnspecified() )
163 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
169 wxWindow* aCtrl, wxEvent& aEvent )
const
171 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
173 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
175 if( !textCtrl->HasFocus() )
177 textCtrl->SelectAll();
183 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
188 wxWindow* aCtrl )
const
193 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
194 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
195 wxString textVal = textCtrl->GetValue();
197 if( textVal == wxT(
"<...>" ) )
209 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
212 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
222 changed = ( aVariant.IsNull() || angle.
AsDegrees() != aVariant.GetDouble() );
234 changed = ( aVariant.IsNull() ||
result != aVariant.GetLongLong() );
242 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
245 std::optional<int>
result;
249 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
253 aVariant = wxVariant( std::optional<int>() );
260 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
264 aVariant = wxVariant(
result );
272 changed = ( aVariant.IsNull() ||
result != aVariant.GetLong() );
283 if( !changed && aVariant.IsNull() )
297 const wxPoint& aPos,
const wxSize& aSize )
const
302 if( aProperty->IsValueUnspecified() )
303 aProperty->SetValueFromInt( 0 );
305 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
310 wxEvent& aEvent )
const
317 const wxPoint& aPos,
const wxSize& aSize )
const
328 colorProp->GetBackgroundColor(), defColor,
330 editor->SetPosition( aPos );
333 editor->Bind( COLOR_SWATCH_CHANGED,
334 [=]( wxCommandEvent& aEvt )
339 aGrid->ChangePropertyValue( colorProp, val );
342#if wxCHECK_VERSION( 3, 3, 0 )
343 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
345 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
351 editor->GetNewSwatchColor();
361 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
371 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
388 wxWindow* aCtrl )
const
390 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
391 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
392 wxString textVal = textCtrl->GetValue();
394 if( textVal == wxT(
"<...>" ) )
402 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
406 if( textVal.empty() )
408 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
411 aVariant = wxVariant( std::optional<double>() );
416 textVal.ToDouble( &dblValue );
417 std::optional<double>
result( dblValue );
418 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
422 aVariant = wxVariant(
result );
423 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
430 textVal.ToDouble( &
result );
431 changed = ( aVariant.IsNull() ||
result != aVariant.GetDouble() );
436 textCtrl->SetValue( wxString::Format( wxS(
"%g" ),
result ) );
442 if( !changed && aVariant.IsNull() )
451 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
452 wxVariant var = aProperty->GetValue();
454 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
456 if( var.GetType() == wxT(
"std::optional<double>" ) )
461 if( variantData->Value().has_value() )
462 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
466 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
468 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
470 else if( !aProperty->IsValueUnspecified() )
472 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric "
501 const wxPoint& aPos,
const wxSize& aSize )
const
503 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
505 buttons->Finalize( aGrid, aPos );
506 wxSize textSize = buttons->GetPrimarySize();
507 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
508 aProperty->GetValueAsString(),
nullptr, 0,
509 aProperty->GetMaxLength() );
510 wxPGWindowList ret( textCtrl, buttons );
516 wxEvent& aEvent )
const
518 if( aEvent.GetEventType() == wxEVT_BUTTON )
520 wxString fpid = aProperty->GetValue().GetString();
524 if( frame->ShowModal( &fpid,
m_frame ) )
525 aGrid->ChangePropertyValue( aProperty, fpid );
533 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
560 const wxPoint& aPos,
const wxSize& aSize )
const
562 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
564 wxString urlValue = aProperty->GetValueAsString();
565 bool hasUrl = !( urlValue.IsEmpty() || urlValue == wxS(
"~" ) );
567 buttons->Finalize( aGrid, aPos );
568 wxSize textSize = buttons->GetPrimarySize();
569 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
570 aProperty->GetValueAsString(),
nullptr, 0,
571 aProperty->GetMaxLength() );
572 wxPGWindowList ret( textCtrl, buttons );
578 wxEvent& aEvent )
const
580 if( aEvent.GetEventType() == wxEVT_BUTTON )
582 wxString filename = aProperty->GetValue().GetString();
584 if( filename.IsEmpty() || filename == wxS(
"~" ) )
586 wxFileDialog openFileDialog(
m_frame,
_(
"Open file" ), wxS(
"" ), wxS(
"" ),
587 _(
"All Files" ) + wxS(
" (*.*)|*.*" ),
588 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
590 if( openFileDialog.ShowModal() == wxID_OK )
592 filename = openFileDialog.GetPath();
593 aGrid->ChangePropertyValue( aProperty, wxString::Format( wxS(
"file://%s" ),
603 if( wxObject* src = aEvent.GetEventObject() )
605 wxString newUrl = aProperty->GetValueAsString();
606 bool hasUrl = !( newUrl.IsEmpty() || newUrl == wxS(
"~" ) );
609 if( wxWindow* win = wxDynamicCast( src, wxWindow ) )
611 if( wxBitmapButton* bb = wxDynamicCast( win, wxBitmapButton ) )
613 bb->SetBitmap( bmp );
615 else if( wxButton* b = wxDynamicCast( win, wxButton ) )
619 else if( wxWindow* parent = win->GetParent() )
621 if( wxPGMultiButton* buttons = wxDynamicCast( parent, wxPGMultiButton ) )
623 wxWindow* btn0 = buttons->GetButton( 0 );
624 if( wxBitmapButton* bb0 = wxDynamicCast( btn0, wxBitmapButton ) )
625 bb0->SetBitmap( bmp );
626 else if( wxButton* b0 = wxDynamicCast( btn0, wxButton ) )
627 b0->SetBitmap( bmp );
635 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.