Esempio n. 1
0
bool DRW_Class::parseDwg(DRW::Version version, dwgBuffer *buf, dwgBuffer *strBuf){
    DRW_DBG("\n***************************** parsing Class *********************************************\n");

    classNum = buf->getBitShort();
    DRW_DBG("Class number: "); DRW_DBG(classNum);
    proxyFlag = buf->getBitShort(); //in dwg specs says "version"

    appName = strBuf->getVariableText(version, false);
    className = strBuf->getVariableText(version, false);
    recName = strBuf->getVariableText(version, false);

    DRW_DBG("\napp name: "); DRW_DBG(appName.c_str());
    DRW_DBG("\nclass name: "); DRW_DBG(className.c_str());
    DRW_DBG("\ndxf rec name: "); DRW_DBG(recName.c_str());
    wasaProxyFlag = buf->getBit(); //in dwg says wasazombie
    entityFlag = buf->getBitShort();
    entityFlag = entityFlag == 0x1F2 ? 1: 0;

    DRW_DBG("\nProxy capabilities flag: "); DRW_DBG(proxyFlag);
    DRW_DBG(", proxy flag (280): "); DRW_DBG(wasaProxyFlag);
    DRW_DBG(", entity flag: "); DRW_DBGH(entityFlag);

    if (version > DRW::AC1015) {//2004+
        instanceCount = buf->getBitLong();
        DRW_DBG("\nInstance Count: "); DRW_DBG(instanceCount);
        duint32 dwgVersion = buf->getBitLong();
        DRW_DBG("\nDWG version: "); DRW_DBG(dwgVersion);
        DRW_DBG("\nmaintenance version: "); DRW_DBG(buf->getBitLong());
        DRW_DBG("\nunknown 1: "); DRW_DBG(buf->getBitLong());
        DRW_DBG("\nunknown 2: "); DRW_DBG(buf->getBitLong());
    }
    DRW_DBG("\n");
    toDwgType();
    return buf->isGood();
}
Esempio n. 2
0
//RLZ: TODO add check instead print
bool dwgReader::checkSentinel(dwgBuffer *buf, enum secEnum::DWGSection, bool start){
    DRW_UNUSED(start);
    for (int i=0; i<16;i++) {
        DRW_DBGH(buf->getRawChar8()); DRW_DBG(" ");
    }
    return true;
}
Esempio n. 3
0
bool dwgReader15::readDwgClasses(){
    DRW_DBG("\ndwgReader15::readDwgClasses\n");
    dwgSectionInfo si = sections[secEnum::CLASSES];
    if (si.Id<0)//not found, ends
        return false;
    if (!fileBuf->setPosition(si.address))
        return false;

    DRW_DBG("classes section sentinel= ");
	checkSentinel(fileBuf.get(), secEnum::CLASSES, true);

    duint32 size = fileBuf->getRawLong32();
    if (size != (si.size - 38)) {
        DRW_DBG("\nWARNING dwgReader15::readDwgClasses size are "); DRW_DBG(size);
        DRW_DBG(" and secSize - 38 are "); DRW_DBG(si.size - 38); DRW_DBG("\n");
	}
	std::vector<duint8> tmpByteStr(size);

	fileBuf->getBytes(tmpByteStr.data(), size);
	dwgBuffer buff(tmpByteStr.data(), size, &decoder);
    size--; //reduce 1 byte instead of check pos + bitPos
    while (size > buff.getPosition()) {
        DRW_Class *cl = new DRW_Class();
        cl->parseDwg(version, &buff, &buff);
        classesmap[cl->classNum] = cl;
    }
     DRW_DBG("\nCRC: "); DRW_DBGH(fileBuf->getRawShort16());
     DRW_DBG("\nclasses section end sentinel= ");
	 checkSentinel(fileBuf.get(), secEnum::CLASSES, false);
	 bool ret = buff.isGood();
     return ret;
}
Esempio n. 4
0
bool dwgR::testReader(){
    bool isOk = false;

    std::ifstream filestr;
    filestr.open (fileName.c_str(), std::ios_base::in | std::ios::binary);
    if (!filestr.is_open() || !filestr.good() ){
        error = DRW::BAD_OPEN;
        return isOk;
    }

    dwgBuffer fileBuf(&filestr);
    duint8 strdata[fileBuf.size()];
    fileBuf.getBytes(strdata, fileBuf.size());
    dwgBuffer dataBuf(strdata, fileBuf.size());
    fileBuf.setPosition(0);
    DRW_DBG("\ndwgR::testReader filebuf size: ");DRW_DBG(fileBuf.size());
    DRW_DBG("\ndwgR::testReader dataBuf size: ");DRW_DBG(dataBuf.size());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    fileBuf.setBitPos(4);
    dataBuf.setBitPos(4);
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    fileBuf.setBitPos(6);
    dataBuf.setBitPos(6);
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    fileBuf.setBitPos(0);
    dataBuf.setBitPos(0);
    DRW_DBG("\n filebuf first byte : ");DRW_DBGH(fileBuf.getRawChar8());
    DRW_DBG("\n dataBuf  first byte : ");DRW_DBGH(dataBuf.getRawChar8());
    DRW_DBG("\n filebuf pos: ");DRW_DBG(fileBuf.getPosition());
    DRW_DBG("\n dataBuf pos: ");DRW_DBG(dataBuf.getPosition());
    DRW_DBG("\n filebuf bitpos: ");DRW_DBG(fileBuf.getBitPos());
    DRW_DBG("\n dataBuf bitpos: ");DRW_DBG(dataBuf.getBitPos());


    filestr.close();
    DRW_DBG("\n\n");
    return isOk;
}
Esempio n. 5
0
/** Note: object map are split in sections with max size 2035?
 *  heach section are 2 bytes size + data bytes + 2 bytes crc
 *  size value are data bytes + 2 and to calculate crc are used
 *  2 bytes size + data bytes
 *  last section are 2 bytes size + 2 bytes crc (size value always 2)
**/
bool dwgReader::readDwgHandles(dwgBuffer *dbuf, duint32 offset, duint32 size) {
    DRW_DBG("\ndwgReader::readDwgHandles\n");
    if (!dbuf->setPosition(offset))
        return false;

    duint32 maxPos = offset + size;
    DRW_DBG("\nSection HANDLES offset= "); DRW_DBG(offset);
    DRW_DBG("\nSection HANDLES size= "); DRW_DBG(size);
    DRW_DBG("\nSection HANDLES maxPos= "); DRW_DBG(maxPos);

    int startPos = offset;

    while (maxPos > dbuf->getPosition()) {
        DRW_DBG("\nstart handles section buf->curPosition()= "); DRW_DBG(dbuf->getPosition()); DRW_DBG("\n");
        duint16 size = dbuf->getBERawShort16();
        DRW_DBG("object map section size= "); DRW_DBG(size); DRW_DBG("\n");
        dbuf->setPosition(startPos);
        duint8 *tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        if (size != 2){
            buff.setPosition(2);
            int lastHandle = 0;
            int lastLoc = 0;
            //read data
            while(buff.getPosition()< size){
                lastHandle += buff.getUModularChar();
                DRW_DBG("object map lastHandle= "); DRW_DBGH(lastHandle);
                lastLoc += buff.getModularChar();
                DRW_DBG(" lastLoc= "); DRW_DBG(lastLoc); DRW_DBG("\n");
                ObjectMap[lastHandle]= objHandle(0, lastHandle, lastLoc);
            }
        }
        //verify crc
        duint16 crcCalc = buff.crc8(0xc0c1,0,size);
        delete[]tmpByteStr;
        duint16 crcRead = dbuf->getBERawShort16();
        DRW_DBG("object map section crc8 read= "); DRW_DBG(crcRead);
        DRW_DBG("\nobject map section crc8 calculated= "); DRW_DBG(crcCalc);
        DRW_DBG("\nobject section buf->curPosition()= "); DRW_DBG(dbuf->getPosition()); DRW_DBG("\n");
        startPos = dbuf->getPosition();
    }

    bool ret = dbuf->isGood();
    return ret;
}
Esempio n. 6
0
bool dwgReader::readPlineVertex(DRW_Polyline& pline, dwgBuffer *dbuf){
    bool ret = true;
    bool ret2 = true;
    objHandle oc;
    duint32 bs = 0;
    std::map<duint32, objHandle>::iterator mit;

    if (version < DRW::AC1018) { //pre 2004
        duint32 nextH = pline.firstEH;
        while (nextH != 0){
            mit = ObjectMap.find(nextH);
            if (mit==ObjectMap.end()) {
                nextH = pline.lastEH;//end while if entity not foud
                DRW_DBG("\nWARNING: pline vertex not found\n");
                ret = false;
                continue;
            } else {//foud entity reads it
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_Vertex vt;
                dbuf->setPosition(oc.loc);
                //RLZ: verify if pos is ok
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) {//2010+
                    bs = dbuf->getUModularChar();
                }
                duint8 *tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                dint16 oType = buff.getObjType(version);
                buff.resetPosition();
                DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n");
                ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z);
                delete[]tmpByteStr;
                pline.addVertex(vt);
                nextEntLink = vt.nextEntLink; \
                prevEntLink = vt.prevEntLink;
                ret = ret && ret2;
            }
            if (nextH == pline.lastEH)
                nextH = 0; //redundant, but prevent read errors
            else
                nextH = nextEntLink;
        }
    } else {//2004+
        for (std::list<duint32>::iterator it = pline.hadlesList.begin() ; it != pline.hadlesList.end(); ++it){
            duint32 nextH = *it;
            mit = ObjectMap.find(nextH);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: Entity of block not found\n");
                ret = false;
                continue;
            } else {//foud entity reads it
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("\nPline vertex, parsing entity: "); DRW_DBGH(oc.handle); DRW_DBG(", pos: "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Vertex vt;
                dbuf->setPosition(oc.loc);
                //RLZ: verify if pos is ok
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) {//2010+
                    bs = dbuf->getUModularChar();
                }
                duint8 *tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                dint16 oType = buff.getObjType(version);
                buff.resetPosition();
                DRW_DBG(" object type= "); DRW_DBG(oType); DRW_DBG("\n");
                ret2 = vt.parseDwg(version, &buff, bs, pline.basePoint.z);
                delete[]tmpByteStr;
                pline.addVertex(vt);
                nextEntLink = vt.nextEntLink; \
                prevEntLink = vt.prevEntLink;
                ret = ret && ret2;
            }
        }
    }//end 2004+
    DRW_DBG("\nRemoved SEQEND entity: "); DRW_DBGH(pline.seqEndH.ref);DRW_DBG("\n");
    ObjectMap.erase(pline.seqEndH.ref);

    return ret;
}
Esempio n. 7
0
bool dwgReader::readDwgBlocks(DRW_Interface& intfa, dwgBuffer *dbuf){
    bool ret = true;
    bool ret2 = true;
    duint32 bs =0;
    duint8 *tmpByteStr;
    std::map<duint32, objHandle>::iterator mit;
    DRW_DBG("\nobject map total size= "); DRW_DBG(ObjectMap.size());

    for (std::map<duint32, DRW_Block_Record*>::iterator it=blockRecordmap.begin(); it != blockRecordmap.end(); ++it){
        DRW_Block_Record* bkr= it->second;
        DRW_DBG("\nParsing Block, record handle= "); DRW_DBGH(it->first); DRW_DBG(" Name= "); DRW_DBG(bkr->name); DRW_DBG("\n");
        DRW_DBG("\nFinding Block, handle= "); DRW_DBGH(bkr->block); DRW_DBG("\n");
        mit = ObjectMap.find(bkr->block);
        if (mit==ObjectMap.end()) {
            DRW_DBG("\nWARNING: block entity not found\n");
            ret = false;
            continue;
        }
        objHandle oc = mit->second;
        ObjectMap.erase(mit);
        DRW_DBG("Block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n");
        if ( !(dbuf->setPosition(oc.loc)) ){
            DRW_DBG("Bad Location reading blocks\n");
            ret = false;
            continue;
        }
        int size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        DRW_Block bk;
        ret2 = bk.parseDwg(version, &buff, bs);
        delete[]tmpByteStr;
        ret = ret && ret2;
        parseAttribs(&bk);
        //complete block entity with block record data
        bk.basePoint = bkr->basePoint;
        bk.flags = bkr->flags;
        intfa.addBlock(bk);
        //and update block record name
        bkr->name = bk.name;

        /**read & send block entities**/
        // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it (RLZ: only tested in 2000)
        if (bk.parentHandle == DRW::NoHandle) {
            // in dwg code 330 are not set like dxf in ModelSpace & PaperSpace, set it
            bk.parentHandle= bkr->handle;
            //and do not send block entities like dxf
        } else {
            if (version < DRW::AC1018) { //pre 2004
                duint32 nextH = bkr->firstEH;
                while (nextH != 0){
                    mit = ObjectMap.find(nextH);
                    if (mit==ObjectMap.end()) {
                        nextH = bkr->lastEH;//end while if entity not foud
                        DRW_DBG("\nWARNING: Entity of block not found\n");
                        ret = false;
                        continue;
                    } else {//foud entity reads it
                        oc = mit->second;
                        ObjectMap.erase(mit);
                        ret2 = readDwgEntity(dbuf, oc, intfa);
                        ret = ret && ret2;
                    }
                    if (nextH == bkr->lastEH)
                        nextH = 0; //redundant, but prevent read errors
                    else
                        nextH = nextEntLink;
                }
            } else {//2004+
                for (std::vector<duint32>::iterator it = bkr->entMap.begin() ; it != bkr->entMap.end(); ++it){
                    duint32 nextH = *it;
                    mit = ObjectMap.find(nextH);
                    if (mit==ObjectMap.end()) {
                        DRW_DBG("\nWARNING: Entity of block not found\n");
                        ret = false;
                        continue;
                    } else {//foud entity reads it
                        oc = mit->second;
                        ObjectMap.erase(mit);
                        DRW_DBG("\nBlocks, parsing entity: "); DRW_DBGH(oc.handle); DRW_DBG(", pos: "); DRW_DBG(oc.loc); DRW_DBG("\n");
                        ret2 = readDwgEntity(dbuf, oc, intfa);
                        ret = ret && ret2;
                    }
                }
            }//end 2004+
        }

        //end block entity, really needed to parse a dummy entity??
        mit = ObjectMap.find(bkr->endBlock);
        if (mit==ObjectMap.end()) {
            DRW_DBG("\nWARNING: end block entity not found\n");
            ret = false;
            continue;
        }
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_DBG("End block Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" Location: "); DRW_DBG(oc.loc); DRW_DBG("\n");
        dbuf->setPosition(oc.loc);
        size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff1(tmpByteStr, size, &decoder);
        DRW_Block end;
        end.isEnd = true;
        ret2 = end.parseDwg(version, &buff1, bs);
        delete[]tmpByteStr;
        ret = ret && ret2;
        if (bk.parentHandle == DRW::NoHandle) bk.parentHandle= bkr->handle;
        parseAttribs(&end);
        intfa.endBlock();
    }

    return ret;
}
Esempio n. 8
0
/**
 * Reads all the object referenced in the object map section of the DWG file
 * (using their object file offsets)
 */
bool dwgReader::readDwgTables(DRW_Header& hdr, dwgBuffer *dbuf) {
    DRW_DBG("\ndwgReader::readDwgTables start\n");
    bool ret = true;
    bool ret2 = true;
    objHandle oc;
    std::map<duint32, objHandle>::iterator mit;
    dint16 oType;
    duint32 bs = 0; //bit size of handle stream 2010+
    duint8 *tmpByteStr;

    //parse linetypes, start with linetype Control
    mit = ObjectMap.find(hdr.linetypeCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: LineType control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing LineType control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl ltControl;
        dbuf->setPosition(oc.loc);
        int csize = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[csize];
        dbuf->getBytes(tmpByteStr, csize);
        dwgBuffer cbuff(tmpByteStr, csize, &decoder);
        //verify if object are correct
        oType = cbuff.getObjType(version);
        if (oType != 0x38) {
                DRW_DBG("\nWARNING: Not LineType control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x38\n");
                ret = false;
            } else { //reset position
            cbuff.resetPosition();
            ret2 = ltControl.parseDwg(version, &cbuff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=ltControl.hadlesList.begin(); it != ltControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: LineType not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("\nLineType Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" loc.: "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_LType *lt = new DRW_LType();
                dbuf->setPosition(oc.loc);
                int lsize = dbuf->getModularShort();
                DRW_DBG("LineType size in bytes= "); DRW_DBG(lsize);
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[lsize];
                dbuf->getBytes(tmpByteStr, lsize);
                dwgBuffer lbuff(tmpByteStr, lsize, &decoder);
                ret2 = lt->parseDwg(version, &lbuff, bs);
                ltypemap[lt->handle] = lt;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //parse layers, start with layer Control
    mit = ObjectMap.find(hdr.layerCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: Layer control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing Layer control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl layControl;
        dbuf->setPosition(oc.loc);
        int size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x32) {
                DRW_DBG("\nWARNING: Not Layer control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x32\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = layControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=layControl.hadlesList.begin(); it != layControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: Layer not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("Layer Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Layer *la = new DRW_Layer();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = la->parseDwg(version, &buff, bs);
                layermap[la->handle] = la;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //set linetype in layer
    for (std::map<duint32, DRW_Layer*>::iterator it=layermap.begin(); it!=layermap.end(); ++it) {
        DRW_Layer *ly = it->second;
        duint32 ref =ly->lTypeH.ref;
        std::map<duint32, DRW_LType*>::iterator lt_it = ltypemap.find(ref);
        if (lt_it != ltypemap.end()){
            ly->lineType = (lt_it->second)->name;
        }
    }

    //parse text styles, start with style Control
    mit = ObjectMap.find(hdr.styleCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: Style control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing Style control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl styControl;
        dbuf->setPosition(oc.loc);
        int size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x34) {
                DRW_DBG("\nWARNING: Not Text Style control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x34\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = styControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=styControl.hadlesList.begin(); it != styControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: Style not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("Style Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Textstyle *sty = new DRW_Textstyle();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = sty->parseDwg(version, &buff, bs);
                stylemap[sty->handle] = sty;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //parse dim styles, start with dimstyle Control
    mit = ObjectMap.find(hdr.dimstyleCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: Dimension Style control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing Dimension Style control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl dimstyControl;
        dbuf->setPosition(oc.loc);
        duint32 size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x44) {
                DRW_DBG("\nWARNING: Not Dim Style control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x44\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = dimstyControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=dimstyControl.hadlesList.begin(); it != dimstyControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: Dimension Style not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("Dimstyle Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Dimstyle *sty = new DRW_Dimstyle();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = sty->parseDwg(version, &buff, bs);
                dimstylemap[sty->handle] = sty;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //parse vports, start with vports Control
    mit = ObjectMap.find(hdr.vportCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: vports control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing vports control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl vportControl;
        dbuf->setPosition(oc.loc);
        int size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x40) {
                DRW_DBG("\nWARNING: Not VPorts control object, found oType: ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x40\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = vportControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=vportControl.hadlesList.begin(); it != vportControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: vport not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("Vport Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Vport *vp = new DRW_Vport();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = vp->parseDwg(version, &buff, bs);
                vportmap[vp->handle] = vp;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //parse Block_records , start with Block_record Control
    mit = ObjectMap.find(hdr.blockCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: Block_record control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing Block_record control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_ObjControl blockControl;
        dbuf->setPosition(oc.loc);
        int csize = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[csize];
        dbuf->getBytes(tmpByteStr, csize);
        dwgBuffer buff(tmpByteStr, csize, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x30) {
                DRW_DBG("\nWARNING: Not Block Record control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x30\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = blockControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=blockControl.hadlesList.begin(); it != blockControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: block record not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("block record Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_Block_Record *br = new DRW_Block_Record();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = br->parseDwg(version, &buff, bs);
                blockRecordmap[br->handle] = br;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //parse appId , start with appId Control
    mit = ObjectMap.find(hdr.appidCtrl);
    if (mit==ObjectMap.end()) {
        DRW_DBG("\nWARNING: AppId control not found\n");
        ret = false;
    } else {
        DRW_DBG("\n**********Parsing AppId control*******\n");
        oc = mit->second;
        ObjectMap.erase(mit);
        DRW_DBG("AppId Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
        DRW_ObjControl appIdControl;
        dbuf->setPosition(oc.loc);
        int size = dbuf->getModularShort();
        if (version > DRW::AC1021) //2010+
            bs = dbuf->getUModularChar();
        else
            bs = 0;
        tmpByteStr = new duint8[size];
        dbuf->getBytes(tmpByteStr, size);
        dwgBuffer buff(tmpByteStr, size, &decoder);
        //verify if object are correct
        oType = buff.getObjType(version);
        if (oType != 0x42) {
                DRW_DBG("\nWARNING: Not AppId control object, found oType ");
                DRW_DBG(oType);  DRW_DBG(" instead 0x42\n");
                ret = false;
            } else { //reset position
            buff.resetPosition();
            ret2 = appIdControl.parseDwg(version, &buff, bs);
            if(ret)
                ret = ret2;
        }
        delete[]tmpByteStr;
        for (std::list<duint32>::iterator it=appIdControl.hadlesList.begin(); it != appIdControl.hadlesList.end(); ++it){
            mit = ObjectMap.find(*it);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: AppId not found\n");
                ret = false;
            } else {
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("AppId Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_AppId *ai = new DRW_AppId();
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                ret2 = ai->parseDwg(version, &buff, bs);
                appIdmap[ai->handle] = ai;
                if(ret)
                    ret = ret2;
                delete[]tmpByteStr;
            }
        }
    }

    //RLZ: parse remaining object controls, TODO: implement all
    if (DRW_DBGGL == DRW_dbg::DEBUG){
        mit = ObjectMap.find(hdr.viewCtrl);
        if (mit==ObjectMap.end()) {
            DRW_DBG("\nWARNING: View control not found\n");
            ret = false;
        } else {
            DRW_DBG("\n**********Parsing View control*******\n");
            oc = mit->second;
            ObjectMap.erase(mit);
            DRW_DBG("View Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
            DRW_ObjControl viewControl;
            dbuf->setPosition(oc.loc);
            int size = dbuf->getModularShort();
            if (version > DRW::AC1021) //2010+
                bs = dbuf->getUModularChar();
            else
                bs = 0;
            tmpByteStr = new duint8[size];
            dbuf->getBytes(tmpByteStr, size);
            dwgBuffer buff(tmpByteStr, size, &decoder);
            //verify if object are correct
            oType = buff.getObjType(version);
            if (oType != 0x3C) {
                    DRW_DBG("\nWARNING: Not View control object, found oType ");
                    DRW_DBG(oType);  DRW_DBG(" instead 0x3C\n");
                    ret = false;
                } else { //reset position
                buff.resetPosition();
                ret2 = viewControl.parseDwg(version, &buff, bs);
                if(ret)
                    ret = ret2;
            }
            delete[]tmpByteStr;
        }

        mit = ObjectMap.find(hdr.ucsCtrl);
        if (mit==ObjectMap.end()) {
            DRW_DBG("\nWARNING: Ucs control not found\n");
            ret = false;
        } else {
            oc = mit->second;
            ObjectMap.erase(mit);
            DRW_DBG("\n**********Parsing Ucs control*******\n");
            DRW_DBG("Ucs Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
            DRW_ObjControl ucsControl;
            dbuf->setPosition(oc.loc);
            int size = dbuf->getModularShort();
            if (version > DRW::AC1021) //2010+
                bs = dbuf->getUModularChar();
            else
                bs = 0;
            tmpByteStr = new duint8[size];
            dbuf->getBytes(tmpByteStr, size);
            dwgBuffer buff(tmpByteStr, size, &decoder);
            //verify if object are correct
            oType = buff.getObjType(version);
            if (oType != 0x3E) {
                    DRW_DBG("\nWARNING: Not Ucs control object, found oType ");
                    DRW_DBG(oType);  DRW_DBG(" instead 0x3E\n");
                    ret = false;
                } else { //reset position
                buff.resetPosition();
                ret2 = ucsControl.parseDwg(version, &buff, bs);
                if(ret)
                    ret = ret2;
            }
            delete[]tmpByteStr;
        }

        if (version < DRW::AC1018) {//r2000-
            mit = ObjectMap.find(hdr.vpEntHeaderCtrl);
            if (mit==ObjectMap.end()) {
                DRW_DBG("\nWARNING: vpEntHeader control not found\n");
                ret = false;
            } else {
                DRW_DBG("\n**********Parsing vpEntHeader control*******\n");
                oc = mit->second;
                ObjectMap.erase(mit);
                DRW_DBG("vpEntHeader Control Obj Handle= "); DRW_DBGH(oc.handle); DRW_DBG(" "); DRW_DBG(oc.loc); DRW_DBG("\n");
                DRW_ObjControl vpEntHeaderCtrl;
                dbuf->setPosition(oc.loc);
                int size = dbuf->getModularShort();
                if (version > DRW::AC1021) //2010+
                    bs = dbuf->getUModularChar();
                else
                    bs = 0;
                tmpByteStr = new duint8[size];
                dbuf->getBytes(tmpByteStr, size);
                dwgBuffer buff(tmpByteStr, size, &decoder);
                //verify if object are correct
                oType = buff.getObjType(version);
                if (oType != 0x46) {
                        DRW_DBG("\nWARNING: Not vpEntHeader control object, found oType ");
                        DRW_DBG(oType);  DRW_DBG(" instead 0x46\n");
                        ret = false;
                    } else { //reset position
                    buff.resetPosition();
/* RLZ: writeme                   ret2 = vpEntHeader.parseDwg(version, &buff, bs);
                    if(ret)
                        ret = ret2;*/
                }
                delete[]tmpByteStr;
            }
        }
    }

    return ret;
}