Example #1
0
void SchemeConfigParser::onStyleGroup(const XMLAttributes& att, const StylePtr& pClass)
{
	PNASSERT(m_pCurrent != NULL);

	LPCTSTR name = att.getValue(_T("name"));
	if(name)
	{
		m_pCurrent->BeginStyleGroup(name, att.getValue(_T("description")), (pClass.get() ? pClass->Style->name.c_str() : NULL) );
	}
}
Example #2
0
void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
{
  string Name(name);
  Element *temp_element;

  working_string.erase();

  if (!first_element_read) {
    document = new Element(Name);
    current_element = document;
    first_element_read = true;
  } else {
    temp_element = new Element(Name);
    temp_element->SetParent(current_element);
    current_element->AddChildElement(temp_element);
    current_element = temp_element;
  }

  if (current_element == 0L) {
      std::stringstream error;
    error << "In file " << getPath() << ": line " << getLine() << endl
         << "No current element read (running out of memory?)" << endl;
    throw std::runtime_error(error.str());
  }

  current_element->SetLineNumber(getLine());
  current_element->SetFileName(getPath());

  for (int i=0; i<atts.size();i++) {
    current_element->AddAttribute(atts.getName(i), atts.getValue(i));
  }
}
Example #3
0
void FGXMLParse::startElement (const char * name, const XMLAttributes &atts)
{
  string Name(name);
  Element *temp_element;

  working_string.erase();

  if (!first_element_read) {
    document = new Element(Name);
    current_element = document;
    first_element_read = true;
  } else {
    temp_element = new Element(Name);
    temp_element->SetParent(current_element);
    current_element->AddChildElement(temp_element);
    current_element = temp_element;
  }

  if (current_element == 0L) {
    cerr << "No current element read (no top-level element in XML file?)" << endl;
    exit (-1);
  }

  for (int i=0; i<atts.size();i++) {
    current_element->AddAttribute(atts.getName(i), atts.getValue(i));
  }
}
END_TEST
  

START_TEST (test_uncertml_attributes)
{
  fail_unless ( node->getNumAttributes() == 0 );

  XMLAttributes * attr = new XMLAttributes();
  attr->add("definition", "http://");

  int i = node->setAttributes(*(attr));

  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless ( node->getNumAttributes() == 1 );

  const XMLAttributes retrieved = node->getAttributes();

  fail_unless ( retrieved.isEmpty() == false );
  fail_unless ( retrieved.getLength() == 1 );
  fail_unless ( retrieved.getName(0) == "definition" );
  fail_unless ( retrieved.getValue(0) == "http://" );

  i = node->unsetAttributes();

  fail_unless ( i == LIBSBML_OPERATION_SUCCESS );
  fail_unless ( node->getNumAttributes() == 0 );
  fail_unless ( node->getAttributes().isEmpty() == true );
}
Example #5
0
void MagicFolderCache::startElement(XML_CSTR name, const XMLAttributes& atts)
{
	if( IN_STATE( PS_FOLDER ) )
	{
		if( MATCH("MagicFolder") )
		{
			_depth++;
			
			// Push this folder path onto the path stack...
			_pathStack = newStringStackItem(_pathStack, atts.getValue(_T("name")));
			
			// Store a folder object which will hold configuration etc.
			_current = new Folder(_pathStack->val.c_str(), _T(""));
			_map->insert(MagicFolderCache::FolderMap::value_type(_pathStack->val, _current));
		}
		else if( MATCH("File") )
		{
			STATE(PS_FILE);
			processFile(atts);
		}
		else
		{
			processUserData(name, atts);
		}
	}
	else if( IN_STATE( PS_FILE ) || IN_STATE( PS_USERDATA ) )
	{
		processUserData(name, atts);
	}
}
Example #6
0
 static void
 populateDOMAttributes(const XMLAttributes& src, XERCES_CPP_NAMESPACE::DOMElement* dest)
 {
     for (size_t i = 0; i < src.getCount(); ++i)
     {
         dest->setAttribute(XercesHelper::transcode(src.getName(i)).c_str(),
                            XercesHelper::transcode(src.getValue(i)).c_str());
     }
 }
Example #7
0
void UserSettingsParser::processSchemeElement(SchemeLoaderState* pState, LPCTSTR name, const XMLAttributes& atts)
{
	if(pState->m_State == US_STYLE_OVERRIDES)
	{
		if(_tcscmp(name, _T("style")) == 0)
		{
			StyleDetails* pStyle = new StyleDetails;
			SchemeParser::parseStyle(pState, atts, pStyle);

			if(!m_loadingPreset)
			{
				// Hand off the style to the master style
				StylePtr p( new FullStyleDetails(pStyle->Key) );
				p->CustomStyle = pStyle;
				m_pCurScheme->PreLoadCustomisedStyle( p );
			}
			else
			{
				// Apply customisation to existing style...
				StylePtr p = m_pCurScheme->GetStyle(pStyle->Key);
				if(p != NULL)
				{
					p->CustomStyle = pStyle;
				}
			}
		}
	}
	else if (pState->m_State == US_KEYWORD_OVERRIDES)
	{
		if(_tcscmp(name, _T("keywords")) == 0)
		{
			LPCTSTR key = atts.getValue(_T("key"));
			m_idval = _ttoi(key);

			pState->m_CDATA = "";

			pState->m_State = US_KEYWORDS;
		}
	}
	else if(pState->m_State == US_SCHEME)
	{
		if(_tcscmp(name, _T("override-keywords")) == 0)
		{
			pState->m_State = US_KEYWORD_OVERRIDES;
		}
		else if(_tcscmp(name, _T("override-styles")) == 0)
		{
			pState->m_State = US_STYLE_OVERRIDES;
		}
		else if(_tcscmp(name, _T("colours")) == 0)
		{
			m_pCurScheme->CustomColours.SetFromXml(atts);
		}
	}
}
LIBSBML_CPP_NAMESPACE_USE

