Пример #1
0
bool XMLSceneVisitor::VisitEnter(const TiXmlElement& element, const TiXmlAttribute* attribute)
{
    if(element.ValueStr() == "scene")
    {
        return (element.Parent() == element.GetDocument());
    }
    else if (element.ValueStr() == "materials")
    {
        return true;
    }
    else if (element.ValueStr() == "primitives")
    {
        return (element.Parent()->ValueStr() == "scene");
    }
    else if (element.ValueStr() == "plane")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double nx(0.0f), ny(1.0f), nz(0.0f), value(0.0f);

        element.Attribute("nx", &nx);
        element.Attribute("ny", &ny);
        element.Attribute("nz", &nz);
        element.Attribute("value", &value);

        glm::vec3 normal(nx, ny, nz);
        normal = glm::normalize(normal);

        m_current = new Scene::Plane(normal, value);
        return true;
    }
    else if (element.ValueStr() == "sphere")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double cx(0.0f), cy(1.0f), cz(0.0f), radius(0.0f);

        element.Attribute("cx", &cx);
        element.Attribute("cy", &cy);
        element.Attribute("cz", &cz);
        element.Attribute("radius", &radius);

        glm::vec3 center(cx, cy, cz);
        m_current = new Scene::Sphere(center, radius);
        return true;
    }
    else
        return false;
}
Пример #2
0
bool xmlFile::CWElementToParent()
{
    if(!m_pWorkingElement)
        return false;

    if( m_pWorkingElement->Parent() )
    {
        m_pWorkingElement = (TiXmlElement*)m_pWorkingElement->Parent();
        return true;
    }

    return false;
}
Пример #3
0
bool XMLSceneVisitor::VisitExit( const TiXmlElement& element)
{
    if(element.ValueStr() == "scene")
    {
        return (element.Parent() == element.GetDocument());
    }
    else if (element.ValueStr() == "materials")
    {
        return true;
    }
    else if (element.ValueStr() == "primitives")
    {
        return true;
    }
    else if (element.ValueStr() == "plane")
    {
        m_scene->insert_primitive(m_current);
        m_current = NULL;
        return true;
    }
    else if (element.ValueStr() == "sphere")
    {
        m_scene->insert_primitive(m_current);
        m_current = NULL;
        return true;
    }
    else
        return false;
}
Пример #4
0
/*!
*  /brief 删除指定节点的值。
*
*  /param XmlFile xml文件全路径。
*  /param strNodeName 指定的节点名。
*  /return 是否成功。true为成功,false表示失败。
*/
bool xml_DelNode(TiXmlDocument *pDoc, std::string strNodeName)
{
    TiXmlElement *pRootEle = pDoc->RootElement();

    if (NULL == pRootEle) {
        return false;
    }
    TiXmlElement *pNode = NULL;
    xml_GetNodePointerByName(pRootEle, strNodeName, pNode);
    // 假如是根节点
    if (pRootEle == pNode) {
        if (pDoc->RemoveChild(pRootEle)) {
            return true;
        } else
            return false;
    }
    // 假如是其它节点
    if (NULL != pNode) {
        TiXmlNode *pParNode = pNode->Parent();
        if (NULL == pParNode) {
            return false;
        }

        TiXmlElement* pParentEle = pParNode->ToElement();
        if (NULL != pParentEle) {
            if (pParentEle->RemoveChild(pNode))
                return true;
            else
                return false;
        }
    } else {
        return false;
    }
    return false;
}
Пример #5
0
void joinNetworkGameDialogImpl::deleteServerProfile()
{

	TiXmlDocument doc(QString::fromUtf8(myServerProfilesFile.c_str()).toStdString());
	if(!doc.LoadFile()) {
		MyMessageBox::warning(this, tr("Load Server-Profile-File Error"),
							  tr("Could not load server-profiles-file:\n"+QString::fromUtf8(myServerProfilesFile.c_str()).toAscii()),
							  QMessageBox::Close);
	} else {
		TiXmlHandle docHandle( &doc );

		TiXmlElement* profile = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).FirstChild( treeWidget->currentItem()->data(0,0).toString().toUtf8().constData() ).ToElement();

		if ( profile ) {
			profile->Parent()->RemoveChild(profile);
		}

		if(!doc.SaveFile()) {
			MyMessageBox::warning(this, tr("Save Server-Profile-File Error"),
								  tr("Could not save server-profiles-file:\n"+QString::fromUtf8(myServerProfilesFile.c_str()).toAscii()),
								  QMessageBox::Close);
		}

		//Liste Füllen
		fillServerProfileList();
	}

	pushButton_delete->setDisabled(TRUE);
}
/***********************************************************************************************************
 * 程序作者:赵进军
 * 函数功能:删除XML文件中指定的节点的最后一个节点
 * 参数说明:
 * delNodeName:需要删除的节点的名称
 *   nodeIndex:需要删除的节点的位置
 * 注意事项:null
 * 修改日期:2015/12/12 16:49:00
 ***********************************************************************************************************/
