Exemple #1
0
Trigger *Table::getTrigger(const QString &name)
{
	int idx;
	return(dynamic_cast<Trigger *>(getObject(name,OBJ_TRIGGER,idx)));
}
      void DetectorObjectView::check()
      {
        InternalMessage("Model","Model::DetectorObjectView::check entering") ;
        
        Detector* detector = getViewPoint()->getObserver() ;
        if (!detector)
          return ;
        bool in_range = detector ? detector->canDetect(getObject()) : false ;
        
        if (!detector->getComputer())
          return ;        
        
        Computer* computer = detector->getComputer()->getTrait<Computer>() ;
        if (! computer)
          return ;
                  
        if (!in_range && m_detection_information)
        {
          // destroy object
          computer->getMemoryModel()->destroyObject(m_detection_information) ;
          m_detection_information = NULL ;
        }
        else if (in_range)
        {
          InternalMessage(
            "Model",
            "Model::DetectorObjectView::check in range updating detection data") ;
          
          bool mobile = false ;
          
          if (! m_detection_information)
          {
            Solid* solid = getObject()->getTrait<Solid>() ;
            
            // create object 
            m_detection_information = computer->getMemoryModel()->createObject() ;
            m_detection_information->addTrait(new DetectionData(detector->getComputer())) ;
            m_detection_information->addTrait(new Positionned()) ;
            m_detection_information->addTrait(new Solid(solid->getMesh())) ;

            m_detection_information->getTrait<DetectionData>()->m_detected = getObject() ;
          }
          // update object position
          Position position = getRelativePosition(getObject(),
                                                  computer->getObject()) ;
          
          m_detection_information->getTrait<Positionned>()->setPosition(position) ;
          
          // update speed if exists
          Mobile* mobileTrait = getObject()->getTrait<Mobile>() ;
          
          if (mobileTrait)
          {
            Mobile* data = m_detection_information->getTrait<Mobile>() ;
            if (! data)
            {
              data = new Mobile() ;
              m_detection_information->addTrait(data) ;
            }
            data->setSpeed(mobileTrait->getSpeed()) ;
            data->setAngularSpeed(mobileTrait->getAngularSpeed()) ;
          }

          // update identification
          Transponder* identified = 
              getObject()->getTrait<Transponder>() ; 
          
          Transponder* identifedData = 
              m_detection_information->getTrait<Transponder>() ; 
          
          if (identified)
          {
            if (! identifedData)
            {
              // gained identification
              m_detection_information->addTrait(new Transponder(*identified)) ;
            }
            else if (identifedData->getCode() != identified->getCode())
            {
              // changed identification
              identifedData->setCode(identified) ;
            }
          }
          else if (identifedData)
          {
            // lost identification
            m_detection_information->destroyTrait(identifedData) ;
          }

          // update Targetting
          std::set<TargetingSystem*> systems = getObject()->getChildren<TargetingSystem>() ;
          TargetingSystem* system_data = 
              m_detection_information->getTrait<TargetingSystem>() ;
          
          if (systems.size() == 1)
          {
            TargetingSystem* system = *(systems.begin()) ;
            
            if (! system_data)
            {
              // gained identification
              m_detection_information->addTrait(new TargetingSystem()) ;
              
              m_detection_information->getTrait<TargetingSystem>()->m_target =
                system->getTarget() ;
              m_detection_information->getTrait<TargetingSystem>()->notify() ;
            }
            else if (system_data->getTarget() != system->getTarget())
            {
              // changed selection
              system_data->m_target = system->getTarget() ;
              system_data->notify() ;
            }
          }
          else if (system_data)
          {
            // lost targeting system
            m_detection_information->destroyTrait(system_data) ;
          }
          
        }
        
        
        InternalMessage("Model","Model::DetectorObjectView::check leaving") ;
      }
DynamicObject* var::getDynamicObject() const noexcept   { return dynamic_cast <DynamicObject*> (getObject()); }
 void ActivatedMission::onInit()
 {
   getTrait<Mission>()->load() ;
   getObject()->getModel()->resetStatistics() ;
 }