/** @endcond */


CK_CPPSTART



START_TEST (test_XMLAttributes_add_get)
{
  XMLAttributes attrs;

  fail_unless( attrs.getLength() == 0 );
  fail_unless( attrs.getNumAttributes() == 0 );
  fail_unless( attrs.isEmpty()        );

  attrs.add("xmlns", "http://foo.org/");
  fail_unless( attrs.getLength() == 1     );
  fail_unless( attrs.getNumAttributes() == 1 );
  fail_unless( attrs.isEmpty()   == false );

  attrs.add("foo", "bar");
  fail_unless( attrs.getLength() == 2     );
  fail_unless( attrs.getNumAttributes() == 2 );
  fail_unless( attrs.isEmpty()   == false );

  fail_unless( attrs.getIndex("xmlns") ==  0 );
  fail_unless( attrs.getIndex("foo"  ) ==  1 );
  fail_unless( attrs.getIndex("bar"  ) == -1 );

  fail_unless( attrs.getValue("xmlns") == "http://foo.org/" );
  fail_unless( attrs.getValue("foo"  ) == "bar"             );
  fail_unless( attrs.getValue("bar"  ) == ""                );

  fail_unless( attrs.getName(0) == "xmlns" );
  fail_unless( attrs.getName(1) == "foo"   );
  fail_unless( attrs.getName(2) == ""      );
}
Example #9
0
void plotXMLVisitor::startElement (const char * name, const XMLAttributes &atts)
{
  current_element = name;
  for (int i=0; i<atts.size();i++) {
    if (string(atts.getName(i)) == string("axis")) {
      if (string(atts.getValue(i)) == string("x")) axis = eX;
      else if (string(atts.getValue(i)) == string("y2")) axis = eY2;
      else axis = eY;
    } else {
      cerr << "Unknown attribute " << atts.getName(i) << " encountered." << endl;
      exit (-1);
    }
    if (i == 1) {
      cerr << "Too many attributes. Offending attribute (item:" << i << ") is " << atts.getName(i) << endl;
      exit (-1);
    }
  }

  if (!first_element_read) {
    if (current_element != string("plotset")) {
      cerr << endl << "  This is not a valid plotset description (" << current_element << ")" << endl;
      exit (-1);
    } else {
      first_element_read = true;
    }
  }

  if (current_element == "page") {
    vPages.push_back(Page());
    inPage = true;
  } else if (current_element == "plot") {
    if (!inPage) {
      vPlots.push_back(Plots());
    } else {
      vPages.back().vPlots.push_back(Plots());
    }
  }
}
void
TerrainData_xmlHandler::startElement(const String& element, const XMLAttributes& attrs)
{
    if (element == "Terrain")
    {
        mData->mName = attrs.getValueAs<String>("name", Ogre::StringUtil::BLANK);
        mData->mXSize = attrs.getValueAs<uint>("xsize");
        mData->mZSize = attrs.getValueAs<uint>("zsize");
        mData->mTileSize = attrs.getValueAs<uint>("tileSize");
    }
    else if (element == "scale")
    {
        mData->mScale = Ogre::Vector3(attrs.getValueAs<Real>("x"),
                                      attrs.getValueAs<Real>("y"),
                                      attrs.getValueAs<Real>("z"));

        if (mData->mScale.x <= 0 || mData->mScale.y <= 0 || mData->mScale.z <= 0)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate scale definition in terrain file",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mPosition = Ogre::Vector3(- mData->mScale.x * mData->mXSize / 2,
                                           0,
                                         - mData->mScale.z * mData->mZSize / 2);
    }
    else if (element == "size")
    {
        mData->mScale = Ogre::Vector3(attrs.getValueAs<Real>("x") / mData->mXSize,
                                      attrs.getValueAs<Real>("y"),
                                      attrs.getValueAs<Real>("z") / mData->mZSize);

        if (mData->mScale.x <= 0 || mData->mScale.y <= 0 || mData->mScale.z <= 0)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate size definition in terrain file",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mPosition = Ogre::Vector3(- mData->mScale.x * mData->mXSize / 2,
                                           0,
                                         - mData->mScale.z * mData->mZSize / 2);
    }
    else if (element == "position")
    {
        mData->mPosition = Ogre::Vector3(attrs.getValueAs<Real>("x"),
                                         attrs.getValueAs<Real>("y"),
                                         attrs.getValueAs<Real>("z"));
    }
    else if (element == "centre" || element == "center")
    {
        mData->mPosition = Ogre::Vector3(attrs.getValueAs<Real>("x") - mData->mScale.x * mData->mXSize / 2,
                                         attrs.getValueAs<Real>("y"),
                                         attrs.getValueAs<Real>("z") - mData->mScale.z * mData->mZSize / 2);
    }
    else if (element == "heightmap")
    {
        const String& type = attrs.getValueAs<String>("type", "standard");
        const String& filename = attrs.getValue("filename");

        if (type != "image" && type != "standard" && type != "raw")
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate height data type",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mHeightmapType = type;
        mData->mHeightmapFilename = filename;
        if (mData->mHeightmapFilename.empty())
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate height data filename",
                "TerrainData_xmlHandler::startElement");
        }
    }
    else if (element == "gridInfo")
    {
        const String& type = attrs.getValueAs<String>("type", "standard");
        const String& filename = attrs.getValue("filename");

        if (type != "standard")
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate height info type",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mGridInfoFilename = filename;
        if (mData->mGridInfoFilename.empty())
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate grid info filename",
                "TerrainData_xmlHandler::startElement");
        }
    }    
    else if (element == "lightmap")
    {   
        const String& type = attrs.getValueAs<String>("type", "standard");
        const String& filename = attrs.getValue("filename");

        if (type != "standard" &&
			type != "image")
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate lightmap type",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mLightmapType = type;
        mData->mLightmapFilename = filename;
        if (mData->mLightmapFilename.empty())
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate lightmap filename",
                "TerrainData_xmlHandler::startElement");
        }
    }
    else if (element == "pixmap")
    {
        TerrainData::Pixmap pixmap;
        pixmap.textureId = attrs.getValueAs<uint>("textureId");
        pixmap.left = attrs.getValueAs<Real>("left", 0);
        pixmap.top = attrs.getValueAs<Real>("top", 0);
        pixmap.right = attrs.getValueAs<Real>("right", 1);
        pixmap.bottom = attrs.getValueAs<Real>("bottom", 1);

        if (!(0 <= pixmap.left && pixmap.left <= 1 &&
              0 <= pixmap.top && pixmap.top <= 1 &&
              0 <= pixmap.right && pixmap.right <= 1 &&
              0 <= pixmap.bottom && pixmap.bottom <= 1))
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate pixmap definition in terrain file",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mPixmaps.push_back(pixmap);
    }
    else if (element == "texture")
    {
        const String& type = attrs.getValueAs<String>("type", "image");
        const String& filename = attrs.getValue("filename");

        if (type != "image")
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INVALIDPARAMS,
                "Invalidate texture type",
                "TerrainData_xmlHandler::startElement");
        }

        mData->mTextures.push_back(filename);
    }
    else if (element == "template")
    {
        const String& name = attrs.getValue("name");
        const String& material = attrs.getValue("material");

        std::pair<TerrainData::MaterialTemplates::iterator, bool> inserted =
            mData->mMaterialTemplates.insert(TerrainData::MaterialTemplates::value_type(
                name, material));
        if (!inserted.second)
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_DUPLICATE_ITEM,
                "Duplicate material template '" + inserted.first->first + "' in terrain file",
                "TerrainData_xmlHandler::startElement");
        }
    }
    else if (element == "fog_replacement")
    {
        TerrainData::FogReplacement fogReplacement;
        fogReplacement.programNames[Ogre::FOG_NONE] = attrs.getValue("none");
        fogReplacement.programNames[Ogre::FOG_EXP] = attrs.getValue("exp");
        fogReplacement.programNames[Ogre::FOG_EXP2] = attrs.getValue("exp2");
        fogReplacement.programNames[Ogre::FOG_LINEAR] = attrs.getValue("linear");
        mData->mFogReplacements.push_back(fogReplacement);
    }
    else if (element == "ambient")
    {
        readColourRGB(attrs, mData->mSurfaceParams.ambient);
    }
    else if (element == "diffuse")
    {
        readColourRGB(attrs, mData->mSurfaceParams.diffuse);
    }
    else if (element == "specular")
    {
        readColourRGB(attrs, mData->mSurfaceParams.specular);
        mData->mSurfaceParams.shininess = attrs.getValueAs<Real>("shininess", mData->msDefaultSurfaceParams.shininess);
    }
    else if (element == "emissive")
    {
        readColourRGB(attrs, mData->mSurfaceParams.emissive);
    }
    else if (element == "pixmaps")
    {
        // no attributes
    }
    else if (element == "textures")
    {
        // no attributes
    }
    else if (element == "materials")
    {
        // no attributes
    }
    else if (element == "surface")
    {
        // no attributes
    }
	// anything else is an error which *should* have already been caught by XML validation
	else
	{
        OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
            "Unexpected data was found while parsing the terrain file: '" + element + "' is unknown.",
            "TerrainData_xmlHandler::startElement");
	}
}
Example #11
0
void UserSettingsParser::processScheme(SchemeLoaderState* pState, const XMLAttributes& atts)
{
	LPCTSTR pName =  atts.getValue(_T("name"));

	if(pName && ((int)_tcslen(pName) > 0))
	{
		if(!m_loadingPreset)
		{
			CT2CA schemeName(pName);
			m_pCurScheme = new SchemeDetails(schemeName);
		}
		else
		{
			CT2CA schemeName(pName);
			SchemeDetailsMap::iterator iScheme = pState->m_SchemeDetails.find(std::string(schemeName));
			if(iScheme != pState->m_SchemeDetails.end())
			{
				m_pCurScheme = (*iScheme).second;
			}
			else
			{
				m_pCurScheme = NULL;
			}
		}

		if(m_pCurScheme == NULL)
			return;

		//pScheme = new CustomisedScheme;
		m_SchemeName = pName;
		pState->m_State = US_SCHEME;

		LPCTSTR temp = atts.getValue(_T("ovtabs"));
		if(temp != NULL && _tcslen(temp) > 0)
		{
			m_pCurScheme->CustomFlagFlags |= schOverrideTabs;

			if(SZTRUE(temp))
				// Signal that we definitely want to override the tab use.
				m_pCurScheme->CustomFlags |= schOverrideTabs;
		
			temp = atts.getValue(_T("usetabs"));
			if(temp != NULL && _tcslen(temp) > 0)
			{
				m_pCurScheme->CustomFlagFlags |= schUseTabs;
				if(SZTRUE(temp))
					m_pCurScheme->CustomFlags |= schUseTabs;
			}

		}

		temp = atts.getValue(_T("tabwidth"));
		if(temp != NULL && _tcslen(temp) > 0)
		{
			m_pCurScheme->CustomFlagFlags |= schOverrideTabSize;
			m_pCurScheme->CustomFlags |= schOverrideTabSize;

			m_pCurScheme->CustomTabWidth = _ttoi(temp);
		}
	}
#ifdef _DEBUG
	else
	{
		LOG(_T("UserSettingsParser::processScheme(): Scheme section without name attribute.\n"));
	}
#endif
}
Example #12
0
void StructureVisitor::startElement (const char * name, const XMLAttributes &atts)
{
	int i;

	if (_level == 0)
	{
		if (string(name) != (string)"structures-file")
		{
			string message = "Root element name is ";
			message += name;
			message += "; expected structures-file";
			throw xh_io_exception(message, "XML Reader");
		}
		push_state(NULL, "top");
		return;
	}

	if (_level == 1)
	{
		if (string(name) == (string)"coordinates")
		{
			const char *type  = atts.getValue("type");
			const char *value = atts.getValue("value");
			m_pSA->m_proj.SetTextDescription(type, value);
			g_Conv.Setup(m_pSA->m_proj.GetUnits(), DRECT(0,1,1,0));
		}
		else if (string(name) == (string)"structures")
		{
			push_state(NULL, "structures");
		}
		else
		{
			// Unknown element: ignore
			push_state(NULL, "dummy");
		}
		return;
	}

	const char *attval;

	if (_level == 2)
	{
		vtStructure *pStruct = NULL;
		if (string(name) == (string)"structure")
		{
			// Get the name.
			attval = atts.getValue("type");
			if (attval != NULL)
			{
				if (string(attval) == (string)"building")
				{
					vtBuilding *bld = m_pSA->NewBuilding();
					pStruct = bld;
				}
				if (string(attval) == (string)"linear")
				{
					vtFence *fen = m_pSA->NewFence();
					pStruct = fen;
				}
				if (string(attval) == (string)"instance")
				{
					vtStructInstance *inst = m_pSA->NewInstance();
					pStruct = inst;
				}
			}
			push_state(pStruct, "structure");
		}
		else
		{
			// Unknown field, ignore.
			pStruct = NULL;
			push_state(pStruct, "dummy");
		}
		return;
	}

	State &st = state();
	vtStructure *pStruct = st.item;
	if (!pStruct)
		return;
	vtFence *fen = pStruct->GetFence();
	vtBuilding *bld = pStruct->GetBuilding();
	vtStructInstance *inst = pStruct->GetInstance();

	if (_level == 3 && bld != NULL)
	{
		if (string(name) == (string)"height")
		{
			attval = atts.getValue("stories");
			if (attval)
			{
				// height in stories ("floors")
				int stories = atoi(attval);
				if (bld)
					bld->SetStories(stories);
			}
		}
		if (string(name) == (string)"walls")
		{
			attval = atts.getValue("color");
			if (bld && attval)
				st.wall_color = ParseRGB(attval);
		}
		if (string(name) == (string)"shapes")
		{
			push_state(pStruct, "shapes");
			return;
		}
		if (string(name) == (string)"roof")
		{
			// hack to postpone setting building color until now
			bld->SetColor(BLD_BASIC, st.wall_color);

			const char *type = atts.getValue("type");
			if (bld && (string)type == (string)"flat")
				bld->SetRoofType(ROOF_FLAT);
			if (bld && (string)type == (string)"shed")
				bld->SetRoofType(ROOF_SHED);
			if (bld && (string)type == (string)"gable")
				bld->SetRoofType(ROOF_GABLE);
			if (bld && (string)type == (string)"hip")
				bld->SetRoofType(ROOF_HIP);
			attval = atts.getValue("color");
			if (bld && attval)
				bld->SetColor(BLD_ROOF, ParseRGB(attval));
		}
		if (string(name) == (string)"points")
		{
			attval = atts.getValue("num");
		}
		return;
	}
	if (_level == 3 && fen != NULL)
	{
		if (string(name) == (string)"points")
		{
			int points;
			const char *num = atts.getValue("num");
			points = atoi(num);

			DLine2 &fencepts = fen->GetFencePoints();

			DPoint2 loc;
			const char *coords = atts.getValue("coords");
			const char *cp = coords;
			for (i = 0; i < points; i++)
			{
				sscanf(cp, "%lf %lf", &loc.x, &loc.y);
				fencepts.Append(loc);
				cp = strchr(cp, ' ');
				cp++;
				cp = strchr(cp, ' ');
				cp++;
			}
		}
		if (string(name) == (string)"height")
		{
			// absolute height in meters
			const char *abs_str = atts.getValue("abs");
			if (abs_str)
				fen->GetParams().m_fPostHeight = (float)atof(abs_str);
		}
		if (string(name) == (string)"posts")
		{
			// this linear structure has posts
			const char *type = atts.getValue("type");
			if (0 == strcmp(type, "wood"))
				fen->ApplyStyle(FS_WOOD_POSTS_WIRE);
			else if (0 == strcmp(type, "steel"))
				fen->ApplyStyle(FS_CHAINLINK);
			else
				fen->ApplyStyle(FS_METAL_POSTS_WIRE);

			const char *size = atts.getValue("size");
			FPoint3 postsize;
			postsize.y = fen->GetParams().m_fPostHeight;
			sscanf(size, "%f, %f", &postsize.x, &postsize.z);
			fen->GetParams().m_fPostWidth = postsize.x;
			fen->GetParams().m_fPostDepth = postsize.z;

			const char *spacing = atts.getValue("spacing");
			if (spacing)
				fen->GetParams().m_fPostSpacing = (float)atof(spacing);
		}
		if (string(name) == (string)"connect")
		{
			attval = atts.getValue("type");
			// not supported here
		}
		return;
	}
	if (_level == 3 && inst != NULL)
	{
		if (string(name) == (string)"placement")
		{
			const char *loc = atts.getValue("location");
			if (loc)
			{
				DPoint2 p;
				sscanf(loc, "%lf %lf", &p.x, &p.y);
				inst->SetPoint(p);
			}
			const char *rot = atts.getValue("rotation");
			if (rot)
			{
				float fRot;
				sscanf(rot, "%f", &fRot);
				inst->SetRotation(fRot);
			}
		}
		else
			_data = "";
	}
	if (_level == 4 && bld != NULL)
	{
		if (string(name) == (string)"rect")
		{
			DPoint2 loc;
			FPoint2 size2;
			const char *ref_point = atts.getValue("ref_point");
			if (ref_point)
			{
				sscanf(ref_point, "%lf %lf", &loc.x, &loc.y);
				bld->SetRectangle(loc, 10, 10);
			}
			float fRotation = 0.0f;
			const char *rot = atts.getValue("rot");
			if (rot)
			{
				fRotation = (float)atof(rot);
			}
			const char *size = atts.getValue("size");
			if (size)
			{
				sscanf(size, "%f, %f", &size2.x, &size2.y);
				bld->SetRectangle(loc, size2.x, size2.y, fRotation);
			}
		}
		if (string(name) == (string)"circle")
		{
			DPoint2 loc;
			const char *ref_point = atts.getValue("ref_point");
			if (ref_point)
			{
				sscanf(ref_point, "%lf %lf", &loc.x, &loc.y);
				bld->SetCircle(loc, 10);
			}
			const char *radius = atts.getValue("radius");
			if (radius)
			{
				bld->SetCircle(loc, (float)atof(radius));
			}
		}
		if (string(name) == (string)"poly")
		{
			int points;
			const char *num = atts.getValue("num");
			points = atoi(num);

			DLine2 foot;
			DPoint2 loc;
			const char *coords = atts.getValue("coords");
			const char *cp = coords;
			for (i = 0; i < points; i++)
			{
				sscanf(cp, "%lf %lf", &loc.x, &loc.y);
				foot.Append(loc);
				cp = strchr(cp, ' ');
				cp++;
				cp = strchr(cp, ' ');
				cp++;
			}
			bld->SetFootprint(0, foot);
		}
	}
}
XMLNode * 
RDFAnnotationParser::createCVTerms(const SBase * object)
{
  if (object == NULL) return NULL;

  /* create the basic triples */
  XMLTriple li_triple = XMLTriple("li", 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdf");
  XMLTriple bag_triple = XMLTriple("Bag", 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdf");
  
  /* attributes */
  XMLAttributes blank_att = XMLAttributes();
 
  /* tokens */
  XMLToken bag_token = XMLToken(bag_triple, blank_att);

  std::string prefix;
  std::string name;
  std::string uri;

  XMLAttributes *resources;

  XMLNode *description = createRDFDescription(object);

  /* loop through the cv terms and add */
  /* want to add these in blocks of same qualifier */
  if (object->getCVTerms())
  {
    for (unsigned int n = 0; n < object->getCVTerms()->getSize(); n++)
    {
      CVTerm* current = static_cast <CVTerm *> (object->getCVTerms()->get(n));
      if (current == NULL) continue;

      if (current->getQualifierType() == MODEL_QUALIFIER)
      {
        prefix = "bqmodel";
        uri = "http://biomodels.net/model-qualifiers/";
       
        const char* term = ModelQualifierType_toString(
          current->getModelQualifierType());
        if (term == NULL) return NULL;

        name = term;
        
      }
      else if (current
        ->getQualifierType() == BIOLOGICAL_QUALIFIER)
      {
        prefix = "bqbiol";
        uri = "http://biomodels.net/biological-qualifiers/";

        const char* term = BiolQualifierType_toString(
            current->getBiologicalQualifierType());
        if (term == NULL) return NULL;
        name = term;        
      }
      else
      {
        continue;
      }
      

      resources = current->getResources();
      XMLNode   bag(bag_token);

      for (int r = 0; r < resources->getLength(); r++)
      {
        XMLAttributes att;
        att.add(resources->getName(r), resources->getValue(r)); 
        
        XMLToken li_token(li_triple, att);
        li_token.setEnd();
        XMLNode li(li_token);

        bag.addChild(li);
      }

      XMLTriple type_triple(name, uri, prefix);
      XMLToken  type_token(type_triple, blank_att);
      XMLNode   type(type_token);

      type.addChild(bag);
      description->addChild(type);
    }

  }
  return description;
}
Example #14
0
void UtilOSMVisitor::startElement(const char *name, const XMLAttributes &atts)
{
	const char *val;

	if (m_state == 0)
	{
		if (!strcmp(name, "node"))
		{
			DPoint2 p;

			val = atts.getValue("id");
			if (val)
				m_id = atoi(val);
			else
				m_id = -1;	// Shouldn't happen.

			val = atts.getValue("lon");
			if (val)
				p.x = atof(val);

			val = atts.getValue("lat");
			if (val)
				p.y = atof(val);

			OSMNode node;
			node.p = p;
			m_nodes[m_id] = node;

			m_state = PS_NODE;

			m_pole = NULL;
		}
		else if (!strcmp(name, "way"))
		{
			m_refs.clear();
			m_state = PS_WAY;
			val = atts.getValue("id");
			if (val)
				m_id = atoi(val);
			else
				m_id = -1;	// Shouldn't happen.

			// Defaults
			m_line = NULL;
		}
	}
	else if (m_state == PS_NODE && !strcmp(name, "tag"))
	{
		vtString key, value;

		val = atts.getValue("k");
		if (val)
			key = val;

		val = atts.getValue("v");
		if (val)
			value = val;

		if (key == "power" && value == "tower")
			StartPowerPole();

		// Node key/value
		else if (key == "highway")
		{
			if (value == "traffic_signals")
			{
				m_nodes[m_nodes.size()-1].signal_lights = true;
			}
		}
		else if (m_pole)
		{
			// Add all node tags for power towers
			m_pole->AddTag(key, value);
		}
	}
	else if (m_state == PS_WAY)
	{
		if (!strcmp(name, "nd"))
		{
			val = atts.getValue("ref");
			if (val)
			{
				int ref = atoi(val);
				m_refs.push_back(ref);
			}
		}
		else if (!strcmp(name, "tag"))
		{
			vtString key, value;

			val = atts.getValue("k");
			if (val)
				key = val;

			val = atts.getValue("v");
			if (val)
				value = val;

			if (m_line)
				m_line->AddTag(key, value);
			else
				ParseOSMTag(key, value);
		}
	}
}
Example #15
0
void StructVisitorGML::startElement(const char *name, const XMLAttributes &atts)
{
	const char *attval;
	float f;

	// clear data at the start of each element
	m_data = "";

	if (m_state == 0 && !strcmp(name, "StructureCollection"))
	{
		m_state = 1;
		return;
	}

	if (m_state == 1)
	{
		if (!strcmp(name, "Building"))
		{
			m_pBuilding = m_pSA->NewBuilding();
			m_pStructure = m_pBuilding;
			m_state = 2;
			m_iLevel = 0;
		}
		else if (!strcmp(name, "Linear"))
		{
			m_pFence = m_pSA->NewFence();
			m_pFence->GetParams().Blank();
			m_pStructure = m_pFence;

			// support obsolete attribute
			attval = atts.getValue("Height");
			if (attval)
			{
				f = (float) atof(attval);
				m_pFence->GetParams().m_fPostHeight = f;
				m_pFence->GetParams().m_fConnectTop = f;
			}
			m_state = 10;
		}
		else if (!strcmp(name, "Imported"))
		{
			m_pInstance = m_pSA->NewInstance();
			m_pStructure = m_pInstance;

			m_state = 20;
		}
		attval = atts.getValue("ElevationOffset");
		if (attval)
			m_pStructure->SetElevationOffset((float) atof(attval));
		attval = atts.getValue("Absolute");
		if (attval)
			m_pStructure->SetAbsolute(*attval == 't');

		return;
	}

	if (m_state == 2)	// Building
	{
		if (!strcmp(name, "Level"))
		{
			m_pLevel = m_pBuilding->CreateLevel();
			attval = atts.getValue("FloorHeight");
			if (attval)
				m_pLevel->m_fStoryHeight = (float) atof(attval);
			attval = atts.getValue("StoryCount");
			if (attval)
				m_pLevel->m_iStories = atoi(attval);
			m_state = 3;
			m_iEdge = 0;
		}
		return;
	}

	if (m_state == 3)	// Level
	{
		if (!strcmp(name, "Footprint"))
		{
			m_state = 4;
			m_Footprint.clear();
		}
		else if (!strcmp(name, "Edge"))
		{
			m_pEdge = m_pLevel->GetEdge(m_iEdge);
			if (m_pEdge)	// safety check
			{
				m_pEdge->m_Features.clear();

				attval = atts.getValue("Material");
				if (attval)
				{
					vtMaterialDescriptorArray *mats = GetGlobalMaterials();
					m_pEdge->m_pMaterial = mats->FindName(attval);
					if (m_pEdge->m_pMaterial == NULL)
					{
						// What to do when a VTST references a material that
						// we don't have?  We don't want to lose the material
						// name information, and we also don't want to crash
						// later with a NULL material.  So, make a dummy.
						vtMaterialDescriptor *mat;
						mat = new vtMaterialDescriptor(attval, "", VT_MATERIAL_COLOUR);
						mat->SetRGB(RGBi(255,255,255));	// white means: missing
						mats->Append(mat);
						m_pEdge->m_pMaterial = &mat->GetName();
					}
				}
				attval = atts.getValue("Color");
				if (attval)
					m_pEdge->m_Color = ParseHexColor(attval);
				attval = atts.getValue("Slope");
				if (attval)
					m_pEdge->m_iSlope = atoi(attval);
				attval = atts.getValue("EaveLength");
				if (attval)
					m_pEdge->m_fEaveLength = (float) atof(attval);
				attval = atts.getValue("Facade");
				if (attval)
					m_pEdge->m_Facade = attval;
			}

			m_state = 7;	// in Edge
		}
		return;
	}

	if (m_state == 4)	// Footprint
	{
		if (!strcmp(name, "gml:outerBoundaryIs"))
			m_state = 5;
		if (!strcmp(name, "gml:innerBoundaryIs"))
			m_state = 6;
	}

	if (m_state == 5)	// Footprint outerBoundaryIs
	{
		// nothing necessary here, catch the end of element
	}

	if (m_state == 6)	// Footprint innerBoundaryIs
	{
		// nothing necessary here, catch the end of element
	}

	if (m_state == 7)	// Edge
	{
		if (!strcmp(name, "EdgeElement"))
		{
			vtEdgeFeature ef;

			attval = atts.getValue("Type");
			if (attval)
				ef.m_code = vtBuilding::GetEdgeFeatureValue(attval);
			attval = atts.getValue("Begin");
			if (attval)
				ef.m_vf1 = (float) atof(attval);
			attval = atts.getValue("End");
			if (attval)
				ef.m_vf2 = (float) atof(attval);
			if (m_pEdge)
				m_pEdge->m_Features.push_back(ef);
		}
	}

	if (m_state == 10)	// Linear
	{
		vtLinearParams &param = m_pFence->GetParams();
		if (!strcmp(name, "Path"))
		{
			m_state = 11;
		}
		else if (!strcmp(name, "Posts"))
		{
			// this linear structure has posts
			const char *type = atts.getValue("Type");
			if (type)
				param.m_PostType = type;
			else
				param.m_PostType = "none";

			const char *spacing = atts.getValue("Spacing");
			if (spacing)
				param.m_fPostSpacing = (float)atof(spacing);

			const char *height = atts.getValue("Height");
			if (height)
				param.m_fPostHeight = (float)atof(height);

			const char *size = atts.getValue("Size");
			if (size)
			{
				FPoint3 postsize;
				sscanf(size, "%f, %f", &postsize.x, &postsize.z);
				param.m_fPostWidth = postsize.x;
				param.m_fPostDepth = postsize.z;
			}

			const char *exten = atts.getValue("Extension");
			if (exten)
				param.m_PostExtension = exten;
		}
		else if (!strcmp(name, "Connect"))
		{
			const char *type = atts.getValue("Type");
			if (type)
			{
				// Older format version had string "none", "wire", or a material for type
				// Newer format has integer 0,1,2,3 for none,wire,simple,profile
				if (*type >= '0' && *type <= '9')
					param.m_iConnectType = atoi(type);
				else
				{
					// Convert old to new
					if (!strcmp(type, "none"))
						param.m_iConnectType = 0;
					else if (!strcmp(type, "wire"))
						param.m_iConnectType = 1;
					else
					{
						param.m_iConnectType = 2;
						param.m_ConnectMaterial = type;
					}
				}
			}
			else
				param.m_iConnectType = 0;

			attval = atts.getValue("Material");
			if (attval)
				param.m_ConnectMaterial = attval;

			attval = atts.getValue("Top");
			if (attval)
				param.m_fConnectTop = (float)atof(attval);
			attval = atts.getValue("Bottom");
			if (attval)
				param.m_fConnectBottom = (float)atof(attval);
			attval = atts.getValue("Width");
			if (attval)
				param.m_fConnectWidth = (float)atof(attval);
			attval = atts.getValue("Slope");
			if (attval)
				param.m_iConnectSlope = atoi(attval);
			attval = atts.getValue("ConstantTop");
			if (attval)
				param.m_bConstantTop = (*attval == 't');

			attval = atts.getValue("Profile");
			if (attval)
				param.m_ConnectProfile = attval;
		}
	}
	if (m_state == 20)	// Imported
	{
		if (!strcmp(name, "Location"))
		{
			m_state = 21;
		}
	}
}
Example #16
0
void UtilityVisitor::startElement(const char *name, const XMLAttributes &atts)
{
	const char *attval;

	// clear data at the start of each element
	m_data = "";

	if (m_state == 0)
	{
		if (!strcmp(name, "UtilityCollection"))
		{
			m_state = 1;
		}
		else
		{
			string message = "Root element name is ";
			message += name;
			message += "; expected UtilityCollection";
			throw xh_io_exception(message, "XML Reader");
		}
		return;
	}
	if (m_state == 1)
	{
		if (!strcmp(name, "OverheadLine"))
		{
			m_pRoute = new vtRoute(GetCurrentTerrain());		// Create new route (should this be in vtUtilityMap ??)
			attval = atts.getValue("name");
			if (attval)
				m_pRoute->SetName(attval);		// TODO Set Name of the overhead line
			GetCurrentTerrain()->AddRoute(m_pRoute);
			m_state = 2;
		}
		return;
	}

	if (m_state == 2)	// Conductor
	{
		if (!strcmp(name, "Conductor"))
		{
			attval = atts.getValue("width");
			if (attval)
				m_pRoute->SetThickness(atof(attval));
			attval = atts.getValue("color");
			if (attval)
				m_pRoute->SetColor(ParseHexColor(attval));
			m_state = 3;
		}
		return;
	}

	if (m_state == 3)	// Pylon
	{
		if (!strcmp(name, "Pylon"))
		{
			attval = atts.getValue("name");
			if (attval)
				SetName(attval);
			attval = atts.getValue("reference");
			if (attval)
				SetReference(attval);
			attval = atts.getValue("rotation");
			if (attval)
				SetRotation(atof(attval));

			m_state = 4;	// now read in the coordinate ...
		}
		else
			m_state = 1;	// then it is a new overhead line
		return;
	}
}
Example #17
0
XMLNode * 
RDFAnnotationParser::createCVTerms(const SBase * object)
{

  /* create the basic triples */
  XMLTriple li_triple = XMLTriple("li", 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdf");
  XMLTriple bag_triple = XMLTriple("Bag", 
    "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
    "rdf");
  
  /* attributes */
  XMLAttributes blank_att = XMLAttributes();
 
  /* tokens */
  XMLToken bag_token = XMLToken(bag_triple, blank_att);

  std::string prefix;
  std::string name;
  std::string uri;

  XMLAttributes *resources;

  XMLNode *description = createRDFDescription(object);

  /* loop through the cv terms and add */
  /* want to add these in blocks of same qualifier */
  if (object->getCVTerms())
  {
    for (unsigned int n = 0; n < object->getCVTerms()->getSize(); n++)
    {

      if (static_cast <CVTerm *> (object->getCVTerms()->get(n))
        ->getQualifierType() == MODEL_QUALIFIER)
      {
        prefix = "bqmodel";
        uri = "http://biomodels.net/model-qualifiers/";

        switch (static_cast <CVTerm *> (object->getCVTerms()->get(n))
                                            ->getModelQualifierType())
        {
        case BQM_IS:
          name = "is";
          break;
        case BQM_IS_DESCRIBED_BY:
          name = "isDescribedBy";
          break;
        case BQM_UNKNOWN:
          return NULL;
	        break;
        }
      }
      else if (static_cast <CVTerm *> (object->getCVTerms()->get(n))
        ->getQualifierType() == BIOLOGICAL_QUALIFIER)
      {
        prefix = "bqbiol";
        uri = "http://biomodels.net/biological-qualifiers/";

        switch (static_cast <CVTerm *> (object->getCVTerms()->get(n))
                                            ->getBiologicalQualifierType())
        {
        case BQB_IS:
          name = "is";
          break;
        case BQB_HAS_PART:
          name = "hasPart";
          break;
        case BQB_IS_PART_OF:
          name = "isPartOf";
          break;
        case BQB_IS_VERSION_OF:
          name = "isVersionOf";
          break;
        case BQB_HAS_VERSION:
          name = "hasVersion";
          break;
        case BQB_IS_HOMOLOG_TO:
          name = "isHomologTo";
          break;
        case BQB_IS_DESCRIBED_BY:
          name = "isDescribedBy";
          break;
        case BQB_IS_ENCODED_BY:
          name = "isEncodedBy";
          break;
        case BQB_ENCODES:
          name = "encodes";
          break;
        case BQB_OCCURS_IN:
          name = "occursIn";
          break;
        case BQB_UNKNOWN:
          return NULL;
      	  break;
        }
      }
      else
      {
        continue;
      }
      

      resources = static_cast <CVTerm *> (object->getCVTerms()->get(n))
                                                        ->getResources();
      XMLNode   bag(bag_token);

      for (int r = 0; r < resources->getLength(); r++)
      {
        XMLAttributes att;
        att.add(resources->getName(r), resources->getValue(r)); 
        
        XMLToken li_token(li_triple, att);
        li_token.setEnd();
        XMLNode li(li_token);

        bag.addChild(li);
      }

      XMLTriple type_triple(name, uri, prefix);
      XMLToken  type_token(type_triple, blank_att);
      XMLNode   type(type_token);

      type.addChild(bag);
      description->addChild(type);
    }

  }
  return description;
}
    /** Overridden from XMLHandler */
    void TerrainPaintXMLHandler::startElement(const String& element, const XMLAttributes& attributes)
    {
        if (element == "贴图")
        {
            mCurrentTextureInfo.clear();
        }
        else if (element == "所属贴图名称")
        {
            String attValue = attributes.getValue("名称");
            
            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

            mCurrentTextureInfo.ownerTextureName = attValue;
        }
        else if (element == "贴图大小")
        {
            String attValue = attributes.getValue("大小");

            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

            Ogre::StringVector valueVector = Ogre::StringUtil::split(attValue,",");

            if ( valueVector.size() != 2 )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " size of parameter must be two!");
                mCurrentElementWrong = true;
                return;
            }

            mCurrentTextureInfo.width = Ogre::StringConverter::parseUnsignedInt(valueVector[0]);
            mCurrentTextureInfo.height = Ogre::StringConverter::parseUnsignedInt(valueVector[1]);
        }
        else if (element == "贴图坐标")
        {
            String attValue = attributes.getValue("坐标");
            
            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

            Ogre::StringVector valueVector = Ogre::StringUtil::split(attValue,",");

            if ( valueVector.size() != 2 )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " size of parameter must be two!");
                mCurrentElementWrong = true;
                return;
            }

            mCurrentTextureInfo.leftCorner = Ogre::StringConverter::parseUnsignedInt(valueVector[0]);
            mCurrentTextureInfo.topCorner = Ogre::StringConverter::parseUnsignedInt(valueVector[1]);
        }
        else if (element == "画刷名称")
        {
            String attValue = attributes.getValue("名称");

            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

            mCurrentTextureInfo.brushName = attValue;
        }
        else if (element == "贴图类型")
        {
            String attValue = attributes.getValue("类型");

            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

            TerrainPaintInfoContainer::StringTexTypeMap::const_iterator it = mPaintInfoContainer->mStringTexTypeMap.find(attValue);

            if  ( it == mPaintInfoContainer->mStringTexTypeMap.end() )
            {
                _pushErrorInfoString(element + " " + attValue + " can't find the texture type!");
                mCurrentElementWrong = true;
                return;
            }

            // 从对应表中查找出相应的类型字符串
            mCurrentTextureInfo.textureType = it->second;

			attValue = attributes.getValue("额外的类型信息");

            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

			TerrainPaintInfoContainer::StringExtraTexTypeMap::const_iterator itt = mPaintInfoContainer->mStringExtraTexTypeMap.find(attValue);

			if ( itt == mPaintInfoContainer->mStringExtraTexTypeMap.end() )
            {
                _pushErrorInfoString(element + " " + attValue + " can't find the extra texture info type!");
                mCurrentElementWrong = true;
                return;
            }

			// 从对应表中查找出相应的类型字符串
			mCurrentTextureInfo.extraTexType = itt->second;
        }
		else if (element == "旋转方向")
        {
            String attValue = attributes.getValue("方向类型");

            if ( attValue.empty() )
            {
                _pushErrorInfoString(element + " " + attValue +
                    " the value can't be empty!");
                mCurrentElementWrong = true;
                return;
            }

			mCurrentTextureInfo.rotateType = Ogre::StringConverter::parseUnsignedInt(attValue);

			// 在拼接的大贴图中方向只能有4种选择
			if ( false == (mCurrentTextureInfo.rotateType >= 0 && mCurrentTextureInfo.rotateType <= 3) )
            {
                _pushErrorInfoString(element + " " + attValue + 
                    " rotate type must be between 0 and 3!");
                mCurrentElementWrong = true;
                return;
            }
		}
        else if (element == "贴图信息")
        {
        }
        // anything else is an error which *should* have already been caught by XML validation
        else
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_INTERNAL_ERROR,
                "Unexpected data was found while parsing the scene file: '" + element + "' is unknown.",
                "SceneXMLHandler::startElement");
        }
    }