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
251 ret = new PGPROPERTY_NET( aProperty->Choices() );
252 break;
253
254 default:
255 wxFAIL;
257 /* fall through */
259 {
260 // Create a corresponding wxPGProperty
261 size_t typeId = aProperty->TypeHash();
262
263 // Enum property
264 if( aProperty->HasChoices() )
265 {
266 const_cast<PROPERTY_BASE*>( aProperty )->TranslateChoices();
267
268 // I do not know why enum property takes a non-const reference to wxPGChoices..
269 ret = new wxEnumProperty( wxPG_LABEL, wxPG_LABEL,
270 const_cast<wxPGChoices&>( aProperty->Choices() ) );
271 }
272 else if( typeId == TYPE_HASH( int ) || typeId == TYPE_HASH( long ) )
273 {
274 ret = new wxIntProperty();
275 }
276 else if( typeId == TYPE_HASH( unsigned int ) || typeId == TYPE_HASH( unsigned long ) )
277 {
278 ret = new wxUIntProperty();
279 }
280 else if( typeId == TYPE_HASH( float ) || typeId == TYPE_HASH( double ) )
281 {
282 ret = new wxFloatProperty();
283 }
284 else if( typeId == TYPE_HASH( bool ) )
285 {
286 ret = new PGPROPERTY_BOOL();
287 }
288 else if( typeId == TYPE_HASH( wxString ) )
289 {
290 ret = new PGPROPERTY_STRING();
291 }
292 else if( typeId == TYPE_HASH( COLOR4D ) )
293 {
294 ret = new PGPROPERTY_COLOR4D();
295 }
296 else
297 {
298 wxFAIL_MSG( wxString::Format( wxS( "Property %s not supported by PGPropertyFactory" ),
299 aProperty->Name() ) );
300 ret = new wxPropertyCategory();
301 ret->Enable( false );
302 }
303
304 break;
305 }
306 }
307
308 if( ret )
309 {
310 ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
311 ret->SetName( aProperty->Name() );
312 ret->SetHelpString( wxGetTranslation( aProperty->Name() ) );
313 ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
314 }
315
316 return ret;
317}
318
319
322 m_parentFrame( aParentFrame ),
323 m_coordType( aCoordType )
324{
325}
326
327
331
332
333#if wxCHECK_VERSION( 3, 3, 0 )
334bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
335 wxPGPropValFormatFlags aFlags ) const
336#else
337bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
338 int aFlags ) const
339#endif
340{
341 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
342}
343
344
345#if wxCHECK_VERSION( 3, 3, 0 )
346wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant,
347 wxPGPropValFormatFlags aFlags ) const
348#else
349wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const
350#endif
351{
352 if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
353 {
354 double distanceIU = aVariant.GetDouble();
355 ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
356 distanceIU = transforms.ToDisplay( distanceIU, m_coordType );
357 return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
358 }
359
360 long distanceIU;
361
362 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
363 {
364 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
365
366 if( !variantData->Value().has_value() )
367 return wxEmptyString;
368
369 distanceIU = variantData->Value().value();
370 }
371 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
372 {
373 distanceIU = aVariant.GetLong();
374 }
375 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_ULONGLONG )
376 {
377 distanceIU = static_cast<long>( aVariant.GetULongLong().GetValue() );
378 }
379 else
380 {
381 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
382 return wxEmptyString;
383 }
384
385 ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
386
387 distanceIU = transforms.ToDisplay( static_cast<long long int>( distanceIU ), m_coordType );
388
389 return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
390}
391
392
394 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
395 m_parentFrame( aParentFrame )
396{
397}
398
399
400#if wxCHECK_VERSION( 3, 3, 0 )
401bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
402 wxPGPropValFormatFlags aArgFlags ) const
403#else
404bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
405#endif
406{
407 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_AREA::StringToValue should not be used." ) );
408}
409
410
411#if wxCHECK_VERSION( 3, 3, 0 )
412wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
413#else
414wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, int aArgFlags ) const
415#endif
416{
417 wxLongLongNative areaIU;
418
419 if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
420 {
421 areaIU = aVariant.GetLongLong();
422 }
423 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
424 {
425 areaIU = wxLongLongNative( aVariant.GetLong() );
426 }
427 else
428 {
429 wxFAIL_MSG( wxString::Format( wxS( "Unexpected variant type in PGPROPERTY_AREA: %s" ),
430 aVariant.GetType() ) );
431 return wxEmptyString;
432 }
433
434 return m_parentFrame->StringFromValue( areaIU.ToDouble(), true, EDA_DATA_TYPE::AREA );
435}
436
437
439{
440 return nullptr;
441}
442
443
445 wxUIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
446 PGPROPERTY_DISTANCE( aParentFrame, ORIGIN_TRANSFORMS::NOT_A_COORD )
447{
448}
449
450
451bool PGPROPERTY_SIZE::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
452{
453 if( aValue.GetType() == wxT( "std::optional<int>" ) )
454 {
455 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aValue.GetData() );
456
457 if( !data->Value().has_value() )
458 return wxEmptyString;
459
460 wxVariant value( data->Value().value() );
461 return wxUIntProperty::ValidateValue( value, aValidationInfo );
462 }
463
464 return wxUIntProperty::ValidateValue( aValue, aValidationInfo );
465}
466
467
469{
470 return nullptr;
471}
472
473
475 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
476 PGPROPERTY_DISTANCE( aParentFrame, aCoordType )
477{
478}
479
480
482{
483 return nullptr;
484}
485
486
488 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 )
489{
490 SetEditor( PG_RATIO_EDITOR::EDITOR_NAME );
491}
492
493
494const wxPGEditor* PGPROPERTY_RATIO::DoGetEditorClass() const
495{
496 wxCHECK_MSG( m_customEditor, wxPGEditor_TextCtrl,
497 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_RATIO!" ) );
498 return m_customEditor;
499}
500
501
502#if wxCHECK_VERSION( 3, 3, 0 )
503bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
504 wxPGPropValFormatFlags aArgFlags ) const
505#else
506bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
507#endif
508{
509 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
510}
511
512
513#if wxCHECK_VERSION( 3, 3, 0 )
514wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
515#else
516wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, int aArgFlags ) const
517#endif
518{
519 double value;
520
521 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
522 {
523 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
524
525 if( !variantData->Value().has_value() )
526 return wxEmptyString;
527
528 value = variantData->Value().value();
529 }
530 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
531 {
532 value = aVariant.GetDouble();
533 }
534 else
535 {
536 wxFAIL_MSG( wxT( "Expected double (or std::optional<double>) value type" ) );
537 return wxEmptyString;
538 }
539
540 return wxString::Format( wxS( "%g" ), value );
541}
542
543
544bool PGPROPERTY_RATIO::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
545{
546 if( aValue.GetType() == wxT( "std::optional<double>" ) )
547 {
548 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aValue.GetData() );
549
550 if( !data->Value().has_value() )
551 return wxEmptyString;
552
553 wxVariant value( data->Value().value() );
554 return wxFloatProperty::ValidateValue( value, aValidationInfo );
555 }
556
557 return wxFloatProperty::ValidateValue( aValue, aValidationInfo );
558}
559
560
562{
563 return nullptr;
564}
565
566
567#if wxCHECK_VERSION( 3, 3, 0 )
568bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
569 wxPGPropValFormatFlags aArgFlags ) const
570#else
571bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
572#endif
573{
574 double value = 0.0;
575
576 if( !aText.ToDouble( &value ) )
577 {
578 aVariant.MakeNull();
579 return true;
580 }
581
582 value *= m_scale;
583
584 if( aVariant.IsNull() || aVariant.GetDouble() != value )
585 {
586 aVariant = value;
587 return true;
588 }
589
590 return false;
591}
592
593
594#if wxCHECK_VERSION( 3, 3, 0 )
595wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
596#else
597wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) const
598#endif
599{
600 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
601 {
602 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
603
604 if( variantData->Value().has_value() )
605 return wxString::Format( wxS( "%g\u00B0" ), variantData->Value().value() / m_scale );
606 else
607 return wxEmptyString;
608 }
609 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
610 {
611 return wxString::Format( wxS( "%g\u00B0" ), aVariant.GetDouble() / m_scale );
612 }
613 else if( aVariant.GetType() == wxS( "EDA_ANGLE" ) )
614 {
615 wxString ret;
616 static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
617 return ret;
618 }
619 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
620 {
621 return wxString::Format( wxS( "%g\u00B0" ), (double) aVariant.GetLong() / m_scale );
622 }
623 else
624 {
625 wxCHECK_MSG( false, wxEmptyString, wxS( "Unexpected variant type in PGPROPERTY_ANGLE" ) );
626 }
627}
628
629
631{
632 return nullptr;
633}
634
635
637{
638 wxSize size( 16, -1 );
639
640 if( wxPropertyGrid* pg = GetGrid() )
641 size = pg->FromDIP( size );
642
643 return size;
644}
645
646
647void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect,
648 wxPGPaintData& aPaintData )
649{
650 int index = aPaintData.m_choiceItem;
651
652 if( index < 0 )
653 index = GetIndex();
654
655 // GetIndex can return -1 when the control hasn't been set up yet
656 if( index < 0 || index >= static_cast<int>( GetChoices().GetCount() ) )
657 return;
658
659 wxColour color = GetColor( GetChoices().GetValue( index ) );
660
661 if( color == wxNullColour )
662 return;
663
664 aDC.SetPen( *wxTRANSPARENT_PEN );
665 aDC.SetBrush( wxBrush( color ) );
666 aDC.DrawRectangle( aRect );
667
668 aPaintData.m_drawnWidth = aRect.width;
669}
670
671
672#if wxCHECK_VERSION( 3, 3, 0 )
673wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, wxPGPropValFormatFlags aFlags ) const
674#else
675wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
676#endif
677{
678 if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
679 return wxEmptyString;
680
681 return UnescapeString( aValue.GetString() );
682}
683
684
685#if wxCHECK_VERSION( 3, 3, 0 )
686bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
687 wxPGPropValFormatFlags aArgFlags ) const
688#else
689bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString, int aFlags ) const
690#endif
691{
692 aVariant = EscapeString( aString, CTX_QUOTED_STR );
693 return true;
694}
695
696
697PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) :
698 wxBoolProperty( aLabel, aName, aValue )
699{
701}
702
703
704const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
705{
706 wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
707 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_BOOL!" ) );
708 return m_customEditor;
709}
710
711
712PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
713 COLOR4D aValue, COLOR4D aBackgroundColor ) :
714 wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
715 m_backgroundColor( aBackgroundColor )
716{
717 SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
718#if wxCHECK_VERSION( 3, 3, 1 )
719 SetFlag( wxPGFlags::NoEditor );
720#elif wxCHECK_VERSION( 3, 3, 0 )
721 SetFlag( wxPGPropertyFlags::NoEditor );
722#else
723 SetFlag( wxPG_PROP_NOEDITOR );
724#endif
725}
726
727
728#if wxCHECK_VERSION( 3, 3, 0 )
729bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
730 wxPGPropValFormatFlags aArgFlags ) const
731#else
732bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString, int aFlags ) const
733#endif
734{
735 aVariant.SetData( new COLOR4D_VARIANT_DATA( aString ) );
736 return true;
737}
738
739
740#if wxCHECK_VERSION( 3, 3, 0 )
741wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, wxPGPropValFormatFlags aFlags ) const
742#else
743wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) const
744#endif
745{
746 wxString ret;
747
748 if( aValue.IsType( wxS( "COLOR4D" ) ) )
749 static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
750 else
751 return wxStringProperty::ValueToString( aValue, aFlags );
752
753 return ret;
754}
755
756
758 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
759 m_parentFrame( aParentFrame )
760{
761}
762
763
764#if wxCHECK_VERSION( 3, 3, 0 )
765bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText,
766 wxPGPropValFormatFlags aArgFlags ) const
767#else
768bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
769#endif
770{
771 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
772}
773
774
775#if wxCHECK_VERSION( 3, 3, 0 )
776wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
777#else
778wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant, int aArgFlags ) const
779#endif
780{
781 int value;
782
783 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
784 {
785 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
786
787 if( !variantData->Value().has_value() )
788 return wxEmptyString;
789
790 value = variantData->Value().value();
791 }
792 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
793 {
794 value = static_cast<int>( aVariant.GetInteger() );
795 }
796 else
797 {
798 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
799 return wxEmptyString;
800 }
801
802 return m_parentFrame->StringFromValue( value, true, EDA_DATA_TYPE::TIME );
803}
804
805
806bool PGPROPERTY_TIME::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
807{
808 return true;
809}
810
811
813{
814 return nullptr;
815}
816
817
818PGPROPERTY_NET::PGPROPERTY_NET( const wxPGChoices& aChoices ) :
819 wxEnumProperty( wxPG_LABEL, wxPG_LABEL, const_cast<wxPGChoices&>( aChoices ) )
820{
821 SetEditor( wxS( "PG_NET_SELECTOR_EDITOR" ) );
822}
823
824
825const wxPGEditor* PGPROPERTY_NET::DoGetEditorClass() const
826{
827 wxCHECK_MSG( m_customEditor, wxPGEditor_Choice,
828 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_NET!" ) );
829
830 return m_customEditor;
831}
int index
bool Write(wxString &aString) const override
static wxVariantData * VariantDataFactory(const wxAny &aAny)
static wxVariantData * VariantDataFactory(const wxAny &aAny)
bool Write(wxString &aString) const override
The base class for create windows for drawing purpose.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
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
double m_scale
< Scale factor to convert between raw and displayed value
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
EDA_DRAW_FRAME * m_parentFrame
const wxPGEditor * DoGetEditorClass() const override
PGPROPERTY_BOOL(const wxString &aLabel=wxPG_LABEL, const wxString &aName=wxPG_LABEL, bool aValue=false)
KIGFX::COLOR4D m_backgroundColor
Used for rendering colors with opacity.
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
EDA_DRAW_FRAME * m_parentFrame
wxString DistanceToString(wxVariant &aVariant, int aArgFlags=0) const
bool StringToDistance(wxVariant &aVariant, const wxString &aText, int aArgFlags=0) const
virtual ~PGPROPERTY_DISTANCE()=0
ORIGIN_TRANSFORMS::COORD_TYPES_T m_coordType
PGPROPERTY_DISTANCE(EDA_DRAW_FRAME *aParentFrame, ORIGIN_TRANSFORMS::COORD_TYPES_T aCoordType)
PGPROPERTY_NET(const wxPGChoices &aChoices=wxPGChoices())
const wxPGEditor * DoGetEditorClass() const override
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
EDA_DRAW_FRAME * m_parentFrame
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)
virtual size_t TypeHash() const =0
Return type-id of the property type.
PROPERTY_DISPLAY Display() const
Definition property.h:308
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition property.h:311
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:246
const wxString & Name() const
Definition property.h:220
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition property.h:226
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)
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:74
PROPERTY_DISPLAY
Common property types.
Definition property.h:61
@ PT_DEGREE
Angle expressed in degrees.
Definition property.h:66
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_RATIO
Definition property.h:68
@ PT_DECIDEGREE
Angle expressed in decidegrees.
Definition property.h:67
@ PT_AREA
Area expressed in distance units-squared (mm/inch)
Definition property.h:64
@ PT_DEFAULT
Default property for a given type.
Definition property.h:62
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
@ PT_NET
Net selection property.
Definition property.h:70
@ PT_TIME
Time expressed in ps.
Definition property.h:69
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
Custom text control validator definitions.