Exemplo n.º 1
0
/*-------------------------------------------------------------------*
 |  ReadBlockHeader                                                  |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFBLOCKHEADER pBlockHeader =                               |
 |                           pointer to blockheader structure        |
 |  Output: Nothing!                                                 |
 *-------------------------------------------------------------------*/
void ReadBlockHeader( PDXF pDxf, PDXFBLOCKHEADER pBlockHeader )
{
	int		GCode;
	char	strValue[2048];

	dxfStorePos(pDxf);
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	while(GCode!=0)
	{
		switch(GCode)
		{
		case 8:		// Layer Name
			strcpy(pBlockHeader->LayerName, strValue);
			break;
		case 2:		// Block Name
			strcpy(pBlockHeader->Name, strValue);
			break;
		case 70:	// Block-type flags
			pBlockHeader->Flags = char(atoi(strValue));
		case 10:	// Base point X
			pBlockHeader->BasePoint.x = atoi(strValue);
			break;
		case 20:	// Base point Y
			pBlockHeader->BasePoint.y = atoi(strValue);
			break;
		case 30:	// Base point Z
			pBlockHeader->BasePoint.z = atoi(strValue);
			break;
		case 3:		// Block Name
			strcpy(pBlockHeader->Name, strValue);
			break;
		}
		dxfStorePos(pDxf);
		ReadParamFromDxfFile(pDxf, GCode, strValue);
	}

	if((GCode==0) && (strcmp(strValue, "ENDBLK")==0))
	{
		pDxf->Read.isBlockOpen = FALSE;

		do{
			dxfStorePos(pDxf);
			ReadParamFromDxfFile(pDxf, GCode, strValue);
		} while(GCode!=0);

		if(strcmp(strValue, "ENDSEC")==0)
			pDxf->Read.CurrentSection = SEC_NOTSET; // Blocks section has been finished
		else // Reached to next block
			dxfRestorePos(pDxf);
	}
	else
	{
		dxfRestorePos(pDxf);
		pDxf->Read.isBlockOpen = TRUE;
	}
}
Exemplo n.º 2
0
/*-------------------------------------------------------------------*
 |  dxfReadTableTypeName                                             |
 |  Inputs:                                                          |
 |      HDXF hDxf = handle to the openning DXF file structure        |
 |  Output: TableType Code else TAB_NOTSET                           |
 *-------------------------------------------------------------------*/
DWORD dxfReadTableTypeName( HDXF hDxf )
{
	PDXF	pDxf;
	int		GCode;
	char	strValue[2048];
	DWORD	result;

	// Initialize pDxf ------------------
	if((pDxf = InitilizePDXF(hDxf))==NULL)
		return FALSE;

	// Check if current section is TABLES
	if(pDxf->Read.CurrentSection!=SEC_TABLES)
	{
		// Current section is not TABLES
		GlobalUnlock(hDxf);
		return FALSE;
	}

	dxfStorePos(pDxf);

	// Read TableType Name
	dxfReadParam(hDxf, GCode, strValue);
	if((GCode==0) && (strcmp(strValue, "TABLE")==0))
		ReadTableTypeName(pDxf);
	else
		dxfRestorePos(pDxf); // Restore Old Position

	result = pDxf->Read.CurrentTableType;

	// UnInitilize hDxf -----------------
	UnInitilizePDXF(hDxf);

	return result;
}
Exemplo n.º 3
0
/*-------------------------------------------------------------------*
 |  ReadLayerData                                                    |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFLAYER pLayer = pointer to Layer structure                |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL ReadLayerData( PDXF pDxf, PDXFLAYER pLayer )
{
	int		GCode;
	char	strValue[2048];

	ZeroMemory(pLayer, sizeof(DXFLAYER));
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	while(GCode!=0)
	{
		switch(GCode)
		{
		case 2:		// Layer Name
			strcpy(pLayer->Name, strValue);
			break;
		case 70:	// Standard flags
			pLayer->StandardFlags = char(atoi(strValue));
			break;
		case 62:	// Layer Color
			pLayer->Color = atoi(strValue);
			break;
		case 6:		// Linetype
			strcpy(pLayer->LineType, strValue);
			break;
 		}
		dxfStorePos(pDxf);
		ReadParamFromDxfFile(pDxf, GCode, strValue);
	}
	
	dxfRestorePos(pDxf);
	return TRUE;
}
Exemplo n.º 4
0
/*-------------------------------------------------------------------*
 |  FindParamFromDxfFile                                             |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      int GroupCode = group code                                   |
 |      LPCTSTR valuestr = pointer to null terminated string to find |
 |  Output: TRUE if found else FALSE                                 |
 *-------------------------------------------------------------------*/