bool OperationProfile_XML::DeleteNodeByNameIndex(char* delNodeName, int nodeIndex)
{
	if (nodeIndex >= groupNodeCount)
		printf("当前删除的节点位置不存在!");

	if (!OperationProfile_XML::XMLExits())
		return false;

	TiXmlDocument* myDocument = new TiXmlDocument();

	if (NULL == myDocument)
		return false;
	myDocument->LoadFile(IOperationProfile::ProfileAddress);

	TiXmlElement* pRootEle = myDocument->RootElement();
	if (NULL == pRootEle)
		return false;

	TiXmlElement *pNode = NULL;

	if (arrayIndex != 0)
		arrayIndex = 0;
	if (!GetNodePointerByName(pRootEle, delNodeName, pNode, nodeIndex))
		return false;

	if (pRootEle == pNode)
	{
		if (myDocument->RemoveChild(pRootEle))
		{
			myDocument->SaveFile(IOperationProfile::ProfileAddress);
			return true;
		}
		else
		{
			return false;
		}
	}

	if (NULL != pNode)
	{
		TiXmlNode* pParNode = pNode->Parent();
		if (NULL == pParNode)
			return false;

		TiXmlElement* pParentEle = pParNode->ToElement();
		if (NULL != pParentEle)
		{
			if (pParentEle->RemoveChild(pNode))
				myDocument->SaveFile(IOperationProfile::ProfileAddress);
			else
				return false;
		}
	}
	else
	{
		return false;
	}
	return false;
}
Пример #7
0
void XMLLanguages::RemoveItem(int id)
{
    TiXmlElement* item = GetItem(id);
    TiXmlNode* parent;
    if(item && (parent = item->Parent()))
    {
        parent->RemoveChild(item);
    }
}
Пример #8
0
static void DoLayers()
{
/* ---- */
/* Open */
/* ---- */

	XML_TKEM		xml( gArgs.GetXML(), flog );
	TiXmlElement*	layer	= xml.GetFirstLayer();

/* ------------------------- */
/* Kill layers outside range */
/* ------------------------- */

	TiXmlNode*		lyrset = layer->Parent();
	TiXmlElement*	next;

	for( ; layer; layer = next ) {

		// next layer0 before deleting anything
		next = layer->NextSiblingElement();

		int	z = atoi( layer->Attribute( "z" ) );

		if( z < gArgs.zmin || z > gArgs.zmax )
			lyrset->RemoveChild( layer );
	}

/* --------------------------- */
/* Copies for remaining layers */
/* --------------------------- */

	layer = lyrset->FirstChild( "t2_layer" )->ToElement();

	for( ; layer; layer = layer->NextSiblingElement() ) {

		int	z = atoi( layer->Attribute( "z" ) );

		gArgs.NewLayer( z );
		UpdateTiles( layer );
	}

/* ---- */
/* Save */
/* ---- */

	xml.Save( "xmltmp.txt", true );

/* ------------------ */
/* Rename version two */
/* ------------------ */

	gArgs.RenameXML();
}
Пример #9
0
TiXmlElement* ConfigManager::AssertPath(wxString& path)
{
    Collapse(path);

    wxString illegal(_T(" -:.\"\'$&()[]<>+#"));
    size_t i = 0;
    while ((i = path.find_first_of(illegal, i)) != wxString::npos)
        path[i] = _T('_');

    TiXmlElement *localPath = pathNode ? pathNode : root;

    if (path.GetChar(0) == '/')  // absolute path
    {
        localPath = root;
        path = path.Mid(1);
    }

    if (path.find(_T('/')) != wxString::npos) // need for path walking
        to_lower(path);

    wxString sub;

    while (path.find(_T('/')) != wxString::npos)
    {
        sub = path.BeforeFirst(_T('/'));
        path = path.AfterFirst(_T('/'));

        if (localPath != root && sub.IsSameAs(CfgMgrConsts::dotDot))
            localPath = localPath->Parent()->ToElement();
        else if (sub.GetChar(0) < _T('a') || sub.GetChar(0) > _T('z'))
        {
            cbThrow(InvalidNameMessage(_T("subpath"), sub, localPath));
        }
        else
        {
            TiXmlElement* n = localPath->FirstChildElement(cbU2C(sub));
            if (n)
                localPath = n;
            else
                localPath = (TiXmlElement*) localPath->InsertEndChild(TiXmlElement(cbU2C(sub)));
        }
    }

    to_upper(path);

    if (!path.IsEmpty() && (path.GetChar(0) < _T('A') || path.GetChar(0) > _T('Z')))
        cbThrow(InvalidNameMessage(_T("key"), path, localPath));

    return localPath;
}
Пример #10
0
wxString ConfigManager::GetPath() const
{
    TiXmlElement *e = pathNode;
    wxString ret;
    ret.Alloc(64);

    ret = cbC2U(e->Value());
    while ((e = e->Parent()->ToElement()) && e != root)
    {
        ret.Prepend(_T('/'));
        ret.Prepend(cbC2U(e->Value()));
    }
    ret.Prepend(_T('/'));
    return ret;
}
Пример #11
0
int CFieldDataXML::DeleteField(CString strFieldID)
{
	if (!m_bInit)
	{
		if (!myDocument.LoadFile(m_strXML.GetBuffer()))
		{
			return ERROR_OPEN_FILE;
		}
		m_bInit = TRUE;
	}

	//获得根元素
	TiXmlElement *RootElement = myDocument.RootElement();
	//获得第一个field节点。
	TiXmlElement *field = RootElement->FirstChildElement();

	int i=0;
	while(field)
	{
		CString strIDFind = field->Attribute("id");
		if (strIDFind == strFieldID)
		{
			//找到了
			break;
		}

		field = field->NextSiblingElement("field");
	} 
	if (field)
	{
		//找到了
		TiXmlNode *pParNode =  field->Parent();
		if (NULL == pParNode)
		{
			return ERROR_UNKNOW_ERROR;
		}

		TiXmlElement* pParentEle = pParNode->ToElement();
		if (NULL != pParentEle)
		{
			if(pParentEle->RemoveChild(field))
			{
				myDocument.SaveFile();
			}
		}
	}
	return ERROR_OK;
}
Пример #12
0
int keyset_load_key(TiXmlHandle node, unsigned char* key, unsigned int size, int* valid)
{
	TiXmlElement* elem = node.ToElement();

	if (valid)
		*valid = 0;

	if (!elem)
		return 0;

	const char* text = elem->GetText();
	unsigned int textlen = strlen(text);

	int status = keyset_parse_key(text, textlen, key, size, valid);

	if (status == KEY_ERR_LEN_MISMATCH)
	{
		fprintf(stderr, "Error size mismatch for key \"%s/%s\"\n", elem->Parent()->Value(), elem->Value());
		return 0;
	}
	
	return 1;
}
Пример #13
0
/*
 *  Attempts to read parameters from a XML file.
 *
 *  @param  element TiXmlElement to examine.
 *  @return true if successful, false otherwise.
 */
