void SphereCollider::LoadState(TiXmlElement* xmlElement)
	{
		TiXmlElement* centerEle = xmlElement->FirstChildElement("Center");

		if( centerEle != 0 )
		{
			TiXmlElement* xEle = centerEle->FirstChildElement("x");
			if( xEle != 0 &&
				xEle->GetText() != 0 &&
				strlen(xEle->GetText()) != 0 )
			{
				sphere.center.x = (float)atof(xEle->GetText());
			}

			TiXmlElement* yEle = centerEle->FirstChildElement("y");
			if( yEle != 0 &&
				yEle->GetText() != 0 &&
				strlen(yEle->GetText()) != 0 )
			{
				sphere.center.y = (float)atof(yEle->GetText());
			}

			TiXmlElement* zEle = centerEle->FirstChildElement("z");
			if( zEle != 0 &&
				zEle->GetText() != 0 &&
				strlen(zEle->GetText()) != 0 )
			{
				sphere.center.z = (float)atof(zEle->GetText());
			}
		}

		TiXmlElement* radiusEle = xmlElement->FirstChildElement("Radius");
		
		if( radiusEle != 0 &&
			radiusEle->GetText() != 0 &&
			strlen(radiusEle->GetText()) != 0 )
			sphere.radius = (float)atof(radiusEle->GetText());
	}
