コード例 #1
0
ファイル: OSGDXFFile.cpp プロジェクト: chengzg/OSGAddOnsGV
/*! Initialize FILE:FILE as root of the DXF hierarchy.
 */
DXFFile::DXFFile(void) :
	 Inherited          (),
	_entityTypes        (),
	_entityTypeHierarchy()
{
	_entityClassName   = "FILE";
	_entityTypeName    = "FILE";

	_childBeginKeyword = "SECTION";
	_childEndKeyword   = "ENDSEC";
	
	// We need to do the relevant parts of registerToParentEntityType("FILE");
	// by hand here to avoid a infinite constructor call recursion.  DXFFile
	// has no parentEntityType and furthermore *DXFFile::_the will be
	// instantiated *before* all other entityTypes, thus we only need to put it
	// into the _entityTypes.
	std::string entityUniqueName =
		std::string() + getEntityClassName() + ":" + getEntityTypeName();
	_entityTypes[entityUniqueName] = this;
}
コード例 #2
0
ファイル: OSGDXFBlocks.cpp プロジェクト: mlimper/OpenSG1x
/*! Handle special dispatch case for BLOCKS section.
 *
 *  \dev This method is almost the same as DXFEntityBase::dispatch() besides
 *  that it dispatches a BLOCK directly without reading a name in a group with
 *  code 2. Thanks to the very very well designed DXF file format we need this
 *  distinction here :( \enddev 
 */
void DXFBlocks::dispatch(void)
{
	EntityTypeMap::iterator itr;

	// There must be a keyword!  // TODO: raus! DXFRecord::getValueType() < 0
	// wird schon in DXFEntityBase::read() gecheckt!!!
	if(DXFRecord::getValueStr().empty())
	{
		FWARNING(("DXF Loader: syntax error in line %d!\n",
				  DXFRecord::getLineNumber() + 1));
		_state = DXFStateError;
		FDEBUGx(("Line %d: %s:%s returns %s because of Record (%d|%s)\n",
				DXFRecord::getLineNumber(),
				getEntityClassName(),
				getEntityTypeName(),
				DXFResultNames[_state],
				DXFRecord::getGroupCode(),
				DXFRecord::getValueStr().c_str()
			   ));
		return;
	}

	// Keyword ENDSEC for SECTIONs, TABLEs, BLOCKS, ...
	if(DXFRecord::getValueStr() == _parent->getChildEndKeyword())
	{
		FDEBUGx(("EndKeyword: %s\n", DXFRecord::getValueStr().c_str()));
		DXFRecord::unget();
		_state = DXFStateReturn;
		FDEBUGx(("Line %d: %s:%s returns %s because of Record (%d|%s)\n",
				 DXFRecord::getLineNumber(),
				 getEntityClassName(),
				 getEntityTypeName(),
				 DXFResultNames[_state],
				 DXFRecord::getGroupCode(),
				 DXFRecord::getValueStr().c_str()
				));
		return;
	}

	if(DXFRecord::getValueStr() == _childBeginKeyword)  // == "BLOCK" !
	{
		itr = _childEntityTypes.find(DXFRecord::getValueStr());
		// unknown entity type?
		if(itr == _childEntityTypes.end())
		{
			FWARNING(("DXF Loader (%s:%s): in line %d: "
					  "%s '%s' not yet implemented. Ignoring!\n",
					  getEntityClassName(),
					  getEntityTypeName(),
					  DXFRecord::getLineNumber(),
					  _childBeginKeyword.c_str(),
					  DXFRecord::getValueStr().c_str()));
			_state = DXFStateIgnore;
			FDEBUGx(("(%s:%d) line %d: %s:%s returns %s because of Record (%d|%s)\n", 
					 __FILE__,
					 __LINE__,
					 DXFRecord::getLineNumber(),
					 getEntityClassName(),
					 getEntityTypeName(),
					 DXFResultNames[_state],
					 DXFRecord::getGroupCode(),
					 DXFRecord::getValueStr().c_str()
					));
			return;
		}

		// descent into the entity type hierarchy.
#if 1
		DXFEntityBase *entityBasePtr = dynamic_cast<DXFEntityBase *>(itr->second);
		entityBasePtr->read(this);
#else
		// doesn't work since read is protected in DFXEntityBase
		itr->second->DXFEntityBase::read(this);
#endif
		FDEBUGx(("(%s, %d) line %d: %s:%s returns %s because of Record (%d|%s)\n",
				 __FILE__, __LINE__,
				 DXFRecord::getLineNumber(),
				 getEntityClassName(),
				 getEntityTypeName(),
				 DXFResultNames[_state],
				 DXFRecord::getGroupCode(),
				 DXFRecord::getValueStr().c_str()
				));
		return;
	}
		
	// Eat up the END* keyword, which has been put back by a child entity, or
	// start reading again after the end of an unknown high level entity's
	// child.
	if(DXFRecord::getValueStr() == _childEndKeyword)
	{
		_state = DXFStateContinue;
		FDEBUGx(("(%s, %d) line %d: %s:%s returns %s because of Record (%d|%s)\n",
				 __FILE__, __LINE__,
				DXFRecord::getLineNumber(),
				getEntityClassName(),
				getEntityTypeName(),
				DXFResultNames[_state],
				DXFRecord::getGroupCode(),
				DXFRecord::getValueStr().c_str()
			   ));
		return;
	}

	if(_state == DXFStateIgnore)
	{
		FDEBUGx(("(%s, %d) line %d: %s:%s returns %s because of Record (%d|%s)\n",
				 __FILE__, __LINE__,
				DXFRecord::getLineNumber(),
				getEntityClassName(),
				getEntityTypeName(),
				DXFResultNames[_state],
				DXFRecord::getGroupCode(),
				DXFRecord::getValueStr().c_str()
			   ));
		return;
	}
	
	// Something went wrong
	_state = DXFStateError;
	FWARNING(("DXF Loader: syntax error in line %d, reported by %s:%s, "
			  "current record is (%d|%s). "
			  "May have happened already before. Giving up! (return = %s)\n",
			  DXFRecord::getLineNumber(),
			  getEntityClassName(),
			  getEntityTypeName(),
			  DXFRecord::getGroupCode(),
			  DXFRecord::getValueStr().c_str(),	
			  DXFResultNames[_state]
			 ));
	return;
}  // DXFBlocks::dispatch()