bool FixedLayout::readParameters(const TiXmlElement& element)
{
	cerr << "Attempting to parse a layout param" << endl;
    if (Layout::readParameters(element)) {
        // this parameter was already handled
        return true;
    }

    if (element.ValueStr().compare("LayoutFiles") == 0) {
	nParams++;
        return true;
    }
	
	/*
	*  Following statements exist because although the logic for reading the parameters
    *  contained in these elements is later in this function, the traversal of nodes
    *  causes this function to be called to handle the each of the elements individually. 
	*/
/*needed?
	if (element.ValueStr().compare("A") == 0){
		if(element.Parent()->ValueStr().compare("FixedLayoutParams") == 0){
			return true;
		}
	}
	if (element.ValueStr().compare("I") == 0){
		if(element.Parent()->ValueStr().compare("FixedLayoutParams") == 0){
			return true;
		}
	}
*/
/*
    // Parse fixed layout (overrides random layouts)
    if (element.ValueStr().compare("FixedLayoutParams") == 0) {
        const TiXmlNode* pNode = NULL;
        while ((pNode = element.IterateChildren(pNode)) != NULL) {
            string activeNListFileName;
            string inhNListFileName;
            string probedNListFileName;

            if (strcmp(pNode->Value(), "A") == 0) {
                getValueList(pNode->ToElement()->GetText(), &m_endogenously_active_neuron_list);
                num_endogenously_active_neurons = m_endogenously_active_neuron_list.size();
            } else if (strcmp(pNode->Value(), "I") == 0) {
                getValueList(pNode->ToElement()->GetText(), &m_inhibitory_neuron_layout);
            }
            else if (strcmp(pNode->Value(), "LayoutFiles") == 0)
            {
                if (pNode->ToElement()->QueryValueAttribute( "inhNListFileName", &inhNListFileName ) == TIXML_SUCCESS)
                {
                    TiXmlDocument simDoc( inhNListFileName.c_str( ) );
                    if (!simDoc.LoadFile( ))
                    {
                        cerr << "Failed loading positions of inhibitory neurons list file " << inhNListFileName << ":" << "\n\t"
                            << simDoc.ErrorDesc( ) << endl;
                        cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                        return false;
                    }
                    TiXmlNode* temp2 = NULL;
                    if (( temp2 = simDoc.FirstChildElement( "I" ) ) == NULL)
                    {
                        cerr << "Could not find <I> in positons of inhibitory neurons list file " << inhNListFileName << endl;
                        return false;
                    }
                    getValueList(temp2->ToElement()->GetText(), &m_inhibitory_neuron_layout);
                }
                if (pNode->ToElement()->QueryValueAttribute( "activeNListFileName", &activeNListFileName ) == TIXML_SUCCESS)
                {
                    TiXmlDocument simDoc( activeNListFileName.c_str( ) );
                    if (!simDoc.LoadFile( ))
                    {
                        cerr << "Failed loading positions of endogenously active neurons list file " << activeNListFileName << ":" << "\n\t"
                            << simDoc.ErrorDesc( ) << endl;
                        cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                        return false;
                    }
                    TiXmlNode* temp2 = NULL;
                    if (( temp2 = simDoc.FirstChildElement( "A" ) ) == NULL)
                    {
                        cerr << "Could not find <A> in positons of endogenously active neurons list file " << activeNListFileName << endl;
                        return false;
                    }
                    getValueList(temp2->ToElement()->GetText(), &m_endogenously_active_neuron_list);
                    num_endogenously_active_neurons = m_endogenously_active_neuron_list.size();
                }

                if (pNode->ToElement()->QueryValueAttribute( "probedNListFileName", &probedNListFileName ) == TIXML_SUCCESS) {
                    TiXmlDocument simDoc( probedNListFileName.c_str( ) );
                    if (!simDoc.LoadFile( ))
                    {
                        cerr << "Failed loading positions of probed neurons list file " << probedNListFileName << ":" << "\n\t"
                            << simDoc.ErrorDesc( ) << endl;
                        cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                        return false;
                    }
                    TiXmlNode* temp2 = NULL;
                    if (( temp2 = simDoc.FirstChildElement( "P" ) ) == NULL)
                    {
                        cerr << "Could not find <P> in positions of probed neurons list file " << probedNListFileName << endl;
                        return false;
                    }
                    getValueList(temp2->ToElement()->GetText(), &m_probed_neuron_list);
               }
            }
        }
        nParams++;
*/
    // Parse fixed layout (changed to utilize the Visiter Pattern provided by Tinyxml
    if (element.Parent()->ValueStr().compare("LayoutFiles") == 0) {
	if(element.ValueStr().compare("activeNListFileName") == 0){
	    const char* activeNListFileName = element.GetText();
	    if(activeNListFileName == NULL){
		return true;
	    }
            TiXmlDocument simDoc(activeNListFileName);
            if (!simDoc.LoadFile( ))
            {
                cerr << "Failed loading positions of endogenously active neurons list file " << activeNListFileName << ":" << "\n\t"
                    << simDoc.ErrorDesc( ) << endl;
                cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                return false;
            }
            TiXmlNode* temp2 = NULL;
            if (( temp2 = simDoc.FirstChildElement( "A" ) ) == NULL)
            {
                cerr << "Could not find <A> in positons of endogenously active neurons list file " << activeNListFileName << endl;
                return false;
            }
            getValueList(temp2->ToElement()->GetText(), &m_endogenously_active_neuron_list);
            num_endogenously_active_neurons = m_endogenously_active_neuron_list.size();

	    return true;
	}
	if(element.ValueStr().compare("inhNListFileName") == 0){
	    const char* inhNListFileName = element.GetText();
	    if(inhNListFileName == NULL){
		return true;
	    }
            TiXmlDocument simDoc(inhNListFileName);
            if (!simDoc.LoadFile( ))
            {
                cerr << "Failed loading positions of inhibitory neurons list file " << inhNListFileName << ":" << "\n\t"
                    << simDoc.ErrorDesc( ) << endl;
                cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                return false;
            }
            TiXmlNode* temp2 = NULL;
            if (( temp2 = simDoc.FirstChildElement( "I" ) ) == NULL)
            {
                cerr << "Could not find <I> in positions of inhibitory neurons list file " << inhNListFileName << endl;
                return false;
            }
            getValueList(temp2->ToElement()->GetText(), &m_inhibitory_neuron_layout);
	    return true;
	}
	if(element.ValueStr().compare("probedNListFileName") == 0){
	    const char* probedNListFileName = element.GetText();
	    if(probedNListFileName == NULL){
		return true;
	    }
            TiXmlDocument simDoc(probedNListFileName);
            if (!simDoc.LoadFile( ))
            {
                cerr << "Failed loading positions of probed neurons list file " << probedNListFileName << ":" << "\n\t"
                    << simDoc.ErrorDesc( ) << endl;
                cerr << " error: " << simDoc.ErrorRow( ) << ", " << simDoc.ErrorCol( ) << endl;
                return false;
            }
            TiXmlNode* temp2 = NULL;
            if (( temp2 = simDoc.FirstChildElement( "P" ) ) == NULL)
            {
                cerr << "Could not find <P> in positions of probed neurons list file " << probedNListFileName << endl;
                return false;
            }
            getValueList(temp2->ToElement()->GetText(), &m_probed_neuron_list);
	    return true;
	}
    }

    return false;
}
Пример #14
0
void MainFrame::OnBtnExportClick(wxCommandEvent& event)
{
  TiXmlDocument* doc = new TiXmlDocument();

  if (doc)
  {
    if (mCfgSrcValid)
    {
      wxMessageBox(wxT("You are about to export the selected node(s) to a backup C::B configuration file.\n"
                       "Please note that this is *not* complete because it includes the selected node(s) only.\n"
                       "It's purpose is to backup misc. nodes for transferring them using cb_share_config."),
                   wxT("Information"), wxICON_INFORMATION);

      TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "yes");
      TiXmlElement*     root = new TiXmlElement("CodeBlocksConfig");
      // NOTE (Morten#1#): This has to be in sync with C::B SDK (confimanager)!
      root->SetAttribute("version", 1);

      doc->LinkEndChild(decl);
      doc->LinkEndChild(root);

      // Save all (checked) variables of lstEnvVars
      int items_selected = 0;
      for (int i=0; i<clbCfgSrc->GetCount(); ++i)
      {
        if (clbCfgSrc->IsChecked(i) && (mNodesSrc.size()>i))
        {
          items_selected++;

          TiXmlNode*    node     = mNodesSrc.at(i);
          wxString      path     = clbCfgSrc->GetString(i);
          wxArrayString path_arr = PathToArray(path);

          TiXmlElement* element  = root;
          for (size_t i=0; i<path_arr.Count(); ++i)
          {
            wxString section_path = path_arr.Item(i);
            if (element->NoChildren())
            {
              // element has no children -> create new child named after section
              element = (TiXmlElement*) element->InsertEndChild(
                TiXmlElement(
#if wxUSE_UNICODE
                  section_path.mb_str(wxConvUTF8)
#else
                  (wxChar*)section_path.mb_str()
#endif
                ));
            }// if
            else
            {
              // element has children -> find child named after section
              TiXmlElement* new_element = element->FirstChildElement(
#if wxUSE_UNICODE
                section_path.mb_str(wxConvUTF8)
#else
                (wxChar*)section_path.mb_str()
#endif
              );

              if (!new_element)
              {
                // child could not be found -> create child named after section
                element = (TiXmlElement*) element->InsertEndChild(TiXmlElement(
#if wxUSE_UNICODE
                  section_path.mb_str(wxConvUTF8)
#else
                  (wxChar*)section_path.mb_str()
#endif
                  ));
              }
              else
              {
                // child has been found -> switch to this child
                element = new_element;
              }
            }

            if (!element)
              return;
            // ...continue with next section.
          }

          TiXmlNode* parent_node = element->Parent();
          parent_node->ReplaceChild(element, *node);
        }
      }

      if (items_selected)
      {
        wxString filename = wxFileSelector
        (
          wxT("Choose a Code::Blocks backup configuration file"), // title
          wxT(""),                                                // default path
          wxT("backup.conf"),                                     // default file
          wxT("*.conf"),                                          // default extension
          wxT("Code::Blocks configuration files (*.conf)|*.conf|"
              "All files (*.*)|*.*"),                             // wildcards
          wxFD_SAVE                                               // flags
        );
        if (!filename.IsEmpty())
        {
          if (TiXmlSaveDocument(filename, doc))
          {
            wxMessageBox(wxT("Backup configuration file has been saved."),
                         wxT("Information"), wxICON_INFORMATION | wxOK);
          }
          else
          {
            wxMessageBox(wxT("Could not save backup configuration file."),
                         wxT("Warning"), wxICON_EXCLAMATION | wxOK);
          }
        }
      }
      else
      {
        wxMessageBox(wxT("There were no items selected to backup."),
                     wxT("Warning"), wxICON_EXCLAMATION | wxOK);
      }
    }

    delete doc;
  }
  else
  {
    wxMessageBox(wxT("Cannot create empty XML document...?!"),
                 wxT("Error"), wxICON_EXCLAMATION | wxOK);
  }
}// OnBtnExportClick
Пример #15
0
bool XMLSceneVisitor::VisitEnter(const TiXmlElement& element, const TiXmlAttribute* attribute)
{
    if(element.ValueStr() == "scene")
    {
        return (element.Parent() == element.GetDocument());
    }
    else if (element.ValueStr() == "materials")
    {
        return true;
    }
    else if (element.ValueStr() == "primitives")
    {
        return (element.Parent()->ValueStr() == "scene");
    }
    else if (element.ValueStr() == "plane")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double nx(0.0), ny(1.0), nz(0.0), value(0.0);

        element.Attribute("nx", &nx);
        element.Attribute("ny", &ny);
        element.Attribute("nz", &nz);
        element.Attribute("value", &value);

        glm::vec3 normal(nx, ny, nz);
        normal = glm::normalize(normal);

        m_current = new Plane(normal, value);
		m_current->m_ini_pos=m_current->m_pos;
        return true;
    }
    else if (element.ValueStr() == "sphere")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double cx(0.0), cy(1.0), cz(0.0), radius(0.0);
		double vx,vy,vz;

        element.Attribute("cx", &cx);
        element.Attribute("cy", &cy);
        element.Attribute("cz", &cz);
		element.Attribute("vx", &vx);
		element.Attribute("vy", &vy);
		element.Attribute("vz", &vz);
        element.Attribute("radius", &radius);

        glm::vec3 center(cx, cy, cz);
        m_current = new Sphere(center, glm::vec3(vx,vy,vz),radius);
		m_current->m_ini_pos=m_current->m_pos;
        return true;
    }
    else if (element.ValueStr() == "cube")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double cx(0.0), cy(1.0), cz(0.0), hx(0.0), hy(0.0), hz(0.0);

        element.Attribute("cx", &cx);
        element.Attribute("cy", &cy);
        element.Attribute("cz", &cz);
        element.Attribute("hx", &hx);
        element.Attribute("hy", &hy);
        element.Attribute("hz", &hz);

        glm::vec3 center(cx, cy, cz);
        glm::vec3 hf_dims(hx, hy, hz);
        m_current = new Cube(center, hf_dims);
		m_current->m_ini_pos=m_current->m_pos;
        return true;
    }
    else if (element.ValueStr() == "obj")
    {
        if(element.Parent()->ValueStr() != "primitives")
            return false;
        assert(m_current == NULL);

        double cx(0.0), cy(1.0), cz(0.0), scale(0.0);

        element.Attribute("cx", &cx);
        element.Attribute("cy", &cy);
        element.Attribute("cz", &cz);
        element.Attribute("scale", &scale);

        glm::vec3 center(cx, cy, cz);
        m_current = new ObjMesh(DEFAULT_OBJ_MODEL, center, scale);
		m_current->m_ini_pos=m_current->m_pos;
        return true;
    }
    else
        return false;
}
Пример #16
0
void ConfigManager::DeleteSubPath(const wxString& thePath)
{
    if (doc->ErrorId())
    {
        cbMessageBox(wxString(_T("### TinyXML error:\n")) << cbC2U(doc->ErrorDesc()));
        doc->ClearError();
    }

    wxString path(thePath);
    to_lower(path);

    Collapse(path);

    wxString illegal(_T(" :.,;!\"\'$%&()[]<>{}?*+-|#"));
    size_t i;
    while ((i = path.find_first_of(illegal)) != wxString::npos)
        path[i] = _T('_');

    if (path.Last() == _T('/'))
        path.RemoveLast();

    if (path.IsSameAs(_T("/"))) // this function will refuse to remove root!
        return;

    TiXmlElement* parent = pathNode ? pathNode : root;

    if (path.find(_T('/')) != wxString::npos)
    {
        wxString sub;
        do
        {
            sub = path.BeforeFirst(_T('/'));
            path = path.AfterFirst(_T('/'));

            if (sub.IsEmpty())
                parent = root;
            else if (sub.IsSameAs(_T(".")))
                ;
            else if (parent != root && sub.IsSameAs(_T("..")))
                parent = parent->Parent()->ToElement();
            else
            {
                TiXmlElement* n = parent->FirstChildElement(cbU2C(sub));
                if (n)
                    parent = n;
                else
                    return;
            }
        }
        while (path.find(_T('/')) != wxString::npos);
    }

    if (!path.IsEmpty())
    {
        if (TiXmlNode *toRemove = parent->FirstChild(cbU2C(path)))
        {
            toRemove->Clear();
            parent->RemoveChild(toRemove);
        }
    }
}
Пример #17
0
void joinNetworkGameDialogImpl::saveServerProfile()
{

// 	bool toIntTrue;

	TiXmlDocument doc(QString::fromUtf8(myServerProfilesFile.c_str()).toStdString());
	if(!doc.LoadFile()) {
		MyMessageBox::warning(this, tr("Load Server-Profile-File Error"),
							  tr("Could not load server-profiles-file:\n"+QString::fromUtf8(myServerProfilesFile.c_str()).toAscii()),
							  QMessageBox::Close);
	}
	TiXmlHandle docHandle( &doc );

	TiXmlElement* profiles = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).ToElement();
	if ( profiles ) {

		TiXmlElement * testProfile = docHandle.FirstChild( "PokerTH" ).FirstChild( "ServerProfiles" ).FirstChild( lineEdit_profileName->text().toStdString() ).ToElement();

		if( testProfile ) {
			// Wenn der Name schon existiert --> Überschreiben?
			MyMessageBox msgBox(QMessageBox::Warning, tr("Save Server Profile Error"),
								QString(tr("A profile with the name: %1 already exists.\nWould you like to overwrite ?")).arg(lineEdit_profileName->text()), QMessageBox::Yes | QMessageBox::No, this);
			switch (msgBox.exec()) {

			case QMessageBox::Yes: {
				// yes was clicked
				// remove the old
				testProfile->Parent()->RemoveChild(testProfile);
				// write the new
				TiXmlElement * profile1 = new TiXmlElement( lineEdit_profileName->text().toUtf8().constData() );
				profiles->LinkEndChild( profile1 );
				profile1->SetAttribute("Name", lineEdit_profileName->text().toUtf8().constData());
				profile1->SetAttribute("Address", lineEdit_ipAddress->text().toUtf8().constData());
				profile1->SetAttribute("Port", spinBox_port->value());
				profile1->SetAttribute("IsIpv6", checkBox_ipv6->isChecked());
				profile1->SetAttribute("IsSctp", checkBox_sctp->isChecked());
			}
			break;
			case QMessageBox::No:
				// no was clicked
				break;
			default:
				// should never be reached
				break;
			}

		} else {
			// Wenn der Name nicht existiert --> speichern
			TiXmlElement * profile2 = new TiXmlElement( lineEdit_profileName->text().toStdString() );
			profiles->LinkEndChild( profile2 );
			profile2->SetAttribute("Name", lineEdit_profileName->text().toUtf8().constData());
			profile2->SetAttribute("Address", lineEdit_ipAddress->text().toUtf8().constData());
			profile2->SetAttribute("Port", spinBox_port->value());
			profile2->SetAttribute("IsIpv6", checkBox_ipv6->isChecked());
			profile2->SetAttribute("IsSctp", checkBox_sctp->isChecked());

		}
	} else {
		MyMessageBox::warning(this, tr("Read Server-Profile List Error"),
							  tr("Could not read server-profiles list"),
							  QMessageBox::Close);
	}

	if(!doc.SaveFile()) {
		MyMessageBox::warning(this, tr("Save Server-Profile-File Error"),
							  tr("Could not save server-profiles-file:\n"+QString::fromUtf8(myServerProfilesFile.c_str()).toAscii()),
							  QMessageBox::Close);
	}

	fillServerProfileList();
}
Пример #18
0
	/// Visit an element.
	virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* attribute)
	{
		if(element.ValueStr() == "world")
		{
			if(element.Parent() != element.GetDocument()) return false;
			return true;
		}
		else if(element.ValueStr() == "materials")
		{
			if(element.Parent()->ValueStr() != "world") return false;
			return true;
		}
		else if(element.ValueStr() == "material")
		{
			if(element.Parent()->ValueStr() != "materials") return false;

			char const* name;
			double density = 1;
			double friction = 0;
			double restitution = 0;
			double cr = 0;
			double cg = 0;
			double cb = 0;

			name = element.Attribute("name");
			if(!name)
			{
				return false;
			}

			element.Attribute("density", &density);
			element.Attribute("friction", &friction);
			element.Attribute("restitution", &restitution);
			element.Attribute("cr", &cr);
			element.Attribute("cg", &cg);
			element.Attribute("cb", &cb);

			


			// populate sound parameters
			double thickness;
			double youngsModulus;
			double fluidDamping;
			double viscoelasticDamping;
			
			element.Attribute("thickness", &thickness);
			element.Attribute("youngsModulus", &youngsModulus);
			element.Attribute("fluidDamping", &fluidDamping);
			element.Attribute("viscoelasticDamping", &viscoelasticDamping);
			
			// if any values are NULL then set them to the default
			thickness = thickness == NULL ? 0.1 : thickness;
			youngsModulus = youngsModulus == NULL ? 900 : youngsModulus;
			fluidDamping = fluidDamping == NULL ? 0.00001 : fluidDamping;
			viscoelasticDamping = viscoelasticDamping == NULL ? 0.1 : viscoelasticDamping;
			
			m_curMaterial = new Material(float(density), float(friction), float(restitution), Vector3(float(cr), float(cg), float(cb)),
											float(thickness), float(youngsModulus), float(fluidDamping), float(viscoelasticDamping));
			
			m_materials[name] = m_curMaterial;

			return true;
		}
		else if(element.ValueStr() == "bodies")
		{
			if(element.Parent()->ValueStr() != "world") return false;
			return true;
		}
		else if(element.ValueStr() == "ground")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			m_curBody = new Ground();
			return true;
		}
		else if(element.ValueStr() == "box")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double hx = 1;
			double hy = 1;
			double hz = 1;
			
			element.Attribute("hx", &hx);
			element.Attribute("hy", &hy);
			element.Attribute("hz", &hz);

			m_curBody = new Box(Vector3(float(hx), float(hy), float(hz)));
			return true;
		}
		else if(element.ValueStr() == "sphere")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double r = 1;

			element.Attribute("r", &r);

			m_curBody = new Sphere(float(r));
			return true;
		}
		else if(element.ValueStr() == "id")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			int id = 0;
			element.Attribute("id", &id);

			m_curBody->SetID(id);
			return true;
		}
		else if(element.ValueStr() == "pos")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->SetPosition(Vector3(float(x), float(y), float(z)));
			return true;
		}
		else if(element.ValueStr() == "vel")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->SetVelocity(Vector3(float(x), float(y), float(z)));
			return true;
		}
		else if(element.ValueStr() == "ori")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double theta = 0;
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("theta", &theta);
			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->SetOrientation(Quaternion(float(theta), Vector3(float(x), float(y), float(z))));
			return true;
		}
		else if(element.ValueStr() == "avel")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->SetAngularVelocity(Vector3(float(x), float(y), float(z)));
			return true;
		}
		else if(element.ValueStr() == "bodymaterial")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);

			const char* name = element.Attribute("name");
			Material* material = m_materials[name];
			if(material != NULL)
			{
				m_curBody->SetMaterial(material);
			}
			return true;
		}
		else
		{
			return false;
		}

		assert(false); // we should never get here
		return false;
	}