Exemple #5
0
void RunnerSprite::extralInit(){
    auto roleGroup = this->mMap->getObjectGroup("role");
    ValueMap obj = static_cast<ValueMap>(roleGroup->getObject("player"));
    
    float spX = obj["x"].asFloat();
    float spY = obj["y"].asFloat();

    SpriteFrameCache::getInstance()->addSpriteFramesWithFile("playerrun.plist", "playerrun.png");
    mRunner = cocos2d::Sprite::createWithSpriteFrameName("image1.png");
    mRunner->setPosition(Vec2(spX,spY));
    mRunner->setAnchorPoint(Vec2(0.5,0.0));
    
    mMap->addChild(mRunner);
    auto runAnim = Animation::create();
    for(int i = 1;i<17;i++){
        char nameBuf[100] = {0};
        sprintf(nameBuf, "image%d.png",i);
        auto frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(nameBuf);
        runAnim->addSpriteFrame(frame);
    }
    runAnim->setDelayPerUnit(0.06f);
    runAnim->setRestoreOriginalFrame(true);
    AnimationCache::getInstance()->addAnimation(runAnim,"runAction");
    
    
    
    auto colGroup = mMap->getObjectGroup("collision");
    auto colObj = colGroup->getObjects();
    CCLOG("objs %lu",colObj.size());
    
    barriers.reserve(colObj.size());
    
    for(ValueVector::iterator it  = colObj.begin(); it != colObj.end(); ++it) {
        ValueMap mp = it->asValueMap();
        barriers.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
    }
    
    auto colGroup2 = mMap->getObjectGroup("collision");
    auto colObj2 = colGroup2->getObjects();
    CCLOG("objs %lu",colObj.size());
    
    goldens.reserve(colObj2.size());
    goldenSs.reserve(colObj2.size());
    int i = 0;
    for(ValueVector::iterator it  = colObj2.begin(); it != colObj2.end(); ++it) {
        ValueMap mp = it->asValueMap();
        goldens.push_back(Rect(mp["x"].asFloat(), mp["y"].asFloat(), mp["width"].asFloat(), mp["height"].asFloat()));
        auto gold =  Sprite::create("gold.png");
        gold->setAnchorPoint(Vec2(0.5,0.5));
        gold->setPosition(Vec2(mp["x"].asFloat(), mp["y"].asFloat() + 180));
        gold->setScale(0.2, 0.2);
        gold->setTag(2800+i);
        mMap->getLayer("ground")->addChild(gold);
        goldenSs.push_back(gold);
        i++;
    }
    
    
    setRunState(kROLERUN);
    
    auto runAim = RepeatForever::create(Animate::create(AnimationCache::getInstance()->getAnimation("runAction"))) ;
    this->mRunner->runAction(runAim);
    
    gNum = 0;
    mNum = 0;

}
 Model::Orientation SoundEmitter::getOrientation() const
 {
   return Model::getRelativeOrientation(getObject(),getObject()->getRoot()) ;
 }
