/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/


#include <string.h>
#include <dxfentrd.hxx>

//--------------------------DXFBasicEntity--------------------------------------

DXFBasicEntity::DXFBasicEntity(DXFEntityType eThisType)
{
    eType=eThisType;
    pSucc=NULL;
    strncpy(sLayer,"0", 2 );
    strncpy(sLineType,"BYLAYER", 8 );
    fElevation=0;
    fThickness=0;
    nColor=256;
    nSpace=0;
    aExtrusion.fx=0.0;
    aExtrusion.fy=0.0;
    aExtrusion.fz=1.0;
}

void DXFBasicEntity::Read(DXFGroupReader & rDGR)
{
    while (rDGR.Read()!=0) EvaluateGroup(rDGR);
}

void DXFBasicEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG())
    {
        case   8: strncpy( sLayer, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case   6: strncpy( sLineType, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case  38: fElevation=rDGR.GetF(); break;
        case  39: fThickness=rDGR.GetF(); break;
        case  62: nColor=rDGR.GetI(); break;
        case  67: nSpace=rDGR.GetI(); break;
        case 210: aExtrusion.fx=rDGR.GetF(); break;
        case 220: aExtrusion.fy=rDGR.GetF(); break;
        case 230: aExtrusion.fz=rDGR.GetF(); break;
    }
}

DXFBasicEntity::~DXFBasicEntity()
{
}

//--------------------------DXFLineEntity---------------------------------------

DXFLineEntity::DXFLineEntity() : DXFBasicEntity(DXF_LINE)
{
}

void DXFLineEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 11: aP1.fx=rDGR.GetF(); break;
        case 21: aP1.fy=rDGR.GetF(); break;
        case 31: aP1.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFPointEntity--------------------------------------

DXFPointEntity::DXFPointEntity() : DXFBasicEntity(DXF_POINT)
{
}

void DXFPointEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFCircleEntity-------------------------------------

DXFCircleEntity::DXFCircleEntity() : DXFBasicEntity(DXF_CIRCLE)
{
    fRadius=1.0;
}

void DXFCircleEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fRadius=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFArcEntity----------------------------------------

DXFArcEntity::DXFArcEntity() : DXFBasicEntity(DXF_ARC)
{
    fRadius=1.0;
    fStart=0;
    fEnd=360.0;
}

void DXFArcEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fRadius=rDGR.GetF(); break;
        case 50: fStart=rDGR.GetF(); break;
        case 51: fEnd=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFTraceEntity--------------------------------------

DXFTraceEntity::DXFTraceEntity() : DXFBasicEntity(DXF_TRACE)
{
}

void DXFTraceEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 11: aP1.fx=rDGR.GetF(); break;
        case 21: aP1.fy=rDGR.GetF(); break;
        case 31: aP1.fz=rDGR.GetF(); break;
        case 12: aP2.fx=rDGR.GetF(); break;
        case 22: aP2.fy=rDGR.GetF(); break;
        case 32: aP2.fz=rDGR.GetF(); break;
        case 13: aP3.fx=rDGR.GetF(); break;
        case 23: aP3.fy=rDGR.GetF(); break;
        case 33: aP3.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFSolidEntity--------------------------------------

DXFSolidEntity::DXFSolidEntity() : DXFBasicEntity(DXF_SOLID)
{
}

void DXFSolidEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 11: aP1.fx=rDGR.GetF(); break;
        case 21: aP1.fy=rDGR.GetF(); break;
        case 31: aP1.fz=rDGR.GetF(); break;
        case 12: aP2.fx=rDGR.GetF(); break;
        case 22: aP2.fy=rDGR.GetF(); break;
        case 32: aP2.fz=rDGR.GetF(); break;
        case 13: aP3.fx=rDGR.GetF(); break;
        case 23: aP3.fy=rDGR.GetF(); break;
        case 33: aP3.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFTextEntity---------------------------------------

DXFTextEntity::DXFTextEntity() : DXFBasicEntity(DXF_TEXT)
{
    fHeight=1.0;
    sText[0]=0;
    fRotAngle=0.0;
    fXScale=1.0;
    fOblAngle=0.0;
    strncpy( sStyle, "STANDARD", 9 );
    nGenFlags=0;
    nHorzJust=0;
    nVertJust=0;
}

void DXFTextEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fHeight=rDGR.GetF(); break;
        case  1: strncpy( sText, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 50: fRotAngle=rDGR.GetF(); break;
        case 41: fXScale=rDGR.GetF(); break;
        case 42: fOblAngle=rDGR.GetF(); break;
        case  7: strncpy( sStyle, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 71: nGenFlags=rDGR.GetI(); break;
        case 72: nHorzJust=rDGR.GetI(); break;
        case 73: nVertJust=rDGR.GetI(); break;
        case 11: aAlign.fx=rDGR.GetF(); break;
        case 21: aAlign.fy=rDGR.GetF(); break;
        case 31: aAlign.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFShapeEntity--------------------------------------

DXFShapeEntity::DXFShapeEntity() : DXFBasicEntity(DXF_SHAPE)
{
    fSize=1.0;
    sName[0]=0;
    fRotAngle=0;
    fXScale=1.0;
    fOblAngle=0;
}

void DXFShapeEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fSize=rDGR.GetF(); break;
        case  2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 50: fRotAngle=rDGR.GetF(); break;
        case 41: fXScale=rDGR.GetF(); break;
        case 51: fOblAngle=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFInsertEntity-------------------------------------

DXFInsertEntity::DXFInsertEntity() : DXFBasicEntity(DXF_INSERT)
{
    nAttrFlag=0;
    sName[0]=0;
    fXScale=1.0;
    fYScale=1.0;
    fZScale=1.0;
    fRotAngle=0.0;
    nColCount=1;
    nRowCount=1;
    fColSpace=0.0;
    fRowSpace=0.0;
}

void DXFInsertEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 66: nAttrFlag=rDGR.GetI(); break;
        case  2: strncpy( sName, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 41: fXScale=rDGR.GetF(); break;
        case 42: fYScale=rDGR.GetF(); break;
        case 43: fZScale=rDGR.GetF(); break;
        case 50: fRotAngle=rDGR.GetF(); break;
        case 70: nColCount=rDGR.GetI(); break;
        case 71: nRowCount=rDGR.GetI(); break;
        case 44: fColSpace=rDGR.GetF(); break;
        case 45: fRowSpace=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFAttDefEntity-------------------------------------

DXFAttDefEntity::DXFAttDefEntity() : DXFBasicEntity(DXF_ATTDEF)
{
    fHeight=1.0;
    sDefVal[0]=0;
    sPrompt[0]=0;
    sTagStr[0]=0;
    nAttrFlags=0;
    nFieldLen=0;
    fRotAngle=0.0;
    fXScale=1.0;
    fOblAngle=0.0;
    strncpy( sStyle, "STANDARD", 9 );
    nGenFlags=0;
    nHorzJust=0;
    nVertJust=0;
}

void DXFAttDefEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fHeight=rDGR.GetF(); break;
        case  1: strncpy( sDefVal, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case  3: strncpy( sPrompt, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case  2: strncpy( sTagStr, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 70: nAttrFlags=rDGR.GetI(); break;
        case 73: nFieldLen=rDGR.GetI(); break;
        case 50: fRotAngle=rDGR.GetF(); break;
        case 41: fXScale=rDGR.GetF(); break;
        case 51: fOblAngle=rDGR.GetF(); break;
        case  7: strncpy( sStyle, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 71: nGenFlags=rDGR.GetI(); break;
        case 72: nHorzJust=rDGR.GetI(); break;
        case 74: nVertJust=rDGR.GetI(); break;
        case 11: aAlign.fx=rDGR.GetF(); break;
        case 21: aAlign.fy=rDGR.GetF(); break;
        case 31: aAlign.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFAttribEntity-------------------------------------

DXFAttribEntity::DXFAttribEntity() : DXFBasicEntity(DXF_ATTRIB)
{
    fHeight=1.0;
    sText[0]=0;
    sTagStr[0]=0;
    nAttrFlags=0;
    nFieldLen=0;
    fRotAngle=0.0;
    fXScale=1.0;
    fOblAngle=0.0;
    strncpy( sStyle, "STANDARD", 9 );
    nGenFlags=0;
    nHorzJust=0;
    nVertJust=0;
}

void DXFAttribEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fHeight=rDGR.GetF(); break;
        case  1: strncpy( sText, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case  2: strncpy( sTagStr, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 70: nAttrFlags=rDGR.GetI(); break;
        case 73: nFieldLen=rDGR.GetI(); break;
        case 50: fRotAngle=rDGR.GetF(); break;
        case 41: fXScale=rDGR.GetF(); break;
        case 51: fOblAngle=rDGR.GetF(); break;
        case  7: strncpy( sStyle, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        case 71: nGenFlags=rDGR.GetI(); break;
        case 72: nHorzJust=rDGR.GetI(); break;
        case 74: nVertJust=rDGR.GetI(); break;
        case 11: aAlign.fx=rDGR.GetF(); break;
        case 21: aAlign.fy=rDGR.GetF(); break;
        case 31: aAlign.fz=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFPolyLine-----------------------------------------

DXFPolyLineEntity::DXFPolyLineEntity() : DXFBasicEntity(DXF_POLYLINE)
{
    fElevation=0.0;
    nFlags=0;
    fSWidth=0.0;
    fEWidth=0.0;
    nMeshMCount=0;
    nMeshNCount=0;
    nMDensity=0;
    nNDensity=0;
    nCSSType=0;
}

void DXFPolyLineEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 30: fElevation=rDGR.GetF(); break;
        case 70: nFlags=rDGR.GetI(); break;
        case 40: fSWidth=rDGR.GetF(); break;
        case 41: fEWidth=rDGR.GetF(); break;
        case 71: nMeshMCount=rDGR.GetI(); break;
        case 72: nMeshNCount=rDGR.GetI(); break;
        case 73: nMDensity=rDGR.GetI(); break;
        case 74: nNDensity=rDGR.GetI(); break;
        case 75: nCSSType=rDGR.GetI(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFLWPolyLine---------------------------------------

DXFLWPolyLineEntity::DXFLWPolyLineEntity() :
    DXFBasicEntity( DXF_LWPOLYLINE ),
    nIndex( 0 ),
    nCount( 0 ),
    nFlags( 0 ),
    fConstantWidth( 0.0 ),
    fStartWidth( 0.0 ),
    fEndWidth( 0.0 ),
    pP( NULL )
{
}

void DXFLWPolyLineEntity::EvaluateGroup( DXFGroupReader & rDGR )
{
    switch ( rDGR.GetG() )
    {
        case 90 :
        {
            nCount = rDGR.GetI();
            if ( nCount )
                pP = new DXFVector[ nCount ];
        }
        break;
        case 70: nFlags = rDGR.GetI(); break;
        case 43: fConstantWidth = rDGR.GetF(); break;
        case 40: fStartWidth = rDGR.GetF(); break;
        case 41: fEndWidth = rDGR.GetF(); break;
        case 10:
        {
            if ( pP && ( nIndex < nCount ) )
                pP[ nIndex ].fx = rDGR.GetF();
        }
        break;
        case 20:
        {
            if ( pP && ( nIndex < nCount ) )
                pP[ nIndex++ ].fy = rDGR.GetF();
        }
        break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

DXFLWPolyLineEntity::~DXFLWPolyLineEntity()
{
    delete[] pP;
}

//--------------------------DXFHatchEntity-------------------------------------

DXFEdgeTypeLine::DXFEdgeTypeLine() :
    DXFEdgeType( 1 )
{

}
DXFEdgeTypeLine::~DXFEdgeTypeLine()
{

}
sal_Bool DXFEdgeTypeLine::EvaluateGroup( DXFGroupReader & rDGR )
{
    sal_Bool bExecutingGroupCode = sal_True;
    switch ( rDGR.GetG() )
    {
        case 10 : aStartPoint.fx = rDGR.GetF(); break;
        case 20 : aStartPoint.fy = rDGR.GetF(); break;
        case 11 : aEndPoint.fx = rDGR.GetF(); break;
        case 21 : aEndPoint.fy = rDGR.GetF(); break;
        default : bExecutingGroupCode = sal_False; break;
    }
    return  bExecutingGroupCode;
}

DXFEdgeTypeCircularArc::DXFEdgeTypeCircularArc() :
    DXFEdgeType( 2 ),
    fRadius( 0.0 ),
    fStartAngle( 0.0 ),
    fEndAngle( 0.0 ),
    nIsCounterClockwiseFlag( 0 )
{
}
DXFEdgeTypeCircularArc::~DXFEdgeTypeCircularArc()
{
}
sal_Bool DXFEdgeTypeCircularArc::EvaluateGroup( DXFGroupReader & rDGR )
{
    sal_Bool bExecutingGroupCode = sal_True;
    switch ( rDGR.GetG() )
    {
        case 10 : aCenter.fx = rDGR.GetF(); break;
        case 20 : aCenter.fy = rDGR.GetF(); break;
        case 40 : fRadius = rDGR.GetF(); break;
        case 50 : fStartAngle = rDGR.GetF(); break;
        case 51 : fEndAngle = rDGR.GetF(); break;
        case 73 : nIsCounterClockwiseFlag = rDGR.GetI(); break;
        default : bExecutingGroupCode = sal_False; break;
    }
    return  bExecutingGroupCode;
}

DXFEdgeTypeEllipticalArc::DXFEdgeTypeEllipticalArc() :
    DXFEdgeType( 3 ),
    fLength( 0.0 ),
    fStartAngle( 0.0 ),
    fEndAngle( 0.0 ),
    nIsCounterClockwiseFlag( 0 )
{
}
DXFEdgeTypeEllipticalArc::~DXFEdgeTypeEllipticalArc()
{

}
sal_Bool DXFEdgeTypeEllipticalArc::EvaluateGroup( DXFGroupReader & rDGR )
{
    sal_Bool bExecutingGroupCode = sal_True;
    switch( rDGR.GetG() )
    {
        case 10 : aCenter.fx = rDGR.GetF(); break;
        case 20 : aCenter.fy = rDGR.GetF(); break;
        case 11 : aEndPoint.fx = rDGR.GetF(); break;
        case 21 : aEndPoint.fy = rDGR.GetF(); break;
        case 40 : fLength = rDGR.GetF(); break;
        case 50 : fStartAngle = rDGR.GetF(); break;
        case 51 : fEndAngle = rDGR.GetF(); break;
        case 73 : nIsCounterClockwiseFlag = rDGR.GetI(); break;
        default : bExecutingGroupCode = sal_False; break;
    }
    return  bExecutingGroupCode;
}

DXFEdgeTypeSpline::DXFEdgeTypeSpline() :
    DXFEdgeType( 4 ),
    nDegree( 0 ),
    nRational( 0 ),
    nPeriodic( 0 ),
    nKnotCount( 0 ),
    nControlCount( 0 )
{
}
DXFEdgeTypeSpline::~DXFEdgeTypeSpline()
{

}
sal_Bool DXFEdgeTypeSpline::EvaluateGroup( DXFGroupReader & rDGR )
{
    sal_Bool bExecutingGroupCode = sal_True;
    switch ( rDGR.GetG() )
    {
        case 94 : nDegree = rDGR.GetI(); break;
        case 73 : nRational = rDGR.GetI(); break;
        case 74 : nPeriodic = rDGR.GetI(); break;
        case 95 : nKnotCount = rDGR.GetI(); break;
        case 96 : nControlCount = rDGR.GetI(); break;
        default : bExecutingGroupCode = sal_False; break;
    }
    return  bExecutingGroupCode;
}

DXFBoundaryPathData::DXFBoundaryPathData() :
    nFlags( 0 ),
    nHasBulgeFlag( 0 ),
    nIsClosedFlag( 0 ),
    nPointCount( 0 ),
    fBulge( 0.0 ),
    nSourceBoundaryObjects( 0 ),
    nEdgeCount( 0 ),
    bIsPolyLine( sal_True ),
    nPointIndex( 0 ),
    pP( NULL )
{
}

DXFBoundaryPathData::~DXFBoundaryPathData()
{
    sal_uInt32 i = 0;
    for ( i = 0; i < aEdges.size(); i++ )
        delete aEdges[ i ];
    delete[] pP;
}

sal_Bool DXFBoundaryPathData::EvaluateGroup( DXFGroupReader & rDGR )
{
    sal_Bool bExecutingGroupCode = sal_True;
    if ( bIsPolyLine )
    {
        switch( rDGR.GetG() )
        {
            case 92 :
            {
                nFlags = rDGR.GetI();
                if ( ( nFlags & 2 ) == 0 )
                    bIsPolyLine = sal_False;
            }
            break;
            case 93 :
            {
                nPointCount = rDGR.GetI();
                if ( nPointCount )
                    pP = new DXFVector[ nPointCount ];
            }
            break;
            case 72 : nHasBulgeFlag = rDGR.GetI(); break;
            case 73 : nIsClosedFlag = rDGR.GetI(); break;
            case 97 : nSourceBoundaryObjects = rDGR.GetI(); break;
            case 42 : fBulge = rDGR.GetF(); break;
            case 10:
            {
                if ( pP && ( nPointIndex < nPointCount ) )
                    pP[ nPointIndex ].fx = rDGR.GetF();
            }
            break;
            case 20:
            {
                if ( pP && ( nPointIndex < nPointCount ) )
                    pP[ nPointIndex++ ].fy = rDGR.GetF();
            }
            break;

            default : bExecutingGroupCode = sal_False; break;
        }
    }
    else
    {
        if ( rDGR.GetG() == 93 )
            nEdgeCount = rDGR.GetI();
        else if ( rDGR.GetG() == 72 )
        {
            sal_Int32 nEdgeType = rDGR.GetI();
            switch( nEdgeType )
            {
                case 1 : aEdges.push_back( new DXFEdgeTypeLine() ); break;
                case 2 : aEdges.push_back( new DXFEdgeTypeCircularArc() ); break;
                case 3 : aEdges.push_back( new DXFEdgeTypeEllipticalArc() ); break;
                case 4 : aEdges.push_back( new DXFEdgeTypeSpline() ); break;
            }
        }
        else if ( aEdges.size() )
            aEdges[ aEdges.size() - 1 ]->EvaluateGroup( rDGR );
        else
            bExecutingGroupCode = sal_False;
    }
    return bExecutingGroupCode;
}

DXFHatchEntity::DXFHatchEntity() :
    DXFBasicEntity( DXF_HATCH ),
    bIsInBoundaryPathContext( sal_False ),
    nCurrentBoundaryPathIndex( -1 ),
    nFlags( 0 ),
    nAssociativityFlag( 0 ),
    nBoundaryPathCount( 0 ),
    nHatchStyle( 0 ),
    nHatchPatternType( 0 ),
    fHatchPatternAngle( 0.0 ),
    fHatchPatternScale( 1.0 ),
    nHatchDoubleFlag( 0 ),
    nHatchPatternDefinitionLines( 0 ),
    fPixelSize( 1.0 ),
    nNumberOfSeedPoints( 0 ),
    pBoundaryPathData( NULL )
{
}

void DXFHatchEntity::EvaluateGroup( DXFGroupReader & rDGR )
{
    switch ( rDGR.GetG() )
    {
//      case 10 : aElevationPoint.fx = rDGR.GetF(); break;
//      case 20 : aElevationPoint.fy = rDGR.GetF(); break;
//      case 30 : aElevationPoint.fz = rDGR.GetF(); break;
        case 70 : nFlags = rDGR.GetI(); break;
        case 71 : nAssociativityFlag = rDGR.GetI(); break;
        case 91 :
        {
            bIsInBoundaryPathContext = sal_True;
            nBoundaryPathCount = rDGR.GetI();
            if ( nBoundaryPathCount )
                pBoundaryPathData = new DXFBoundaryPathData[ nBoundaryPathCount ];
        }
        break;
        case 75 :
        {
            nHatchStyle = rDGR.GetI();
            bIsInBoundaryPathContext = sal_False;
        }
        break;
        case 76 : nHatchPatternType = rDGR.GetI(); break;
        case 52 : fHatchPatternAngle = rDGR.GetF(); break;
        case 41 : fHatchPatternScale = rDGR.GetF(); break;
        case 77 : nHatchDoubleFlag = rDGR.GetI(); break;
        case 78 : nHatchPatternDefinitionLines = rDGR.GetI(); break;
        case 47 : fPixelSize = rDGR.GetF(); break;
        case 98 : nNumberOfSeedPoints = rDGR.GetI(); break;

        //!! passthrough !!
        case 92 : nCurrentBoundaryPathIndex++;
        default:
        {
            sal_Bool bExecutingGroupCode = sal_False;
            if ( bIsInBoundaryPathContext )
            {
                if ( ( nCurrentBoundaryPathIndex >= 0 ) &&
                    ( nCurrentBoundaryPathIndex < nBoundaryPathCount ) )
                    bExecutingGroupCode = pBoundaryPathData[ nCurrentBoundaryPathIndex ].EvaluateGroup( rDGR );
            }
            if ( bExecutingGroupCode == sal_False )
                DXFBasicEntity::EvaluateGroup(rDGR);
        }
        break;
    }
}

DXFHatchEntity::~DXFHatchEntity()
{
    delete[] pBoundaryPathData;
}

//--------------------------DXFVertexEntity-------------------------------------

DXFVertexEntity::DXFVertexEntity() : DXFBasicEntity(DXF_VERTEX)
{
    fSWidth=-1.0;
    fEWidth=-1.0;
    fBulge=0.0;
    nFlags=0;
    fCFTDir=0.0;

}

void DXFVertexEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 40: fSWidth=rDGR.GetF(); break;
        case 41: fEWidth=rDGR.GetF(); break;
        case 42: fBulge=rDGR.GetF(); break;
        case 70: nFlags=rDGR.GetI(); break;
        case 50: fCFTDir=rDGR.GetF(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//--------------------------DXFSeqEndEntity-------------------------------------

DXFSeqEndEntity::DXFSeqEndEntity() : DXFBasicEntity(DXF_SEQEND)
{
}

//--------------------------DXF3DFace-------------------------------------------

DXF3DFaceEntity::DXF3DFaceEntity() : DXFBasicEntity(DXF_3DFACE)
{
    nIEFlags=0;
}

void DXF3DFaceEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case 10: aP0.fx=rDGR.GetF(); break;
        case 20: aP0.fy=rDGR.GetF(); break;
        case 30: aP0.fz=rDGR.GetF(); break;
        case 11: aP1.fx=rDGR.GetF(); break;
        case 21: aP1.fy=rDGR.GetF(); break;
        case 31: aP1.fz=rDGR.GetF(); break;
        case 12: aP2.fx=rDGR.GetF(); break;
        case 22: aP2.fy=rDGR.GetF(); break;
        case 32: aP2.fz=rDGR.GetF(); break;
        case 13: aP3.fx=rDGR.GetF(); break;
        case 23: aP3.fy=rDGR.GetF(); break;
        case 33: aP3.fz=rDGR.GetF(); break;
        case 70: nIEFlags=rDGR.GetI(); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}


//--------------------------DXFDimensionEntity----------------------------------

DXFDimensionEntity::DXFDimensionEntity() : DXFBasicEntity(DXF_DIMENSION)
{
    sPseudoBlock[0]=0;
}

void DXFDimensionEntity::EvaluateGroup(DXFGroupReader & rDGR)
{
    switch (rDGR.GetG()) {
        case  2: strncpy( sPseudoBlock, rDGR.GetS(), DXF_MAX_STRING_LEN + 1 ); break;
        default: DXFBasicEntity::EvaluateGroup(rDGR);
    }
}

//---------------------------- DXFEntites --------------------------------------

void DXFEntities::Read(DXFGroupReader & rDGR)
{
    DXFBasicEntity * pE, * * ppSucc;

    ppSucc=&pFirst;
    while (*ppSucc!=NULL) ppSucc=&((*ppSucc)->pSucc);

    while (rDGR.GetG()!=0) rDGR.Read();

    while (strcmp(rDGR.GetS(),"ENDBLK")!=0 &&
           strcmp(rDGR.GetS(),"ENDSEC")!=0 &&
           strcmp(rDGR.GetS(),"EOF")!=0 )
    {

        if      (strcmp(rDGR.GetS(),"LINE"      )==0) pE=new DXFLineEntity;
        else if (strcmp(rDGR.GetS(),"POINT"     )==0) pE=new DXFPointEntity;
        else if (strcmp(rDGR.GetS(),"CIRCLE"    )==0) pE=new DXFCircleEntity;
        else if (strcmp(rDGR.GetS(),"ARC"       )==0) pE=new DXFArcEntity;
        else if (strcmp(rDGR.GetS(),"TRACE"     )==0) pE=new DXFTraceEntity;
        else if (strcmp(rDGR.GetS(),"SOLID"     )==0) pE=new DXFSolidEntity;
        else if (strcmp(rDGR.GetS(),"TEXT"      )==0) pE=new DXFTextEntity;
        else if (strcmp(rDGR.GetS(),"SHAPE"     )==0) pE=new DXFShapeEntity;
        else if (strcmp(rDGR.GetS(),"INSERT"    )==0) pE=new DXFInsertEntity;
        else if (strcmp(rDGR.GetS(),"ATTDEF"    )==0) pE=new DXFAttDefEntity;
        else if (strcmp(rDGR.GetS(),"ATTRIB"    )==0) pE=new DXFAttribEntity;
        else if (strcmp(rDGR.GetS(),"POLYLINE"  )==0) pE=new DXFPolyLineEntity;
        else if (strcmp(rDGR.GetS(),"LWPOLYLINE")==0) pE=new DXFLWPolyLineEntity;
        else if (strcmp(rDGR.GetS(),"VERTEX"    )==0) pE=new DXFVertexEntity;
        else if (strcmp(rDGR.GetS(),"SEQEND"    )==0) pE=new DXFSeqEndEntity;
        else if (strcmp(rDGR.GetS(),"3DFACE"    )==0) pE=new DXF3DFaceEntity;
        else if (strcmp(rDGR.GetS(),"DIMENSION" )==0) pE=new DXFDimensionEntity;
        else if (strcmp(rDGR.GetS(),"HATCH"     )==0) pE=new DXFHatchEntity;
        else
        {
            do {
                rDGR.Read();
            } while (rDGR.GetG()!=0);
            continue;
        }
        *ppSucc=pE;
        ppSucc=&(pE->pSucc);
        pE->Read(rDGR);
    }
}

void DXFEntities::Clear()
{
    DXFBasicEntity * ptmp;

    while (pFirst!=NULL) {
        ptmp=pFirst;
        pFirst=ptmp->pSucc;
        delete ptmp;
    }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
