예제 #1
0
void
StepRepeat::initialize(QXmlStreamReader& xml)
{
  m_stepRef = getStringAttribute(xml, "StepRepeat", "stepRef");
  m_x = getDoubleAttribute(xml, "StepRepeat", "x");
  m_y = getDoubleAttribute(xml, "StepRepeat", "y");
  m_nx = getNonNegativeIntAttribute(xml, "StepRepeat", "nx");
  m_ny = getNonNegativeIntAttribute(xml, "StepRepeat", "ny");
  m_dx = getNonNegativeDoubleAttribute(xml, "StepRepeat", "dx");
  m_dy = getNonNegativeDoubleAttribute(xml, "StepRepeat", "dy");
  m_angle = getDoubleAttribute(xml, "StepRepeat", "angle");
  m_mirror = getBoolAttribute(xml, "mirror");
}
예제 #2
0
bool cAlarmServer::loadAlarmConfig(const UtlString& alarmFile, const UtlString& groupFile)
{
   // load global alarm config from alarm-config.xml
   OsSysLog::add(FAC_ALARM, PRI_DEBUG, "Loading alarm config files '%s' '%s'",
                 alarmFile.data(), groupFile.data());

   // Load the alarm configuration file
   TiXmlDocument alarmDoc(alarmFile);
   TiXmlHandle alarmDocHandle( &alarmDoc );
   if (!alarmDoc.LoadFile())
   {
      UtlString errorMsg;
      XmlErrorMsg( alarmDoc, errorMsg );
      OsSysLog::add(FAC_ALARM, PRI_ERR, "Failed to load alarm config file: %s", errorMsg.data());
      return false;
   }
   TiXmlHandle alarmDocH( &alarmDoc );
   TiXmlHandle alarmServerHandle = alarmDocH.FirstChildElement("alarm_server");

   // Load the alarm group configuration file
   TiXmlDocument groupDoc(groupFile);
   TiXmlHandle groupDocHandle( &groupDoc );
   if (!groupDoc.LoadFile())
   {
      UtlString errorMsg;
      XmlErrorMsg( groupDoc, errorMsg );
      OsSysLog::add(FAC_ALARM, PRI_ERR, "Failed to load alarm group config file: %s", errorMsg.data());
      return false;
   }
   TiXmlHandle groupDocH( &groupDoc );
   TiXmlHandle groupServerHandle = groupDocH.FirstChildElement("alarm_groups");

   // Continue to process the alarm configuration file
   TiXmlElement* settingsElement = alarmServerHandle.FirstChildElement("settings").Element();
   if (!settingsElement)
   {
      OsSysLog::add(FAC_ALARM, PRI_ERR,
                    "No <settings> element in alarm config file '%s'",
                    alarmFile.data());
      return false;
   }

   TiXmlElement* langElement = settingsElement->FirstChildElement("language");
   if (langElement)
   {
      textContentShallow(mLanguage, langElement);
      OsSysLog::add(FAC_ALARM, PRI_INFO, "Language for alarm notifications: %s", mLanguage.data());
   }

   //load alarm action settings
   TiXmlElement* alarmActionsElement = settingsElement->FirstChildElement("actions");
   if (alarmActionsElement)
   {
      TiXmlElement* element = alarmActionsElement->FirstChildElement("log");
      if (getBoolAttribute(element, "enabled"))
      {
         LogNotifier* pLogNotifier = new LogNotifier();
         if (mpNotifiers[cAlarmData::eActionLog])
         {
            delete mpNotifiers[cAlarmData::eActionLog];
         }
         mpNotifiers[cAlarmData::eActionLog] = pLogNotifier;
         if (pLogNotifier)
         {
            pLogNotifier->init(element, NULL);
            gbActions[cAlarmData::eActionLog] = true;
         }
      }

      // Alarm email notifications
      element = alarmActionsElement->FirstChildElement("email");
      if (getBoolAttribute(element, "enabled"))
      {
         EmailNotifier* pEmailNotifier = new EmailNotifier();
         if (mpNotifiers[cAlarmData::eActionEmail])
         {
            delete mpNotifiers[cAlarmData::eActionEmail];
         }
         mpNotifiers[cAlarmData::eActionEmail] = pEmailNotifier;
         if (pEmailNotifier)
         {
            TiXmlElement* groupElement = groupServerHandle.FirstChildElement("definitions").Element();
            pEmailNotifier->init(element, groupElement);
            gbActions[cAlarmData::eActionEmail] = true;
         }
      }

      element = alarmActionsElement->FirstChildElement("sms");
      if (getBoolAttribute(element, "enabled"))
      {
         SmsNotifier* pSmsNotifier = new SmsNotifier();
         if (mpNotifiers[cAlarmData::eActionSms])
         {
            delete mpNotifiers[cAlarmData::eActionSms];
         }
         mpNotifiers[cAlarmData::eActionSms] = pSmsNotifier;
         if (pSmsNotifier)
         {
            TiXmlElement* groupElement = groupServerHandle.FirstChildElement("definitions").Element();
            pSmsNotifier->init(element, groupElement);
            gbActions[cAlarmData::eActionSms] = true;
         }
      }

      // Alarm SNMPv2 trap notifications
      element = alarmActionsElement->FirstChildElement("trap");
      if (getBoolAttribute(element, "enabled"))
      {
         TrapNotifier* pTrapNotifier = new TrapNotifier();
         if (mpNotifiers[cAlarmData::eActionTrap])
         {
            delete mpNotifiers[cAlarmData::eActionTrap];
         }
         mpNotifiers[cAlarmData::eActionTrap] = pTrapNotifier;
         if (pTrapNotifier)
         {
            TiXmlElement* groupElement = groupServerHandle.FirstChildElement("definitions").Element();
            pTrapNotifier->init(element, groupElement);
            gbActions[cAlarmData::eActionTrap] = true;
         }
      }
      else
      {
         // The trap notification of alarms is disabled.
         // So, delete the notifier
         if (mpNotifiers[cAlarmData::eActionTrap])
         {
            delete mpNotifiers[cAlarmData::eActionTrap];
            mpNotifiers[cAlarmData::eActionTrap] = 0;
         }
         gbActions[cAlarmData::eActionTrap] = false;
      }
   }
   return true;
}
예제 #3
0
bool cAlarmServer::loadAlarmData(TiXmlElement* element, cAlarmData* data)
{

   UtlString codeStr;
   UtlString idStr;
   UtlString compStr("");
   UtlString sevStr("minor");
   UtlString resStr("");
   UtlString groupName("disabled");
   bool actEmail = true;
   bool actSms = true;
   bool actLog = true;
   bool actTrap = true;
   int  filtMax = INT_MAX;
   int  filtMin = 0;
   if (element && data)
   {
      idStr = element->Attribute("id");
      if (idStr.isNull())
      {
         OsSysLog::add(FAC_ALARM, PRI_ERR,"code=%s: alarm ID is required", codeStr.data());
         return false;
      }

      TiXmlElement* codeElement = element->FirstChildElement("code");
      if ( !codeElement )
      {
         OsSysLog::add(FAC_ALARM, PRI_ERR,
               "id=%s: alarm code is required", element->Attribute("id"));
         return false;
      }
      textContentShallow(codeStr, codeElement);

      codeElement = element->FirstChildElement("severity");
      if ( codeElement )
      {
         textContentShallow(sevStr, codeElement);
      }
      else
      {
         OsSysLog::add(FAC_ALARM, PRI_WARNING,
               "id=%s: no severity; assuming %s", idStr.data(), sevStr.data());
      }

      codeElement = element->FirstChildElement("component");
      if ( codeElement )
      {
         textContentShallow(compStr, codeElement);
      }
      else
      {
         OsSysLog::add(FAC_ALARM, PRI_WARNING,"id=%s: no component; set to null", idStr.data());
      }

      codeElement = element->FirstChildElement("action");
      actLog   = getBoolAttribute(codeElement, "log", true);
      if ( codeElement )
      {
         // Get the alarm group name used for both regular emails and SMS emails.
         groupName = codeElement->Attribute("email");
         if (strcmp(groupName.data(), "disabled") == 0)
         {
            // All regular/SMS notifications for this alarm type must be disabled.
            actEmail = false;
            actSms = false;
            actTrap = false;
         }
      }
      codeElement = element->FirstChildElement("filter");
      filtMax  = getIntAttribute(codeElement, "max_reports", INT_MAX);
      filtMin  = getIntAttribute(codeElement, "min_threshold");
   }
   else
   {
      return false;
   }

   data->setAlarmId(idStr);
   data->setCode(codeStr);
   data->setSeverity(sevToSyslogPri(sevStr));
   data->setComponent(compStr);
   data->setShortTitle(idStr);  // default fallback title is internal id
   data->setDescription(idStr); // default fallback description is internal id
   data->setResolution(resStr);
   data->actions[cAlarmData::eActionLog] = actLog;
   data->actions[cAlarmData::eActionEmail] = actEmail;
   data->actions[cAlarmData::eActionSms] = actSms;
   data->actions[cAlarmData::eActionTrap] = actTrap;
   data->group_name = groupName;
   data->max_report = filtMax;
   data->min_threshold = filtMin;
   data->resetCount();

   return true;

}
예제 #4
0
void SBCollisionManager::start()
{
#ifndef SB_NO_ODE_PHYSICS
	_singleChrCapsuleMode = getBoolAttribute("singleChrCapsuleMode");
	float jointBVLenRadRatio = (float)(getDoubleAttribute("jointBVLenRadRatio"));

	SR_CLIP(jointBVLenRadRatio, 0.001f, 1000.0f);
	_jointBVLenRadRatio = jointBVLenRadRatio;

	SBScene* scene = SmartBody::SBScene::getScene();
	SBSteerManager* steerManager = scene->getSteerManager();
	_characterRadius = (float) steerManager->getDoubleAttribute("initialConditions.radius");
	double sceneScale = scene->getDoubleAttribute("scale");
	if (sceneScale != 0.0)
	{
		_characterRadius *= (float) (1.0 / sceneScale);
	}
	_positions.clear();
	_velocities.clear();
	if (!collisionSpace)
	{
		collisionSpace = new ODECollisionSpace();

	}
	const std::vector<std::string>& characterNames = scene->getCharacterNames();
	for (std::vector<std::string>::const_iterator iter = characterNames.begin();
		 iter != characterNames.end();
		 iter++)
	{
		_positions.insert(std::pair<std::string, SrVec>((*iter), SrVec()));
		_velocities.insert(std::pair<std::string, SrVec>((*iter), SrVec()));
		SBCharacter* character = scene->getCharacter(*iter);
		if (!character->getGeomObject() || character->getGeomObject()->geomType() == "null") // no collision geometry setup for the character
		{
			if(_singleChrCapsuleMode)
			{
				//SBGeomObject* obj = new SBGeomCapsule()			
				SrBox bbox = character->getBoundingBox();	
				float yoffset = bbox.getMinimum().y - character->get_world_offset().get_translation().y;
				SrVec size = SrVec(0,_characterRadius,0);
				SBGeomObject* obj = createCollisionObject(character->getGeomObjectName(),"capsule",size,SrVec(0,yoffset,0),SrVec(0,yoffset+character->getHeight(),0));
				obj->attachToObj(character);
				addObjectToCollisionSpace(character->getGeomObjectName());
				//new SBGeomCapsule(SrVec(0,yoffset,0),SrVec(0,yoffset+character->getHeight(),0),_characterRadius);
				//character->setGeomObject(obj);
				//collisionSpace->addCollisionObjects(obj);
			}
			else // create collision capsules based on skel bones
			{
				LOG(character->getName().c_str());
				SkSkeleton* sk = character->getSkeleton();
				const std::vector<SkJoint*>& origJnts = sk->joints();
				sk->update_global_matrices();
				std::vector<SkJoint*> jnt_excld_list;
				for(unsigned int i=0; i<origJnts.size(); i++)
				{
					SkJoint* j = origJnts[i];
					SrString jname(j->jointName().c_str());
					if(jname.search("world_offset")>=0) { jnt_excld_list.push_back(j); continue; } // skip world_offset
					if(jname.search("face")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("brow")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("eye")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("nose")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("lid")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("jaw")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("tongue")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("lip")>=0)    { jnt_excld_list.push_back(j); continue; }
					if(jname.search("cheek")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("finger")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("thumb")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("index")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("middle")>=0) { jnt_excld_list.push_back(j); continue; }
					if(jname.search("pinky")>=0)  { jnt_excld_list.push_back(j); continue; }
					if(jname.search("ring")>=0)   { jnt_excld_list.push_back(j); continue; }
				}
				std::string chrName = character->getGeomObjectName();
				float chrHeight = character->getHeight();
				for(unsigned int i=0; i<origJnts.size(); i++)
				{
					SkJoint* j = origJnts[i];
					if(isJointExcluded(j, jnt_excld_list)) continue;
					SrString jname(j->jointName().c_str());
					for(int k=0; k<j->num_children(); k++)
					{
						SkJoint* j_ch = j->child(k);
						if(isJointExcluded(j_ch, jnt_excld_list)) continue;
						const SrVec& offset = j_ch->offset();
						float offset_len = offset.norm();
						float radius = offset_len / jointBVLenRadRatio;
						if(offset_len < 0.03*chrHeight) continue; // skip short bones
						std::string colObjName = chrName + ":" + j->jointName();
						if(k>0) colObjName = colObjName + ":" + boost::lexical_cast<std::string>(k);
						SBGeomObject* obj = createCollisionObject(colObjName,"capsule",SrVec(0, radius, 0),SrVec::null,offset);
						LOG("SBColMan: col primitive added: %s, len: %f, radius: %f", colObjName.c_str(), offset_len, radius);
						obj->attachToObj(dynamic_cast<SBTransformObjInterface*>(j));
						addObjectToCollisionSpace(colObjName);
					}
				}
			}
		}
	}

	const std::vector<std::string>& pawnNames = scene->getPawnNames();
	for (std::vector<std::string>::const_iterator iter = pawnNames.begin();
		 iter != pawnNames.end(); iter++)
	{
		SBPawn* pawn = scene->getPawn(*iter);
		if(pawn->getGeomObject()->geomType() != "null")
		{
			//SBGeomObject* obj = pawn->getGeomObject();
			SBGeomObject* obj = createCollisionObject(pawn->getGeomObjectName(),pawn->getGeomObject()->geomType(),pawn->getGeomObject()->getGeomSize(),SrVec::null,SrVec::null);
			obj->attachToObj(pawn);

			addObjectToCollisionSpace(pawn->getGeomObjectName());
		}
	}
#endif
}