示例#1
0
DXFResult DXFFile::endEntity()
{
	StringToNodePtrMap::iterator itr;

	FDEBUGx(("DXFFile::endEntity(): _layersMapP = %p\n", 
			_layersMapP));

	for(itr  = _layersMapP->begin();
		itr != _layersMapP->end();
		++ itr)
	{
		FDEBUGx(("DXFFile::endEntity(): Adding LAYER %s to root node.\n",
				itr->first.c_str()));

		_rootNodeP->addChild(itr->second);
	}

	FDEBUGx(("DXFFile::endEntity(): _blocksMapP = %p\n", 
			_blocksMapP));

	for(itr  = _blocksMapP->begin();
		itr != _blocksMapP->end();
		++ itr)
	{
		FDEBUGx(("DXFFile::endEntity(): Have  BLOCK %s stored...\n",
				itr->first.c_str()));
	}


	return DXFStateContinue;
}
示例#2
0
/*! Complete Node representing the block from the fetched data.
 * \todo set trafo to _basePoint[]
 */
DXFResult DXFBlock::endEntity(void)
{
	StringToNodePtrMap::iterator itr = _blocksMapP->begin();

	setName(_blockNodeP, _entityTypeName + "=" + _blockName);

	while(itr != _blocksMapP->end())
	{
		itr = _blocksMapP->find(_blockName);
		if( itr != _blocksMapP->end())
		{	
			_blockName += _handle;
			FWARNING(("DXF Loader: in line %d: "
					  "block with same name '%s' already exists! "
					  "Renaming the new one to '%s' "
					  "(won't be able to access it for referencing though)\n",
					  DXFRecord::getLineNumber(),
					  itr->first.c_str(),
					  _blockName.c_str()
					 ));
		}
	}
	(*_blocksMapP)[_blockName] = _blockNodeP;

	FDEBUGx(("DXFBlocks::endEntity(): BLOCK '%s' in map and is stored as '%s'.\n",
			getName((*_blocksMapP)[_blockName]),
			_blockName.c_str()));

	// TODO: set transformation to _basePoint[] ?!?!?

	endEditCP(_blockNodeP);

	return DXFStateContinue;
}
示例#3
0
DXFResult DXFFile::beginEntity()
{
	_rootNodeP            = Node::create();
	GroupUnrecPtr groupP  = Group::create();

    _rootNodeP->setCore(groupP);
    //setName(_rootNodeP, szFilename);

	if(_linetypeMapP == NULL)
	{
		_linetypeMapP = new StringToLineChunkPtrMap();
	}
	else
	{
		_linetypeMapP->clear();
	}
	
	if(_layersMapP == NULL)
	{
		_layersMapP = new StringToNodePtrMap();
	}
	else
	{
		_layersMapP->clear();
	}

	FDEBUGx(("DXFFile::beginEntity(): _layersMapP = %p\n", 
			_layersMapP));
	
	if(_blocksMapP == NULL)
	{
		_blocksMapP = new StringToNodePtrMap();
	}
	else
	{
		_blocksMapP->clear();
	}
	
	return DXFStateContinue;
}
示例#4
0
/*! An entity type may be registered as child of more than one parent entity
 * type, e.g. VERTEX, which is child of 3DMESH, POLYLINE and many others.
 *
 * \pre entityType is a valid pointer != 0
 */
void DXFFile::registerEntityType( const Char8 *entityParentTypeName,
								  DXFEntityBase *entityType )
{
	StringToStringMMap::iterator  hmItr;

	// The ugly concept of entityTypeName, entityClassName and entityUniqueName
	// was introduced because of the **** "feature" of the DXF file format to
	// have pairs of different entities having the same keywords: there is a
	// TABLES entry named LAYER, thus a LAYERs table, and ther is the entry to
	// that table, the LAYER itself. The same **** holds for all other TABLE
	// types!

	// only for better readibility
	Char8 const * const entityTypeName  = entityType->getEntityTypeName();
	Char8 const * const entityClassName = entityType->getEntityClassName();
	const std::string entityUniqueName(std::string() + 
									   entityClassName + ":" + entityTypeName);

	if(_the == NULL)
	{
		// The constructor of DXFFile must be the only one of all instantiable
		// classes derived from DXFEntityBase, which does *NOT* call
		// DXFEntityBase::registerToParentEntity()!
		_the = new DXFFile();
	}

	// search for new entityType and add it if unknown. 
	EntityTypeMap::iterator itr = 
		_the->_entityTypes.find(entityUniqueName);
	if (itr == _the->_entityTypes.end())
		_the->_entityTypes[entityUniqueName] = entityType;

#if 1 // DEBUG
	for ( itr =  _the->_entityTypes.begin();
		  itr != _the->_entityTypes.end();
		  ++ itr)
	{
		FDEBUGx(("DXFFile::registerEntityType(%s(%p))\n", 
				itr->first.c_str(), itr->second
			   ));
	}
#endif

	if(entityType != _the) // (only) DXFFile has no parent entity type, thus
						   // ignore it!
	{
		// search for entityParentType
		EntityTypeMap::iterator itr = 
			_the->_entityTypes.find(entityParentTypeName);
		if (itr == _the->_entityTypes.end())
		{
			FDEBUGx(("DXFFile::registerEntityType: "
					"Parent Entity '%s' for Entity type '%s' not found. "
					"Storing for unresolved family\n",
					entityParentTypeName,
					entityTypeName));
			// Entity parent entity not found: the registration to the
			// respective entity parent type has to be deferred until the
			// parent type will be registered. Store the registration request.
			_the->_entityTypeHierarchy.insert(
				std::pair<const std::string, std::string>(entityParentTypeName,
													entityUniqueName)
											 );
		}
		else
		{			
			itr->second->_childEntityTypes[entityTypeName]
				= entityType;
			FDEBUGx(("DXFFile::registerEntityType: "
					"inserted entity type %s(%p) to parent type %s(%p).\n",
					itr->second->_childEntityTypes[entityTypeName]->getEntityTypeName(),
					itr->second->_childEntityTypes[entityTypeName],
					itr->second->getEntityTypeName(),
					itr->second
				   ));
			FDEBUGx(("DXFFile::registerEntityType: "
					"%s(%p)->_childEntityTypes.size() = %d\n",
					itr->second->getEntityTypeName(),
					itr->second,
					itr->second->_childEntityTypes.size()
				   ));
		}
	}

	// Resolve older registration requests for the added entity type
	// (entityUniqueName now has the role of a entityParentTypeName) and remove
	// it from unresolved list.

	std::pair<StringToStringMMap::iterator, StringToStringMMap::iterator>
		range = _the->_entityTypeHierarchy.equal_range(entityUniqueName);

	for( hmItr =  range.first;
		 hmItr != range.second;
		 ++ hmItr )
	{
		DXFEntityBase *childEntityType = 
			_the->_entityTypes[hmItr->second];
		Char8 const * const childEntityTypeName = 
			childEntityType->getEntityTypeName();
		
		_the->_entityTypes[hmItr->first]
			->_childEntityTypes[childEntityTypeName] = childEntityType;
	}
	_the->_entityTypeHierarchy.erase(range.first, range.second);
}
示例#5
0
/*! 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()