33#include <wx/filedlg.h>
40#include <wx/bmpbuttn.h>
94 const wxPoint& aPos,
const wxSize& aSize )
const
98#if wxCHECK_VERSION( 3, 3, 0 )
99 wxString
text = aProperty->GetValueAsString( wxPGPropValFormatFlags::EditableValue );
101 wxString
text = aProperty->GetValueAsString( wxPG_EDITABLE_VALUE );
103 wxWindow* win = aPropGrid->GenerateEditorTextCtrl( aPos, aSize,
text,
nullptr, 0,
104 aProperty->GetMaxLength() );
105 wxPGWindowList ret( win,
nullptr );
138 wxVariant var = aProperty->GetValue();
141 if( aProperty->IsValueUnspecified() )
143 if( wxTextEntry* textEntry =
dynamic_cast<wxTextEntry*
>( aCtrl ) )
151 if( var.GetType() == wxT(
"EDA_ANGLE" ) )
157 else if( !aProperty->IsValueUnspecified() )
159 double scale = angleProp->GetScale();
163 else if( var.GetType() == wxT(
"std::optional<int>" ) )
167 if( variantData->OptValue().has_value() )
168 m_unitBinder->ChangeValue( variantData->OptValue().value() );
172 else if( var.GetType() == wxPG_VARIANT_TYPE_LONG )
176 else if( var.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
178 m_unitBinder->ChangeDoubleValue( var.GetLongLong().ToDouble() );
180 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
184 else if( var.GetType() == wxT(
"EDA_ANGLE" ) )
189 else if( !aProperty->IsValueUnspecified() )
191 wxFAIL_MSG( wxT(
"PG_UNIT_EDITOR should only be used with numeric properties!" ) );
197 wxWindow* aCtrl, wxEvent& aEvent )
const
199 if( aEvent.GetEventType() == wxEVT_LEFT_UP )
201 if( wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl ) )
203 if( !textCtrl->HasFocus() )
205 textCtrl->SelectAll();
211 return wxPGTextCtrlEditor::OnEvent( aPropGrid, aProperty, aCtrl, aEvent );
216 wxWindow* aCtrl )
const
221 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
222 wxCHECK_MSG( textCtrl,
false,
"PG_UNIT_EDITOR requires a text control!" );
223 wxString textVal = textCtrl->GetValue();
225 if( textVal == wxT(
"<...>" ) )
241 if( aVariant.GetType() == wxT(
"EDA_ANGLE" ) )
244 changed = ( aVariant.IsNull() || angle != ad->
Angle() );
257 changed = ( aVariant.IsNull() || scaledValue != aVariant.GetDouble() );
261 aVariant = scaledValue;
269 changed = ( aVariant.IsNull() ||
result != aVariant.GetLongLong() );
277 else if( aVariant.GetType() == wxT(
"std::optional<int>" ) )
280 std::optional<int>
result;
284 changed = ( aVariant.IsNull() || variantData->OptValue().has_value() );
288 aVariant = wxVariant( std::optional<int>() );
295 changed = ( aVariant.IsNull() ||
result != variantData->OptValue() );
299 aVariant = wxVariant(
result );
307 changed = ( aVariant.IsNull() ||
result != aVariant.GetLong() );
317 if( !changed && aVariant.IsNull() )
331 const wxPoint& aPos,
const wxSize& aSize )
const
336 if( aProperty->IsValueUnspecified() )
337 aProperty->SetValueFromInt( 0 );
339 return wxPGCheckBoxEditor::CreateControls( aGrid, aProperty, aPos, aSize );
344 wxEvent& aEvent )
const
351 const wxPoint& aPos,
const wxSize& aSize )
const
362 colorProp->GetBackgroundColor(), defColor,
364 editor->SetPosition( aPos );
368 wxString propName = colorProp->GetName();
370 editor->Bind( COLOR_SWATCH_CHANGED,
371 [=]( wxCommandEvent& aEvt )
373 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
380 aGrid->ChangePropertyValue( prop, val );
384#if wxCHECK_VERSION( 3, 3, 0 )
385 if( aGrid->GetInternalFlags() & wxPropertyGrid::wxPG_FL_ACTIVATION_BY_CLICK )
387 if( aGrid->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK )
393 editor->GetNewSwatchColor();
395 wxPGProperty* prop = aGrid->GetPropertyByName( propName );
398 aGrid->DrawItem( prop );
408 if(
auto swatch =
dynamic_cast<COLOR_SWATCH*
>( aCtrl ) )
418 if( aVariant.IsType( wxS(
"COLOR4D" ) ) )
421 color = data->
Color();
435 wxWindow* aCtrl )
const
437 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
438 wxCHECK_MSG( textCtrl,
false,
"PG_RATIO_EDITOR requires a text control!" );
439 wxString textVal = textCtrl->GetValue();
441 if( textVal == wxT(
"<...>" ) )
449 if( aVariant.GetType() == wxT(
"std::optional<double>" ) )
453 if( textVal.empty() )
455 changed = ( aVariant.IsNull() || variantData->OptValue().has_value() );
458 aVariant = wxVariant( std::optional<double>() );
464 double dblValue = 0.0;
465 textVal.ToDouble( &dblValue );
466 std::optional<double>
result( dblValue );
467 changed = ( aVariant.IsNull() ||
result != variantData->OptValue() );
471 aVariant = wxVariant(
result );
472 textCtrl->SetValue( wxString::Format( wxS(
"%g" ), dblValue ) );
481 textVal.ToDouble( &
result );
482 changed = ( aVariant.IsNull() ||
result != aVariant.GetDouble() );
487 textCtrl->SetValue( wxString::Format( wxS(
"%g" ),
result ) );
492 if( !changed && aVariant.IsNull() )
501 wxTextCtrl* textCtrl =
dynamic_cast<wxTextCtrl*
>( aCtrl );
502 wxVariant var = aProperty->GetValue();
504 wxCHECK_MSG( textCtrl, , wxT(
"PG_RATIO_EDITOR must be used with a textCtrl!" ) );
506 if( var.GetType() == wxT(
"std::optional<double>" ) )
511 if( variantData->OptValue().has_value() )
512 strValue = wxString::Format( wxS(
"%g" ), variantData->OptValue().value() );
516 else if( var.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
518 textCtrl->ChangeValue( wxString::Format( wxS(
"%g" ), var.GetDouble() ) );
520 else if( !aProperty->IsValueUnspecified() )
522 wxFAIL_MSG( wxT(
"PG_RATIO_EDITOR should only be used with scale-free numeric properties!" ) );
558 const wxPoint& aPos,
const wxSize& aSize )
const
560 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
562 buttons->Finalize( aGrid, aPos );
563 wxSize textSize = buttons->GetPrimarySize();
564 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize, aProperty->GetValueAsString(),
565 nullptr, 0, aProperty->GetMaxLength() );
566 wxPGWindowList ret( textCtrl, buttons );
572 wxEvent& aEvent )
const
574 if( aEvent.GetEventType() == wxEVT_BUTTON )
579 wxString fpid = aProperty->GetValue().GetString();
586 if( !symbolNetlist.empty() )
589 frame->KiwayMailIn( event );
592 if( frame->ShowModal( &fpid,
m_frame ) )
593 aGrid->ChangePropertyValue( aProperty, fpid );
601 return wxPGTextCtrlEditor::OnEvent( aGrid, aProperty, aCtrl, aEvent );
628 const wxPoint& aPos,
const wxSize& aSize )
const
630 wxPGMultiButton* buttons =
new wxPGMultiButton( aGrid, aSize );
632 wxString urlValue = aProperty->GetValueAsString();
633 bool hasUrl = !( urlValue.IsEmpty() || urlValue == wxS(
"~" ) );
635 buttons->Finalize( aGrid, aPos );
636 wxSize textSize = buttons->GetPrimarySize();
637 wxWindow* textCtrl = aGrid->GenerateEditorTextCtrl( aPos, textSize,
638 aProperty->GetValueAsString(),
nullptr, 0,
639 aProperty->GetMaxLength() );
640 wxPGWindowList ret( textCtrl, buttons );
646 wxEvent& aEvent )
const
648 if( aEvent.GetEventType() == wxEVT_BUTTON )
653 wxString filename = aProperty->GetValue().GetString();
655 if( filename.IsEmpty() || filename == wxS(
"~" ) )
657 wxFileDialog openFileDialog(
m_frame,
_(
"Open file" ), wxS(
"" ), wxS(
"" ),
658 _(
"All Files" ) + wxS(
" (*.*)|*.*" ),
659 wxFD_OPEN | wxFD_FILE_MUST_EXIST );
663 if( openFileDialog.ShowModal() == wxID_OK )
665 filename = openFileDialog.GetPath();
666 aGrid->ChangePropertyValue( aProperty, wxString::Format( wxS(
"file://%s" ),
676 if( wxObject* src = aEvent.GetEventObject() )
678 wxString newUrl = aProperty->GetValueAsString();
679 bool hasUrl = !( newUrl.IsEmpty() || newUrl == wxS(
"~" ) );
682 if( wxWindow* win = wxDynamicCast( src, wxWindow ) )
684 if( wxBitmapButton* bb = wxDynamicCast( win, wxBitmapButton ) )
686 bb->SetBitmap( bmp );
688 else if( wxButton* b = wxDynamicCast( win, wxButton ) )
692 else if( wxWindow* parent = win->GetParent() )
694 if( wxPGMultiButton* buttons = wxDynamicCast( parent, wxPGMultiButton ) )
696 wxWindow* btn0 = buttons->GetButton( 0 );
697 if( wxBitmapButton* bb0 = wxDynamicCast( btn0, wxBitmapButton ) )
698 bb0->SetBitmap( bmp );
699 else if( wxButton* b0 = wxDynamicCast( btn0, wxButton ) )
700 b0->SetBitmap( bmp );
708 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.
Customized wxPGProperty class to handle angles.
Customized abstract wxPGProperty class to handle coordinate/size units.
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.
Functions to provide common constants and other functions to assist in making a consistent UI.
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...