BOOL FindParamFromDxfFile( PDXF pDxf, int GroupCode, LPCTSTR valuestr )
{
	int		groupcode;
	char	value[2048];
	BOOL	found;

	found = FALSE;
	dxfStorePos(pDxf);
	while(/*!feof(pDxf->pStream)*/pDxf->Read.CurrentPos<pDxf->Read.FileSize)
	{
/*		if(fscanf(pDxf->pStream, "%d", &groupcode)<=0)
		{
			// file read error
			break;
		}

		ReadLine(pDxf, value);*/

		char strGroupCode[32];
		ReadLine(pDxf, strGroupCode);
		groupcode = atoi(strGroupCode);
		ReadLine(pDxf, value);

		if((groupcode==GroupCode) && (strcmp(valuestr, value)==0))
		{
			found = TRUE;
			break;
		}
	}

	if(!found)
		dxfRestorePos(pDxf);

	return found;
}
Exemplo n.º 5
0
/*-------------------------------------------------------------------*
 |  dxfReadBlockHeader                                               |
 |  Inputs:                                                          |
 |      HDXF hDxf = handle to the openning DXF file structure        |
 |      PDXFBLOCKHEADER pBlockHeader =                               |
 |                           pointer to blockheader structure        |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL dxfReadBlockHeader( HDXF hDxf, PDXFBLOCKHEADER pBlockHeader )
{
	PDXF	pDxf;
	int		GCode;
	char	strValue[2048];

	// Initialize pDxf ------------------
	if((pDxf = InitilizePDXF(hDxf))==NULL)
		return FALSE;

	// Check if current section is BLOCKS
	if(pDxf->Read.CurrentSection!=SEC_BLOCKS)
	{
		// Current section is not BLOCKS
		GlobalUnlock(hDxf);
		return FALSE;
	}

	dxfStorePos(pDxf);
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	if((GCode==0) && (strcmp(strValue, "BLOCK")==0))
		ReadBlockHeader(pDxf, pBlockHeader);
	else
	{
		// Can not read block header
		dxfRestorePos(pDxf);
		GlobalUnlock(hDxf);
		return FALSE;
	}
	
	// UnInitilize hDxf -----------------
	return UnInitilizePDXF(hDxf);
}
Exemplo n.º 6
0
/*-------------------------------------------------------------------*
 |  dxfFindBlockHeader                                               |
 |  Inputs:                                                          |
 |      HDXF hDxf = handle to the openning DXF file structure        |
 |      PDXFBLOCKHEADER pBlockHeader =                               |
 |                           pointer to blockheader structure        |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL dxfFindBlockHeader( HDXF hDxf, PDXFBLOCKHEADER pBlockHeader )
{
	PDXF	pDxf;

	// Initialize pDxf ------------------
	if((pDxf = InitilizePDXF(hDxf))==NULL)
		return FALSE;

	// Check if current section is BLOCKS
	if(pDxf->Read.CurrentSection!=SEC_BLOCKS)
	{
		// Current section is not BLOCKS
		GlobalUnlock(hDxf);
		return FALSE;
	}

	dxfStorePos(pDxf);
	if(FindParamFromDxfFile(pDxf, 0, "BLOCK"))
		ReadBlockHeader(pDxf, pBlockHeader);
	else
	{
		// Can not read block header
		dxfRestorePos(pDxf);
		GlobalUnlock(hDxf);
		return FALSE;
	}
	
	// UnInitilize hDxf -----------------
	return UnInitilizePDXF(hDxf);
}
Exemplo n.º 7
0
/*-------------------------------------------------------------------*
 |  dxfFindParam                                                     |
 |  Inputs:                                                          |
 |      HDXF hDxf = handle to the openning DXF file structure        |
 |      int GroupCode = group code                                   |
 |      LPCTSTR valuestr = pointer to null terminated string to find |
 |  Output: TRUE if found else FALSE                                 |
 *-------------------------------------------------------------------*/
