Example #1
0
void VRGuiBits_on_camera_changed(GtkComboBox* cb, gpointer data) {
    int i = gtk_combo_box_get_active(cb);
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    scene->setActiveCamera(i);

    VRGuiSignals::get()->getSignal("camera_changed")->trigger();
}
Example #2
0
void VRGuiBits_on_navigation_changed(GtkComboBox* cb, gpointer data) {
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    if (scene == 0) return;

    char* c = gtk_combo_box_get_active_text(cb);
    if (c == 0) return;
    string name = string(c);
    scene->setActivePreset(name);
}
Example #3
0
void VRScript::load(xmlpp::Element* e) {
    clean();
    loadName(e);
    if (e->get_attribute("core")) core = e->get_attribute("core")->get_value();
    if (e->get_attribute("type")) type = e->get_attribute("type")->get_value();
    if (e->get_attribute("mobile")) mobile = e->get_attribute("mobile")->get_value();

    for (xmlpp::Node* n : e->get_children() ) {
        xmlpp::Element* el = dynamic_cast<xmlpp::Element*>(n);
        if (!el) continue;

        string name = el->get_name();

        if (name == "core") {
            if (el->has_child_text()) {
                core = el->get_child_text()->get_content();
                core = core.substr(1,core.size()-2);
            }
        }

        if (name == "arg") {
            arg* a = addArgument();
            a->type = el->get_attribute("type")->get_value();
            a->val  = el->get_attribute("value")->get_value();
            string oname = a->getName();
            a->loadName(el);
            changeArgName(oname, a->getName());
        }

        if (name == "trig") {
            trig* t = new trig();
            t->trigger = el->get_attribute("type")->get_value();
            t->dev = el->get_attribute("dev")->get_value();
            t->state = el->get_attribute("state")->get_value();
            t->param = el->get_attribute("param")->get_value();
            t->key = toInt( el->get_attribute("key")->get_value() );
            t->loadName(el);
            trigs[t->getName()] = t;

            if (t->trigger == "on_scene_load" && active) {
                VRScene* scene = VRSceneManager::getCurrent();
                scene->queueJob(cbfkt_sys);
            }
        }
    }

    update();
}
Example #4
0
void VRGuiNav_on_new_preset_clicked(GtkButton* b, gpointer d) {
    VRNavPreset* preset = new VRNavPreset();
    VRScene* scene = VRSceneManager::get()->getActiveScene();

    string name = "preset"; //TODO: dialog with name, and copy from other scene options
    scene->addPreset(preset, name);

    //preset->setDevice(VRMouse::get());
    preset->setTarget(scene->getActiveCamera());

    Glib::RefPtr<Gtk::ListStore> store = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("nav_presets"));
    Gtk::ListStore::Row row = *store->append();
    gtk_list_store_set (store->gobj(), row.gobj(), 0, name.c_str(), -1);

    setComboboxLastActive("combobox5");
}
Example #5
0
// scene updated, get cameras and nav presets
void VRGuiNav::update() {
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    if (scene == 0) return;

    Glib::RefPtr<Gtk::ListStore> combo_list;
    combo_list = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("binding_callbacks"));
        // get navigator callback library!
    map<string, VRDevCb*> cbs = scene->getCallbacks();
    map<string, VRDevCb*>::iterator itr;
    combo_list->clear();
    for (itr = cbs.begin(); itr != cbs.end(); itr++) {
        Gtk::ListStore::Row row = *combo_list->append();
        gtk_list_store_set(combo_list->gobj(), row.gobj(), 0, itr->first.c_str(), -1);
    }

    setComboboxLastActive("combobox5");
}
Example #6
0
void VRScript::clean() {
    VRMobile* mob = (VRMobile*)VRSetupManager::getCurrent()->getDevice(this->mobile);
    if (mob) mob->remWebSite(getName());

    VRScene* scene = VRSceneManager::getCurrent();

    for (t_itr = trigs.begin(); t_itr != trigs.end(); t_itr++) {
        trig* t = t_itr->second;
        if (t->a && args.count("dev")) { args.erase("dev"); delete t->a; }
        if (t->soc) t->soc->unsetCallbacks();
        if (t->sig) t->sig->sub(cbfkt_dev);
        if (t->trigger == "on_timeout") scene->dropTimeoutFkt(cbfkt_sys);
        t->soc = 0;
        t->sig = 0;
        t->a = 0;
    }
}
Example #7
0
void VRSceneLoader::loadScene(string path) {
    xmlpp::DomParser parser;
    parser.set_validate(false);

    parser.parse_file(path.c_str());

    xmlpp::Node* n = parser.get_document()->get_root_node();
    xmlpp::Element* sceneN = dynamic_cast<xmlpp::Element*>(n);

    // load scenegraph
    xmlpp::Element* objectsN = VRSceneLoader_getElementChild_(sceneN, "Objects");
    xmlpp::Element* root = VRSceneLoader_getElementChild_(objectsN, 0);
    VRScene* scene = new VRScene();
    scene->setPath(path);
    VRSceneManager::get()->setWorkdir(scene->getWorkdir());
    scene->setName(scene->getFileName());
    VRSceneLoader_current_scene = scene;

    VRTimer timer;
    timer.start("total_time");
    VRSceneLoader_loadObject(scene, scene->getRoot(), root);
    timer.stop("total_time");

    VRSceneManager::get()->addScene(scene);

    scene->load(sceneN);
    //timer.print();

    ihr_flag = false;
}
Example #8
0
void VRTransform::startPathAnimation(path* p, float t, bool redirect) {
    VRFunction<Vec3f> *fkt1, *fkt2;
    fkt1 = new VRFunction<Vec3f>("3DEntSetFrom", boost::bind(&VRTransform::setFrom, this, _1));
    fkt2 = new VRFunction<Vec3f>("3DEntSetDir", boost::bind(&VRTransform::setDir, this, _1));

    Vec3f p0, p1, n0, n1, c, d;
    p->getStartPoint(p0,n0,c);
    p->getEndPoint(p1,n1,c);
    d = getDir();

    VRScene* scene = VRSceneManager::get()->getActiveScene();
    int a1, a2;
    a1 = scene->addAnimation(t, 0, fkt1, p0, p1, false);
    if (redirect) a2 = scene->addAnimation(t, 0, fkt2, n0, n1, false);
    else a2 = scene->addAnimation(t, 0, fkt2, d, d, false);
    animations.push_back(a1);
    animations.push_back(a2);
}
Example #9
0
PyObject* VRScriptManager::stackCall(VRScriptManager* self, PyObject *args) {
    PyObject *pyFkt, *pArgs = 0;
    float delay;
    if (PyTuple_Size(args) == 2) {
        if (! PyArg_ParseTuple(args, "Of", &pyFkt, &delay)) return NULL;
    } else if (! PyArg_ParseTuple(args, "OfO", &pyFkt, &delay, &pArgs)) return NULL;
    Py_IncRef(pyFkt);

    if (pArgs != 0) {
        std::string type = pArgs->ob_type->tp_name;
        if (type == "list") pArgs = PyList_AsTuple(pArgs);
    }

    VRFunction<int>* fkt = new VRFunction<int>( "pyExecCall", boost::bind(execCall, pyFkt, pArgs, _1) );

    VRScene* scene = VRSceneManager::getCurrent();
    scene->addAnimation(0, delay, fkt, 0, 0, false);
    Py_RETURN_TRUE;
}
Example #10
0
void VRSceneLoader::saveScene(string file, xmlpp::Element* guiN) {
    if (boost::filesystem::exists(file))
        file = boost::filesystem::canonical(file).string();
    cout << " save " << file << endl;
    VRScene* scene = VRSceneManager::getCurrent();
    if (scene == 0) return;

    xmlpp::Document doc;
    xmlpp::Element* sceneN = doc.create_root_node("Scene", "", "VRF"); //name, ns_uri, ns_prefix
    xmlpp::Element* objectsN = sceneN->add_child("Objects");
    if (guiN) sceneN->import_node(guiN, true);

    // save scenegraph
    scene->setPath(file);
    VRObject* root = scene->getRoot();
    xmlpp::Element* rootN = objectsN->add_child("Object");
    VRSceneLoader_saveObject(root, rootN);
    scene->save(sceneN);
    doc.write_to_file_formatted(file);
}
Example #11
0
void updateArgPtr(VRScript::arg* a) {
    string t = a->type;
    VRScene* scene = VRSceneManager::getCurrent();
    VRSetup* setup = VRSetupManager::getCurrent();

    if (t == "VRPyObjectType" || t == "VRPyGeometryType" || t == "VRPyTransformType" || t == "VRPyLightType" || t == "VRPyLodType") {
        a->ptr = (void*)scene->get(a->val);
        return;
    }
    if (t == "VRPySocketType") {
        a->ptr = (void*)scene->getSocket(a->val);
        return;
    }
    if (t == "VRPyDeviceType" || t == "VRPyHapticType") {
        a->ptr = (void*)setup->getDevice(a->val);
        return;
    }

    if (t == "int" || t == "float" || t == "str" || t == "NoneType") return;

    cout << "\nupdateArgPtr: " << t << " is an unknown argument type!" << endl;
}
Example #12
0
void VRGuiBits_on_viewoption_changed(GtkComboBox* cb, gpointer data) {
    int i = gtk_combo_box_get_active(cb);
    if (i == -1) return;

    // get all in
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    VRSetup* setup = VRSetupManager::get()->getCurrent();
    Glib::RefPtr<Gtk::ListStore> opt_list = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("view_options"));
    VRGuiSetup_ViewOptsColumns cols;
    Gtk::TreeModel::Row row = *getComboboxIter("combobox20");
    string opt = row.get_value(cols.option);
    bool b = row.get_value(cols.state);
    b = !b;

    // process option
    if (opt == "referentials") scene->showReferentials(b);
    if (opt == "setup") setup->showSetup(b);
    if (opt == "lights and cameras") scene->showLightsCameras(b);

    // update liststore toggle
    gtk_list_store_set (opt_list->gobj(), row.gobj(), 1, (int)b, -1);
    setCombobox("combobox20", -1);
}
Example #13
0
void VRGuiNet_updateList() {
    VRScene* scene = VRSceneManager::getCurrent();
    if (scene == 0) return;

    // update script list
    Glib::RefPtr<Gtk::ListStore> store = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("Sockets"));
    store->clear();

    map<string, VRSocket*> sockets = scene->getSockets();
    map<string, VRSocket*>::iterator itr;
    for (itr = sockets.begin(); itr != sockets.end(); itr++) {
        Gtk::ListStore::Row row = *store->append();
        VRSocket* socket = itr->second;
        gtk_list_store_set(store->gobj(), row.gobj(), 0, socket->getType().c_str(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 1, socket->getPort(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 2, socket->getIP().c_str(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 3, socket->getCallback().c_str(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 4, socket->getSignal()->getName().c_str(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 5, socket->getName().c_str(), -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 6, socket, -1);
        gtk_list_store_set(store->gobj(), row.gobj(), 7, socket->isClient(), -1);
    }
}
Example #14
0
void VRSceneManager::newScene(string path) {
    removeScene(getCurrent());

    VRScene* scene = new VRScene();
    scene->setPath(path);
    setWorkdir(scene->getWorkdir());
    scene->setName(scene->getFileName());
    VRTransform* cam = scene->addCamera("Default");

    VRLight* headlight = scene->addLight("Headlight");
    headlight->setType("point");
    VRLightBeacon* headlight_B = new VRLightBeacon("Headlight_beacon");
    headlight->setBeacon(headlight_B);
    VRTransform* user = VRSetupManager::getCurrent()->getUser();
    scene->add(headlight);
    headlight->addChild(cam);
    if (user) user->addChild(headlight_B);
    else cam->addChild(headlight_B);

    cam->setFrom(Vec3f(0,0,3));
    addScene(scene);
}
Example #15
0
// scene updated, get cameras and nav presets
void VRGuiBits::update() {
    // update camera liststore
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    setLabel("label24", "Project: None");
    if (scene == 0) return;

    vector<VRCamera*> cams = scene->getCameraMap();
    Glib::RefPtr<Gtk::ListStore> store = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("cameras"));
    store->clear();
    int active;
    for (uint i=0; i<cams.size(); i++) {
        if (cams[i] == scene->getActiveCamera()) active = i;
        Gtk::ListStore::Row row = *store->append();
        gtk_list_store_set (store->gobj(), row.gobj(), 0, cams[i]->getName().c_str(), -1);
    }

    // set active cam active
    Gtk::ComboBox* cb;
    VRGuiBuilder()->get_widget("combobox4", cb);
    cb->set_active(active);

    // update nav_presets liststore
    map<string, VRNavPreset*>::iterator itr;
    map<string, VRNavPreset*> presets = scene->getPresets();
    store = Glib::RefPtr<Gtk::ListStore>::cast_static(VRGuiBuilder()->get_object("nav_presets"));
    store->clear();
    for (itr = presets.begin(); itr != presets.end(); itr++) {
        Gtk::ListStore::Row row = *store->append();
        gtk_list_store_set (store->gobj(), row.gobj(), 0, itr->first.c_str(), -1);
        //if (itr->second) itr->second->setScene(scene);
    }

    // set first element active
    VRGuiBuilder()->get_widget("combobox9", cb);
    cb->set_active(0);

    // update setup and project label
    cout << " now running: " << scene->getName() << endl;
    setLabel("label24", "Project: " + scene->getName());
}
Example #16
0
void VRTransform::stopAnimation() {
    VRScene* scene = VRSceneManager::get()->getActiveScene();
    for (auto a : animations)
        scene->stopAnimation(a);
    animations.clear();
}
Example #17
0
void VRScript::update() {
    if (type == "HTML") {
        VRMobile* mob = (VRMobile*)VRSetupManager::getCurrent()->getDevice(mobile);
        if (mob) mob->addWebSite(getName(), core);
    }

    VRScene* scene = VRSceneManager::getCurrent();

    for (t_itr = trigs.begin(); t_itr != trigs.end(); t_itr++) {
        trig* t = t_itr->second;
        if (t->trigger == "on_timeout") {
            int i = toInt(t->param.c_str());
            scene->addTimeoutFkt(cbfkt_sys, 0, i);
            continue;
        }

        if (t->trigger == "on_device") {
            VRDevice* dev = VRSetupManager::getCurrent()->getDevice(t->dev);
            int state = -1;
            if (t->state == "Released") state = 0;
            if (t->state == "Pressed") state = 1;
            if (t->state == "Drag") state = 2;
            if (t->state == "Drop") state = 3;
            if (t->state == "To edge") state = 4;
            if (t->state == "From edge") state = 5;
            if (state == -1) continue;

            if (dev != 0) {
                if (state <= 1) t->sig = dev->addSignal(t->key, state);
                if (state == 2) t->sig = dev->getDragSignal();
                if (state == 3) t->sig = dev->getDropSignal();
                if (state == 4) t->sig = dev->getToEdgeSignal();
                if (state == 5) t->sig = dev->getFromEdgeSignal();
                if (t->sig == 0) continue;
                t->sig->add(cbfkt_dev);
            }

            // add dev argument
            if (args.count("dev") == 0) args["dev"] = new arg(VRName::getName(), "dev");
            arg* a = args["dev"];
            a->type = "VRPyDeviceType";
            a->val = "";
            a->trig = true;
            t->a = a;
            continue;
        }

        if (t->trigger == "on_socket") {
            t->soc = scene->getSocket(t->dev);
            if (t->soc == 0) continue;
            t->soc->setTCPCallback(cbfkt_soc);

            // add msg argument
            arg* a = new arg(VRName::getName(), "msg");
            args[a->getName()] = a;
            a->type = "str";
            a->val = "";
            t->a = a;
            a->trig = true;
            continue;
        }
    }

    // update args namespaces && map
    map<string, arg*> tmp_args;
    for (auto _a : args) {
        arg* a = _a.second;
        a->setNameSpace(VRName::getName());
        tmp_args[a->getName()] = a;
        changeArgValue(a->getName(), a->val);
    }
    args = tmp_args;

    // update head
    head = "";
    if (type == "Python") {
        head = "def " + name + "(";
        int i=0;
        for (a_itr = args.begin(); a_itr != args.end(); a_itr++, i++) {
            if (i != 0) head += ", ";
            head += a_itr->second->getName();
        }
        head += "):\n";
    }
}
Example #18
0
void VRSocket::handle(string s) {
    VRScene* scene = VRSceneManager::getCurrent();
    tcp_msg = s;
    scene->queueJob(queued_signal);
}