Esempio n. 1
0
    void FilterRotate::execute()
    {
        Port* p = getPort("out");
        std::list<const Port*> primlist;
        p->getPrimitiveSiblingList(primlist);
        unsigned int numberOutputs = primlist.size();
        if (numberOutputs == 0)
            throw NoPrimitiveConnectedException("out", getFullId(), __FUNCTION_NAME__);


        FilterRotatePrimitive * frotate = addObject<FilterRotatePrimitive>("RotateFilter");        
        
        frotate->setParameter("nb",toString<unsigned int>(numberOutputs));
        frotate->setParameter("elementsize",toString<unsigned int>(1));
        
        
        frotate->createPorts();
        
        unsigned int counter = 0;

	//link the output port to out0,out1, ..., outn
        for( std::list<const Port*>::const_iterator it = primlist.begin(); it != primlist.end(); ++it)
            {
                link(p, frotate->getPort("out" + toString<unsigned int>(counter)));
                frotate->getPort("out" + toString<unsigned int>(counter))->addRestrictionToPrimitiveSibling(*it);
                counter++;
            }
        link(frotate->getPort("in"), getPort("in"));
    }
    void msPhysicalInterface::setParameters(boost::shared_ptr<msParamsManager> param){
        
        LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::setParameters(boost::shared_ptr<msParamsManager> param)", getFullId());
        LOGGER_WRITE(msLogger::DEBUG, "set the parameters from type "+param->getType())
        
        try{
            msTreeMapper::update<msParamsManager>( Parameters , param);
            Parameters->addObjectUsingMe( boost::static_pointer_cast<msPhysicalInterface>( mySharedPtr() ) );
            Parameters->setAffiliation(mySharedPtr());
            updateParameters();
        }
        catch(msException& e){
            
            e.addContext("void msPhysicalInterface::setParameters(boost::shared_ptr<msParamsManager> param)");
	    throw e;
        }
        LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::setParameters(boost::shared_ptr<msParamsManager> param)");
        
    }
    void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id) {
      
        LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id)", getFullId());
	 
        if(id=="") id = "var_"+output::getString<size_t>(PhysicalVariables.size());
        *ptr = getUnits()->convert(unit,value);
        PhysicalVariables[id] = boost::shared_ptr<msPhysicalVariable>(new msPhysicalVariable(id,ptr,unit));
	LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::declarePhysicalVariable(double* ptr,double value,const msUnit& unit,string id)");
       //PtrOnPhysicalVariables[ptr] =  unit;
    }
 void msPhysicalInterface::updateUnits(msUnitsManager& Old,msUnitsManager& New) {
     
     LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::updateUnits(msUnitsManager& Old,msUnitsManager& New)", getFullId());
     LOGGER_WRITE(msLogger::DEBUG, "update the value of the physical variables declared")
     /*
     map< double* , msUnit >::iterator it = PtrOnPhysicalVariables.begin();
     
     for(;it!=PtrOnPhysicalVariables.end();++it){
         
         *((*it).first) *= New.convert( (*it).second, 1 );
         (*it).second.reset(New);
     }*/
     map< string, boost::shared_ptr<msPhysicalVariable> >::iterator it = PhysicalVariables.begin();
     
     for(;it!=PhysicalVariables.end();++it)  (*it).second->reset( New );
     
     LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::updateUnits(msUnitsManager& Old,msUnitsManager& New)");
 }
    void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units){
        
        LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units)", getFullId());
        msUnitsManager old;
        old.set( Units->getExpression() );
        
        msTreeMapper::update<msUnitsManager>( Units , units);
        units->addObjectUsingMe( boost::static_pointer_cast<msPhysicalInterface>( mySharedPtr() ) );
	LOGGER_WRITE(msLogger::DEBUG, "Number of objects using the units: " + output::getString<size_t>(getUnits()->LinkedObjects.size()));
        updateUnits(old,*units);
	
	LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::setUnits(boost::shared_ptr<msUnitsManager> units)");        
    }
 void msPhysicalInterface::setParameter(string key,string value){
     
     LOGGER_ENTER_FUNCTION_DBG("void msPhysicalInterface::setParameter(string key,string value)", getFullId());
     
     try{
         Parameters->setParameter(key,value,*Units);
         updateParameters();
     }
     catch(msException& e){
         
         e.addContext("void msPhysicalInterface::setParameter(string key,string value)");
     }
     LOGGER_EXIT_FUNCTION2("void msPhysicalInterface::setParameter(string key,string value)");
     
 }