Beispiel #2
0
void CButtonTranslator::MapJoystickActions(int windowID, TiXmlNode *pJoystick)
{
  string joyname = "_xbmc_"; // default global map name
  vector<string> joynames;
  map<int, string> buttonMap;
  map<int, string> axisMap;
  map<int, string> hatMap;

  TiXmlElement *pJoy = pJoystick->ToElement();
  if (pJoy && pJoy->Attribute("name"))
    joyname = pJoy->Attribute("name");
  else
    CLog::Log(LOGNOTICE, "No Joystick name specified, loading default map");

  joynames.push_back(joyname);

  // parse map
  TiXmlElement *pButton = pJoystick->FirstChildElement();
  int id = 0;
  //char* szId;
  const char* szType;
  const char *szAction;
  while (pButton)
  {
    szType = pButton->Value();
    szAction = pButton->GetText();
    if (szAction == NULL)
      szAction = "";
    if (szType)
    {
      if ((pButton->QueryIntAttribute("id", &id) == TIXML_SUCCESS) && id>=0 && id<=256)
      {
        if (strcmpi(szType, "button")==0)
        {
          buttonMap[id] = string(szAction);
        }
        else if (strcmpi(szType, "axis")==0)
        {
          int limit = 0;
          if (pButton->QueryIntAttribute("limit", &limit) == TIXML_SUCCESS)
          {
            if (limit==-1)
              axisMap[-id] = string(szAction);
            else if (limit==1)
              axisMap[id] = string(szAction);
            else if (limit==0)
              axisMap[id|0xFFFF0000] = string(szAction);
            else
            {
              axisMap[id] = string(szAction);
              axisMap[-id] = string(szAction);
              CLog::Log(LOGERROR, "Error in joystick map, invalid limit specified %d for axis %d", limit, id);
            }
          }
          else
          {
            axisMap[id] = string(szAction);
            axisMap[-id] = string(szAction);
          }
        }
        else if (strcmpi(szType, "hat")==0)
        {
          string position;
          if (pButton->QueryValueAttribute("position", &position) == TIXML_SUCCESS)
          {
            uint32_t hatID = id|0xFFF00000;
            if (position.compare("up") == 0)
              hatMap[(JACTIVE_HAT_UP<<16)|hatID] = string(szAction);
            else if (position.compare("down") == 0)
              hatMap[(JACTIVE_HAT_DOWN<<16)|hatID] = string(szAction);
            else if (position.compare("right") == 0)
              hatMap[(JACTIVE_HAT_RIGHT<<16)|hatID] = string(szAction);
            else if (position.compare("left") == 0)
              hatMap[(JACTIVE_HAT_LEFT<<16)|hatID] = string(szAction);
            else
              CLog::Log(LOGERROR, "Error in joystick map, invalid position specified %s for axis %d", position.c_str(), id);
          }
        }
        else
          CLog::Log(LOGERROR, "Error reading joystick map element, unknown button type: %s", szType);
      }
      else if (strcmpi(szType, "altname")==0)
        joynames.push_back(string(szAction));
      else
        CLog::Log(LOGERROR, "Error reading joystick map element, Invalid id: %d", id);
    }
    else
      CLog::Log(LOGERROR, "Error reading joystick map element, skipping");

    pButton = pButton->NextSiblingElement();
  }
  vector<string>::iterator it = joynames.begin();
  while (it!=joynames.end())
  {
    m_joystickButtonMap[*it][windowID] = buttonMap;
    m_joystickAxisMap[*it][windowID] = axisMap;
    m_joystickHatMap[*it][windowID] = hatMap;
//    CLog::Log(LOGDEBUG, "Found Joystick map for window %d using %s", windowID, it->c_str());
    it++;
  }
}
Beispiel #3
0
void MainWindow::openFile()
{
    if( !scene->items().isEmpty() )
    {
        QMessageBox::warning(this, tr("Warning"), tr("All unsaved data will be lost!"));
    }

    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", tr("XML Files (*.xml)"));
    if(fileName != "")
    {
        scene->clearAllItems();
        projectName.clear();
        commands.clear();

        TiXmlDocument doc;
        if(!doc.LoadFile(fileName.toStdString()))
        {
            QMessageBox::critical(this, tr("Error"), tr("Could not open file"));
        }
        TiXmlElement * pProjectElement = doc.FirstChildElement("project");
        TiXmlElement * pNodeElement;
        if( pProjectElement == NULL )
        {
            QMessageBox::critical(this, tr("Error"), tr("Could not parse file: <project> not found"));
            return;
        }
        pNodeElement = pProjectElement->FirstChildElement("name");
        if( pNodeElement != NULL )
        {
            projectName = QString(pNodeElement->GetText());
			ui->projectEdit->setText(projectName);
        }
        std::map<QString, HEESGraphicsItem*> nameIndex;
        // First pass: add components
        for( pNodeElement = pProjectElement->FirstChildElement("comp"); pNodeElement != NULL; pNodeElement = pNodeElement->NextSiblingElement("comp"))
        {
            HEESGraphicsItem * item;
            QString type(pNodeElement->Attribute("type"));
            if( type == QString("cti") )
            {
                item = new HEESGraphicsItem(CTI);
            }
            else if( type == QString("bank"))
            {
                item = new HEESGraphicsItem(BANK);
            }
            else if( type == QString("load") )
            {
                item = new HEESGraphicsItem(LOAD);
            }
            else if( type == QString("source") )
            {
                item = new HEESGraphicsItem(SOURCE);
            }
            else if( type == QString("converter") )
            {
                // will be added in the second pass
                continue;
            }
            else if( type == QString("manager") )
            {
                item = new HEESGraphicsItem(MANAGER);
            }
            else
            {
                continue;
            }
            QString xpos(pNodeElement->Attribute("x_pos"));
            QString ypos(pNodeElement->Attribute("y_pos"));
            if( !xpos.isEmpty() && !ypos.isEmpty() )
            {
                item->setPos( xpos.toDouble(), ypos.toDouble() );
            }
            TiXmlElement * pNameElement = pNodeElement->FirstChildElement("name");
            if( pNameElement != NULL )
            {
                item->name = QString(pNameElement->GetText());
            }
            TiXmlElement * pDerivedElement = pNodeElement->FirstChildElement("derived");
            if( pDerivedElement == NULL )
            {
                QMessageBox::critical(this, tr("Error"), tr("Could not parse file: <derived> not found for component:")+item->name);
                scene->clearAllItems();
                projectName.clear();
                commands.clear();
                return;
            }
            if( type != QString("cti") )
            {
                item->derivedType = QString(pDerivedElement->Attribute("type"));
            }
            TiXmlElement * pElement;
            for( pElement = pDerivedElement->FirstChildElement(); pElement != NULL; pElement = pElement->NextSiblingElement() )
            {
                item->myAttributes()->insertBack( pElement->Value(), pElement->GetText() );
            }
            nameIndex[item->name] = item;
            scene->addItem(item);
        }
        // Second pass: add converters
        for( pNodeElement = pProjectElement->FirstChildElement("comp"); pNodeElement != NULL; pNodeElement = pNodeElement->NextSiblingElement("comp"))
        {
            HEESGraphicsItem * item;
            QString type(pNodeElement->Attribute("type"));
            if( type == QString("converter") )
            {
                // will be added in the second pass
                item = new HEESGraphicsItem(CONVERTER);
            }
            else
            {
                continue;
            }
            QString xpos(pNodeElement->Attribute("x_pos"));
            QString ypos(pNodeElement->Attribute("y_pos"));
            if( !xpos.isEmpty() && !ypos.isEmpty() )
            {
                item->setPos( xpos.toDouble(), ypos.toDouble() );
            }
            TiXmlElement * pNameElement = pNodeElement->FirstChildElement("name");
            if( pNameElement != NULL )
            {
                item->name = QString(pNameElement->GetText());
            }
            TiXmlElement * pDerivedElement = pNodeElement->FirstChildElement("derived");
            if( pDerivedElement == NULL )
            {
                QMessageBox::critical(this, tr("Error"), tr("Could not parse file: <derived> not found for component:")+item->name);
                scene->clearAllItems();
                projectName.clear();
                commands.clear();
                return;
            }
            item->derivedType = QString(pDerivedElement->Attribute("type"));
            TiXmlElement * pElement;
            for( pElement = pDerivedElement->FirstChildElement(); pElement != NULL; pElement = pElement->NextSiblingElement() )
            {
                item->myAttributes()->insertBack( pElement->Value(), pElement->GetText() );
            }
            TiXmlElement * pElementA = pNodeElement->FirstChildElement("port_a");
            TiXmlElement * pElementB = pNodeElement->FirstChildElement("port_b");
            std::map<QString, HEESGraphicsItem*>::iterator it;
            if( pElementA != NULL && (it = nameIndex.find(QString(pElementA->GetText()))) != nameIndex.end() )
            {
                if( it->second->myType() != CONVERTER && it->second->myType() != MANAGER )
                    item->setLeftItem(it->second);
            }
            if( pElementB != NULL && (it = nameIndex.find(QString(pElementB->GetText()))) != nameIndex.end() )
            {
                if( it->second->myType() != CONVERTER && it->second->myType() != MANAGER )
                    item->setRightItem(it->second);
            }
            nameIndex[item->name] = item;
            scene->addItem(item);
        }
        // Thrid pass: add sensors
        for( pNodeElement = pProjectElement->FirstChildElement("sensor"); pNodeElement != NULL; pNodeElement = pNodeElement->NextSiblingElement("sensor") )
        {
            QString target(pNodeElement->Attribute("target"));
            QString prop(pNodeElement->Attribute("property"));
            if( nameIndex.find(target) != nameIndex.end() )
            {
                nameIndex[target]->mySensors()->insertBack(prop);
            }
        }
        // Fourth pass: add commands
        for( pNodeElement = pProjectElement->FirstChildElement("cmd"); pNodeElement != NULL; pNodeElement = pNodeElement->NextSiblingElement("cmd") )
        {
            QString type(pNodeElement->Attribute("type"));
            double time;
            pNodeElement->Attribute("time", &time);
            if( type == QString("set") || type == QString("get") )
            {
                QString targetName(pNodeElement->Attribute("target"));
                for(TiXmlElement * pElement = pNodeElement->FirstChildElement(); pElement != NULL; pElement = pElement->NextSiblingElement() )
                {
                    Command command;
                    command.type = type;
                    command.time = time;
                    command.targetName = targetName;
                    command.propertyName = QString(pElement->Value());
                    command.propertyValue = QString(pElement->GetText());
                    commands.insertBack(command);
                }
            }
            else if( type == QString("finish") || type == QString("sim") )
            {
                Command command;
                command.type = type;
                command.time = time;
                commands.insertBack(command);
            }
        }
    }
}