OpenShot Library | libopenshot  0.2.5
Coordinate.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Source file for Coordinate class
4  * @author Jonathan Thomas <jonathan@openshot.org>
5  *
6  * @ref License
7  */
8 
9 /* LICENSE
10  *
11  * Copyright (c) 2008-2019 OpenShot Studios, LLC
12  * <http://www.openshotstudios.com/>. This file is part of
13  * OpenShot Library (libopenshot), an open-source project dedicated to
14  * delivering high quality video editing and animation solutions to the
15  * world. For more information visit <http://www.openshot.org/>.
16  *
17  * OpenShot Library (libopenshot) is free software: you can redistribute it
18  * and/or modify it under the terms of the GNU Lesser General Public License
19  * as published by the Free Software Foundation, either version 3 of the
20  * License, or (at your option) any later version.
21  *
22  * OpenShot Library (libopenshot) is distributed in the hope that it will be
23  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public License
28  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29  */
30 
31 #include "../include/Coordinate.h"
32 
33 using namespace std;
34 using namespace openshot;
35 
36 // Default constructor for a coordinate, which defaults the X and Y to zero (0,0)
37 Coordinate::Coordinate() :
38  X(0), Y(0) {
39 }
40 
41 // Constructor which also allows the user to set the X and Y
42 Coordinate::Coordinate(double x, double y) :
43  X(x), Y(y) {
44 }
45 
46 
47 // Generate JSON string of this object
48 std::string Coordinate::Json() const {
49 
50  // Return formatted string
51  return JsonValue().toStyledString();
52 }
53 
54 // Generate Json::Value for this object
55 Json::Value Coordinate::JsonValue() const {
56 
57  // Create root json object
58  Json::Value root;
59  root["X"] = X;
60  root["Y"] = Y;
61  //root["increasing"] = increasing;
62  //root["repeated"] = Json::Value(Json::objectValue);
63  //root["repeated"]["num"] = repeated.num;
64  //root["repeated"]["den"] = repeated.den;
65  //root["delta"] = delta;
66 
67  // return JsonValue
68  return root;
69 }
70 
71 // Load JSON string into this object
72 void Coordinate::SetJson(const std::string value) {
73 
74  // Parse JSON string into JSON objects
75  try
76  {
77  const Json::Value root = openshot::stringToJson(value);
78  // Set all values that match
79  SetJsonValue(root);
80  }
81  catch (const std::exception& e)
82  {
83  // Error parsing JSON (or missing keys)
84  throw InvalidJSON("JSON is invalid (missing keys or invalid data types)");
85  }
86 }
87 
88 // Load Json::Value into this object
89 void Coordinate::SetJsonValue(const Json::Value root) {
90 
91  // Set data from Json (if key is found)
92  if (!root["X"].isNull())
93  X = root["X"].asDouble();
94  if (!root["Y"].isNull())
95  Y = root["Y"].asDouble();
96 }
openshot::stringToJson
const Json::Value stringToJson(const std::string value)
Definition: Json.cpp:33
openshot::Coordinate::Y
double Y
The Y value of the coordinate (usually representing the value of the property being animated)
Definition: Coordinate.h:58
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:38
openshot::Coordinate::Coordinate
Coordinate()
The default constructor, which defaults to (0,0)
Definition: Coordinate.cpp:37
openshot::Coordinate::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: Coordinate.cpp:89
openshot::Coordinate::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: Coordinate.cpp:72
openshot::InvalidJSON
Exception for invalid JSON.
Definition: Exceptions.h:205
openshot::Coordinate::Json
std::string Json() const
Get and Set JSON methods.
Definition: Coordinate.cpp:48
openshot::Coordinate::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: Coordinate.cpp:55
openshot::Coordinate::X
double X
The X value of the coordinate (usually representing the frame #)
Definition: Coordinate.h:57