Esempio n. 1
0
void PythonPlugin::restoreProperties(const Archive& archive)
{
    Listing& pathListing = *archive.findListing("moduleSearchPath");
    if(pathListing.isValid()){
        MessageView* mv = MessageView::instance();
        PyGILock lock;
        python::list syspath = python::extract<python::list>(sysModule.attr("path"));
        string newPath;
        for(int i=0; i < pathListing.size(); ++i){
            newPath = archive.resolveRelocatablePath(pathListing[i].toString());
            if(!newPath.empty()){
                bool isExisting = false;
                list<string>::iterator p;
                for(p = additionalSearchPathList.begin(); p != additionalSearchPathList.end(); ++p){
                    if(newPath == (*p)){
                        isExisting = true;
                        break;
                    }
                }
                if(!isExisting){
                    syspath.insert(0, getNativePathString(filesystem::path(newPath)));
                    additionalSearchPathList.push_back(newPath);
                    mv->putln(format(_("PythonPlugin: \"%1%\" has been added to the python module search path list."))
                              % newPath);
                }
            }
        }
    }
}
Esempio n. 2
0
bool ExtCommandItem::execute()
{
    bool result = false;
    
    MessageView* mv = MessageView::instance();
    
    if(!command_.empty()){
        terminate();
        string actualCommand(command_);
#ifdef _WIN32
        if(filesystem::path(actualCommand).extension() != ".exe"){
            actualCommand += ".exe";
        }
        // quote the command string to support a path including spaces
        process.start(QString("\"") + actualCommand.c_str() + "\"");
#else
        process.start(actualCommand.c_str());
#endif

        if(process.waitForStarted()){
            mv->putln(fmt(_("External command \"%1%\" has been executed by item \"%2%\"."))
                      % actualCommand % name());

            if(waitingTimeAfterStarted_ > 0.0){
                msleep(waitingTimeAfterStarted_ * 1000.0);
            }
            
            result = true;

        } else {
            mv->put(fmt(_("External command \"%1%\" cannot be executed.")) % actualCommand);
            if(!boost::filesystem::exists(actualCommand)){
                mv->putln(_(" The command does not exist."));
            } else {
                mv->putln("");
            }
        }
    }
    return result;
}
    void onItemAdded(Item* item)
        {
            MessageView* mv = MessageView::instance();

            if(BodyItem* bodyItem = dynamic_cast<BodyItem*>(item)){
                Body* body = bodyItem->body();
                for(size_t i=0; i < body->numDevices(); ++i){
                    Device* device = body->device(i);
                    if(!camera){
                        camera = dynamic_pointer_cast<Camera>(device);
                        if(camera){
                            mv->putln(format("RTCVisionSensorSamplePlugin: Detected Camera \"%1%\" of %2%.")
                                      % camera->name() % body->name());
                            visionSensorSampleRTC->setCameraLocalT(camera->T_local());
                        }
                    }
                    if(!rangeSensor){
                        rangeSensor = dynamic_pointer_cast<RangeSensor>(device);
                        if(rangeSensor){
                            mv->putln(format("RTCVisionSensorSamplePlugin: Detected RangeSensor \"%1%\" of %2%.")
                                      % rangeSensor->name() % body->name());
                            visionSensorSampleRTC->setRangeSensorLocalT(rangeSensor->T_local());
                        }
                    }
                }
            }else if(PointSetItem* pointSetItem = dynamic_cast<PointSetItem*>(item)){
                if(pointSetItem->name() == "RangeCameraPoints"){
                    pointSetFromRangeCamera = pointSetItem->pointSet();
                    mv->putln("RTCVisionSensorSamplePlugin: Detected PointSetItem \"RangeCameraPoints\"");
                    visionSensorSampleRTC->setPointSetFromRangeCamera(pointSetFromRangeCamera);
                } else if(pointSetItem->name() == "RangeSensorPoints"){
                    pointSetFromRangeSensor = pointSetItem->pointSet();
                    mv->putln("RTCVisionSensorSamplePlugin: Detected PointSetItem \"RangeSensorPoints\"");
                    visionSensorSampleRTC->setPointSetFromRangeSensor(pointSetFromRangeSensor);
                }
            }
        }
