32#include <wx/filedlg.h>
39#include <wx/bmpbuttn.h>
93 const wxPoint& aPos,
const wxSize& aSize )
const
97#if wxCHECK_VERSION( 3, 3, 0 )
98 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
100 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
102 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
103 aProperty->GetMaxLength() );
104 wxPGWindowList ret( win,
nullptr );
136 wxVariant var = aProperty->GetValue();
140 if( var.GetType() == wxT(
"EDA_ANGLE" ) )
146 else if( !aProperty->IsValueUnspecified() )
148 double scale = angleProp->GetScale();
152 else if( var.GetType() == wxT(
"std::optional<int>" ) )
156 if( variantData->Value().has_value() )
157 m_unitBinder->ChangeValue( variantData->Value().value() );
161 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
165 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
167 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
169 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
173 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
178 else if( !aProperty->IsValueUnspecified() )
180 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
186 wxWindow* aCtrl, wxEvent& aEvent )
const
188 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
190 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
192 if( !textCtrl->HasFocus() )
194 textCtrl->SelectAll();
200 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
205 wxWindow* aCtrl )
const
210 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
211 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
212 wxString textVal = textCtrl->GetValue();
214 if( textVal == wxT(
"<...>" ) )
226 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
229 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
242 changed = ( aVariant.IsNull() || scaledValue != aVariant.GetDouble() );
246 aVariant = scaledValue;
254 changed = ( aVariant.IsNull() ||
result != aVariant.GetLongLong() );
262 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
265 std::optional<int>
result;
269 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
273 aVariant = wxVariant( std::optional<int>() );
280 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
284 aVariant = wxVariant(
result );
292 changed = ( aVariant.IsNull() ||
result != aVariant.GetLong() );
303 if( !changed && aVariant.IsNull() )
317 const wxPoint& aPos,
const wxSize& aSize )
const
322 if( aProperty->IsValueUnspecified() )
323 aProperty->SetValueFromInt( 0 );
325 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
330 wxEvent& aEvent )
const
337 const wxPoint& aPos,
const wxSize& aSize )
const
348 colorProp->GetBackgroundColor(), defColor,
350 editor->SetPosition( aPos );
354 wxString propName = colorProp->GetName();
356 editor->Bind( COLOR_SWATCH_CHANGED,
357 [=]( wxCommandEvent& aEvt )
359 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
366 aGrid->ChangePropertyValue( prop, val );
370#if wxCHECK_VERSION( 3, 3, 0 )
371 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
373 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
379 editor->GetNewSwatchColor();
381 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
384 aGrid->DrawItem( prop );
394 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
404 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
407 color = data->
Color();
421 wxWindow* aCtrl )
const
423 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
424 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
425 wxString textVal = textCtrl->GetValue();
427 if( textVal == wxT(
"<...>" ) )
435 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
439 if( textVal.empty() )
441 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
444 aVariant = wxVariant( std::optional<double>() );
449 textVal.ToDouble( &dblValue );
450 std::optional<double>
result( dblValue );
451 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
455 aVariant = wxVariant(
result );
456 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
463 textVal.ToDouble( &
result );
464 changed = ( aVariant.IsNull() ||
result != aVariant.GetDouble() );
469 textCtrl->SetValue( wxString::Format( wxS(
"%g" ),
result ) );
475 if( !changed && aVariant.IsNull() )
484 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
485 wxVariant var = aProperty->GetValue();
487 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
489 if( var.GetType() == wxT(
"std::optional<double>" ) )
494 if( variantData->Value().has_value() )
495 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
499 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
501 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
503 else if( !aProperty->IsValueUnspecified() )
505 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric "
542 const wxPoint& aPos,
const wxSize& aSize )
const
544 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
546 buttons->Finalize( aGrid, aPos );
547 wxSize textSize = buttons->GetPrimarySize();
548 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
549 aProperty->GetValueAsString(),
nullptr, 0,
550 aProperty->GetMaxLength() );
551 wxPGWindowList ret( textCtrl, buttons );
557 wxEvent& aEvent )
const
559 if( aEvent.GetEventType() == wxEVT_BUTTON )
564 wxString fpid = aProperty->GetValue().GetString();
571 if( !symbolNetlist.empty() )
574 frame->KiwayMailIn( event );
577 if( frame->ShowModal( &fpid,
m_frame ) )
578 aGrid->ChangePropertyValue( aProperty, fpid );
586 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
613 const wxPoint& aPos,
const wxSize& aSize )
const
615 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
617 wxString urlValue = aProperty->GetValueAsString();
618 bool hasUrl = !( urlValue.IsEmpty() || urlValue == wxS(
"~" ) );
620 buttons->Finalize( aGrid, aPos );
621 wxSize textSize = buttons->GetPrimarySize();
622 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
623 aProperty->GetValueAsString(),
nullptr, 0,
624 aProperty->GetMaxLength() );
625 wxPGWindowList ret( textCtrl, buttons );
631 wxEvent& aEvent )
const
633 if( aEvent.GetEventType() == wxEVT_BUTTON )
638 wxString filename = aProperty->GetValue().GetString();
640 if( filename.IsEmpty() || filename == wxS(
"~" ) )
642 wxFileDialog openFileDialog(
m_frame,
_(
"Open file" ), wxS(
"" ), wxS(
"" ),
643 _(
"All Files" ) + wxS(
" (*.*)|*.*" ),
644 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
648 if( openFileDialog.ShowModal() == wxID_OK )
650 filename = openFileDialog.GetPath();
651 aGrid->ChangePropertyValue( aProperty, wxString::Format( wxS(
"file://%s" ),
661 if( wxObject* src = aEvent.GetEventObject() )
663 wxString newUrl = aProperty->GetValueAsString();
664 bool hasUrl = !( newUrl.IsEmpty() || newUrl == wxS(
"~" ) );
667 if( wxWindow* win = wxDynamicCast( src, wxWindow ) )
669 if( wxBitmapButton* bb = wxDynamicCast( win, wxBitmapButton ) )
671 bb->SetBitmap( bmp );
673 else if( wxButton* b = wxDynamicCast( win, wxButton ) )
677 else if( wxWindow* parent = win->GetParent() )
679 if( wxPGMultiButton* buttons = wxDynamicCast( parent, wxPGMultiButton ) )
681 wxWindow* btn0 = buttons->GetButton( 0 );
682 if( wxBitmapButton* bb0 = wxDynamicCast( btn0, wxBitmapButton ) )
683 bb0->SetBitmap( bmp );
684 else if( wxButton* b0 = wxDynamicCast( btn0, wxButton ) )
685 b0->SetBitmap( bmp );
693 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.
Carry a payload from one KIWAY_PLAYER to another within a PROJECT.
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)
std::function< std::string()> m_netlistCallback
PG_FPID_EDITOR(EDA_DRAW_FRAME *aFrame, const std::function< std::string()> &aNetlistCallback)
void UpdateCallback(const std::function< std::string()> &aNetlistCallback)
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.