BOOL dxfFindParam( HDXF hDxf, int GroupCode, LPCTSTR valuestr )
{
	PDXF	pDxf;
	int		groupcode;
	char	value[2048];
	BOOL	found;

	// Initialize pDxf ------------------
	if((pDxf = InitilizePDXF(hDxf))==NULL)
		return FALSE;

	found = FALSE;
	dxfStorePos(pDxf);
	while(/*!feof(pDxf->pStream)*/pDxf->Read.CurrentPos<pDxf->Read.FileSize)
	{
/*		if(fscanf(pDxf->pStream, "%d", &groupcode)<=0)
		{
			// file read error
			GlobalUnlock(hDxf);
			return FALSE;
		}

		ReadLine(pDxf, value);*/

		char strGroupCode[32];
		ReadLine(pDxf, strGroupCode);
		groupcode = atoi(strGroupCode);
		ReadLine(pDxf, value);

		if((groupcode==GroupCode) && (strcmp(valuestr, value)==0))
		{
			found = TRUE;
			break;
		}
	}

	if(!found)
		dxfRestorePos(pDxf);

	// UnInitilize hDxf -----------------
	UnInitilizePDXF(hDxf);

	return found;
}
Exemplo n.º 8
0
/*-------------------------------------------------------------------*
 |  ReadStyleData                                                    |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFSTYLE pStyle = pointer to Style structure                |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL ReadStyleData( PDXF pDxf, PDXFSTYLE pStyle )
{
	int		GCode;
	char	strValue[2048];

	ZeroMemory(pStyle, sizeof(DXFSTYLE));
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	while(GCode!=0)
	{
		switch(GCode)
		{
		case 2:		// Style Name
			strcpy(pStyle->Name, strValue);
			break;
		case 3:		// Primary Font Filename
			strcpy(pStyle->PrimaryFontFilename, strValue);
			break;
		case 70:	// Standard flags
			pStyle->StandardFlags = char(atoi(strValue));
			break;
		case 71:	// Text generation flags -> 2=Text is backward  4=Text is upside down
			pStyle->TextGenerationFlags = atoi(strValue);
			break;
		case 40:	// Fixed text height
			pStyle->FixedTextHeight = atof(strValue);
			break;
		case 41:	// Width Factor
			pStyle->WidthFactor = atof(strValue);
			break;
		case 42:	// Height
			pStyle->Height = atof(strValue);
			break;
		case 50:	// Oblique angle
			pStyle->ObliqueAngle = atof(strValue);
			break;
		}
		dxfStorePos(pDxf);
		ReadParamFromDxfFile(pDxf, GCode, strValue);
	}

	dxfRestorePos(pDxf);
	return TRUE;
}
Exemplo n.º 9
0
/*-------------------------------------------------------------------*
 |  ReadLTypeData                                                    |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFLTYPE pLType = pointer to LType structure                |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL ReadLTypeData( PDXF pDxf, PDXFLTYPE pLType )
{
	int		GCode;
	char	strValue[2048];
	int		i;

	i = 0;
	ZeroMemory(pLType, sizeof(DXFLTYPE));
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	while(GCode!=0)
	{
		switch(GCode)
		{
		case 2:		// Linetype Name
			strcpy(pLType->Name, strValue);
			break;
		case 70:	// Standard flags
			pLType->StandardFlags = char(atoi(strValue));
			break;
		case 3:		// Descriptive text for linetype
			strcpy(pLType->DescriptiveText, strValue);
			break;
		case 73:	// Number of linetype elements
			pLType->ElementsNumber = atoi(strValue);
			break;
		case 40:	// Total pattern length
			pLType->TotalPatternLength = atof(strValue);
			break;
		case 49:	// Dash, dot or space length
			pLType->Elements[i] = atof(strValue);
			i++;
			break;
		}
		dxfStorePos(pDxf);
		ReadParamFromDxfFile(pDxf, GCode, strValue);
	}
	
	dxfRestorePos(pDxf);
	return TRUE;
}
Exemplo n.º 10
0
/*-------------------------------------------------------------------*
 |  dxfReadTableType                                                 |
 |  Inputs:                                                          |
 |      HDXF hDxf = handle to the openning DXF file structure        |
 |      LPVOID pTableType = pointer to table type structure          |
 |  Output: TableType Code else TAB_NOTSET                           |
 *-------------------------------------------------------------------*/