Exemple #7
0
const Field& SetFieldValueAST::getField(const TypeChecker& checker) const {
	return getObject(checker).getField(getMemberName());
}
Exemple #8
0
Rule *Table::getRule(const QString &name)
{
	int idx;
	return(dynamic_cast<Rule *>(getObject(name,OBJ_RULE,idx)));
}
Exemple #9
0
Rule *Table::getRule(unsigned idx)
{
	return(dynamic_cast<Rule *>(getObject(idx,OBJ_RULE)));
}
Exemple #10
0
Index *Table::getIndex(const QString &name)
{
	int idx;
	return(dynamic_cast<Index *>(getObject(name,OBJ_INDEX,idx)));
}
Exemple #11
0
Index *Table::getIndex(unsigned idx)
{
	return(dynamic_cast<Index *>(getObject(idx,OBJ_INDEX)));
}
Exemple #12
0
Constraint *Table::getConstraint(unsigned idx)
{
	return(dynamic_cast<Constraint *>(getObject(idx,OBJ_CONSTRAINT)));
}
Exemple #13
0
Constraint *Table::getConstraint(const QString &name)
{
	int idx;
	return(dynamic_cast<Constraint *>(getObject(name,OBJ_CONSTRAINT,idx)));
}
Exemple #14
0
Trigger *Table::getTrigger(unsigned idx)
{
	return(dynamic_cast<Trigger *>(getObject(idx,OBJ_TRIGGER)));
}
Exemple #15
0
void JFont::readContent(JDictionary& dict) {
  JObject::readContent(dict);
  name = *(JString*)getObject(dict, "name");
  style = getInteger(dict, "style");
  size = getInteger(dict, "size");
}
Exemple #16
0
/// Generic object access, given a path from the current context
///
/// Note that the template wrapper method should generally be used to have the correct return type,
void* GNode::getObject(const sofa::core::objectmodel::ClassInfo& class_info, const std::string& path) const
{
    if (path.empty())
    {
        return Node::getObject(class_info, Local);
    }
    else if (path[0] == '/')
    {
        if (parent()) return parent()->getObject(class_info, path);
        else return getObject(class_info,std::string(path,1));
    }
    else if (std::string(path,0,2)==std::string("./"))
    {
        std::string newpath = std::string(path, 2);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        return getObject(class_info,newpath);
    }
    else if (std::string(path,0,3)==std::string("../"))
    {
        std::string newpath = std::string(path, 3);
        while (!newpath.empty() && path[0] == '/')
            newpath.erase(0);
        if (parent()) return parent()->getObject(class_info,newpath);
        else return getObject(class_info,newpath);
    }
    else
    {
        std::string::size_type pend = path.find('/');
        if (pend == std::string::npos) pend = path.length();
        std::string name ( path, 0, pend );
        Node* child = getChild(name);
        if (child)
        {
            while (pend < path.length() && path[pend] == '/')
                ++pend;
            return child->getObject(class_info, std::string(path, pend));
        }
        else if (pend < path.length())
        {
            //std::cerr << "ERROR: child node "<<name<<" not found in "<<getPathName()<<std::endl;
            return NULL;
        }
        else
        {
            core::objectmodel::BaseObject* obj = simulation::Node::getObject(name);
            if (obj == NULL)
            {
                //std::cerr << "ERROR: object "<<name<<" not found in "<<getPathName()<<std::endl;
                return NULL;
            }
            else
            {
                void* result = class_info.dynamicCast(obj);
                if (result == NULL)
                {
                    std::cerr << "ERROR: object "<<name<<" in "<<getPathName()<<" does not implement class "<<class_info.name()<<std::endl;
                    return NULL;
                }
                else
                {
                    return result;
                }
            }
        }
    }
}
 Model::Position SoundEmitter::getPosition() const
 {
   return Model::getRelativePosition(getObject(),getObject()->getRoot()) ;
 }
Exemple #18
0
	RelationalObjectRef RelationalCollection::getObjectRef(int index) const{
		RelationalObject *object = getObject(index);
		RelationalObjectRef object_ref(object);
		delete object;
		return object_ref;
	}
Exemple #19
0
const Field& MemberAccessAST::getField(const TypeChecker& checker) const {
	auto memberName = getMemberName();
	return getObject(checker).getField(memberName);
}
Exemple #20
0
	RelationalObject* RelationalCollection::getObject(int index) const {
		RelationalObject *object = getObject();
		object->load(record(index));
		return object;
	}
