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
19 * along with this program. If not, see <https://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:
43 wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl( wxVariantDataFactory factory ) :
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 }
63
64private:
65 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
66 {
67 return wxTypeId(a) == wxTypeId(b);
68 }
69
70 static wxAnyValueTypeScopedPtr s_instance;
71};
72
73
74wxAnyValueTypeScopedPtr
75wxAnyToSTD_OPTIONAL_INT_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<std::optional<int>>() );
76
77
79 s_wxAnyToSTD_OPTIONAL_INT_VARIANTRegistration( &STD_OPTIONAL_INT_VARIANT_DATA::VariantDataFactory );
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 }
105
106private:
107 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
108 {
109 return wxTypeId(a) == wxTypeId(b);
110 }
111
112 static wxAnyValueTypeScopedPtr s_instance;
113};
114
115
116wxAnyValueTypeScopedPtr
117wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistrationImpl::s_instance( new wxAnyValueTypeImpl<std::optional<double>>() );
118
119
121 s_wxAnyToSTD_OPTIONAL_DOUBLE_VARIANTRegistration( &STD_OPTIONAL_DOUBLE_VARIANT_DATA::VariantDataFactory );
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 }
147
148private:
149 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
150 {
151 return wxTypeId(a) == wxTypeId(b);
152 }
153
154 static wxAnyValueTypeScopedPtr s_instance;
155};
156
157
158wxAnyValueTypeScopedPtr 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 }
188
189private:
190 static bool AreSameClasses(const wxAnyValueType& a, const wxAnyValueType& b)
191 {
192 return wxTypeId(a) == wxTypeId(b);
193 }
194
195 static wxAnyValueTypeScopedPtr s_instance;
196};
197
198
199wxAnyValueTypeScopedPtr wxAnyToCOLOR4D_VARIANTRegistrationImpl::s_instance( 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 const wxString& help = aProperty->HelpString();
311
312 ret->SetLabel( wxGetTranslation( aProperty->Name() ) );
313 ret->SetName( aProperty->Name() );
314 ret->SetHelpString( wxGetTranslation( help.IsEmpty() ? aProperty->Name() : help ) );
315 ret->SetClientData( const_cast<PROPERTY_BASE*>( aProperty ) );
316 }
317
318 return ret;
319}
320
321
324 m_parentFrame( aParentFrame ),
325 m_coordType( aCoordType )
326{
327}
328
329
333
334
335#if wxCHECK_VERSION( 3, 3, 0 )
336bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
337 wxPGPropValFormatFlags aFlags ) const
338#else
339bool PGPROPERTY_DISTANCE::StringToDistance( wxVariant& aVariant, const wxString& aText,
340 int aFlags ) const
341#endif
342{
343 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_DISTANCE::StringToDistance should not be used." ) );
344}
345
346
347#if wxCHECK_VERSION( 3, 3, 0 )
348wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant,
349 wxPGPropValFormatFlags aFlags ) const
350#else
351wxString PGPROPERTY_DISTANCE::DistanceToString( wxVariant& aVariant, int aFlags ) const
352#endif
353{
354 if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
355 {
356 double distanceIU = aVariant.GetDouble();
357 ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
358 distanceIU = transforms.ToDisplay( distanceIU, m_coordType );
359 return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
360 }
361
362 long distanceIU;
363
364 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
365 {
366 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
367
368 if( !variantData->OptValue().has_value() )
369 return wxEmptyString;
370
371 distanceIU = variantData->OptValue().value();
372 }
373 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
374 {
375 distanceIU = aVariant.GetLong();
376 }
377 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
378 {
379 distanceIU = static_cast<long>( aVariant.GetLongLong().GetValue() );
380 }
381 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_ULONGLONG )
382 {
383 distanceIU = static_cast<long>( aVariant.GetULongLong().GetValue() );
384 }
385 else
386 {
387 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
388 return wxEmptyString;
389 }
390
391 ORIGIN_TRANSFORMS& transforms = m_parentFrame->GetOriginTransforms();
392
393 distanceIU = transforms.ToDisplay( static_cast<long long int>( distanceIU ), m_coordType );
394
395 return m_parentFrame->StringFromValue( distanceIU, true, EDA_DATA_TYPE::DISTANCE );
396}
397
398
400 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
401 m_parentFrame( aParentFrame )
402{
403}
404
405
406#if wxCHECK_VERSION( 3, 3, 0 )
407bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText,
408 wxPGPropValFormatFlags aArgFlags ) const
409#else
410bool PGPROPERTY_AREA::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
411#endif
412{
413 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_AREA::StringToValue should not be used." ) );
414}
415
416
417#if wxCHECK_VERSION( 3, 3, 0 )
418wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
419#else
420wxString PGPROPERTY_AREA::ValueToString( wxVariant& aVariant, int aArgFlags ) const
421#endif
422{
423 wxLongLongNative areaIU;
424
425 if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONGLONG )
426 {
427 areaIU = aVariant.GetLongLong();
428 }
429 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
430 {
431 areaIU = wxLongLongNative( aVariant.GetLong() );
432 }
433 else
434 {
435 wxFAIL_MSG( wxString::Format( wxS( "Unexpected variant type in PGPROPERTY_AREA: %s" ), aVariant.GetType() ) );
436 return wxEmptyString;
437 }
438
439 return m_parentFrame->StringFromValue( areaIU.ToDouble(), true, EDA_DATA_TYPE::AREA );
440}
441
442
444{
445 return nullptr;
446}
447
448
450 wxUIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
451 PGPROPERTY_DISTANCE( aParentFrame, ORIGIN_TRANSFORMS::NOT_A_COORD )
452{
453}
454
455
456bool PGPROPERTY_SIZE::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
457{
458 if( aValue.GetType() == wxT( "std::optional<int>" ) )
459 {
460 auto* data = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aValue.GetData() );
461
462 if( !data->OptValue().has_value() )
463 return wxEmptyString;
464
465 wxVariant value( data->OptValue().value() );
466 return wxUIntProperty::ValidateValue( value, aValidationInfo );
467 }
468
469 return wxUIntProperty::ValidateValue( aValue, aValidationInfo );
470}
471
472
474{
475 return nullptr;
476}
477
478
480 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
481 PGPROPERTY_DISTANCE( aParentFrame, aCoordType )
482{
483}
484
485
487{
488 return nullptr;
489}
490
491
493 wxFloatProperty( wxPG_LABEL, wxPG_LABEL, 0 )
494{
495 SetEditor( PG_RATIO_EDITOR::EDITOR_NAME );
496}
497
498
499const wxPGEditor* PGPROPERTY_RATIO::DoGetEditorClass() const
500{
501 wxCHECK_MSG( m_customEditor, wxPGEditor_TextCtrl,
502 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_RATIO!" ) );
503 return m_customEditor;
504}
505
506
507#if wxCHECK_VERSION( 3, 3, 0 )
508bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText,
509 wxPGPropValFormatFlags aArgFlags ) const
510#else
511bool PGPROPERTY_RATIO::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
512#endif
513{
514 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
515}
516
517
518#if wxCHECK_VERSION( 3, 3, 0 )
519wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
520#else
521wxString PGPROPERTY_RATIO::ValueToString( wxVariant& aVariant, int aArgFlags ) const
522#endif
523{
524 double value;
525
526 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
527 {
528 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
529
530 if( !variantData->OptValue().has_value() )
531 return wxEmptyString;
532
533 value = variantData->OptValue().value();
534 }
535 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
536 {
537 value = aVariant.GetDouble();
538 }
539 else
540 {
541 wxFAIL_MSG( wxT( "Expected double (or std::optional<double>) value type" ) );
542 return wxEmptyString;
543 }
544
545 return wxString::Format( wxS( "%g" ), value );
546}
547
548
549bool PGPROPERTY_RATIO::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
550{
551 if( aValue.GetType() == wxT( "std::optional<double>" ) )
552 {
553 auto* data = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aValue.GetData() );
554
555 if( !data->OptValue().has_value() )
556 return wxEmptyString;
557
558 wxVariant value( data->OptValue().value() );
559 return wxFloatProperty::ValidateValue( value, aValidationInfo );
560 }
561
562 return wxFloatProperty::ValidateValue( aValue, aValidationInfo );
563}
564
565
567{
568 return nullptr;
569}
570
571
572#if wxCHECK_VERSION( 3, 3, 0 )
573bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText,
574 wxPGPropValFormatFlags aArgFlags ) const
575#else
576bool PGPROPERTY_ANGLE::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
577#endif
578{
579 double value = 0.0;
580
581 if( !aText.ToDouble( &value ) )
582 {
583 aVariant.MakeNull();
584 return true;
585 }
586
587 value *= m_scale;
588
589 if( aVariant.IsNull() || aVariant.GetDouble() != value )
590 {
591 aVariant = value;
592 return true;
593 }
594
595 return false;
596}
597
598
599#if wxCHECK_VERSION( 3, 3, 0 )
600wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
601#else
602wxString PGPROPERTY_ANGLE::ValueToString( wxVariant& aVariant, int aArgFlags ) const
603#endif
604{
605 if( aVariant.GetType() == wxT( "std::optional<double>" ) )
606 {
607 auto* variantData = static_cast<STD_OPTIONAL_DOUBLE_VARIANT_DATA*>( aVariant.GetData() );
608
609 if( variantData->OptValue().has_value() )
610 return wxString::Format( wxS( "%g\u00B0" ), variantData->OptValue().value() / m_scale );
611 else
612 return wxEmptyString;
613 }
614 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_DOUBLE )
615 {
616 return wxString::Format( wxS( "%g\u00B0" ), aVariant.GetDouble() / m_scale );
617 }
618 else if( aVariant.GetType() == wxS( "EDA_ANGLE" ) )
619 {
620 wxString ret;
621 static_cast<EDA_ANGLE_VARIANT_DATA*>( aVariant.GetData() )->Write( ret );
622 return ret;
623 }
624 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
625 {
626 return wxString::Format( wxS( "%g\u00B0" ), (double) aVariant.GetLong() / m_scale );
627 }
628 else
629 {
630 wxCHECK_MSG( false, wxEmptyString, wxS( "Unexpected variant type in PGPROPERTY_ANGLE" ) );
631 }
632}
633
634
636{
637 return nullptr;
638}
639
640
642{
643 wxSize size( 16, -1 );
644
645 if( wxPropertyGrid* pg = GetGrid() )
646 size = pg->FromDIP( size );
647
648 return size;
649}
650
651
652void PGPROPERTY_COLORENUM::OnCustomPaint( wxDC& aDC, const wxRect& aRect, wxPGPaintData& aPaintData )
653{
654 int index = aPaintData.m_choiceItem;
655
656 if( index < 0 )
657 index = GetIndex();
658
659 // GetIndex can return -1 when the control hasn't been set up yet
660 if( index < 0 || index >= static_cast<int>( GetChoices().GetCount() ) )
661 return;
662
663 wxColour color = GetColor( GetChoices().GetValue( index ) );
664
665 if( color == wxNullColour )
666 return;
667
668 aDC.SetPen( *wxTRANSPARENT_PEN );
669 aDC.SetBrush( wxBrush( color ) );
670 aDC.DrawRectangle( aRect );
671
672 aPaintData.m_drawnWidth = aRect.width;
673}
674
675
676#if wxCHECK_VERSION( 3, 3, 0 )
677wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, wxPGPropValFormatFlags aFlags ) const
678#else
679wxString PGPROPERTY_STRING::ValueToString( wxVariant& aValue, int aFlags ) const
680#endif
681{
682 if( aValue.GetType() != wxPG_VARIANT_TYPE_STRING )
683 return wxEmptyString;
684
685 return UnescapeString( aValue.GetString() );
686}
687
688
689#if wxCHECK_VERSION( 3, 3, 0 )
690bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString,
691 wxPGPropValFormatFlags aArgFlags ) const
692#else
693bool PGPROPERTY_STRING::StringToValue( wxVariant& aVariant, const wxString& aString, int aFlags ) const
694#endif
695{
696 aVariant = EscapeString( aString, CTX_QUOTED_STR );
697 return true;
698}
699
700
701PGPROPERTY_BOOL::PGPROPERTY_BOOL( const wxString& aLabel, const wxString& aName, bool aValue ) :
702 wxBoolProperty( aLabel, aName, aValue )
703{
705}
706
707
708const wxPGEditor* PGPROPERTY_BOOL::DoGetEditorClass() const
709{
710 wxCHECK_MSG( m_customEditor, wxPGEditor_CheckBox,
711 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_BOOL!" ) );
712 return m_customEditor;
713}
714
715
716PGPROPERTY_COLOR4D::PGPROPERTY_COLOR4D( const wxString& aLabel, const wxString& aName,
717 COLOR4D aValue, COLOR4D aBackgroundColor ) :
718 wxStringProperty( aLabel, aName, aValue.ToCSSString() ),
719 m_backgroundColor( aBackgroundColor )
720{
721 SetEditor( PG_COLOR_EDITOR::EDITOR_NAME );
722#if wxCHECK_VERSION( 3, 3, 1 )
723 SetFlag( wxPGFlags::NoEditor );
724#elif wxCHECK_VERSION( 3, 3, 0 )
725 SetFlag( wxPGPropertyFlags::NoEditor );
726#else
727 SetFlag( wxPG_PROP_NOEDITOR );
728#endif
729}
730
731
732#if wxCHECK_VERSION( 3, 3, 0 )
733bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString,
734 wxPGPropValFormatFlags aArgFlags ) const
735#else
736bool PGPROPERTY_COLOR4D::StringToValue( wxVariant& aVariant, const wxString& aString, int aFlags ) const
737#endif
738{
739 aVariant.SetData( new COLOR4D_VARIANT_DATA( aString ) );
740 return true;
741}
742
743
744#if wxCHECK_VERSION( 3, 3, 0 )
745wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, wxPGPropValFormatFlags aFlags ) const
746#else
747wxString PGPROPERTY_COLOR4D::ValueToString( wxVariant& aValue, int aFlags ) const
748#endif
749{
750 wxString ret;
751
752 if( aValue.IsType( wxS( "COLOR4D" ) ) )
753 static_cast<COLOR4D_VARIANT_DATA*>( aValue.GetData() )->Write( ret );
754 else
755 return wxStringProperty::ValueToString( aValue, aFlags );
756
757 return ret;
758}
759
760
762 wxIntProperty( wxPG_LABEL, wxPG_LABEL, 0 ),
763 m_parentFrame( aParentFrame )
764{
765}
766
767
768#if wxCHECK_VERSION( 3, 3, 0 )
769bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText,
770 wxPGPropValFormatFlags aArgFlags ) const
771#else
772bool PGPROPERTY_TIME::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const
773#endif
774{
775 wxCHECK_MSG( false, false, wxS( "PGPROPERTY_RATIO::StringToValue should not be used." ) );
776}
777
778
779#if wxCHECK_VERSION( 3, 3, 0 )
780wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant, wxPGPropValFormatFlags aArgFlags ) const
781#else
782wxString PGPROPERTY_TIME::ValueToString( wxVariant& aVariant, int aArgFlags ) const
783#endif
784{
785 int value;
786
787 if( aVariant.GetType() == wxT( "std::optional<int>" ) )
788 {
789 auto* variantData = static_cast<STD_OPTIONAL_INT_VARIANT_DATA*>( aVariant.GetData() );
790
791 if( !variantData->OptValue().has_value() )
792 return wxEmptyString;
793
794 value = variantData->OptValue().value();
795 }
796 else if( aVariant.GetType() == wxPG_VARIANT_TYPE_LONG )
797 {
798 value = static_cast<int>( aVariant.GetInteger() );
799 }
800 else
801 {
802 wxFAIL_MSG( wxT( "Expected int (or std::optional<int>) value type" ) );
803 return wxEmptyString;
804 }
805
806 return m_parentFrame->StringFromValue( value, true, EDA_DATA_TYPE::TIME );
807}
808
809
810bool PGPROPERTY_TIME::ValidateValue( wxVariant& aValue, wxPGValidationInfo& aValidationInfo ) const
811{
812 return true;
813}
814
815
817{
818 return nullptr;
819}
820
821
822PGPROPERTY_NET::PGPROPERTY_NET( const wxPGChoices& aChoices ) :
823 wxEnumProperty( wxPG_LABEL, wxPG_LABEL, const_cast<wxPGChoices&>( aChoices ) )
824{
825 SetEditor( wxS( "PG_NET_SELECTOR_EDITOR" ) );
826}
827
828
829const wxPGEditor* PGPROPERTY_NET::DoGetEditorClass() const
830{
831 wxCHECK_MSG( m_customEditor, wxPGEditor_Choice,
832 wxT( "Make sure to RegisterEditorClass() for PGPROPERTY_NET!" ) );
833
834 return m_customEditor;
835}
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:101
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.
Customized wxPGProperty class to handle angles.
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
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
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:326
const wxString & HelpString() const
Definition property.h:223
ORIGIN_TRANSFORMS::COORD_TYPES_T CoordType() const
Definition property.h:329
virtual bool HasChoices() const
Return true if this PROPERTY has a limited set of possible values.
Definition property.h:259
const wxString & Name() const
Definition property.h:221
virtual const wxPGChoices & Choices() const
Return a limited set of possible values (e.g.
Definition property.h:239
static wxVariantData * VariantDataFactory(const wxAny &aAny)
std::optional< double > OptValue() const
static wxVariantData * VariantDataFactory(const wxAny &aAny)
std::optional< int > OptValue() const
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:79
wxPGProperty * PGPropertyFactory(const PROPERTY_BASE *aProperty, EDA_DRAW_FRAME *aFrame)
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
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.