DWORD dxfReadTableType( HDXF hDxf, LPVOID pTableType )
{
	PDXF	pDxf;
	int		GCode;
	char	strValue[2048];
	DWORD	result;

	// Initialize pDxf ------------------
	if((pDxf = InitilizePDXF(hDxf))==NULL)
		return FALSE;

	// Check if current section is TABLES
	if(pDxf->Read.CurrentSection!=SEC_TABLES)
	{
		// Current section is not TABLES
		GlobalUnlock(hDxf);
		return TAB_NOTSET;
	}

	// Looking for next table type if CurrentTableType==TAB_NOTSET
	if(pDxf->Read.CurrentTableType==TAB_NOTSET)
	{
		if(dxfFindNextTableType(hDxf)==TAB_NOTSET)
		{
			pDxf->Read.CurrentSection = SEC_NOTSET;
			GlobalUnlock(hDxf);
			return TAB_NOTSET;
		}
	}

	// Read current table type data
	result = TAB_NOTSET;
	switch(pDxf->Read.CurrentTableType)
	{
	case TAB_DIMSTYLE:
		if(!FindParamFromDxfFile(pDxf, 0, "DIMSTYLE"))
			break;
		else
		{
			if(ReadDimStyleData(pDxf, (PDXFDIMSTYLE)pTableType))
				result = TAB_DIMSTYLE;
		}
		break;

	case TAB_LAYER:
		if(!FindParamFromDxfFile(pDxf, 0, "LAYER"))
			break;
		else
		{
			if(ReadLayerData(pDxf, (PDXFLAYER)pTableType))
				result = TAB_LAYER;
		}
		break;

	case TAB_LTYPE:
		if(!FindParamFromDxfFile(pDxf, 0, "LTYPE"))
			break;
		else
		{
			if(ReadLTypeData(pDxf, (PDXFLTYPE)pTableType))
				result = TAB_LTYPE;
		}
		break;

	case TAB_STYLE:
		if(!dxfFindParam( hDxf, 0, "STYLE" ))
			break;
		else
		{
			if(ReadStyleData(pDxf, (PDXFSTYLE)pTableType))
				result = TAB_STYLE;
		}
		break;
	}

	dxfStorePos(pDxf);
	dxfReadParam(hDxf, GCode, strValue);

	if((GCode==0) && (strcmp(strValue, "ENDTAB")==0))
	{
		pDxf->Read.CurrentTableType = TAB_NOTSET;

//		while(dxfReadTableTypeName(hDxf)==TAB_NOTSET)
//		{
			dxfStorePos(pDxf);
			dxfReadParam(hDxf, GCode, strValue);
			if((GCode==0) && (strcmp(strValue, "ENDSEC")==0))
			{
				pDxf->Read.CurrentSection = SEC_NOTSET; // Tables section has been finished
//				break;
			}
			else
				dxfRestorePos(pDxf);
//		}
	}
	else
		dxfRestorePos(pDxf);

	// UnInitilize hDxf -----------------
	UnInitilizePDXF(hDxf);

	return result;
}
Exemplo n.º 11
0
/*-------------------------------------------------------------------*
 |  ReadDimStyleData                                                 |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFDIMSTYLE pDimStyle = pointer to DimStyle structure       |
 |  Output: TRUE if everything is ok                                 |
 *-------------------------------------------------------------------*/
BOOL ReadDimStyleData( PDXF pDxf, PDXFDIMSTYLE pDimStyle )
{
	int		GCode;
	char	strValue[2048];

	ZeroMemory(pDimStyle, sizeof(DXFDIMSTYLE));
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	while(GCode!=0)
	{
		switch(GCode)
		{
		case 2:		// DimStyle Name
			strcpy(pDimStyle->Name, strValue);
			break;
		case 70:	// Standard flag values
			pDimStyle->StandardFlags = char(atoi(strValue));
			break;
		case 176:	// Dimension line & Arrow heads color
			pDimStyle->DIMCLRD = atoi(strValue);
			break;
		case 46:	// Dimension line size after Extensionline
			pDimStyle->DIMDLE = atof(strValue);
			break;
		case 177:	// Extension line color
			pDimStyle->DIMCLRE = atoi(strValue);
			break;
		case 44:	// Extension line size after Dimline
			pDimStyle->DIMEXE = atof(strValue);
			break;
		case 42:	// Offset from origin
			pDimStyle->DIMEXO = atof(strValue);
			break;
		case 6:		// 1st Arrow head
			strcpy(pDimStyle->DIMBLK1, strValue);
			break;
		case 7:		// 2nd Arrow head
			strcpy(pDimStyle->DIMBLK2, strValue);
			break;
		case 41:	// Arrow size
			pDimStyle->DIMASZ = atof(strValue);
			break;
		case 340:	// Text style handle
			pDimStyle->DIMTXSTYObjhandle = atoi(strValue);
			break;
		case 178:	// Text color
			pDimStyle->DIMCLRT = atoi(strValue);
			break;
		case 140:	// Text height
			pDimStyle->DIMTXT = atof(strValue);
			break;
		case 77:	// Vertical Text Placement
			pDimStyle->DIMTAD = atoi(strValue);
			break;
		case 147:	// Offset from dimension line
			pDimStyle->DIMGAP = atof(strValue);
			break;
		}
		dxfStorePos(pDxf);
		ReadParamFromDxfFile(pDxf, GCode, strValue);
	}
	
	dxfRestorePos(pDxf);
	return TRUE;
}
Exemplo n.º 12
0
/*-------------------------------------------------------------------*
 |  dxfReadEntityData_Direct                                         |
 |  Inputs:                                                          |
 |      PDXF pDxf = pointer to the openning DXF file structure       |
 |      PDXFENTITYHEADER pEntityHeader =                             |
 |                  pointer to entity data header                    |
 |      LPVOID pEntityData = pointer to entity data structure to read|
 |  Output: TRUE if new entity is loaded                             |
 *-------------------------------------------------------------------*/