Exemple #21
0
const ViewObject* ViewIndex::getTopObject(const vector<ViewLayer>& layers) const {
  for (int i = layers.size() - 1; i >= 0; --i)
    if (hasObject(layers[i]))
      return &getObject(layers[i]);
  return nullptr;
}
void ObservationGenerator::generateGoalObservations() {
    getSelf(gtSelf, obsSelf, player_);
    int seenPostCount = 0;
    int firstPost = 0;
    for (int i = WO_OWN_LEFT_GOALPOST; i <= WO_OPP_RIGHT_GOALPOST; i++) {
        getObject(gtPost, obsPost, i);
        float bearing = gtSelf.loc.getBearingTo(gtPost.loc,gtSelf.orientation);
        float distance = gtSelf.loc.getDistanceTo(gtPost.loc);
        if(isVisible(i)) {
            float missedObsRate = 1.0/10.0;
            if (distance > 3000)
                missedObsRate = 1.0/3.0;
            float randPct = rand_.sampleU();
            if (randPct > (missedObsRate * MISSED_OBS_FACTOR) && distance < 7000) {
                // seen
                obsPost.seen = true;
                if (seenPostCount == 0) firstPost = i;
                seenPostCount++;
                float diff = joint_->values_[HeadPan] - bearing;
                obsPost.imageCenterX = iparams_.width/2.0 + (diff / (FOVx/2.0) * iparams_.width/2.0);
                obsPost.imageCenterY = iparams_.height/2.0;
                // add distance and bearing noise
                float randNoise = rand_.sampleU()-0.5;
                obsPost.visionDistance = distance + randNoise * VISION_ERROR_FACTOR * 0.25*distance;// up to 25% distance error
                obsPost.visionBearing = bearing + randNoise * VISION_ERROR_FACTOR * 5.0*DEG_T_RAD;// up to 5 deg bearing error
                obsPost.visionConfidence = 1.0;


            }
        }
    }

    // actually have to fill those into unknown post spot
    if (seenPostCount == 1) {
        // fill in unknown post
        WorldObject& obsPost = obs_object_->objects_[WO_UNKNOWN_GOALPOST];
        WorldObject& known = obs_object_->objects_[firstPost];
        obsPost.seen = true;
        obsPost.frameLastSeen = frame_info_->frame_id;
        obsPost.imageCenterX = known.imageCenterX;
        obsPost.imageCenterY = known.imageCenterY;
        obsPost.visionDistance = known.visionDistance;
        obsPost.visionBearing = known.visionBearing;
        obsPost.visionConfidence = 1.0;
        known.seen = false;

    }
    else if (seenPostCount == 2) {
        // fill in left and right post and goal with average of two
        float sumX = 0;
        float sumDist = 0;
        float sumBear = 0;
        for (int i = 0; i < 2; i++) {
            WorldObject& obsPost = obs_object_->objects_[WO_UNKNOWN_LEFT_GOALPOST+i];
            WorldObject& known = obs_object_->objects_[firstPost+(i*2)];
            obsPost.seen = true;
            obsPost.frameLastSeen = frame_info_->frame_id;
            obsPost.imageCenterX = known.imageCenterX;
            obsPost.imageCenterY = known.imageCenterY;
            obsPost.visionDistance = known.visionDistance;
            obsPost.visionBearing = known.visionBearing;
            obsPost.visionConfidence = 1.0;

            known.seen = false;
            sumX += obsPost.imageCenterX;
            sumDist += obsPost.visionDistance;
            sumBear += obsPost.visionBearing;

        }
        WorldObject& obsPost = obs_object_->objects_[WO_UNKNOWN_GOAL];
        obsPost.seen = true;
        obsPost.frameLastSeen = frame_info_->frame_id;
        obsPost.imageCenterX = sumX / 2.0;
        obsPost.imageCenterY = iparams_.height/2.0;
        obsPost.visionDistance = sumDist / 2.0;
        obsPost.visionBearing = sumBear / 2.0;
        obsPost.visionConfidence = 1.0;

    } else if (seenPostCount > 2) {
        //cout << index_ << " error saw more than 2 posts: " << seenPostCount << endl;
    }
}
Exemple #23
0
JSValue QtInstance::booleanValue() const
{
    // ECMA 9.2
    return jsBoolean(getObject());
}
void ConfigStabilizationWidget::setupStabBanksGUI()
{
    StabilizationSettings *stabSettings = qobject_cast<StabilizationSettings *>(getObject("StabilizationSettings"));

    Q_ASSERT(stabSettings);

    m_stabSettingsBankCount = stabSettings->getField("FlightModeMap")->getOptions().count();

    // Set up fake tab widget stuff for pid banks support
    m_stabTabBars.append(ui->basicPIDBankTabBar);
    m_stabTabBars.append(ui->advancedPIDBankTabBar);

    QAction *defaultStabMenuAction = new QAction(QIcon(":configgadget/images/gear.png"), QString(), this);
    QAction *restoreAllAction     = new QAction(tr("all to saved"), this);
    connect(restoreAllAction, SIGNAL(triggered()), this, SLOT(restoreAllStabBanks()));
    QAction *resetAllAction       = new QAction(tr("all to default"), this);
    connect(resetAllAction, SIGNAL(triggered()), this, SLOT(resetAllStabBanks()));
    QAction *restoreCurrentAction = new QAction(tr("to saved"), this);
    connect(restoreCurrentAction, SIGNAL(triggered()), this, SLOT(restoreCurrentAction()));
    QAction *resetCurrentAction   = new QAction(tr("to default"), this);
    connect(resetCurrentAction, SIGNAL(triggered()), this, SLOT(resetCurrentStabBank()));
    QAction *copyCurrentAction    = new QAction(tr("to others"), this);
    connect(copyCurrentAction, SIGNAL(triggered()), this, SLOT(copyCurrentStabBank()));
    connect(&m_stabSettingsCopyFromSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyFromBankToCurrent(int)));
    connect(&m_stabSettingsCopyToSignalMapper, SIGNAL(mapped(int)), this, SLOT(copyToBankFromCurrent(int)));
    connect(&m_stabSettingsSwapSignalMapper, SIGNAL(mapped(int)), this, SLOT(swapBankAndCurrent(int)));

    foreach(QTabBar * tabBar, m_stabTabBars) {
        for (int i = 0; i < m_stabSettingsBankCount; i++) {
            tabBar->addTab(tr("Settings Bank %1").arg(i + 1));
            tabBar->setTabData(i, QString("StabilizationSettingsBank%1").arg(i + 1));
            QToolButton *tabButton = new QToolButton();
            connect(this, SIGNAL(enableControlsChanged(bool)), tabButton, SLOT(setEnabled(bool)));
            tabButton->setDefaultAction(defaultStabMenuAction);
            tabButton->setAutoRaise(true);
            tabButton->setPopupMode(QToolButton::InstantPopup);
            tabButton->setToolTip(tr("The functions in this menu effect all fields in the settings banks,\n"
                                     "not only the ones visible on screen."));
            QMenu *tabMenu     = new QMenu();
            QMenu *restoreMenu = new QMenu(tr("Restore"));
            QMenu *resetMenu   = new QMenu(tr("Reset"));
            QMenu *copyMenu    = new QMenu(tr("Copy"));
            QMenu *swapMenu    = new QMenu(tr("Swap"));
            QAction *menuAction;
            for (int j = 0; j < m_stabSettingsBankCount; j++) {
                if (j == i) {
                    restoreMenu->addAction(restoreCurrentAction);
                    resetMenu->addAction(resetCurrentAction);
                    copyMenu->addAction(copyCurrentAction);
                } else {
                    menuAction = new QAction(tr("from %1").arg(j + 1), this);
                    connect(menuAction, SIGNAL(triggered()), &m_stabSettingsCopyFromSignalMapper, SLOT(map()));
                    m_stabSettingsCopyFromSignalMapper.setMapping(menuAction, j);
                    copyMenu->addAction(menuAction);

                    menuAction = new QAction(tr("to %1").arg(j + 1), this);
                    connect(menuAction, SIGNAL(triggered()), &m_stabSettingsCopyToSignalMapper, SLOT(map()));
                    m_stabSettingsCopyToSignalMapper.setMapping(menuAction, j);
                    copyMenu->addAction(menuAction);

                    menuAction = new QAction(tr("with %1").arg(j + 1), this);
                    connect(menuAction, SIGNAL(triggered()), &m_stabSettingsSwapSignalMapper, SLOT(map()));
                    m_stabSettingsSwapSignalMapper.setMapping(menuAction, j);
                    swapMenu->addAction(menuAction);
                }
            }
            restoreMenu->addAction(restoreAllAction);
            resetMenu->addAction(resetAllAction);
            tabMenu->addMenu(copyMenu);
            tabMenu->addMenu(swapMenu);
            tabMenu->addMenu(resetMenu);
            tabMenu->addMenu(restoreMenu);
            tabButton->setMenu(tabMenu);
            tabBar->setTabButton(i, QTabBar::RightSide, tabButton);
        }
        tabBar->setExpanding(false);
        connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(stabBankChanged(int)));
    }

    for (int i = 0; i < m_stabSettingsBankCount; i++) {
        if (i > 0) {
            m_stabilizationObjectsString.append(",");
        }
        m_stabilizationObjectsString.append(m_stabTabBars.at(0)->tabData(i).toString());
    }
}
    std::string BaseControler::toString() const
    {
      std::string result(getObjectTypeIdentifier(this).fullName()) ;

      return result + "(" + Kernel::toString(getObject()->getIdentifier()) + ")" ;
    }
