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();
138 if( var.GetType() == wxT(
"std::optional<int>" ) )
142 if( variantData->Value().has_value() )
143 m_unitBinder->ChangeValue( variantData->Value().value() );
147 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
151 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
153 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
155 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
159 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
164 else if( !aProperty->IsValueUnspecified() )
166 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
172 wxWindow* aCtrl, wxEvent& aEvent )
const
174 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
176 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
178 if( !textCtrl->HasFocus() )
180 textCtrl->SelectAll();
186 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
191 wxWindow* aCtrl )
const
196 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
197 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
198 wxString textVal = textCtrl->GetValue();
200 if( textVal == wxT(
"<...>" ) )
212 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
215 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
225 changed = ( aVariant.IsNull() || angle.
AsDegrees() != aVariant.GetDouble() );
237 changed = ( aVariant.IsNull() ||
result != aVariant.GetLongLong() );
245 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
248 std::optional<int>
result;
252 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
256 aVariant = wxVariant( std::optional<int>() );
263 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
267 aVariant = wxVariant(
result );
275 changed = ( aVariant.IsNull() ||
result != aVariant.GetLong() );
286 if( !changed && aVariant.IsNull() )
300 const wxPoint& aPos,
const wxSize& aSize )
const
305 if( aProperty->IsValueUnspecified() )
306 aProperty->SetValueFromInt( 0 );
308 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
313 wxEvent& aEvent )
const
320 const wxPoint& aPos,
const wxSize& aSize )
const
331 colorProp->GetBackgroundColor(), defColor,
333 editor->SetPosition( aPos );
337 wxString propName = colorProp->GetName();
339 editor->Bind( COLOR_SWATCH_CHANGED,
340 [=]( wxCommandEvent& aEvt )
342 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
349 aGrid->ChangePropertyValue( prop, val );
353#if wxCHECK_VERSION( 3, 3, 0 )
354 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
356 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
362 editor->GetNewSwatchColor();
364 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
367 aGrid->DrawItem( prop );
377 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
387 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
390 color = data->
Color();
404 wxWindow* aCtrl )
const
406 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
407 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
408 wxString textVal = textCtrl->GetValue();
410 if( textVal == wxT(
"<...>" ) )
418 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
422 if( textVal.empty() )
424 changed = ( aVariant.IsNull() || variantData->Value().has_value() );
427 aVariant = wxVariant( std::optional<double>() );
432 textVal.ToDouble( &dblValue );
433 std::optional<double>
result( dblValue );
434 changed = ( aVariant.IsNull() ||
result != variantData->Value() );
438 aVariant = wxVariant(
result );
439 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
446 textVal.ToDouble( &
result );
447 changed = ( aVariant.IsNull() ||
result != aVariant.GetDouble() );
452 textCtrl->SetValue( wxString::Format( wxS(
"%g" ),
result ) );
458 if( !changed && aVariant.IsNull() )
467 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
468 wxVariant var = aProperty->GetValue();
470 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
472 if( var.GetType() == wxT(
"std::optional<double>" ) )
477 if( variantData->Value().has_value() )
478 strValue = wxString::Format( wxS(
"%g" ), variantData->Value().value() );
482 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
484 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
486 else if( !aProperty->IsValueUnspecified() )
488 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric "
519 const wxPoint& aPos,
const wxSize& aSize )
const
521 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
523 buttons->Finalize( aGrid, aPos );
524 wxSize textSize = buttons->GetPrimarySize();
525 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
526 aProperty->GetValueAsString(),
nullptr, 0,
527 aProperty->GetMaxLength() );
528 wxPGWindowList ret( textCtrl, buttons );
534 wxEvent& aEvent )
const
536 if( aEvent.GetEventType() == wxEVT_BUTTON )
538 wxString fpid = aProperty->GetValue().GetString();
545 if( !symbolNetlist.empty() )
548 frame->KiwayMailIn( event );
551 if( frame->ShowModal( &fpid,
m_frame ) )
552 aGrid->ChangePropertyValue( aProperty, fpid );
560 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
587 const wxPoint& aPos,
const wxSize& aSize )
const
589 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
591 wxString urlValue = aProperty->GetValueAsString();
592 bool hasUrl = !( urlValue.IsEmpty() || urlValue == wxS(
"~" ) );
594 buttons->Finalize( aGrid, aPos );
595 wxSize textSize = buttons->GetPrimarySize();
596 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
597 aProperty->GetValueAsString(),
nullptr, 0,
598 aProperty->GetMaxLength() );
599 wxPGWindowList ret( textCtrl, buttons );
605 wxEvent& aEvent )
const
607 if( aEvent.GetEventType() == wxEVT_BUTTON )
609 wxString filename = aProperty->GetValue().GetString();
611 if( filename.IsEmpty() || filename == wxS(
"~" ) )
613 wxFileDialog openFileDialog(
m_frame,
_(
"Open file" ), wxS(
"" ), wxS(
"" ),
614 _(
"All Files" ) + wxS(
" (*.*)|*.*" ),
615 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
619 if( openFileDialog.ShowModal() == wxID_OK )
621 filename = openFileDialog.GetPath();
622 aGrid->ChangePropertyValue( aProperty, wxString::Format( wxS(
"file://%s" ),
632 if( wxObject* src = aEvent.GetEventObject() )
634 wxString newUrl = aProperty->GetValueAsString();
635 bool hasUrl = !( newUrl.IsEmpty() || newUrl == wxS(
"~" ) );
638 if( wxWindow* win = wxDynamicCast( src, wxWindow ) )
640 if( wxBitmapButton* bb = wxDynamicCast( win, wxBitmapButton ) )
642 bb->SetBitmap( bmp );
644 else if( wxButton* b = wxDynamicCast( win, wxButton ) )
648 else if( wxWindow* parent = win->GetParent() )
650 if( wxPGMultiButton* buttons = wxDynamicCast( parent, wxPGMultiButton ) )
652 wxWindow* btn0 = buttons->GetButton( 0 );
653 if( wxBitmapButton* bb0 = wxDynamicCast( btn0, wxBitmapButton ) )
654 bb0->SetBitmap( bmp );
655 else if( wxButton* b0 = wxDynamicCast( btn0, wxButton ) )
656 b0->SetBitmap( bmp );
664 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)
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.