BOOL dxfReadEntityData_Direct( PDXF pDxf, PDXFENTITYHEADER pEntityHeader, LPVOID pEntityData )
{
	BOOL	result;

	// Check if current section is ENTITIES or BLOCKS
	if(pDxf->Read.CurrentSection!=SEC_ENTITIES)
	{
		if((pDxf->Read.CurrentSection!=SEC_BLOCKS) || (!pDxf->Read.isBlockOpen))
		{
			// Can not read entity data
			return FALSE;
		}
	}

	dxfStorePos(pDxf);
	ReadParamFromDxfFile(pDxf, GCode, strValue);
	if(GCode!=0)
	{
		// Can not read entity data
		dxfRestorePos(pDxf);
		return FALSE;
	}

	SetEntityHeaderDefaultValues(pEntityHeader);	// Set Entities Header to Default Values
	result = FALSE;

	do {
		if(strcmp(strValue, "LINE")==0)
		{
			ReadLineData(pDxf, pEntityHeader, (PDXFENTLINE)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "POINT")==0)
		{
			ReadPointData(pDxf, pEntityHeader, (PDXFENTPOINT)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "CIRCLE")==0)
		{
			ReadCircleData(pDxf, pEntityHeader, (PDXFENTCIRCLE)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "ELLIPSE")==0)
		{
			ReadEllipseData(pDxf, pEntityHeader, (PDXFENTELLIPSE)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "TEXT")==0)
		{
			ReadTextData(pDxf, pEntityHeader, (PDXFENTTEXT)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "ARC")==0)
		{
			ReadArcData(pDxf, pEntityHeader, (PDXFENTARC)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "SOLID")==0)
		{
			ReadSolidData(pDxf, pEntityHeader, (PDXFENTSOLID)pEntityData);
			result = TRUE;
			break;
		}
		else if(strcmp(strValue, "INSERT")==0)
		{
			ReadInsertData(pDxf, pEntityHeader, (PDXFENTINSERT)pEntityData);
			result = TRUE;
			break;
		}
		//This code is implemented by tran duy dung
		//*******************************************************************
		else if(strcmp(strValue, "POLYLINE")==0){
			ReadPolyLineData(pDxf, pEntityHeader, (PDXFENTPOLYLINE)pEntityData);
			result = TRUE;
			break;
		}
		//*******************************************************************
		else if(strcmp(strValue, "DIMENSION")==0)
		{
			ReadDimensionData(pDxf, pEntityHeader, (PDXFENTDIMENSION)pEntityData);
			result = TRUE;
			break;
		}
		else
		{
			// Unknown entity
			// Looking for next entity
			do {
				ReadParamFromDxfFile(pDxf, GCode, strValue);
			} while(GCode!=0);
		}
	} while((strcmp(strValue, "ENDBLK")!=0) && (strcmp(strValue, "ENDSEC")!=0) && (pDxf->Read.CurrentPos<pDxf->Read.FileSize));

	if((pDxf->Read.CurrentSection==SEC_BLOCKS) && (pDxf->Read.isBlockOpen))
	{
		if((GCode==0) && (strcmp(strValue, "ENDBLK")==0))
		{
			pDxf->Read.isBlockOpen = FALSE;

			do{
				dxfStorePos(pDxf);
				ReadParamFromDxfFile(pDxf, GCode, strValue);
			} while(GCode!=0);

			if(strcmp(strValue, "ENDSEC")==0)
				pDxf->Read.CurrentSection = SEC_NOTSET; // Blocks section has been finished
			else // Reached to the next block
				dxfRestorePos(pDxf);
		}
		else
			dxfRestorePos(pDxf);
	}
	else
	{
		if((GCode==0) && (strcmp(strValue, "ENDSEC")==0))
			pDxf->Read.CurrentSection = SEC_NOTSET; // Entities section has been finished
		else
			dxfRestorePos(pDxf);
	}

	return result;
}