Exemplo n.º 1
0
void Processor::deserialize(XmlDeserializer& s) {
    // meta data
    metaDataContainer_.deserialize(s);

    // misc settings
    s.deserialize("name", id_);
    guiName_ = id_;

    // deserialize properties
    PropertyOwner::deserialize(s);


    // ---
    // the following entities are static resources that should not be dynamically created by the serializer
    //
    const bool usePointerContentSerialization = s.getUsePointerContentSerialization();
    s.setUsePointerContentSerialization(true);

    // deserialize inports using a temporary map
    map<string, Port*> inportMap;
    for (vector<Port*>::const_iterator it = inports_.begin(); it != inports_.end(); ++it)
        inportMap[(*it)->getID()] = *it;
    try {
        s.deserialize("Inports", inportMap, "Port", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // port key missing => just ignore
        s.removeLastError();
    }

    // deserialize outports using a temporary map
    map<string, Port*> outportMap;
    for (vector<Port*>::const_iterator it = outports_.begin(); it != outports_.end(); ++it)
        outportMap[(*it)->getID()] = *it;
    try {
        s.deserialize("Outports", outportMap, "Port", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // port key missing => just ignore
        s.removeLastError();
    }

    // deserialize interaction handlers using a temporary map
    map<string, InteractionHandler*> handlerMap;
    const std::vector<InteractionHandler*>& handlers = getInteractionHandlers();
    for (vector<InteractionHandler*>::const_iterator it = handlers.begin(); it != handlers.end(); ++it)
        handlerMap[(*it)->getID()] = *it;
    try {
        s.deserialize("InteractionHandlers", handlerMap, "Handler", "name");
    }
    catch (XmlSerializationNoSuchDataException& /*e*/){
        // interaction handler key missing => just ignore
        s.removeLastError();
    }

    s.setUsePointerContentSerialization(usePointerContentSerialization);
    // --- static resources end ---

    firstProcessAfterDeserialization_ = true;
}
Exemplo n.º 2
0
void Property::deserialize(XmlDeserializer& s) {
    if (serializeValue_)
        return;

    // deserialize level-of-detail, if available
    try {
        int lod;
        s.deserialize("lod", lod);
        lod_ = static_cast<LODSetting>(lod);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        lod_ = USER;
    }

    // deserialize gui name, if available
    try {
        std::string temp;
        s.deserialize("guiName", temp);
        guiName_ = temp;
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }

    metaDataContainer_.deserialize(s);
}
Exemplo n.º 3
0
void CameraProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    try {
        float left, right, bottom, top, nearP, farP;
        s.deserialize("frustLeft", left);
        s.deserialize("frustRight", right);
        s.deserialize("frustBottom", bottom);
        s.deserialize("frustTop", top);
        s.deserialize("frustNear", nearP);
        s.deserialize("frustFar", farP);
        value_.setFrustum(tgt::Frustum(left, right, bottom, top, nearP, farP));
    } catch(SerializationException&) {
        s.removeLastError();
    }

    int projMode;
    try {
        s.deserialize("projectionMode", projMode);
    } catch(SerializationException&) {
        s.removeLastError();
        projMode = tgt::Camera::PERSPECTIVE;
    }

    value_.setProjectionMode((tgt::Camera::ProjectionMode)projMode);

    tgt::vec3 vector;
    s.deserialize("position", vector);
    value_.setPosition(vector);
    s.deserialize("focus", vector);
    value_.setFocus(vector);
    s.deserialize("upVector", vector);
    value_.setUpVector(vector);

    try {
        float fovy;
        s.deserialize("fovy", fovy);
        value_.setFovy(fovy);
    }
    catch(SerializationException&) {
        s.removeLastError();
    }

    try {
        int eyeMode, axisMode;
        float eyeSep;
        s.deserialize("eyeMode", eyeMode);
        s.deserialize("eyeSeparation", eyeSep);
        s.deserialize("axisMode", axisMode);
        value_.setStereoEyeMode((tgt::Camera::StereoEyeMode)eyeMode, false);
        value_.setStereoEyeSeparation(eyeSep, false);
        value_.setStereoAxisMode((tgt::Camera::StereoAxisMode)axisMode);
    }
    catch(SerializationException&) {
        s.removeLastError();
    }
}
Exemplo n.º 4
0
void Workspace::deserialize(XmlDeserializer& s) {
    // clear existing network and containers
    clear();

    try {
        s.deserialize("readonly", readOnly_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        readOnly_ = false;
    }

    // Deserialize network...
    s.deserialize("ProcessorNetwork", network_);

    // Deserialize animation if present...
    try {
        s.deserialize("Animation", animation_);
    } catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }

    if (animation_) {
        animation_->setNetwork(network_);

        // register this as observer on all propertytimelines for undo/redo
        const std::vector<AnimatedProcessor*> animproc = this->animation_->getAnimatedProcessors();
        std::vector<AnimatedProcessor*>::const_iterator it;
        for (it = animproc.begin();it != animproc.end();it++)
        {
            const std::vector<PropertyTimeline*> timelines = (*it)->getPropertyTimelines();
            std::vector<PropertyTimeline*>::const_iterator it2;
            for (it2 = timelines.begin();it2 != timelines.end(); ++it2) {
                (*it2)->registerUndoObserver(this->animation_);
            }
        }

        // register this as observer in the processornetwork to register added and removed processors
        ProcessorNetwork* net = const_cast<ProcessorNetwork*>(network_);
        net->addObserver(this->animation_);
    }

    try {
        s.deserialize("GlobalDescription", description_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
        description_ = "";
    }
}
Exemplo n.º 5
0
void VolumeURLListProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    std::vector<std::string> urlList = value_;
    std::map<std::string, bool> selectMap = selectionMap_;
    s.deserialize("VolumeURLs", urlList, "url");

    try {
        s.deserialize("Selection", selectMap, "entry", "url");
    }
    catch (SerializationException& e) {
        s.removeLastError();
        LWARNING("Failed to deserialize selection map: " << e.what());
    }

    // convert URLs to absolute path
    std::string basePath = tgt::FileSystem::dirName(s.getDocumentPath());
    for (size_t i=0; i<urlList.size(); i++) {
        std::string url = urlList[i];
        std::string urlConv = VolumeURL::convertURLToAbsolutePath(url, basePath);
        urlList[i] = urlConv;
        if (selectMap.find(url) != selectMap.end()) {
            bool selected = selectMap[url];
            selectMap.erase(url);
            selectMap.insert(std::pair<std::string, bool>(urlConv, selected));
        }
    }

    value_ = urlList;
    selectionMap_ = selectMap;

    invalidate();
}
Exemplo n.º 6
0
void FileDialogProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    // An empty serialized value does not necessarily mean that it wasn't set, but could also mean that it was the
    // same path as the document path passed during serialization, which makes the relative path empty.  We need an
    // extra bool to remember if this was the case.
    try {
        bool noPathSet;
        s.deserialize("noPathSet", noPathSet);
        if(noPathSet) {
            set("");
            return;
        }
    }
    catch (XmlSerializationNoSuchDataException) {
        s.removeLastError();
    }

    std::string value;
    s.deserialize("value", value);

    // convert path relative to the document's path to an absolute one
    if (!s.getDocumentPath().empty())
        value = tgt::FileSystem::absolutePath(tgt::FileSystem::dirName(s.getDocumentPath()) + "/" + value);

    try {
        set(value);
    }
    catch (Condition::ValidationFailed& e) {
        s.addError(e);
    }
}
Exemplo n.º 7
0
bool deserializeSettings(PropertyOwner* po, const std::string& filename) {
    std::ifstream stream;
    stream.open(filename.c_str(), std::ios_base::in);
    if(stream.fail()) {
        stream.close();
        return false;
    }
    else {
        XmlDeserializer xmlDeserializer;
        try {
            xmlDeserializer.read(stream);
            po->deserialize(xmlDeserializer);
            stream.close();
        }
        catch (XmlSerializationNoSuchDataException) {
            // no data present => ignore
            xmlDeserializer.removeLastError();
            return false;
        }
        catch (SerializationException &e) {
            LWARNINGC("VoreenSettingsDialog", std::string("Deserialization failed: ") + e.what());
            return false;
        }
    }
    return true;
}
Exemplo n.º 8
0
void EventPropertyBase::deserialize(XmlDeserializer& s) {

    Property::deserialize(s);

    try {
        bool enabled, shareEvents;
        s.deserialize("enabled", enabled);
        s.deserialize("shareEvents", shareEvents);
        enabled_ = enabled;
        shareEvents_ = shareEvents;
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int mouseAction = 0;
        int mouseButtons = 0;
        s.deserialize("mouseAction", mouseAction);
        s.deserialize("mouseButtons", mouseButtons);
        mouseAction_ = static_cast<tgt::MouseEvent::MouseAction>(mouseAction);
        mouseButtons_ = static_cast<tgt::MouseEvent::MouseButtons>(mouseButtons);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int keyCode = 0;
        s.deserialize("keyCode", keyCode);
        keyCode_ = static_cast<tgt::KeyEvent::KeyCode>(keyCode);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    try {
        int modifier = 0;
        s.deserialize("modifier", modifier);
        modifier_ = static_cast<tgt::Event::Modifier>(modifier);
    }
    catch (XmlSerializationNoSuchDataException& /*e*/) {
        s.removeLastError();
    }

    notifyChangeListener();
}
Exemplo n.º 9
0
void FaceGeometry::deserialize(XmlDeserializer& s) {
    s.deserialize("vertices", vertices_);
    try {
        s.deserialize("normal", normal_);
        normalIsSet_ = true;
    }
    catch (...) {
        s.removeLastError();
        normalIsSet_ = false;
    }
    setHasChanged(true);
}
Exemplo n.º 10
0
void LightSourceProperty::deserialize(XmlDeserializer& s) {
    FloatVec4Property::deserialize(s);
    try {
        s.deserialize("Center", curCenter_);
        s.deserialize("LightPos", lightPos_);
        s.deserialize("FollowCam", followCam_);
        s.deserialize("MaxDist", maxDist_);
    }
    catch(SerializationException&) {
        // TODO necessary?
        lightPos_ = tgt::vec4(get().xyz(), 1.f);
        s.removeLastError();
    }
}
Exemplo n.º 11
0
void PropertyKeyValue<tgt::Camera>::deserialize(XmlDeserializer& s) {
    // base class props
    s.deserialize("time", time_);
    s.deserialize("smooth", smooth_);
    s.deserialize("before", before_);
    s.deserialize("after", after_);

    // camera
    tgt::vec3 vector;
    s.deserialize("position", vector);
    value_.setPosition(vector);
    s.deserialize("focus", vector);
    value_.setFocus(vector);
    s.deserialize("upVector", vector);
    value_.setUpVector(vector);
    float winRatio = 1.f;
    try {
        s.deserialize("winRatio", winRatio);
    } catch(SerializationException&) {
        s.removeLastError();
    }

    // camera frustum
    try {
        float left, right, bottom, top, nearP, farP;
        s.deserialize("frustLeft", left);
        s.deserialize("frustRight", right);
        s.deserialize("frustBottom", bottom);
        s.deserialize("frustTop", top);
        s.deserialize("frustNear", nearP);
        s.deserialize("frustFar", farP);
        value_.setFrustum(tgt::Frustum(left, right, bottom, top, nearP, farP));
    } catch(SerializationException&) {
        s.removeLastError();
    }
}
Exemplo n.º 12
0
void TransFuncProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    TransFunc* tf = 0;
    s.deserialize("TransferFunction", tf);
    set(tf);

    try {
        int fittingStrategy = domainFittingStrategy_;
        s.deserialize("domainFittingStrategy", fittingStrategy);
        domainFittingStrategy_ = (DomainAutoFittingStrategy)fittingStrategy;
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }
}
Exemplo n.º 13
0
void NumericProperty<T>::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    // deserialize value
    T value;
    s.deserialize("value", value);
    try {
        set(value);
    }
    catch (Condition::ValidationFailed& e) {
        s.addError(e);
    }

    // deserialize tracking mode, if available
    try {
        s.deserialize("tracking", tracking_);
    }
    catch (XmlSerializationNoSuchDataException&) {
        s.removeLastError();
    }
}
Exemplo n.º 14
0
void CameraProperty::deserialize(XmlDeserializer& s) {
    Property::deserialize(s);

    try {
        float left, right, bottom, top, nearP, farP;
        s.deserialize("frustLeft", left);
        s.deserialize("frustRight", right);
        s.deserialize("frustBottom", bottom);
        s.deserialize("frustTop", top);
        s.deserialize("frustNear", nearP);
        s.deserialize("frustFar", farP);
        value_.setFrustum(tgt::Frustum(left, right, bottom, top, nearP, farP));
    } catch(SerializationException&) {
        s.removeLastError();
    }

    int projMode;
    try {
        s.deserialize("projectionMode", projMode);
    } catch(SerializationException&) {
        s.removeLastError();
        projMode = tgt::Camera::PERSPECTIVE;
    }

    value_.setProjectionMode((tgt::Camera::ProjectionMode)projMode);

    tgt::vec3 vector;
    s.deserialize("position", vector);
    value_.setPosition(vector);
    s.deserialize("focus", vector);
    value_.setFocus(vector);
    s.deserialize("upVector", vector);
    value_.setUpVector(vector);

    try {
        float maxValue, minValue;
        s.deserialize("maxValue", maxValue);
        maxValue_ = maxValue;
        s.deserialize("minValue", minValue);
        minValue_ = minValue;
    }
    catch(SerializationException&) {
        s.removeLastError();
    }

    try {
        float fovy;
        s.deserialize("fovy", fovy);
        value_.setFovy(fovy);
    }
    catch(SerializationException&) {
        s.removeLastError();
    }

    try {
        int eyeMode, axisMode;
        float eyeSep;
        s.deserialize("eyeMode", eyeMode);
        s.deserialize("eyeSeparation", eyeSep);
        s.deserialize("axisMode", axisMode);
        value_.setStereoEyeMode((tgt::Camera::StereoEyeMode)eyeMode, false);
        value_.setStereoEyeSeparation(eyeSep, false);
        value_.setStereoAxisMode((tgt::Camera::StereoAxisMode)axisMode, false);
    }
    catch(SerializationException&) {
        s.removeLastError();
    }

    try {
        s.deserialize("trackball", trackball_);
    }
    catch (SerializationException&) {
        s.removeLastError();
    }

    try {
        int centerOption;
        s.deserialize("centerOption", centerOption);
        s.deserialize("adaptOnChange", adaptOnChange_);
        tgt::vec3 llf, urb;
        s.deserialize("sceneLLF", llf);
        s.deserialize("sceneURB", urb);
        currentSceneBounds_ = tgt::Bounds(llf, urb);
        setTrackballCenterBehaviour((TrackballCenter)centerOption);
    }
    catch(SerializationException&) {
        s.removeLastError();
    }
}