Example #1
0
Values Factory::jsonToValues(const Json::Value& values)
{
    Values outValues;

    if (values.isInt())
        outValues.emplace_back(values.asInt());
    else if (values.isDouble())
        outValues.emplace_back(values.asFloat());
    else if (values.isArray())
        for (const auto& v : values)
        {
            if (v.isInt())
                outValues.emplace_back(v.asInt());
            else if (v.isDouble())
                outValues.emplace_back(v.asFloat());
            else if (v.isArray())
                outValues.emplace_back(jsonToValues(v));
            else
                outValues.emplace_back(v.asString());
        }
    else
        outValues.emplace_back(values.asString());

    return outValues;
}
Example #2
0
void GetVal(Json::Value &config, float* setting)
{
	if (config.isNull())
		return;

	*setting = config.asFloat();
}
 bool Deserialize ( const Json::Value& json_val, float & obj_val )
 {
     if ( json_val.isDouble () )
     {
         obj_val = json_val.asFloat ();
         return true;
     }
     return false;
 }
Example #4
0
bool GetFloat32(const Json::Value& value, float32_t* out) {
  if (value.isNull()) {
    return false;
  }
  if (!value.isDouble()) {
    return false;
  }
  *out = value.asFloat();
  return true;
}
Example #5
0
    float JsonUtils::asFloat(const Json::Value &value, float defaultValue)
    {
        float returned = defaultValue;

        if(value.isString())
            returned =  Ogre::StringConverter::parseReal(value.asString(), defaultValue);

        if(value.isNumeric())
            returned = value.asFloat();

        return returned;
    }
std::vector<float> ParserActionParameters::parseVector(Json::Value temp_info){
	std::vector<float> vector;
	if(!temp_info.isNull() && temp_info.isArray()){
		Json::Value value;
		for(int i= 0; i< temp_info.size(); ++i){
			value = temp_info.get(i,"UTF-8");
			if(!value.isNull() && value.isNumeric()){
				vector.push_back(value.asFloat());
			}
		}
	}
	return vector;
}
Example #7
0
bool deserialize(const Json::Value& node, float& f)
{
	if (node.empty())
	{
		std::cout << "Node is empty." << std::endl;
		return false;
	}
	if (!node.isNumeric())
	{
		std::cout << "Node data type is not numeric." << std::endl;
		return false;
	}
	f = node.asFloat();
	return true;
}
Example #8
0
  void AddShape(const Json::Value& shape) {
    Json::Value name = shape["name"];
    Json::Value type = shape["type"];

    std::string shapeType = type.asString();

    btCollisionShape* bulletShape = NULL;

    if (shapeType.compare("cube") == 0) {
      Json::Value wx = shape["wx"];
      Json::Value wy = shape["wy"];
      Json::Value wz = shape["wz"];
      btVector3 halfExtents = btVector3(wx.asFloat(), wy.asFloat(), wz.asFloat());
      halfExtents *= btScalar(0.5);
      bulletShape = new btBoxShape(halfExtents);
    } else if (shapeType.compare("convex") == 0) {
      Json::Value points = shape["points"];
      int numPoints = points.size();
      if (numPoints > 0) {
        btVector3* convexHull = new btVector3[numPoints];
        for (int i = 0; i < numPoints; i++) {
          convexHull[i][0] = points[i][0].asFloat();
          convexHull[i][1] = points[i][1].asFloat();
          convexHull[i][2] = points[i][2].asFloat();
        }
        bulletShape = new btConvexHullShape(&convexHull[0][0], numPoints);
      }
    } else if (shapeType.compare("sphere") == 0) {
      Json::Value radius = shape["radius"];
      bulletShape = new btSphereShape(radius.asFloat());
    } else if (shapeType.compare("cylinder") == 0) {
      Json::Value radius = shape["radius"];
      Json::Value height = shape["height"];
      btVector3 halfExtents = btVector3(radius.asFloat(), height.asFloat()*0.5f, 0.0f);
      bulletShape = new btCylinderShape(halfExtents);
    } else {
      NaClAMPrintf("Could not load shape type %s\n", shapeType.c_str());
      return;
    }

    if (bulletShape == NULL) {
      NaClAMPrintf("Could not build shape %s\n", name.asString().c_str());
      return;
    }

    shapes[name.asString()] = bulletShape;

    NaClAMPrintf("Added shape %s of %s\n", name.asString().c_str(), type.asString().c_str());
  }
