void SymbolPropertySetting::OnPropertyGridChange(const std::string& name, const wxAny& value) { if (value.IsNull()) return; bool dirty = true; if (name == wxT("Name")) { if (m_sym) { std::string name = wxANY_AS(value, wxString); m_sym->name = name; m_sym->SetName(name); RefreshPanelSJ::Instance()->Refresh(); } else if (m_name) { *m_name = wxANY_AS(value, wxString); } } else if (name == "Tag") { if (m_sym) { m_sym->tag = wxANY_AS(value, wxString); } else if (m_tag) { *m_tag = wxANY_AS(value, wxString); } } else { dirty = false; } if (dirty) { SetCanvasDirtySJ::Instance()->SetDirty(); } }
void PropertySetting::SplitString2Double(const wxAny& value, double* x, double* y) { std::vector<std::string> str; StringHelper::Split(wxANY_AS(value, wxString).ToStdString().c_str(), ";", str); if (str.size() == 2) { StringHelper::FromString(str[0], *x); StringHelper::FromString(str[1], *y); } }
void wxAnyTestCase::As() { // // Test getting C++ data from wxAny without dynamic conversion signed char a = wxANY_AS(m_anySignedChar1, signed char); CPPUNIT_ASSERT(a == (signed int)15); signed short b = wxANY_AS(m_anySignedShort1, signed short); CPPUNIT_ASSERT(b == (signed int)15); signed int c = wxANY_AS(m_anySignedInt1, signed int); CPPUNIT_ASSERT(c == (signed int)15); signed long d = wxANY_AS(m_anySignedLong1, signed long); CPPUNIT_ASSERT(d == (signed int)15); #ifdef wxLongLong_t wxLongLong_t e = wxANY_AS(m_anySignedLongLong1, wxLongLong_t); CPPUNIT_ASSERT(e == (signed int)15); #endif unsigned char f = wxANY_AS(m_anyUnsignedChar1, unsigned char); CPPUNIT_ASSERT(f == (unsigned int)15); unsigned short g = wxANY_AS(m_anyUnsignedShort1, unsigned short); CPPUNIT_ASSERT(g == (unsigned int)15); unsigned int h = wxANY_AS(m_anyUnsignedInt1, unsigned int); CPPUNIT_ASSERT(h == (unsigned int)15); unsigned long i = wxANY_AS(m_anyUnsignedLong1, unsigned long); CPPUNIT_ASSERT(i == (unsigned int)15); #ifdef wxLongLong_t wxULongLong_t j = wxANY_AS(m_anyUnsignedLongLong1, wxULongLong_t); CPPUNIT_ASSERT(j == (unsigned int)15); #endif wxString k = wxANY_AS(m_anyStringString1, wxString); CPPUNIT_ASSERT(k == "abc"); wxString l = wxANY_AS(m_anyCharString1, wxString); const char* cptr = wxANY_AS(m_anyCharString1, const char*); CPPUNIT_ASSERT(l == "abc"); CPPUNIT_ASSERT(cptr); wxString m = wxANY_AS(m_anyWcharString1, wxString); const wchar_t* wcptr = wxANY_AS(m_anyWcharString1, const wchar_t*); CPPUNIT_ASSERT(wcptr); CPPUNIT_ASSERT(m == "abc"); bool n = wxANY_AS(m_anyBool1, bool); CPPUNIT_ASSERT(n); // Make sure the stored float that comes back is -identical-. // So do not use delta comparison here. float o = wxANY_AS(m_anyFloatDouble1, float); CPPUNIT_ASSERT_EQUAL(o, TEST_FLOAT_CONST); double p = wxANY_AS(m_anyDoubleDouble1, double); CPPUNIT_ASSERT_EQUAL(p, TEST_DOUBLE_CONST); wxUniChar chr = wxANY_AS(m_anyUniChar1, wxUniChar); CPPUNIT_ASSERT(chr == 'A'); wxDateTime q = wxANY_AS(m_anyDateTime1, wxDateTime); CPPUNIT_ASSERT(q == m_testDateTime); wxObject* r = wxANY_AS(m_anyWxObjectPtr1, wxObject*); CPPUNIT_ASSERT(r == dummyWxObjectPointer); void* s = wxANY_AS(m_anyVoidPtr1, void*); CPPUNIT_ASSERT(s == dummyVoidPointer); }
std::string PropertySetting::GetPGType(wxPropertyGrid* pg) const { if (!pg) { return ""; } wxPGProperty* property = pg->GetProperty(TYPE_NAME.c_str()); if (!property) { return ""; } wxAny value = property->GetValue(); return wxANY_AS(value, wxString).ToStdString().c_str(); }
void TextPropertySetting::onPropertyGridChange(const wxString& name, const wxAny& value) { if (value.IsNull()) return; if (name == "Text") { wxString text = wxANY_AS(value, wxString); m_sprite->setText(text.ToStdString()); } else if (name == "Size") { m_sprite->setSize(wxANY_AS(value, float)); }
void JointPropertySetting::OnPropertyGridChange(const std::string& name, const wxAny& value) { if (value.IsNull()) return; bool dirty = true; if (name == wxT("Name")) m_joint->m_name = wxANY_AS(value, wxString); else if (name == wxT("collideConnected")) m_joint->m_collide_connected = wxANY_AS(value, bool); switch (m_joint->m_type) { case Joint::e_revoluteJoint: OnPropertyGridChange(static_cast<RevoluteJoint*>(m_joint), name, value); break; case Joint::e_prismaticJoint: OnPropertyGridChange(static_cast<PrismaticJoint*>(m_joint), name, value); break; case Joint::e_distanceJoint: OnPropertyGridChange(static_cast<DistanceJoint*>(m_joint), name, value); break; case Joint::e_pulleyJoint: OnPropertyGridChange(static_cast<PulleyJoint*>(m_joint), name, value); break; case Joint::e_gearJoint: OnPropertyGridChange(static_cast<GearJoint*>(m_joint), name, value); break; case Joint::e_wheelJoint: OnPropertyGridChange(static_cast<WheelJoint*>(m_joint), name, value); break; case Joint::e_weldJoint: OnPropertyGridChange(static_cast<WeldJoint*>(m_joint), name, value); break; case Joint::e_frictionJoint: OnPropertyGridChange(static_cast<FrictionJoint*>(m_joint), name, value); break; case Joint::e_ropeJoint: OnPropertyGridChange(static_cast<RopeJoint*>(m_joint), name, value); break; case Joint::e_motorJoint: OnPropertyGridChange(static_cast<MotorJoint*>(m_joint), name, value); break; } if (dirty) { ee::SetCanvasDirtySJ::Instance()->SetDirty(); } }
wxVariantData* wxVariantDataErrorCode::VariantDataFactory(const wxAny& any) { return new wxVariantDataErrorCode(wxANY_AS(any, SCODE)); }
wxVariantData* wxVariantDataCurrency::VariantDataFactory(const wxAny& any) { return new wxVariantDataCurrency(wxANY_AS(any, CURRENCY)); }
void wxAnyTestCase::wxVariantConversions() { #if wxUSE_VARIANT // // Test various conversions to and from wxVariant // bool res; // Prepare wxVariants wxVariant vLong(123L); wxVariant vString("ABC"); wxVariant vDouble(TEST_FLOAT_CONST); wxVariant vBool((bool)true); wxVariant vChar('A'); #ifdef wxLongLong_t wxVariant vLongLong(wxLongLong(wxLL(0xAABBBBCCCC))); wxVariant vULongLong(wxULongLong(wxULL(123456))); #endif wxArrayString arrstr; arrstr.push_back("test string"); wxVariant vArrayString(arrstr); wxVariant vDateTime(m_testDateTime); wxVariant vVoidPtr(dummyVoidPointer); wxVariant vCustomType(new wxMyVariantData(MyClass(101))); wxVariant vList; vList.NullList(); vList.Append(15); vList.Append("abc"); // Convert to wxAnys, and then back to wxVariants wxVariant variant; wxAny any(vLong); CPPUNIT_ASSERT(any == 123L); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant == 123L); // Make sure integer variant has correct type information CPPUNIT_ASSERT(variant.GetLong() == 123); CPPUNIT_ASSERT(variant.GetType() == "long"); // Unsigned long wxAny should convert to "ulonglong" wxVariant any = 1000UL; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "ulonglong"); CPPUNIT_ASSERT(variant.GetLong() == 1000); any = vString; CPPUNIT_ASSERT(any == "ABC"); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetString() == "ABC"); // Must be able to build string wxVariant from wxAny built from // string literal any = "ABC"; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "string"); CPPUNIT_ASSERT(variant.GetString() == "ABC"); any = L"ABC"; res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "string"); #if wxUSE_UNICODE CPPUNIT_ASSERT(variant.GetString() == L"ABC"); #endif any = vDouble; double d = wxANY_AS(any, double); CPPUNIT_ASSERT_DOUBLES_EQUAL(d, TEST_FLOAT_CONST, FEQ_DELTA); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT_DOUBLES_EQUAL(variant.GetDouble(), TEST_FLOAT_CONST, FEQ_DELTA); any = vBool; CPPUNIT_ASSERT(wxANY_AS(any, bool) == true); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetBool() == true); any = wxAny(vChar); //CPPUNIT_ASSERT(wxANY_AS(any, wxUniChar) == 'A'); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetChar() == 'A'); #ifdef wxLongLong_t any = wxAny(vLongLong); CPPUNIT_ASSERT(any == wxLL(0xAABBBBCCCC)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "longlong"); CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC))); #if LONG_MAX == wxINT64_MAX // As a sanity check, test that wxVariant of type 'long' converts // seamlessly to 'longlong' (on some 64-bit systems) any = 0xAABBBBCCCCL; res = any.GetAs(&variant); CPPUNIT_ASSERT(variant.GetLongLong() == wxLongLong(wxLL(0xAABBBBCCCC))); #endif any = wxAny(vULongLong); CPPUNIT_ASSERT(any == wxLL(123456)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "ulonglong"); CPPUNIT_ASSERT(variant.GetULongLong() == wxULongLong(wxULL(123456))); #endif // Cannot test equality for the rest, just test that they convert // back correctly. any = wxAny(vArrayString); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); wxArrayString arrstr2 = variant.GetArrayString(); CPPUNIT_ASSERT(arrstr2 == arrstr); any = m_testDateTime; CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime); any = wxAny(vDateTime); CPPUNIT_ASSERT(wxANY_AS(any, wxDateTime) == m_testDateTime); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant == m_testDateTime); any = wxAny(vVoidPtr); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetVoidPtr() == dummyVoidPointer); any = wxAny(vList); CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxAnyList)); wxAnyList anyList = wxANY_AS(any, wxAnyList); CPPUNIT_ASSERT(anyList.GetCount() == 2); CPPUNIT_ASSERT(wxANY_AS((*anyList[0]), int) == 15); CPPUNIT_ASSERT(wxANY_AS((*anyList[1]), wxString) == "abc"); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "list"); CPPUNIT_ASSERT(variant.GetCount() == 2); CPPUNIT_ASSERT(variant[0].GetLong() == 15); CPPUNIT_ASSERT(variant[1].GetString() == "abc"); any = wxAny(vCustomType); CPPUNIT_ASSERT(wxANY_CHECK_TYPE(any, wxVariantData*)); res = any.GetAs(&variant); CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "MyClass"); #endif // wxUSE_VARIANT }