Exemple #1
0
void GraphIO::loadFulcrum(const YAML::Node& fulcrum, SemanticVersion version)
{
    YAML::Node from_node = fulcrum["from"];
    if (!from_node.IsDefined()) {
        return;
    }

    YAML::Node to_node = fulcrum["to"];
    if (!to_node.IsDefined()) {
        return;
    }

    std::string from_uuid_tmp = from_node.as<std::string>();
    std::string to_uuid_tmp = to_node.as<std::string>();

    UUID from_uuid = UUIDProvider::makeUUID_forced(graph_.getLocalGraph()->shared_from_this(), from_uuid_tmp);
    UUID to_uuid = UUIDProvider::makeUUID_forced(graph_.getLocalGraph()->shared_from_this(), to_uuid_tmp);

    ConnectorPtr from = graph_.findConnector(from_uuid);
    if (from == nullptr) {
        sendNotificationStreamGraphio("cannot load fulcrum, connector with uuid '" << from_uuid << "' doesn't exist.");
        return;
    }

    ConnectorPtr to = graph_.findConnector(to_uuid);
    if (to == nullptr) {
        sendNotificationStreamGraphio("cannot load fulcrum, connector with uuid '" << to_uuid << "' doesn't exist.");
        return;
    }

    ConnectionPtr connection = graph_.getLocalGraph()->getConnection(from->getUUID(), to->getUUID());

    std::vector<std::vector<double>> pts = fulcrum["pts"].as<std::vector<std::vector<double>>>();

    std::vector<std::vector<double>> handles;
    bool has_handle = fulcrum["handles"].IsDefined();
    if (has_handle) {
        handles = fulcrum["handles"].as<std::vector<std::vector<double>>>();
    }

    std::vector<int> types;
    if (fulcrum["types"].IsDefined()) {
        types = fulcrum["types"].as<std::vector<int>>();
    }

    int n = pts.size();
    for (int i = 0; i < n; ++i) {
        int type = (!types.empty()) ? types[i] : Fulcrum::FULCRUM_LINEAR;
        if (has_handle) {
            Point in(handles[i][0], handles[i][1]);
            Point out(handles[i][2], handles[i][3]);
            connection->addFulcrum(i, Point(pts[i][0], pts[i][1]), type, in, out);
        } else {
            connection->addFulcrum(i, Point(pts[i][0], pts[i][1]), type);
        }
    }
}