Пример #19
0
CSiteManagerItemData_Site* CSiteManager::GetSiteByPath(wxString sitePath)
{
	wxChar c = sitePath[0];
	if (c != '0' && c != '1')
	{
		wxMessageBox(_("Site path has to begin with 0 or 1."), _("Invalid site path"));
		return 0;
	}

	sitePath = sitePath.Mid(1);

	// We have to synchronize access to sitemanager.xml so that multiple processed don't write
	// to the same file or one is reading while the other one writes.
	CInterProcessMutex mutex(MUTEX_SITEMANAGER);

	CXmlFile file;
	TiXmlElement* pDocument = 0;

	if (c == '0')
		pDocument = file.Load(_T("sitemanager"));
	else
	{
		const wxString& defaultsDir = wxGetApp().GetDefaultsDir();
		if (defaultsDir == _T(""))
		{
			wxMessageBox(_("Site does not exist."), _("Invalid site path"));
			return 0;
		}
		wxFileName name(defaultsDir, _T("fzdefaults.xml"));
		pDocument = file.Load(name);
	}

	if (!pDocument)
	{
		wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR);

		return 0;
	}

	TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
	if (!pElement)
	{
		wxMessageBox(_("Site does not exist."), _("Invalid site path"));
		return 0;
	}

	std::list<wxString> segments;
	if (!UnescapeSitePath(sitePath, segments) || segments.empty())
	{
		wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement* pChild = GetElementByPath(pElement, segments);
	if (!pChild)
	{
		wxMessageBox(_("Site does not exist."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement* pBookmark;
	if (!strcmp(pChild->Value(), "Bookmark"))
	{
		pBookmark = pChild;
		pChild = pChild->Parent()->ToElement();
		segments.pop_back();
	}
	else
		pBookmark = 0;

	CSiteManagerItemData_Site* data = ReadServerElement(pChild);

	if (!data)
	{
		wxMessageBox(_("Could not read server item."), _("Invalid site path"));
		return 0;
	}

	if (pBookmark)
	{
		TiXmlHandle handle(pBookmark);

		wxString localPath;
		CServerPath remotePath;
		TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text();
		if (localDir)
			localPath = ConvLocal(localDir->Value());
		TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text();
		if (remoteDir)
			remotePath.SetSafePath(ConvLocal(remoteDir->Value()));
		if (!localPath.empty() && !remotePath.IsEmpty())
		{
			data->m_sync = GetTextElementBool(pBookmark, "SyncBrowsing", false);
		}
		else
			data->m_sync = false;

		data->m_localDir = localPath;
		data->m_remoteDir = remotePath;
	}

	data->m_path = BuildPath( c, segments );

	return data;
}
Пример #20
0
	/// Visit an element.
	virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* attribute)
	{
		if(element.ValueStr() == "world")
		{
			if(element.Parent() != element.GetDocument()) return false;
			return true;
		}
		else if(element.ValueStr() == "materials")
		{
			return true;
		}
		else if(element.ValueStr() == "material")
		{
            return true;
		}
		else if(element.ValueStr() == "bodies")
		{
			if(element.Parent()->ValueStr() != "world") return false;
			return true;
		}
		else if(element.ValueStr() == "ground")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

            m_curBody = new World::Ground();
			return true;
		}
		else if(element.ValueStr() == "box")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double hx = 0.5;
			double hy = 0.5;
			double hz = 0.5;
			
			element.Attribute("hx", &hx);
			element.Attribute("hy", &hy);
			element.Attribute("hz", &hz);

            World::Cube* cube = new World::Cube();
            cube->hx = hx;
            cube->hy = hy;
            cube->hz = hz;
            m_curBody = cube;
			return true;
		}
		else if(element.ValueStr() == "sphere")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double r = 1;		
			element.Attribute("r", &r);

            World::Sphere* sphere = new World::Sphere();
            sphere->r = r;
            m_curBody = sphere;
			return true;
		}
		else if(element.ValueStr() == "cylinder")
		{
			if(element.Parent()->ValueStr() != "bodies") return false;
			assert(m_curBody == NULL);

			double r = 1;
            double startx, starty, startz;
            double endx, endy, endz;
			element.Attribute("r", &r);

            element.Attribute("sx", &startx);
			element.Attribute("sy", &starty);
			element.Attribute("sz", &startz);

            element.Attribute("ex", &endx);
			element.Attribute("ey", &endy);
			element.Attribute("ez", &endz);

            World::Cylinder* cylinder = new World::Cylinder();
            cylinder->start = vec3(startx, starty, startz);
            cylinder->end = vec3(endx, endy, endz);
            cylinder->r = r;
            m_curBody = cylinder;
			return true;
		}
		else if(element.ValueStr() == "pos")
		{
			if(!IsBody(element.Parent())) return false;
			assert(m_curBody != NULL);
			double x = 0;
			double y = 0;
			double z = 0;

			element.Attribute("x", &x);
			element.Attribute("y", &y);
			element.Attribute("z", &z);

			m_curBody->pos = vec3(float(x), float(y), float(z));
			return true;
		}
		else if(element.ValueStr() == "vel")
		{
            return false;
		}
		else if(element.ValueStr() == "ori")
		{
            return false;
		}
		else if(element.ValueStr() == "avel")
		{
            return false;
		}
		else if(element.ValueStr() == "bodymaterial")
		{
            return false;
		}
		else
		{
			return false;
		}

		assert(false); // we should never get here
		return false;
	}
