Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/graph/node_xml.cpp
| Show First 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | for (size_t j = 0; j < VECTOR_SIZE; j++) | ||||
| value_float[j] = (float)atof(tokens[i * VECTOR_SIZE + j].c_str()); | value_float[j] = (float)atof(tokens[i * VECTOR_SIZE + j].c_str()); | ||||
| } | } | ||||
| } | } | ||||
| void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node) | void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node) | ||||
| { | { | ||||
| xml_attribute name_attr = xml_node.attribute("name"); | xml_attribute name_attr = xml_node.attribute("name"); | ||||
| if (name_attr) { | if (name_attr) { | ||||
| node->name = ustring(name_attr.value()); | node->set_name(ustring(name_attr.value())); | ||||
| } | } | ||||
| foreach (const SocketType &socket, node->type->inputs) { | foreach (const SocketType &socket, node->get_type()->get_inputs()) { | ||||
| if (socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) { | if (socket.get_type() == SocketType::CLOSURE || socket.get_type() == SocketType::UNDEFINED) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (socket.flags & SocketType::INTERNAL) { | if (socket.get_flags() & SocketType::INTERNAL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| xml_attribute attr = xml_node.attribute(socket.name.c_str()); | xml_attribute attr = xml_node.attribute(socket.get_name().c_str()); | ||||
| if (!attr) { | if (!attr) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| switch (socket.type) { | switch (socket.get_type()) { | ||||
| case SocketType::BOOLEAN: { | case SocketType::BOOLEAN: { | ||||
| node->set(socket, xml_read_boolean(attr.value())); | node->set(socket, xml_read_boolean(attr.value())); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::BOOLEAN_ARRAY: { | case SocketType::BOOLEAN_ARRAY: { | ||||
| vector<string> tokens; | vector<string> tokens; | ||||
| string_split(tokens, attr.value()); | string_split(tokens, attr.value()); | ||||
| ▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | switch (socket.get_type()) { | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::STRING: { | case SocketType::STRING: { | ||||
| node->set(socket, attr.value()); | node->set(socket, attr.value()); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::ENUM: { | case SocketType::ENUM: { | ||||
| ustring value(attr.value()); | ustring value(attr.value()); | ||||
| if (socket.enum_values->exists(value)) { | if (socket.get_enum_values()->exists(value)) { | ||||
| node->set(socket, value); | node->set(socket, value); | ||||
| } | } | ||||
| else { | else { | ||||
| fprintf(stderr, | fprintf(stderr, | ||||
| "Unknown value \"%s\" for attribute \"%s\".\n", | "Unknown value \"%s\" for attribute \"%s\".\n", | ||||
| value.c_str(), | value.c_str(), | ||||
| socket.name.c_str()); | socket.get_name().c_str()); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::STRING_ARRAY: { | case SocketType::STRING_ARRAY: { | ||||
| vector<string> tokens; | vector<string> tokens; | ||||
| string_split(tokens, attr.value()); | string_split(tokens, attr.value()); | ||||
| array<ustring> value; | array<ustring> value; | ||||
| Show All 18 Lines | switch (socket.get_type()) { | ||||
| node->set(socket, value); | node->set(socket, value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::NODE: { | case SocketType::NODE: { | ||||
| ustring value(attr.value()); | ustring value(attr.value()); | ||||
| map<ustring, Node *>::iterator it = reader.node_map.find(value); | map<ustring, Node *>::iterator it = reader.node_map.find(value); | ||||
| if (it != reader.node_map.end()) { | if (it != reader.node_map.end()) { | ||||
| Node *value_node = it->second; | Node *value_node = it->second; | ||||
| if (value_node->is_a(*(socket.node_type))) | if (value_node->is_a(*(socket.get_node_type()))) | ||||
| node->set(socket, it->second); | node->set(socket, it->second); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::NODE_ARRAY: { | case SocketType::NODE_ARRAY: { | ||||
| vector<string> tokens; | vector<string> tokens; | ||||
| string_split(tokens, attr.value()); | string_split(tokens, attr.value()); | ||||
| array<Node *> value; | array<Node *> value; | ||||
| value.resize(tokens.size()); | value.resize(tokens.size()); | ||||
| for (size_t i = 0; i < value.size(); i++) { | for (size_t i = 0; i < value.size(); i++) { | ||||
| map<ustring, Node *>::iterator it = reader.node_map.find(ustring(tokens[i])); | map<ustring, Node *>::iterator it = reader.node_map.find(ustring(tokens[i])); | ||||
| if (it != reader.node_map.end()) { | if (it != reader.node_map.end()) { | ||||
| Node *value_node = it->second; | Node *value_node = it->second; | ||||
| value[i] = (value_node->is_a(*(socket.node_type))) ? value_node : NULL; | value[i] = (value_node->is_a(*(socket.get_node_type()))) ? value_node : NULL; | ||||
| } | } | ||||
| else { | else { | ||||
| value[i] = NULL; | value[i] = NULL; | ||||
| } | } | ||||
| } | } | ||||
| node->set(socket, value); | node->set(socket, value); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::CLOSURE: | case SocketType::CLOSURE: | ||||
| case SocketType::UNDEFINED: | case SocketType::UNDEFINED: | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (!node->name.empty()) | if (!node->get_name().empty()) | ||||
| reader.node_map[node->name] = node; | reader.node_map[node->get_name()] = node; | ||||
| } | } | ||||
| xml_node xml_write_node(Node *node, xml_node xml_root) | xml_node xml_write_node(Node *node, xml_node xml_root) | ||||
| { | { | ||||
| xml_node xml_node = xml_root.append_child(node->type->name.c_str()); | xml_node xml_node = xml_root.append_child(node->get_type()->get_name().c_str()); | ||||
| xml_node.append_attribute("name") = node->name.c_str(); | xml_node.append_attribute("name") = node->get_name().c_str(); | ||||
| foreach (const SocketType &socket, node->type->inputs) { | foreach (const SocketType &socket, node->get_type()->get_inputs()) { | ||||
| if (socket.type == SocketType::CLOSURE || socket.type == SocketType::UNDEFINED) { | if (socket.get_type() == SocketType::CLOSURE || socket.get_type() == SocketType::UNDEFINED) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (socket.flags & SocketType::INTERNAL) { | if (socket.get_flags() & SocketType::INTERNAL) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (node->has_default_value(socket)) { | if (node->has_default_value(socket)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| xml_attribute attr = xml_node.append_attribute(socket.name.c_str()); | xml_attribute attr = xml_node.append_attribute(socket.get_name().c_str()); | ||||
| switch (socket.type) { | switch (socket.get_type()) { | ||||
| case SocketType::BOOLEAN: { | case SocketType::BOOLEAN: { | ||||
| attr = xml_write_boolean(node->get_bool(socket)); | attr = xml_write_boolean(node->get_bool(socket)); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::BOOLEAN_ARRAY: { | case SocketType::BOOLEAN_ARRAY: { | ||||
| std::stringstream ss; | std::stringstream ss; | ||||
| const array<bool> &value = node->get_bool_array(socket); | const array<bool> &value = node->get_bool_array(socket); | ||||
| for (size_t i = 0; i < value.size(); i++) { | for (size_t i = 0; i < value.size(); i++) { | ||||
| ▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | switch (socket.get_type()) { | ||||
| } | } | ||||
| } | } | ||||
| attr = ss.str().c_str(); | attr = ss.str().c_str(); | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::NODE: { | case SocketType::NODE: { | ||||
| Node *value = node->get_node(socket); | Node *value = node->get_node(socket); | ||||
| if (value) { | if (value) { | ||||
| attr = value->name.c_str(); | attr = value->get_name().c_str(); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case SocketType::NODE_ARRAY: { | case SocketType::NODE_ARRAY: { | ||||
| std::stringstream ss; | std::stringstream ss; | ||||
| const array<Node *> &value = node->get_node_array(socket); | const array<Node *> &value = node->get_node_array(socket); | ||||
| for (size_t i = 0; i < value.size(); i++) { | for (size_t i = 0; i < value.size(); i++) { | ||||
| if (value[i]) { | if (value[i]) { | ||||
| ss << value[i]->name.c_str(); | ss << value[i]->get_name().c_str(); | ||||
| } | } | ||||
| if (i != value.size() - 1) { | if (i != value.size() - 1) { | ||||
| ss << " "; | ss << " "; | ||||
| } | } | ||||
| } | } | ||||
| attr = ss.str().c_str(); | attr = ss.str().c_str(); | ||||
| break; | break; | ||||
| } | } | ||||
| Show All 10 Lines | |||||