static BodyCustomizerHandle create(BodyHandle bodyHandle, const char* modelName)
{
    HoseCustomizer* customizer = 0;

    int jointIndices[53];
    jointIndices[ 0] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_hose0");
	jointIndices[ 1] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_1st2L11WD");
	jointIndices[ 2] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L11WD2L11ND");
    jointIndices[ 3] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L11ND2L12WD");
	jointIndices[ 4] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L12WD2L12ND");
	jointIndices[ 5] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L12ND2L13WD");
    jointIndices[ 6] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L13WD2L13ND");
	jointIndices[ 7] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L13ND2S1WD");
	jointIndices[ 8] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S1WD2S1ND");
    jointIndices[ 9] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S1ND2L21WD");
	jointIndices[10] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L21WD2L21ND");
	jointIndices[11] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L21ND2L22WD");
    jointIndices[12] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L22WD2L22ND");
	jointIndices[13] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L22ND2L23WD");
	jointIndices[14] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L23WD2L23ND");
    jointIndices[15] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L23ND2S2WD");
	jointIndices[16] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S2WD2S2ND");
	jointIndices[17] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S2ND2L31WD");
    jointIndices[18] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L31WD2L31ND");
	jointIndices[19] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L31ND2L32WD");
	jointIndices[20] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L32WD2L32ND");
    jointIndices[21] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L32ND2L33WD");
	jointIndices[22] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L33WD2L33ND");
	jointIndices[23] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L33ND2S3WD");
    jointIndices[24] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S3WD2S3ND");
	jointIndices[25] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S3ND2L41WD");
	jointIndices[26] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L41WD2L41ND");
    jointIndices[27] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L41ND2L42WD");
	jointIndices[28] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L42WD2L42ND");
	jointIndices[29] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L42ND2L43WD");
    jointIndices[30] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L43WD2L43ND");
	jointIndices[31] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L43ND2S4WD");
	jointIndices[32] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S4WD2S4ND");
    jointIndices[33] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S4ND2L51WD");
	jointIndices[34] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L51WD2L51ND");
	jointIndices[35] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L51ND2L52WD");
    jointIndices[36] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L52WD2L52ND");
	jointIndices[37] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L52ND2L53WD");
	jointIndices[38] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L53WD2L53ND");
	jointIndices[39] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L53ND2S5WD");
	jointIndices[40] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S5WD2S5ND");
	jointIndices[41] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S5ND2L61WD");
	jointIndices[42] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L61WD2L61ND");
	jointIndices[43] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L61ND2L62WD");
	jointIndices[44] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L62WD2L62ND");
	jointIndices[45] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L62ND2L63WD");
	jointIndices[46] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L63WD2L63ND");
	jointIndices[47] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L63ND2S6WD");
	jointIndices[48] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S6WD2S6ND");
	jointIndices[49] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_S6ND2L71WD");
	jointIndices[50] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L71WD2L71ND");
	jointIndices[51] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L71ND2L72WD");
	jointIndices[52] = bodyInterface->getLinkIndexFromName(bodyHandle, "hinge_L72WD2L72ND");

    string name(modelName);

    MessageView* mv;
    mv = MessageView::instance();
    mv->putln("The hose customizer is running");

    if (name == "HOSE") {
        customizer = new HoseCustomizer;
        customizer->bodyHandle = bodyHandle;

		for (int i = 0; i < 53; i++) {
			
			int jointIndex = jointIndices[i];
			JointValSet& jointValSet = customizer->jointValSet[i];

			if (jointIndex >= 0) {
				jointValSet.q_ptr = bodyInterface->getJointValuePtr(bodyHandle, jointIndex);
				jointValSet.dq_ptr = bodyInterface->getJointVelocityPtr(bodyHandle, jointIndex);
				jointValSet.u_ptr = bodyInterface->getJointForcePtr(bodyHandle, jointIndex);
			}
			else {
				jointValSet.q_ptr = NULL;
				jointValSet.dq_ptr = NULL;
				jointValSet.u_ptr = NULL;
			}
		}
    }
    
    return static_cast<BodyCustomizerHandle>(customizer);
}
Esempio n. 5
0
void ViewManager::restoreViews(ArchivePtr archive, const std::string& key, ViewManager::ViewStateInfo& out_viewStateInfo)
{
    MessageView* mv = MessageView::instance();

    typedef map<ViewInfo*, vector<View*> > ViewsMap;
    ViewsMap remainingViewsMap;
        
    Listing* viewList = archive->findListing(key);
    
    if(viewList->isValid() && !viewList->empty()){

        vector<ViewState>* viewsToRestoreState = new vector<ViewState>();        
        out_viewStateInfo.data = viewsToRestoreState;
        int id;
        string moduleName;
        string className;
        string instanceName;
        
        for(int i=0; i < viewList->size(); ++i){
            Archive* viewArchive = dynamic_cast<Archive*>(viewList->at(i)->toMapping());
            if(viewArchive){
                bool isHeaderValid =
                    viewArchive->read("id", id) &&
                    viewArchive->read("plugin", moduleName) &&
                    viewArchive->read("class", className);
            
                if(isHeaderValid){
                    View* view = 0;
                    if(!viewArchive->read("name", instanceName)){
                        view = getOrCreateView(moduleName, className);
                    } else {
                        // get one of the view instances having the instance name, or create a new instance.
                        // Different instances are assigned even if there are instances with the same name in the archive
                        ViewInfo* info = findViewInfo(moduleName, className);
                        if(info){
                            vector<View*>* remainingViews;
                            ViewsMap::iterator p = remainingViewsMap.find(info);
                            if(p != remainingViewsMap.end()){
                                remainingViews = &p->second;
                            } else {
                                remainingViews = &remainingViewsMap[info];
                                InstanceInfoList& instances = info->instances;
                                remainingViews->reserve(instances.size());
                                InstanceInfoList::iterator q = instances.begin();
                                if(info->hasDefaultInstance() && q != instances.end()){
                                    ++q;
                                }
                                while(q != instances.end()){
                                    remainingViews->push_back((*q++)->view);
                                }
                            }
                            for(vector<View*>::iterator q = remainingViews->begin(); q != remainingViews->end(); ++q){
                                if((*q)->name() == instanceName){
                                    view = *q;
                                    remainingViews->erase(q);
                                    break;
                                }
                            }
                            if(!view){
                                if(!info->isSingleton() || info->instances.empty()){
                                    view = info->createView(instanceName, true);
                                } else {
                                    mv->putln(MessageView::ERROR,
                                              boost::format(_("A singleton view \"%1%\" of the %2% type cannot be created because its singleton instance has already been created."))
                                              % instanceName % info->className());
                                }
                            }
                        }
                    }
                    if(view){
                        archive->registerViewId(view, id);
                        
                        ArchivePtr state = viewArchive->findSubArchive("state");
                        if(state->isValid()){
                            state->inheritSharedInfoFrom(*archive);
                            viewsToRestoreState->push_back(ViewState(view, state));
                        }

                        if(viewArchive->get("mounted", false)){
                            mainWindow->viewArea()->addView(view);
                        }
                    }
                }
            }
        }
    }
}