/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// // ODA Platform #include "OdaCommon.h" #include "RxDynamicModule.h" #include "RxVariantValue.h" #include "RxObject.h" #include "RxInit.h" #include "DynamicLinker.h" #include "TvFactory.h" #include "TvFilerTimer.h" #include "TvModuleNames.h" #include "TvDatabaseCleaner.h" #include "TvDatabaseUtils.h" #include "ColorMapping.h" #include "daiDeviationParams.h" #include "Common/daiModuleNames.h" #include "Iges2Visualize.h" #include "IGES/Core/IgesGiContext.h" #include "IGES/Core/IgesModelContext.h" #include "IGES/Core/IgesFile.h" #include "daiAggr/daiSet.h" #include "daiSettings.h" #include "daiError/daiErrorEvent.h" #include #include #include using namespace IGES2Visualize; OdTv::Units getUnits(IgesFilePtr pIgesDatabase, double& addUnitCoefToMeters) { OdTv::Units tvUnits = OdTv::kMeters; addUnitCoefToMeters = 1.; /* OdQif::OdQifFileUnitsPtr fileUnits = pIgesDatabase->fileUnits(); if (fileUnits) { OdQif::OdQifPrimaryUnitsPtr primaryUnits = fileUnits->primaryUnits(); if (primaryUnits) { OdQif::OdQifLinearUnitPtr linearUnit = primaryUnits->linearUnit(); if (linearUnit) { OdAnsiString SIUnitName = linearUnit->siUnitName(); SIUnitName.makeUpper(); OdAnsiString UnitName = linearUnit->unitName(); UnitName.makeUpper(); if (linearUnit->unitConversion()) { double factor = linearUnit->unitConversion()->factor(); double offset = linearUnit->unitConversion()->offset(); } if (UnitName == "MM") { tvUnits = OdTv::kMillimeters; } else if (UnitName == "M") { tvUnits = OdTv::kMeters; } else if (UnitName == "INCH") { tvUnits = OdTv::kInches; } else { ODA_FAIL_M_ONCE("Units not supported."); } } else { tvUnits = OdTv::kUserDefined; ODA_FAIL_M_ONCE("TODO: Other units processing."); } } } */ return tvUnits; } //***************************************************************************// // 'OdTvVisualizeIgesFilerProperties' methods implementation //***************************************************************************// OdTvVisualizeIgesFilerProperties::OdTvVisualizeIgesFilerProperties() : m_flags(0) , m_pPalette(0) , m_pCallback(NULL) , m_minPerCircle(8) , m_maxPerCircle(128) , m_deviation(0.5) , m_modelerType(0) , m_brepToleranceType(0) , m_brepToleranceDynamic(0.0001) , m_brepToleranceStatic(0.01) , m_pHostAppProgressMeter(NULL) , m_customBgTypeValue(0) , m_envBackgroundParam (nullptr) , m_pInterruptCallback(0) { m_importRect.xmax = 0; m_importRect.xmin = 0; m_importRect.ymax = 0; m_importRect.ymin = 0; } OdRxDictionaryPtr OdTvVisualizeIgesFilerProperties::createObject() { return OdRxObjectImpl::createObject(); } void OdTvVisualizeIgesFilerProperties::setDefaultColor(OdIntPtr pDefColor) { ODCOLORREF* pColor = (ODCOLORREF*)(pDefColor); if (!pColor) { ODA_ASSERT(false); } m_defaultColor = *pColor; } OdIntPtr OdTvVisualizeIgesFilerProperties::getDefaultColor() const { return (OdIntPtr)(&m_defaultColor); } void OdTvVisualizeIgesFilerProperties::setPalette(OdIntPtr palette) { const ODCOLORREF* pPalette = (const ODCOLORREF*)(palette); m_pPalette = pPalette; } void OdTvVisualizeIgesFilerProperties::setBgColor(OdIntPtr pDefColor) { ODCOLORREF* pColor = (ODCOLORREF*)(pDefColor); if (!pColor) { ODA_ASSERT(false); } m_bgColor = *pColor; } OdIntPtr OdTvVisualizeIgesFilerProperties::getBgColor() const { return (OdIntPtr)(&m_bgColor); } OdIntPtr OdTvVisualizeIgesFilerProperties::getPalette() const { return (OdIntPtr)(m_pPalette); } void OdTvVisualizeIgesFilerProperties::setDeviation(double deviation) { m_deviation = deviation; } double OdTvVisualizeIgesFilerProperties::getDeviation() const { return m_deviation; } void OdTvVisualizeIgesFilerProperties::setMinPerCircle(OdUInt16 minPerCircle) { m_minPerCircle = minPerCircle; } OdUInt16 OdTvVisualizeIgesFilerProperties::getMinPerCircle() const { return m_minPerCircle; } void OdTvVisualizeIgesFilerProperties::setMaxPerCircle(OdUInt16 maxPerCircle) { m_maxPerCircle = maxPerCircle; } OdUInt16 OdTvVisualizeIgesFilerProperties::getMaxPerCircle() const { return m_maxPerCircle; } OdUInt8 OdTvVisualizeIgesFilerProperties::getModelerType() const { return m_modelerType; } void OdTvVisualizeIgesFilerProperties::setModelerType(OdUInt8 type) { m_modelerType = type; } void OdTvVisualizeIgesFilerProperties::setBrepToleranceType(OdUInt8 type) { m_brepToleranceType = type; } OdUInt8 OdTvVisualizeIgesFilerProperties::getBrepToleranceType() const { return m_brepToleranceType; } void OdTvVisualizeIgesFilerProperties::setBrepToleranceDynamic(double coef) { m_brepToleranceDynamic = coef; } double OdTvVisualizeIgesFilerProperties::getBrepToleranceDynamic() const { return m_brepToleranceDynamic; } void OdTvVisualizeIgesFilerProperties::setBrepToleranceStatic(double coef) { m_brepToleranceStatic = coef; } double OdTvVisualizeIgesFilerProperties::getBrepToleranceStatic() const { return m_brepToleranceStatic; } void OdTvVisualizeIgesFilerProperties::setHostAppProgressMeter(OdIntPtr pProgressMeter) { m_pHostAppProgressMeter = (OdTvHostAppProgressMeter*)pProgressMeter; } OdIntPtr OdTvVisualizeIgesFilerProperties::getHostAppProgressMeter() const { return (OdIntPtr)m_pHostAppProgressMeter; } void OdTvVisualizeIgesFilerProperties::setCustomBgTypeValue(OdInt16 customBgValue) { m_customBgTypeValue = customBgValue; } OdInt16 OdTvVisualizeIgesFilerProperties::getCustomBgTypeValue() const { return m_customBgTypeValue; } void OdTvVisualizeIgesFilerProperties::setEnvBackgroundParam(OdIntPtr envParam) { OdTvEnvBackgroundImportParameters* pEnvBackgroundParam = reinterpret_cast(envParam); if (!pEnvBackgroundParam) { ODA_ASSERT(false); } m_envBackgroundParam = pEnvBackgroundParam; } OdIntPtr OdTvVisualizeIgesFilerProperties::getEnvBackgroundParam() const { return reinterpret_cast(m_envBackgroundParam); } OdTvVisualizeIgesFilerProperties::~OdTvVisualizeIgesFilerProperties() { } namespace IGES2Visualize { ODRX_DECLARE_PROPERTY(Palette) ODRX_DECLARE_PROPERTY(DCRect) ODRX_DECLARE_PROPERTY(ObjectNaming) ODRX_DECLARE_PROPERTY(StoreSourceObjects) ODRX_DECLARE_PROPERTY(ClearEmptyObjects) ODRX_DECLARE_PROPERTY(RearrangeObjects) ODRX_DECLARE_PROPERTY(AppendTransform) ODRX_DECLARE_PROPERTY(FeedbackForChooseCallback) ODRX_DECLARE_PROPERTY(DefaultEntityColor) ODRX_DECLARE_PROPERTY(Deviation) ODRX_DECLARE_PROPERTY(MinPerCircle) ODRX_DECLARE_PROPERTY(MaxPerCircle) ODRX_DECLARE_PROPERTY(NeedCDATree) ODRX_DECLARE_PROPERTY(ModelerType) ODRX_DECLARE_PROPERTY(NeedCollectPropertiesInCDA) ODRX_DECLARE_PROPERTY(UseCustomBgColor) ODRX_DECLARE_PROPERTY(BgEntityColor) ODRX_DECLARE_PROPERTY(HostAppProgressMeter) ODRX_DECLARE_PROPERTY(IsLogOn) ODRX_DECLARE_PROPERTY(CalculateIsolines) ODRX_DECLARE_PROPERTY(CustomBgTypeValue) ODRX_DECLARE_PROPERTY(EnvBackgroundParam) ODRX_DECLARE_PROPERTY(InterruptCallback) ODRX_DECLARE_PROPERTY(BrepToleranceType) ODRX_DECLARE_PROPERTY(BrepToleranceDynamic) ODRX_DECLARE_PROPERTY(BrepToleranceStatic) ODRX_DECLARE_PROPERTY(SurfaceOfRevolutionAsNurbs) ODRX_BEGIN_DYNAMIC_PROPERTY_MAP(OdTvVisualizeIgesFilerProperties); ODRX_GENERATE_PROPERTY(Palette) ODRX_GENERATE_PROPERTY(DCRect) ODRX_GENERATE_PROPERTY(ObjectNaming) ODRX_GENERATE_PROPERTY(StoreSourceObjects) ODRX_GENERATE_PROPERTY(ClearEmptyObjects) ODRX_GENERATE_PROPERTY(RearrangeObjects) ODRX_GENERATE_PROPERTY(AppendTransform) ODRX_GENERATE_PROPERTY(FeedbackForChooseCallback) ODRX_GENERATE_PROPERTY(DefaultEntityColor) ODRX_GENERATE_PROPERTY(Deviation) ODRX_GENERATE_PROPERTY(MinPerCircle) ODRX_GENERATE_PROPERTY(MaxPerCircle) ODRX_GENERATE_PROPERTY(NeedCDATree) ODRX_GENERATE_PROPERTY(ModelerType) ODRX_GENERATE_PROPERTY(NeedCollectPropertiesInCDA) ODRX_GENERATE_PROPERTY(UseCustomBgColor) ODRX_GENERATE_PROPERTY(BgEntityColor) ODRX_GENERATE_PROPERTY(HostAppProgressMeter) ODRX_GENERATE_PROPERTY(IsLogOn) ODRX_GENERATE_PROPERTY(CalculateIsolines) ODRX_GENERATE_PROPERTY(CustomBgTypeValue) ODRX_GENERATE_PROPERTY(EnvBackgroundParam) ODRX_GENERATE_PROPERTY(InterruptCallback) ODRX_GENERATE_PROPERTY(BrepToleranceType) ODRX_GENERATE_PROPERTY(BrepToleranceDynamic) ODRX_GENERATE_PROPERTY(BrepToleranceStatic) ODRX_GENERATE_PROPERTY(SurfaceOfRevolutionAsNurbs) ODRX_END_DYNAMIC_PROPERTY_MAP(OdTvVisualizeIgesFilerProperties); ODRX_DEFINE_PROPERTY_METHODS(Palette, OdTvVisualizeIgesFilerProperties, getPalette, setPalette, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(DCRect, OdTvVisualizeIgesFilerProperties, getDCRect, setDCRect, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(ObjectNaming, OdTvVisualizeIgesFilerProperties, getObjectNaming, setObjectNaming, getBool); ODRX_DEFINE_PROPERTY_METHODS(StoreSourceObjects, OdTvVisualizeIgesFilerProperties, getStoreSourceObjects, setStoreSourceObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(ClearEmptyObjects, OdTvVisualizeIgesFilerProperties, getClearEmptyObjects, setClearEmptyObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(RearrangeObjects, OdTvVisualizeIgesFilerProperties, getRearrangeObjects, setRearrangeObjects, getBool); ODRX_DEFINE_PROPERTY_METHODS(AppendTransform, OdTvVisualizeIgesFilerProperties, getAppendTransform, setAppendTransform, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(FeedbackForChooseCallback, OdTvVisualizeIgesFilerProperties, getFeedbackForChooseCallback, setFeedbackForChooseCallback, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(InterruptCallback, OdTvVisualizeIgesFilerProperties, getInterruptionCallback, setInterruptionCallback, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(DefaultEntityColor, OdTvVisualizeIgesFilerProperties, getDefaultColor, setDefaultColor, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(Deviation, OdTvVisualizeIgesFilerProperties, getDeviation, setDeviation, getDouble); ODRX_DEFINE_PROPERTY_METHODS(MinPerCircle, OdTvVisualizeIgesFilerProperties, getMinPerCircle, setMinPerCircle, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(MaxPerCircle, OdTvVisualizeIgesFilerProperties, getMaxPerCircle, setMaxPerCircle, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(NeedCDATree, OdTvVisualizeIgesFilerProperties, getNeedCDATree, setNeedCDATree, getBool) ODRX_DEFINE_PROPERTY_METHODS(ModelerType, OdTvVisualizeIgesFilerProperties, getModelerType, setModelerType, getIntPtr) ODRX_DEFINE_PROPERTY_METHODS(NeedCollectPropertiesInCDA, OdTvVisualizeIgesFilerProperties, getNeedCollectPropertiesInCDA, setNeedCollectPropertiesInCDA, getBool); ODRX_DEFINE_PROPERTY_METHODS(UseCustomBgColor, OdTvVisualizeIgesFilerProperties, getUseCustomBgColor, setUseCustomBgColor, getBool); ODRX_DEFINE_PROPERTY_METHODS(BgEntityColor, OdTvVisualizeIgesFilerProperties, getBgColor, setBgColor, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(HostAppProgressMeter, OdTvVisualizeIgesFilerProperties, getHostAppProgressMeter, setHostAppProgressMeter, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(IsLogOn, OdTvVisualizeIgesFilerProperties, getIsLogOn, setIsLogOn, getBool); ODRX_DEFINE_PROPERTY_METHODS(CalculateIsolines, OdTvVisualizeIgesFilerProperties, getCalculateIsolines, setCalculateIsolines, getBool); ODRX_DEFINE_PROPERTY_METHODS(CustomBgTypeValue, OdTvVisualizeIgesFilerProperties, getCustomBgTypeValue, setCustomBgTypeValue, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(EnvBackgroundParam, OdTvVisualizeIgesFilerProperties, getEnvBackgroundParam, setEnvBackgroundParam, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceType, OdTvVisualizeIgesFilerProperties, getBrepToleranceType, setBrepToleranceType, getIntPtr); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceDynamic, OdTvVisualizeIgesFilerProperties, getBrepToleranceDynamic, setBrepToleranceDynamic, getDouble); ODRX_DEFINE_PROPERTY_METHODS(BrepToleranceStatic, OdTvVisualizeIgesFilerProperties, getBrepToleranceStatic, setBrepToleranceStatic, getDouble); ODRX_DEFINE_PROPERTY_METHODS(SurfaceOfRevolutionAsNurbs, OdTvVisualizeIgesFilerProperties, getSurfaceOfRevolutionAsNurbs, setSurfaceOfRevolutionAsNurbs, getBool); } void OdTvVisualizeIgesFilerProperties::setDCRect(OdIntPtr rect) { OdTvDCRect* pRect = (OdTvDCRect*)(rect); if (!pRect) { ODA_ASSERT(false); } m_importRect = *pRect; } OdIntPtr OdTvVisualizeIgesFilerProperties::getDCRect() const { return (OdIntPtr)(&m_importRect); } void OdTvVisualizeIgesFilerProperties::setAppendTransform(OdIntPtr pTransform) { const OdTvMatrix* pAppendTransform = (const OdTvMatrix*)(pTransform); if (pAppendTransform) { m_appendTransform = *pAppendTransform; } else { m_appendTransform = OdTvMatrix::kIdentity; } } OdIntPtr OdTvVisualizeIgesFilerProperties::getAppendTransform() const { return (OdIntPtr)(&m_appendTransform); } void OdTvVisualizeIgesFilerProperties::setFeedbackForChooseCallback(OdIntPtr pCallback) { m_pCallback = (OdTvFeedbackForChooseCallback)pCallback; } OdIntPtr OdTvVisualizeIgesFilerProperties::getFeedbackForChooseCallback() const { return (OdIntPtr)m_pCallback; } void OdTvVisualizeIgesFilerProperties::setInterruptionCallback(OdIntPtr pInterrupt) { m_pInterruptCallback = (OdDAI::InterruptCallback)pInterrupt; } OdIntPtr OdTvVisualizeIgesFilerProperties::getInterruptionCallback() const { return (OdIntPtr)m_pInterruptCallback; } //***************************************************************************// // 'OdTvVisualizeIgesFiler' methods implementation //***************************************************************************// OdTvVisualizeIgesFiler::OdTvVisualizeIgesFiler() : m_properties(OdTvVisualizeIgesFilerProperties::createObject()) { } int OdTvVisualizeIgesFiler::getChoosedRepresentationContexts(IgesFilePtr pIgesFile, OdTvFilerFeedbackForChooseObject & filerFeedbackForChoose, bool& bCanceled) const { m_selContexts.clear(); OdDAI::ModelPtr pModel = pIgesFile->getModel(); if (pModel.isNull()) { ODA_ASSERT_ONCE(pModel.get()); return -1; } // TODO: Should we show views separately? return -1; } OdTvDatabaseId OdTvVisualizeIgesFiler::loadFrom(const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes, OdTvResult* rc) const { OdStreamBufPtr pStreamBuf = odrxSystemServices()->createFile(filePath); if (pStreamBuf.isNull()) { if (rc) *rc = tvInvalidFilePath; return OdTvDatabaseId(); } return loadFrom(pStreamBuf, pProfileRes, rc); } void OdTvVisualizeIgesFiler::createCommonDataAccessTree(OdTvDatabasePtr pTvDb, OdDbBaseDatabase *pDatabase, const OdString& strTreeName, const OdTvModelId& modelId /*= OdTvModelId()*/) const { IgesFilePtr pIgesFile = IgesFile::cast(pDatabase); if (pIgesFile.isNull()) { ODA_ASSERT_ONCE("Wrong database class!"); return; } OdDAI::ModelPtr pModel = pIgesFile->getModel(); if (pModel.isNull()) { ODA_ASSERT_ONCE("Can not create CDA tree for empty IgesFile!"); return; } ::odrxDynamicLinker()->loadModule(L"RxProperties"); //Create CDA tree OdTvCDATreePtr pTree = OdTvCDATree::createObject(); if (m_properties->getNeedCollectPropertiesInCDA()) pTree->createDatabaseHierarchyTree(pIgesFile.get(), true); else { std::set props; props.insert(OdTvCDAPropNameForGrouping); pTree->createDatabaseHierarchyTree(pIgesFile.get(), &props); } //Add tree to the Tv database OdTvResult rc; OdTvCDATreeStorageId cdaTreeId = pTvDb->addCDATreeStorage(strTreeName, pTree, &rc); if (rc == tvAlreadyExistSameName) { OdUInt32 i = 1; while (rc != tvOk && i < MAX_CDATREENAME_GENERATION_ATTEMPTS) { OdString str; str.format(L"%s_%d", strTreeName.c_str(), i++); //not to fast but it is not a "bottle neck" cdaTreeId = pTvDb->addCDATreeStorage(str, pTree, &rc); } } //Add new CDA tree to the appropriate models OdTvModelId curModel = modelId; if (curModel.isNull()) { OdTvModelsIteratorPtr modelsIterPtr = pTvDb->getModelsIterator(); if (!modelsIterPtr->done()) { curModel = modelsIterPtr->getModel(); OdTvModelPtr pModel = curModel.openObject(); if (!pModel.isNull()) pModel->setCDATreeStorage(cdaTreeId); } } else { OdTvModelPtr pModel = curModel.openObject(); pModel->setCDATreeStorage(cdaTreeId); } OdTvCDATreeNodePtr pTvNode = pTree->getDatabaseNode(); if (!pTvNode.isNull()) { const OdRxModelTreeBaseNodePtrArray& nodes = pTvNode->getChildren(); for (auto it = nodes.begin(); it != nodes.end(); ++it) { OdTvCDATreeNodePtr pNode = *it; if (pNode.isNull()) continue; pNode->setTvModelId(curModel); } } // formally it is not very fast function due to string comparison. But current implementation finds ONLY first occurrence of // object with Storeys Class Name. That's why currently it is fast enough OdRxModelTreeBaseNodePtr pDbNode = pTree->getDatabaseNode(); if (!pDbNode.isNull()) processCDANode(pDbNode.get(), NULL); } bool OdTvVisualizeIgesFiler::processCDANode(OdRxModelTreeBaseNode* pNode, OdRxModelTreeBaseNode* pParentNode) const { if (!pNode) return true; if (pParentNode) { OdTvCDATreeNodePtr pTvNode = dynamic_cast(pNode); OdTvCDATreeNodePtr pTvParentNode = dynamic_cast(pParentNode); if (!pTvNode.isNull() && !pTvParentNode.isNull()) { // No other cases so far. pTvNode->setValidWithoutTv(true); pTvNode->setNeedGroup(false); /*OdString strClassName = getClassNameProperty(pTvNode->getProperties()); if (!strClassName.isEmpty()) { strClassName = strClassName.right(strClassName.getLength() - strClassName.find(L":") - 2); if ( !strClassName.isEmpty() ) { bool bNeedGroup = (strClassName == "..."); if (bNeedGroup) { pTvParentNode->setNeedGroup(false); return false; } } }*/ } } const OdRxModelTreeBaseNodePtrArray& children = pNode->getChildren(); if (children.isEmpty()) return true; for (auto it = children.begin(); it != children.end(); ++it) { if (!processCDANode( const_cast(it->get()), pNode)) return false; } return true; } OdString OdTvVisualizeIgesFiler::getClassNameProperty(const OdArray& nodeProperties) const { if (nodeProperties.size() == 0) return OdString(); for (OdUInt32 i = 0; i < nodeProperties.size(); i++) { if (nodeProperties[i].name == OdTvCDAPropNameForGrouping) return nodeProperties[i].value.getString(); } return OdString(); } int OdTvVisualizeIgesFiler::odSelectRepresentationContextsByDefault(OdDAI::ModelPtr pModel) const { return -1; } OdTvGsViewId OdTvVisualizeIgesFiler::getActiveTvView(OdTvGsDeviceId& tvDeviceId, int iActViewViewInd) const { OdTvGsDevicePtr pTvDevice = tvDeviceId.openObject(); if (!pTvDevice.isNull()) { return pTvDevice->viewAt(iActViewViewInd); } return OdTvGsViewId(); } OdTvGsDeviceId OdTvVisualizeIgesFiler::getActiveTvDevice(OdTvDatabaseId& tvDbId, int idDevice) const { OdTvDevicesIteratorPtr pDevicesIterator = tvDbId.openObject()->getDevicesIterator(); unsigned iDeviceInd = 0; if (!pDevicesIterator.isNull() && !pDevicesIterator->done()) { if (iDeviceInd == idDevice) return pDevicesIterator->getDevice(); pDevicesIterator->step(); } return OdTvGsDeviceId(); } OdTvModelId OdTvVisualizeIgesFiler::import(OdTvDatabaseId &tvDbId, OdStreamBuf* pBuffer, IgesFilePtr pIgesFile, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { if (rc) *rc = tvOk; OdTvModelId idModel; OdString fileName; if (pBuffer) fileName = OdTvDatabaseUtils::getFileNameFromPath(pBuffer->fileName()); else if (!pIgesFile.isNull()) fileName = OdTvDatabaseUtils::getFileNameFromPath(pIgesFile->getFileName()); if (fileName.isEmpty()) fileName = OD_T("StreamBuffData"); OdString modelName; OdTvGsDeviceId activeTvGsDeviceId; bool bIsAppend = false; if (tvDbId.isNull()) { // // Create empty TV database. // OdTvFactoryId tvFactoryId = odTvGetFactory(); tvDbId = tvFactoryId.createDatabase(); OdTvDatabasePtr pTvDb = tvDbId.openObject(OdTv::kForWrite); } else { bIsAppend = true; // // Check that we are in the real append mode // { OdTvDatabasePtr pTvDb = tvDbId.openObject(); OdTvDevicesIteratorPtr devicesIteratorPtr = pTvDb->getDevicesIterator(); while (!devicesIteratorPtr->done()) { activeTvGsDeviceId = devicesIteratorPtr->getDevice(); if (activeTvGsDeviceId.openObject()->getActive()) break; devicesIteratorPtr->step(); } } modelName = OdTvDatabaseUtils::generateModelName(tvDbId, fileName); } // // Check if time profiling is needed // bool bUseTimeProfiling = false; if (pProfileRes) bUseTimeProfiling = true; double internalTiming = 0.; double externalTiming = 0.; double fileOpenTiming = 0.; double composeTiming = 0.; double contextSelectionTiming = 0.; double CDATiming = 0.; OdStaticRxObject svcs; // // Start total timing // OdTvFilerTimer timing(bUseTimeProfiling); timing.startTotal(); OdRxModulePtr sdaiModule = ::odrxSafeLoadApp(OdSDAIModuleName); bool bActivated = !pIgesFile.isNull(); if (!bActivated) { odIgesInitialize(true); if (m_properties->getIsLogOn()) { OdDAI::SessionPtr pSession = oddaiSession(); if (pSession.isNull()) pSession = oddaiCreateSession(); pSession->startEventRecording(); } } // // Store visualize device module name // OdString moduleName; try { // // Local smart pointer pIgesDatabase, so we can release it and uninitialize IGES SDK if // pIgesFilePtr wasn't provided, and IGES file should be loaded into this module. // IgesFilePtr pIgesDatabase = pIgesFile; if (pIgesDatabase.isNull() && pBuffer) { // // No IgesFile provided, so file should be loaded and released in this module // OdDAI::Settings &setting = OdDAI::settings(); OdDbHostAppProgressMeter* pMeter = (OdDbHostAppProgressMeter*)m_properties->getHostAppProgressMeter(); if (pMeter) svcs.setProgressMeter(pMeter); timing.startMisc(); pIgesDatabase = svcs.readFile(pBuffer); timing.endMisc(); fileOpenTiming = timing.getMiscTime(); } if (!pIgesDatabase.isNull()) { // pIgesDatabase->writeFile("e:/fromiges.spf"); // // Interrupt total timing for ask what representation contexts should be drawn // timing.startMisc(); OdTvFilerFeedbackForChooseObject filerFeedbackForChooseObject(OD_T("Geometric contexts for import")); bool bCanceled = false; IgesModelContext& igesModelContext = pIgesDatabase->getContext(); int nSelContexts = getChoosedRepresentationContexts(pIgesDatabase, filerFeedbackForChooseObject, bCanceled); timing.endMisc(); if (bCanceled) { if (rc) *rc = tvFilerEmptyInternalDatabase; odTvGetFactory().removeDatabase(tvDbId); tvDbId.setNull(); pIgesDatabase = nullptr; if(!bActivated) { // Uninitialize IGES modules odIgesUninitialize(); } // Unload everything including Visualize device odrxDynamicLinker()->unloadUnreferenced(); return idModel; } contextSelectionTiming = timing.getMiscTime(); if (1) //nSelContexts >= 0) { // // Customize Model Context // // // Should Surface of Revolution be interpreted as NURB surface internaly? // igesModelContext.setSurfaceOfRevolutionAsNurbSurface(m_properties->getSurfaceOfRevolutionAsNurbs()); // // Deviation params from properties // OdDeviationParams deviationParams(m_properties->getDeviation(), m_properties->getMinPerCircle(), m_properties->getMaxPerCircle()); igesModelContext.setDeviationParams(deviationParams); // // Brep params from properties // igesModelContext.setBrepParams(OdBrepParams(OdBrepParams::ToleranceType(m_properties->getBrepToleranceType()), m_properties->getBrepToleranceDynamic(), m_properties->getBrepToleranceStatic())); // // Textures support // //OdIgesHostAppServices* pServices = pIgesDatabase->getAppServices(); //if (pServices) // pServices->setTexturesVisibility(m_properties->getTexturesVisibility()); // // Default color from properties // ODCOLORREF* pDefColor = (ODCOLORREF*)m_properties->getDefaultColor(); OdUInt8 r, g, b; r = ODGETRED(*pDefColor); g = ODGETGREEN(*pDefColor); b = ODGETBLUE(*pDefColor); OdCmEntityColor color(r, g, b); igesModelContext.setDefaultEntityColor(color); // // Get units from IGES Document // double addUnitCoefToMeters; OdTv::Units tvUnits = getUnits(pIgesDatabase, addUnitCoefToMeters); OdTvIgesPartialImportNotifier notifier; OdDbHostAppProgressMeter* pMeter = (OdDbHostAppProgressMeter*)m_properties->getHostAppProgressMeter(); if (pMeter) { pMeter->start(OD_T("Import starting...")); } notifier.setProgressMeter(pMeter); const OdDAI::SetOfOdDAIObjectId* geometrics = pIgesDatabase->getModel()->getEntityExtent("geometric"); notifier.setEntitiesCount(geometrics->getMemberCount()); // 0 or 1? // // Vectorizing // timing.startVectorizing(); OdGsModulePtr pGs = ::odrxDynamicLinker()->loadModule(OdTvVisualizeDeviceModuleName, false); if (!pGs.isNull()) { moduleName = pGs->moduleName(); // // Create vectorizer device // OdGsDevicePtr pDevice = pGs->createDevice(); OdTvIgesGeomertyNotifier geometryNotifier(tvDbId.openObject()); OdGiContextForIgesDatabasePtr giGontextForIgesDatabase = OdGiContextForIgesDatabase::createObject(); giGontextForIgesDatabase->setDatabase(pIgesDatabase); giGontextForIgesDatabase->enableGsModel(true); OdRxDictionaryPtr pProperties = pDevice->properties(); if (pProperties.get()) { if (pProperties->has(OD_T("DisplayViaGLES2"))) pProperties->putAt(OD_T("DisplayViaGLES2"), OdRxVariantValue(false)); if (pProperties->has(OD_T("AllowNonPersistentObjects"))) pProperties->putAt(OD_T("AllowNonPersistentObjects"), OdRxVariantValue(false)); #if !defined(__APPLE__) if (pProperties->has(OD_T("EnableTiming"))) pProperties->putAt(OD_T("EnableTiming"), OdRxVariantValue(bUseTimeProfiling)); #endif if (pProperties->has(OD_T("TvDatabaseID"))) pProperties->putAt(OD_T("TvDatabaseID"), OdRxVariantValue((OdIntPtr)(&tvDbId))); if (pProperties->has(OD_T("WriteUserData"))) pProperties->putAt(OD_T("WriteUserData"), OdRxVariantValue(true /*m_properties->getStoreSourceObjects()*/)); if (pProperties->has(OD_T("GenerateEntityNames"))) pProperties->putAt(OD_T("GenerateEntityNames"), OdRxVariantValue(true /*m_properties->getObjectNaming()*/)); if (pProperties->has(OD_T("CompareUnnamedImages"))) pProperties->putAt(OD_T("CompareUnnamedImages"), OdRxVariantValue(true)); if (pProperties->has(OD_T("CompareMaterialsForUniqueness"))) pProperties->putAt(OD_T("CompareMaterialsForUniqueness"), OdRxVariantValue(false)); if (!activeTvGsDeviceId.isNull()) { if (pProperties->has(OD_T("IgnoreFlags"))) pProperties->putAt(OD_T("IgnoreFlags"), OdRxVariantValue(OdUInt16(1)/*DeviceIgnoreFlags::kIgnoreViewInfoFlags*/)); if (pProperties->has(OD_T("ModelName"))) pProperties->putAt(OD_T("ModelName"), OdRxVariantValue(modelName)); if (pProperties->has(OD_T("NamePrefix"))) pProperties->putAt(OD_T("NamePrefix"), OdRxVariantValue(modelName)); if (pProperties->has(OD_T("TvDeviceDAM"))) pProperties->putAt(OD_T("TvDeviceDAM"), OdRxVariantValue((OdIntPtr)(&activeTvGsDeviceId))); OdTvGsViewId viewId = activeTvGsDeviceId.openObject()->getActiveView(); OdString name = viewId.openObject()->getName(); if (pProperties->has(OD_T("TvViewDAM"))) pProperties->putAt(OD_T("TvViewDAM"), OdRxVariantValue((OdIntPtr)(&viewId))); } if (bIsAppend) { if (pProperties->has(OD_T("DisableSettingExtents"))) pProperties->putAt(OD_T("DisableSettingExtents"), OdRxVariantValue(true)); } // put device notifier if (pProperties->has(OD_T("DeviceNotifier"))) { pProperties->putAt(OD_T("DeviceNotifier"), OdRxVariantValue((OdIntPtr)(¬ifier))); } if (pProperties->has(OD_T("GeometryNotifier"))) { pProperties->putAt(OD_T("GeometryNotifier"), OdRxVariantValue((OdIntPtr)(&geometryNotifier))); } } // // Setup the device and view // OdGsIgesLayoutHelperPtr pLayoutHelper = OdIgesGsManager::setupActiveLayoutViews(pDevice.get(), giGontextForIgesDatabase); if (pLayoutHelper.isNull()) { throw OdError(eNullPtr); } pLayoutHelper->activeView()->setMode(OdGsView::kGouraudShaded); // // Set the palette // const ODCOLORREF* palette = (const ODCOLORREF*)m_properties->getPalette(); bool bDefaultPalette = false; if (palette == 0) { bDefaultPalette = true; palette = odcmAcadPalette(ODRGB(255, 255, 255)); } OdArray > pPalCpy; pPalCpy.insert(pPalCpy.begin(), palette, palette + 256); pDevice->setLogicalPalette(pPalCpy.asArrayPtr(), 256); pDevice->setBackgroundColor(ODRGB(192, 192, 192)); giGontextForIgesDatabase->setPaletteBackground(ODRGB(192, 192, 192)); // // Call onsize // OdTvDCRect* pRect = (OdTvDCRect*)m_properties->getDCRect(); if (pRect && (pRect->xmax > 0 || pRect->xmin > 0 || pRect->ymax > 0 || pRect->ymin > 0)) { OdGsDCRect gsRect(pRect->xmin, pRect->xmax, pRect->ymin, pRect->ymax); pDevice->onSize(gsRect); } // // Call draw to the Visualize database // pLayoutHelper->update(); if (pProperties->has(OD_T("TvDatabaseID"))) tvDbId = *(OdTvDatabaseId*)OdRxVariantValue(pProperties->getAt(OD_T("TvDatabaseID")).get())->getIntPtr(); if (bUseTimeProfiling) { #if !defined(__APPLE__) if (pProperties->has(OD_T("TvElapsedTime"))) { internalTiming = OdRxVariantValue(pProperties->getAt(OD_T("TvElapsedTime")).get())->getDouble(); } #endif } // // Setup active view // timing.startMisc(); if (tvDbId.isValid()) { OdTvDatabasePtr pTvDb = tvDbId.openObject(OdTv::kForWrite); OdTvModelId tvCreatedModelId; if (activeTvGsDeviceId.isNull()) { int iActViewViewInd = getActiveViewId(pLayoutHelper.get()); if (iActViewViewInd >= 0) { //get current tv device OdTvGsDeviceId tvDeviceId = getActiveTvDevice(tvDbId, 0); OdTvGsViewId tvViewId = getActiveTvView(tvDeviceId, iActViewViewInd); if (!tvDeviceId.isNull() && !tvViewId.isNull()) { OdTvGsViewPtr pActiveTvView = tvViewId.openObject(OdTv::kForWrite); pActiveTvView->setActive(true); // mark other views sibling OdTvGsDevicePtr pTvDevice = tvDeviceId.openObject(OdTv::kForWrite); if (!pTvDevice.isNull()) { pTvDevice->setName(OD_T("IGES Document")); for (int i = 0; i < pTvDevice->numViews(); i++) { if (i != iActViewViewInd) continue; OdTvGsViewId viewId = pTvDevice->viewAt(i); if(viewId != tvViewId) pActiveTvView->addSibling(viewId); //set background int test = m_properties->getCustomBgTypeValue(); switch(static_cast(m_properties->getCustomBgTypeValue())) { case BackgroundType::kGradient: { OdTvGsViewBackgroundId bgId = pTvDb->createBackground(OD_T("IGES2VISUALIZE"), OdTvGsViewBackgroundId::kGradient); if (!bgId.isNull()) { OdTvGsViewGradientBackgroundPtr pGradientBackground = bgId.openAsGradientBackground(OdTv::kForWrite); pGradientBackground->setColorTop(OdTvColorDef(33, 108, 170)); pGradientBackground->setColorMiddle(OdTvColorDef(109, 158, 200)); pGradientBackground->setColorBottom(OdTvColorDef(184, 208, 230)); pGradientBackground->setHeight(0.33); pGradientBackground->setHorizon(0.5); } pActiveTvView->setBackground(bgId); break; } case BackgroundType::kColor: { ODCOLORREF* pBgColor = (ODCOLORREF*)m_properties->getBgColor(); pTvDevice->setBackgroundColor(*pBgColor); break; } case BackgroundType::kEnviroment: { OdTvEnvBackgroundImportParameters* envParam = reinterpret_cast(m_properties->getEnvBackgroundParam()); OdTvDatabasePtr pDb = tvDbId.openObject(OdTv::kForWrite); OdTvGsViewBackgroundId bgId = pDb->findBackground(envParam->getEnviromentType()); OdTvGsViewEnvironmentBackgroundPtr pBg; if (bgId.isNull() || bgId.getType() != OdTvGsViewBackgroundId::kEnvironment) { bgId = pDb->createBackground(envParam->getEnviromentType(), OdTvGsViewBackgroundId::kEnvironment); pBg = bgId.openAsEnvironmentBackground(OdTv::kForWrite); if (!envParam->getCustomCubic().isNull()) { pBg->setEnvironmentImage(envParam->getCustomCubic()); } else { pBg->setEnvironmentImageFileName(envParam->getEnviromentPath()); } } if(pBg.isNull()) pBg = bgId.openAsEnvironmentBackground(OdTv::kForWrite); pBg->setLongitude(envParam->getLongitude()); pBg->setLatitude(envParam->getLatitude()); pBg->setFovOverride(envParam->getAngleStatus(), envParam->getAngle()); pActiveTvView->setBackground(bgId); break; } default: { ODA_FAIL_M_ONCE("Iges2Visualize background type not implemented"); break; } } //set more lighting pActiveTvView->setDefaultLightingIntensity(1.25); // Zoom to extents OdTvPoint minPt, maxPt; pActiveTvView->zoomExtents(minPt, maxPt); } } } } // // Store filename to database user data // OdTvDatabaseUtils::writeFileNameToTvDatabase(tvDbId, fileName); // // Rename the model (here we suppose that database contain only one model) // OdTvModelsIteratorPtr pModelsIterator = pTvDb->getModelsIterator(); if (!pModelsIterator.isNull() && !pModelsIterator->done()) { OdTvModelId modelId = pModelsIterator->getModel(); OdTvModelPtr pIvModel = modelId.openObject(OdTv::kForWrite); if (!pIvModel.isNull()) { tvCreatedModelId = modelId; pIvModel->setName(fileName); OdTvSelectabilityDef selectability; selectability.setGeometries(true); pIvModel->setSelectability(selectability, true); //set units pIvModel->setUnits(tvUnits, tvUnits == OdTv::kUserDefined ? addUnitCoefToMeters : 1.); //calculate isolines if need if (m_properties->getCalculateIsolines()) { OdTvEntitiesIteratorPtr pEntitiesIterator = pIvModel->getEntitiesIterator(); while (!pEntitiesIterator->done()) { OdTvEntityId entityId = pEntitiesIterator->getEntity(); if (entityId.getType() == OdTvEntityId::kEntity) { OdTvEntityPtr pEntity = entityId.openObject(OdTv::kForWrite); if (!pEntity.isNull()) pEntity->setCalculateIsolinesForShells(true, 89.0 * OdaPI / 180.0, false); } pEntitiesIterator->step(); } } } } if (m_properties->getNeedCDATree()) { OdPerfTimerBase* pCDATiming = OdPerfTimerBase::createTiming(); pCDATiming->start(); createCommonDataAccessTree(pTvDb, pIgesDatabase, fileName + OD_T(".iges")); pCDATiming->stop(); CDATiming += pCDATiming->countedSec(); if (pProfileRes) pProfileRes->setCDATreeCreationTime(OdInt64((CDATiming) * 1000.)); delete pCDATiming; } } else { idModel = pTvDb->findModel(modelName); OdTvModelPtr pTvModel = idModel.openObject(OdTv::kForWrite); if ( !pTvModel.isNull() ) { tvCreatedModelId = idModel; OdTvSelectabilityDef selectability; selectability.setGeometries(true); pTvModel->setSelectability(selectability, true); //set units pTvModel->setUnits(tvUnits, tvUnits == OdTv::kUserDefined ? addUnitCoefToMeters : 1.); // Apply transform if needed OdTvMatrix* pTransform = (OdTvMatrix*)m_properties->getAppendTransform(); if (pTransform) pTvModel->setModelingMatrix(*pTransform); //calculate isolines if need if (m_properties->getCalculateIsolines()) { OdTvEntitiesIteratorPtr pEntitiesIterator = pTvModel->getEntitiesIterator(); while (!pEntitiesIterator->done()) { OdTvEntityId entityId = pEntitiesIterator->getEntity(); if (entityId.getType() == OdTvEntityId::kEntity) { OdTvEntityPtr pEntity = entityId.openObject(OdTv::kForWrite); if (!pEntity.isNull()) pEntity->setCalculateIsolinesForShells(true, 89.0 * OdaPI / 180.0, true); } pEntitiesIterator->step(); } } } if (m_properties->getNeedCDATree()) { OdPerfTimerBase* pCDATiming = OdPerfTimerBase::createTiming(); pCDATiming->start(); createCommonDataAccessTree(pTvDb, pIgesDatabase, fileName + OD_T(".iges"), idModel); pCDATiming->stop(); CDATiming += pCDATiming->countedSec(); if (pProfileRes) pProfileRes->setCDATreeCreationTime(OdInt64((CDATiming) * 1000.)); } } //remove alone first level subentities and set shadow parameters OdTvModelPtr pTvModel = tvCreatedModelId.openObject(OdTv::kForWrite); if (!pTvModel.isNull()) { OdTvEntitiesIteratorPtr pEntitiesIterator = pTvModel->getEntitiesIterator(); while (!pEntitiesIterator->done()) { OdTvEntityId entityId = pEntitiesIterator->getEntity(); if (entityId.getType() == OdTvEntityId::kEntity) { OdTvEntityPtr pTvEntity = entityId.openObject(OdTv::kForWrite); if ( !pTvEntity.isNull() ) { pTvEntity->removeSubEntities(OdTvEntity::kRemoveAlone); pTvEntity->setShadowParameters(true, false); } } pEntitiesIterator->step(); } } } if (!bIsAppend || activeTvGsDeviceId.isNull()) { OdTvDatabaseUtils::createAndApplyPreferableVS(tvDbId, true, false); OdTvVisualStyleId visualStyleHiddenId = tvDbId.openObject(OdTv::kForWrite)->findVisualStyle(OD_T("Hidden Line Black")); if (!visualStyleHiddenId.isNull()) { OdTvVisualStylePtr pVisualStyle = visualStyleHiddenId.openObject(OdTv::kForWrite); if (!pVisualStyle.isNull()) pVisualStyle->setOption(OdTvVisualStyleOptions::kFaceColorMode, (OdInt32)OdTvVisualStyleOptions::kBackgroundTexture); } } //remove empty data if need if (tvDbId.isValid() && m_properties->getClearEmptyObjects()) OdTvDatabaseCleaner::cleanTvDatabase(tvDbId); timing.endMisc(); externalTiming += timing.getMiscTime(); } else { if (rc) *rc = tvMissingVisualizeDeviceModule; } timing.endVectorizing(); } else { if (rc) *rc = tvFilerEmptyContext; } if (m_properties->getIsLogOn()) { OdDAI::SessionPtr pSession = oddaiSession(); if (pSession->isRecordingOn()) { OdAnsiString log = getLog(pSession, pIgesDatabase); if (!log.isEmpty()) { OdString logName = (pIgesDatabase.isNull() ? fileName : pIgesDatabase->getFileName()) + ".log"; std::ofstream file((const char*)logName); file << log; file.close(); } } } } else { // // File open error // if (rc) *rc = tvFilerEmptyInternalDatabase; } } catch (...) { if (rc) *rc = tvInternal; timing.endVectorizing(); } // Unload vectorizing device if (!moduleName.isEmpty()) odrxDynamicLinker()->unloadModule(moduleName); if (!bActivated) { // Uninitialize IGES modules odIgesUninitialize(); // // Here we will unload everything including Visualize device // odrxDynamicLinker()->unloadUnreferenced(); } timing.endTotal(); if (pProfileRes) { pProfileRes->setImportTime((OdInt64)(fileOpenTiming * 1000.)); pProfileRes->setMiscTime((OdInt64)(composeTiming * 1000.)); pProfileRes->setVectorizingTime(OdInt64((timing.getVectorizingTime() - CDATiming) * 1000.)); #if !defined(__APPLE__) pProfileRes->setTvTime(OdInt64((internalTiming + externalTiming - CDATiming) * 1000.)); #endif } //set the selectability level if (!idModel.isNull()) { OdTvModelPtr pTvModel = idModel.openObject(OdTv::kForWrite); OdTvSelectabilityDef selectability; selectability.setGeometries(true); pTvModel->setSelectability(selectability, true); } return idModel; } OdAnsiString OdTvVisualizeIgesFiler::getLog(OdDAI::SessionPtr& pSession, IgesFilePtr pFile) const { if (pFile.isNull()) return OdAnsiString(); OdString fileName = pFile->getFileName(); OdAnsiString logString; logString = "********************************************************************************\n"; auto t = std::time(nullptr); auto tm = *std::localtime(&t); logString += "Date:\t\t\t "; logString += std::asctime(&tm); logString += "File name:\t\t "; logString += fileName; logString += "\n"; logString += "Readed with schema:\t\t "; logString += pFile->getModel()->underlyingSchemaName(); logString += "\n"; OdDAIHostAppServicesBase* pServices = pFile->getAppServices(); logString += "Produced by:\t\t "; logString += "ODA IGES SDK "; logString += pServices->versionString(); logString += "\n"; logString += "User:\t\t\t "; logString += pServices->getAppUserName(Oda::kUserId); logString += "\n"; logString += "********************************************************************************\n\n" ; logString += "--------------------------------------------------------------------------------\n"; if (!pSession.isNull()) { OdDAI::List* errors = nullptr; if (pSession->getAttr("errors") >> errors) { if (errors->getMemberCount() > 0) { for (int i = 0; i < errors->getMemberCount(); ++i) { OdDAI::ErrorEventPtr pEvent; if (errors->getByIndex(i) >> pEvent) { OdAnsiString descr = pEvent->description(); OdAnsiString func = pEvent->functionId(); logString += descr; logString += "<"; logString += func; logString += ">"; logString += "\n"; } } } else logString += "SUCCESS\n"; } } logString += "--------------------------------------------------------------------------------\n"; return logString; } OdTvDatabaseId OdTvVisualizeIgesFiler::loadFrom(OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId idDb; import(idDb, pBuffer, IgesFilePtr(), pProfileRes, rc); return idDb; } OdTvDatabaseId OdTvVisualizeIgesFiler::loadFrom(OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId tvDbId; import(tvDbId, NULL, pDatabase, pProfileRes, rc); return tvDbId; } OdTvDatabaseId OdTvVisualizeIgesFiler::generate(OdTvFilerTimeProfiling* pProfileRes) const { OdTvDatabaseId tvDbId; // does nothing return tvDbId; } OdTvModelId OdTvVisualizeIgesFiler::appendFrom(const OdTvDatabaseId& databaseId, const OdString& filePath, OdTvFilerTimeProfiling* pProfileRes, OdTvResult* rc) const { OdStreamBufPtr pStreamBuf = odrxSystemServices()->createFile(filePath); if (pStreamBuf.isNull()) { if (rc) *rc = tvInvalidFilePath; return OdTvModelId(); } return appendFrom(databaseId, pStreamBuf, pProfileRes, rc); } OdTvModelId OdTvVisualizeIgesFiler::appendFrom(const OdTvDatabaseId& databaseId, OdStreamBuf* pBuffer, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId idTvDb = (OdTvDatabaseId)databaseId; return import(idTvDb, pBuffer, IgesFilePtr(), pProfileRes, rc); } OdTvModelId OdTvVisualizeIgesFiler::appendFrom(const OdTvDatabaseId& databaseId, OdDbBaseDatabase* pDatabase, OdTvFilerTimeProfiling* pProfileRes /*= NULL*/, OdTvResult* rc /*= NULL*/) const { OdTvDatabaseId tvDbId = databaseId; return import(tvDbId, NULL, pDatabase, pProfileRes, rc); } int OdTvVisualizeIgesFiler::getActiveViewId(OdGsIgesLayoutHelper* pLayoutHelper) const { if (!pLayoutHelper) return -1; OdGsViewPtr pActiveView = pLayoutHelper->activeView(); int num = pLayoutHelper->numViews(); int iActViewViewInd = 0; for (int i = 0; i < num; ++i) { OdGsView* pView = pLayoutHelper->viewAt(i); if (pView == pActiveView.get()) { iActViewViewInd = i; break; } } return iActViewViewInd; } OdTvGsViewId OdTvVisualizeIgesFiler::getActiveTvView(OdTvDatabaseId& dbId, int iActViewViewInd) const { OdTvDevicesIteratorPtr pDevicesIterator = dbId.openObject()->getDevicesIterator(); if (!pDevicesIterator.isNull() && !pDevicesIterator->done()) { OdTvGsDevicePtr pTvDevice = pDevicesIterator->getDevice().openObject(); if (!pTvDevice.isNull()) { return pTvDevice->viewAt(iActViewViewInd); } } return OdTvGsViewId(); } //***************************************************************************// // Native properties methods implementation //***************************************************************************// OdTvResult OdTvVisualizeIgesFiler::startActionsWithNativeProperties(const OdString& sFilePath, bool bPartial) { if (!m_pIgesFile.isNull()) { if (m_pIgesFile->getFileName() != sFilePath) m_pIgesFile.release(); else return tvOk; } { if (m_pRxPropertiesModule.isNull()) m_pRxPropertiesModule = ::odrxDynamicLinker()->loadModule(L"RxProperties"); } odIgesInitialize(true); OdTvResult rc = tvOk; if (m_pFilerPtr.isNull()) { m_pFilerPtr = new OdTvVisualizeIgesFilerDbSource; } IgesFilePtr pIgesFile = m_pFilerPtr->readFile(sFilePath); if (pIgesFile.isNull()) return tvFilerEmptyInternalDatabase; //OdTvVisualizeDwgFilerSourceFromFile dl; //if (!dl.initialize(sFilePath, NULL, &rc)) { try { m_pIgesFile = pIgesFile; m_pIgesModel = m_pIgesFile->getModel(); } catch (...) { return tvFilerEmptyInternalDatabase; } } return rc; } bool OdTvVisualizeIgesFiler::isActionsWithNativePropertiesStarted(const OdString& sFilePath) { if (!m_pIgesFile.isNull() && m_pIgesFile->getFileName() == sFilePath) return true; return false; } OdTvResult OdTvVisualizeIgesFiler::endActionsWithNativeProperties() { m_pFilerPtr = NULL; m_pIgesModel.release(); m_pIgesFile.release(); m_pIgesCoreModule.release(); m_pRxPropertiesModule.release(); odIgesUninitialize(); ::odrxDynamicLinker()->unloadModule(L"RxProperties"); ::odrxDynamicLinker()->unloadUnreferenced(); return tvOk; } OdRxMemberIteratorPtr OdTvVisualizeIgesFiler::getNativePropertiesIterator(OdUInt64 dbHandle, OdTvResult* rc /*= NULL*/) { if (m_pIgesModel.isNull()) { if (rc) *rc = tvNativePropMissedDatabase; return OdRxMemberIteratorPtr(); } OdRxMemberIteratorPtr pIter; if (dbHandle == 0) pIter = OdRxMemberQueryEngine::theEngine()->newMemberIterator(m_pIgesFile.get()); else { OdDAIObjectId id = m_pIgesModel->getEntityInstance(dbHandle); if (id.isNull()) { if (rc) *rc = tvNativePropMissedObject; return OdRxMemberIteratorPtr(); } OdDAI::ApplicationInstancePtr pInst = id.openObject(); pIter = OdRxMemberQueryEngine::theEngine()->newMemberIterator(pInst.get()); } if (pIter.isNull()) { if (rc) *rc = tvInternal; return OdRxMemberIteratorPtr(); } if (rc) *rc = tvOk; return pIter; } OdRxValue OdTvVisualizeIgesFiler::getNativePropertyValue(OdUInt64 dbHandle, const OdRxPropertyPtr& pProperty, bool* bReadOnly /*= NULL*/, OdTvResult* rc /*= NULL*/) { if (pProperty.isNull()) { if (rc) *rc = tvInvalidInput; return OdRxValue(); } if (m_pIgesModel.isNull()) { if (rc) *rc = tvNativePropMissedDatabase; return OdRxValue(); } OdRxObjectPtr pInst; if (dbHandle == 0) pInst = m_pIgesFile; else { OdDAIObjectId id = m_pIgesModel->getEntityInstance(dbHandle); pInst = id.openObject(); } if (pInst.isNull()) { if (rc) *rc = tvNativePropMissedObject; return OdRxValue(); } OdRxValue value; OdResult odRes = pProperty->getValue(pInst, value); if (bReadOnly) *bReadOnly = pProperty->isReadOnly(pInst); if (odRes != eOk) { if (rc) *rc = tvInternal; return OdRxValue(); } if (rc) *rc = tvOk; return value; } OdRxValueIteratorPtr OdTvVisualizeIgesFiler::getNativeCollectionPropertyIterator(OdUInt64 dbHandle, const OdRxCollectionPropertyPtr& pCollectionProperty, bool* bReadOnly /*= NULL*/, OdTvResult* rc /*= NULL*/) { return OdRxValueIteratorPtr(); } OdTvResult OdTvVisualizeIgesFiler::setNativePropertyValue(OdUInt64 dbHandle, OdRxPropertyPtr& pProperty, const OdRxValue& value) { return tvOk; } OdDbBaseDatabase* OdTvVisualizeIgesFiler::getNativeDatabase(OdTvResult* rc) const { if (m_pIgesFile.isNull()) { if (rc) *rc = tvNativePropMissedDatabase; return NULL; } return (OdDbBaseDatabase*)m_pIgesFile.get(); } //***************************************************************************// // 'OdTvVisualizeIgesFilerModule' methods implementation //***************************************************************************// ODRX_DEFINE_DYNAMIC_MODULE(OdTvVisualizeIgesFilerModule); void OdTvVisualizeIgesFilerModule::initApp() { // initialize the Visualize SDK odTvInitialize(); OdTvIges2VisService::s_moduleDir = getModuleWorkDir(); } void OdTvVisualizeIgesFilerModule::uninitApp() { // Uninitialize the Visualize SDK odTvUninitialize(); } OdTvVisualizeFilerPtr OdTvVisualizeIgesFilerModule::getVisualizeFiler() const { OdTvVisualizeFilerPtr pDwgFiler = new OdTvVisualizeIgesFiler(); return pDwgFiler; } OdString OdTvVisualizeIgesFilerModule::getModuleWorkDir() const { OdString moduleDir = moduleName(); int pos = moduleDir.reverseFind('\\'); if (pos < 0) { pos = moduleDir.reverseFind('/'); } if (pos > 0) { moduleDir = moduleDir.mid(0, pos + 1); } return moduleDir; } //***************************************************************************// // 'OdTvVisualizeIgesFilerDbSource' methods implementation //***************************************************************************// OdAnsiString OdTvIges2VisService::s_moduleDir; IgesFilePtr OdTvVisualizeIgesFilerDbSource::readFile(const OdString &file) { return m_svcs.readFile(file); } void OdTvIgesPartialImportNotifier::entityVectorizationDone(const OdTvEntityId& entityId) { if (entityId.isNull()) return; m_nCurrentObject++; if (m_pMeter) { m_pMeter->meterProgress(); } } void OdTvIgesPartialImportNotifier::insertVectorizationDone(const OdTvEntityId& insertId) { m_nCurrentObject++; if (m_pMeter) { m_pMeter->meterProgress(); } } OdTvIgesPartialImportNotifier::OdTvIgesPartialImportNotifier() { m_nEntitiesEstimation = 0; m_nCurrentObject = 0; m_pMeter = NULL; } OdTvIgesPartialImportNotifier::~OdTvIgesPartialImportNotifier() { } void OdTvIgesPartialImportNotifier::setEntitiesCount(OdUInt32 nCount) { m_nEntitiesEstimation = nCount; if (m_pMeter) m_pMeter->setLimit(m_nEntitiesEstimation); }