UAVObject *ConfigStabilizationWidget::getStabBankObject(int bank)
{
    return getObject(QString("StabilizationSettingsBank%1").arg(bank + 1));
}
 void Mission::load()
 {
   Model::loadMission(m_name,getObject(),m_player_configuration,m_main_menu) ;
 }
Exemple #28
0
/*!
  To set the values of centred moments. Required when normalizing the moment values.
  @param i : first index of the 2D moment.
  @param j : second index of the 2D moment.
  @param value : value of the moment.
*/
void vpMomentCentered::set(unsigned int i, unsigned int j, double value){
    vpMomentObject mobj = getObject();
    assert(i+j<=mobj.getOrder());
    if(i+j>mobj.getOrder()) throw vpException(vpException::badValue,"You cannot set that value.");
    values[j*(mobj.getOrder()+1)+i] = value;
}
update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, ScicosID v)
{
    model::BaseObject* baseObject = getObject(uid);
    if (baseObject == nullptr)
    {
        return FAIL;
    }

    if (k == ANNOTATION)
    {
        model::Annotation* o = static_cast<model::Annotation*>(baseObject);
        switch (p)
        {
            case PARENT_DIAGRAM:
                return o->setParentDiagram(v);
            case PARENT_BLOCK:
                return o->setParentBlock(v);
            default:
                break;
        }
    }
    else if (k == BLOCK)
    {
        model::Block* o = static_cast<model::Block*>(baseObject);
        switch (p)
        {
            case PARENT_DIAGRAM:
                return o->setParentDiagram(v);
            case PARENT_BLOCK:
                return o->setParentBlock(v);
            case PORT_REFERENCE:
                return o->setPortReference(v);
            default:
                break;
        }
    }
    else if (k == DIAGRAM)
    {
        switch (p)
        {
            default:
                break;
        }
    }
    else if (k == LINK)
    {
        model::Link* o = static_cast<model::Link*>(baseObject);
        switch (p)
        {
            case PARENT_DIAGRAM:
                return o->setParentDiagram(v);
            case PARENT_BLOCK:
                return o->setParentBlock(v);
            case SOURCE_PORT:
                return o->setSourcePort(v);
            case DESTINATION_PORT:
                return o->setDestinationPort(v);
            default:
                break;
        }
    }
    else if (k == PORT)
    {
        model::Port* o = static_cast<model::Port*>(baseObject);
        switch (p)
        {
            case SOURCE_BLOCK:
                return o->setSourceBlock(v);
            case CONNECTED_SIGNALS:
                return o->setConnectedSignals(std::vector<ScicosID> (1, v));
            default:
                break;
        }
    }
    return FAIL;
}
Exemple #30
0
Column *Table::getColumn(unsigned idx)
{
	return(dynamic_cast<Column *>(getObject(idx,OBJ_COLUMN)));
}