/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include "DgnImportImpl.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "DgnImportLS.h" #include "DbSymUtl.h" #include #include #include #include #include #include "DgnImportCommon.h" #include "DgnImportContext.h" #include "DgnImportPE.h" #include #include "DgMultilineStyleTableRecord.h" #include #include "Gi/GiMaterial.h" #include "DgDisplayStyle.h" #include #include #include #include #include "DgGeoData.h" #include #include #include #include #include namespace TD_DGN_IMPORT { // From DgnImportElements.cpp OdDb::LineWeight odDgnImportLineweightMapping(OdUInt32 mappingVal); void DgnImporter::copyLayerProperties(OdDgLevelTableRecord* l, OdDbLayerTableRecord* l_d) { l_d->setLineWeight(odDgnImportLineweightMapping(l->getElementLineWeight())); { OdUInt32 entryId = l->getElementLineStyleEntryId(); if (entryId < 8 && entryId >= 0) { // internal if (entryId == 0) l_d->setLinetypeObjectId(l_d->database()->getLinetypeContinuousId()); else { l_d->setLinetypeObjectId(OdDbLinetypeTable::cast(l_d->database()->getLinetypeTableId().openObject())->getAt(OdString().format(OD_T("DGN%u"), entryId))); OdDbObjectId idInternalLS = l_d->linetypeObjectId(); if (!idInternalLS.isNull()) OdDgnImportContext::setResourceUsage(idInternalLS, true); } } else if (entryId == OdDg::kLineStyleByLevel) l_d->setLinetypeObjectId(l_d->database()->getLinetypeByLayerId()); else if (entryId == OdDg::kLineStyleByCell) l_d->setLinetypeObjectId(l_d->database()->getLinetypeByBlockId()); else { OdDgElementId idLineStyle = l->database()->getLineStyleTable()->getAt(l->getElementLineStyleEntryId()); OdDgnImportPathToDwgObject dwgPath = _idMap[idLineStyle]; if( dwgPath.m_idPath.objectIds().isEmpty() && l_d->database()) { OdDgLineStyleTableRecordPtr pDgnLineStyle = idLineStyle.openObject(OdDg::kForRead); if (!pDgnLineStyle.isNull()) { OdDbLinetypeTablePtr pDwgLSTable = l_d->database()->getLinetypeTableId().openObject(OdDb::kForRead); if (!pDwgLSTable.isNull()) { OdDbObjectId ltpId = pDwgLSTable->getAt(pDgnLineStyle->getName()); if (!ltpId.isNull()) dwgPath.m_idPath.objectIds().push_back(ltpId); } } } if( !dwgPath.m_idPath.objectIds().isEmpty() ) { setResourceUsage(dwgPath.m_idPath.objectIds()[0]); l_d->setLinetypeObjectId( dwgPath.m_idPath.objectIds()[0] ); if (!dwgPath.m_idPath.objectIds()[0].isNull()) OdDgnImportContext::setResourceUsage(dwgPath.m_idPath.objectIds()[0], true); } else l_d->setLinetypeObjectId( 0 ); } } l_d->setIsFrozen(l->getIsFrozenFlag()); l_d->setIsOff(!l->getIsDisplayedFlag()); l_d->setIsLocked( l->getElementAccess() == OdDgLevelTableRecord::kAccessLocked ); l_d->setIsPlottable(l->getIsPlotFlag()); OdUInt32 color = l->getElementColorIndex(); ODCOLORREF c = OdDgColorTable::lookupRGB(l->database(), color); bool bSetTrueColor = true; if( color < 256 && !OdDgnImportContext::getConvertColorIndexToTrueColorFlag() ) { OdDgnImportColorIndexDescription dwgColor; if( OdDgnImportContext::getDwgColor( color, dwgColor ) ) { if( !dwgColor.m_bUseTrueColor ) { bSetTrueColor = false; l_d->setColorIndex(dwgColor.m_uDwgColorIndex); } } } if( bSetTrueColor ) { OdCmColor cc; cc.setRGB(ODGETRED(c), ODGETGREEN(c), ODGETBLUE(c)); l_d->setColor(cc); } OdCmTransparency transparency = l->getTransparency(); if( transparency.alphaPercent() != 0 ) { l_d->setTransparency( transparency ); } l_d->setDescription(l->getDescription()); if( !l->getByLevelMaterial().isNull() ) l_d->setMaterialId( OdDgnImportContext::getObjectId(l->getByLevelMaterial()) ); } void convertDgnTextureMappingToDwgTextureMapping( OdGiMaterialMap& matMapping ) { if( matMapping.source() == OdGiMaterialMap::kFile ) { OdGiMapper& texMapper = matMapping.mapper(); if( texMapper.projection() == OdGiMapper::kDgnParametric || texMapper.projection() == OdGiMapper::kDgnPlanar ) { texMapper.setProjection( OdGiMapper::kPlanar ); matMapping.setMapper( texMapper ); } else if( texMapper.projection() == OdGiMapper::kDgnSphere ) { texMapper.setProjection( OdGiMapper::kSphere ); matMapping.setMapper( texMapper ); } else if( texMapper.projection() == OdGiMapper::kDgnCylinder || texMapper.projection() == OdGiMapper::kDgnCylinderCapped ) { texMapper.setProjection( OdGiMapper::kCylinder ); matMapping.setMapper( texMapper ); } } } bool DgnImporter::copyMaterialProperties( const OdDgMaterialTableRecordPtr& pDgMaterial, OdDbMaterialPtr& pDbMaterial, const OdDbDictionaryPtr& pMatDictionary ) { if( pDgMaterial.isNull() || pDbMaterial.isNull() || pMatDictionary.isNull() ) { return false; } // Material name OdString strMaterialName = pDgMaterial->getName(); if( strMaterialName.isEmpty() ) { OdUInt32 uIndexMat = 1; do { strMaterialName.format(L"DgnMaterial_%d",uIndexMat); uIndexMat++; } while( pMatDictionary->has(strMaterialName) ); } else if( pMatDictionary->has( strMaterialName ) ) { OdUInt32 uIndexMat = 1; OdString strMaterialNameBase = strMaterialName; do { strMaterialName.format(L"_%d",uIndexMat); strMaterialName = strMaterialNameBase + strMaterialName; uIndexMat++; } while( pMatDictionary->has(strMaterialName) ); } OdString repairedName; if( (OdDbSymUtil::repairSymbolName(repairedName, strMaterialName, pMatDictionary->database()) == eOk) && !repairedName.isEmpty() ) { strMaterialName = repairedName; } pDbMaterial->setName( strMaterialName ); // Information about palette if( !pDgMaterial->getPaletteName().isEmpty() ) { pDbMaterial->setDescription(L"Material Palette:" + pDgMaterial->getPaletteName() ); } // Ambient color OdGiMaterialColor clrAmbient; pDgMaterial->getAmbient( clrAmbient ); pDbMaterial->setAmbient( clrAmbient ); // Diffuse color OdGiMaterialColor clrDiffuse; OdDgMaterialMap mapDiffuse; OdGiMaterialMap mapGiDiffuse; pDgMaterial->getDiffuse( clrDiffuse, mapDiffuse ); mapDiffuse.getGiMaterialMap( mapGiDiffuse ); if( mapGiDiffuse.source() == OdGiMaterialMap::kFile && mapGiDiffuse.sourceFileName().isEmpty() ) { mapGiDiffuse.setSource( OdGiMaterialMap::kScene ); } convertDgnTextureMappingToDwgTextureMapping(mapGiDiffuse); pDbMaterial->setDiffuse( clrDiffuse, mapGiDiffuse); // Specular color OdGiMaterialColor clrSpecular; double dGlossFactor; OdGiMaterialMap mapSpecular; mapSpecular.setSource( OdGiMaterialMap::kScene); pDgMaterial->getSpecular( clrSpecular, dGlossFactor ); pDbMaterial->setSpecular( clrSpecular, mapSpecular, dGlossFactor ); // Reflection OdGiMaterialMap mapReflection; pDgMaterial->getReflection( mapReflection ); pDbMaterial->setReflection( mapReflection ); pDbMaterial->setReflectanceScale( 1.0 ); // Opacity OdGiMaterialMap mapOpacity; pDbMaterial->setOpacity( pDgMaterial->getOpacity(), mapOpacity ); // Refraction OdGiMaterialMap mapRefraction; pDbMaterial->setRefraction( pDgMaterial->getRefraction(), mapRefraction ); // Translucence pDbMaterial->setTranslucence( pDgMaterial->getTranslucence() ); // Luminance pDbMaterial->setShininess( pDgMaterial->getShininess() ); // Bump OdDgMaterialMap mapBump; OdGiMaterialMap mapGiBump; pDgMaterial->getBump( mapBump ); mapBump.getGiMaterialMap( mapGiBump ); convertDgnTextureMappingToDwgTextureMapping(mapGiBump); if( mapGiBump.source() == OdGiMaterialMap::kFile && mapGiBump.sourceFileName().isEmpty() ) { mapGiBump.setSource( OdGiMaterialMap::kScene ); } pDbMaterial->setBump(mapGiBump); // Global illumination. pDbMaterial->setGlobalIllumination( pDgMaterial->getGlobalIlluminationFlag() ? OdGiMaterialTraits::kGlobalIlluminationCastAndReceive : OdGiMaterialTraits::kGlobalIlluminationNone); // Two sided. pDbMaterial->setTwoSided( true ); return true; } void DgnImporter::copyMaterials(OdDgDatabase* pDg, OdDbDatabase* pDb ) { OdDgMaterialTablePtr pDgnMaterialTable = pDg->getMaterialTable(OdDg::kForRead); OdDbObjectId idMatDictionary = pDb->getMaterialDictionaryId(); if( idMatDictionary.isNull() || pDgnMaterialTable.isNull() ) { ODA_FAIL_ONCE(); return; } OdDbDictionaryPtr pDbMatDictionary = idMatDictionary.openObject(OdDb::kForWrite); OdDgElementIteratorPtr pMatTableIter = pDgnMaterialTable->createIterator(); for(; !pMatTableIter->done(); pMatTableIter->step() ) { OdDgMaterialTableRecordPtr pDgMaterial = pMatTableIter->item().openObject(OdDg::kForRead); OdDbMaterialPtr pDbMaterial = OdDbMaterial::createObject(); if( copyMaterialProperties( pDgMaterial, pDbMaterial, pDbMatDictionary ) ) { pDbMatDictionary->setAt( pDbMaterial->name(), pDbMaterial ); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pDbMaterial->objectId()); _idMap[pDgMaterial->elementId()] = dwgPath; addResourceId(pDbMaterial->objectId()); } } } void DgnImporter::copyLayers(const OdDgLevelTable* src, OdDbDatabase* dst, bool bRenameLayers, const OdString& strFilename) { OdDgLevelTablePtr lt = src; for (OdDgElementIteratorPtr i = lt->createIterator(); !i->done(); i->step()) { OdDgLevelTableRecordPtr l = i->item().safeOpenObject(); OdString name = l->getName(); if (name.isEmpty()) continue; if (name.iCompare(L"default") == 0) name = L"0"; else { OdString strNameLow = name; strNameLow.makeLower(); OdString strDefPointsName = OdDbSymUtil::layerDefpointsName(); strDefPointsName.makeLower(); if (strNameLow == strDefPointsName) name = L"DGN_" + name; } OdString repairedName; if (OdDbSymUtil::repairSymbolName(repairedName, name, dst) == eOk && !repairedName.isEmpty()) name = repairedName; OdDbLayerTablePtr lt_d = dst->getLayerTableId().safeOpenObject(OdDb::kForWrite); OdDbObjectId l_d_id = lt_d->getAt(name); if( bRenameLayers ) { if( !l_d_id.isNull() ) { OdString strXRefName = strFilename; strXRefName.replace(L'\\', L'/'); if (strXRefName.reverseFind(L'/') != -1) strXRefName = strXRefName.right(strXRefName.getLength() - strXRefName.reverseFind(L'/') - 1); if (strXRefName.find(L".") != -1) strXRefName = strXRefName.left(strXRefName.find(L".")); name = strXRefName + L"_" + name; OdString repairedName; if( OdDbSymUtil::repairSymbolName(repairedName, name, dst) == eOk && !repairedName.isEmpty() ) name = repairedName; l_d_id = lt_d->getAt(name); } OdString strNameBase = name; OdUInt32 uCount = 1; while( !l_d_id.isNull() ) { name.format(L"_%d", uCount ); name = strNameBase + name; l_d_id = lt_d->getAt(name); uCount++; } } if (l_d_id.isNull()) { OdDbLayerTableRecordPtr l_d = OdDbLayerTableRecord::createObject(); l_d->setName(name); dst->addOdDbObject(l_d, lt_d->objectId()); l_d_id = lt_d->add(l_d); } OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(l_d_id); _idMap[l->elementId()] = dwgPath; addResourceId(l_d_id); OdDbLayerTableRecordPtr l_d = l_d_id.safeOpenObject(OdDb::kForWrite); copyLayerProperties(l, l_d); } } OdDbObjectId DgnImporter::getObjectId( const OdDgElementId& idDgnElement ) const { OdDbObjectId retVal; IdMap::const_iterator pIter = _idMap.find( idDgnElement ); if( pIter != _idMap.end() ) { if( pIter->second.m_bExists ) { OdDbObjectIdArray arrPath = pIter->second.m_idPath.objectIds(); retVal = arrPath[arrPath.size() - 1]; } } return retVal; } bool DgnImporter::getObjectPath( const OdDgElementId& idDgnElement, OdDgnImportPathToDwgObject& dwgPath ) { bool bRet = false; IdMap::const_iterator pIter = _idMap.find( idDgnElement ); if( pIter != _idMap.end() ) { dwgPath = pIter->second; bRet = true; } return bRet; } void DgnImporter::addObjectPath( const OdDgElementId& idDgnElement, const OdDgnImportPathToDwgObject& dwgPath ) { _idMap[idDgnElement] = dwgPath; } void DgnImporter::pushIdMap() { m_arrIdMapStack.push_back( _idMap ); _idMap.clear(); } void DgnImporter::popIdMap() { if( m_arrIdMapStack.size() > 0 ) { _idMap = m_arrIdMapStack.last(); m_arrIdMapStack.removeLast(); } } void DgnImporter::pushResourcesByFileName(OdDgDatabase* pCurDb, const OdDgLevelTable* pCurLevelTable) { OdString strFileName = pCurDb->getFilename(); std::map::iterator pIter = m_mapFileNameResourceIds.find(strFileName); if(pIter == m_mapFileNameResourceIds.end()) { OdDgFileResourceDescriptor curDesc; // Text styles OdDgTextStyleTablePtr pTextStyleTable = pCurDb->getTextStyleTable(OdDg::kForRead); OdDgElementIteratorPtr pTextStyleIter = pTextStyleTable->createIterator(); for(; !pTextStyleIter->done(); pTextStyleIter->step()) { OdDgTextStyleTableRecordPtr pTextStyle = pTextStyleIter->item().openObject(OdDg::kForRead, true); OdDbObjectId idDwgTextStyle = OdDgnImportContext::getObjectId(pTextStyle->elementId()); curDesc.m_mapTextStyleNameToId[pTextStyle->getName()] = idDwgTextStyle; } // Layers OdDgLevelTablePtr pLevelTable = pCurLevelTable; if( pLevelTable.isNull() ) pCurLevelTable = pCurDb->getLevelTable(OdDg::kForRead); OdDgElementIteratorPtr pLevelIter = pLevelTable->createIterator(); for (; !pLevelIter->done(); pLevelIter->step()) { OdDgLevelTableRecordPtr pLevel = pLevelIter->item().openObject(OdDg::kForRead, true); OdDbObjectId idDwgLevel = OdDgnImportContext::getObjectId(pLevel->elementId()); curDesc.m_mapLevelNameToId[pLevel->getName()] = idDwgLevel; } // Line Styles OdDgLineStyleTablePtr pLineStyleTable = pCurDb->getLineStyleTable(OdDg::kForRead); OdDgElementIteratorPtr pLineStyleIter = pLineStyleTable->createIterator(); for (; !pLineStyleIter->done(); pLineStyleIter->step()) { OdDgLineStyleTableRecordPtr pLineStyle = pLineStyleIter->item().openObject(OdDg::kForRead, true); OdDbObjectId idDwgLineStyle = OdDgnImportContext::getObjectId(pLineStyle->elementId()); curDesc.m_mapLineStyleNameToId[pLineStyle->getName()] = idDwgLineStyle; } // Blocks OdDgSharedCellDefinitionTablePtr pBlockDefTable = pCurDb->getSharedCellDefinitionTable(OdDg::kForRead); OdDgElementIteratorPtr pBlockDefIter = pBlockDefTable->createIterator(); OdUInt32 uIndex = 0; for (; !pBlockDefIter->done(); pBlockDefIter->step()) { OdDbObjectId idDwgBlock = OdDgnImportContext::getObjectId(pBlockDefIter->item()); curDesc.m_mapSharedCellDefinitionToId[uIndex] = idDwgBlock; uIndex++; } // m_mapFileNameResourceIds[strFileName] = curDesc; } } bool DgnImporter::popResourcesByFilename(OdDgDatabase* pCurDb, const OdDgLevelTable* pCurLevelTable, bool bUpdateLayers) { bool bRet = false; OdString strFileName = pCurDb->getFilename(); std::map::iterator pIter = m_mapFileNameResourceIds.find(strFileName); if (pIter != m_mapFileNameResourceIds.end()) { bRet = true; OdDgFileResourceDescriptor curDesc = pIter->second; // Text styles OdDgTextStyleTablePtr pTextStyleTable = pCurDb->getTextStyleTable(OdDg::kForRead); OdDgElementIteratorPtr pTextStyleIter = pTextStyleTable->createIterator(); for (; !pTextStyleIter->done(); pTextStyleIter->step()) { OdDgTextStyleTableRecordPtr pTextStyle = pTextStyleIter->item().openObject(OdDg::kForRead, true); std::map::iterator pIdIter = curDesc.m_mapTextStyleNameToId.find(pTextStyle->getName()); if( pIdIter != curDesc.m_mapTextStyleNameToId.end() ) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pIdIter->second); _idMap[pTextStyle->elementId()] = dwgPath; } } // Layers if (bUpdateLayers) { OdDgLevelTablePtr pLevelTable = pCurLevelTable; if (pLevelTable.isNull()) pCurLevelTable = pCurDb->getLevelTable(OdDg::kForRead); OdDgElementIteratorPtr pLevelIter = pLevelTable->createIterator(); for (; !pLevelIter->done(); pLevelIter->step()) { OdDgLevelTableRecordPtr pLevel = pLevelIter->item().openObject(OdDg::kForRead, true); std::map::iterator pIdIter = curDesc.m_mapLevelNameToId.find(pLevel->getName()); if (pIdIter != curDesc.m_mapLevelNameToId.end()) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pIdIter->second); _idMap[pLevel->elementId()] = dwgPath; } } } // Line Styles OdDgLineStyleTablePtr pLineStyleTable = pCurDb->getLineStyleTable(OdDg::kForRead); OdDgElementIteratorPtr pLineStyleIter = pLineStyleTable->createIterator(); for (; !pLineStyleIter->done(); pLineStyleIter->step()) { OdDgLineStyleTableRecordPtr pLineStyle = pLineStyleIter->item().openObject(OdDg::kForRead, true); std::map::iterator pIdIter = curDesc.m_mapLineStyleNameToId.find(pLineStyle->getName()); if (pIdIter != curDesc.m_mapLineStyleNameToId.end()) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pIdIter->second); _idMap[pLineStyle->elementId()] = dwgPath; } } // Blocks OdDgSharedCellDefinitionTablePtr pBlockDefTable = pCurDb->getSharedCellDefinitionTable(OdDg::kForRead); OdDgElementIteratorPtr pBlockDefIter = pBlockDefTable->createIterator(); OdUInt32 uIndex = 0; for (; !pBlockDefIter->done(); pBlockDefIter->step()) { std::map::iterator pIdIter = curDesc.m_mapSharedCellDefinitionToId.find(uIndex); if (pIdIter != curDesc.m_mapSharedCellDefinitionToId.end()) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pIdIter->second); _idMap[pBlockDefIter->item()] = dwgPath; } uIndex++; } } return bRet; } void DgnImporter::clearFileResources() { m_mapFileNameResourceIds.clear(); } void DgnImporter::addResourceId( const OdDbObjectId& idResource, bool bAddWithoutConditions ) { if( (bAddWithoutConditions || _properties->get_EraseUnusedResources()) && !idResource.isNull() ) { IdResourceUsage::iterator pIter = _dwgResourceUsage.find(idResource); if( pIter == _dwgResourceUsage.end() ) _dwgResourceUsage[idResource] = false; } } void DgnImporter::setResourceUsage( const OdDbObjectId& idResource, bool bAddWithoutConditions ) { if( (bAddWithoutConditions || _properties->get_EraseUnusedResources()) && !idResource.isNull() ) { IdResourceUsage::iterator pIter = _dwgResourceUsage.find(idResource); if( pIter != _dwgResourceUsage.end() ) _dwgResourceUsage[idResource] = true; } } void DgnImporter::removeUnusedResources() { if( _properties->get_EraseUnusedResources() ) { IdResourceUsage::iterator pIter = _dwgResourceUsage.begin(); for(; pIter != _dwgResourceUsage.end(); pIter++ ) { if( !pIter->second ) { OdDbObjectPtr pObj = pIter->first.openObject(OdDb::kForWrite); pObj->erase(true); } } } } void DgnImporter::removeUnusedDgnInternalLineStyles( OdDbDatabase* pDb ) { OdDbLinetypeTablePtr pLineTypeTable = pDb->getLinetypeTableId().openObject(OdDb::kForWrite); for( OdUInt32 i = 1; i < 8; i++ ) { OdString strInternalLineStyleName; strInternalLineStyleName.format(L"DGN%d", i); OdDbObjectId idLineType = pLineTypeTable->getAt(strInternalLineStyleName); if( !idLineType.isNull() ) { IdResourceUsage::iterator pIter = _dwgResourceUsage.find(idLineType); if( pIter != _dwgResourceUsage.end() && !pIter->second) { OdDbObjectPtr pObj = pIter->first.openObject(OdDb::kForWrite); pObj->erase(true); } } } } OdDbObjectId DgnImporter::getDgnContinuousLineStyle() const { return m_idDgnContinuous; } void DgnImporter::setDgnContinuousLineStyle(const OdDbObjectId& idDgnContinuous) { m_idDgnContinuous = idDgnContinuous; } bool isContinuousDgnStyle(const OdDgLineStyleTableRecord* ls) { bool bRet = true; if (!ls) return bRet; OdDgLineStyleDefTableRecordPtr pLsDef; if (ls->getRefersToElementFlag()) { OdDgElementId lsDefId = ls->getRefersToId(); pLsDef = OdDgLineStyleDefTableRecord::cast(lsDefId.openObject()); } else // from RSC { OdDgLineStyleDefTablePtr pLineStyleDef = ls->database()->getLineStyleDefTable(); pLsDef = pLineStyleDef->getRscLineStyleDef(ls->getName()); } if( pLsDef.isNull() || pLsDef->getResource().isNull() ) return bRet; if( pLsDef->getType() != OdDg::kLsTypeLineCode ) bRet = false; else { OdDgLineCodeResourcePtr pRes = pLsDef->getResource(); if( pRes->getStrokeCount() > 1 ) bRet = false; else if (pRes->getStrokeCount() == 1) { OdDgLineCodeResourceStrokeData firstData; pRes->getStroke(0, firstData); if (!firstData.getDashFlag()) return false; } } return bRet; } void DgnImporter::copyLineStyles(OdDgDatabase* src, OdDbDatabase* dst) { DgnLSImporter lsImporter(src, dst); OdDgLineStyleTablePtr lst = src->getLineStyleTable(); { // Import defaults for (OdUInt32 nDef = 0; nDef < 8; nDef++) { OdDgLineStyleTableRecordPtr ls = lst->getAt(nDef).safeOpenObject(); OdDbLinetypeTableRecordPtr lt_d = lsImporter.copyLinetype(ls); if( !lt_d.isNull() ) addResourceId(lt_d->id(), true); //OdDbLinetypeTableRecordPtr lt_d = lsImporter.copyLinetype(ls); // DGNImportDuplicates_9896_VK // Internal linestyles haven't id's. Them must be searched by entryId. //if (lt_d.isNull()) // _idMap[ls->id()] = dst->getLinetypeContinuousId(); //else // _idMap[ls->id()] = lt_d->id(); } } // OdDbObjectId idContinuous = dst->getLinetypeContinuousId(); OdString strDgnContinuousName; OdString strDgnContinuousNameBasic; if( !idContinuous.isNull() ) { OdDbLinetypeTableRecordPtr pDbContinuousLT = idContinuous.openObject(OdDb::kForRead); strDgnContinuousNameBasic = pDbContinuousLT->getName(); strDgnContinuousName = strDgnContinuousNameBasic + L"_DGN"; } for (OdDgElementIteratorPtr i = lst->createIterator(); !i->done(); i->step()) { OdDgLineStyleTableRecordPtr ls = i->item().safeOpenObject(); if( (ls->getName() == strDgnContinuousNameBasic) || (ls->getName() == strDgnContinuousName) ) { if( isContinuousDgnStyle(ls) ) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(idContinuous); _idMap[i->item()] = dwgPath; m_idDgnContinuous = idContinuous; continue; } } OdDbLinetypeTableRecordPtr lt_d = lsImporter.copyLinetype(ls); if (lt_d.isNull()) { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(dst->getLinetypeContinuousId()); _idMap[i->item()] = dwgPath; } else { OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(lt_d->id()); _idMap[i->item()] = dwgPath; addResourceId(lt_d->id()); if (lt_d->getName() == strDgnContinuousName) m_idDgnContinuous = lt_d->id(); } } } void DgnImporter::copyNamedGroup(OdDgModel* m, const OdString& strGroupName, OdDbBlockTableRecord* ms, OdInt8 iViewIndex ) { if( !m || !ms ) { return; } setModelLevelMask( m, iViewIndex ); OdUInt8 uXRefMode = 2; DgnImporter* pImporter = OdDgnImportContext::getDgnImporter(); if( pImporter ) { OdRxVariantValue tmpVar = (OdRxVariantValue)pImporter->properties()->getAt("XRefImportMode"); uXRefMode = tmpVar->getUInt8(); } OdDgNamedGroupHeaderPtr pNamedGroup; OdDgElementIteratorPtr pCtrlIter = m->createControlElementsIterator(); for(; !pCtrlIter->done(); pCtrlIter->step() ) { OdDgElementPtr pItem = pCtrlIter->item().openObject(OdDg::kForRead); if( pItem->isKindOf( OdDgNamedGroupHeader::desc()) ) { pNamedGroup = pItem; if( pNamedGroup->getName() == strGroupName ) { break; } else { pNamedGroup = 0; } } } if( pNamedGroup.isNull() ) { copySpaceBlock( m, ms, false, iViewIndex ); } else { OdArray idElements; OdDgDatabase* pDb = m->database(); if( pDb ) { for( OdUInt32 i = 0; i < pNamedGroup->getNamedGroupItemCount(); i++ ) { OdDgNamedGroupItem curItem = pNamedGroup->getNamedGroupItem( i ); if( curItem.getPathLength() != 1 ) { continue; } OdArray arrPath; curItem.getPath(arrPath); idElements.push_back(pDb->getElementId( OdDbHandle(arrPath[0]))); } } for( OdUInt32 j = 0; j < idElements.size(); j++ ) { if( idElements[j].isNull() ) { continue; } OdDgElementPtr pDgElement = idElements[j].openObject(); if( !uXRefMode && (pDgElement->getElementType() == OdDgElement::kTypeReferenceAttachmentHeader) ) { continue; } if (!pDgElement.isNull()) { ((OdDgnImportPE*)pDgElement->queryX(OdDgnImportPE::desc()))->importElement(pDgElement, ms); } } } removeModelLevelMask(); } OdDgViewPtr getActualDgnView(OdDgModel* m, OdInt8 iViewIndex) { OdDgViewPtr pRet; if (!m || iViewIndex < 0 || iViewIndex > 7) return pRet; OdDgDatabasePtr pDgnDb = m->database(); if( !pDgnDb.isNull() && (pDgnDb->getActiveModelId() == m->elementId()) ) { OdDgElementId idActiveVG = pDgnDb->getActiveViewGroupId(); if( !idActiveVG.isNull() ) { OdDgViewGroupPtr pActiveVG = idActiveVG.openObject(OdDg::kForRead); if (!pActiveVG.isNull()) { OdDgViewPtr pActiveView = pActiveVG->getAt((OdUInt32)iViewIndex).openObject(OdDg::kForWrite); if( pActiveView->getModelId() == m->elementId() ) { pRet = pActiveView; } } } if( pRet.isNull() ) { OdDgElementId idRecomendedVG = pDgnDb->recommendActiveViewGroupId(); if (!idRecomendedVG.isNull()) { OdDgViewGroupPtr pActiveVG = idRecomendedVG.openObject(OdDg::kForRead); if (!pActiveVG.isNull()) { OdDgViewPtr pActiveView = pActiveVG->getAt((OdUInt32)iViewIndex).openObject(OdDg::kForWrite); if (pActiveView->getModelId() == m->elementId()) { pRet = pActiveView; } } } } } if( pRet.isNull() ) { OdDgViewGroupTablePtr pViewGroupTable = m->database()->getViewGroupTable(OdDg::kForRead); OdDgElementIteratorPtr pViewGroupIter = pViewGroupTable->createIterator(); for (; !pViewGroupIter->done(); pViewGroupIter->step()) { OdDgViewGroupPtr pVG = pViewGroupIter->item().openObject(OdDg::kForRead); if (!pVG.isNull() && pVG->getModelId() == m->elementId()) { OdDgElementIteratorPtr pViewIter = pVG->createIterator(); for (; !pViewIter->done(); pViewIter->step()) { OdDgViewPtr pView = pViewIter->item().openObject(OdDg::kForWrite); if (!pView.isNull() && (pView->getIndex() == (OdUInt8)(iViewIndex))) { OdDgnImportContext::setActiveView(pView); OdDgnImportViewFlags newFlags; newFlags.init(pView); OdDgnImportContext::claerViewFlags(); OdDgnImportContext::pushViewFlags(newFlags); pRet = pView; break; } } break; } } } return pRet; } bool DgnImporter::setActiveModelView( OdDgModel* m, OdInt8 iViewIndex ) { bool bRet = false; if (OdDgnImportContext::getActiveView().isNull() && (iViewIndex >= 0) && (iViewIndex < 8)) { OdDgViewPtr pView = getActualDgnView(m, iViewIndex); if (!pView.isNull()) { OdDgnImportContext::setActiveView(pView); OdDgnImportViewFlags newFlags; newFlags.init(pView); OdDgnImportContext::claerViewFlags(); OdDgnImportContext::pushViewFlags(newFlags); bRet = true; } } return bRet; } //================================================================================================== void compareLevelMaskWithLayerTable(const OdDbDatabase* pDb, const OdDgDatabase* pDg, std::set& arrHiddenLayers, std::set& arrShowenLayers) { if (!pDb || !pDg) return; OdDgLevelTablePtr pLevelTable = pDg->getLevelTable(OdDg::kForRead); OdDbLayerTablePtr pLayerTable = pDb->getLayerTableId().openObject(OdDb::kForRead); OdDgElementIteratorPtr pLevelIter = pLevelTable->createIterator(); for (; !pLevelIter->done(); pLevelIter->step()) { if( pLevelIter->item().isNull() ) continue; OdDgLevelTableRecordPtr pLevel = pLevelIter->item().openObject(OdDg::kForRead); if (pLevel.isNull()) continue; OdDbObjectId idLayer = OdDgnImportContext::getObjectId(pLevelIter->item()); if (idLayer.isNull()) idLayer = pLayerTable->getAt(pLevel->getName()); if( idLayer.isNull() ) continue; OdDbLayerTableRecordPtr pLayer = idLayer.openObject(OdDb::kForRead); if (pLayer.isNull()) continue; bool bLayerIsVisible = !pLayer->isFrozen() && !pLayer->isOff(); bool bLevelIsVisible = OdDgnImportContext::checkLevelMask(pLevel->getEntryId(), bLayerIsVisible); if (bLayerIsVisible != bLevelIsVisible) { if (bLevelIsVisible) arrShowenLayers.insert(pLayer->id()); else arrHiddenLayers.insert(pLayer->id()); } } } //================================================================================================== OdDbObjectId addShowenLayer(const OdDbObjectId& idBaseLayer, OdDbDatabase* pDb, std::map& mapAddedLayers) { OdDbObjectId idRet = idBaseLayer; if( pDb && !idBaseLayer.isNull()) { OdDbLayerTableRecordPtr pBaseLayer = idBaseLayer.openObject(OdDb::kForRead); if( pBaseLayer->isFrozen() || pBaseLayer->isOff() ) { OdDbLayerTablePtr pLayerTable = pDb->getLayerTableId().openObject(OdDb::kForWrite); OdString strLayerNameBase = pBaseLayer->getName() + L"_Vis"; if (!pLayerTable->getAt(strLayerNameBase).isNull()) { idRet = pLayerTable->getAt(strLayerNameBase); mapAddedLayers[idBaseLayer] = idRet; } else { OdString strLayerName = strLayerNameBase; OdString repairedName; if (OdDbSymUtil::repairSymbolName(repairedName, strLayerName, pDb) == eOk && !repairedName.isEmpty()) strLayerName = repairedName; OdDbLayerTableRecordPtr pVisibleLayer = pBaseLayer->clone(); pVisibleLayer->setIsFrozen(false); pVisibleLayer->setIsOff(false); pVisibleLayer->setName(strLayerName); pLayerTable->add(pVisibleLayer); mapAddedLayers[idBaseLayer] = pVisibleLayer->id(); idRet = pVisibleLayer->id(); } } } return idRet; } //================================================================================================== bool hasUpdatedLayers(const OdDbObjectId& idBlockDef, const std::set& arrShowenLayers, const std::set& arrHiddenLayers, std::set& setFreeBlocks, const std::map& mapUpdatedBlocks ) { if( idBlockDef.isNull() ) return false; std::map::const_iterator pBlockMapIter = mapUpdatedBlocks.find(idBlockDef); if (pBlockMapIter != mapUpdatedBlocks.end()) return true; std::set< OdDbObjectId>::const_iterator pFreeBlockIter = setFreeBlocks.find(idBlockDef); if (pFreeBlockIter != setFreeBlocks.end()) return false; OdDbBlockTableRecordPtr pBlockDef = idBlockDef.openObject(OdDb::kForRead); OdDbObjectIteratorPtr pIter = pBlockDef->newIterator(); for(; !pIter->done(); pIter->step()) { OdDbEntityPtr pEnt = pIter->entity(); if( pEnt.isNull() ) continue; OdDbObjectId idLayer = pEnt->layerId(); std::set::const_iterator pHiddenIter = arrHiddenLayers.find(idLayer); if (pHiddenIter != arrHiddenLayers.end()) return true; std::set::const_iterator pShowenIter = arrShowenLayers.find(idLayer); if (pShowenIter != arrShowenLayers.end()) return true; if( pEnt->isA() == OdDbBlockReference::desc() ) { OdDbBlockReferencePtr pItemBlockRef = pEnt; OdDbObjectId idChildBlockDef = pItemBlockRef->blockTableRecord(); if( hasUpdatedLayers(idChildBlockDef, arrShowenLayers, arrHiddenLayers, setFreeBlocks, mapUpdatedBlocks) ) return true; } } setFreeBlocks.insert(idBlockDef); return false; } //================================================================================================== OdDbObjectId createBlockRecordWithCorrectedLevels( const OdDbObjectId& idBlockDef, const std::set& arrShowenLayers, const std::set& arrHiddenLayers, std::map& mapAddedLayers, std::set& setFreeBlocks, std::map& mapUpdatedBlocks ) { OdDbObjectId idRet; if (idBlockDef.isNull()) return idRet; std::map::const_iterator pBlockMapIter = mapUpdatedBlocks.find(idBlockDef); if (pBlockMapIter != mapUpdatedBlocks.end()) return pBlockMapIter->second; std::set< OdDbObjectId>::const_iterator pFreeBlockIter = setFreeBlocks.find(idBlockDef); if (pFreeBlockIter != setFreeBlocks.end()) return idRet; if (!hasUpdatedLayers(idBlockDef, arrShowenLayers, arrHiddenLayers, setFreeBlocks, mapUpdatedBlocks)) return idRet; OdDbBlockTableRecordPtr pBlock = idBlockDef.openObject(OdDb::kForRead); OdDbBlockTableRecordPtr pBlockClone = pBlock->clone(); OdDbDatabase* pDb = pBlock->database(); OdDbBlockTablePtr pBlockTable = pDb->getBlockTableId().openObject(OdDb::kForRead); OdString strNameBase = pBlock->getName() + L"_ForPS"; OdString strNewName = strNameBase; OdUInt32 uCount = 1; while( !pBlockTable->getAt(strNewName).isNull() ) { strNewName.format(L"_%d", uCount); uCount++; strNewName = strNameBase + strNewName; } OdString repairedName; if (OdDbSymUtil::repairSymbolName(repairedName, strNewName, pDb) == eOk && !repairedName.isEmpty()) strNewName = repairedName; pBlockClone->setName(strNewName); // Update layers OdDbObjectIteratorPtr pBlockIter = pBlockClone->newIterator(); for (; !pBlockIter->done(); pBlockIter->step()) { OdDbEntityPtr pItem = pBlockIter->entity(); if (pItem.isNull()) continue; OdDbObjectId idLayer = pItem->layerId(); std::set::iterator pShowenIter = arrShowenLayers.find(idLayer); std::set::iterator pHiddenIter = arrHiddenLayers.find(idLayer); if (pShowenIter != arrShowenLayers.end()) { // change layers. OdDbObjectId idLayerToExchange; std::map::const_iterator pLayerToExchangeIter = mapAddedLayers.find(idLayer); if (pLayerToExchangeIter == mapAddedLayers.end()) idLayerToExchange = addShowenLayer(idLayer, pBlock->database(), mapAddedLayers); pItem->setLayer(idLayerToExchange); } else if( pHiddenIter != arrHiddenLayers.end() ) { pItem->setVisibility(OdDb::kInvisible); continue; } if (pItem->isA() == OdDbBlockReference::desc()) { OdDbBlockReferencePtr pItemBlockRef = pItem; OdDbObjectId idBlockDef = pItemBlockRef->blockTableRecord(); if (!idBlockDef.isNull()) { // Check Block Table Record. OdDbObjectId idNewBlock = createBlockRecordWithCorrectedLevels(idBlockDef, arrShowenLayers, arrHiddenLayers, mapAddedLayers, setFreeBlocks, mapUpdatedBlocks); if (!idNewBlock.isNull()) pItemBlockRef->setBlockTableRecord(idNewBlock); } } } // Add block to database pBlockTable->add(pBlockClone); mapUpdatedBlocks[idBlockDef] = pBlockClone->id(); idRet = pBlockClone->id(); return idRet; } //================================================================================================== void DgnImporter::copySpaceBlock(OdDgModel* m, OdDbBlockTableRecord* ms, bool bIgnoreTransformToOffset, OdInt8 iViewIndex, bool bModelSpace, bool bXRefImport ) { OdUInt32 nNativeItems = 0; if( !bIgnoreTransformToOffset ) { for (OdDbObjectIteratorPtr pDbIter = ms->newIterator(); !pDbIter->done(); pDbIter->step()) nNativeItems++; } // Set global line style scale double dActualLineTypeScale = 1.0; bool bRestoreGlobalLineScale = m && !OdDgnImportContext::getGlobalLineScale(dActualLineTypeScale); if(bRestoreGlobalLineScale) { dActualLineTypeScale = m->getLinestyleScale(); if( m->getCompoundLineScaleFlag() ) { if (OdZero(dActualLineTypeScale)) dActualLineTypeScale = 1.0; double dAnnotationScale = m->getAnnotationScale(); if (OdZero(dAnnotationScale)) dAnnotationScale = 1.0; dActualLineTypeScale *= dAnnotationScale; } else if (m->getAnnotationLineScaleFlag()) dActualLineTypeScale = m->getAnnotationScale(); if (OdZero(dActualLineTypeScale)) dActualLineTypeScale = m->database()->getLineStyleScale(); if (OdZero(dActualLineTypeScale)) dActualLineTypeScale = 1.0; OdDgnImportContext::pushGlobalLineScale(dActualLineTypeScale); } // bool bResetView = false; if( setActiveModelView( m, iViewIndex ) ) { bResetView = true; if( bModelSpace ) { ms->database()->setLWDISPLAY( OdDgnImportContext::getActiveView()->getShowLineWeightsFlag() ); } } setModelLevelMask( m, iViewIndex ); std::set arrHiddenLayers; std::set arrShowenLayers; bool bCorrectLayers = false; if (m && (bXRefImport || !OdDgnImportContext::isLevelMaskApplied(ms->database())) ) { if( !bXRefImport ) updateLayerVisibilityByLevelMask(m->database()); OdDgnImportContext::applyLevelMask(ms->database()); } else if( OdDgnImportContext::isLevelMask() && !bXRefImport ) { compareLevelMaskWithLayerTable(ms->database(), m->database(), arrHiddenLayers, arrShowenLayers); bCorrectLayers = !arrHiddenLayers.empty() || !arrShowenLayers.empty(); } OdUInt8 uXRefMode = 2; DgnImporter* pImporter = OdDgnImportContext::getDgnImporter(); if( pImporter ) { OdRxVariantValue tmpVar = (OdRxVariantValue)pImporter->properties()->getAt("XRefImportMode"); uXRefMode = tmpVar->getUInt8(); } OdDgnImportContext::setBackgroundColor( m->getBackground() ); OdDgElementIdArray arrRasterRefsBefore; OdDgElementIdArray arrRasterRefsAfter; OdDgElementIdArray arrXRefBefore; OdDgElementIdArray arrXRefAfter; OdDgElementIdArray arrXRef; OdDgReferenceOrderPtr pXRefOrder; for (OdDgElementIteratorPtr pIter = m->createControlElementsIterator(); !pIter->done(); pIter->step()) { OdRxObjectPtr unknownElement = pIter->item().openObject( OdDg::kForRead ); if (unknownElement->isKindOf(OdDgRasterAttachmentHeader::desc())) { OdDgRasterAttachmentHeaderPtr pRasterHeader = unknownElement; if( !pRasterHeader.isNull() ) { if( pRasterHeader->getRasterPlane() == OdDgRasterAttachmentHeader::kBackground ) { arrRasterRefsBefore.push_back(pIter->item()); } else if( pRasterHeader->getRasterPlane() == OdDgRasterAttachmentHeader::kForeground ) { arrRasterRefsAfter.push_back(pIter->item()); } } } else if( unknownElement->isKindOf(OdDgGeoDataInfo::desc()) ) { arrXRef.push_back(pIter->item()); } else if (unknownElement->isKindOf(OdDgReferenceAttachmentHeader::desc()) && uXRefMode ) { arrXRef.push_back(pIter->item()); } else if( unknownElement->isKindOf( OdDgReferenceOrder::desc() ) && uXRefMode ) { pXRefOrder = unknownElement; } } if( !pXRefOrder.isNull() ) { OdUInt32 uRef = 0; bool bDrawBeforeOfModel = true; for( uRef = 0; uRef < pXRefOrder->getNumberOfReferences(); uRef++ ) { OdUInt64 uRefId = pXRefOrder->getReferenceId(uRef); if( uRefId == 0 ) { bDrawBeforeOfModel = false; } else { for( OdUInt32 uCurRef = 0; uCurRef < arrXRef.size(); uCurRef++ ) { if( arrXRef[uCurRef].getHandle() == uRefId ) { if( bDrawBeforeOfModel ) { arrXRefBefore.push_back( arrXRef[uCurRef] ); } else { arrXRefAfter.push_back( arrXRef[uCurRef] ); } arrXRef.removeAt( uCurRef ); break; } } } } for( uRef = 0; uRef < arrXRef.size(); uRef++ ) { arrXRefAfter.push_back( arrXRef[uRef] ); } } else { for( OdUInt32 uRef = 0; uRef < arrXRef.size(); uRef++ ) { arrXRefAfter.push_back( arrXRef[uRef] ); } } OdUInt32 i = 0; for( i = 0; i < arrRasterRefsBefore.size(); i++ ) { OdDgElementPtr pRasterAttachment = arrRasterRefsBefore[i].openObject(OdDg::kForRead); if( !pRasterAttachment.isNull() ) { ((OdDgnImportPE*)pRasterAttachment->queryX(OdDgnImportPE::desc()))->importElement(pRasterAttachment, ms); } } for( i = 0; i < arrXRefBefore.size(); i++ ) { OdDgElementPtr pXRef = arrXRefBefore[i].openObject(OdDg::kForRead); if( !pXRef.isNull() ) { ((OdDgnImportPE*)pXRef->queryX(OdDgnImportPE::desc()))->importElement(pXRef, ms); } } OdDgElementIdArray arrModelChildren; for( OdDgElementIteratorPtr pIter = m->createGraphicsElementsIterator(); !pIter->done(); pIter->step() ) arrModelChildren.push_back(pIter->item()); if( !m->getModelIs3dFlag() ) sortElementsByPriority(arrModelChildren); for (OdUInt32 l = 0; l < arrModelChildren.size(); l++ ) { OdDgElementPtr pDgElement = arrModelChildren[l].openObject(); if (!pDgElement.isNull()) { ((OdDgnImportPE*)pDgElement->queryX(OdDgnImportPE::desc()))->importElement(pDgElement, ms); } } for( i = 0; i < arrXRefAfter.size(); i++ ) { OdDgElementPtr pXRef = arrXRefAfter[i].openObject(OdDg::kForRead); if( !pXRef.isNull() ) { ((OdDgnImportPE*)pXRef->queryX(OdDgnImportPE::desc()))->importElement(pXRef, ms); } } for( i = 0; i < arrRasterRefsAfter.size(); i++ ) { OdDgElementPtr pRasterAttachment = arrRasterRefsAfter[i].openObject(OdDg::kForRead); if( !pRasterAttachment.isNull() ) { ((OdDgnImportPE*)pRasterAttachment->queryX(OdDgnImportPE::desc()))->importElement(pRasterAttachment, ms); } } if( !bIgnoreTransformToOffset ) { OdUInt32 uCount = 0; OdGeVector3d globalOffset = m->getGlobalOrigin().asVector(); if (globalOffset != OdGeVector3d::kIdentity) { OdGeMatrix3d tr = OdGeMatrix3d::translation(-globalOffset); for (OdDbObjectIteratorPtr it = ms->newIterator(); !it->done(); it->step(), uCount++ ) { if( uCount < nNativeItems ) continue; OdDbEntityPtr e = it->objectId().safeOpenObject(OdDb::kForWrite); if( e->isKindOf(OdDbDimension::desc() ) ) { OdDbDimensionPtr pDim = e; OdDbObjectId idBlock = pDim->dimBlockId(); if( !idBlock.isNull() ) { OdDbBlockTableRecordPtr pDimBlock = idBlock.openObject(OdDb::kForWrite); OdGeVector3d vrDimNormal = pDim->normal(); OdGeMatrix3d matWorldToPlaneDim = OdGeMatrix3d::worldToPlane(vrDimNormal); OdGeMatrix3d matPlaneToWorldDim = OdGeMatrix3d::planeToWorld(vrDimNormal); if( !pDimBlock.isNull() ) { for (OdDbObjectIteratorPtr it = pDimBlock->newIterator(); !it->done(); it->step()) { OdDbEntityPtr e = it->objectId().safeOpenObject(OdDb::kForWrite); e->transformBy(matPlaneToWorldDim); e->transformBy(tr); e->transformBy(matWorldToPlaneDim); } } } } e->transformBy(tr); } } } // Apply level mask changes to paper space objects and blocks. if( bCorrectLayers ) { std::map mapAddedLayers; std::set setFreeBlocks; std::map mapUpdatedBlocks; OdDbObjectIteratorPtr pBlockIter = ms->newIterator(); for(; !pBlockIter->done(); pBlockIter->step()) { OdDbEntityPtr pItem = pBlockIter->entity(); if( pItem.isNull() ) continue; OdDbObjectId idLayer = pItem->layerId(); std::set::iterator pShowenIter = arrShowenLayers.find(idLayer); if( pShowenIter != arrShowenLayers.end() ) { // change layers. OdDbObjectId idLayerToExchange; std::map::const_iterator pLayerToExchangeIter = mapAddedLayers.find(idLayer); if (pLayerToExchangeIter == mapAddedLayers.end()) idLayerToExchange = addShowenLayer(idLayer, ms->database(), mapAddedLayers); pItem->setLayer(idLayerToExchange); } if( pItem->isA() == OdDbBlockReference::desc() ) { OdDbBlockReferencePtr pItemBlockRef = pItem; OdDbObjectId idBlockDef = pItemBlockRef->blockTableRecord(); if( !idBlockDef.isNull() ) { // Check Block Table Record. OdDbObjectId idNewBlock = createBlockRecordWithCorrectedLevels(idBlockDef, arrShowenLayers, arrHiddenLayers, mapAddedLayers, setFreeBlocks, mapUpdatedBlocks); if (!idNewBlock.isNull()) pItemBlockRef->setBlockTableRecord(idNewBlock); } } } } if( bResetView ) { OdDgnImportContext::setActiveView( OdDgViewPtr() ); OdDgnImportContext::popViewFlags(); } if( iViewIndex >= 0 && iViewIndex < 8 ) { removeModelLevelMask(); } if( bRestoreGlobalLineScale ) OdDgnImportContext::popGlobalLineScale(); } void DgnImporter::copyModelSpace(OdDgModel* m, OdDbDatabase* pDb) { OdDbBlockTableRecordPtr ms = pDb->getModelSpaceId().safeOpenObject(OdDb::kForWrite); OdDgnImportContext::setModelSpaceId(m->elementId()); copySpaceBlock(m, ms, m->isGlobalOriginEnabled(), _properties->get_ImportViewIndex(), true ); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_idPath.objectIds().push_back(ms->objectId()); dwgPath.m_bExists = true; OdDgnImportContext::addObjectPath(m->elementId(), dwgPath); } //========================================================================== void transformDwgBlockDef(OdDbBlockTableRecord* pBlock, const OdGeMatrix3d& matTransform) { OdDbObjectIteratorPtr pIter = pBlock->newIterator(); for (; !pIter->done(); pIter->step()) { OdDbEntityPtr pEnt = pIter->entity(); if (pEnt.isNull()) continue; pEnt->transformBy(matTransform); if( pEnt->isKindOf(OdDbViewport::desc()) ) { OdDbViewportPtr pVp = pEnt; OdGeVector3d vrX = OdGeVector3d::kXAxis; vrX.transformBy(matTransform); pVp->setTwistAngle(pVp->twistAngle() - vrX.angleTo(OdGeVector3d::kXAxis, OdGeVector3d::kZAxis)); } } } //========================================================================== OdDbObjectId DgnImporter::copyLayout(OdDgModel* m, OdDbDatabase* pDb) { ODA_ASSERT(m->isKindOf(OdDgSheetModel::desc())); OdDgSheetModel* sm = (OdDgSheetModel*)m; OdDbObjectId btrId; OdString name = m->getName(), repairedName; if ( OdDbSymUtil::repairSymbolName(repairedName, name, pDb) == eOk && !repairedName.isEmpty()) name = repairedName; OdDbObjectId layoutId = pDb->appServices()->layoutManager()->createLayout(pDb, name, &btrId); OdDbLayoutPtr dbLayout = layoutId.safeOpenObject(OdDb::kForWrite); OdDbSetPlotSettingsPEPtr pSetPlotSettings = OdDbSetPlotSettingsPE::cast(dbLayout); OdDgModel::UnitDescription dgnPaperDesc = sm->getSheetUnits(); bool bInchesAsPaperUnits = false; //if (OdEqual(dgnPaperDesc.m_denominator / dgnPaperDesc.m_numerator, 254.0 / 10000.0)) // bInchesAsPaperUnits = true; OdDgModel::UnitDescription paperUnits; if( bInchesAsPaperUnits ) { paperUnits.m_numerator = 10000.0; paperUnits.m_denominator = 254.0; } else { paperUnits.m_numerator = 1000.0; paperUnits.m_denominator = 1.0; } double dModelScale = sm->getAnnotationScale(); OdDgModel::UnitDescription masterUnits; sm->getMasterUnit(masterUnits); double dMasterUnitsToPaperUnitsScale = masterUnits.m_denominator / masterUnits.m_numerator * paperUnits.m_numerator / paperUnits.m_denominator; if( !sm->getSheetPaperName().isEmpty() ) pSetPlotSettings->setStyleSheet( dbLayout, sm->getSheetPaperName() ); double dSheetWidth = sm->getSheetWidth() + sm->getSheetLeftMargin() + sm->getSheetRightMargin(); double dSheetHeight = sm->getSheetHeight() + sm->getSheetTopMargin() + sm->getSheetBottomMargin(); pSetPlotSettings->setPlotPaperSize( dbLayout, dSheetWidth * dMasterUnitsToPaperUnitsScale, dSheetHeight * dMasterUnitsToPaperUnitsScale); pSetPlotSettings->setMargins( dbLayout, sm->getSheetLeftMargin() * dMasterUnitsToPaperUnitsScale, sm->getSheetRightMargin() * dMasterUnitsToPaperUnitsScale, sm->getSheetTopMargin() * dMasterUnitsToPaperUnitsScale, sm->getSheetBottomMargin() * dMasterUnitsToPaperUnitsScale); double dPaperWidth = 0; double dPaperHeight = 0; dbLayout->getPlotPaperSize(dPaperWidth, dPaperHeight); if (dPaperWidth < 1 || dPaperHeight < 1) { pSetPlotSettings->setStyleSheet(dbLayout, OdString(L"Letter_(8.50_x_11.00_Inches)")); pSetPlotSettings->setPlotPaperSize(dbLayout, 11.00 * dMasterUnitsToPaperUnitsScale, 8.50 * dMasterUnitsToPaperUnitsScale); //bInchesAsPaperUnits = true; } OdDbPlotSettings::PlotRotation curRotation = OdDbPlotSettings::k0degrees; bool bApplyRotation = false; if (OdZero(sm->getSheetRotation() - OdaPI2)) curRotation = OdDbPlotSettings::k90degrees; else if (OdZero(sm->getSheetRotation() - OdaPI)) curRotation = OdDbPlotSettings::k180degrees; else if (OdZero(sm->getSheetRotation() - 3 * OdaPI2)) curRotation = OdDbPlotSettings::k270degrees; else if( !OdZero(sm->getSheetRotation()) ) bApplyRotation = true; pSetPlotSettings->setPlotRotation( dbLayout, curRotation ); OdGePoint2d ptOffset = sm->getSheetOffset() * -1.0 * dMasterUnitsToPaperUnitsScale / dModelScale; if( curRotation == OdDbPlotSettings::k90degrees ) { OdGeVector2d vrOffset = ptOffset.asVector(); vrOffset.rotateBy(OdaPI2); ptOffset.y = sm->getSheetHeight() * dMasterUnitsToPaperUnitsScale + vrOffset.y; ptOffset.x = -vrOffset.x; } else if( curRotation == OdDbPlotSettings::k180degrees ) { OdGeVector2d vrOffset = ptOffset.asVector(); vrOffset.rotateBy(OdaPI); ptOffset.x = sm->getSheetWidth() * dMasterUnitsToPaperUnitsScale - vrOffset.x; ptOffset.y = sm->getSheetHeight() * dMasterUnitsToPaperUnitsScale - vrOffset.y; } else if( curRotation == OdDbPlotSettings::k270degrees ) { OdGeVector2d vrOffset = ptOffset.asVector(); vrOffset.rotateBy(3*OdaPI2); ptOffset.x = sm->getSheetWidth() * dMasterUnitsToPaperUnitsScale + vrOffset.x; ptOffset.y = - vrOffset.y; } pSetPlotSettings->setOrigin( dbLayout, ptOffset ); if( bInchesAsPaperUnits ) pSetPlotSettings->setPlotPaperUnits(dbLayout, OdDbPlotSettings::kInches); else pSetPlotSettings->setPlotPaperUnits( dbLayout, OdDbPlotSettings::kMillimeters ); pSetPlotSettings->setScaleFactor( dbLayout, dMasterUnitsToPaperUnitsScale / dModelScale ); OdDbPlotSettingsValidator* pv = pDb->appServices()->plotSettingsValidator(); if (pv) { if( bInchesAsPaperUnits ) pv->setCustomPrintScale(dbLayout, dMasterUnitsToPaperUnitsScale / 25.4, dModelScale); else pv->setCustomPrintScale(dbLayout, dMasterUnitsToPaperUnitsScale, dModelScale); } // // TODO: units // pv->setClosestMediaName(dbLayout, sm->getSheetWidth(), sm->getSheetHeight(), OdDbPlotSettings::kMillimeters, false); OdDbBlockTableRecordPtr btr = btrId.safeOpenObject(OdDb::kForWrite); OdDbViewportPtr pVp; if( dbLayout->overallVportId().isNull() ) { pVp = OdDbViewport::createObject(); btr->appendOdDbEntity(pVp); pVp->setDatabaseDefaults(pDb); pVp->setLayer(pDb->getLayerZeroId()); OdGeVector2d size = pDb->getPLIMMAX() - pDb->getPLIMMIN(); if (OdZero(size.x) || OdZero(size.y)) dbLayout->getPlotPaperSize(size.x, size.y); OdGePoint3d pt; (OdGePoint2d&)pt = pDb->getPLIMMIN() + size / 2.; pVp->setCenterPoint(pt); pVp->setViewCenter((const OdGePoint2d&)pt); size *= 1.058; pVp->setWidth(size.x); pVp->setHeight(size.y); pVp->setViewHeight(size.y); pVp->subClose(); setLayoutViewport(m->database(), dbLayout->objectId(), m); } copySpaceBlock(m, btr, m->isGlobalOriginEnabled(), _properties->get_ImportViewIndex() ); if (!btr.isNull()) { if( bApplyRotation ) { OdGePoint2d ptSheetOffset = sm->getSheetOffset(); OdGeMatrix3d matRotateBack = OdGeMatrix3d::rotation(-sm->getSheetRotation(), OdGeVector3d::kZAxis, OdGePoint3d(ptSheetOffset.x, ptSheetOffset.y, 0.0)); transformDwgBlockDef(btr, matRotateBack); } } btr->setComments(m->getName()); return layoutId; } void DgnImporter::copyBlocks(OdDgDatabase* pDg, OdDbDatabase* pDb, bool bDimTermBlocksOnly, bool bSkipDimTermBlocks ) { OdDbBlockTablePtr bt = pDb->getBlockTableId().safeOpenObject(OdDb::kForWrite); OdDgElementIteratorPtr i = pDg->getSharedCellDefinitionTable()->createIterator(); std::set setDimTerminatorBlockIds; std::set setSkipBlockIds; for (; !i->done(); i->step()) { OdDgSharedCellDefinitionPtr scd = i->item().safeOpenObject(); OdDbObjectId idBlock = getObjectId(i->item()); if (!idBlock.isNull()) { setSkipBlockIds.insert(i->item()); continue; } OdDbBlockTableRecordPtr block = OdDbBlockTableRecord::createObject(); OdString name = scd->getName(); if (name.isEmpty()) // empty name => user anonymous block name = L"*U"; else if (name[0] == '*') // anonymous blocks will be reindexed { if (name.getLength() < 2) name = L"*U"; else if (name.getLength() > 2) name = name.left(2); } else { OdString repairedName; if (OdDbSymUtil::repairSymbolName(repairedName, name, pDb) == eOk && !repairedName.isEmpty()) name = repairedName; } block->setComments(scd->getDescription()); block->setOrigin(scd->getOrigin()); bool bDimTermitatorBlock = name.getLength() > 1 && name.getAt(0) == L'_' && OdDmUtil::isBuiltInArrow(name); if (bDimTermitatorBlock) { OdString strDimBlockName = name.right(name.getLength() - 1); if (OdDmUtil::isZeroLengthArrow(strDimBlockName)) { name = L"DGN" + name; bDimTermitatorBlock = false; } } if (bDimTermitatorBlock) setDimTerminatorBlockIds.insert(scd->elementId()); if( bSkipDimTermBlocks && bDimTermitatorBlock) continue; if (bDimTermBlocksOnly && !bDimTermitatorBlock ) continue; pDb->addOdDbObject(block, bt->objectId()); if (!bt->has(name)) { if (!bt->has(name)) block->setName(name); else block->setName(L"*U"); } else block->setName(L"*U"); bt->add(block); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(block->objectId()); _idMap[i->item()] = dwgPath; addResourceId(block->objectId()); } // all the block definitions are added first, because of possible block references for (i->start(); !i->done(); i->step()) { OdDgSharedCellDefinitionPtr scd = i->item().safeOpenObject(); OdDbObjectId idBlock = getObjectId( i->item() ); std::set::const_iterator pSkipIter = setSkipBlockIds.find(i->item()); if( pSkipIter != setSkipBlockIds.end() ) continue; std::set::const_iterator pDimTermIter = setDimTerminatorBlockIds.find(i->item()); bool bDimTermitatorBlock = pDimTermIter != setDimTerminatorBlockIds.end(); if (bSkipDimTermBlocks && bDimTermitatorBlock) continue; if (bDimTermBlocksOnly && !bDimTermitatorBlock) continue; if( !idBlock.isNull() ) { OdDbBlockTableRecordPtr block = idBlock.safeOpenObject(OdDb::kForWrite); double dDimBlockScale = OdDgnImportContext::getUORsToModelBlockScale(); if( bDimTermitatorBlock ) dDimBlockScale = 1.0; double dOldDimBlockScale = OdDgnImportContext::getDimDataScale(); OdDgnImportContext::setDimDataScale(dDimBlockScale); OdDgElementIdArray arrBlockDefChildren; for (OdDgElementIteratorPtr pIter = scd->createIterator(); !pIter->done(); pIter->step()) arrBlockDefChildren.push_back(pIter->item()); if (!scd->get3dFormatFlag()) sortElementsByPriority(arrBlockDefChildren); for( OdUInt32 l = 0; l < arrBlockDefChildren.size(); l++ ) { OdDgElementPtr pDgElement = arrBlockDefChildren[l].openObject(); if( pDgElement->isKindOf(OdDgReferenceAttachmentHeader::desc()) ) continue; if (!pDgElement.isNull()) { ((OdDgnImportPE*)pDgElement->queryX(OdDgnImportPE::desc()))->importElement(pDgElement, block); } } OdDgnImportContext::setDimDataScale(dOldDimBlockScale); if( !bDimTermitatorBlock && !OdZero(OdDgnImportContext::getUORsToModelBlockScale() - 1.0)) scaleBlockDefinition(block, OdDgnImportContext::getUORsToModelBlockScale()); if(bDimTermitatorBlock) { OdGeExtents3d extBlock; block->getGeomExtents(extBlock); if (extBlock.isValidExtents()) { double dWidth = extBlock.maxPoint().x - extBlock.minPoint().x; double dHeight = extBlock.maxPoint().y - extBlock.minPoint().y; double dDimTermScale = dWidth > dHeight ? dWidth : dHeight; scaleBlockDefinition(block, 1.0 / dDimTermScale); OdDgnImportContext::addScaledBlock(block->objectId(), dDimTermScale); } } } } } void DgnImporter::copyDatabaseDefaults(OdDgDatabase* pDg, OdDbDatabase* pDb) { // Color OdCmColor defaultColor; OdUInt32 uDefaultColorIndex = pDg->getActiveColorIndex(); setDwgColorByDgnIndex(pDg, defaultColor, uDefaultColorIndex); pDb->setCECOLOR(defaultColor); // Line type OdDbObjectId idDbLineType; OdUInt32 uLineStyleId = pDg->getActiveLineStyleEntryId(); setDwgLineTypeIdByDgnLineTypeIndex(pDb, pDg, uLineStyleId, idDbLineType); if(!idDbLineType.isNull()) pDb->setCELTYPE(idDbLineType); // Line weight OdUInt32 uLineWeight = pDg->getActiveLineWeight(); OdDb::LineWeight extWeight = odDgnImportLineweightMapping(uLineWeight); pDb->setCELWEIGHT(extWeight); // Level OdUInt32 uLevelId = pDg->getActiveLevelEntryId(); OdDgLevelTablePtr pLevelTable = pDg->getLevelTable(OdDg::kForRead); OdDgElementId idLevel = pLevelTable->getAt(uLevelId); OdDbObjectId layerId; if( !idLevel.isNull() ) layerId = OdDgnImportContext::getObjectId(idLevel); if (!layerId.isNull()) pDb->setCLAYER(layerId); // Multiline style OdDgMultilineStyleTablePtr pMLineStyleTable = pDg->getMultilineStyleTable(OdDg::kForRead); OdDgMultilineStyleTableRecordPtr pMLineDefault = pMLineStyleTable->getActiveMultilineStyle(); if (!pMLineDefault.isNull()) { OdDbObjectId dimMLineId = OdDgnImportContext::getObjectId(pMLineDefault->elementId()); if (!dimMLineId.isNull()) pDb->setCMLSTYLE(dimMLineId); } // Text style OdDgTextStyleTablePtr pTextStyleTable = pDg->getTextStyleTable(OdDg::kForRead); OdDgTextStyleTableRecordPtr pTextDefault = pTextStyleTable->getDefaultData(); OdDgElementId idTextStyle; if( !pTextDefault.isNull() ) { idTextStyle = pTextStyleTable->getAt(pTextDefault->getName()); if (!idTextStyle.isNull()) { OdDbObjectId dbTextStyleId = OdDgnImportContext::getObjectId(idTextStyle); if( !dbTextStyleId.isNull() ) pDb->setTEXTSTYLE(dbTextStyleId); } } // Raster frame visibility OdDbRasterVariablesPtr pRVars = OdDbRasterVariables::openRasterVariables(pDb, OdDb::kForWrite); pRVars->setImageFrame(OdDbRasterVariables::kImageFrameOff); } void DgnImporter::copyRegApps(OdDgDatabase* pDg, OdDbDatabase* pDb) { OdDbRegAppTablePtr pRegAppTable = pDb->getRegAppTableId().openObject(OdDb::kForWrite); for (OdDgElementIteratorPtr i = pDg->getRegAppTable()->createIterator(); !i->done(); i->step()) { OdDgRegAppTableRecordPtr r = i->item().safeOpenObject(); OdString regAppName = r->getName(); if( regAppName.isEmpty() ) { regAppName = OD_T("RegApp0"); OdUInt32 iCount = 1; while( pRegAppTable->has(regAppName) ) { regAppName.format(OD_T("RegApp%d"), iCount ); iCount++; } } OdString repairedName; if ( OdDbSymUtil::repairSymbolName(repairedName, regAppName, pDb) == eOk && !repairedName.isEmpty()) regAppName = repairedName; if (!pRegAppTable->has(regAppName)) { OdDbRegAppTableRecordPtr pRegApp = OdDbRegAppTableRecord::createObject(); pRegApp->setName(regAppName); OdDbObjectId idItem = pDb->getOdDbObjectId( OdDbHandle((OdUInt64)(i->item().getHandle()))); if( idItem.isNull() ) { pDb->addOdDbObject(pRegApp, pRegAppTable->objectId(), i->item().getHandle()); } else { pDb->addOdDbObject(pRegApp, pRegAppTable->objectId() ); } pRegAppTable->add(pRegApp); } } } void DgnImporter::copyTextStyles(OdDgDatabase* pDg, OdDbDatabase* pDb, bool bSetDefaultTextSize) { double dUORsToModelScale = 1.0; OdDgModelPtr pDefaultModel; if (!pDg->getDefaultModelId().isNull()) pDefaultModel = pDg->getDefaultModelId().openObject(OdDg::kForRead); else if (!pDg->getActiveModelId().isNull()) pDefaultModel = pDg->getActiveModelId().openObject(OdDg::kForRead); else { OdDgModelTablePtr pModelTable = pDg->getModelTable(); OdDgElementIteratorPtr pModelIter = pModelTable->createIterator(); if (!pModelIter->done()) pDefaultModel = pModelIter->item().openObject(OdDg::kForRead); } if (!pDefaultModel.isNull()) dUORsToModelScale = pDefaultModel->convertUORsToWorkingUnits(1.0) * getUnitConversionScale(pDefaultModel, pDb); OdDbTextStyleTablePtr tst = pDb->getTextStyleTableId().safeOpenObject(OdDb::kForWrite); for (OdDgElementIteratorPtr i = pDg->getTextStyleTable()->createIterator(); !i->done(); i->step()) { OdDgTextStyleTableRecordPtr ts = i->item().safeOpenObject(); OdGiTextStyle giStyle; ts->getGiTextStyle(giStyle); OdDbTextStyleTableRecordPtr dbTs; OdString tsname = ts->getName(); if (tsname.isEmpty()) { OdDgFontTableRecordPtr font = pDg->getFontTable()->getFont(ts->getFontEntryId()); if (font.isNull()) continue; tsname = "Style-" + font->getName(); if(!giStyle.isShxFont()) { OdString Typeface; bool bold, italic; int nCharset, nPitchAndFamily; giStyle.font(Typeface, bold, italic, nCharset, nPitchAndFamily); if( bold || italic ) tsname += L"-"; if( bold ) tsname += L"B"; if( italic ) tsname += L"I"; } } OdString repairedName; if ( OdDbSymUtil::repairSymbolName(repairedName, tsname, pDb) == eOk && !repairedName.isEmpty()) tsname = repairedName; OdDbObjectId id = tst->getAt(tsname); if (id.isNull()) { dbTs = OdDbTextStyleTableRecord::createObject(); dbTs->setName(tsname); OdDbObjectId idItem = pDb->getOdDbObjectId( OdDbHandle((OdUInt64)(i->item().getHandle()))); if( idItem.isNull() ) { pDb->addOdDbObject(dbTs, tst->objectId(), i->item().getHandle()); } else { pDb->addOdDbObject(dbTs, tst->objectId() ); } tst->add(dbTs); } else { dbTs = id.safeOpenObject(OdDb::kForWrite); } dbTs->setIsVertical(giStyle.isVertical()); dbTs->setTextSize(giStyle.textSize()*dUORsToModelScale); dbTs->setXScale(giStyle.xScale()); dbTs->setObliquingAngle(giStyle.obliquingAngle()); dbTs->setIsBackwards(giStyle.isBackward()); dbTs->setIsUpsideDown(giStyle.isUpsideDown()); // TODO: other font types if (giStyle.isShxFont()) { OdString fileName = giStyle.ttfdescriptor().fileName(); if (fileName.isEmpty()) { dbTs->setFileName(giStyle.ttfdescriptor().typeface()); } else if (OdDgnImportContext::getDgnImporter()) { OdString strFileExt = fileName; if (strFileExt.getLength() > 4) { strFileExt = strFileExt.right(4); strFileExt.makeUpper(); if (strFileExt != L".SHX") { if (OdDgnImportContext::getDgnImporter()) OdDgnImportContext::getDgnImporter()->createShxFontFromRscFont(fileName); fileName += L".shx"; } } dbTs->setFileName(fileName); } else { dbTs->setFileName(giStyle.getFontFilePath(pDb)); // ?? } dbTs->setBigFontFileName(giStyle.bigFontFileName()); } else { OdString Typeface; bool bold, italic; int nCharset, nPitchAndFamily; giStyle.font(Typeface, bold, italic, nCharset, nPitchAndFamily); dbTs->setFont(Typeface, bold, italic, nCharset, nPitchAndFamily); if (dbTs->fileName().isEmpty() && (Typeface.find(L".ttf") == -1) && (Typeface.find(L".TTF") == -1)) dbTs->setFileName(Typeface + L".ttf"); } OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(dbTs->objectId()); _idMap[i->item()] = dwgPath; addResourceId(dbTs->objectId()); } OdDgTextStyleTableRecordPtr pDefaultTextStyle = pDg->getTextStyleTable()->getDefaultData(); if( bSetDefaultTextSize && !pDefaultTextStyle.isNull() && !OdZero(pDefaultTextStyle->getTextHeight()) ) { if (!pDefaultModel.isNull()) pDb->setTEXTSIZE(pDefaultTextStyle->getTextHeight()*dUORsToModelScale); } } OdDbObjectId createTextStyleFromDimStyle( const OdDgDimStyleTableRecordPtr& pDgDimStyle, OdDbDatabase* pDb, double dTextHeight, double dTextWidth ) { OdDbObjectId idRet; OdGiTextStyle dimTextStyle; OdDgFontTableRecordPtr pFontRec; OdDgTextStyleTableRecordPtr pRec; OdDgTextStyleTableRecordPtr pTextStyle; if( pDgDimStyle->getTextStyleEntryId() > 0 ) { OdDgTextStyleTablePtr pTextStyleTable = pDgDimStyle->database()->getTextStyleTable(OdDg::kForRead); if( !pTextStyleTable.isNull() ) { OdDgElementId idTextStyle = pTextStyleTable->getAt( pDgDimStyle->getTextStyleEntryId() ); if( !idTextStyle.isNull() ) { pTextStyle = idTextStyle.openObject(OdDg::kForRead); } } } if( pTextStyle.isNull() ) pRec = pDgDimStyle->database()->getTextStyleTable()->getDefaultData(); else pRec = pTextStyle; OdUInt32 uFontId = pRec->getFontEntryId(); if( pDgDimStyle->getTextFontOverrideFlag() ) uFontId = pDgDimStyle->getTextFontId(); pFontRec = OdDgFontTable::getFont(pDgDimStyle->database(), uFontId); OdString strTTFFontName; if( pFontRec->getType() == kFontTypeRsc ) strTTFFontName = odDgnImportRscFontMapping(pFontRec->getName()); if (strTTFFontName.isEmpty() && !OdDgnImportContext::getImportFilledRscFonts() && (pFontRec->getType() == kFontTypeRsc)) { OdDgFontTablePtr pFontTable = pDgDimStyle->database()->getFontTable(); OdDgFontTablePEPtr pFontPE = OdDgFontTablePEPtr(OdRxObjectPtr(pFontTable)); if (!pFontPE.isNull() && pFontPE->isFilledRscFont(pFontTable, pFontRec->getName())) { pFontRec = pFontTable->getFont(pDgDimStyle->database()->appServices()->getAlternateFontName()); if (pFontRec.isNull()) pFontRec = pFontTable->getFont(pDgDimStyle->database()->appServices()->getFAST_FONT()); } } pRec->getGiTextStyle(dimTextStyle); dimTextStyle.setTextSize( dTextHeight ); dimTextStyle.setXScale( dTextWidth/dTextHeight ); dimTextStyle.setUnderlined( pDgDimStyle->getTextUnderlineFlag() ); if( !pFontRec.isNull() ) { if( !strTTFFontName.isEmpty() ) dimTextStyle.setFont(strTTFFontName, pRec->getBoldFlag(), pRec->getItalicsFlag(), 0, 0); else if( pFontRec->getType() == kFontTypeTrueType ) { dimTextStyle.setFont(pFontRec.get()->getName(), pRec->getBoldFlag(), pRec->getItalicsFlag(), 0, 0 ); } else if (OdDgnImportContext::getDgnImporter()) { OdString fileName = pFontRec.get()->getName(); OdString strFileExt = fileName; if (strFileExt.getLength() > 4) { strFileExt = strFileExt.right(4); strFileExt.makeUpper(); if (strFileExt != L".SHX") { if (OdDgnImportContext::getDgnImporter()) OdDgnImportContext::getDgnImporter()->createShxFontFromRscFont(fileName); fileName += L".shx"; } } dimTextStyle.setFont(fileName, false, false, 0, 0); dimTextStyle.setFileName(fileName); } dimTextStyle.loadStyleRec( pDb ); } dimTextStyle.setVertical(false); idRet = OdDgnImportContext::getStyleForDbText(pDb, dimTextStyle ); if( idRet.isNull() ) { idRet = OdDgnImportContext::createStyleForDbText(pDb, pDgDimStyle->database(), dimTextStyle, false ); } return idRet; } void DgnImporter::copyDimStyleProperties( const OdDgDimStyleTableRecordPtr& pDgDimStyle, OdDbDimStyleTableRecordPtr& pDbDimStyle, OdDbDatabase* pDb ) { OdString strName = pDgDimStyle->getName(); if( strName.isEmpty() ) strName = L"Default"; OdString repairedName; if( (OdDbSymUtil::repairSymbolName(repairedName, strName, pDb) == eOk) && !repairedName.isEmpty() ) strName = repairedName; pDbDimStyle->setName( strName ); // Angular data pDbDimStyle->setDimarcsym(0); OdUInt32 uAccur = 4; if( pDgDimStyle->getAngleAccuracy() >= 0 && pDgDimStyle->getAngleAccuracy() < 8 ) { uAccur = pDgDimStyle->getAngleAccuracy(); } pDbDimStyle->setDimadec(static_cast(uAccur)); if( pDgDimStyle->getAngleDisplayMode() == OdDgDimTextFormat::kAngle_Radian ) { pDbDimStyle->setDimaunit(3); } else if( pDgDimStyle->getAngleDisplayMode() == OdDgDimTextFormat::kAngle_C ) { pDbDimStyle->setDimaunit(2); } else if( pDgDimStyle->getShowAngleFormatFlag() ) { pDbDimStyle->setDimaunit(1); } else { pDbDimStyle->setDimaunit(0); } OdUInt32 uDimAZinValue = 0; if( !pDgDimStyle->getAngleLeadingZeroFlag() ) { uDimAZinValue += 1; } if( !pDgDimStyle->getAngleTrailingZerosFlag() ) { uDimAZinValue += 2; } pDbDimStyle->setDimazin( static_cast(uDimAZinValue) ); // Extension lines if( !pDgDimStyle->getExtensionLinesPresentFlag() ) { pDbDimStyle->setDimse1(true); pDbDimStyle->setDimse2(true); } else { bool bLeftLinePrsesnt = pDgDimStyle->getToolLeftExtLinesPresentFlag(OdDgDimension::kToolTypeSizeArrow); bool bRightLinePrsesnt = pDgDimStyle->getToolRightExtLinesPresentFlag(OdDgDimension::kToolTypeSizeArrow); bool bSetExtLinePresentLeftRight = true; for (OdUInt32 l = OdDgDimension::kToolTypeSizeStroke; l < OdDgDimension::kToolTypeCenter; l++) { if((l == OdDgDimension::kToolTypeRadius) || (l == OdDgDimension::kToolTypeDiameter) || (l == OdDgDimension::kToolTypeOrdinate) || (l == OdDgDimension::kToolTypeRadiusExtended) || (l == OdDgDimension::kToolTypeDiameterExtended) || (l == OdDgDimension::kToolTypeCenter) ) { continue; } if ((pDgDimStyle->getToolLeftExtLinesPresentFlag((OdDgDimension::ToolType)(l)) != bLeftLinePrsesnt) || (pDgDimStyle->getToolRightExtLinesPresentFlag((OdDgDimension::ToolType)(l)) != bRightLinePrsesnt) ) { bSetExtLinePresentLeftRight = false; break; } } if( bSetExtLinePresentLeftRight ) { pDbDimStyle->setDimse1(!bLeftLinePrsesnt); pDbDimStyle->setDimse2(!bRightLinePrsesnt); } else { pDbDimStyle->setDimse1(!pDgDimStyle->getExtensionLinesPresentFlag()); pDbDimStyle->setDimse2(!pDgDimStyle->getExtensionLinesPresentFlag()); } } // Dimension units bool bUseSecondaryUnits = false; if( pDgDimStyle->getShowSecondaryUnitsFlag() ) { bUseSecondaryUnits = true; } // Dimension Primary units // 1. leading and trailing zeros OdUInt32 uDimZinValue = 0; if( !pDgDimStyle->getPrimaryLeadingZeroFlag() ) { uDimZinValue += 4; } if( !pDgDimStyle->getPrimaryTrailingZerosFlag() ) { uDimZinValue += 8; } // 2. Scale factor of units and subunits OdString strPrimaryUnitsName; OdString strPrimarySubUnitsName; double dUORtoMasterScaleFactor = 1.0; OdDgModel::UnitDescription baseUnits; OdDgModel::UnitDescription masterUnits; OdDgModel::UnitDescription subUnits; baseUnits.m_numerator = 1.0; baseUnits.m_denominator = 1.0; OdDgModelPtr pDimensionModel; OdDgElementId idModel = pDgDimStyle->database()->getActiveModelId(); if( !idModel.isNull() ) { pDimensionModel = idModel.openObject(OdDg::kForRead); } if( !pDimensionModel.isNull() ) { pDimensionModel->getMasterUnit(baseUnits); pDimensionModel->getSubUnit(subUnits); masterUnits = baseUnits; dUORtoMasterScaleFactor = pDimensionModel->convertUORsToWorkingUnits(1.0); } if( !pDgDimStyle->getMasterFileUnitsFlag() ) { masterUnits = pDgDimStyle->getPrimaryMasterUnits(); subUnits = pDgDimStyle->getPrimarySubUnits(); } double dPrimaryUnitsScaleFactor = baseUnits.m_denominator / baseUnits.m_numerator / masterUnits.m_denominator * masterUnits.m_numerator; double dSubUnitsScaleFactor = masterUnits.m_denominator / masterUnits.m_numerator / subUnits.m_denominator * subUnits.m_numerator; pDbDimStyle->setDimcen(pDgDimStyle->getCenterMarkSize() * dUORtoMasterScaleFactor); // 3. Prefix and suffix for units and subunits OdString strPrefixSuffixMaster = OdString::kEmpty; OdString strPrefixSuffixSub = OdString::kEmpty; OdString strUnitPrefix; OdString strMasterLabel = masterUnits.m_name; OdString strSubLabel = subUnits.m_name; OdString strUnitSuffix; if( pDgDimStyle->getPrimaryLabelDisplayMode() == OdDgDimTextFormat::kMu || pDgDimStyle->getPrimaryLabelDisplayMode() == OdDgDimTextFormat::kMu_Su || pDgDimStyle->getPrimaryLabelDisplayMode() == OdDgDimTextFormat::kSu ) { strMasterLabel = OdString::kEmpty; strSubLabel = OdString::kEmpty; } if( bUseSecondaryUnits ) { strUnitPrefix = pDgDimStyle->getUpperPrefix(); strUnitSuffix = pDgDimStyle->getUpperSuffix(); } else { strUnitPrefix = pDgDimStyle->getMainPrefix(); strUnitSuffix = pDgDimStyle->getMainSuffix(); } if( strUnitPrefix[0] == L'\0' ) strUnitPrefix.empty(); if( strUnitSuffix[0] == L'\0' ) strUnitSuffix.empty(); strPrefixSuffixMaster = strUnitPrefix + L"<>" + strMasterLabel + strUnitSuffix; strPrefixSuffixSub = strSubLabel + strUnitSuffix; if( bUseSecondaryUnits ) { strPrefixSuffixMaster += L"\\X"; strPrefixSuffixSub += L"\\X"; if( pDgDimStyle->getTextUnderlineFlag() ) { strPrefixSuffixMaster += L"\\L"; strPrefixSuffixSub += L"\\L"; } } // 4. Accuracy OdUInt8 uDimUnitFormat = 2; OdUInt8 uDimPresission = 0; OdDgnImportContext::convertAccuracyToDwgFormat(pDgDimStyle->getPrimaryAccuracy(), uDimUnitFormat, uDimPresission ); pDbDimStyle->setDimlfac(dPrimaryUnitsScaleFactor); pDbDimStyle->setDimmzf( dSubUnitsScaleFactor ); pDbDimStyle->setDimrnd(0.0); pDbDimStyle->setDimdec( uDimPresission ); pDbDimStyle->setDimlunit( uDimUnitFormat ); pDbDimStyle->setDimdsep( pDgDimStyle->getDecimalCommaFlag() ? L',' : L'.'); pDbDimStyle->setDimzin( static_cast(uDimZinValue) ); pDbDimStyle->setDimpost( strPrefixSuffixMaster ); pDbDimStyle->setDimmzs( strPrefixSuffixSub ); // Dimension alternate units pDbDimStyle->setDimalt( bUseSecondaryUnits ); if( bUseSecondaryUnits ) { // 1. leading and trailing zeros uDimZinValue = 0; if( !pDgDimStyle->getSecondaryLeadingZeroFlag() ) { uDimZinValue += 4; } if( !pDgDimStyle->getSecondaryTrailingZerosFlag() ) { uDimZinValue += 8; } // 2. Scale factor of units and subunits OdString strSecondaryUnitsName; OdString strSecondarySubUnitsName; masterUnits = pDgDimStyle->getSecondaryMasterUnits(); subUnits = pDgDimStyle->getSecondarySubUnits(); double dSecondaryUnitsScaleFactor = baseUnits.m_denominator / baseUnits.m_numerator / masterUnits.m_denominator * masterUnits.m_numerator; double dSecondarySubUnitsScaleFactor = masterUnits.m_denominator / masterUnits.m_numerator / subUnits.m_denominator * subUnits.m_numerator; // 3. Prefix and suffix for units and subunits strPrefixSuffixMaster = OdString::kEmpty; strPrefixSuffixSub = OdString::kEmpty; strUnitPrefix = OdString::kEmpty; strMasterLabel = masterUnits.m_name; strSubLabel = subUnits.m_name; strUnitSuffix = OdString::kEmpty; if( pDgDimStyle->getSecondaryLabelDisplayMode() == OdDgDimTextFormat::kMu || pDgDimStyle->getSecondaryLabelDisplayMode() == OdDgDimTextFormat::kMu_Su || pDgDimStyle->getSecondaryLabelDisplayMode() == OdDgDimTextFormat::kSu ) { strMasterLabel = OdString::kEmpty; strSubLabel = OdString::kEmpty; } strUnitPrefix = pDgDimStyle->getLowerPrefix(); strUnitSuffix = pDgDimStyle->getLowerSuffix(); if( strUnitPrefix[0] == L'\0' ) strUnitPrefix.empty(); if( strUnitSuffix[0] == L'\0' ) strUnitSuffix.empty(); strPrefixSuffixMaster = strUnitPrefix + L"[]" + strMasterLabel + strUnitSuffix; strPrefixSuffixSub = strSubLabel + strUnitSuffix; // 4. Accuracy uDimUnitFormat = 2; uDimPresission = 0; OdDgnImportContext::convertAccuracyToDwgFormat(pDgDimStyle->getSecondaryAccuracy(), uDimUnitFormat, uDimPresission ); if( uDimUnitFormat == 5 ) // Fractional (stacked) { uDimUnitFormat = 7; // Fractional } pDbDimStyle->setDimaltf(dSecondaryUnitsScaleFactor); pDbDimStyle->setDimaltmzf( dSecondarySubUnitsScaleFactor ); pDbDimStyle->setDimaltrnd(0.0); pDbDimStyle->setDimaltd( uDimPresission ); pDbDimStyle->setDimaltu( uDimUnitFormat ); pDbDimStyle->setDimaltz( static_cast(uDimZinValue) ); pDbDimStyle->setDimapost( strPrefixSuffixMaster ); pDbDimStyle->setDimaltmzs( strPrefixSuffixSub ); } // Dimension Stacked fraction settings if( pDgDimStyle->getUseStackedFractionFlag() ) { pDbDimStyle->setDimfrac( 2 - (OdUInt8)(pDgDimStyle->getStackedFractionType()) ); } else { pDbDimStyle->setDimfrac(2); } // Calculate text height double dTextHeight = 1.0; double dTextWidth = 1.0; OdDgTextStyleTablePtr pTextStyle = pDgDimStyle->database()->getTextStyleTable(OdDg::kForRead); if( !pTextStyle->getAt(pDgDimStyle->getTextStyleEntryId()).isNull() ) { OdDgTextStyleTableRecordPtr pDimTextStyle = pTextStyle->getAt(pDgDimStyle->getTextStyleEntryId()).openObject(OdDg::kForRead); dTextHeight = pDimTextStyle->getTextHeight() * dUORtoMasterScaleFactor; dTextWidth = pDimTextStyle->getTextWidth() * dUORtoMasterScaleFactor; } if( pDgDimStyle->getTextHeightOverrideFlag() ) dTextHeight = pDgDimStyle->getTextHeight() * dUORtoMasterScaleFactor; if( pDgDimStyle->getTextWidthOverrideFlag() ) dTextWidth = pDgDimStyle->getTextWidth() * dUORtoMasterScaleFactor; // Dimension Tolerances bool bDisplayTolerance = false; if( pDgDimStyle->getShowToleranceFlag() && !OdZero(pDgDimStyle->getToleranceTextScale()*dTextHeight) && !OdZero(pDgDimStyle->getToleranceTextScale()*dTextWidth) ) { bDisplayTolerance = true; } pDbDimStyle->setDimtol(bDisplayTolerance); if( bDisplayTolerance ) { pDbDimStyle->setDimlim(pDgDimStyle->getUseToleranceLimitModeFlag()); double dLowTol = pDgDimStyle->getLowerToleranceValue() * dUORtoMasterScaleFactor; double dHighTol = pDgDimStyle->getUpperToleranceValue() * dUORtoMasterScaleFactor; if( OdZero(dLowTol - dHighTol) && pDgDimStyle->getToleranceStackIfEqualFlag() ) { dLowTol -= 1e-9; } pDbDimStyle->setDimtm( dLowTol ); pDbDimStyle->setDimtp( dHighTol ); pDbDimStyle->setDimtolj( 1 ); pDbDimStyle->setDimtfac( pDgDimStyle->getToleranceTextScale() ); uDimUnitFormat = 2; uDimPresission = 0; OdDgDimTextFormat::Accuracy dimAccuracy = pDgDimStyle->getPrimaryToleranceAccuracy(); OdDgnImportContext::convertAccuracyToDwgFormat( dimAccuracy , uDimUnitFormat, uDimPresission ); pDbDimStyle->setDimtdec( uDimPresission ); uDimUnitFormat = 2; uDimPresission = 0; dimAccuracy = pDgDimStyle->getSecondaryToleranceAccuracy(); OdDgnImportContext::convertAccuracyToDwgFormat(dimAccuracy, uDimUnitFormat, uDimPresission ); pDbDimStyle->setDimalttd( uDimPresission ); pDbDimStyle->setDimtzin(8); } // Dimension fit options. pDbDimStyle->setDimtofl( pDgDimStyle->getJoinerFlag() ); pDbDimStyle->setDimsoxd(true); OdDgDimTextInfo::FitOptions iFitMode = pDgDimStyle->getFitOptions(); pDbDimStyle->setDimatfit(3); switch( iFitMode ) { case OdDgDimTextInfo::kTermMovesFirst: { pDbDimStyle->setDimatfit(1); } break; case OdDgDimTextInfo::kTextInside: { pDbDimStyle->setDimtix(true); } break; case OdDgDimTextInfo::kTextMovesFirst: { pDbDimStyle->setDimatfit(2); } break; case OdDgDimTextInfo::kBothMoves: { pDbDimStyle->setDimatfit(0); } break; case OdDgDimTextInfo::kSmallestMoves: { pDbDimStyle->setDimatfit(3); } break; } if( pDgDimStyle->getDimLeaderEnableFlag() ) { OdDgDimOptionOffset::ChainType iLeaderType = pDgDimStyle->getDimLeaderChainType(); if( iLeaderType == OdDgDimOptionOffset::kNone ) { pDbDimStyle->setDimtmove(2); } else { pDbDimStyle->setDimtmove(1); } } else { pDbDimStyle->setDimtmove(0); } // Dimension text // 1.Text height pDbDimStyle->setDimtfill(0); if( !OdZero(dTextHeight) ) pDbDimStyle->setDimtxt( fabs(dTextHeight) ); pDbDimStyle->setDimtxtdirection(false); // 2.Text color OdCmColor textColor; OdUInt32 uTextColorIndex = pDgDimStyle->getDimensionColor(); if( pDgDimStyle->getTextColorOverrideFlag() ) { uTextColorIndex = pDgDimStyle->getTextColor(); } setDwgColorByDgnIndex( pDgDimStyle->database(), textColor, uTextColorIndex ); pDbDimStyle->setDimclrt( textColor ); // 3.Text direction if( pDgDimStyle->getHorizontalTextFlag() ) { pDbDimStyle->setDimtih(true); pDbDimStyle->setDimtoh(true); } else { pDbDimStyle->setDimtih(false); pDbDimStyle->setDimtoh(false); } // 4.Text offset and lift double dTextOffsetX = pDgDimStyle->getGeometryMargin(); if( pDgDimStyle->getCapsuleTextFlag() || pDgDimStyle->getBoxTextFlag() ) { dTextOffsetX *= -0.5; } pDbDimStyle->setDimgap( dTextOffsetX ); pDbDimStyle->setDimtvp( pDgDimStyle->getInlineTextLift() ); // 5. Text alignments OdDgDimTextInfo::TextLocation txtLocation = pDgDimStyle->getTextLocation() ; pDbDimStyle->setDimtad( (OdUInt8)(txtLocation) ); OdDgDimTextInfo::TextAlignment textAlm = pDgDimStyle->getTextJustification(); pDbDimStyle->setDimjust(0); if( textAlm == OdDgDimTextInfo::kLeftText ) { pDbDimStyle->setDimjust(1); } else if( textAlm == OdDgDimTextInfo::kRightText ) { pDbDimStyle->setDimjust(2); } // 6. Text style OdDbObjectId idDimTextStyle = createTextStyleFromDimStyle(pDgDimStyle, pDb, dTextHeight, dTextWidth); pDbDimStyle->setDimtxsty( idDimTextStyle ); // Arrows and lines pDbDimStyle->setDimexe( fabs(pDgDimStyle->getWitnessLineExtension()) ); pDbDimStyle->setDimexo( fabs(pDgDimStyle->getWitnessLineOffset()) ); pDbDimStyle->setDimsd1( false ); pDbDimStyle->setDimsd2( false ); OdUInt32 iDimColor = pDgDimStyle->getDimensionColor(); OdUInt32 iDimWeight = pDgDimStyle->getDimensionLineWeight(); OdUInt32 iDimStyle = pDgDimStyle->getDimensionLineStyleId(); OdUInt32 iExtColor = iDimColor; OdUInt32 iExtWeight = iDimWeight; OdUInt32 iExtStyle = iDimStyle; if( pDgDimStyle->getExtensionLineColorOverrideFlag() ) iExtColor = pDgDimStyle->getExtensionLineColor(); if( pDgDimStyle->getExtensionLineWeightOverrideFlag()) iExtWeight = pDgDimStyle->getExtensionLineWeight(); if( pDgDimStyle->getExtensionLineStyleOverrideFlag()) iExtStyle = pDgDimStyle->getExtensionLineStyleId(); OdCmColor extColor; setDwgColorByDgnIndex( pDgDimStyle->database(), extColor, iExtColor ); OdDb::LineWeight extWeight = odDgnImportLineweightMapping( iExtWeight ); OdDbObjectId lineTypeId; setDwgLineTypeIdByDgnLineTypeIndex( pDb, pDgDimStyle->database(), iExtStyle, lineTypeId ); pDbDimStyle->setDimclre( extColor); pDbDimStyle->setDimlwe( extWeight ); pDbDimStyle->setDimltex1( lineTypeId ); pDbDimStyle->setDimltex2( lineTypeId ); setDwgColorByDgnIndex( pDgDimStyle->database(), extColor, iDimColor ); extWeight = odDgnImportLineweightMapping( iDimWeight ); setDwgLineTypeIdByDgnLineTypeIndex( pDb, pDgDimStyle->database(), iDimStyle, lineTypeId ); pDbDimStyle->setDimclrd( extColor); pDbDimStyle->setDimlwd( extWeight ); pDbDimStyle->setDimltype( lineTypeId ); // Dimension arrow heads OdDgDimension::TerminatorArrowHeadType atype = pDgDimStyle->getTerminatorArrowHead(); if( atype > 2 ) atype = (OdDgDimension::TerminatorArrowHeadType)(atype & OdDgDimension::kClosed); double dArrowSize = pDgDimStyle->getTerminatorHeight() > pDgDimStyle->getTerminatorWidth() ? pDgDimStyle->getTerminatorHeight() : pDgDimStyle->getTerminatorWidth(); double dArrowWidth = 0.0; OdDbObjectId idArrow; switch( atype ) { case OdDgDimension::kClosed: { idArrow = OdDmUtil::getArrowId(L"_CLOSEDBLANK", pDb); } break; case OdDgDimension::kFilled: { idArrow = OdDmUtil::getArrowId(L"", pDb); } break; default: { idArrow = OdDmUtil::getArrowId(L"_OPEN", pDb); } break; } pDbDimStyle->setDimsah(true); pDbDimStyle->setDimblk1( idArrow ); pDbDimStyle->setDimblk2( idArrow ); pDbDimStyle->setDimasz( dArrowSize ); pDbDimStyle->setDimtsz( dArrowWidth ); } void DgnImporter::copyDimStyles(OdDgDatabase* pDg, OdDbDatabase* pDb, bool bCraeteDefaultDgnDimStyle ) { if( _properties->get_EraseUnusedResources() ) return; OdDgDimStyleTablePtr pDgDimStyleTable = pDg->getDimStyleTable(OdDg::kForRead); OdDbDimStyleTablePtr pDbDimStyleTable = pDb->getDimStyleTableId().openObject(OdDb::kForWrite); OdDgElementIteratorPtr pIter = pDgDimStyleTable->createIterator(); for(; !pIter->done(); pIter->step() ) { OdDgDimStyleTableRecordPtr pDgDimStyle = pIter->item().openObject(OdDg::kForRead); OdString strName = pDgDimStyle->getName(); if( strName.isEmpty() ) { OdDbDimStyleTableRecordPtr pDbDimStyle = OdDbDimStyleTableRecord::createObject(); copyDimStyleProperties(pDgDimStyle, pDbDimStyle, pDb); if (!bCraeteDefaultDgnDimStyle) { pDbDimStyle->setName(L"Standard"); OdDbObjectId idDefaultDimStyle = pDb->getDIMSTYLE(); if (!idDefaultDimStyle.isNull()) { OdDbDimStyleTableRecordPtr pDefaultDimStyle = idDefaultDimStyle.openObject(OdDb::kForWrite); OdString strDefName = pDefaultDimStyle->getName(); pDefaultDimStyle->copyFrom(pDbDimStyle); pDefaultDimStyle->setName(strDefName); OdDgnImportContext::setDefaultDgnDimStyle(pDefaultDimStyle->id()); } else { pDbDimStyleTable->add(pDbDimStyle); pDb->setDIMSTYLE(pDbDimStyle->id()); OdDgnImportContext::setDefaultDgnDimStyle(pDbDimStyle->id()); } } else { pDbDimStyle->setName(L"DgnDefault"); if (pDbDimStyleTable->getAt(pDbDimStyle->getName()).isNull()) { pDbDimStyleTable->add(pDbDimStyle); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pDbDimStyle->objectId()); _idMap[pIter->item()] = dwgPath; } else { pDbDimStyle = pDbDimStyleTable->getAt(pDbDimStyle->getName()).openObject(OdDb::kForRead); } OdDgnImportContext::setDefaultDgnDimStyle(pDbDimStyle->id()); } OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pDbDimStyle->objectId()); _idMap[pIter->item()] = dwgPath; } else { if (pDbDimStyleTable->getAt(strName).isNull()) { OdDbDimStyleTableRecordPtr pDbDimStyle = OdDbDimStyleTableRecord::createObject(); copyDimStyleProperties(pDgDimStyle, pDbDimStyle, pDb); pDbDimStyleTable->add(pDbDimStyle); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(pDbDimStyle->objectId()); _idMap[pIter->item()] = dwgPath; } } } } void DgnImporter::copyDisplayStyles(OdDgDatabase* pDg, OdDbDatabase* pDb) { OdDgDisplayStyleTablePtr pDisplayStyleTable = pDg->getDisplayStyleTable(OdDg::kForRead); OdDbDictionaryPtr pDic; if( !pDisplayStyleTable.isNull() && pDb ) { pDic = pDb->getVisualStyleDictionaryId(true).openObject( OdDb::kForWrite ); OdDgElementIteratorPtr pDisplayStyleIter = pDisplayStyleTable->createIterator(); for(; !pDisplayStyleIter->done(); pDisplayStyleIter->step()) { OdDgDisplayStyleTableRecordPtr pDisplayStyle = pDisplayStyleIter->item().openObject(OdDg::kForRead); OdDbVisualStylePtr pVisualStyle = OdDbVisualStyle::createObject(); if( pDic->getAt(pDisplayStyle->getName()).isNull() ) { pVisualStyle->setDescription( OdString::kEmpty ); pVisualStyle->setType( OdGiVisualStyle::kCustom); OdGiDisplayStylePtr giDisplayStyle = pVisualStyle->createDisplayStyle(); OdGiFaceStylePtr giFaceStyle = pVisualStyle->createFaceStyle(); OdGiEdgeStylePtr giEdgeStyle = pVisualStyle->createEdgeStyle(); giDisplayStyle->setBrightness(0.0); giDisplayStyle->setShadowType( pDisplayStyle->getDisplayShadowsFlag()? OdGiDisplayStyle::kShadowsFull : OdGiDisplayStyle::kShadowsNone ); giDisplayStyle->setDisplaySettingsFlag( OdGiDisplayStyle::kBackgrounds, pDisplayStyle->getUseBackgroundColorOverrideFlag() ? true : false); giDisplayStyle->setDisplaySettingsFlag( OdGiDisplayStyle::kMaterials, pDisplayStyle->getDisplayMode() == OdDgDisplayStyleTableRecord::kShaded ? true : false ); giDisplayStyle->setDisplaySettingsFlag( OdGiDisplayStyle::kLights, pDisplayStyle->getSmoothIgnoreLightsFlag() ? false : true ); giDisplayStyle->setDisplaySettingsFlag( OdGiDisplayStyle::kTextures, pDisplayStyle->getIgnorePatternMapsFlag() ? false : true ); switch( pDisplayStyle->getDisplayMode() ) { case OdDgDisplayStyleTableRecord::kWireframe: { giFaceStyle->setLightingModel( OdGiFaceStyle::kInvisible ); giFaceStyle->setFaceColorMode( OdGiFaceStyle::kNoColorMode ); giFaceStyle->setLightingQuality( OdGiFaceStyle::kNoLighting); giEdgeStyle->setEdgeModel( OdGiEdgeStyle::kIsolines ); } break; case OdDgDisplayStyleTableRecord::kFilledVisibleEdges: { giFaceStyle->setLightingModel( OdGiFaceStyle::kConstant ); giFaceStyle->setLightingQuality( OdGiFaceStyle::kNoLighting); if( pDisplayStyle->getUseElementColorOverrideFlag() ) { giFaceStyle->setFaceColorMode( OdGiFaceStyle::kMono ); ODCOLORREF clrElement = OdDgColorTable::lookupRGB( pDg, pDisplayStyle->getElementColor() ); OdDgCmColor faceMonoColor; faceMonoColor.setRGB( ODGETRED(clrElement), ODGETGREEN(clrElement), ODGETBLUE(clrElement)); giFaceStyle->setMonoColor( faceMonoColor, true ); } else { giFaceStyle->setFaceColorMode( OdGiFaceStyle::kObjectColor ); } giEdgeStyle->setEdgeModel( OdGiEdgeStyle::kIsolines ); } break; case OdDgDisplayStyleTableRecord::kVisibleEdges: { giFaceStyle->setLightingModel( OdGiFaceStyle::kConstant ); giFaceStyle->setFaceColorMode( OdGiFaceStyle::kBackgroundColor ); giFaceStyle->setLightingQuality( OdGiFaceStyle::kNoLighting); giEdgeStyle->setEdgeModel( OdGiEdgeStyle::kIsolines ); } break; case OdDgDisplayStyleTableRecord::kShaded: { giFaceStyle->setLightingModel( OdGiFaceStyle::kPhong ); if( pDisplayStyle->getUseElementColorOverrideFlag() ) { giFaceStyle->setFaceColorMode( OdGiFaceStyle::kMono ); ODCOLORREF clrElement = OdDgColorTable::lookupRGB( pDg, pDisplayStyle->getElementColor() ); OdDgCmColor faceMonoColor; faceMonoColor.setRGB( ODGETRED(clrElement), ODGETGREEN(clrElement), ODGETBLUE(clrElement)); giFaceStyle->setMonoColor( faceMonoColor, true ); } else { giFaceStyle->setFaceColorMode( OdGiFaceStyle::kNoColorMode ); } if( pDisplayStyle->getSmoothIgnoreLightsFlag() ) { giFaceStyle->setLightingModel( OdGiFaceStyle::kConstant ); giFaceStyle->setLightingQuality( OdGiFaceStyle::kNoLighting ); } else { giFaceStyle->setLightingQuality( OdGiFaceStyle::kPerVertexLighting ); } if( pDisplayStyle->getDisplayVisibleEdgesFlag() ) { giEdgeStyle->setEdgeModel( OdGiEdgeStyle::kIsolines ); } else { giEdgeStyle->setEdgeModel( OdGiEdgeStyle::kNoEdges ); } } break; } if( pDisplayStyle->getUseElementTransparencyOverrideFlag() ) { giFaceStyle->setFaceModifierFlag( OdGiFaceStyle::kOpacity, true ); giFaceStyle->setOpacityLevel( 1.0 - pDisplayStyle->getElementTransparency(), true ); } if( pDisplayStyle->getUseVisibleEdgeColorFlag() ) { ODCOLORREF clrElement = OdDgColorTable::lookupRGB( pDg, pDisplayStyle->getVisibleEdgeColor() ); OdDgCmColor elmColor; elmColor.setRGB( ODGETRED(clrElement), ODGETGREEN(clrElement), ODGETBLUE(clrElement)); giEdgeStyle->setEdgeColor( elmColor, true ); } else if( pDisplayStyle->getUseElementColorOverrideFlag() ) { ODCOLORREF clrElement = OdDgColorTable::lookupRGB( pDg, pDisplayStyle->getElementColor() ); OdDgCmColor elmColor; elmColor.setRGB( ODGETRED(clrElement), ODGETGREEN(clrElement), ODGETBLUE(clrElement)); giEdgeStyle->setEdgeColor( elmColor, true ); } else { giEdgeStyle->setEdgeModifierFlag(OdGiEdgeStyle::kColor, false); } if( pDisplayStyle->getUseVisibleEdgeWeightFlag() ) { giEdgeStyle->setEdgeWidth(pDisplayStyle->getVisibleEdgeWeight(), true ); } else if( pDisplayStyle->getUseElementLineWeightOverrideFlag() ) { giEdgeStyle->setEdgeWidth(pDisplayStyle->getElementLineWeight(), true ); } else { giEdgeStyle->setEdgeModifierFlag(OdGiEdgeStyle::kWidth, false); } if( pDisplayStyle->getUseHiddenEdgeLineStyleFlag() ) { switch( pDisplayStyle->getHiddenEdgeLineStyle() ) { case OdDgDisplayStyleTableRecord::kDotted: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kDotted ); break; case OdDgDisplayStyleTableRecord::kDashed: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kDashed ); break; case OdDgDisplayStyleTableRecord::kLongDash: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kLongDash); break; case OdDgDisplayStyleTableRecord::kDashDot: case OdDgDisplayStyleTableRecord::kShortLongDash: case OdDgDisplayStyleTableRecord::kDashDotDot: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kMediumLongDash); break; case OdDgDisplayStyleTableRecord::kShortDash: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kShortDash); break; default: giEdgeStyle->setObscuredLinetype( OdGiEdgeStyle::kDotted ); break; }; } giEdgeStyle->setEdgeStyleFlag( OdGiEdgeStyle::kObscured, pDisplayStyle->getDisplayHiddenEdgesFlag() ? true : false ); pVisualStyle->setDisplayStyle( *giDisplayStyle ); pVisualStyle->setEdgeStyle( *giEdgeStyle ); pVisualStyle->setFaceStyle( *giFaceStyle ); pVisualStyle->setInternalUseOnly( pDisplayStyle->getHideInPickerFlag() ); pDic->setAt( pDisplayStyle->getName(), pVisualStyle); OdDbObjectId idStyle = pVisualStyle->objectId(); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(idStyle); _idMap[pDisplayStyle->elementId()] = dwgPath; } } } } void DgnImporter::copyMLineStyles(OdDgDatabase* pDg, OdDbDatabase* pDb, const OdDgModelPtr& pBaseModel ) { OdDgMultilineStyleTablePtr pMLineStyleTable = pDg->getMultilineStyleTable(OdDg::kForRead); if( pMLineStyleTable.isNull() ) { return; } double dScale = 1.0; if( !pBaseModel.isNull() ) { dScale = pBaseModel->convertUORsToWorkingUnits(1.0); } OdDgElementIteratorPtr pIter = pMLineStyleTable->createIterator(); for(; !pIter->done(); pIter->step() ) { OdDgMultilineStyleTableRecordPtr pMLineStyle = pIter->item().openObject(OdDg::kForRead); OdDgnImportMultilineDescriptor styleDesc; styleDesc.m_bTableMLineStyle = true; styleDesc.m_uMLineStyle = (OdUInt64)(pMLineStyle->elementId().getHandle()); styleDesc.m_uJustification = 0; styleDesc.m_strStyleName = pMLineStyle->getName(); if( styleDesc.m_strStyleName.isEmpty() ) { styleDesc.m_strStyleName = OD_T("Default"); } OdDgMultilineSymbology startCap; OdDgMultilineSymbology endCap; OdDgMultilineSymbology middleCap; pMLineStyle->getOriginCap(startCap); pMLineStyle->getEndCap(endCap); pMLineStyle->getMiddleCap( middleCap ); bool bFillMLine = pMLineStyle->getUseFillColorFlag(); OdUInt32 uFillColor = pMLineStyle->getFillColorIndex(); styleDesc.m_bShowJoints = middleCap.getCapLineFlag(); styleDesc.m_bShowStartCapLine = startCap.getCapLineFlag(); styleDesc.m_bShowStartCapInArc = startCap.getCapInArcFlag(); styleDesc.m_bShowStartCapOutArc = startCap.getCapOutArcFlag(); styleDesc.m_bShowEndCapLine = endCap.getCapLineFlag(); styleDesc.m_bShowEndCapInArc = endCap.getCapInArcFlag(); styleDesc.m_bShowEndCapOutArc = endCap.getCapOutArcFlag(); styleDesc.m_dStartCapAngle = pMLineStyle->getOriginCapAngle() / 180.0 * OdaPI; styleDesc.m_dEndCapAngle = pMLineStyle->getEndCapAngle() / 180.0 * OdaPI; styleDesc.m_bShowFill = bFillMLine; styleDesc.m_uFillColor = uFillColor; for( OdUInt32 i = 0; i < pMLineStyle->getProfilesCount(); i++ ) { OdDgMultilineProfile curProfile; pMLineStyle->getProfile( i, curProfile ); styleDesc.m_arrOffsets.push_back( curProfile.getDistance()*dScale ); styleDesc.m_arrColorIndexes.push_back( curProfile.symbology().getColorIndex() ); styleDesc.m_arrLineStyles.push_back( curProfile.symbology().getLineStyleEntryId() ); } OdDbObjectId idStyle = OdDgnImportContext::createMultilineStyle( styleDesc, pDb, pDg ); OdDgnImportPathToDwgObject dwgPath; dwgPath.m_bExists = true; dwgPath.m_idPath.objectIds().push_back(idStyle); _idMap[pIter->item()] = dwgPath; addResourceId(idStyle); } } void normalizeMinMax( double &newMin, double &newMax ) { if (newMin < 0) newMin = 0; if (newMax > 1) newMax = 1; } static void copyViewport(OdDgView* pDgView, OdAbstractViewPE* pView, OdRxObject* dbView) { // conversion algorithm is copypasted from OdDgGsManager::_setupDesignModelView double dFrontClip, dBackClip; // model OdGePoint3d ptGlobalOriginOffset = OdGePoint3d::kOrigin; OdDgElementId idModel = pDgView->getModelId(); if( !idModel.isNull() ) { OdDgModelPtr pModel = idModel.openObject(OdDg::kForRead); if( !pModel.isNull() && !pModel->isGlobalOriginEnabled() ) ptGlobalOriginOffset = pModel->getGlobalOrigin(); } if (pDgView->getUseCameraFlag()) { OdGeMatrix3d rotation; OdGeVector3d upVector = OdGeVector3d::kYAxis, zVector = OdGeVector3d::kZAxis; OdGePoint3d cameraPosition; pDgView->getCameraPosition( cameraPosition ); pDgView->getCameraRotation( rotation ); rotation.transposeIt(); cameraPosition -= ptGlobalOriginOffset.asVector(); OdGeVector3d xVector = OdGeVector3d::kXAxis; upVector.transformBy( rotation ); zVector.transformBy( rotation ); pView->setView(dbView, cameraPosition, zVector, upVector, 1., 1., true ); //TD manages it as a camera with fixed size, so we should juggle with a kind of crop-factor { //take a native rectangle OdGeExtents2d visibleRectangle; pDgView->getCameraVisibleRectangle( visibleRectangle ); OdGePoint2d min = visibleRectangle.minPoint(), max = visibleRectangle.maxPoint(); //emulate new lens double oldFocus = pDgView->getCameraFocalLength(); double newFocus; { double a = fabs( min.x ), b = fabs( min.y ), c = fabs( max.x ), d = fabs( max.y ); double maxX = a > c ? a : c, maxY = b > d ? b : d; double focusX = .018 * oldFocus / maxX, focusY = .012 * oldFocus / maxY; //TD uses 36*24mm camera newFocus = focusX < focusY ? focusX : focusY; } double newMin, newMax; //right edge sticks to the right edge of the view (left one goes outside) if( fabs( min.x ) < fabs( max.x ) ) { newMax = 1.; newMin = 1. - 2. * max.x / ( max.x - min.x ); } //left edge stick to the left edge of the view (right one goes outside right) else { newMin = 0.; newMax = -2. * min.x / ( max.x - min.x ); } normalizeMinMax(newMin, newMax); min.x = newMin; max.x = newMax; //the same for bottom/top edges if( fabs( min.y ) < fabs( max.y ) ) { newMax = 1.; newMin = 1. - 2. * max.y / ( max.y - min.y ); } else { newMin = 0.; newMax = -2. * min.y / ( max.y - min.y ); } normalizeMinMax(newMin, newMax); min.y = newMin; max.y = newMax; //try to set it pView->setLensLength(dbView, newFocus * 1000. ); //it was in meters and is needed as millimeters pView->setViewport(dbView, min, max ); dFrontClip = pDgView->getCameraFrontClippingDistance(); dBackClip = pDgView->getCameraBackClippingDistance(); } } else { OdGeMatrix3d rotation; pDgView->getOrthographyRotation( rotation ); rotation.transposeIt(); //it is an inversion for correct matrices of rotation //apply that rotation OdGeVector3d upVector = OdGeVector3d::kYAxis, rightVector = OdGeVector3d::kXAxis, directionVector = OdGeVector3d::kZAxis; upVector.transformBy( rotation ); directionVector.transformBy( rotation ); rightVector = upVector.crossProduct(directionVector); //get the central point (target) and the extent double width, height; OdGePoint3d target; { OdGeExtents3d visibleRectangle; pDgView->getOrthographyVisibleBox( visibleRectangle ); const OdGePoint3d &min = visibleRectangle.minPoint(), &max = visibleRectangle.maxPoint(); target = ( min + max.asVector() ) / 2.; target.transformBy( rotation ); target -= directionVector; width = fabs(max.x - min.x); height = fabs(max.y - min.y); } OdGePoint3d ptPosition = pDgView->getOrthographyPosition(); OdGeVector3d vrPosDirection = directionVector; OdGePlane targetPlane( target, directionVector ); OdGePoint3d ptPositionProject = ptPosition.orthoProject(targetPlane); double dPosDistance = ptPosition.distanceTo(ptPositionProject); if( OdZero(dPosDistance) ) { dPosDistance = 1.0; } else { vrPosDirection = ptPosition - ptPositionProject; vrPosDirection.normalize(); } OdGePoint3d ptPositionNew = target + vrPosDirection*dPosDistance - ptGlobalOriginOffset.asVector(); pView->setView(dbView, ptPositionNew - directionVector, directionVector, upVector, width, height, false ); dFrontClip = pDgView->getOrthographyFrontClippingDistance(); dBackClip = pDgView->getOrthographyBackClippingDistance(); } if( pDgView->getShowClipFrontFlag() ) { pView->setFrontClipOn(dbView, true); pView->setFrontClipDistance(dbView, 1 - dFrontClip ); pView->setFrontClipAtEyeOn( dbView, false); } if( pDgView->getShowClipBackFlag() ) { pView->setBackClipOn(dbView, true); pView->setBackClipDistance(dbView, 1 - dBackClip ); } OdDgDisplayStyleViewPEPtr pDisplayStyleViewPE = pDgView; if( !pDisplayStyleViewPE.isNull() && !pDisplayStyleViewPE->getDisplayStyle(pDgView).isNull() ) { OdDbObjectId idVisualStyle = OdDgnImportContext::getObjectId(pDisplayStyleViewPE->getDisplayStyle(pDgView)); if( !idVisualStyle.isNull() ) { OdDbVisualStylePtr pVisualStyle = idVisualStyle.openObject(OdDb::kForRead); const OdGiFaceStyle& faceStyle = pVisualStyle->faceStyle(); OdDb::RenderMode rm = OdDb::k2DOptimized; switch( faceStyle.lightingModel() ) { case OdGiFaceStyle::kInvisible: rm = OdDb::k2DOptimized; break; case OdGiFaceStyle::kConstant: rm = OdDb::kHiddenLine; break; case OdGiFaceStyle::kPhong: rm = OdDb::kGouraudShaded; break; } pView->setRenderMode( dbView, rm ); pView->setVisualStyle(dbView, idVisualStyle); } } } void DgnImporter::setLayoutViewport(OdDgDatabase* pDg, const OdDbObjectId& idLayout, const OdDgModelPtr& pBaseModel) { OdInt32 uViewIndex = _properties->get_ImportViewIndex(); OdDgViewGroupPtr viewGroup; if (!pDg->getActiveViewGroupId().isNull()) { viewGroup = pDg->getActiveViewGroupId().openObject(OdDg::kForRead); if (viewGroup.isNull() || viewGroup->getModelId() != pBaseModel->elementId()) viewGroup = NULL; } OdDgViewGroupTablePtr pViewGroupTable = pDg->getViewGroupTable(OdDg::kForRead); if (viewGroup.isNull() && !pViewGroupTable.isNull() && !pBaseModel.isNull()) { OdDgElementIteratorPtr pVgIter = pViewGroupTable->createIterator(); for (; !pVgIter->done(); pVgIter->step()) { OdDgViewGroupPtr pVg = pVgIter->item().openObject(OdDg::kForRead); if (!pVg.isNull() && pVg->getModelId() == pBaseModel->elementId()) { viewGroup = pVg; break; } } } else if (viewGroup.isNull()) { viewGroup = OdDgViewGroup::cast(pDg->getActiveViewGroupId().openObject()); } if (!viewGroup.isNull()) { OdDgElementIteratorPtr iterator = viewGroup->createIterator(); OdDgViewPtr pDgView0; bool bCreateActiveViewport = false; while (!iterator->done()) { OdDgViewPtr pDgView = OdDgView::cast(iterator->item().openObject()); if (pDgView0.isNull()) { pDgView0 = pDgView; } if (uViewIndex >= 0 && uViewIndex < 8) { if (pDgView->getIndex() != uViewIndex) { iterator->step(); continue; } } else { if (!pDgView->getVisibleFlag()) { iterator->step(); continue; } else { _properties->put_ImportViewIndex(static_cast(pDgView->getIndex())); } } bCreateActiveViewport = true; OdDbLayoutPtr pLayout = idLayout.openObject(OdDb::kForRead); OdDbObjectId idViewport = pLayout->activeViewportId(); if( !idViewport.isNull() ) { OdDbViewportPtr pViewport = idViewport.openObject(OdDb::kForWrite); OdAbstractViewPEPtr pView = OdAbstractViewPE::cast(pViewport); copyViewport(pDgView, pView, pViewport); } break; } if (!bCreateActiveViewport) { OdDbLayoutPtr pLayout = idLayout.openObject(OdDb::kForRead); OdDbObjectId idViewport = pLayout->activeViewportId(); if (!idViewport.isNull()) { OdDbViewportPtr pViewport = idViewport.openObject(OdDb::kForWrite); OdAbstractViewPEPtr pView = OdAbstractViewPE::cast(pViewport); copyViewport(pDgView0, pView, pViewport); } } } } void DgnImporter::copyViewports(OdDgDatabase* pDg, OdDbDatabase* pDb, const OdDgModelPtr& pBaseModel ) { OdInt32 uViewIndex = _properties->get_ImportViewIndex(); OdDgViewGroupPtr viewGroup; if( !pDg->getActiveViewGroupId().isNull() ) { viewGroup = pDg->getActiveViewGroupId().openObject(OdDg::kForRead); if (viewGroup.isNull() || viewGroup->getModelId() != pBaseModel->elementId()) viewGroup = NULL; } OdDgViewGroupTablePtr pViewGroupTable = pDg->getViewGroupTable(OdDg::kForRead); if( viewGroup.isNull() && !pViewGroupTable.isNull() && !pBaseModel.isNull() ) { OdDgElementIteratorPtr pVgIter = pViewGroupTable->createIterator(); for(; !pVgIter->done(); pVgIter->step() ) { OdDgViewGroupPtr pVg = pVgIter->item().openObject(OdDg::kForRead); if( !pVg.isNull() && pVg->getModelId() == pBaseModel->elementId() ) { viewGroup = pVg; break; } } } else if( viewGroup.isNull() ) { viewGroup = OdDgViewGroup::cast(pDg->getActiveViewGroupId().openObject()); } if (!viewGroup.isNull()) { OdDgElementIteratorPtr iterator = viewGroup->createIterator(); OdDgViewPtr pDgView0; bool bCreateActiveViewport = false; while( !iterator->done() ) { OdDgViewPtr pDgView = OdDgView::cast(iterator->item().openObject()); if( pDgView0.isNull() ) { pDgView0 = pDgView; } if( uViewIndex >= 0 && uViewIndex < 8 ) { if( pDgView->getIndex() != uViewIndex ) { iterator->step(); continue; } } else { if( !pDgView->getVisibleFlag() ) { iterator->step(); continue; } else { _properties->put_ImportViewIndex( static_cast(pDgView->getIndex()) ); } } bCreateActiveViewport = true; OdDbViewportTablePtr vt = pDb->getViewportTableId().safeOpenObject(); OdDbViewportTableRecordPtr dbView = vt->getActiveViewportId().safeOpenObject(OdDb::kForWrite); OdAbstractViewPEPtr pView = OdAbstractViewPE::cast(dbView); copyViewport(pDgView, pView, dbView); break; } if( !bCreateActiveViewport ) { OdDbViewportTablePtr vt = pDb->getViewportTableId().safeOpenObject(); OdDbViewportTableRecordPtr dbView = vt->getActiveViewportId().safeOpenObject(OdDb::kForWrite); OdAbstractViewPEPtr pView = OdAbstractViewPE::cast(dbView); copyViewport(pDgView0, pView, dbView); } } // TODO: other viewports } void DgnImporter::copyNamedViews(OdDgDatabase* pDg, OdDbDatabase* pDb) { OdDbViewTablePtr vt = pDb->getViewTableId().safeOpenObject(OdDb::kForWrite); for (OdDgElementIteratorPtr i = pDg->getNamedViewTable()->createIterator(); !i->done(); i->step()) { OdDgViewPtr v = i->item().safeOpenObject(); OdString name = v->getName(), repairedName; if ( OdDbSymUtil::repairSymbolName(repairedName, name, pDb) == eOk && !repairedName.isEmpty()) name = repairedName; if (vt->has(name) || name.isEmpty()) continue; OdDbViewTableRecordPtr dbView = OdDbViewTableRecord::createObject(); dbView->setName(name); OdDbObjectId idItem = pDb->getOdDbObjectId( OdDbHandle((OdUInt64)(i->item().getHandle()))); if( idItem.isNull() ) { pDb->addOdDbObject(dbView, vt->objectId(), i->item().getHandle()); } else { pDb->addOdDbObject(dbView, vt->objectId() ); } vt->add(dbView); OdDgModelPtr m = v->getModelId().openObject(); if (!m.isNull() && m->getType() == OdDgModel::kSheetModel) { dbView->setIsPaperspaceView(true); name = m->getName(); if ( OdDbSymUtil::repairSymbolName(repairedName, name, pDb) == eOk && !repairedName.isEmpty()) name = repairedName; dbView->setLayout(pDb->findLayoutNamed(name)); } if (v->getUseCameraFlag()) { dbView->setPerspectiveEnabled(true); OdGePoint3d position; v->getCameraPosition(position); OdGeMatrix3d rotation; v->getCameraRotation(rotation); dbView->setLensLength(v->getCameraFocalLength()); //dbView->set OdGeExtents2d extent; v->getCameraVisibleRectangle(extent); dbView->setFrontClipDistance(v->getCameraFrontClippingDistance()); dbView->setBackClipDistance(v->getCameraBackClippingDistance()); //double v->getCameraLensAngle() const; //v-> } else { dbView->setPerspectiveEnabled(false); OdGeExtents3d box; v->getOrthographyVisibleBox(box); OdGeMatrix3d rotation; v->getOrthographyRotation(rotation); dbView->setFrontClipDistance(v->getOrthographyFrontClippingDistance()); dbView->setBackClipDistance(v->getOrthographyBackClippingDistance()); dbView->setTarget(v->getOrthographyPosition()); } } } //-------------------------------------------------------------------------------------------------------------- extern bool getActualXRefLevelMask(const OdDgReferenceAttachmentHeader* pXRef, OdUInt32 uViewNumber, OdDgLevelMaskPtr& pLevelMask); //-------------------------------------------------------------------------------------------------------------- void DgnImporter::setModelLevelMask( OdDgModel* m, OdInt8 iViewIndex ) { if( m && (iViewIndex >= 0) && (iViewIndex < 8) ) { bool bLevelMaskAdded = false; if( !OdDgnImportContext::getActiveXRefId().isNull() ) { OdDgReferenceAttachmentHeaderPtr pActiveXRef = OdDgnImportContext::getActiveXRefId().openObject(OdDg::kForRead); OdDgnImportContext::removeLastXRef(); OdDgLevelMaskPtr pLevelMask; getActualXRefLevelMask(pActiveXRef, iViewIndex, pLevelMask); OdDgnImportContext::restoreLastXRef(); if (!pLevelMask.isNull()) { OdDgnImportContext::pushLevelMask(pLevelMask, m->database()->getLevelTable(OdDg::kForRead), true); bLevelMaskAdded = true; } } if( !bLevelMaskAdded ) { OdDgViewPtr pActualView = getActualDgnView(m, iViewIndex); if( !pActualView.isNull() ) { OdDgElementIteratorPtr pLMIter = pActualView->createIterator(); if (!pLMIter->done()) { OdDgLevelMaskPtr pLevelMask = pLMIter->item().openObject(OdDg::kForRead); if (!pLevelMask.isNull()) { OdDgnImportContext::pushLevelMask(pLevelMask, m->database()->getLevelTable(OdDg::kForRead), true); bLevelMaskAdded = true; } } } } if( !bLevelMaskAdded ) { OdDgLevelMaskPtr pLevelMask; OdDgnImportContext::pushLevelMask(pLevelMask, m->database()->getLevelTable(OdDg::kForRead), true); } } } //-------------------------------------------------------------------------------------------------------------- void DgnImporter::removeModelLevelMask() { OdDgnImportContext::popLevelMask(); } }