KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pg_properties.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KICAD, a free EDA CAD application.
3 *
4 * Copyright (C) 2020-2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.TXT for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <wx/dc.h>
23#include <wx/propgrid/propgrid.h>
24
25#include <macros.h>
26#include <validators.h>
27#include <eda_draw_frame.h>
28#include <eda_units.h>
35#include <properties/property.h>
36#include <string_utils.h>
38
39
40class wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
41{
42public:
44 : wxAnyToVariantRegistration( factory )
45 {
46 }
47
48public:
49 static bool IsSameClass(const wxAnyValueType* otherType)
50 {
51 return AreSameClasses( *s_instance.get(), *otherType );
52 }
53
54 static wxAnyValueType* GetInstance()
55 {
56 return s_instance.get();
57 }
58
59 virtual wxAnyValueType* GetAssociatedType() override
60 {
62 }
63private:
64 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
65 {
66 return wxTypeId(a) == wxTypeId(b);
67 }
68
69 static wxAnyValueTypeScopedPtr s_instance;
70};
71
72
74 new wxAnyValueTypeImpl<std::optional<int>>() );
75
76
78 s_wxAnyToSTD_OPTIONAL_INT_VARIANTRegistration(
80
81
82class wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
83{
84public:
86 : wxAnyToVariantRegistration( factory )
87 {
88 }
89
90public:
91 static bool IsSameClass(const wxAnyValueType* otherType)
92 {
93 return AreSameClasses( *s_instance.get(), *otherType );
94 }
95
96 static wxAnyValueType* GetInstance()
97 {
98 return s_instance.get();
99 }
100
101 virtual wxAnyValueType* GetAssociatedType() override
102 {
104 }
105private:
106 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
107 {
108 return wxTypeId(a) == wxTypeId(b);
109 }
110
111 static wxAnyValueTypeScopedPtr s_instance;
112};
113
114
116 new wxAnyValueTypeImpl<std::optional<double>>() );
117
118
120 s_wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistration(
122
123
124class wxAnyToEDA_ANGLE_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
125{
126public:
127 wxAnyToEDA_ANGLE_VARIANTRegistrationImpl( wxVariantDataFactory factory )
128 : wxAnyToVariantRegistration( factory )
129 {
130 }
131
132public:
133 static bool IsSameClass(const wxAnyValueType* otherType)
134 {
135 return AreSameClasses( *s_instance.get(), *otherType );
136 }
137
138 static wxAnyValueType* GetInstance()
139 {
140 return s_instance.get();
141 }
142
143 virtual wxAnyValueType* GetAssociatedType() override
144 {
146 }
147private:
148 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
149 {
150 return wxTypeId(a) == wxTypeId(b);
151 }
152
153 static wxAnyValueTypeScopedPtr s_instance;
154};
155
156
157wxAnyValueTypeScopedPtr
158 wxAnyToEDA_ANGLE_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<EDA_ANGLE>() );
159
160
162 s_wxAnyToEDA_ANGLE_VARIANTRegistration( &EDA_ANGLE_VARIANT_DATA::VariantDataFactory );
163
164
165class wxAnyToCOLOR4D_VARIANTRegistrationImpl : public wxAnyToVariantRegistration
166{
167public:
168 wxAnyToCOLOR4D_VARIANTRegistrationImpl( wxVariantDataFactory factory )
169 : wxAnyToVariantRegistration( factory )
170 {
171 }
172
173public:
174 static bool IsSameClass(const wxAnyValueType* otherType)
175 {
176 return AreSameClasses( *s_instance.get(), *otherType );
177 }
178
179 static wxAnyValueType* GetInstance()
180 {
181 return s_instance.get();
182 }
183
184 virtual wxAnyValueType* GetAssociatedType() override
185 {
187 }
188private:
189 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
190 {
191 return wxTypeId(a) == wxTypeId(b);
192 }
193
194 static wxAnyValueTypeScopedPtr s_instance;
195};
196
197
199 new wxAnyValueTypeImpl<KIGFX::COLOR4D>() );
200
201
203 s_wxAnyToCOLOR4D_VARIANTRegistration( &COLOR4D_VARIANT_DATA::VariantDataFactory );
204
205
206wxPGProperty* PGPropertyFactory( const PROPERTY_BASE* aProperty, EDA_DRAW_FRAME* aFrame )
207{
208 wxPGProperty* ret = nullptr;
209 PROPERTY_DISPLAY display = aProperty->Display();
210
211 switch( display )
212 {
214 ret = new PGPROPERTY_TIME( aFrame );
215 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
216 break;
217
219 ret = new PGPROPERTY_SIZE( aFrame );
220 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
221 break;
222
224 ret = new PGPROPERTY_AREA( aFrame );
225 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
226 break;
227
229 ret = new PGPROPERTY_COORD( aFrame, aProperty->CoordType() );
230 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
231 break;
232
235 {
237
238 if( display == PROPERTY_DISPLAY::PT_DECIDEGREE )
239 prop->SetScale( 10.0 );
240
241 ret = prop;
242 ret->SetEditor( PG_UNIT_EDITOR::BuildEditorName( aFrame ) );
243 break;
244 }
245
247 ret = new PGPROPERTY_RATIO();
248 break;
249
250 default:
251 wxFAIL;
253 /* fall through */
255 {
256 // Create a corresponding wxPGProperty
257 size_t typeId = aProperty->TypeHash();
258
259 // Enum property
260 if( aProperty->HasChoices() )
261 {
262 // I do not know why enum property takes a non-const reference to wxPGChoices..
263 ret = new wxEnumProperty( wxPG_LABEL, wxPG_LABEL,
264 const_cast<wxPGChoices&>( aProperty->Choices() ) );
265 }
266 else if( typeId == TYPE_HASH( int ) || typeId == TYPE_HASH( long ) )
267 {
268 ret = new wxIntProperty();
269 }
270 else if( typeId == TYPE_HASH( unsigned int ) || typeId == TYPE_HASH( unsigned long ) )
271 {
272 ret = new wxUIntProperty();
273 }
274 else if( typeId == TYPE_HASH( float ) || typeId == TYPE_HASH( double ) )
275 {
276 ret = new wxFloatProperty();
277 }
278 else if( typeId == TYPE_HASH( bool ) )
279 {
280 ret = new PGPROPERTY_BOOL();
281 }
282 else if( typeId == TYPE_HASH( wxString ) )
283 {
284 ret = new PGPROPERTY_STRING();
285 }
286 else if( typeId == TYPE_HASH( COLOR4D ) )
287 {
288 ret = new PGPROPERTY_COLOR4D();
289 }
290 else
291 {
292 wxFAIL_MSG( wxString::Format( wxS( "Property %s not supported by PGPropertyFactory" ),
293 aProperty->Name() ) );
294 ret = new wxPropertyCategory();
295 ret->Enable( false );
296 }
297
298 break;
299 }
300 }
301
302 if( ret )
303 {
304 ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
305 ret->SetName( aProperty->Name() );
306 ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
307 ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
308 }
309
310 return ret;
311}
312
313
316 m_parentFrame( aParentFrame ),
317 m_coordType( aCoordType )
318{
319}
320
321
323{
324}
325
326
327#if wxCHECK_VERSION( 3, 3, 0 )
328bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
329 wxPGPropValFormatFlags aFlags ) const
330#else
331bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
332 int aFlags ) const
333#endif
334{
335 // TODO(JE): Are there actual use cases for this?
336 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
337}
338
339
340#if wxCHECK_VERSION( 3, 3, 0 )
341wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant,
342 wxPGPropValFormatFlags aFlags ) const
343#else
344wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const
345#endif
346{
347 long distanceIU;
348
349 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
350 {
351 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
352
353 if( !variantData->Value().has_value() )
354 return wxEmptyString;
355
356 distanceIU = variantData->Value().value();
357 }
358 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
359 {
360 distanceIU = aVariant.GetLong();
361 }
362 else
363 {
364 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
365 return wxEmptyString;
366 }
367
368 ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
369
370 distanceIU = transforms.ToDisplay( static_cast<long long int>( distanceIU ), m_coordType );
371
372 return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
373}
374
375
377 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
378 m_parentFrame( aParentFrame )
379{
380}
381
382
383#if wxCHECK_VERSION( 3, 3, 0 )
384bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
385 wxPGPropValFormatFlags aArgFlags ) const
386#else
387bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
388 int aArgFlags ) const
389#endif
390{
391 // TODO(JE): Are there actual use cases for this?
392 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_AREA::StringToValue should not be used." ) );
393}
394
395
396#if wxCHECK_VERSION( 3, 3, 0 )
397wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant,
398 wxPGPropValFormatFlags aArgFlags ) const
399#else
400wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, int aArgFlags ) const
401#endif
402{
403 wxCHECK( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG, wxEmptyString );
404
405 wxLongLongNative areaIU = aVariant.GetLongLong();
406
407 return m_parentFrame->StringFromValue( areaIU.ToDouble(), true, EDA_DATA_TYPE::AREA );
408}
409
410
412{
413 return nullptr;
414}
415
416
418 wxUIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
419 PGPROPERTY_DISTANCE( aParentFrame, ORIGIN_TRANSFORMS::NOT_A_COORD )
420{
421}
422
423
424bool PGPROPERTY_SIZE::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
425{
426 if( aValue.GetType() == wxT( "std::optional<int>" ) )
427 {
428 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aValue.GetData() );
429
430 if( !data->Value().has_value() )
431 return wxEmptyString;
432
433 wxVariant value( data->Value().value() );
434 return wxUIntProperty::ValidateValue( value, aValidationInfo );
435 }
436
437 return wxUIntProperty::ValidateValue( aValue, aValidationInfo );
438}
439
440
442{
443 return nullptr;
444}
445
446
449 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
450 PGPROPERTY_DISTANCE( aParentFrame, aCoordType )
451{
452}
453
454
456{
457 return nullptr;
458}
459
460
462 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 )
463{
464 SetEditor( PG_RATIO_EDITOR::EDITOR_NAME );
465}
466
467
468const wxPGEditor* PGPROPERTY_RATIO::DoGetEditorClass() const
469{
470 wxCHECK_MSG( m_customEditor, wxPGEditor_TextCtrl,
471 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_RATIO!" ) );
472 return m_customEditor;
473}
474
475
476#if wxCHECK_VERSION( 3, 3, 0 )
477bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
478 wxPGPropValFormatFlags aArgFlags ) const
479#else
480bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
481 int aArgFlags ) const
482#endif
483{
484 // TODO(JE): Are there actual use cases for this?
485 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
486}
487
488
489#if wxCHECK_VERSION( 3, 3, 0 )
490wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant,
491 wxPGPropValFormatFlags aArgFlags ) const
492#else
493wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, int aArgFlags ) const
494#endif
495{
496 double value;
497
498 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
499 {
500 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
501
502 if( !variantData->Value().has_value() )
503 return wxEmptyString;
504
505 value = variantData->Value().value();
506 }
507 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
508 {
509 value = aVariant.GetDouble();
510 }
511 else
512 {
513 wxFAIL_MSG( wxT( "Expected double (or std::optional<double>) value type" ) );
514 return wxEmptyString;
515 }
516
517 return wxString::Format( wxS( "%g" ), value );
518}
519
520
521bool PGPROPERTY_RATIO::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
522{
523 if( aValue.GetType() == wxT( "std::optional<double>" ) )
524 {
525 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aValue.GetData() );
526
527 if( !data->Value().has_value() )
528 return wxEmptyString;
529
530 wxVariant value( data->Value().value() );
531 return wxFloatProperty::ValidateValue( value, aValidationInfo );
532 }
533
534 return wxFloatProperty::ValidateValue( aValue, aValidationInfo );
535}
536
537
539{
540 return nullptr;
541}
542
543
544#if wxCHECK_VERSION( 3, 3, 0 )
545bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
546 wxPGPropValFormatFlags aArgFlags ) const
547#else
548bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
549 int aArgFlags ) const
550#endif
551{
552 double value = 0.0;
553
554 if( !aText.ToDouble( &value ) )
555 {
556 aVariant.MakeNull();
557 return true;
558 }
559
560 value *= m_scale;
561
562 if( aVariant.IsNull() || aVariant.GetDouble() != value )
563 {
564 aVariant = value;
565 return true;
566 }
567
568 return false;
569}
570
571
572#if wxCHECK_VERSION( 3, 3, 0 )
573wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant,
574 wxPGPropValFormatFlags aArgFlags ) const
575#else
576wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) const
577#endif
578{
579 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
580 {
581 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
582
583 if( variantData->Value().has_value() )
584 return wxString::Format( wxS( "%g\u00B0" ), variantData->Value().value() / m_scale );
585 else
586 return wxEmptyString;
587 }
588 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
589 {
590 return wxString::Format( wxS( "%g\u00B0" ), aVariant.GetDouble() / m_scale );
591 }
592 else if( aVariant.GetType() == wxS( "EDA_ANGLE" ) )
593 {
594 wxString ret;
595 static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
596 return ret;
597 }
598 else
599 {
600 wxCHECK_MSG( false, wxEmptyString, wxS( "Unexpected variant type in PGPROPERTY_ANGLE" ) );
601 }
602}
603
604
606{
607 return nullptr;
608}
609
610
612{
613 wxSize size( 16, -1 );
614
615 if( wxPropertyGrid* pg = GetGrid() )
616 size = pg->FromDIP( size );
617
618 return size;
619}
620
621
622void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
623 wxPGPaintData& aPaintData )
624{
625 int index = aPaintData.m_choiceItem;
626
627 if( index < 0 )
628 index = GetIndex();
629
630 // GetIndex can return -1 when the control hasn't been set up yet
631 if( index < 0 || index >= static_cast<int>( GetChoices().GetCount() ) )
632 return;
633
634 wxColour color = GetColor( GetChoices().GetValue( index ) );
635
636 if( color == wxNullColour )
637 return;
638
639 aDC.SetPen( *wxTRANSPARENT_PEN );
640 aDC.SetBrush( wxBrush( color ) );
641 aDC.DrawRectangle( aRect );
642
643 aPaintData.m_drawnWidth = aRect.width;
644}
645
646
647#if wxCHECK_VERSION( 3, 3, 0 )
648wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue,
649 wxPGPropValFormatFlags aFlags ) const
650#else
651wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
652#endif
653{
654 if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
655 return wxEmptyString;
656
657 return UnescapeString( aValue.GetString() );
658}
659
660
661#if wxCHECK_VERSION( 3, 3, 0 )
662bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
663 wxPGPropValFormatFlags aArgFlags ) const
664#else
665bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
666 int aFlags ) const
667#endif
668{
669 aVariant = EscapeString( aString, CTX_QUOTED_STR );
670 return true;
671}
672
673
674PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) :
675 wxBoolProperty( aLabel, aName, aValue )
676{
678}
679
680
681const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
682{
683 wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
684 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_BOOL!" ) );
685 return m_customEditor;
686}
687
688
689PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
690 COLOR4D aValue, COLOR4D aBackgroundColor ) :
691 wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
692 m_backgroundColor( aBackgroundColor )
693{
694 SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
695#if wxCHECK_VERSION( 3, 3, 0 )
696 SetFlag( wxPGPropertyFlags::NoEditor );
697#else
698 SetFlag( wxPG_PROP_NOEDITOR );
699#endif
700}
701
702
703#if wxCHECK_VERSION( 3, 3, 0 )
704bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
705 wxPGPropValFormatFlags aArgFlags ) const
706#else
707bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
708 int aFlags ) const
709#endif
710{
711 aVariant.SetData( new COLOR4D_VARIANT_DATA( aString ) );
712 return true;
713}
714
715
716#if wxCHECK_VERSION( 3, 3, 0 )
717wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue,
718 wxPGPropValFormatFlags aFlags ) const
719#else
720wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) const
721#endif
722{
723 wxString ret;
724
725 if( aValue.IsType( wxS( "COLOR4D" ) ) )
726 static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
727 else
728 return wxStringProperty::ValueToString( aValue, aFlags );
729
730 return ret;
731}
732
733
735 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
736 m_parentFrame( aParentFrame )
737{
738}
739
740
741#if wxCHECK_VERSION( 3, 3, 0 )
742bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText,
743 wxPGPropValFormatFlags aArgFlags ) const
744#else
745bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText,
746 int aArgFlags ) const
747#endif
748{
749 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
750}
751
752
753#if wxCHECK_VERSION( 3, 3, 0 )
754wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant,
755 wxPGPropValFormatFlags aArgFlags ) const
756#else
757wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant, int aArgFlags ) const
758#endif
759{
760 int value;
761
762 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
763 {
764 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
765
766 if( !variantData->Value().has_value() )
767 return wxEmptyString;
768
769 value = variantData->Value().value();
770 }
771 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
772 {
773 value = static_cast<int>( aVariant.GetInteger() );
774 }
775 else
776 {
777 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
778 return wxEmptyString;
779 }
780
781 return m_parentFrame->StringFromValue( value, true, EDA_DATA_TYPE::TIME );
782}
783
784
785bool PGPROPERTY_TIME::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
786{
787 return true;
788}
789
790
792{
793 return nullptr;
794}
int color
Definition: DXF_plotter.cpp:63
static wxVariantData * VariantDataFactory(const wxAny &aAny)
static wxVariantData * VariantDataFactory(const wxAny &aAny)
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
A class to perform either relative or absolute display origin transforms for a single axis of a point...
virtual int ToDisplay(int aValue, COORD_TYPES_T aCoordType) const
COORD_TYPES_T
The supported Display Origin Transform types.
A wxEnumProperty that displays a color next to the enum value.
void SetScale(double aScale)
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxValidator * DoGetValidator() const override
Do not perform PG validation; the UX is not what we want.
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
PGPROPERTY_AREA(EDA_DRAW_FRAME *aParentFrame)
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
wxValidator * DoGetValidator() const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
const wxPGEditor * DoGetEditorClass() const override
PGPROPERTY_BOOL(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, bool aValue=false)
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aFlags=0) const override
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
PGPROPERTY_COLOR4D(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, KIGFX::COLOR4D aValue=KIGFX::COLOR4D::UNSPECIFIED, KIGFX::COLOR4D aBackground=KIGFX::COLOR4D::UNSPECIFIED)
wxColour GetColor(int aValue)
wxSize OnMeasureImage(int aItem=-1) const override
void OnCustomPaint(wxDC &aDC, const wxRect &aRect, wxPGPaintData &aPaintData) override
Customized wxPGProperty class to handle angles.
PGPROPERTY_COORD(EDA_DRAW_FRAME *aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
wxValidator * DoGetValidator() const override
wxString DistanceToString(wxVariant &aVariant, int aArgFlags=0) const
bool StringToDistance(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const
virtual ~PGPROPERTY_DISTANCE()=0
PGPROPERTY_DISTANCE(EDA_DRAW_FRAME *aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
const wxPGEditor * DoGetEditorClass() const override
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
PGPROPERTY_SIZE(EDA_DRAW_FRAME *aParentFrame)
wxString ValueToString(wxVariant &aValue, int aFlags=0) const override
bool StringToValue(wxVariant &aVariant, const wxString &aString, int aFlags=0) const override
bool StringToValue(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const override
wxString ValueToString(wxVariant &aVariant, int aArgFlags=0) const override
PGPROPERTY_TIME(EDA_DRAW_FRAME *aParentFrame)
wxValidator * DoGetValidator() const override
bool ValidateValue(wxVariant &aValue, wxPGValidationInfo &aValidationInfo) const override
static const wxString EDITOR_NAME
Definition: pg_editors.h:75
static const wxString EDITOR_NAME
Definition: pg_editors.h:91
static const wxString EDITOR_NAME
Definition: pg_editors.h:117
static wxString BuildEditorName(EDA_DRAW_FRAME *aFrame)
Definition: pg_editors.cpp:52
virtual size_t TypeHash() const =0
Return type-id of the property type.
PROPERTY_DISPLAY Display() const
Definition: property.h:290
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition: property.h:293
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition: property.h:242
const wxString & Name() const
Definition: property.h:218
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition: property.h:224
std::optional< double > Value() const
static wxVariantData * VariantDataFactory(const wxAny &aAny)
std::optional< int > Value() const
static wxVariantData * VariantDataFactory(const wxAny &aAny)
wxAnyToCOLOR4D_VARIANTRegistrationImpl(wxVariantDataFactory factory)
static wxAnyValueType * GetInstance()
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool IsSameClass(const wxAnyValueType *otherType)
virtual wxAnyValueType * GetAssociatedType() override
static wxAnyValueTypeScopedPtr s_instance
static wxAnyValueTypeScopedPtr s_instance
static bool IsSameClass(const wxAnyValueType *otherType)
virtual wxAnyValueType * GetAssociatedType() override
wxAnyToEDA_ANGLE_VARIANTRegistrationImpl(wxVariantDataFactory factory)
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool IsSameClass(const wxAnyValueType *otherType)
wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl(wxVariantDataFactory factory)
virtual wxAnyValueType * GetAssociatedType() override
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static bool AreSameClasses(const wxAnyValueType &a, const wxAnyValueType &b)
static wxAnyValueTypeScopedPtr s_instance
virtual wxAnyValueType * GetAssociatedType() override
static bool IsSameClass(const wxAnyValueType *otherType)
wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl(wxVariantDataFactory factory)
This file contains miscellaneous commonly used macros and functions.
#define KI_FALLTHROUGH
The KI_FALLTHROUGH macro is to be used when switch statement cases should purposely fallthrough from ...
Definition: macros.h:83
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
Customized abstract wxPGProperty class to handle coordinate/size units.
#define TYPE_HASH(x)
Definition: property.h:72
PROPERTY_DISPLAY
Common property types.
Definition: property.h:60
@ PT_DEGREE
Angle expressed in degrees.
Definition: property.h:65
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition: property.h:64
@ PT_RATIO
Definition: property.h:67
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition: property.h:66
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition: property.h:63
@ PT_DEFAULT
Default property for a given type.
Definition: property.h:61
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition: property.h:62
@ PT_TIME
Time expressed in ps.
Definition: property.h:68
wxString UnescapeString(const wxString &aSource)
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_QUOTED_STR
Definition: string_utils.h:57
Custom text control validator definitions.