Example #9
0
    Ogre::Vector3 JsonUtils::asVector3(Json::Value const &value, const Ogre::Vector3 &defaultValue)
    {
        if(value.isString())
        {
            auto const &s = value.asString();

            if(Ogre::StringConverter::isNumber(s))
            {
                float f = Ogre::StringConverter::parseReal(s);
                return Ogre::Vector3(f, f, f);
            }
            else
            {
                return Ogre::StringConverter::parseVector3(s);
            }
        }
        else if(value.isNumeric())
        {
            float f = value.asFloat();
            return Ogre::Vector3(f, f, f);
        }

        return defaultValue;
    }
Example #10
0
	float jsonNodeAs<float>(const Json::Value& node) {
		if (node.isNull()) {
			return 0;
		}
		return node.asFloat();
	}
float ParserActionParameters::parseFloat(Json::Value temp_info){
	if(!temp_info.isNull() && temp_info.isNumeric()){
		return temp_info.asFloat();
	}
	return 0;
}
Example #12
0
// Gets all timers and recordings
bool filmonAPIgetRecordingsTimers(bool completed) {
	bool res = filmonRequest("tv/api/dvr/list", sessionKeyParam);
	if (res == true) {
		Json::Value root;
		Json::Reader reader;
		reader.parse(&response.memory[0],
				&response.memory[(long) response.size - 1], root);

		// Usage
		Json::Value total = root["userStorage"]["total"];
		Json::Value used = root["userStorage"]["recorded"];
		storageTotal = (long long int) (total.asFloat() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
		storageUsed = (long long int) (used.asFloat() * FILMON_ONE_HOUR_RECORDING_SIZE); // bytes
		std::cerr << "FilmonAPI: recordings total is " << storageTotal
				<< std::endl;
		std::cerr << "FilmonAPI: recordings used is " << storageUsed
				<< std::endl;

		bool timersCleared = false;
		bool recordingsCleared = false;

		Json::Value recordingsTimers = root["recordings"];
		for (unsigned int recordingId = 0;
				recordingId < recordingsTimers.size(); recordingId++) {
			std::string recTimId =
					recordingsTimers[recordingId]["id"].asString();
			std::string recTimTitle =
					recordingsTimers[recordingId]["title"].asString();
			unsigned int recTimStart = stringToInt(
					recordingsTimers[recordingId]["time_start"].asString());
			unsigned int recDuration = stringToInt(
					recordingsTimers[recordingId]["length"].asString());

			Json::Value status = recordingsTimers[recordingId]["status"];
			if (completed && status.asString().compare(std::string(RECORDED_STATUS)) == 0) {
				if (recordingsCleared == false) {
					recordings.clear();
					recordingsCleared = true;
				}
				FILMON_RECORDING recording;
				recording.strRecordingId = recTimId;
				recording.strTitle = recTimTitle;
				recording.strStreamURL =
						recordingsTimers[recordingId]["download_link"].asString();
				recording.strPlot =
						recordingsTimers[recordingId]["description"].asString();
				recording.recordingTime = recTimStart;
				recording.iDuration = recDuration;
				recording.strIconPath =	recordingsTimers[recordingId]["images"]["channel_logo"].asString();
				recording.strThumbnailPath = recordingsTimers[recordingId]["images"]["poster"].asString();
				recordings.push_back(recording);
				std::cerr << "FilmonAPI: found completed recording "
						<< recording.strTitle << std::endl;
			} else if (status.asString().compare(std::string(TIMER_STATUS))
					== 0) {
				if (timersCleared == false) {
					timers.clear();
					timersCleared = true;
				}

				FILMON_TIMER timer;
				timer.iClientIndex = stringToInt(recTimId);
				timer.iClientChannelUid = stringToInt(
						recordingsTimers[recordingId]["channel_id"].asString());
				timer.startTime = recTimStart;
				timer.endTime = timer.startTime + recDuration;
				timer.strTitle = recTimTitle;
				timer.state = FILMON_TIMER_STATE_NEW;
				timer.strSummary =
						recordingsTimers[recordingId]["description"].asString();
				setTimerDefaults(&timer);
				time_t t = time(0);
				if (t >= timer.startTime && t <= timer.endTime) {
					std::cerr << "FilmonAPI: found active timer "
							<< timer.strTitle << std::endl;
					timer.state = FILMON_TIMER_STATE_RECORDING;
				} else if (t < timer.startTime) {
					std::cerr << "FilmonAPI: found scheduled timer "
							<< timer.strTitle << std::endl;
					timer.state = FILMON_TIMER_STATE_SCHEDULED;
				} else if (t > timer.endTime) {
					std::cerr << "FilmonAPI: found completed timer "
							<< timer.strTitle << std::endl;
					timer.state = FILMON_TIMER_STATE_COMPLETED;
				}
				timers.push_back(timer);
			}
		}
		clearResponse();
	}
	return res;
}
Example #13
0
void cmnDataJSON<float>::DeSerializeText(DataType & data, const Json::Value & jsonValue) throw (std::runtime_error) {
    data = jsonValue.asFloat();
}
Example #14
0
Texture *ResourceManager::loadTexture(const Json::Value& json,
                                      const std::unordered_map<std::string, ResPtr<Resource> >& externalResources)
{
    std::string textureType = getMember(json, "type").asString();
    Texture::Type type;

    if (textureType == "1d")
    {
        type = Texture::Texture1D;
    } else if (textureType == "2d")
    {
        type = Texture::Texture2D;
    } else if (textureType == "3d")
    {
        type = Texture::Texture3D;
    } else if (textureType == "cubemap")
    {
        type = Texture::TextureCubeMap;
    } else
    {
        throw std::runtime_error("Unknown texture type.");
    }

    Texture *texture;
    bool hasMipmaps = false;
    bool linearMipmapping = false;

    if (type == Texture::TextureCubeMap)
    {
        texture = mRenderer->createCubemap(getMember(json, "positive x").asCString(), getMember(json, "negative x").asCString(),
                                           getMember(json, "positive y").asCString(), getMember(json, "negative y").asCString(),
                                           getMember(json, "positive z").asCString(), getMember(json, "negative z").asCString());
    } else
    {
        texture = mRenderer->createTexture(getMember(json, "filename").asCString());
    }

    if (json.isMember("generate mipmaps"))
    {
        if (json["generate mipmaps"].asBool())
        {
            texture->generateMipmaps();

            hasMipmaps = true;
        }
    }

    if (json.isMember("linear mipmapping"))
    {
        if (json["generate mipmaps"].asBool())
        {
            linearMipmapping = true;
        }
    }

    if (json.isMember("anisotropy"))
    {
        Json::Value anisotropy = json["anisotropy"];

        if (anisotropy.isString())
        {
            if (anisotropy.asString() == "max")
            {
                texture->setAnisotropy(mRenderer->getMaxAnisotropy());
            } else
            {
                throw std::runtime_error("Unknown anisotropy.");
            }
        } else
        {
            texture->setAnisotropy(std::min(mRenderer->getMaxAnisotropy(), anisotropy.asFloat()));
        }
    }

    if (json.isMember("min filter"))
    {
        std::string minFilter = json["min filter"].asString();

        if (minFilter == "linear")
        {
            if (hasMipmaps)
            {
                if (linearMipmapping)
                {
                    texture->setMinFilter(Texture::LinearWithLinearMipmapMinFilter);
                } else
                {
                    texture->setMinFilter(Texture::LinearWithNearestMipmapMinFilter);
                }
            } else
            {
                texture->setMinFilter(Texture::LinearMinFilter);
            }
        } else if (minFilter == "nearest")
        {
            if (hasMipmaps)
            {
                if (linearMipmapping)
                {
                    texture->setMinFilter(Texture::NearestWithLinearMipmapMinFilter);
                } else
                {
                    texture->setMinFilter(Texture::NearestWithNearestMipmapMinFilter);
                }
            } else
            {
                texture->setMinFilter(Texture::NearestMinFilter);
            }
        } else
        {
            throw std::runtime_error("Unknown min filter.");
        }
    }

    if (json.isMember("mag filter"))
    {
        std::string magFilter = json["mag filter"].asString();

        if (magFilter == "linear")
        {
            texture->setMagFilter(Texture::LinearMagFilter);
        } else if (magFilter == "nearest")
        {
            texture->setMagFilter(Texture::NearestMagFilter);
        } else
        {
            throw std::runtime_error("Unknown mag filter.");
        }
    }

    if (json.isMember("wrap u"))
    {
        std::string wrapU = json["wrap u"].asString();

        if (wrapU == "repeat")
        {
            texture->setUWrap(Texture::Repeat);
        } else if (wrapU == "mirrored repeat")
        {
            texture->setUWrap(Texture::MirroredRepeat);
        } else if (wrapU == "clamp")
        {
            texture->setUWrap(Texture::Clamp);
        } else
        {
            throw std::runtime_error("Unknown U wrap.");
        }
    }

    if (json.isMember("wrap v"))
    {
        std::string wrapV = json["wrap v"].asString();

        if (wrapV == "repeat")
        {
            texture->setVWrap(Texture::Repeat);
        } else if (wrapV == "mirrored repeat")
        {
            texture->setVWrap(Texture::MirroredRepeat);
        } else if (wrapV == "clamp")
        {
            texture->setVWrap(Texture::Clamp);
        } else
        {
            throw std::runtime_error("Unknown V wrap.");
        }
    }

    if (json.isMember("wrap w"))
    {
        std::string wrapW = json["wrap w"].asString();

        if (wrapW == "repeat")
        {
            texture->setWWrap(Texture::Repeat);
        } else if (wrapW == "mirrored repeat")
        {
            texture->setWWrap(Texture::MirroredRepeat);
        } else if (wrapW == "clamp")
        {
            texture->setWWrap(Texture::Clamp);
        } else
        {
            throw std::runtime_error("Unknown W wrap.");
        }
    }

    return texture;
}
Example #15
0
template<> ZEROBUF_INL float fromJSON( const Json::Value& json )
    { return json.asFloat(); }
Example #16
0
  static void JsonToXmlInternal(pugi::xml_node& target,
                                const Json::Value& source,
                                const std::string& arrayElement)
  {
    // http://jsoncpp.sourceforge.net/value_8h_source.html#l00030

    switch (source.type())
    {
      case Json::nullValue:
      {
        target.append_child(pugi::node_pcdata).set_value("null");
        break;
      }

      case Json::intValue:
      {
        std::string s = boost::lexical_cast<std::string>(source.asInt());
        target.append_child(pugi::node_pcdata).set_value(s.c_str());
        break;
      }

      case Json::uintValue:
      {
        std::string s = boost::lexical_cast<std::string>(source.asUInt());
        target.append_child(pugi::node_pcdata).set_value(s.c_str());
        break;
      }

      case Json::realValue:
      {
        std::string s = boost::lexical_cast<std::string>(source.asFloat());
        target.append_child(pugi::node_pcdata).set_value(s.c_str());
        break;
      }

      case Json::stringValue:
      {
        target.append_child(pugi::node_pcdata).set_value(source.asString().c_str());
        break;
      }

      case Json::booleanValue:
      {
        target.append_child(pugi::node_pcdata).set_value(source.asBool() ? "true" : "false");
        break;
      }

      case Json::arrayValue:
      {
        for (Json::Value::ArrayIndex i = 0; i < source.size(); i++)
        {
          pugi::xml_node node = target.append_child();
          node.set_name(arrayElement.c_str());
          JsonToXmlInternal(node, source[i], arrayElement);
        }
        break;
      }
        
      case Json::objectValue:
      {
        Json::Value::Members members = source.getMemberNames();

        for (size_t i = 0; i < members.size(); i++)
        {
          pugi::xml_node node = target.append_child();
          node.set_name(members[i].c_str());
          JsonToXmlInternal(node, source[members[i]], arrayElement);          
        }

        break;
      }

      default:
        throw OrthancException(ErrorCode_NotImplemented);
    }
  }
Example #17
0
    int ToPbSingle(const Json::Value &value, const FieldDescriptor *pFieldDescriptor, Message &message, map<string, string>& key_map)
    {
        if (!check_type(value.type(), pFieldDescriptor->cpp_type()))
        {
            return 1;
        }

        const Reflection *pReflection = message.GetReflection();
        EnumDescriptor      *pEnumDes = NULL;
        EnumValueDescriptor *pEnumValueDes = NULL;
        int ret = 0;
        switch(pFieldDescriptor->cpp_type())
        {
            case FieldDescriptor::CPPTYPE_INT32:
            {
                pReflection->SetInt32(&message, pFieldDescriptor, value.asInt());
                break;
            }
            case FieldDescriptor::CPPTYPE_UINT32:
            {
                pReflection->SetUInt32(&message, pFieldDescriptor, value.asUInt());
                break;
            }
            case FieldDescriptor::CPPTYPE_INT64:
            {
                pReflection->SetInt64(&message, pFieldDescriptor, value.asInt64());
                break;
            }
            case FieldDescriptor::CPPTYPE_UINT64:
            {
                pReflection->SetUInt64(&message, pFieldDescriptor, value.asUInt64());
                break;
            }
            case FieldDescriptor::CPPTYPE_STRING:
            {
                pReflection->SetString(&message, pFieldDescriptor, value.asString());
                break;
            }
            case FieldDescriptor::CPPTYPE_BOOL:
            {
                pReflection->SetBool(&message, pFieldDescriptor, value.asBool());
                break;
            }
            case FieldDescriptor::CPPTYPE_DOUBLE:
            {
                pReflection->SetDouble(&message, pFieldDescriptor, value.asDouble());
                break;
            }
            case FieldDescriptor::CPPTYPE_FLOAT:
            {
                pReflection->SetFloat(&message, pFieldDescriptor, value.asFloat());
                break;
            }
            case FieldDescriptor::CPPTYPE_ENUM:
            {
                if ((pEnumDes = (EnumDescriptor *)pFieldDescriptor->enum_type()) == NULL)
                {
                    return 1;
                }

                if ((pEnumValueDes = (EnumValueDescriptor *)pEnumDes->FindValueByNumber(value.asInt())) == NULL)
                {
                    return 1;
                }

                pReflection->SetEnum(&message, pFieldDescriptor, pEnumValueDes);
                break;
            }
            case FieldDescriptor::CPPTYPE_MESSAGE:
            {
                Message *pmessage = pReflection->MutableMessage(&message, pFieldDescriptor);
                if (key_map.size() == 0)
                {
                    ret = ToPb(*pmessage, value);
                }
                else
                {
                    ret = ToPbMap(*pmessage, value, key_map);
                }

                break;
            }
            default:
            {
                ret = 1;
                break;
            }
        }

        return ret;
    }
Example #18
0
TEST(Lua, ReturnJson)
{
  Json::Value b = Json::objectValue;
  b["a"] = 42;
  b["b"] = 44;
  b["c"] = 43;

  Json::Value c = Json::arrayValue;
  c.append("test3");
  c.append("test1");
  c.append("test2");

  Json::Value a = Json::objectValue;
  a["Hello"] = "World";
  a["List"] = Json::arrayValue;
  a["List"].append(b);
  a["List"].append(c);

  Orthanc::LuaContext lua;

  // This is the identity function (it simply returns its input)
  lua.Execute("function identity(a) return a end");

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    f.PushJson("hello");
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_EQ("hello", v.asString());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    f.PushJson(42.25);
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_FLOAT_EQ(42.25f, v.asFloat());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    Json::Value vv = Json::arrayValue;
    f.PushJson(vv);
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_EQ(Json::arrayValue, v.type());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    Json::Value vv = Json::objectValue;
    f.PushJson(vv);
    Json::Value v;
    f.ExecuteToJson(v);
    // Lua does not make the distinction between empty lists and empty objects
    ASSERT_EQ(Json::arrayValue, v.type());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    f.PushJson(b);
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_EQ(Json::objectValue, v.type());
    ASSERT_FLOAT_EQ(42.0f, v["a"].asFloat());
    ASSERT_FLOAT_EQ(44.0f, v["b"].asFloat());
    ASSERT_FLOAT_EQ(43.0f, v["c"].asFloat());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    f.PushJson(c);
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_EQ(Json::arrayValue, v.type());
    ASSERT_EQ("test3", v[0].asString());
    ASSERT_EQ("test1", v[1].asString());
    ASSERT_EQ("test2", v[2].asString());
  }

  {
    Orthanc::LuaFunctionCall f(lua, "identity");
    f.PushJson(a);
    Json::Value v;
    f.ExecuteToJson(v);
    ASSERT_EQ("World", v["Hello"].asString());
    ASSERT_EQ(42, v["List"][0]["a"].asInt());
    ASSERT_EQ(44, v["List"][0]["b"].asInt());
    ASSERT_EQ(43, v["List"][0]["c"].asInt());
    ASSERT_EQ("test3", v["List"][1][0].asString());
    ASSERT_EQ("test1", v["List"][1][1].asString());
    ASSERT_EQ("test2", v["List"][1][2].asString());
  }
}
Example #19
0
bool Application::LoadProject(std::string a_file)
{
  ClearProject();

  std::ifstream fs;
  fs.open(a_file);
  if (!fs.good())
  {
    printf("Failed to open file '%s'!\n", a_file.c_str());
    return false;
  }

  Json::Value root;
  fs >> root;

  Json::Value node = root["State"];
  if (!node.isNull())
  {
    Json::Value val = node["useUpdaterColor"];
    if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterColor = val.asBool();

    val = node["useUpdaterRelativeForce"];
    if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterRelativeForce = val.asBool();

    val = node["useUpdaterSize"];
    if (!val.isNull()) m_projData.parSysOpts[0].useUpdaterSize = val.asBool();
  }

  InitParticleSystem();

  node = root["Emitters"];
  if (!node.isNull())
  {
    for (int i = 0; i < (int)node.size(); ++i)
    {
      EDataItem e;
      Json::Value val = node[i]["ID"];
      if (!val.isNull()) e.first.ID = val.asInt();

      val = node[i]["type"];
      if (!val.isNull()) e.first.type = val.asInt();

      val = node[i]["on"];
      if (!val.isNull()) e.first.on = val.asBool();

      val = node[i]["posGenMethod"];
      if (!val.isNull()) e.first.posGenMethod = val.asInt();

      val = node[i]["velGenMethod"];
      if (!val.isNull()) e.first.velGenMethod = val.asInt();

      val = node[i]["relativeForce"];
      if (!val.isNull()) e.first.relativeForce = val.asFloat();

      val = node[i]["velocity"];
      if (!val.isNull()) e.first.velocity = val.asFloat();

      val = node[i]["rate"];
      if (!val.isNull()) e.first.rate = val.asFloat();

      val = node[i]["life"];
      if (!val.isNull()) e.first.life = val.asFloat();

      val = node[i]["transform"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 7) memcpy(e.first.transform, t.data(), 7 * sizeof(float));
      }

      val = node[i]["boxDim"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 3) memcpy(e.first.boxDim, t.data(), 3 * sizeof(float));
      }

      val = node[i]["velCone"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 3) memcpy(e.first.velCone, t.data(), 3 * sizeof(float));
      }

      val = node[i]["colors"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 8) memcpy(e.first.colors, t.data(), 8 * sizeof(float));
      }

      val = node[i]["sizes"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 2) memcpy(e.first.sizes, t.data(), 2 * sizeof(float));
      }

      memcpy(&e.second, &e.first, sizeof(EmitterData));
      m_projData.eData.push_back(e);
      m_IDManager.MarkAsUsed(e.first.ID);
      EmitterFactory eFact;
      m_particleSystem.AddEmitter(e.first.ID, eFact(e.first));
      m_projData.emitterFocus = 0;
    }
  }

  node = root["Attractors"];
  if (!node.isNull())
  {
    for (int i = 0; i < (int)node.size(); ++i)
    {
      ADataItem a;
      Json::Value val;
      val = node[i]["ID"];
      if (!val.isNull()) a.first.ID = val.asInt();

      val = node[i]["attenuationMethod"];
      if (!val.isNull()) a.first.attenuationMethod = val.asInt();

      val = node[i]["maxAppliedAccelMag"];
      if (!val.isNull()) a.first.maxAppliedAccelMag = val.asFloat();

      val = node[i]["show"];
      if (!val.isNull()) a.first.show = val.asBool();

      val = node[i]["strength"];
      if (!val.isNull()) a.first.strength = val.asFloat();

      val = node[i]["type"];
      if (!val.isNull()) a.first.type = val.asInt();

      val = node[i]["transform"];
      if (!val.isNull())
      {
        std::vector<float> t;
        Dg::StringToNumberList(val.asString(), ',', std::dec, t);
        if (t.size() == 6) memcpy(a.first.transform, t.data(), 6 * sizeof(float));
      }

      memcpy(&a.second, &a.first, sizeof(AttractorData));
      m_projData.aData.push_back(a);
      m_IDManager.MarkAsUsed(a.first.ID);
      AttractorFactory aFact;
      m_particleSystem.AddUpdater(a.first.ID, aFact(a.first));
      m_projData.attrFocus = 0;
    }
  }

  UpdateProjectTitle(a_file);
  m_projData.dirty = false;

  return true;
}
bool mtsIntuitiveResearchKitConsole::ConfigurePSMTeleopJSON(const Json::Value & jsonTeleop)
{
    const std::string masterName = jsonTeleop["master"].asString();
    const std::string slaveName = jsonTeleop["slave"].asString();
    if ((masterName == "") || (slaveName == "")) {
        CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: both \"master\" and \"slave\" must be provided as strings" << std::endl;
        return false;
    }

    // check that both arms have been defined and have correct type
    Arm * armPointer;
    ArmList::iterator armIterator = mArms.find(masterName);
    if (armIterator == mArms.end()) {
        CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: master \""
                                 << masterName << "\" is not defined in \"arms\"" << std::endl;
        return false;
    } else {
        armPointer = armIterator->second;
        if (!((armPointer->mType == Arm::ARM_MTM_GENERIC) ||
              (armPointer->mType == Arm::ARM_MTM_DERIVED) ||
              (armPointer->mType == Arm::ARM_MTM))) {
            CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: master \""
                                     << masterName << "\" type must be \"MTM\" or \"GENERIC_MTM\"" << std::endl;
            return false;
        }
    }
    armIterator = mArms.find(slaveName);
    if (armIterator == mArms.end()) {
        CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: slave \""
                                 << slaveName << "\" is not defined in \"arms\"" << std::endl;
        return false;
    } else {
        armPointer = armIterator->second;
        if (!((armPointer->mType == Arm::ARM_PSM_GENERIC) ||
              (armPointer->mType == Arm::ARM_PSM_DERIVED) ||
              (armPointer->mType == Arm::ARM_PSM))) {
            CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: slave \""
                                     << masterName << "\" type must be \"PSM\" or \"GENERIC_PSM\"" << std::endl;
            return false;
        }
    }

    // check if pair already exist and then add
    const std::string name = masterName + "-" + slaveName;
    const TeleopList::iterator teleopIterator = mTeleops.find(name);
    TeleopPSM * teleopPointer = 0;
    if (teleopIterator == mTeleops.end()) {
        // create a new teleop if needed
        teleopPointer = new TeleopPSM(name, masterName, slaveName, this->GetName());
        mTeleops[name] = teleopPointer;
    } else {
        CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: there is already a teleop for the pair \""
                                 << name << "\"" << std::endl;
        return false;
    }

    Json::Value jsonValue;
    jsonValue = jsonTeleop["type"];
    if (!jsonValue.empty()) {
        std::string typeString = jsonValue.asString();
        if (typeString == "TELEOP_PSM") {
            teleopPointer->mType = TeleopPSM::TELEOP_PSM;
        } else if (typeString == "TELEOP_PSM_GENERIC") {
            teleopPointer->mType = TeleopPSM::TELEOP_PSM_GENERIC;
        } else {
            CMN_LOG_CLASS_INIT_ERROR << "ConfigurePSMTeleopJSON: teleop " << name << ": invalid type \""
                                     << typeString << "\", needs to be TELEOP_PSM or TELEOP_PSM_GENERIC" << std::endl;
            return false;
        }
    } else {
        // default value
        teleopPointer->mType = TeleopPSM::TELEOP_PSM;
    }

    // read orientation if present
    vctMatRot3 orientation; // identity by default
    jsonValue = jsonTeleop["rotation"];
    if (!jsonValue.empty()) {
        cmnDataJSON<vctMatRot3>::DeSerializeText(orientation, jsonTeleop["rotation"]);
    }

    // read period if present
    double period = 2.0 * cmn_ms;
    jsonValue = jsonTeleop["period"];
    if (!jsonValue.empty()) {
        period = jsonValue.asFloat();
    }
    teleopPointer->ConfigureTeleop(teleopPointer->mType, orientation, period);
    AddTeleopInterfaces(teleopPointer);
    return true;
}