bool Nau::validateUserAttribName(std::string context, std::string name) { AttribSet *attribs = getAttribs(context); // invalid context if (attribs == NULL) return false; std::unique_ptr<Attribute> &a = attribs->get(name); if (a->getName() == "NO_ATTR") return true; else return false; }
bool ToolBar::addDir(const std::string &windowName, const std::string &varLabel, const std::string &varType, const std::string &varContext, const std::string &component, int id) { // window does not exist if (m_Windows.count(windowName) == 0) return false; AttribSet *attrSet = NAU->getAttribs(varType); // type is not valid if (attrSet == NULL) return false; Enums::DataType dt; int attr; attrSet->getPropTypeAndId(component, &dt, &attr); // component is not valid if (attr == -1) return false; if (dt != Enums::VEC4) return false; NauVar *clientData = new NauVar(); clientData->type = varType; clientData->context = varContext; clientData->component = component; std::string name = varLabel; name.erase(remove_if(name.begin(), name.end(), [](char c) { return !isalpha(c); }), name.end()); char s[256]; if (name != varLabel) { sprintf(s, " label='%s' ", varLabel.c_str()); } else s[0] = '\0'; if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(m_Windows[windowName].second, varLabel.c_str(), TW_TYPE_DIR3F, SetDirCallBack, GetDirCallBack, clientData, s) == 1); else return (TwAddVarCB(m_Windows[windowName].second, varLabel.c_str(), TW_TYPE_DIR3F, NULL, GetDirCallBack, clientData, s) == 1); }
ProgramBlockValue::ProgramBlockValue (std::string name, std::string block, std::string type, std::string context,std::string valueof, int id, bool inSpecML) : m_Cardinality (0) { IUniformBlock *aBlock = UNIFORMBLOCKMANAGER->getBlock(name); //if (aBlock == NULL) { // NAU_THROW("Uniform Block %s is not defined", block.c_str()); //} //if (!aBlock->hasUniform(name)) // NAU_THROW("Uniform Block %s does not hava a uniform named %s", block.c_str(), name.c_str()); //if (!aBlock->getUniformType(name) != Enums::getType(type)) // NAU_THROW("Uniform Block %s, uniform %s - type does not match", block.c_str(), name.c_str()); int attr; nau::Enums::DataType dt; m_InSpecML = inSpecML; m_TypeString = type; m_ValueOfString = valueof; m_Name = name; m_Block = block; m_Context = context; m_Id = id; std::string what; //if (type == "CURRENT") // what = context; //else what = type; AttribSet *attrSet = NAU->getAttribs(what); if (attrSet == NULL) NAU_THROW("Exception creating a program value. name=%s, type=%s, context=%s, component=%s, int=%d", name.c_str(), type.c_str(), context.c_str(), valueof.c_str(), id); attrSet->getPropTypeAndId(valueof, &dt, &attr); m_ValueOf = attr; m_ValueType = dt; m_Cardinality = Enums::getCardinality(dt); void *def = (void *)attrSet->get(attr, dt)->getDefault().get(); if (def != NULL) m_Values = def; else m_Values = (void *)malloc(Enums::getSize(dt)); }
ProgramValue::ProgramValue (std::string name, std::string type, std::string context,std::string valueof, int id, bool inSpecML) : m_Cardinality (0) { int attr; nau::Enums::DataType dt; m_Values = NULL; // m_IntValue = NULL; m_InSpecML = inSpecML; m_TypeString = type; m_Name = name; m_Context = context; m_ValueOfString = valueof; m_Id = id; std::string what; //if (type == "CURRENT") // what = context; //else what = type; AttribSet *attrSet = NAU->getAttribs(what); if (attrSet == NULL) NAU_THROW("Exception creating a program value. name=%s, type=%s, context=%s, component=%s, int=%d", name.c_str(), type.c_str(), context.c_str(), valueof.c_str(), id); attrSet->getPropTypeAndId(valueof, &dt, &attr); m_ValueOf = attr; m_ValueType = dt; m_Cardinality = Enums::getCardinality(dt); void *def = (void *)attrSet->get(attr,dt)->getDefault().get(); if (def != NULL) m_Values = def; else m_Values = (void *)malloc(Enums::getSize(dt)); }
void PropertyManager::updateProp(wxPropertyGridManager *pg, std::string prop, AttribSet &attribs, AttributeValues *attribVal) { std::unique_ptr<Attribute> &a = attribs.get(prop); Enums::DataType dt; wxPGProperty *pgProp; int id,i; unsigned int ui; uivec2 uiv2; uivec3 uiv3; bool b; std::string s; attribs.getPropTypeAndId(prop, &dt, &id); float f; vec2 v; vec3 v3; vec4 v4; bvec4 b4; mat3 m3; mat4 m4; Attribute::Semantics sem = a->getSemantics(); wxColour col; wxVariant variant; switch (dt) { case Enums::ENUM: pgProp = pg->GetProperty(wxString(prop)); i = pgProp->GetValue().GetInteger(); attribVal->setPrope((AttributeValues::EnumProperty)id, i); break; case Enums::BOOL: pgProp = pg->GetProperty(wxString(prop)); b = pgProp->GetValue().GetBool(); attribVal->setPropb((AttributeValues::BoolProperty)id, b); break; case Enums::BVEC4: s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); b4.x = pgProp->GetValue().GetBool(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); b4.y = pgProp->GetValue().GetBool(); s = prop + "." + "z"; pgProp = pg->GetProperty(wxString(s)); b4.z = pgProp->GetValue().GetBool(); s = prop + "." + "w"; pgProp = pg->GetProperty(wxString(s)); b4.w = pgProp->GetValue().GetBool(); attribVal->setPropb4((AttributeValues::Bool4Property)id, b4); break; case Enums::INT: pgProp = pg->GetProperty(wxString(prop)); i = pgProp->GetValue().GetInteger(); attribVal->setPropi((AttributeValues::IntProperty)id, i); break; case Enums::UINT: pgProp = pg->GetProperty(wxString(prop)); ui = pgProp->GetValue().GetInteger(); attribVal->setPropui((AttributeValues::UIntProperty)id, ui); break; case Enums::UIVEC2: s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); uiv2.x = pgProp->GetValue().GetDouble(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); uiv2.y = pgProp->GetValue().GetDouble(); attribVal->setPropui2((AttributeValues::UInt2Property)id, uiv2); break; case Enums::UIVEC3: s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); uiv3.x = pgProp->GetValue().GetDouble(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); uiv3.y = pgProp->GetValue().GetDouble(); s = prop + "." + "w"; pgProp = pg->GetProperty(wxString(s)); uiv3.z = pgProp->GetValue().GetDouble(); attribVal->setPropui3((AttributeValues::UInt3Property)id, uiv3); break; case Enums::FLOAT: pgProp = pg->GetProperty(wxString(prop)); f = pgProp->GetValue().GetDouble(); attribVal->setPropf((AttributeValues::FloatProperty)id, f); break; case Enums::VEC2: s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); v.x = pgProp->GetValue().GetDouble(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); v.y = pgProp->GetValue().GetDouble(); attribVal->setPropf2((AttributeValues::Float2Property)id, v); break; case Enums::VEC3: s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); v3.x = pgProp->GetValue().GetDouble(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); v3.y = pgProp->GetValue().GetDouble(); s = prop + "." + "w"; pgProp = pg->GetProperty(wxString(s)); v3.z = pgProp->GetValue().GetDouble(); attribVal->setPropf3((AttributeValues::Float3Property)id, v3); break; case Enums::VEC4: if (sem == Attribute::COLOR) { s = prop + ".RGB"; variant = pg->GetPropertyValue(wxString(s)); col << variant; v4.x = col.Red()/255.0; v4.y = col.Green() / 255.0; v4.z = col.Blue() / 255.0; s = prop + ".Alpha" ; pgProp = pg->GetProperty(wxString(s)); v4.w = pgProp->GetValue().GetDouble(); } else { s = prop + "." + "x"; pgProp = pg->GetProperty(wxString(s)); v4.x = pgProp->GetValue().GetDouble(); s = prop + "." + "y"; pgProp = pg->GetProperty(wxString(s)); v4.y = pgProp->GetValue().GetDouble(); s = prop + "." + "z"; pgProp = pg->GetProperty(wxString(s)); v4.z = pgProp->GetValue().GetDouble(); s = prop + "." + "w"; pgProp = pg->GetProperty(wxString(s)); v4.w = pgProp->GetValue().GetDouble(); } attribVal->setPropf4((AttributeValues::Float4Property)id, v4); break; case Enums::MAT3: s = prop + "." + "Row0.x"; pgProp = pg->GetProperty(wxString(s)); m3.set(0,0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row0.y"; pgProp = pg->GetProperty(wxString(s)); m3.set(0, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row0.z"; pgProp = pg->GetProperty(wxString(s)); m3.set(0, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.x"; pgProp = pg->GetProperty(wxString(s)); m3.set(1, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.y"; pgProp = pg->GetProperty(wxString(s)); m3.set(1, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.z"; pgProp = pg->GetProperty(wxString(s)); m3.set(1, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.x"; pgProp = pg->GetProperty(wxString(s)); m3.set(2, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.y"; pgProp = pg->GetProperty(wxString(s)); m3.set(2, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.z"; pgProp = pg->GetProperty(wxString(s)); m3.set(2, 2, pgProp->GetValue().GetDouble()); attribVal->setPropm3((AttributeValues::Mat3Property)id, m3); break; case Enums::MAT4: s = prop + "." + "Row0.x"; pgProp = pg->GetProperty(wxString(s)); m4.set(0, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row0.y"; pgProp = pg->GetProperty(wxString(s)); m4.set(0, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row0.z"; pgProp = pg->GetProperty(wxString(s)); m4.set(0, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row0.w"; pgProp = pg->GetProperty(wxString(s)); m4.set(0, 3, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.x"; pgProp = pg->GetProperty(wxString(s)); m4.set(1, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.y"; pgProp = pg->GetProperty(wxString(s)); m4.set(1, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.z"; pgProp = pg->GetProperty(wxString(s)); m4.set(1, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row1.w"; pgProp = pg->GetProperty(wxString(s)); m4.set(1, 3, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.x"; pgProp = pg->GetProperty(wxString(s)); m4.set(2, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.y"; pgProp = pg->GetProperty(wxString(s)); m4.set(2, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.z"; pgProp = pg->GetProperty(wxString(s)); m4.set(2, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row2.w"; pgProp = pg->GetProperty(wxString(s)); m4.set(2, 3, pgProp->GetValue().GetDouble()); s = prop + "." + "Row3.x"; pgProp = pg->GetProperty(wxString(s)); m4.set(3, 0, pgProp->GetValue().GetDouble()); s = prop + "." + "Row3.y"; pgProp = pg->GetProperty(wxString(s)); m4.set(3, 1, pgProp->GetValue().GetDouble()); s = prop + "." + "Row3.z"; pgProp = pg->GetProperty(wxString(s)); m4.set(3, 2, pgProp->GetValue().GetDouble()); s = prop + "." + "Row3.w"; pgProp = pg->GetProperty(wxString(s)); m4.set(3, 3, pgProp->GetValue().GetDouble()); attribVal->setPropm4((AttributeValues::Mat4Property)id, m4); break; default: assert(false && "Missing data type on property manager: updateProp"); } }
bool ToolBar::addVar(const std::string &windowName, const std::string &varLabel, const std::string &varType, const std::string &varContext, const std::string &component, int id, const std::string def) { // window does not exist if (m_Windows.count(windowName) == 0) return false; AttribSet *attrSet = NAU->getAttribs(varType); // type is not valid if (attrSet == NULL) return false; Enums::DataType dt; int attr; attrSet->getPropTypeAndId(component, &dt, &attr); // component is invalid if (attr == -1) return false; std::unique_ptr<Attribute> &attribute = NAU->getAttribute(varType, component); std::shared_ptr<math::Data> &max = attribute->getMax(); std::shared_ptr<math::Data> &min = attribute->getMin(); std::string defLocal = ""; if (min) defLocal += " min=" + Enums::pointerToString(dt, min->getPtr()) + " "; if (max) defLocal += "max=" + Enums::pointerToString(dt, max->getPtr()); defLocal = def + defLocal; NauVar *clientData = new NauVar(); clientData->type = varType; clientData->context = varContext; clientData->component = component; m_ClientDataVec.push_back(clientData); TwBar *t = m_Windows[windowName].second; std::string name = varLabel; name.erase(remove_if(name.begin(), name.end(), [](char c) { return !isalpha(c); }), name.end()); char s[256]; s[0] = '\0'; if (name != varLabel) { sprintf(s, " label='%s' ", varLabel.c_str()); } if (defLocal != "") { sprintf(s, "%s%s ", s, defLocal.c_str()); } //else // s[0] = '\0'; switch (dt) { case nau::Enums::INT: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), TW_TYPE_INT32, SetIntCallBack, GetIntCallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), TW_TYPE_INT32, NULL, GetIntCallBack, clientData, s) == 1); break; case nau::Enums::UINT: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), TW_TYPE_UINT32, SetUIntCallBack, GetUIntCallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), TW_TYPE_UINT32, NULL, GetUIntCallBack, clientData, s) == 1); break; case nau::Enums::UIVEC2: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), UIVec2, SetCallBack, GetUIVec2CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), UIVec2, NULL, GetUIVec2CallBack, clientData, s) == 1); break; case nau::Enums::UIVEC3: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), UIVec3, SetCallBack, GetUIVec3CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), UIVec3, NULL, GetUIVec3CallBack, clientData, s) == 1); break; case nau::Enums::BOOL: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), TW_TYPE_BOOLCPP, SetBoolCallBack, GetBoolCallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), TW_TYPE_BOOLCPP, NULL, GetBoolCallBack, clientData, s) == 1); break; case nau::Enums::BVEC4: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), BVec4, SetCallBack, GetBVec4CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), BVec4, NULL, GetBVec4CallBack, clientData, s) == 1); break; case nau::Enums::FLOAT: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), TW_TYPE_FLOAT, SetFloatCallBack, GetFloatCallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), TW_TYPE_FLOAT, NULL, GetFloatCallBack, clientData, s) == 1); break; case nau::Enums::VEC2: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), Vec2, SetCallBack, GetVec2CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), Vec2, NULL, GetVec2CallBack, clientData, s) == 1); break; case nau::Enums::VEC3: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), Vec3, SetCallBack, GetVec3CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), Vec3, NULL, GetVec3CallBack, clientData, s) == 1); break; case nau::Enums::VEC4: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), Vec4, SetCallBack, GetVec4CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), Vec4, NULL, GetVec4CallBack, clientData, s) == 1); break; case nau::Enums::MAT3: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), Mat3, SetCallBack, GetMat3CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), Mat3, NULL, GetMat3CallBack, clientData, s) == 1); break; case nau::Enums::MAT4: if (attrSet->get(attr, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), Mat4, SetCallBack, GetMat4CallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), Mat4, NULL, GetMat4CallBack, clientData, s) == 1); break; case nau::Enums::ENUM: { const std::vector<std::string> &vs = NAU->getAttribs(varType)->getListString(id); const std::vector<int> &vi = NAU->getAttribs(varType)->getListValues(id); TwEnumVal *enums; enums = (TwEnumVal *)malloc(vi.size() * sizeof(TwEnumVal)); for (int i = 0; i < vi.size(); ++i) { enums[i].Label = vs[i].c_str(); enums[i].Value = vi[i]; } TwType options = TwDefineEnum(name.c_str(), enums, (unsigned int)vi.size()); if (attrSet->get(id, dt)->getReadOnlyFlag() == false) return (TwAddVarCB(t, name.c_str(), options, SetIntCallBack, GetIntCallBack, clientData, s) == 1); else return (TwAddVarCB(t, name.c_str(), options, NULL, GetIntCallBack, clientData, s) == 1); } break; default: assert(false && "Missing type in ToolBar::addVar"); return false; } return true; }