Пример #21
0
bool MainFrame::TransferNode(TiXmlNode** node, const wxArrayString& path)
{
  if (!path.IsEmpty())
  {
    int           level     = 0;
    TiXmlElement* element   = mCfgDst->FirstChildElement("CodeBlocksConfig");
    TiXmlNode*    node_copy = (*node)->Clone();

    if (!TiXmlSuccess(mCfgDst))
      return false;

    for (size_t i=0; i<path.Count(); ++i)
    {
      wxString section_path = path.Item(i);

      if (element->NoChildren())
      {
        // element has no children -> create new child named after section
        element = (TiXmlElement*) element->InsertEndChild(
          TiXmlElement(
#if wxUSE_UNICODE
            section_path.mb_str(wxConvUTF8)
#else
            (wxChar*)section_path.mb_str()
#endif
          ));
      }// if
      else
      {
        // element has children -> find child named after section
        TiXmlElement* new_element = element->FirstChildElement(
#if wxUSE_UNICODE
          section_path.mb_str(wxConvUTF8)
#else
          (wxChar*)section_path.mb_str()
#endif
        );

        if (!new_element)
        {
          // child could not be found -> create child named after section
          element = (TiXmlElement*) element->InsertEndChild(TiXmlElement(
#if wxUSE_UNICODE
            section_path.mb_str(wxConvUTF8)
#else
            (wxChar*)section_path.mb_str()
#endif
            ));
        }
        else
        {
          // child has been found -> switch to this child
          element = new_element;
        }
      }// else

      if (!element)
        return false;

      // ...continue with next section.
    }

    TiXmlNode* parent_node = element->Parent();
    parent_node->ReplaceChild(element, *node_copy);

    return true;
  }

  return false;
}// TransferNode
Пример #22
0
bool CSiteManager::GetBookmarks(wxString sitePath, std::list<wxString> &bookmarks)
{
	wxChar c = sitePath[0];
	if (c != '0' && c != '1')
		return false;

	sitePath = sitePath.Mid(1);

	// We have to synchronize access to sitemanager.xml so that multiple processed don't write
	// to the same file or one is reading while the other one writes.
	CInterProcessMutex mutex(MUTEX_SITEMANAGER);

	CXmlFile file;
	TiXmlElement* pDocument = 0;

	if (c == '0')
		pDocument = file.Load(_T("sitemanager"));
	else
	{
		const wxString& defaultsDir = wxGetApp().GetDefaultsDir();
		if (defaultsDir == _T(""))
			return false;
		pDocument = file.Load(wxFileName(defaultsDir, _T("fzdefaults.xml")));
	}

	if (!pDocument)
	{
		wxMessageBox(file.GetError(), _("Error loading xml file"), wxICON_ERROR);

		return false;
	}

	TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
	if (!pElement)
		return false;

	std::list<wxString> segments;
	if (!UnescapeSitePath(sitePath, segments))
	{
		wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement* pChild = GetElementByPath(pElement, segments);

	if (pChild && !strcmp(pChild->Value(), "Bookmark"))
		pChild = pChild->Parent()->ToElement();

	if (!pChild || strcmp(pChild->Value(), "Server"))
		return 0;

	// Bookmarks
	for (TiXmlElement* pBookmark = pChild->FirstChildElement("Bookmark"); pBookmark; pBookmark = pBookmark->NextSiblingElement("Bookmark"))
	{
		TiXmlHandle handle(pBookmark);

		wxString name = GetTextElement_Trimmed(pBookmark, "Name");
		if (name.empty())
			continue;

		wxString localPath;
		CServerPath remotePath;
		TiXmlText* localDir = handle.FirstChildElement("LocalDir").FirstChild().Text();
		if (localDir)
			localPath = ConvLocal(localDir->Value());
		TiXmlText* remoteDir = handle.FirstChildElement("RemoteDir").FirstChild().Text();
		if (remoteDir)
			remotePath.SetSafePath(ConvLocal(remoteDir->Value()));

		if (localPath.empty() && remotePath.IsEmpty())
			continue;

		bookmarks.push_back(name);
	}

	return true;
}
Пример #23
0
void KrEncoder::CalcAllInfo( TiXmlNode* node, 
							 AllInfo* i,
							 SDL_Surface* surface )
{
	TiXmlElement* ele = node->ToElement();
	if ( !ele )
	{
		GLASSERT( 0 );
		return;
	}	

	// Walk up the tree, get information as we go.
	TiXmlNode* parent = ele->Parent();
	while( parent )
	{
		TiXmlElement* parentEle = parent->ToElement();
		if ( parentEle )
		{
			if ( parentEle->Value() == "Definition" )
			{
//				i->format = FORMAT_DEF;
//
//				if ( parentEle->Attribute( "filename" ) )
//					i->filename = *parentEle->Attribute( "filename" );

				// We need go no higher.
				break;
			}
			else if ( parentEle->Value() == "Sprite" )
			{
				i->type = TYPE_SPRITE;

				if ( parentEle->Attribute( "name" ) )
					i->name = *parentEle->Attribute( "name" );
			}
			else if ( parentEle->Value() == "Action" )
			{
				if ( parentEle->Attribute( "name" ) )
					i->action = *parentEle->Attribute( "name" );
			}
			else if ( parentEle->Value() ==  "File" )
			{
//				if ( parentEle->Attribute( "filename" ) )
//					i->filename = *parentEle->Attribute( "filename" );
			}
			else if ( parentEle->Value() ==  "Direct" )
			{
				//i->format = FORMAT_DIRECT;
				// Go no higher.
				break;
			}
		}
		parent = parent->Parent();
	}

	// Now interpret the element itself:
	if ( ele->Value() == "Image" )
	{
		// Could be sprite or tile.
		i->useEntireImage = true;
	}
	else if ( ele->Value() == "ColorKey" )
	{
		// Could be sprite on tile.
		//i->useEntireImage = false;
	}
	else if ( ele->Value() == "Frame" )
	{
		i->type = TYPE_SPRITE;
	}
	else if ( ele->Value() == "Font" )
	{
		i->type = TYPE_FONT;
	}
	else if ( ele->Value() == "Tile" )
	{
		i->type = TYPE_TILE;
	}
	
	// And its attributes. They don't have different meanings in different
	// tags, so they can all be read in together.

	// ColorKey and Image attributes:
	if ( ele->Attribute( "tile" ) )
	{
		GLASSERT( i->type == TYPE_NONE );
		i->name = *ele->Attribute( "tile" );
		i->type = TYPE_TILE;
	}
	if ( ele->Attribute( "sprite" ) )
	{
		GLASSERT( i->type == TYPE_NONE );
		i->name = *ele->Attribute( "sprite" );
		i->type = TYPE_SPRITE;
	}
	if ( ele->Attribute( "color" ) )
	{
		gedString c = *ele->Attribute( "color" );
		i->keyColor.FromString( c.c_str() );
		i->keyColor.c.alpha = KrRGBA::KR_OPAQUE;	// alpha not used
	}
	if ( ele->Attribute( "frameCount" ) )
	{
		ele->Attribute( "frameCount", &i->frameCount );
	}
	if ( ele->Attribute( "action" ) )
	{
		i->action = *ele->Attribute( "action" );
	}
	if ( ele->Attribute( "sprite" ) )
	{
		i->name = *ele->Attribute( "sprite" );
	}

	// Used by tile and font:
	if ( ele->Attribute( "name" ) )
	{
		i->name = *ele->Attribute( "name" );
	}

	// Font attributes:
	if ( i->type == TYPE_FONT )
	{
		if ( ele->Attribute( "start" ) )
		{
			ele->Attribute( "start", &i->fontStart );
		}
		if ( ele->Attribute( "space" ) )
		{
			ele->Attribute( "space", &i->space );
		}
		if ( ele->Attribute( "type" ) )
		{
			if ( *ele->Attribute( "type" ) == "sfont" )
				i->subType = SUBTYPE_SFONT;
		}
	}

	// Generic attributes:
	if ( ele->Attribute( "x" ) )
	{
		ele->Attribute( "x", &i->x );
	}
	if ( ele->Attribute( "y" ) )
	{
		ele->Attribute( "y", &i->y );
	}
	if ( ele->Attribute( "size" ) )
	{
		GLASSERT( i->type == TYPE_TILE );
		ele->Attribute( "size", &i->width );
		i->height = i->width;					// size is height and width for tiles.
	}
	if ( ele->Attribute( "width" ) )
	{
		ele->Attribute( "width", &i->width );
	}
	if ( ele->Attribute( "height" ) )
	{
		ele->Attribute( "height", &i->height );
	}
	if ( ele->Attribute( "hotspotx" ) )
	{
		//i->hasHotspot = true;
		ele->Attribute( "hotspotx", &i->hotx);
	}
	if ( ele->Attribute( "hotspoty" ) )
	{
		//i->hasHotspot = true;
		ele->Attribute( "hotspoty", &i->hoty );
	}
	if ( ele->Attribute( "deltax" ) )
	{
		//i->hasDelta = true;
		ele->Attribute( "deltax", &i->deltax );
	}
	if ( ele->Attribute( "deltay" ) )
	{
		//i->hasDelta = true;
		ele->Attribute( "deltay", &i->deltay );
	}
	if ( ele->Attribute( "isotile" ) )
	{
		i->isoTargetWidth = 0;
		ele->Attribute( "isotile", &i->isoTargetWidth );
	}
	if ( ele->Attribute( "length" ) )
	{
		ele->Attribute( "length", &i->fontLength );
	}
	if ( ele->Attribute( "rotation" ) )
	{
		gedString r = *ele->Attribute( "rotation" );
		GlString::RemoveWhiteSpace( &r );

		GlDynArray< gedString > strArray;
		GlString::Split( &strArray, r, ",", false );

		for( int k=0; k<(int)strArray.Count(); ++k )
		{
			if ( strArray[k].length() > 1 && strArray[k].at( 0 ) == 'd' )
			{
				int division = strArray[k].at( 1 ) - '0'; //maks
				if ( division > 0 )
				{
					int increment = 360 / division;
					if ( increment > 0 )
					{
						for( int theta = 0; theta < 360; theta += increment )
						{
							i->rotation.PushBack( theta );
						}
					}
				}
			}
			else
			{
				int theta = atoi( strArray[k].c_str() );
				i->rotation.PushBack( theta );
			}
		}
		i->rotation.Sort();
	}

	if ( i->useEntireImage )
	{
		i->x = 0;
		i->y = 0;
		i->width = surface->w;
		i->height = surface->h;
	}
}